pbos@webrtc.org | 0181b5f | 2013-09-09 08:26:30 | [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 04:47:31 | [diff] [blame] | 11 | #include "test/fake_decoder.h" |
pbos@webrtc.org | 0181b5f | 2013-09-09 08:26:30 | [diff] [blame] | 12 | |
Yves Gerey | 3e70781 | 2018-11-28 15:47:49 | [diff] [blame] | 13 | #include <string.h> |
| 14 | |
Mirko Bonadei | 92ea95e | 2017-09-15 04:47:31 | [diff] [blame] | 15 | #include "api/video/i420_buffer.h" |
Yves Gerey | 3e70781 | 2018-11-28 15:47:49 | [diff] [blame] | 16 | #include "api/video/video_frame.h" |
| 17 | #include "api/video/video_frame_buffer.h" |
| 18 | #include "api/video/video_rotation.h" |
| 19 | #include "modules/video_coding/include/video_error_codes.h" |
| 20 | #include "rtc_base/checks.h" |
| 21 | #include "rtc_base/scoped_ref_ptr.h" |
Steve Anton | 10542f2 | 2019-01-11 17:11:00 | [diff] [blame] | 22 | #include "rtc_base/time_utils.h" |
pbos@webrtc.org | 0181b5f | 2013-09-09 08:26:30 | [diff] [blame] | 23 | |
| 24 | namespace webrtc { |
| 25 | namespace test { |
| 26 | |
Ilya Nikolaevskiy | b0588e6 | 2018-08-27 12:12:27 | [diff] [blame] | 27 | namespace { |
| 28 | const int kDefaultWidth = 320; |
| 29 | const int kDefaultHeight = 180; |
| 30 | } // namespace |
| 31 | |
philipel | 0e07572 | 2018-04-05 11:04:42 | [diff] [blame] | 32 | FakeDecoder::FakeDecoder() |
Ilya Nikolaevskiy | b0588e6 | 2018-08-27 12:12:27 | [diff] [blame] | 33 | : callback_(NULL), width_(kDefaultWidth), height_(kDefaultHeight) {} |
pbos@webrtc.org | 0181b5f | 2013-09-09 08:26:30 | [diff] [blame] | 34 | |
| 35 | int32_t FakeDecoder::InitDecode(const VideoCodec* config, |
| 36 | int32_t number_of_cores) { |
pbos@webrtc.org | 0181b5f | 2013-09-09 08:26:30 | [diff] [blame] | 37 | return WEBRTC_VIDEO_CODEC_OK; |
| 38 | } |
| 39 | |
| 40 | int32_t FakeDecoder::Decode(const EncodedImage& input, |
| 41 | bool missing_frames, |
pbos@webrtc.org | 0181b5f | 2013-09-09 08:26:30 | [diff] [blame] | 42 | const CodecSpecificInfo* codec_specific_info, |
| 43 | int64_t render_time_ms) { |
philipel | 0e07572 | 2018-04-05 11:04:42 | [diff] [blame] | 44 | if (input._encodedWidth > 0 && input._encodedHeight > 0) { |
| 45 | width_ = input._encodedWidth; |
| 46 | height_ = input._encodedHeight; |
| 47 | } |
| 48 | |
Artem Titov | 1ebfb6a | 2019-01-03 22:49:37 | [diff] [blame] | 49 | VideoFrame frame = |
| 50 | VideoFrame::Builder() |
| 51 | .set_video_frame_buffer(I420Buffer::Create(width_, height_)) |
| 52 | .set_rotation(webrtc::kVideoRotation_0) |
| 53 | .set_timestamp_ms(render_time_ms) |
| 54 | .build(); |
Niels Möller | 2377588 | 2018-08-16 08:24:12 | [diff] [blame] | 55 | frame.set_timestamp(input.Timestamp()); |
nisse | f122a85 | 2016-10-05 06:27:30 | [diff] [blame] | 56 | frame.set_ntp_time_ms(input.ntp_time_ms_); |
pbos@webrtc.org | 0181b5f | 2013-09-09 08:26:30 | [diff] [blame] | 57 | |
nisse | f122a85 | 2016-10-05 06:27:30 | [diff] [blame] | 58 | callback_->Decoded(frame); |
pbos@webrtc.org | 0181b5f | 2013-09-09 08:26:30 | [diff] [blame] | 59 | |
| 60 | return WEBRTC_VIDEO_CODEC_OK; |
| 61 | } |
| 62 | |
| 63 | int32_t FakeDecoder::RegisterDecodeCompleteCallback( |
| 64 | DecodedImageCallback* callback) { |
| 65 | callback_ = callback; |
| 66 | return WEBRTC_VIDEO_CODEC_OK; |
| 67 | } |
| 68 | |
| 69 | int32_t FakeDecoder::Release() { |
| 70 | return WEBRTC_VIDEO_CODEC_OK; |
| 71 | } |
Peter Boström | b7d9a97 | 2015-12-18 15:01:11 | [diff] [blame] | 72 | |
Peter Boström | b7d9a97 | 2015-12-18 15:01:11 | [diff] [blame] | 73 | const char* FakeDecoder::kImplementationName = "fake_decoder"; |
| 74 | const char* FakeDecoder::ImplementationName() const { |
| 75 | return kImplementationName; |
| 76 | } |
| 77 | |
stefan@webrtc.org | 79c3359 | 2014-08-06 09:24:53 | [diff] [blame] | 78 | int32_t FakeH264Decoder::Decode(const EncodedImage& input, |
| 79 | bool missing_frames, |
stefan@webrtc.org | 79c3359 | 2014-08-06 09:24:53 | [diff] [blame] | 80 | const CodecSpecificInfo* codec_specific_info, |
| 81 | int64_t render_time_ms) { |
| 82 | uint8_t value = 0; |
Niels Möller | 77536a2 | 2019-01-15 07:50:01 | [diff] [blame] | 83 | for (size_t i = 0; i < input.size(); ++i) { |
stefan@webrtc.org | 79c3359 | 2014-08-06 09:24:53 | [diff] [blame] | 84 | uint8_t kStartCode[] = {0, 0, 0, 1}; |
Niels Möller | 77536a2 | 2019-01-15 07:50:01 | [diff] [blame] | 85 | if (i < input.size() - sizeof(kStartCode) && |
Niels Möller | 24871e4 | 2019-01-17 10:31:13 | [diff] [blame^] | 86 | !memcmp(&input.data()[i], kStartCode, sizeof(kStartCode))) { |
stefan@webrtc.org | 79c3359 | 2014-08-06 09:24:53 | [diff] [blame] | 87 | i += sizeof(kStartCode) + 1; // Skip start code and NAL header. |
| 88 | } |
Niels Möller | 24871e4 | 2019-01-17 10:31:13 | [diff] [blame^] | 89 | if (input.data()[i] != value) { |
| 90 | RTC_CHECK_EQ(value, input.data()[i]) |
stefan@webrtc.org | 79c3359 | 2014-08-06 09:24:53 | [diff] [blame] | 91 | << "Bitstream mismatch between sender and receiver."; |
| 92 | return -1; |
| 93 | } |
| 94 | ++value; |
| 95 | } |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 96 | return FakeDecoder::Decode(input, missing_frames, codec_specific_info, |
stefan@webrtc.org | 79c3359 | 2014-08-06 09:24:53 | [diff] [blame] | 97 | render_time_ms); |
| 98 | } |
| 99 | |
pbos@webrtc.org | 0181b5f | 2013-09-09 08:26:30 | [diff] [blame] | 100 | } // namespace test |
| 101 | } // namespace webrtc |