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"
22 // A key value pair structure for codec specific parameters.
23 struct CastCodecSpecificParams {
27 CastCodecSpecificParams();
28 ~CastCodecSpecificParams();
31 // Defines the basic properties of a payload supported by cast transport.
32 struct CastRtpPayloadParams {
33 // RTP specific field that identifies the content type.
36 // RTP specific field to identify a stream.
39 // RTP specific field to idenfity the feedback stream.
42 // Update frequency of payload sample.
51 // Number of audio channels.
54 // Width and height of the video content.
58 // Name of the codec used.
59 std::string codec_name;
61 // AES encryption key.
64 // AES encryption IV mask.
65 std::string aes_iv_mask;
67 // List of codec specific parameters.
68 std::vector<CastCodecSpecificParams> codec_specific_params;
70 CastRtpPayloadParams();
71 ~CastRtpPayloadParams();
74 // Defines the parameters of a RTP stream.
75 struct CastRtpParams {
76 explicit CastRtpParams(const CastRtpPayloadParams& payload_params);
78 // Payload parameters.
79 CastRtpPayloadParams payload;
81 // Names of supported RTCP features.
82 std::vector<std::string> rtcp_features;
88 // This object represents a RTP stream that encodes and optionally
89 // encrypt audio or video data from a WebMediaStreamTrack.
90 // Note that this object does not actually output packets. It allows
91 // configuration of encoding and RTP parameters and control such a logical
95 typedef base::Callback<void(const std::string&)> ErrorCallback;
97 CastRtpStream(const blink::WebMediaStreamTrack& track,
98 const scoped_refptr<CastSession>& session);
101 // Return parameters currently supported by this stream.
102 std::vector<CastRtpParams> GetSupportedParams();
104 // Return parameters set to this stream.
105 CastRtpParams GetParams();
107 // Begin encoding of media stream and then submit the encoded streams
108 // to underlying transport.
109 // When the stream is started |start_callback| is called.
110 // When the stream is stopped |stop_callback| is called.
111 // When there is an error |error_callback| is called with a message.
112 void Start(const CastRtpParams& params,
113 const base::Closure& start_callback,
114 const base::Closure& stop_callback,
115 const ErrorCallback& error_callback);
121 // Return true if this track is an audio track. Return false if this
122 // track is a video track.
123 bool IsAudio() const;
125 void DidEncounterError(const std::string& message);
127 blink::WebMediaStreamTrack track_;
128 const scoped_refptr<CastSession> cast_session_;
129 scoped_ptr<CastAudioSink> audio_sink_;
130 scoped_ptr<CastVideoSink> video_sink_;
131 CastRtpParams params_;
132 base::WeakPtrFactory<CastRtpStream> weak_factory_;
133 base::Closure stop_callback_;
134 ErrorCallback error_callback_;
136 DISALLOW_COPY_AND_ASSIGN(CastRtpStream);
139 #endif // CHROME_RENDERER_MEDIA_CAST_RTP_STREAM_H_