| 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/sender/vp8_encoder.h" | 5 #include "media/cast/sender/vp8_encoder.h" |
| 6 | 6 |
| 7 #include "base/debug/crash_logging.h" | 7 #include "base/debug/crash_logging.h" |
| 8 #include "base/debug/dump_without_crashing.h" | 8 #include "base/debug/dump_without_crashing.h" |
| 9 #include "base/format_macros.h" | 9 #include "base/format_macros.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 248 } | 248 } |
| 249 predicted_frame_duration = | 249 predicted_frame_duration = |
| 250 std::max(minimum_frame_duration, | 250 std::max(minimum_frame_duration, |
| 251 std::min(maximum_frame_duration, predicted_frame_duration)); | 251 std::min(maximum_frame_duration, predicted_frame_duration)); |
| 252 last_frame_timestamp_ = video_frame->timestamp(); | 252 last_frame_timestamp_ = video_frame->timestamp(); |
| 253 | 253 |
| 254 // Encode the frame. The presentation time stamp argument here is fixed to | 254 // Encode the frame. The presentation time stamp argument here is fixed to |
| 255 // zero to force the encoder to base its single-frame bandwidth calculations | 255 // zero to force the encoder to base its single-frame bandwidth calculations |
| 256 // entirely on |predicted_frame_duration| and the target bitrate setting being | 256 // entirely on |predicted_frame_duration| and the target bitrate setting being |
| 257 // micro-managed via calls to UpdateRates(). | 257 // micro-managed via calls to UpdateRates(). |
| 258 // If the check fails, invalid arguments were passed to vpx_codec_encode(). |
| 258 CHECK_EQ(vpx_codec_encode(&encoder_, &vpx_image, 0, | 259 CHECK_EQ(vpx_codec_encode(&encoder_, &vpx_image, 0, |
| 259 predicted_frame_duration.InMicroseconds(), | 260 predicted_frame_duration.InMicroseconds(), |
| 260 key_frame_requested_ ? VPX_EFLAG_FORCE_KF : 0, | 261 key_frame_requested_ ? VPX_EFLAG_FORCE_KF : 0, |
| 261 VPX_DL_REALTIME), | 262 VPX_DL_REALTIME), |
| 262 VPX_CODEC_OK) | 263 VPX_CODEC_OK); |
| 263 << "BUG: Invalid arguments passed to vpx_codec_encode()."; | |
| 264 | 264 |
| 265 // Pull data from the encoder, populating a new EncodedFrame. | 265 // Pull data from the encoder, populating a new EncodedFrame. |
| 266 encoded_frame->frame_id = next_frame_id_++; | 266 encoded_frame->frame_id = next_frame_id_++; |
| 267 const vpx_codec_cx_pkt_t* pkt = NULL; | 267 const vpx_codec_cx_pkt_t* pkt = NULL; |
| 268 vpx_codec_iter_t iter = NULL; | 268 vpx_codec_iter_t iter = NULL; |
| 269 while ((pkt = vpx_codec_get_cx_data(&encoder_, &iter)) != NULL) { | 269 while ((pkt = vpx_codec_get_cx_data(&encoder_, &iter)) != NULL) { |
| 270 if (pkt->kind != VPX_CODEC_CX_FRAME_PKT) | 270 if (pkt->kind != VPX_CODEC_CX_FRAME_PKT) |
| 271 continue; | 271 continue; |
| 272 if (pkt->data.frame.flags & VPX_FRAME_IS_KEY) { | 272 if (pkt->data.frame.flags & VPX_FRAME_IS_KEY) { |
| 273 // TODO(hubbe): Replace "dependency" with a "bool is_key_frame". | 273 // TODO(hubbe): Replace "dependency" with a "bool is_key_frame". |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 412 VLOG(1) << "VP8 new rc_target_bitrate: " << new_bitrate_kbit << " kbps"; | 412 VLOG(1) << "VP8 new rc_target_bitrate: " << new_bitrate_kbit << " kbps"; |
| 413 } | 413 } |
| 414 | 414 |
| 415 void Vp8Encoder::GenerateKeyFrame() { | 415 void Vp8Encoder::GenerateKeyFrame() { |
| 416 DCHECK(thread_checker_.CalledOnValidThread()); | 416 DCHECK(thread_checker_.CalledOnValidThread()); |
| 417 key_frame_requested_ = true; | 417 key_frame_requested_ = true; |
| 418 } | 418 } |
| 419 | 419 |
| 420 } // namespace cast | 420 } // namespace cast |
| 421 } // namespace media | 421 } // namespace media |
| OLD | NEW |