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