Upstream version 6.35.121.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     : client_(NULL), first_(true) {}
18
19 FakeVideoEncodeAccelerator::~FakeVideoEncodeAccelerator() {}
20
21 void FakeVideoEncodeAccelerator::Initialize(
22     media::VideoFrame::Format input_format,
23     const gfx::Size& input_visible_size,
24     VideoCodecProfile output_profile,
25     uint32 initial_bitrate,
26     Client* client) {
27   client_ = client;
28   if (output_profile != media::VP8PROFILE_MAIN &&
29       output_profile != media::H264PROFILE_MAIN) {
30     client_->NotifyError(kInvalidArgumentError);
31     return;
32   }
33   client_->NotifyInitializeDone();
34   client_->RequireBitstreamBuffers(
35       kMinimumInputCount, input_visible_size, kMinimumOutputBufferSize);
36 }
37
38 void FakeVideoEncodeAccelerator::Encode(const scoped_refptr<VideoFrame>& frame,
39                                         bool force_keyframe) {
40   DCHECK(client_);
41   DCHECK(!available_buffer_ids_.empty());
42
43   // Fake that we have encoded the frame; resulting in using the full output
44   // buffer.
45   int32 id = available_buffer_ids_.front();
46   available_buffer_ids_.pop_front();
47
48   bool is_key_fame = force_keyframe;
49   if (first_) {
50     is_key_fame = true;
51     first_ = false;
52   }
53   client_->BitstreamBufferReady(id, kMinimumOutputBufferSize, is_key_fame);
54 }
55
56 void FakeVideoEncodeAccelerator::UseOutputBitstreamBuffer(
57     const BitstreamBuffer& buffer) {
58   available_buffer_ids_.push_back(buffer.id());
59 }
60
61 void FakeVideoEncodeAccelerator::RequestEncodingParametersChange(
62     uint32 bitrate,
63     uint32 framerate) {
64   // No-op.
65 }
66
67 void FakeVideoEncodeAccelerator::Destroy() { delete this; }
68
69 }  // namespace test
70 }  // namespace cast
71 }  // namespace media