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

Side by Side Diff: content/renderer/media_recorder/video_track_recorder.cc

Issue 2750993002: Move destruction of VEAEncoder to encoding task runner (Closed)
Patch Set: Created 3 years, 9 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/renderer/media_recorder/video_track_recorder.h" 5 #include "content/renderer/media_recorder/video_track_recorder.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 434 matching lines...) Expand 10 before | Expand all | Expand 10 after
445 void UseOutputBitstreamBufferId(int32_t bitstream_buffer_id); 445 void UseOutputBitstreamBufferId(int32_t bitstream_buffer_id);
446 void FrameFinished(std::unique_ptr<base::SharedMemory> shm); 446 void FrameFinished(std::unique_ptr<base::SharedMemory> shm);
447 447
448 // VideoTrackRecorder::Encoder implementation. 448 // VideoTrackRecorder::Encoder implementation.
449 ~VEAEncoder() override; 449 ~VEAEncoder() override;
450 void EncodeOnEncodingTaskRunner(scoped_refptr<VideoFrame> frame, 450 void EncodeOnEncodingTaskRunner(scoped_refptr<VideoFrame> frame,
451 base::TimeTicks capture_timestamp) override; 451 base::TimeTicks capture_timestamp) override;
452 452
453 void ConfigureEncoderOnEncodingTaskRunner(const gfx::Size& size); 453 void ConfigureEncoderOnEncodingTaskRunner(const gfx::Size& size);
454 454
455 void DestroyOnEncodingTaskRunner(base::WaitableEvent* async_waiter);
456
455 media::GpuVideoAcceleratorFactories* const gpu_factories_; 457 media::GpuVideoAcceleratorFactories* const gpu_factories_;
456 458
457 const media::VideoCodecProfile codec_; 459 const media::VideoCodecProfile codec_;
458 460
459 // The underlying VEA to perform encoding on. 461 // The underlying VEA to perform encoding on.
460 std::unique_ptr<media::VideoEncodeAccelerator> video_encoder_; 462 std::unique_ptr<media::VideoEncodeAccelerator> video_encoder_;
461 463
462 // Shared memory buffers for output with the VEA. 464 // Shared memory buffers for output with the VEA.
463 std::vector<std::unique_ptr<base::SharedMemory>> output_buffers_; 465 std::vector<std::unique_ptr<base::SharedMemory>> output_buffers_;
464 466
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
608 DCHECK(gpu_factories_); 610 DCHECK(gpu_factories_);
609 DCHECK_GE(size.width(), kVEAEncoderMinResolutionWidth); 611 DCHECK_GE(size.width(), kVEAEncoderMinResolutionWidth);
610 DCHECK_GE(size.height(), kVEAEncoderMinResolutionHeight); 612 DCHECK_GE(size.height(), kVEAEncoderMinResolutionHeight);
611 613
612 encoding_task_runner_->PostTask( 614 encoding_task_runner_->PostTask(
613 FROM_HERE, base::Bind(&VEAEncoder::ConfigureEncoderOnEncodingTaskRunner, 615 FROM_HERE, base::Bind(&VEAEncoder::ConfigureEncoderOnEncodingTaskRunner,
614 this, size)); 616 this, size));
615 } 617 }
616 618
617 VEAEncoder::~VEAEncoder() { 619 VEAEncoder::~VEAEncoder() {
620 base::WaitableEvent release_waiter(
621 base::WaitableEvent::ResetPolicy::MANUAL,
622 base::WaitableEvent::InitialState::NOT_SIGNALED);
623 // base::Unretained is safe because the class will be alive until
624 // |release_waiter| is signaled.
625 // TODO(emircan): Consider refactoring media::VideoEncodeAccelerator to avoid
626 // using naked pointers and using DeleteSoon() here, see
627 // http://crbug.com/701627.
628 // It is currently unsafe because |video_encoder_| might be in use on another
629 // function on |encoding_task_runner_|, see http://crbug.com/701030.
618 encoding_task_runner_->PostTask( 630 encoding_task_runner_->PostTask(
619 FROM_HERE, base::Bind(&media::VideoEncodeAccelerator::Destroy, 631 FROM_HERE, base::Bind(&VEAEncoder::DestroyOnEncodingTaskRunner,
620 base::Unretained(video_encoder_.release()))); 632 base::Unretained(this), &release_waiter));
633 release_waiter.Wait();
621 } 634 }
622 635
623 void VEAEncoder::RequireBitstreamBuffers(unsigned int /*input_count*/, 636 void VEAEncoder::RequireBitstreamBuffers(unsigned int /*input_count*/,
624 const gfx::Size& input_coded_size, 637 const gfx::Size& input_coded_size,
625 size_t output_buffer_size) { 638 size_t output_buffer_size) {
626 DVLOG(3) << __func__; 639 DVLOG(3) << __func__;
627 DCHECK(encoding_task_runner_->BelongsToCurrentThread()); 640 DCHECK(encoding_task_runner_->BelongsToCurrentThread());
628 641
629 vea_requested_input_size_ = input_coded_size; 642 vea_requested_input_size_ = input_coded_size;
630 output_buffers_.clear(); 643 output_buffers_.clear();
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
765 video_frame->stride(media::VideoFrame::kYPlane), 778 video_frame->stride(media::VideoFrame::kYPlane),
766 video_frame->visible_data(media::VideoFrame::kUPlane), 779 video_frame->visible_data(media::VideoFrame::kUPlane),
767 video_frame->stride(media::VideoFrame::kUPlane), 780 video_frame->stride(media::VideoFrame::kUPlane),
768 video_frame->visible_data(media::VideoFrame::kVPlane), 781 video_frame->visible_data(media::VideoFrame::kVPlane),
769 video_frame->stride(media::VideoFrame::kVPlane), 782 video_frame->stride(media::VideoFrame::kVPlane),
770 input_size_.width(), input_size_.height()); 783 input_size_.width(), input_size_.height());
771 } 784 }
772 frames_in_encode_.push(std::make_pair( 785 frames_in_encode_.push(std::make_pair(
773 media::WebmMuxer::VideoParameters(frame), capture_timestamp)); 786 media::WebmMuxer::VideoParameters(frame), capture_timestamp));
774 787
775 encoding_task_runner_->PostTask( 788 video_encoder_->Encode(video_frame, false);
776 FROM_HERE,
777 base::Bind(&media::VideoEncodeAccelerator::Encode,
778 base::Unretained(video_encoder_.get()), video_frame, false));
779 } 789 }
780 790
781 void VEAEncoder::ConfigureEncoderOnEncodingTaskRunner(const gfx::Size& size) { 791 void VEAEncoder::ConfigureEncoderOnEncodingTaskRunner(const gfx::Size& size) {
782 DVLOG(3) << __func__; 792 DVLOG(3) << __func__;
783 DCHECK(encoding_task_runner_->BelongsToCurrentThread()); 793 DCHECK(encoding_task_runner_->BelongsToCurrentThread());
784 DCHECK(gpu_factories_->GetTaskRunner()->BelongsToCurrentThread()); 794 DCHECK(gpu_factories_->GetTaskRunner()->BelongsToCurrentThread());
785 DCHECK_GT(bits_per_second_, 0); 795 DCHECK_GT(bits_per_second_, 0);
786 796
787 input_size_ = size; 797 input_size_ = size;
788 video_encoder_ = gpu_factories_->CreateVideoEncodeAccelerator(); 798 video_encoder_ = gpu_factories_->CreateVideoEncodeAccelerator();
789 if (!video_encoder_ || 799 if (!video_encoder_ ||
790 !video_encoder_->Initialize(media::PIXEL_FORMAT_I420, input_size_, codec_, 800 !video_encoder_->Initialize(media::PIXEL_FORMAT_I420, input_size_, codec_,
791 bits_per_second_, this)) { 801 bits_per_second_, this)) {
792 NotifyError(media::VideoEncodeAccelerator::kPlatformFailureError); 802 NotifyError(media::VideoEncodeAccelerator::kPlatformFailureError);
793 } 803 }
794 } 804 }
795 805
806 void VEAEncoder::DestroyOnEncodingTaskRunner(
807 base::WaitableEvent* async_waiter) {
808 DCHECK(encoding_task_runner_->BelongsToCurrentThread());
809 video_encoder_.reset();
810 async_waiter->Signal();
811 }
812
796 // static 813 // static
797 void VpxEncoder::ShutdownEncoder(std::unique_ptr<base::Thread> encoding_thread, 814 void VpxEncoder::ShutdownEncoder(std::unique_ptr<base::Thread> encoding_thread,
798 ScopedVpxCodecCtxPtr encoder) { 815 ScopedVpxCodecCtxPtr encoder) {
799 DCHECK(encoding_thread->IsRunning()); 816 DCHECK(encoding_thread->IsRunning());
800 encoding_thread->Stop(); 817 encoding_thread->Stop();
801 // Both |encoding_thread| and |encoder| will be destroyed at end-of-scope. 818 // Both |encoding_thread| and |encoder| will be destroyed at end-of-scope.
802 } 819 }
803 820
804 VpxEncoder::VpxEncoder( 821 VpxEncoder::VpxEncoder(
805 bool use_vp9, 822 bool use_vp9,
(...skipping 517 matching lines...) Expand 10 before | Expand all | Expand 10 after
1323 base::Bind(&VideoTrackRecorder::Encoder::StartFrameEncode, encoder_), 1340 base::Bind(&VideoTrackRecorder::Encoder::StartFrameEncode, encoder_),
1324 false); 1341 false);
1325 } 1342 }
1326 1343
1327 bool VideoTrackRecorder::CanEncodeAlphaChannelForTesting() { 1344 bool VideoTrackRecorder::CanEncodeAlphaChannelForTesting() {
1328 DCHECK(encoder_); 1345 DCHECK(encoder_);
1329 return encoder_->CanEncodeAlphaChannel(); 1346 return encoder_->CanEncodeAlphaChannel();
1330 } 1347 }
1331 1348
1332 } // namespace content 1349 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698