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 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
138 const CodecSpecificInfo* codecSpecificInfo, | 138 const CodecSpecificInfo* codecSpecificInfo, |
139 const std::vector<FrameType>& frameTypes) { | 139 const std::vector<FrameType>& frameTypes) { |
140 TRACE_EVENT1("webrtc", "VCMGenericEncoder::Encode", "timestamp", | 140 TRACE_EVENT1("webrtc", "VCMGenericEncoder::Encode", "timestamp", |
141 inputFrame.timestamp()); | 141 inputFrame.timestamp()); |
142 | 142 |
143 for (FrameType frame_type : frameTypes) | 143 for (FrameType frame_type : frameTypes) |
144 RTC_DCHECK(frame_type == kVideoFrameKey || frame_type == kVideoFrameDelta); | 144 RTC_DCHECK(frame_type == kVideoFrameKey || frame_type == kVideoFrameDelta); |
145 | 145 |
146 rotation_ = inputFrame.rotation(); | 146 rotation_ = inputFrame.rotation(); |
147 | 147 |
148 // Keep track of the current frame rotation and apply to the output of the | |
149 // encoder. There might not be exact as the encoder could have one frame delay | |
150 // but it should be close enough. | |
151 // TODO(pbos): Map from timestamp, this is racy (even if rotation_ is locked | |
152 // properly, which it isn't). More than one frame may be in the pipeline. | |
153 vcm_encoded_frame_callback_->SetRotation(rotation_); | |
154 | |
155 int32_t result = encoder_->Encode(inputFrame, codecSpecificInfo, &frameTypes); | 148 int32_t result = encoder_->Encode(inputFrame, codecSpecificInfo, &frameTypes); |
156 | 149 |
157 if (vcm_encoded_frame_callback_) { | 150 if (vcm_encoded_frame_callback_) { |
158 vcm_encoded_frame_callback_->SignalLastEncoderImplementationUsed( | 151 vcm_encoded_frame_callback_->SignalLastEncoderImplementationUsed( |
159 encoder_->ImplementationName()); | 152 encoder_->ImplementationName()); |
160 } | 153 } |
161 | 154 |
162 if (is_screenshare_ && | 155 if (is_screenshare_ && |
163 result == WEBRTC_VIDEO_CODEC_TARGET_BITRATE_OVERSHOOT) { | 156 result == WEBRTC_VIDEO_CODEC_TARGET_BITRATE_OVERSHOOT) { |
164 // Target bitrate exceeded, encoder state has been reset - try again. | 157 // Target bitrate exceeded, encoder state has been reset - try again. |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
226 | 219 |
227 /*************************** | 220 /*************************** |
228 * Callback Implementation | 221 * Callback Implementation |
229 ***************************/ | 222 ***************************/ |
230 VCMEncodedFrameCallback::VCMEncodedFrameCallback( | 223 VCMEncodedFrameCallback::VCMEncodedFrameCallback( |
231 EncodedImageCallback* post_encode_callback) | 224 EncodedImageCallback* post_encode_callback) |
232 : send_callback_(), | 225 : send_callback_(), |
233 _mediaOpt(NULL), | 226 _mediaOpt(NULL), |
234 _payloadType(0), | 227 _payloadType(0), |
235 _internalSource(false), | 228 _internalSource(false), |
236 _rotation(kVideoRotation_0), | |
237 post_encode_callback_(post_encode_callback) | 229 post_encode_callback_(post_encode_callback) |
238 #ifdef DEBUG_ENCODER_BIT_STREAM | 230 #ifdef DEBUG_ENCODER_BIT_STREAM |
239 , | 231 , |
240 _bitStreamAfterEncoder(NULL) | 232 _bitStreamAfterEncoder(NULL) |
241 #endif | 233 #endif |
242 { | 234 { |
243 #ifdef DEBUG_ENCODER_BIT_STREAM | 235 #ifdef DEBUG_ENCODER_BIT_STREAM |
244 _bitStreamAfterEncoder = fopen("encoderBitStream.bit", "wb"); | 236 _bitStreamAfterEncoder = fopen("encoderBitStream.bit", "wb"); |
245 #endif | 237 #endif |
246 } | 238 } |
(...skipping 28 matching lines...) Expand all Loading... |
275 _bitStreamAfterEncoder); | 267 _bitStreamAfterEncoder); |
276 } | 268 } |
277 #endif | 269 #endif |
278 | 270 |
279 RTPVideoHeader rtpVideoHeader; | 271 RTPVideoHeader rtpVideoHeader; |
280 memset(&rtpVideoHeader, 0, sizeof(RTPVideoHeader)); | 272 memset(&rtpVideoHeader, 0, sizeof(RTPVideoHeader)); |
281 RTPVideoHeader* rtpVideoHeaderPtr = &rtpVideoHeader; | 273 RTPVideoHeader* rtpVideoHeaderPtr = &rtpVideoHeader; |
282 if (codecSpecificInfo) { | 274 if (codecSpecificInfo) { |
283 CopyCodecSpecific(codecSpecificInfo, rtpVideoHeaderPtr); | 275 CopyCodecSpecific(codecSpecificInfo, rtpVideoHeaderPtr); |
284 } | 276 } |
285 rtpVideoHeader.rotation = _rotation; | 277 rtpVideoHeader.rotation = encoded_image.rotation_; |
286 | 278 |
287 int32_t callbackReturn = send_callback_->SendData( | 279 int32_t callbackReturn = send_callback_->SendData( |
288 _payloadType, encoded_image, fragmentationHeader, rtpVideoHeaderPtr); | 280 _payloadType, encoded_image, fragmentationHeader, rtpVideoHeaderPtr); |
289 if (callbackReturn < 0) { | 281 if (callbackReturn < 0) { |
290 return callbackReturn; | 282 return callbackReturn; |
291 } | 283 } |
292 | 284 |
293 if (_mediaOpt != NULL) { | 285 if (_mediaOpt != NULL) { |
294 _mediaOpt->UpdateWithEncodedData(encoded_image); | 286 _mediaOpt->UpdateWithEncodedData(encoded_image); |
295 if (_internalSource) | 287 if (_internalSource) |
296 return _mediaOpt->DropFrame(); // Signal to encoder to drop next frame. | 288 return _mediaOpt->DropFrame(); // Signal to encoder to drop next frame. |
297 } | 289 } |
298 return VCM_OK; | 290 return VCM_OK; |
299 } | 291 } |
300 | 292 |
301 void VCMEncodedFrameCallback::SetMediaOpt( | 293 void VCMEncodedFrameCallback::SetMediaOpt( |
302 media_optimization::MediaOptimization* mediaOpt) { | 294 media_optimization::MediaOptimization* mediaOpt) { |
303 _mediaOpt = mediaOpt; | 295 _mediaOpt = mediaOpt; |
304 } | 296 } |
305 | 297 |
306 void VCMEncodedFrameCallback::SignalLastEncoderImplementationUsed( | 298 void VCMEncodedFrameCallback::SignalLastEncoderImplementationUsed( |
307 const char* implementation_name) { | 299 const char* implementation_name) { |
308 if (send_callback_) | 300 if (send_callback_) |
309 send_callback_->OnEncoderImplementationName(implementation_name); | 301 send_callback_->OnEncoderImplementationName(implementation_name); |
310 } | 302 } |
311 | 303 |
312 } // namespace webrtc | 304 } // namespace webrtc |
OLD | NEW |