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 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
218 fprintf(stderr, "Failed to encode frame %d, return code: %d\n", | 218 fprintf(stderr, "Failed to encode frame %d, return code: %d\n", |
219 frame_number, encode_result); | 219 frame_number, encode_result); |
220 } | 220 } |
221 stat.encode_return_code = encode_result; | 221 stat.encode_return_code = encode_result; |
222 return true; | 222 return true; |
223 } else { | 223 } else { |
224 return false; // we've reached the last frame | 224 return false; // we've reached the last frame |
225 } | 225 } |
226 } | 226 } |
227 | 227 |
228 void VideoProcessorImpl::FrameEncoded(const EncodedImage& encoded_image) { | 228 void VideoProcessorImpl::FrameEncoded( |
| 229 const EncodedImage& encoded_image, |
| 230 const webrtc::RTPFragmentationHeader* fragmentation) { |
229 // Timestamp is frame number, so this gives us #dropped frames. | 231 // Timestamp is frame number, so this gives us #dropped frames. |
230 int num_dropped_from_prev_encode = | 232 int num_dropped_from_prev_encode = |
231 encoded_image._timeStamp - prev_time_stamp_ - 1; | 233 encoded_image._timeStamp - prev_time_stamp_ - 1; |
232 num_dropped_frames_ += num_dropped_from_prev_encode; | 234 num_dropped_frames_ += num_dropped_from_prev_encode; |
233 prev_time_stamp_ = encoded_image._timeStamp; | 235 prev_time_stamp_ = encoded_image._timeStamp; |
234 if (num_dropped_from_prev_encode > 0) { | 236 if (num_dropped_from_prev_encode > 0) { |
235 // For dropped frames, we write out the last decoded frame to avoid getting | 237 // For dropped frames, we write out the last decoded frame to avoid getting |
236 // out of sync for the computation of PSNR and SSIM. | 238 // out of sync for the computation of PSNR and SSIM. |
237 for (int i = 0; i < num_dropped_from_prev_encode; i++) { | 239 for (int i = 0; i < num_dropped_from_prev_encode; i++) { |
238 frame_writer_->WriteFrame(last_successful_frame_buffer_); | 240 frame_writer_->WriteFrame(last_successful_frame_buffer_); |
(...skipping 30 matching lines...) Expand all Loading... |
269 exclude_this_frame = true; | 271 exclude_this_frame = true; |
270 } | 272 } |
271 break; | 273 break; |
272 case kExcludeAllKeyFrames: | 274 case kExcludeAllKeyFrames: |
273 exclude_this_frame = true; | 275 exclude_this_frame = true; |
274 break; | 276 break; |
275 default: | 277 default: |
276 assert(false); | 278 assert(false); |
277 } | 279 } |
278 } | 280 } |
| 281 |
| 282 // The image to feed to the decoder. |
| 283 EncodedImage copied_image; |
| 284 memcpy(&copied_image, &encoded_image, sizeof(copied_image)); |
| 285 // Make a raw copy of the |encoded_image| buffer. |
279 rtc::scoped_ptr<uint8_t[]> copied_buffer(new uint8_t[encoded_image._length]); | 286 rtc::scoped_ptr<uint8_t[]> copied_buffer(new uint8_t[encoded_image._length]); |
280 memcpy(copied_buffer.get(), encoded_image._buffer, encoded_image._length); | 287 memcpy(copied_buffer.get(), encoded_image._buffer, encoded_image._length); |
281 EncodedImage copied_image; | |
282 memcpy(&copied_image, &encoded_image, sizeof(copied_image)); | |
283 copied_image._size = copied_image._length; | 288 copied_image._size = copied_image._length; |
284 copied_image._buffer = copied_buffer.get(); | 289 copied_image._buffer = copied_buffer.get(); |
| 290 |
285 if (!exclude_this_frame) { | 291 if (!exclude_this_frame) { |
286 stat.packets_dropped = | 292 stat.packets_dropped = |
287 packet_manipulator_->ManipulatePackets(&copied_image); | 293 packet_manipulator_->ManipulatePackets(&copied_image); |
288 } | 294 } |
289 | 295 |
290 // Keep track of if frames are lost due to packet loss so we can tell | 296 // Keep track of if frames are lost due to packet loss so we can tell |
291 // this to the encoder (this is handled by the RTP logic in the full stack) | 297 // this to the encoder (this is handled by the RTP logic in the full stack) |
292 decode_start_ = TickTime::Now(); | 298 decode_start_ = TickTime::Now(); |
293 // TODO(kjellander): Pass fragmentation header to the decoder when | 299 // TODO(kjellander): Pass fragmentation header to the decoder when |
294 // CL 172001 has been submitted and PacketManipulator supports this. | 300 // CL 172001 has been submitted and PacketManipulator supports this. |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
405 assert(false); | 411 assert(false); |
406 return "Unknown"; | 412 return "Unknown"; |
407 } | 413 } |
408 } | 414 } |
409 | 415 |
410 // Callbacks | 416 // Callbacks |
411 int32_t VideoProcessorImpl::VideoProcessorEncodeCompleteCallback::Encoded( | 417 int32_t VideoProcessorImpl::VideoProcessorEncodeCompleteCallback::Encoded( |
412 const EncodedImage& encoded_image, | 418 const EncodedImage& encoded_image, |
413 const webrtc::CodecSpecificInfo* codec_specific_info, | 419 const webrtc::CodecSpecificInfo* codec_specific_info, |
414 const webrtc::RTPFragmentationHeader* fragmentation) { | 420 const webrtc::RTPFragmentationHeader* fragmentation) { |
415 video_processor_->FrameEncoded(encoded_image); // Forward to parent class. | 421 // Forward to parent class. |
| 422 video_processor_->FrameEncoded(encoded_image, fragmentation); |
416 return 0; | 423 return 0; |
417 } | 424 } |
418 int32_t VideoProcessorImpl::VideoProcessorDecodeCompleteCallback::Decoded( | 425 int32_t VideoProcessorImpl::VideoProcessorDecodeCompleteCallback::Decoded( |
419 VideoFrame& image) { | 426 VideoFrame& image) { |
420 video_processor_->FrameDecoded(image); // forward to parent class | 427 // Forward to parent class. |
| 428 video_processor_->FrameDecoded(image); |
421 return 0; | 429 return 0; |
422 } | 430 } |
423 | 431 |
424 } // namespace test | 432 } // namespace test |
425 } // namespace webrtc | 433 } // namespace webrtc |
OLD | NEW |