summaryrefslogtreecommitdiffstats
path: root/video
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2012-11-05 19:27:38 +0100
committerwm4 <wm4@nowhere>2013-01-13 17:39:31 +0100
commit06ccd9f6716ffb5220941bea12f345154545862e (patch)
tree26c2ebdd4e202d0888e76737d79fa9888f4f096d /video
parent42e0afe641de6eb15d89164e82671b6207402190 (diff)
downloadmpv-06ccd9f6716ffb5220941bea12f345154545862e.tar.bz2
mpv-06ccd9f6716ffb5220941bea12f345154545862e.tar.xz
video: simplify decoder pixel format handling
Simplify the decoder pixel format handling by making it handle only the case vd_lavc needs: a video stream always decodes to a single pixel format. Remove the handling for multiple pixel formats, and remove the codecs.conf pixel format declarations that are left. Remove the handling of "ambiguous" pixel formats like YV12 vs. I420 (via VDCTRL_QUERY_FORMAT etc.). This is only a problem if the video chain supports I420, but not YV12, which doesn't seem to be the case anywhere, and in fact would not have any advantage. Make the "flip" flag a global per-codec flag, rather than a pixel format specific flag. (Some ffmpeg decoders still return a flipped image, so this has to be done manually.) Also fix handling of the flip operation: do not overwrite the global flip option, and make the --flip option invert the codec flip option rather than overriding it.
Diffstat (limited to 'video')
-rw-r--r--video/decode/dec_video.c6
-rw-r--r--video/decode/vd.c83
-rw-r--r--video/decode/vd.h5
-rw-r--r--video/decode/vd_lavc.c34
4 files changed, 29 insertions, 99 deletions
diff --git a/video/decode/dec_video.c b/video/decode/dec_video.c
index 5c6cfc96ce..9ec5e3db65 100644
--- a/video/decode/dec_video.c
+++ b/video/decode/dec_video.c
@@ -252,12 +252,6 @@ static int init_video(sh_video_t *sh_video, char *codecname, char *vfm,
orig_h = sh_video->bih ? sh_video->bih->biHeight : sh_video->disp_h;
sh_video->disp_w = orig_w;
sh_video->disp_h = orig_h;
- // it's available, let's try to init!
- if (sh_video->codec->flags & CODECS_FLAG_ALIGN16) {
- // align width/height to n*16
- sh_video->disp_w = (sh_video->disp_w + 15) & (~15);
- sh_video->disp_h = (sh_video->disp_h + 15) & (~15);
- }
if (sh_video->bih) {
sh_video->bih->biWidth = sh_video->disp_w;
sh_video->bih->biHeight = sh_video->disp_h;
diff --git a/video/decode/vd.c b/video/decode/vd.c
index 89783da189..2ed553d440 100644
--- a/video/decode/vd.c
+++ b/video/decode/vd.c
@@ -16,9 +16,10 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
-#include <stdio.h>
+#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
+#include <assert.h>
#include "config.h"
#include "core/mp_msg.h"
@@ -51,13 +52,9 @@ const vd_functions_t * const mpcodecs_vd_drivers[] = {
NULL
};
-int mpcodecs_config_vo(sh_video_t *sh, int w, int h,
- const unsigned int *outfmts,
- unsigned int preferred_outfmt)
+int mpcodecs_config_vo(sh_video_t *sh, int w, int h, unsigned int out_fmt)
{
struct MPOpts *opts = sh->opts;
- int j;
- unsigned int out_fmt = 0;
int screen_size_x = 0;
int screen_size_y = 0;
vf_instance_t *vf = sh->vfilter;
@@ -76,61 +73,37 @@ int mpcodecs_config_vo(sh_video_t *sh, int w, int h,
if (!sh->disp_w || !sh->disp_h)
return 0;
- mp_msg(MSGT_DECVIDEO, MSGL_V,
- "VDec: vo config request - %d x %d (preferred colorspace: %s)\n",
- w, h, vo_format_name(preferred_outfmt));
+ mp_msg(MSGT_DECVIDEO, MSGL_V, "VDec: vo config request - %d x %d (%s)\n",
+ w, h, vo_format_name(out_fmt));
if (get_video_quality_max(sh) <= 0 && divx_quality) {
// user wants postprocess but no pp filter yet:
sh->vfilter = vf = vf_open_filter(opts, vf, "pp", NULL);
}
- if (!outfmts || sh->codec->outfmt[0] != 0xffffffff)
- outfmts = sh->codec->outfmt;
-
// check if libvo and codec has common outfmt (no conversion):
- csp_again:
-
- if (mp_msg_test(MSGT_DECVIDEO, MSGL_V)) {
- mp_msg(MSGT_DECVIDEO, MSGL_V, "Trying filter chain:");
- for (vf_instance_t *f = vf; f; f = f->next)
- mp_msg(MSGT_DECVIDEO, MSGL_V, " %s", f->info->name);
- mp_msg(MSGT_DECVIDEO, MSGL_V, "\n");
- }
+ for (;;) {
+ if (mp_msg_test(MSGT_DECVIDEO, MSGL_V)) {
+ mp_msg(MSGT_DECVIDEO, MSGL_V, "Trying filter chain:");
+ for (vf_instance_t *f = vf; f; f = f->next)
+ mp_msg(MSGT_DECVIDEO, MSGL_V, " %s", f->info->name);
+ mp_msg(MSGT_DECVIDEO, MSGL_V, "\n");
+ }
- j = -1;
- for (int i = 0; i < CODECS_MAX_OUTFMT; i++) {
- int flags;
- out_fmt = outfmts[i];
- if (out_fmt == (unsigned int) 0xFFFFFFFF)
- break;
- flags = vf->query_format(vf, out_fmt);
- mp_msg(MSGT_CPLAYER, MSGL_DBG2,
- "vo_debug: query(%s) returned 0x%X (i=%d) \n",
- vo_format_name(out_fmt), flags, i);
+ int flags = vf->query_format(vf, out_fmt);
+ mp_msg(MSGT_CPLAYER, MSGL_DBG2, "vo_debug: query(%s) returned 0x%X \n",
+ vo_format_name(out_fmt), flags);
if ((flags & VFCAP_CSP_SUPPORTED_BY_HW)
- || (flags & VFCAP_CSP_SUPPORTED && j < 0)) {
- // check (query) if codec really support this outfmt...
- sh->outfmtidx = j; // pass index to the control() function this way
- if (sh->vd_driver->control(sh, VDCTRL_QUERY_FORMAT, &out_fmt) ==
- CONTROL_FALSE) {
- mp_msg(MSGT_CPLAYER, MSGL_DBG2,
- "vo_debug: codec query_format(%s) returned FALSE\n",
- vo_format_name(out_fmt));
- continue;
- }
- j = i;
+ || (flags & VFCAP_CSP_SUPPORTED))
+ {
sh->output_flags = flags;
- if (flags & VFCAP_CSP_SUPPORTED_BY_HW)
- break;
+ break;
}
- }
- if (j < 0) {
// TODO: no match - we should use conversion...
if (strcmp(vf->info->name, "scale")) {
mp_tmsg(MSGT_DECVIDEO, MSGL_INFO, "Could not find matching colorspace - retrying with -vf scale...\n");
vf = vf_open_filter(opts, vf, "scale", NULL);
- goto csp_again;
+ continue;
}
mp_tmsg(MSGT_CPLAYER, MSGL_WARN,
"The selected video_out device is incompatible with this codec.\n"\
@@ -139,24 +112,18 @@ int mpcodecs_config_vo(sh_video_t *sh, int w, int h,
sh->vf_initialized = -1;
return 0; // failed
}
- out_fmt = outfmts[j];
sh->outfmt = out_fmt;
- mp_msg(MSGT_CPLAYER, MSGL_V, "VDec: using %s as output csp (no %d)\n",
- vo_format_name(out_fmt), j);
- sh->outfmtidx = j;
+ mp_msg(MSGT_CPLAYER, MSGL_V, "VDec: using %s as output csp\n",
+ vo_format_name(out_fmt));
sh->vfilter = vf;
// autodetect flipping
- if (opts->flip == -1) {
- opts->flip = 0;
- if (sh->codec->outflags[j] & CODECS_FLAG_FLIP)
- if (!(sh->codec->outflags[j] & CODECS_FLAG_NOFLIP))
- opts->flip = 1;
- }
- if (opts->flip && !(sh->output_flags & VFCAP_FLIP)) {
+ bool flip = !!opts->flip != !!(sh->codec->flags & CODECS_FLAG_FLIP);
+ if (flip && !(sh->output_flags & VFCAP_FLIP)) {
// we need to flip, but no flipping filter avail.
vf_add_before_vo(&vf, "flip", NULL);
sh->vfilter = vf;
+ flip = false;
}
// time to do aspect ratio corrections...
@@ -216,7 +183,7 @@ int mpcodecs_config_vo(sh_video_t *sh, int w, int h,
vocfg_flags = (opts->fullscreen ? VOFLAG_FULLSCREEN : 0)
| (opts->vidmode ? VOFLAG_MODESWITCHING : 0)
- | (opts->flip ? VOFLAG_FLIPPING : 0);
+ | (flip ? VOFLAG_FLIPPING : 0);
// Time to config libvo!
mp_msg(MSGT_CPLAYER, MSGL_V,
diff --git a/video/decode/vd.h b/video/decode/vd.h
index 838e5ad123..7b53c62840 100644
--- a/video/decode/vd.h
+++ b/video/decode/vd.h
@@ -42,15 +42,12 @@ typedef struct vd_functions
// NULL terminated array of all drivers
extern const vd_functions_t *const mpcodecs_vd_drivers[];
-#define VDCTRL_QUERY_FORMAT 3 // test for availabilty of a format
#define VDCTRL_RESYNC_STREAM 8 // reset decode state after seeking
#define VDCTRL_QUERY_UNSEEN_FRAMES 9 // current decoder lag
#define VDCTRL_RESET_ASPECT 10 // reinit filter/VO chain for new aspect ratio
// callbacks:
-int mpcodecs_config_vo(sh_video_t *sh, int w, int h,
- const unsigned int *outfmts,
- unsigned int preferred_outfmt);
+int mpcodecs_config_vo(sh_video_t *sh, int w, int h, unsigned int outfmt);
mp_image_t *mpcodecs_get_image(sh_video_t *sh, int mp_imgtype, int mp_imgflag,
int w, int h);
diff --git a/video/decode/vd_lavc.c b/video/decode/vd_lavc.c
index 2f661dfdd1..41286141ab 100644
--- a/video/decode/vd_lavc.c
+++ b/video/decode/vd_lavc.c
@@ -408,23 +408,11 @@ static int init_vo(sh_video_t *sh, enum PixelFormat pix_fmt)
sh->disp_h = height;
ctx->pix_fmt = pix_fmt;
ctx->best_csp = pixfmt2imgfmt(pix_fmt);
- const unsigned int *supported_fmts;
- if (ctx->best_csp == IMGFMT_YV12)
- supported_fmts = (const unsigned int[]){
- IMGFMT_YV12, IMGFMT_I420, IMGFMT_IYUV, 0xffffffff
- };
- else if (ctx->best_csp == IMGFMT_422P)
- supported_fmts = (const unsigned int[]){
- IMGFMT_422P, IMGFMT_YV12, IMGFMT_I420, IMGFMT_IYUV, 0xffffffff
- };
- else
- supported_fmts = (const unsigned int[]){ctx->best_csp, 0xffffffff};
sh->colorspace = avcol_spc_to_mp_csp(avctx->colorspace);
sh->color_range = avcol_range_to_mp_csp_levels(avctx->color_range);
- if (!mpcodecs_config_vo(sh, sh->disp_w, sh->disp_h, supported_fmts,
- ctx->best_csp))
+ if (!mpcodecs_config_vo(sh, sh->disp_w, sh->disp_h, ctx->best_csp))
return -1;
ctx->vo_initialized = 1;
}
@@ -726,6 +714,8 @@ static struct mp_image *decode(struct sh_video *sh, struct demux_packet *packet,
if (!mpi->planes[0])
return NULL;
+ assert(mpi->imgfmt == pixfmt2imgfmt(avctx->pix_fmt));
+
if (ctx->best_csp == IMGFMT_422P && mpi->chroma_y_shift == 1) {
// we have 422p but user wants 420p
mpi->stride[1] *= 2;
@@ -777,24 +767,6 @@ static int control(sh_video_t *sh, int cmd, void *arg)
vd_ffmpeg_ctx *ctx = sh->context;
AVCodecContext *avctx = ctx->avctx;
switch (cmd) {
- case VDCTRL_QUERY_FORMAT: {
- int format = (*((int *)arg));
- if (format == ctx->best_csp)
- return CONTROL_TRUE;
- // possible conversions:
- switch (format) {
- case IMGFMT_YV12:
- case IMGFMT_IYUV:
- case IMGFMT_I420:
- // "converted" using pointer/stride modification
- if (ctx->best_csp == IMGFMT_YV12)
- return CONTROL_TRUE; // u/v swap
- if (ctx->best_csp == IMGFMT_422P && !ctx->do_dr1)
- return CONTROL_TRUE; // half stride
- break;
- }
- return CONTROL_FALSE;
- }
case VDCTRL_RESYNC_STREAM:
avcodec_flush_buffers(avctx);
return CONTROL_TRUE;