diff codec-cfg.c @ 25661:293aeec83153

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.
author reimar
date Sat, 12 Jan 2008 14:05:46 +0000
parents 3605c9777989
children a004d8e043a5
line wrap: on
line diff
--- a/codec-cfg.c	Sat Jan 12 02:27:01 2008 +0000
+++ b/codec-cfg.c	Sat Jan 12 14:05:46 2008 +0000
@@ -818,36 +818,30 @@
 	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 stringset_free(stringset_t *set) {
+  free(*set);
+  *set = 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);
+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){