ref: a1c0c95c8c6dbab14c1223cdfdd0dc62022c6444
parent: c2aa1520a4610fb5cc640f55c117805fb0047502
author: angiebird <angiebird@google.com>
date: Wed Feb 26 10:18:52 EST 2020
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
--- a/vp9/simple_encode.cc
+++ b/vp9/simple_encode.cc
@@ -789,6 +789,14 @@
external_arf_indexes_ = external_arf_indexes;
}
+template <typename T>
+T *GetVectorData(const std::vector<T> &v) {
+ if (v.empty()) {
+ return nullptr;
+ }
+ return const_cast<T *>(v.data());
+}
+
void SimpleEncode::StartEncode() {
assert(impl_ptr_->first_pass_stats.size() > 0);
vpx_rational_t frame_rate =
@@ -797,7 +805,7 @@
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 @@
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 @@
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,