OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
(...skipping 25 matching lines...) Expand all Loading... |
36 frame_dropper_enabled_(true), | 36 frame_dropper_enabled_(true), |
37 _sendStatsTimer(1000, clock_), | 37 _sendStatsTimer(1000, clock_), |
38 current_codec_(), | 38 current_codec_(), |
39 encoder_params_({0, 0, 0, 0}), | 39 encoder_params_({0, 0, 0, 0}), |
40 encoder_has_internal_source_(false), | 40 encoder_has_internal_source_(false), |
41 next_frame_types_(1, kVideoFrameDelta) { | 41 next_frame_types_(1, kVideoFrameDelta) { |
42 _mediaOpt.Reset(); | 42 _mediaOpt.Reset(); |
43 // Allow VideoSender to be created on one thread but used on another, post | 43 // Allow VideoSender to be created on one thread but used on another, post |
44 // construction. This is currently how this class is being used by at least | 44 // construction. This is currently how this class is being used by at least |
45 // one external project (diffractor). | 45 // one external project (diffractor). |
46 sequenced_checker_.Detach(); | 46 main_thread_.DetachFromThread(); |
47 } | 47 } |
48 | 48 |
49 VideoSender::~VideoSender() {} | 49 VideoSender::~VideoSender() {} |
50 | 50 |
51 void VideoSender::Process() { | 51 void VideoSender::Process() { |
52 if (_sendStatsTimer.TimeUntilProcess() == 0) { | 52 if (_sendStatsTimer.TimeUntilProcess() == 0) { |
53 // |_sendStatsTimer.Processed()| must be called. Otherwise | 53 // |_sendStatsTimer.Processed()| must be called. Otherwise |
54 // VideoSender::Process() will be called in an infinite loop. | 54 // VideoSender::Process() will be called in an infinite loop. |
55 _sendStatsTimer.Processed(); | 55 _sendStatsTimer.Processed(); |
56 if (send_stats_callback_) { | 56 if (send_stats_callback_) { |
(...skipping 18 matching lines...) Expand all Loading... |
75 } | 75 } |
76 | 76 |
77 int64_t VideoSender::TimeUntilNextProcess() { | 77 int64_t VideoSender::TimeUntilNextProcess() { |
78 return _sendStatsTimer.TimeUntilProcess(); | 78 return _sendStatsTimer.TimeUntilProcess(); |
79 } | 79 } |
80 | 80 |
81 // Register the send codec to be used. | 81 // Register the send codec to be used. |
82 int32_t VideoSender::RegisterSendCodec(const VideoCodec* sendCodec, | 82 int32_t VideoSender::RegisterSendCodec(const VideoCodec* sendCodec, |
83 uint32_t numberOfCores, | 83 uint32_t numberOfCores, |
84 uint32_t maxPayloadSize) { | 84 uint32_t maxPayloadSize) { |
85 RTC_DCHECK(sequenced_checker_.CalledSequentially()); | 85 RTC_DCHECK(main_thread_.CalledOnValidThread()); |
86 rtc::CritScope lock(&encoder_crit_); | 86 rtc::CritScope lock(&encoder_crit_); |
87 if (sendCodec == nullptr) { | 87 if (sendCodec == nullptr) { |
88 return VCM_PARAMETER_ERROR; | 88 return VCM_PARAMETER_ERROR; |
89 } | 89 } |
90 | 90 |
91 bool ret = | 91 bool ret = |
92 _codecDataBase.SetSendCodec(sendCodec, numberOfCores, maxPayloadSize); | 92 _codecDataBase.SetSendCodec(sendCodec, numberOfCores, maxPayloadSize); |
93 | 93 |
94 // Update encoder regardless of result to make sure that we're not holding on | 94 // Update encoder regardless of result to make sure that we're not holding on |
95 // to a deleted instance. | 95 // to a deleted instance. |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
143 sendCodec->height, sendCodec->maxFramerate, | 143 sendCodec->height, sendCodec->maxFramerate, |
144 numLayers, maxPayloadSize); | 144 numLayers, maxPayloadSize); |
145 return VCM_OK; | 145 return VCM_OK; |
146 } | 146 } |
147 | 147 |
148 // Register an external decoder object. | 148 // Register an external decoder object. |
149 // This can not be used together with external decoder callbacks. | 149 // This can not be used together with external decoder callbacks. |
150 void VideoSender::RegisterExternalEncoder(VideoEncoder* externalEncoder, | 150 void VideoSender::RegisterExternalEncoder(VideoEncoder* externalEncoder, |
151 uint8_t payloadType, | 151 uint8_t payloadType, |
152 bool internalSource /*= false*/) { | 152 bool internalSource /*= false*/) { |
153 RTC_DCHECK(sequenced_checker_.CalledSequentially()); | 153 RTC_DCHECK(main_thread_.CalledOnValidThread()); |
154 | 154 |
155 rtc::CritScope lock(&encoder_crit_); | 155 rtc::CritScope lock(&encoder_crit_); |
156 | 156 |
157 if (externalEncoder == nullptr) { | 157 if (externalEncoder == nullptr) { |
158 bool wasSendCodec = false; | 158 bool wasSendCodec = false; |
159 RTC_CHECK( | 159 RTC_CHECK( |
160 _codecDataBase.DeregisterExternalEncoder(payloadType, &wasSendCodec)); | 160 _codecDataBase.DeregisterExternalEncoder(payloadType, &wasSendCodec)); |
161 if (wasSendCodec) { | 161 if (wasSendCodec) { |
162 // Make sure the VCM doesn't use the de-registered codec | 162 // Make sure the VCM doesn't use the de-registered codec |
163 rtc::CritScope params_lock(¶ms_crit_); | 163 rtc::CritScope params_lock(¶ms_crit_); |
164 _encoder = nullptr; | 164 _encoder = nullptr; |
165 encoder_has_internal_source_ = false; | 165 encoder_has_internal_source_ = false; |
166 } | 166 } |
167 return; | 167 return; |
168 } | 168 } |
169 _codecDataBase.RegisterExternalEncoder(externalEncoder, payloadType, | 169 _codecDataBase.RegisterExternalEncoder(externalEncoder, payloadType, |
170 internalSource); | 170 internalSource); |
171 } | 171 } |
172 | 172 |
173 // Get encode bitrate | 173 // Get encode bitrate |
174 int VideoSender::Bitrate(unsigned int* bitrate) const { | 174 int VideoSender::Bitrate(unsigned int* bitrate) const { |
175 RTC_DCHECK(sequenced_checker_.CalledSequentially()); | 175 RTC_DCHECK(main_thread_.CalledOnValidThread()); |
176 // Since we're running on the thread that's the only thread known to modify | 176 // Since we're running on the thread that's the only thread known to modify |
177 // the value of _encoder, we don't need to grab the lock here. | 177 // the value of _encoder, we don't need to grab the lock here. |
178 | 178 |
179 if (!_encoder) | 179 if (!_encoder) |
180 return VCM_UNINITIALIZED; | 180 return VCM_UNINITIALIZED; |
181 *bitrate = _encoder->GetEncoderParameters().target_bitrate; | 181 *bitrate = _encoder->GetEncoderParameters().target_bitrate; |
182 return 0; | 182 return 0; |
183 } | 183 } |
184 | 184 |
185 // Get encode frame rate | 185 // Get encode frame rate |
186 int VideoSender::FrameRate(unsigned int* framerate) const { | 186 int VideoSender::FrameRate(unsigned int* framerate) const { |
187 RTC_DCHECK(sequenced_checker_.CalledSequentially()); | 187 RTC_DCHECK(main_thread_.CalledOnValidThread()); |
188 // Since we're running on the thread that's the only thread known to modify | 188 // Since we're running on the thread that's the only thread known to modify |
189 // the value of _encoder, we don't need to grab the lock here. | 189 // the value of _encoder, we don't need to grab the lock here. |
190 | 190 |
191 if (!_encoder) | 191 if (!_encoder) |
192 return VCM_UNINITIALIZED; | 192 return VCM_UNINITIALIZED; |
193 | 193 |
194 *framerate = _encoder->GetEncoderParameters().input_frame_rate; | 194 *framerate = _encoder->GetEncoderParameters().input_frame_rate; |
195 return 0; | 195 return 0; |
196 } | 196 } |
197 | 197 |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
358 } | 358 } |
359 | 359 |
360 int32_t VideoSender::EnableFrameDropper(bool enable) { | 360 int32_t VideoSender::EnableFrameDropper(bool enable) { |
361 rtc::CritScope lock(&encoder_crit_); | 361 rtc::CritScope lock(&encoder_crit_); |
362 frame_dropper_enabled_ = enable; | 362 frame_dropper_enabled_ = enable; |
363 _mediaOpt.EnableFrameDropper(enable); | 363 _mediaOpt.EnableFrameDropper(enable); |
364 return VCM_OK; | 364 return VCM_OK; |
365 } | 365 } |
366 } // namespace vcm | 366 } // namespace vcm |
367 } // namespace webrtc | 367 } // namespace webrtc |
OLD | NEW |