• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *  Copyright (c) 2018 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 
11 #include "test/fake_vp8_decoder.h"
12 
13 #include <stddef.h>
14 
15 #include "absl/types/optional.h"
16 #include "api/scoped_refptr.h"
17 #include "api/video/i420_buffer.h"
18 #include "api/video/video_frame.h"
19 #include "api/video/video_frame_buffer.h"
20 #include "api/video/video_rotation.h"
21 #include "modules/video_coding/include/video_error_codes.h"
22 #include "rtc_base/time_utils.h"
23 
24 namespace webrtc {
25 namespace test {
26 
27 namespace {
28 // Read width and height from the payload of the frame if it is a key frame the
29 // same way as the real VP8 decoder.
30 // FakeEncoder writes width, height and frame type.
ParseFakeVp8(const unsigned char * data,int * width,int * height)31 void ParseFakeVp8(const unsigned char* data, int* width, int* height) {
32   bool key_frame = data[0] == 0;
33   if (key_frame) {
34     *width = ((data[7] << 8) + data[6]) & 0x3FFF;
35     *height = ((data[9] << 8) + data[8]) & 0x3FFF;
36   }
37 }
38 }  // namespace
39 
FakeVp8Decoder()40 FakeVp8Decoder::FakeVp8Decoder() : callback_(nullptr), width_(0), height_(0) {}
41 
Configure(const Settings & settings)42 bool FakeVp8Decoder::Configure(const Settings& settings) {
43   return true;
44 }
45 
Decode(const EncodedImage & input,bool missing_frames,int64_t render_time_ms)46 int32_t FakeVp8Decoder::Decode(const EncodedImage& input,
47                                bool missing_frames,
48                                int64_t render_time_ms) {
49   constexpr size_t kMinPayLoadHeaderLength = 10;
50   if (input.size() < kMinPayLoadHeaderLength) {
51     return WEBRTC_VIDEO_CODEC_ERROR;
52   }
53   ParseFakeVp8(input.data(), &width_, &height_);
54 
55   VideoFrame frame =
56       VideoFrame::Builder()
57           .set_video_frame_buffer(I420Buffer::Create(width_, height_))
58           .set_rotation(webrtc::kVideoRotation_0)
59           .set_timestamp_ms(render_time_ms)
60           .build();
61   frame.set_timestamp(input.Timestamp());
62   frame.set_ntp_time_ms(input.ntp_time_ms_);
63 
64   callback_->Decoded(frame, /*decode_time_ms=*/absl::nullopt,
65                      /*qp=*/absl::nullopt);
66 
67   return WEBRTC_VIDEO_CODEC_OK;
68 }
69 
RegisterDecodeCompleteCallback(DecodedImageCallback * callback)70 int32_t FakeVp8Decoder::RegisterDecodeCompleteCallback(
71     DecodedImageCallback* callback) {
72   callback_ = callback;
73   return WEBRTC_VIDEO_CODEC_OK;
74 }
75 
Release()76 int32_t FakeVp8Decoder::Release() {
77   return WEBRTC_VIDEO_CODEC_OK;
78 }
79 
80 const char* FakeVp8Decoder::kImplementationName = "fake_vp8_decoder";
GetDecoderInfo() const81 VideoDecoder::DecoderInfo FakeVp8Decoder::GetDecoderInfo() const {
82   DecoderInfo info;
83   info.implementation_name = kImplementationName;
84   info.is_hardware_accelerated = false;
85   return info;
86 }
87 
ImplementationName() const88 const char* FakeVp8Decoder::ImplementationName() const {
89   return kImplementationName;
90 }
91 
92 }  // namespace test
93 }  // namespace webrtc
94