From d63fb8ba992a6b610615bde9c678f4b111bba667 Mon Sep 17 00:00:00 2001 From: reimar Date: Sat, 12 Jan 2008 14:05:46 +0000 Subject: Replace the persistent CODECS_FLAG_SELECTED by a local "stringset" with an almost-trivial implementation. This allows making the builtin codec structs const, and it also makes clearer that this "selected" status is not used outside the init functions. git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@25689 b3059339-0415-0410-9bf9-f77b7e298cf2 --- codec-cfg.c | 50 ++++++++++++++++++++++--------------------------- codec-cfg.h | 9 ++++++--- libmpcodecs/dec_audio.c | 18 ++++++++++-------- libmpcodecs/dec_video.c | 19 +++++++++++-------- 4 files changed, 49 insertions(+), 47 deletions(-) diff --git a/codec-cfg.c b/codec-cfg.c index 2d3e119601..945fb8b285 100644 --- a/codec-cfg.c +++ b/codec-cfg.c @@ -818,36 +818,30 @@ codecs_t* find_codec(unsigned int fourcc,unsigned int *fourccmap, return NULL; } -void select_codec(char* codecname,int audioflag){ - int i; - codecs_t *c; -// printf("select_codec('%s')\n",codecname); - if (audioflag) { - i = nr_acodecs; - c = audio_codecs; - } else { - i = nr_vcodecs; - c = video_codecs; - } - if(i) - for (/* NOTHING */; i--; c++) - if(!strcmp(c->name,codecname)) - c->flags|=CODECS_FLAG_SELECTED; +void stringset_init(stringset_t *set) { + *set = calloc(1, sizeof(char *)); } -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); +void stringset_free(stringset_t *set) { + free(*set); + *set = NULL; +} + +void stringset_add(stringset_t *set, const char *str) { + int count = 0; + while ((*set)[count]) count++; + count++; + *set = realloc(*set, sizeof(char *) * (count + 1)); + (*set)[count - 1] = strdup(str); + (*set)[count] = NULL; +} + +int stringset_test(stringset_t *set, const char *str) { + stringset_t s; + for (s = *set; *s; s++) + if (strcmp(*s, str) == 0) + return 1; + return 0; } void list_codecs(int audioflag){ diff --git a/codec-cfg.h b/codec-cfg.h index f2755f7d2c..4f6705bef2 100644 --- a/codec-cfg.h +++ b/codec-cfg.h @@ -10,7 +10,6 @@ // Global flags: #define CODECS_FLAG_SEEKABLE (1<<0) #define CODECS_FLAG_ALIGN16 (1<<1) -#define CODECS_FLAG_SELECTED (1<<15) /* for internal use */ // Outfmt flags: #define CODECS_FLAG_FLIP (1<<0) @@ -65,9 +64,13 @@ codecs_t* find_audio_codec(unsigned int fourcc, unsigned int *fourccmap, codecs_t *start, int force); codecs_t* find_codec(unsigned int fourcc, unsigned int *fourccmap, codecs_t *start, int audioflag, int force); -void select_codec(char* codecname,int audioflag); void list_codecs(int audioflag); -void codecs_reset_selection(int audioflag); void codecs_uninit_free(void); +typedef char ** stringset_t; +void stringset_init(stringset_t *set); +void stringset_free(stringset_t *set); +void stringset_add(stringset_t *set, const char *str); +int stringset_test(stringset_t *set, const char *str); + #endif /* CODEC_CFG_H */ diff --git a/libmpcodecs/dec_audio.c b/libmpcodecs/dec_audio.c index 77764d5928..b7ce68f0b1 100644 --- a/libmpcodecs/dec_audio.c +++ b/libmpcodecs/dec_audio.c @@ -129,7 +129,7 @@ static int init_audio_codec(sh_audio_t *sh_audio) } static int init_audio(sh_audio_t *sh_audio, char *codecname, char *afm, - int status) + int status, stringset_t *selected) { unsigned int orig_fourcc = sh_audio->wf ? sh_audio->wf->wFormatTag : 0; int force = 0; @@ -152,7 +152,7 @@ static int init_audio(sh_audio_t *sh_audio, char *codecname, char *afm, if (sh_audio->wf) sh_audio->wf->wFormatTag = i; // ok we found one codec - if (sh_audio->codec->flags & CODECS_FLAG_SELECTED) + if (stringset_test(selected, sh_audio->codec->name)) continue; // already tried & failed if (codecname && strcmp(sh_audio->codec->name, codecname)) continue; // -ac @@ -160,7 +160,7 @@ static int init_audio(sh_audio_t *sh_audio, char *codecname, char *afm, continue; // afm doesn't match if (!force && sh_audio->codec->status < status) continue; // too unstable - sh_audio->codec->flags |= CODECS_FLAG_SELECTED; // tagging it + stringset_add(selected, sh_audio->codec->name); // tagging it // ok, it matches all rules, let's find the driver! for (i = 0; mpcodecs_ad_drivers[i] != NULL; i++) if (!strcmp(mpcodecs_ad_drivers[i]->info->short_name, @@ -227,24 +227,25 @@ static int init_audio(sh_audio_t *sh_audio, char *codecname, char *afm, int init_best_audio_codec(sh_audio_t *sh_audio, char **audio_codec_list, char **audio_fm_list) { + stringset_t selected; char *ac_l_default[2] = { "", (char *) NULL }; // hack: if (!audio_codec_list) audio_codec_list = ac_l_default; // Go through the codec.conf and find the best codec... sh_audio->inited = 0; - codecs_reset_selection(1); + stringset_init(&selected); while (!sh_audio->inited && *audio_codec_list) { char *audio_codec = *(audio_codec_list++); if (audio_codec[0]) { if (audio_codec[0] == '-') { // disable this codec: - select_codec(audio_codec + 1, 1); + stringset_add(&selected, audio_codec + 1); } else { // forced codec by name: mp_msg(MSGT_DECAUDIO, MSGL_INFO, MSGTR_ForcedAudioCodec, audio_codec); - init_audio(sh_audio, audio_codec, NULL, -1); + init_audio(sh_audio, audio_codec, NULL, -1, &selected); } } else { int status; @@ -259,17 +260,18 @@ int init_best_audio_codec(sh_audio_t *sh_audio, char **audio_codec_list, audio_fm); for (status = CODECS_STATUS__MAX; status >= CODECS_STATUS__MIN; --status) - if (init_audio(sh_audio, NULL, audio_fm, status)) + if (init_audio(sh_audio, NULL, audio_fm, status, &selected)) break; } } if (!sh_audio->inited) for (status = CODECS_STATUS__MAX; status >= CODECS_STATUS__MIN; --status) - if (init_audio(sh_audio, NULL, NULL, status)) + if (init_audio(sh_audio, NULL, NULL, status, &selected)) break; } } + stringset_free(&selected); if (!sh_audio->inited) { mp_msg(MSGT_DECAUDIO, MSGL_ERR, MSGTR_CantFindAudioCodec, diff --git a/libmpcodecs/dec_video.c b/libmpcodecs/dec_video.c index b29c01aba4..403f29d4cd 100644 --- a/libmpcodecs/dec_video.c +++ b/libmpcodecs/dec_video.c @@ -175,7 +175,8 @@ void vfm_help(void){ mpcodecs_vd_drivers[i]->info->comment); } -static int init_video(sh_video_t *sh_video,char* codecname,char* vfm,int status){ +static int init_video(sh_video_t *sh_video,char* codecname,char* vfm,int status, + stringset_t *selected){ int force = 0; unsigned int orig_fourcc=sh_video->bih?sh_video->bih->biCompression:0; sh_video->codec=NULL; @@ -194,11 +195,11 @@ static int init_video(sh_video_t *sh_video,char* codecname,char* vfm,int status) sh_video->bih?((unsigned int*) &sh_video->bih->biCompression):NULL, sh_video->codec,force) )) break; // ok we found one codec - if(sh_video->codec->flags&CODECS_FLAG_SELECTED) continue; // already tried & failed + if(stringset_test(selected, sh_video->codec->name)) continue; // already tried & failed if(codecname && strcmp(sh_video->codec->name,codecname)) continue; // -vc if(vfm && strcmp(sh_video->codec->drv,vfm)) continue; // vfm doesn't match if(!force && sh_video->codec->statuscodec->flags|=CODECS_FLAG_SELECTED; // tagging it + stringset_add(selected, sh_video->codec->name); // tagging it // ok, it matches all rules, let's find the driver! for (i=0; mpcodecs_vd_drivers[i] != NULL; i++) // if(mpcodecs_vd_drivers[i]->info->id==sh_video->codec->driver) break; @@ -279,21 +280,22 @@ static int init_video(sh_video_t *sh_video,char* codecname,char* vfm,int status) int init_best_video_codec(sh_video_t *sh_video,char** video_codec_list,char** video_fm_list){ char* vc_l_default[2]={"",(char*)NULL}; +stringset_t selected; // hack: if(!video_codec_list) video_codec_list=vc_l_default; // Go through the codec.conf and find the best codec... sh_video->inited=0; -codecs_reset_selection(0); +stringset_init(&selected); while(!sh_video->inited && *video_codec_list){ char* video_codec=*(video_codec_list++); if(video_codec[0]){ if(video_codec[0]=='-'){ // disable this codec: - select_codec(video_codec+1,0); + stringset_add(&selected, video_codec+1); } else { // forced codec by name: mp_msg(MSGT_DECVIDEO,MSGL_INFO,MSGTR_ForcedVideoCodec,video_codec); - init_video(sh_video,video_codec,NULL,-1); + init_video(sh_video,video_codec,NULL,-1, &selected); } } else { int status; @@ -305,14 +307,15 @@ while(!sh_video->inited && *video_codec_list){ char* video_fm=*(fmlist++); mp_msg(MSGT_DECVIDEO,MSGL_INFO,MSGTR_TryForceVideoFmtStr,video_fm); for(status=CODECS_STATUS__MAX;status>=CODECS_STATUS__MIN;--status) - if(init_video(sh_video,NULL,video_fm,status)) break; + if(init_video(sh_video,NULL,video_fm,status, &selected)) break; } } if(!sh_video->inited) for(status=CODECS_STATUS__MAX;status>=CODECS_STATUS__MIN;--status) - if(init_video(sh_video,NULL,NULL,status)) break; + if(init_video(sh_video,NULL,NULL,status, &selected)) break; } } +stringset_free(&selected); if(!sh_video->inited){ mp_msg(MSGT_DECVIDEO,MSGL_ERR,MSGTR_CantFindVideoCodec,sh_video->format); -- cgit v1.2.3