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 } |
267 rtc::scoped_ptr<uint8_t[]> copied_buffer(new uint8_t[encoded_image._length]); | 271 |
268 memcpy(copied_buffer.get(), encoded_image._buffer, encoded_image._length); | 272 // The image to feed to the decoder. |
269 EncodedImage copied_image; | 273 EncodedImage copied_image; |
270 memcpy(&copied_image, &encoded_image, sizeof(copied_image)); | 274 memcpy(&copied_image, &encoded_image, sizeof(copied_image)); |
271 copied_image._size = copied_image._length; | 275 rtc::scoped_ptr<uint8_t[]> copied_buffer; |
272 copied_image._buffer = copied_buffer.get(); | 276 bool copied_image_done = false; |
277 #if defined(WEBRTC_OPENH264) | |
stefan-webrtc
2015/09/28 11:19:02
Do you need this ifdef if you have the if statemen
hbos
2015/09/30 15:35:19
(Removed, no longer needed due to including start
| |
278 if (config_.codec_settings->codecType == kVideoCodecH264 && | |
279 H264Encoder::IsSupportedOpenH264()) { | |
280 // H264 with OpenH264 encoder (H264EncoderImpl): Defragmentization necessary | |
281 // for decoder to be able to decode the EncodedImage. | |
282 size_t copied_buffer_size = | |
283 H264EncoderImpl::RTPDefragmentizeBufferLengthWithNAL(encoded_image, | |
stefan-webrtc
2015/09/28 11:19:02
Code should probably live in this test?
hbos
2015/09/30 15:35:19
(Removed, no longer needed due to including start
| |
284 fragmentation); | |
285 copied_buffer.reset(new uint8_t[copied_buffer_size]); | |
286 H264EncoderImpl::RTPDefragmentize( | |
287 encoded_image, fragmentation, copied_buffer.get(), copied_buffer_size); | |
288 copied_image._size = copied_buffer_size; | |
289 copied_image._length = copied_buffer_size; | |
290 copied_image._buffer = copied_buffer.get(); | |
291 copied_image_done = true; | |
292 } | |
293 #endif | |
294 if (!copied_image_done) { | |
295 // Make a raw copy of the |encoded_image| buffer. | |
296 copied_buffer.reset(new uint8_t[encoded_image._length]); | |
297 memcpy(copied_buffer.get(), encoded_image._buffer, encoded_image._length); | |
298 copied_image._size = copied_image._length; | |
299 copied_image._buffer = copied_buffer.get(); | |
300 } | |
301 | |
273 if (!exclude_this_frame) { | 302 if (!exclude_this_frame) { |
274 stat.packets_dropped = | 303 stat.packets_dropped = |
275 packet_manipulator_->ManipulatePackets(&copied_image); | 304 packet_manipulator_->ManipulatePackets(&copied_image); |
276 } | 305 } |
277 | 306 |
278 // Keep track of if frames are lost due to packet loss so we can tell | 307 // 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) | 308 // this to the encoder (this is handled by the RTP logic in the full stack) |
280 decode_start_ = TickTime::Now(); | 309 decode_start_ = TickTime::Now(); |
281 // TODO(kjellander): Pass fragmentation header to the decoder when | 310 // TODO(kjellander): Pass fragmentation header to the decoder when |
282 // CL 172001 has been submitted and PacketManipulator supports this. | 311 // 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"; | 423 return "Unknown"; |
395 } | 424 } |
396 } | 425 } |
397 | 426 |
398 // Callbacks | 427 // Callbacks |
399 int32_t | 428 int32_t |
400 VideoProcessorImpl::VideoProcessorEncodeCompleteCallback::Encoded( | 429 VideoProcessorImpl::VideoProcessorEncodeCompleteCallback::Encoded( |
401 const EncodedImage& encoded_image, | 430 const EncodedImage& encoded_image, |
402 const webrtc::CodecSpecificInfo* codec_specific_info, | 431 const webrtc::CodecSpecificInfo* codec_specific_info, |
403 const webrtc::RTPFragmentationHeader* fragmentation) { | 432 const webrtc::RTPFragmentationHeader* fragmentation) { |
404 video_processor_->FrameEncoded(encoded_image); // Forward to parent class. | 433 // Forward to parent class. |
434 video_processor_->FrameEncoded(encoded_image, fragmentation); | |
405 return 0; | 435 return 0; |
406 } | 436 } |
407 int32_t VideoProcessorImpl::VideoProcessorDecodeCompleteCallback::Decoded( | 437 int32_t VideoProcessorImpl::VideoProcessorDecodeCompleteCallback::Decoded( |
408 VideoFrame& image) { | 438 VideoFrame& image) { |
409 video_processor_->FrameDecoded(image); // forward to parent class | 439 // Forward to parent class. |
440 video_processor_->FrameDecoded(image); | |
410 return 0; | 441 return 0; |
411 } | 442 } |
412 | 443 |
413 } // namespace test | 444 } // namespace test |
414 } // namespace webrtc | 445 } // namespace webrtc |
OLD | NEW |