OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 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. | |
4 | |
5 #ifndef CONTENT_RENDERER_PEPPER_VIDEO_DECODER_ADAPTER_H_ | |
6 #define CONTENT_RENDERER_PEPPER_VIDEO_DECODER_ADAPTER_H_ | |
7 | |
8 #include <queue> | |
9 #include <vector> | |
10 | |
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 "base/message_loop/message_loop_proxy.h" | |
17 #include "gpu/command_buffer/common/mailbox.h" | |
18 #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.
| |
19 #include "media/base/video_decoder.h" | |
20 #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
| |
21 | |
22 #include "ppapi/c/pp_codecs.h" | |
23 | |
24 namespace gpu { | |
25 namespace gles2 { | |
26 class GLES2Interface; | |
27 } | |
28 } | |
29 | |
30 namespace webkit { | |
31 namespace gpu { | |
32 class ContextProviderWebContext; | |
33 } | |
34 } | |
35 | |
36 namespace content { | |
37 | |
38 class PepperVideoDecoderHost; | |
39 | |
40 // This class proxies calls to a media::VideoDecoder on the media thread. | |
41 // Instances should be constructed, used, and destructed on the main (render) | |
42 // thread. | |
43 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
| |
44 public: | |
45 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.
| |
46 | |
47 void Initialize(media::VideoCodecProfile profile); | |
48 void Decode(uint32_t decode_id, const uint8_t* buffer, uint32_t size); | |
49 void AssignTextures(const std::vector<uint32_t>& texture_ids); | |
50 void RecycleTexture(uint32_t texture_id); | |
51 void Flush(); | |
52 void Reset(); | |
53 void Destroy(); | |
54 | |
55 private: | |
56 enum State { | |
57 UNINITIALIZED, | |
58 DECODING, | |
59 FLUSHING, | |
60 RESETTING, | |
61 DESTROYED, | |
62 }; | |
63 | |
64 struct PendingDecode; | |
65 struct PendingFrame; | |
66 | |
67 // This class is constructed on the main (render) thread, but used and | |
68 // 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.
| |
69 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.
| |
70 public: | |
71 explicit Delegate(const base::WeakPtr<VideoDecoderAdapter>& proxy); | |
72 ~Delegate(); | |
73 | |
74 void Initialize(media::VideoDecoderConfig config); | |
75 void Decode(uint32_t decode_id, scoped_refptr<media::DecoderBuffer> buffer); | |
76 void Reset(); | |
77 void Stop(); | |
78 | |
79 private: | |
80 void OnPipelineStatus(media::PipelineStatus status); | |
81 void OnDecodeComplete(uint32_t decode_id, | |
82 media::VideoDecoder::Status status, | |
83 const scoped_refptr<media::VideoFrame>& frame); | |
84 void OnResetComplete(); | |
85 | |
86 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.
| |
87 scoped_ptr<media::VideoDecoder> decoder_; | |
88 scoped_refptr<base::MessageLoopProxy> main_message_loop_; | |
89 // Queue of decodes waiting for the decoder. | |
90 typedef std::queue<PendingDecode> PendingDecodeQueue; | |
91 PendingDecodeQueue pending_decodes_; | |
92 int max_pending_decodes_; | |
93 int num_pending_decodes_; | |
94 }; | |
95 | |
96 // Do not delete directly; use Destroy() or own it with a scoped_ptr, which | |
97 // will Destroy() it properly by default. | |
98 ~VideoDecoderAdapter(); | |
99 | |
100 void OnPipelineStatus(media::PipelineStatus status); | |
101 void OnDecodeComplete(media::VideoDecoder::Status status, | |
102 scoped_ptr<PendingFrame> frame); | |
103 void SendPictures(); | |
104 void OnResetComplete(); | |
105 void DismissTexture(uint32_t texture_id); | |
106 void DeleteTexture(uint32_t texture_id); | |
107 // Call this whenever we change GL state that the plugin relies on, such as | |
108 // creating picture textures. | |
109 void FlushCommandBuffer(); | |
110 | |
111 scoped_ptr<Delegate> delegate_; | |
112 State state_; | |
113 | |
114 PepperVideoDecoderHost* host_; | |
115 scoped_refptr<base::MessageLoopProxy> media_message_loop_; | |
116 scoped_refptr<webkit::gpu::ContextProviderWebContext> context_provider_; | |
117 | |
118 // The current decoded frame size. | |
119 gfx::Size texture_size_; | |
120 // Map that takes the plugin's GL texture id to the renderer's GL texture id. | |
121 typedef base::hash_map<uint32_t, uint32_t> TextureIdMap; | |
122 TextureIdMap texture_id_map_; | |
123 // Available textures (these are plugin ids.) | |
124 std::vector<uint32_t> available_textures_; | |
125 // Track textures that are no longer needed (these are plugin ids.) | |
126 typedef base::hash_set<uint32_t> TextureIdSet; | |
127 TextureIdSet textures_to_dismiss_; | |
128 // Mailboxes for pending texture requests, to write to plugin's textures. | |
129 std::vector<gpu::Mailbox> pending_texture_mailboxes_; | |
130 // Queue of decoded frames that have been converted to RGB and await upload to | |
131 // a GL texture. | |
132 typedef std::queue<linked_ptr<PendingFrame> > PendingFrameQueue; | |
133 PendingFrameQueue pending_frames_; | |
134 // |num_pending_decodes_| is incremented when we call Decode, and decremented | |
135 // when we receive a decoded frame. A VideoDecoder always returns a (possibly | |
136 // empty) frame to signal completion. | |
137 uint32_t num_pending_decodes_; | |
138 | |
139 base::WeakPtrFactory<VideoDecoderAdapter> weak_ptr_factory_; | |
140 | |
141 DISALLOW_COPY_AND_ASSIGN(VideoDecoderAdapter); | |
142 }; | |
143 | |
144 } // namespace content | |
145 | |
146 namespace base { | |
147 | |
148 template <class T> | |
149 struct DefaultDeleter; | |
150 | |
151 // Specialize DefaultDeleter so that scoped_ptr<content::VideoDecoderAdapter> | |
152 // always uses "Destroy()" instead of trying to use the destructor. | |
153 template <> | |
154 struct DefaultDeleter<content::VideoDecoderAdapter> { | |
155 public: | |
156 inline void operator()(void* video_decoder_adapter) const { | |
157 static_cast<content::VideoDecoderAdapter*>(video_decoder_adapter) | |
158 ->Destroy(); | |
159 } | |
160 }; | |
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.
| |
161 | |
162 } // namespace base | |
163 | |
164 #endif // CONTENT_RENDERER_PEPPER_VIDEO_DECODER_ADAPTER_H_ | |
OLD | NEW |