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> |
11 #include <queue> | 11 #include <queue> |
12 | 12 |
13 #include "base/mac/scoped_cftyperef.h" | 13 #include "base/mac/scoped_cftyperef.h" |
14 #include "base/memory/linked_ptr.h" | 14 #include "base/memory/linked_ptr.h" |
15 #include "base/memory/weak_ptr.h" | 15 #include "base/memory/weak_ptr.h" |
16 #include "base/message_loop/message_loop.h" | 16 #include "base/message_loop/message_loop.h" |
17 #include "base/threading/thread.h" | 17 #include "base/threading/thread.h" |
18 #include "base/threading/thread_checker.h" | 18 #include "base/threading/thread_checker.h" |
| 19 #include "content/common/gpu/media/h264_dpb.h" |
19 #include "content/common/gpu/media/vt.h" | 20 #include "content/common/gpu/media/vt.h" |
20 #include "media/filters/h264_parser.h" | 21 #include "media/filters/h264_parser.h" |
21 #include "media/video/video_decode_accelerator.h" | 22 #include "media/video/video_decode_accelerator.h" |
22 #include "ui/gfx/geometry/size.h" | 23 #include "ui/gfx/geometry/size.h" |
23 #include "ui/gl/gl_context_cgl.h" | 24 #include "ui/gl/gl_context_cgl.h" |
24 | 25 |
25 namespace base { | 26 namespace base { |
26 class SingleThreadTaskRunner; | 27 class SingleThreadTaskRunner; |
27 } // namespace base | 28 } // namespace base |
28 | 29 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 TASK_FRAME, | 66 TASK_FRAME, |
66 TASK_FLUSH, | 67 TASK_FLUSH, |
67 TASK_RESET, | 68 TASK_RESET, |
68 TASK_DESTROY, | 69 TASK_DESTROY, |
69 }; | 70 }; |
70 | 71 |
71 struct Frame { | 72 struct Frame { |
72 Frame(int32_t bitstream_id); | 73 Frame(int32_t bitstream_id); |
73 ~Frame(); | 74 ~Frame(); |
74 | 75 |
| 76 // ID of the bitstream buffer this Frame will be decoded from. |
75 int32_t bitstream_id; | 77 int32_t bitstream_id; |
76 base::ScopedCFTypeRef<CVImageBufferRef> image; | 78 |
| 79 // Relative presentation order of this frame (see AVC spec). |
| 80 // TODO(sandersd): Reorder window size. |
| 81 int32_t pic_order_cnt; |
| 82 |
| 83 // Size of the decoded frame. |
77 // TODO(sandersd): visible_rect. | 84 // TODO(sandersd): visible_rect. |
78 gfx::Size coded_size; | 85 gfx::Size coded_size; |
| 86 |
| 87 // VideoToolbox decoded image, if decoding was successful. |
| 88 base::ScopedCFTypeRef<CVImageBufferRef> image; |
79 }; | 89 }; |
80 | 90 |
81 struct Task { | 91 struct Task { |
82 Task(TaskType type); | 92 Task(TaskType type); |
83 ~Task(); | 93 ~Task(); |
84 | 94 |
85 TaskType type; | 95 TaskType type; |
86 linked_ptr<Frame> frame; | 96 linked_ptr<Frame> frame; |
87 }; | 97 }; |
88 | 98 |
89 // | 99 // |
90 // Methods for interacting with VideoToolbox. Run on |decoder_thread_|. | 100 // Methods for interacting with VideoToolbox. Run on |decoder_thread_|. |
91 // | 101 // |
| 102 |
92 // Set up VideoToolbox using the current SPS and PPS. Returns true or calls | 103 // Set up VideoToolbox using the current SPS and PPS. Returns true or calls |
93 // NotifyError() before returning false. | 104 // NotifyError() before returning false. |
94 bool ConfigureDecoder(); | 105 bool ConfigureDecoder(); |
95 | 106 |
96 // Wait for VideoToolbox to output all pending frames. Returns true or calls | 107 // Wait for VideoToolbox to output all pending frames. Returns true or calls |
97 // NotifyError() before returning false. | 108 // NotifyError() before returning false. |
98 bool FinishDelayedFrames(); | 109 bool FinishDelayedFrames(); |
99 | 110 |
100 // |frame| is owned by |pending_frames_|. | 111 // |frame| is owned by |pending_frames_|. |
101 void DecodeTask(const media::BitstreamBuffer&, Frame* frame); | 112 void DecodeTask(const media::BitstreamBuffer&, Frame* frame); |
102 void DecodeDone(Frame* frame); | 113 void DecodeDone(Frame* frame); |
103 | 114 |
104 // | 115 // |
105 // Methods for interacting with |client_|. Run on |gpu_task_runner_|. | 116 // Methods for interacting with |client_|. Run on |gpu_task_runner_|. |
106 // | 117 // |
107 void NotifyError(Error error); | 118 void NotifyError(Error error); |
108 | 119 |
109 // |type| is the type of task that the flush will complete, one of TASK_FLUSH, | 120 // |type| is the type of task that the flush will complete, one of TASK_FLUSH, |
110 // TASK_RESET, or TASK_DESTROY. | 121 // TASK_RESET, or TASK_DESTROY. |
111 void QueueFlush(TaskType type); | 122 void QueueFlush(TaskType type); |
112 void FlushTask(TaskType type); | 123 void FlushTask(TaskType type); |
113 void FlushDone(TaskType type); | 124 void FlushDone(TaskType type); |
114 | 125 |
115 // Attempt to make progress on |pending_tasks_|. | 126 // Try to make progress on tasks in the |task_queue_| or sending frames in the |
116 void ProcessTasks(); | 127 // |reorder_queue_|. |
| 128 void ProcessWorkQueues(); |
117 | 129 |
118 // These methods returns true if the task was completed, false if it couldn't | 130 // These methods returns true if a task was completed, false otherwise. |
119 // be completed yet. | 131 bool ProcessTaskQueue(); |
120 bool ProcessTask(const Task& task); | 132 bool ProcessReorderQueue(); |
121 bool ProcessFrame(const Frame& frame); | 133 bool ProcessFrame(const Frame& frame); |
122 bool SendFrame(const Frame& frame); | 134 bool SendFrame(const Frame& frame); |
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 State state_; | 142 State state_; |
131 | 143 |
132 // Queue of pending flush tasks. This is used to drop frames when a reset | 144 // Queue of pending flush tasks. This is used to drop frames when a reset |
133 // is pending. | 145 // is pending. |
134 std::queue<TaskType> pending_flush_tasks_; | 146 std::queue<TaskType> pending_flush_tasks_; |
135 | 147 |
136 // Queue of tasks to complete in the GPU thread. | 148 // Queue of tasks to complete in the GPU thread. |
137 std::queue<Task> pending_tasks_; | 149 std::queue<Task> task_queue_; |
| 150 |
| 151 // Utility class to define the order of frames in the reorder queue. |
| 152 struct FrameOrder { |
| 153 bool operator()( |
| 154 const linked_ptr<Frame>& lhs, |
| 155 const linked_ptr<Frame>& rhs) const; |
| 156 }; |
| 157 |
| 158 // Queue of decoded frames in presentation order. |
| 159 std::priority_queue<linked_ptr<Frame>, |
| 160 std::vector<linked_ptr<Frame>>, |
| 161 FrameOrder> reorder_queue_; |
138 | 162 |
139 // Size of assigned picture buffers. | 163 // Size of assigned picture buffers. |
140 gfx::Size picture_size_; | 164 gfx::Size picture_size_; |
141 | 165 |
142 // Queue of frames that have not yet been decoded; maintains ownership of the | 166 // Queue of frames that have not yet been decoded; maintains ownership of the |
143 // Frame objects while they flow through VideoToolbox. | 167 // Frame objects while they flow through VideoToolbox. |
144 std::queue<linked_ptr<Frame>> pending_frames_; | 168 std::queue<linked_ptr<Frame>> pending_frames_; |
145 | 169 |
146 // Set of assigned bitstream IDs, so that Destroy() can release them all. | 170 // Set of assigned bitstream IDs, so that Destroy() can release them all. |
147 std::set<int32_t> assigned_bitstream_ids_; | 171 std::set<int32_t> assigned_bitstream_ids_; |
(...skipping 14 matching lines...) Expand all Loading... |
162 | 186 |
163 // | 187 // |
164 // Decoder thread state. | 188 // Decoder thread state. |
165 // | 189 // |
166 VTDecompressionOutputCallbackRecord callback_; | 190 VTDecompressionOutputCallbackRecord callback_; |
167 base::ScopedCFTypeRef<CMFormatDescriptionRef> format_; | 191 base::ScopedCFTypeRef<CMFormatDescriptionRef> format_; |
168 base::ScopedCFTypeRef<VTDecompressionSessionRef> session_; | 192 base::ScopedCFTypeRef<VTDecompressionSessionRef> session_; |
169 media::H264Parser parser_; | 193 media::H264Parser parser_; |
170 gfx::Size coded_size_; | 194 gfx::Size coded_size_; |
171 | 195 |
| 196 int last_sps_id_; |
172 std::vector<uint8_t> last_sps_; | 197 std::vector<uint8_t> last_sps_; |
173 std::vector<uint8_t> last_spsext_; | 198 std::vector<uint8_t> last_spsext_; |
| 199 int last_pps_id_; |
174 std::vector<uint8_t> last_pps_; | 200 std::vector<uint8_t> last_pps_; |
175 | 201 |
176 // | 202 // |
177 // Shared state (set up and torn down on GPU thread). | 203 // Shared state (set up and torn down on GPU thread). |
178 // | 204 // |
179 scoped_refptr<base::SingleThreadTaskRunner> gpu_task_runner_; | 205 scoped_refptr<base::SingleThreadTaskRunner> gpu_task_runner_; |
180 base::ThreadChecker gpu_thread_checker_; | 206 base::ThreadChecker gpu_thread_checker_; |
181 base::WeakPtr<VTVideoDecodeAccelerator> weak_this_; | 207 base::WeakPtr<VTVideoDecodeAccelerator> weak_this_; |
182 base::Thread decoder_thread_; | 208 base::Thread decoder_thread_; |
183 | 209 |
184 // Declared last to ensure that all weak pointers are invalidated before | 210 // Declared last to ensure that all weak pointers are invalidated before |
185 // other destructors run. | 211 // other destructors run. |
186 base::WeakPtrFactory<VTVideoDecodeAccelerator> weak_this_factory_; | 212 base::WeakPtrFactory<VTVideoDecodeAccelerator> weak_this_factory_; |
187 | 213 |
188 DISALLOW_COPY_AND_ASSIGN(VTVideoDecodeAccelerator); | 214 DISALLOW_COPY_AND_ASSIGN(VTVideoDecodeAccelerator); |
189 }; | 215 }; |
190 | 216 |
191 } // namespace content | 217 } // namespace content |
192 | 218 |
193 #endif // CONTENT_COMMON_GPU_MEDIA_VT_VIDEO_DECODE_ACCELERATOR_H_ | 219 #endif // CONTENT_COMMON_GPU_MEDIA_VT_VIDEO_DECODE_ACCELERATOR_H_ |
OLD | NEW |