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

Side by Side Diff: media/filters/gpu_video_decoder.cc

Issue 297553002: Add callback in VideoDecoder and AudioDecoder to return decoded frames. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 6 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "media/filters/gpu_video_decoder.h" 5 #include "media/filters/gpu_video_decoder.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/callback_helpers.h" 10 #include "base/callback_helpers.h"
(...skipping 23 matching lines...) Expand all
34 // Size of shared-memory segments we allocate. Since we reuse them we let them 34 // Size of shared-memory segments we allocate. Since we reuse them we let them
35 // be on the beefy side. 35 // be on the beefy side.
36 static const size_t kSharedMemorySegmentBytes = 100 << 10; 36 static const size_t kSharedMemorySegmentBytes = 100 << 10;
37 37
38 GpuVideoDecoder::SHMBuffer::SHMBuffer(base::SharedMemory* m, size_t s) 38 GpuVideoDecoder::SHMBuffer::SHMBuffer(base::SharedMemory* m, size_t s)
39 : shm(m), size(s) { 39 : shm(m), size(s) {
40 } 40 }
41 41
42 GpuVideoDecoder::SHMBuffer::~SHMBuffer() {} 42 GpuVideoDecoder::SHMBuffer::~SHMBuffer() {}
43 43
44 GpuVideoDecoder::BufferPair::BufferPair( 44 GpuVideoDecoder::PendingDecoderBuffer::PendingDecoderBuffer(
45 SHMBuffer* s, const scoped_refptr<DecoderBuffer>& b) 45 SHMBuffer* s,
46 : shm_buffer(s), buffer(b) { 46 const scoped_refptr<DecoderBuffer>& b,
47 const DecodeCB& done_cb)
48 : shm_buffer(s), buffer(b), done_cb(done_cb) {
47 } 49 }
48 50
49 GpuVideoDecoder::BufferPair::~BufferPair() {} 51 GpuVideoDecoder::PendingDecoderBuffer::~PendingDecoderBuffer() {}
50 52
51 GpuVideoDecoder::BufferData::BufferData( 53 GpuVideoDecoder::BufferData::BufferData(
52 int32 bbid, base::TimeDelta ts, const gfx::Rect& vr, const gfx::Size& ns) 54 int32 bbid, base::TimeDelta ts, const gfx::Rect& vr, const gfx::Size& ns)
53 : bitstream_buffer_id(bbid), timestamp(ts), visible_rect(vr), 55 : bitstream_buffer_id(bbid), timestamp(ts), visible_rect(vr),
54 natural_size(ns) { 56 natural_size(ns) {
55 } 57 }
56 58
57 GpuVideoDecoder::BufferData::~BufferData() {} 59 GpuVideoDecoder::BufferData::~BufferData() {}
58 60
59 GpuVideoDecoder::GpuVideoDecoder( 61 GpuVideoDecoder::GpuVideoDecoder(
(...skipping 13 matching lines...) Expand all
73 75
74 void GpuVideoDecoder::Reset(const base::Closure& closure) { 76 void GpuVideoDecoder::Reset(const base::Closure& closure) {
75 DVLOG(3) << "Reset()"; 77 DVLOG(3) << "Reset()";
76 DCheckGpuVideoAcceleratorFactoriesTaskRunnerIsCurrent(); 78 DCheckGpuVideoAcceleratorFactoriesTaskRunnerIsCurrent();
77 79
78 if (state_ == kDrainingDecoder) { 80 if (state_ == kDrainingDecoder) {
79 base::MessageLoop::current()->PostTask( 81 base::MessageLoop::current()->PostTask(
80 FROM_HERE, 82 FROM_HERE,
81 base::Bind( 83 base::Bind(
82 &GpuVideoDecoder::Reset, weak_factory_.GetWeakPtr(), closure)); 84 &GpuVideoDecoder::Reset, weak_factory_.GetWeakPtr(), closure));
83 // NOTE: if we're deferring Reset() until a Flush() completes, return
84 // queued pictures to the VDA so they can be used to finish that Flush().
85 if (pending_decode_cb_.is_null())
86 ready_video_frames_.clear();
87 return; 85 return;
88 } 86 }
89 87
90 // Throw away any already-decoded, not-yet-delivered frames.
91 ready_video_frames_.clear();
92
93 if (!vda_) { 88 if (!vda_) {
94 base::MessageLoop::current()->PostTask(FROM_HERE, closure); 89 base::MessageLoop::current()->PostTask(FROM_HERE, closure);
95 return; 90 return;
96 } 91 }
97 92
98 if (!pending_decode_cb_.is_null())
99 EnqueueFrameAndTriggerFrameDelivery(VideoFrame::CreateEOSFrame());
100
101 DCHECK(pending_reset_cb_.is_null()); 93 DCHECK(pending_reset_cb_.is_null());
102 pending_reset_cb_ = BindToCurrentLoop(closure); 94 pending_reset_cb_ = BindToCurrentLoop(closure);
103 95
104 vda_->Reset(); 96 vda_->Reset();
105 } 97 }
106 98
107 void GpuVideoDecoder::Stop() { 99 void GpuVideoDecoder::Stop() {
108 DCheckGpuVideoAcceleratorFactoriesTaskRunnerIsCurrent(); 100 DCheckGpuVideoAcceleratorFactoriesTaskRunnerIsCurrent();
109 if (vda_) 101 if (vda_)
110 DestroyVDA(); 102 DestroyVDA();
111 if (!pending_decode_cb_.is_null()) 103 DCHECK(bitstream_buffers_in_decoder_.empty());
112 EnqueueFrameAndTriggerFrameDelivery(VideoFrame::CreateEOSFrame());
113 if (!pending_reset_cb_.is_null()) 104 if (!pending_reset_cb_.is_null())
114 base::ResetAndReturn(&pending_reset_cb_).Run(); 105 base::ResetAndReturn(&pending_reset_cb_).Run();
115 } 106 }
116 107
117 static bool IsCodedSizeSupported(const gfx::Size& coded_size) { 108 static bool IsCodedSizeSupported(const gfx::Size& coded_size) {
118 // Only non-Windows, Ivy Bridge+ platforms can support more than 1920x1080. 109 // Only non-Windows, Ivy Bridge+ platforms can support more than 1920x1080.
119 // We test against 1088 to account for 16x16 macroblocks. 110 // We test against 1088 to account for 16x16 macroblocks.
120 if (coded_size.width() <= 1920 && coded_size.height() <= 1088) 111 if (coded_size.width() <= 1920 && coded_size.height() <= 1088)
121 return true; 112 return true;
122 113
(...skipping 13 matching lines...) Expand all
136 static void ReportGpuVideoDecoderInitializeStatusToUMAAndRunCB( 127 static void ReportGpuVideoDecoderInitializeStatusToUMAAndRunCB(
137 const PipelineStatusCB& cb, 128 const PipelineStatusCB& cb,
138 PipelineStatus status) { 129 PipelineStatus status) {
139 UMA_HISTOGRAM_ENUMERATION( 130 UMA_HISTOGRAM_ENUMERATION(
140 "Media.GpuVideoDecoderInitializeStatus", status, PIPELINE_STATUS_MAX + 1); 131 "Media.GpuVideoDecoderInitializeStatus", status, PIPELINE_STATUS_MAX + 1);
141 cb.Run(status); 132 cb.Run(status);
142 } 133 }
143 134
144 void GpuVideoDecoder::Initialize(const VideoDecoderConfig& config, 135 void GpuVideoDecoder::Initialize(const VideoDecoderConfig& config,
145 bool live_mode, 136 bool live_mode,
146 const PipelineStatusCB& orig_status_cb) { 137 const PipelineStatusCB& orig_status_cb,
138 const OutputCB& output_cb) {
147 DVLOG(3) << "Initialize()"; 139 DVLOG(3) << "Initialize()";
148 DCheckGpuVideoAcceleratorFactoriesTaskRunnerIsCurrent(); 140 DCheckGpuVideoAcceleratorFactoriesTaskRunnerIsCurrent();
149 DCHECK(config.IsValidConfig()); 141 DCHECK(config.IsValidConfig());
150 DCHECK(!config.is_encrypted()); 142 DCHECK(!config.is_encrypted());
151 143
152 PipelineStatusCB status_cb = 144 PipelineStatusCB status_cb =
153 base::Bind(&ReportGpuVideoDecoderInitializeStatusToUMAAndRunCB, 145 base::Bind(&ReportGpuVideoDecoderInitializeStatusToUMAAndRunCB,
154 BindToCurrentLoop(orig_status_cb)); 146 BindToCurrentLoop(orig_status_cb));
155 147
156 bool previously_initialized = config_.IsValidConfig(); 148 bool previously_initialized = config_.IsValidConfig();
157 DVLOG(1) << "(Re)initializing GVD with config: " 149 DVLOG(1) << "(Re)initializing GVD with config: "
158 << config.AsHumanReadableString(); 150 << config.AsHumanReadableString();
159 151
160 // TODO(posciak): destroy and create a new VDA on codec/profile change 152 // TODO(posciak): destroy and create a new VDA on codec/profile change
161 // (http://crbug.com/260224). 153 // (http://crbug.com/260224).
162 if (previously_initialized && (config_.profile() != config.profile())) { 154 if (previously_initialized && (config_.profile() != config.profile())) {
163 DVLOG(1) << "Codec or profile changed, cannot reinitialize."; 155 DVLOG(1) << "Codec or profile changed, cannot reinitialize.";
164 status_cb.Run(DECODER_ERROR_NOT_SUPPORTED); 156 status_cb.Run(DECODER_ERROR_NOT_SUPPORTED);
165 return; 157 return;
166 } 158 }
167 159
168 if (!IsCodedSizeSupported(config.coded_size())) { 160 if (!IsCodedSizeSupported(config.coded_size())) {
169 status_cb.Run(DECODER_ERROR_NOT_SUPPORTED); 161 status_cb.Run(DECODER_ERROR_NOT_SUPPORTED);
170 return; 162 return;
171 } 163 }
172 164
173 config_ = config; 165 config_ = config;
174 needs_bitstream_conversion_ = (config.codec() == kCodecH264); 166 needs_bitstream_conversion_ = (config.codec() == kCodecH264);
167 output_cb_ = output_cb;
xhwang 2014/06/05 21:53:51 In some decoders we BindToCurrentLoop, in some we
Sergey Ulanov 2014/06/06 22:49:41 I think all VDA implementations should call the ca
175 168
176 if (previously_initialized) { 169 if (previously_initialized) {
177 // Reinitialization with a different config (but same codec and profile). 170 // Reinitialization with a different config (but same codec and profile).
178 // VDA should handle it by detecting this in-stream by itself, 171 // VDA should handle it by detecting this in-stream by itself,
179 // no need to notify it. 172 // no need to notify it.
180 status_cb.Run(PIPELINE_OK); 173 status_cb.Run(PIPELINE_OK);
181 return; 174 return;
182 } 175 }
183 176
184 vda_ = factories_->CreateVideoDecodeAccelerator().Pass(); 177 vda_ = factories_->CreateVideoDecodeAccelerator().Pass();
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 ++it) { 209 ++it) {
217 assigned_picture_buffers_.erase(it->first); 210 assigned_picture_buffers_.erase(it->first);
218 } 211 }
219 DestroyPictureBuffers(&assigned_picture_buffers_); 212 DestroyPictureBuffers(&assigned_picture_buffers_);
220 } 213 }
221 214
222 void GpuVideoDecoder::Decode(const scoped_refptr<DecoderBuffer>& buffer, 215 void GpuVideoDecoder::Decode(const scoped_refptr<DecoderBuffer>& buffer,
223 const DecodeCB& decode_cb) { 216 const DecodeCB& decode_cb) {
224 DCheckGpuVideoAcceleratorFactoriesTaskRunnerIsCurrent(); 217 DCheckGpuVideoAcceleratorFactoriesTaskRunnerIsCurrent();
225 DCHECK(pending_reset_cb_.is_null()); 218 DCHECK(pending_reset_cb_.is_null());
226 DCHECK(pending_decode_cb_.is_null());
227 219
228 pending_decode_cb_ = BindToCurrentLoop(decode_cb); 220 DecodeCB bound_decode_cb = BindToCurrentLoop(decode_cb);
229 221
230 if (state_ == kError || !vda_) { 222 if (state_ == kError || !vda_) {
231 base::ResetAndReturn(&pending_decode_cb_).Run(kDecodeError, NULL); 223 bound_decode_cb.Run(kDecodeError);
232 return; 224 return;
233 } 225 }
234 226
235 switch (state_) { 227 switch (state_) {
236 case kDecoderDrained: 228 case kDecoderDrained:
237 if (!ready_video_frames_.empty()) {
238 EnqueueFrameAndTriggerFrameDelivery(NULL);
239 return;
240 }
241 state_ = kNormal; 229 state_ = kNormal;
242 // Fall-through. 230 // Fall-through.
243 case kNormal: 231 case kNormal:
244 break; 232 break;
245 case kDrainingDecoder: 233 case kDrainingDecoder:
246 DCHECK(buffer->end_of_stream());
247 // Do nothing. Will be satisfied either by a PictureReady or
248 // NotifyFlushDone below.
249 return;
250 case kError: 234 case kError:
251 NOTREACHED(); 235 NOTREACHED();
252 return; 236 return;
253 } 237 }
254 238
239 DCHECK_EQ(state_, kNormal);
240
255 if (buffer->end_of_stream()) { 241 if (buffer->end_of_stream()) {
256 if (state_ == kNormal) { 242 state_ = kDrainingDecoder;
257 state_ = kDrainingDecoder; 243 eos_decode_cb_ = bound_decode_cb;
258 vda_->Flush(); 244 vda_->Flush();
259 // If we have ready frames, go ahead and process them to ensure that the
260 // Flush operation does not block in the VDA due to lack of picture
261 // buffers.
262 if (!ready_video_frames_.empty())
263 EnqueueFrameAndTriggerFrameDelivery(NULL);
264 }
265 return; 245 return;
266 } 246 }
267 247
268 size_t size = buffer->data_size(); 248 size_t size = buffer->data_size();
269 SHMBuffer* shm_buffer = GetSHM(size); 249 SHMBuffer* shm_buffer = GetSHM(size);
270 if (!shm_buffer) { 250 if (!shm_buffer) {
271 base::ResetAndReturn(&pending_decode_cb_).Run(kDecodeError, NULL); 251 bound_decode_cb.Run(kDecodeError);
272 return; 252 return;
273 } 253 }
274 254
275 memcpy(shm_buffer->shm->memory(), buffer->data(), size); 255 memcpy(shm_buffer->shm->memory(), buffer->data(), size);
276 BitstreamBuffer bitstream_buffer( 256 BitstreamBuffer bitstream_buffer(
277 next_bitstream_buffer_id_, shm_buffer->shm->handle(), size); 257 next_bitstream_buffer_id_, shm_buffer->shm->handle(), size);
278 // Mask against 30 bits, to avoid (undefined) wraparound on signed integer. 258 // Mask against 30 bits, to avoid (undefined) wraparound on signed integer.
279 next_bitstream_buffer_id_ = (next_bitstream_buffer_id_ + 1) & 0x3FFFFFFF; 259 next_bitstream_buffer_id_ = (next_bitstream_buffer_id_ + 1) & 0x3FFFFFFF;
280 bool inserted = bitstream_buffers_in_decoder_.insert(std::make_pair( 260 DCHECK(bitstream_buffers_in_decoder_.find(bitstream_buffer.id()) ==
281 bitstream_buffer.id(), BufferPair(shm_buffer, buffer))).second; 261 bitstream_buffers_in_decoder_.end());
xhwang 2014/06/05 21:53:51 nit: You can use ContainsKey(): https://code.googl
Sergey Ulanov 2014/06/06 22:49:41 Done.
282 DCHECK(inserted); 262 bitstream_buffers_in_decoder_.insert(
263 std::make_pair(bitstream_buffer.id(),
264 PendingDecoderBuffer(shm_buffer, buffer, decode_cb)));
265 DCHECK_LE(static_cast<int>(bitstream_buffers_in_decoder_.size()),
266 kMaxInFlightDecodes);
283 RecordBufferData(bitstream_buffer, *buffer.get()); 267 RecordBufferData(bitstream_buffer, *buffer.get());
284 268
285 vda_->Decode(bitstream_buffer); 269 vda_->Decode(bitstream_buffer);
286
287 if (!ready_video_frames_.empty()) {
288 EnqueueFrameAndTriggerFrameDelivery(NULL);
289 return;
290 }
291
292 if (CanMoreDecodeWorkBeDone())
293 base::ResetAndReturn(&pending_decode_cb_).Run(kNotEnoughData, NULL);
294 }
295
296 bool GpuVideoDecoder::CanMoreDecodeWorkBeDone() {
297 return bitstream_buffers_in_decoder_.size() < kMaxInFlightDecodes;
298 } 270 }
299 271
300 void GpuVideoDecoder::RecordBufferData(const BitstreamBuffer& bitstream_buffer, 272 void GpuVideoDecoder::RecordBufferData(const BitstreamBuffer& bitstream_buffer,
301 const DecoderBuffer& buffer) { 273 const DecoderBuffer& buffer) {
302 input_buffer_data_.push_front(BufferData(bitstream_buffer.id(), 274 input_buffer_data_.push_front(BufferData(bitstream_buffer.id(),
303 buffer.timestamp(), 275 buffer.timestamp(),
304 config_.visible_rect(), 276 config_.visible_rect(),
305 config_.natural_size())); 277 config_.natural_size()));
306 // Why this value? Because why not. avformat.h:MAX_REORDER_DELAY is 16, but 278 // Why this value? Because why not. avformat.h:MAX_REORDER_DELAY is 16, but
307 // that's too small for some pathological B-frame test videos. The cost of 279 // that's too small for some pathological B-frame test videos. The cost of
(...skipping 23 matching lines...) Expand all
331 303
332 bool GpuVideoDecoder::NeedsBitstreamConversion() const { 304 bool GpuVideoDecoder::NeedsBitstreamConversion() const {
333 DCheckGpuVideoAcceleratorFactoriesTaskRunnerIsCurrent(); 305 DCheckGpuVideoAcceleratorFactoriesTaskRunnerIsCurrent();
334 return needs_bitstream_conversion_; 306 return needs_bitstream_conversion_;
335 } 307 }
336 308
337 bool GpuVideoDecoder::CanReadWithoutStalling() const { 309 bool GpuVideoDecoder::CanReadWithoutStalling() const {
338 DCheckGpuVideoAcceleratorFactoriesTaskRunnerIsCurrent(); 310 DCheckGpuVideoAcceleratorFactoriesTaskRunnerIsCurrent();
339 return 311 return
340 next_picture_buffer_id_ == 0 || // Decode() will ProvidePictureBuffers(). 312 next_picture_buffer_id_ == 0 || // Decode() will ProvidePictureBuffers().
341 available_pictures_ > 0 || !ready_video_frames_.empty(); 313 available_pictures_ > 0;
314 }
315
316 int GpuVideoDecoder::GetMaxDecodeRequests() const {
317 return kMaxInFlightDecodes;
342 } 318 }
343 319
344 void GpuVideoDecoder::ProvidePictureBuffers(uint32 count, 320 void GpuVideoDecoder::ProvidePictureBuffers(uint32 count,
345 const gfx::Size& size, 321 const gfx::Size& size,
346 uint32 texture_target) { 322 uint32 texture_target) {
347 DVLOG(3) << "ProvidePictureBuffers(" << count << ", " 323 DVLOG(3) << "ProvidePictureBuffers(" << count << ", "
348 << size.width() << "x" << size.height() << ")"; 324 << size.width() << "x" << size.height() << ")";
349 DCheckGpuVideoAcceleratorFactoriesTaskRunnerIsCurrent(); 325 DCheckGpuVideoAcceleratorFactoriesTaskRunnerIsCurrent();
350 326
351 std::vector<uint32> texture_ids; 327 std::vector<uint32> texture_ids;
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
464 timestamp, 440 timestamp,
465 base::Bind(&ReadPixelsSync, factories_, pb.texture_id(), visible_rect))); 441 base::Bind(&ReadPixelsSync, factories_, pb.texture_id(), visible_rect)));
466 CHECK_GT(available_pictures_, 0); 442 CHECK_GT(available_pictures_, 0);
467 --available_pictures_; 443 --available_pictures_;
468 bool inserted = 444 bool inserted =
469 picture_buffers_at_display_.insert(std::make_pair( 445 picture_buffers_at_display_.insert(std::make_pair(
470 picture.picture_buffer_id(), 446 picture.picture_buffer_id(),
471 pb.texture_id())).second; 447 pb.texture_id())).second;
472 DCHECK(inserted); 448 DCHECK(inserted);
473 449
474 EnqueueFrameAndTriggerFrameDelivery(frame); 450 DeliverFrame(frame);
475 } 451 }
476 452
477 void GpuVideoDecoder::EnqueueFrameAndTriggerFrameDelivery( 453 void GpuVideoDecoder::DeliverFrame(
478 const scoped_refptr<VideoFrame>& frame) { 454 const scoped_refptr<VideoFrame>& frame) {
479 DCheckGpuVideoAcceleratorFactoriesTaskRunnerIsCurrent(); 455 DCheckGpuVideoAcceleratorFactoriesTaskRunnerIsCurrent();
480 456
481 // During a pending vda->Reset(), we don't accumulate frames. Drop it on the 457 // During a pending vda->Reset(), we don't accumulate frames. Drop it on the
482 // floor and return. 458 // floor and return.
483 if (!pending_reset_cb_.is_null()) 459 if (!pending_reset_cb_.is_null())
484 return; 460 return;
485 461
486 if (frame.get()) 462 output_cb_.Run(frame);
487 ready_video_frames_.push_back(frame);
488 else
489 DCHECK(!ready_video_frames_.empty());
490
491 if (pending_decode_cb_.is_null())
492 return;
493
494 base::ResetAndReturn(&pending_decode_cb_)
495 .Run(kOk, ready_video_frames_.front());
496 ready_video_frames_.pop_front();
497 } 463 }
498 464
499 // static 465 // static
500 void GpuVideoDecoder::ReleaseMailbox( 466 void GpuVideoDecoder::ReleaseMailbox(
501 base::WeakPtr<GpuVideoDecoder> decoder, 467 base::WeakPtr<GpuVideoDecoder> decoder,
502 const scoped_refptr<media::GpuVideoAcceleratorFactories>& factories, 468 const scoped_refptr<media::GpuVideoAcceleratorFactories>& factories,
503 int64 picture_buffer_id, 469 int64 picture_buffer_id,
504 uint32 texture_id, 470 uint32 texture_id,
505 const std::vector<uint32>& release_sync_points) { 471 const std::vector<uint32>& release_sync_points) {
506 DCHECK(factories->GetTaskRunner()->BelongsToCurrentThread()); 472 DCHECK(factories->GetTaskRunner()->BelongsToCurrentThread());
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
559 525
560 void GpuVideoDecoder::PutSHM(SHMBuffer* shm_buffer) { 526 void GpuVideoDecoder::PutSHM(SHMBuffer* shm_buffer) {
561 DCheckGpuVideoAcceleratorFactoriesTaskRunnerIsCurrent(); 527 DCheckGpuVideoAcceleratorFactoriesTaskRunnerIsCurrent();
562 available_shm_segments_.push_back(shm_buffer); 528 available_shm_segments_.push_back(shm_buffer);
563 } 529 }
564 530
565 void GpuVideoDecoder::NotifyEndOfBitstreamBuffer(int32 id) { 531 void GpuVideoDecoder::NotifyEndOfBitstreamBuffer(int32 id) {
566 DVLOG(3) << "NotifyEndOfBitstreamBuffer(" << id << ")"; 532 DVLOG(3) << "NotifyEndOfBitstreamBuffer(" << id << ")";
567 DCheckGpuVideoAcceleratorFactoriesTaskRunnerIsCurrent(); 533 DCheckGpuVideoAcceleratorFactoriesTaskRunnerIsCurrent();
568 534
569 std::map<int32, BufferPair>::iterator it = 535 std::map<int32, PendingDecoderBuffer>::iterator it =
570 bitstream_buffers_in_decoder_.find(id); 536 bitstream_buffers_in_decoder_.find(id);
571 if (it == bitstream_buffers_in_decoder_.end()) { 537 if (it == bitstream_buffers_in_decoder_.end()) {
572 NotifyError(VideoDecodeAccelerator::PLATFORM_FAILURE); 538 NotifyError(VideoDecodeAccelerator::PLATFORM_FAILURE);
573 NOTREACHED() << "Missing bitstream buffer: " << id; 539 NOTREACHED() << "Missing bitstream buffer: " << id;
574 return; 540 return;
575 } 541 }
576 542
577 PutSHM(it->second.shm_buffer); 543 PutSHM(it->second.shm_buffer);
544 it->second.done_cb.Run(state_ == kError ? kDecodeError : kOk);
578 bitstream_buffers_in_decoder_.erase(it); 545 bitstream_buffers_in_decoder_.erase(it);
579
580 if (pending_reset_cb_.is_null() && state_ != kDrainingDecoder &&
581 CanMoreDecodeWorkBeDone() && !pending_decode_cb_.is_null()) {
582 base::ResetAndReturn(&pending_decode_cb_).Run(kNotEnoughData, NULL);
583 }
584 } 546 }
585 547
586 GpuVideoDecoder::~GpuVideoDecoder() { 548 GpuVideoDecoder::~GpuVideoDecoder() {
587 DCheckGpuVideoAcceleratorFactoriesTaskRunnerIsCurrent(); 549 DCheckGpuVideoAcceleratorFactoriesTaskRunnerIsCurrent();
588 // Stop should have been already called. 550 // Stop should have been already called.
589 DCHECK(!vda_.get() && assigned_picture_buffers_.empty()); 551 DCHECK(!vda_.get() && assigned_picture_buffers_.empty());
590 DCHECK(pending_decode_cb_.is_null()); 552 DCHECK(bitstream_buffers_in_decoder_.empty());
591 for (size_t i = 0; i < available_shm_segments_.size(); ++i) { 553 for (size_t i = 0; i < available_shm_segments_.size(); ++i) {
592 available_shm_segments_[i]->shm->Close(); 554 available_shm_segments_[i]->shm->Close();
593 delete available_shm_segments_[i]; 555 delete available_shm_segments_[i];
594 } 556 }
595 available_shm_segments_.clear(); 557 available_shm_segments_.clear();
596 for (std::map<int32, BufferPair>::iterator it = 558 for (std::map<int32, PendingDecoderBuffer>::iterator it =
597 bitstream_buffers_in_decoder_.begin(); 559 bitstream_buffers_in_decoder_.begin();
598 it != bitstream_buffers_in_decoder_.end(); ++it) { 560 it != bitstream_buffers_in_decoder_.end(); ++it) {
599 it->second.shm_buffer->shm->Close(); 561 it->second.shm_buffer->shm->Close();
600 } 562 }
601 bitstream_buffers_in_decoder_.clear(); 563 bitstream_buffers_in_decoder_.clear();
602 } 564 }
603 565
604 void GpuVideoDecoder::NotifyFlushDone() { 566 void GpuVideoDecoder::NotifyFlushDone() {
605 DVLOG(3) << "NotifyFlushDone()"; 567 DVLOG(3) << "NotifyFlushDone()";
606 DCheckGpuVideoAcceleratorFactoriesTaskRunnerIsCurrent(); 568 DCheckGpuVideoAcceleratorFactoriesTaskRunnerIsCurrent();
607 DCHECK_EQ(state_, kDrainingDecoder); 569 DCHECK_EQ(state_, kDrainingDecoder);
608 state_ = kDecoderDrained; 570 state_ = kDecoderDrained;
609 EnqueueFrameAndTriggerFrameDelivery(VideoFrame::CreateEOSFrame()); 571 DeliverFrame(VideoFrame::CreateEOSFrame());
572 base::ResetAndReturn(&eos_decode_cb_).Run(kOk);
610 } 573 }
611 574
612 void GpuVideoDecoder::NotifyResetDone() { 575 void GpuVideoDecoder::NotifyResetDone() {
613 DVLOG(3) << "NotifyResetDone()"; 576 DVLOG(3) << "NotifyResetDone()";
614 DCheckGpuVideoAcceleratorFactoriesTaskRunnerIsCurrent(); 577 DCheckGpuVideoAcceleratorFactoriesTaskRunnerIsCurrent();
615 DCHECK(ready_video_frames_.empty()); 578 DCHECK(bitstream_buffers_in_decoder_.empty());
616 579
617 // This needs to happen after the Reset() on vda_ is done to ensure pictures 580 // This needs to happen after the Reset() on vda_ is done to ensure pictures
618 // delivered during the reset can find their time data. 581 // delivered during the reset can find their time data.
619 input_buffer_data_.clear(); 582 input_buffer_data_.clear();
620 583
621 if (!pending_reset_cb_.is_null()) 584 if (!pending_reset_cb_.is_null())
622 base::ResetAndReturn(&pending_reset_cb_).Run(); 585 base::ResetAndReturn(&pending_reset_cb_).Run();
623
624 if (!pending_decode_cb_.is_null())
625 EnqueueFrameAndTriggerFrameDelivery(VideoFrame::CreateEOSFrame());
626 } 586 }
627 587
628 void GpuVideoDecoder::NotifyError(media::VideoDecodeAccelerator::Error error) { 588 void GpuVideoDecoder::NotifyError(media::VideoDecodeAccelerator::Error error) {
629 DCheckGpuVideoAcceleratorFactoriesTaskRunnerIsCurrent(); 589 DCheckGpuVideoAcceleratorFactoriesTaskRunnerIsCurrent();
630 if (!vda_) 590 if (!vda_)
631 return; 591 return;
632 592
593 state_ = kError;
594
633 DLOG(ERROR) << "VDA Error: " << error; 595 DLOG(ERROR) << "VDA Error: " << error;
634 DestroyVDA(); 596 DestroyVDA();
635
636 state_ = kError;
637
638 if (!pending_decode_cb_.is_null()) {
639 base::ResetAndReturn(&pending_decode_cb_).Run(kDecodeError, NULL);
640 return;
641 }
642 } 597 }
643 598
644 void GpuVideoDecoder::DCheckGpuVideoAcceleratorFactoriesTaskRunnerIsCurrent() 599 void GpuVideoDecoder::DCheckGpuVideoAcceleratorFactoriesTaskRunnerIsCurrent()
645 const { 600 const {
646 DCHECK(factories_->GetTaskRunner()->BelongsToCurrentThread()); 601 DCHECK(factories_->GetTaskRunner()->BelongsToCurrentThread());
647 } 602 }
648 603
649 } // namespace media 604 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698