| 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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 189 encoded_image->key_frame = true; | 190 encoded_image->key_frame = true; |
| 190 } else { | 191 } else { |
| 191 encoded_image->key_frame = false; | 192 encoded_image->key_frame = false; |
| 192 } | 193 } |
| 193 } | 194 } |
| 194 } | 195 } |
| 195 // Don't update frame_id for zero size frames. | 196 // Don't update frame_id for zero size frames. |
| 196 if (total_size == 0) return true; | 197 if (total_size == 0) return true; |
| 197 | 198 |
| 198 // Populate the encoded frame. | 199 // Populate the encoded frame. |
| 199 encoded_image->codec = kVp8; | 200 encoded_image->codec = transport::kVp8; |
| 200 encoded_image->last_referenced_frame_id = latest_frame_id_to_reference; | 201 encoded_image->last_referenced_frame_id = latest_frame_id_to_reference; |
| 201 encoded_image->frame_id = ++last_encoded_frame_id_; | 202 encoded_image->frame_id = ++last_encoded_frame_id_; |
| 202 | 203 |
| 203 VLOG(1) << "VP8 encoded frame:" << static_cast<int>(encoded_image->frame_id) | 204 VLOG(1) << "VP8 encoded frame:" << static_cast<int>(encoded_image->frame_id) |
| 204 << " sized:" << total_size; | 205 << " sized:" << total_size; |
| 205 | 206 |
| 206 if (encoded_image->key_frame) { | 207 if (encoded_image->key_frame) { |
| 207 key_frame_requested_ = false; | 208 key_frame_requested_ = false; |
| 208 | 209 |
| 209 for (int i = 0; i < kNumberOfVp8VideoBuffers; ++i) { | 210 for (int i = 0; i < kNumberOfVp8VideoBuffers; ++i) { |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 371 float scale_parameter = 0.5; | 372 float scale_parameter = 0.5; |
| 372 uint32 target_pct = optimal_buffer_size_ms * scale_parameter * | 373 uint32 target_pct = optimal_buffer_size_ms * scale_parameter * |
| 373 cast_config_.max_frame_rate / 10; | 374 cast_config_.max_frame_rate / 10; |
| 374 | 375 |
| 375 // Don't go below 3 times the per frame bandwidth. | 376 // Don't go below 3 times the per frame bandwidth. |
| 376 return std::max(target_pct, kMinIntra); | 377 return std::max(target_pct, kMinIntra); |
| 377 } | 378 } |
| 378 | 379 |
| 379 } // namespace cast | 380 } // namespace cast |
| 380 } // namespace media | 381 } // namespace media |
| OLD | NEW |