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