Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / third_party / webrtc / test / configurable_frame_size_encoder.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/configurable_frame_size_encoder.h"
12
13 #include <string.h>
14
15 #include "webrtc/common_video/interface/video_image.h"
16 #include "testing/gtest/include/gtest/gtest.h"
17
18 namespace webrtc {
19 namespace test {
20
21 ConfigurableFrameSizeEncoder::ConfigurableFrameSizeEncoder(
22     uint32_t max_frame_size)
23     : callback_(NULL),
24       max_frame_size_(max_frame_size),
25       current_frame_size_(max_frame_size),
26       buffer_(new uint8_t[max_frame_size]) {
27   memset(buffer_.get(), 0, max_frame_size);
28 }
29
30 ConfigurableFrameSizeEncoder::~ConfigurableFrameSizeEncoder() {}
31
32 int32_t ConfigurableFrameSizeEncoder::InitEncode(
33     const VideoCodec* codec_settings,
34     int32_t number_of_cores,
35     uint32_t max_payload_size) {
36   return WEBRTC_VIDEO_CODEC_OK;
37 }
38
39 int32_t ConfigurableFrameSizeEncoder::Encode(
40     const I420VideoFrame& inputImage,
41     const CodecSpecificInfo* codecSpecificInfo,
42     const std::vector<VideoFrameType>* frame_types) {
43   EncodedImage encodedImage(
44       buffer_.get(), current_frame_size_, max_frame_size_);
45   encodedImage._completeFrame = true;
46   encodedImage._encodedHeight = inputImage.height();
47   encodedImage._encodedWidth = inputImage.width();
48   encodedImage._frameType = kKeyFrame;
49   encodedImage._timeStamp = inputImage.timestamp();
50   encodedImage.capture_time_ms_ = inputImage.render_time_ms();
51   RTPFragmentationHeader* fragmentation = NULL;
52   CodecSpecificInfo specific;
53   memset(&specific, 0, sizeof(specific));
54   callback_->Encoded(encodedImage, &specific, fragmentation);
55
56   return WEBRTC_VIDEO_CODEC_OK;
57 }
58
59 int32_t ConfigurableFrameSizeEncoder::RegisterEncodeCompleteCallback(
60     EncodedImageCallback* callback) {
61   callback_ = callback;
62   return WEBRTC_VIDEO_CODEC_OK;
63 }
64
65 int32_t ConfigurableFrameSizeEncoder::Release() {
66   return WEBRTC_VIDEO_CODEC_OK;
67 }
68
69 int32_t ConfigurableFrameSizeEncoder::SetChannelParameters(uint32_t packet_loss,
70                                                            int rtt) {
71   return WEBRTC_VIDEO_CODEC_OK;
72 }
73
74 int32_t ConfigurableFrameSizeEncoder::SetRates(uint32_t new_bit_rate,
75                                                uint32_t frame_rate) {
76   return WEBRTC_VIDEO_CODEC_OK;
77 }
78
79 int32_t ConfigurableFrameSizeEncoder::SetPeriodicKeyFrames(bool enable) {
80   return WEBRTC_VIDEO_CODEC_OK;
81 }
82
83 int32_t ConfigurableFrameSizeEncoder::CodecConfigParameters(uint8_t* buffer,
84                                                             int32_t size) {
85   return WEBRTC_VIDEO_CODEC_OK;
86 }
87
88 int32_t ConfigurableFrameSizeEncoder::SetFrameSize(uint32_t size) {
89   assert(size <= max_frame_size_);
90   current_frame_size_ = size;
91   return WEBRTC_VIDEO_CODEC_OK;
92 }
93
94 }  // namespace test
95 }  // namespace webrtc