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.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"
13 using media::BitstreamBuffer;
17 PlatformVideoDecoder::PlatformVideoDecoder(int32 command_buffer_route_id)
18 : command_buffer_route_id_(command_buffer_route_id) {}
20 PlatformVideoDecoder::~PlatformVideoDecoder() {}
22 bool PlatformVideoDecoder::Initialize(
23 media::VideoCodecProfile profile,
24 media::VideoDecodeAccelerator::Client* client) {
27 // TODO(vrk): Support multiple decoders.
31 RenderThreadImpl* render_thread = RenderThreadImpl::current();
33 // This is not synchronous, but subsequent IPC messages will be buffered, so
34 // it is okay to immediately send IPC messages through the returned channel.
35 GpuChannelHost* channel =
36 render_thread->EstablishGpuChannelSync(
37 CAUSE_FOR_GPU_LAUNCH_VIDEODECODEACCELERATOR_INITIALIZE);
42 // Send IPC message to initialize decoder in GPU process.
43 decoder_ = channel->CreateVideoDecoder(command_buffer_route_id_, profile);
44 return (decoder_ && decoder_->Initialize(profile, this));
47 void PlatformVideoDecoder::Decode(const BitstreamBuffer& bitstream_buffer) {
48 DCHECK(decoder_.get());
49 decoder_->Decode(bitstream_buffer);
52 void PlatformVideoDecoder::AssignPictureBuffers(
53 const std::vector<media::PictureBuffer>& buffers) {
54 DCHECK(decoder_.get());
55 decoder_->AssignPictureBuffers(buffers);
58 void PlatformVideoDecoder::ReusePictureBuffer(int32 picture_buffer_id) {
59 DCHECK(decoder_.get());
60 decoder_->ReusePictureBuffer(picture_buffer_id);
63 void PlatformVideoDecoder::Flush() {
64 DCHECK(decoder_.get());
68 void PlatformVideoDecoder::Reset() {
69 DCHECK(decoder_.get());
73 void PlatformVideoDecoder::Destroy() {
75 decoder_.release()->Destroy();
80 void PlatformVideoDecoder::NotifyError(
81 VideoDecodeAccelerator::Error error) {
82 DCHECK(RenderThreadImpl::current());
83 client_->NotifyError(error);
86 void PlatformVideoDecoder::ProvidePictureBuffers(
87 uint32 requested_num_of_buffers,
88 const gfx::Size& dimensions,
89 uint32 texture_target) {
90 DCHECK(RenderThreadImpl::current());
91 client_->ProvidePictureBuffers(requested_num_of_buffers, dimensions,
95 void PlatformVideoDecoder::DismissPictureBuffer(int32 picture_buffer_id) {
96 DCHECK(RenderThreadImpl::current());
97 client_->DismissPictureBuffer(picture_buffer_id);
100 void PlatformVideoDecoder::PictureReady(const media::Picture& picture) {
101 DCHECK(RenderThreadImpl::current());
102 client_->PictureReady(picture);
105 void PlatformVideoDecoder::NotifyInitializeDone() {
106 NOTREACHED() << "GpuVideoDecodeAcceleratorHost::Initialize is synchronous!";
109 void PlatformVideoDecoder::NotifyEndOfBitstreamBuffer(
110 int32 bitstream_buffer_id) {
111 DCHECK(RenderThreadImpl::current());
112 client_->NotifyEndOfBitstreamBuffer(bitstream_buffer_id);
115 void PlatformVideoDecoder::NotifyFlushDone() {
116 DCHECK(RenderThreadImpl::current());
117 client_->NotifyFlushDone();
120 void PlatformVideoDecoder::NotifyResetDone() {
121 DCHECK(RenderThreadImpl::current());
122 client_->NotifyResetDone();
125 } // namespace content