blob: e0011971cc080c1f816895989b6312c7db170652 [file] [log] [blame]
pbos@webrtc.org0181b5f2013-09-09 08:26:30 +00001/*
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 Bonadei92ea95e2017-09-15 06:47:31 +020011#include "test/fake_decoder.h"
pbos@webrtc.org0181b5f2013-09-09 08:26:30 +000012
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020013#include "api/video/i420_buffer.h"
14#include "rtc_base/timeutils.h"
philipel0e075722018-04-05 13:04:42 +020015#include "test/call_test.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020016#include "test/gtest.h"
pbos@webrtc.org0181b5f2013-09-09 08:26:30 +000017
18namespace webrtc {
19namespace test {
20
philipel0e075722018-04-05 13:04:42 +020021FakeDecoder::FakeDecoder()
22 : callback_(NULL),
23 width_(CallTest::kDefaultWidth),
24 height_(CallTest::kDefaultHeight) {}
pbos@webrtc.org0181b5f2013-09-09 08:26:30 +000025
26int32_t FakeDecoder::InitDecode(const VideoCodec* config,
27 int32_t number_of_cores) {
pbos@webrtc.org0181b5f2013-09-09 08:26:30 +000028 return WEBRTC_VIDEO_CODEC_OK;
29}
30
31int32_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) {
philipel0e075722018-04-05 13:04:42 +020036 if (input._encodedWidth > 0 && input._encodedHeight > 0) {
37 width_ = input._encodedWidth;
38 height_ = input._encodedHeight;
39 }
40
41 VideoFrame frame(I420Buffer::Create(width_, height_),
nissef122a852016-10-04 23:27:30 -070042 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.org0181b5f2013-09-09 08:26:30 +000046
nissef122a852016-10-04 23:27:30 -070047 callback_->Decoded(frame);
pbos@webrtc.org0181b5f2013-09-09 08:26:30 +000048
49 return WEBRTC_VIDEO_CODEC_OK;
50}
51
52int32_t FakeDecoder::RegisterDecodeCompleteCallback(
53 DecodedImageCallback* callback) {
54 callback_ = callback;
55 return WEBRTC_VIDEO_CODEC_OK;
56}
57
58int32_t FakeDecoder::Release() {
59 return WEBRTC_VIDEO_CODEC_OK;
60}
Peter Boströmb7d9a972015-12-18 16:01:11 +010061
Peter Boströmb7d9a972015-12-18 16:01:11 +010062const char* FakeDecoder::kImplementationName = "fake_decoder";
63const char* FakeDecoder::ImplementationName() const {
64 return kImplementationName;
65}
66
stefan@webrtc.org79c33592014-08-06 09:24:53 +000067int32_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.org0181b5f2013-09-09 08:26:30 +000093} // namespace test
94} // namespace webrtc