From: angiebird Date: Mon, 11 Nov 2019 18:20:15 +0000 (-0800) Subject: Add EncodeFrameResults X-Git-Tag: v1.8.2~38 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=f975d02d6dc095c97c6950a2b8c3768f29644fe5;p=libvpx Add EncodeFrameResults It contains coding_data_size and coding_data. The EncodeFrame will allocate a buffer, write the coding data into the buffer and give the ownership of the buffer to encode_frame_result->coding_data Change-Id: I6bd86aede191ade1db4a1f1bba5be601eef97d60 --- diff --git a/test/simple_encode_test.cc b/test/simple_encode_test.cc index b917e028e..f9643f612 100644 --- a/test/simple_encode_test.cc +++ b/test/simple_encode_test.cc @@ -60,14 +60,12 @@ TEST(SimpleEncode, EncodeFrame) { FILE *file = fopen("bus_352x288_420_f20_b8.yuv", "r"); SimpleEncode simple_encode(w, h, frame_rate_num, frame_rate_den, target_bitrate, num_frames, file); - char cx_data[352 * 288 * 3]; - size_t max_size = 352 * 288 * 3; - size_t frame_size; simple_encode.ComputeFirstPassStats(); int num_coding_frames = simple_encode.GetCodingFrameNum(); simple_encode.StartEncode(); for (int i = 0; i < num_coding_frames; ++i) { - simple_encode.EncodeFrame(cx_data, &frame_size, max_size); + EncodeFrameResult encode_frame_result; + simple_encode.EncodeFrame(&encode_frame_result); // TODO(angiebird): For now, this test just check whether EncodeFrame can be // run proprly. Add extra check later. } diff --git a/vp9/simple_encode.cc b/vp9/simple_encode.cc index fd8867e11..020ea9fe8 100644 --- a/vp9/simple_encode.cc +++ b/vp9/simple_encode.cc @@ -182,7 +182,7 @@ void SimpleEncode::EndEncode() { rewind(file); } -void SimpleEncode::EncodeFrame(char *cx_data, size_t *size, size_t max_size) { +void SimpleEncode::EncodeFrame(EncodeFrameResult *encode_frame_result) { VP9_COMP *cpi = pimpl->cpi; struct lookahead_ctx *lookahead = cpi->lookahead; int use_highbitdepth = 0; @@ -210,19 +210,21 @@ void SimpleEncode::EncodeFrame(char *cx_data, size_t *size, size_t max_size) { break; } } + assert(encode_frame_result->coding_data.get() == nullptr); + const size_t max_coding_data_size = frame_width * frame_height * 3; + encode_frame_result->coding_data = + std::move(std::unique_ptr(new uint8_t[max_coding_data_size])); int64_t time_stamp; int64_t time_end; int flush = 1; // Make vp9_get_compressed_data encode a frame unsigned int frame_flags = 0; - vp9_get_compressed_data(cpi, &frame_flags, size, - reinterpret_cast(cx_data), &time_stamp, - &time_end, flush); + vp9_get_compressed_data( + cpi, &frame_flags, &encode_frame_result->coding_data_size, + encode_frame_result->coding_data.get(), &time_stamp, &time_end, flush); // vp9_get_compressed_data is expected to encode a frame every time, so the // data size should be greater than zero. - assert(*size > 0); - if (*size >= max_size) { - assert(0); - } + assert(encode_frame_result->coding_data_size > 0); + assert(encode_frame_result->coding_data_size < max_coding_data_size); } int SimpleEncode::GetCodingFrameNum() { diff --git a/vp9/simple_encode.h b/vp9/simple_encode.h index bc8b70bab..b06339f43 100644 --- a/vp9/simple_encode.h +++ b/vp9/simple_encode.h @@ -1,5 +1,23 @@ #include #include + +enum FrameType { + kKeyFrame = 0, + kInterFrame, + kAlternateReference, +}; + +struct EncodeFrameResult { + // TODO(angiebird): int show_index; + // TODO(angiebird): FrameType frame_type; + size_t coding_data_size; + // The EncodeFrame will allocate a buffer, write the coding data into the + // buffer and give the ownership of the buffer to coding_data + std::unique_ptr coding_data; + // TODO(angiebird): double psnr; + // TODO(angiebird): int quantize_index ; +}; + class SimpleEncode { public: SimpleEncode(int frame_width, int frame_height, int frame_rate_num, @@ -26,7 +44,7 @@ class SimpleEncode { // Encode a frame // This funtion should be called after StartEncode() before EndEncode() - void EncodeFrame(char *cx_data, size_t *size, size_t max_size); + void EncodeFrame(EncodeFrameResult *encode_frame_result); // Get the number of coding frames for the video. The coding frames include // show frame and no show frame.