Unregister from GCM when the only GCM app is removed
[chromium-blink-merge.git] / chrome / renderer / media / cast_rtp_stream.h
blob61a6bf4b1309cc38c12eaa2af82b6a21b805a6f9
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef CHROME_RENDERER_MEDIA_CAST_RTP_STREAM_H_
6 #define CHROME_RENDERER_MEDIA_CAST_RTP_STREAM_H_
8 #include <string>
9 #include <vector>
11 #include "base/basictypes.h"
12 #include "base/callback.h"
13 #include "base/memory/ref_counted.h"
14 #include "base/memory/scoped_ptr.h"
15 #include "base/memory/weak_ptr.h"
16 #include "third_party/WebKit/public/platform/WebMediaStreamTrack.h"
18 namespace base {
19 class BinaryValue;
20 class DictionaryValue;
23 class CastAudioSink;
24 class CastSession;
25 class CastVideoSink;
27 // A key value pair structure for codec specific parameters.
28 struct CastCodecSpecificParams {
29 std::string key;
30 std::string value;
32 CastCodecSpecificParams();
33 ~CastCodecSpecificParams();
36 // Defines the basic properties of a payload supported by cast transport.
37 struct CastRtpPayloadParams {
38 // RTP specific field that identifies the content type.
39 int payload_type;
41 // Maximum latency in milliseconds. Implemetation tries to keep latency
42 // under this threshold.
43 int max_latency_ms;
45 // Minimum latency.
46 // Default value (0) means use max_latency_ms.
47 int min_latency_ms;
49 // RTP specific field to identify a stream.
50 int ssrc;
52 // RTP specific field to idenfity the feedback stream.
53 int feedback_ssrc;
55 // Update frequency of payload sample.
56 int clock_rate;
58 // Maximum bitrate in kilobits per second.
59 int max_bitrate;
61 // Minimum bitrate in kilobits per second.
62 int min_bitrate;
64 // Number of audio channels.
65 int channels;
67 // The maximum frame rate.
68 double max_frame_rate;
70 // Width and height of the video content.
71 // TODO(miu): DEPRECATED. Remove these, as they are ignored.
72 int width;
73 int height;
75 // Name of the codec used.
76 std::string codec_name;
78 // AES encryption key.
79 std::string aes_key;
81 // AES encryption IV mask.
82 std::string aes_iv_mask;
84 // List of codec specific parameters.
85 std::vector<CastCodecSpecificParams> codec_specific_params;
87 CastRtpPayloadParams();
88 ~CastRtpPayloadParams();
91 // Defines the parameters of a RTP stream.
92 struct CastRtpParams {
93 explicit CastRtpParams(const CastRtpPayloadParams& payload_params);
95 // Payload parameters.
96 CastRtpPayloadParams payload;
98 // Names of supported RTCP features.
99 std::vector<std::string> rtcp_features;
101 CastRtpParams();
102 ~CastRtpParams();
105 // This object represents a RTP stream that encodes and optionally
106 // encrypt audio or video data from a WebMediaStreamTrack.
107 // Note that this object does not actually output packets. It allows
108 // configuration of encoding and RTP parameters and control such a logical
109 // stream.
110 class CastRtpStream {
111 public:
112 typedef base::Callback<void(const std::string&)> ErrorCallback;
114 CastRtpStream(const blink::WebMediaStreamTrack& track,
115 const scoped_refptr<CastSession>& session);
116 ~CastRtpStream();
118 // Return parameters currently supported by this stream.
119 std::vector<CastRtpParams> GetSupportedParams();
121 // Return parameters set to this stream.
122 CastRtpParams GetParams();
124 // Begin encoding of media stream and then submit the encoded streams
125 // to underlying transport.
126 // When the stream is started |start_callback| is called.
127 // When the stream is stopped |stop_callback| is called.
128 // When there is an error |error_callback| is called with a message.
129 void Start(const CastRtpParams& params,
130 const base::Closure& start_callback,
131 const base::Closure& stop_callback,
132 const ErrorCallback& error_callback);
134 // Stop encoding.
135 void Stop();
137 // Enables or disables logging for this stream.
138 void ToggleLogging(bool enable);
140 // Get serialized raw events for this stream with |extra_data| attached,
141 // and invokes |callback| with the result.
142 void GetRawEvents(
143 const base::Callback<void(scoped_ptr<base::BinaryValue>)>& callback,
144 const std::string& extra_data);
146 // Get stats in DictionaryValue format and invokves |callback| with
147 // the result.
148 void GetStats(const base::Callback<void(
149 scoped_ptr<base::DictionaryValue>)>& callback);
151 private:
152 // Return true if this track is an audio track. Return false if this
153 // track is a video track.
154 bool IsAudio() const;
156 void DidEncounterError(const std::string& message);
158 blink::WebMediaStreamTrack track_;
159 const scoped_refptr<CastSession> cast_session_;
160 scoped_ptr<CastAudioSink> audio_sink_;
161 scoped_ptr<CastVideoSink> video_sink_;
162 CastRtpParams params_;
163 base::Closure stop_callback_;
164 ErrorCallback error_callback_;
166 base::WeakPtrFactory<CastRtpStream> weak_factory_;
168 DISALLOW_COPY_AND_ASSIGN(CastRtpStream);
171 #endif // CHROME_RENDERER_MEDIA_CAST_RTP_STREAM_H_