Cast: Stop logging kVideoFrameSentToEncoder and rename a couple events.
[chromium-blink-merge.git] / media / filters / gpu_video_decoder.cc
blob6842e4d7c59a4797c6c373f5916ad1c30feb357a
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
3 // found in the LICENSE file.
5 #include "media/filters/gpu_video_decoder.h"
7 #include <algorithm>
9 #include "base/bind.h"
10 #include "base/callback_helpers.h"
11 #include "base/cpu.h"
12 #include "base/message_loop/message_loop.h"
13 #include "base/metrics/histogram.h"
14 #include "base/stl_util.h"
15 #include "base/synchronization/waitable_event.h"
16 #include "base/task_runner_util.h"
17 #include "gpu/command_buffer/common/mailbox_holder.h"
18 #include "media/base/bind_to_current_loop.h"
19 #include "media/base/decoder_buffer.h"
20 #include "media/base/media_log.h"
21 #include "media/base/pipeline.h"
22 #include "media/base/pipeline_status.h"
23 #include "media/base/video_decoder_config.h"
24 #include "media/filters/gpu_video_accelerator_factories.h"
25 #include "third_party/skia/include/core/SkBitmap.h"
27 namespace media {
29 // Maximum number of concurrent VDA::Decode() operations GVD will maintain.
30 // Higher values allow better pipelining in the GPU, but also require more
31 // resources.
32 enum { kMaxInFlightDecodes = 4 };
34 // Size of shared-memory segments we allocate. Since we reuse them we let them
35 // be on the beefy side.
36 static const size_t kSharedMemorySegmentBytes = 100 << 10;
38 GpuVideoDecoder::SHMBuffer::SHMBuffer(base::SharedMemory* m, size_t s)
39 : shm(m), size(s) {
42 GpuVideoDecoder::SHMBuffer::~SHMBuffer() {}
44 GpuVideoDecoder::BufferPair::BufferPair(
45 SHMBuffer* s, const scoped_refptr<DecoderBuffer>& b)
46 : shm_buffer(s), buffer(b) {
49 GpuVideoDecoder::BufferPair::~BufferPair() {}
51 GpuVideoDecoder::BufferData::BufferData(
52 int32 bbid, base::TimeDelta ts, const gfx::Rect& vr, const gfx::Size& ns)
53 : bitstream_buffer_id(bbid), timestamp(ts), visible_rect(vr),
54 natural_size(ns) {
57 GpuVideoDecoder::BufferData::~BufferData() {}
59 GpuVideoDecoder::GpuVideoDecoder(
60 const scoped_refptr<GpuVideoAcceleratorFactories>& factories,
61 const scoped_refptr<MediaLog>& media_log)
62 : needs_bitstream_conversion_(false),
63 factories_(factories),
64 state_(kNormal),
65 media_log_(media_log),
66 decoder_texture_target_(0),
67 next_picture_buffer_id_(0),
68 next_bitstream_buffer_id_(0),
69 available_pictures_(0),
70 weak_factory_(this) {
71 DCHECK(factories_.get());
74 void GpuVideoDecoder::Reset(const base::Closure& closure) {
75 DVLOG(3) << "Reset()";
76 DCheckGpuVideoAcceleratorFactoriesTaskRunnerIsCurrent();
78 if (state_ == kDrainingDecoder) {
79 base::MessageLoop::current()->PostTask(
80 FROM_HERE,
81 base::Bind(
82 &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;
90 // Throw away any already-decoded, not-yet-delivered frames.
91 ready_video_frames_.clear();
93 if (!vda_) {
94 base::MessageLoop::current()->PostTask(FROM_HERE, closure);
95 return;
98 if (!pending_decode_cb_.is_null())
99 EnqueueFrameAndTriggerFrameDelivery(VideoFrame::CreateEOSFrame());
101 DCHECK(pending_reset_cb_.is_null());
102 pending_reset_cb_ = BindToCurrentLoop(closure);
104 vda_->Reset();
107 void GpuVideoDecoder::Stop() {
108 DCheckGpuVideoAcceleratorFactoriesTaskRunnerIsCurrent();
109 if (vda_)
110 DestroyVDA();
111 if (!pending_decode_cb_.is_null())
112 EnqueueFrameAndTriggerFrameDelivery(VideoFrame::CreateEOSFrame());
113 if (!pending_reset_cb_.is_null())
114 base::ResetAndReturn(&pending_reset_cb_).Run();
117 static bool IsCodedSizeSupported(const gfx::Size& coded_size) {
118 // Only non-Windows, Ivy Bridge+ platforms can support more than 1920x1080.
119 // We test against 1088 to account for 16x16 macroblocks.
120 if (coded_size.width() <= 1920 && coded_size.height() <= 1088)
121 return true;
123 base::CPU cpu;
124 bool hw_large_video_support =
125 (cpu.vendor_name() == "GenuineIntel") && cpu.model() >= 55;
126 bool os_large_video_support = true;
127 #if defined(OS_WIN)
128 os_large_video_support = false;
129 #endif
130 return os_large_video_support && hw_large_video_support;
133 // Report |status| to UMA and run |cb| with it. This is super-specific to the
134 // UMA stat reported because the UMA_HISTOGRAM_ENUMERATION API requires a
135 // callsite to always be called with the same stat name (can't parameterize it).
136 static void ReportGpuVideoDecoderInitializeStatusToUMAAndRunCB(
137 const PipelineStatusCB& cb,
138 PipelineStatus status) {
139 UMA_HISTOGRAM_ENUMERATION(
140 "Media.GpuVideoDecoderInitializeStatus", status, PIPELINE_STATUS_MAX + 1);
141 cb.Run(status);
144 void GpuVideoDecoder::Initialize(const VideoDecoderConfig& config,
145 bool live_mode,
146 const PipelineStatusCB& orig_status_cb) {
147 DVLOG(3) << "Initialize()";
148 DCheckGpuVideoAcceleratorFactoriesTaskRunnerIsCurrent();
149 DCHECK(config.IsValidConfig());
150 DCHECK(!config.is_encrypted());
152 PipelineStatusCB status_cb =
153 base::Bind(&ReportGpuVideoDecoderInitializeStatusToUMAAndRunCB,
154 BindToCurrentLoop(orig_status_cb));
156 bool previously_initialized = config_.IsValidConfig();
157 DVLOG(1) << "(Re)initializing GVD with config: "
158 << config.AsHumanReadableString();
160 // TODO(posciak): destroy and create a new VDA on codec/profile change
161 // (http://crbug.com/260224).
162 if (previously_initialized && (config_.profile() != config.profile())) {
163 DVLOG(1) << "Codec or profile changed, cannot reinitialize.";
164 status_cb.Run(DECODER_ERROR_NOT_SUPPORTED);
165 return;
168 if (!IsCodedSizeSupported(config.coded_size())) {
169 status_cb.Run(DECODER_ERROR_NOT_SUPPORTED);
170 return;
173 config_ = config;
174 needs_bitstream_conversion_ = (config.codec() == kCodecH264);
176 if (previously_initialized) {
177 // Reinitialization with a different config (but same codec and profile).
178 // VDA should handle it by detecting this in-stream by itself,
179 // no need to notify it.
180 status_cb.Run(PIPELINE_OK);
181 return;
184 vda_ = factories_->CreateVideoDecodeAccelerator().Pass();
185 if (!vda_ || !vda_->Initialize(config.profile(), this)) {
186 status_cb.Run(DECODER_ERROR_NOT_SUPPORTED);
187 return;
190 DVLOG(3) << "GpuVideoDecoder::Initialize() succeeded.";
191 media_log_->SetStringProperty("video_decoder", "gpu");
192 status_cb.Run(PIPELINE_OK);
195 void GpuVideoDecoder::DestroyPictureBuffers(PictureBufferMap* buffers) {
196 DCheckGpuVideoAcceleratorFactoriesTaskRunnerIsCurrent();
197 for (PictureBufferMap::iterator it = buffers->begin(); it != buffers->end();
198 ++it) {
199 factories_->DeleteTexture(it->second.texture_id());
202 buffers->clear();
205 void GpuVideoDecoder::DestroyVDA() {
206 DCheckGpuVideoAcceleratorFactoriesTaskRunnerIsCurrent();
208 if (vda_)
209 vda_.release()->Destroy();
211 // Not destroying PictureBuffers in |picture_buffers_at_display_| yet, since
212 // their textures may still be in use by the user of this GpuVideoDecoder.
213 for (PictureBufferTextureMap::iterator it =
214 picture_buffers_at_display_.begin();
215 it != picture_buffers_at_display_.end();
216 ++it) {
217 assigned_picture_buffers_.erase(it->first);
219 DestroyPictureBuffers(&assigned_picture_buffers_);
222 void GpuVideoDecoder::Decode(const scoped_refptr<DecoderBuffer>& buffer,
223 const DecodeCB& decode_cb) {
224 DCheckGpuVideoAcceleratorFactoriesTaskRunnerIsCurrent();
225 DCHECK(pending_reset_cb_.is_null());
226 DCHECK(pending_decode_cb_.is_null());
228 pending_decode_cb_ = BindToCurrentLoop(decode_cb);
230 if (state_ == kError || !vda_) {
231 base::ResetAndReturn(&pending_decode_cb_).Run(kDecodeError, NULL);
232 return;
235 switch (state_) {
236 case kDecoderDrained:
237 if (!ready_video_frames_.empty()) {
238 EnqueueFrameAndTriggerFrameDelivery(NULL);
239 return;
241 state_ = kNormal;
242 // Fall-through.
243 case kNormal:
244 break;
245 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:
251 NOTREACHED();
252 return;
255 if (buffer->end_of_stream()) {
256 if (state_ == kNormal) {
257 state_ = kDrainingDecoder;
258 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);
265 return;
268 size_t size = buffer->data_size();
269 SHMBuffer* shm_buffer = GetSHM(size);
270 if (!shm_buffer) {
271 base::ResetAndReturn(&pending_decode_cb_).Run(kDecodeError, NULL);
272 return;
275 memcpy(shm_buffer->shm->memory(), buffer->data(), size);
276 BitstreamBuffer bitstream_buffer(
277 next_bitstream_buffer_id_, shm_buffer->shm->handle(), size);
278 // Mask against 30 bits, to avoid (undefined) wraparound on signed integer.
279 next_bitstream_buffer_id_ = (next_bitstream_buffer_id_ + 1) & 0x3FFFFFFF;
280 bool inserted = bitstream_buffers_in_decoder_.insert(std::make_pair(
281 bitstream_buffer.id(), BufferPair(shm_buffer, buffer))).second;
282 DCHECK(inserted);
283 RecordBufferData(bitstream_buffer, *buffer.get());
285 vda_->Decode(bitstream_buffer);
287 if (!ready_video_frames_.empty()) {
288 EnqueueFrameAndTriggerFrameDelivery(NULL);
289 return;
292 if (CanMoreDecodeWorkBeDone())
293 base::ResetAndReturn(&pending_decode_cb_).Run(kNotEnoughData, NULL);
296 bool GpuVideoDecoder::CanMoreDecodeWorkBeDone() {
297 return bitstream_buffers_in_decoder_.size() < kMaxInFlightDecodes;
300 void GpuVideoDecoder::RecordBufferData(const BitstreamBuffer& bitstream_buffer,
301 const DecoderBuffer& buffer) {
302 input_buffer_data_.push_front(BufferData(bitstream_buffer.id(),
303 buffer.timestamp(),
304 config_.visible_rect(),
305 config_.natural_size()));
306 // 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
308 // using too-high a value is low (192 bits per extra slot).
309 static const size_t kMaxInputBufferDataSize = 128;
310 // Pop from the back of the list, because that's the oldest and least likely
311 // to be useful in the future data.
312 if (input_buffer_data_.size() > kMaxInputBufferDataSize)
313 input_buffer_data_.pop_back();
316 void GpuVideoDecoder::GetBufferData(int32 id, base::TimeDelta* timestamp,
317 gfx::Rect* visible_rect,
318 gfx::Size* natural_size) {
319 for (std::list<BufferData>::const_iterator it =
320 input_buffer_data_.begin(); it != input_buffer_data_.end();
321 ++it) {
322 if (it->bitstream_buffer_id != id)
323 continue;
324 *timestamp = it->timestamp;
325 *visible_rect = it->visible_rect;
326 *natural_size = it->natural_size;
327 return;
329 NOTREACHED() << "Missing bitstreambuffer id: " << id;
332 bool GpuVideoDecoder::NeedsBitstreamConversion() const {
333 DCheckGpuVideoAcceleratorFactoriesTaskRunnerIsCurrent();
334 return needs_bitstream_conversion_;
337 bool GpuVideoDecoder::CanReadWithoutStalling() const {
338 DCheckGpuVideoAcceleratorFactoriesTaskRunnerIsCurrent();
339 return
340 next_picture_buffer_id_ == 0 || // Decode() will ProvidePictureBuffers().
341 available_pictures_ > 0 || !ready_video_frames_.empty();
344 void GpuVideoDecoder::ProvidePictureBuffers(uint32 count,
345 const gfx::Size& size,
346 uint32 texture_target) {
347 DVLOG(3) << "ProvidePictureBuffers(" << count << ", "
348 << size.width() << "x" << size.height() << ")";
349 DCheckGpuVideoAcceleratorFactoriesTaskRunnerIsCurrent();
351 std::vector<uint32> texture_ids;
352 std::vector<gpu::Mailbox> texture_mailboxes;
353 decoder_texture_target_ = texture_target;
354 if (!factories_->CreateTextures(count,
355 size,
356 &texture_ids,
357 &texture_mailboxes,
358 decoder_texture_target_)) {
359 NotifyError(VideoDecodeAccelerator::PLATFORM_FAILURE);
360 return;
362 DCHECK_EQ(count, texture_ids.size());
363 DCHECK_EQ(count, texture_mailboxes.size());
365 if (!vda_)
366 return;
368 std::vector<PictureBuffer> picture_buffers;
369 for (size_t i = 0; i < texture_ids.size(); ++i) {
370 picture_buffers.push_back(PictureBuffer(
371 next_picture_buffer_id_++, size, texture_ids[i], texture_mailboxes[i]));
372 bool inserted = assigned_picture_buffers_.insert(std::make_pair(
373 picture_buffers.back().id(), picture_buffers.back())).second;
374 DCHECK(inserted);
377 available_pictures_ += count;
379 vda_->AssignPictureBuffers(picture_buffers);
382 void GpuVideoDecoder::DismissPictureBuffer(int32 id) {
383 DVLOG(3) << "DismissPictureBuffer(" << id << ")";
384 DCheckGpuVideoAcceleratorFactoriesTaskRunnerIsCurrent();
386 PictureBufferMap::iterator it = assigned_picture_buffers_.find(id);
387 if (it == assigned_picture_buffers_.end()) {
388 NOTREACHED() << "Missing picture buffer: " << id;
389 return;
392 PictureBuffer buffer_to_dismiss = it->second;
393 assigned_picture_buffers_.erase(it);
395 if (!picture_buffers_at_display_.count(id)) {
396 // We can delete the texture immediately as it's not being displayed.
397 factories_->DeleteTexture(buffer_to_dismiss.texture_id());
398 CHECK_GT(available_pictures_, 0);
399 --available_pictures_;
401 // Not destroying a texture in display in |picture_buffers_at_display_|.
402 // Postpone deletion until after it's returned to us.
405 static void ReadPixelsSyncInner(
406 const scoped_refptr<media::GpuVideoAcceleratorFactories>& factories,
407 uint32 texture_id,
408 const gfx::Rect& visible_rect,
409 const SkBitmap& pixels,
410 base::WaitableEvent* event) {
411 factories->ReadPixels(texture_id, visible_rect, pixels);
412 event->Signal();
415 static void ReadPixelsSync(
416 const scoped_refptr<media::GpuVideoAcceleratorFactories>& factories,
417 uint32 texture_id,
418 const gfx::Rect& visible_rect,
419 const SkBitmap& pixels) {
420 base::WaitableEvent event(true, false);
421 if (!factories->GetTaskRunner()->PostTask(FROM_HERE,
422 base::Bind(&ReadPixelsSyncInner,
423 factories,
424 texture_id,
425 visible_rect,
426 pixels,
427 &event)))
428 return;
429 event.Wait();
432 void GpuVideoDecoder::PictureReady(const media::Picture& picture) {
433 DVLOG(3) << "PictureReady()";
434 DCheckGpuVideoAcceleratorFactoriesTaskRunnerIsCurrent();
436 PictureBufferMap::iterator it =
437 assigned_picture_buffers_.find(picture.picture_buffer_id());
438 if (it == assigned_picture_buffers_.end()) {
439 NOTREACHED() << "Missing picture buffer: " << picture.picture_buffer_id();
440 NotifyError(VideoDecodeAccelerator::PLATFORM_FAILURE);
441 return;
443 const PictureBuffer& pb = it->second;
445 // Update frame's timestamp.
446 base::TimeDelta timestamp;
447 gfx::Rect visible_rect;
448 gfx::Size natural_size;
449 GetBufferData(picture.bitstream_buffer_id(), &timestamp, &visible_rect,
450 &natural_size);
451 DCHECK(decoder_texture_target_);
453 scoped_refptr<VideoFrame> frame(VideoFrame::WrapNativeTexture(
454 make_scoped_ptr(new gpu::MailboxHolder(
455 pb.texture_mailbox(), decoder_texture_target_, 0 /* sync_point */)),
456 BindToCurrentLoop(base::Bind(&GpuVideoDecoder::ReleaseMailbox,
457 weak_factory_.GetWeakPtr(),
458 factories_,
459 picture.picture_buffer_id(),
460 pb.texture_id())),
461 pb.size(),
462 visible_rect,
463 natural_size,
464 timestamp,
465 base::Bind(&ReadPixelsSync, factories_, pb.texture_id(), visible_rect)));
466 CHECK_GT(available_pictures_, 0);
467 --available_pictures_;
468 bool inserted =
469 picture_buffers_at_display_.insert(std::make_pair(
470 picture.picture_buffer_id(),
471 pb.texture_id())).second;
472 DCHECK(inserted);
474 EnqueueFrameAndTriggerFrameDelivery(frame);
477 void GpuVideoDecoder::EnqueueFrameAndTriggerFrameDelivery(
478 const scoped_refptr<VideoFrame>& frame) {
479 DCheckGpuVideoAcceleratorFactoriesTaskRunnerIsCurrent();
481 // During a pending vda->Reset(), we don't accumulate frames. Drop it on the
482 // floor and return.
483 if (!pending_reset_cb_.is_null())
484 return;
486 if (frame.get())
487 ready_video_frames_.push_back(frame);
488 else
489 DCHECK(!ready_video_frames_.empty());
491 if (pending_decode_cb_.is_null())
492 return;
494 base::ResetAndReturn(&pending_decode_cb_)
495 .Run(kOk, ready_video_frames_.front());
496 ready_video_frames_.pop_front();
499 // static
500 void GpuVideoDecoder::ReleaseMailbox(
501 base::WeakPtr<GpuVideoDecoder> decoder,
502 const scoped_refptr<media::GpuVideoAcceleratorFactories>& factories,
503 int64 picture_buffer_id,
504 uint32 texture_id,
505 const std::vector<uint32>& release_sync_points) {
506 DCHECK(factories->GetTaskRunner()->BelongsToCurrentThread());
508 for (size_t i = 0; i < release_sync_points.size(); i++)
509 factories->WaitSyncPoint(release_sync_points[i]);
511 if (decoder) {
512 decoder->ReusePictureBuffer(picture_buffer_id);
513 return;
515 // It's the last chance to delete the texture after display,
516 // because GpuVideoDecoder was destructed.
517 factories->DeleteTexture(texture_id);
520 void GpuVideoDecoder::ReusePictureBuffer(int64 picture_buffer_id) {
521 DVLOG(3) << "ReusePictureBuffer(" << picture_buffer_id << ")";
522 DCheckGpuVideoAcceleratorFactoriesTaskRunnerIsCurrent();
524 DCHECK(!picture_buffers_at_display_.empty());
525 PictureBufferTextureMap::iterator display_iterator =
526 picture_buffers_at_display_.find(picture_buffer_id);
527 uint32 texture_id = display_iterator->second;
528 DCHECK(display_iterator != picture_buffers_at_display_.end());
529 picture_buffers_at_display_.erase(display_iterator);
531 if (!assigned_picture_buffers_.count(picture_buffer_id)) {
532 // This picture was dismissed while in display, so we postponed deletion.
533 factories_->DeleteTexture(texture_id);
534 return;
537 ++available_pictures_;
539 // DestroyVDA() might already have been called.
540 if (vda_)
541 vda_->ReusePictureBuffer(picture_buffer_id);
544 GpuVideoDecoder::SHMBuffer* GpuVideoDecoder::GetSHM(size_t min_size) {
545 DCheckGpuVideoAcceleratorFactoriesTaskRunnerIsCurrent();
546 if (available_shm_segments_.empty() ||
547 available_shm_segments_.back()->size < min_size) {
548 size_t size_to_allocate = std::max(min_size, kSharedMemorySegmentBytes);
549 base::SharedMemory* shm = factories_->CreateSharedMemory(size_to_allocate);
550 // CreateSharedMemory() can return NULL during Shutdown.
551 if (!shm)
552 return NULL;
553 return new SHMBuffer(shm, size_to_allocate);
555 SHMBuffer* ret = available_shm_segments_.back();
556 available_shm_segments_.pop_back();
557 return ret;
560 void GpuVideoDecoder::PutSHM(SHMBuffer* shm_buffer) {
561 DCheckGpuVideoAcceleratorFactoriesTaskRunnerIsCurrent();
562 available_shm_segments_.push_back(shm_buffer);
565 void GpuVideoDecoder::NotifyEndOfBitstreamBuffer(int32 id) {
566 DVLOG(3) << "NotifyEndOfBitstreamBuffer(" << id << ")";
567 DCheckGpuVideoAcceleratorFactoriesTaskRunnerIsCurrent();
569 std::map<int32, BufferPair>::iterator it =
570 bitstream_buffers_in_decoder_.find(id);
571 if (it == bitstream_buffers_in_decoder_.end()) {
572 NotifyError(VideoDecodeAccelerator::PLATFORM_FAILURE);
573 NOTREACHED() << "Missing bitstream buffer: " << id;
574 return;
577 PutSHM(it->second.shm_buffer);
578 bitstream_buffers_in_decoder_.erase(it);
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);
586 GpuVideoDecoder::~GpuVideoDecoder() {
587 DCheckGpuVideoAcceleratorFactoriesTaskRunnerIsCurrent();
588 // Stop should have been already called.
589 DCHECK(!vda_.get() && assigned_picture_buffers_.empty());
590 DCHECK(pending_decode_cb_.is_null());
591 for (size_t i = 0; i < available_shm_segments_.size(); ++i) {
592 available_shm_segments_[i]->shm->Close();
593 delete available_shm_segments_[i];
595 available_shm_segments_.clear();
596 for (std::map<int32, BufferPair>::iterator it =
597 bitstream_buffers_in_decoder_.begin();
598 it != bitstream_buffers_in_decoder_.end(); ++it) {
599 it->second.shm_buffer->shm->Close();
601 bitstream_buffers_in_decoder_.clear();
604 void GpuVideoDecoder::NotifyFlushDone() {
605 DVLOG(3) << "NotifyFlushDone()";
606 DCheckGpuVideoAcceleratorFactoriesTaskRunnerIsCurrent();
607 DCHECK_EQ(state_, kDrainingDecoder);
608 state_ = kDecoderDrained;
609 EnqueueFrameAndTriggerFrameDelivery(VideoFrame::CreateEOSFrame());
612 void GpuVideoDecoder::NotifyResetDone() {
613 DVLOG(3) << "NotifyResetDone()";
614 DCheckGpuVideoAcceleratorFactoriesTaskRunnerIsCurrent();
615 DCHECK(ready_video_frames_.empty());
617 // This needs to happen after the Reset() on vda_ is done to ensure pictures
618 // delivered during the reset can find their time data.
619 input_buffer_data_.clear();
621 if (!pending_reset_cb_.is_null())
622 base::ResetAndReturn(&pending_reset_cb_).Run();
624 if (!pending_decode_cb_.is_null())
625 EnqueueFrameAndTriggerFrameDelivery(VideoFrame::CreateEOSFrame());
628 void GpuVideoDecoder::NotifyError(media::VideoDecodeAccelerator::Error error) {
629 DCheckGpuVideoAcceleratorFactoriesTaskRunnerIsCurrent();
630 if (!vda_)
631 return;
633 DLOG(ERROR) << "VDA Error: " << error;
634 DestroyVDA();
636 state_ = kError;
638 if (!pending_decode_cb_.is_null()) {
639 base::ResetAndReturn(&pending_decode_cb_).Run(kDecodeError, NULL);
640 return;
644 void GpuVideoDecoder::DCheckGpuVideoAcceleratorFactoriesTaskRunnerIsCurrent()
645 const {
646 DCHECK(factories_->GetTaskRunner()->BelongsToCurrentThread());
649 } // namespace media