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

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

Issue 10749019: VideoDecodeAccelerator now SupportsWeakPtr instead of being RefCountedThreadSafe. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Pure rebase Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | 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 "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 530 matching lines...) Expand 10 before | Expand all | Expand 10 after
541 SendMFTMessage(MFT_MESSAGE_NOTIFY_BEGIN_STREAMING, 0), 541 SendMFTMessage(MFT_MESSAGE_NOTIFY_BEGIN_STREAMING, 0),
542 "Send MFT_MESSAGE_NOTIFY_BEGIN_STREAMING notification failed", 542 "Send MFT_MESSAGE_NOTIFY_BEGIN_STREAMING notification failed",
543 PLATFORM_FAILURE, false); 543 PLATFORM_FAILURE, false);
544 544
545 RETURN_AND_NOTIFY_ON_FAILURE( 545 RETURN_AND_NOTIFY_ON_FAILURE(
546 SendMFTMessage(MFT_MESSAGE_NOTIFY_START_OF_STREAM, 0), 546 SendMFTMessage(MFT_MESSAGE_NOTIFY_START_OF_STREAM, 0),
547 "Send MFT_MESSAGE_NOTIFY_START_OF_STREAM notification failed", 547 "Send MFT_MESSAGE_NOTIFY_START_OF_STREAM notification failed",
548 PLATFORM_FAILURE, false); 548 PLATFORM_FAILURE, false);
549 549
550 state_ = kNormal; 550 state_ = kNormal;
551 MessageLoop::current()->PostTask(FROM_HERE, 551 MessageLoop::current()->PostTask(FROM_HERE, base::Bind(
552 base::Bind(&DXVAVideoDecodeAccelerator::NotifyInitializeDone, this)); 552 &DXVAVideoDecodeAccelerator::NotifyInitializeDone,
553 base::AsWeakPtr(this)));
553 return true; 554 return true;
554 } 555 }
555 556
556 void DXVAVideoDecodeAccelerator::Decode( 557 void DXVAVideoDecodeAccelerator::Decode(
557 const media::BitstreamBuffer& bitstream_buffer) { 558 const media::BitstreamBuffer& bitstream_buffer) {
558 DCHECK(CalledOnValidThread()); 559 DCHECK(CalledOnValidThread());
559 560
560 RETURN_AND_NOTIFY_ON_FAILURE((state_ == kNormal || state_ == kStopped), 561 RETURN_AND_NOTIFY_ON_FAILURE((state_ == kNormal || state_ == kStopped),
561 "Invalid state: " << state_, ILLEGAL_STATE,); 562 "Invalid state: " << state_, ILLEGAL_STATE,);
562 563
(...skipping 27 matching lines...) Expand all
590 // The Microsoft Media foundation decoder internally buffers up to 30 frames 591 // The Microsoft Media foundation decoder internally buffers up to 30 frames
591 // before returning a decoded frame. We need to inform the client that this 592 // before returning a decoded frame. We need to inform the client that this
592 // input buffer is processed as it may stop sending us further input. 593 // input buffer is processed as it may stop sending us further input.
593 // Note: This may break clients which expect every input buffer to be 594 // Note: This may break clients which expect every input buffer to be
594 // associated with a decoded output buffer. 595 // associated with a decoded output buffer.
595 // TODO(ananta) 596 // TODO(ananta)
596 // Do some more investigation into whether it is possible to get the MFT 597 // Do some more investigation into whether it is possible to get the MFT
597 // decoder to emit an output packet for every input packet. 598 // decoder to emit an output packet for every input packet.
598 // http://code.google.com/p/chromium/issues/detail?id=108121 599 // http://code.google.com/p/chromium/issues/detail?id=108121
599 MessageLoop::current()->PostTask(FROM_HERE, base::Bind( 600 MessageLoop::current()->PostTask(FROM_HERE, base::Bind(
600 &DXVAVideoDecodeAccelerator::NotifyInputBufferRead, this, 601 &DXVAVideoDecodeAccelerator::NotifyInputBufferRead, base::AsWeakPtr(this),
601 bitstream_buffer.id())); 602 bitstream_buffer.id()));
602 } 603 }
603 604
604 void DXVAVideoDecodeAccelerator::AssignPictureBuffers( 605 void DXVAVideoDecodeAccelerator::AssignPictureBuffers(
605 const std::vector<media::PictureBuffer>& buffers) { 606 const std::vector<media::PictureBuffer>& buffers) {
606 DCHECK(CalledOnValidThread()); 607 DCHECK(CalledOnValidThread());
607 // Copy the picture buffers provided by the client to the available list, 608 // Copy the picture buffers provided by the client to the available list,
608 // and mark these buffers as available for use. 609 // and mark these buffers as available for use.
609 for (size_t buffer_index = 0; buffer_index < buffers.size(); 610 for (size_t buffer_index = 0; buffer_index < buffers.size();
610 ++buffer_index) { 611 ++buffer_index) {
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
651 // the state to kStopped when the decoder returns 652 // the state to kStopped when the decoder returns
652 // MF_E_TRANSFORM_NEED_MORE_INPUT. 653 // MF_E_TRANSFORM_NEED_MORE_INPUT.
653 // The MFT decoder can buffer upto 30 frames worth of input before returning 654 // The MFT decoder can buffer upto 30 frames worth of input before returning
654 // an output frame. This loop here attempts to retrieve as many output frames 655 // an output frame. This loop here attempts to retrieve as many output frames
655 // as possible from the buffered set. 656 // as possible from the buffered set.
656 while (state_ != kStopped) { 657 while (state_ != kStopped) {
657 DoDecode(); 658 DoDecode();
658 } 659 }
659 660
660 MessageLoop::current()->PostTask(FROM_HERE, base::Bind( 661 MessageLoop::current()->PostTask(FROM_HERE, base::Bind(
661 &DXVAVideoDecodeAccelerator::NotifyFlushDone, this)); 662 &DXVAVideoDecodeAccelerator::NotifyFlushDone, base::AsWeakPtr(this)));
662 663
663 state_ = kNormal; 664 state_ = kNormal;
664 } 665 }
665 666
666 void DXVAVideoDecodeAccelerator::Reset() { 667 void DXVAVideoDecodeAccelerator::Reset() {
667 DCHECK(CalledOnValidThread()); 668 DCHECK(CalledOnValidThread());
668 669
669 DVLOG(1) << "DXVAVideoDecodeAccelerator::Reset"; 670 DVLOG(1) << "DXVAVideoDecodeAccelerator::Reset";
670 671
671 RETURN_AND_NOTIFY_ON_FAILURE((state_ == kNormal || state_ == kStopped), 672 RETURN_AND_NOTIFY_ON_FAILURE((state_ == kNormal || state_ == kStopped),
672 "Reset: invalid state: " << state_, ILLEGAL_STATE,); 673 "Reset: invalid state: " << state_, ILLEGAL_STATE,);
673 674
674 state_ = kResetting; 675 state_ = kResetting;
675 676
676 RETURN_AND_NOTIFY_ON_FAILURE(SendMFTMessage(MFT_MESSAGE_COMMAND_FLUSH, 0), 677 RETURN_AND_NOTIFY_ON_FAILURE(SendMFTMessage(MFT_MESSAGE_COMMAND_FLUSH, 0),
677 "Reset: Failed to send message.", PLATFORM_FAILURE,); 678 "Reset: Failed to send message.", PLATFORM_FAILURE,);
678 679
679 MessageLoop::current()->PostTask(FROM_HERE, base::Bind( 680 MessageLoop::current()->PostTask(FROM_HERE, base::Bind(
680 &DXVAVideoDecodeAccelerator::NotifyResetDone, this)); 681 &DXVAVideoDecodeAccelerator::NotifyResetDone, base::AsWeakPtr(this)));
681 682
682 state_ = DXVAVideoDecodeAccelerator::kNormal; 683 state_ = DXVAVideoDecodeAccelerator::kNormal;
683 } 684 }
684 685
685 void DXVAVideoDecodeAccelerator::Destroy() { 686 void DXVAVideoDecodeAccelerator::Destroy(bool pass_ownership) {
686 DCHECK(CalledOnValidThread()); 687 DCHECK(CalledOnValidThread());
687 Invalidate(); 688 Invalidate();
689 if (pass_ownership)
690 delete this;
688 } 691 }
689 692
690 bool DXVAVideoDecodeAccelerator::InitDecoder() { 693 bool DXVAVideoDecodeAccelerator::InitDecoder() {
691 // We cannot use CoCreateInstance to instantiate the decoder object as that 694 // We cannot use CoCreateInstance to instantiate the decoder object as that
692 // fails in the sandbox. We mimic the steps CoCreateInstance uses to 695 // fails in the sandbox. We mimic the steps CoCreateInstance uses to
693 // instantiate the object. 696 // instantiate the object.
694 HMODULE decoder_dll = ::GetModuleHandle(L"msmpeg2vdec.dll"); 697 HMODULE decoder_dll = ::GetModuleHandle(L"msmpeg2vdec.dll");
695 RETURN_ON_FAILURE(decoder_dll, 698 RETURN_ON_FAILURE(decoder_dll,
696 "msmpeg2vdec.dll required for decoding is not loaded", 699 "msmpeg2vdec.dll required for decoding is not loaded",
697 false); 700 false);
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after
939 ProcessPendingSamples(); 942 ProcessPendingSamples();
940 return true; 943 return true;
941 } 944 }
942 if (pictures_requested_) { 945 if (pictures_requested_) {
943 DVLOG(1) << "Waiting for picture slots from the client."; 946 DVLOG(1) << "Waiting for picture slots from the client.";
944 return true; 947 return true;
945 } 948 }
946 // Go ahead and request picture buffers. 949 // Go ahead and request picture buffers.
947 MessageLoop::current()->PostTask(FROM_HERE, base::Bind( 950 MessageLoop::current()->PostTask(FROM_HERE, base::Bind(
948 &DXVAVideoDecodeAccelerator::RequestPictureBuffers, 951 &DXVAVideoDecodeAccelerator::RequestPictureBuffers,
949 this, surface_desc.Width, surface_desc.Height)); 952 base::AsWeakPtr(this), surface_desc.Width, surface_desc.Height));
950 953
951 pictures_requested_ = true; 954 pictures_requested_ = true;
952 return true; 955 return true;
953 } 956 }
954 957
955 void DXVAVideoDecodeAccelerator::ProcessPendingSamples() { 958 void DXVAVideoDecodeAccelerator::ProcessPendingSamples() {
956 if (pending_output_samples_.empty()) 959 if (pending_output_samples_.empty())
957 return; 960 return;
958 961
959 OutputBuffers::iterator index; 962 OutputBuffers::iterator index;
960 963
961 for (index = output_picture_buffers_.begin(); 964 for (index = output_picture_buffers_.begin();
962 index != output_picture_buffers_.end() && 965 index != output_picture_buffers_.end() &&
963 !pending_output_samples_.empty(); 966 !pending_output_samples_.empty();
964 ++index) { 967 ++index) {
965 if (index->second->available()) { 968 if (index->second->available()) {
966 PendingSampleInfo sample_info = pending_output_samples_.front(); 969 PendingSampleInfo sample_info = pending_output_samples_.front();
967 970
968 RETURN_AND_NOTIFY_ON_FAILURE( 971 RETURN_AND_NOTIFY_ON_FAILURE(
969 index->second->CopyOutputSampleDataToPictureBuffer( 972 index->second->CopyOutputSampleDataToPictureBuffer(
970 sample_info.dest_surface), 973 sample_info.dest_surface),
971 "Failed to copy output sample", PLATFORM_FAILURE,); 974 "Failed to copy output sample", PLATFORM_FAILURE,);
972 975
973 media::Picture output_picture(index->second->id(), 976 media::Picture output_picture(index->second->id(),
974 sample_info.input_buffer_id); 977 sample_info.input_buffer_id);
975 MessageLoop::current()->PostTask(FROM_HERE, base::Bind( 978 MessageLoop::current()->PostTask(FROM_HERE, base::Bind(
976 &DXVAVideoDecodeAccelerator::NotifyPictureReady, this, 979 &DXVAVideoDecodeAccelerator::NotifyPictureReady,
977 output_picture)); 980 base::AsWeakPtr(this), output_picture));
978 981
979 index->second->set_available(false); 982 index->second->set_available(false);
980 pending_output_samples_.pop_front(); 983 pending_output_samples_.pop_front();
981 } 984 }
982 } 985 }
983 } 986 }
984 987
985 void DXVAVideoDecodeAccelerator::ClearState() { 988 void DXVAVideoDecodeAccelerator::ClearState() {
986 output_picture_buffers_.clear(); 989 output_picture_buffers_.clear();
987 pending_output_samples_.clear(); 990 pending_output_samples_.clear();
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
1040 GL_TEXTURE_2D); 1043 GL_TEXTURE_2D);
1041 } 1044 }
1042 } 1045 }
1043 1046
1044 void DXVAVideoDecodeAccelerator::NotifyPictureReady( 1047 void DXVAVideoDecodeAccelerator::NotifyPictureReady(
1045 const media::Picture& picture) { 1048 const media::Picture& picture) {
1046 // This task could execute after the decoder has been torn down. 1049 // This task could execute after the decoder has been torn down.
1047 if (state_ != kUninitialized && client_) 1050 if (state_ != kUninitialized && client_)
1048 client_->PictureReady(picture); 1051 client_->PictureReady(picture);
1049 } 1052 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698