| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/cast/sender/external_video_encoder.h" | 5 #include "media/cast/sender/external_video_encoder.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/memory/scoped_vector.h" | 9 #include "base/memory/scoped_vector.h" |
| 10 #include "base/memory/shared_memory.h" | 10 #include "base/memory/shared_memory.h" |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 bool result = video_encode_accelerator_->Initialize( | 107 bool result = video_encode_accelerator_->Initialize( |
| 108 media::VideoFrame::I420, | 108 media::VideoFrame::I420, |
| 109 gfx::Size(video_config.width, video_config.height), | 109 gfx::Size(video_config.width, video_config.height), |
| 110 output_profile, | 110 output_profile, |
| 111 video_config.start_bitrate, | 111 video_config.start_bitrate, |
| 112 this); | 112 this); |
| 113 | 113 |
| 114 UMA_HISTOGRAM_BOOLEAN("Cast.Sender.VideoEncodeAcceleratorInitializeSuccess", | 114 UMA_HISTOGRAM_BOOLEAN("Cast.Sender.VideoEncodeAcceleratorInitializeSuccess", |
| 115 result); | 115 result); |
| 116 if (!result) { | 116 if (!result) { |
| 117 NotifyError(VideoEncodeAccelerator::kInvalidArgumentError); | 117 cast_environment_->PostTask( |
| 118 CastEnvironment::MAIN, |
| 119 FROM_HERE, |
| 120 base::Bind(&ExternalVideoEncoder::EncoderInitialized, weak_owner_, |
| 121 false)); |
| 118 return; | 122 return; |
| 119 } | 123 } |
| 120 | 124 |
| 121 // Wait until shared memory is allocated to indicate that encoder is | 125 // Wait until shared memory is allocated to indicate that encoder is |
| 122 // initialized. | 126 // initialized. |
| 123 } | 127 } |
| 124 | 128 |
| 125 // Destroy the VEA on the correct thread. | 129 // Destroy the VEA on the correct thread. |
| 126 void Destroy() { | 130 void Destroy() { |
| 127 DCHECK(encoder_task_runner_.get()); | 131 DCHECK(encoder_task_runner_.get()); |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 335 for (size_t i = 0; i < output_buffers_.size(); ++i) { | 339 for (size_t i = 0; i < output_buffers_.size(); ++i) { |
| 336 video_encode_accelerator_->UseOutputBitstreamBuffer( | 340 video_encode_accelerator_->UseOutputBitstreamBuffer( |
| 337 media::BitstreamBuffer(static_cast<int32>(i), | 341 media::BitstreamBuffer(static_cast<int32>(i), |
| 338 output_buffers_[i]->handle(), | 342 output_buffers_[i]->handle(), |
| 339 output_buffers_[i]->mapped_size())); | 343 output_buffers_[i]->mapped_size())); |
| 340 } | 344 } |
| 341 | 345 |
| 342 cast_environment_->PostTask( | 346 cast_environment_->PostTask( |
| 343 CastEnvironment::MAIN, | 347 CastEnvironment::MAIN, |
| 344 FROM_HERE, | 348 FROM_HERE, |
| 345 base::Bind(&ExternalVideoEncoder::EncoderInitialized, weak_owner_)); | 349 base::Bind(&ExternalVideoEncoder::EncoderInitialized, weak_owner_, |
| 350 true)); |
| 346 } | 351 } |
| 347 | 352 |
| 348 static void DestroyVideoEncodeAcceleratorOnEncoderThread( | 353 static void DestroyVideoEncodeAcceleratorOnEncoderThread( |
| 349 scoped_ptr<media::VideoEncodeAccelerator> vea) { | 354 scoped_ptr<media::VideoEncodeAccelerator> vea) { |
| 350 // VEA::~VEA specialization takes care of calling Destroy() on the VEA impl. | 355 // VEA::~VEA specialization takes care of calling Destroy() on the VEA impl. |
| 351 } | 356 } |
| 352 | 357 |
| 353 friend class base::RefCountedThreadSafe<LocalVideoEncodeAcceleratorClient>; | 358 friend class base::RefCountedThreadSafe<LocalVideoEncodeAcceleratorClient>; |
| 354 | 359 |
| 355 virtual ~LocalVideoEncodeAcceleratorClient() { | 360 virtual ~LocalVideoEncodeAcceleratorClient() { |
| (...skipping 16 matching lines...) Expand all Loading... |
| 372 | 377 |
| 373 // FIFO list. | 378 // FIFO list. |
| 374 std::list<EncodedFrameReturnData> encoded_frame_data_storage_; | 379 std::list<EncodedFrameReturnData> encoded_frame_data_storage_; |
| 375 | 380 |
| 376 DISALLOW_COPY_AND_ASSIGN(LocalVideoEncodeAcceleratorClient); | 381 DISALLOW_COPY_AND_ASSIGN(LocalVideoEncodeAcceleratorClient); |
| 377 }; | 382 }; |
| 378 | 383 |
| 379 ExternalVideoEncoder::ExternalVideoEncoder( | 384 ExternalVideoEncoder::ExternalVideoEncoder( |
| 380 scoped_refptr<CastEnvironment> cast_environment, | 385 scoped_refptr<CastEnvironment> cast_environment, |
| 381 const VideoSenderConfig& video_config, | 386 const VideoSenderConfig& video_config, |
| 387 const CastInitializationCallback& initialization_cb, |
| 382 const CreateVideoEncodeAcceleratorCallback& create_vea_cb, | 388 const CreateVideoEncodeAcceleratorCallback& create_vea_cb, |
| 383 const CreateVideoEncodeMemoryCallback& create_video_encode_mem_cb) | 389 const CreateVideoEncodeMemoryCallback& create_video_encode_mem_cb) |
| 384 : video_config_(video_config), | 390 : video_config_(video_config), |
| 385 cast_environment_(cast_environment), | 391 cast_environment_(cast_environment), |
| 386 encoder_active_(false), | 392 encoder_active_(false), |
| 387 key_frame_requested_(false), | 393 key_frame_requested_(false), |
| 394 initialization_cb_(initialization_cb), |
| 388 weak_factory_(this) { | 395 weak_factory_(this) { |
| 389 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); | 396 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); |
| 390 | 397 |
| 391 video_accelerator_client_ = | 398 video_accelerator_client_ = |
| 392 LocalVideoEncodeAcceleratorClient::Create(cast_environment_, | 399 LocalVideoEncodeAcceleratorClient::Create(cast_environment_, |
| 393 create_vea_cb, | 400 create_vea_cb, |
| 394 create_video_encode_mem_cb, | 401 create_video_encode_mem_cb, |
| 395 weak_factory_.GetWeakPtr()); | 402 weak_factory_.GetWeakPtr()); |
| 396 DCHECK(video_accelerator_client_.get()); | 403 DCHECK(video_accelerator_client_.get()); |
| 397 } | 404 } |
| 398 | 405 |
| 399 ExternalVideoEncoder::~ExternalVideoEncoder() { | 406 ExternalVideoEncoder::~ExternalVideoEncoder() { |
| 400 } | 407 } |
| 401 | 408 |
| 402 void ExternalVideoEncoder::EncoderInitialized() { | 409 void ExternalVideoEncoder::EncoderInitialized(bool success) { |
| 403 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); | 410 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); |
| 404 encoder_active_ = true; | 411 encoder_active_ = success; |
| 412 DCHECK(!initialization_cb_.is_null()); |
| 413 initialization_cb_.Run( |
| 414 success ? |
| 415 STATUS_VIDEO_INITIALIZED : STATUS_HW_VIDEO_ENCODER_NOT_SUPPORTED); |
| 416 initialization_cb_.Reset(); |
| 405 } | 417 } |
| 406 | 418 |
| 407 void ExternalVideoEncoder::EncoderError() { | 419 void ExternalVideoEncoder::EncoderError() { |
| 408 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); | 420 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); |
| 409 encoder_active_ = false; | 421 encoder_active_ = false; |
| 410 } | 422 } |
| 411 | 423 |
| 412 void ExternalVideoEncoder::OnCreateVideoEncodeAccelerator( | 424 void ExternalVideoEncoder::OnCreateVideoEncodeAccelerator( |
| 413 scoped_refptr<base::SingleThreadTaskRunner> encoder_task_runner) { | 425 scoped_refptr<base::SingleThreadTaskRunner> encoder_task_runner) { |
| 414 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); | 426 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 465 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); | 477 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); |
| 466 key_frame_requested_ = true; | 478 key_frame_requested_ = true; |
| 467 } | 479 } |
| 468 | 480 |
| 469 // Inform the encoder to only reference frames older or equal to frame_id; | 481 // Inform the encoder to only reference frames older or equal to frame_id; |
| 470 void ExternalVideoEncoder::LatestFrameIdToReference(uint32 /*frame_id*/) { | 482 void ExternalVideoEncoder::LatestFrameIdToReference(uint32 /*frame_id*/) { |
| 471 // Do nothing not supported. | 483 // Do nothing not supported. |
| 472 } | 484 } |
| 473 } // namespace cast | 485 } // namespace cast |
| 474 } // namespace media | 486 } // namespace media |
| OLD | NEW |