Index: content/renderer/pepper/video_decoder_adapter.h |
diff --git a/content/renderer/pepper/video_decoder_adapter.h b/content/renderer/pepper/video_decoder_adapter.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..424770a3b674c251a8e02524bc7751a2f51966b1 |
--- /dev/null |
+++ b/content/renderer/pepper/video_decoder_adapter.h |
@@ -0,0 +1,164 @@ |
+// 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_ADAPTER_H_ |
+#define CONTENT_RENDERER_PEPPER_VIDEO_DECODER_ADAPTER_H_ |
+ |
+#include <queue> |
+#include <vector> |
+ |
+#include "base/basictypes.h" |
+#include "base/containers/hash_tables.h" |
+#include "base/memory/linked_ptr.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" |
dmichael (off chromium)
2014/06/06 17:24:01
nit: This could probably be a forward reference
bbudge
2014/06/07 00:31:09
Done.
|
+#include "media/base/video_decoder.h" |
+#include "media/base/video_decoder_config.h" |
dmichael (off chromium)
2014/06/06 17:24:00
nit: ditto (I think even by-value params can be fo
bbudge
2014/06/07 00:31:09
Can't, it's an enum. I was able to fwd decl VideoD
|
+ |
+#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. |
+// Instances should be constructed, used, and destructed on the main (render) |
+// thread. |
+class VideoDecoderAdapter { |
Ami GONE FROM CHROMIUM
2014/06/06 17:14:34
Pro-tip for the future: if you address all the com
Ami GONE FROM CHROMIUM
2014/06/06 17:14:34
I'll let you & dmichael make a final call here but
bbudge
2014/06/07 00:31:09
OK, how about VideoDecoderShim?
bbudge
2014/06/07 00:31:09
Sorry, I didn't realize that. Thanks for the pro-t
|
+ public: |
+ explicit VideoDecoderAdapter(PepperVideoDecoderHost* host); |
Ami GONE FROM CHROMIUM
2014/06/06 17:14:34
Why? Isn't it as simple as
SharedMemory shm(hand
bbudge
2014/06/07 00:31:09
The adapter class now implements media::VDA.
Done.
|
+ |
+ 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(); |
+ |
+ private: |
+ enum State { |
+ UNINITIALIZED, |
+ DECODING, |
+ FLUSHING, |
+ RESETTING, |
+ DESTROYED, |
+ }; |
+ |
+ struct PendingDecode; |
+ struct PendingFrame; |
+ |
+ // This class is constructed on the main (render) thread, but used and |
+ // destructed on the media thread. |
Ami GONE FROM CHROMIUM
2014/06/06 17:14:34
Comment should also say what this is for.
bbudge
2014/06/07 00:31:10
Done.
|
+ class Delegate { |
Ami GONE FROM CHROMIUM
2014/06/06 17:14:34
fwd-declare?
Ami GONE FROM CHROMIUM
2014/06/06 17:14:34
Delegate is used in chrome as a synonym for "Clien
bbudge
2014/06/07 00:31:09
Renamed to VideoDecoderShim::DecoderImpl.
bbudge
2014/06/07 00:31:10
Done.
|
+ public: |
+ explicit Delegate(const base::WeakPtr<VideoDecoderAdapter>& proxy); |
+ ~Delegate(); |
+ |
+ void Initialize(media::VideoDecoderConfig config); |
+ void Decode(uint32_t decode_id, scoped_refptr<media::DecoderBuffer> buffer); |
+ void Reset(); |
+ void Stop(); |
+ |
+ private: |
+ void OnPipelineStatus(media::PipelineStatus status); |
+ void OnDecodeComplete(uint32_t decode_id, |
+ media::VideoDecoder::Status status, |
+ const scoped_refptr<media::VideoFrame>& frame); |
+ void OnResetComplete(); |
+ |
+ base::WeakPtr<VideoDecoderAdapter> adapter_; |
Ami GONE FROM CHROMIUM
2014/06/06 17:14:33
My comment is about the weakptr's thread-binding,
dmichael (off chromium)
2014/06/06 17:24:01
I think Ami's prior comment here was that you shou
bbudge
2014/06/07 00:31:09
Done.
|
+ 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_; |
+ int max_pending_decodes_; |
+ int num_pending_decodes_; |
+ }; |
+ |
+ // Do not delete directly; use Destroy() or own it with a scoped_ptr, which |
+ // will Destroy() it properly by default. |
+ ~VideoDecoderAdapter(); |
+ |
+ void OnPipelineStatus(media::PipelineStatus status); |
+ void OnDecodeComplete(media::VideoDecoder::Status status, |
+ scoped_ptr<PendingFrame> frame); |
+ void SendPictures(); |
+ void OnResetComplete(); |
+ void DismissTexture(uint32_t texture_id); |
+ void DeleteTexture(uint32_t texture_id); |
+ // Call this whenever we change GL state that the plugin relies on, such as |
+ // creating picture textures. |
+ void FlushCommandBuffer(); |
+ |
+ 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 decoded frames that have been converted to RGB and await upload to |
+ // a GL texture. |
+ typedef std::queue<linked_ptr<PendingFrame> > PendingFrameQueue; |
+ PendingFrameQueue pending_frames_; |
+ // |num_pending_decodes_| is incremented when we call Decode, and decremented |
+ // when we receive a decoded frame. A VideoDecoder always returns a (possibly |
+ // empty) frame to signal completion. |
+ uint32_t num_pending_decodes_; |
+ |
+ base::WeakPtrFactory<VideoDecoderAdapter> weak_ptr_factory_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(VideoDecoderAdapter); |
+}; |
+ |
+} // namespace content |
+ |
+namespace base { |
+ |
+template <class T> |
+struct DefaultDeleter; |
+ |
+// Specialize DefaultDeleter so that scoped_ptr<content::VideoDecoderAdapter> |
+// always uses "Destroy()" instead of trying to use the destructor. |
+template <> |
+struct DefaultDeleter<content::VideoDecoderAdapter> { |
+ public: |
+ inline void operator()(void* video_decoder_adapter) const { |
+ static_cast<content::VideoDecoderAdapter*>(video_decoder_adapter) |
+ ->Destroy(); |
+ } |
+}; |
dmichael (off chromium)
2014/06/06 17:24:00
I still think you can get away without this for Vi
bbudge
2014/06/07 01:01:23
People who are right can harp. Done.
|
+ |
+} // namespace base |
+ |
+#endif // CONTENT_RENDERER_PEPPER_VIDEO_DECODER_ADAPTER_H_ |