| 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/video_sender/external_video_encoder.h" | 5 #include "media/cast/video_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" |
| 11 #include "base/message_loop/message_loop.h" | 11 #include "base/message_loop/message_loop.h" |
| 12 #include "media/base/video_frame.h" | 12 #include "media/base/video_frame.h" |
| 13 #include "media/base/video_util.h" | 13 #include "media/base/video_util.h" |
| 14 #include "media/cast/cast_defines.h" | 14 #include "media/cast/cast_defines.h" |
| 15 #include "media/cast/transport/cast_transport_config.h" | |
| 16 #include "media/video/video_encode_accelerator.h" | 15 #include "media/video/video_encode_accelerator.h" |
| 17 | 16 |
| 18 namespace { | 17 namespace { |
| 19 // We allocate more input buffers than what is asked for by | 18 // We allocate more input buffers than what is asked for by |
| 20 // RequireBitstreamBuffers() due to potential threading timing. | 19 // RequireBitstreamBuffers() due to potential threading timing. |
| 21 static const int kInputBufferExtraCount = 1; | 20 static const int kInputBufferExtraCount = 1; |
| 22 static const int kOutputBufferCount = 3; | 21 static const int kOutputBufferCount = 3; |
| 23 | 22 |
| 24 void LogFrameEncodedEvent( | 23 void LogFrameEncodedEvent( |
| 25 const base::TimeTicks& now, | 24 const base::TimeTicks& now, |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 DCHECK(encoder_task_runner_); | 71 DCHECK(encoder_task_runner_); |
| 73 | 72 |
| 74 DCHECK(encoder_task_runner_->RunsTasksOnCurrentThread()); | 73 DCHECK(encoder_task_runner_->RunsTasksOnCurrentThread()); |
| 75 | 74 |
| 76 video_encode_accelerator_ = | 75 video_encode_accelerator_ = |
| 77 gpu_factories_->CreateVideoEncodeAccelerator(this).Pass(); | 76 gpu_factories_->CreateVideoEncodeAccelerator(this).Pass(); |
| 78 if (!video_encode_accelerator_) return; | 77 if (!video_encode_accelerator_) return; |
| 79 | 78 |
| 80 VideoCodecProfile output_profile = media::VIDEO_CODEC_PROFILE_UNKNOWN; | 79 VideoCodecProfile output_profile = media::VIDEO_CODEC_PROFILE_UNKNOWN; |
| 81 switch (video_config.codec) { | 80 switch (video_config.codec) { |
| 82 case transport::kVp8: | 81 case kVp8: |
| 83 output_profile = media::VP8PROFILE_MAIN; | 82 output_profile = media::VP8PROFILE_MAIN; |
| 84 break; | 83 break; |
| 85 case transport::kH264: | 84 case kH264: |
| 86 output_profile = media::H264PROFILE_MAIN; | 85 output_profile = media::H264PROFILE_MAIN; |
| 87 break; | 86 break; |
| 88 } | 87 } |
| 89 codec_ = video_config.codec; | 88 codec_ = video_config.codec; |
| 90 max_frame_rate_ = video_config.max_frame_rate; | 89 max_frame_rate_ = video_config.max_frame_rate; |
| 91 | 90 |
| 92 // Asynchronous initialization call; NotifyInitializeDone or NotifyError | 91 // Asynchronous initialization call; NotifyInitializeDone or NotifyError |
| 93 // will be called once the HW is initialized. | 92 // will be called once the HW is initialized. |
| 94 video_encode_accelerator_->Initialize( | 93 video_encode_accelerator_->Initialize( |
| 95 media::VideoFrame::I420, | 94 media::VideoFrame::I420, |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 257 VLOG(1) << "BitstreamBufferReady(): invalid payload_size = " | 256 VLOG(1) << "BitstreamBufferReady(): invalid payload_size = " |
| 258 << payload_size; | 257 << payload_size; |
| 259 NotifyError(media::VideoEncodeAccelerator::kPlatformFailureError); | 258 NotifyError(media::VideoEncodeAccelerator::kPlatformFailureError); |
| 260 return; | 259 return; |
| 261 } | 260 } |
| 262 if (encoded_frame_data_storage_.empty()) { | 261 if (encoded_frame_data_storage_.empty()) { |
| 263 NOTREACHED(); | 262 NOTREACHED(); |
| 264 NotifyError(media::VideoEncodeAccelerator::kPlatformFailureError); | 263 NotifyError(media::VideoEncodeAccelerator::kPlatformFailureError); |
| 265 return; | 264 return; |
| 266 } | 265 } |
| 267 scoped_ptr<transport::EncodedVideoFrame> | 266 scoped_ptr<EncodedVideoFrame> encoded_frame(new EncodedVideoFrame()); |
| 268 encoded_frame(new transport::EncodedVideoFrame()); | |
| 269 | 267 |
| 270 encoded_frame->codec = codec_; | 268 encoded_frame->codec = codec_; |
| 271 encoded_frame->key_frame = key_frame; | 269 encoded_frame->key_frame = key_frame; |
| 272 encoded_frame->last_referenced_frame_id = last_encoded_frame_id_; | 270 encoded_frame->last_referenced_frame_id = last_encoded_frame_id_; |
| 273 last_encoded_frame_id_++; | 271 last_encoded_frame_id_++; |
| 274 encoded_frame->frame_id = last_encoded_frame_id_; | 272 encoded_frame->frame_id = last_encoded_frame_id_; |
| 275 if (key_frame) { | 273 if (key_frame) { |
| 276 // Self referenced. | 274 // Self referenced. |
| 277 encoded_frame->last_referenced_frame_id = encoded_frame->frame_id; | 275 encoded_frame->last_referenced_frame_id = encoded_frame->frame_id; |
| 278 } | 276 } |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 315 | 313 |
| 316 virtual ~LocalVideoEncodeAcceleratorClient() {} | 314 virtual ~LocalVideoEncodeAcceleratorClient() {} |
| 317 | 315 |
| 318 const scoped_refptr<CastEnvironment> cast_environment_; | 316 const scoped_refptr<CastEnvironment> cast_environment_; |
| 319 scoped_refptr<GpuVideoAcceleratorFactories> gpu_factories_; | 317 scoped_refptr<GpuVideoAcceleratorFactories> gpu_factories_; |
| 320 scoped_refptr<base::SingleThreadTaskRunner> encoder_task_runner_; | 318 scoped_refptr<base::SingleThreadTaskRunner> encoder_task_runner_; |
| 321 const base::WeakPtr<ExternalVideoEncoder> weak_owner_; | 319 const base::WeakPtr<ExternalVideoEncoder> weak_owner_; |
| 322 | 320 |
| 323 scoped_ptr<media::VideoEncodeAccelerator> video_encode_accelerator_; | 321 scoped_ptr<media::VideoEncodeAccelerator> video_encode_accelerator_; |
| 324 int max_frame_rate_; | 322 int max_frame_rate_; |
| 325 transport::VideoCodec codec_; | 323 VideoCodec codec_; |
| 326 uint32 last_encoded_frame_id_; | 324 uint32 last_encoded_frame_id_; |
| 327 | 325 |
| 328 // Shared memory buffers for input/output with the VideoAccelerator. | 326 // Shared memory buffers for input/output with the VideoAccelerator. |
| 329 ScopedVector<base::SharedMemory> input_buffers_; | 327 ScopedVector<base::SharedMemory> input_buffers_; |
| 330 ScopedVector<base::SharedMemory> output_buffers_; | 328 ScopedVector<base::SharedMemory> output_buffers_; |
| 331 | 329 |
| 332 // Input buffers ready to be filled with input from Encode(). As a LIFO since | 330 // Input buffers ready to be filled with input from Encode(). As a LIFO since |
| 333 // we don't care about ordering. | 331 // we don't care about ordering. |
| 334 std::vector<int> input_buffers_free_; | 332 std::vector<int> input_buffers_free_; |
| 335 | 333 |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 432 // Do nothing not supported. | 430 // Do nothing not supported. |
| 433 } | 431 } |
| 434 | 432 |
| 435 int ExternalVideoEncoder::NumberOfSkippedFrames() const { | 433 int ExternalVideoEncoder::NumberOfSkippedFrames() const { |
| 436 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); | 434 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); |
| 437 return skip_count_; | 435 return skip_count_; |
| 438 } | 436 } |
| 439 | 437 |
| 440 } // namespace cast | 438 } // namespace cast |
| 441 } // namespace media | 439 } // namespace media |
| OLD | NEW |