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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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 |
75 int32_t bitstream_id; | 76 int32_t bitstream_id; |
76 base::ScopedCFTypeRef<CVImageBufferRef> image; | 77 // TODO(sandersd): Reorder window size. |
78 int32_t pic_order_cnt; | |
DaleCurtis
2014/11/14 21:11:45
Needs docs. It'd be nice for all of them too.
sandersd (OOO until July 31)
2014/11/14 21:28:52
Done.
| |
77 // TODO(sandersd): visible_rect. | 79 // TODO(sandersd): visible_rect. |
78 gfx::Size coded_size; | 80 gfx::Size coded_size; |
81 base::ScopedCFTypeRef<CVImageBufferRef> image; | |
79 }; | 82 }; |
80 | 83 |
81 struct Task { | 84 struct Task { |
82 Task(TaskType type); | 85 Task(TaskType type); |
83 ~Task(); | 86 ~Task(); |
84 | 87 |
85 TaskType type; | 88 TaskType type; |
86 linked_ptr<Frame> frame; | 89 linked_ptr<Frame> frame; |
87 }; | 90 }; |
88 | 91 |
89 // | 92 // |
90 // Methods for interacting with VideoToolbox. Run on |decoder_thread_|. | 93 // Methods for interacting with VideoToolbox. Run on |decoder_thread_|. |
91 // | 94 // |
95 | |
92 // Set up VideoToolbox using the current SPS and PPS. Returns true or calls | 96 // Set up VideoToolbox using the current SPS and PPS. Returns true or calls |
93 // NotifyError() before returning false. | 97 // NotifyError() before returning false. |
94 bool ConfigureDecoder(); | 98 bool ConfigureDecoder(); |
95 | 99 |
96 // Wait for VideoToolbox to output all pending frames. Returns true or calls | 100 // Wait for VideoToolbox to output all pending frames. Returns true or calls |
97 // NotifyError() before returning false. | 101 // NotifyError() before returning false. |
98 bool FinishDelayedFrames(); | 102 bool FinishDelayedFrames(); |
99 | 103 |
100 // |frame| is owned by |pending_frames_|. | 104 // |frame| is owned by |pending_frames_|. |
101 void DecodeTask(const media::BitstreamBuffer&, Frame* frame); | 105 void DecodeTask(const media::BitstreamBuffer&, Frame* frame); |
102 void DecodeDone(Frame* frame); | 106 void DecodeDone(Frame* frame); |
103 | 107 |
104 // | 108 // |
105 // Methods for interacting with |client_|. Run on |gpu_task_runner_|. | 109 // Methods for interacting with |client_|. Run on |gpu_task_runner_|. |
106 // | 110 // |
107 void NotifyError(Error error); | 111 void NotifyError(Error error); |
108 | 112 |
109 // |type| is the type of task that the flush will complete, one of TASK_FLUSH, | 113 // |type| is the type of task that the flush will complete, one of TASK_FLUSH, |
110 // TASK_RESET, or TASK_DESTROY. | 114 // TASK_RESET, or TASK_DESTROY. |
111 void QueueFlush(TaskType type); | 115 void QueueFlush(TaskType type); |
112 void FlushTask(TaskType type); | 116 void FlushTask(TaskType type); |
113 void FlushDone(TaskType type); | 117 void FlushDone(TaskType type); |
114 | 118 |
115 // Attempt to make progress on |pending_tasks_|. | 119 // Try to make progress on tasks in the |task_queue_| or sending frame in the |
116 void ProcessTasks(); | 120 // |reorder_queue_|. |
121 void ProcessWorkQueues(); | |
117 | 122 |
118 // These methods returns true if the task was completed, false if it couldn't | 123 // These methods returns true if the task was completed, false if it couldn't |
119 // be completed yet. | 124 // be completed yet. |
120 bool ProcessTask(const Task& task); | 125 bool ProcessTaskQueue(); |
126 bool ProcessReorderQueue(); | |
121 bool ProcessFrame(const Frame& frame); | 127 bool ProcessFrame(const Frame& frame); |
122 bool SendFrame(const Frame& frame); | 128 bool SendFrame(const Frame& frame); |
123 | 129 |
124 // | 130 // |
125 // GPU thread state. | 131 // GPU thread state. |
126 // | 132 // |
127 CGLContextObj cgl_context_; | 133 CGLContextObj cgl_context_; |
128 base::Callback<bool(void)> make_context_current_; | 134 base::Callback<bool(void)> make_context_current_; |
129 media::VideoDecodeAccelerator::Client* client_; | 135 media::VideoDecodeAccelerator::Client* client_; |
130 State state_; | 136 State state_; |
131 | 137 |
132 // Queue of pending flush tasks. This is used to drop frames when a reset | 138 // Queue of pending flush tasks. This is used to drop frames when a reset |
133 // is pending. | 139 // is pending. |
134 std::queue<TaskType> pending_flush_tasks_; | 140 std::queue<TaskType> pending_flush_tasks_; |
135 | 141 |
136 // Queue of tasks to complete in the GPU thread. | 142 // Queue of tasks to complete in the GPU thread. |
137 std::queue<Task> pending_tasks_; | 143 std::queue<Task> task_queue_; |
144 | |
145 // Utility class to define the order of frames in the reorder queue. | |
146 struct FrameOrder { | |
147 bool operator()( | |
148 const linked_ptr<Frame>& lhs, | |
149 const linked_ptr<Frame>& rhs) const; | |
150 }; | |
151 | |
152 // Queue of decoded frames in presentation order. | |
153 std::priority_queue<linked_ptr<Frame>, | |
154 std::vector<linked_ptr<Frame>>, | |
155 FrameOrder> reorder_queue_; | |
138 | 156 |
139 // Size of assigned picture buffers. | 157 // Size of assigned picture buffers. |
140 gfx::Size picture_size_; | 158 gfx::Size picture_size_; |
141 | 159 |
142 // Queue of frames that have not yet been decoded; maintains ownership of the | 160 // Queue of frames that have not yet been decoded; maintains ownership of the |
143 // Frame objects while they flow through VideoToolbox. | 161 // Frame objects while they flow through VideoToolbox. |
144 std::queue<linked_ptr<Frame>> pending_frames_; | 162 std::queue<linked_ptr<Frame>> pending_frames_; |
145 | 163 |
146 // Set of assigned bitstream IDs, so that Destroy() can release them all. | 164 // Set of assigned bitstream IDs, so that Destroy() can release them all. |
147 std::set<int32_t> assigned_bitstream_ids_; | 165 std::set<int32_t> assigned_bitstream_ids_; |
(...skipping 14 matching lines...) Expand all Loading... | |
162 | 180 |
163 // | 181 // |
164 // Decoder thread state. | 182 // Decoder thread state. |
165 // | 183 // |
166 VTDecompressionOutputCallbackRecord callback_; | 184 VTDecompressionOutputCallbackRecord callback_; |
167 base::ScopedCFTypeRef<CMFormatDescriptionRef> format_; | 185 base::ScopedCFTypeRef<CMFormatDescriptionRef> format_; |
168 base::ScopedCFTypeRef<VTDecompressionSessionRef> session_; | 186 base::ScopedCFTypeRef<VTDecompressionSessionRef> session_; |
169 media::H264Parser parser_; | 187 media::H264Parser parser_; |
170 gfx::Size coded_size_; | 188 gfx::Size coded_size_; |
171 | 189 |
190 int last_sps_id_; | |
172 std::vector<uint8_t> last_sps_; | 191 std::vector<uint8_t> last_sps_; |
173 std::vector<uint8_t> last_spsext_; | 192 std::vector<uint8_t> last_spsext_; |
193 int last_pps_id_; | |
174 std::vector<uint8_t> last_pps_; | 194 std::vector<uint8_t> last_pps_; |
175 | 195 |
176 // | 196 // |
177 // Shared state (set up and torn down on GPU thread). | 197 // Shared state (set up and torn down on GPU thread). |
178 // | 198 // |
179 base::ThreadChecker gpu_thread_checker_; | 199 base::ThreadChecker gpu_thread_checker_; |
180 scoped_refptr<base::SingleThreadTaskRunner> gpu_task_runner_; | 200 scoped_refptr<base::SingleThreadTaskRunner> gpu_task_runner_; |
181 | 201 |
182 // This WeakPtrFactory does not need to be last as its pointers are bound to | 202 // This WeakPtrFactory does not need to be last as its pointers are bound to |
183 // the same thread it is destructed on (the GPU thread). | 203 // the same thread it is destructed on (the GPU thread). |
184 base::WeakPtrFactory<VTVideoDecodeAccelerator> weak_this_factory_; | 204 base::WeakPtrFactory<VTVideoDecodeAccelerator> weak_this_factory_; |
185 | 205 |
186 // Declared last to ensure that all decoder thread tasks complete before any | 206 // Declared last to ensure that all decoder thread tasks complete before any |
187 // state is destructed. | 207 // state is destructed. |
188 base::Thread decoder_thread_; | 208 base::Thread decoder_thread_; |
189 | 209 |
190 DISALLOW_COPY_AND_ASSIGN(VTVideoDecodeAccelerator); | 210 DISALLOW_COPY_AND_ASSIGN(VTVideoDecodeAccelerator); |
191 }; | 211 }; |
192 | 212 |
193 } // namespace content | 213 } // namespace content |
194 | 214 |
195 #endif // CONTENT_COMMON_GPU_MEDIA_VT_VIDEO_DECODE_ACCELERATOR_H_ | 215 #endif // CONTENT_COMMON_GPU_MEDIA_VT_VIDEO_DECODE_ACCELERATOR_H_ |
OLD | NEW |