Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / third_party / webrtc / test / fake_decoder.cc
1 /*
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
11 #include "webrtc/test/fake_decoder.h"
12
13 #include "testing/gtest/include/gtest/gtest.h"
14
15 namespace webrtc {
16 namespace test {
17
18 FakeDecoder::FakeDecoder() : callback_(NULL) {}
19
20 int32_t FakeDecoder::InitDecode(const VideoCodec* config,
21                                 int32_t number_of_cores) {
22   config_ = *config;
23   size_t width = config->width;
24   size_t height = config->height;
25   frame_.CreateEmptyFrame(static_cast<int>(width),
26                           static_cast<int>(height),
27                           static_cast<int>(width),
28                           static_cast<int>((width + 1) / 2),
29                           static_cast<int>((width + 1) / 2));
30   return WEBRTC_VIDEO_CODEC_OK;
31 }
32
33 int32_t FakeDecoder::Decode(const EncodedImage& input,
34                             bool missing_frames,
35                             const RTPFragmentationHeader* fragmentation,
36                             const CodecSpecificInfo* codec_specific_info,
37                             int64_t render_time_ms) {
38   frame_.set_timestamp(input._timeStamp);
39   frame_.set_ntp_time_ms(input.ntp_time_ms_);
40   frame_.set_render_time_ms(render_time_ms);
41
42   callback_->Decoded(frame_);
43
44   return WEBRTC_VIDEO_CODEC_OK;
45 }
46
47 int32_t FakeDecoder::RegisterDecodeCompleteCallback(
48     DecodedImageCallback* callback) {
49   callback_ = callback;
50   return WEBRTC_VIDEO_CODEC_OK;
51 }
52
53 int32_t FakeDecoder::Release() {
54   return WEBRTC_VIDEO_CODEC_OK;
55 }
56 int32_t FakeDecoder::Reset() {
57   return WEBRTC_VIDEO_CODEC_OK;
58 }
59
60 int32_t FakeH264Decoder::Decode(const EncodedImage& input,
61                                 bool missing_frames,
62                                 const RTPFragmentationHeader* fragmentation,
63                                 const CodecSpecificInfo* codec_specific_info,
64                                 int64_t render_time_ms) {
65   uint8_t value = 0;
66   for (size_t i = 0; i < input._length; ++i) {
67     uint8_t kStartCode[] = {0, 0, 0, 1};
68     if (i < input._length - sizeof(kStartCode) &&
69         !memcmp(&input._buffer[i], kStartCode, sizeof(kStartCode))) {
70       i += sizeof(kStartCode) + 1;  // Skip start code and NAL header.
71     }
72     if (input._buffer[i] != value) {
73       EXPECT_EQ(value, input._buffer[i])
74           << "Bitstream mismatch between sender and receiver.";
75       return -1;
76     }
77     ++value;
78   }
79   return FakeDecoder::Decode(input,
80                              missing_frames,
81                              fragmentation,
82                              codec_specific_info,
83                              render_time_ms);
84 }
85
86 }  // namespace test
87 }  // namespace webrtc