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

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 431 matching lines...) Expand 10 before | Expand all | Expand 10 after
442 442
443 void UseOutputBitstreamBufferId(int32_t bitstream_buffer_id); 443 void UseOutputBitstreamBufferId(int32_t bitstream_buffer_id);
444 void FrameFinished(std::unique_ptr<base::SharedMemory> shm); 444 void FrameFinished(std::unique_ptr<base::SharedMemory> shm);
445 445
446 // VideoTrackRecorder::Encoder implementation. 446 // VideoTrackRecorder::Encoder implementation.
447 ~VEAEncoder() override; 447 ~VEAEncoder() override;
448 void EncodeOnEncodingTaskRunner(scoped_refptr<VideoFrame> frame, 448 void EncodeOnEncodingTaskRunner(scoped_refptr<VideoFrame> frame,
449 base::TimeTicks capture_timestamp) override; 449 base::TimeTicks capture_timestamp) override;
450 void ConfigureEncoderOnEncodingTaskRunner(const gfx::Size& size) override; 450 void ConfigureEncoderOnEncodingTaskRunner(const gfx::Size& size) override;
451 451
452 void DestroyOnEncodingTaskRunner(base::WaitableEvent* async_waiter);
453
452 media::GpuVideoAcceleratorFactories* const gpu_factories_; 454 media::GpuVideoAcceleratorFactories* const gpu_factories_;
453 455
454 const media::VideoCodecProfile codec_; 456 const media::VideoCodecProfile codec_;
455 457
456 // The underlying VEA to perform encoding on. 458 // The underlying VEA to perform encoding on.
457 std::unique_ptr<media::VideoEncodeAccelerator> video_encoder_; 459 std::unique_ptr<media::VideoEncodeAccelerator> video_encoder_;
458 460
459 // Shared memory buffers for output with the VEA. 461 // Shared memory buffers for output with the VEA.
460 std::vector<std::unique_ptr<base::SharedMemory>> output_buffers_; 462 std::vector<std::unique_ptr<base::SharedMemory>> output_buffers_;
461 463
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
578 DCHECK(gpu_factories_); 580 DCHECK(gpu_factories_);
579 DCHECK_GE(size.width(), kVEAEncoderMinResolutionWidth); 581 DCHECK_GE(size.width(), kVEAEncoderMinResolutionWidth);
580 DCHECK_GE(size.height(), kVEAEncoderMinResolutionHeight); 582 DCHECK_GE(size.height(), kVEAEncoderMinResolutionHeight);
581 583
582 encoding_task_runner_->PostTask( 584 encoding_task_runner_->PostTask(
583 FROM_HERE, base::Bind(&VEAEncoder::ConfigureEncoderOnEncodingTaskRunner, 585 FROM_HERE, base::Bind(&VEAEncoder::ConfigureEncoderOnEncodingTaskRunner,
584 this, size)); 586 this, size));
585 } 587 }
586 588
587 VEAEncoder::~VEAEncoder() { 589 VEAEncoder::~VEAEncoder() {
590 DVLOG(3) << __func__;
mcasas 2017/03/15 01:14:17 nit: remove the DVLOG()s
emircan 2017/03/15 01:36:18 Done.
591
592 base::WaitableEvent release_waiter(
593 base::WaitableEvent::ResetPolicy::MANUAL,
594 base::WaitableEvent::InitialState::NOT_SIGNALED);
595 // base::Unretained is safe because the class will be alive until
596 // |release_waiter| is signaled.
mcasas 2017/03/15 01:14:17 I (still) think we need a comment here saying that
emircan 2017/03/15 01:36:18 Done.
588 encoding_task_runner_->PostTask( 597 encoding_task_runner_->PostTask(
589 FROM_HERE, base::Bind(&media::VideoEncodeAccelerator::Destroy, 598 FROM_HERE, base::Bind(&VEAEncoder::DestroyOnEncodingTaskRunner,
590 base::Unretained(video_encoder_.release()))); 599 base::Unretained(this), &release_waiter));
600 release_waiter.Wait();
591 } 601 }
592 602
593 void VEAEncoder::RequireBitstreamBuffers(unsigned int /*input_count*/, 603 void VEAEncoder::RequireBitstreamBuffers(unsigned int /*input_count*/,
594 const gfx::Size& input_coded_size, 604 const gfx::Size& input_coded_size,
595 size_t output_buffer_size) { 605 size_t output_buffer_size) {
596 DVLOG(3) << __func__; 606 DVLOG(3) << __func__;
597 DCHECK(encoding_task_runner_->BelongsToCurrentThread()); 607 DCHECK(encoding_task_runner_->BelongsToCurrentThread());
598 608
599 vea_requested_input_size_ = input_coded_size; 609 vea_requested_input_size_ = input_coded_size;
600 output_buffers_.clear(); 610 output_buffers_.clear();
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
737 video_frame->stride(media::VideoFrame::kYPlane), 747 video_frame->stride(media::VideoFrame::kYPlane),
738 video_frame->visible_data(media::VideoFrame::kUPlane), 748 video_frame->visible_data(media::VideoFrame::kUPlane),
739 video_frame->stride(media::VideoFrame::kUPlane), 749 video_frame->stride(media::VideoFrame::kUPlane),
740 video_frame->visible_data(media::VideoFrame::kVPlane), 750 video_frame->visible_data(media::VideoFrame::kVPlane),
741 video_frame->stride(media::VideoFrame::kVPlane), 751 video_frame->stride(media::VideoFrame::kVPlane),
742 input_size_.width(), input_size_.height()); 752 input_size_.width(), input_size_.height());
743 } 753 }
744 frames_in_encode_.push(std::make_pair( 754 frames_in_encode_.push(std::make_pair(
745 media::WebmMuxer::VideoParameters(frame), capture_timestamp)); 755 media::WebmMuxer::VideoParameters(frame), capture_timestamp));
746 756
747 encoding_task_runner_->PostTask( 757 video_encoder_->Encode(video_frame, false);
748 FROM_HERE,
749 base::Bind(&media::VideoEncodeAccelerator::Encode,
750 base::Unretained(video_encoder_.get()), video_frame, false));
751 } 758 }
752 759
753 void VEAEncoder::ConfigureEncoderOnEncodingTaskRunner(const gfx::Size& size) { 760 void VEAEncoder::ConfigureEncoderOnEncodingTaskRunner(const gfx::Size& size) {
754 DVLOG(3) << __func__; 761 DVLOG(3) << __func__;
755 DCHECK(encoding_task_runner_->BelongsToCurrentThread()); 762 DCHECK(encoding_task_runner_->BelongsToCurrentThread());
756 DCHECK(gpu_factories_->GetTaskRunner()->BelongsToCurrentThread()); 763 DCHECK(gpu_factories_->GetTaskRunner()->BelongsToCurrentThread());
757 DCHECK_GT(bits_per_second_, 0); 764 DCHECK_GT(bits_per_second_, 0);
758 765
759 input_size_ = size; 766 input_size_ = size;
760 video_encoder_ = gpu_factories_->CreateVideoEncodeAccelerator(); 767 video_encoder_ = gpu_factories_->CreateVideoEncodeAccelerator();
761 if (!video_encoder_ || 768 if (!video_encoder_ ||
762 !video_encoder_->Initialize(media::PIXEL_FORMAT_I420, input_size_, codec_, 769 !video_encoder_->Initialize(media::PIXEL_FORMAT_I420, input_size_, codec_,
763 bits_per_second_, this)) { 770 bits_per_second_, this)) {
764 NotifyError(media::VideoEncodeAccelerator::kPlatformFailureError); 771 NotifyError(media::VideoEncodeAccelerator::kPlatformFailureError);
765 } 772 }
766 } 773 }
767 774
775 void VEAEncoder::DestroyOnEncodingTaskRunner(
776 base::WaitableEvent* async_waiter) {
777 DVLOG(3) << __func__;
778 DCHECK(encoding_task_runner_->BelongsToCurrentThread());
mcasas 2017/03/15 01:14:17 This one as well.
emircan 2017/03/15 01:36:18 Done.
779 video_encoder_.reset();
780 async_waiter->Signal();
781 }
782
768 // static 783 // static
769 void VpxEncoder::ShutdownEncoder(std::unique_ptr<base::Thread> encoding_thread, 784 void VpxEncoder::ShutdownEncoder(std::unique_ptr<base::Thread> encoding_thread,
770 ScopedVpxCodecCtxPtr encoder) { 785 ScopedVpxCodecCtxPtr encoder) {
771 DCHECK(encoding_thread->IsRunning()); 786 DCHECK(encoding_thread->IsRunning());
772 encoding_thread->Stop(); 787 encoding_thread->Stop();
773 // Both |encoding_thread| and |encoder| will be destroyed at end-of-scope. 788 // Both |encoding_thread| and |encoder| will be destroyed at end-of-scope.
774 } 789 }
775 790
776 VpxEncoder::VpxEncoder( 791 VpxEncoder::VpxEncoder(
777 bool use_vp9, 792 bool use_vp9,
(...skipping 452 matching lines...) Expand 10 before | Expand all | Expand 10 after
1230 encoder_->SetPaused(paused_before_init_); 1245 encoder_->SetPaused(paused_before_init_);
1231 1246
1232 // StartFrameEncode() will be called on Render IO thread. 1247 // StartFrameEncode() will be called on Render IO thread.
1233 MediaStreamVideoSink::ConnectToTrack( 1248 MediaStreamVideoSink::ConnectToTrack(
1234 track_, 1249 track_,
1235 base::Bind(&VideoTrackRecorder::Encoder::StartFrameEncode, encoder_), 1250 base::Bind(&VideoTrackRecorder::Encoder::StartFrameEncode, encoder_),
1236 false); 1251 false);
1237 } 1252 }
1238 1253
1239 } // namespace content 1254 } // 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