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