[MPlayer-dev-eng] [PATCH] vo colourspace choosing
Reimar Döffinger
Reimar.Doeffinger at stud.uni-karlsruhe.de
Wed Oct 20 22:29:51 CEST 2004
Hi,
this patch should simplify and improve colorspace selection. First, it
tries to avoid the Y800 colorspace (grey only :-( ), and it migh allow
for a correct implementation of palettized colorspaces some day
(currently the have the same format identifier as the non-palettized
format!!!).
Greetings,
Reimar Döffinger
-------------- next part --------------
Index: libmpcodecs/vd.c
===================================================================
RCS file: /cvsroot/mplayer/main/libmpcodecs/vd.c,v
retrieving revision 1.79
diff -u -r1.79 vd.c
--- libmpcodecs/vd.c 1 Oct 2004 20:08:21 -0000 1.79
+++ libmpcodecs/vd.c 20 Oct 2004 20:24:18 -0000
@@ -140,14 +140,30 @@
extern vd_functions_t* mpvdec; // FIXME!
extern int divx_quality;
+static int is_fmt_better(unsigned old_fmt, int old_flags,
+ unsigned fmt, int flags,
+ unsigned preferred_fmt) {
+ if (!(flags & VFCAP_CSP_SUPPORTED))
+ return 0;
+ if (old_fmt == IMGFMT_Y8 || old_fmt == IMGFMT_Y800)
+ return 1;
+ if (!(old_flags & VFCAP_CSP_SUPPORTED_BY_HW) &&
+ (flags & VFCAP_CSP_SUPPORTED_BY_HW))
+ return 1;
+ if (!(flags & VFCAP_CSP_SUPPORTED_BY_HW) &&
+ (old_flags & VFCAP_CSP_SUPPORTED_BY_HW))
+ return 0;
+ return (fmt == preferred_fmt);
+}
+
int mpcodecs_config_vo(sh_video_t *sh, int w, int h, unsigned int preferred_outfmt){
int i,j;
unsigned int out_fmt=0;
int screen_size_x=0;//SCREEN_SIZE_X;
int screen_size_y=0;//SCREEN_SIZE_Y;
// vo_functions_t* video_out=sh->video_out;
- vf_instance_t* vf=sh->vfilter,*sc=NULL;
- int palette=0;
+ vf_instance_t* vf=sh->vfilter,*sc=NULL, *pal = NULL;
+ int conv_try_nr = 0;
if(!sh->disp_w || !sh->disp_h)
mp_msg(MSGT_DECVIDEO,MSGL_WARN, MSGTR_CodecDidNotSet);
@@ -182,48 +198,64 @@
}
j=-1;
+ vo_flags = 0;
+ out_fmt = 0;
for(i=0;i<CODECS_MAX_OUTFMT;i++){
int flags;
+ unsigned prev_fmt = out_fmt;
out_fmt=sh->codec->outfmt[i];
if(out_fmt==(unsigned int)0xFFFFFFFF) continue;
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&2) || (flags && j<0)){
+ if (is_fmt_better(prev_fmt, vo_flags, out_fmt, flags,
+ preferred_outfmt)) {
// check (query) if codec really support this outfmt...
sh->outfmtidx=j; // pass index to the control() function this way
if(mpvdec->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; vo_flags=flags; if(flags&2) break;
- } else
- if(!palette && !(flags&3) && (out_fmt==IMGFMT_RGB8||out_fmt==IMGFMT_BGR8)){
- sh->outfmtidx=j; // pass index to the control() function this way
- if(mpvdec->control(sh,VDCTRL_QUERY_FORMAT,&out_fmt)!=CONTROL_FALSE)
- palette=1;
+ j=i; vo_flags=flags;
}
}
if(j<0){
// TODO: no match - we should use conversion...
- if(strcmp(vf->info->name,"scale") && palette!=-1){
+ // Try palette, then scale, then scale + palette and MPEGPES last.
+ while (vf == sc || vf == pal) {
+ // Remove any filters we added ourselves
+ vf_instance_t *ve;
+ ve = vf;
+ vf = vf->next;
+ vf_uninit_filter(ve);
+ }
+ pal = sc = NULL;
+ switch (conv_try_nr) {
+ case 0:
+ conv_try_nr++;
+ if (strcmp(vf->info->name, "scale") != 0) {
mp_msg(MSGT_DECVIDEO,MSGL_INFO,MSGTR_CouldNotFindColorspace);
sc=vf=vf_open_filter(vf,"scale",NULL);
goto csp_again;
- } else
- if(palette==1){
+ }
+ // scale is already there
+ case 1:
+ conv_try_nr++;
+ if (strcmp(vf->info->name, "palette") != 0) {
mp_msg(MSGT_DECVIDEO,MSGL_V,"vd: Trying -vf palette...\n");
- palette=-1;
- vf=vf_open_filter(vf,"palette",NULL);
+ pal=vf=vf_open_filter(vf,"palette",NULL);
goto csp_again;
- } else
+ }
+ case 2:
+ conv_try_nr++;
+ if (strcmp(vf->info->name, "scale") != 0) {
+ mp_msg(MSGT_DECVIDEO,MSGL_V,"vd: Trying -vf palette, scale...\n");
+ sc=vf=vf_open_filter(vf,"scale",NULL);
+ pal=vf=vf_open_filter(vf,"palette",NULL);
+ goto csp_again;
+ }
+ case 3:
{ // sws failed, if the last filter (vf_vo) support MPEGPES try to append vf_lavc
vf_instance_t* vo, *vp = NULL, *ve;
- // Remove the scale filter if we added it ourself
- if(vf == sc) {
- ve = vf;
- vf = vf->next;
- vf_uninit_filter(ve);
- }
// Find the last filter (vf_vo)
for(vo = vf ; vo->next ; vo = vo->next)
vp = vo;
@@ -234,6 +266,7 @@
goto csp_again;
}
}
+ }
mp_msg(MSGT_CPLAYER,MSGL_WARN,MSGTR_VOincompCodec);
sh->vf_inited=-1;
return 0; // failed
More information about the MPlayer-dev-eng
mailing list