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.
This commit is contained in:
wm4 2012-11-05 19:27:38 +01:00
parent 42e0afe641
commit 06ccd9f671
10 changed files with 37 additions and 212 deletions

View File

@ -480,7 +480,7 @@ const m_option_t common_opts[] = {
OPT_FLAG_CONSTANTS("no-aspect", movie_aspect, 0, 0, 0),
OPT_FLOATRANGE("xy", screen_size_xy, 0, 0.001, 4096),
OPT_FLAG_CONSTANTS("flip", flip, 0, -1, 1),
OPT_FLAG_CONSTANTS("flip", flip, 0, 0, 1),
// use (probably completely broken) decoder direct rendering
OPT_MAKE_FLAGS("dr1", vd_use_dr1, 0),

View File

@ -138,71 +138,6 @@ static int add_to_format(char *s, char *alias,unsigned int *fourcc, unsigned int
return 1;
}
static int add_to_inout(char *sfmt, char *sflags, unsigned int *outfmt,
unsigned char *outflags)
{
static char *flagstr[] = {
"flip",
"noflip",
"yuvhack",
"query",
"static",
NULL
};
int i, j, freeslots;
unsigned char flags;
for (i = 0; i < CODECS_MAX_OUTFMT && outfmt[i] != 0xffffffff; i++)
/* NOTHING */;
freeslots = CODECS_MAX_OUTFMT - i;
if (!freeslots)
goto err_out_too_many;
flags = 0;
if(sflags) {
do {
for (j = 0; flagstr[j] != NULL; j++)
if (!strncmp(sflags, flagstr[j],
strlen(flagstr[j])))
break;
if (flagstr[j] == NULL)
goto err_out_parse_error;
flags|=(1<<j);
sflags+=strlen(flagstr[j]);
} while (*(sflags++) == ',');
if (*(--sflags) != '\0')
goto err_out_parse_error;
}
do {
for (j = 0; isalnum(sfmt[j]) || sfmt[j] == '_'; j++);
unsigned int fmt = mp_imgfmt_from_name((bstr) {sfmt, j}, true);
if (!fmt)
goto err_out_parse_error;
outfmt[i] = fmt;
outflags[i] = flags;
++i;
sfmt += j;
} while ((*(sfmt++) == ',') && --freeslots);
if (!freeslots)
goto err_out_too_many;
if (*(--sfmt) != '\0')
goto err_out_parse_error;
return 1;
err_out_too_many:
mp_tmsg(MSGT_CODECCFG,MSGL_ERR,"too many out...");
return 0;
err_out_parse_error:
mp_tmsg(MSGT_CODECCFG,MSGL_ERR,"parse error");
return 0;
}
static int validate_codec(codecs_t *c, int type)
{
unsigned int i;
@ -422,8 +357,6 @@ int parse_codec_cfg(const char *cfgfile)
++*nr_codecsp;
memset(codec,0,sizeof(codecs_t));
memset(codec->fourcc, 0xff, sizeof(codec->fourcc));
memset(codec->outfmt, 0xff, sizeof(codec->outfmt));
memset(codec->infmt, 0xff, sizeof(codec->infmt));
if (get_token(1, 1) < 0)
goto err_out_parse_error;
@ -497,25 +430,11 @@ int parse_codec_cfg(const char *cfgfile)
*endptr != '\0')
goto err_out_parse_error;
}
} else if (!strcmp(token[0], "out")) {
if (get_token(1, 2) < 0)
goto err_out_parse_error;
if (!add_to_inout(token[0], token[1], codec->outfmt,
codec->outflags))
goto err_out_print_linenum;
} else if (!strcmp(token[0], "in")) {
if (get_token(1, 2) < 0)
goto err_out_parse_error;
if (!add_to_inout(token[0], token[1], codec->infmt,
codec->inflags))
goto err_out_print_linenum;
} else if (!strcmp(token[0], "flags")) {
if (get_token(1, 1) < 0)
goto err_out_parse_error;
if (!strcmp(token[0], "seekable"))
codec->flags |= CODECS_FLAG_SEEKABLE;
else if (!strcmp(token[0], "align16"))
codec->flags |= CODECS_FLAG_ALIGN16;
if (!strcmp(token[0], "flip"))
codec->flags |= CODECS_FLAG_FLIP;
else
goto err_out_parse_error;
} else if (!strcmp(token[0], "status")) {

View File

@ -22,19 +22,9 @@
#include <stdbool.h>
#define CODECS_MAX_FOURCC 92
#define CODECS_MAX_OUTFMT 16
#define CODECS_MAX_INFMT 16
// Global flags:
#define CODECS_FLAG_SEEKABLE (1<<0)
#define CODECS_FLAG_ALIGN16 (1<<1)
// Outfmt flags:
#define CODECS_FLAG_FLIP (1<<0)
#define CODECS_FLAG_NOFLIP (1<<1)
#define CODECS_FLAG_YUVHACK (1<<2)
#define CODECS_FLAG_QUERY (1<<3)
#define CODECS_FLAG_STATIC (1<<4)
#define CODECS_STATUS__MIN 0
#define CODECS_STATUS_NOT_WORKING -1
@ -59,10 +49,6 @@ typedef struct {
typedef struct codecs {
unsigned int fourcc[CODECS_MAX_FOURCC];
unsigned int fourccmap[CODECS_MAX_FOURCC];
unsigned int outfmt[CODECS_MAX_OUTFMT];
unsigned char outflags[CODECS_MAX_OUTFMT];
unsigned int infmt[CODECS_MAX_INFMT];
unsigned char inflags[CODECS_MAX_INFMT];
char *name;
char *info;
char *comment;

View File

@ -52,7 +52,6 @@ void set_default_mplayer_options(struct MPOpts *opts)
.playback_speed = 1.,
.drc_level = 1.,
.movie_aspect = -1.,
.flip = -1,
.sub_auto = 1,
#ifdef CONFIG_ASS
.ass_enabled = 1,

View File

@ -156,7 +156,6 @@ typedef struct sh_video {
int color_range; // mp_csp_levels
// output driver/filters: (set by libmpcodecs core)
unsigned int outfmt;
unsigned int outfmtidx;
struct vf_instance *vfilter; // video filter chain
int output_flags; // query_format() results for output filters+vo
const struct vd_functions *vd_driver;

View File

@ -209,8 +209,6 @@ videocodec ffmpeg12vdpau
fourcc m2v1,m1v1
driver ffmpeg
dll "mpegvideo_vdpau"
out VDPAU_MPEG1
out VDPAU_MPEG2
videocodec ffmpeg2crystalhd
info "FFmpeg MPEG-2 (CrystalHD)"
@ -307,7 +305,6 @@ videocodec mpng
fourcc "png " ; for PNG-encoded QuickTime files
dll "libpng"
driver mpng
out BGR32,BGR24,BGR8,Y800
videocodec ffptx
info "FFmpeg V.Flash PTX"
@ -647,7 +644,6 @@ videocodec ffwmv3vdpau
fourcc WMV3,wmv3
driver ffmpeg
dll wmv3_vdpau
out VDPAU_WMV3
videocodec ffwmv3crystalhd
info "FFmpeg WMV3/WMV9 (CrystalHD)"
@ -671,7 +667,6 @@ videocodec ffvc1vdpau
fourcc vc-1,VC-1
driver ffmpeg
dll vc1_vdpau
out VDPAU_VC1
videocodec ffvc1crystalhd
info "FFmpeg WVC1 (CrystalHD)"
@ -708,7 +703,6 @@ videocodec ffh264vdpau
format 0x10000005
driver ffmpeg
dll h264_vdpau
out VDPAU_H264
videocodec ffh264crystalhd
info "FFmpeg H.264 (CrystalHD)"
@ -738,7 +732,6 @@ videocodec ffh264vda
format 0x10000005
driver ffmpeg
dll h264_vda
out YUY2,UYVY,YV12,NV12
videocodec ffsvq3
info "FFmpeg Sorenson Video v3 (SVQ3)"
@ -810,7 +803,6 @@ videocodec ffodivxvdpau
fourcc SIPP ; Samsung SHR-6040
driver ffmpeg
dll mpeg4_vdpau
out VDPAU_MPEG4
videocodec ffodivxcrystalhd
info "FFmpeg MPEG-4,DIVX-4/5 (CrystalHD)"
@ -850,7 +842,7 @@ videocodec ffwv1f
fourcc WV1F
driver ffmpeg
dll mpeg4
out YV12,I420,IYUV flip
flags flip
videocodec fflibschroedinger
info "Dirac (through FFmpeg libschroedinger)"
@ -946,7 +938,7 @@ videocodec ffzygo
fourcc ZyGo
driver ffmpeg
dll h263
out YV12,I420,IYUV flip
flags flip
videocodec ffh261
info "CCITT H.261"

View File

@ -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;

View File

@ -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");
}
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);
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;
sh->output_flags = flags;
if (flags & VFCAP_CSP_SUPPORTED_BY_HW)
break;
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");
}
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))
{
sh->output_flags = flags;
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,

View File

@ -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);

View File

@ -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;