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

Side by Side Diff: content/common/gpu/media/vt_video_decode_accelerator.h

Issue 1320893004: Mac Overlays: Enable h264 overlays (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add comment Created 5 years, 3 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CONTENT_COMMON_GPU_MEDIA_VT_VIDEO_DECODE_ACCELERATOR_H_ 5 #ifndef CONTENT_COMMON_GPU_MEDIA_VT_VIDEO_DECODE_ACCELERATOR_H_
6 #define CONTENT_COMMON_GPU_MEDIA_VT_VIDEO_DECODE_ACCELERATOR_H_ 6 #define CONTENT_COMMON_GPU_MEDIA_VT_VIDEO_DECODE_ACCELERATOR_H_
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <map> 10 #include <map>
11 #include <queue> 11 #include <queue>
12 12
13 #include "base/mac/scoped_cftyperef.h" 13 #include "base/mac/scoped_cftyperef.h"
14 #include "base/memory/linked_ptr.h" 14 #include "base/memory/linked_ptr.h"
15 #include "base/memory/weak_ptr.h" 15 #include "base/memory/weak_ptr.h"
16 #include "base/message_loop/message_loop.h" 16 #include "base/message_loop/message_loop.h"
17 #include "base/threading/thread.h" 17 #include "base/threading/thread.h"
18 #include "base/threading/thread_checker.h" 18 #include "base/threading/thread_checker.h"
19 #include "content/common/gpu/media/vt.h" 19 #include "content/common/gpu/media/vt.h"
20 #include "media/filters/h264_parser.h" 20 #include "media/filters/h264_parser.h"
21 #include "media/video/h264_poc.h" 21 #include "media/video/h264_poc.h"
22 #include "media/video/video_decode_accelerator.h" 22 #include "media/video/video_decode_accelerator.h"
23 #include "ui/gfx/geometry/size.h" 23 #include "ui/gfx/geometry/size.h"
24 #include "ui/gl/gl_context_cgl.h" 24 #include "ui/gl/gl_context_cgl.h"
25 #include "ui/gl/gl_image_io_surface.h"
25 26
26 namespace content { 27 namespace content {
27 28
28 // Preload VideoToolbox libraries, needed for sandbox warmup. 29 // Preload VideoToolbox libraries, needed for sandbox warmup.
29 bool InitializeVideoToolbox(); 30 bool InitializeVideoToolbox();
30 31
31 // VideoToolbox.framework implementation of the VideoDecodeAccelerator 32 // VideoToolbox.framework implementation of the VideoDecodeAccelerator
32 // interface for Mac OS X (currently limited to 10.9+). 33 // interface for Mac OS X (currently limited to 10.9+).
33 class VTVideoDecodeAccelerator : public media::VideoDecodeAccelerator { 34 class VTVideoDecodeAccelerator : public media::VideoDecodeAccelerator {
34 public: 35 public:
35 explicit VTVideoDecodeAccelerator( 36 explicit VTVideoDecodeAccelerator(
36 const base::Callback<bool(void)>& make_context_current); 37 const base::Callback<bool(void)>& make_context_current,
38 const base::Callback<void(uint32, uint32, scoped_refptr<gfx::GLImage>)>&
39 bind_image);
37 ~VTVideoDecodeAccelerator() override; 40 ~VTVideoDecodeAccelerator() override;
38 41
39 // VideoDecodeAccelerator implementation. 42 // VideoDecodeAccelerator implementation.
40 bool Initialize(media::VideoCodecProfile profile, Client* client) override; 43 bool Initialize(media::VideoCodecProfile profile, Client* client) override;
41 void Decode(const media::BitstreamBuffer& bitstream) override; 44 void Decode(const media::BitstreamBuffer& bitstream) override;
42 void AssignPictureBuffers( 45 void AssignPictureBuffers(
43 const std::vector<media::PictureBuffer>& pictures) override; 46 const std::vector<media::PictureBuffer>& pictures) override;
44 void ReusePictureBuffer(int32_t picture_id) override; 47 void ReusePictureBuffer(int32_t picture_id) override;
45 void Flush() override; 48 void Flush() override;
46 void Reset() override; 49 void Reset() override;
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 }; 109 };
107 110
108 struct Task { 111 struct Task {
109 Task(TaskType type); 112 Task(TaskType type);
110 ~Task(); 113 ~Task();
111 114
112 TaskType type; 115 TaskType type;
113 linked_ptr<Frame> frame; 116 linked_ptr<Frame> frame;
114 }; 117 };
115 118
119 struct PictureInfo {
120 PictureInfo(uint32_t client_texture_id, uint32_t service_texture_id);
121 ~PictureInfo();
122
123 // Image buffer, kept alive while they are bound to pictures.
124 base::ScopedCFTypeRef<CVImageBufferRef> cv_image;
125
126 // The GLImage representation of |cv_image|. This is kept around to ensure
127 // that Destroy is called on it before it hits its destructor (there is a
128 // DCHECK that requires this).
129 scoped_refptr<gfx::GLImageIOSurface> gl_image;
130
131 // Texture IDs for the image buffer.
132 const uint32_t client_texture_id;
133 const uint32_t service_texture_id;
134 };
135
116 // 136 //
117 // Methods for interacting with VideoToolbox. Run on |decoder_thread_|. 137 // Methods for interacting with VideoToolbox. Run on |decoder_thread_|.
118 // 138 //
119 139
120 // Compute the |pic_order_cnt| for a frame. Returns true or calls 140 // Compute the |pic_order_cnt| for a frame. Returns true or calls
121 // NotifyError() before returning false. 141 // NotifyError() before returning false.
122 bool ComputePicOrderCnt( 142 bool ComputePicOrderCnt(
123 const media::H264SPS* sps, 143 const media::H264SPS* sps,
124 const media::H264SliceHeader& slice_hdr, 144 const media::H264SliceHeader& slice_hdr,
125 Frame* frame); 145 Frame* frame);
(...skipping 30 matching lines...) Expand all
156 // These methods returns true if a task was completed, false otherwise. 176 // These methods returns true if a task was completed, false otherwise.
157 bool ProcessTaskQueue(); 177 bool ProcessTaskQueue();
158 bool ProcessReorderQueue(); 178 bool ProcessReorderQueue();
159 bool ProcessFrame(const Frame& frame); 179 bool ProcessFrame(const Frame& frame);
160 bool SendFrame(const Frame& frame); 180 bool SendFrame(const Frame& frame);
161 181
162 // 182 //
163 // GPU thread state. 183 // GPU thread state.
164 // 184 //
165 base::Callback<bool(void)> make_context_current_; 185 base::Callback<bool(void)> make_context_current_;
186 base::Callback<void(uint32, uint32, scoped_refptr<gfx::GLImage>)> bind_image_;
166 media::VideoDecodeAccelerator::Client* client_; 187 media::VideoDecodeAccelerator::Client* client_;
167 State state_; 188 State state_;
168 189
169 // Queue of pending flush tasks. This is used to drop frames when a reset 190 // Queue of pending flush tasks. This is used to drop frames when a reset
170 // is pending. 191 // is pending.
171 std::queue<TaskType> pending_flush_tasks_; 192 std::queue<TaskType> pending_flush_tasks_;
172 193
173 // Queue of tasks to complete in the GPU thread. 194 // Queue of tasks to complete in the GPU thread.
174 std::queue<Task> task_queue_; 195 std::queue<Task> task_queue_;
175 196
(...skipping 17 matching lines...) Expand all
193 std::map<int32_t, linked_ptr<Frame>> pending_frames_; 214 std::map<int32_t, linked_ptr<Frame>> pending_frames_;
194 215
195 // Set of assigned bitstream IDs, so that Destroy() can release them all. 216 // Set of assigned bitstream IDs, so that Destroy() can release them all.
196 std::set<int32_t> assigned_bitstream_ids_; 217 std::set<int32_t> assigned_bitstream_ids_;
197 218
198 // All picture buffers assigned to us. Used to check if reused picture buffers 219 // All picture buffers assigned to us. Used to check if reused picture buffers
199 // should be added back to the available list or released. (They are not 220 // should be added back to the available list or released. (They are not
200 // released immediately because we need the reuse event to free the binding.) 221 // released immediately because we need the reuse event to free the binding.)
201 std::set<int32_t> assigned_picture_ids_; 222 std::set<int32_t> assigned_picture_ids_;
202 223
203 // Texture IDs of assigned pictures. 224 // Texture IDs and image buffers of assigned pictures.
204 std::map<int32_t, uint32_t> texture_ids_; 225 std::map<int32_t, linked_ptr<PictureInfo>> picture_info_map_;
205 226
206 // Pictures ready to be rendered to. 227 // Pictures ready to be rendered to.
207 std::vector<int32_t> available_picture_ids_; 228 std::vector<int32_t> available_picture_ids_;
208 229
209 // Image buffers kept alive while they are bound to pictures.
210 std::map<int32_t, base::ScopedCFTypeRef<CVImageBufferRef>> picture_bindings_;
211
212 // 230 //
213 // Decoder thread state. 231 // Decoder thread state.
214 // 232 //
215 VTDecompressionOutputCallbackRecord callback_; 233 VTDecompressionOutputCallbackRecord callback_;
216 base::ScopedCFTypeRef<CMFormatDescriptionRef> format_; 234 base::ScopedCFTypeRef<CMFormatDescriptionRef> format_;
217 base::ScopedCFTypeRef<VTDecompressionSessionRef> session_; 235 base::ScopedCFTypeRef<VTDecompressionSessionRef> session_;
218 media::H264Parser parser_; 236 media::H264Parser parser_;
219 gfx::Size coded_size_; 237 gfx::Size coded_size_;
220 238
221 int last_sps_id_; 239 int last_sps_id_;
(...skipping 14 matching lines...) Expand all
236 // Declared last to ensure that all weak pointers are invalidated before 254 // Declared last to ensure that all weak pointers are invalidated before
237 // other destructors run. 255 // other destructors run.
238 base::WeakPtrFactory<VTVideoDecodeAccelerator> weak_this_factory_; 256 base::WeakPtrFactory<VTVideoDecodeAccelerator> weak_this_factory_;
239 257
240 DISALLOW_COPY_AND_ASSIGN(VTVideoDecodeAccelerator); 258 DISALLOW_COPY_AND_ASSIGN(VTVideoDecodeAccelerator);
241 }; 259 };
242 260
243 } // namespace content 261 } // namespace content
244 262
245 #endif // CONTENT_COMMON_GPU_MEDIA_VT_VIDEO_DECODE_ACCELERATOR_H_ 263 #endif // CONTENT_COMMON_GPU_MEDIA_VT_VIDEO_DECODE_ACCELERATOR_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698