Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / chrome / renderer / media / cast_rtp_stream.h
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.
4
5 #ifndef CHROME_RENDERER_MEDIA_CAST_RTP_STREAM_H_
6 #define CHROME_RENDERER_MEDIA_CAST_RTP_STREAM_H_
7
8 #include <string>
9 #include <vector>
10
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"
17
18 class CastAudioSink;
19 class CastSession;
20 class CastVideoSink;
21
22 // A key value pair structure for codec specific parameters.
23 struct CastCodecSpecificParams {
24   std::string key;
25   std::string value;
26
27   CastCodecSpecificParams();
28   ~CastCodecSpecificParams();
29 };
30
31 // Defines the basic properties of a payload supported by cast transport.
32 struct CastRtpPayloadParams {
33   // RTP specific field that identifies the content type.
34   int payload_type;
35
36   // RTP specific field to identify a stream.
37   int ssrc;
38
39   // RTP specific field to idenfity the feedback stream.
40   int feedback_ssrc;
41
42   // Update frequency of payload sample.
43   int clock_rate;
44
45   // Maximum bitrate.
46   int max_bitrate;
47
48   // Minimum bitrate.
49   int min_bitrate;
50
51   // Number of audio channels.
52   int channels;
53
54   // Width and height of the video content.
55   int width;
56   int height;
57
58   // Name of the codec used.
59   std::string codec_name;
60
61   // AES encryption key.
62   std::string aes_key;
63
64   // AES encryption IV mask.
65   std::string aes_iv_mask;
66
67   // List of codec specific parameters.
68   std::vector<CastCodecSpecificParams> codec_specific_params;
69
70   CastRtpPayloadParams();
71   ~CastRtpPayloadParams();
72 };
73
74 // Defines the parameters of a RTP stream.
75 struct CastRtpParams {
76   explicit CastRtpParams(const CastRtpPayloadParams& payload_params);
77
78   // Payload parameters.
79   CastRtpPayloadParams payload;
80
81   // Names of supported RTCP features.
82   std::vector<std::string> rtcp_features;
83
84   CastRtpParams();
85   ~CastRtpParams();
86 };
87
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
92 // stream.
93 class CastRtpStream {
94  public:
95   typedef base::Callback<void(const std::string&)> ErrorCallback;
96
97   CastRtpStream(const blink::WebMediaStreamTrack& track,
98                 const scoped_refptr<CastSession>& session);
99   ~CastRtpStream();
100
101   // Return parameters currently supported by this stream.
102   std::vector<CastRtpParams> GetSupportedParams();
103
104   // Return parameters set to this stream.
105   CastRtpParams GetParams();
106
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);
116
117   // Stop encoding.
118   void Stop();
119
120  private:
121   // Return true if this track is an audio track. Return false if this
122   // track is a video track.
123   bool IsAudio() const;
124
125   void DidEncounterError(const std::string& message);
126
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_;
135
136   DISALLOW_COPY_AND_ASSIGN(CastRtpStream);
137 };
138
139 #endif  // CHROME_RENDERER_MEDIA_CAST_RTP_STREAM_H_