Chromium Code Reviews| 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/cast_streaming_native_handler.h" | 5 #include "chrome/renderer/extensions/cast_streaming_native_handler.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <algorithm> | 10 #include <algorithm> |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 57 const char kInvalidAesIvMask[] = "Invalid value for AES IV mask"; | 57 const char kInvalidAesIvMask[] = "Invalid value for AES IV mask"; |
| 58 const char kInvalidAesKey[] = "Invalid value for AES key"; | 58 const char kInvalidAesKey[] = "Invalid value for AES key"; |
| 59 const char kInvalidAudioParams[] = "Invalid audio params"; | 59 const char kInvalidAudioParams[] = "Invalid audio params"; |
| 60 const char kInvalidDestination[] = "Invalid destination"; | 60 const char kInvalidDestination[] = "Invalid destination"; |
| 61 const char kInvalidFPS[] = "Invalid FPS"; | 61 const char kInvalidFPS[] = "Invalid FPS"; |
| 62 const char kInvalidMediaStreamURL[] = "Invalid MediaStream URL"; | 62 const char kInvalidMediaStreamURL[] = "Invalid MediaStream URL"; |
| 63 const char kInvalidRtpParams[] = "Invalid value for RTP params"; | 63 const char kInvalidRtpParams[] = "Invalid value for RTP params"; |
| 64 const char kInvalidLatency[] = "Invalid value for max_latency. (0-1000)"; | 64 const char kInvalidLatency[] = "Invalid value for max_latency. (0-1000)"; |
| 65 const char kInvalidRtpTimebase[] = "Invalid rtp_timebase. (1000-1000000)"; | 65 const char kInvalidRtpTimebase[] = "Invalid rtp_timebase. (1000-1000000)"; |
| 66 const char kInvalidStreamArgs[] = "Invalid stream arguments"; | 66 const char kInvalidStreamArgs[] = "Invalid stream arguments"; |
| 67 const char kInvalidCodec[] = "Invalid codec"; | |
| 67 const char kRtpStreamNotFound[] = "The RTP stream cannot be found"; | 68 const char kRtpStreamNotFound[] = "The RTP stream cannot be found"; |
| 68 const char kUdpTransportNotFound[] = "The UDP transport cannot be found"; | 69 const char kUdpTransportNotFound[] = "The UDP transport cannot be found"; |
| 69 const char kUnableToConvertArgs[] = "Unable to convert arguments"; | 70 const char kUnableToConvertArgs[] = "Unable to convert arguments"; |
| 70 const char kUnableToConvertParams[] = "Unable to convert params"; | 71 const char kUnableToConvertParams[] = "Unable to convert params"; |
| 71 | 72 |
| 72 // These helper methods are used to convert between Extension API | 73 // These helper methods are used to convert between Extension API |
| 73 // types and Cast types. | 74 // types and Cast types. |
| 74 void ToCastCodecSpecificParams(const CodecSpecificParams& ext_params, | 75 void ToCastCodecSpecificParams(const CodecSpecificParams& ext_params, |
| 75 CastCodecSpecificParams* cast_params) { | 76 CastCodecSpecificParams* cast_params) { |
| 76 cast_params->key = ext_params.key; | 77 cast_params->key = ext_params.key; |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 89 if (!base::HexStringToBytes(input, &bytes)) | 90 if (!base::HexStringToBytes(input, &bytes)) |
| 90 return false; | 91 return false; |
| 91 output->assign(reinterpret_cast<const char*>(&bytes[0]), bytes.size()); | 92 output->assign(reinterpret_cast<const char*>(&bytes[0]), bytes.size()); |
| 92 return true; | 93 return true; |
| 93 } | 94 } |
| 94 } // namespace | 95 } // namespace |
| 95 | 96 |
| 96 bool ToCastRtpPayloadParamsOrThrow(v8::Isolate* isolate, | 97 bool ToCastRtpPayloadParamsOrThrow(v8::Isolate* isolate, |
| 97 const RtpPayloadParams& ext_params, | 98 const RtpPayloadParams& ext_params, |
| 98 CastRtpPayloadParams* cast_params) { | 99 CastRtpPayloadParams* cast_params) { |
| 99 cast_params->payload_type = ext_params.payload_type; | |
| 100 cast_params->max_latency_ms = ext_params.max_latency; | 100 cast_params->max_latency_ms = ext_params.max_latency; |
| 101 cast_params->min_latency_ms = | 101 cast_params->min_latency_ms = |
| 102 ext_params.min_latency ? *ext_params.min_latency : ext_params.max_latency; | 102 ext_params.min_latency ? *ext_params.min_latency : ext_params.max_latency; |
| 103 cast_params->animated_latency_ms = ext_params.animated_latency | 103 cast_params->animated_latency_ms = ext_params.animated_latency |
| 104 ? *ext_params.animated_latency | 104 ? *ext_params.animated_latency |
| 105 : ext_params.max_latency; | 105 : ext_params.max_latency; |
| 106 cast_params->codec_name = ext_params.codec_name; | 106 cast_params->codec_name = ext_params.codec_name; |
| 107 if (cast_params->codec_name == "OPUS") { | |
| 108 cast_params->payload_type = media::cast::RtpPayloadType::AUDIO_OPUS; | |
| 109 } else if (cast_params->codec_name == "PCM16") { | |
| 110 cast_params->payload_type = media::cast::RtpPayloadType::AUDIO_PCM16; | |
| 111 } else if (cast_params->codec_name == "AAC") { | |
| 112 cast_params->payload_type = media::cast::RtpPayloadType::AUDIO_AAC; | |
| 113 } else if (cast_params->codec_name == "VP8") { | |
| 114 cast_params->payload_type = media::cast::RtpPayloadType::VIDEO_VP8; | |
| 115 } else if (cast_params->codec_name == "H264") { | |
| 116 cast_params->payload_type = media::cast::RtpPayloadType::VIDEO_H264; | |
| 117 } else { | |
| 118 isolate->ThrowException( | |
|
Marijn Kruisselbrink
2016/06/24 16:54:57
One of the now failing tests seems to be a test to
miu
2016/06/27 21:00:36
FWIW, I have a change WIP to clean-up and simplify
xjz
2016/06/28 16:46:26
Thanks Yuri for the reply. Now revert the CL to Pa
| |
| 119 v8::Exception::Error(v8::String::NewFromUtf8(isolate, kInvalidCodec))); | |
| 120 return false; | |
| 121 } | |
| 107 cast_params->ssrc = ext_params.ssrc; | 122 cast_params->ssrc = ext_params.ssrc; |
| 108 cast_params->feedback_ssrc = ext_params.feedback_ssrc; | 123 cast_params->feedback_ssrc = ext_params.feedback_ssrc; |
| 109 cast_params->clock_rate = ext_params.clock_rate ? *ext_params.clock_rate : 0; | 124 cast_params->clock_rate = ext_params.clock_rate ? *ext_params.clock_rate : 0; |
| 110 cast_params->min_bitrate = | 125 cast_params->min_bitrate = |
| 111 ext_params.min_bitrate ? *ext_params.min_bitrate : 0; | 126 ext_params.min_bitrate ? *ext_params.min_bitrate : 0; |
| 112 cast_params->max_bitrate = | 127 cast_params->max_bitrate = |
| 113 ext_params.max_bitrate ? *ext_params.max_bitrate : 0; | 128 ext_params.max_bitrate ? *ext_params.max_bitrate : 0; |
| 114 cast_params->channels = ext_params.channels ? *ext_params.channels : 0; | 129 cast_params->channels = ext_params.channels ? *ext_params.channels : 0; |
| 115 cast_params->max_frame_rate = | 130 cast_params->max_frame_rate = |
| 116 ext_params.max_frame_rate ? *ext_params.max_frame_rate : 0.0; | 131 ext_params.max_frame_rate ? *ext_params.max_frame_rate : 0.0; |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 130 CastCodecSpecificParams cast_codec_params; | 145 CastCodecSpecificParams cast_codec_params; |
| 131 ToCastCodecSpecificParams(ext_params.codec_specific_params[i], | 146 ToCastCodecSpecificParams(ext_params.codec_specific_params[i], |
| 132 &cast_codec_params); | 147 &cast_codec_params); |
| 133 cast_params->codec_specific_params.push_back(cast_codec_params); | 148 cast_params->codec_specific_params.push_back(cast_codec_params); |
| 134 } | 149 } |
| 135 return true; | 150 return true; |
| 136 } | 151 } |
| 137 | 152 |
| 138 void FromCastRtpPayloadParams(const CastRtpPayloadParams& cast_params, | 153 void FromCastRtpPayloadParams(const CastRtpPayloadParams& cast_params, |
| 139 RtpPayloadParams* ext_params) { | 154 RtpPayloadParams* ext_params) { |
| 140 ext_params->payload_type = cast_params.payload_type; | 155 ext_params->payload_type = static_cast<int>(cast_params.payload_type); |
| 141 ext_params->max_latency = cast_params.max_latency_ms; | 156 ext_params->max_latency = cast_params.max_latency_ms; |
| 142 ext_params->min_latency.reset(new int(cast_params.min_latency_ms)); | 157 ext_params->min_latency.reset(new int(cast_params.min_latency_ms)); |
| 143 ext_params->animated_latency.reset(new int(cast_params.animated_latency_ms)); | 158 ext_params->animated_latency.reset(new int(cast_params.animated_latency_ms)); |
| 144 ext_params->codec_name = cast_params.codec_name; | 159 ext_params->codec_name = cast_params.codec_name; |
| 145 ext_params->ssrc = cast_params.ssrc; | 160 ext_params->ssrc = cast_params.ssrc; |
| 146 ext_params->feedback_ssrc = cast_params.feedback_ssrc; | 161 ext_params->feedback_ssrc = cast_params.feedback_ssrc; |
| 147 if (cast_params.clock_rate) | 162 if (cast_params.clock_rate) |
| 148 ext_params->clock_rate.reset(new int(cast_params.clock_rate)); | 163 ext_params->clock_rate.reset(new int(cast_params.clock_rate)); |
| 149 if (cast_params.min_bitrate) | 164 if (cast_params.min_bitrate) |
| 150 ext_params->min_bitrate.reset(new int(cast_params.min_bitrate)); | 165 ext_params->min_bitrate.reset(new int(cast_params.min_bitrate)); |
| (...skipping 518 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 669 config->rtp_max_delay_ms = params->max_latency; | 684 config->rtp_max_delay_ms = params->max_latency; |
| 670 if (config->rtp_max_delay_ms < 0 || config->rtp_max_delay_ms > 1000) { | 685 if (config->rtp_max_delay_ms < 0 || config->rtp_max_delay_ms > 1000) { |
| 671 isolate->ThrowException(v8::Exception::TypeError( | 686 isolate->ThrowException(v8::Exception::TypeError( |
| 672 v8::String::NewFromUtf8(isolate, kInvalidLatency))); | 687 v8::String::NewFromUtf8(isolate, kInvalidLatency))); |
| 673 return false; | 688 return false; |
| 674 } | 689 } |
| 675 config->channels = 2; | 690 config->channels = 2; |
| 676 if (params->codec_name == "OPUS") { | 691 if (params->codec_name == "OPUS") { |
| 677 config->codec = media::cast::CODEC_AUDIO_OPUS; | 692 config->codec = media::cast::CODEC_AUDIO_OPUS; |
| 678 config->rtp_timebase = 48000; | 693 config->rtp_timebase = 48000; |
| 679 config->rtp_payload_type = media::cast::kDefaultRtpAudioPayloadType; | 694 config->rtp_payload_type = media::cast::RtpPayloadType::AUDIO_OPUS; |
| 680 } else if (params->codec_name == "PCM16") { | 695 } else if (params->codec_name == "PCM16") { |
| 681 config->codec = media::cast::CODEC_AUDIO_PCM16; | 696 config->codec = media::cast::CODEC_AUDIO_PCM16; |
| 682 config->rtp_timebase = 48000; | 697 config->rtp_timebase = 48000; |
| 683 config->rtp_payload_type = media::cast::kDefaultRtpAudioPayloadType; | 698 config->rtp_payload_type = media::cast::RtpPayloadType::AUDIO_PCM16; |
| 684 } else if (params->codec_name == "AAC") { | 699 } else if (params->codec_name == "AAC") { |
| 685 config->codec = media::cast::CODEC_AUDIO_AAC; | 700 config->codec = media::cast::CODEC_AUDIO_AAC; |
| 686 config->rtp_timebase = 48000; | 701 config->rtp_timebase = 48000; |
| 687 config->rtp_payload_type = media::cast::kDefaultRtpAudioPayloadType; | 702 config->rtp_payload_type = media::cast::RtpPayloadType::AUDIO_AAC; |
| 688 } else if (params->codec_name == "VP8") { | 703 } else if (params->codec_name == "VP8") { |
| 689 config->codec = media::cast::CODEC_VIDEO_VP8; | 704 config->codec = media::cast::CODEC_VIDEO_VP8; |
| 690 config->rtp_timebase = 90000; | 705 config->rtp_timebase = 90000; |
| 691 config->rtp_payload_type = media::cast::kDefaultRtpVideoPayloadType; | 706 config->rtp_payload_type = media::cast::RtpPayloadType::VIDEO_VP8; |
| 692 } else if (params->codec_name == "H264") { | 707 } else if (params->codec_name == "H264") { |
| 693 config->codec = media::cast::CODEC_VIDEO_H264; | 708 config->codec = media::cast::CODEC_VIDEO_H264; |
| 694 config->rtp_timebase = 90000; | 709 config->rtp_timebase = 90000; |
| 695 config->rtp_payload_type = media::cast::kDefaultRtpVideoPayloadType; | 710 config->rtp_payload_type = media::cast::RtpPayloadType::VIDEO_H264; |
| 711 } else { | |
| 712 isolate->ThrowException( | |
| 713 v8::Exception::Error(v8::String::NewFromUtf8(isolate, kInvalidCodec))); | |
| 714 return false; | |
| 696 } | 715 } |
| 697 if (params->rtp_timebase) { | 716 if (params->rtp_timebase) { |
| 698 config->rtp_timebase = *params->rtp_timebase; | 717 config->rtp_timebase = *params->rtp_timebase; |
| 699 if (config->rtp_timebase < 1000 || config->rtp_timebase > 1000000) { | 718 if (config->rtp_timebase < 1000 || config->rtp_timebase > 1000000) { |
| 700 isolate->ThrowException(v8::Exception::TypeError( | 719 isolate->ThrowException(v8::Exception::TypeError( |
| 701 v8::String::NewFromUtf8(isolate, kInvalidRtpTimebase))); | 720 v8::String::NewFromUtf8(isolate, kInvalidRtpTimebase))); |
| 702 return false; | 721 return false; |
| 703 } | 722 } |
| 704 } | 723 } |
| 705 if (params->aes_key && | 724 if (params->aes_key && |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 877 LOG(ERROR) << "Failed to add Cast audio track to media stream."; | 896 LOG(ERROR) << "Failed to add Cast audio track to media stream."; |
| 878 } | 897 } |
| 879 if (!content::AddVideoTrackToMediaStream(std::move(video), true, // is_remote | 898 if (!content::AddVideoTrackToMediaStream(std::move(video), true, // is_remote |
| 880 true, // is_readonly | 899 true, // is_readonly |
| 881 &web_stream)) { | 900 &web_stream)) { |
| 882 LOG(ERROR) << "Failed to add Cast video track to media stream."; | 901 LOG(ERROR) << "Failed to add Cast video track to media stream."; |
| 883 } | 902 } |
| 884 } | 903 } |
| 885 | 904 |
| 886 } // namespace extensions | 905 } // namespace extensions |
| OLD | NEW |