]> git.sesse.net Git - nageru/commitdiff
Various fixes for non-VA-API MJPEG encoding.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Sun, 9 Feb 2020 18:10:31 +0000 (19:10 +0100)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Sun, 9 Feb 2020 18:10:31 +0000 (19:10 +0100)
nageru/mjpeg_encoder.cpp
nageru/pbo_frame_allocator.cpp

index 033f67afd9e439db3a5289248bed5b67e8f306ba..e39e802c843cbef0bcd6f130db17702d722c2ce3 100644 (file)
@@ -832,7 +832,7 @@ vector<uint8_t> MJPEGEncoder::encode_jpeg_libjpeg(const QueuedFrame &qf)
        for (unsigned y = 0; y < qf.video_format.height; y += 8) {
                const uint8_t *src = qf.frame->data_copy + field_start + y * qf.video_format.width * 2;
 
-               memcpy_interleaved(tmp_y, tmp_cbcr, src, qf.video_format.width * 8 * 2);
+               memcpy_interleaved(tmp_cbcr, tmp_y, src, qf.video_format.width * 8 * 2);
                memcpy_interleaved(tmp_cb, tmp_cr, tmp_cbcr, qf.video_format.width * 8);
                for (unsigned yy = 0; yy < 8; ++yy) {
                        yptr[yy] = tmp_y + yy * width;
index 4640d355e25e96a60db88fddc3963419577cd636..c4c08a826624316fcca470a9eb4ff225b8aed619 100644 (file)
@@ -272,8 +272,9 @@ bmusb::FrameAllocator::Frame PBOFrameAllocator::alloc_frame()
        vf.len = 0;
        vf.overflow = 0;
 
-       if (mjpeg_encoder != nullptr && mjpeg_encoder->using_vaapi() &&
-           mjpeg_encoder->get_mjpeg_stream_for_card(card_index) != -1) {
+       if (mjpeg_encoder != nullptr &&
+           mjpeg_encoder->get_mjpeg_stream_for_card(card_index) != -1 &&
+           vf.userdata != nullptr) {
                Userdata *ud = (Userdata *)vf.userdata;
                vf.data_copy = ud->data_copy_malloc;
                ud->data_copy_current_src = Userdata::FROM_MALLOC;
@@ -305,22 +306,27 @@ bmusb::FrameAllocator::Frame PBOFrameAllocator::create_frame(size_t width, size_
 
        Userdata *userdata = (Userdata *)vf.userdata;
 
-       if (mjpeg_encoder != nullptr && mjpeg_encoder->using_vaapi() &&
+       if (mjpeg_encoder != nullptr &&
            mjpeg_encoder->get_mjpeg_stream_for_card(card_index) != -1) {
-               VADisplay va_dpy = mjpeg_encoder->va_dpy->va_dpy;
-               MJPEGEncoder::VAResources resources = mjpeg_encoder->get_va_resources(width, height);
-               MJPEGEncoder::ReleaseVAResources release(mjpeg_encoder, resources);
-
-               if (resources.image.pitches[0] == stride) {
-                       userdata->va_resources = move(resources);
-                       userdata->va_resources_release = move(release);
-
-                       VAStatus va_status = vaMapBuffer(va_dpy, resources.image.buf, (void **)&vf.data_copy);
-                       CHECK_VASTATUS(va_status, "vaMapBuffer");
-                       vf.data_copy += resources.image.offsets[0];
-                       userdata->data_copy_current_src = Userdata::FROM_VA_API;
+               if (mjpeg_encoder->using_vaapi()) {
+                       VADisplay va_dpy = mjpeg_encoder->va_dpy->va_dpy;
+                       MJPEGEncoder::VAResources resources = mjpeg_encoder->get_va_resources(width, height);
+                       MJPEGEncoder::ReleaseVAResources release(mjpeg_encoder, resources);
+
+                       if (resources.image.pitches[0] == stride) {
+                               userdata->va_resources = move(resources);
+                               userdata->va_resources_release = move(release);
+
+                               VAStatus va_status = vaMapBuffer(va_dpy, resources.image.buf, (void **)&vf.data_copy);
+                               CHECK_VASTATUS(va_status, "vaMapBuffer");
+                               vf.data_copy += resources.image.offsets[0];
+                               userdata->data_copy_current_src = Userdata::FROM_VA_API;
+                       } else {
+                               printf("WARNING: Could not copy directly into VA-API MJPEG buffer for %zu x %zu, since producer and consumer disagreed on stride (%zu != %d).\n", width, height, stride, resources.image.pitches[0]);
+                               vf.data_copy = userdata->data_copy_malloc;
+                               userdata->data_copy_current_src = Userdata::FROM_MALLOC;
+                       }
                } else {
-                       printf("WARNING: Could not copy directly into VA-API MJPEG buffer for %zu x %zu, since producer and consumer disagreed on stride (%zu != %d).\n", width, height, stride, resources.image.pitches[0]);
                        vf.data_copy = userdata->data_copy_malloc;
                        userdata->data_copy_current_src = Userdata::FROM_MALLOC;
                }