Chromium Code Reviews| Index: webrtc/modules/video_coding/codecs/h264/h264_encoder_impl.cc |
| diff --git a/webrtc/modules/video_coding/codecs/h264/h264_encoder_impl.cc b/webrtc/modules/video_coding/codecs/h264/h264_encoder_impl.cc |
| index 99402607c1c1071c2303f7ff14312f297beefe91..0ae3640c3248dccd824f0ad4ae4e1d9e216e3b9c 100644 |
| --- a/webrtc/modules/video_coding/codecs/h264/h264_encoder_impl.cc |
| +++ b/webrtc/modules/video_coding/codecs/h264/h264_encoder_impl.cc |
| @@ -20,6 +20,7 @@ |
| #include "webrtc/base/checks.h" |
| #include "webrtc/base/logging.h" |
| #include "webrtc/common_video/libyuv/include/webrtc_libyuv.h" |
| +#include "webrtc/system_wrappers/include/metrics.h" |
| namespace webrtc { |
| @@ -140,7 +141,9 @@ static void RtpFragmentize(EncodedImage* encoded_image, |
| } |
| H264EncoderImpl::H264EncoderImpl() |
| - : openh264_encoder_(nullptr), |
| + : has_reported_init_(false), |
| + has_reported_error_(false), |
| + openh264_encoder_(nullptr), |
| encoded_image_callback_(nullptr) { |
| } |
| @@ -151,18 +154,26 @@ H264EncoderImpl::~H264EncoderImpl() { |
| int32_t H264EncoderImpl::InitEncode(const VideoCodec* codec_settings, |
| int32_t number_of_cores, |
| size_t /*max_payload_size*/) { |
| + ReportInit(); |
| if (!codec_settings || |
| codec_settings->codecType != kVideoCodecH264) { |
| + ReportError(); |
| return WEBRTC_VIDEO_CODEC_ERR_PARAMETER; |
| } |
| - if (codec_settings->maxFramerate == 0) |
| + if (codec_settings->maxFramerate == 0) { |
| + ReportError(); |
| return WEBRTC_VIDEO_CODEC_ERR_PARAMETER; |
| - if (codec_settings->width < 1 || codec_settings->height < 1) |
| + } |
| + if (codec_settings->width < 1 || codec_settings->height < 1) { |
| + ReportError(); |
| return WEBRTC_VIDEO_CODEC_ERR_PARAMETER; |
| + } |
| int32_t release_ret = Release(); |
| - if (release_ret != WEBRTC_VIDEO_CODEC_OK) |
| + if (release_ret != WEBRTC_VIDEO_CODEC_OK) { |
| + ReportError(); |
| return release_ret; |
| + } |
| RTC_DCHECK(!openh264_encoder_); |
| // Create encoder. |
| @@ -170,6 +181,7 @@ int32_t H264EncoderImpl::InitEncode(const VideoCodec* codec_settings, |
| // Failed to create encoder. |
| LOG(LS_ERROR) << "Failed to create OpenH264 encoder"; |
| RTC_DCHECK(!openh264_encoder_); |
| + ReportError(); |
| return WEBRTC_VIDEO_CODEC_ERROR; |
| } |
| RTC_DCHECK(openh264_encoder_); |
| @@ -196,6 +208,7 @@ int32_t H264EncoderImpl::InitEncode(const VideoCodec* codec_settings, |
| } else if (codec_settings_.mode == kScreensharing) { |
| init_params.iUsageType = SCREEN_CONTENT_REAL_TIME; |
| } else { |
| + ReportError(); |
| return WEBRTC_VIDEO_CODEC_ERR_PARAMETER; |
| } |
| init_params.iPicWidth = codec_settings_.width; |
| @@ -236,6 +249,7 @@ int32_t H264EncoderImpl::InitEncode(const VideoCodec* codec_settings, |
| if (openh264_encoder_->InitializeExt(&init_params) != 0) { |
| LOG(LS_ERROR) << "Failed to initialize OpenH264 encoder"; |
| Release(); |
| + ReportError(); |
| return WEBRTC_VIDEO_CODEC_ERROR; |
| } |
| int video_format = EVideoFormatType::videoFormatI420; |
| @@ -299,13 +313,18 @@ int32_t H264EncoderImpl::SetRates(uint32_t bitrate, uint32_t framerate) { |
| int32_t H264EncoderImpl::Encode( |
| const VideoFrame& frame, const CodecSpecificInfo* codec_specific_info, |
| const std::vector<FrameType>* frame_types) { |
| - if (!IsInitialized()) |
| + if (!IsInitialized()) { |
| + ReportError(); |
| return WEBRTC_VIDEO_CODEC_UNINITIALIZED; |
| - if (frame.IsZeroSize()) |
| + } |
| + if (frame.IsZeroSize()) { |
| + ReportError(); |
| return WEBRTC_VIDEO_CODEC_ERR_PARAMETER; |
| + } |
| if (!encoded_image_callback_) { |
| LOG(LS_WARNING) << "InitEncode() has been called, but a callback function " |
| << "has not been set with RegisterEncodeCompleteCallback()"; |
| + ReportError(); |
| return WEBRTC_VIDEO_CODEC_UNINITIALIZED; |
| } |
| if (frame.width() != codec_settings_.width || |
| @@ -313,6 +332,7 @@ int32_t H264EncoderImpl::Encode( |
| LOG(LS_WARNING) << "Encoder initialized for " << codec_settings_.width |
| << "x" << codec_settings_.height << " but trying to encode " |
| << frame.width() << "x" << frame.height() << " frame."; |
| + ReportError(); |
| return WEBRTC_VIDEO_CODEC_ERR_SIZE; |
| } |
| @@ -357,6 +377,7 @@ int32_t H264EncoderImpl::Encode( |
| if (enc_ret != 0) { |
| LOG(LS_ERROR) << "OpenH264 frame encoding failed, EncodeFrame returned " |
| << enc_ret << "."; |
| + ReportError(); |
| return WEBRTC_VIDEO_CODEC_ERROR; |
| } |
| @@ -389,6 +410,26 @@ bool H264EncoderImpl::IsInitialized() const { |
| return openh264_encoder_ != nullptr; |
| } |
| +void H264EncoderImpl::ReportInit() { |
| + if (has_reported_init_) |
| + return; |
| + RTC_HISTOGRAM_COUNTS("WebRTC.Video.H264EncoderImpl.Init", |
|
hlundin-webrtc
2016/02/23 13:55:54
Same again.
hbos
2016/02/23 14:43:26
Done.
|
| + 1 /* sample */, |
| + 1 /* min */, 1 /* max */, |
| + 1 /* bucket count */); |
| + has_reported_init_ = true; |
| +} |
| + |
| +void H264EncoderImpl::ReportError() { |
| + if (has_reported_error_) |
| + return; |
| + RTC_HISTOGRAM_COUNTS("WebRTC.Video.H264EncoderImpl.Error", |
| + 1 /* sample */, |
| + 1 /* min */, 1 /* max */, |
| + 1 /* bucket count */); |
| + has_reported_error_ = true; |
| +} |
| + |
| int32_t H264EncoderImpl::SetChannelParameters( |
| uint32_t packet_loss, int64_t rtt) { |
| return WEBRTC_VIDEO_CODEC_OK; |