videoconvert: get the correct strides

Use ffmpeg to get the right stride for the negotiated format instead of
using a wrong hardcoded value.
This commit is contained in:
Wim Taymans 2025-03-20 10:57:26 +01:00
parent 6f8a814f29
commit 4e0545aa04

View file

@ -12,6 +12,7 @@
#include <libavformat/avformat.h> #include <libavformat/avformat.h>
#include <libswscale/swscale.h> #include <libswscale/swscale.h>
#include <libavutil/pixfmt.h> #include <libavutil/pixfmt.h>
#include <libavutil/imgutils.h>
#include <spa/support/plugin.h> #include <spa/support/plugin.h>
#include <spa/support/cpu.h> #include <spa/support/cpu.h>
@ -1516,6 +1517,8 @@ static int port_set_format(void *object,
else { else {
struct dir *dir = &this->dir[direction]; struct dir *dir = &this->dir[direction];
struct dir *odir = &this->dir[SPA_DIRECTION_REVERSE(direction)]; struct dir *odir = &this->dir[SPA_DIRECTION_REVERSE(direction)];
enum AVPixelFormat pix_fmt;
int linesizes[4];
if (info.media_type != SPA_MEDIA_TYPE_video) { if (info.media_type != SPA_MEDIA_TYPE_video) {
spa_log_error(this->log, "unexpected types %d/%d", spa_log_error(this->log, "unexpected types %d/%d",
@ -1526,8 +1529,9 @@ static int port_set_format(void *object,
spa_log_error(this->log, "can't parse format %s", spa_strerror(res)); spa_log_error(this->log, "can't parse format %s", spa_strerror(res));
return res; return res;
} }
port->stride = 2; pix_fmt = format_to_pix_fmt(info.info.raw.format);
port->stride *= info.info.raw.size.width; av_image_fill_linesizes(linesizes, pix_fmt, info.info.raw.size.width);
port->stride = linesizes[0];
port->blocks = 1; port->blocks = 1;
dir->format = info; dir->format = info;
dir->have_format = true; dir->have_format = true;