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_
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"
20 class DictionaryValue;
27 // A key value pair structure for codec specific parameters.
28 struct CastCodecSpecificParams {
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.
41 // Maximum latency in milliseconds. Implemetation tries to keep latency
42 // under this threshold.
45 // RTP specific field to identify a stream.
48 // RTP specific field to idenfity the feedback stream.
51 // Update frequency of payload sample.
54 // Maximum bitrate in kilobits per second.
57 // Minimum bitrate in kilobits per second.
60 // Number of audio channels.
63 // The maximum frame rate.
64 double max_frame_rate;
66 // Width and height of the video content.
70 // Name of the codec used.
71 std::string codec_name;
73 // AES encryption key.
76 // AES encryption IV mask.
77 std::string aes_iv_mask;
79 // List of codec specific parameters.
80 std::vector<CastCodecSpecificParams> codec_specific_params;
82 CastRtpPayloadParams();
83 ~CastRtpPayloadParams();
86 // Defines the parameters of a RTP stream.
87 struct CastRtpParams {
88 explicit CastRtpParams(const CastRtpPayloadParams& payload_params);
90 // Payload parameters.
91 CastRtpPayloadParams payload;
93 // Names of supported RTCP features.
94 std::vector<std::string> rtcp_features;
100 // This object represents a RTP stream that encodes and optionally
101 // encrypt audio or video data from a WebMediaStreamTrack.
102 // Note that this object does not actually output packets. It allows
103 // configuration of encoding and RTP parameters and control such a logical
105 class CastRtpStream {
107 typedef base::Callback<void(const std::string&)> ErrorCallback;
109 CastRtpStream(const blink::WebMediaStreamTrack& track,
110 const scoped_refptr<CastSession>& session);
113 // Return parameters currently supported by this stream.
114 std::vector<CastRtpParams> GetSupportedParams();
116 // Return parameters set to this stream.
117 CastRtpParams GetParams();
119 // Begin encoding of media stream and then submit the encoded streams
120 // to underlying transport.
121 // When the stream is started |start_callback| is called.
122 // When the stream is stopped |stop_callback| is called.
123 // When there is an error |error_callback| is called with a message.
124 void Start(const CastRtpParams& params,
125 const base::Closure& start_callback,
126 const base::Closure& stop_callback,
127 const ErrorCallback& error_callback);
132 // Enables or disables logging for this stream.
133 void ToggleLogging(bool enable);
135 // Get serialized raw events for this stream with |extra_data| attached,
136 // and invokes |callback| with the result.
138 const base::Callback<void(scoped_ptr<base::BinaryValue>)>& callback,
139 const std::string& extra_data);
141 // Get stats in DictionaryValue format and invokves |callback| with
143 void GetStats(const base::Callback<void(
144 scoped_ptr<base::DictionaryValue>)>& callback);
147 // Return true if this track is an audio track. Return false if this
148 // track is a video track.
149 bool IsAudio() const;
151 void DidEncounterError(const std::string& message);
153 blink::WebMediaStreamTrack track_;
154 const scoped_refptr<CastSession> cast_session_;
155 scoped_ptr<CastAudioSink> audio_sink_;
156 scoped_ptr<CastVideoSink> video_sink_;
157 CastRtpParams params_;
158 base::WeakPtrFactory<CastRtpStream> weak_factory_;
159 base::Closure stop_callback_;
160 ErrorCallback error_callback_;
162 DISALLOW_COPY_AND_ASSIGN(CastRtpStream);
165 #endif // CHROME_RENDERER_MEDIA_CAST_RTP_STREAM_H_