1618a0ec1d2c17d485b7ce51cbfd282e6bae8e019pbos@webrtc.org/*
2618a0ec1d2c17d485b7ce51cbfd282e6bae8e019pbos@webrtc.org *  Copyright (c) 2013 The WebRTC project authors. All Rights Reserved.
3618a0ec1d2c17d485b7ce51cbfd282e6bae8e019pbos@webrtc.org *
4618a0ec1d2c17d485b7ce51cbfd282e6bae8e019pbos@webrtc.org *  Use of this source code is governed by a BSD-style license
5618a0ec1d2c17d485b7ce51cbfd282e6bae8e019pbos@webrtc.org *  that can be found in the LICENSE file in the root of the source
6618a0ec1d2c17d485b7ce51cbfd282e6bae8e019pbos@webrtc.org *  tree. An additional intellectual property rights grant can be found
7618a0ec1d2c17d485b7ce51cbfd282e6bae8e019pbos@webrtc.org *  in the file PATENTS.  All contributing project authors may
8618a0ec1d2c17d485b7ce51cbfd282e6bae8e019pbos@webrtc.org *  be found in the AUTHORS file in the root of the source tree.
9618a0ec1d2c17d485b7ce51cbfd282e6bae8e019pbos@webrtc.org */
10618a0ec1d2c17d485b7ce51cbfd282e6bae8e019pbos@webrtc.org
1124e2089750e9e51228b82d6c7ebf4fa064c797bapbos@webrtc.org#include "webrtc/test/fake_decoder.h"
12618a0ec1d2c17d485b7ce51cbfd282e6bae8e019pbos@webrtc.org
13618a0ec1d2c17d485b7ce51cbfd282e6bae8e019pbos@webrtc.org#include "testing/gtest/include/gtest/gtest.h"
14618a0ec1d2c17d485b7ce51cbfd282e6bae8e019pbos@webrtc.org
15618a0ec1d2c17d485b7ce51cbfd282e6bae8e019pbos@webrtc.orgnamespace webrtc {
16618a0ec1d2c17d485b7ce51cbfd282e6bae8e019pbos@webrtc.orgnamespace test {
17618a0ec1d2c17d485b7ce51cbfd282e6bae8e019pbos@webrtc.org
18618a0ec1d2c17d485b7ce51cbfd282e6bae8e019pbos@webrtc.orgFakeDecoder::FakeDecoder() : callback_(NULL) {}
19618a0ec1d2c17d485b7ce51cbfd282e6bae8e019pbos@webrtc.org
20618a0ec1d2c17d485b7ce51cbfd282e6bae8e019pbos@webrtc.orgint32_t FakeDecoder::InitDecode(const VideoCodec* config,
21618a0ec1d2c17d485b7ce51cbfd282e6bae8e019pbos@webrtc.org                                int32_t number_of_cores) {
22618a0ec1d2c17d485b7ce51cbfd282e6bae8e019pbos@webrtc.org  config_ = *config;
23618a0ec1d2c17d485b7ce51cbfd282e6bae8e019pbos@webrtc.org  size_t width = config->width;
24618a0ec1d2c17d485b7ce51cbfd282e6bae8e019pbos@webrtc.org  size_t height = config->height;
25618a0ec1d2c17d485b7ce51cbfd282e6bae8e019pbos@webrtc.org  frame_.CreateEmptyFrame(static_cast<int>(width),
26618a0ec1d2c17d485b7ce51cbfd282e6bae8e019pbos@webrtc.org                          static_cast<int>(height),
27618a0ec1d2c17d485b7ce51cbfd282e6bae8e019pbos@webrtc.org                          static_cast<int>(width),
28618a0ec1d2c17d485b7ce51cbfd282e6bae8e019pbos@webrtc.org                          static_cast<int>((width + 1) / 2),
29618a0ec1d2c17d485b7ce51cbfd282e6bae8e019pbos@webrtc.org                          static_cast<int>((width + 1) / 2));
30618a0ec1d2c17d485b7ce51cbfd282e6bae8e019pbos@webrtc.org  return WEBRTC_VIDEO_CODEC_OK;
31618a0ec1d2c17d485b7ce51cbfd282e6bae8e019pbos@webrtc.org}
32618a0ec1d2c17d485b7ce51cbfd282e6bae8e019pbos@webrtc.org
33618a0ec1d2c17d485b7ce51cbfd282e6bae8e019pbos@webrtc.orgint32_t FakeDecoder::Decode(const EncodedImage& input,
34618a0ec1d2c17d485b7ce51cbfd282e6bae8e019pbos@webrtc.org                            bool missing_frames,
35618a0ec1d2c17d485b7ce51cbfd282e6bae8e019pbos@webrtc.org                            const RTPFragmentationHeader* fragmentation,
36618a0ec1d2c17d485b7ce51cbfd282e6bae8e019pbos@webrtc.org                            const CodecSpecificInfo* codec_specific_info,
37618a0ec1d2c17d485b7ce51cbfd282e6bae8e019pbos@webrtc.org                            int64_t render_time_ms) {
38618a0ec1d2c17d485b7ce51cbfd282e6bae8e019pbos@webrtc.org  frame_.set_timestamp(input._timeStamp);
39093fc0b0b0b9ca4fe56a32e17c9c418382e802f0wu@webrtc.org  frame_.set_ntp_time_ms(input.ntp_time_ms_);
40618a0ec1d2c17d485b7ce51cbfd282e6bae8e019pbos@webrtc.org  frame_.set_render_time_ms(render_time_ms);
41618a0ec1d2c17d485b7ce51cbfd282e6bae8e019pbos@webrtc.org
42618a0ec1d2c17d485b7ce51cbfd282e6bae8e019pbos@webrtc.org  callback_->Decoded(frame_);
43618a0ec1d2c17d485b7ce51cbfd282e6bae8e019pbos@webrtc.org
44618a0ec1d2c17d485b7ce51cbfd282e6bae8e019pbos@webrtc.org  return WEBRTC_VIDEO_CODEC_OK;
45618a0ec1d2c17d485b7ce51cbfd282e6bae8e019pbos@webrtc.org}
46618a0ec1d2c17d485b7ce51cbfd282e6bae8e019pbos@webrtc.org
47618a0ec1d2c17d485b7ce51cbfd282e6bae8e019pbos@webrtc.orgint32_t FakeDecoder::RegisterDecodeCompleteCallback(
48618a0ec1d2c17d485b7ce51cbfd282e6bae8e019pbos@webrtc.org    DecodedImageCallback* callback) {
49618a0ec1d2c17d485b7ce51cbfd282e6bae8e019pbos@webrtc.org  callback_ = callback;
50618a0ec1d2c17d485b7ce51cbfd282e6bae8e019pbos@webrtc.org  return WEBRTC_VIDEO_CODEC_OK;
51618a0ec1d2c17d485b7ce51cbfd282e6bae8e019pbos@webrtc.org}
52618a0ec1d2c17d485b7ce51cbfd282e6bae8e019pbos@webrtc.org
53618a0ec1d2c17d485b7ce51cbfd282e6bae8e019pbos@webrtc.orgint32_t FakeDecoder::Release() {
54618a0ec1d2c17d485b7ce51cbfd282e6bae8e019pbos@webrtc.org  return WEBRTC_VIDEO_CODEC_OK;
55618a0ec1d2c17d485b7ce51cbfd282e6bae8e019pbos@webrtc.org}
56618a0ec1d2c17d485b7ce51cbfd282e6bae8e019pbos@webrtc.orgint32_t FakeDecoder::Reset() {
57618a0ec1d2c17d485b7ce51cbfd282e6bae8e019pbos@webrtc.org  return WEBRTC_VIDEO_CODEC_OK;
58618a0ec1d2c17d485b7ce51cbfd282e6bae8e019pbos@webrtc.org}
59618a0ec1d2c17d485b7ce51cbfd282e6bae8e019pbos@webrtc.org
60617e272fea14f31c0b32aa6c47afc81dbb65697bstefan@webrtc.orgint32_t FakeH264Decoder::Decode(const EncodedImage& input,
61617e272fea14f31c0b32aa6c47afc81dbb65697bstefan@webrtc.org                                bool missing_frames,
62617e272fea14f31c0b32aa6c47afc81dbb65697bstefan@webrtc.org                                const RTPFragmentationHeader* fragmentation,
63617e272fea14f31c0b32aa6c47afc81dbb65697bstefan@webrtc.org                                const CodecSpecificInfo* codec_specific_info,
64617e272fea14f31c0b32aa6c47afc81dbb65697bstefan@webrtc.org                                int64_t render_time_ms) {
65617e272fea14f31c0b32aa6c47afc81dbb65697bstefan@webrtc.org  uint8_t value = 0;
66617e272fea14f31c0b32aa6c47afc81dbb65697bstefan@webrtc.org  for (size_t i = 0; i < input._length; ++i) {
67617e272fea14f31c0b32aa6c47afc81dbb65697bstefan@webrtc.org    uint8_t kStartCode[] = {0, 0, 0, 1};
68617e272fea14f31c0b32aa6c47afc81dbb65697bstefan@webrtc.org    if (i < input._length - sizeof(kStartCode) &&
69617e272fea14f31c0b32aa6c47afc81dbb65697bstefan@webrtc.org        !memcmp(&input._buffer[i], kStartCode, sizeof(kStartCode))) {
70617e272fea14f31c0b32aa6c47afc81dbb65697bstefan@webrtc.org      i += sizeof(kStartCode) + 1;  // Skip start code and NAL header.
71617e272fea14f31c0b32aa6c47afc81dbb65697bstefan@webrtc.org    }
72617e272fea14f31c0b32aa6c47afc81dbb65697bstefan@webrtc.org    if (input._buffer[i] != value) {
73617e272fea14f31c0b32aa6c47afc81dbb65697bstefan@webrtc.org      EXPECT_EQ(value, input._buffer[i])
74617e272fea14f31c0b32aa6c47afc81dbb65697bstefan@webrtc.org          << "Bitstream mismatch between sender and receiver.";
75617e272fea14f31c0b32aa6c47afc81dbb65697bstefan@webrtc.org      return -1;
76617e272fea14f31c0b32aa6c47afc81dbb65697bstefan@webrtc.org    }
77617e272fea14f31c0b32aa6c47afc81dbb65697bstefan@webrtc.org    ++value;
78617e272fea14f31c0b32aa6c47afc81dbb65697bstefan@webrtc.org  }
79617e272fea14f31c0b32aa6c47afc81dbb65697bstefan@webrtc.org  return FakeDecoder::Decode(input,
80617e272fea14f31c0b32aa6c47afc81dbb65697bstefan@webrtc.org                             missing_frames,
81617e272fea14f31c0b32aa6c47afc81dbb65697bstefan@webrtc.org                             fragmentation,
82617e272fea14f31c0b32aa6c47afc81dbb65697bstefan@webrtc.org                             codec_specific_info,
83617e272fea14f31c0b32aa6c47afc81dbb65697bstefan@webrtc.org                             render_time_ms);
84617e272fea14f31c0b32aa6c47afc81dbb65697bstefan@webrtc.org}
85617e272fea14f31c0b32aa6c47afc81dbb65697bstefan@webrtc.org
86618a0ec1d2c17d485b7ce51cbfd282e6bae8e019pbos@webrtc.org}  // namespace test
87618a0ec1d2c17d485b7ce51cbfd282e6bae8e019pbos@webrtc.org}  // namespace webrtc
88