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 |
11 #include "webrtc/modules/video_coding/codecs/test/videoprocessor.h" | 11 #include "webrtc/modules/video_coding/codecs/test/videoprocessor.h" |
12 | 12 |
13 #include <assert.h> | 13 #include <assert.h> |
14 #include <string.h> | 14 #include <string.h> |
15 | 15 |
16 #include <limits> | 16 #include <limits> |
17 #include <vector> | 17 #include <vector> |
18 | 18 |
| 19 #include "webrtc/base/checks.h" |
| 20 #include "webrtc/modules/video_coding/codecs/h264/h264_encoder_impl.h" |
19 #include "webrtc/system_wrappers/interface/cpu_info.h" | 21 #include "webrtc/system_wrappers/interface/cpu_info.h" |
20 | 22 |
21 namespace webrtc { | 23 namespace webrtc { |
22 namespace test { | 24 namespace test { |
23 | 25 |
24 TestConfig::TestConfig() | 26 TestConfig::TestConfig() |
25 : name(""), | 27 : name(""), |
26 description(""), | 28 description(""), |
27 test_number(0), | 29 test_number(0), |
28 input_filename(""), | 30 input_filename(""), |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
209 fprintf(stderr, "Failed to encode frame %d, return code: %d\n", | 211 fprintf(stderr, "Failed to encode frame %d, return code: %d\n", |
210 frame_number, encode_result); | 212 frame_number, encode_result); |
211 } | 213 } |
212 stat.encode_return_code = encode_result; | 214 stat.encode_return_code = encode_result; |
213 return true; | 215 return true; |
214 } else { | 216 } else { |
215 return false; // we've reached the last frame | 217 return false; // we've reached the last frame |
216 } | 218 } |
217 } | 219 } |
218 | 220 |
219 void VideoProcessorImpl::FrameEncoded(const EncodedImage& encoded_image) { | 221 void VideoProcessorImpl::FrameEncoded( |
| 222 const EncodedImage& encoded_image, |
| 223 const webrtc::RTPFragmentationHeader* fragmentation) { |
220 // Timestamp is frame number, so this gives us #dropped frames. | 224 // Timestamp is frame number, so this gives us #dropped frames. |
221 int num_dropped_from_prev_encode = encoded_image._timeStamp - | 225 int num_dropped_from_prev_encode = encoded_image._timeStamp - |
222 prev_time_stamp_ - 1; | 226 prev_time_stamp_ - 1; |
223 num_dropped_frames_ += num_dropped_from_prev_encode; | 227 num_dropped_frames_ += num_dropped_from_prev_encode; |
224 prev_time_stamp_ = encoded_image._timeStamp; | 228 prev_time_stamp_ = encoded_image._timeStamp; |
225 if (num_dropped_from_prev_encode > 0) { | 229 if (num_dropped_from_prev_encode > 0) { |
226 // For dropped frames, we write out the last decoded frame to avoid getting | 230 // For dropped frames, we write out the last decoded frame to avoid getting |
227 // out of sync for the computation of PSNR and SSIM. | 231 // out of sync for the computation of PSNR and SSIM. |
228 for (int i = 0; i < num_dropped_from_prev_encode; i++) { | 232 for (int i = 0; i < num_dropped_from_prev_encode; i++) { |
229 frame_writer_->WriteFrame(last_successful_frame_buffer_); | 233 frame_writer_->WriteFrame(last_successful_frame_buffer_); |
(...skipping 27 matching lines...) Expand all Loading... |
257 exclude_this_frame = true; | 261 exclude_this_frame = true; |
258 } | 262 } |
259 break; | 263 break; |
260 case kExcludeAllKeyFrames: | 264 case kExcludeAllKeyFrames: |
261 exclude_this_frame = true; | 265 exclude_this_frame = true; |
262 break; | 266 break; |
263 default: | 267 default: |
264 assert(false); | 268 assert(false); |
265 } | 269 } |
266 } | 270 } |
| 271 |
| 272 // The image to feed to the decoder. |
| 273 EncodedImage copied_image; |
| 274 memcpy(&copied_image, &encoded_image, sizeof(copied_image)); |
| 275 // Make a raw copy of the |encoded_image| buffer. |
267 rtc::scoped_ptr<uint8_t[]> copied_buffer(new uint8_t[encoded_image._length]); | 276 rtc::scoped_ptr<uint8_t[]> copied_buffer(new uint8_t[encoded_image._length]); |
268 memcpy(copied_buffer.get(), encoded_image._buffer, encoded_image._length); | 277 memcpy(copied_buffer.get(), encoded_image._buffer, encoded_image._length); |
269 EncodedImage copied_image; | |
270 memcpy(&copied_image, &encoded_image, sizeof(copied_image)); | |
271 copied_image._size = copied_image._length; | 278 copied_image._size = copied_image._length; |
272 copied_image._buffer = copied_buffer.get(); | 279 copied_image._buffer = copied_buffer.get(); |
| 280 |
273 if (!exclude_this_frame) { | 281 if (!exclude_this_frame) { |
274 stat.packets_dropped = | 282 stat.packets_dropped = |
275 packet_manipulator_->ManipulatePackets(&copied_image); | 283 packet_manipulator_->ManipulatePackets(&copied_image); |
276 } | 284 } |
277 | 285 |
278 // Keep track of if frames are lost due to packet loss so we can tell | 286 // Keep track of if frames are lost due to packet loss so we can tell |
279 // this to the encoder (this is handled by the RTP logic in the full stack) | 287 // this to the encoder (this is handled by the RTP logic in the full stack) |
280 decode_start_ = TickTime::Now(); | 288 decode_start_ = TickTime::Now(); |
281 // TODO(kjellander): Pass fragmentation header to the decoder when | 289 // TODO(kjellander): Pass fragmentation header to the decoder when |
282 // CL 172001 has been submitted and PacketManipulator supports this. | 290 // CL 172001 has been submitted and PacketManipulator supports this. |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
394 return "Unknown"; | 402 return "Unknown"; |
395 } | 403 } |
396 } | 404 } |
397 | 405 |
398 // Callbacks | 406 // Callbacks |
399 int32_t | 407 int32_t |
400 VideoProcessorImpl::VideoProcessorEncodeCompleteCallback::Encoded( | 408 VideoProcessorImpl::VideoProcessorEncodeCompleteCallback::Encoded( |
401 const EncodedImage& encoded_image, | 409 const EncodedImage& encoded_image, |
402 const webrtc::CodecSpecificInfo* codec_specific_info, | 410 const webrtc::CodecSpecificInfo* codec_specific_info, |
403 const webrtc::RTPFragmentationHeader* fragmentation) { | 411 const webrtc::RTPFragmentationHeader* fragmentation) { |
404 video_processor_->FrameEncoded(encoded_image); // Forward to parent class. | 412 // Forward to parent class. |
| 413 video_processor_->FrameEncoded(encoded_image, fragmentation); |
405 return 0; | 414 return 0; |
406 } | 415 } |
407 int32_t VideoProcessorImpl::VideoProcessorDecodeCompleteCallback::Decoded( | 416 int32_t VideoProcessorImpl::VideoProcessorDecodeCompleteCallback::Decoded( |
408 VideoFrame& image) { | 417 VideoFrame& image) { |
409 video_processor_->FrameDecoded(image); // forward to parent class | 418 // Forward to parent class. |
| 419 video_processor_->FrameDecoded(image); |
410 return 0; | 420 return 0; |
411 } | 421 } |
412 | 422 |
413 } // namespace test | 423 } // namespace test |
414 } // namespace webrtc | 424 } // namespace webrtc |
OLD | NEW |