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