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

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

Issue 765533005: Move the DXVA decoder off the GPU thread. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed presubmit Created 6 years 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 (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 "content/common/gpu/media/dxva_video_decode_accelerator.h" 5 #include "content/common/gpu/media/dxva_video_decode_accelerator.h"
6 6
7 #if !defined(OS_WIN) 7 #if !defined(OS_WIN)
8 #error This file should only be built on Windows. 8 #error This file should only be built on Windows.
9 #endif // !defined(OS_WIN) 9 #endif // !defined(OS_WIN)
10 10
(...skipping 470 matching lines...) Expand 10 before | Expand all | Expand 10 after
481 DXVAVideoDecodeAccelerator::DXVAVideoDecodeAccelerator( 481 DXVAVideoDecodeAccelerator::DXVAVideoDecodeAccelerator(
482 const base::Callback<bool(void)>& make_context_current) 482 const base::Callback<bool(void)>& make_context_current)
483 : client_(NULL), 483 : client_(NULL),
484 dev_manager_reset_token_(0), 484 dev_manager_reset_token_(0),
485 egl_config_(NULL), 485 egl_config_(NULL),
486 state_(kUninitialized), 486 state_(kUninitialized),
487 pictures_requested_(false), 487 pictures_requested_(false),
488 inputs_before_decode_(0), 488 inputs_before_decode_(0),
489 make_context_current_(make_context_current), 489 make_context_current_(make_context_current),
490 weak_this_factory_(this), 490 weak_this_factory_(this),
491 codec_(media::kUnknownVideoCodec) { 491 codec_(media::kUnknownVideoCodec),
492 decoder_thread_("DXVAVideoDecoderThread") {
492 memset(&input_stream_info_, 0, sizeof(input_stream_info_)); 493 memset(&input_stream_info_, 0, sizeof(input_stream_info_));
493 memset(&output_stream_info_, 0, sizeof(output_stream_info_)); 494 memset(&output_stream_info_, 0, sizeof(output_stream_info_));
494 } 495 }
495 496
496 DXVAVideoDecodeAccelerator::~DXVAVideoDecodeAccelerator() { 497 DXVAVideoDecodeAccelerator::~DXVAVideoDecodeAccelerator() {
497 client_ = NULL; 498 client_ = NULL;
498 } 499 }
499 500
500 bool DXVAVideoDecodeAccelerator::Initialize(media::VideoCodecProfile profile, 501 bool DXVAVideoDecodeAccelerator::Initialize(media::VideoCodecProfile profile,
501 Client* client) { 502 Client* client) {
(...skipping 19 matching lines...) Expand all
521 RETURN_AND_NOTIFY_ON_FAILURE(false, 522 RETURN_AND_NOTIFY_ON_FAILURE(false,
522 "Unsupported h.264, vp8, or vp9 profile", PLATFORM_FAILURE, false); 523 "Unsupported h.264, vp8, or vp9 profile", PLATFORM_FAILURE, false);
523 } 524 }
524 525
525 RETURN_AND_NOTIFY_ON_FAILURE( 526 RETURN_AND_NOTIFY_ON_FAILURE(
526 gfx::g_driver_egl.ext.b_EGL_ANGLE_surface_d3d_texture_2d_share_handle, 527 gfx::g_driver_egl.ext.b_EGL_ANGLE_surface_d3d_texture_2d_share_handle,
527 "EGL_ANGLE_surface_d3d_texture_2d_share_handle unavailable", 528 "EGL_ANGLE_surface_d3d_texture_2d_share_handle unavailable",
528 PLATFORM_FAILURE, 529 PLATFORM_FAILURE,
529 false); 530 false);
530 531
531 RETURN_AND_NOTIFY_ON_FAILURE((state_ == kUninitialized), 532 State state = GetState();
532 "Initialize: invalid state: " << state_, ILLEGAL_STATE, false); 533 RETURN_AND_NOTIFY_ON_FAILURE((state == kUninitialized),
534 "Initialize: invalid state: " << state, ILLEGAL_STATE, false);
533 535
534 HRESULT hr = MFStartup(MF_VERSION, MFSTARTUP_FULL); 536 HRESULT hr = MFStartup(MF_VERSION, MFSTARTUP_FULL);
535 RETURN_AND_NOTIFY_ON_HR_FAILURE(hr, "MFStartup failed.", PLATFORM_FAILURE, 537 RETURN_AND_NOTIFY_ON_HR_FAILURE(hr, "MFStartup failed.", PLATFORM_FAILURE,
536 false); 538 false);
537 539
538 RETURN_AND_NOTIFY_ON_FAILURE(CreateD3DDevManager(), 540 RETURN_AND_NOTIFY_ON_FAILURE(CreateD3DDevManager(),
539 "Failed to initialize D3D device and manager", 541 "Failed to initialize D3D device and manager",
540 PLATFORM_FAILURE, 542 PLATFORM_FAILURE,
541 false); 543 false);
542 544
543 RETURN_AND_NOTIFY_ON_FAILURE(InitDecoder(profile), 545 RETURN_AND_NOTIFY_ON_FAILURE(InitDecoder(profile),
544 "Failed to initialize decoder", PLATFORM_FAILURE, false); 546 "Failed to initialize decoder", PLATFORM_FAILURE, false);
545 547
546 RETURN_AND_NOTIFY_ON_FAILURE(GetStreamsInfoAndBufferReqs(), 548 RETURN_AND_NOTIFY_ON_FAILURE(GetStreamsInfoAndBufferReqs(),
547 "Failed to get input/output stream info.", PLATFORM_FAILURE, false); 549 "Failed to get input/output stream info.", PLATFORM_FAILURE, false);
548 550
549 RETURN_AND_NOTIFY_ON_FAILURE( 551 RETURN_AND_NOTIFY_ON_FAILURE(
550 SendMFTMessage(MFT_MESSAGE_NOTIFY_BEGIN_STREAMING, 0), 552 SendMFTMessage(MFT_MESSAGE_NOTIFY_BEGIN_STREAMING, 0),
551 "Send MFT_MESSAGE_NOTIFY_BEGIN_STREAMING notification failed", 553 "Send MFT_MESSAGE_NOTIFY_BEGIN_STREAMING notification failed",
552 PLATFORM_FAILURE, false); 554 PLATFORM_FAILURE, false);
553 555
554 RETURN_AND_NOTIFY_ON_FAILURE( 556 RETURN_AND_NOTIFY_ON_FAILURE(
555 SendMFTMessage(MFT_MESSAGE_NOTIFY_START_OF_STREAM, 0), 557 SendMFTMessage(MFT_MESSAGE_NOTIFY_START_OF_STREAM, 0),
556 "Send MFT_MESSAGE_NOTIFY_START_OF_STREAM notification failed", 558 "Send MFT_MESSAGE_NOTIFY_START_OF_STREAM notification failed",
557 PLATFORM_FAILURE, false); 559 PLATFORM_FAILURE, false);
558 560
559 state_ = kNormal; 561 SetState(kNormal);
562
563 main_thread_task_runner_ = base::MessageLoop::current()->task_runner();
564
565 decoder_thread_.init_com_with_mta(false);
566 decoder_thread_.Start();
567 decoder_thread_task_runner_ = decoder_thread_.task_runner();
560 return true; 568 return true;
561 } 569 }
562 570
563 void DXVAVideoDecodeAccelerator::Decode( 571 void DXVAVideoDecodeAccelerator::Decode(
564 const media::BitstreamBuffer& bitstream_buffer) { 572 const media::BitstreamBuffer& bitstream_buffer) {
565 DCHECK(CalledOnValidThread()); 573 DCHECK(CalledOnValidThread());
566 574
567 RETURN_AND_NOTIFY_ON_FAILURE((state_ == kNormal || state_ == kStopped || 575 State state = GetState();
568 state_ == kFlushing), 576 RETURN_AND_NOTIFY_ON_FAILURE((state == kNormal || state == kStopped ||
569 "Invalid state: " << state_, ILLEGAL_STATE,); 577 state == kFlushing),
578 "Invalid state: " << state, ILLEGAL_STATE,);
570 579
571 base::win::ScopedComPtr<IMFSample> sample; 580 base::win::ScopedComPtr<IMFSample> sample;
572 sample.Attach(CreateSampleFromInputBuffer(bitstream_buffer, 581 sample.Attach(CreateSampleFromInputBuffer(bitstream_buffer,
573 input_stream_info_.cbSize, 582 input_stream_info_.cbSize,
574 input_stream_info_.cbAlignment)); 583 input_stream_info_.cbAlignment));
575 RETURN_AND_NOTIFY_ON_FAILURE(sample.get(), "Failed to create input sample", 584 RETURN_AND_NOTIFY_ON_FAILURE(sample.get(), "Failed to create input sample",
576 PLATFORM_FAILURE, ); 585 PLATFORM_FAILURE, );
577 586
578 RETURN_AND_NOTIFY_ON_HR_FAILURE(sample->SetSampleTime(bitstream_buffer.id()), 587 RETURN_AND_NOTIFY_ON_HR_FAILURE(sample->SetSampleTime(bitstream_buffer.id()),
579 "Failed to associate input buffer id with sample", PLATFORM_FAILURE,); 588 "Failed to associate input buffer id with sample", PLATFORM_FAILURE,);
580 589
581 DecodeInternal(sample); 590 decoder_thread_task_runner_->PostTask(FROM_HERE,
591 base::Bind(&DXVAVideoDecodeAccelerator::DecodeInternal,
592 base::Unretained(this), sample));
582 } 593 }
583 594
584 void DXVAVideoDecodeAccelerator::AssignPictureBuffers( 595 void DXVAVideoDecodeAccelerator::AssignPictureBuffers(
585 const std::vector<media::PictureBuffer>& buffers) { 596 const std::vector<media::PictureBuffer>& buffers) {
586 DCHECK(CalledOnValidThread()); 597 DCHECK(CalledOnValidThread());
587 598
588 RETURN_AND_NOTIFY_ON_FAILURE((state_ != kUninitialized), 599 State state = GetState();
589 "Invalid state: " << state_, ILLEGAL_STATE,); 600 RETURN_AND_NOTIFY_ON_FAILURE((state != kUninitialized),
601 "Invalid state: " << state, ILLEGAL_STATE,);
590 RETURN_AND_NOTIFY_ON_FAILURE((kNumPictureBuffers == buffers.size()), 602 RETURN_AND_NOTIFY_ON_FAILURE((kNumPictureBuffers == buffers.size()),
591 "Failed to provide requested picture buffers. (Got " << buffers.size() << 603 "Failed to provide requested picture buffers. (Got " << buffers.size() <<
592 ", requested " << kNumPictureBuffers << ")", INVALID_ARGUMENT,); 604 ", requested " << kNumPictureBuffers << ")", INVALID_ARGUMENT,);
593 605
594 // Copy the picture buffers provided by the client to the available list, 606 // Copy the picture buffers provided by the client to the available list,
595 // and mark these buffers as available for use. 607 // and mark these buffers as available for use.
596 for (size_t buffer_index = 0; buffer_index < buffers.size(); 608 for (size_t buffer_index = 0; buffer_index < buffers.size();
597 ++buffer_index) { 609 ++buffer_index) {
598 linked_ptr<DXVAPictureBuffer> picture_buffer = 610 linked_ptr<DXVAPictureBuffer> picture_buffer =
599 DXVAPictureBuffer::Create(*this, buffers[buffer_index], egl_config_); 611 DXVAPictureBuffer::Create(*this, buffers[buffer_index], egl_config_);
600 RETURN_AND_NOTIFY_ON_FAILURE(picture_buffer.get(), 612 RETURN_AND_NOTIFY_ON_FAILURE(picture_buffer.get(),
601 "Failed to allocate picture buffer", PLATFORM_FAILURE,); 613 "Failed to allocate picture buffer", PLATFORM_FAILURE,);
602 614
603 bool inserted = output_picture_buffers_.insert(std::make_pair( 615 bool inserted = output_picture_buffers_.insert(std::make_pair(
604 buffers[buffer_index].id(), picture_buffer)).second; 616 buffers[buffer_index].id(), picture_buffer)).second;
605 DCHECK(inserted); 617 DCHECK(inserted);
606 } 618 }
607 ProcessPendingSamples(); 619 ProcessPendingSamples();
608 if (state_ == kFlushing && pending_output_samples_.empty()) 620
621 if (state == kFlushing && pending_output_samples_.empty())
609 FlushInternal(); 622 FlushInternal();
610 } 623 }
611 624
612 void DXVAVideoDecodeAccelerator::ReusePictureBuffer( 625 void DXVAVideoDecodeAccelerator::ReusePictureBuffer(
613 int32 picture_buffer_id) { 626 int32 picture_buffer_id) {
614 DCHECK(CalledOnValidThread()); 627 DCHECK(CalledOnValidThread());
615 628
616 RETURN_AND_NOTIFY_ON_FAILURE((state_ != kUninitialized), 629 State state = GetState();
617 "Invalid state: " << state_, ILLEGAL_STATE,); 630 RETURN_AND_NOTIFY_ON_FAILURE((state != kUninitialized),
631 "Invalid state: " << state, ILLEGAL_STATE,);
618 632
619 if (output_picture_buffers_.empty() && stale_output_picture_buffers_.empty()) 633 if (output_picture_buffers_.empty() && stale_output_picture_buffers_.empty())
620 return; 634 return;
621 635
622 OutputBuffers::iterator it = output_picture_buffers_.find(picture_buffer_id); 636 OutputBuffers::iterator it = output_picture_buffers_.find(picture_buffer_id);
623 // If we didn't find the picture id in the |output_picture_buffers_| map we 637 // If we didn't find the picture id in the |output_picture_buffers_| map we
624 // try the |stale_output_picture_buffers_| map, as this may have been an 638 // try the |stale_output_picture_buffers_| map, as this may have been an
625 // output picture buffer from before a resolution change, that at resolution 639 // output picture buffer from before a resolution change, that at resolution
626 // change time had yet to be displayed. The client is calling us back to tell 640 // change time had yet to be displayed. The client is calling us back to tell
627 // us that we can now recycle this picture buffer, so if we were waiting to 641 // us that we can now recycle this picture buffer, so if we were waiting to
628 // dispose of it we now can. 642 // dispose of it we now can.
629 if (it == output_picture_buffers_.end()) { 643 if (it == output_picture_buffers_.end()) {
630 it = stale_output_picture_buffers_.find(picture_buffer_id); 644 it = stale_output_picture_buffers_.find(picture_buffer_id);
631 RETURN_AND_NOTIFY_ON_FAILURE(it != stale_output_picture_buffers_.end(), 645 RETURN_AND_NOTIFY_ON_FAILURE(it != stale_output_picture_buffers_.end(),
632 "Invalid picture id: " << picture_buffer_id, INVALID_ARGUMENT,); 646 "Invalid picture id: " << picture_buffer_id, INVALID_ARGUMENT,);
633 base::MessageLoop::current()->PostTask(FROM_HERE, 647 base::MessageLoop::current()->PostTask(FROM_HERE,
634 base::Bind(&DXVAVideoDecodeAccelerator::DeferredDismissStaleBuffer, 648 base::Bind(&DXVAVideoDecodeAccelerator::DeferredDismissStaleBuffer,
635 weak_this_factory_.GetWeakPtr(), picture_buffer_id)); 649 weak_this_factory_.GetWeakPtr(), picture_buffer_id));
636 return; 650 return;
637 } 651 }
638 652
639 it->second->ReusePictureBuffer(); 653 it->second->ReusePictureBuffer();
640 ProcessPendingSamples(); 654 ProcessPendingSamples();
641 655
642 if (state_ == kFlushing && pending_output_samples_.empty()) 656 if (state == kFlushing && pending_output_samples_.empty())
643 FlushInternal(); 657 FlushInternal();
644 } 658 }
645 659
646 void DXVAVideoDecodeAccelerator::Flush() { 660 void DXVAVideoDecodeAccelerator::Flush() {
647 DCHECK(CalledOnValidThread()); 661 DCHECK(CalledOnValidThread());
648 662
649 DVLOG(1) << "DXVAVideoDecodeAccelerator::Flush"; 663 DVLOG(1) << "DXVAVideoDecodeAccelerator::Flush";
650 664
651 RETURN_AND_NOTIFY_ON_FAILURE((state_ == kNormal || state_ == kStopped), 665 State state = GetState();
652 "Unexpected decoder state: " << state_, ILLEGAL_STATE,); 666 RETURN_AND_NOTIFY_ON_FAILURE((state == kNormal || state == kStopped),
667 "Unexpected decoder state: " << state, ILLEGAL_STATE,);
653 668
654 state_ = kFlushing; 669 SetState(kFlushing);
655 670
656 RETURN_AND_NOTIFY_ON_FAILURE(SendMFTMessage(MFT_MESSAGE_COMMAND_DRAIN, 0), 671 RETURN_AND_NOTIFY_ON_FAILURE(SendMFTMessage(MFT_MESSAGE_COMMAND_DRAIN, 0),
657 "Failed to send drain message", PLATFORM_FAILURE,); 672 "Failed to send drain message", PLATFORM_FAILURE,);
658 673
659 if (!pending_output_samples_.empty()) 674 if (!pending_output_samples_.empty())
660 return; 675 return;
661 676
662 FlushInternal(); 677 FlushInternal();
663 } 678 }
664 679
665 void DXVAVideoDecodeAccelerator::Reset() { 680 void DXVAVideoDecodeAccelerator::Reset() {
666 DCHECK(CalledOnValidThread());
667
668 DVLOG(1) << "DXVAVideoDecodeAccelerator::Reset"; 681 DVLOG(1) << "DXVAVideoDecodeAccelerator::Reset";
669 682
670 RETURN_AND_NOTIFY_ON_FAILURE((state_ == kNormal || state_ == kStopped), 683 State state = GetState();
671 "Reset: invalid state: " << state_, ILLEGAL_STATE,); 684 RETURN_AND_NOTIFY_ON_FAILURE((state == kNormal || state == kStopped),
685 "Reset: invalid state: " << state, ILLEGAL_STATE,);
672 686
673 state_ = kResetting; 687 if (decoder_thread_.thread_id() != ::GetCurrentThreadId()) {
674 688 decoder_thread_task_runner_->PostTask(FROM_HERE,
675 pending_output_samples_.clear(); 689 base::Bind(&DXVAVideoDecodeAccelerator::ResetHelper,
676 690 base::Unretained(this)));
677 NotifyInputBuffersDropped(); 691 return;
678 692 }
679 RETURN_AND_NOTIFY_ON_FAILURE(SendMFTMessage(MFT_MESSAGE_COMMAND_FLUSH, 0),
680 "Reset: Failed to send message.", PLATFORM_FAILURE,);
681
682 base::MessageLoop::current()->PostTask(
683 FROM_HERE,
684 base::Bind(&DXVAVideoDecodeAccelerator::NotifyResetDone,
685 weak_this_factory_.GetWeakPtr()));
686
687 state_ = DXVAVideoDecodeAccelerator::kNormal;
688 } 693 }
689 694
690 void DXVAVideoDecodeAccelerator::Destroy() { 695 void DXVAVideoDecodeAccelerator::Destroy() {
691 DCHECK(CalledOnValidThread()); 696 DCHECK(CalledOnValidThread());
692 Invalidate(); 697 Invalidate();
693 delete this; 698 delete this;
694 } 699 }
695 700
696 bool DXVAVideoDecodeAccelerator::CanDecodeOnIOThread() { 701 bool DXVAVideoDecodeAccelerator::CanDecodeOnIOThread() {
697 return false; 702 return false;
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after
924 CHECK_EQ(output_stream_info_.dwFlags, 0x107u); 929 CHECK_EQ(output_stream_info_.dwFlags, 0x107u);
925 } 930 }
926 DVLOG(1) << "Min buffer size: " << output_stream_info_.cbSize; 931 DVLOG(1) << "Min buffer size: " << output_stream_info_.cbSize;
927 DVLOG(1) << "Alignment: " << output_stream_info_.cbAlignment; 932 DVLOG(1) << "Alignment: " << output_stream_info_.cbAlignment;
928 return true; 933 return true;
929 } 934 }
930 935
931 void DXVAVideoDecodeAccelerator::DoDecode() { 936 void DXVAVideoDecodeAccelerator::DoDecode() {
932 // This function is also called from FlushInternal in a loop which could 937 // This function is also called from FlushInternal in a loop which could
933 // result in the state transitioning to kStopped due to no decoded output. 938 // result in the state transitioning to kStopped due to no decoded output.
939 State state = GetState();
934 RETURN_AND_NOTIFY_ON_FAILURE( 940 RETURN_AND_NOTIFY_ON_FAILURE(
935 (state_ == kNormal || state_ == kFlushing || 941 (state == kNormal || state == kFlushing ||
936 state_ == kStopped || state_ == kFlushingPendingInputBuffers), 942 state == kStopped || state == kFlushingPendingInputBuffers),
937 "DoDecode: not in normal/flushing/stopped state", ILLEGAL_STATE,); 943 "DoDecode: not in normal/flushing/stopped state", ILLEGAL_STATE,);
938 944
939 MFT_OUTPUT_DATA_BUFFER output_data_buffer = {0}; 945 MFT_OUTPUT_DATA_BUFFER output_data_buffer = {0};
940 DWORD status = 0; 946 DWORD status = 0;
941 947
942 HRESULT hr = decoder_->ProcessOutput(0, // No flags 948 HRESULT hr = decoder_->ProcessOutput(0, // No flags
943 1, // # of out streams to pull from 949 1, // # of out streams to pull from
944 &output_data_buffer, 950 &output_data_buffer,
945 &status); 951 &status);
946 IMFCollection* events = output_data_buffer.pEvents; 952 IMFCollection* events = output_data_buffer.pEvents;
947 if (events != NULL) { 953 if (events != NULL) {
948 DVLOG(1) << "Got events from ProcessOuput, but discarding"; 954 DVLOG(1) << "Got events from ProcessOuput, but discarding";
949 events->Release(); 955 events->Release();
950 } 956 }
951 if (FAILED(hr)) { 957 if (FAILED(hr)) {
952 // A stream change needs further ProcessInput calls to get back decoder 958 // A stream change needs further ProcessInput calls to get back decoder
953 // output which is why we need to set the state to stopped. 959 // output which is why we need to set the state to stopped.
954 if (hr == MF_E_TRANSFORM_STREAM_CHANGE) { 960 if (hr == MF_E_TRANSFORM_STREAM_CHANGE) {
955 if (!SetDecoderOutputMediaType(MFVideoFormat_NV12)) { 961 if (!SetDecoderOutputMediaType(MFVideoFormat_NV12)) {
956 // Decoder didn't let us set NV12 output format. Not sure as to why 962 // Decoder didn't let us set NV12 output format. Not sure as to why
957 // this can happen. Give up in disgust. 963 // this can happen. Give up in disgust.
958 NOTREACHED() << "Failed to set decoder output media type to NV12"; 964 NOTREACHED() << "Failed to set decoder output media type to NV12";
959 state_ = kStopped; 965 SetState(kStopped);
960 } else { 966 } else {
961 DVLOG(1) << "Received output format change from the decoder." 967 DVLOG(1) << "Received output format change from the decoder."
962 " Recursively invoking DoDecode"; 968 " Recursively invoking DoDecode";
963 DoDecode(); 969 DoDecode();
964 } 970 }
965 return; 971 return;
966 } else if (hr == MF_E_TRANSFORM_NEED_MORE_INPUT) { 972 } else if (hr == MF_E_TRANSFORM_NEED_MORE_INPUT) {
967 // No more output from the decoder. Stop playback. 973 // No more output from the decoder. Stop playback.
968 if (state_ != kFlushingPendingInputBuffers) 974 if (state != kFlushingPendingInputBuffers)
969 state_ = kStopped; 975 SetState(kStopped);
970 return; 976 return;
971 } else { 977 } else {
972 NOTREACHED() << "Unhandled error in DoDecode()"; 978 NOTREACHED() << "Unhandled error in DoDecode()";
973 return; 979 return;
974 } 980 }
975 } 981 }
976 TRACE_EVENT_END_ETW("DXVAVideoDecodeAccelerator.Decoding", this, ""); 982 TRACE_EVENT_END_ETW("DXVAVideoDecodeAccelerator.Decoding", this, "");
977 983
978 TRACE_COUNTER1("DXVA Decoding", "TotalPacketsBeforeDecode", 984 TRACE_COUNTER1("DXVA Decoding", "TotalPacketsBeforeDecode",
979 inputs_before_decode_); 985 inputs_before_decode_);
(...skipping 21 matching lines...) Expand all
1001 RETURN_ON_HR_FAILURE(sample->GetSampleTime(&input_buffer_id), 1007 RETURN_ON_HR_FAILURE(sample->GetSampleTime(&input_buffer_id),
1002 "Failed to get input buffer id associated with sample", 1008 "Failed to get input buffer id associated with sample",
1003 false); 1009 false);
1004 1010
1005 pending_output_samples_.push_back( 1011 pending_output_samples_.push_back(
1006 PendingSampleInfo(input_buffer_id, sample)); 1012 PendingSampleInfo(input_buffer_id, sample));
1007 1013
1008 // If we have available picture buffers to copy the output data then use the 1014 // If we have available picture buffers to copy the output data then use the
1009 // first one and then flag it as not being available for use. 1015 // first one and then flag it as not being available for use.
1010 if (output_picture_buffers_.size()) { 1016 if (output_picture_buffers_.size()) {
1011 ProcessPendingSamples(); 1017 main_thread_task_runner_->PostTask(
1018 FROM_HERE,
1019 base::Bind(&DXVAVideoDecodeAccelerator::ProcessPendingSamples,
1020 weak_this_factory_.GetWeakPtr()));
1012 return true; 1021 return true;
1013 } 1022 }
1014 if (pictures_requested_) { 1023 if (pictures_requested_) {
1015 DVLOG(1) << "Waiting for picture slots from the client."; 1024 DVLOG(1) << "Waiting for picture slots from the client.";
1016 return true; 1025 return true;
1017 } 1026 }
1018 1027
1019 // We only read the surface description, which contains its width/height when 1028 // We only read the surface description, which contains its width/height when
1020 // we need the picture buffers from the client. Once we have those, then they 1029 // we need the picture buffers from the client. Once we have those, then they
1021 // are reused. 1030 // are reused.
1022 D3DSURFACE_DESC surface_desc; 1031 D3DSURFACE_DESC surface_desc;
1023 hr = surface->GetDesc(&surface_desc); 1032 hr = surface->GetDesc(&surface_desc);
1024 RETURN_ON_HR_FAILURE(hr, "Failed to get surface description", false); 1033 RETURN_ON_HR_FAILURE(hr, "Failed to get surface description", false);
1025 1034
1026 // Go ahead and request picture buffers. 1035 // Go ahead and request picture buffers.
1027 base::MessageLoop::current()->PostTask( 1036 main_thread_task_runner_->PostTask(
1028 FROM_HERE, 1037 FROM_HERE,
1029 base::Bind(&DXVAVideoDecodeAccelerator::RequestPictureBuffers, 1038 base::Bind(&DXVAVideoDecodeAccelerator::RequestPictureBuffers,
1030 weak_this_factory_.GetWeakPtr(), 1039 weak_this_factory_.GetWeakPtr(),
1031 surface_desc.Width, 1040 surface_desc.Width,
1032 surface_desc.Height)); 1041 surface_desc.Height));
1033 1042
1034 pictures_requested_ = true; 1043 pictures_requested_ = true;
1035 return true; 1044 return true;
1036 } 1045 }
1037 1046
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
1075 } 1084 }
1076 1085
1077 RETURN_AND_NOTIFY_ON_FAILURE( 1086 RETURN_AND_NOTIFY_ON_FAILURE(
1078 index->second->CopyOutputSampleDataToPictureBuffer(*this, 1087 index->second->CopyOutputSampleDataToPictureBuffer(*this,
1079 surface.get()), 1088 surface.get()),
1080 "Failed to copy output sample", PLATFORM_FAILURE, ); 1089 "Failed to copy output sample", PLATFORM_FAILURE, );
1081 1090
1082 media::Picture output_picture(index->second->id(), 1091 media::Picture output_picture(index->second->id(),
1083 sample_info.input_buffer_id, 1092 sample_info.input_buffer_id,
1084 gfx::Rect(index->second->size())); 1093 gfx::Rect(index->second->size()));
1085 base::MessageLoop::current()->PostTask( 1094 main_thread_task_runner_->PostTask(
1086 FROM_HERE, 1095 FROM_HERE,
1087 base::Bind(&DXVAVideoDecodeAccelerator::NotifyPictureReady, 1096 base::Bind(&DXVAVideoDecodeAccelerator::NotifyPictureReady,
1088 weak_this_factory_.GetWeakPtr(), 1097 weak_this_factory_.GetWeakPtr(),
1089 output_picture)); 1098 output_picture));
1090 1099
1091 index->second->set_available(false); 1100 index->second->set_available(false);
1092 pending_output_samples_.pop_front(); 1101 pending_output_samples_.pop_front();
1093 } 1102 }
1094 } 1103 }
1095 1104 decoder_thread_task_runner_->PostTask(
1096 if (!pending_input_buffers_.empty() && pending_output_samples_.empty()) { 1105 FROM_HERE,
1097 base::MessageLoop::current()->PostTask( 1106 base::Bind(&DXVAVideoDecodeAccelerator::DecodePendingInputBuffers,
1098 FROM_HERE, 1107 base::Unretained(this)));
1099 base::Bind(&DXVAVideoDecodeAccelerator::DecodePendingInputBuffers,
1100 weak_this_factory_.GetWeakPtr()));
1101 }
1102 } 1108 }
1103 1109
1104 void DXVAVideoDecodeAccelerator::StopOnError( 1110 void DXVAVideoDecodeAccelerator::StopOnError(
1105 media::VideoDecodeAccelerator::Error error) { 1111 media::VideoDecodeAccelerator::Error error) {
1106 DCHECK(CalledOnValidThread()); 1112 DCHECK(CalledOnValidThread());
1107 1113
1108 if (client_) 1114 if (client_)
1109 client_->NotifyError(error); 1115 client_->NotifyError(error);
1110 client_ = NULL; 1116 client_ = NULL;
1111 1117
1112 if (state_ != kUninitialized) { 1118 if (GetState() != kUninitialized) {
1113 Invalidate(); 1119 Invalidate();
1114 } 1120 }
1115 } 1121 }
1116 1122
1117 void DXVAVideoDecodeAccelerator::Invalidate() { 1123 void DXVAVideoDecodeAccelerator::Invalidate() {
1118 if (state_ == kUninitialized) 1124 if (GetState() == kUninitialized)
1119 return; 1125 return;
1126 decoder_thread_.Stop();
1120 weak_this_factory_.InvalidateWeakPtrs(); 1127 weak_this_factory_.InvalidateWeakPtrs();
1121 output_picture_buffers_.clear(); 1128 output_picture_buffers_.clear();
1122 stale_output_picture_buffers_.clear(); 1129 stale_output_picture_buffers_.clear();
1123 pending_output_samples_.clear(); 1130 pending_output_samples_.clear();
1124 pending_input_buffers_.clear(); 1131 pending_input_buffers_.clear();
1125 decoder_.Release(); 1132 decoder_.Release();
1126 MFShutdown(); 1133 MFShutdown();
1127 state_ = kUninitialized; 1134 SetState(kUninitialized);
1128 } 1135 }
1129 1136
1130 void DXVAVideoDecodeAccelerator::NotifyInputBufferRead(int input_buffer_id) { 1137 void DXVAVideoDecodeAccelerator::NotifyInputBufferRead(int input_buffer_id) {
1131 if (client_) 1138 if (client_)
1132 client_->NotifyEndOfBitstreamBuffer(input_buffer_id); 1139 client_->NotifyEndOfBitstreamBuffer(input_buffer_id);
1133 } 1140 }
1134 1141
1135 void DXVAVideoDecodeAccelerator::NotifyFlushDone() { 1142 void DXVAVideoDecodeAccelerator::NotifyFlushDone() {
1136 if (client_) 1143 if (client_)
1137 client_->NotifyFlushDone(); 1144 client_->NotifyFlushDone();
1138 } 1145 }
1139 1146
1140 void DXVAVideoDecodeAccelerator::NotifyResetDone() { 1147 void DXVAVideoDecodeAccelerator::NotifyResetDone() {
1148 pending_output_samples_.clear();
1141 if (client_) 1149 if (client_)
1142 client_->NotifyResetDone(); 1150 client_->NotifyResetDone();
1143 } 1151 }
1144 1152
1145 void DXVAVideoDecodeAccelerator::RequestPictureBuffers(int width, int height) { 1153 void DXVAVideoDecodeAccelerator::RequestPictureBuffers(int width, int height) {
1146 // This task could execute after the decoder has been torn down. 1154 // This task could execute after the decoder has been torn down.
1147 if (state_ != kUninitialized && client_) { 1155 if (GetState() != kUninitialized && client_) {
1148 client_->ProvidePictureBuffers( 1156 client_->ProvidePictureBuffers(
1149 kNumPictureBuffers, 1157 kNumPictureBuffers,
1150 gfx::Size(width, height), 1158 gfx::Size(width, height),
1151 GL_TEXTURE_2D); 1159 GL_TEXTURE_2D);
1152 } 1160 }
1153 } 1161 }
1154 1162
1155 void DXVAVideoDecodeAccelerator::NotifyPictureReady( 1163 void DXVAVideoDecodeAccelerator::NotifyPictureReady(
1156 const media::Picture& picture) { 1164 const media::Picture& picture) {
1157 // This task could execute after the decoder has been torn down. 1165 // This task could execute after the decoder has been torn down.
1158 if (state_ != kUninitialized && client_) 1166 if (GetState() != kUninitialized && client_)
1159 client_->PictureReady(picture); 1167 client_->PictureReady(picture);
1160 } 1168 }
1161 1169
1162 void DXVAVideoDecodeAccelerator::NotifyInputBuffersDropped() { 1170 void DXVAVideoDecodeAccelerator::NotifyInputBuffersDropped(
1163 if (!client_ || !pending_output_samples_.empty()) 1171 const PendingInputs& input_buffers) {
1172 if (!client_)
1164 return; 1173 return;
1165 1174
1166 for (PendingInputs::iterator it = pending_input_buffers_.begin(); 1175 for (PendingInputs::const_iterator it = input_buffers.begin();
1167 it != pending_input_buffers_.end(); ++it) { 1176 it != input_buffers.end(); ++it) {
1168 LONGLONG input_buffer_id = 0; 1177 LONGLONG input_buffer_id = 0;
1169 RETURN_ON_HR_FAILURE((*it)->GetSampleTime(&input_buffer_id), 1178 RETURN_ON_HR_FAILURE((*it)->GetSampleTime(&input_buffer_id),
1170 "Failed to get buffer id associated with sample",); 1179 "Failed to get buffer id associated with sample",);
1171 client_->NotifyEndOfBitstreamBuffer(input_buffer_id); 1180 client_->NotifyEndOfBitstreamBuffer(input_buffer_id);
1172 } 1181 }
1173 pending_input_buffers_.clear();
1174 } 1182 }
1175 1183
1176 void DXVAVideoDecodeAccelerator::DecodePendingInputBuffers() { 1184 void DXVAVideoDecodeAccelerator::DecodePendingInputBuffers() {
1177 RETURN_AND_NOTIFY_ON_FAILURE((state_ != kUninitialized), 1185 State state = GetState();
1178 "Invalid state: " << state_, ILLEGAL_STATE,); 1186 RETURN_AND_NOTIFY_ON_FAILURE((state != kUninitialized),
1187 "Invalid state: " << state, ILLEGAL_STATE,);
1179 1188
1180 if (pending_input_buffers_.empty() || !pending_output_samples_.empty()) 1189 if (pending_input_buffers_.empty() || !pending_output_samples_.empty())
1181 return; 1190 return;
1182 1191
1183 PendingInputs pending_input_buffers_copy; 1192 PendingInputs pending_input_buffers_copy;
1184 std::swap(pending_input_buffers_, pending_input_buffers_copy); 1193 std::swap(pending_input_buffers_, pending_input_buffers_copy);
1185 1194
1186 for (PendingInputs::iterator it = pending_input_buffers_copy.begin(); 1195 for (PendingInputs::iterator it = pending_input_buffers_copy.begin();
1187 it != pending_input_buffers_copy.end(); ++it) { 1196 it != pending_input_buffers_copy.end(); ++it) {
1188 DecodeInternal(*it); 1197 DecodeInternal(*it);
1189 } 1198 }
1190 1199
1191 if (state_ != kFlushingPendingInputBuffers) 1200 if (state != kFlushingPendingInputBuffers)
1192 return; 1201 return;
1193 1202
1194 // If we are scheduled during a flush operation then mark the flush as 1203 // If we are scheduled during a flush operation then mark the flush as
1195 // complete if we have no pending input and pending output frames. 1204 // complete if we have no pending input and pending output frames.
1196 // If we don't have available output slots then this function will be 1205 // If we don't have available output slots then this function will be
1197 // scheduled again by the ProcessPendingSamples function once slots become 1206 // scheduled again by the ProcessPendingSamples function once slots become
1198 // available. 1207 // available.
1199 if (pending_input_buffers_.empty() && pending_output_samples_.empty()) { 1208 if (pending_input_buffers_.empty() && pending_output_samples_.empty()) {
1200 state_ = kNormal; 1209 SetState(kNormal);
1201 base::MessageLoop::current()->PostTask( 1210 base::MessageLoop::current()->PostTask(
1202 FROM_HERE, 1211 FROM_HERE,
1203 base::Bind(&DXVAVideoDecodeAccelerator::NotifyFlushDone, 1212 base::Bind(&DXVAVideoDecodeAccelerator::NotifyFlushDone,
1204 weak_this_factory_.GetWeakPtr())); 1213 weak_this_factory_.GetWeakPtr()));
1205 } 1214 }
1206 } 1215 }
1207 1216
1208 void DXVAVideoDecodeAccelerator::FlushInternal() { 1217 void DXVAVideoDecodeAccelerator::FlushInternal() {
1218 if (decoder_thread_.thread_id() != ::GetCurrentThreadId()) {
DaleCurtis 2014/12/03 01:04:33 decoder_thread_task_runner_->BelongsToCurrentThrea
ananta 2014/12/03 04:08:02 Done.
1219 decoder_thread_task_runner_->PostTask(FROM_HERE,
1220 base::Bind(&DXVAVideoDecodeAccelerator::FlushInternal,
1221 base::Unretained(this)));
1222 return;
1223 }
1209 // The DoDecode function sets the state to kStopped when the decoder returns 1224 // The DoDecode function sets the state to kStopped when the decoder returns
1210 // MF_E_TRANSFORM_NEED_MORE_INPUT. 1225 // MF_E_TRANSFORM_NEED_MORE_INPUT.
1211 // The MFT decoder can buffer upto 30 frames worth of input before returning 1226 // The MFT decoder can buffer upto 30 frames worth of input before returning
1212 // an output frame. This loop here attempts to retrieve as many output frames 1227 // an output frame. This loop here attempts to retrieve as many output frames
1213 // as possible from the buffered set. 1228 // as possible from the buffered set.
1214 while (state_ != kStopped) { 1229 while (GetState() != kStopped) {
1215 DoDecode(); 1230 DoDecode();
1216 if (!pending_output_samples_.empty()) 1231 if (!pending_output_samples_.empty())
1217 return; 1232 return;
1218 } 1233 }
1219 1234
1220 // TODO(ananta) 1235 // TODO(ananta)
1221 // Look into whether we can simplify this function by combining the while 1236 // Look into whether we can simplify this function by combining the while
1222 // above and the code below into a single block which achieves both. The Flush 1237 // above and the code below into a single block which achieves both. The Flush
1223 // transitions in the decoder are a touch intertwined with other portions of 1238 // transitions in the decoder are a touch intertwined with other portions of
1224 // the code like AssignPictureBuffers, ReusePictureBuffers etc. 1239 // the code like AssignPictureBuffers, ReusePictureBuffers etc.
1225 if (!pending_input_buffers_.empty()) { 1240 if (!pending_input_buffers_.empty()) {
1226 state_ = kFlushingPendingInputBuffers; 1241 SetState(kFlushingPendingInputBuffers);
1227 base::MessageLoop::current()->PostTask( 1242 main_thread_task_runner_->PostTask(
1228 FROM_HERE, 1243 FROM_HERE,
1229 base::Bind(&DXVAVideoDecodeAccelerator::DecodePendingInputBuffers, 1244 base::Bind(&DXVAVideoDecodeAccelerator::DecodePendingInputBuffers,
1230 weak_this_factory_.GetWeakPtr())); 1245 weak_this_factory_.GetWeakPtr()));
1231 return; 1246 return;
1232 } 1247 }
1233 1248
1234 base::MessageLoop::current()->PostTask( 1249 main_thread_task_runner_->PostTask(
1235 FROM_HERE, 1250 FROM_HERE,
1236 base::Bind(&DXVAVideoDecodeAccelerator::NotifyFlushDone, 1251 base::Bind(&DXVAVideoDecodeAccelerator::NotifyFlushDone,
1237 weak_this_factory_.GetWeakPtr())); 1252 weak_this_factory_.GetWeakPtr()));
1238 1253
1239 state_ = kNormal; 1254 SetState(kNormal);
1240 } 1255 }
1241 1256
1242 void DXVAVideoDecodeAccelerator::DecodeInternal( 1257 void DXVAVideoDecodeAccelerator::DecodeInternal(
1243 const base::win::ScopedComPtr<IMFSample>& sample) { 1258 const base::win::ScopedComPtr<IMFSample>& sample) {
1244 DCHECK(CalledOnValidThread()); 1259 if (GetState() == kUninitialized)
DaleCurtis 2014/12/03 01:04:33 Can you replace this with the appropriate DCHECK(t
ananta 2014/12/03 04:08:02 Done.
1245
1246 if (state_ == kUninitialized)
1247 return; 1260 return;
1248 1261
1249 if (!pending_output_samples_.empty() || !pending_input_buffers_.empty()) { 1262 if (!pending_output_samples_.empty() || !pending_input_buffers_.empty()) {
1250 pending_input_buffers_.push_back(sample); 1263 pending_input_buffers_.push_back(sample);
1251 return; 1264 return;
1252 } 1265 }
1253 1266
1254 if (!inputs_before_decode_) { 1267 if (!inputs_before_decode_) {
1255 TRACE_EVENT_BEGIN_ETW("DXVAVideoDecodeAccelerator.Decoding", this, ""); 1268 TRACE_EVENT_BEGIN_ETW("DXVAVideoDecodeAccelerator.Decoding", this, "");
1256 } 1269 }
1257 inputs_before_decode_++; 1270 inputs_before_decode_++;
1258 1271
1259 HRESULT hr = decoder_->ProcessInput(0, sample.get(), 0); 1272 HRESULT hr = decoder_->ProcessInput(0, sample.get(), 0);
1260 // As per msdn if the decoder returns MF_E_NOTACCEPTING then it means that it 1273 // As per msdn if the decoder returns MF_E_NOTACCEPTING then it means that it
1261 // has enough data to produce one or more output samples. In this case the 1274 // has enough data to produce one or more output samples. In this case the
1262 // recommended options are to 1275 // recommended options are to
1263 // 1. Generate new output by calling IMFTransform::ProcessOutput until it 1276 // 1. Generate new output by calling IMFTransform::ProcessOutput until it
1264 // returns MF_E_TRANSFORM_NEED_MORE_INPUT. 1277 // returns MF_E_TRANSFORM_NEED_MORE_INPUT.
1265 // 2. Flush the input data 1278 // 2. Flush the input data
1266 // We implement the first option, i.e to retrieve the output sample and then 1279 // We implement the first option, i.e to retrieve the output sample and then
1267 // process the input again. Failure in either of these steps is treated as a 1280 // process the input again. Failure in either of these steps is treated as a
1268 // decoder failure. 1281 // decoder failure.
1269 if (hr == MF_E_NOTACCEPTING) { 1282 if (hr == MF_E_NOTACCEPTING) {
1270 DoDecode(); 1283 DoDecode();
1271 RETURN_AND_NOTIFY_ON_FAILURE((state_ == kStopped || state_ == kNormal), 1284 State state = GetState();
1272 "Failed to process output. Unexpected decoder state: " << state_, 1285 RETURN_AND_NOTIFY_ON_FAILURE((state == kStopped || state == kNormal ||
1286 state == kFlushing),
1287 "Failed to process output. Unexpected decoder state: " << state,
1273 PLATFORM_FAILURE,); 1288 PLATFORM_FAILURE,);
1274 hr = decoder_->ProcessInput(0, sample.get(), 0); 1289 hr = decoder_->ProcessInput(0, sample.get(), 0);
1275 // If we continue to get the MF_E_NOTACCEPTING error we do the following:- 1290 // If we continue to get the MF_E_NOTACCEPTING error we do the following:-
1276 // 1. Add the input sample to the pending queue. 1291 // 1. Add the input sample to the pending queue.
1277 // 2. If we don't have any output samples we post the 1292 // 2. If we don't have any output samples we post the
1278 // DecodePendingInputBuffers task to process the pending input samples. 1293 // DecodePendingInputBuffers task to process the pending input samples.
1279 // If we have an output sample then the above task is posted when the 1294 // If we have an output sample then the above task is posted when the
1280 // output samples are sent to the client. 1295 // output samples are sent to the client.
1281 // This is because we only support 1 pending output sample at any 1296 // This is because we only support 1 pending output sample at any
1282 // given time due to the limitation with the Microsoft media foundation 1297 // given time due to the limitation with the Microsoft media foundation
1283 // decoder where it recycles the output Decoder surfaces. 1298 // decoder where it recycles the output Decoder surfaces.
1284 if (hr == MF_E_NOTACCEPTING) { 1299 if (hr == MF_E_NOTACCEPTING) {
1285 pending_input_buffers_.push_back(sample); 1300 pending_input_buffers_.push_back(sample);
1286 if (pending_output_samples_.empty()) { 1301 if (pending_output_samples_.empty()) {
1287 base::MessageLoop::current()->PostTask( 1302 base::MessageLoop::current()->PostTask(
1288 FROM_HERE, 1303 FROM_HERE,
1289 base::Bind(&DXVAVideoDecodeAccelerator::DecodePendingInputBuffers, 1304 base::Bind(&DXVAVideoDecodeAccelerator::DecodePendingInputBuffers,
1290 weak_this_factory_.GetWeakPtr())); 1305 weak_this_factory_.GetWeakPtr()));
1291 } 1306 }
1292 return; 1307 return;
1293 } 1308 }
1294 } 1309 }
1295 RETURN_AND_NOTIFY_ON_HR_FAILURE(hr, "Failed to process input sample", 1310 RETURN_AND_NOTIFY_ON_HR_FAILURE(hr, "Failed to process input sample",
1296 PLATFORM_FAILURE,); 1311 PLATFORM_FAILURE,);
1297 1312
1298 DoDecode(); 1313 DoDecode();
1299 1314
1300 RETURN_AND_NOTIFY_ON_FAILURE((state_ == kStopped || state_ == kNormal || 1315 State state = GetState();
1301 state_ == kFlushingPendingInputBuffers), 1316 RETURN_AND_NOTIFY_ON_FAILURE((state == kStopped || state == kNormal ||
1302 "Failed to process output. Unexpected decoder state: " << state_, 1317 state == kFlushingPendingInputBuffers ||
1318 state == kFlushing),
1319 "Failed to process output. Unexpected decoder state: " << state,
1303 ILLEGAL_STATE,); 1320 ILLEGAL_STATE,);
1304 1321
1305 LONGLONG input_buffer_id = 0; 1322 LONGLONG input_buffer_id = 0;
1306 RETURN_ON_HR_FAILURE(sample->GetSampleTime(&input_buffer_id), 1323 RETURN_ON_HR_FAILURE(sample->GetSampleTime(&input_buffer_id),
1307 "Failed to get input buffer id associated with sample",); 1324 "Failed to get input buffer id associated with sample",);
1308 // The Microsoft Media foundation decoder internally buffers up to 30 frames 1325 // The Microsoft Media foundation decoder internally buffers up to 30 frames
1309 // before returning a decoded frame. We need to inform the client that this 1326 // before returning a decoded frame. We need to inform the client that this
1310 // input buffer is processed as it may stop sending us further input. 1327 // input buffer is processed as it may stop sending us further input.
1311 // Note: This may break clients which expect every input buffer to be 1328 // Note: This may break clients which expect every input buffer to be
1312 // associated with a decoded output buffer. 1329 // associated with a decoded output buffer.
1313 // TODO(ananta) 1330 // TODO(ananta)
1314 // Do some more investigation into whether it is possible to get the MFT 1331 // Do some more investigation into whether it is possible to get the MFT
1315 // decoder to emit an output packet for every input packet. 1332 // decoder to emit an output packet for every input packet.
1316 // http://code.google.com/p/chromium/issues/detail?id=108121 1333 // http://code.google.com/p/chromium/issues/detail?id=108121
1317 // http://code.google.com/p/chromium/issues/detail?id=150925 1334 // http://code.google.com/p/chromium/issues/detail?id=150925
1318 base::MessageLoop::current()->PostTask( 1335 main_thread_task_runner_->PostTask(
1319 FROM_HERE, 1336 FROM_HERE,
1320 base::Bind(&DXVAVideoDecodeAccelerator::NotifyInputBufferRead, 1337 base::Bind(&DXVAVideoDecodeAccelerator::NotifyInputBufferRead,
1321 weak_this_factory_.GetWeakPtr(), 1338 weak_this_factory_.GetWeakPtr(),
1322 input_buffer_id)); 1339 input_buffer_id));
1323 } 1340 }
1324 1341
1325 void DXVAVideoDecodeAccelerator::HandleResolutionChanged(int width, 1342 void DXVAVideoDecodeAccelerator::HandleResolutionChanged(int width,
1326 int height) { 1343 int height) {
1327 base::MessageLoop::current()->PostTask( 1344 base::MessageLoop::current()->PostTask(
1328 FROM_HERE, 1345 FROM_HERE,
(...skipping 30 matching lines...) Expand all
1359 void DXVAVideoDecodeAccelerator::DeferredDismissStaleBuffer( 1376 void DXVAVideoDecodeAccelerator::DeferredDismissStaleBuffer(
1360 int32 picture_buffer_id) { 1377 int32 picture_buffer_id) {
1361 OutputBuffers::iterator it = stale_output_picture_buffers_.find( 1378 OutputBuffers::iterator it = stale_output_picture_buffers_.find(
1362 picture_buffer_id); 1379 picture_buffer_id);
1363 DCHECK(it != stale_output_picture_buffers_.end()); 1380 DCHECK(it != stale_output_picture_buffers_.end());
1364 DVLOG(1) << "Dismissing picture id: " << it->second->id(); 1381 DVLOG(1) << "Dismissing picture id: " << it->second->id();
1365 client_->DismissPictureBuffer(it->second->id()); 1382 client_->DismissPictureBuffer(it->second->id());
1366 stale_output_picture_buffers_.erase(it); 1383 stale_output_picture_buffers_.erase(it);
1367 } 1384 }
1368 1385
1386 DXVAVideoDecodeAccelerator::State
1387 DXVAVideoDecodeAccelerator::GetState() const {
1388 State state = kUninitialized;
1389 ::InterlockedExchange(reinterpret_cast<long*>(&state),
1390 state_);
1391 return state;
1392 }
1393
1394 void DXVAVideoDecodeAccelerator::SetState(State new_state) {
1395 ::InterlockedCompareExchange(reinterpret_cast<long*>(&state_),
DaleCurtis 2014/12/03 01:04:33 This can fail if it's racing against another SetSt
ananta 2014/12/03 04:08:02 SetState now runs on the main thread only.
1396 new_state, state_);
1397 }
1398
1399 void DXVAVideoDecodeAccelerator::ResetHelper() {
1400 SetState(kResetting);
1401
1402 PendingInputs pending_input_buffers_copy;
1403 std::swap(pending_input_buffers_, pending_input_buffers_copy);
1404 pending_input_buffers_.clear();
1405
1406 main_thread_task_runner_->PostTask(
1407 FROM_HERE,
1408 base::Bind(&DXVAVideoDecodeAccelerator::NotifyInputBuffersDropped,
1409 weak_this_factory_.GetWeakPtr(),
1410 pending_input_buffers_copy));
1411
1412 RETURN_AND_NOTIFY_ON_FAILURE(SendMFTMessage(MFT_MESSAGE_COMMAND_FLUSH, 0),
1413 "Reset: Failed to send message.", PLATFORM_FAILURE,);
1414
1415 main_thread_task_runner_->PostTask(
1416 FROM_HERE,
1417 base::Bind(&DXVAVideoDecodeAccelerator::NotifyResetDone,
1418 weak_this_factory_.GetWeakPtr()));
1419
1420 SetState(DXVAVideoDecodeAccelerator::kNormal);
1421 }
1422
1369 } // namespace content 1423 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698