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