Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(96)

Side by Side Diff: content/renderer/pepper/video_decoder_proxy.h

Issue 311853005: Implement software fallback for PPB_VideoDecoder. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Use WeakPtr to tie VideoDecoderProxy and Delegate. Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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_PROXY_H_
6 #define CONTENT_RENDERER_PEPPER_VIDEO_DECODER_PROXY_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/scoped_ptr.h"
14 #include "base/memory/weak_ptr.h"
15 #include "base/message_loop/message_loop_proxy.h"
16 #include "gpu/command_buffer/common/mailbox.h"
17 #include "media/base/decoder_buffer.h"
18 #include "media/base/video_decoder.h"
19 #include "media/base/video_decoder_config.h"
20
21 #include "ppapi/c/pp_codecs.h"
22
23 namespace gpu {
24 namespace gles2 {
25 class GLES2Interface;
26 }
27 }
28
29 namespace webkit {
30 namespace gpu {
31 class ContextProviderWebContext;
32 }
33 }
34
35 namespace content {
36
37 class PepperVideoDecoderHost;
38
39 // 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
40 // Instances should be constructed, used, and destructed on the main (render)
41 // thread.
42 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.
43 public:
44 explicit VideoDecoderProxy(PepperVideoDecoderHost* host);
45
46 void Initialize(media::VideoCodecProfile profile);
47 void Decode(uint32_t decode_id, const uint8_t* buffer, uint32_t size);
48 void AssignTextures(const std::vector<uint32_t>& texture_ids);
49 void RecycleTexture(uint32_t texture_id);
50 void Flush();
51 void Reset();
52 void Destroy();
53
54 protected:
Ami GONE FROM CHROMIUM 2014/06/05 00:06:24 why not private?
bbudge 2014/06/06 02:03:43 Done.
55 // Do not delete directly; use Destroy() or own it with a scoped_ptr, which
56 // will Destroy() it properly by default.
57 ~VideoDecoderProxy();
58
59 private:
60 enum State {
61 UNINITIALIZED,
62 DECODING,
63 FLUSHING,
64 RESETTING,
65 };
66
67 struct PendingDecode {
68 PendingDecode(uint32_t decode_id,
69 const scoped_refptr<media::DecoderBuffer>& buffer);
70 ~PendingDecode();
71
72 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.
73 scoped_refptr<media::DecoderBuffer> buffer;
74 };
75
76 struct PendingFrame {
77 PendingFrame(uint32_t decode_id, const gfx::Size& size);
78 ~PendingFrame();
79
80 uint32_t decode_id;
81 gfx::Size size;
82 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
83 };
84
85 // This class is constructed on the main (render) thread, but used and
86 // destructed on the media thread.
87 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.
88 public:
89 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.
90 ~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'
91
92 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.
93 media::VideoDecoderConfig config);
94 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
95 scoped_refptr<media::DecoderBuffer> buffer);
96 void Decode();
97 void Reset();
98 void Destroy();
99
100 private:
101 void OnPipelineStatus(media::PipelineStatus status);
102 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
103 media::VideoDecoder::Status status,
104 const scoped_refptr<media::VideoFrame>& frame);
105 void OnResetComplete();
106
107 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
108 scoped_ptr<media::VideoDecoder> decoder_;
109 scoped_refptr<base::MessageLoopProxy> main_message_loop_;
110 // Queue of decodes waiting for the decoder.
111 typedef std::queue<PendingDecode> PendingDecodeQueue;
112 PendingDecodeQueue pending_decodes_;
113 };
114
115 void OnPipelineStatus(media::PipelineStatus status);
116 void ReceiveFrame(media::VideoDecoder::Status status,
117 scoped_ptr<PendingFrame> frame);
118 void SendPictures();
119 void OnResetComplete();
120 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.
121 void DismissTexture(uint32_t texture_id);
122 void DeleteTexture(uint32_t texture_id);
123 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.
124
125 scoped_ptr<Delegate> delegate_;
126 State state_;
127
128 PepperVideoDecoderHost* host_;
129 scoped_refptr<base::MessageLoopProxy> media_message_loop_;
130 scoped_refptr<webkit::gpu::ContextProviderWebContext> context_provider_;
131
132 // The current decoded frame size.
133 gfx::Size texture_size_;
134 // Map that takes the plugin's GL texture id to the renderer's GL texture id.
135 typedef base::hash_map<uint32_t, uint32_t> TextureIdMap;
136 TextureIdMap texture_id_map_;
137 // Available textures (these are plugin ids.)
138 std::vector<uint32_t> available_textures_;
139 // Track textures that are no longer needed (these are plugin ids.)
140 typedef base::hash_set<uint32_t> TextureIdSet;
141 TextureIdSet textures_to_dismiss_;
142 // Mailboxes for pending texture requests, to write to plugin's textures.
143 std::vector<gpu::Mailbox> pending_texture_mailboxes_;
144 // Queue of pending decoded frames. These have been converted to RGB, and
145 // await upload to a GL texture.
146 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.
147 PendingFrameQueue pending_frames_;
148 uint32_t num_pending_decodes_;
149
150 base::WeakPtrFactory<VideoDecoderProxy> weak_ptr_factory_;
151
152 DISALLOW_COPY_AND_ASSIGN(VideoDecoderProxy);
153 };
154
155 } // namespace content
156
157 namespace base {
158
159 template <class T>
160 struct DefaultDeleter;
161
162 // Specialize DefaultDeleter so that scoped_ptr<content::VideoDecoderProxy>
163 // always uses "Destroy()" instead of trying to use the destructor.
164 template <>
165 struct DefaultDeleter<content::VideoDecoderProxy> {
166 public:
167 inline void operator()(void* video_decoder) const {
168 static_cast<content::VideoDecoderProxy*>(video_decoder)->Destroy();
169 }
170 };
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.
171
172 } // namespace base
173
174 #endif // CONTENT_RENDERER_PEPPER_VIDEO_DECODER_PROXY_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698