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.
5 #ifndef CONTENT_RENDERER_PEPPER_VIDEO_DECODER_SHIM_H_
6 #define CONTENT_RENDERER_PEPPER_VIDEO_DECODER_SHIM_H_
11 #include "base/basictypes.h"
12 #include "base/containers/hash_tables.h"
13 #include "base/memory/linked_ptr.h"
14 #include "base/memory/scoped_ptr.h"
15 #include "base/memory/weak_ptr.h"
16 #include "gpu/command_buffer/common/mailbox.h"
17 #include "media/base/video_decoder_config.h"
18 #include "media/video/video_decode_accelerator.h"
20 #include "ppapi/c/pp_codecs.h"
23 class SingleThreadTaskRunner
;
38 class ContextProviderWebContext
;
44 class PepperVideoDecoderHost
;
46 // This class is a shim to wrap a media::VideoDecoder so that it can be used
47 // by PepperVideoDecoderHost in place of a media::VideoDecodeAccelerator.
48 // This class should be constructed, used, and destructed on the main (render)
50 class VideoDecoderShim
: public media::VideoDecodeAccelerator
{
52 explicit VideoDecoderShim(PepperVideoDecoderHost
* host
);
53 ~VideoDecoderShim() override
;
55 // media::VideoDecodeAccelerator implementation.
56 bool Initialize(media::VideoCodecProfile profile
,
57 media::VideoDecodeAccelerator::Client
* client
) override
;
58 void Decode(const media::BitstreamBuffer
& bitstream_buffer
) override
;
59 void AssignPictureBuffers(
60 const std::vector
<media::PictureBuffer
>& buffers
) override
;
61 void ReusePictureBuffer(int32 picture_buffer_id
) override
;
62 void Flush() override
;
63 void Reset() override
;
64 void Destroy() override
;
78 void OnInitializeComplete(int32_t result
, uint32_t texture_pool_size
);
79 void OnDecodeComplete(int32_t result
, uint32_t decode_id
);
80 void OnOutputComplete(scoped_ptr
<PendingFrame
> frame
);
82 void OnResetComplete();
83 void NotifyCompletedDecodes();
84 void DismissTexture(uint32_t texture_id
);
85 void DeleteTexture(uint32_t texture_id
);
86 // Call this whenever we change GL state that the plugin relies on, such as
87 // creating picture textures.
88 void FlushCommandBuffer();
90 scoped_ptr
<DecoderImpl
> decoder_impl_
;
93 PepperVideoDecoderHost
* host_
;
94 scoped_refptr
<base::SingleThreadTaskRunner
> media_task_runner_
;
95 scoped_refptr
<webkit::gpu::ContextProviderWebContext
> context_provider_
;
97 // The current decoded frame size.
98 gfx::Size texture_size_
;
99 // Map that takes the plugin's GL texture id to the renderer's GL texture id.
100 typedef base::hash_map
<uint32_t, uint32_t> TextureIdMap
;
101 TextureIdMap texture_id_map_
;
102 // Available textures (these are plugin ids.)
103 typedef base::hash_set
<uint32_t> TextureIdSet
;
104 TextureIdSet available_textures_
;
105 // Track textures that are no longer needed (these are plugin ids.)
106 TextureIdSet textures_to_dismiss_
;
107 // Mailboxes for pending texture requests, to write to plugin's textures.
108 std::vector
<gpu::Mailbox
> pending_texture_mailboxes_
;
110 // Queue of completed decode ids, for notifying the host.
111 typedef std::queue
<uint32_t> CompletedDecodeQueue
;
112 CompletedDecodeQueue completed_decodes_
;
114 // Queue of decoded frames that have been converted to RGB and await upload to
116 typedef std::queue
<linked_ptr
<PendingFrame
> > PendingFrameQueue
;
117 PendingFrameQueue pending_frames_
;
119 // The optimal number of textures to allocate for decoder_impl_.
120 uint32_t texture_pool_size_
;
122 uint32_t num_pending_decodes_
;
124 base::WeakPtrFactory
<VideoDecoderShim
> weak_ptr_factory_
;
126 DISALLOW_COPY_AND_ASSIGN(VideoDecoderShim
);
129 } // namespace content
131 #endif // CONTENT_RENDERER_PEPPER_VIDEO_DECODER_SHIM_H_