X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;ds=sidebyside;f=nageru%2Fpbo_frame_allocator.cpp;h=133b65fe3310c2b0c69b27330098286e9f6cb994;hb=e01e8253288b3b706b22ea0c788c2c8f50bfac2e;hp=54182a83a899fa3ca9994974a76316c90e812d4d;hpb=575f6eb1b052bb1291987753b1a8cccc7f1e3ab3;p=nageru diff --git a/nageru/pbo_frame_allocator.cpp b/nageru/pbo_frame_allocator.cpp index 54182a8..133b65f 100644 --- a/nageru/pbo_frame_allocator.cpp +++ b/nageru/pbo_frame_allocator.cpp @@ -166,11 +166,7 @@ void PBOFrameAllocator::init_frame(size_t frame_idx, size_t frame_size, GLuint w check_error(); set_clamp_to_edge(); if (field == 0) { - if (global_flags.can_disable_srgb_decoder) { // See the comments in tweaked_inputs.h. - glTexImage2D(GL_TEXTURE_2D, 0, GL_SRGB8_ALPHA8, width, height, 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, nullptr); - } else { - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, width, height, 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, nullptr); - } + glTexImage2D(GL_TEXTURE_2D, 0, GL_SRGB8_ALPHA8, width, height, 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, nullptr); check_error(); } break; @@ -276,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->should_encode_mjpeg_for_card(card_index) && + vf.userdata != nullptr) { Userdata *ud = (Userdata *)vf.userdata; vf.data_copy = ud->data_copy_malloc; ud->data_copy_current_src = Userdata::FROM_MALLOC; @@ -309,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() && - 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 != nullptr && + mjpeg_encoder->should_encode_mjpeg_for_card(card_index)) { + 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; } @@ -370,6 +372,21 @@ void PBOFrameAllocator::release_frame(Frame frame) } #endif + { + // In case we never got to upload the frame to MJPEGEncoder. + Userdata *userdata = (Userdata *)frame.userdata; + MJPEGEncoder::VAResources resources __attribute__((unused)) = move(userdata->va_resources); + MJPEGEncoder::ReleaseVAResources release = move(userdata->va_resources_release); + + if (frame.data_copy != nullptr && userdata->data_copy_current_src == Userdata::FROM_VA_API) { + VADisplay va_dpy = mjpeg_encoder->va_dpy->va_dpy; + VAStatus va_status = vaUnmapBuffer(va_dpy, resources.image.buf); + CHECK_VASTATUS(va_status, "vaUnmapBuffer"); + + frame.data_copy = nullptr; + } + } + lock_guard lock(freelist_mutex); freelist.push(frame); //--sumsum;