OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2015 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/video_decoder.h" | 11 #include "webrtc/video_decoder.h" |
12 | 12 |
13 #include "webrtc/base/checks.h" | 13 #include "webrtc/base/checks.h" |
14 #include "webrtc/media/engine/videodecodersoftwarefallbackwrapper.h" | 14 #include "webrtc/media/engine/videodecodersoftwarefallbackwrapper.h" |
15 #include "webrtc/modules/video_coding/include/video_error_codes.h" | 15 #include "webrtc/modules/video_coding/include/video_error_codes.h" |
16 #include "webrtc/test/gtest.h" | 16 #include "webrtc/test/gtest.h" |
17 | 17 |
18 namespace webrtc { | 18 namespace webrtc { |
19 | 19 |
20 class VideoDecoderSoftwareFallbackWrapperTest : public ::testing::Test { | 20 class VideoDecoderSoftwareFallbackWrapperTest : public ::testing::Test { |
21 protected: | 21 protected: |
22 VideoDecoderSoftwareFallbackWrapperTest() | 22 VideoDecoderSoftwareFallbackWrapperTest() |
23 : fallback_wrapper_(kVideoCodecVP8, &fake_decoder_) {} | 23 : fallback_wrapper_(kVideoCodecVP8, &fake_decoder_) {} |
24 | 24 |
25 class CountingFakeDecoder : public VideoDecoder { | 25 class CountingFakeDecoder : public VideoDecoder { |
26 public: | 26 public: |
27 int32_t InitDecode(const VideoCodec* codec_settings, | 27 int32_t InitDecode(const VideoCodec* codec_settings, |
28 int32_t number_of_cores) override { | 28 int32_t number_of_cores) override { |
29 puts("CountingFakeDecoder::InitDecode"); | |
29 ++init_decode_count_; | 30 ++init_decode_count_; |
30 return WEBRTC_VIDEO_CODEC_OK; | 31 return init_decode_return_code_; |
31 } | 32 } |
32 | 33 |
33 int32_t Decode(const EncodedImage& input_image, | 34 int32_t Decode(const EncodedImage& input_image, |
34 bool missing_frames, | 35 bool missing_frames, |
35 const RTPFragmentationHeader* fragmentation, | 36 const RTPFragmentationHeader* fragmentation, |
36 const CodecSpecificInfo* codec_specific_info, | 37 const CodecSpecificInfo* codec_specific_info, |
37 int64_t render_time_ms) override { | 38 int64_t render_time_ms) override { |
38 ++decode_count_; | 39 ++decode_count_; |
39 return decode_return_code_; | 40 return decode_return_code_; |
40 } | 41 } |
41 | 42 |
42 int32_t RegisterDecodeCompleteCallback( | 43 int32_t RegisterDecodeCompleteCallback( |
43 DecodedImageCallback* callback) override { | 44 DecodedImageCallback* callback) override { |
44 decode_complete_callback_ = callback; | 45 decode_complete_callback_ = callback; |
45 return WEBRTC_VIDEO_CODEC_OK; | 46 return WEBRTC_VIDEO_CODEC_OK; |
46 } | 47 } |
47 | 48 |
48 int32_t Release() override { | 49 int32_t Release() override { |
49 ++release_count_; | 50 ++release_count_; |
50 return WEBRTC_VIDEO_CODEC_OK; | 51 return WEBRTC_VIDEO_CODEC_OK; |
51 } | 52 } |
52 | 53 |
53 const char* ImplementationName() const override { | 54 const char* ImplementationName() const override { |
54 return "fake-decoder"; | 55 return "fake-decoder"; |
55 } | 56 } |
56 | 57 |
57 int init_decode_count_ = 0; | 58 int init_decode_count_ = 0; |
58 int decode_count_ = 0; | 59 int decode_count_ = 0; |
60 int32_t init_decode_return_code_ = WEBRTC_VIDEO_CODEC_OK; | |
59 int32_t decode_return_code_ = WEBRTC_VIDEO_CODEC_OK; | 61 int32_t decode_return_code_ = WEBRTC_VIDEO_CODEC_OK; |
60 DecodedImageCallback* decode_complete_callback_ = nullptr; | 62 DecodedImageCallback* decode_complete_callback_ = nullptr; |
61 int release_count_ = 0; | 63 int release_count_ = 0; |
62 int reset_count_ = 0; | 64 int reset_count_ = 0; |
63 }; | 65 }; |
64 CountingFakeDecoder fake_decoder_; | 66 CountingFakeDecoder fake_decoder_; |
65 VideoDecoderSoftwareFallbackWrapper fallback_wrapper_; | 67 VideoDecoderSoftwareFallbackWrapper fallback_wrapper_; |
66 }; | 68 }; |
67 | 69 |
68 TEST_F(VideoDecoderSoftwareFallbackWrapperTest, InitializesDecoder) { | 70 TEST_F(VideoDecoderSoftwareFallbackWrapperTest, InitializesDecoder) { |
69 VideoCodec codec = {}; | 71 VideoCodec codec = {}; |
70 fallback_wrapper_.InitDecode(&codec, 2); | 72 fallback_wrapper_.InitDecode(&codec, 2); |
71 EXPECT_EQ(1, fake_decoder_.init_decode_count_); | 73 EXPECT_EQ(1, fake_decoder_.init_decode_count_); |
74 | |
75 EncodedImage encoded_image; | |
76 encoded_image._frameType = kVideoFrameKey; | |
77 fallback_wrapper_.Decode(encoded_image, false, nullptr, nullptr, -1); | |
78 EXPECT_EQ(1, fake_decoder_.init_decode_count_) | |
79 << "Initialized decoder should not be reinitialized."; | |
80 EXPECT_EQ(1, fake_decoder_.decode_count_); | |
72 } | 81 } |
73 | 82 |
74 TEST_F(VideoDecoderSoftwareFallbackWrapperTest, | 83 TEST_F(VideoDecoderSoftwareFallbackWrapperTest, |
84 UsesFallbackDecoderAfterOnInitDecodeFailure) { | |
85 VideoCodec codec = {}; | |
86 fake_decoder_.init_decode_return_code_ = WEBRTC_VIDEO_CODEC_FALLBACK_SOFTWARE; | |
87 fallback_wrapper_.InitDecode(&codec, 2); | |
88 EXPECT_EQ(1, fake_decoder_.init_decode_count_); | |
89 | |
90 EncodedImage encoded_image; | |
91 encoded_image._frameType = kVideoFrameKey; | |
92 fallback_wrapper_.Decode(encoded_image, false, nullptr, nullptr, -1); | |
93 EXPECT_EQ(2, fake_decoder_.init_decode_count_) | |
94 << "Should have attempted reinitializing the fallback decoder on " | |
95 "keyframe."; | |
96 // Unfortunately faking a VP8 frame is hard. Rely on no Decode -> using SW | |
noahric
2017/02/13 20:42:30
Makes sense, just check the result of fallback_wra
| |
97 // decoder. | |
98 EXPECT_EQ(0, fake_decoder_.decode_count_) | |
99 << "Decoder used even though no InitDecode had succeeded."; | |
100 } | |
101 | |
102 TEST_F(VideoDecoderSoftwareFallbackWrapperTest, | |
75 CanRecoverFromSoftwareFallback) { | 103 CanRecoverFromSoftwareFallback) { |
76 VideoCodec codec = {}; | 104 VideoCodec codec = {}; |
77 fallback_wrapper_.InitDecode(&codec, 2); | 105 fallback_wrapper_.InitDecode(&codec, 2); |
78 // Unfortunately faking a VP8 frame is hard. Rely on no Decode -> using SW | 106 // Unfortunately faking a VP8 frame is hard. Rely on no Decode -> using SW |
79 // decoder. | 107 // decoder. |
80 fake_decoder_.decode_return_code_ = WEBRTC_VIDEO_CODEC_FALLBACK_SOFTWARE; | 108 fake_decoder_.decode_return_code_ = WEBRTC_VIDEO_CODEC_FALLBACK_SOFTWARE; |
81 EncodedImage encoded_image; | 109 EncodedImage encoded_image; |
82 fallback_wrapper_.Decode(encoded_image, false, nullptr, nullptr, -1); | 110 fallback_wrapper_.Decode(encoded_image, false, nullptr, nullptr, -1); |
83 EXPECT_EQ(1, fake_decoder_.decode_count_); | 111 EXPECT_EQ(1, fake_decoder_.decode_count_); |
84 | 112 |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
169 EncodedImage encoded_image; | 197 EncodedImage encoded_image; |
170 fallback_wrapper_.Decode(encoded_image, false, nullptr, nullptr, -1); | 198 fallback_wrapper_.Decode(encoded_image, false, nullptr, nullptr, -1); |
171 // Hard coded expected value since libvpx is the software implementation name | 199 // Hard coded expected value since libvpx is the software implementation name |
172 // for VP8. Change accordingly if the underlying implementation does. | 200 // for VP8. Change accordingly if the underlying implementation does. |
173 EXPECT_STREQ("libvpx (fallback from: fake-decoder)", | 201 EXPECT_STREQ("libvpx (fallback from: fake-decoder)", |
174 fallback_wrapper_.ImplementationName()); | 202 fallback_wrapper_.ImplementationName()); |
175 fallback_wrapper_.Release(); | 203 fallback_wrapper_.Release(); |
176 } | 204 } |
177 | 205 |
178 } // namespace webrtc | 206 } // namespace webrtc |
OLD | NEW |