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 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
222 encoded_frame->dependency = EncodedFrame::DEPENDENT; | 222 encoded_frame->dependency = EncodedFrame::DEPENDENT; |
223 // Frame dependencies could theoretically be relaxed by looking for the | 223 // Frame dependencies could theoretically be relaxed by looking for the |
224 // VPX_FRAME_IS_DROPPABLE flag, but in recent testing (Oct 2014), this | 224 // VPX_FRAME_IS_DROPPABLE flag, but in recent testing (Oct 2014), this |
225 // flag never seems to be set. | 225 // flag never seems to be set. |
226 encoded_frame->referenced_frame_id = last_encoded_frame_id_ - 1; | 226 encoded_frame->referenced_frame_id = last_encoded_frame_id_ - 1; |
227 } | 227 } |
228 encoded_frame->rtp_timestamp = | 228 encoded_frame->rtp_timestamp = |
229 TimeDeltaToRtpDelta(video_frame->timestamp(), kVideoFrequency); | 229 TimeDeltaToRtpDelta(video_frame->timestamp(), kVideoFrequency); |
230 encoded_frame->reference_time = reference_time; | 230 encoded_frame->reference_time = reference_time; |
231 encoded_frame->data.assign( | 231 encoded_frame->data.assign( |
232 static_cast<const uint8*>(pkt->data.frame.buf), | 232 static_cast<const uint8_t*>(pkt->data.frame.buf), |
233 static_cast<const uint8*>(pkt->data.frame.buf) + pkt->data.frame.sz); | 233 static_cast<const uint8_t*>(pkt->data.frame.buf) + pkt->data.frame.sz); |
234 break; // Done, since all data is provided in one CX_FRAME_PKT packet. | 234 break; // Done, since all data is provided in one CX_FRAME_PKT packet. |
235 } | 235 } |
236 DCHECK(!encoded_frame->data.empty()) | 236 DCHECK(!encoded_frame->data.empty()) |
237 << "BUG: Encoder must provide data since lagged encoding is disabled."; | 237 << "BUG: Encoder must provide data since lagged encoding is disabled."; |
238 | 238 |
239 // TODO(miu): Determine when/why encoding can produce zero-length data, | 239 // TODO(miu): Determine when/why encoding can produce zero-length data, |
240 // which causes crypto crashes. http://crbug.com/519022 | 240 // which causes crypto crashes. http://crbug.com/519022 |
241 if (!has_seen_zero_length_encoded_frame_ && encoded_frame->data.empty()) { | 241 if (!has_seen_zero_length_encoded_frame_ && encoded_frame->data.empty()) { |
242 has_seen_zero_length_encoded_frame_ = true; | 242 has_seen_zero_length_encoded_frame_ = true; |
243 | 243 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
284 << ", sized: " << encoded_frame->data.size() | 284 << ", sized: " << encoded_frame->data.size() |
285 << ", deadline_utilization: " << encoded_frame->deadline_utilization | 285 << ", deadline_utilization: " << encoded_frame->deadline_utilization |
286 << ", lossy_utilization: " << encoded_frame->lossy_utilization | 286 << ", lossy_utilization: " << encoded_frame->lossy_utilization |
287 << " (quantizer chosen by the encoder was " << quantizer << ')'; | 287 << " (quantizer chosen by the encoder was " << quantizer << ')'; |
288 | 288 |
289 if (encoded_frame->dependency == EncodedFrame::KEY) { | 289 if (encoded_frame->dependency == EncodedFrame::KEY) { |
290 key_frame_requested_ = false; | 290 key_frame_requested_ = false; |
291 } | 291 } |
292 } | 292 } |
293 | 293 |
294 void Vp8Encoder::UpdateRates(uint32 new_bitrate) { | 294 void Vp8Encoder::UpdateRates(uint32_t new_bitrate) { |
295 DCHECK(thread_checker_.CalledOnValidThread()); | 295 DCHECK(thread_checker_.CalledOnValidThread()); |
296 | 296 |
297 if (!is_initialized()) | 297 if (!is_initialized()) |
298 return; | 298 return; |
299 | 299 |
300 uint32 new_bitrate_kbit = new_bitrate / 1000; | 300 uint32_t new_bitrate_kbit = new_bitrate / 1000; |
301 if (config_.rc_target_bitrate == new_bitrate_kbit) | 301 if (config_.rc_target_bitrate == new_bitrate_kbit) |
302 return; | 302 return; |
303 | 303 |
304 config_.rc_target_bitrate = bitrate_kbit_ = new_bitrate_kbit; | 304 config_.rc_target_bitrate = bitrate_kbit_ = new_bitrate_kbit; |
305 | 305 |
306 // Update encoder context. | 306 // Update encoder context. |
307 if (vpx_codec_enc_config_set(&encoder_, &config_)) { | 307 if (vpx_codec_enc_config_set(&encoder_, &config_)) { |
308 NOTREACHED() << "Invalid return value"; | 308 NOTREACHED() << "Invalid return value"; |
309 } | 309 } |
310 | 310 |
311 VLOG(1) << "VP8 new rc_target_bitrate: " << new_bitrate_kbit << " kbps"; | 311 VLOG(1) << "VP8 new rc_target_bitrate: " << new_bitrate_kbit << " kbps"; |
312 } | 312 } |
313 | 313 |
314 void Vp8Encoder::GenerateKeyFrame() { | 314 void Vp8Encoder::GenerateKeyFrame() { |
315 DCHECK(thread_checker_.CalledOnValidThread()); | 315 DCHECK(thread_checker_.CalledOnValidThread()); |
316 key_frame_requested_ = true; | 316 key_frame_requested_ = true; |
317 } | 317 } |
318 | 318 |
319 } // namespace cast | 319 } // namespace cast |
320 } // namespace media | 320 } // namespace media |
OLD | NEW |