Add AVBufferRef setup when Populating AVFrame from Image. This allows hwtranfer to work because it relies on AVBuffer AVFrame. Please note that we don't want AVBuffer to free the buffer so we pass an empty function to it.

pull/3122/head
Isaac Connor 2021-01-11 13:35:23 -05:00
parent f625734c82
commit 70090f7edc
1 changed files with 8 additions and 1 deletions

View File

@ -226,19 +226,23 @@ Image::Image(const AVFrame *frame) {
this->Assign(frame); this->Assign(frame);
} }
static void dont_free(void *opaque, uint8_t *data) {
}
int Image::PopulateFrame(AVFrame *frame) { int Image::PopulateFrame(AVFrame *frame) {
Debug(1, "PopulateFrame: width %d height %d linesize %d colours %d imagesize %d %s", Debug(1, "PopulateFrame: width %d height %d linesize %d colours %d imagesize %d %s",
width, height, linesize, colours, size, width, height, linesize, colours, size,
av_get_pix_fmt_name(imagePixFormat) av_get_pix_fmt_name(imagePixFormat)
); );
AVBufferRef *ref = av_buffer_create(buffer, size, AVBufferRef *ref = av_buffer_create(buffer, size,
nullptr, /* Free callback */ dont_free, /* Free callback */
nullptr, /* opaque */ nullptr, /* opaque */
0 /* flags */ 0 /* flags */
); );
if ( !ref ) { if ( !ref ) {
Warning("Failed to create av_buffer "); Warning("Failed to create av_buffer ");
} }
frame->buf[0] = ref;
#if LIBAVUTIL_VERSION_CHECK(54, 6, 0, 6, 0) #if LIBAVUTIL_VERSION_CHECK(54, 6, 0, 6, 0)
// From what I've read, we should align the linesizes to 32bit so that ffmpeg can use SIMD instructions too. // From what I've read, we should align the linesizes to 32bit so that ffmpeg can use SIMD instructions too.
int size = av_image_fill_arrays( int size = av_image_fill_arrays(
@ -255,6 +259,9 @@ int Image::PopulateFrame(AVFrame *frame) {
avpicture_fill((AVPicture *)frame, buffer, avpicture_fill((AVPicture *)frame, buffer,
imagePixFormat, width, height); imagePixFormat, width, height);
#endif #endif
frame->width = width;
frame->height = height;
frame->format = imagePixFormat;
Debug(1, "PopulateFrame: width %d height %d linesize %d colours %d imagesize %d", width, height, linesize, colours, size); Debug(1, "PopulateFrame: width %d height %d linesize %d colours %d imagesize %d", width, height, linesize, colours, size);
zm_dump_video_frame(frame, "Image.Populate(frame)"); zm_dump_video_frame(frame, "Image.Populate(frame)");
return 1; return 1;