examples: handle I420 and IYUV formats

They are represented in PipeWire with 3 planes now.
This commit is contained in:
Wim Taymans 2025-04-16 11:00:28 +02:00
parent 7d6e2a6417
commit 41665e6bb8
2 changed files with 19 additions and 11 deletions

View file

@ -151,7 +151,7 @@ static inline struct spa_pod *sdl_build_formats(SDL_RendererInfo *info, struct s
if (id == 0) if (id == 0)
continue; continue;
if (c++ == 0) if (c++ == 0)
spa_pod_builder_id(b, id); spa_pod_builder_id(b, SPA_VIDEO_FORMAT_UNKNOWN);
spa_pod_builder_id(b, id); spa_pod_builder_id(b, id);
} }
/* then all the other ones SDL can convert from/to */ /* then all the other ones SDL can convert from/to */

View file

@ -177,15 +177,21 @@ on_process(void *_data)
/* copy video image in texture */ /* copy video image in texture */
if (data->is_yuv) { if (data->is_yuv) {
void *datas[4];
sstride = data->stride; sstride = data->stride;
SDL_UpdateYUVTexture(data->texture, if (buf->n_datas == 1) {
NULL, datas[0] = sdata;
sdata, datas[1] = SPA_PTROFF(sdata, sstride * data->size.height, void);
sstride, datas[2] = SPA_PTROFF(sdata, 5 * (sstride * data->size.height) / 4, void);
SPA_PTROFF(sdata, sstride * data->size.height, void), } else {
sstride / 2, datas[0] = sdata;
SPA_PTROFF(sdata, 5 * (sstride * data->size.height) / 4, void), datas[1] = buf->datas[1].data;
sstride / 2); datas[2] = buf->datas[2].data;
}
SDL_UpdateYUVTexture(data->texture, NULL,
datas[0], sstride,
datas[1], sstride / 2,
datas[2], sstride / 2);
} }
else { else {
if (SDL_LockTexture(data->texture, NULL, &ddata, &dstride) < 0) { if (SDL_LockTexture(data->texture, NULL, &ddata, &dstride) < 0) {
@ -286,7 +292,7 @@ on_stream_param_changed(void *_data, uint32_t id, const struct spa_pod *param)
const struct spa_pod *params[5]; const struct spa_pod *params[5];
Uint32 sdl_format; Uint32 sdl_format;
void *d; void *d;
int32_t mult, size; int32_t mult, size, blocks;
if (param != NULL && id == SPA_PARAM_Tag) { if (param != NULL && id == SPA_PARAM_Tag) {
spa_debug_pod(0, NULL, param); spa_debug_pod(0, NULL, param);
@ -360,9 +366,11 @@ on_stream_param_changed(void *_data, uint32_t id, const struct spa_pod *param)
case SDL_PIXELFORMAT_IYUV: case SDL_PIXELFORMAT_IYUV:
size = (data->stride * data->size.height) * 3 / 2; size = (data->stride * data->size.height) * 3 / 2;
data->is_yuv = true; data->is_yuv = true;
blocks = 3;
break; break;
default: default:
size = data->stride * data->size.height; size = data->stride * data->size.height;
blocks = 1;
break; break;
} }
@ -376,7 +384,7 @@ on_stream_param_changed(void *_data, uint32_t id, const struct spa_pod *param)
params[0] = spa_pod_builder_add_object(&b, params[0] = spa_pod_builder_add_object(&b,
SPA_TYPE_OBJECT_ParamBuffers, SPA_PARAM_Buffers, SPA_TYPE_OBJECT_ParamBuffers, SPA_PARAM_Buffers,
SPA_PARAM_BUFFERS_buffers, SPA_POD_CHOICE_RANGE_Int(8, 2, MAX_BUFFERS), SPA_PARAM_BUFFERS_buffers, SPA_POD_CHOICE_RANGE_Int(8, 2, MAX_BUFFERS),
SPA_PARAM_BUFFERS_blocks, SPA_POD_Int(1), SPA_PARAM_BUFFERS_blocks, SPA_POD_Int(blocks),
SPA_PARAM_BUFFERS_size, SPA_POD_Int(size * mult), SPA_PARAM_BUFFERS_size, SPA_POD_Int(size * mult),
SPA_PARAM_BUFFERS_stride, SPA_POD_Int(data->stride * mult), SPA_PARAM_BUFFERS_stride, SPA_POD_Int(data->stride * mult),
SPA_PARAM_BUFFERS_dataType, SPA_POD_CHOICE_FLAGS_Int((1<<SPA_DATA_MemPtr))); SPA_PARAM_BUFFERS_dataType, SPA_POD_CHOICE_FLAGS_Int((1<<SPA_DATA_MemPtr)));