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 ++init_decode_count_; | 29 ++init_decode_count_; |
30 return WEBRTC_VIDEO_CODEC_OK; | 30 return init_decode_return_code_; |
31 } | 31 } |
32 | 32 |
33 int32_t Decode(const EncodedImage& input_image, | 33 int32_t Decode(const EncodedImage& input_image, |
34 bool missing_frames, | 34 bool missing_frames, |
35 const RTPFragmentationHeader* fragmentation, | 35 const RTPFragmentationHeader* fragmentation, |
36 const CodecSpecificInfo* codec_specific_info, | 36 const CodecSpecificInfo* codec_specific_info, |
37 int64_t render_time_ms) override { | 37 int64_t render_time_ms) override { |
38 ++decode_count_; | 38 ++decode_count_; |
39 return decode_return_code_; | 39 return decode_return_code_; |
40 } | 40 } |
41 | 41 |
42 int32_t RegisterDecodeCompleteCallback( | 42 int32_t RegisterDecodeCompleteCallback( |
43 DecodedImageCallback* callback) override { | 43 DecodedImageCallback* callback) override { |
44 decode_complete_callback_ = callback; | 44 decode_complete_callback_ = callback; |
45 return WEBRTC_VIDEO_CODEC_OK; | 45 return WEBRTC_VIDEO_CODEC_OK; |
46 } | 46 } |
47 | 47 |
48 int32_t Release() override { | 48 int32_t Release() override { |
49 ++release_count_; | 49 ++release_count_; |
50 return WEBRTC_VIDEO_CODEC_OK; | 50 return WEBRTC_VIDEO_CODEC_OK; |
51 } | 51 } |
52 | 52 |
53 const char* ImplementationName() const override { | 53 const char* ImplementationName() const override { |
54 return "fake-decoder"; | 54 return "fake-decoder"; |
55 } | 55 } |
56 | 56 |
57 int init_decode_count_ = 0; | 57 int init_decode_count_ = 0; |
58 int decode_count_ = 0; | 58 int decode_count_ = 0; |
| 59 int32_t init_decode_return_code_ = WEBRTC_VIDEO_CODEC_OK; |
59 int32_t decode_return_code_ = WEBRTC_VIDEO_CODEC_OK; | 60 int32_t decode_return_code_ = WEBRTC_VIDEO_CODEC_OK; |
60 DecodedImageCallback* decode_complete_callback_ = nullptr; | 61 DecodedImageCallback* decode_complete_callback_ = nullptr; |
61 int release_count_ = 0; | 62 int release_count_ = 0; |
62 int reset_count_ = 0; | 63 int reset_count_ = 0; |
63 }; | 64 }; |
64 CountingFakeDecoder fake_decoder_; | 65 CountingFakeDecoder fake_decoder_; |
65 VideoDecoderSoftwareFallbackWrapper fallback_wrapper_; | 66 VideoDecoderSoftwareFallbackWrapper fallback_wrapper_; |
66 }; | 67 }; |
67 | 68 |
68 TEST_F(VideoDecoderSoftwareFallbackWrapperTest, InitializesDecoder) { | 69 TEST_F(VideoDecoderSoftwareFallbackWrapperTest, InitializesDecoder) { |
69 VideoCodec codec = {}; | 70 VideoCodec codec = {}; |
70 fallback_wrapper_.InitDecode(&codec, 2); | 71 fallback_wrapper_.InitDecode(&codec, 2); |
71 EXPECT_EQ(1, fake_decoder_.init_decode_count_); | 72 EXPECT_EQ(1, fake_decoder_.init_decode_count_); |
| 73 |
| 74 EncodedImage encoded_image; |
| 75 encoded_image._frameType = kVideoFrameKey; |
| 76 fallback_wrapper_.Decode(encoded_image, false, nullptr, nullptr, -1); |
| 77 EXPECT_EQ(1, fake_decoder_.init_decode_count_) |
| 78 << "Initialized decoder should not be reinitialized."; |
| 79 EXPECT_EQ(1, fake_decoder_.decode_count_); |
72 } | 80 } |
73 | 81 |
74 TEST_F(VideoDecoderSoftwareFallbackWrapperTest, | 82 TEST_F(VideoDecoderSoftwareFallbackWrapperTest, |
| 83 UsesFallbackDecoderAfterOnInitDecodeFailure) { |
| 84 VideoCodec codec = {}; |
| 85 fake_decoder_.init_decode_return_code_ = WEBRTC_VIDEO_CODEC_FALLBACK_SOFTWARE; |
| 86 fallback_wrapper_.InitDecode(&codec, 2); |
| 87 EXPECT_EQ(1, fake_decoder_.init_decode_count_); |
| 88 |
| 89 EncodedImage encoded_image; |
| 90 encoded_image._frameType = kVideoFrameKey; |
| 91 fallback_wrapper_.Decode(encoded_image, false, nullptr, nullptr, -1); |
| 92 EXPECT_EQ(2, fake_decoder_.init_decode_count_) |
| 93 << "Should have attempted reinitializing the fallback decoder on " |
| 94 "keyframe."; |
| 95 // Unfortunately faking a VP8 frame is hard. Rely on no Decode -> using SW |
| 96 // decoder. |
| 97 EXPECT_EQ(0, fake_decoder_.decode_count_) |
| 98 << "Decoder used even though no InitDecode had succeeded."; |
| 99 } |
| 100 |
| 101 TEST_F(VideoDecoderSoftwareFallbackWrapperTest, |
75 CanRecoverFromSoftwareFallback) { | 102 CanRecoverFromSoftwareFallback) { |
76 VideoCodec codec = {}; | 103 VideoCodec codec = {}; |
77 fallback_wrapper_.InitDecode(&codec, 2); | 104 fallback_wrapper_.InitDecode(&codec, 2); |
78 // Unfortunately faking a VP8 frame is hard. Rely on no Decode -> using SW | 105 // Unfortunately faking a VP8 frame is hard. Rely on no Decode -> using SW |
79 // decoder. | 106 // decoder. |
80 fake_decoder_.decode_return_code_ = WEBRTC_VIDEO_CODEC_FALLBACK_SOFTWARE; | 107 fake_decoder_.decode_return_code_ = WEBRTC_VIDEO_CODEC_FALLBACK_SOFTWARE; |
81 EncodedImage encoded_image; | 108 EncodedImage encoded_image; |
82 fallback_wrapper_.Decode(encoded_image, false, nullptr, nullptr, -1); | 109 fallback_wrapper_.Decode(encoded_image, false, nullptr, nullptr, -1); |
83 EXPECT_EQ(1, fake_decoder_.decode_count_); | 110 EXPECT_EQ(1, fake_decoder_.decode_count_); |
84 | 111 |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
169 EncodedImage encoded_image; | 196 EncodedImage encoded_image; |
170 fallback_wrapper_.Decode(encoded_image, false, nullptr, nullptr, -1); | 197 fallback_wrapper_.Decode(encoded_image, false, nullptr, nullptr, -1); |
171 // Hard coded expected value since libvpx is the software implementation name | 198 // Hard coded expected value since libvpx is the software implementation name |
172 // for VP8. Change accordingly if the underlying implementation does. | 199 // for VP8. Change accordingly if the underlying implementation does. |
173 EXPECT_STREQ("libvpx (fallback from: fake-decoder)", | 200 EXPECT_STREQ("libvpx (fallback from: fake-decoder)", |
174 fallback_wrapper_.ImplementationName()); | 201 fallback_wrapper_.ImplementationName()); |
175 fallback_wrapper_.Release(); | 202 fallback_wrapper_.Release(); |
176 } | 203 } |
177 | 204 |
178 } // namespace webrtc | 205 } // namespace webrtc |
OLD | NEW |