Chromium Code Reviews| 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 enum Action { | |
|
Pawel Osciak
2014/09/25 01:27:29
Please document this and the class.
sandersd (OOO until July 31)
2014/09/25 19:18:53
Done.
| |
| 68 ACTION_FLUSH, | |
| 69 ACTION_RESET, | |
| 70 ACTION_DESTROY | |
| 71 }; | |
| 72 | |
| 73 struct PendingAction { | |
| 74 PendingAction(Action action, int32_t bitstream_id); | |
| 75 ~PendingAction(); | |
| 76 | |
| 77 Action action; | |
| 78 int32_t bitstream_id; | |
| 79 }; | |
| 80 | |
| 67 // Methods for interacting with VideoToolbox. Run on |decoder_thread_|. | 81 // Methods for interacting with VideoToolbox. Run on |decoder_thread_|. |
| 68 void ConfigureDecoder( | 82 void ConfigureDecoder( |
| 69 const std::vector<const uint8_t*>& nalu_data_ptrs, | 83 const std::vector<const uint8_t*>& nalu_data_ptrs, |
| 70 const std::vector<size_t>& nalu_data_sizes); | 84 const std::vector<size_t>& nalu_data_sizes); |
| 71 void DecodeTask(const media::BitstreamBuffer); | 85 void DecodeTask(const media::BitstreamBuffer); |
| 86 void FlushTask(); | |
| 72 | 87 |
| 73 // Methods for interacting with |client_|. Run on |gpu_task_runner_|. | 88 // Methods for interacting with |client_|. Run on |gpu_task_runner_|. |
| 74 void OutputTask(DecodedFrame frame); | 89 void OutputTask(DecodedFrame frame); |
| 75 void SizeChangedTask(gfx::Size coded_size); | 90 void SizeChangedTask(gfx::Size coded_size); |
| 76 void SendPictures(); | 91 |
| 92 // Send decoded frames up to and including |up_to_bitstream_id|, and return | |
| 93 // the last sent |bitstream_id|. | |
| 94 int32_t SendPictures(int32_t up_to_bitstream_id); | |
| 95 | |
| 96 void ProcessDecodedFrames(); | |
|
Pawel Osciak
2014/09/25 01:27:29
Please document.
sandersd (OOO until July 31)
2014/09/25 19:18:53
Done.
| |
| 97 void CompleteAction(Action action); | |
| 98 void CompleteActions(int32_t bitstream_id); | |
| 99 void QueueAction(Action action); | |
| 77 | 100 |
| 78 // | 101 // |
| 79 // GPU thread state. | 102 // GPU thread state. |
| 80 // | 103 // |
| 81 CGLContextObj cgl_context_; | 104 CGLContextObj cgl_context_; |
| 82 media::VideoDecodeAccelerator::Client* client_; | 105 media::VideoDecodeAccelerator::Client* client_; |
| 83 gfx::Size texture_size_; | 106 gfx::Size texture_size_; |
| 84 | 107 |
| 108 // Since VideoToolbox has no reset feature (only flush), and the VDA API | |
| 109 // allows Decode() and Flush() calls during a reset operation, it's possible | |
| 110 // to have multiple pending actions at once. We handle the fully general | |
| 111 // case of an arbitrary sequence of pending actions (in reality, there should | |
| 112 // probably be at most one reset and one flush at a time). | |
| 113 std::queue<PendingAction> pending_actions_; | |
| 114 std::queue<int32_t> pending_bitstream_ids_; | |
| 115 | |
| 85 // Texture IDs of pictures. | 116 // Texture IDs of pictures. |
| 86 // TODO(sandersd): A single map of structs holding picture data. | 117 // TODO(sandersd): A single map of structs holding picture data. |
| 87 std::map<int32_t, uint32_t> texture_ids_; | 118 std::map<int32_t, uint32_t> texture_ids_; |
| 88 | 119 |
| 89 // Pictures ready to be rendered to. | 120 // Pictures ready to be rendered to. |
| 90 std::queue<int32_t> available_picture_ids_; | 121 std::queue<int32_t> available_picture_ids_; |
| 91 | 122 |
| 92 // Decoded frames ready to render. | 123 // Decoded frames ready to render. |
| 93 std::queue<DecodedFrame> decoded_frames_; | 124 std::queue<DecodedFrame> decoded_frames_; |
| 94 | 125 |
| 95 // Image buffers kept alive while they are bound to pictures. | 126 // Image buffers kept alive while they are bound to pictures. |
| 96 std::map<int32_t, base::ScopedCFTypeRef<CVImageBufferRef>> picture_bindings_; | 127 std::map<int32_t, base::ScopedCFTypeRef<CVImageBufferRef>> picture_bindings_; |
| 97 | 128 |
| 98 // | 129 // |
| 99 // Decoder thread state. | 130 // Decoder thread state. |
| 100 // | 131 // |
| 101 VTDecompressionOutputCallbackRecord callback_; | 132 VTDecompressionOutputCallbackRecord callback_; |
| 102 base::ScopedCFTypeRef<CMFormatDescriptionRef> format_; | 133 base::ScopedCFTypeRef<CMFormatDescriptionRef> format_; |
| 103 base::ScopedCFTypeRef<VTDecompressionSessionRef> session_; | 134 base::ScopedCFTypeRef<VTDecompressionSessionRef> session_; |
| 104 media::H264Parser parser_; | 135 media::H264Parser parser_; |
| 105 gfx::Size coded_size_; | 136 gfx::Size coded_size_; |
| 106 | 137 |
| 107 // | 138 // |
| 108 // Unprotected shared state (set up and torn down on GPU thread). | 139 // Shared state (set up and torn down on GPU thread). |
| 109 // | 140 // |
| 110 scoped_refptr<base::SingleThreadTaskRunner> gpu_task_runner_; | 141 scoped_refptr<base::SingleThreadTaskRunner> gpu_task_runner_; |
| 111 | 142 |
| 112 // This WeakPtrFactory does not need to be last as its pointers are bound to | 143 // 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). | 144 // the same thread it is destructed on (the GPU thread). |
| 114 base::WeakPtrFactory<VTVideoDecodeAccelerator> weak_this_factory_; | 145 base::WeakPtrFactory<VTVideoDecodeAccelerator> weak_this_factory_; |
| 115 | 146 |
| 116 // Declared last to ensure that all decoder thread tasks complete before any | 147 // Declared last to ensure that all decoder thread tasks complete before any |
| 117 // state is destructed. | 148 // state is destructed. |
| 118 base::Thread decoder_thread_; | 149 base::Thread decoder_thread_; |
| 119 | 150 |
| 120 DISALLOW_COPY_AND_ASSIGN(VTVideoDecodeAccelerator); | 151 DISALLOW_COPY_AND_ASSIGN(VTVideoDecodeAccelerator); |
| 121 }; | 152 }; |
| 122 | 153 |
| 123 } // namespace content | 154 } // namespace content |
| 124 | 155 |
| 125 #endif // CONTENT_COMMON_GPU_MEDIA_VT_VIDEO_DECODE_ACCELERATOR_H_ | 156 #endif // CONTENT_COMMON_GPU_MEDIA_VT_VIDEO_DECODE_ACCELERATOR_H_ |
| OLD | NEW |