blob: fe8aef7167705068f0358291fb3cb4c00e7145da [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"
15#include "test/gtest.h"
pbos@webrtc.org0181b5f2013-09-09 08:26:30 +000016
17namespace webrtc {
18namespace test {
19
20FakeDecoder::FakeDecoder() : callback_(NULL) {}
21
22int32_t FakeDecoder::InitDecode(const VideoCodec* config,
23 int32_t number_of_cores) {
24 config_ = *config;
pbos@webrtc.org0181b5f2013-09-09 08:26:30 +000025 return WEBRTC_VIDEO_CODEC_OK;
26}
27
28int32_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) {
nissef122a852016-10-04 23:27:30 -070033 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.org0181b5f2013-09-09 08:26:30 +000038
nissef122a852016-10-04 23:27:30 -070039 callback_->Decoded(frame);
pbos@webrtc.org0181b5f2013-09-09 08:26:30 +000040
41 return WEBRTC_VIDEO_CODEC_OK;
42}
43
44int32_t FakeDecoder::RegisterDecodeCompleteCallback(
45 DecodedImageCallback* callback) {
46 callback_ = callback;
47 return WEBRTC_VIDEO_CODEC_OK;
48}
49
50int32_t FakeDecoder::Release() {
51 return WEBRTC_VIDEO_CODEC_OK;
52}
Peter Boströmb7d9a972015-12-18 16:01:11 +010053
Peter Boströmb7d9a972015-12-18 16:01:11 +010054const char* FakeDecoder::kImplementationName = "fake_decoder";
55const char* FakeDecoder::ImplementationName() const {
56 return kImplementationName;
57}
58
stefan@webrtc.org79c33592014-08-06 09:24:53 +000059int32_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.org0181b5f2013-09-09 08:26:30 +000085} // namespace test
86} // namespace webrtc