X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=h264encode.cpp;h=a478c2a1a2459a2fa24d3ed06c34a598ea1bf8d1;hb=c957e3daa14e615a3aa5d6bd4d15ddf409812fd3;hp=96e0165746ef71928ca1ca3b72dfd3bccf877fb4;hpb=ded4cffec7a53c01389a306ebc5caf1a4e965c05;p=nageru diff --git a/h264encode.cpp b/h264encode.cpp index 96e0165..a478c2a 100644 --- a/h264encode.cpp +++ b/h264encode.cpp @@ -205,7 +205,6 @@ private: EGLImage y_egl_image, cbcr_egl_image; // Only if use_zerocopy == false. - RefCountedGLsync readback_done_fence; GLuint pbo; uint8_t *y_ptr, *cbcr_ptr; size_t y_offset, cbcr_offset; @@ -925,7 +924,7 @@ int H264EncoderImpl::init_va(const string &va_display) if (support_encode == 0) { printf("Can't find VAEntrypointEncSlice for H264 profiles. If you are using a non-Intel GPU\n"); - printf("but have one in your system, try launching Nageru with --va-display /dev/dri/card0\n"); + printf("but have one in your system, try launching Nageru with --va-display /dev/dri/renderD128\n"); printf("to use VA-API against DRM instead of X11.\n"); exit(1); } else { @@ -1112,10 +1111,10 @@ int H264EncoderImpl::setup_encode() glBindBuffer(GL_PIXEL_PACK_BUFFER, gl_surfaces[i].pbo); glBufferStorage(GL_PIXEL_PACK_BUFFER, frame_width * frame_height * 2, nullptr, GL_MAP_READ_BIT | GL_MAP_WRITE_BIT | GL_MAP_PERSISTENT_BIT); uint8_t *ptr = (uint8_t *)glMapBufferRange(GL_PIXEL_PACK_BUFFER, 0, frame_width * frame_height * 2, GL_MAP_READ_BIT | GL_MAP_PERSISTENT_BIT); - gl_surfaces[i].y_ptr = ptr; - gl_surfaces[i].cbcr_ptr = ptr + frame_width * frame_height; gl_surfaces[i].y_offset = 0; gl_surfaces[i].cbcr_offset = frame_width * frame_height; + gl_surfaces[i].y_ptr = ptr + gl_surfaces[i].y_offset; + gl_surfaces[i].cbcr_ptr = ptr + gl_surfaces[i].cbcr_offset; glBindBuffer(GL_PIXEL_PACK_BUFFER, 0); } } @@ -1950,7 +1949,12 @@ void H264EncoderImpl::encode_frame(H264EncoderImpl::PendingFrame frame, int enco int frame_type, int64_t pts, int64_t dts) { // Wait for the GPU to be done with the frame. - glClientWaitSync(frame.fence.get(), 0, 0); + GLenum sync_status; + do { + sync_status = glClientWaitSync(frame.fence.get(), 0, 1000000000); + check_error(); + } while (sync_status == GL_TIMEOUT_EXPIRED); + assert(sync_status != GL_WAIT_FAILED); // Release back any input frames we needed to render this frame. frame.input_frames.clear(); @@ -1967,11 +1971,11 @@ void H264EncoderImpl::encode_frame(H264EncoderImpl::PendingFrame frame, int enco unsigned char *surface_p = nullptr; vaMapBuffer(va_dpy, surf->surface_image.buf, (void **)&surface_p); - unsigned char *y_ptr = (unsigned char *)surface_p + surf->surface_image.offsets[0]; - memcpy_with_pitch(y_ptr, surf->y_ptr, frame_width, surf->surface_image.pitches[0], frame_height); + unsigned char *va_y_ptr = (unsigned char *)surface_p + surf->surface_image.offsets[0]; + memcpy_with_pitch(va_y_ptr, surf->y_ptr, frame_width, surf->surface_image.pitches[0], frame_height); - unsigned char *cbcr_ptr = (unsigned char *)surface_p + surf->surface_image.offsets[1]; - memcpy_with_pitch(cbcr_ptr, surf->cbcr_ptr, (frame_width / 2) * sizeof(uint16_t), surf->surface_image.pitches[1], frame_height / 2); + unsigned char *va_cbcr_ptr = (unsigned char *)surface_p + surf->surface_image.offsets[1]; + memcpy_with_pitch(va_cbcr_ptr, surf->cbcr_ptr, (frame_width / 2) * sizeof(uint16_t), surf->surface_image.pitches[1], frame_height / 2); va_status = vaUnmapBuffer(va_dpy, surf->surface_image.buf); CHECK_VASTATUS(va_status, "vaUnmapBuffer");