From a1c0c95c8c6dbab14c1223cdfdd0dc62022c6444 Mon Sep 17 00:00:00 2001 From: angiebird Date: Wed, 26 Feb 2020 15:18:52 -0800 Subject: [PATCH] Add GetVectorData() It's necessary to get data pointer from a vector sometimes. This function will guarantee that the data pointer is nullptr if the vector is empty. Change-Id: I156308bcb193fe404452d3cd3b24b3f80c3c3727 --- vp9/simple_encode.cc | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/vp9/simple_encode.cc b/vp9/simple_encode.cc index 25d0251..d5e6fb5 100644 --- a/vp9/simple_encode.cc +++ b/vp9/simple_encode.cc @@ -789,6 +789,14 @@ void SimpleEncode::SetExternalGroupOfPicture( external_arf_indexes_ = external_arf_indexes; } +template +T *GetVectorData(const std::vector &v) { + if (v.empty()) { + return nullptr; + } + return const_cast(v.data()); +} + void SimpleEncode::StartEncode() { assert(impl_ptr_->first_pass_stats.size() > 0); vpx_rational_t frame_rate = @@ -797,7 +805,7 @@ void SimpleEncode::StartEncode() { vp9_get_encoder_config(frame_width_, frame_height_, frame_rate, target_bitrate_, VPX_RC_LAST_PASS); vpx_fixed_buf_t stats; - stats.buf = impl_ptr_->first_pass_stats.data(); + stats.buf = GetVectorData(impl_ptr_->first_pass_stats); stats.sz = sizeof(impl_ptr_->first_pass_stats[0]) * impl_ptr_->first_pass_stats.size(); @@ -808,7 +816,7 @@ void SimpleEncode::StartEncode() { frame_height_, 1); frame_coding_index_ = 0; encode_command_set_external_arf_indexes(&impl_ptr_->cpi->encode_command, - external_arf_indexes_.data()); + GetVectorData(external_arf_indexes_)); UpdateGroupOfPicture(impl_ptr_->cpi, frame_coding_index_, ref_frame_info_, &group_of_picture_); rewind(in_file_); @@ -952,7 +960,8 @@ int SimpleEncode::GetCodingFrameNum() const { target_bitrate_, VPX_RC_LAST_PASS); FRAME_INFO frame_info = vp9_get_frame_info(&oxcf); FIRST_PASS_INFO first_pass_info; - fps_init_first_pass_info(&first_pass_info, impl_ptr_->first_pass_stats.data(), + fps_init_first_pass_info(&first_pass_info, + GetVectorData(impl_ptr_->first_pass_stats), num_frames_); return vp9_get_coding_frame_num(external_arf_indexes_.data(), &oxcf, &frame_info, &first_pass_info, -- 2.7.4