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