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