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 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/debug/crash_logging.h" | |
11 #include "base/debug/dump_without_crashing.h" | |
12 #include "base/format_macros.h" | |
10 #include "base/logging.h" | 13 #include "base/logging.h" |
11 #include "base/memory/scoped_vector.h" | 14 #include "base/memory/scoped_vector.h" |
12 #include "base/memory/shared_memory.h" | 15 #include "base/memory/shared_memory.h" |
13 #include "base/message_loop/message_loop.h" | 16 #include "base/message_loop/message_loop.h" |
14 #include "base/metrics/histogram.h" | 17 #include "base/metrics/histogram.h" |
18 #include "base/strings/stringprintf.h" | |
15 #include "media/base/video_frame.h" | 19 #include "media/base/video_frame.h" |
16 #include "media/base/video_types.h" | 20 #include "media/base/video_types.h" |
17 #include "media/base/video_util.h" | 21 #include "media/base/video_util.h" |
18 #include "media/cast/cast_defines.h" | 22 #include "media/cast/cast_defines.h" |
19 #include "media/cast/logging/logging_defines.h" | 23 #include "media/cast/logging/logging_defines.h" |
20 #include "media/cast/net/cast_transport_config.h" | 24 #include "media/cast/net/cast_transport_config.h" |
21 #include "media/cast/sender/vp8_quantizer_parser.h" | 25 #include "media/cast/sender/vp8_quantizer_parser.h" |
22 #include "media/filters/h264_parser.h" | 26 #include "media/filters/h264_parser.h" |
23 | 27 |
24 namespace { | 28 namespace { |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
90 task_runner_(encoder_task_runner), | 94 task_runner_(encoder_task_runner), |
91 max_frame_rate_(max_frame_rate), | 95 max_frame_rate_(max_frame_rate), |
92 status_change_cb_(status_change_cb), | 96 status_change_cb_(status_change_cb), |
93 create_video_encode_memory_cb_(create_video_encode_memory_cb), | 97 create_video_encode_memory_cb_(create_video_encode_memory_cb), |
94 video_encode_accelerator_(vea.Pass()), | 98 video_encode_accelerator_(vea.Pass()), |
95 encoder_active_(false), | 99 encoder_active_(false), |
96 next_frame_id_(0u), | 100 next_frame_id_(0u), |
97 key_frame_encountered_(false), | 101 key_frame_encountered_(false), |
98 codec_profile_(media::VIDEO_CODEC_PROFILE_UNKNOWN), | 102 codec_profile_(media::VIDEO_CODEC_PROFILE_UNKNOWN), |
99 key_frame_quantizer_parsable_(false), | 103 key_frame_quantizer_parsable_(false), |
100 requested_bit_rate_(-1) {} | 104 requested_bit_rate_(-1), |
105 has_seen_zero_length_encoded_frame_(false) {} | |
101 | 106 |
102 base::SingleThreadTaskRunner* task_runner() const { | 107 base::SingleThreadTaskRunner* task_runner() const { |
103 return task_runner_.get(); | 108 return task_runner_.get(); |
104 } | 109 } |
105 | 110 |
106 void Initialize(const gfx::Size& frame_size, | 111 void Initialize(const gfx::Size& frame_size, |
107 VideoCodecProfile codec_profile, | 112 VideoCodecProfile codec_profile, |
108 int start_bit_rate, | 113 int start_bit_rate, |
109 uint32 first_frame_id) { | 114 uint32 first_frame_id) { |
110 DCHECK(task_runner_->RunsTasksOnCurrentThread()); | 115 DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
299 codec_profile_ == media::VP8PROFILE_ANY | 304 codec_profile_ == media::VP8PROFILE_ANY |
300 ? static_cast<int>(QuantizerEstimator::MAX_VP8_QUANTIZER) | 305 ? static_cast<int>(QuantizerEstimator::MAX_VP8_QUANTIZER) |
301 : static_cast<int>(MAX_H264_QUANTIZER); | 306 : static_cast<int>(MAX_H264_QUANTIZER); |
302 encoded_frame->lossy_utilization = | 307 encoded_frame->lossy_utilization = |
303 bitrate_utilization * (quantizer / max_quantizer); | 308 bitrate_utilization * (quantizer / max_quantizer); |
304 } | 309 } |
305 } else { | 310 } else { |
306 quantizer_estimator_.Reset(); | 311 quantizer_estimator_.Reset(); |
307 } | 312 } |
308 | 313 |
314 // TODO(miu): Determine when/why encoding can produce zero-length data, | |
315 // which causes crypto crashes. http://crbug.com/519022 | |
316 if (!has_seen_zero_length_encoded_frame_ && encoded_frame->data.empty()) { | |
317 has_seen_zero_length_encoded_frame_ = true; | |
318 | |
319 const char kZeroEncodeDetails[] = "zero-encode-details"; | |
320 const std::string details = base::StringPrintf( | |
321 "%c/%c,id=%" PRIu32 ",rtp=%" PRIu32 ",br=%d,q=%zu,act=%c,ref=%d", | |
brucedawson
2015/11/02 21:22:59
Unfortunately this line of code uses a C99 feature
| |
322 codec_profile_ == media::VP8PROFILE_ANY ? 'V' : 'H', | |
323 key_frame ? 'K' : 'D', encoded_frame->frame_id, | |
324 encoded_frame->rtp_timestamp, request.target_bit_rate / 1000, | |
325 in_progress_frame_encodes_.size(), encoder_active_ ? 'Y' : 'N', | |
326 static_cast<int>(encoded_frame->referenced_frame_id % 1000)); | |
327 base::debug::SetCrashKeyValue(kZeroEncodeDetails, details); | |
328 // Please forward crash reports to http://crbug.com/519022: | |
329 base::debug::DumpWithoutCrashing(); | |
330 base::debug::ClearCrashKey(kZeroEncodeDetails); | |
331 } | |
332 | |
309 cast_environment_->PostTask( | 333 cast_environment_->PostTask( |
310 CastEnvironment::MAIN, | 334 CastEnvironment::MAIN, |
311 FROM_HERE, | 335 FROM_HERE, |
312 base::Bind(&LogFrameEncodedEvent, | 336 base::Bind(&LogFrameEncodedEvent, |
313 cast_environment_, | 337 cast_environment_, |
314 cast_environment_->Clock()->NowTicks(), | 338 cast_environment_->Clock()->NowTicks(), |
315 encoded_frame->rtp_timestamp, | 339 encoded_frame->rtp_timestamp, |
316 encoded_frame->frame_id)); | 340 encoded_frame->frame_id)); |
317 | 341 |
318 cast_environment_->PostTask( | 342 cast_environment_->PostTask( |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
450 | 474 |
451 // FIFO list. | 475 // FIFO list. |
452 std::list<InProgressFrameEncode> in_progress_frame_encodes_; | 476 std::list<InProgressFrameEncode> in_progress_frame_encodes_; |
453 | 477 |
454 // The requested encode bit rate for the next frame. | 478 // The requested encode bit rate for the next frame. |
455 int requested_bit_rate_; | 479 int requested_bit_rate_; |
456 | 480 |
457 // Used to compute utilization metrics for each frame. | 481 // Used to compute utilization metrics for each frame. |
458 QuantizerEstimator quantizer_estimator_; | 482 QuantizerEstimator quantizer_estimator_; |
459 | 483 |
484 // Set to true once a frame with zero-length encoded data has been | |
485 // encountered. | |
486 // TODO(miu): Remove after discovering cause. http://crbug.com/519022 | |
487 bool has_seen_zero_length_encoded_frame_; | |
488 | |
460 DISALLOW_COPY_AND_ASSIGN(VEAClientImpl); | 489 DISALLOW_COPY_AND_ASSIGN(VEAClientImpl); |
461 }; | 490 }; |
462 | 491 |
463 // static | 492 // static |
464 bool ExternalVideoEncoder::IsSupported(const VideoSenderConfig& video_config) { | 493 bool ExternalVideoEncoder::IsSupported(const VideoSenderConfig& video_config) { |
465 if (video_config.codec != CODEC_VIDEO_VP8 && | 494 if (video_config.codec != CODEC_VIDEO_VP8 && |
466 video_config.codec != CODEC_VIDEO_H264) | 495 video_config.codec != CODEC_VIDEO_H264) |
467 return false; | 496 return false; |
468 | 497 |
469 // TODO(miu): "Layering hooks" are needed to be able to query outside of | 498 // TODO(miu): "Layering hooks" are needed to be able to query outside of |
(...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
767 const double kEntropyAtMaxQuantizer = 7.5; | 796 const double kEntropyAtMaxQuantizer = 7.5; |
768 const double slope = | 797 const double slope = |
769 (MAX_VP8_QUANTIZER - MIN_VP8_QUANTIZER) / kEntropyAtMaxQuantizer; | 798 (MAX_VP8_QUANTIZER - MIN_VP8_QUANTIZER) / kEntropyAtMaxQuantizer; |
770 const double quantizer = std::min<double>( | 799 const double quantizer = std::min<double>( |
771 MAX_VP8_QUANTIZER, MIN_VP8_QUANTIZER + slope * shannon_entropy); | 800 MAX_VP8_QUANTIZER, MIN_VP8_QUANTIZER + slope * shannon_entropy); |
772 return quantizer; | 801 return quantizer; |
773 } | 802 } |
774 | 803 |
775 } // namespace cast | 804 } // namespace cast |
776 } // namespace media | 805 } // namespace media |
OLD | NEW |