pbos@webrtc.org | 0181b5f | 2013-09-09 08:26:30 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2013 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 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 11 | #include "test/fake_decoder.h" |
pbos@webrtc.org | 0181b5f | 2013-09-09 08:26:30 +0000 | [diff] [blame] | 12 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 13 | #include "api/video/i420_buffer.h" |
| 14 | #include "rtc_base/timeutils.h" |
philipel | 0e07572 | 2018-04-05 13:04:42 +0200 | [diff] [blame] | 15 | #include "test/call_test.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 16 | #include "test/gtest.h" |
pbos@webrtc.org | 0181b5f | 2013-09-09 08:26:30 +0000 | [diff] [blame] | 17 | |
| 18 | namespace webrtc { |
| 19 | namespace test { |
| 20 | |
philipel | 0e07572 | 2018-04-05 13:04:42 +0200 | [diff] [blame] | 21 | FakeDecoder::FakeDecoder() |
| 22 | : callback_(NULL), |
| 23 | width_(CallTest::kDefaultWidth), |
| 24 | height_(CallTest::kDefaultHeight) {} |
pbos@webrtc.org | 0181b5f | 2013-09-09 08:26:30 +0000 | [diff] [blame] | 25 | |
| 26 | int32_t FakeDecoder::InitDecode(const VideoCodec* config, |
| 27 | int32_t number_of_cores) { |
pbos@webrtc.org | 0181b5f | 2013-09-09 08:26:30 +0000 | [diff] [blame] | 28 | return WEBRTC_VIDEO_CODEC_OK; |
| 29 | } |
| 30 | |
| 31 | int32_t FakeDecoder::Decode(const EncodedImage& input, |
| 32 | bool missing_frames, |
| 33 | const RTPFragmentationHeader* fragmentation, |
| 34 | const CodecSpecificInfo* codec_specific_info, |
| 35 | int64_t render_time_ms) { |
philipel | 0e07572 | 2018-04-05 13:04:42 +0200 | [diff] [blame] | 36 | if (input._encodedWidth > 0 && input._encodedHeight > 0) { |
| 37 | width_ = input._encodedWidth; |
| 38 | height_ = input._encodedHeight; |
| 39 | } |
| 40 | |
| 41 | VideoFrame frame(I420Buffer::Create(width_, height_), |
nisse | f122a85 | 2016-10-04 23:27:30 -0700 | [diff] [blame] | 42 | webrtc::kVideoRotation_0, |
| 43 | render_time_ms * rtc::kNumMicrosecsPerMillisec); |
| 44 | frame.set_timestamp(input._timeStamp); |
| 45 | frame.set_ntp_time_ms(input.ntp_time_ms_); |
pbos@webrtc.org | 0181b5f | 2013-09-09 08:26:30 +0000 | [diff] [blame] | 46 | |
nisse | f122a85 | 2016-10-04 23:27:30 -0700 | [diff] [blame] | 47 | callback_->Decoded(frame); |
pbos@webrtc.org | 0181b5f | 2013-09-09 08:26:30 +0000 | [diff] [blame] | 48 | |
| 49 | return WEBRTC_VIDEO_CODEC_OK; |
| 50 | } |
| 51 | |
| 52 | int32_t FakeDecoder::RegisterDecodeCompleteCallback( |
| 53 | DecodedImageCallback* callback) { |
| 54 | callback_ = callback; |
| 55 | return WEBRTC_VIDEO_CODEC_OK; |
| 56 | } |
| 57 | |
| 58 | int32_t FakeDecoder::Release() { |
| 59 | return WEBRTC_VIDEO_CODEC_OK; |
| 60 | } |
Peter Boström | b7d9a97 | 2015-12-18 16:01:11 +0100 | [diff] [blame] | 61 | |
Peter Boström | b7d9a97 | 2015-12-18 16:01:11 +0100 | [diff] [blame] | 62 | const char* FakeDecoder::kImplementationName = "fake_decoder"; |
| 63 | const char* FakeDecoder::ImplementationName() const { |
| 64 | return kImplementationName; |
| 65 | } |
| 66 | |
stefan@webrtc.org | 79c3359 | 2014-08-06 09:24:53 +0000 | [diff] [blame] | 67 | int32_t FakeH264Decoder::Decode(const EncodedImage& input, |
| 68 | bool missing_frames, |
| 69 | const RTPFragmentationHeader* fragmentation, |
| 70 | const CodecSpecificInfo* codec_specific_info, |
| 71 | int64_t render_time_ms) { |
| 72 | uint8_t value = 0; |
| 73 | for (size_t i = 0; i < input._length; ++i) { |
| 74 | uint8_t kStartCode[] = {0, 0, 0, 1}; |
| 75 | if (i < input._length - sizeof(kStartCode) && |
| 76 | !memcmp(&input._buffer[i], kStartCode, sizeof(kStartCode))) { |
| 77 | i += sizeof(kStartCode) + 1; // Skip start code and NAL header. |
| 78 | } |
| 79 | if (input._buffer[i] != value) { |
| 80 | EXPECT_EQ(value, input._buffer[i]) |
| 81 | << "Bitstream mismatch between sender and receiver."; |
| 82 | return -1; |
| 83 | } |
| 84 | ++value; |
| 85 | } |
| 86 | return FakeDecoder::Decode(input, |
| 87 | missing_frames, |
| 88 | fragmentation, |
| 89 | codec_specific_info, |
| 90 | render_time_ms); |
| 91 | } |
| 92 | |
pbos@webrtc.org | 0181b5f | 2013-09-09 08:26:30 +0000 | [diff] [blame] | 93 | } // namespace test |
| 94 | } // namespace webrtc |