| 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_encoder.h" | 11 #include "webrtc/video_encoder.h" |
| 12 | 12 |
| 13 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
| 14 #include "webrtc/modules/video_coding/include/video_codec_interface.h" |
| 14 #include "webrtc/modules/video_coding/include/video_error_codes.h" | 15 #include "webrtc/modules/video_coding/include/video_error_codes.h" |
| 15 | 16 |
| 16 namespace webrtc { | 17 namespace webrtc { |
| 17 | 18 |
| 18 const int kWidth = 320; | 19 const int kWidth = 320; |
| 19 const int kHeight = 240; | 20 const int kHeight = 240; |
| 20 const size_t kMaxPayloadSize = 800; | 21 const size_t kMaxPayloadSize = 800; |
| 21 | 22 |
| 22 class VideoEncoderSoftwareFallbackWrapperTest : public ::testing::Test { | 23 class VideoEncoderSoftwareFallbackWrapperTest : public ::testing::Test { |
| 23 protected: | 24 protected: |
| 24 VideoEncoderSoftwareFallbackWrapperTest() | 25 VideoEncoderSoftwareFallbackWrapperTest() |
| 25 : fallback_wrapper_(kVideoCodecVP8, &fake_encoder_) {} | 26 : fallback_wrapper_(kVideoCodecVP8, &fake_encoder_) {} |
| 26 | 27 |
| 27 class CountingFakeEncoder : public VideoEncoder { | 28 class CountingFakeEncoder : public VideoEncoder { |
| 28 public: | 29 public: |
| 29 int32_t InitEncode(const VideoCodec* codec_settings, | 30 int32_t InitEncode(const VideoCodec* codec_settings, |
| 30 int32_t number_of_cores, | 31 int32_t number_of_cores, |
| 31 size_t max_payload_size) override { | 32 size_t max_payload_size) override { |
| 32 ++init_encode_count_; | 33 ++init_encode_count_; |
| 33 return init_encode_return_code_; | 34 return init_encode_return_code_; |
| 34 } | 35 } |
| 35 int32_t Encode(const VideoFrame& frame, | 36 int32_t Encode(const VideoFrame& frame, |
| 36 const CodecSpecificInfo* codec_specific_info, | 37 const CodecSpecificInfo* codec_specific_info, |
| 37 const std::vector<FrameType>* frame_types) override { | 38 const std::vector<FrameType>* frame_types) override { |
| 38 ++encode_count_; | 39 ++encode_count_; |
| 40 if (encode_complete_callback_ && |
| 41 encode_return_code_ == WEBRTC_VIDEO_CODEC_OK) { |
| 42 CodecSpecificInfo info; |
| 43 info.codec_name = ImplementationName(); |
| 44 encode_complete_callback_->OnEncodedImage(EncodedImage(), &info, |
| 45 nullptr); |
| 46 } |
| 39 return encode_return_code_; | 47 return encode_return_code_; |
| 40 } | 48 } |
| 41 | 49 |
| 42 int32_t RegisterEncodeCompleteCallback( | 50 int32_t RegisterEncodeCompleteCallback( |
| 43 EncodedImageCallback* callback) override { | 51 EncodedImageCallback* callback) override { |
| 44 encode_complete_callback_ = callback; | 52 encode_complete_callback_ = callback; |
| 45 return WEBRTC_VIDEO_CODEC_OK; | 53 return WEBRTC_VIDEO_CODEC_OK; |
| 46 } | 54 } |
| 47 | 55 |
| 48 int32_t Release() override { | 56 int32_t Release() override { |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 mutable int supports_native_handle_count_ = 0; | 91 mutable int supports_native_handle_count_ = 0; |
| 84 }; | 92 }; |
| 85 | 93 |
| 86 class FakeEncodedImageCallback : public EncodedImageCallback { | 94 class FakeEncodedImageCallback : public EncodedImageCallback { |
| 87 public: | 95 public: |
| 88 Result OnEncodedImage( | 96 Result OnEncodedImage( |
| 89 const EncodedImage& encoded_image, | 97 const EncodedImage& encoded_image, |
| 90 const CodecSpecificInfo* codec_specific_info, | 98 const CodecSpecificInfo* codec_specific_info, |
| 91 const RTPFragmentationHeader* fragmentation) override { | 99 const RTPFragmentationHeader* fragmentation) override { |
| 92 ++callback_count_; | 100 ++callback_count_; |
| 101 last_codec_name_ = codec_specific_info->codec_name; |
| 93 return Result(Result::OK, callback_count_); | 102 return Result(Result::OK, callback_count_); |
| 94 } | 103 } |
| 95 int callback_count_ = 0; | 104 int callback_count_ = 0; |
| 105 std::string last_codec_name_; |
| 96 }; | 106 }; |
| 97 | 107 |
| 98 void UtilizeFallbackEncoder(); | 108 void UtilizeFallbackEncoder(); |
| 99 void FallbackFromEncodeRequest(); | 109 void FallbackFromEncodeRequest(); |
| 100 void EncodeFrame(); | 110 void EncodeFrame(); |
| 111 void CheckLastEncoderName(const char* expected_name) { |
| 112 EXPECT_STREQ(expected_name, callback_.last_codec_name_.c_str()); |
| 113 } |
| 101 | 114 |
| 102 FakeEncodedImageCallback callback_; | 115 FakeEncodedImageCallback callback_; |
| 103 CountingFakeEncoder fake_encoder_; | 116 CountingFakeEncoder fake_encoder_; |
| 104 VideoEncoderSoftwareFallbackWrapper fallback_wrapper_; | 117 VideoEncoderSoftwareFallbackWrapper fallback_wrapper_; |
| 105 VideoCodec codec_ = {}; | 118 VideoCodec codec_ = {}; |
| 106 VideoFrame frame_; | 119 VideoFrame frame_; |
| 107 }; | 120 }; |
| 108 | 121 |
| 109 void VideoEncoderSoftwareFallbackWrapperTest::EncodeFrame() { | 122 void VideoEncoderSoftwareFallbackWrapperTest::EncodeFrame() { |
| 110 frame_.CreateEmptyFrame(kWidth, kHeight, kWidth, (kWidth + 1) / 2, | 123 frame_.CreateEmptyFrame(kWidth, kHeight, kWidth, (kWidth + 1) / 2, |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 258 } | 271 } |
| 259 | 272 |
| 260 TEST_F(VideoEncoderSoftwareFallbackWrapperTest, | 273 TEST_F(VideoEncoderSoftwareFallbackWrapperTest, |
| 261 SupportsNativeHandleNotForwardedDuringFallback) { | 274 SupportsNativeHandleNotForwardedDuringFallback) { |
| 262 UtilizeFallbackEncoder(); | 275 UtilizeFallbackEncoder(); |
| 263 fallback_wrapper_.SupportsNativeHandle(); | 276 fallback_wrapper_.SupportsNativeHandle(); |
| 264 EXPECT_EQ(0, fake_encoder_.supports_native_handle_count_); | 277 EXPECT_EQ(0, fake_encoder_.supports_native_handle_count_); |
| 265 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, fallback_wrapper_.Release()); | 278 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, fallback_wrapper_.Release()); |
| 266 } | 279 } |
| 267 | 280 |
| 281 TEST_F(VideoEncoderSoftwareFallbackWrapperTest, ReportsImplementationName) { |
| 282 VideoCodec codec = {}; |
| 283 fallback_wrapper_.RegisterEncodeCompleteCallback(&callback_); |
| 284 fallback_wrapper_.InitEncode(&codec, 2, kMaxPayloadSize); |
| 285 EncodeFrame(); |
| 286 CheckLastEncoderName("fake-encoder"); |
| 287 } |
| 288 |
| 268 TEST_F(VideoEncoderSoftwareFallbackWrapperTest, | 289 TEST_F(VideoEncoderSoftwareFallbackWrapperTest, |
| 269 ReportsFallbackImplementationName) { | 290 ReportsFallbackImplementationName) { |
| 270 UtilizeFallbackEncoder(); | 291 UtilizeFallbackEncoder(); |
| 271 // Hard coded expected value since libvpx is the software implementation name | 292 // Hard coded expected value since libvpx is the software implementation name |
| 272 // for VP8. Change accordingly if the underlying implementation does. | 293 // for VP8. Change accordingly if the underlying implementation does. |
| 273 EXPECT_STREQ("libvpx (fallback from: fake-encoder)", | 294 CheckLastEncoderName("libvpx"); |
| 274 fallback_wrapper_.ImplementationName()); | |
| 275 } | 295 } |
| 276 | 296 |
| 277 } // namespace webrtc | 297 } // namespace webrtc |
| OLD | NEW |