[Mplayerxp-cvslog] SF.net SVN: mplayerxp:[279] mplayerxp
Brought to you by:
olov
From: <nic...@us...> - 2012-11-02 09:08:50
|
Revision: 279 http://mplayerxp.svn.sourceforge.net/mplayerxp/?rev=279&view=rev Author: nickols_k Date: 2012-11-02 09:08:44 +0000 (Fri, 02 Nov 2012) Log Message: ----------- use ffmpeg's video decoders as last hope Modified Paths: -------------- mplayerxp/libmpcodecs/dec_video.c mplayerxp/libmpcodecs/dec_video.h mplayerxp/libmpcodecs/vd_ffmpeg.c mplayerxp/libmpconf/codec-cfg.c mplayerxp/mplayer.c Modified: mplayerxp/libmpcodecs/dec_video.c =================================================================== --- mplayerxp/libmpcodecs/dec_video.c 2012-11-02 08:57:39 UTC (rev 278) +++ mplayerxp/libmpcodecs/dec_video.c 2012-11-02 09:08:44 UTC (rev 279) @@ -88,15 +88,57 @@ static unsigned smp_num_cpus=1; static unsigned use_vf_threads=0; +static const vd_functions_t* mpcv_find_driver_by_name(const char *name) { + unsigned i; + for (i=0; mpcodecs_vd_drivers[i] != NULL; i++) + if(strcmp(mpcodecs_vd_drivers[i]->info->driver_name,name)==0) break; + return mpcodecs_vd_drivers[i]; +} + +static void mpcv_print_codec_info(sh_video_t* sh_video) { + MSG_OK("[VC] %s decoder: [%s] drv:%s.%s (%dx%d (aspect %g) %4.2ffps\n" + ,mp_conf.video_codec?"Forcing":"Selected" + ,sh_video->codec->codec_name + ,mpvdec->info->driver_name + ,sh_video->codec->dll_name + ,sh_video->src_w + ,sh_video->src_h + ,sh_video->aspect + ,sh_video->fps); + // Yeah! We got it! + sh_video->inited=1; + sh_video->vf_flags=vf_query_flags(sh_video->vfilter); +#ifdef _OPENMP + if(mp_conf.gomp) { + smp_num_cpus=omp_get_num_procs(); + use_vf_threads=0; + if(((sh_video->vf_flags&MPDEC_THREAD_COND)==MPDEC_THREAD_COND) && (smp_num_cpus>1)) use_vf_threads=1; + if(use_vf_threads) + MSG_STATUS("[mpdec] will perform parallel video-filter on %u CPUs\n",smp_num_cpus); + } +#else + MSG_V("[mpdec] GOMP was not compiled-in! Using single threaded video filtering!\n"); +#endif +} + +int mpcv_ffmpeg_init(sh_video_t*sh_video) { + /* Use ffmpeg's drivers as last hope */ + mpvdec=mpcv_find_driver_by_name("ffmpeg"); + if(!mpvdec->init(sh_video)){ + MSG_ERR(MSGTR_CODEC_CANT_INITV); + return 0; + } + mpcv_print_codec_info(sh_video); + return 1; +} + int mpcv_init(sh_video_t *sh_video,const char* codecname,const char * vfm,int status){ - unsigned o_bps,bpp; sh_video->codec=NULL; MSG_DBG3("mpcv_init(%p, %s, %s, %i)\n",sh_video,codecname,vfm,status); while((sh_video->codec=find_codec(sh_video->fourcc, - sh_video->bih?((unsigned int*) &sh_video->bih->biCompression):NULL, - sh_video->codec,0) )){ + sh_video->bih?((unsigned int*) &sh_video->bih->biCompression):NULL, + sh_video->codec,0) )){ // ok we found one codec - int i; if(sh_video->codec->flags&CODECS_FLAG_SELECTED) { MSG_DBG3("mpcv_init: %s already tried and failed\n",sh_video->codec->codec_name); continue; @@ -115,63 +157,14 @@ } sh_video->codec->flags|=CODECS_FLAG_SELECTED; // tagging it // ok, it matches all rules, let's find the driver! - for (i=0; mpcodecs_vd_drivers[i] != NULL; i++) - if(strcmp(mpcodecs_vd_drivers[i]->info->driver_name,sh_video->codec->driver_name)==0) break; - mpvdec=mpcodecs_vd_drivers[i]; - if(!mpvdec) continue; + if(!(mpvdec=mpcv_find_driver_by_name(sh_video->codec->driver_name))) continue; else MSG_DBG3("mpcv_init: mpcodecs_vd_drivers[%s]->mpvdec==0\n",mpcodecs_vd_drivers[i]->info->driver_name); // it's available, let's try to init! if(!mpvdec->init(sh_video)){ MSG_ERR(MSGTR_CODEC_CANT_INITV); continue; // try next... } - switch(sh_video->codec->outfmt[sh_video->outfmtidx]) - { - case IMGFMT_RGB8: - case IMGFMT_BGR8: - case IMGFMT_Y800: bpp=8; break; - case IMGFMT_YVU9: - case IMGFMT_IF09: bpp = 9; break; - case IMGFMT_YV12: - case IMGFMT_I420: - case IMGFMT_IYUV: bpp = 12; break; - default: - case IMGFMT_RGB15: - case IMGFMT_BGR15: - case IMGFMT_RGB16: - case IMGFMT_BGR16: - case IMGFMT_YUY2: - case IMGFMT_YVYU: - case IMGFMT_UYVY: bpp = 16; break; - case IMGFMT_RGB24: - case IMGFMT_BGR24: bpp = 24; break; - case IMGFMT_RGB32: - case IMGFMT_BGR32: bpp = 32; break; - } - o_bps=sh_video->fps*sh_video->src_w*sh_video->src_h*bpp/8; - MSG_OK("[VC] %s decoder: [%s] drv:%s.%s (%dx%d (aspect %g) %4.2ffps\n" - ,mp_conf.video_codec?"Forcing":"Selected" - ,sh_video->codec->codec_name - ,mpvdec->info->driver_name - ,sh_video->codec->dll_name - ,sh_video->src_w - ,sh_video->src_h - ,sh_video->aspect - ,sh_video->fps); - // Yeah! We got it! - sh_video->inited=1; - sh_video->vf_flags=vf_query_flags(sh_video->vfilter); -#ifdef _OPENMP - if(mp_conf.gomp) { - smp_num_cpus=omp_get_num_procs(); - use_vf_threads=0; - if(((sh_video->vf_flags&MPDEC_THREAD_COND)==MPDEC_THREAD_COND) && (smp_num_cpus>1)) use_vf_threads=1; - if(use_vf_threads) - MSG_STATUS("[mpdec] will perform parallel video-filter on %u CPUs\n",smp_num_cpus); - } -#else - MSG_V("[mpdec] GOMP was not compiled-in! Using single threaded video filtering!\n"); -#endif + mpcv_print_codec_info(sh_video); return 1; } return 0; Modified: mplayerxp/libmpcodecs/dec_video.h =================================================================== --- mplayerxp/libmpcodecs/dec_video.h 2012-11-02 08:57:39 UTC (rev 278) +++ mplayerxp/libmpcodecs/dec_video.h 2012-11-02 09:08:44 UTC (rev 279) @@ -4,6 +4,7 @@ // dec_video.c: extern int __FASTCALL__ mpcv_init(sh_video_t *sh_video, const char *codec_name,const char *family,int status); extern void __FASTCALL__ mpcv_uninit(sh_video_t *sh_video); +extern int __FASTCALL__ mpcv_ffmpeg_init(sh_video_t*); extern int __FASTCALL__ mpcv_decode(sh_video_t *sh_video,unsigned char *start,int in_size,int drop_frame,float pts); Modified: mplayerxp/libmpcodecs/vd_ffmpeg.c =================================================================== --- mplayerxp/libmpcodecs/vd_ffmpeg.c 2012-11-02 08:57:39 UTC (rev 278) +++ mplayerxp/libmpcodecs/vd_ffmpeg.c 2012-11-02 09:08:44 UTC (rev 279) @@ -74,6 +74,7 @@ LIBVD_EXTERN(ffmpeg) #include "libavcodec/avcodec.h" +#include "libavformat/riff.h" #include "libvo/video_out.h" @@ -214,6 +215,32 @@ return 1; } +static int find_vdecoder(sh_video_t* sh) { + unsigned i; + unsigned char flag = CODECS_FLAG_NOFLIP; + enum AVCodecID id = ff_codec_get_id(ff_codec_bmp_tags,sh->fourcc); + if (id <= 0) { + const char *fourcc; + prn_err: + fourcc=&sh->fourcc; + MSG_ERR("Cannot find AVCodecID for for '%c%c%c%c' fourcc! Try force -vc option\n" + ,fourcc[0],fourcc[1],fourcc[2],fourcc[3]); + return 0; + } + AVCodec *codec=avcodec_find_decoder(id); + if(!codec) goto prn_err; + sh->codec=mp_mallocz(sizeof(struct codecs_st)); + strcpy(sh->codec->dll_name,"ffmpeg"); + strcpy(sh->codec->driver_name,"ffmpeg"); + strcpy(sh->codec->codec_name,avcodec_get_name(id)); + for(i=0;i<CODECS_MAX_OUTFMT;i++) { + if(codec->pix_fmts[i]==-1) break; + sh->codec->outfmt[i]=avcodec_pix_fmt_to_codec_tag(codec->pix_fmts[i]); + sh->codec->outflags[i]=flag; + } + return 1; +} + extern unsigned xp_num_cpu; static int init(sh_video_t *sh){ unsigned avc_version=0; @@ -228,6 +255,10 @@ vdff_ctx=mp_mallocz(sizeof(priv_t)); sh->context = vdff_ctx; vdff_ctx->frame_number=-2; + if(!sh->codec) if(!find_vdecoder(sh)) { + MSG_ERR("Can't find ffmpeg decoder\n"); + return 0; + } vdff_ctx->lavc_codec = (AVCodec *)avcodec_find_decoder_by_name(sh->codec->dll_name); if(!vdff_ctx->lavc_codec){ MSG_ERR(MSGTR_MissingLAVCcodec,sh->codec->dll_name); Modified: mplayerxp/libmpconf/codec-cfg.c =================================================================== --- mplayerxp/libmpconf/codec-cfg.c 2012-11-02 08:57:39 UTC (rev 278) +++ mplayerxp/libmpconf/codec-cfg.c 2012-11-02 09:08:44 UTC (rev 279) @@ -267,27 +267,25 @@ return 0; } -static int validate_codec(codecs_t *c, int type) +static int validate_codec(codecs_t *c) { - unsigned i; - char *tmp_name = mp_strdup(c->codec_name); + unsigned i; + char *tmp_name = mp_strdup(c->codec_name); - for (i = 0; i < strlen(tmp_name) && isalnum(tmp_name[i]); i++) - /* NOTHING */; + for (i = 0; i < strlen(tmp_name) && isalnum(tmp_name[i]); i++)/* NOTHING */; - if (i < strlen(tmp_name)) { - MSG_ERR("\ncodec(%s) name is not valid!\n", c->codec_name); - mp_free(tmp_name); - return 0; - } - - if (!c->s_info) - { - strncpy(c->s_info,c->codec_name,sizeof(c->s_info)); - c->s_info[sizeof(c->s_info)-1]=0; - } + if (i < strlen(tmp_name)) { + MSG_ERR("\ncodec(%s) name is not valid!\n", c->codec_name); mp_free(tmp_name); - return 1; + return 0; + } + + if (!c->s_info) { + strncpy(c->s_info,c->codec_name,sizeof(c->s_info)); + c->s_info[sizeof(c->s_info)-1]=0; + } + mp_free(tmp_name); + return 1; } static short get_cpuflags(char *s) @@ -399,9 +397,9 @@ codecs_t *codec = NULL; // current codec codecs_t **codecsp = NULL;// points to audio_codecs or to video_codecs char *endptr; // strtoul()... - int *nr_codecsp; + int *nr_codecsp=NULL; const char *err_hint=NULL; - int codec_type; /* TYPE_VIDEO/TYPE_AUDIO */ + int codec_type=0; /* TYPE_VIDEO/TYPE_AUDIO */ int tmp, i; // in case we call it secont time @@ -414,7 +412,7 @@ nr_vcodecs = 0; nr_acodecs = 0; - if(cfgfile==NULL)return 0; + if(cfgfile==NULL) return 0; if ((fp = fopen(cfgfile, "r")) == NULL) { MSG_FATAL("can't open '%s': %s\n", cfgfile, strerror(errno)); @@ -444,7 +442,7 @@ continue; if (!strcmp(token[0], "audiocodec") || !strcmp(token[0], "videocodec")) { - if (!validate_codec(codec, codec_type)) + if (!validate_codec(codec)) goto err_out_not_valid; loop_enter: if (*token[0] == 'v') { @@ -613,7 +611,7 @@ } else goto err_out_parse_error; } - if (!validate_codec(codec, codec_type)) + if (!validate_codec(codec)) goto err_out_not_valid; MSG_INFO("%d audio & %d video codecs\n", nr_acodecs, nr_vcodecs); if(video_codecs) video_codecs[nr_vcodecs].codec_name[0] = '\0'; @@ -649,106 +647,103 @@ codecs_t *find_audio_codec(unsigned int fourcc, unsigned int *fourccmap, const codecs_t *start) { - return find_codec(fourcc, fourccmap, start, 1); + return find_codec(fourcc, fourccmap, start, 1); } codecs_t *find_video_codec(unsigned int fourcc, unsigned int *fourccmap, const codecs_t *start) { - return find_codec(fourcc, fourccmap, start, 0); + return find_codec(fourcc, fourccmap, start, 0); } codecs_t* find_codec(unsigned int fourcc,unsigned int *fourccmap, const codecs_t *start, int audioflag) { - int i, j; - codecs_t *c; - { - if (audioflag) { - i = nr_acodecs; - c = audio_codecs; - } else { - i = nr_vcodecs; - c = video_codecs; - } - if(!i) return NULL; - for (/* NOTHING */; i--; c++) { - if(start && c<=start) continue; - for (j = 0; j < CODECS_MAX_FOURCC; j++) { - if (c->fourcc[j]==fourcc || c->driver_name==0) { - if (fourccmap) - *fourccmap = c->fourccmap[j]; - return c; - } - } - } + int i, j; + codecs_t *c; + if (audioflag) { + i = nr_acodecs; + c = audio_codecs; + } else { + i = nr_vcodecs; + c = video_codecs; + } + if(!i) return NULL; + for (/* NOTHING */; i--; c++) { + if(start && c<=start) continue; + for (j = 0; j < CODECS_MAX_FOURCC; j++) { + if (c->fourcc[j]==fourcc || c->driver_name==0) { + if (fourccmap) + *fourccmap = c->fourccmap[j]; + return c; + } } - return NULL; + } + return NULL; } void codecs_reset_selection(int audioflag){ - int i; - codecs_t *c; - if (audioflag) { - i = nr_acodecs; - c = audio_codecs; - } else { - i = nr_vcodecs; - c = video_codecs; - } - if(i) - for (/* NOTHING */; i--; c++) - c->flags&=(~CODECS_FLAG_SELECTED); + int i; + codecs_t *c; + if (audioflag) { + i = nr_acodecs; + c = audio_codecs; + } else { + i = nr_vcodecs; + c = video_codecs; + } + if(i) + for (/* NOTHING */; i--; c++) + c->flags&=(~CODECS_FLAG_SELECTED); } void list_codecs(int audioflag){ int i; codecs_t *c; - if (audioflag) { - i = nr_acodecs; - c = audio_codecs; - MSG_INFO("Available audio codecs:\n"); - } else { - i = nr_vcodecs; - c = video_codecs; - MSG_INFO("Available video codecs:\n"); - } - MSG_INFO(" %-11s %-10s %s %s [%s]\n" + if (audioflag) { + i = nr_acodecs; + c = audio_codecs; + MSG_INFO("Available audio codecs:\n"); + } else { + i = nr_vcodecs; + c = video_codecs; + MSG_INFO("Available video codecs:\n"); + } + MSG_INFO(" %-11s %-10s %s %s [%s]\n" ,audioflag?"ac:":"vc:" ,audioflag?"afm:":"vfm:" ,"status:" ,"info:" ,"lib/dll"); - if(!i) return; - for (/* NOTHING */; i--; c++) { - char* s="unknown "; - switch(c->status){ - case CODECS_STATUS_WORKING: s="working ";break; - case CODECS_STATUS_PROBLEMS: s="problems";break; - case CODECS_STATUS_NOT_WORKING: s="crashing";break; - case CODECS_STATUS_UNTESTED: s="untested";break; - } - if(c->dll_name) - MSG_INFO(" %-11s %-10s %s %s [%s]\n",c->codec_name,c->driver_name,s,c->s_info,c->dll_name); - else - MSG_INFO(" %-11s %-10s %s %s\n",c->codec_name,c->driver_name,s,c->s_info); + if(!i) return; + for (/* NOTHING */; i--; c++) { + char* s="unknown "; + switch(c->status){ + case CODECS_STATUS_WORKING: s="working ";break; + case CODECS_STATUS_PROBLEMS: s="problems";break; + case CODECS_STATUS_NOT_WORKING: s="crashing";break; + case CODECS_STATUS_UNTESTED: s="untested";break; } - MSG_INFO("\n"); + if(c->dll_name) + MSG_INFO(" %-11s %-10s %s %s [%s]\n",c->codec_name,c->driver_name,s,c->s_info,c->dll_name); + else + MSG_INFO(" %-11s %-10s %s %s\n",c->codec_name,c->driver_name,s,c->s_info); + } + MSG_INFO("\n"); } - - #ifdef CODECS2HTML void wrapline(FILE *f2,char *s){ int c; if(!s){ - fprintf(f2,"-"); - return; + fprintf(f2,"-"); + return; } while((c=*s++)){ - if(c==',') fprintf(f2,"<br>"); else fputc(c,f2); + if(c==',') fprintf(f2,"<br>"); + else fputc(c,f2); } } @@ -760,7 +755,7 @@ continue; } d=fgetc(f1); - + switch(d){ case '.': return; // end of section @@ -802,14 +797,14 @@ } void skiphtml(FILE *f1){ - int c,d; - while((c=fgetc(f1))>=0){ - if(c!='%'){ - continue; - } - d=fgetc(f1); - if(d=='.') return; // end of section - } + int c,d; + while((c=fgetc(f1))>=0){ + if(c!='%'){ + continue; + } + d=fgetc(f1); + if(d=='.') return; // end of section + } } int main(void) @@ -830,7 +825,7 @@ f1=fopen("DOCS/codecs-in.html","rb"); if(!f1) exit(1); f2=fopen("DOCS/codecs-status.html","wb"); if(!f2) exit(1); - + while((c=fgetc(f1))>=0){ if(c!='%'){ fputc(c,f2); @@ -890,16 +885,16 @@ fseeko(f1,pos,SEEK_SET); skiphtml(f1); //void parsehtml(FILE *f1,FILE *f2,codecs_t *codec,int section,int dshow){ - + continue; } fputc(c,f2); fputc(d,f2); - } - - fclose(f2); - fclose(f1); - return 0; + } + + fclose(f2); + fclose(f1); + return 0; } #endif Modified: mplayerxp/mplayer.c =================================================================== --- mplayerxp/mplayer.c 2012-11-02 08:57:39 UTC (rev 278) +++ mplayerxp/mplayer.c 2012-11-02 09:08:44 UTC (rev 279) @@ -1208,7 +1208,7 @@ sh_audio_t* sh_audio=priv->demuxer->audio->sh; sh_video_t* sh_video=priv->demuxer->video->sh; float sleep_time=0; - if(sh_audio) { + if(sh_audio && xp_core->audio) { /* FIXME!!! need the same technique to detect xp_core->audio->eof as for video_eof! often ao_get_delay() never returns 0 :( */ if(xp_core->audio->eof && !get_delay_audio_buffer()) goto nosound_model; @@ -1234,6 +1234,7 @@ #define XP_MIN_TIMESLICE 0.010 /* under Linux on x86 min time_slice = 10 ms */ #define XP_MIN_AUDIOBUFF 0.05 #define XP_MAX_TIMESLICE 0.1 + if(!xp_core->audio) sh_audio=NULL; if(sh_audio && (!xp_core->audio->eof || ao_get_delay(ao_data)) && sleep_time>XP_MAX_TIMESLICE) { float t; @@ -1360,6 +1361,7 @@ /* FIXME: this block was added to fix A-V resync caused by some strange things like playing 48KHz audio on 44.1KHz soundcard and other. Now we know PTS of every audio frame so don't need to have it */ + if(!xp_core->audio) sh_audio=NULL; if(sh_audio && (!xp_core->audio->eof || ao_get_delay(ao_data)) && !mp_conf.av_sync_pts) { float a_pts=0; @@ -1923,6 +1925,9 @@ if(mpcv_init(sh_video,NULL,NULL,status)) break; } } + /* Use ffmpeg decoders as last hope */ + if(!sh_video->inited) mpcv_ffmpeg_init(sh_video); + if(!sh_video->inited) { const char *fmt; MSG_ERR(MSGTR_CantFindVideoCodec); @@ -1936,6 +1941,7 @@ rc=-1; } else priv->inited_flags|=INITED_VCODEC; + if(sh_video) MSG_V("%s video codec: [%s] vfm:%s (%s)\n", mp_conf.video_codec?"Forcing":"Detected",sh_video->codec->codec_name,sh_video->codec->driver_name,sh_video->codec->s_info); return rc; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |