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/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/logging/logging_defines.h" | 15 #include "media/cast/logging/logging_defines.h" |
16 #include "media/cast/transport/cast_transport_config.h" | 16 #include "media/cast/net/cast_transport_config.h" |
17 #include "media/video/video_encode_accelerator.h" | 17 #include "media/video/video_encode_accelerator.h" |
18 | 18 |
19 namespace media { | 19 namespace media { |
20 namespace cast { | 20 namespace cast { |
21 class LocalVideoEncodeAcceleratorClient; | 21 class LocalVideoEncodeAcceleratorClient; |
22 } // namespace cast | 22 } // namespace cast |
23 } // namespace media | 23 } // namespace media |
24 | 24 |
25 namespace { | 25 namespace { |
26 static const size_t kOutputBufferCount = 3; | 26 static const size_t kOutputBufferCount = 3; |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 DCHECK(encoder_task_runner_); | 92 DCHECK(encoder_task_runner_); |
93 } | 93 } |
94 | 94 |
95 // Initialize the real HW encoder. | 95 // Initialize the real HW encoder. |
96 void Initialize(const VideoSenderConfig& video_config) { | 96 void Initialize(const VideoSenderConfig& video_config) { |
97 DCHECK(encoder_task_runner_); | 97 DCHECK(encoder_task_runner_); |
98 DCHECK(encoder_task_runner_->RunsTasksOnCurrentThread()); | 98 DCHECK(encoder_task_runner_->RunsTasksOnCurrentThread()); |
99 | 99 |
100 VideoCodecProfile output_profile = media::VIDEO_CODEC_PROFILE_UNKNOWN; | 100 VideoCodecProfile output_profile = media::VIDEO_CODEC_PROFILE_UNKNOWN; |
101 switch (video_config.codec) { | 101 switch (video_config.codec) { |
102 case transport::CODEC_VIDEO_VP8: | 102 case CODEC_VIDEO_VP8: |
103 output_profile = media::VP8PROFILE_MAIN; | 103 output_profile = media::VP8PROFILE_MAIN; |
104 break; | 104 break; |
105 case transport::CODEC_VIDEO_H264: | 105 case CODEC_VIDEO_H264: |
106 output_profile = media::H264PROFILE_MAIN; | 106 output_profile = media::H264PROFILE_MAIN; |
107 break; | 107 break; |
108 case transport::CODEC_VIDEO_FAKE: | 108 case CODEC_VIDEO_FAKE: |
109 NOTREACHED() << "Fake software video encoder cannot be external"; | 109 NOTREACHED() << "Fake software video encoder cannot be external"; |
110 break; | 110 break; |
111 default: | 111 default: |
112 NOTREACHED() << "Video codec not specified or not supported"; | 112 NOTREACHED() << "Video codec not specified or not supported"; |
113 break; | 113 break; |
114 } | 114 } |
115 max_frame_rate_ = video_config.max_frame_rate; | 115 max_frame_rate_ = video_config.max_frame_rate; |
116 | 116 |
117 if (!video_encode_accelerator_->Initialize( | 117 if (!video_encode_accelerator_->Initialize( |
118 media::VideoFrame::I420, | 118 media::VideoFrame::I420, |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
213 } | 213 } |
214 if (key_frame) | 214 if (key_frame) |
215 key_frame_encountered_ = true; | 215 key_frame_encountered_ = true; |
216 if (!key_frame_encountered_) { | 216 if (!key_frame_encountered_) { |
217 // Do not send video until we have encountered the first key frame. | 217 // Do not send video until we have encountered the first key frame. |
218 // Save the bitstream buffer in |stream_header_| to be sent later along | 218 // Save the bitstream buffer in |stream_header_| to be sent later along |
219 // with the first key frame. | 219 // with the first key frame. |
220 stream_header_.append(static_cast<const char*>(output_buffer->memory()), | 220 stream_header_.append(static_cast<const char*>(output_buffer->memory()), |
221 payload_size); | 221 payload_size); |
222 } else if (!encoded_frame_data_storage_.empty()) { | 222 } else if (!encoded_frame_data_storage_.empty()) { |
223 scoped_ptr<transport::EncodedFrame> encoded_frame( | 223 scoped_ptr<EncodedFrame> encoded_frame( |
224 new transport::EncodedFrame()); | 224 new EncodedFrame()); |
225 encoded_frame->dependency = key_frame ? transport::EncodedFrame::KEY : | 225 encoded_frame->dependency = key_frame ? EncodedFrame::KEY : |
226 transport::EncodedFrame::DEPENDENT; | 226 EncodedFrame::DEPENDENT; |
227 encoded_frame->frame_id = ++last_encoded_frame_id_; | 227 encoded_frame->frame_id = ++last_encoded_frame_id_; |
228 if (key_frame) | 228 if (key_frame) |
229 encoded_frame->referenced_frame_id = encoded_frame->frame_id; | 229 encoded_frame->referenced_frame_id = encoded_frame->frame_id; |
230 else | 230 else |
231 encoded_frame->referenced_frame_id = encoded_frame->frame_id - 1; | 231 encoded_frame->referenced_frame_id = encoded_frame->frame_id - 1; |
232 encoded_frame->reference_time = | 232 encoded_frame->reference_time = |
233 encoded_frame_data_storage_.front().capture_time; | 233 encoded_frame_data_storage_.front().capture_time; |
234 encoded_frame->rtp_timestamp = | 234 encoded_frame->rtp_timestamp = |
235 GetVideoRtpTimestamp(encoded_frame->reference_time); | 235 GetVideoRtpTimestamp(encoded_frame->reference_time); |
236 if (!stream_header_.empty()) { | 236 if (!stream_header_.empty()) { |
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
425 key_frame_requested_ = true; | 425 key_frame_requested_ = true; |
426 } | 426 } |
427 | 427 |
428 // Inform the encoder to only reference frames older or equal to frame_id; | 428 // Inform the encoder to only reference frames older or equal to frame_id; |
429 void ExternalVideoEncoder::LatestFrameIdToReference(uint32 /*frame_id*/) { | 429 void ExternalVideoEncoder::LatestFrameIdToReference(uint32 /*frame_id*/) { |
430 // Do nothing not supported. | 430 // Do nothing not supported. |
431 } | 431 } |
432 | 432 |
433 } // namespace cast | 433 } // namespace cast |
434 } // namespace media | 434 } // namespace media |
OLD | NEW |