[MPlayer-cvslog] r25689 - in trunk: codec-cfg.c codec-cfg.h libmpcodecs/dec_audio.c libmpcodecs/dec_video.c

reimar subversion at mplayerhq.hu
Sat Jan 12 15:05:46 CET 2008


Author: reimar
Date: Sat Jan 12 15:05:46 2008
New Revision: 25689

Log:
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.


Modified:
   trunk/codec-cfg.c
   trunk/codec-cfg.h
   trunk/libmpcodecs/dec_audio.c
   trunk/libmpcodecs/dec_video.c

Modified: trunk/codec-cfg.c
==============================================================================
--- trunk/codec-cfg.c	(original)
+++ trunk/codec-cfg.c	Sat Jan 12 15:05:46 2008
@@ -818,36 +818,30 @@ codecs_t* find_codec(unsigned int fourcc
 	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){

Modified: trunk/codec-cfg.h
==============================================================================
--- trunk/codec-cfg.h	(original)
+++ trunk/codec-cfg.h	Sat Jan 12 15:05:46 2008
@@ -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 
                            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 */

Modified: trunk/libmpcodecs/dec_audio.c
==============================================================================
--- trunk/libmpcodecs/dec_audio.c	(original)
+++ trunk/libmpcodecs/dec_audio.c	Sat Jan 12 15:05:46 2008
@@ -129,7 +129,7 @@ static int init_audio_codec(sh_audio_t *
 }
 
 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_aud
 	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_aud
 	    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_aud
 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_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,

Modified: trunk/libmpcodecs/dec_video.c
==============================================================================
--- trunk/libmpcodecs/dec_video.c	(original)
+++ trunk/libmpcodecs/dec_video.c	Sat Jan 12 15:05:46 2008
@@ -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_vid
           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->status<status) continue; // too unstable
-	sh_video->codec->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_vid
 
 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_
         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);



More information about the MPlayer-cvslog mailing list