From: Steinar H. Gunderson Date: Wed, 6 Mar 2019 19:07:39 +0000 (+0100) Subject: Fix some unneeded copying of encoded JPEGs around (would take ~15% of uninterpolated... X-Git-Tag: 1.8.3~17 X-Git-Url: https://git.sesse.net/?p=nageru;a=commitdiff_plain;h=b57d57b88a1d7388c6eacf8cc0867f680123120a Fix some unneeded copying of encoded JPEGs around (would take ~15% of uninterpolated export). --- diff --git a/futatabi/video_stream.cpp b/futatabi/video_stream.cpp index a820411..da57ebb 100644 --- a/futatabi/video_stream.cpp +++ b/futatabi/video_stream.cpp @@ -28,7 +28,7 @@ extern HTTPD *global_httpd; struct VectorDestinationManager { jpeg_destination_mgr pub; - std::vector dest; + string dest; VectorDestinationManager() { @@ -62,7 +62,7 @@ struct VectorDestinationManager { { dest.resize(bytes_used + 4096); dest.resize(dest.capacity()); - pub.next_output_byte = dest.data() + bytes_used; + pub.next_output_byte = (uint8_t *)dest.data() + bytes_used; pub.free_in_buffer = dest.size() - bytes_used; } @@ -78,7 +78,7 @@ struct VectorDestinationManager { }; static_assert(std::is_standard_layout::value, ""); -vector encode_jpeg(const uint8_t *y_data, const uint8_t *cb_data, const uint8_t *cr_data, unsigned width, unsigned height) +string encode_jpeg(const uint8_t *y_data, const uint8_t *cb_data, const uint8_t *cr_data, unsigned width, unsigned height) { VectorDestinationManager dest; @@ -659,15 +659,14 @@ void VideoStream::encode_thread_func() pkt.size = jpeg.size(); pkt.flags = AV_PKT_FLAG_KEY; mux->add_packet(pkt, qf.output_pts, qf.output_pts); - - last_frame.assign(&jpeg[0], &jpeg[0] + jpeg.size()); + last_frame = move(jpeg); } else if (qf.type == QueuedFrame::FADED) { glClientWaitSync(qf.fence.get(), /*flags=*/0, GL_TIMEOUT_IGNORED); shared_ptr frame = frame_from_pbo(qf.resources->pbo_contents, global_flags.width, global_flags.height); // Now JPEG encode it, and send it on to the stream. - vector jpeg = encode_jpeg(frame->y.get(), frame->cb.get(), frame->cr.get(), global_flags.width, global_flags.height); + string jpeg = encode_jpeg(frame->y.get(), frame->cb.get(), frame->cr.get(), global_flags.width, global_flags.height); AVPacket pkt; av_init_packet(&pkt); @@ -687,7 +686,7 @@ void VideoStream::encode_thread_func() } // Now JPEG encode it, and send it on to the stream. - vector jpeg = encode_jpeg(frame->y.get(), frame->cb.get(), frame->cr.get(), global_flags.width, global_flags.height); + string jpeg = encode_jpeg(frame->y.get(), frame->cb.get(), frame->cr.get(), global_flags.width, global_flags.height); if (qf.flow_tex != 0) { compute_flow->release_texture(qf.flow_tex); } diff --git a/futatabi/video_stream.h b/futatabi/video_stream.h index 1b33587..26cb7c8 100644 --- a/futatabi/video_stream.h +++ b/futatabi/video_stream.h @@ -114,8 +114,6 @@ private: // For original frames only. Made move-only so we know explicitly // we don't copy these ~200 kB files around inadvertedly. - // - // TODO: Consider using vector instead, so we save one copy. std::unique_ptr encoded_jpeg; // For everything except original frames. @@ -160,7 +158,7 @@ private: GLuint last_flow_tex = 0; FrameOnDisk last_frame1, last_frame2; - std::vector last_frame; + std::string last_frame; }; #endif // !defined(_VIDEO_STREAM_H)