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/external_video_encoder.h" | 5 #include "media/cast/sender/external_video_encoder.h" |
6 | 6 |
7 #include <cmath> | 7 #include <cmath> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
53 // The reference time for this frame. | 53 // The reference time for this frame. |
54 const base::TimeTicks reference_time; | 54 const base::TimeTicks reference_time; |
55 | 55 |
56 // The callback to run when the result is ready. | 56 // The callback to run when the result is ready. |
57 const VideoEncoder::FrameEncodedCallback frame_encoded_callback; | 57 const VideoEncoder::FrameEncodedCallback frame_encoded_callback; |
58 | 58 |
59 // The target encode bit rate. | 59 // The target encode bit rate. |
60 const int target_bit_rate; | 60 const int target_bit_rate; |
61 | 61 |
62 // The real-world encode start time. This is used to compute the encoded | 62 // The real-world encode start time. This is used to compute the encoded |
63 // frame's |deadline_utilization| and so it uses the real-world clock instead | 63 // frame's |encoder_utilization| and so it uses the real-world clock instead |
64 // of the CastEnvironment clock, the latter of which might be simulated. | 64 // of the CastEnvironment clock, the latter of which might be simulated. |
65 const base::TimeTicks start_time; | 65 const base::TimeTicks start_time; |
66 | 66 |
67 InProgressFrameEncode(const scoped_refptr<VideoFrame>& v_frame, | 67 InProgressFrameEncode(const scoped_refptr<VideoFrame>& v_frame, |
68 base::TimeTicks r_time, | 68 base::TimeTicks r_time, |
69 VideoEncoder::FrameEncodedCallback callback, | 69 VideoEncoder::FrameEncodedCallback callback, |
70 int bit_rate) | 70 int bit_rate) |
71 : video_frame(v_frame), | 71 : video_frame(v_frame), |
72 reference_time(r_time), | 72 reference_time(r_time), |
73 frame_encoded_callback(callback), | 73 frame_encoded_callback(callback), |
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
300 } | 300 } |
301 encoded_frame->data.append( | 301 encoded_frame->data.append( |
302 static_cast<const char*>(output_buffer->memory()), payload_size); | 302 static_cast<const char*>(output_buffer->memory()), payload_size); |
303 | 303 |
304 // If FRAME_DURATION metadata was provided in the source VideoFrame, | 304 // If FRAME_DURATION metadata was provided in the source VideoFrame, |
305 // compute the utilization metrics. | 305 // compute the utilization metrics. |
306 base::TimeDelta frame_duration; | 306 base::TimeDelta frame_duration; |
307 if (request.video_frame->metadata()->GetTimeDelta( | 307 if (request.video_frame->metadata()->GetTimeDelta( |
308 media::VideoFrameMetadata::FRAME_DURATION, &frame_duration) && | 308 media::VideoFrameMetadata::FRAME_DURATION, &frame_duration) && |
309 frame_duration > base::TimeDelta()) { | 309 frame_duration > base::TimeDelta()) { |
310 // Compute deadline utilization as the real-world time elapsed divided | 310 // Compute encoder utilization as the real-world time elapsed divided |
311 // by the frame duration. | 311 // by the frame duration. |
312 const base::TimeDelta processing_time = | 312 const base::TimeDelta processing_time = |
313 base::TimeTicks::Now() - request.start_time; | 313 base::TimeTicks::Now() - request.start_time; |
314 encoded_frame->deadline_utilization = | 314 encoded_frame->encoder_utilization = |
315 processing_time.InSecondsF() / frame_duration.InSecondsF(); | 315 processing_time.InSecondsF() / frame_duration.InSecondsF(); |
316 | 316 |
317 const double actual_bit_rate = | 317 const double actual_bit_rate = |
318 encoded_frame->data.size() * 8.0 / frame_duration.InSecondsF(); | 318 encoded_frame->data.size() * 8.0 / frame_duration.InSecondsF(); |
319 DCHECK_GT(request.target_bit_rate, 0); | 319 DCHECK_GT(request.target_bit_rate, 0); |
320 const double bitrate_utilization = | 320 const double bitrate_utilization = |
321 actual_bit_rate / request.target_bit_rate; | 321 actual_bit_rate / request.target_bit_rate; |
322 double quantizer = QuantizerEstimator::NO_RESULT; | 322 double quantizer = QuantizerEstimator::NO_RESULT; |
323 // If the quantizer can be parsed from the key frame, try to parse | 323 // If the quantizer can be parsed from the key frame, try to parse |
324 // the following delta frames as well. | 324 // the following delta frames as well. |
(...skipping 569 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
894 const double kEntropyAtMaxQuantizer = 7.5; | 894 const double kEntropyAtMaxQuantizer = 7.5; |
895 const double slope = | 895 const double slope = |
896 (MAX_VP8_QUANTIZER - MIN_VP8_QUANTIZER) / kEntropyAtMaxQuantizer; | 896 (MAX_VP8_QUANTIZER - MIN_VP8_QUANTIZER) / kEntropyAtMaxQuantizer; |
897 const double quantizer = std::min<double>( | 897 const double quantizer = std::min<double>( |
898 MAX_VP8_QUANTIZER, MIN_VP8_QUANTIZER + slope * shannon_entropy); | 898 MAX_VP8_QUANTIZER, MIN_VP8_QUANTIZER + slope * shannon_entropy); |
899 return quantizer; | 899 return quantizer; |
900 } | 900 } |
901 | 901 |
902 } // namespace cast | 902 } // namespace cast |
903 } // namespace media | 903 } // namespace media |
OLD | NEW |