[MPlayer-dev-eng] [PATCH] codec-cfg: Optimize built-in codecs format.
Reimar Döffinger
Reimar.Doeffinger at gmx.de
Sat Feb 13 22:00:36 CET 2016
Lookup strings via index in an array instead of
using direct pointers.
The two main advantages are
1) No data relocations that pointers would otherwise cause
2) Smaller size on 64 bit systems
---
codec-cfg.c | 156 +++++++++++++++++++++++++++++------------------
codec-cfg.h | 11 ++--
command.c | 4 +-
gui/interface.c | 2 +-
libmpcodecs/ad_acm.c | 2 +-
libmpcodecs/ad_dmo.c | 4 +-
libmpcodecs/ad_dshow.c | 4 +-
libmpcodecs/ad_ffmpeg.c | 4 +-
libmpcodecs/ad_realaud.c | 11 ++--
libmpcodecs/ad_spdif.c | 2 +-
libmpcodecs/ad_twin.c | 4 +-
libmpcodecs/dec_audio.c | 33 +++++-----
libmpcodecs/dec_video.c | 32 +++++-----
libmpcodecs/vd_dmo.c | 4 +-
libmpcodecs/vd_dshow.c | 7 ++-
libmpcodecs/vd_ffmpeg.c | 4 +-
libmpcodecs/vd_realvid.c | 11 ++--
libmpcodecs/vd_vfw.c | 7 ++-
libmpcodecs/vd_xanim.c | 4 +-
mplayer.c | 8 +--
20 files changed, 180 insertions(+), 134 deletions(-)
diff --git a/codec-cfg.c b/codec-cfg.c
index aebf8d2..42235e0 100644
--- a/codec-cfg.c
+++ b/codec-cfg.c
@@ -399,28 +399,29 @@ static short get_driver(char *s,int audioflag)
static int validate_codec(codecs_t *c, int type)
{
unsigned int i;
- char *tmp_name = c->name;
+ const char *name = codec_idx2str(c->name_idx);
+ const char *tmp_name = name;
for (i = 0; i < strlen(tmp_name) && isalnum(tmp_name[i]); i++)
/* NOTHING */;
if (i < strlen(tmp_name)) {
- mp_msg(MSGT_CODECCFG,MSGL_ERR,MSGTR_InvalidCodecName, c->name);
+ mp_msg(MSGT_CODECCFG,MSGL_ERR,MSGTR_InvalidCodecName, name);
return 0;
}
- if (!c->info)
- c->info = strdup(c->name);
+ if (!c->info_idx)
+ c->info_idx = c->name_idx;
#if 0
if (c->fourcc[0] == 0xffffffff) {
- mp_msg(MSGT_CODECCFG,MSGL_ERR,MSGTR_CodecLacksFourcc, c->name);
+ mp_msg(MSGT_CODECCFG,MSGL_ERR,MSGTR_CodecLacksFourcc, name);
return 0;
}
#endif
- if (!c->drv) {
- mp_msg(MSGT_CODECCFG,MSGL_ERR,MSGTR_CodecLacksDriver, c->name);
+ if (!c->drv_idx) {
+ mp_msg(MSGT_CODECCFG,MSGL_ERR,MSGTR_CodecLacksDriver, name);
return 0;
}
@@ -429,7 +430,7 @@ static int validate_codec(codecs_t *c, int type)
//FIXME: Where are they defined ????????????
if (!c->dll && (c->driver == 4 ||
(c->driver == 2 && type == TYPE_VIDEO))) {
- mp_msg(MSGT_CODECCFG,MSGL_ERR,MSGTR_CodecNeedsDLL, c->name);
+ mp_msg(MSGT_CODECCFG,MSGL_ERR,MSGTR_CodecNeedsDLL, name);
return 0;
}
// FIXME: Can guid.f1 be 0? How does one know that it was not given?
@@ -437,7 +438,7 @@ static int validate_codec(codecs_t *c, int type)
if (type == TYPE_VIDEO)
if (c->outfmt[0] == 0xffffffff) {
- mp_msg(MSGT_CODECCFG,MSGL_ERR,MSGTR_CodecNeedsOutfmt, c->name);
+ mp_msg(MSGT_CODECCFG,MSGL_ERR,MSGTR_CodecNeedsOutfmt, name);
return 0;
}
#endif
@@ -558,14 +559,55 @@ out_eol:
static codecs_t *video_codecs=NULL;
static codecs_t *audio_codecs=NULL;
+static char *codec_strs = NULL;
+static unsigned codec_strs_len = 0;
static int nr_vcodecs = 0;
static int nr_acodecs = 0;
+const char *codec_idx2str(unsigned idx)
+{
+ if (idx >= codec_strs_len) return NULL;
+ if (idx > 0 && codec_strs[idx - 1]) return NULL;
+ return codec_strs + idx;
+}
+
+static unsigned codec_addstr(const char *s)
+{
+#ifdef CODECS2HTML
+ int i;
+#endif
+ int len;
+ char *newstr;
+ if (!s || !s[0]) return 0;
+ len = strlen(s) + 1;
+#ifdef CODECS2HTML
+ // try to de-duplicate
+ for (i = 1; i < codec_strs_len; ) {
+ int curlen = strlen(codec_strs + i) + 1;
+ if (len == curlen && !strcmp(s, codec_strs + i))
+ return i;
+ i += curlen;
+ }
+#endif
+ if (codec_strs_len) {
+ newstr = realloc(codec_strs, codec_strs_len + len);
+ } else {
+ codec_strs_len = 1;
+ newstr = calloc(1, 1 + len);
+ }
+ if (!newstr) return 0;
+ codec_strs = newstr;
+ memcpy(codec_strs + codec_strs_len, s, len);
+ codec_strs_len += len;
+ return codec_strs_len - len;
+}
+
int parse_codec_cfg(const char *cfgfile)
{
codecs_t *codec = NULL; // current codec
codecs_t **codecsp = NULL;// points to audio_codecs or to video_codecs
char *endptr; // strtoul()...
+ char *comment = NULL;
int *nr_codecsp;
int codec_type; /* TYPE_VIDEO/TYPE_AUDIO */
int tmp, i;
@@ -584,6 +626,8 @@ int parse_codec_cfg(const char *cfgfile)
audio_codecs = builtin_audio_codecs;
nr_vcodecs = sizeof(builtin_video_codecs)/sizeof(codecs_t);
nr_acodecs = sizeof(builtin_audio_codecs)/sizeof(codecs_t);
+ codec_strs = builtin_codec_strs;
+ codec_strs_len = sizeof(builtin_codec_strs);
return 1;
#endif
}
@@ -636,6 +680,9 @@ int parse_codec_cfg(const char *cfgfile)
continue;
if (!strcmp(token[0], "audiocodec") ||
!strcmp(token[0], "videocodec")) {
+ codec->comment_idx = codec_addstr(comment);
+ free(comment);
+ comment = NULL;
if (!validate_codec(codec, codec_type))
goto err_out_not_valid;
loop_enter:
@@ -668,27 +715,27 @@ int parse_codec_cfg(const char *cfgfile)
if (get_token(1, 1) < 0)
goto err_out_parse_error;
for (i = 0; i < *nr_codecsp - 1; i++) {
- if(( (*codecsp)[i].name!=NULL) &&
- (!strcmp(token[0], (*codecsp)[i].name)) ) {
+ if(( (*codecsp)[i].name_idx) &&
+ (!strcmp(token[0], codec_idx2str((*codecsp)[i].name_idx))) ) {
mp_msg(MSGT_CODECCFG,MSGL_ERR,MSGTR_CodecNameNotUnique, token[0]);
goto err_out_print_linenum;
}
}
- if (!(codec->name = strdup(token[0]))) {
+ if (!(codec->name_idx = codec_addstr(token[0]))) {
mp_msg(MSGT_CODECCFG,MSGL_ERR,MSGTR_CantStrdupName, strerror(errno));
goto err_out;
}
} else if (!strcmp(token[0], "info")) {
- if (codec->info || get_token(1, 1) < 0)
+ if (codec->info_idx || get_token(1, 1) < 0)
goto err_out_parse_error;
- if (!(codec->info = strdup(token[0]))) {
+ if (!(codec->info_idx = codec_addstr(token[0]))) {
mp_msg(MSGT_CODECCFG,MSGL_ERR,MSGTR_CantStrdupInfo, strerror(errno));
goto err_out;
}
} else if (!strcmp(token[0], "comment")) {
if (get_token(1, 1) < 0)
goto err_out_parse_error;
- add_comment(token[0], &codec->comment);
+ add_comment(token[0], &comment);
} else if (!strcmp(token[0], "fourcc")) {
if (get_token(1, 2) < 0)
goto err_out_parse_error;
@@ -705,14 +752,14 @@ int parse_codec_cfg(const char *cfgfile)
} else if (!strcmp(token[0], "driver")) {
if (get_token(1, 1) < 0)
goto err_out_parse_error;
- if (!(codec->drv = strdup(token[0]))) {
+ if (!(codec->drv_idx = codec_addstr(token[0]))) {
mp_msg(MSGT_CODECCFG,MSGL_ERR,MSGTR_CantStrdupDriver, strerror(errno));
goto err_out;
}
} else if (!strcmp(token[0], "dll")) {
if (get_token(1, 1) < 0)
goto err_out_parse_error;
- if (!(codec->dll = strdup(token[0]))) {
+ if (!(codec->dll_idx = codec_addstr(token[0]))) {
mp_msg(MSGT_CODECCFG,MSGL_ERR,MSGTR_CantStrdupDLL, strerror(errno));
goto err_out;
}
@@ -786,8 +833,8 @@ int parse_codec_cfg(const char *cfgfile)
if (!validate_codec(codec, codec_type))
goto err_out_not_valid;
mp_msg(MSGT_CODECCFG,MSGL_INFO,MSGTR_AudioVideoCodecTotals, nr_acodecs, nr_vcodecs);
- if(video_codecs) video_codecs[nr_vcodecs].name = NULL;
- if(audio_codecs) audio_codecs[nr_acodecs].name = NULL;
+ if(video_codecs) video_codecs[nr_vcodecs].name_idx = 0;
+ if(audio_codecs) audio_codecs[nr_acodecs].name_idx = 0;
out:
free(line);
line=NULL;
@@ -814,26 +861,14 @@ err_out_release_num:
goto err_out_print_linenum;
}
-static void codecs_free(codecs_t* codecs,int count) {
- int i;
- for ( i = 0; i < count; i++)
- if ( codecs[i].name ) {
- free(codecs[i].name);
- free(codecs[i].info);
- free(codecs[i].comment);
- free(codecs[i].dll);
- free(codecs[i].drv);
- }
- free(codecs);
-}
-
void codecs_uninit_free(void) {
- if (video_codecs)
- codecs_free(video_codecs,nr_vcodecs);
+ free(video_codecs);
video_codecs=NULL;
- if (audio_codecs)
- codecs_free(audio_codecs,nr_acodecs);
+ free(audio_codecs);
audio_codecs=NULL;
+ free(codec_strs);
+ codec_strs=NULL;
+ codec_strs_len = 0;
}
codecs_t *find_audio_codec(unsigned int fourcc, unsigned int *fourccmap,
@@ -941,16 +976,21 @@ void list_codecs(int audioflag){
case CODECS_STATUS_NOT_WORKING: s="crashing";break;
case CODECS_STATUS_UNTESTED: s="untested";break;
}
- if(c->dll)
- mp_msg(MSGT_CODECCFG,MSGL_INFO,"%-11s %-9s %s %s [%s]\n",c->name,c->drv,s,c->info,c->dll);
+ if(c->dll_idx)
+ mp_msg(MSGT_CODECCFG,MSGL_INFO,"%-11s %-9s %s %s [%s]\n",
+ codec_idx2str(c->name_idx),
+ codec_idx2str(c->drv_idx),s,codec_idx2str(c->info_idx),
+ codec_idx2str(c->dll_idx));
else
- mp_msg(MSGT_CODECCFG,MSGL_INFO,"%-11s %-9s %s %s\n",c->name,c->drv,s,c->info);
+ mp_msg(MSGT_CODECCFG,MSGL_INFO,"%-11s %-9s %s %s\n",
+ codec_idx2str(c->name_idx),
+ codec_idx2str(c->drv_idx),s,codec_idx2str(c->info_idx));
}
}
#ifdef CODECS2HTML
-static void wrapline(FILE *f2,char *s){
+static void wrapline(FILE *f2,const char *s){
int c;
if(!s){
fprintf(f2,"-");
@@ -974,15 +1014,15 @@ static void parsehtml(FILE *f1,FILE *f2,codecs_t *codec){
case '.':
return; // end of section
case 'n':
- wrapline(f2,codec->name); break;
+ wrapline(f2,codec_idx2str(codec->name_idx)); break;
case 'i':
- wrapline(f2,codec->info); break;
+ wrapline(f2,codec_idx2str(codec->info_idx)); break;
case 'c':
- wrapline(f2,codec->comment); break;
+ wrapline(f2,codec_idx2str(codec->comment_idx)); break;
case 'd':
- wrapline(f2,codec->dll); break;
+ wrapline(f2,codec_idx2str(codec->dll_idx)); break;
case 'D':
- fprintf(f2,"%c",!strcmp(codec->drv,"dshow")?'+':'-'); break;
+ fprintf(f2,"%c",!strcmp(codec_idx2str(codec->drv_idx),"dshow")?'+':'-'); break;
case 'F':
for(d=0;d<CODECS_MAX_FOURCC;d++)
if(!d || codec->fourcc[d]!=0xFFFFFFFF)
@@ -1042,12 +1082,6 @@ static void print_char_array(const unsigned char* a, int size)
printf(" }");
}
-static void print_string(const char* s)
-{
- if (!s) printf("NULL");
- else printf("\"%s\"", s);
-}
-
int main(int argc, char* argv[])
{
codecs_t *cl;
@@ -1112,11 +1146,10 @@ int main(int argc, char* argv[])
print_char_array(cod[i][j].inflags, CODECS_MAX_INFMT);
printf(", /* inflags */\n");
- print_string(cod[i][j].name); printf(", /* name */\n");
- print_string(cod[i][j].info); printf(", /* info */\n");
- print_string(cod[i][j].comment); printf(", /* comment */\n");
- print_string(cod[i][j].dll); printf(", /* dll */\n");
- print_string(cod[i][j].drv); printf(", /* drv */\n");
+ printf("%i, /* name */\n%i, /* info */\n"
+ "%i, /* comment */\n%i, /* dll */\n%i, /* drv */\n",
+ cod[i][j].name_idx, cod[i][j].info_idx,
+ cod[i][j].comment_idx, cod[i][j].dll_idx, cod[i][j].drv_idx);
printf("{ 0x%08lx, %hu, %hu,",
cod[i][j].guid.f1,
@@ -1132,6 +1165,9 @@ int main(int argc, char* argv[])
}
printf("};\n\n");
}
+ printf("const char builtin_codec_strs[] = ");
+ print_char_array(codec_strs, codec_strs_len);
+ printf(";\n");
exit(0);
}
@@ -1236,10 +1272,10 @@ next:
for(i=0;i<nr_codecs;i++, c++){
printf("\n============== %scodec %02d ===============\n",
state==0?"video":"audio",i);
- printf("name='%s'\n",c->name);
- printf("info='%s'\n",c->info);
- printf("comment='%s'\n",c->comment);
- printf("dll='%s'\n",c->dll);
+ printf("name='%s'\n",codec_idx2str(c->name_idx));
+ printf("info='%s'\n",codec_idx2str(c->info_idx));
+ printf("comment='%s'\n",codec_idx2str(c->comment_idx));
+ printf("dll='%s'\n",codec_idx2str(c->dll_idx));
/* printf("flags=%X driver=%d status=%d cpuflags=%d\n",
c->flags, c->driver, c->status, c->cpuflags); */
printf("flags=%X status=%d cpuflags=%d\n",
diff --git a/codec-cfg.h b/codec-cfg.h
index 14d836f..fbbf60d 100644
--- a/codec-cfg.h
+++ b/codec-cfg.h
@@ -65,11 +65,11 @@ typedef struct codecs {
unsigned char outflags[CODECS_MAX_OUTFMT];
unsigned int infmt[CODECS_MAX_INFMT];
unsigned char inflags[CODECS_MAX_INFMT];
- char *name;
- char *info;
- char *comment;
- char *dll;
- char* drv;
+ unsigned name_idx;
+ unsigned info_idx;
+ unsigned comment_idx;
+ unsigned dll_idx;
+ unsigned drv_idx;
GUID guid;
// short driver;
short flags;
@@ -86,6 +86,7 @@ codecs_t* find_codec(unsigned int fourcc, unsigned int *fourccmap,
codecs_t *start, int audioflag, int force);
void list_codecs(int audioflag);
void codecs_uninit_free(void);
+const char *codec_idx2str(unsigned idx);
typedef char ** stringset_t;
void stringset_init(stringset_t *set);
diff --git a/command.c b/command.c
index bd4dcd7..f5ae58e 100644
--- a/command.c
+++ b/command.c
@@ -787,7 +787,7 @@ static int mp_property_audio_codec(m_option_t *prop, int action,
{
if (!mpctx->sh_audio || !mpctx->sh_audio->codec)
return M_PROPERTY_UNAVAILABLE;
- return m_property_string_ro(prop, action, arg, mpctx->sh_audio->codec->name);
+ return m_property_string_ro(prop, action, arg, codec_idx2str(mpctx->sh_audio->codec->name_idx));
}
/// Audio bitrate (RO)
@@ -1373,7 +1373,7 @@ static int mp_property_video_codec(m_option_t *prop, int action,
{
if (!mpctx->sh_video || !mpctx->sh_video->codec)
return M_PROPERTY_UNAVAILABLE;
- return m_property_string_ro(prop, action, arg, mpctx->sh_video->codec->name);
+ return m_property_string_ro(prop, action, arg, codec_idx2str(mpctx->sh_video->codec->name_idx));
}
diff --git a/gui/interface.c b/gui/interface.c
index 3982f50..30a564f 100644
--- a/gui/interface.c
+++ b/gui/interface.c
@@ -869,7 +869,7 @@ int gui(int what, void *data)
nfree(guiInfo.CodecName);
if (guiInfo.sh_video)
- guiInfo.CodecName = strdup(guiInfo.sh_video->codec->name);
+ guiInfo.CodecName = strdup(codec_idx2str(guiInfo.sh_video->codec->name_idx));
state = (isSeekableStreamtype ? btnReleased : btnDisabled);
btnSet(evForward10sec, state);
diff --git a/libmpcodecs/ad_acm.c b/libmpcodecs/ad_acm.c
index 0d2cba8..cde8eac 100644
--- a/libmpcodecs/ad_acm.c
+++ b/libmpcodecs/ad_acm.c
@@ -96,7 +96,7 @@ static int preinit(sh_audio_t *sh_audio)
print_wave_header(priv->o_wf, MSGL_V);
}
- MSACM_RegisterDriver((const char *)sh_audio->codec->dll, in_fmt->wFormatTag, 0);
+ MSACM_RegisterDriver(codec_idx2str(sh_audio->codec->dll_idx), in_fmt->wFormatTag, 0);
ret = acmStreamOpen(&priv->handle, (HACMDRIVER)NULL, in_fmt,
priv->o_wf, NULL, 0, 0, 0);
if (ret)
diff --git a/libmpcodecs/ad_dmo.c b/libmpcodecs/ad_dmo.c
index 20bd6b7..8a3b8ce 100644
--- a/libmpcodecs/ad_dmo.c
+++ b/libmpcodecs/ad_dmo.c
@@ -51,9 +51,9 @@ static int preinit(sh_audio_t *sh_audio)
DMO_AudioDecoder* ds_adec;
int chans=(audio_output_channels==sh_audio->wf->nChannels) ?
audio_output_channels : (sh_audio->wf->nChannels>=2 ? 2 : 1);
- if(!(ds_adec=DMO_AudioDecoder_Open(sh_audio->codec->dll,&sh_audio->codec->guid,sh_audio->wf,chans)))
+ if(!(ds_adec=DMO_AudioDecoder_Open(codec_idx2str(sh_audio->codec->dll_idx),&sh_audio->codec->guid,sh_audio->wf,chans)))
{
- mp_msg(MSGT_DECAUDIO,MSGL_ERR,MSGTR_MissingDLLcodec,sh_audio->codec->dll);
+ mp_msg(MSGT_DECAUDIO,MSGL_ERR,MSGTR_MissingDLLcodec,codec_idx2str(sh_audio->codec->dll_idx));
return 0;
}
sh_audio->i_bps=sh_audio->wf->nAvgBytesPerSec;
diff --git a/libmpcodecs/ad_dshow.c b/libmpcodecs/ad_dshow.c
index e88ed0c..8c863c4 100644
--- a/libmpcodecs/ad_dshow.c
+++ b/libmpcodecs/ad_dshow.c
@@ -47,9 +47,9 @@ static int init(sh_audio_t *sh)
static int preinit(sh_audio_t *sh_audio)
{
DS_AudioDecoder* ds_adec;
- if(!(ds_adec=DS_AudioDecoder_Open(sh_audio->codec->dll,&sh_audio->codec->guid,sh_audio->wf)))
+ if(!(ds_adec=DS_AudioDecoder_Open(codec_idx2str(sh_audio->codec->dll_idx),&sh_audio->codec->guid,sh_audio->wf)))
{
- mp_msg(MSGT_DECAUDIO,MSGL_ERR,MSGTR_MissingDLLcodec,sh_audio->codec->dll);
+ mp_msg(MSGT_DECAUDIO,MSGL_ERR,MSGTR_MissingDLLcodec,codec_idx2str(sh_audio->codec->dll_idx));
return 0;
}
sh_audio->i_bps=sh_audio->wf->nAvgBytesPerSec;
diff --git a/libmpcodecs/ad_ffmpeg.c b/libmpcodecs/ad_ffmpeg.c
index 6def3bd..5f1acfd 100644
--- a/libmpcodecs/ad_ffmpeg.c
+++ b/libmpcodecs/ad_ffmpeg.c
@@ -106,9 +106,9 @@ static int init(sh_audio_t *sh_audio)
mp_msg(MSGT_DECAUDIO,MSGL_V,"FFmpeg's libavcodec audio codec\n");
init_avcodec();
- lavc_codec = avcodec_find_decoder_by_name(sh_audio->codec->dll);
+ lavc_codec = avcodec_find_decoder_by_name(codec_idx2str(sh_audio->codec->dll_idx));
if(!lavc_codec){
- mp_msg(MSGT_DECAUDIO,MSGL_ERR,MSGTR_MissingLAVCcodec,sh_audio->codec->dll);
+ mp_msg(MSGT_DECAUDIO,MSGL_ERR,MSGTR_MissingLAVCcodec,codec_idx2str(sh_audio->codec->dll_idx));
return 0;
}
diff --git a/libmpcodecs/ad_realaud.c b/libmpcodecs/ad_realaud.c
index 7716fbf..76186db 100644
--- a/libmpcodecs/ad_realaud.c
+++ b/libmpcodecs/ad_realaud.c
@@ -251,23 +251,24 @@ static int preinit(sh_audio_t *sh){
// let's check if the driver is available, return 0 if not.
// (you should do that if you use external lib(s) which is optional)
unsigned int result;
+ const char *dll = codec_idx2str(sh->codec->dll_idx);
char *path;
- path = malloc(strlen(codec_path) + strlen(sh->codec->dll) + 2);
+ path = malloc(strlen(codec_path) + strlen(dll) + 2);
if (!path) return 0;
- sprintf(path, "%s/%s", codec_path, sh->codec->dll);
+ sprintf(path, "%s/%s", codec_path, dll);
/* first try to load linux dlls, if failed and we're supporting win32 dlls,
then try to load the windows ones */
#ifdef HAVE_LIBDL
- if (strstr(sh->codec->dll,".dll") || !load_syms_linux(path))
+ if (strstr(dll,".dll") || !load_syms_linux(path))
#endif
#ifdef CONFIG_WIN32DLL
- if (!load_syms_windows(sh->codec->dll))
+ if (!load_syms_windows(dll))
#endif
{
- mp_msg(MSGT_DECVIDEO, MSGL_ERR, MSGTR_MissingDLLcodec, sh->codec->dll);
+ mp_msg(MSGT_DECVIDEO, MSGL_ERR, MSGTR_MissingDLLcodec, dll);
mp_msg(MSGT_DECVIDEO, MSGL_HINT, "Read the RealAudio section of the DOCS!\n");
free(path);
return 0;
diff --git a/libmpcodecs/ad_spdif.c b/libmpcodecs/ad_spdif.c
index 2198769..1fc237b 100644
--- a/libmpcodecs/ad_spdif.c
+++ b/libmpcodecs/ad_spdif.c
@@ -125,7 +125,7 @@ static int init(sh_audio_t *sh)
lavf_ctx->duration = AV_NOPTS_VALUE;
lavf_ctx->start_time = AV_NOPTS_VALUE;
for (i = 0; fmt_id_type[i].name; i++) {
- if (!strcmp(sh->codec->dll, fmt_id_type[i].name)) {
+ if (!strcmp(codec_idx2str(sh->codec->dll_idx), fmt_id_type[i].name)) {
lavf_ctx->streams[0]->codec->codec_id = fmt_id_type[i].id;
break;
}
diff --git a/libmpcodecs/ad_twin.c b/libmpcodecs/ad_twin.c
index 6bac93b..c2a3f50 100644
--- a/libmpcodecs/ad_twin.c
+++ b/libmpcodecs/ad_twin.c
@@ -182,7 +182,7 @@ int preinit(sh_audio_t *sh_audio)
vqf_priv_t *priv;
if(!(sh_audio->context=malloc(sizeof(vqf_priv_t)))) return 0;
priv=sh_audio->context;
- if(!load_dll(sh_audio->codec->dll))
+ if(!load_dll(codec_idx2str(sh_audio->codec->dll_idx)))
{
mp_msg(MSGT_DECAUDIO, MSGL_ERR, "win32.dll looks broken :(\n");
return 0;
@@ -191,7 +191,7 @@ int preinit(sh_audio_t *sh_audio)
mp_msg(MSGT_DECAUDIO, MSGL_ERR, "TWinVQ initialization fail\n");
return 0;
}
- mp_msg(MSGT_DECAUDIO, MSGL_INFO, "INFO: TWinVQ (%s) audio codec init OK!\n",sh_audio->codec->dll);
+ mp_msg(MSGT_DECAUDIO, MSGL_INFO, "INFO: TWinVQ (%s) audio codec init OK!\n",codec_idx2str(sh_audio->codec->dll_idx));
priv->skip_cnt = 2;
return 1;
}
diff --git a/libmpcodecs/dec_audio.c b/libmpcodecs/dec_audio.c
index 47a6833..476f47a 100644
--- a/libmpcodecs/dec_audio.c
+++ b/libmpcodecs/dec_audio.c
@@ -159,6 +159,7 @@ static int init_audio(sh_audio_t *sh_audio, char *codecname, char *afm,
}
sh_audio->codec = NULL;
while (1) {
+ const char *drv;
const ad_functions_t *mpadec;
int i;
sh_audio->ad_driver = 0;
@@ -169,22 +170,22 @@ static int init_audio(sh_audio_t *sh_audio, char *codecname, char *afm,
sh_audio->wf ? (&i) : NULL,
sh_audio->codec, force)))
break;
+ drv = codec_idx2str(sh_audio->codec->drv_idx);
if (sh_audio->wf)
sh_audio->wf->wFormatTag = i;
// ok we found one codec
- if (stringset_test(selected, sh_audio->codec->name))
+ if (stringset_test(selected, codec_idx2str(sh_audio->codec->name_idx)))
continue; // already tried & failed
- if (codecname && strcmp(sh_audio->codec->name, codecname))
+ if (codecname && strcmp(codec_idx2str(sh_audio->codec->name_idx), codecname))
continue; // -ac
- if (afm && strcmp(sh_audio->codec->drv, afm))
+ if (afm && strcmp(drv, afm))
continue; // afm doesn't match
if (!force && sh_audio->codec->status < status)
continue; // too unstable
- stringset_add(selected, sh_audio->codec->name); // tagging it
+ stringset_add(selected, codec_idx2str(sh_audio->codec->name_idx)); // 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,
- sh_audio->codec->drv))
+ if (!strcmp(mpcodecs_ad_drivers[i]->info->short_name, drv))
break;
mpadec = mpcodecs_ad_drivers[i];
#ifdef CONFIG_DYNAMIC_PLUGINS
@@ -196,37 +197,37 @@ static int init_audio(sh_audio_t *sh_audio, char *codecname, char *afm,
ad_info_t *info_sym;
buf_len =
- strlen(MPLAYER_LIBDIR) + strlen(sh_audio->codec->drv) + 16;
+ strlen(MPLAYER_LIBDIR) + strlen(drv) + 16;
buf = malloc(buf_len);
if (!buf)
break;
- snprintf(buf, buf_len, "%s/mplayer/ad_%s.so", MPLAYER_LIBDIR,
- sh_audio->codec->drv);
+ snprintf(buf, buf_len, "%s/mplayer/ad_%s.so", MPLAYER_LIBDIR, drv);
mp_msg(MSGT_DECAUDIO, MSGL_DBG2,
"Trying to open external plugin: %s\n", buf);
sh_audio->dec_handle = dlopen(buf, RTLD_LAZY);
if (!sh_audio->dec_handle)
break;
- snprintf(buf, buf_len, "mpcodecs_ad_%s", sh_audio->codec->drv);
+ snprintf(buf, buf_len, "mpcodecs_ad_%s", drv);
funcs_sym = dlsym(sh_audio->dec_handle, buf);
if (!funcs_sym || !funcs_sym->info || !funcs_sym->preinit
|| !funcs_sym->init || !funcs_sym->uninit
|| !funcs_sym->control || !funcs_sym->decode_audio)
break;
info_sym = funcs_sym->info;
- if (strcmp(info_sym->short_name, sh_audio->codec->drv))
+ if (strcmp(info_sym->short_name, drv))
break;
free(buf);
mpadec = funcs_sym;
mp_msg(MSGT_DECAUDIO, MSGL_V,
"Using external decoder plugin (%s/mplayer/ad_%s.so)!\n",
- MPLAYER_LIBDIR, sh_audio->codec->drv);
+ MPLAYER_LIBDIR, drv);
}
#endif
if (!mpadec) { // driver not available (==compiled in)
mp_msg(MSGT_DECAUDIO, MSGL_ERR,
MSGTR_AudioCodecFamilyNotAvailableStr,
- sh_audio->codec->name, sh_audio->codec->drv);
+ codec_idx2str(sh_audio->codec->name_idx),
+ codec_idx2str(sh_audio->codec->drv_idx));
continue;
}
/* only allow dummy codecs if specified via -ac */
@@ -305,7 +306,9 @@ int init_best_audio_codec(sh_audio_t *sh_audio, char **audio_codec_list,
}
mp_msg(MSGT_DECAUDIO, MSGL_INFO, MSGTR_SelectedAudioCodec,
- sh_audio->codec->name, sh_audio->codec->drv, sh_audio->codec->info);
+ codec_idx2str(sh_audio->codec->name_idx),
+ codec_idx2str(sh_audio->codec->drv_idx),
+ codec_idx2str(sh_audio->codec->info_idx));
return 1; // success
}
@@ -319,7 +322,7 @@ void uninit_audio(sh_audio_t *sh_audio)
}
if (sh_audio->initialized) {
mp_msg(MSGT_DECAUDIO, MSGL_V, "Uninit audio: %s\n",
- sh_audio->codec->drv);
+ codec_idx2str(sh_audio->codec->drv_idx));
sh_audio->ad_driver->uninit(sh_audio);
#ifdef CONFIG_DYNAMIC_PLUGINS
if (sh_audio->dec_handle)
diff --git a/libmpcodecs/dec_video.c b/libmpcodecs/dec_video.c
index c12a3b9..97a9ac2 100644
--- a/libmpcodecs/dec_video.c
+++ b/libmpcodecs/dec_video.c
@@ -175,7 +175,7 @@ void uninit_video(sh_video_t *sh_video)
{
if (!sh_video->initialized)
return;
- mp_msg(MSGT_DECVIDEO, MSGL_V, "Uninit video: %s\n", sh_video->codec->drv);
+ mp_msg(MSGT_DECVIDEO, MSGL_V, "Uninit video: %s\n", codec_idx2str(sh_video->codec->drv_idx));
mpvdec->uninit(sh_video);
mpvdec = NULL;
#ifdef CONFIG_DYNAMIC_PLUGINS
@@ -213,6 +213,7 @@ static int init_video(sh_video_t *sh_video, char *codecname, char *vfm,
}
while (1) {
+ const char *drv;
int i;
int orig_w, orig_h;
// restore original fourcc:
@@ -223,22 +224,22 @@ static int init_video(sh_video_t *sh_video, char *codecname, char *vfm,
sh_video->bih ? ((unsigned int *) &sh_video->bih->biCompression) : NULL,
sh_video->codec, force)))
break;
+ drv = codec_idx2str(sh_video->codec->drv_idx);
// ok we found one codec
- if (stringset_test(selected, sh_video->codec->name))
+ if (stringset_test(selected, codec_idx2str(sh_video->codec->name_idx)))
continue; // already tried & failed
- if (codecname && strcmp(sh_video->codec->name, codecname))
+ if (codecname && strcmp(codec_idx2str(sh_video->codec->name_idx), codecname))
continue; // -vc
- if (vfm && strcmp(sh_video->codec->drv, vfm))
+ if (vfm && strcmp(drv, vfm))
continue; // vfm doesn't match
if (!force && sh_video->codec->status < status)
continue; // too unstable
- stringset_add(selected, sh_video->codec->name); // tagging it
+ stringset_add(selected, codec_idx2str(sh_video->codec->name_idx)); // 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;
if (!strcmp
- (mpcodecs_vd_drivers[i]->info->short_name,
- sh_video->codec->drv))
+ (mpcodecs_vd_drivers[i]->info->short_name, drv))
break;
mpvdec = mpcodecs_vd_drivers[i];
#ifdef CONFIG_DYNAMIC_PLUGINS
@@ -250,37 +251,36 @@ static int init_video(sh_video_t *sh_video, char *codecname, char *vfm,
vd_info_t *info_sym;
buf_len = strlen(MPLAYER_LIBDIR) +
- strlen(sh_video->codec->drv) + 16;
+ strlen(drv) + 16;
buf = malloc(buf_len);
if (!buf)
break;
- snprintf(buf, buf_len, "%s/mplayer/vd_%s.so", MPLAYER_LIBDIR,
- sh_video->codec->drv);
+ snprintf(buf, buf_len, "%s/mplayer/vd_%s.so", MPLAYER_LIBDIR, drv);
mp_msg(MSGT_DECVIDEO, MSGL_DBG2,
"Trying to open external plugin: %s\n", buf);
sh_video->dec_handle = dlopen(buf, RTLD_LAZY);
if (!sh_video->dec_handle)
break;
- snprintf(buf, buf_len, "mpcodecs_vd_%s", sh_video->codec->drv);
+ snprintf(buf, buf_len, "mpcodecs_vd_%s", drv);
funcs_sym = dlsym(sh_video->dec_handle, buf);
if (!funcs_sym || !funcs_sym->info || !funcs_sym->init
|| !funcs_sym->uninit || !funcs_sym->control
|| !funcs_sym->decode)
break;
info_sym = funcs_sym->info;
- if (strcmp(info_sym->short_name, sh_video->codec->drv))
+ if (strcmp(info_sym->short_name, drv))
break;
free(buf);
mpvdec = funcs_sym;
mp_msg(MSGT_DECVIDEO, MSGL_V,
"Using external decoder plugin (%s/mplayer/vd_%s.so)!\n",
- MPLAYER_LIBDIR, sh_video->codec->drv);
+ MPLAYER_LIBDIR, drv);
}
#endif
if (!mpvdec) { // driver not available (==compiled in)
mp_msg(MSGT_DECVIDEO, MSGL_WARN,
MSGTR_VideoCodecFamilyNotAvailableStr,
- sh_video->codec->name, sh_video->codec->drv);
+ codec_idx2str(sh_video->codec->name_idx), drv);
continue;
}
/* only allow dummy codecs if specified via -vc */
@@ -381,7 +381,9 @@ int init_best_video_codec(sh_video_t *sh_video, char **video_codec_list,
}
mp_msg(MSGT_DECVIDEO, MSGL_INFO, MSGTR_SelectedVideoCodec,
- sh_video->codec->name, sh_video->codec->drv, sh_video->codec->info);
+ codec_idx2str(sh_video->codec->name_idx),
+ codec_idx2str(sh_video->codec->drv_idx),
+ codec_idx2str(sh_video->codec->info_idx));
return 1; // success
}
diff --git a/libmpcodecs/vd_dmo.c b/libmpcodecs/vd_dmo.c
index 0205713..94931fa 100644
--- a/libmpcodecs/vd_dmo.c
+++ b/libmpcodecs/vd_dmo.c
@@ -58,8 +58,8 @@ static int init(sh_video_t *sh){
unsigned int out_fmt=sh->codec->outfmt[0];
struct context *ctx;
void *decoder;
- if(!(decoder=DMO_VideoDecoder_Open(sh->codec->dll,&sh->codec->guid, sh->bih, 0, 0))){
- mp_msg(MSGT_DECVIDEO,MSGL_ERR,MSGTR_MissingDLLcodec,sh->codec->dll);
+ if(!(decoder=DMO_VideoDecoder_Open(codec_idx2str(sh->codec->dll_idx),&sh->codec->guid, sh->bih, 0, 0))){
+ mp_msg(MSGT_DECVIDEO,MSGL_ERR,MSGTR_MissingDLLcodec,codec_idx2str(sh->codec->dll_idx));
mp_msg(MSGT_DECVIDEO,MSGL_HINT,MSGTR_DownloadCodecPackage);
return 0;
}
diff --git a/libmpcodecs/vd_dshow.c b/libmpcodecs/vd_dshow.c
index 6ca8ca3..a4106d0 100644
--- a/libmpcodecs/vd_dshow.c
+++ b/libmpcodecs/vd_dshow.c
@@ -68,16 +68,17 @@ static int control(sh_video_t *sh,int cmd,void* arg,...){
// init driver
static int init(sh_video_t *sh){
unsigned int out_fmt=sh->codec->outfmt[0];
+ const char *dll = codec_idx2str(sh->codec->dll_idx);
/* Hack for VSSH codec: new dll can't decode old files
* In my samples old files have no extradata, so use that info
* to decide what dll should be used (here and in vd_vfw).
*/
- if (!strcmp(sh->codec->dll, "vsshdsd.dll") && (sh->bih->biSize == 40))
+ if (!strcmp(dll, "vsshdsd.dll") && (sh->bih->biSize == 40))
return 0;
- if(!(sh->context=DS_VideoDecoder_Open(sh->codec->dll,&sh->codec->guid, sh->bih, 0, 0))){
- mp_msg(MSGT_DECVIDEO,MSGL_ERR,MSGTR_MissingDLLcodec,sh->codec->dll);
+ if(!(sh->context=DS_VideoDecoder_Open(dll,&sh->codec->guid, sh->bih, 0, 0))){
+ mp_msg(MSGT_DECVIDEO,MSGL_ERR,MSGTR_MissingDLLcodec,dll);
mp_msg(MSGT_DECVIDEO,MSGL_HINT,MSGTR_DownloadCodecPackage);
return 0;
}
diff --git a/libmpcodecs/vd_ffmpeg.c b/libmpcodecs/vd_ffmpeg.c
index 6a5885d..af19291 100644
--- a/libmpcodecs/vd_ffmpeg.c
+++ b/libmpcodecs/vd_ffmpeg.c
@@ -336,9 +336,9 @@ static int init(sh_video_t *sh){
if (!ctx)
return 0;
- lavc_codec = avcodec_find_decoder_by_name(sh->codec->dll);
+ lavc_codec = avcodec_find_decoder_by_name(codec_idx2str(sh->codec->dll_idx));
if(!lavc_codec){
- mp_msg(MSGT_DECVIDEO, MSGL_ERR, MSGTR_MissingLAVCcodec, sh->codec->dll);
+ mp_msg(MSGT_DECVIDEO, MSGL_ERR, MSGTR_MissingLAVCcodec, codec_idx2str(sh->codec->dll_idx));
uninit(sh);
return 0;
}
diff --git a/libmpcodecs/vd_realvid.c b/libmpcodecs/vd_realvid.c
index e9bd0a0..669c24c 100644
--- a/libmpcodecs/vd_realvid.c
+++ b/libmpcodecs/vd_realvid.c
@@ -265,6 +265,7 @@ static int init(sh_video_t *sh){
unsigned char* extrahdr=(unsigned char*)(sh->bih+1);
unsigned int extrahdr_size = sh->bih->biSize - sizeof(*sh->bih);
struct rv_init_t init_data;
+ const char *dll = codec_idx2str(sh->codec->dll_idx);
if(extrahdr_size < 8) {
mp_msg(MSGT_DECVIDEO,MSGL_ERR,"realvideo: extradata too small (%u)\n", extrahdr_size);
@@ -274,20 +275,20 @@ static int init(sh_video_t *sh){
mp_msg(MSGT_DECVIDEO,MSGL_V,"realvideo codec id: 0x%08X sub-id: 0x%08X\n",init_data.format,init_data.subformat);
- path = malloc(strlen(codec_path) + strlen(sh->codec->dll) + 2);
+ path = malloc(strlen(codec_path) + strlen(dll) + 2);
if (!path) return 0;
- sprintf(path, "%s/%s", codec_path, sh->codec->dll);
+ sprintf(path, "%s/%s", codec_path, dll);
/* first try to load linux dlls, if failed and we're supporting win32 dlls,
then try to load the windows ones */
#ifdef HAVE_LIBDL
- if(strstr(sh->codec->dll,".dll") || !load_syms_linux(path))
+ if(strstr(dll,".dll") || !load_syms_linux(path))
#endif
#ifdef CONFIG_WIN32DLL
- if (!load_syms_windows(sh->codec->dll))
+ if (!load_syms_windows(dll))
#endif
{
- mp_msg(MSGT_DECVIDEO,MSGL_ERR,MSGTR_MissingDLLcodec,sh->codec->dll);
+ mp_msg(MSGT_DECVIDEO,MSGL_ERR,MSGTR_MissingDLLcodec,dll);
mp_msg(MSGT_DECVIDEO,MSGL_HINT,"Read the RealVideo section of the DOCS!\n");
free(path);
return 0;
diff --git a/libmpcodecs/vd_vfw.c b/libmpcodecs/vd_vfw.c
index 23fc490..a513f82 100644
--- a/libmpcodecs/vd_vfw.c
+++ b/libmpcodecs/vd_vfw.c
@@ -157,12 +157,13 @@ static int init(sh_video_t *sh){
// unsigned int outfmt=sh->codec->outfmt[sh->outfmtidx];
int i, o_bih_len;
vd_vfw_ctx *priv;
+ const char *dll = codec_idx2str(sh->codec->dll_idx);
/* Hack for VSSH codec: new dll can't decode old files
* In my samples old files have no extradata, so use that info
* to decide what dll should be used (here and in vd_dshow).
*/
- if (!strcmp(sh->codec->dll, "vssh264.dll") && (sh->bih->biSize > 40))
+ if (!strcmp(dll, "vssh264.dll") && (sh->bih->biSize > 40))
return 0;
priv = malloc(sizeof(vd_vfw_ctx));
@@ -174,10 +175,10 @@ static int init(sh_video_t *sh){
mp_msg(MSGT_WIN32,MSGL_V,"======= Win32 (VFW) VIDEO Codec init =======\n");
-// win32_codec_name = sh->codec->dll;
+// win32_codec_name = dll;
// sh->hic = ICOpen( 0x63646976, sh->bih->biCompression, ICMODE_FASTDECOMPRESS);
// priv->handle = ICOpen( 0x63646976, sh->bih->biCompression, ICMODE_DECOMPRESS);
- priv->handle = ICOpen( (long)(sh->codec->dll), sh->bih->biCompression, ICMODE_DECOMPRESS);
+ priv->handle = ICOpen( (long)(dll), sh->bih->biCompression, ICMODE_DECOMPRESS);
if(!priv->handle){
mp_msg(MSGT_WIN32,MSGL_ERR,"ICOpen failed! unknown codec / wrong parameters?\n");
return 0;
diff --git a/libmpcodecs/vd_xanim.c b/libmpcodecs/vd_xanim.c
index a26e5a5..61a29cf 100644
--- a/libmpcodecs/vd_xanim.c
+++ b/libmpcodecs/vd_xanim.c
@@ -698,13 +698,13 @@ static int init(sh_video_t *sh)
for (i=0; i < XA_CLOSE_FUNCS; i++)
xa_close_func[i] = NULL;
- snprintf(dll, 1024, "%s/%s", codec_path, sh->codec->dll);
+ snprintf(dll, 1024, "%s/%s", codec_path, codec_idx2str(sh->codec->dll_idx));
if (xacodec_load(sh, dll) == 0)
return 0;
codec_hdr.xapi_rev = XAVID_API_REV;
codec_hdr.anim_hdr = malloc(4096);
- codec_hdr.description = sh->codec->info;
+ codec_hdr.description = codec_idx2str(sh->codec->info_idx);
codec_hdr.compression = bswap_32(sh->bih->biCompression);
codec_hdr.decoder = NULL;
codec_hdr.x = sh->bih->biWidth; /* ->disp_w */
diff --git a/mplayer.c b/mplayer.c
index aa5ca33..7310026 100644
--- a/mplayer.c
+++ b/mplayer.c
@@ -467,8 +467,8 @@ char *get_metadata(metadata_t type)
return mp_asprintf("%d x %d", sh_video->disp_w, sh_video->disp_h);
case META_AUDIO_CODEC:
- if (sh_audio->codec && sh_audio->codec->name)
- return strdup(sh_audio->codec->name);
+ if (sh_audio->codec && sh_audio->codec->name_idx)
+ return strdup(codec_idx2str(sh_audio->codec->name_idx));
break;
case META_AUDIO_BITRATE:
@@ -2419,7 +2419,7 @@ int reinit_video_chain(void)
initialized_flags |= INITIALIZED_VCODEC;
if (sh_video->codec)
- mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_VIDEO_CODEC=%s\n", sh_video->codec->name);
+ mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_VIDEO_CODEC=%s\n", codec_idx2str(sh_video->codec->name_idx));
sh_video->last_pts = MP_NOPTS_VALUE;
sh_video->num_buffered_pts = 0;
@@ -3660,7 +3660,7 @@ goto_enable_cache:
if (mpctx->sh_audio) {
reinit_audio_chain();
if (mpctx->sh_audio && mpctx->sh_audio->codec)
- mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_AUDIO_CODEC=%s\n", mpctx->sh_audio->codec->name);
+ mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_AUDIO_CODEC=%s\n", codec_idx2str(mpctx->sh_audio->codec->name_idx));
if (mpctx->audio_out)
mpctx->audio_out->control(AOCONTROL_FILENAME, (void *)(vo_wintitle ? vo_wintitle : mp_basename(filename)));
}
--
2.7.0
More information about the MPlayer-dev-eng
mailing list