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.
5 #include "content/renderer/media/pepper_platform_video_decoder_impl.h"
8 #include "base/logging.h"
9 #include "content/common/child_process.h"
10 #include "content/common/gpu/client/gpu_channel_host.h"
11 #include "content/renderer/render_thread_impl.h"
13 using media::BitstreamBuffer
;
17 PlatformVideoDecoderImpl::PlatformVideoDecoderImpl(
18 VideoDecodeAccelerator::Client
* client
,
19 int32 command_buffer_route_id
)
21 command_buffer_route_id_(command_buffer_route_id
) {
25 PlatformVideoDecoderImpl::~PlatformVideoDecoderImpl() {}
27 bool PlatformVideoDecoderImpl::Initialize(media::VideoCodecProfile profile
) {
28 // TODO(vrk): Support multiple decoders.
32 RenderThreadImpl
* render_thread
= RenderThreadImpl::current();
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
);
43 DCHECK_EQ(channel
->state(), GpuChannelHost::kConnected
);
45 // Send IPC message to initialize decoder in GPU process.
46 decoder_
.reset(channel
->CreateVideoDecoder(
47 command_buffer_route_id_
, profile
, this));
48 return decoder_
.get() != NULL
;
51 void PlatformVideoDecoderImpl::Decode(const BitstreamBuffer
& bitstream_buffer
) {
52 DCHECK(decoder_
.get());
53 decoder_
->Decode(bitstream_buffer
);
56 void PlatformVideoDecoderImpl::AssignPictureBuffers(
57 const std::vector
<media::PictureBuffer
>& buffers
) {
58 DCHECK(decoder_
.get());
59 decoder_
->AssignPictureBuffers(buffers
);
62 void PlatformVideoDecoderImpl::ReusePictureBuffer(
63 int32 picture_buffer_id
) {
64 DCHECK(decoder_
.get());
65 decoder_
->ReusePictureBuffer(picture_buffer_id
);
68 void PlatformVideoDecoderImpl::Flush() {
69 DCHECK(decoder_
.get());
73 void PlatformVideoDecoderImpl::Reset() {
74 DCHECK(decoder_
.get());
78 void PlatformVideoDecoderImpl::Destroy() {
80 decoder_
.release()->Destroy();
85 void PlatformVideoDecoderImpl::NotifyError(
86 VideoDecodeAccelerator::Error error
) {
87 DCHECK(RenderThreadImpl::current());
88 client_
->NotifyError(error
);
91 void PlatformVideoDecoderImpl::ProvidePictureBuffers(
92 uint32 requested_num_of_buffers
,
93 const gfx::Size
& dimensions
,
94 uint32 texture_target
) {
95 DCHECK(RenderThreadImpl::current());
96 client_
->ProvidePictureBuffers(requested_num_of_buffers
, dimensions
,
100 void PlatformVideoDecoderImpl::DismissPictureBuffer(int32 picture_buffer_id
) {
101 DCHECK(RenderThreadImpl::current());
102 client_
->DismissPictureBuffer(picture_buffer_id
);
105 void PlatformVideoDecoderImpl::PictureReady(const media::Picture
& picture
) {
106 DCHECK(RenderThreadImpl::current());
107 client_
->PictureReady(picture
);
110 void PlatformVideoDecoderImpl::NotifyInitializeDone() {
111 NOTREACHED() << "GpuVideoDecodeAcceleratorHost::Initialize is synchronous!";
114 void PlatformVideoDecoderImpl::NotifyEndOfBitstreamBuffer(
115 int32 bitstream_buffer_id
) {
116 DCHECK(RenderThreadImpl::current());
117 client_
->NotifyEndOfBitstreamBuffer(bitstream_buffer_id
);
120 void PlatformVideoDecoderImpl::NotifyFlushDone() {
121 DCHECK(RenderThreadImpl::current());
122 client_
->NotifyFlushDone();
125 void PlatformVideoDecoderImpl::NotifyResetDone() {
126 DCHECK(RenderThreadImpl::current());
127 client_
->NotifyResetDone();
130 } // namespace content