| 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 <memory> | 11 #include <memory> |
| 12 #include <queue> | 12 #include <queue> |
| 13 | 13 |
| 14 #include "base/mac/scoped_cftyperef.h" | 14 #include "base/mac/scoped_cftyperef.h" |
| 15 #include "base/macros.h" | 15 #include "base/macros.h" |
| 16 #include "base/memory/linked_ptr.h" | 16 #include "base/memory/linked_ptr.h" |
| 17 #include "base/memory/weak_ptr.h" | 17 #include "base/memory/weak_ptr.h" |
| 18 #include "base/message_loop/message_loop.h" | 18 #include "base/message_loop/message_loop.h" |
| 19 #include "base/threading/thread.h" | 19 #include "base/threading/thread.h" |
| 20 #include "base/threading/thread_checker.h" | 20 #include "base/threading/thread_checker.h" |
| 21 #include "content/common/gpu/media/gpu_video_decode_accelerator_helpers.h" | |
| 22 #include "content/common/gpu/media/vt_mac.h" | |
| 23 #include "media/filters/h264_parser.h" | 21 #include "media/filters/h264_parser.h" |
| 22 #include "media/gpu/gpu_video_decode_accelerator_helpers.h" |
| 23 #include "media/gpu/vt_mac.h" |
| 24 #include "media/video/h264_poc.h" | 24 #include "media/video/h264_poc.h" |
| 25 #include "media/video/video_decode_accelerator.h" | 25 #include "media/video/video_decode_accelerator.h" |
| 26 #include "ui/gfx/geometry/size.h" | 26 #include "ui/gfx/geometry/size.h" |
| 27 #include "ui/gl/gl_context_cgl.h" | 27 #include "ui/gl/gl_context_cgl.h" |
| 28 #include "ui/gl/gl_image_io_surface.h" | 28 #include "ui/gl/gl_image_io_surface.h" |
| 29 | 29 |
| 30 namespace content { | 30 namespace media { |
| 31 | 31 |
| 32 // Preload VideoToolbox libraries, needed for sandbox warmup. | 32 // Preload VideoToolbox libraries, needed for sandbox warmup. |
| 33 bool InitializeVideoToolbox(); | 33 bool InitializeVideoToolbox(); |
| 34 | 34 |
| 35 // VideoToolbox.framework implementation of the VideoDecodeAccelerator | 35 // VideoToolbox.framework implementation of the VideoDecodeAccelerator |
| 36 // interface for Mac OS X (currently limited to 10.9+). | 36 // interface for Mac OS X (currently limited to 10.9+). |
| 37 class VTVideoDecodeAccelerator : public media::VideoDecodeAccelerator { | 37 class VTVideoDecodeAccelerator : public media::VideoDecodeAccelerator { |
| 38 public: | 38 public: |
| 39 explicit VTVideoDecodeAccelerator( | 39 explicit VTVideoDecodeAccelerator( |
| 40 const MakeGLContextCurrentCallback& make_context_current_cb, | 40 const MakeGLContextCurrentCallback& make_context_current_cb, |
| 41 const BindGLImageCallback& bind_image_cb); | 41 const BindGLImageCallback& bind_image_cb); |
| 42 | 42 |
| 43 ~VTVideoDecodeAccelerator() override; | 43 ~VTVideoDecodeAccelerator() override; |
| 44 | 44 |
| 45 // VideoDecodeAccelerator implementation. | 45 // VideoDecodeAccelerator implementation. |
| 46 bool Initialize(const Config& config, Client* client) override; | 46 bool Initialize(const Config& config, Client* client) override; |
| 47 void Decode(const media::BitstreamBuffer& bitstream) override; | 47 void Decode(const media::BitstreamBuffer& bitstream) override; |
| 48 void AssignPictureBuffers( | 48 void AssignPictureBuffers( |
| 49 const std::vector<media::PictureBuffer>& pictures) override; | 49 const std::vector<media::PictureBuffer>& pictures) override; |
| 50 void ReusePictureBuffer(int32_t picture_id) override; | 50 void ReusePictureBuffer(int32_t picture_id) override; |
| 51 void Flush() override; | 51 void Flush() override; |
| 52 void Reset() override; | 52 void Reset() override; |
| 53 void Destroy() override; | 53 void Destroy() override; |
| 54 bool TryToSetupDecodeOnSeparateThread( | 54 bool TryToSetupDecodeOnSeparateThread( |
| 55 const base::WeakPtr<Client>& decode_client, | 55 const base::WeakPtr<Client>& decode_client, |
| 56 const scoped_refptr<base::SingleThreadTaskRunner>& decode_task_runner) | 56 const scoped_refptr<base::SingleThreadTaskRunner>& decode_task_runner) |
| 57 override; | 57 override; |
| 58 | 58 |
| 59 // Called by OutputThunk() when VideoToolbox finishes decoding a frame. | 59 // Called by OutputThunk() when VideoToolbox finishes decoding a frame. |
| 60 void Output( | 60 void Output(void* source_frame_refcon, |
| 61 void* source_frame_refcon, | 61 OSStatus status, |
| 62 OSStatus status, | 62 CVImageBufferRef image_buffer); |
| 63 CVImageBufferRef image_buffer); | |
| 64 | 63 |
| 65 static media::VideoDecodeAccelerator::SupportedProfiles | 64 static media::VideoDecodeAccelerator::SupportedProfiles |
| 66 GetSupportedProfiles(); | 65 GetSupportedProfiles(); |
| 67 | 66 |
| 68 private: | 67 private: |
| 69 // Logged to UMA, so never reuse values. Make sure to update | 68 // Logged to UMA, so never reuse values. Make sure to update |
| 70 // VTVDASessionFailureType in histograms.xml to match. | 69 // VTVDASessionFailureType in histograms.xml to match. |
| 71 enum VTVDASessionFailureType { | 70 enum VTVDASessionFailureType { |
| 72 SFT_SUCCESSFULLY_INITIALIZED = 0, | 71 SFT_SUCCESSFULLY_INITIALIZED = 0, |
| 73 SFT_PLATFORM_ERROR = 1, | 72 SFT_PLATFORM_ERROR = 1, |
| 74 SFT_INVALID_STREAM = 2, | 73 SFT_INVALID_STREAM = 2, |
| 75 SFT_UNSUPPORTED_STREAM_PARAMETERS = 3, | 74 SFT_UNSUPPORTED_STREAM_PARAMETERS = 3, |
| 76 SFT_DECODE_ERROR = 4, | 75 SFT_DECODE_ERROR = 4, |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 145 private: | 144 private: |
| 146 DISALLOW_COPY_AND_ASSIGN(PictureInfo); | 145 DISALLOW_COPY_AND_ASSIGN(PictureInfo); |
| 147 }; | 146 }; |
| 148 | 147 |
| 149 // | 148 // |
| 150 // Methods for interacting with VideoToolbox. Run on |decoder_thread_|. | 149 // Methods for interacting with VideoToolbox. Run on |decoder_thread_|. |
| 151 // | 150 // |
| 152 | 151 |
| 153 // Compute the |pic_order_cnt| for a frame. Returns true or calls | 152 // Compute the |pic_order_cnt| for a frame. Returns true or calls |
| 154 // NotifyError() before returning false. | 153 // NotifyError() before returning false. |
| 155 bool ComputePicOrderCnt( | 154 bool ComputePicOrderCnt(const media::H264SPS* sps, |
| 156 const media::H264SPS* sps, | 155 const media::H264SliceHeader& slice_hdr, |
| 157 const media::H264SliceHeader& slice_hdr, | 156 Frame* frame); |
| 158 Frame* frame); | |
| 159 | 157 |
| 160 // Set up VideoToolbox using the current SPS and PPS. Returns true or calls | 158 // Set up VideoToolbox using the current SPS and PPS. Returns true or calls |
| 161 // NotifyError() before returning false. | 159 // NotifyError() before returning false. |
| 162 bool ConfigureDecoder(); | 160 bool ConfigureDecoder(); |
| 163 | 161 |
| 164 // Wait for VideoToolbox to output all pending frames. Returns true or calls | 162 // Wait for VideoToolbox to output all pending frames. Returns true or calls |
| 165 // NotifyError() before returning false. | 163 // NotifyError() before returning false. |
| 166 bool FinishDelayedFrames(); | 164 bool FinishDelayedFrames(); |
| 167 | 165 |
| 168 // |frame| is owned by |pending_frames_|. | 166 // |frame| is owned by |pending_frames_|. |
| 169 void DecodeTask(const media::BitstreamBuffer&, Frame* frame); | 167 void DecodeTask(const media::BitstreamBuffer&, Frame* frame); |
| 170 void DecodeDone(Frame* frame); | 168 void DecodeDone(Frame* frame); |
| 171 | 169 |
| 172 // | 170 // |
| 173 // Methods for interacting with |client_|. Run on |gpu_task_runner_|. | 171 // Methods for interacting with |client_|. Run on |gpu_task_runner_|. |
| 174 // | 172 // |
| 175 void NotifyError( | 173 void NotifyError(Error vda_error_type, |
| 176 Error vda_error_type, | 174 VTVDASessionFailureType session_failure_type); |
| 177 VTVDASessionFailureType session_failure_type); | |
| 178 | 175 |
| 179 // |type| is the type of task that the flush will complete, one of TASK_FLUSH, | 176 // |type| is the type of task that the flush will complete, one of TASK_FLUSH, |
| 180 // TASK_RESET, or TASK_DESTROY. | 177 // TASK_RESET, or TASK_DESTROY. |
| 181 void QueueFlush(TaskType type); | 178 void QueueFlush(TaskType type); |
| 182 void FlushTask(TaskType type); | 179 void FlushTask(TaskType type); |
| 183 void FlushDone(TaskType type); | 180 void FlushDone(TaskType type); |
| 184 | 181 |
| 185 // Try to make progress on tasks in the |task_queue_| or sending frames in the | 182 // Try to make progress on tasks in the |task_queue_| or sending frames in the |
| 186 // |reorder_queue_|. | 183 // |reorder_queue_|. |
| 187 void ProcessWorkQueues(); | 184 void ProcessWorkQueues(); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 203 | 200 |
| 204 // Queue of pending flush tasks. This is used to drop frames when a reset | 201 // Queue of pending flush tasks. This is used to drop frames when a reset |
| 205 // is pending. | 202 // is pending. |
| 206 std::queue<TaskType> pending_flush_tasks_; | 203 std::queue<TaskType> pending_flush_tasks_; |
| 207 | 204 |
| 208 // Queue of tasks to complete in the GPU thread. | 205 // Queue of tasks to complete in the GPU thread. |
| 209 std::queue<Task> task_queue_; | 206 std::queue<Task> task_queue_; |
| 210 | 207 |
| 211 // Utility class to define the order of frames in the reorder queue. | 208 // Utility class to define the order of frames in the reorder queue. |
| 212 struct FrameOrder { | 209 struct FrameOrder { |
| 213 bool operator()( | 210 bool operator()(const linked_ptr<Frame>& lhs, |
| 214 const linked_ptr<Frame>& lhs, | 211 const linked_ptr<Frame>& rhs) const; |
| 215 const linked_ptr<Frame>& rhs) const; | |
| 216 }; | 212 }; |
| 217 | 213 |
| 218 // Queue of decoded frames in presentation order. | 214 // Queue of decoded frames in presentation order. |
| 219 std::priority_queue<linked_ptr<Frame>, | 215 std::priority_queue<linked_ptr<Frame>, |
| 220 std::vector<linked_ptr<Frame>>, | 216 std::vector<linked_ptr<Frame>>, |
| 221 FrameOrder> reorder_queue_; | 217 FrameOrder> |
| 218 reorder_queue_; |
| 222 | 219 |
| 223 // Size of assigned picture buffers. | 220 // Size of assigned picture buffers. |
| 224 gfx::Size picture_size_; | 221 gfx::Size picture_size_; |
| 225 | 222 |
| 226 // Frames that have not yet been decoded, keyed by bitstream ID; maintains | 223 // Frames that have not yet been decoded, keyed by bitstream ID; maintains |
| 227 // ownership of Frame objects while they flow through VideoToolbox. | 224 // ownership of Frame objects while they flow through VideoToolbox. |
| 228 std::map<int32_t, linked_ptr<Frame>> pending_frames_; | 225 std::map<int32_t, linked_ptr<Frame>> pending_frames_; |
| 229 | 226 |
| 230 // Set of assigned bitstream IDs, so that Destroy() can release them all. | 227 // Set of assigned bitstream IDs, so that Destroy() can release them all. |
| 231 std::set<int32_t> assigned_bitstream_ids_; | 228 std::set<int32_t> assigned_bitstream_ids_; |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 268 base::WeakPtr<VTVideoDecodeAccelerator> weak_this_; | 265 base::WeakPtr<VTVideoDecodeAccelerator> weak_this_; |
| 269 base::Thread decoder_thread_; | 266 base::Thread decoder_thread_; |
| 270 | 267 |
| 271 // Declared last to ensure that all weak pointers are invalidated before | 268 // Declared last to ensure that all weak pointers are invalidated before |
| 272 // other destructors run. | 269 // other destructors run. |
| 273 base::WeakPtrFactory<VTVideoDecodeAccelerator> weak_this_factory_; | 270 base::WeakPtrFactory<VTVideoDecodeAccelerator> weak_this_factory_; |
| 274 | 271 |
| 275 DISALLOW_COPY_AND_ASSIGN(VTVideoDecodeAccelerator); | 272 DISALLOW_COPY_AND_ASSIGN(VTVideoDecodeAccelerator); |
| 276 }; | 273 }; |
| 277 | 274 |
| 278 } // namespace content | 275 } // namespace media |
| 279 | 276 |
| 280 #endif // CONTENT_COMMON_GPU_MEDIA_VT_VIDEO_DECODE_ACCELERATOR_H_ | 277 #endif // CONTENT_COMMON_GPU_MEDIA_VT_VIDEO_DECODE_ACCELERATOR_H_ |
| OLD | NEW |