Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(434)

Side by Side Diff: content/common/gpu/media/vt_video_decode_accelerator.cc

Issue 397883002: Implement actually decoding frames in VTVideoDecodeAccelerator. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address comments. Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 #include <CoreVideo/CoreVideo.h> 5 #include <CoreVideo/CoreVideo.h>
6 #include <OpenGL/CGLIOSurface.h> 6 #include <OpenGL/CGLIOSurface.h>
7 7
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/thread_task_runner_handle.h" 9 #include "base/thread_task_runner_handle.h"
10 #include "content/common/gpu/media/vt_video_decode_accelerator.h" 10 #include "content/common/gpu/media/vt_video_decode_accelerator.h"
11 #include "media/filters/h264_parser.h" 11 #include "media/filters/h264_parser.h"
12 12
13 using content_common_gpu_media::kModuleVt; 13 using content_common_gpu_media::kModuleVt;
14 using content_common_gpu_media::InitializeStubs; 14 using content_common_gpu_media::InitializeStubs;
15 using content_common_gpu_media::IsVtInitialized; 15 using content_common_gpu_media::IsVtInitialized;
16 using content_common_gpu_media::StubPathMap; 16 using content_common_gpu_media::StubPathMap;
17 17
18 namespace content { 18 namespace content {
19 19
20 // Size of length headers prepended to NALUs in MPEG-4 framing. (1, 2, or 4.) 20 // Size of NALU length headers in AVCC/MPEG-4 format (can be 1, 2, or 4).
21 static const int kNALUHeaderLength = 4; 21 static const int kNALUHeaderLength = 4;
22 22
23 // We only request 5 picture buffers from the client which are used to hold the
24 // decoded samples. These buffers are then reused when the client tells us that
25 // it is done with the buffer.
26 static const int kNumPictureBuffers = 5;
27
28 // FOURCC for YCBCR_422_APPLE.
29 // TODO(sandersd): RGBA option for 4:4:4 video.
30 static const int32_t kYCbCr422 = '2vuy';
31
23 // Route decoded frame callbacks back into the VTVideoDecodeAccelerator. 32 // Route decoded frame callbacks back into the VTVideoDecodeAccelerator.
24 static void OutputThunk( 33 static void OutputThunk(
25 void* decompression_output_refcon, 34 void* decompression_output_refcon,
26 void* source_frame_refcon, 35 void* source_frame_refcon,
27 OSStatus status, 36 OSStatus status,
28 VTDecodeInfoFlags info_flags, 37 VTDecodeInfoFlags info_flags,
29 CVImageBufferRef image_buffer, 38 CVImageBufferRef image_buffer,
30 CMTime presentation_time_stamp, 39 CMTime presentation_time_stamp,
31 CMTime presentation_duration) { 40 CMTime presentation_duration) {
41 // TODO(sandersd): Implement flush-before-delete to guarantee validity.
32 VTVideoDecodeAccelerator* vda = 42 VTVideoDecodeAccelerator* vda =
33 reinterpret_cast<VTVideoDecodeAccelerator*>(decompression_output_refcon); 43 reinterpret_cast<VTVideoDecodeAccelerator*>(decompression_output_refcon);
34 int32_t* bitstream_id_ptr = reinterpret_cast<int32_t*>(source_frame_refcon); 44 intptr_t bitstream_id = reinterpret_cast<intptr_t>(source_frame_refcon);
35 int32_t bitstream_id = *bitstream_id_ptr;
36 delete bitstream_id_ptr;
37 CFRetain(image_buffer);
38 vda->Output(bitstream_id, status, info_flags, image_buffer); 45 vda->Output(bitstream_id, status, info_flags, image_buffer);
39 } 46 }
40 47
48 VTVideoDecodeAccelerator::DecodedFrame::DecodedFrame(
49 uint32_t bitstream_id,
50 CVImageBufferRef image_buffer)
51 : bitstream_id(bitstream_id),
52 image_buffer(image_buffer) {
53 }
54
55 VTVideoDecodeAccelerator::DecodedFrame::~DecodedFrame() {
56 }
57
41 VTVideoDecodeAccelerator::VTVideoDecodeAccelerator(CGLContextObj cgl_context) 58 VTVideoDecodeAccelerator::VTVideoDecodeAccelerator(CGLContextObj cgl_context)
42 : cgl_context_(cgl_context), 59 : cgl_context_(cgl_context),
43 client_(NULL),
44 decoder_thread_("VTDecoderThread"),
45 format_(NULL), 60 format_(NULL),
46 session_(NULL), 61 session_(NULL),
47 weak_this_factory_(this) { 62 frames_pending_decode_(0),
scherkus (not reviewing) 2014/07/17 02:08:26 can you remove this for this CL and add it back in
sandersd (OOO until July 31) 2014/07/17 20:31:46 Done.
63 gpu_task_runner_(base::ThreadTaskRunnerHandle::Get()),
64 weak_this_factory_(this),
65 decoder_thread_("VTDecoderThread") {
48 callback_.decompressionOutputCallback = OutputThunk; 66 callback_.decompressionOutputCallback = OutputThunk;
49 callback_.decompressionOutputRefCon = this; 67 callback_.decompressionOutputRefCon = this;
50 } 68 }
51 69
52 VTVideoDecodeAccelerator::~VTVideoDecodeAccelerator() { 70 VTVideoDecodeAccelerator::~VTVideoDecodeAccelerator() {
53 } 71 }
54 72
55 bool VTVideoDecodeAccelerator::Initialize( 73 bool VTVideoDecodeAccelerator::Initialize(
56 media::VideoCodecProfile profile, 74 media::VideoCodecProfile profile,
57 Client* client) { 75 Client* client) {
58 DCHECK(CalledOnValidThread()); 76 DCHECK(CalledOnValidThread());
59 client_ = client; 77
78 weak_client_factory_.reset(
79 new base::WeakPtrFactory<media::VideoDecodeAccelerator::Client>(client));
60 80
61 // Only H.264 is supported. 81 // Only H.264 is supported.
62 if (profile < media::H264PROFILE_MIN || profile > media::H264PROFILE_MAX) 82 if (profile < media::H264PROFILE_MIN || profile > media::H264PROFILE_MAX)
63 return false; 83 return false;
64 84
65 // TODO(sandersd): Move VideoToolbox library loading to sandbox startup; 85 // TODO(sandersd): Move VideoToolbox library loading to sandbox startup;
66 // until then, --no-sandbox is required. 86 // until then, --no-sandbox is required.
67 if (!IsVtInitialized()) { 87 if (!IsVtInitialized()) {
68 StubPathMap paths; 88 StubPathMap paths;
69 // CoreVideo is also required, but the loader stops after the first 89 // CoreVideo is also required, but the loader stops after the first
(...skipping 11 matching lines...) Expand all
81 return false; 101 return false;
82 102
83 // Note that --ignore-gpu-blacklist is still required to get here. 103 // Note that --ignore-gpu-blacklist is still required to get here.
84 return true; 104 return true;
85 } 105 }
86 106
87 // TODO(sandersd): Proper error reporting instead of CHECKs. 107 // TODO(sandersd): Proper error reporting instead of CHECKs.
88 void VTVideoDecodeAccelerator::ConfigureDecoder( 108 void VTVideoDecodeAccelerator::ConfigureDecoder(
89 const std::vector<const uint8_t*>& nalu_data_ptrs, 109 const std::vector<const uint8_t*>& nalu_data_ptrs,
90 const std::vector<size_t>& nalu_data_sizes) { 110 const std::vector<size_t>& nalu_data_sizes) {
111 DCHECK(decoder_thread_.message_loop_proxy()->BelongsToCurrentThread());
112 // Construct a new format description from the parameter sets.
113 // TODO(sandersd): Replace this with custom code to support OS X < 10.9.
91 format_.reset(); 114 format_.reset();
92 CHECK(!CMVideoFormatDescriptionCreateFromH264ParameterSets( 115 CHECK(!CMVideoFormatDescriptionCreateFromH264ParameterSets(
93 kCFAllocatorDefault, 116 kCFAllocatorDefault,
94 nalu_data_ptrs.size(), // parameter_set_count 117 nalu_data_ptrs.size(), // parameter_set_count
95 &nalu_data_ptrs.front(), // &parameter_set_pointers 118 &nalu_data_ptrs.front(), // &parameter_set_pointers
96 &nalu_data_sizes.front(), // &parameter_set_sizes 119 &nalu_data_sizes.front(), // &parameter_set_sizes
97 kNALUHeaderLength, // nal_unit_header_length 120 kNALUHeaderLength, // nal_unit_header_length
98 format_.InitializeInto() 121 format_.InitializeInto()));
99 )); 122 CMVideoDimensions coded_dimensions =
123 CMVideoFormatDescriptionGetDimensions(format_);
100 124
101 // TODO(sandersd): Check if the size has changed and handle picture requests. 125 // Prepare VideoToolbox configuration dictionaries.
102 CMVideoDimensions coded_size = CMVideoFormatDescriptionGetDimensions(format_);
103 coded_size_.SetSize(coded_size.width, coded_size.height);
104
105 base::ScopedCFTypeRef<CFMutableDictionaryRef> decoder_config( 126 base::ScopedCFTypeRef<CFMutableDictionaryRef> decoder_config(
106 CFDictionaryCreateMutable( 127 CFDictionaryCreateMutable(
107 kCFAllocatorDefault, 128 kCFAllocatorDefault,
108 1, // capacity 129 1, // capacity
109 &kCFTypeDictionaryKeyCallBacks, 130 &kCFTypeDictionaryKeyCallBacks,
110 &kCFTypeDictionaryValueCallBacks)); 131 &kCFTypeDictionaryValueCallBacks));
111 132
112 CFDictionarySetValue( 133 CFDictionarySetValue(
113 decoder_config, 134 decoder_config,
114 // kVTVideoDecoderSpecification_EnableHardwareAcceleratedVideoDecoder 135 // kVTVideoDecoderSpecification_EnableHardwareAcceleratedVideoDecoder
115 CFSTR("EnableHardwareAcceleratedVideoDecoder"), 136 CFSTR("EnableHardwareAcceleratedVideoDecoder"),
116 kCFBooleanTrue); 137 kCFBooleanTrue);
117 138
118 base::ScopedCFTypeRef<CFMutableDictionaryRef> image_config( 139 base::ScopedCFTypeRef<CFMutableDictionaryRef> image_config(
119 CFDictionaryCreateMutable( 140 CFDictionaryCreateMutable(
120 kCFAllocatorDefault, 141 kCFAllocatorDefault,
121 4, // capacity 142 4, // capacity
122 &kCFTypeDictionaryKeyCallBacks, 143 &kCFTypeDictionaryKeyCallBacks,
123 &kCFTypeDictionaryValueCallBacks)); 144 &kCFTypeDictionaryValueCallBacks));
124 145
125 // TODO(sandersd): ARGB for video that is not 4:2:0.
126 int32_t pixel_format = '2vuy';
127 #define CFINT(i) CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &i) 146 #define CFINT(i) CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &i)
128 base::ScopedCFTypeRef<CFNumberRef> cf_pixel_format(CFINT(pixel_format)); 147 base::ScopedCFTypeRef<CFNumberRef> cf_pixel_format(CFINT(kYCbCr422));
129 base::ScopedCFTypeRef<CFNumberRef> cf_width(CFINT(coded_size.width)); 148 base::ScopedCFTypeRef<CFNumberRef> cf_width(CFINT(coded_dimensions.width));
130 base::ScopedCFTypeRef<CFNumberRef> cf_height(CFINT(coded_size.height)); 149 base::ScopedCFTypeRef<CFNumberRef> cf_height(CFINT(coded_dimensions.height));
131 #undef CFINT 150 #undef CFINT
132 CFDictionarySetValue( 151 CFDictionarySetValue(
133 image_config, kCVPixelBufferPixelFormatTypeKey, cf_pixel_format); 152 image_config, kCVPixelBufferPixelFormatTypeKey, cf_pixel_format);
134 CFDictionarySetValue(image_config, kCVPixelBufferWidthKey, cf_width); 153 CFDictionarySetValue(image_config, kCVPixelBufferWidthKey, cf_width);
135 CFDictionarySetValue(image_config, kCVPixelBufferHeightKey, cf_height); 154 CFDictionarySetValue(image_config, kCVPixelBufferHeightKey, cf_height);
136 CFDictionarySetValue( 155 CFDictionarySetValue(
137 image_config, kCVPixelBufferOpenGLCompatibilityKey, kCFBooleanTrue); 156 image_config, kCVPixelBufferOpenGLCompatibilityKey, kCFBooleanTrue);
138 157
139 // TODO(sandersd): Skip if the session is compatible. 158 // TODO(sandersd): Check if the session is already compatible.
140 // TODO(sandersd): Flush frames when resetting. 159 // TODO(sandersd): Flush.
141 session_.reset(); 160 session_.reset();
142 CHECK(!VTDecompressionSessionCreate( 161 CHECK(!VTDecompressionSessionCreate(
143 kCFAllocatorDefault, 162 kCFAllocatorDefault,
144 format_, // video_format_description 163 format_, // video_format_description
145 decoder_config, // video_decoder_specification 164 decoder_config, // video_decoder_specification
146 image_config, // destination_image_buffer_attributes 165 image_config, // destination_image_buffer_attributes
147 &callback_, // output_callback 166 &callback_, // output_callback
148 session_.InitializeInto() 167 session_.InitializeInto()));
149 )); 168
150 DVLOG(2) << "Created VTDecompressionSession"; 169 // If the size has changed, request new picture buffers.
170 gfx::Size new_coded_size(coded_dimensions.width, coded_dimensions.height);
171 if (coded_size_ != new_coded_size) {
172 coded_size_ = new_coded_size;
173 // TODO(sandersd): Dismiss existing picture buffers.
174 gpu_task_runner_->PostTask(FROM_HERE, base::Bind(
175 &media::VideoDecodeAccelerator::Client::ProvidePictureBuffers,
176 weak_client_factory_->GetWeakPtr(),
177 kNumPictureBuffers,
178 coded_size_,
179 GL_TEXTURE_RECTANGLE_ARB));
180 }
151 } 181 }
152 182
153 void VTVideoDecodeAccelerator::Decode(const media::BitstreamBuffer& bitstream) { 183 void VTVideoDecodeAccelerator::Decode(const media::BitstreamBuffer& bitstream) {
154 DCHECK(CalledOnValidThread()); 184 DCHECK(CalledOnValidThread());
155 decoder_thread_.message_loop_proxy()->PostTask(FROM_HERE, base::Bind( 185 decoder_thread_.message_loop_proxy()->PostTask(FROM_HERE, base::Bind(
156 &VTVideoDecodeAccelerator::DecodeTask, base::Unretained(this), 186 &VTVideoDecodeAccelerator::DecodeTask, base::Unretained(this),
157 bitstream)); 187 bitstream));
158 } 188 }
159 189
160 void VTVideoDecodeAccelerator::DecodeTask( 190 void VTVideoDecodeAccelerator::DecodeTask(
161 const media::BitstreamBuffer bitstream) { 191 const media::BitstreamBuffer bitstream) {
162 DCHECK(decoder_thread_.message_loop_proxy()->BelongsToCurrentThread()); 192 DCHECK(decoder_thread_.message_loop_proxy()->BelongsToCurrentThread());
163 193
164 // Map the bitstream buffer. 194 // Map the bitstream buffer.
165 base::SharedMemory memory(bitstream.handle(), true); 195 base::SharedMemory memory(bitstream.handle(), true);
166 size_t size = bitstream.size(); 196 size_t size = bitstream.size();
167 CHECK(memory.Map(size)); 197 CHECK(memory.Map(size));
168 const uint8_t* buf = static_cast<uint8_t*>(memory.memory()); 198 const uint8_t* buf = static_cast<uint8_t*>(memory.memory());
169 199
170 // Locate relevant NALUs in the buffer. 200 // NALUs are stored with Annex B format in the bitstream buffer (3-byte start
201 // codes), but VideoToolbox expects AVCC/MPEG-4 format (length headers), so we
202 // must to rewrite the data.
203 //
204 // 1. Locate relevant NALUs and compute the size of the translated data.
205 // Also record any parameter sets for VideoToolbox initialization.
171 size_t data_size = 0; 206 size_t data_size = 0;
172 std::vector<media::H264NALU> nalus; 207 std::vector<media::H264NALU> nalus;
173 std::vector<const uint8_t*> config_nalu_data_ptrs; 208 std::vector<const uint8_t*> config_nalu_data_ptrs;
174 std::vector<size_t> config_nalu_data_sizes; 209 std::vector<size_t> config_nalu_data_sizes;
175 parser_.SetStream(buf, size); 210 parser_.SetStream(buf, size);
176 media::H264NALU nalu; 211 media::H264NALU nalu;
177 while (true) { 212 while (true) {
178 media::H264Parser::Result result = parser_.AdvanceToNextNALU(&nalu); 213 media::H264Parser::Result result = parser_.AdvanceToNextNALU(&nalu);
179 if (result == media::H264Parser::kEOStream) 214 if (result == media::H264Parser::kEOStream)
180 break; 215 break;
181 CHECK_EQ(result, media::H264Parser::kOk); 216 CHECK_EQ(result, media::H264Parser::kOk);
217 // TODO(sandersd): Check that these are only at the start.
182 if (nalu.nal_unit_type == media::H264NALU::kSPS || 218 if (nalu.nal_unit_type == media::H264NALU::kSPS ||
183 nalu.nal_unit_type == media::H264NALU::kPPS || 219 nalu.nal_unit_type == media::H264NALU::kPPS ||
184 nalu.nal_unit_type == media::H264NALU::kSPSExt) { 220 nalu.nal_unit_type == media::H264NALU::kSPSExt) {
221 DVLOG(2) << "Parameter set " << nalu.nal_unit_type;
185 config_nalu_data_ptrs.push_back(nalu.data); 222 config_nalu_data_ptrs.push_back(nalu.data);
186 config_nalu_data_sizes.push_back(nalu.size); 223 config_nalu_data_sizes.push_back(nalu.size);
224 } else {
225 nalus.push_back(nalu);
226 data_size += kNALUHeaderLength + nalu.size;
187 } 227 }
188 nalus.push_back(nalu);
189 // Each NALU will have a 4-byte length header prepended.
190 data_size += kNALUHeaderLength + nalu.size;
191 } 228 }
192 229
193 if (!config_nalu_data_ptrs.empty()) 230 // 2. Initialize VideoToolbox.
231 // TODO(sandersd): Reinitialize when there are new parameter sets.
232 if (!session_)
194 ConfigureDecoder(config_nalu_data_ptrs, config_nalu_data_sizes); 233 ConfigureDecoder(config_nalu_data_ptrs, config_nalu_data_sizes);
195 234
196 // TODO(sandersd): Rewrite slice NALU headers and send for decoding. 235 // 3. Allocate a memory-backed CMBlockBuffer for the translated data.
236 base::ScopedCFTypeRef<CMBlockBufferRef> data;
237 CHECK(!CMBlockBufferCreateWithMemoryBlock(
238 kCFAllocatorDefault,
239 NULL, // &memory_block
240 data_size, // block_length
241 kCFAllocatorDefault, // block_allocator
242 NULL, // &custom_block_source
243 0, // offset_to_data
244 data_size, // data_length
245 0, // flags
246 data.InitializeInto()));
247
248 // 4. Copy NALU data, inserting length headers.
249 size_t offset = 0;
250 for (size_t i = 0; i < nalus.size(); i++) {
251 media::H264NALU& nalu = nalus[i];
252 uint8_t header[4] = {0xff & nalu.size >> 24,
253 0xff & nalu.size >> 16,
254 0xff & nalu.size >> 8,
255 0xff & nalu.size};
256 CHECK(!CMBlockBufferReplaceDataBytes(header, data, offset, 4));
257 offset += 4;
258 CHECK(!CMBlockBufferReplaceDataBytes(nalu.data, data, offset, nalu.size));
259 offset += nalu.size;
260 }
261
262 // 5. Package the data for VideoToolbox and request decoding.
263 base::ScopedCFTypeRef<CMSampleBufferRef> frame;
264 CHECK(!CMSampleBufferCreate(
265 kCFAllocatorDefault,
266 data, // data_buffer
267 true, // data_ready
268 NULL, // make_data_ready_callback
269 NULL, // make_data_ready_refcon
270 format_, // format_description
271 1, // num_samples
272 0, // num_sample_timing_entries
273 NULL, // &sample_timing_array
274 0, // num_sample_size_entries
275 NULL, // &sample_size_array
276 frame.InitializeInto()));
277
278 VTDecodeFrameFlags decode_flags =
279 kVTDecodeFrame_EnableAsynchronousDecompression |
280 kVTDecodeFrame_EnableTemporalProcessing;
281
282 intptr_t bitstream_id = bitstream.id();
283 CHECK(!VTDecompressionSessionDecodeFrame(
284 session_,
285 frame, // sample_buffer
286 decode_flags, // decode_flags
287 reinterpret_cast<void*>(bitstream_id), // source_frame_refcon
288 NULL)); // &info_flags_out
289
290 base::AutoLock lock(lock_);
291 frames_pending_decode_++;
197 } 292 }
198 293
199 // This method may be called on any VideoToolbox thread. 294 // This method may be called on any VideoToolbox thread.
200 void VTVideoDecodeAccelerator::Output( 295 void VTVideoDecodeAccelerator::Output(
201 int32_t bitstream_id, 296 int32_t bitstream_id,
202 OSStatus status, 297 OSStatus status,
203 VTDecodeInfoFlags info_flags, 298 VTDecodeInfoFlags info_flags,
204 CVImageBufferRef image_buffer) { 299 CVImageBufferRef image_buffer) {
205 // TODO(sandersd): Store the frame in a queue. 300 // The info_flags are ignored for now as they seem to be corrupted when the
206 CFRelease(image_buffer); 301 // software decoder is selected.
scherkus (not reviewing) 2014/07/17 02:08:26 this comment is confusing to me ... is this a TODO
sandersd (OOO until July 31) 2014/07/17 20:31:46 The only bit of interest in info_flags is the fram
302 CHECK(!status);
303 CHECK(CFGetTypeID(image_buffer) == CVPixelBufferGetTypeID());
scherkus (not reviewing) 2014/07/17 02:08:25 nit: is it possible to CHECK_EQ() these two, or do
sandersd (OOO until July 31) 2014/07/17 20:31:46 Done.
304 CHECK(CVPixelBufferGetPixelFormatType(image_buffer) == kYCbCr422);
305 {
306 base::AutoLock lock(lock_);
307 frames_pending_decode_--;
308 }
309 gpu_task_runner_->PostTask(FROM_HERE, base::Bind(
310 &VTVideoDecodeAccelerator::OutputTask,
311 weak_this_factory_.GetWeakPtr(),
312 bitstream_id,
313 base::ScopedCFTypeRef<CVImageBufferRef>(
314 image_buffer, base::scoped_policy::RETAIN)));
315 }
316
317 void VTVideoDecodeAccelerator::OutputTask(
318 int32_t bitstream_id,
319 base::ScopedCFTypeRef<CVImageBufferRef> image_buffer) {
320 DCHECK(CalledOnValidThread());
321 decoded_frames_.push(DecodedFrame(bitstream_id, image_buffer));
322 SendPictures();
207 } 323 }
208 324
209 void VTVideoDecodeAccelerator::AssignPictureBuffers( 325 void VTVideoDecodeAccelerator::AssignPictureBuffers(
210 const std::vector<media::PictureBuffer>& pictures) { 326 const std::vector<media::PictureBuffer>& pictures) {
211 DCHECK(CalledOnValidThread()); 327 DCHECK(CalledOnValidThread());
328
329 for (size_t i = 0; i < pictures.size(); i++) {
330 picture_ids_.push(pictures[i].id());
331 texture_ids_[pictures[i].id()] = pictures[i].texture_id();
332 }
333
334 // Pictures are not marked as uncleared until this method returns. They will
335 // become broken if they are used before that happens.
336 gpu_task_runner_->PostTask(FROM_HERE, base::Bind(
337 &VTVideoDecodeAccelerator::SendPictures,
338 weak_this_factory_.GetWeakPtr()));
212 } 339 }
213 340
214 void VTVideoDecodeAccelerator::ReusePictureBuffer(int32_t picture_id) { 341 void VTVideoDecodeAccelerator::ReusePictureBuffer(int32_t picture_id) {
215 DCHECK(CalledOnValidThread()); 342 DCHECK(CalledOnValidThread());
343
344 picture_bindings_.erase(picture_id);
345 picture_ids_.push(picture_id);
346
347 gpu_task_runner_->PostTask(FROM_HERE, base::Bind(
scherkus (not reviewing) 2014/07/17 02:08:26 does this have to be made async? it looks like we
sandersd (OOO until July 31) 2014/07/17 20:31:46 Done. I've tried to avoid any calling back into t
348 &VTVideoDecodeAccelerator::SendPictures,
349 weak_this_factory_.GetWeakPtr()));
350 }
351
352 void VTVideoDecodeAccelerator::SendPictures() {
353 DCHECK(CalledOnValidThread());
354 if (!picture_ids_.empty() && !decoded_frames_.empty()) {
scherkus (not reviewing) 2014/07/17 02:08:25 nit: prefer early return when possible so we avoid
sandersd (OOO until July 31) 2014/07/17 20:31:46 Done.
355 CGLContextObj prev_context = CGLGetCurrentContext();
356 CHECK(!CGLSetCurrentContext(cgl_context_));
357 glEnable(GL_TEXTURE_RECTANGLE_ARB);
358
359 while (!picture_ids_.empty() && !decoded_frames_.empty()) {
360 int32_t picture_id = picture_ids_.front();
361 picture_ids_.pop();
362 DecodedFrame frame = decoded_frames_.front();
363 decoded_frames_.pop();
364 IOSurfaceRef surface = CVPixelBufferGetIOSurface(frame.image_buffer);
365
366 glBindTexture(GL_TEXTURE_RECTANGLE_ARB, texture_ids_[picture_id]);
367 CHECK(!CGLTexImageIOSurface2D(
368 cgl_context_, // ctx
369 GL_TEXTURE_RECTANGLE_ARB, // target
370 GL_RGB, // internal_format
371 coded_size_.width(), // width
372 coded_size_.height(), // height
373 GL_YCBCR_422_APPLE, // format
374 GL_UNSIGNED_SHORT_8_8_APPLE, // type
375 surface, // io_surface
376 0)); // plane
377 glBindTexture(GL_TEXTURE_RECTANGLE_ARB, 0);
378
379 picture_bindings_[picture_id] = frame.image_buffer;
380
381 gpu_task_runner_->PostTask(FROM_HERE, base::Bind(
scherkus (not reviewing) 2014/07/17 02:08:25 do these need to be async? we're already on gpu_t
sandersd (OOO until July 31) 2014/07/17 20:31:46 Done. It looks like both the Chrome and Pepper im
382 &media::VideoDecodeAccelerator::Client::PictureReady,
383 weak_client_factory_->GetWeakPtr(),
384 media::Picture(picture_id, frame.bitstream_id)));
385
386 gpu_task_runner_->PostTask(FROM_HERE, base::Bind(
387 &media::VideoDecodeAccelerator::Client::NotifyEndOfBitstreamBuffer,
388 weak_client_factory_->GetWeakPtr(),
389 frame.bitstream_id));
390 }
391
392 glDisable(GL_TEXTURE_RECTANGLE_ARB);
393 CHECK(!CGLSetCurrentContext(prev_context));
394 }
216 } 395 }
217 396
218 void VTVideoDecodeAccelerator::Flush() { 397 void VTVideoDecodeAccelerator::Flush() {
219 DCHECK(CalledOnValidThread()); 398 DCHECK(CalledOnValidThread());
220 // TODO(sandersd): Trigger flush, sending frames. 399 // TODO(sandersd): Trigger flush, sending frames.
221 } 400 }
222 401
223 void VTVideoDecodeAccelerator::Reset() { 402 void VTVideoDecodeAccelerator::Reset() {
224 DCHECK(CalledOnValidThread()); 403 DCHECK(CalledOnValidThread());
225 // TODO(sandersd): Trigger flush, discarding frames. 404 // TODO(sandersd): Trigger flush, discarding frames.
226 } 405 }
227 406
228 void VTVideoDecodeAccelerator::Destroy() { 407 void VTVideoDecodeAccelerator::Destroy() {
229 DCHECK(CalledOnValidThread()); 408 DCHECK(CalledOnValidThread());
230 // TODO(sandersd): Trigger flush, discarding frames, and wait for them. 409 // TODO(sandersd): Trigger flush, discarding frames, and wait for them.
231 delete this; 410 delete this;
232 } 411 }
233 412
234 bool VTVideoDecodeAccelerator::CanDecodeOnIOThread() { 413 bool VTVideoDecodeAccelerator::CanDecodeOnIOThread() {
235 return false; 414 return false;
236 } 415 }
237 416
238 } // namespace content 417 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698