Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "media/gpu/ipc/service/gpu_video_encode_accelerator.h" | 5 #include "media/gpu/ipc/service/gpu_video_encode_accelerator.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "base/callback.h" | 9 #include "base/callback.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 175 weak_this_factory_(this) { | 175 weak_this_factory_(this) { |
| 176 stub_->AddDestructionObserver(this); | 176 stub_->AddDestructionObserver(this); |
| 177 make_context_current_ = | 177 make_context_current_ = |
| 178 base::Bind(&MakeDecoderContextCurrent, stub_->AsWeakPtr()); | 178 base::Bind(&MakeDecoderContextCurrent, stub_->AsWeakPtr()); |
| 179 } | 179 } |
| 180 | 180 |
| 181 GpuVideoEncodeAccelerator::~GpuVideoEncodeAccelerator() { | 181 GpuVideoEncodeAccelerator::~GpuVideoEncodeAccelerator() { |
| 182 // This class can only be self-deleted from OnWillDestroyStub(), which means | 182 // This class can only be self-deleted from OnWillDestroyStub(), which means |
| 183 // the VEA has already been destroyed in there. | 183 // the VEA has already been destroyed in there. |
| 184 DCHECK(!encoder_); | 184 DCHECK(!encoder_); |
| 185 if (encoder_worker_thread_.IsRunning()) { | 185 DCHECK(!encoder_worker_thread_.IsRunning()); |
| 186 encoder_worker_task_runner_->PostTask( | |
| 187 FROM_HERE, | |
| 188 base::Bind(&GpuVideoEncodeAccelerator::DestroyOnEncoderWorker, | |
| 189 weak_this_factory_for_encoder_worker_.GetWeakPtr())); | |
| 190 encoder_worker_thread_.Stop(); | |
| 191 } | |
| 192 } | 186 } |
| 193 | 187 |
| 194 bool GpuVideoEncodeAccelerator::Initialize(VideoPixelFormat input_format, | 188 bool GpuVideoEncodeAccelerator::Initialize(VideoPixelFormat input_format, |
| 195 const gfx::Size& input_visible_size, | 189 const gfx::Size& input_visible_size, |
| 196 VideoCodecProfile output_profile, | 190 VideoCodecProfile output_profile, |
| 197 uint32_t initial_bitrate) { | 191 uint32_t initial_bitrate) { |
| 198 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 192 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
| 199 DVLOG(1) << __func__ | 193 DVLOG(1) << __func__ |
| 200 << " input_format=" << VideoPixelFormatToString(input_format) | 194 << " input_format=" << VideoPixelFormatToString(input_format) |
| 201 << ", input_visible_size=" << input_visible_size.ToString() | 195 << ", input_visible_size=" << input_visible_size.ToString() |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 318 // removed however, since we cannot service incoming messages with VEA gone. | 312 // removed however, since we cannot service incoming messages with VEA gone. |
| 319 // We cannot simply check for existence of VEA on IO thread though, because | 313 // We cannot simply check for existence of VEA on IO thread though, because |
| 320 // we don't want to synchronize the IO thread with the ChildThread. | 314 // we don't want to synchronize the IO thread with the ChildThread. |
| 321 // So we have to wait for the RemoveFilter callback here instead and remove | 315 // So we have to wait for the RemoveFilter callback here instead and remove |
| 322 // the VEA after it arrives and before returning. | 316 // the VEA after it arrives and before returning. |
| 323 if (filter_) { | 317 if (filter_) { |
| 324 stub_->channel()->RemoveFilter(filter_.get()); | 318 stub_->channel()->RemoveFilter(filter_.get()); |
| 325 filter_removed_.Wait(); | 319 filter_removed_.Wait(); |
| 326 } | 320 } |
| 327 | 321 |
| 322 // We should stop |encoder_worker_thread_| before releasing |encoder_|, see | |
| 323 // crbug.com/715759. | |
| 324 if (encoder_worker_thread_.IsRunning()) { | |
| 325 encoder_worker_task_runner_->PostTask( | |
| 326 FROM_HERE, | |
| 327 base::Bind(&GpuVideoEncodeAccelerator::DestroyOnEncoderWorker, | |
| 328 weak_this_factory_for_encoder_worker_.GetWeakPtr())); | |
|
sandersd (OOO until July 31)
2017/04/28 00:47:44
This WeakPtrFactory should probably not be vending
emircan
2017/04/28 01:11:09
Sure. I changed it such that we use copies of the
sandersd (OOO until July 31)
2017/04/28 18:22:44
Please document this in the header file, the curre
emircan
2017/04/29 00:10:46
Done.
| |
| 329 encoder_worker_thread_.Stop(); | |
| 330 } | |
| 331 | |
| 328 stub_->channel()->RemoveRoute(host_route_id_); | 332 stub_->channel()->RemoveRoute(host_route_id_); |
| 329 stub_->RemoveDestructionObserver(this); | 333 stub_->RemoveDestructionObserver(this); |
| 330 encoder_.reset(); | 334 encoder_.reset(); |
| 331 delete this; | 335 delete this; |
| 332 } | 336 } |
| 333 | 337 |
| 334 // static | 338 // static |
| 335 gpu::VideoEncodeAcceleratorSupportedProfiles | 339 gpu::VideoEncodeAcceleratorSupportedProfiles |
| 336 GpuVideoEncodeAccelerator::GetSupportedProfiles( | 340 GpuVideoEncodeAccelerator::GetSupportedProfiles( |
| 337 const gpu::GpuPreferences& gpu_preferences) { | 341 const gpu::GpuPreferences& gpu_preferences) { |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 510 weak_this_factory_for_encoder_worker_.InvalidateWeakPtrs(); | 514 weak_this_factory_for_encoder_worker_.InvalidateWeakPtrs(); |
| 511 } | 515 } |
| 512 | 516 |
| 513 void GpuVideoEncodeAccelerator::OnEncodeFrameCreated( | 517 void GpuVideoEncodeAccelerator::OnEncodeFrameCreated( |
| 514 int32_t frame_id, | 518 int32_t frame_id, |
| 515 bool force_keyframe, | 519 bool force_keyframe, |
| 516 const scoped_refptr<media::VideoFrame>& frame) { | 520 const scoped_refptr<media::VideoFrame>& frame) { |
| 517 DVLOG(3) << __func__; | 521 DVLOG(3) << __func__; |
| 518 DCHECK(CheckIfCalledOnCorrectThread()); | 522 DCHECK(CheckIfCalledOnCorrectThread()); |
| 519 | 523 |
| 524 if (filter_removed_.IsSignaled()) | |
| 525 return; | |
| 526 | |
| 520 if (!frame) { | 527 if (!frame) { |
| 521 DLOG(ERROR) << __func__ << " could not create a frame"; | 528 DLOG(ERROR) << __func__ << " could not create a frame"; |
| 522 NotifyError(VideoEncodeAccelerator::kPlatformFailureError); | 529 NotifyError(VideoEncodeAccelerator::kPlatformFailureError); |
| 523 return; | 530 return; |
| 524 } | 531 } |
| 525 | 532 |
| 526 frame->AddDestructionObserver(BindToCurrentLoop( | 533 frame->AddDestructionObserver(BindToCurrentLoop( |
| 527 base::Bind(&GpuVideoEncodeAccelerator::EncodeFrameFinished, | 534 base::Bind(&GpuVideoEncodeAccelerator::EncodeFrameFinished, |
| 528 weak_this_factory_.GetWeakPtr(), frame_id))); | 535 weak_this_factory_.GetWeakPtr(), frame_id))); |
| 529 encoder_->Encode(frame, force_keyframe); | 536 encoder_->Encode(frame, force_keyframe); |
| 530 } | 537 } |
| 531 | 538 |
| 532 void GpuVideoEncodeAccelerator::EncodeFrameFinished(int32_t frame_id) { | 539 void GpuVideoEncodeAccelerator::EncodeFrameFinished(int32_t frame_id) { |
| 533 DCHECK(CheckIfCalledOnCorrectThread()); | 540 DCHECK(CheckIfCalledOnCorrectThread()); |
| 534 if (!Send(new AcceleratedVideoEncoderHostMsg_NotifyInputDone(host_route_id_, | 541 if (!Send(new AcceleratedVideoEncoderHostMsg_NotifyInputDone(host_route_id_, |
| 535 frame_id))) { | 542 frame_id))) { |
| 536 DLOG(ERROR) << __func__ << " failed."; | 543 DLOG(ERROR) << __func__ << " failed."; |
| 537 } | 544 } |
| 538 } | 545 } |
| 539 | 546 |
| 540 bool GpuVideoEncodeAccelerator::CheckIfCalledOnCorrectThread() { | 547 bool GpuVideoEncodeAccelerator::CheckIfCalledOnCorrectThread() { |
| 541 return (filter_ && io_task_runner_->BelongsToCurrentThread()) || | 548 return (filter_ && io_task_runner_->BelongsToCurrentThread()) || |
| 542 (!filter_ && main_task_runner_->BelongsToCurrentThread()); | 549 (!filter_ && main_task_runner_->BelongsToCurrentThread()); |
| 543 } | 550 } |
| 544 | 551 |
| 545 } // namespace media | 552 } // namespace media |
| OLD | NEW |