]> git.sesse.net Git - nageru/commitdiff
Fix an unneeded copy when muxing MJPEGs.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Wed, 13 Mar 2019 20:36:40 +0000 (21:36 +0100)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Wed, 13 Mar 2019 20:38:28 +0000 (21:38 +0100)
Saves ~10% of one core at five 1080p50 sources.

nageru/mjpeg_encoder.cpp
nageru/mjpeg_encoder.h

index 3f98cd0662a5e5be7eaec3240b6f267b3e8635e5..07e302c4e93148c2b9a83edfc1034e5465f1e8bc 100644 (file)
@@ -318,7 +318,7 @@ void MJPEGEncoder::encoder_thread_func()
                } else {
                        // Encode synchronously, in the same thread.
                        vector<uint8_t> jpeg = encode_jpeg_libjpeg(qf);
-                       write_mjpeg_packet(qf.pts, qf.card_index, jpeg);
+                       write_mjpeg_packet(qf.pts, qf.card_index, jpeg.data(), jpeg.size());
                }
        }
 
@@ -328,13 +328,13 @@ void MJPEGEncoder::encoder_thread_func()
        free(tmp_cr);
 }
 
-void MJPEGEncoder::write_mjpeg_packet(int64_t pts, unsigned card_index, const vector<uint8_t> &jpeg)
+void MJPEGEncoder::write_mjpeg_packet(int64_t pts, unsigned card_index, const uint8_t *jpeg, size_t jpeg_size)
 {
        AVPacket pkt;
        memset(&pkt, 0, sizeof(pkt));
        pkt.buf = nullptr;
-       pkt.data = const_cast<uint8_t *>(&jpeg[0]);
-       pkt.size = jpeg.size();
+       pkt.data = const_cast<uint8_t *>(jpeg);
+       pkt.size = jpeg_size;
        pkt.stream_index = card_index;
        pkt.flags = AV_PKT_FLAG_KEY;
        AVRational time_base = avctx->streams[pkt.stream_index]->time_base;
@@ -708,13 +708,11 @@ void MJPEGEncoder::va_receiver_thread_func()
                va_status = vaMapBuffer(va_dpy->va_dpy, qf.resources.data_buffer, (void **)&segment);
                CHECK_VASTATUS(va_status, "vaMapBuffer");
 
-               const char *coded_buf = reinterpret_cast<char *>(segment->buf);
-               vector<uint8_t> jpeg(coded_buf, coded_buf + segment->size);
+               const uint8_t *coded_buf = reinterpret_cast<uint8_t *>(segment->buf);
+               write_mjpeg_packet(qf.pts, qf.card_index, coded_buf, segment->size);
 
                va_status = vaUnmapBuffer(va_dpy->va_dpy, qf.resources.data_buffer);
                CHECK_VASTATUS(va_status, "vaUnmapBuffer");
-
-               write_mjpeg_packet(qf.pts, qf.card_index, jpeg);
        }
 }
 
index 6610e1315a7d26ee41d024d48caca65f60a67377..8b68294a48d9e01dfd0254b213b2770d57e0330d 100644 (file)
@@ -103,7 +103,7 @@ private:
        void va_receiver_thread_func();
        void encode_jpeg_va(QueuedFrame &&qf);
        std::vector<uint8_t> encode_jpeg_libjpeg(const QueuedFrame &qf);
-       void write_mjpeg_packet(int64_t pts, unsigned card_index, const std::vector<uint8_t> &jpeg);
+       void write_mjpeg_packet(int64_t pts, unsigned card_index, const uint8_t *jpeg, size_t jpeg_size);
        void init_jpeg_422(unsigned width, unsigned height, VectorDestinationManager *dest, jpeg_compress_struct *cinfo);
        std::vector<uint8_t> get_jpeg_header(unsigned width, unsigned height, jpeg_compress_struct *cinfo);