OLD | NEW |
| (Empty) |
1 /* | |
2 * Copyright (c) 2017 The WebRTC project authors. All Rights Reserved. | |
3 * | |
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 | |
6 * tree. An additional intellectual property rights grant can be found | |
7 * in the file PATENTS. All contributing project authors may | |
8 * be found in the AUTHORS file in the root of the source tree. | |
9 */ | |
10 | |
11 #include "webrtc/modules/video_coding/codecs/test/video_codec_test.h" | |
12 | |
13 #include "webrtc/modules/video_coding/include/video_error_codes.h" | |
14 #include "webrtc/test/frame_utils.h" | |
15 #include "webrtc/test/testsupport/fileutils.h" | |
16 | |
17 static const int kEncodeTimeoutMs = 100; | |
18 static const int kDecodeTimeoutMs = 25; | |
19 // Set bitrate to get higher quality. | |
20 static const int kStartBitrate = 300; | |
21 static const int kTargetBitrate = 2000; | |
22 static const int kMaxBitrate = 4000; | |
23 static const int kWidth = 172; // Width of the input image. | |
24 static const int kHeight = 144; // Height of the input image. | |
25 static const int kMaxFramerate = 30; // Arbitrary value. | |
26 | |
27 namespace webrtc { | |
28 | |
29 EncodedImageCallback::Result | |
30 VideoCodecTest::FakeEncodeCompleteCallback::OnEncodedImage( | |
31 const EncodedImage& frame, | |
32 const CodecSpecificInfo* codec_specific_info, | |
33 const RTPFragmentationHeader* fragmentation) { | |
34 rtc::CritScope lock(&test_->encoded_frame_section_); | |
35 test_->encoded_frame_.emplace(frame); | |
36 test_->encoded_frame_event_.Set(); | |
37 return Result(Result::OK); | |
38 } | |
39 | |
40 void VideoCodecTest::FakeDecodeCompleteCallback::Decoded( | |
41 VideoFrame& frame, | |
42 rtc::Optional<int32_t> decode_time_ms, | |
43 rtc::Optional<uint8_t> qp) { | |
44 rtc::CritScope lock(&test_->decoded_frame_section_); | |
45 test_->decoded_frame_.emplace(frame); | |
46 test_->decoded_qp_ = qp; | |
47 test_->decoded_frame_event_.Set(); | |
48 } | |
49 | |
50 void VideoCodecTest::SetUp() { | |
51 // Using a QCIF image. Processing only one frame. | |
52 FILE* source_file_ = | |
53 fopen(test::ResourcePath("paris_qcif", "yuv").c_str(), "rb"); | |
54 ASSERT_TRUE(source_file_ != NULL); | |
55 rtc::scoped_refptr<VideoFrameBuffer> video_frame_buffer( | |
56 test::ReadI420Buffer(kWidth, kHeight, source_file_)); | |
57 input_frame_.reset(new VideoFrame(video_frame_buffer, kVideoRotation_0, 0)); | |
58 fclose(source_file_); | |
59 | |
60 encoder_.reset(CreateEncoder()); | |
61 decoder_.reset(CreateDecoder()); | |
62 encoder_->RegisterEncodeCompleteCallback(&encode_complete_callback_); | |
63 decoder_->RegisterDecodeCompleteCallback(&decode_complete_callback_); | |
64 | |
65 InitCodecs(); | |
66 } | |
67 | |
68 bool VideoCodecTest::WaitForEncodedFrame(EncodedImage* frame) { | |
69 bool ret = encoded_frame_event_.Wait(kEncodeTimeoutMs); | |
70 EXPECT_TRUE(ret) << "Timed out while waiting for an encoded frame."; | |
71 // This becomes unsafe if there are multiple threads waiting for frames. | |
72 rtc::CritScope lock(&encoded_frame_section_); | |
73 EXPECT_TRUE(encoded_frame_); | |
74 if (encoded_frame_) { | |
75 *frame = std::move(*encoded_frame_); | |
76 encoded_frame_.reset(); | |
77 return true; | |
78 } else { | |
79 return false; | |
80 } | |
81 } | |
82 | |
83 bool VideoCodecTest::WaitForDecodedFrame(std::unique_ptr<VideoFrame>* frame, | |
84 rtc::Optional<uint8_t>* qp) { | |
85 bool ret = decoded_frame_event_.Wait(kDecodeTimeoutMs); | |
86 EXPECT_TRUE(ret) << "Timed out while waiting for a decoded frame."; | |
87 // This becomes unsafe if there are multiple threads waiting for frames. | |
88 rtc::CritScope lock(&decoded_frame_section_); | |
89 EXPECT_TRUE(decoded_frame_); | |
90 if (decoded_frame_) { | |
91 frame->reset(new VideoFrame(std::move(*decoded_frame_))); | |
92 *qp = decoded_qp_; | |
93 decoded_frame_.reset(); | |
94 return true; | |
95 } else { | |
96 return false; | |
97 } | |
98 } | |
99 | |
100 void VideoCodecTest::InitCodecs() { | |
101 VideoCodec codec_inst = codec_settings(); | |
102 codec_inst.startBitrate = kStartBitrate; | |
103 codec_inst.targetBitrate = kTargetBitrate; | |
104 codec_inst.maxBitrate = kMaxBitrate; | |
105 codec_inst.maxFramerate = kMaxFramerate; | |
106 codec_inst.width = kWidth; | |
107 codec_inst.height = kHeight; | |
108 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, | |
109 encoder_->InitEncode(&codec_inst, 1 /* number of cores */, | |
110 0 /* max payload size (unused) */)); | |
111 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, | |
112 decoder_->InitDecode(&codec_inst, 1 /* number of cores */)); | |
113 } | |
114 | |
115 } // namespace webrtc | |
OLD | NEW |