OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/renderer/extensions/webrtc_native_handler.h" | 5 #include "chrome/renderer/extensions/webrtc_native_handler.h" |
6 | 6 |
7 #include <functional> | |
8 | |
7 #include "base/logging.h" | 9 #include "base/logging.h" |
8 #include "chrome/common/extensions/api/webrtc_cast_send_transport.h" | 10 #include "chrome/common/extensions/api/webrtc_cast_send_transport.h" |
9 #include "chrome/common/extensions/api/webrtc_cast_udp_transport.h" | 11 #include "chrome/common/extensions/api/webrtc_cast_udp_transport.h" |
10 #include "chrome/renderer/extensions/chrome_v8_context.h" | 12 #include "chrome/renderer/extensions/chrome_v8_context.h" |
11 #include "chrome/renderer/media/cast_send_transport.h" | 13 #include "chrome/renderer/media/cast_send_transport.h" |
12 #include "chrome/renderer/media/cast_session.h" | 14 #include "chrome/renderer/media/cast_session.h" |
13 #include "chrome/renderer/media/cast_udp_transport.h" | 15 #include "chrome/renderer/media/cast_udp_transport.h" |
14 #include "content/public/renderer/v8_value_converter.h" | 16 #include "content/public/renderer/v8_value_converter.h" |
15 #include "net/base/host_port_pair.h" | 17 #include "net/base/host_port_pair.h" |
16 | 18 |
17 using content::V8ValueConverter; | 19 using content::V8ValueConverter; |
18 | 20 |
19 // Extension types. | 21 // Extension types. |
22 using extensions::api::webrtc_cast_send_transport::CodecSpecificParams; | |
20 using extensions::api::webrtc_cast_send_transport::RtpCaps; | 23 using extensions::api::webrtc_cast_send_transport::RtpCaps; |
21 using extensions::api::webrtc_cast_send_transport::RtpParams; | 24 using extensions::api::webrtc_cast_send_transport::RtpParams; |
22 using extensions::api::webrtc_cast_send_transport::RtpPayloadParams; | 25 using extensions::api::webrtc_cast_send_transport::RtpPayloadParams; |
23 using extensions::api::webrtc_cast_udp_transport::CreateInfo; | 26 using extensions::api::webrtc_cast_udp_transport::CreateInfo; |
24 using extensions::api::webrtc_cast_udp_transport::UdpParams; | 27 using extensions::api::webrtc_cast_udp_transport::UdpParams; |
25 | 28 |
26 namespace extensions { | 29 namespace extensions { |
27 | 30 |
28 namespace { | 31 namespace { |
29 const char kSendTransportNotFound[] = "The send transport cannot be found"; | 32 const char kSendTransportNotFound[] = "The send transport cannot be found"; |
30 const char kUdpTransportNotFound[] = "The UDP transport cannot be found"; | 33 const char kUdpTransportNotFound[] = "The UDP transport cannot be found"; |
31 const char kInvalidUdpParams[] = "Invalid UDP params"; | 34 const char kInvalidUdpParams[] = "Invalid UDP params"; |
32 const char kInvalidRtpCaps[] = "Invalid value for RTP caps"; | 35 const char kInvalidRtpCaps[] = "Invalid value for RTP caps"; |
33 const char kInvalidRtpParams[] = "Invalid value for RTP params"; | 36 const char kInvalidRtpParams[] = "Invalid value for RTP params"; |
34 const char kUnableToConvertArgs[] = "Unable to convert arguments"; | 37 const char kUnableToConvertArgs[] = "Unable to convert arguments"; |
35 const char kUnableToConvertCaps[] = "Unable to convert caps"; | 38 const char kUnableToConvertCaps[] = "Unable to convert caps"; |
36 const char kUnableToConvertParams[] = "Unable to convert params"; | 39 const char kUnableToConvertParams[] = "Unable to convert params"; |
37 | 40 |
38 // These helper methods are used to convert between Extension API | 41 // These helper methods are used to convert between Extension API |
39 // types and Cast types. | 42 // types and Cast types. |
43 bool ToCastCodecSpecificParams(const CodecSpecificParams& ext_params, | |
44 CastCodecSpecificParams* cast_params) { | |
45 cast_params->key = ext_params.key; | |
46 cast_params->value = ext_params.value; | |
47 return true; | |
scherkus (not reviewing)
2013/11/01 00:26:23
this is silly
Alpha Left Google
2013/11/01 00:39:20
Yeah returning a boolean is probably not useful he
| |
48 } | |
49 | |
50 bool FromCastCodecSpecificParams(const CastCodecSpecificParams& cast_params, | |
51 CodecSpecificParams* ext_params) { | |
52 ext_params->key = cast_params.key; | |
53 ext_params->value = cast_params.value; | |
54 return true; | |
scherkus (not reviewing)
2013/11/01 00:26:23
ditto
Alpha Left Google
2013/11/01 00:39:20
Done.
| |
55 } | |
56 | |
57 bool ToCastRtpPayloadParams(const RtpPayloadParams& ext_params, | |
58 CastRtpPayloadParams* cast_params) { | |
59 cast_params->payload_type = ext_params.payload_type; | |
60 cast_params->codec_name = ext_params.codec_name; | |
61 cast_params->ssrc = ext_params.ssrc ? *ext_params.ssrc : 0; | |
62 cast_params->clock_rate = ext_params.clock_rate ? *ext_params.clock_rate : 0; | |
63 cast_params->min_bitrate = | |
64 ext_params.min_bitrate ? *ext_params.min_bitrate : 0; | |
65 cast_params->max_bitrate = | |
66 ext_params.max_bitrate ? *ext_params.max_bitrate : 0; | |
67 cast_params->channels = ext_params.channels ? *ext_params.channels : 0; | |
68 cast_params->width = ext_params.width ? *ext_params.width : 0; | |
69 cast_params->height = ext_params.height ? *ext_params.height : 0; | |
70 for (size_t i = 0; i < ext_params.codec_specific_params.size(); ++i) { | |
71 CastCodecSpecificParams cast_codec_params; | |
72 if (!ToCastCodecSpecificParams(*ext_params.codec_specific_params[i], | |
73 &cast_codec_params)) { | |
scherkus (not reviewing)
2013/11/01 00:26:23
fix indent
Alpha Left Google
2013/11/01 00:39:20
Done.
| |
74 return false; | |
75 } | |
76 cast_params->codec_specific_params.push_back(cast_codec_params); | |
77 } | |
78 return true; | |
scherkus (not reviewing)
2013/11/01 00:26:23
this function always returns true
please s/bool/v
Alpha Left Google
2013/11/01 00:39:20
Done.
| |
79 } | |
80 | |
81 bool FromCastRtpPayloadParams(const CastRtpPayloadParams& cast_params, | |
82 RtpPayloadParams* ext_params) { | |
83 ext_params->payload_type = cast_params.payload_type; | |
84 ext_params->codec_name = cast_params.codec_name; | |
85 if (cast_params.ssrc) { | |
86 ext_params->ssrc.reset(new int); | |
87 *ext_params->ssrc = cast_params.ssrc; | |
88 } | |
89 if (cast_params.clock_rate) { | |
90 ext_params->clock_rate.reset(new int); | |
91 *ext_params->clock_rate = cast_params.clock_rate; | |
92 } | |
93 if (cast_params.min_bitrate) { | |
94 ext_params->min_bitrate.reset(new int); | |
95 *ext_params->min_bitrate = cast_params.min_bitrate; | |
96 } | |
97 if (cast_params.max_bitrate) { | |
98 ext_params->max_bitrate.reset(new int); | |
99 *ext_params->max_bitrate = cast_params.max_bitrate; | |
100 } | |
101 if (cast_params.channels) { | |
102 ext_params->channels.reset(new int); | |
103 *ext_params->channels = cast_params.channels; | |
104 } | |
105 if (cast_params.width) { | |
106 ext_params->width.reset(new int); | |
107 *ext_params->width = cast_params.width; | |
108 } | |
109 if (cast_params.height) { | |
110 ext_params->height.reset(new int); | |
111 *ext_params->height = cast_params.height; | |
112 } | |
113 for (size_t i = 0; i < cast_params.codec_specific_params.size(); ++i) { | |
114 linked_ptr<CodecSpecificParams> ext_codec_params( | |
115 new CodecSpecificParams()); | |
116 if (!FromCastCodecSpecificParams(cast_params.codec_specific_params[i], | |
117 ext_codec_params.get())) { | |
118 return false; | |
119 } | |
120 ext_params->codec_specific_params.push_back(ext_codec_params); | |
121 } | |
122 return true; | |
123 } | |
124 | |
40 bool ToCastRtpCaps(const RtpCaps& ext_caps, CastRtpCaps* cast_caps) { | 125 bool ToCastRtpCaps(const RtpCaps& ext_caps, CastRtpCaps* cast_caps) { |
41 NOTIMPLEMENTED(); | 126 std::copy(ext_caps.rtcp_features.begin(), ext_caps.rtcp_features.end(), |
127 cast_caps->rtcp_features.begin()); | |
128 std::copy(ext_caps.fec_mechanisms.begin(), ext_caps.fec_mechanisms.end(), | |
129 cast_caps->fec_mechanisms.begin()); | |
130 for (size_t i = 0; i < ext_caps.payloads.size(); ++i) { | |
131 CastRtpPayloadParams cast_payload_params; | |
132 if (!ToCastRtpPayloadParams(*ext_caps.payloads[i], &cast_payload_params)) { | |
133 return false; | |
134 } | |
135 cast_caps->payloads.push_back(cast_payload_params); | |
136 } | |
42 return true; | 137 return true; |
43 } | 138 } |
44 | 139 |
45 bool FromCastRtpCaps(const CastRtpCaps& cast_caps, RtpCaps* ext_caps) { | 140 bool FromCastRtpCaps(const CastRtpCaps& cast_caps, RtpCaps* ext_caps) { |
46 NOTIMPLEMENTED(); | 141 std::copy(cast_caps.rtcp_features.begin(), cast_caps.rtcp_features.end(), |
142 ext_caps->rtcp_features.begin()); | |
143 std::copy(cast_caps.fec_mechanisms.begin(), cast_caps.fec_mechanisms.end(), | |
144 ext_caps->fec_mechanisms.begin()); | |
145 for (size_t i = 0; i < cast_caps.payloads.size(); ++i) { | |
146 linked_ptr<RtpPayloadParams> ext_payload_params(new RtpPayloadParams()); | |
147 if (!FromCastRtpPayloadParams(cast_caps.payloads[i], | |
148 ext_payload_params.get())) { | |
149 return false; | |
150 } | |
151 ext_caps->payloads.push_back(ext_payload_params); | |
152 } | |
47 return true; | 153 return true; |
48 } | 154 } |
49 | 155 |
50 bool ToCastRtpParams(const RtpParams& ext_params, CastRtpParams* cast_params) { | 156 bool ToCastRtpParams(const RtpParams& ext_params, CastRtpParams* cast_params) { |
51 NOTIMPLEMENTED(); | 157 std::copy(ext_params.rtcp_features.begin(), ext_params.rtcp_features.end(), |
158 cast_params->rtcp_features.begin()); | |
159 std::copy(ext_params.fec_mechanisms.begin(), ext_params.fec_mechanisms.end(), | |
160 cast_params->fec_mechanisms.begin()); | |
161 for (size_t i = 0; i < ext_params.payloads.size(); ++i) { | |
162 CastRtpPayloadParams cast_payload_params; | |
163 if (!ToCastRtpPayloadParams(*ext_params.payloads[i], | |
164 &cast_payload_params)) { | |
165 return false; | |
166 } | |
167 cast_params->payloads.push_back(cast_payload_params); | |
168 } | |
52 return true; | 169 return true; |
53 } | 170 } |
54 | 171 |
55 bool FromCastRtpParams(const CastRtpParams& cast_params, | 172 bool FromCastRtpParams(const CastRtpParams& cast_params, |
56 RtpParams* ext_params) { | 173 RtpParams* ext_params) { |
57 NOTIMPLEMENTED(); | 174 std::copy(cast_params.rtcp_features.begin(), cast_params.rtcp_features.end(), |
175 ext_params->rtcp_features.begin()); | |
176 std::copy(cast_params.fec_mechanisms.begin(), | |
177 cast_params.fec_mechanisms.end(), | |
178 ext_params->fec_mechanisms.begin()); | |
179 for (size_t i = 0; i < cast_params.payloads.size(); ++i) { | |
180 linked_ptr<RtpPayloadParams> ext_payload_params(new RtpPayloadParams()); | |
181 if (!FromCastRtpPayloadParams(cast_params.payloads[i], | |
182 ext_payload_params.get())) { | |
183 return false; | |
184 } | |
185 ext_params->payloads.push_back(ext_payload_params); | |
186 } | |
58 return true; | 187 return true; |
59 } | 188 } |
60 | 189 |
61 } // namespace | 190 } // namespace |
62 | 191 |
63 WebRtcNativeHandler::WebRtcNativeHandler(ChromeV8Context* context) | 192 WebRtcNativeHandler::WebRtcNativeHandler(ChromeV8Context* context) |
64 : ObjectBackedNativeHandler(context), | 193 : ObjectBackedNativeHandler(context), |
65 last_transport_id_(0) { | 194 last_transport_id_(0) { |
66 RouteFunction("CreateCastSendTransport", | 195 RouteFunction("CreateCastSendTransport", |
67 base::Bind(&WebRtcNativeHandler::CreateCastSendTransport, | 196 base::Bind(&WebRtcNativeHandler::CreateCastSendTransport, |
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
342 UdpTransportMap::const_iterator iter = udp_transport_map_.find( | 471 UdpTransportMap::const_iterator iter = udp_transport_map_.find( |
343 transport_id); | 472 transport_id); |
344 if (iter != udp_transport_map_.end()) | 473 if (iter != udp_transport_map_.end()) |
345 return iter->second.get(); | 474 return iter->second.get(); |
346 v8::ThrowException(v8::Exception::RangeError(v8::String::New( | 475 v8::ThrowException(v8::Exception::RangeError(v8::String::New( |
347 kUdpTransportNotFound))); | 476 kUdpTransportNotFound))); |
348 return NULL; | 477 return NULL; |
349 } | 478 } |
350 | 479 |
351 } // namespace extensions | 480 } // namespace extensions |
OLD | NEW |