pbos@webrtc.org | dc8c883 | 2013-05-16 12:08:03 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license |
| 5 | * that can be found in the LICENSE file in the root of the source |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
| 10 | |
pbos@webrtc.org | b581c90 | 2013-10-28 16:32:01 +0000 | [diff] [blame] | 11 | #include "webrtc/video/video_send_stream.h" |
pbos@webrtc.org | dc8c883 | 2013-05-16 12:08:03 +0000 | [diff] [blame] | 12 | |
henrik.lundin@webrtc.org | ce21c82 | 2013-10-23 11:04:57 +0000 | [diff] [blame] | 13 | #include <string> |
pbos@webrtc.org | dc8c883 | 2013-05-16 12:08:03 +0000 | [diff] [blame] | 14 | #include <vector> |
| 15 | |
| 16 | #include "webrtc/common_video/libyuv/include/webrtc_libyuv.h" |
| 17 | #include "webrtc/video_engine/include/vie_base.h" |
| 18 | #include "webrtc/video_engine/include/vie_capture.h" |
| 19 | #include "webrtc/video_engine/include/vie_codec.h" |
stefan@webrtc.org | a0a91d8 | 2013-08-22 09:29:56 +0000 | [diff] [blame] | 20 | #include "webrtc/video_engine/include/vie_external_codec.h" |
pbos@webrtc.org | 3ba57eb | 2013-10-21 10:34:43 +0000 | [diff] [blame] | 21 | #include "webrtc/video_engine/include/vie_image_process.h" |
pbos@webrtc.org | dc8c883 | 2013-05-16 12:08:03 +0000 | [diff] [blame] | 22 | #include "webrtc/video_engine/include/vie_network.h" |
| 23 | #include "webrtc/video_engine/include/vie_rtp_rtcp.h" |
pbos@webrtc.org | f39df52 | 2014-03-19 08:43:57 +0000 | [diff] [blame] | 24 | #include "webrtc/video_engine/vie_defines.h" |
pbos@webrtc.org | b581c90 | 2013-10-28 16:32:01 +0000 | [diff] [blame] | 25 | #include "webrtc/video_send_stream.h" |
pbos@webrtc.org | dc8c883 | 2013-05-16 12:08:03 +0000 | [diff] [blame] | 26 | |
| 27 | namespace webrtc { |
| 28 | namespace internal { |
| 29 | |
pbos@webrtc.org | 12d5ede | 2013-07-09 08:02:33 +0000 | [diff] [blame] | 30 | VideoSendStream::VideoSendStream(newapi::Transport* transport, |
asapersson@webrtc.org | 4b1817f | 2014-01-31 10:05:07 +0000 | [diff] [blame] | 31 | CpuOveruseObserver* overuse_observer, |
pbos@webrtc.org | 12d5ede | 2013-07-09 08:02:33 +0000 | [diff] [blame] | 32 | webrtc::VideoEngine* video_engine, |
mflodman@webrtc.org | e4d538a | 2013-12-13 09:40:45 +0000 | [diff] [blame] | 33 | const VideoSendStream::Config& config, |
| 34 | int base_channel) |
pbos@webrtc.org | 8f2997c | 2013-11-14 08:58:14 +0000 | [diff] [blame] | 35 | : transport_adapter_(transport), |
sprang@webrtc.org | 4a9843f | 2013-11-26 11:41:59 +0000 | [diff] [blame] | 36 | encoded_frame_proxy_(config.post_encode_callback), |
pbos@webrtc.org | 8f2997c | 2013-11-14 08:58:14 +0000 | [diff] [blame] | 37 | codec_lock_(CriticalSectionWrapper::CreateCriticalSection()), |
| 38 | config_(config), |
mflodman@webrtc.org | e4d538a | 2013-12-13 09:40:45 +0000 | [diff] [blame] | 39 | external_codec_(NULL), |
pbos@webrtc.org | c54ff69 | 2014-04-28 13:00:21 +0000 | [diff] [blame^] | 40 | channel_(-1), |
| 41 | stats_proxy_(new SendStatisticsProxy(config, this)) { |
pbos@webrtc.org | dc8c883 | 2013-05-16 12:08:03 +0000 | [diff] [blame] | 42 | video_engine_base_ = ViEBase::GetInterface(video_engine); |
mflodman@webrtc.org | e4d538a | 2013-12-13 09:40:45 +0000 | [diff] [blame] | 43 | video_engine_base_->CreateChannel(channel_, base_channel); |
pbos@webrtc.org | dc8c883 | 2013-05-16 12:08:03 +0000 | [diff] [blame] | 44 | assert(channel_ != -1); |
| 45 | |
| 46 | rtp_rtcp_ = ViERTP_RTCP::GetInterface(video_engine); |
| 47 | assert(rtp_rtcp_ != NULL); |
| 48 | |
pbos@webrtc.org | 8f2997c | 2013-11-14 08:58:14 +0000 | [diff] [blame] | 49 | assert(config_.rtp.ssrcs.size() > 0); |
henrik.lundin@webrtc.org | d7d60c8 | 2013-11-21 14:05:40 +0000 | [diff] [blame] | 50 | if (config_.suspend_below_min_bitrate) |
| 51 | config_.pacing = true; |
stefan@webrtc.org | a0a91d8 | 2013-08-22 09:29:56 +0000 | [diff] [blame] | 52 | rtp_rtcp_->SetTransmissionSmoothingStatus(channel_, config_.pacing); |
pbos@webrtc.org | 905cebd | 2013-09-11 10:14:56 +0000 | [diff] [blame] | 53 | |
pbos@webrtc.org | bef6e62 | 2014-03-19 10:59:52 +0000 | [diff] [blame] | 54 | assert(config_.rtp.min_transmit_bitrate_bps >= 0); |
pbos@webrtc.org | 9420a1f | 2014-03-13 12:52:27 +0000 | [diff] [blame] | 55 | rtp_rtcp_->SetMinTransmitBitrate(channel_, |
pbos@webrtc.org | bef6e62 | 2014-03-19 10:59:52 +0000 | [diff] [blame] | 56 | config_.rtp.min_transmit_bitrate_bps / 1000); |
pbos@webrtc.org | 9420a1f | 2014-03-13 12:52:27 +0000 | [diff] [blame] | 57 | |
pbos@webrtc.org | 905cebd | 2013-09-11 10:14:56 +0000 | [diff] [blame] | 58 | for (size_t i = 0; i < config_.rtp.extensions.size(); ++i) { |
| 59 | const std::string& extension = config_.rtp.extensions[i].name; |
| 60 | int id = config_.rtp.extensions[i].id; |
pbos@webrtc.org | 60108c2 | 2013-11-20 11:48:56 +0000 | [diff] [blame] | 61 | if (extension == RtpExtension::kTOffset) { |
pbos@webrtc.org | 905cebd | 2013-09-11 10:14:56 +0000 | [diff] [blame] | 62 | if (rtp_rtcp_->SetSendTimestampOffsetStatus(channel_, true, id) != 0) |
| 63 | abort(); |
pbos@webrtc.org | 60108c2 | 2013-11-20 11:48:56 +0000 | [diff] [blame] | 64 | } else if (extension == RtpExtension::kAbsSendTime) { |
pbos@webrtc.org | e22b761 | 2013-09-11 19:00:39 +0000 | [diff] [blame] | 65 | if (rtp_rtcp_->SetSendAbsoluteSendTimeStatus(channel_, true, id) != 0) |
| 66 | abort(); |
pbos@webrtc.org | 905cebd | 2013-09-11 10:14:56 +0000 | [diff] [blame] | 67 | } else { |
| 68 | abort(); // Unsupported extension. |
| 69 | } |
| 70 | } |
pbos@webrtc.org | dc8c883 | 2013-05-16 12:08:03 +0000 | [diff] [blame] | 71 | |
mflodman@webrtc.org | ab6ccbc | 2013-12-13 16:36:28 +0000 | [diff] [blame] | 72 | rtp_rtcp_->SetRembStatus(channel_, true, false); |
| 73 | |
pbos@webrtc.org | aa693dd | 2013-09-20 11:56:26 +0000 | [diff] [blame] | 74 | // Enable NACK, FEC or both. |
| 75 | if (config_.rtp.fec.red_payload_type != -1) { |
| 76 | assert(config_.rtp.fec.ulpfec_payload_type != -1); |
| 77 | if (config_.rtp.nack.rtp_history_ms > 0) { |
| 78 | rtp_rtcp_->SetHybridNACKFECStatus( |
| 79 | channel_, |
| 80 | true, |
| 81 | static_cast<unsigned char>(config_.rtp.fec.red_payload_type), |
| 82 | static_cast<unsigned char>(config_.rtp.fec.ulpfec_payload_type)); |
| 83 | } else { |
| 84 | rtp_rtcp_->SetFECStatus( |
| 85 | channel_, |
| 86 | true, |
| 87 | static_cast<unsigned char>(config_.rtp.fec.red_payload_type), |
| 88 | static_cast<unsigned char>(config_.rtp.fec.ulpfec_payload_type)); |
| 89 | } |
| 90 | } else { |
| 91 | rtp_rtcp_->SetNACKStatus(channel_, config_.rtp.nack.rtp_history_ms > 0); |
| 92 | } |
| 93 | |
pbos@webrtc.org | debc672 | 2013-08-22 09:42:17 +0000 | [diff] [blame] | 94 | char rtcp_cname[ViERTP_RTCP::KMaxRTCPCNameLength]; |
| 95 | assert(config_.rtp.c_name.length() < ViERTP_RTCP::KMaxRTCPCNameLength); |
| 96 | strncpy(rtcp_cname, config_.rtp.c_name.c_str(), sizeof(rtcp_cname) - 1); |
| 97 | rtcp_cname[sizeof(rtcp_cname) - 1] = '\0'; |
| 98 | |
| 99 | rtp_rtcp_->SetRTCPCName(channel_, rtcp_cname); |
| 100 | |
pbos@webrtc.org | dc8c883 | 2013-05-16 12:08:03 +0000 | [diff] [blame] | 101 | capture_ = ViECapture::GetInterface(video_engine); |
| 102 | capture_->AllocateExternalCaptureDevice(capture_id_, external_capture_); |
| 103 | capture_->ConnectCaptureDevice(capture_id_, channel_); |
| 104 | |
| 105 | network_ = ViENetwork::GetInterface(video_engine); |
| 106 | assert(network_ != NULL); |
| 107 | |
pbos@webrtc.org | 26d75f3 | 2013-09-18 11:52:42 +0000 | [diff] [blame] | 108 | network_->RegisterSendTransport(channel_, transport_adapter_); |
sprang@webrtc.org | 6133dd5 | 2013-10-16 13:29:14 +0000 | [diff] [blame] | 109 | // 28 to match packet overhead in ModuleRtpRtcpImpl. |
pbos@webrtc.org | b581c90 | 2013-10-28 16:32:01 +0000 | [diff] [blame] | 110 | network_->SetMTU(channel_, |
| 111 | static_cast<unsigned int>(config_.rtp.max_packet_size + 28)); |
pbos@webrtc.org | dc8c883 | 2013-05-16 12:08:03 +0000 | [diff] [blame] | 112 | |
pbos@webrtc.org | f39df52 | 2014-03-19 08:43:57 +0000 | [diff] [blame] | 113 | assert(config.encoder_settings.encoder != NULL); |
| 114 | assert(config.encoder_settings.payload_type >= 0); |
| 115 | assert(config.encoder_settings.payload_type <= 127); |
| 116 | external_codec_ = ViEExternalCodec::GetInterface(video_engine); |
| 117 | if (external_codec_->RegisterExternalSendCodec( |
| 118 | channel_, |
| 119 | config.encoder_settings.payload_type, |
| 120 | config.encoder_settings.encoder, |
| 121 | false) != 0) { |
| 122 | abort(); |
stefan@webrtc.org | a0a91d8 | 2013-08-22 09:29:56 +0000 | [diff] [blame] | 123 | } |
| 124 | |
pbos@webrtc.org | dc8c883 | 2013-05-16 12:08:03 +0000 | [diff] [blame] | 125 | codec_ = ViECodec::GetInterface(video_engine); |
pbos@webrtc.org | f39df52 | 2014-03-19 08:43:57 +0000 | [diff] [blame] | 126 | if (!ReconfigureVideoEncoder(config_.encoder_settings.streams, |
| 127 | config_.encoder_settings.encoder_settings)) { |
pbos@webrtc.org | dc8c883 | 2013-05-16 12:08:03 +0000 | [diff] [blame] | 128 | abort(); |
mflodman@webrtc.org | ecbeb2b | 2013-07-23 11:35:00 +0000 | [diff] [blame] | 129 | } |
pbos@webrtc.org | 3ba57eb | 2013-10-21 10:34:43 +0000 | [diff] [blame] | 130 | |
pbos@webrtc.org | f39df52 | 2014-03-19 08:43:57 +0000 | [diff] [blame] | 131 | if (overuse_observer) |
| 132 | video_engine_base_->RegisterCpuOveruseObserver(channel_, overuse_observer); |
| 133 | |
pbos@webrtc.org | 3ba57eb | 2013-10-21 10:34:43 +0000 | [diff] [blame] | 134 | image_process_ = ViEImageProcess::GetInterface(video_engine); |
| 135 | image_process_->RegisterPreEncodeCallback(channel_, |
| 136 | config_.pre_encode_callback); |
sprang@webrtc.org | 4a9843f | 2013-11-26 11:41:59 +0000 | [diff] [blame] | 137 | if (config_.post_encode_callback) { |
| 138 | image_process_->RegisterPostEncodeImageCallback(channel_, |
| 139 | &encoded_frame_proxy_); |
| 140 | } |
henrik.lundin@webrtc.org | ce21c82 | 2013-10-23 11:04:57 +0000 | [diff] [blame] | 141 | |
henrik.lundin@webrtc.org | 0bf5a2f | 2014-03-06 07:19:28 +0000 | [diff] [blame] | 142 | if (config_.suspend_below_min_bitrate) { |
henrik.lundin@webrtc.org | 8fdf191 | 2013-11-18 12:18:43 +0000 | [diff] [blame] | 143 | codec_->SuspendBelowMinBitrate(channel_); |
henrik.lundin@webrtc.org | ce21c82 | 2013-10-23 11:04:57 +0000 | [diff] [blame] | 144 | } |
sprang@webrtc.org | ca72300 | 2014-01-07 09:54:34 +0000 | [diff] [blame] | 145 | |
sprang@webrtc.org | ca72300 | 2014-01-07 09:54:34 +0000 | [diff] [blame] | 146 | rtp_rtcp_->RegisterSendChannelRtcpStatisticsCallback(channel_, |
| 147 | stats_proxy_.get()); |
| 148 | rtp_rtcp_->RegisterSendChannelRtpStatisticsCallback(channel_, |
| 149 | stats_proxy_.get()); |
| 150 | rtp_rtcp_->RegisterSendBitrateObserver(channel_, stats_proxy_.get()); |
| 151 | rtp_rtcp_->RegisterSendFrameCountObserver(channel_, stats_proxy_.get()); |
| 152 | |
| 153 | codec_->RegisterEncoderObserver(channel_, *stats_proxy_); |
| 154 | capture_->RegisterObserver(capture_id_, *stats_proxy_); |
pbos@webrtc.org | dc8c883 | 2013-05-16 12:08:03 +0000 | [diff] [blame] | 155 | } |
| 156 | |
| 157 | VideoSendStream::~VideoSendStream() { |
sprang@webrtc.org | ca72300 | 2014-01-07 09:54:34 +0000 | [diff] [blame] | 158 | capture_->DeregisterObserver(capture_id_); |
| 159 | codec_->DeregisterEncoderObserver(channel_); |
| 160 | |
| 161 | rtp_rtcp_->DeregisterSendFrameCountObserver(channel_, stats_proxy_.get()); |
| 162 | rtp_rtcp_->DeregisterSendBitrateObserver(channel_, stats_proxy_.get()); |
| 163 | rtp_rtcp_->DeregisterSendChannelRtpStatisticsCallback(channel_, |
| 164 | stats_proxy_.get()); |
| 165 | rtp_rtcp_->DeregisterSendChannelRtcpStatisticsCallback(channel_, |
| 166 | stats_proxy_.get()); |
| 167 | |
pbos@webrtc.org | 3ba57eb | 2013-10-21 10:34:43 +0000 | [diff] [blame] | 168 | image_process_->DeRegisterPreEncodeCallback(channel_); |
| 169 | |
pbos@webrtc.org | dc8c883 | 2013-05-16 12:08:03 +0000 | [diff] [blame] | 170 | network_->DeregisterSendTransport(channel_); |
pbos@webrtc.org | dc8c883 | 2013-05-16 12:08:03 +0000 | [diff] [blame] | 171 | |
| 172 | capture_->DisconnectCaptureDevice(channel_); |
| 173 | capture_->ReleaseCaptureDevice(capture_id_); |
| 174 | |
pbos@webrtc.org | f39df52 | 2014-03-19 08:43:57 +0000 | [diff] [blame] | 175 | external_codec_->DeRegisterExternalSendCodec( |
| 176 | channel_, config_.encoder_settings.payload_type); |
stefan@webrtc.org | a0a91d8 | 2013-08-22 09:29:56 +0000 | [diff] [blame] | 177 | |
pbos@webrtc.org | 3ba57eb | 2013-10-21 10:34:43 +0000 | [diff] [blame] | 178 | video_engine_base_->DeleteChannel(channel_); |
| 179 | |
| 180 | image_process_->Release(); |
pbos@webrtc.org | dc8c883 | 2013-05-16 12:08:03 +0000 | [diff] [blame] | 181 | video_engine_base_->Release(); |
| 182 | capture_->Release(); |
| 183 | codec_->Release(); |
stefan@webrtc.org | a0a91d8 | 2013-08-22 09:29:56 +0000 | [diff] [blame] | 184 | if (external_codec_) |
| 185 | external_codec_->Release(); |
pbos@webrtc.org | dc8c883 | 2013-05-16 12:08:03 +0000 | [diff] [blame] | 186 | network_->Release(); |
| 187 | rtp_rtcp_->Release(); |
| 188 | } |
| 189 | |
pbos@webrtc.org | 7123a80 | 2013-12-11 16:26:16 +0000 | [diff] [blame] | 190 | void VideoSendStream::PutFrame(const I420VideoFrame& frame) { |
| 191 | input_frame_.CopyFrame(frame); |
| 192 | SwapFrame(&input_frame_); |
| 193 | } |
pbos@webrtc.org | dc8c883 | 2013-05-16 12:08:03 +0000 | [diff] [blame] | 194 | |
pbos@webrtc.org | 7123a80 | 2013-12-11 16:26:16 +0000 | [diff] [blame] | 195 | void VideoSendStream::SwapFrame(I420VideoFrame* frame) { |
| 196 | // TODO(pbos): Warn if frame is "too far" into the future, or too old. This |
| 197 | // would help detect if frame's being used without NTP. |
| 198 | // TO REVIEWER: Is there any good check for this? Should it be |
| 199 | // skipped? |
| 200 | if (frame != &input_frame_) |
| 201 | input_frame_.SwapFrame(frame); |
pbos@webrtc.org | dc8c883 | 2013-05-16 12:08:03 +0000 | [diff] [blame] | 202 | |
pbos@webrtc.org | 7123a80 | 2013-12-11 16:26:16 +0000 | [diff] [blame] | 203 | // TODO(pbos): Local rendering should not be done on the capture thread. |
| 204 | if (config_.local_renderer != NULL) |
| 205 | config_.local_renderer->RenderFrame(input_frame_, 0); |
pbos@webrtc.org | dc8c883 | 2013-05-16 12:08:03 +0000 | [diff] [blame] | 206 | |
pbos@webrtc.org | 7123a80 | 2013-12-11 16:26:16 +0000 | [diff] [blame] | 207 | external_capture_->SwapFrame(&input_frame_); |
pbos@webrtc.org | dc8c883 | 2013-05-16 12:08:03 +0000 | [diff] [blame] | 208 | } |
| 209 | |
pbos@webrtc.org | d8e92c9 | 2013-08-23 09:19:30 +0000 | [diff] [blame] | 210 | VideoSendStreamInput* VideoSendStream::Input() { return this; } |
pbos@webrtc.org | dc8c883 | 2013-05-16 12:08:03 +0000 | [diff] [blame] | 211 | |
pbos@webrtc.org | 9d0f79f | 2014-04-24 11:13:21 +0000 | [diff] [blame] | 212 | void VideoSendStream::Start() { |
sprang@webrtc.org | 48ac0da | 2014-01-27 13:03:02 +0000 | [diff] [blame] | 213 | transport_adapter_.Enable(); |
pbos@webrtc.org | df9f099 | 2014-01-10 18:47:32 +0000 | [diff] [blame] | 214 | video_engine_base_->StartSend(channel_); |
| 215 | video_engine_base_->StartReceive(channel_); |
pbos@webrtc.org | dc8c883 | 2013-05-16 12:08:03 +0000 | [diff] [blame] | 216 | } |
| 217 | |
pbos@webrtc.org | 9d0f79f | 2014-04-24 11:13:21 +0000 | [diff] [blame] | 218 | void VideoSendStream::Stop() { |
pbos@webrtc.org | df9f099 | 2014-01-10 18:47:32 +0000 | [diff] [blame] | 219 | video_engine_base_->StopSend(channel_); |
| 220 | video_engine_base_->StopReceive(channel_); |
sprang@webrtc.org | 48ac0da | 2014-01-27 13:03:02 +0000 | [diff] [blame] | 221 | transport_adapter_.Disable(); |
pbos@webrtc.org | dc8c883 | 2013-05-16 12:08:03 +0000 | [diff] [blame] | 222 | } |
| 223 | |
pbos@webrtc.org | f39df52 | 2014-03-19 08:43:57 +0000 | [diff] [blame] | 224 | bool VideoSendStream::ReconfigureVideoEncoder( |
| 225 | const std::vector<VideoStream>& streams, |
| 226 | void* encoder_settings) { |
| 227 | assert(!streams.empty()); |
| 228 | assert(config_.rtp.ssrcs.size() >= streams.size()); |
| 229 | // TODO(pbos): Wire encoder_settings. |
| 230 | assert(encoder_settings == NULL); |
pbos@webrtc.org | 8f2997c | 2013-11-14 08:58:14 +0000 | [diff] [blame] | 231 | |
pbos@webrtc.org | f39df52 | 2014-03-19 08:43:57 +0000 | [diff] [blame] | 232 | // VideoStreams in config_.encoder_settings need to be locked. |
pbos@webrtc.org | 8f2997c | 2013-11-14 08:58:14 +0000 | [diff] [blame] | 233 | CriticalSectionScoped crit(codec_lock_.get()); |
pbos@webrtc.org | f39df52 | 2014-03-19 08:43:57 +0000 | [diff] [blame] | 234 | |
| 235 | VideoCodec video_codec; |
| 236 | memset(&video_codec, 0, sizeof(video_codec)); |
| 237 | video_codec.codecType = |
| 238 | (config_.encoder_settings.payload_name == "VP8" ? kVideoCodecVP8 |
| 239 | : kVideoCodecGeneric); |
| 240 | |
| 241 | if (video_codec.codecType == kVideoCodecVP8) { |
| 242 | video_codec.codecSpecific.VP8.resilience = kResilientStream; |
| 243 | video_codec.codecSpecific.VP8.numberOfTemporalLayers = 1; |
| 244 | video_codec.codecSpecific.VP8.denoisingOn = true; |
| 245 | video_codec.codecSpecific.VP8.errorConcealmentOn = false; |
| 246 | video_codec.codecSpecific.VP8.automaticResizeOn = false; |
| 247 | video_codec.codecSpecific.VP8.frameDroppingOn = true; |
| 248 | video_codec.codecSpecific.VP8.keyFrameInterval = 3000; |
| 249 | } |
| 250 | |
| 251 | strncpy(video_codec.plName, |
| 252 | config_.encoder_settings.payload_name.c_str(), |
| 253 | kPayloadNameSize - 1); |
| 254 | video_codec.plName[kPayloadNameSize - 1] = '\0'; |
| 255 | video_codec.plType = config_.encoder_settings.payload_type; |
| 256 | video_codec.numberOfSimulcastStreams = |
| 257 | static_cast<unsigned char>(streams.size()); |
| 258 | video_codec.minBitrate = streams[0].min_bitrate_bps / 1000; |
| 259 | assert(streams.size() <= kMaxSimulcastStreams); |
| 260 | for (size_t i = 0; i < streams.size(); ++i) { |
| 261 | SimulcastStream* sim_stream = &video_codec.simulcastStream[i]; |
| 262 | assert(streams[i].width > 0); |
| 263 | assert(streams[i].height > 0); |
| 264 | assert(streams[i].max_framerate > 0); |
| 265 | // Different framerates not supported per stream at the moment. |
| 266 | assert(streams[i].max_framerate == streams[0].max_framerate); |
| 267 | assert(streams[i].min_bitrate_bps >= 0); |
| 268 | assert(streams[i].target_bitrate_bps >= streams[i].min_bitrate_bps); |
| 269 | assert(streams[i].max_bitrate_bps >= streams[i].target_bitrate_bps); |
| 270 | assert(streams[i].max_qp >= 0); |
| 271 | |
| 272 | sim_stream->width = static_cast<unsigned short>(streams[i].width); |
| 273 | sim_stream->height = static_cast<unsigned short>(streams[i].height); |
| 274 | sim_stream->minBitrate = streams[i].min_bitrate_bps / 1000; |
| 275 | sim_stream->targetBitrate = streams[i].target_bitrate_bps / 1000; |
| 276 | sim_stream->maxBitrate = streams[i].max_bitrate_bps / 1000; |
| 277 | sim_stream->qpMax = streams[i].max_qp; |
| 278 | // TODO(pbos): Implement mapping for temporal layers. |
| 279 | assert(streams[i].temporal_layers.empty()); |
| 280 | |
| 281 | video_codec.width = std::max(video_codec.width, |
| 282 | static_cast<unsigned short>(streams[i].width)); |
| 283 | video_codec.height = std::max( |
| 284 | video_codec.height, static_cast<unsigned short>(streams[i].height)); |
| 285 | video_codec.minBitrate = |
| 286 | std::min(video_codec.minBitrate, |
| 287 | static_cast<unsigned int>(streams[i].min_bitrate_bps / 1000)); |
| 288 | video_codec.maxBitrate += streams[i].max_bitrate_bps / 1000; |
| 289 | video_codec.qpMax = std::max(video_codec.qpMax, |
| 290 | static_cast<unsigned int>(streams[i].max_qp)); |
| 291 | } |
| 292 | |
| 293 | if (video_codec.minBitrate < kViEMinCodecBitrate) |
| 294 | video_codec.minBitrate = kViEMinCodecBitrate; |
| 295 | if (video_codec.maxBitrate < kViEMinCodecBitrate) |
| 296 | video_codec.maxBitrate = kViEMinCodecBitrate; |
| 297 | |
| 298 | video_codec.startBitrate = 300; |
| 299 | |
| 300 | if (video_codec.startBitrate < video_codec.minBitrate) |
| 301 | video_codec.startBitrate = video_codec.minBitrate; |
| 302 | if (video_codec.startBitrate > video_codec.maxBitrate) |
| 303 | video_codec.startBitrate = video_codec.maxBitrate; |
| 304 | |
| 305 | assert(config_.encoder_settings.streams[0].max_framerate > 0); |
| 306 | video_codec.maxFramerate = config_.encoder_settings.streams[0].max_framerate; |
| 307 | |
| 308 | if (codec_->SetSendCodec(channel_, video_codec) != 0) |
pbos@webrtc.org | 8f2997c | 2013-11-14 08:58:14 +0000 | [diff] [blame] | 309 | return false; |
| 310 | |
pbos@webrtc.org | 9105cbd | 2013-11-28 11:59:31 +0000 | [diff] [blame] | 311 | for (size_t i = 0; i < config_.rtp.ssrcs.size(); ++i) { |
| 312 | rtp_rtcp_->SetLocalSSRC(channel_, |
| 313 | config_.rtp.ssrcs[i], |
| 314 | kViEStreamTypeNormal, |
| 315 | static_cast<unsigned char>(i)); |
| 316 | } |
| 317 | |
pbos@webrtc.org | f39df52 | 2014-03-19 08:43:57 +0000 | [diff] [blame] | 318 | config_.encoder_settings.streams = streams; |
| 319 | config_.encoder_settings.encoder_settings = encoder_settings; |
pbos@webrtc.org | c766775 | 2014-01-24 09:30:53 +0000 | [diff] [blame] | 320 | |
pbos@webrtc.org | 9105cbd | 2013-11-28 11:59:31 +0000 | [diff] [blame] | 321 | if (config_.rtp.rtx.ssrcs.empty()) |
| 322 | return true; |
| 323 | |
| 324 | // Set up RTX. |
| 325 | assert(config_.rtp.rtx.ssrcs.size() == config_.rtp.ssrcs.size()); |
| 326 | for (size_t i = 0; i < config_.rtp.ssrcs.size(); ++i) { |
| 327 | rtp_rtcp_->SetLocalSSRC(channel_, |
| 328 | config_.rtp.rtx.ssrcs[i], |
| 329 | kViEStreamTypeRtx, |
| 330 | static_cast<unsigned char>(i)); |
| 331 | } |
| 332 | |
pbos@webrtc.org | c766775 | 2014-01-24 09:30:53 +0000 | [diff] [blame] | 333 | if (config_.rtp.rtx.payload_type != 0) |
| 334 | rtp_rtcp_->SetRtxSendPayloadType(channel_, config_.rtp.rtx.payload_type); |
pbos@webrtc.org | 9105cbd | 2013-11-28 11:59:31 +0000 | [diff] [blame] | 335 | |
pbos@webrtc.org | 8f2997c | 2013-11-14 08:58:14 +0000 | [diff] [blame] | 336 | return true; |
pbos@webrtc.org | dc8c883 | 2013-05-16 12:08:03 +0000 | [diff] [blame] | 337 | } |
| 338 | |
pbos@webrtc.org | bf9bc32 | 2013-08-05 12:01:36 +0000 | [diff] [blame] | 339 | bool VideoSendStream::DeliverRtcp(const uint8_t* packet, size_t length) { |
| 340 | return network_->ReceivedRTCPPacket( |
pbos@webrtc.org | 30c741a | 2013-08-05 13:25:51 +0000 | [diff] [blame] | 341 | channel_, packet, static_cast<int>(length)) == 0; |
pbos@webrtc.org | bf9bc32 | 2013-08-05 12:01:36 +0000 | [diff] [blame] | 342 | } |
sprang@webrtc.org | ca72300 | 2014-01-07 09:54:34 +0000 | [diff] [blame] | 343 | |
| 344 | VideoSendStream::Stats VideoSendStream::GetStats() const { |
| 345 | return stats_proxy_->GetStats(); |
| 346 | } |
| 347 | |
| 348 | bool VideoSendStream::GetSendSideDelay(VideoSendStream::Stats* stats) { |
| 349 | return codec_->GetSendSideDelay( |
| 350 | channel_, &stats->avg_delay_ms, &stats->max_delay_ms); |
| 351 | } |
| 352 | |
| 353 | std::string VideoSendStream::GetCName() { |
| 354 | char rtcp_cname[ViERTP_RTCP::KMaxRTCPCNameLength]; |
| 355 | rtp_rtcp_->GetRTCPCName(channel_, rtcp_cname); |
| 356 | return rtcp_cname; |
| 357 | } |
| 358 | |
pbos@webrtc.org | dc8c883 | 2013-05-16 12:08:03 +0000 | [diff] [blame] | 359 | } // namespace internal |
| 360 | } // namespace webrtc |