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 #include "media/cast/sender/vp8_encoder.h" |
6 // protocol and the VP8 specific details. | |
7 #include "media/cast/video_sender/codecs/vp8/vp8_encoder.h" | |
8 | 6 |
9 #include <vector> | 7 #include <vector> |
10 | 8 |
11 #include "base/logging.h" | 9 #include "base/logging.h" |
12 #include "media/base/video_frame.h" | 10 #include "media/base/video_frame.h" |
13 #include "media/cast/cast_defines.h" | 11 #include "media/cast/cast_defines.h" |
14 #include "media/cast/transport/cast_transport_config.h" | 12 #include "media/cast/net/cast_transport_config.h" |
15 #include "third_party/libvpx/source/libvpx/vpx/vp8cx.h" | 13 #include "third_party/libvpx/source/libvpx/vpx/vp8cx.h" |
16 | 14 |
17 namespace media { | 15 namespace media { |
18 namespace cast { | 16 namespace cast { |
19 | 17 |
20 static const uint32 kMinIntra = 300; | 18 static const uint32 kMinIntra = 300; |
21 | 19 |
22 static int ComputeMaxNumOfRepeatedBuffes(int max_unacked_frames) { | 20 static int ComputeMaxNumOfRepeatedBuffes(int max_unacked_frames) { |
23 if (max_unacked_frames > kNumberOfVp8VideoBuffers) | 21 if (max_unacked_frames > kNumberOfVp8VideoBuffers) |
24 return (max_unacked_frames - 1) / kNumberOfVp8VideoBuffers; | 22 return (max_unacked_frames - 1) / kNumberOfVp8VideoBuffers; |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 return; | 126 return; |
129 } | 127 } |
130 vpx_codec_control(encoder_.get(), VP8E_SET_STATIC_THRESHOLD, 1); | 128 vpx_codec_control(encoder_.get(), VP8E_SET_STATIC_THRESHOLD, 1); |
131 vpx_codec_control(encoder_.get(), VP8E_SET_NOISE_SENSITIVITY, 0); | 129 vpx_codec_control(encoder_.get(), VP8E_SET_NOISE_SENSITIVITY, 0); |
132 vpx_codec_control(encoder_.get(), VP8E_SET_CPUUSED, -6); | 130 vpx_codec_control(encoder_.get(), VP8E_SET_CPUUSED, -6); |
133 vpx_codec_control( | 131 vpx_codec_control( |
134 encoder_.get(), VP8E_SET_MAX_INTRA_BITRATE_PCT, rc_max_intra_target); | 132 encoder_.get(), VP8E_SET_MAX_INTRA_BITRATE_PCT, rc_max_intra_target); |
135 } | 133 } |
136 | 134 |
137 bool Vp8Encoder::Encode(const scoped_refptr<media::VideoFrame>& video_frame, | 135 bool Vp8Encoder::Encode(const scoped_refptr<media::VideoFrame>& video_frame, |
138 transport::EncodedFrame* encoded_image) { | 136 EncodedFrame* encoded_image) { |
139 DCHECK(thread_checker_.CalledOnValidThread()); | 137 DCHECK(thread_checker_.CalledOnValidThread()); |
140 // Image in vpx_image_t format. | 138 // Image in vpx_image_t format. |
141 // Input image is const. VP8's raw image is not defined as const. | 139 // Input image is const. VP8's raw image is not defined as const. |
142 raw_image_->planes[PLANE_Y] = | 140 raw_image_->planes[PLANE_Y] = |
143 const_cast<uint8*>(video_frame->data(VideoFrame::kYPlane)); | 141 const_cast<uint8*>(video_frame->data(VideoFrame::kYPlane)); |
144 raw_image_->planes[PLANE_U] = | 142 raw_image_->planes[PLANE_U] = |
145 const_cast<uint8*>(video_frame->data(VideoFrame::kUPlane)); | 143 const_cast<uint8*>(video_frame->data(VideoFrame::kUPlane)); |
146 raw_image_->planes[PLANE_V] = | 144 raw_image_->planes[PLANE_V] = |
147 const_cast<uint8*>(video_frame->data(VideoFrame::kVPlane)); | 145 const_cast<uint8*>(video_frame->data(VideoFrame::kVPlane)); |
148 | 146 |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
209 is_key_frame = !!(pkt->data.frame.flags & VPX_FRAME_IS_KEY); | 207 is_key_frame = !!(pkt->data.frame.flags & VPX_FRAME_IS_KEY); |
210 break; // Done, since all data is provided in one CX_FRAME_PKT packet. | 208 break; // Done, since all data is provided in one CX_FRAME_PKT packet. |
211 } | 209 } |
212 // Don't update frame_id for zero size frames. | 210 // Don't update frame_id for zero size frames. |
213 if (encoded_image->data.empty()) | 211 if (encoded_image->data.empty()) |
214 return true; | 212 return true; |
215 | 213 |
216 // Populate the encoded frame. | 214 // Populate the encoded frame. |
217 encoded_image->frame_id = ++last_encoded_frame_id_; | 215 encoded_image->frame_id = ++last_encoded_frame_id_; |
218 if (is_key_frame) { | 216 if (is_key_frame) { |
219 encoded_image->dependency = transport::EncodedFrame::KEY; | 217 encoded_image->dependency = EncodedFrame::KEY; |
220 encoded_image->referenced_frame_id = encoded_image->frame_id; | 218 encoded_image->referenced_frame_id = encoded_image->frame_id; |
221 } else { | 219 } else { |
222 encoded_image->dependency = transport::EncodedFrame::DEPENDENT; | 220 encoded_image->dependency = EncodedFrame::DEPENDENT; |
223 encoded_image->referenced_frame_id = latest_frame_id_to_reference; | 221 encoded_image->referenced_frame_id = latest_frame_id_to_reference; |
224 } | 222 } |
225 | 223 |
226 DVLOG(1) << "VP8 encoded frame_id " << encoded_image->frame_id | 224 DVLOG(1) << "VP8 encoded frame_id " << encoded_image->frame_id |
227 << ", sized:" << encoded_image->data.size(); | 225 << ", sized:" << encoded_image->data.size(); |
228 | 226 |
229 if (is_key_frame) { | 227 if (is_key_frame) { |
230 key_frame_requested_ = false; | 228 key_frame_requested_ = false; |
231 | 229 |
232 for (int i = 0; i < kNumberOfVp8VideoBuffers; ++i) { | 230 for (int i = 0; i < kNumberOfVp8VideoBuffers; ++i) { |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
406 float scale_parameter = 0.5; | 404 float scale_parameter = 0.5; |
407 uint32 target_pct = optimal_buffer_size_ms * scale_parameter * | 405 uint32 target_pct = optimal_buffer_size_ms * scale_parameter * |
408 cast_config_.max_frame_rate / 10; | 406 cast_config_.max_frame_rate / 10; |
409 | 407 |
410 // Don't go below 3 times the per frame bandwidth. | 408 // Don't go below 3 times the per frame bandwidth. |
411 return std::max(target_pct, kMinIntra); | 409 return std::max(target_pct, kMinIntra); |
412 } | 410 } |
413 | 411 |
414 } // namespace cast | 412 } // namespace cast |
415 } // namespace media | 413 } // namespace media |
OLD | NEW |