Skip to content

Commit 9b1d47e

Browse files
committed
mp_image: map hwdec format parameters correctly
1 parent 28ef6b7 commit 9b1d47e

File tree

2 files changed

+18
-11
lines changed

2 files changed

+18
-11
lines changed

video/mp_image.c

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -187,12 +187,13 @@ static bool mp_image_alloc_planes(struct mp_image *mpi)
187187
return true;
188188
}
189189

190-
void mp_image_setfmt(struct mp_image *mpi, int out_fmt)
190+
void mp_image_sethwfmt(struct mp_image *mpi, enum mp_imgfmt hw_fmt, enum mp_imgfmt sw_fmt)
191191
{
192-
struct mp_imgfmt_desc fmt = mp_imgfmt_get_desc(out_fmt);
193-
mpi->params.imgfmt = fmt.id;
192+
struct mp_imgfmt_desc fmt = mp_imgfmt_get_desc(sw_fmt ? sw_fmt : hw_fmt);
193+
mpi->params.imgfmt = hw_fmt;
194+
mpi->params.hw_subfmt = sw_fmt;
194195
mpi->fmt = fmt;
195-
mpi->imgfmt = fmt.id;
196+
mpi->imgfmt = hw_fmt;
196197
mpi->num_planes = fmt.num_planes;
197198
mpi->params.repr.alpha = (fmt.flags & MP_IMGFLAG_ALPHA) ? PL_ALPHA_INDEPENDENT
198199
#if PL_API_VER >= 344
@@ -207,6 +208,11 @@ void mp_image_setfmt(struct mp_image *mpi, int out_fmt)
207208
};
208209
}
209210

211+
void mp_image_setfmt(struct mp_image *mpi, enum mp_imgfmt fmt)
212+
{
213+
mp_image_sethwfmt(mpi, fmt, IMGFMT_NONE);
214+
}
215+
210216
static void mp_image_destructor(void *ptr)
211217
{
212218
mp_image_t *mpi = ptr;
@@ -1065,7 +1071,12 @@ struct mp_image *mp_image_from_av_frame(struct AVFrame *src)
10651071

10661072
dst->hwctx = src->hw_frames_ctx;
10671073

1068-
mp_image_setfmt(dst, pixfmt2imgfmt(src->format));
1074+
if (dst->hwctx) {
1075+
AVHWFramesContext *fctx = (void *)dst->hwctx->data;
1076+
dst->params.hw_subfmt = pixfmt2imgfmt(fctx->sw_format);
1077+
}
1078+
1079+
mp_image_sethwfmt(dst, pixfmt2imgfmt(src->format), dst->params.hw_subfmt);
10691080
mp_image_set_size(dst, src->width, src->height);
10701081

10711082
dst->params.p_w = src->sample_aspect_ratio.num;
@@ -1193,11 +1204,6 @@ struct mp_image *mp_image_from_av_frame(struct AVFrame *src)
11931204
MP_TARRAY_APPEND(NULL, dst->ff_side_data, dst->num_ff_side_data, mpsd);
11941205
}
11951206

1196-
if (dst->hwctx) {
1197-
AVHWFramesContext *fctx = (void *)dst->hwctx->data;
1198-
dst->params.hw_subfmt = pixfmt2imgfmt(fctx->sw_format);
1199-
}
1200-
12011207
struct mp_image *res = mp_image_new_ref(dst);
12021208

12031209
// Allocated, but non-refcounted data.

video/mp_image.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,8 @@ void mp_image_set_size(struct mp_image *mpi, int w, int h);
162162
int mp_image_plane_w(struct mp_image *mpi, int plane);
163163
int mp_image_plane_h(struct mp_image *mpi, int plane);
164164

165-
void mp_image_setfmt(mp_image_t* mpi, int out_fmt);
165+
void mp_image_sethwfmt(mp_image_t *mpi, enum mp_imgfmt hw_fmt, enum mp_imgfmt sw_fmt);
166+
void mp_image_setfmt(mp_image_t* mpi, enum mp_imgfmt out_fmt);
166167
void mp_image_steal_data(struct mp_image *dst, struct mp_image *src);
167168
void mp_image_unref_data(struct mp_image *img);
168169

0 commit comments

Comments
 (0)