Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / media / cast / test / fake_video_encode_accelerator.cc
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "media/cast/test/fake_video_encode_accelerator.h"
6
7 #include "base/logging.h"
8
9 namespace media {
10 namespace cast {
11 namespace test {
12
13 static const unsigned int kMinimumInputCount = 1;
14 static const size_t kMinimumOutputBufferSize = 123456;
15
16 FakeVideoEncodeAccelerator::FakeVideoEncodeAccelerator(
17     VideoEncodeAccelerator::Client* client)
18     : client_(client), first_(true) {
19   DCHECK(client);
20 }
21
22 FakeVideoEncodeAccelerator::~FakeVideoEncodeAccelerator() {}
23
24 void FakeVideoEncodeAccelerator::Initialize(
25     media::VideoFrame::Format input_format,
26     const gfx::Size& input_visible_size,
27     VideoCodecProfile output_profile,
28     uint32 initial_bitrate) {
29   DCHECK(client_);
30
31   if (output_profile != media::VP8PROFILE_MAIN &&
32       output_profile != media::H264PROFILE_MAIN) {
33     client_->NotifyError(kInvalidArgumentError);
34     return;
35   }
36   client_->NotifyInitializeDone();
37   client_->RequireBitstreamBuffers(
38       kMinimumInputCount, input_visible_size, kMinimumOutputBufferSize);
39 }
40
41 void FakeVideoEncodeAccelerator::Encode(const scoped_refptr<VideoFrame>& frame,
42                                         bool force_keyframe) {
43   DCHECK(client_);
44   DCHECK(!available_buffer_ids_.empty());
45
46   // Fake that we have encoded the frame; resulting in using the full output
47   // buffer.
48   int32 id = available_buffer_ids_.front();
49   available_buffer_ids_.pop_front();
50
51   bool is_key_fame = force_keyframe;
52   if (first_) {
53     is_key_fame = true;
54     first_ = false;
55   }
56   client_->BitstreamBufferReady(id, kMinimumOutputBufferSize, is_key_fame);
57 }
58
59 void FakeVideoEncodeAccelerator::UseOutputBitstreamBuffer(
60     const BitstreamBuffer& buffer) {
61   available_buffer_ids_.push_back(buffer.id());
62 }
63
64 void FakeVideoEncodeAccelerator::RequestEncodingParametersChange(
65     uint32 bitrate,
66     uint32 framerate) {
67   // No-op.
68 }
69
70 void FakeVideoEncodeAccelerator::Destroy() { delete this; }
71
72 }  // namespace test
73 }  // namespace cast
74 }  // namespace media