summaryrefslogtreecommitdiffstats
path: root/video
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2019-11-08 17:20:57 +0100
committerwm4 <wm4@nowhere>2019-11-08 21:22:49 +0100
commit1edb3d061bd88e86cba05e9383d6decb4a13950b (patch)
tree18b5438f040464f841c5e0b9ae0a877175759c75 /video
parenta6c8b4efa59628a755755c510aa9ee6db2728fb9 (diff)
downloadmpv-1edb3d061bd88e86cba05e9383d6decb4a13950b.tar.bz2
mpv-1edb3d061bd88e86cba05e9383d6decb4a13950b.tar.xz
test: add dumping of img_format metadata
This is fragile enough that it warrants getting "monitored". This takes the commented test program code from img_format.c, makes it output to a text file, and then compares it to a "ref" file stored in git. Originally, I wanted to do the comparison etc. in a shell or Python script. But why not do it in C. So mpv calls /usr/bin/diff as a sub-process now. This test will start producing different output if FFmpeg adds new pixel formats or pixel format flags, or if mpv adds new IMGFMT (either aliases to FFmpeg formats or own formats). That is unavoidable, and requires manual inspection of the results, and then updating the ref file. The changes in the non-test code are to guarantee that the format ID conversion functions only translate between valid IDs.
Diffstat (limited to 'video')
-rw-r--r--video/fmt-conversion.c4
-rw-r--r--video/img_format.c95
2 files changed, 2 insertions, 97 deletions
diff --git a/video/fmt-conversion.c b/video/fmt-conversion.c
index 72f4407e70..b9b3d5ef66 100644
--- a/video/fmt-conversion.c
+++ b/video/fmt-conversion.c
@@ -95,7 +95,7 @@ enum AVPixelFormat imgfmt2pixfmt(int fmt)
enum AVPixelFormat pixfmt = fmt - IMGFMT_AVPIXFMT_START;
// Avoid duplicate format - each format must be unique.
int mpfmt = pixfmt2imgfmt(pixfmt);
- if (mpfmt == fmt)
+ if (mpfmt == fmt && av_pix_fmt_desc_get(pixfmt))
return pixfmt;
return AV_PIX_FMT_NONE;
}
@@ -118,7 +118,7 @@ int pixfmt2imgfmt(enum AVPixelFormat pix_fmt)
}
int generic = IMGFMT_AVPIXFMT_START + pix_fmt;
- if (generic < IMGFMT_AVPIXFMT_END)
+ if (generic < IMGFMT_AVPIXFMT_END && av_pix_fmt_desc_get(pix_fmt))
return generic;
return 0;
diff --git a/video/img_format.c b/video/img_format.c
index ace8159ecf..4028bf0e0b 100644
--- a/video/img_format.c
+++ b/video/img_format.c
@@ -534,98 +534,3 @@ int mp_imgfmt_select_best_list(int *dst, int num_dst, int src)
best = best ? mp_imgfmt_select_best(best, dst[n], src) : dst[n];
return best;
}
-
-#if 0
-
-#include <libavutil/frame.h>
-#include "sws_utils.h"
-
-int main(int argc, char **argv)
-{
- const AVPixFmtDescriptor *avd = av_pix_fmt_desc_next(NULL);
- for (; avd; avd = av_pix_fmt_desc_next(avd)) {
- enum AVPixelFormat fmt = av_pix_fmt_desc_get_id(avd);
- if (fmt == AV_PIX_FMT_YUVJ420P || fmt == AV_PIX_FMT_YUVJ422P ||
- fmt == AV_PIX_FMT_YUVJ444P || fmt == AV_PIX_FMT_YUVJ440P)
- continue;
- printf("%s (%d)", avd->name, (int)fmt);
- int mpfmt = pixfmt2imgfmt(fmt);
- bool generic = mpfmt >= IMGFMT_AVPIXFMT_START &&
- mpfmt < IMGFMT_AVPIXFMT_END;
- printf(" mp=%d%s\n ", mpfmt, generic ? " [GENERIC]" : "");
- struct mp_imgfmt_desc d = mp_imgfmt_get_desc(mpfmt);
- if (d.id)
- assert(d.avformat == fmt);
-#define FLAG(t, c) if (d.flags & (t)) printf("[%s]", c);
- FLAG(MP_IMGFLAG_BYTE_ALIGNED, "BA")
- FLAG(MP_IMGFLAG_ALPHA, "a")
- FLAG(MP_IMGFLAG_YUV_P, "YUVP")
- FLAG(MP_IMGFLAG_YUV_NV, "NV")
- FLAG(MP_IMGFLAG_YUV, "yuv")
- FLAG(MP_IMGFLAG_RGB, "rgb")
- FLAG(MP_IMGFLAG_LE, "le")
- FLAG(MP_IMGFLAG_BE, "be")
- FLAG(MP_IMGFLAG_PAL, "pal")
- FLAG(MP_IMGFLAG_HWACCEL, "hw")
- int fcsp = mp_imgfmt_get_forced_csp(mpfmt);
- if (fcsp)
- printf(" fcsp=%d", fcsp);
- printf(" ctype=%d", mp_imgfmt_get_component_type(mpfmt));
- printf("\n");
- printf(" planes=%d, chroma=%d:%d align=%d:%d bits=%d cbits=%d\n",
- d.num_planes, d.chroma_xs, d.chroma_ys, d.align_x, d.align_y,
- d.plane_bits, d.component_bits);
- printf(" {");
- for (int n = 0; n < MP_MAX_PLANES; n++)
- printf("%d/%d/[%d:%d] ", d.bytes[n], d.bpp[n], d.xs[n], d.ys[n]);
- printf("}\n");
- if (mpfmt && !(d.flags & MP_IMGFLAG_HWACCEL) && fmt != AV_PIX_FMT_UYYVYY411)
- {
- AVFrame *fr = av_frame_alloc();
- fr->format = fmt;
- fr->width = 128;
- fr->height = 128;
- int err = av_frame_get_buffer(fr, MP_IMAGE_BYTE_ALIGN);
- assert(err >= 0);
- struct mp_image *mpi = mp_image_alloc(mpfmt, fr->width, fr->height);
- assert(mpi);
- // A rather fuzzy test, which might fail even if there's no bug.
- for (int n = 0; n < 4; n++) {
- if (!!mpi->planes[n] != !!fr->data[n]) {
- printf(" Warning: p%d: %p %p\n", n,
- mpi->planes[n], fr->data[n]);
- }
- if (mpi->stride[n] != fr->linesize[n]) {
- printf(" Warning: p%d: %d %d\n", n,
- mpi->stride[n], fr->linesize[n]);
- }
- }
- talloc_free(mpi);
- av_frame_free(&fr);
- }
- struct mp_regular_imgfmt reg;
- if (mp_get_regular_imgfmt(&reg, mpfmt)) {
- const char *type = "unknown";
- switch (reg.component_type) {
- case MP_COMPONENT_TYPE_UINT: type = "uint"; break;
- case MP_COMPONENT_TYPE_FLOAT: type = "float"; break;
- }
- printf(" Regular: %d planes, %d bytes per comp., %d bit-pad, "
- "%dx%d chroma, type=%s\n",
- reg.num_planes, reg.component_size, reg.component_pad,
- reg.chroma_w, reg.chroma_h, type);
- for (int n = 0; n < reg.num_planes; n++) {
- struct mp_regular_imgfmt_plane *plane = &reg.planes[n];
- printf(" %d: {", n);
- for (int i = 0; i < plane->num_components; i++) {
- if (i > 0)
- printf(", ");
- printf("%d", plane->components[i]);
- }
- printf("}\n");
- }
- }
- }
-}
-
-#endif