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 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
85 // Methods for interacting with VideoToolbox. Run on |decoder_thread_|. | 85 // Methods for interacting with VideoToolbox. Run on |decoder_thread_|. |
86 bool ConfigureDecoder( | 86 bool ConfigureDecoder( |
87 const std::vector<const uint8_t*>& nalu_data_ptrs, | 87 const std::vector<const uint8_t*>& nalu_data_ptrs, |
88 const std::vector<size_t>& nalu_data_sizes); | 88 const std::vector<size_t>& nalu_data_sizes); |
89 void DecodeTask(const media::BitstreamBuffer&); | 89 void DecodeTask(const media::BitstreamBuffer&); |
90 void FlushTask(); | 90 void FlushTask(); |
91 void DropBitstream(int32_t bitstream_id); | 91 void DropBitstream(int32_t bitstream_id); |
92 | 92 |
93 // Methods for interacting with |client_|. Run on |gpu_task_runner_|. | 93 // Methods for interacting with |client_|. Run on |gpu_task_runner_|. |
94 void OutputTask(DecodedFrame frame); | 94 void OutputTask(DecodedFrame frame); |
95 void SizeChangedTask(gfx::Size coded_size); | |
96 void NotifyError(Error error); | 95 void NotifyError(Error error); |
97 | 96 |
98 // Send decoded frames up to and including |up_to_bitstream_id|, and return | 97 // Send decoded frames up to and including |up_to_bitstream_id|, and return |
99 // the last sent |bitstream_id|. | 98 // the last sent |bitstream_id|. |
100 int32_t SendPictures(int32_t up_to_bitstream_id); | 99 int32_t SendPictures(int32_t up_to_bitstream_id); |
101 | 100 |
| 101 // Internal helper for SendPictures(): Drop frames with no image data up to |
| 102 // a particular bitstream ID, so that if there is still a frame in the queue |
| 103 // when this function returns, it is guaranteed to have image data, and thus |
| 104 // it is time to set up the GPU context. Returns the last bitstream ID that |
| 105 // was dropped, or |last_sent_bitstream_id| if no frames were dropped. |
| 106 int32_t ProcessDroppedFrames( |
| 107 int32_t last_sent_bitstream_id, |
| 108 int32_t up_to_bitstream_id); |
| 109 |
| 110 // Internal helper for SendPictures(): Check if the next frame has a size |
| 111 // different from the current picture buffers, and request new ones if so. |
| 112 void ProcessSizeChangeIfNeeded(); |
| 113 |
102 // Since VideoToolbox has no reset feature (only flush), and the VDA API | 114 // Since VideoToolbox has no reset feature (only flush), and the VDA API |
103 // allows Decode() and Flush() calls during a reset operation, it's possible | 115 // allows Decode() and Flush() calls during a reset operation, it's possible |
104 // to have multiple pending actions at once. We handle the fully general case | 116 // to have multiple pending actions at once. We handle the fully general case |
105 // of an arbitrary sequence of pending actions (in reality, there should | 117 // of an arbitrary sequence of pending actions (in reality, there should |
106 // probably be at most one reset and one flush at a time). | 118 // probably be at most one reset and one flush at a time). |
107 void QueueAction(Action action); | 119 void QueueAction(Action action); |
108 | 120 |
109 // Process queued decoded frames, usually by sending them (unless there | 121 // Process queued decoded frames, usually by sending them (unless there |
110 // is a pending ACTION_RESET or ACTION_DESTROY, in which case they are | 122 // is a pending ACTION_RESET or ACTION_DESTROY, in which case they are |
111 // dropped), completing queued actions along the way. | 123 // dropped), completing queued actions along the way. |
112 void ProcessDecodedFrames(); | 124 void ProcessDecodedFrames(); |
113 | 125 |
114 // Complete a particular action, by eg. calling NotifyFlushDone(). | 126 // Complete a particular action, by eg. calling NotifyFlushDone(). |
115 // Warning: Deletes |this| if |action| is ACTION_DESTROY. | 127 // Warning: Deletes |this| if |action| is ACTION_DESTROY. |
116 void CompleteAction(Action action); | 128 void CompleteAction(Action action); |
117 | 129 |
118 // Complete all actions pending for a particular |bitstream_id|. | 130 // Complete all actions pending for a particular |bitstream_id|. |
119 // Warning: Do not call if there is a pending ACTION_DESTROY. | 131 // Warning: Do not call if there is a pending ACTION_DESTROY. |
120 void CompleteActions(int32_t bitstream_id); | 132 void CompleteActions(int32_t bitstream_id); |
121 | 133 |
122 // | 134 // |
123 // GPU thread state. | 135 // GPU thread state. |
124 // | 136 // |
125 CGLContextObj cgl_context_; | 137 CGLContextObj cgl_context_; |
126 base::Callback<bool(void)> make_context_current_; | 138 base::Callback<bool(void)> make_context_current_; |
127 media::VideoDecodeAccelerator::Client* client_; | 139 media::VideoDecodeAccelerator::Client* client_; |
128 bool has_error_; // client_->NotifyError() called. | 140 |
129 gfx::Size texture_size_; | 141 // client_->NotifyError() called. |
| 142 bool has_error_; |
| 143 |
| 144 // Size of assigned picture buffers. |
| 145 gfx::Size picture_size_; |
| 146 |
| 147 // Queue of actions so that we can quickly discover what the next action will |
| 148 // be; this is useful because we are dropping all frames when the next action |
| 149 // is ACTION_RESET or ACTION_DESTROY. |
130 std::queue<PendingAction> pending_actions_; | 150 std::queue<PendingAction> pending_actions_; |
| 151 |
| 152 // Queue of bitstreams that have not yet been decoded. This is mostly needed |
| 153 // to be sure we free them all in Destroy(). |
131 std::queue<int32_t> pending_bitstream_ids_; | 154 std::queue<int32_t> pending_bitstream_ids_; |
132 | 155 |
133 // Texture IDs of pictures. | 156 // All picture buffers assigned to us. Used to check if reused picture buffers |
134 // TODO(sandersd): A single map of structs holding picture data. | 157 // should be added back to the available list or released. (They are not |
| 158 // released immediately because we need the reuse event to free the binding.) |
| 159 std::set<int32_t> assigned_picture_ids_; |
| 160 |
| 161 // Texture IDs of assigned pictures. |
135 std::map<int32_t, uint32_t> texture_ids_; | 162 std::map<int32_t, uint32_t> texture_ids_; |
136 | 163 |
137 // Pictures ready to be rendered to. | 164 // Pictures ready to be rendered to. |
138 std::queue<int32_t> available_picture_ids_; | 165 std::vector<int32_t> available_picture_ids_; |
139 | 166 |
140 // Decoded frames ready to render. | 167 // Decoded frames ready to render. |
141 std::queue<DecodedFrame> decoded_frames_; | 168 std::queue<DecodedFrame> decoded_frames_; |
142 | 169 |
143 // Image buffers kept alive while they are bound to pictures. | 170 // Image buffers kept alive while they are bound to pictures. |
144 std::map<int32_t, base::ScopedCFTypeRef<CVImageBufferRef>> picture_bindings_; | 171 std::map<int32_t, base::ScopedCFTypeRef<CVImageBufferRef>> picture_bindings_; |
145 | 172 |
146 // | 173 // |
147 // Decoder thread state. | 174 // Decoder thread state. |
148 // | 175 // |
149 VTDecompressionOutputCallbackRecord callback_; | 176 VTDecompressionOutputCallbackRecord callback_; |
150 base::ScopedCFTypeRef<CMFormatDescriptionRef> format_; | 177 base::ScopedCFTypeRef<CMFormatDescriptionRef> format_; |
151 base::ScopedCFTypeRef<VTDecompressionSessionRef> session_; | 178 base::ScopedCFTypeRef<VTDecompressionSessionRef> session_; |
152 media::H264Parser parser_; | 179 media::H264Parser parser_; |
153 gfx::Size coded_size_; | 180 |
| 181 std::vector<uint8_t> last_sps_; |
| 182 std::vector<uint8_t> last_spsext_; |
| 183 std::vector<uint8_t> last_pps_; |
154 | 184 |
155 // | 185 // |
156 // Shared state (set up and torn down on GPU thread). | 186 // Shared state (set up and torn down on GPU thread). |
157 // | 187 // |
158 scoped_refptr<base::SingleThreadTaskRunner> gpu_task_runner_; | 188 scoped_refptr<base::SingleThreadTaskRunner> gpu_task_runner_; |
159 | 189 |
160 // This WeakPtrFactory does not need to be last as its pointers are bound to | 190 // This WeakPtrFactory does not need to be last as its pointers are bound to |
161 // the same thread it is destructed on (the GPU thread). | 191 // the same thread it is destructed on (the GPU thread). |
162 base::WeakPtrFactory<VTVideoDecodeAccelerator> weak_this_factory_; | 192 base::WeakPtrFactory<VTVideoDecodeAccelerator> weak_this_factory_; |
163 | 193 |
164 // Declared last to ensure that all decoder thread tasks complete before any | 194 // Declared last to ensure that all decoder thread tasks complete before any |
165 // state is destructed. | 195 // state is destructed. |
166 base::Thread decoder_thread_; | 196 base::Thread decoder_thread_; |
167 | 197 |
168 DISALLOW_COPY_AND_ASSIGN(VTVideoDecodeAccelerator); | 198 DISALLOW_COPY_AND_ASSIGN(VTVideoDecodeAccelerator); |
169 }; | 199 }; |
170 | 200 |
171 } // namespace content | 201 } // namespace content |
172 | 202 |
173 #endif // CONTENT_COMMON_GPU_MEDIA_VT_VIDEO_DECODE_ACCELERATOR_H_ | 203 #endif // CONTENT_COMMON_GPU_MEDIA_VT_VIDEO_DECODE_ACCELERATOR_H_ |
OLD | NEW |