- add sources.
[platform/framework/web/crosswalk.git] / src / content / renderer / media / pepper_platform_video_decoder.cc
1 // Copyright (c) 2012 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 "content/renderer/media/pepper_platform_video_decoder.h"
6
7 #include "base/bind.h"
8 #include "base/logging.h"
9 #include "content/child/child_process.h"
10 #include "content/common/gpu/client/gpu_channel_host.h"
11 #include "content/renderer/render_thread_impl.h"
12
13 using media::BitstreamBuffer;
14
15 namespace content {
16
17 PlatformVideoDecoder::PlatformVideoDecoder(
18     VideoDecodeAccelerator::Client* client,
19     int32 command_buffer_route_id)
20     : client_(client),
21       command_buffer_route_id_(command_buffer_route_id) {
22   DCHECK(client);
23 }
24
25 PlatformVideoDecoder::~PlatformVideoDecoder() {}
26
27 bool PlatformVideoDecoder::Initialize(media::VideoCodecProfile profile) {
28   // TODO(vrk): Support multiple decoders.
29   if (decoder_)
30     return true;
31
32   RenderThreadImpl* render_thread = RenderThreadImpl::current();
33
34   // This is not synchronous, but subsequent IPC messages will be buffered, so
35   // it is okay to immediately send IPC messages through the returned channel.
36   GpuChannelHost* channel =
37       render_thread->EstablishGpuChannelSync(
38           CAUSE_FOR_GPU_LAUNCH_VIDEODECODEACCELERATOR_INITIALIZE);
39
40   if (!channel)
41     return false;
42
43   // Send IPC message to initialize decoder in GPU process.
44   decoder_ =
45       channel->CreateVideoDecoder(command_buffer_route_id_, profile, this);
46   return decoder_.get() != NULL;
47 }
48
49 void PlatformVideoDecoder::Decode(const BitstreamBuffer& bitstream_buffer) {
50   DCHECK(decoder_.get());
51   decoder_->Decode(bitstream_buffer);
52 }
53
54 void PlatformVideoDecoder::AssignPictureBuffers(
55     const std::vector<media::PictureBuffer>& buffers) {
56   DCHECK(decoder_.get());
57   decoder_->AssignPictureBuffers(buffers);
58 }
59
60 void PlatformVideoDecoder::ReusePictureBuffer(int32 picture_buffer_id) {
61   DCHECK(decoder_.get());
62   decoder_->ReusePictureBuffer(picture_buffer_id);
63 }
64
65 void PlatformVideoDecoder::Flush() {
66   DCHECK(decoder_.get());
67   decoder_->Flush();
68 }
69
70 void PlatformVideoDecoder::Reset() {
71   DCHECK(decoder_.get());
72   decoder_->Reset();
73 }
74
75 void PlatformVideoDecoder::Destroy() {
76   if (decoder_)
77     decoder_.release()->Destroy();
78   client_ = NULL;
79   delete this;
80 }
81
82 void PlatformVideoDecoder::NotifyError(
83     VideoDecodeAccelerator::Error error) {
84   DCHECK(RenderThreadImpl::current());
85   client_->NotifyError(error);
86 }
87
88 void PlatformVideoDecoder::ProvidePictureBuffers(
89     uint32 requested_num_of_buffers,
90     const gfx::Size& dimensions,
91     uint32 texture_target) {
92   DCHECK(RenderThreadImpl::current());
93   client_->ProvidePictureBuffers(requested_num_of_buffers, dimensions,
94                                  texture_target);
95 }
96
97 void PlatformVideoDecoder::DismissPictureBuffer(int32 picture_buffer_id) {
98   DCHECK(RenderThreadImpl::current());
99   client_->DismissPictureBuffer(picture_buffer_id);
100 }
101
102 void PlatformVideoDecoder::PictureReady(const media::Picture& picture) {
103   DCHECK(RenderThreadImpl::current());
104   client_->PictureReady(picture);
105 }
106
107 void PlatformVideoDecoder::NotifyInitializeDone() {
108   NOTREACHED() << "GpuVideoDecodeAcceleratorHost::Initialize is synchronous!";
109 }
110
111 void PlatformVideoDecoder::NotifyEndOfBitstreamBuffer(
112   int32 bitstream_buffer_id) {
113   DCHECK(RenderThreadImpl::current());
114   client_->NotifyEndOfBitstreamBuffer(bitstream_buffer_id);
115 }
116
117 void PlatformVideoDecoder::NotifyFlushDone() {
118   DCHECK(RenderThreadImpl::current());
119   client_->NotifyFlushDone();
120 }
121
122 void PlatformVideoDecoder::NotifyResetDone() {
123   DCHECK(RenderThreadImpl::current());
124   client_->NotifyResetDone();
125 }
126
127 }  // namespace content