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 // TODO (pwestin): add a link to the design document describing the generic | 5 // TODO (pwestin): add a link to the design document describing the generic |
6 // protocol and the VP8 specific details. | 6 // protocol and the VP8 specific details. |
7 #include "media/cast/video_sender/codecs/vp8/vp8_encoder.h" | 7 #include "media/cast/video_sender/codecs/vp8/vp8_encoder.h" |
8 | 8 |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "media/base/video_frame.h" | 12 #include "media/base/video_frame.h" |
13 #include "media/cast/cast_defines.h" | 13 #include "media/cast/cast_defines.h" |
| 14 #include "media/cast/transport/cast_transport_config.h" |
14 #include "third_party/libvpx/source/libvpx/vpx/vp8cx.h" | 15 #include "third_party/libvpx/source/libvpx/vpx/vp8cx.h" |
15 | 16 |
16 namespace media { | 17 namespace media { |
17 namespace cast { | 18 namespace cast { |
18 | 19 |
19 static const uint32 kMinIntra = 300; | 20 static const uint32 kMinIntra = 300; |
20 | 21 |
21 Vp8Encoder::Vp8Encoder(const VideoSenderConfig& video_config, | 22 Vp8Encoder::Vp8Encoder(const VideoSenderConfig& video_config, |
22 uint8 max_unacked_frames) | 23 uint8 max_unacked_frames) |
23 : cast_config_(video_config), | 24 : cast_config_(video_config), |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
120 return; | 121 return; |
121 } | 122 } |
122 vpx_codec_control(encoder_.get(), VP8E_SET_STATIC_THRESHOLD, 1); | 123 vpx_codec_control(encoder_.get(), VP8E_SET_STATIC_THRESHOLD, 1); |
123 vpx_codec_control(encoder_.get(), VP8E_SET_NOISE_SENSITIVITY, 0); | 124 vpx_codec_control(encoder_.get(), VP8E_SET_NOISE_SENSITIVITY, 0); |
124 vpx_codec_control(encoder_.get(), VP8E_SET_CPUUSED, -6); | 125 vpx_codec_control(encoder_.get(), VP8E_SET_CPUUSED, -6); |
125 vpx_codec_control(encoder_.get(), VP8E_SET_MAX_INTRA_BITRATE_PCT, | 126 vpx_codec_control(encoder_.get(), VP8E_SET_MAX_INTRA_BITRATE_PCT, |
126 rc_max_intra_target); | 127 rc_max_intra_target); |
127 } | 128 } |
128 | 129 |
129 bool Vp8Encoder::Encode(const scoped_refptr<media::VideoFrame>& video_frame, | 130 bool Vp8Encoder::Encode(const scoped_refptr<media::VideoFrame>& video_frame, |
130 EncodedVideoFrame* encoded_image) { | 131 transport::EncodedVideoFrame* encoded_image) { |
131 // Image in vpx_image_t format. | 132 // Image in vpx_image_t format. |
132 // Input image is const. VP8's raw image is not defined as const. | 133 // Input image is const. VP8's raw image is not defined as const. |
133 raw_image_->planes[PLANE_Y] = | 134 raw_image_->planes[PLANE_Y] = |
134 const_cast<uint8*>(video_frame->data(VideoFrame::kYPlane)); | 135 const_cast<uint8*>(video_frame->data(VideoFrame::kYPlane)); |
135 raw_image_->planes[PLANE_U] = | 136 raw_image_->planes[PLANE_U] = |
136 const_cast<uint8*>(video_frame->data(VideoFrame::kUPlane)); | 137 const_cast<uint8*>(video_frame->data(VideoFrame::kUPlane)); |
137 raw_image_->planes[PLANE_V] = | 138 raw_image_->planes[PLANE_V] = |
138 const_cast<uint8*>(video_frame->data(VideoFrame::kVPlane)); | 139 const_cast<uint8*>(video_frame->data(VideoFrame::kVPlane)); |
139 | 140 |
140 raw_image_->stride[VPX_PLANE_Y] = video_frame->stride(VideoFrame::kYPlane); | 141 raw_image_->stride[VPX_PLANE_Y] = video_frame->stride(VideoFrame::kYPlane); |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
190 encoded_image->key_frame = true; | 191 encoded_image->key_frame = true; |
191 } else { | 192 } else { |
192 encoded_image->key_frame = false; | 193 encoded_image->key_frame = false; |
193 } | 194 } |
194 } | 195 } |
195 } | 196 } |
196 // Don't update frame_id for zero size frames. | 197 // Don't update frame_id for zero size frames. |
197 if (total_size == 0) return true; | 198 if (total_size == 0) return true; |
198 | 199 |
199 // Populate the encoded frame. | 200 // Populate the encoded frame. |
200 encoded_image->codec = kVp8; | 201 encoded_image->codec = transport::kVp8; |
201 encoded_image->last_referenced_frame_id = latest_frame_id_to_reference; | 202 encoded_image->last_referenced_frame_id = latest_frame_id_to_reference; |
202 encoded_image->frame_id = ++last_encoded_frame_id_; | 203 encoded_image->frame_id = ++last_encoded_frame_id_; |
203 | 204 |
204 VLOG(1) << "VP8 encoded frame:" << static_cast<int>(encoded_image->frame_id) | 205 VLOG(1) << "VP8 encoded frame:" << static_cast<int>(encoded_image->frame_id) |
205 << " sized:" << total_size; | 206 << " sized:" << total_size; |
206 | 207 |
207 if (encoded_image->key_frame) { | 208 if (encoded_image->key_frame) { |
208 key_frame_requested_ = false; | 209 key_frame_requested_ = false; |
209 | 210 |
210 for (int i = 0; i < kNumberOfVp8VideoBuffers; ++i) { | 211 for (int i = 0; i < kNumberOfVp8VideoBuffers; ++i) { |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
372 float scale_parameter = 0.5; | 373 float scale_parameter = 0.5; |
373 uint32 target_pct = optimal_buffer_size_ms * scale_parameter * | 374 uint32 target_pct = optimal_buffer_size_ms * scale_parameter * |
374 cast_config_.max_frame_rate / 10; | 375 cast_config_.max_frame_rate / 10; |
375 | 376 |
376 // Don't go below 3 times the per frame bandwidth. | 377 // Don't go below 3 times the per frame bandwidth. |
377 return std::max(target_pct, kMinIntra); | 378 return std::max(target_pct, kMinIntra); |
378 } | 379 } |
379 | 380 |
380 } // namespace cast | 381 } // namespace cast |
381 } // namespace media | 382 } // namespace media |
OLD | NEW |