Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(166)

Unified Diff: webrtc/modules/video_coding/codecs/test/videoprocessor.cc

Issue 2684223002: Use std::unique_ptr in VideoProcessor. (Closed)
Patch Set: Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: webrtc/modules/video_coding/codecs/test/videoprocessor.cc
diff --git a/webrtc/modules/video_coding/codecs/test/videoprocessor.cc b/webrtc/modules/video_coding/codecs/test/videoprocessor.cc
index 35bf5593664a8b2cc6cbefebad5e3791f75ccb94..9b5d856ba69179cdcdce6722ff968ffe34761041 100644
--- a/webrtc/modules/video_coding/codecs/test/videoprocessor.cc
+++ b/webrtc/modules/video_coding/codecs/test/videoprocessor.cc
@@ -60,8 +60,6 @@ VideoProcessorImpl::VideoProcessorImpl(webrtc::VideoEncoder* encoder,
packet_manipulator_(packet_manipulator),
config_(config),
stats_(stats),
- encode_callback_(nullptr),
- decode_callback_(nullptr),
last_successful_frame_buffer_(nullptr),
first_key_frame_has_been_excluded_(false),
last_frame_missing_(false),
@@ -104,44 +102,29 @@ bool VideoProcessorImpl::Init() {
last_encoder_frame_height_ = config_.codec_settings->height;
// Setup required callbacks for the encoder/decoder:
- encode_callback_ = new VideoProcessorEncodeCompleteCallback(this);
- decode_callback_ = new VideoProcessorDecodeCompleteCallback(this);
- int32_t register_result =
- encoder_->RegisterEncodeCompleteCallback(encode_callback_);
- if (register_result != WEBRTC_VIDEO_CODEC_OK) {
- fprintf(stderr,
- "Failed to register encode complete callback, return code: "
- "%d\n",
- register_result);
- return false;
- }
- register_result = decoder_->RegisterDecodeCompleteCallback(decode_callback_);
- if (register_result != WEBRTC_VIDEO_CODEC_OK) {
- fprintf(stderr,
- "Failed to register decode complete callback, return code: "
- "%d\n",
- register_result);
- return false;
- }
+ encode_callback_.reset(new VideoProcessorEncodeCompleteCallback(this));
+ decode_callback_.reset(new VideoProcessorDecodeCompleteCallback(this));
+ RTC_CHECK_EQ(encoder_->RegisterEncodeCompleteCallback(encode_callback_.get()),
+ WEBRTC_VIDEO_CODEC_OK)
+ << "Failed to register encode complete callback";
+ RTC_CHECK_EQ(decoder_->RegisterDecodeCompleteCallback(decode_callback_.get()),
+ WEBRTC_VIDEO_CODEC_OK)
+ << "Failed to register decode complete callback";
+
// Init the encoder and decoder
uint32_t nbr_of_cores = 1;
if (!config_.use_single_core) {
nbr_of_cores = CpuInfo::DetectNumberOfCores();
}
- int32_t init_result =
+ RTC_CHECK_EQ(
encoder_->InitEncode(config_.codec_settings, nbr_of_cores,
- config_.networking_config.max_payload_size_in_bytes);
- if (init_result != WEBRTC_VIDEO_CODEC_OK) {
- fprintf(stderr, "Failed to initialize VideoEncoder, return code: %d\n",
- init_result);
- return false;
- }
- init_result = decoder_->InitDecode(config_.codec_settings, nbr_of_cores);
- if (init_result != WEBRTC_VIDEO_CODEC_OK) {
- fprintf(stderr, "Failed to initialize VideoDecoder, return code: %d\n",
- init_result);
- return false;
- }
+ config_.networking_config.max_payload_size_in_bytes),
+ WEBRTC_VIDEO_CODEC_OK)
+ << "Failed to initialize VideoEncoder";
+
+ RTC_CHECK_EQ(decoder_->InitDecode(config_.codec_settings, nbr_of_cores),
+ WEBRTC_VIDEO_CODEC_OK)
+ << "Failed to initialize VideoDecoder";
if (config_.verbose) {
printf("Video Processor:\n");
@@ -179,23 +162,16 @@ bool VideoProcessorImpl::Init() {
VideoProcessorImpl::~VideoProcessorImpl() {
delete[] last_successful_frame_buffer_;
- encoder_->RegisterEncodeCompleteCallback(NULL);
- delete encode_callback_;
- decoder_->RegisterDecodeCompleteCallback(NULL);
- delete decode_callback_;
+ encoder_->RegisterEncodeCompleteCallback(nullptr);
+ decoder_->RegisterDecodeCompleteCallback(nullptr);
}
void VideoProcessorImpl::SetRates(int bit_rate, int frame_rate) {
int set_rates_result = encoder_->SetRateAllocation(
bitrate_allocator_->GetAllocation(bit_rate * 1000, frame_rate),
frame_rate);
- RTC_CHECK_GE(set_rates_result, 0);
- if (set_rates_result < 0) {
- fprintf(stderr,
- "Failed to update encoder with new rate %d, "
- "return code: %d\n",
- bit_rate, set_rates_result);
- }
+ RTC_CHECK_GE(set_rates_result, 0) << "Failed to update encoder with new rate "
+ << bit_rate;
num_dropped_frames_ = 0;
num_spatial_resizes_ = 0;
}
@@ -218,10 +194,8 @@ int VideoProcessorImpl::NumberSpatialResizes() {
bool VideoProcessorImpl::ProcessFrame(int frame_number) {
RTC_DCHECK_GE(frame_number, 0);
- if (!initialized_) {
- fprintf(stderr, "Attempting to use uninitialized VideoProcessor!\n");
- return false;
- }
+ RTC_CHECK(initialized_) << "Attempting to use uninitialized VideoProcessor";
+
// |prev_time_stamp_| is used for getting number of dropped frames.
if (frame_number == 0) {
prev_time_stamp_ = -1;
@@ -247,7 +221,8 @@ bool VideoProcessorImpl::ProcessFrame(int frame_number) {
encoded_frame_size_ = 0;
encoded_frame_type_ = kVideoFrameDelta;
- int32_t encode_result = encoder_->Encode(source_frame, NULL, &frame_types);
+ int32_t encode_result =
+ encoder_->Encode(source_frame, nullptr, &frame_types);
if (encode_result != WEBRTC_VIDEO_CODEC_OK) {
fprintf(stderr, "Failed to encode frame %d, return code: %d\n",
@@ -337,7 +312,7 @@ void VideoProcessorImpl::FrameEncoded(
// TODO(kjellander): Pass fragmentation header to the decoder when
// CL 172001 has been submitted and PacketManipulator supports this.
int32_t decode_result =
- decoder_->Decode(copied_image, last_frame_missing_, NULL);
+ decoder_->Decode(copied_image, last_frame_missing_, nullptr);
stat.decode_return_code = decode_result;
if (decode_result != WEBRTC_VIDEO_CODEC_OK) {
// Write the last successful frame the output file to avoid getting it out

Powered by Google App Engine
This is Rietveld 408576698