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 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 89 if (!base::HexStringToBytes(input, &bytes)) | 89 if (!base::HexStringToBytes(input, &bytes)) |
| 90 return false; | 90 return false; |
| 91 output->assign(reinterpret_cast<const char*>(&bytes[0]), bytes.size()); | 91 output->assign(reinterpret_cast<const char*>(&bytes[0]), bytes.size()); |
| 92 return true; | 92 return true; |
| 93 } | 93 } |
| 94 } // namespace | 94 } // namespace |
| 95 | 95 |
| 96 bool ToCastRtpPayloadParamsOrThrow(v8::Isolate* isolate, | 96 bool ToCastRtpPayloadParamsOrThrow(v8::Isolate* isolate, |
| 97 const RtpPayloadParams& ext_params, | 97 const RtpPayloadParams& ext_params, |
| 98 CastRtpPayloadParams* cast_params) { | 98 CastRtpPayloadParams* cast_params) { |
| 99 cast_params->payload_type = ext_params.payload_type; | |
| 100 cast_params->max_latency_ms = ext_params.max_latency; | 99 cast_params->max_latency_ms = ext_params.max_latency; |
| 101 cast_params->min_latency_ms = | 100 cast_params->min_latency_ms = |
| 102 ext_params.min_latency ? *ext_params.min_latency : ext_params.max_latency; | 101 ext_params.min_latency ? *ext_params.min_latency : ext_params.max_latency; |
| 103 cast_params->animated_latency_ms = ext_params.animated_latency | 102 cast_params->animated_latency_ms = ext_params.animated_latency |
| 104 ? *ext_params.animated_latency | 103 ? *ext_params.animated_latency |
| 105 : ext_params.max_latency; | 104 : ext_params.max_latency; |
| 106 cast_params->codec_name = ext_params.codec_name; | 105 cast_params->codec_name = ext_params.codec_name; |
| 106 if (cast_params->codec_name == "OPUS") { | |
| 107 cast_params->payload_type = media::cast::RtpPayloadType::AUDIO_OPUS; | |
| 108 } else if (cast_params->codec_name == "PCM16") { | |
| 109 cast_params->payload_type = media::cast::RtpPayloadType::AUDIO_PCM16; | |
| 110 } else if (cast_params->codec_name == "AAC") { | |
| 111 cast_params->payload_type = media::cast::RtpPayloadType::AUDIO_AAC; | |
| 112 } else if (cast_params->codec_name == "VP8") { | |
| 113 cast_params->payload_type = media::cast::RtpPayloadType::VIDEO_VP8; | |
| 114 } else if (cast_params->codec_name == "H264") { | |
| 115 cast_params->payload_type = media::cast::RtpPayloadType::VIDEO_H264; | |
| 116 } | |
|
miu
2016/06/23 23:19:03
nit: Please add a fail clause for an unrecognized
xjz
2016/06/24 01:22:44
Done.
| |
| 107 cast_params->ssrc = ext_params.ssrc; | 117 cast_params->ssrc = ext_params.ssrc; |
| 108 cast_params->feedback_ssrc = ext_params.feedback_ssrc; | 118 cast_params->feedback_ssrc = ext_params.feedback_ssrc; |
| 109 cast_params->clock_rate = ext_params.clock_rate ? *ext_params.clock_rate : 0; | 119 cast_params->clock_rate = ext_params.clock_rate ? *ext_params.clock_rate : 0; |
| 110 cast_params->min_bitrate = | 120 cast_params->min_bitrate = |
| 111 ext_params.min_bitrate ? *ext_params.min_bitrate : 0; | 121 ext_params.min_bitrate ? *ext_params.min_bitrate : 0; |
| 112 cast_params->max_bitrate = | 122 cast_params->max_bitrate = |
| 113 ext_params.max_bitrate ? *ext_params.max_bitrate : 0; | 123 ext_params.max_bitrate ? *ext_params.max_bitrate : 0; |
| 114 cast_params->channels = ext_params.channels ? *ext_params.channels : 0; | 124 cast_params->channels = ext_params.channels ? *ext_params.channels : 0; |
| 115 cast_params->max_frame_rate = | 125 cast_params->max_frame_rate = |
| 116 ext_params.max_frame_rate ? *ext_params.max_frame_rate : 0.0; | 126 ext_params.max_frame_rate ? *ext_params.max_frame_rate : 0.0; |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 130 CastCodecSpecificParams cast_codec_params; | 140 CastCodecSpecificParams cast_codec_params; |
| 131 ToCastCodecSpecificParams(ext_params.codec_specific_params[i], | 141 ToCastCodecSpecificParams(ext_params.codec_specific_params[i], |
| 132 &cast_codec_params); | 142 &cast_codec_params); |
| 133 cast_params->codec_specific_params.push_back(cast_codec_params); | 143 cast_params->codec_specific_params.push_back(cast_codec_params); |
| 134 } | 144 } |
| 135 return true; | 145 return true; |
| 136 } | 146 } |
| 137 | 147 |
| 138 void FromCastRtpPayloadParams(const CastRtpPayloadParams& cast_params, | 148 void FromCastRtpPayloadParams(const CastRtpPayloadParams& cast_params, |
| 139 RtpPayloadParams* ext_params) { | 149 RtpPayloadParams* ext_params) { |
| 140 ext_params->payload_type = cast_params.payload_type; | 150 ext_params->payload_type = static_cast<int>(cast_params.payload_type); |
|
miu
2016/06/23 23:19:03
Is the static_cast<> still needed if you add " : i
xjz
2016/06/24 01:22:44
Yes, static_cast<int> is still needed even if I ad
| |
| 141 ext_params->max_latency = cast_params.max_latency_ms; | 151 ext_params->max_latency = cast_params.max_latency_ms; |
| 142 ext_params->min_latency.reset(new int(cast_params.min_latency_ms)); | 152 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)); | 153 ext_params->animated_latency.reset(new int(cast_params.animated_latency_ms)); |
| 144 ext_params->codec_name = cast_params.codec_name; | 154 ext_params->codec_name = cast_params.codec_name; |
| 145 ext_params->ssrc = cast_params.ssrc; | 155 ext_params->ssrc = cast_params.ssrc; |
| 146 ext_params->feedback_ssrc = cast_params.feedback_ssrc; | 156 ext_params->feedback_ssrc = cast_params.feedback_ssrc; |
| 147 if (cast_params.clock_rate) | 157 if (cast_params.clock_rate) |
| 148 ext_params->clock_rate.reset(new int(cast_params.clock_rate)); | 158 ext_params->clock_rate.reset(new int(cast_params.clock_rate)); |
| 149 if (cast_params.min_bitrate) | 159 if (cast_params.min_bitrate) |
| 150 ext_params->min_bitrate.reset(new int(cast_params.min_bitrate)); | 160 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; | 679 config->rtp_max_delay_ms = params->max_latency; |
| 670 if (config->rtp_max_delay_ms < 0 || config->rtp_max_delay_ms > 1000) { | 680 if (config->rtp_max_delay_ms < 0 || config->rtp_max_delay_ms > 1000) { |
| 671 isolate->ThrowException(v8::Exception::TypeError( | 681 isolate->ThrowException(v8::Exception::TypeError( |
| 672 v8::String::NewFromUtf8(isolate, kInvalidLatency))); | 682 v8::String::NewFromUtf8(isolate, kInvalidLatency))); |
| 673 return false; | 683 return false; |
| 674 } | 684 } |
| 675 config->channels = 2; | 685 config->channels = 2; |
| 676 if (params->codec_name == "OPUS") { | 686 if (params->codec_name == "OPUS") { |
| 677 config->codec = media::cast::CODEC_AUDIO_OPUS; | 687 config->codec = media::cast::CODEC_AUDIO_OPUS; |
| 678 config->rtp_timebase = 48000; | 688 config->rtp_timebase = 48000; |
| 679 config->rtp_payload_type = media::cast::kDefaultRtpAudioPayloadType; | 689 config->rtp_payload_type = media::cast::RtpPayloadType::AUDIO_OPUS; |
| 680 } else if (params->codec_name == "PCM16") { | 690 } else if (params->codec_name == "PCM16") { |
| 681 config->codec = media::cast::CODEC_AUDIO_PCM16; | 691 config->codec = media::cast::CODEC_AUDIO_PCM16; |
| 682 config->rtp_timebase = 48000; | 692 config->rtp_timebase = 48000; |
| 683 config->rtp_payload_type = media::cast::kDefaultRtpAudioPayloadType; | 693 config->rtp_payload_type = media::cast::RtpPayloadType::AUDIO_PCM16; |
| 684 } else if (params->codec_name == "AAC") { | 694 } else if (params->codec_name == "AAC") { |
| 685 config->codec = media::cast::CODEC_AUDIO_AAC; | 695 config->codec = media::cast::CODEC_AUDIO_AAC; |
| 686 config->rtp_timebase = 48000; | 696 config->rtp_timebase = 48000; |
| 687 config->rtp_payload_type = media::cast::kDefaultRtpAudioPayloadType; | 697 config->rtp_payload_type = media::cast::RtpPayloadType::AUDIO_AAC; |
| 688 } else if (params->codec_name == "VP8") { | 698 } else if (params->codec_name == "VP8") { |
| 689 config->codec = media::cast::CODEC_VIDEO_VP8; | 699 config->codec = media::cast::CODEC_VIDEO_VP8; |
| 690 config->rtp_timebase = 90000; | 700 config->rtp_timebase = 90000; |
| 691 config->rtp_payload_type = media::cast::kDefaultRtpVideoPayloadType; | 701 config->rtp_payload_type = media::cast::RtpPayloadType::VIDEO_VP8; |
| 692 } else if (params->codec_name == "H264") { | 702 } else if (params->codec_name == "H264") { |
| 693 config->codec = media::cast::CODEC_VIDEO_H264; | 703 config->codec = media::cast::CODEC_VIDEO_H264; |
| 694 config->rtp_timebase = 90000; | 704 config->rtp_timebase = 90000; |
| 695 config->rtp_payload_type = media::cast::kDefaultRtpVideoPayloadType; | 705 config->rtp_payload_type = media::cast::RtpPayloadType::VIDEO_H264; |
| 696 } | 706 } |
|
miu
2016/06/23 23:19:03
ditto: Please add fail clause, like above.
xjz
2016/06/24 01:22:44
Done.
| |
| 697 if (params->rtp_timebase) { | 707 if (params->rtp_timebase) { |
| 698 config->rtp_timebase = *params->rtp_timebase; | 708 config->rtp_timebase = *params->rtp_timebase; |
| 699 if (config->rtp_timebase < 1000 || config->rtp_timebase > 1000000) { | 709 if (config->rtp_timebase < 1000 || config->rtp_timebase > 1000000) { |
| 700 isolate->ThrowException(v8::Exception::TypeError( | 710 isolate->ThrowException(v8::Exception::TypeError( |
| 701 v8::String::NewFromUtf8(isolate, kInvalidRtpTimebase))); | 711 v8::String::NewFromUtf8(isolate, kInvalidRtpTimebase))); |
| 702 return false; | 712 return false; |
| 703 } | 713 } |
| 704 } | 714 } |
| 705 if (params->aes_key && | 715 if (params->aes_key && |
| 706 !HexDecode(*params->aes_key, &config->aes_key)) { | 716 !HexDecode(*params->aes_key, &config->aes_key)) { |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 877 LOG(ERROR) << "Failed to add Cast audio track to media stream."; | 887 LOG(ERROR) << "Failed to add Cast audio track to media stream."; |
| 878 } | 888 } |
| 879 if (!content::AddVideoTrackToMediaStream(std::move(video), true, // is_remote | 889 if (!content::AddVideoTrackToMediaStream(std::move(video), true, // is_remote |
| 880 true, // is_readonly | 890 true, // is_readonly |
| 881 &web_stream)) { | 891 &web_stream)) { |
| 882 LOG(ERROR) << "Failed to add Cast video track to media stream."; | 892 LOG(ERROR) << "Failed to add Cast video track to media stream."; |
| 883 } | 893 } |
| 884 } | 894 } |
| 885 | 895 |
| 886 } // namespace extensions | 896 } // namespace extensions |
| OLD | NEW |