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

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

Issue 2766753003: Merge 57: 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/video_track_recorder.h" 5 #include "content/renderer/media/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 419 matching lines...) Expand 10 before | Expand all | Expand 10 after
430 430
431 void UseOutputBitstreamBufferId(int32_t bitstream_buffer_id); 431 void UseOutputBitstreamBufferId(int32_t bitstream_buffer_id);
432 void FrameFinished(std::unique_ptr<base::SharedMemory> shm); 432 void FrameFinished(std::unique_ptr<base::SharedMemory> shm);
433 433
434 // VideoTrackRecorder::Encoder implementation. 434 // VideoTrackRecorder::Encoder implementation.
435 ~VEAEncoder() override; 435 ~VEAEncoder() override;
436 void EncodeOnEncodingTaskRunner(scoped_refptr<VideoFrame> frame, 436 void EncodeOnEncodingTaskRunner(scoped_refptr<VideoFrame> frame,
437 base::TimeTicks capture_timestamp) override; 437 base::TimeTicks capture_timestamp) override;
438 void ConfigureEncoderOnEncodingTaskRunner(const gfx::Size& size) override; 438 void ConfigureEncoderOnEncodingTaskRunner(const gfx::Size& size) override;
439 439
440 void DestroyOnEncodingTaskRunner(base::WaitableEvent* async_waiter);
441
440 media::GpuVideoAcceleratorFactories* const gpu_factories_; 442 media::GpuVideoAcceleratorFactories* const gpu_factories_;
441 443
442 const media::VideoCodecProfile codec_; 444 const media::VideoCodecProfile codec_;
443 445
444 // The underlying VEA to perform encoding on. 446 // The underlying VEA to perform encoding on.
445 std::unique_ptr<media::VideoEncodeAccelerator> video_encoder_; 447 std::unique_ptr<media::VideoEncodeAccelerator> video_encoder_;
446 448
447 // Shared memory buffers for output with the VEA. 449 // Shared memory buffers for output with the VEA.
448 std::vector<std::unique_ptr<base::SharedMemory>> output_buffers_; 450 std::vector<std::unique_ptr<base::SharedMemory>> output_buffers_;
449 451
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
566 DCHECK(gpu_factories_); 568 DCHECK(gpu_factories_);
567 DCHECK_GE(size.width(), kVEAEncoderMinResolutionWidth); 569 DCHECK_GE(size.width(), kVEAEncoderMinResolutionWidth);
568 DCHECK_GE(size.height(), kVEAEncoderMinResolutionHeight); 570 DCHECK_GE(size.height(), kVEAEncoderMinResolutionHeight);
569 571
570 encoding_task_runner_->PostTask( 572 encoding_task_runner_->PostTask(
571 FROM_HERE, base::Bind(&VEAEncoder::ConfigureEncoderOnEncodingTaskRunner, 573 FROM_HERE, base::Bind(&VEAEncoder::ConfigureEncoderOnEncodingTaskRunner,
572 this, size)); 574 this, size));
573 } 575 }
574 576
575 VEAEncoder::~VEAEncoder() { 577 VEAEncoder::~VEAEncoder() {
578 base::WaitableEvent release_waiter(
579 base::WaitableEvent::ResetPolicy::MANUAL,
580 base::WaitableEvent::InitialState::NOT_SIGNALED);
581 // base::Unretained is safe because the class will be alive until
582 // |release_waiter| is signaled.
583 // TODO(emircan): Consider refactoring media::VideoEncodeAccelerator to avoid
584 // using naked pointers and using DeleteSoon() here, see
585 // http://crbug.com/701627.
586 // It is currently unsafe because |video_encoder_| might be in use on another
587 // function on |encoding_task_runner_|, see http://crbug.com/701030.
576 encoding_task_runner_->PostTask( 588 encoding_task_runner_->PostTask(
577 FROM_HERE, base::Bind(&media::VideoEncodeAccelerator::Destroy, 589 FROM_HERE, base::Bind(&VEAEncoder::DestroyOnEncodingTaskRunner,
578 base::Unretained(video_encoder_.release()))); 590 base::Unretained(this), &release_waiter));
591 release_waiter.Wait();
579 } 592 }
580 593
581 void VEAEncoder::RequireBitstreamBuffers(unsigned int /*input_count*/, 594 void VEAEncoder::RequireBitstreamBuffers(unsigned int /*input_count*/,
582 const gfx::Size& input_coded_size, 595 const gfx::Size& input_coded_size,
583 size_t output_buffer_size) { 596 size_t output_buffer_size) {
584 DVLOG(3) << __func__; 597 DVLOG(3) << __func__;
585 DCHECK(encoding_task_runner_->BelongsToCurrentThread()); 598 DCHECK(encoding_task_runner_->BelongsToCurrentThread());
586 599
587 vea_requested_input_size_ = input_coded_size; 600 vea_requested_input_size_ = input_coded_size;
588 output_buffers_.clear(); 601 output_buffers_.clear();
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
725 video_frame->stride(media::VideoFrame::kYPlane), 738 video_frame->stride(media::VideoFrame::kYPlane),
726 video_frame->visible_data(media::VideoFrame::kUPlane), 739 video_frame->visible_data(media::VideoFrame::kUPlane),
727 video_frame->stride(media::VideoFrame::kUPlane), 740 video_frame->stride(media::VideoFrame::kUPlane),
728 video_frame->visible_data(media::VideoFrame::kVPlane), 741 video_frame->visible_data(media::VideoFrame::kVPlane),
729 video_frame->stride(media::VideoFrame::kVPlane), 742 video_frame->stride(media::VideoFrame::kVPlane),
730 input_size_.width(), input_size_.height()); 743 input_size_.width(), input_size_.height());
731 } 744 }
732 frames_in_encode_.push(std::make_pair( 745 frames_in_encode_.push(std::make_pair(
733 media::WebmMuxer::VideoParameters(frame), capture_timestamp)); 746 media::WebmMuxer::VideoParameters(frame), capture_timestamp));
734 747
735 encoding_task_runner_->PostTask( 748 video_encoder_->Encode(video_frame, false);
736 FROM_HERE,
737 base::Bind(&media::VideoEncodeAccelerator::Encode,
738 base::Unretained(video_encoder_.get()), video_frame, false));
739 } 749 }
740 750
741 void VEAEncoder::ConfigureEncoderOnEncodingTaskRunner(const gfx::Size& size) { 751 void VEAEncoder::ConfigureEncoderOnEncodingTaskRunner(const gfx::Size& size) {
742 DVLOG(3) << __func__; 752 DVLOG(3) << __func__;
743 DCHECK(encoding_task_runner_->BelongsToCurrentThread()); 753 DCHECK(encoding_task_runner_->BelongsToCurrentThread());
744 DCHECK(gpu_factories_->GetTaskRunner()->BelongsToCurrentThread()); 754 DCHECK(gpu_factories_->GetTaskRunner()->BelongsToCurrentThread());
745 DCHECK_GT(bits_per_second_, 0); 755 DCHECK_GT(bits_per_second_, 0);
746 756
747 input_size_ = size; 757 input_size_ = size;
748 video_encoder_ = gpu_factories_->CreateVideoEncodeAccelerator(); 758 video_encoder_ = gpu_factories_->CreateVideoEncodeAccelerator();
749 if (!video_encoder_ || 759 if (!video_encoder_ ||
750 !video_encoder_->Initialize(media::PIXEL_FORMAT_I420, input_size_, codec_, 760 !video_encoder_->Initialize(media::PIXEL_FORMAT_I420, input_size_, codec_,
751 bits_per_second_, this)) { 761 bits_per_second_, this)) {
752 NotifyError(media::VideoEncodeAccelerator::kPlatformFailureError); 762 NotifyError(media::VideoEncodeAccelerator::kPlatformFailureError);
753 } 763 }
754 } 764 }
755 765
766 void VEAEncoder::DestroyOnEncodingTaskRunner(
767 base::WaitableEvent* async_waiter) {
768 DCHECK(encoding_task_runner_->BelongsToCurrentThread());
769 video_encoder_.reset();
770 async_waiter->Signal();
771 }
772
756 // static 773 // static
757 void VpxEncoder::ShutdownEncoder(std::unique_ptr<base::Thread> encoding_thread, 774 void VpxEncoder::ShutdownEncoder(std::unique_ptr<base::Thread> encoding_thread,
758 ScopedVpxCodecCtxPtr encoder) { 775 ScopedVpxCodecCtxPtr encoder) {
759 DCHECK(encoding_thread->IsRunning()); 776 DCHECK(encoding_thread->IsRunning());
760 encoding_thread->Stop(); 777 encoding_thread->Stop();
761 // Both |encoding_thread| and |encoder| will be destroyed at end-of-scope. 778 // Both |encoding_thread| and |encoder| will be destroyed at end-of-scope.
762 } 779 }
763 780
764 VpxEncoder::VpxEncoder( 781 VpxEncoder::VpxEncoder(
765 bool use_vp9, 782 bool use_vp9,
(...skipping 452 matching lines...) Expand 10 before | Expand all | Expand 10 after
1218 encoder_->SetPaused(paused_before_init_); 1235 encoder_->SetPaused(paused_before_init_);
1219 1236
1220 // StartFrameEncode() will be called on Render IO thread. 1237 // StartFrameEncode() will be called on Render IO thread.
1221 MediaStreamVideoSink::ConnectToTrack( 1238 MediaStreamVideoSink::ConnectToTrack(
1222 track_, 1239 track_,
1223 base::Bind(&VideoTrackRecorder::Encoder::StartFrameEncode, encoder_), 1240 base::Bind(&VideoTrackRecorder::Encoder::StartFrameEncode, encoder_),
1224 false); 1241 false);
1225 } 1242 }
1226 1243
1227 } // namespace content 1244 } // 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