| 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> |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 | 57 |
| 58 private: | 58 private: |
| 59 struct DecodedFrame { | 59 struct DecodedFrame { |
| 60 DecodedFrame(int32_t bitstream_id, CVImageBufferRef image_buffer); | 60 DecodedFrame(int32_t bitstream_id, CVImageBufferRef image_buffer); |
| 61 ~DecodedFrame(); | 61 ~DecodedFrame(); |
| 62 | 62 |
| 63 int32_t bitstream_id; | 63 int32_t bitstream_id; |
| 64 base::ScopedCFTypeRef<CVImageBufferRef> image_buffer; | 64 base::ScopedCFTypeRef<CVImageBufferRef> image_buffer; |
| 65 }; | 65 }; |
| 66 | 66 |
| 67 // Actions are the possible types of pending operations, which are queued |
| 68 // by Flush(), Reset(), and Destroy(). |
| 69 enum Action { |
| 70 ACTION_FLUSH, |
| 71 ACTION_RESET, |
| 72 ACTION_DESTROY |
| 73 }; |
| 74 |
| 75 // PendingActions contain the |bitstream_id| of a frame that, once decoded and |
| 76 // sent, a particular |action| should be completed at. |
| 77 struct PendingAction { |
| 78 PendingAction(Action action, int32_t bitstream_id); |
| 79 ~PendingAction(); |
| 80 |
| 81 Action action; |
| 82 int32_t bitstream_id; |
| 83 }; |
| 84 |
| 67 // Methods for interacting with VideoToolbox. Run on |decoder_thread_|. | 85 // Methods for interacting with VideoToolbox. Run on |decoder_thread_|. |
| 68 void ConfigureDecoder( | 86 void ConfigureDecoder( |
| 69 const std::vector<const uint8_t*>& nalu_data_ptrs, | 87 const std::vector<const uint8_t*>& nalu_data_ptrs, |
| 70 const std::vector<size_t>& nalu_data_sizes); | 88 const std::vector<size_t>& nalu_data_sizes); |
| 71 void DecodeTask(const media::BitstreamBuffer); | 89 void DecodeTask(const media::BitstreamBuffer); |
| 90 void FlushTask(); |
| 72 | 91 |
| 73 // Methods for interacting with |client_|. Run on |gpu_task_runner_|. | 92 // Methods for interacting with |client_|. Run on |gpu_task_runner_|. |
| 74 void OutputTask(DecodedFrame frame); | 93 void OutputTask(DecodedFrame frame); |
| 75 void SizeChangedTask(gfx::Size coded_size); | 94 void SizeChangedTask(gfx::Size coded_size); |
| 76 void SendPictures(); | 95 |
| 96 // Send decoded frames up to and including |up_to_bitstream_id|, and return |
| 97 // the last sent |bitstream_id|. |
| 98 int32_t SendPictures(int32_t up_to_bitstream_id); |
| 99 |
| 100 // Since VideoToolbox has no reset feature (only flush), and the VDA API |
| 101 // allows Decode() and Flush() calls during a reset operation, it's possible |
| 102 // to have multiple pending actions at once. We handle the fully general case |
| 103 // of an arbitrary sequence of pending actions (in reality, there should |
| 104 // probably be at most one reset and one flush at a time). |
| 105 void QueueAction(Action action); |
| 106 |
| 107 // Process queued decoded frames, usually by sending them (unless there |
| 108 // is a pending ACTION_RESET or ACTION_DESTROY, in which case they are |
| 109 // dropped), completing queued actions along the way. |
| 110 void ProcessDecodedFrames(); |
| 111 |
| 112 // Complete a particular action, by eg. calling NotifyFlushDone(). |
| 113 // Warning: Deletes |this| if |action| is ACTION_DESTROY. |
| 114 void CompleteAction(Action action); |
| 115 |
| 116 // Complete all actions pending for a particular |bitstream_id|. |
| 117 // Warning: Do not call if there is a pending ACTION_DESTROY. |
| 118 void CompleteActions(int32_t bitstream_id); |
| 77 | 119 |
| 78 // | 120 // |
| 79 // GPU thread state. | 121 // GPU thread state. |
| 80 // | 122 // |
| 81 CGLContextObj cgl_context_; | 123 CGLContextObj cgl_context_; |
| 82 media::VideoDecodeAccelerator::Client* client_; | 124 media::VideoDecodeAccelerator::Client* client_; |
| 83 gfx::Size texture_size_; | 125 gfx::Size texture_size_; |
| 126 std::queue<PendingAction> pending_actions_; |
| 127 std::queue<int32_t> pending_bitstream_ids_; |
| 84 | 128 |
| 85 // Texture IDs of pictures. | 129 // Texture IDs of pictures. |
| 86 // TODO(sandersd): A single map of structs holding picture data. | 130 // TODO(sandersd): A single map of structs holding picture data. |
| 87 std::map<int32_t, uint32_t> texture_ids_; | 131 std::map<int32_t, uint32_t> texture_ids_; |
| 88 | 132 |
| 89 // Pictures ready to be rendered to. | 133 // Pictures ready to be rendered to. |
| 90 std::queue<int32_t> available_picture_ids_; | 134 std::queue<int32_t> available_picture_ids_; |
| 91 | 135 |
| 92 // Decoded frames ready to render. | 136 // Decoded frames ready to render. |
| 93 std::queue<DecodedFrame> decoded_frames_; | 137 std::queue<DecodedFrame> decoded_frames_; |
| 94 | 138 |
| 95 // Image buffers kept alive while they are bound to pictures. | 139 // Image buffers kept alive while they are bound to pictures. |
| 96 std::map<int32_t, base::ScopedCFTypeRef<CVImageBufferRef>> picture_bindings_; | 140 std::map<int32_t, base::ScopedCFTypeRef<CVImageBufferRef>> picture_bindings_; |
| 97 | 141 |
| 98 // | 142 // |
| 99 // Decoder thread state. | 143 // Decoder thread state. |
| 100 // | 144 // |
| 101 VTDecompressionOutputCallbackRecord callback_; | 145 VTDecompressionOutputCallbackRecord callback_; |
| 102 base::ScopedCFTypeRef<CMFormatDescriptionRef> format_; | 146 base::ScopedCFTypeRef<CMFormatDescriptionRef> format_; |
| 103 base::ScopedCFTypeRef<VTDecompressionSessionRef> session_; | 147 base::ScopedCFTypeRef<VTDecompressionSessionRef> session_; |
| 104 media::H264Parser parser_; | 148 media::H264Parser parser_; |
| 105 gfx::Size coded_size_; | 149 gfx::Size coded_size_; |
| 106 | 150 |
| 107 // | 151 // |
| 108 // Unprotected shared state (set up and torn down on GPU thread). | 152 // Shared state (set up and torn down on GPU thread). |
| 109 // | 153 // |
| 110 scoped_refptr<base::SingleThreadTaskRunner> gpu_task_runner_; | 154 scoped_refptr<base::SingleThreadTaskRunner> gpu_task_runner_; |
| 111 | 155 |
| 112 // This WeakPtrFactory does not need to be last as its pointers are bound to | 156 // This WeakPtrFactory does not need to be last as its pointers are bound to |
| 113 // the same thread it is destructed on (the GPU thread). | 157 // the same thread it is destructed on (the GPU thread). |
| 114 base::WeakPtrFactory<VTVideoDecodeAccelerator> weak_this_factory_; | 158 base::WeakPtrFactory<VTVideoDecodeAccelerator> weak_this_factory_; |
| 115 | 159 |
| 116 // Declared last to ensure that all decoder thread tasks complete before any | 160 // Declared last to ensure that all decoder thread tasks complete before any |
| 117 // state is destructed. | 161 // state is destructed. |
| 118 base::Thread decoder_thread_; | 162 base::Thread decoder_thread_; |
| 119 | 163 |
| 120 DISALLOW_COPY_AND_ASSIGN(VTVideoDecodeAccelerator); | 164 DISALLOW_COPY_AND_ASSIGN(VTVideoDecodeAccelerator); |
| 121 }; | 165 }; |
| 122 | 166 |
| 123 } // namespace content | 167 } // namespace content |
| 124 | 168 |
| 125 #endif // CONTENT_COMMON_GPU_MEDIA_VT_VIDEO_DECODE_ACCELERATOR_H_ | 169 #endif // CONTENT_COMMON_GPU_MEDIA_VT_VIDEO_DECODE_ACCELERATOR_H_ |
| OLD | NEW |