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

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

Powered by Google App Engine
This is Rietveld 408576698