summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2016-07-15 11:54:44 +0200
committerwm4 <wm4@nowhere>2016-07-15 13:04:17 +0200
commit85488f68928ed40020e545b736118e0273e06cd1 (patch)
treee9e6344f5eff9206a08bc2732dd411fe56269ae7
parent4a4a9f330281ad11eb39a013bf7308063767bab8 (diff)
downloadmpv-85488f68928ed40020e545b736118e0273e06cd1.tar.bz2
mpv-85488f68928ed40020e545b736118e0273e06cd1.tar.xz
video: change hw_subfmt meaning
The hw_subfmt field roughly corresponds to the field AVHWFramesContext.sw_format in ffmpeg. The ffmpeg one is of the type AVPixelFormat (instead of the underlying hardware format), so it's a good idea to switch to this too for preparation. Now the hw_subfmt field is an mp_imgfmt instead of an opaque/API- specific number. VDPAU and Direct3D11 already used mp_imgfmt, but Videotoolbox and VAAPI had to be switched. One somewhat user-visible change is that the verbose log will now always show the hw_subfmt as image format, instead of as nonsensical number. (In the end it would be good if we could switch to AVHWFramesContext completely, but the upstream API is incomplete and doesn't cover Direct3D11 and Videotoolbox.)
-rw-r--r--video/decode/videotoolbox.c32
-rw-r--r--video/mp_image.c2
-rw-r--r--video/mp_image.h3
-rw-r--r--video/out/opengl/hwdec_osx.c2
-rw-r--r--video/out/opengl/hwdec_vaegl.c7
-rw-r--r--video/vaapi.c2
6 files changed, 22 insertions, 26 deletions
diff --git a/video/decode/videotoolbox.c b/video/decode/videotoolbox.c
index 355017ffd4..c6f1a472bf 100644
--- a/video/decode/videotoolbox.c
+++ b/video/decode/videotoolbox.c
@@ -138,6 +138,17 @@ static void uninit(struct lavc_ctx *ctx)
ctx->hwdec_priv = NULL;
}
+static int mp_imgfmt_from_cvpixelformat(uint32_t cvpixfmt)
+{
+ switch (cvpixfmt) {
+ case kCVPixelFormatType_420YpCbCr8Planar: return IMGFMT_420P;
+ case kCVPixelFormatType_422YpCbCr8: return IMGFMT_UYVY;
+ case kCVPixelFormatType_32BGRA: return IMGFMT_RGB0;
+ case kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange: return IMGFMT_NV12;
+ }
+ return 0;
+}
+
static struct mp_image *copy_image(struct lavc_ctx *ctx, struct mp_image *hw_image)
{
if (hw_image->imgfmt != IMGFMT_VIDEOTOOLBOX)
@@ -150,23 +161,9 @@ static struct mp_image *copy_image(struct lavc_ctx *ctx, struct mp_image *hw_ima
size_t width = CVPixelBufferGetWidth(pbuf);
size_t height = CVPixelBufferGetHeight(pbuf);
uint32_t cvpixfmt = CVPixelBufferGetPixelFormatType(pbuf);
- int pixfmt = 0;
- switch (cvpixfmt) {
- case kCVPixelFormatType_420YpCbCr8Planar:
- pixfmt = IMGFMT_420P;
- break;
- case kCVPixelFormatType_422YpCbCr8:
- pixfmt = IMGFMT_UYVY;
- break;
- case kCVPixelFormatType_32BGRA:
- pixfmt = IMGFMT_RGB0;
- break;
- case kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange:
- pixfmt = IMGFMT_NV12;
- break;
- default:
+ int pixfmt = mp_imgfmt_from_cvpixelformat(cvpixfmt);
+ if (!pixfmt)
goto unlock;
- }
struct mp_image img = {0};
mp_image_setfmt(&img, pixfmt);
@@ -202,7 +199,8 @@ static struct mp_image *process_image(struct lavc_ctx *ctx, struct mp_image *img
{
if (img->imgfmt == IMGFMT_VIDEOTOOLBOX) {
CVPixelBufferRef pbuf = (CVPixelBufferRef)img->planes[3];
- img->params.hw_subfmt = CVPixelBufferGetPixelFormatType(pbuf);
+ uint32_t cvpixfmt = CVPixelBufferGetPixelFormatType(pbuf);
+ img->params.hw_subfmt = mp_imgfmt_from_cvpixelformat(cvpixfmt);
}
return img;
}
diff --git a/video/mp_image.c b/video/mp_image.c
index a4ce6d1cc5..531565f837 100644
--- a/video/mp_image.c
+++ b/video/mp_image.c
@@ -512,7 +512,7 @@ char *mp_image_params_to_str_buf(char *b, size_t bs,
mp_snprintf_cat(b, bs, " [%d:%d]", p->p_w, p->p_h);
mp_snprintf_cat(b, bs, " %s", mp_imgfmt_to_name(p->imgfmt));
if (p->hw_subfmt)
- mp_snprintf_cat(b, bs, "[%llu]", (unsigned long long)(p->hw_subfmt));
+ mp_snprintf_cat(b, bs, "[%s]", mp_imgfmt_to_name(p->hw_subfmt));
mp_snprintf_cat(b, bs, " %s/%s",
m_opt_choice_str(mp_csp_names, p->color.space),
m_opt_choice_str(mp_csp_levels_names, p->color.levels));
diff --git a/video/mp_image.h b/video/mp_image.h
index dfbe4ee0ba..13e364ae24 100644
--- a/video/mp_image.h
+++ b/video/mp_image.h
@@ -39,8 +39,7 @@
// usually copy the whole struct, so that fields added later will be preserved.
struct mp_image_params {
enum mp_imgfmt imgfmt; // pixel format
- uint64_t hw_subfmt; // underlying format for some hwaccel pixfmts
- // (will use the HW API's format identifiers)
+ enum mp_imgfmt hw_subfmt; // underlying format for some hwaccel pixfmts
int w, h; // image dimensions
int p_w, p_h; // define pixel aspect ratio (undefined: 0/0)
struct mp_colorspace color;
diff --git a/video/out/opengl/hwdec_osx.c b/video/out/opengl/hwdec_osx.c
index 6ddfa66e0a..17399a80f4 100644
--- a/video/out/opengl/hwdec_osx.c
+++ b/video/out/opengl/hwdec_osx.c
@@ -186,7 +186,7 @@ static int reinit(struct gl_hwdec *hw, struct mp_image_params *params)
{
assert(params->imgfmt == hw->driver->imgfmt);
- struct vt_format *f = vt_get_gl_format(params->hw_subfmt);
+ struct vt_format *f = vt_get_gl_format_from_imgfmt(params->hw_subfmt);
if (!f) {
MP_ERR(hw, "Unsupported CVPixelBuffer format.\n");
return -1;
diff --git a/video/out/opengl/hwdec_vaegl.c b/video/out/opengl/hwdec_vaegl.c
index 6c52cdde11..1de5969bc4 100644
--- a/video/out/opengl/hwdec_vaegl.c
+++ b/video/out/opengl/hwdec_vaegl.c
@@ -250,17 +250,16 @@ static int reinit(struct gl_hwdec *hw, struct mp_image_params *params)
}
gl->BindTexture(GL_TEXTURE_2D, 0);
- p->current_mpfmt = va_fourcc_to_imgfmt(params->hw_subfmt);
+ p->current_mpfmt = params->hw_subfmt;
if (p->current_mpfmt != IMGFMT_NV12 &&
p->current_mpfmt != IMGFMT_420P)
{
MP_FATAL(p, "unsupported VA image format %s\n",
- mp_tag_str(params->hw_subfmt));
+ mp_imgfmt_to_name(p->current_mpfmt));
return -1;
}
- MP_VERBOSE(p, "format: %s %s\n", mp_tag_str(params->hw_subfmt),
- mp_imgfmt_to_name(p->current_mpfmt));
+ MP_VERBOSE(p, "hw format: %s\n", mp_imgfmt_to_name(p->current_mpfmt));
params->imgfmt = p->current_mpfmt;
diff --git a/video/vaapi.c b/video/vaapi.c
index f8d0faba34..604fffa738 100644
--- a/video/vaapi.c
+++ b/video/vaapi.c
@@ -509,7 +509,7 @@ void va_surface_init_subformat(struct mp_image *mpi)
if (status != VA_STATUS_SUCCESS)
goto err;
- mpi->params.hw_subfmt = va_image.format.fourcc;
+ mpi->params.hw_subfmt = va_fourcc_to_imgfmt(va_image.format.fourcc);
status = vaDestroyImage(p->display, va_image.image_id);
CHECK_VA_STATUS(p->ctx, "vaDestroyImage()");