OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2012 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 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
143 rotation_ = inputFrame.rotation(); | 143 rotation_ = inputFrame.rotation(); |
144 | 144 |
145 // Keep track of the current frame rotation and apply to the output of the | 145 // Keep track of the current frame rotation and apply to the output of the |
146 // encoder. There might not be exact as the encoder could have one frame delay | 146 // encoder. There might not be exact as the encoder could have one frame delay |
147 // but it should be close enough. | 147 // but it should be close enough. |
148 // TODO(pbos): Map from timestamp, this is racy (even if rotation_ is locked | 148 // TODO(pbos): Map from timestamp, this is racy (even if rotation_ is locked |
149 // properly, which it isn't). More than one frame may be in the pipeline. | 149 // properly, which it isn't). More than one frame may be in the pipeline. |
150 vcm_encoded_frame_callback_->SetRotation(rotation_); | 150 vcm_encoded_frame_callback_->SetRotation(rotation_); |
151 | 151 |
152 int32_t result = encoder_->Encode(inputFrame, codecSpecificInfo, &frameTypes); | 152 int32_t result = encoder_->Encode(inputFrame, codecSpecificInfo, &frameTypes); |
| 153 |
| 154 if (vcm_encoded_frame_callback_) { |
| 155 vcm_encoded_frame_callback_->SignalLastEncoderImplementationUsed( |
| 156 encoder_->ImplementationName()); |
| 157 } |
| 158 |
153 if (is_screenshare_ && | 159 if (is_screenshare_ && |
154 result == WEBRTC_VIDEO_CODEC_TARGET_BITRATE_OVERSHOOT) { | 160 result == WEBRTC_VIDEO_CODEC_TARGET_BITRATE_OVERSHOOT) { |
155 // Target bitrate exceeded, encoder state has been reset - try again. | 161 // Target bitrate exceeded, encoder state has been reset - try again. |
156 return encoder_->Encode(inputFrame, codecSpecificInfo, &frameTypes); | 162 return encoder_->Encode(inputFrame, codecSpecificInfo, &frameTypes); |
157 } | 163 } |
158 | 164 |
159 return result; | 165 return result; |
160 } | 166 } |
161 | 167 |
162 void VCMGenericEncoder::SetEncoderParameters(const EncoderParameters& params) { | 168 void VCMGenericEncoder::SetEncoderParameters(const EncoderParameters& params) { |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
217 | 223 |
218 int VCMGenericEncoder::GetTargetFramerate() { | 224 int VCMGenericEncoder::GetTargetFramerate() { |
219 return encoder_->GetTargetFramerate(); | 225 return encoder_->GetTargetFramerate(); |
220 } | 226 } |
221 | 227 |
222 /*************************** | 228 /*************************** |
223 * Callback Implementation | 229 * Callback Implementation |
224 ***************************/ | 230 ***************************/ |
225 VCMEncodedFrameCallback::VCMEncodedFrameCallback( | 231 VCMEncodedFrameCallback::VCMEncodedFrameCallback( |
226 EncodedImageCallback* post_encode_callback) | 232 EncodedImageCallback* post_encode_callback) |
227 : _sendCallback(), | 233 : send_callback_(), |
228 _mediaOpt(NULL), | 234 _mediaOpt(NULL), |
229 _payloadType(0), | 235 _payloadType(0), |
230 _internalSource(false), | 236 _internalSource(false), |
231 _rotation(kVideoRotation_0), | 237 _rotation(kVideoRotation_0), |
232 post_encode_callback_(post_encode_callback) | 238 post_encode_callback_(post_encode_callback) |
233 #ifdef DEBUG_ENCODER_BIT_STREAM | 239 #ifdef DEBUG_ENCODER_BIT_STREAM |
234 , | 240 , |
235 _bitStreamAfterEncoder(NULL) | 241 _bitStreamAfterEncoder(NULL) |
236 #endif | 242 #endif |
237 { | 243 { |
238 #ifdef DEBUG_ENCODER_BIT_STREAM | 244 #ifdef DEBUG_ENCODER_BIT_STREAM |
239 _bitStreamAfterEncoder = fopen("encoderBitStream.bit", "wb"); | 245 _bitStreamAfterEncoder = fopen("encoderBitStream.bit", "wb"); |
240 #endif | 246 #endif |
241 } | 247 } |
242 | 248 |
243 VCMEncodedFrameCallback::~VCMEncodedFrameCallback() | 249 VCMEncodedFrameCallback::~VCMEncodedFrameCallback() |
244 { | 250 { |
245 #ifdef DEBUG_ENCODER_BIT_STREAM | 251 #ifdef DEBUG_ENCODER_BIT_STREAM |
246 fclose(_bitStreamAfterEncoder); | 252 fclose(_bitStreamAfterEncoder); |
247 #endif | 253 #endif |
248 } | 254 } |
249 | 255 |
250 int32_t | 256 int32_t |
251 VCMEncodedFrameCallback::SetTransportCallback(VCMPacketizationCallback* transpor
t) | 257 VCMEncodedFrameCallback::SetTransportCallback(VCMPacketizationCallback* transpor
t) |
252 { | 258 { |
253 _sendCallback = transport; | 259 send_callback_ = transport; |
254 return VCM_OK; | 260 return VCM_OK; |
255 } | 261 } |
256 | 262 |
257 int32_t VCMEncodedFrameCallback::Encoded( | 263 int32_t VCMEncodedFrameCallback::Encoded( |
258 const EncodedImage& encodedImage, | 264 const EncodedImage& encoded_image, |
259 const CodecSpecificInfo* codecSpecificInfo, | 265 const CodecSpecificInfo* codecSpecificInfo, |
260 const RTPFragmentationHeader* fragmentationHeader) { | 266 const RTPFragmentationHeader* fragmentationHeader) { |
261 TRACE_EVENT_INSTANT1("webrtc", "VCMEncodedFrameCallback::Encoded", | 267 TRACE_EVENT_INSTANT1("webrtc", "VCMEncodedFrameCallback::Encoded", |
262 "timestamp", encodedImage._timeStamp); | 268 "timestamp", encoded_image._timeStamp); |
263 RTC_DCHECK(encodedImage._frameType == kVideoFrameKey || | 269 post_encode_callback_->Encoded(encoded_image, NULL, NULL); |
264 encodedImage._frameType == kVideoFrameDelta); | |
265 post_encode_callback_->Encoded(encodedImage, NULL, NULL); | |
266 | 270 |
267 if (_sendCallback == NULL) { | 271 if (send_callback_ == NULL) { |
268 return VCM_UNINITIALIZED; | 272 return VCM_UNINITIALIZED; |
269 } | 273 } |
270 | 274 |
271 #ifdef DEBUG_ENCODER_BIT_STREAM | 275 #ifdef DEBUG_ENCODER_BIT_STREAM |
272 if (_bitStreamAfterEncoder != NULL) { | 276 if (_bitStreamAfterEncoder != NULL) { |
273 fwrite(encodedImage._buffer, 1, encodedImage._length, | 277 fwrite(encoded_image._buffer, 1, encoded_image._length, |
274 _bitStreamAfterEncoder); | 278 _bitStreamAfterEncoder); |
275 } | 279 } |
276 #endif | 280 #endif |
277 | 281 |
278 RTPVideoHeader rtpVideoHeader; | 282 RTPVideoHeader rtpVideoHeader; |
279 memset(&rtpVideoHeader, 0, sizeof(RTPVideoHeader)); | 283 memset(&rtpVideoHeader, 0, sizeof(RTPVideoHeader)); |
280 RTPVideoHeader* rtpVideoHeaderPtr = &rtpVideoHeader; | 284 RTPVideoHeader* rtpVideoHeaderPtr = &rtpVideoHeader; |
281 if (codecSpecificInfo) { | 285 if (codecSpecificInfo) { |
282 CopyCodecSpecific(codecSpecificInfo, rtpVideoHeaderPtr); | 286 CopyCodecSpecific(codecSpecificInfo, rtpVideoHeaderPtr); |
283 } | 287 } |
284 rtpVideoHeader.rotation = _rotation; | 288 rtpVideoHeader.rotation = _rotation; |
285 | 289 |
286 int32_t callbackReturn = _sendCallback->SendData( | 290 int32_t callbackReturn = send_callback_->SendData( |
287 _payloadType, encodedImage, *fragmentationHeader, rtpVideoHeaderPtr); | 291 _payloadType, encoded_image, *fragmentationHeader, rtpVideoHeaderPtr); |
288 if (callbackReturn < 0) { | 292 if (callbackReturn < 0) { |
289 return callbackReturn; | 293 return callbackReturn; |
290 } | 294 } |
291 | 295 |
292 if (_mediaOpt != NULL) { | 296 if (_mediaOpt != NULL) { |
293 _mediaOpt->UpdateWithEncodedData(encodedImage); | 297 _mediaOpt->UpdateWithEncodedData(encoded_image); |
294 if (_internalSource) | 298 if (_internalSource) |
295 return _mediaOpt->DropFrame(); // Signal to encoder to drop next frame. | 299 return _mediaOpt->DropFrame(); // Signal to encoder to drop next frame. |
296 } | 300 } |
297 return VCM_OK; | 301 return VCM_OK; |
298 } | 302 } |
299 | 303 |
300 void | 304 void VCMEncodedFrameCallback::SetMediaOpt( |
301 VCMEncodedFrameCallback::SetMediaOpt( | 305 media_optimization::MediaOptimization* mediaOpt) { |
302 media_optimization::MediaOptimization *mediaOpt) | 306 _mediaOpt = mediaOpt; |
303 { | 307 } |
304 _mediaOpt = mediaOpt; | 308 |
| 309 void VCMEncodedFrameCallback::SignalLastEncoderImplementationUsed( |
| 310 const char* implementation_name) { |
| 311 if (send_callback_) |
| 312 send_callback_->OnEncoderImplementationName(implementation_name); |
305 } | 313 } |
306 | 314 |
307 } // namespace webrtc | 315 } // namespace webrtc |
OLD | NEW |