blob: 865bca7983607a53ddc87aca65ac1daa9bd9f525 [file] [log] [blame]
pbos@webrtc.org0181b5f2013-09-09 08:26:301/*
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 04:47:3111#include "test/fake_decoder.h"
pbos@webrtc.org0181b5f2013-09-09 08:26:3012
Yves Gerey3e707812018-11-28 15:47:4913#include <string.h>
14
Mirko Bonadei92ea95e2017-09-15 04:47:3115#include "api/video/i420_buffer.h"
Yves Gerey3e707812018-11-28 15:47:4916#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 Anton10542f22019-01-11 17:11:0022#include "rtc_base/time_utils.h"
pbos@webrtc.org0181b5f2013-09-09 08:26:3023
24namespace webrtc {
25namespace test {
26
Ilya Nikolaevskiyb0588e62018-08-27 12:12:2727namespace {
28const int kDefaultWidth = 320;
29const int kDefaultHeight = 180;
30} // namespace
31
philipel0e075722018-04-05 11:04:4232FakeDecoder::FakeDecoder()
Ilya Nikolaevskiyb0588e62018-08-27 12:12:2733 : callback_(NULL), width_(kDefaultWidth), height_(kDefaultHeight) {}
pbos@webrtc.org0181b5f2013-09-09 08:26:3034
35int32_t FakeDecoder::InitDecode(const VideoCodec* config,
36 int32_t number_of_cores) {
pbos@webrtc.org0181b5f2013-09-09 08:26:3037 return WEBRTC_VIDEO_CODEC_OK;
38}
39
40int32_t FakeDecoder::Decode(const EncodedImage& input,
41 bool missing_frames,
pbos@webrtc.org0181b5f2013-09-09 08:26:3042 const CodecSpecificInfo* codec_specific_info,
43 int64_t render_time_ms) {
philipel0e075722018-04-05 11:04:4244 if (input._encodedWidth > 0 && input._encodedHeight > 0) {
45 width_ = input._encodedWidth;
46 height_ = input._encodedHeight;
47 }
48
Artem Titov1ebfb6a2019-01-03 22:49:3749 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öller23775882018-08-16 08:24:1255 frame.set_timestamp(input.Timestamp());
nissef122a852016-10-05 06:27:3056 frame.set_ntp_time_ms(input.ntp_time_ms_);
pbos@webrtc.org0181b5f2013-09-09 08:26:3057
nissef122a852016-10-05 06:27:3058 callback_->Decoded(frame);
pbos@webrtc.org0181b5f2013-09-09 08:26:3059
60 return WEBRTC_VIDEO_CODEC_OK;
61}
62
63int32_t FakeDecoder::RegisterDecodeCompleteCallback(
64 DecodedImageCallback* callback) {
65 callback_ = callback;
66 return WEBRTC_VIDEO_CODEC_OK;
67}
68
69int32_t FakeDecoder::Release() {
70 return WEBRTC_VIDEO_CODEC_OK;
71}
Peter Boströmb7d9a972015-12-18 15:01:1172
Peter Boströmb7d9a972015-12-18 15:01:1173const char* FakeDecoder::kImplementationName = "fake_decoder";
74const char* FakeDecoder::ImplementationName() const {
75 return kImplementationName;
76}
77
stefan@webrtc.org79c33592014-08-06 09:24:5378int32_t FakeH264Decoder::Decode(const EncodedImage& input,
79 bool missing_frames,
stefan@webrtc.org79c33592014-08-06 09:24:5380 const CodecSpecificInfo* codec_specific_info,
81 int64_t render_time_ms) {
82 uint8_t value = 0;
Niels Möller77536a22019-01-15 07:50:0183 for (size_t i = 0; i < input.size(); ++i) {
stefan@webrtc.org79c33592014-08-06 09:24:5384 uint8_t kStartCode[] = {0, 0, 0, 1};
Niels Möller77536a22019-01-15 07:50:0185 if (i < input.size() - sizeof(kStartCode) &&
Niels Möller24871e42019-01-17 10:31:1386 !memcmp(&input.data()[i], kStartCode, sizeof(kStartCode))) {
stefan@webrtc.org79c33592014-08-06 09:24:5387 i += sizeof(kStartCode) + 1; // Skip start code and NAL header.
88 }
Niels Möller24871e42019-01-17 10:31:1389 if (input.data()[i] != value) {
90 RTC_CHECK_EQ(value, input.data()[i])
stefan@webrtc.org79c33592014-08-06 09:24:5391 << "Bitstream mismatch between sender and receiver.";
92 return -1;
93 }
94 ++value;
95 }
Yves Gerey665174f2018-06-19 13:03:0596 return FakeDecoder::Decode(input, missing_frames, codec_specific_info,
stefan@webrtc.org79c33592014-08-06 09:24:5397 render_time_ms);
98}
99
pbos@webrtc.org0181b5f2013-09-09 08:26:30100} // namespace test
101} // namespace webrtc