Chromium Code Reviews| Index: content/renderer/pepper/video_decoder_proxy.h |
| diff --git a/content/renderer/pepper/video_decoder_proxy.h b/content/renderer/pepper/video_decoder_proxy.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..06d1292aef614562b810e65f3ebb8513b4814c2c |
| --- /dev/null |
| +++ b/content/renderer/pepper/video_decoder_proxy.h |
| @@ -0,0 +1,174 @@ |
| +// Copyright (c) 2014 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef CONTENT_RENDERER_PEPPER_VIDEO_DECODER_PROXY_H_ |
| +#define CONTENT_RENDERER_PEPPER_VIDEO_DECODER_PROXY_H_ |
| + |
| +#include <queue> |
| +#include <vector> |
| + |
| +#include "base/basictypes.h" |
| +#include "base/containers/hash_tables.h" |
| +#include "base/memory/scoped_ptr.h" |
| +#include "base/memory/weak_ptr.h" |
| +#include "base/message_loop/message_loop_proxy.h" |
| +#include "gpu/command_buffer/common/mailbox.h" |
| +#include "media/base/decoder_buffer.h" |
| +#include "media/base/video_decoder.h" |
| +#include "media/base/video_decoder_config.h" |
| + |
| +#include "ppapi/c/pp_codecs.h" |
| + |
| +namespace gpu { |
| +namespace gles2 { |
| +class GLES2Interface; |
| +} |
| +} |
| + |
| +namespace webkit { |
| +namespace gpu { |
| +class ContextProviderWebContext; |
| +} |
| +} |
| + |
| +namespace content { |
| + |
| +class PepperVideoDecoderHost; |
| + |
| +// This class proxies calls to a media::VideoDecoder on the media thread. |
|
Ami GONE FROM CHROMIUM
2014/06/05 00:06:24
I think it is the case that this class is meant to
bbudge
2014/06/06 02:03:44
It would definitely simplify the host if this was
|
| +// Instances should be constructed, used, and destructed on the main (render) |
| +// thread. |
| +class VideoDecoderProxy { |
|
dmichael (off chromium)
2014/06/05 23:00:43
I can see why you used "Proxy", but I'm so used to
bbudge
2014/06/06 02:03:43
Adapter it is. Done.
|
| + public: |
| + explicit VideoDecoderProxy(PepperVideoDecoderHost* host); |
| + |
| + void Initialize(media::VideoCodecProfile profile); |
| + void Decode(uint32_t decode_id, const uint8_t* buffer, uint32_t size); |
| + void AssignTextures(const std::vector<uint32_t>& texture_ids); |
| + void RecycleTexture(uint32_t texture_id); |
| + void Flush(); |
| + void Reset(); |
| + void Destroy(); |
| + |
| + protected: |
|
Ami GONE FROM CHROMIUM
2014/06/05 00:06:24
why not private?
bbudge
2014/06/06 02:03:43
Done.
|
| + // Do not delete directly; use Destroy() or own it with a scoped_ptr, which |
| + // will Destroy() it properly by default. |
| + ~VideoDecoderProxy(); |
| + |
| + private: |
| + enum State { |
| + UNINITIALIZED, |
| + DECODING, |
| + FLUSHING, |
| + RESETTING, |
| + }; |
| + |
| + struct PendingDecode { |
| + PendingDecode(uint32_t decode_id, |
| + const scoped_refptr<media::DecoderBuffer>& buffer); |
| + ~PendingDecode(); |
| + |
| + uint32_t decode_id; |
|
Ami GONE FROM CHROMIUM
2014/06/05 00:06:24
Here and below, make const-able members const?
bbudge
2014/06/06 02:03:44
Done.
|
| + scoped_refptr<media::DecoderBuffer> buffer; |
| + }; |
| + |
| + struct PendingFrame { |
| + PendingFrame(uint32_t decode_id, const gfx::Size& size); |
| + ~PendingFrame(); |
| + |
| + uint32_t decode_id; |
| + gfx::Size size; |
| + std::vector<uint8_t> pixels; |
|
Ami GONE FROM CHROMIUM
2014/06/05 00:06:24
rgba_pixels ?
(or comment on their colorspace)
bbudge
2014/06/06 02:03:43
Changed to argb_pixels, to match the conversion fu
|
| + }; |
| + |
| + // This class is constructed on the main (render) thread, but used and |
| + // destructed on the media thread. |
| + class Delegate { |
|
Ami GONE FROM CHROMIUM
2014/06/05 00:06:24
optional: here and above, can fwd-declare inner cl
bbudge
2014/06/06 02:03:44
Done.
|
| + public: |
| + Delegate(const base::WeakPtr<VideoDecoderProxy>& proxy); |
|
Ami GONE FROM CHROMIUM
2014/06/05 00:06:24
explicit
bbudge
2014/06/06 02:03:43
Done.
|
| + ~Delegate(); |
|
Ami GONE FROM CHROMIUM
2014/06/05 00:06:24
private b/c Destroy?
bbudge
2014/06/06 02:03:43
Destroy is a misleading name here, since it doesn'
|
| + |
| + void Initialize(scoped_ptr<media::VideoDecoder> decoder, |
|
Ami GONE FROM CHROMIUM
2014/06/05 00:06:24
decoder seems like a strange thing to pass to Init
bbudge
2014/06/06 02:03:43
Yeah, that works out well. Thanks.
|
| + media::VideoDecoderConfig config); |
| + void ReceiveBuffer(uint32_t decode_id, |
|
Ami GONE FROM CHROMIUM
2014/06/05 00:06:24
I get that you want to distinguish between a calle
bbudge
2014/06/06 02:03:43
I eliminated the second method, and renamed this m
|
| + scoped_refptr<media::DecoderBuffer> buffer); |
| + void Decode(); |
| + void Reset(); |
| + void Destroy(); |
| + |
| + private: |
| + void OnPipelineStatus(media::PipelineStatus status); |
| + void ConvertFrame(uint32_t decode_id, |
|
Ami GONE FROM CHROMIUM
2014/06/05 00:06:24
"convert"? From what to what?
doco please (here a
bbudge
2014/06/06 02:03:43
I changed some other method names, and now OnDecod
|
| + media::VideoDecoder::Status status, |
| + const scoped_refptr<media::VideoFrame>& frame); |
| + void OnResetComplete(); |
| + |
| + base::WeakPtr<VideoDecoderProxy> proxy_; |
|
Ami GONE FROM CHROMIUM
2014/06/05 00:06:24
// Bound to main_message_loop_.
bbudge
2014/06/06 02:03:43
I don't understand this comment. I construct and d
|
| + scoped_ptr<media::VideoDecoder> decoder_; |
| + scoped_refptr<base::MessageLoopProxy> main_message_loop_; |
| + // Queue of decodes waiting for the decoder. |
| + typedef std::queue<PendingDecode> PendingDecodeQueue; |
| + PendingDecodeQueue pending_decodes_; |
| + }; |
| + |
| + void OnPipelineStatus(media::PipelineStatus status); |
| + void ReceiveFrame(media::VideoDecoder::Status status, |
| + scoped_ptr<PendingFrame> frame); |
| + void SendPictures(); |
| + void OnResetComplete(); |
| + void OnDestroyComplete(); |
|
Ami GONE FROM CHROMIUM
2014/06/05 00:06:24
Not implemented (and thank goodness, because what
bbudge
2014/06/06 02:03:43
Left over from previous patchset. Removed.
|
| + void DismissTexture(uint32_t texture_id); |
| + void DeleteTexture(uint32_t texture_id); |
| + void FlushCommandBuffer(); |
|
Ami GONE FROM CHROMIUM
2014/06/05 00:06:24
doco should say when it is required to call this (
bbudge
2014/06/06 02:03:43
Done.
|
| + |
| + scoped_ptr<Delegate> delegate_; |
| + State state_; |
| + |
| + PepperVideoDecoderHost* host_; |
| + scoped_refptr<base::MessageLoopProxy> media_message_loop_; |
| + scoped_refptr<webkit::gpu::ContextProviderWebContext> context_provider_; |
| + |
| + // The current decoded frame size. |
| + gfx::Size texture_size_; |
| + // Map that takes the plugin's GL texture id to the renderer's GL texture id. |
| + typedef base::hash_map<uint32_t, uint32_t> TextureIdMap; |
| + TextureIdMap texture_id_map_; |
| + // Available textures (these are plugin ids.) |
| + std::vector<uint32_t> available_textures_; |
| + // Track textures that are no longer needed (these are plugin ids.) |
| + typedef base::hash_set<uint32_t> TextureIdSet; |
| + TextureIdSet textures_to_dismiss_; |
| + // Mailboxes for pending texture requests, to write to plugin's textures. |
| + std::vector<gpu::Mailbox> pending_texture_mailboxes_; |
| + // Queue of pending decoded frames. These have been converted to RGB, and |
| + // await upload to a GL texture. |
| + typedef std::queue<PendingFrame*> PendingFrameQueue; |
|
Ami GONE FROM CHROMIUM
2014/06/05 00:06:24
y no queue<linked_ptr<PF> > ?
bbudge
2014/06/06 02:03:43
Good idea. Done.
|
| + PendingFrameQueue pending_frames_; |
| + uint32_t num_pending_decodes_; |
| + |
| + base::WeakPtrFactory<VideoDecoderProxy> weak_ptr_factory_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(VideoDecoderProxy); |
| +}; |
| + |
| +} // namespace content |
| + |
| +namespace base { |
| + |
| +template <class T> |
| +struct DefaultDeleter; |
| + |
| +// Specialize DefaultDeleter so that scoped_ptr<content::VideoDecoderProxy> |
| +// always uses "Destroy()" instead of trying to use the destructor. |
| +template <> |
| +struct DefaultDeleter<content::VideoDecoderProxy> { |
| + public: |
| + inline void operator()(void* video_decoder) const { |
| + static_cast<content::VideoDecoderProxy*>(video_decoder)->Destroy(); |
| + } |
| +}; |
|
dmichael (off chromium)
2014/06/05 23:00:43
(Note, if you are able to get rid of Destroy and j
bbudge
2014/06/06 02:03:43
I don't think it's possible for this class.
|
| + |
| +} // namespace base |
| + |
| +#endif // CONTENT_RENDERER_PEPPER_VIDEO_DECODER_PROXY_H_ |