comparison libmpcodecs/dec_video.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 054ec3ddc5e1
children afa125da85cf
comparison
equal deleted inserted replaced
25660:3993c96eaa95 25661:293aeec83153
173 mpcodecs_vd_drivers[i]->info->short_name, 173 mpcodecs_vd_drivers[i]->info->short_name,
174 mpcodecs_vd_drivers[i]->info->name, 174 mpcodecs_vd_drivers[i]->info->name,
175 mpcodecs_vd_drivers[i]->info->comment); 175 mpcodecs_vd_drivers[i]->info->comment);
176 } 176 }
177 177
178 static int init_video(sh_video_t *sh_video,char* codecname,char* vfm,int status){ 178 static int init_video(sh_video_t *sh_video,char* codecname,char* vfm,int status,
179 stringset_t *selected){
179 int force = 0; 180 int force = 0;
180 unsigned int orig_fourcc=sh_video->bih?sh_video->bih->biCompression:0; 181 unsigned int orig_fourcc=sh_video->bih?sh_video->bih->biCompression:0;
181 sh_video->codec=NULL; 182 sh_video->codec=NULL;
182 sh_video->vf_inited=0; 183 sh_video->vf_inited=0;
183 if (codecname && codecname[0] == '+') { 184 if (codecname && codecname[0] == '+') {
192 if(sh_video->bih) sh_video->bih->biCompression=orig_fourcc; 193 if(sh_video->bih) sh_video->bih->biCompression=orig_fourcc;
193 if(!(sh_video->codec=find_video_codec(sh_video->format, 194 if(!(sh_video->codec=find_video_codec(sh_video->format,
194 sh_video->bih?((unsigned int*) &sh_video->bih->biCompression):NULL, 195 sh_video->bih?((unsigned int*) &sh_video->bih->biCompression):NULL,
195 sh_video->codec,force) )) break; 196 sh_video->codec,force) )) break;
196 // ok we found one codec 197 // ok we found one codec
197 if(sh_video->codec->flags&CODECS_FLAG_SELECTED) continue; // already tried & failed 198 if(stringset_test(selected, sh_video->codec->name)) continue; // already tried & failed
198 if(codecname && strcmp(sh_video->codec->name,codecname)) continue; // -vc 199 if(codecname && strcmp(sh_video->codec->name,codecname)) continue; // -vc
199 if(vfm && strcmp(sh_video->codec->drv,vfm)) continue; // vfm doesn't match 200 if(vfm && strcmp(sh_video->codec->drv,vfm)) continue; // vfm doesn't match
200 if(!force && sh_video->codec->status<status) continue; // too unstable 201 if(!force && sh_video->codec->status<status) continue; // too unstable
201 sh_video->codec->flags|=CODECS_FLAG_SELECTED; // tagging it 202 stringset_add(selected, sh_video->codec->name); // tagging it
202 // ok, it matches all rules, let's find the driver! 203 // ok, it matches all rules, let's find the driver!
203 for (i=0; mpcodecs_vd_drivers[i] != NULL; i++) 204 for (i=0; mpcodecs_vd_drivers[i] != NULL; i++)
204 // if(mpcodecs_vd_drivers[i]->info->id==sh_video->codec->driver) break; 205 // if(mpcodecs_vd_drivers[i]->info->id==sh_video->codec->driver) break;
205 if(!strcmp(mpcodecs_vd_drivers[i]->info->short_name,sh_video->codec->drv)) break; 206 if(!strcmp(mpcodecs_vd_drivers[i]->info->short_name,sh_video->codec->drv)) break;
206 mpvdec=mpcodecs_vd_drivers[i]; 207 mpvdec=mpcodecs_vd_drivers[i];
277 return 0; 278 return 0;
278 } 279 }
279 280
280 int init_best_video_codec(sh_video_t *sh_video,char** video_codec_list,char** video_fm_list){ 281 int init_best_video_codec(sh_video_t *sh_video,char** video_codec_list,char** video_fm_list){
281 char* vc_l_default[2]={"",(char*)NULL}; 282 char* vc_l_default[2]={"",(char*)NULL};
283 stringset_t selected;
282 // hack: 284 // hack:
283 if(!video_codec_list) video_codec_list=vc_l_default; 285 if(!video_codec_list) video_codec_list=vc_l_default;
284 // Go through the codec.conf and find the best codec... 286 // Go through the codec.conf and find the best codec...
285 sh_video->inited=0; 287 sh_video->inited=0;
286 codecs_reset_selection(0); 288 stringset_init(&selected);
287 while(!sh_video->inited && *video_codec_list){ 289 while(!sh_video->inited && *video_codec_list){
288 char* video_codec=*(video_codec_list++); 290 char* video_codec=*(video_codec_list++);
289 if(video_codec[0]){ 291 if(video_codec[0]){
290 if(video_codec[0]=='-'){ 292 if(video_codec[0]=='-'){
291 // disable this codec: 293 // disable this codec:
292 select_codec(video_codec+1,0); 294 stringset_add(&selected, video_codec+1);
293 } else { 295 } else {
294 // forced codec by name: 296 // forced codec by name:
295 mp_msg(MSGT_DECVIDEO,MSGL_INFO,MSGTR_ForcedVideoCodec,video_codec); 297 mp_msg(MSGT_DECVIDEO,MSGL_INFO,MSGTR_ForcedVideoCodec,video_codec);
296 init_video(sh_video,video_codec,NULL,-1); 298 init_video(sh_video,video_codec,NULL,-1, &selected);
297 } 299 }
298 } else { 300 } else {
299 int status; 301 int status;
300 // try in stability order: UNTESTED, WORKING, BUGGY. never try CRASHING. 302 // try in stability order: UNTESTED, WORKING, BUGGY. never try CRASHING.
301 if(video_fm_list){ 303 if(video_fm_list){
303 // try first the preferred codec families: 305 // try first the preferred codec families:
304 while(!sh_video->inited && *fmlist){ 306 while(!sh_video->inited && *fmlist){
305 char* video_fm=*(fmlist++); 307 char* video_fm=*(fmlist++);
306 mp_msg(MSGT_DECVIDEO,MSGL_INFO,MSGTR_TryForceVideoFmtStr,video_fm); 308 mp_msg(MSGT_DECVIDEO,MSGL_INFO,MSGTR_TryForceVideoFmtStr,video_fm);
307 for(status=CODECS_STATUS__MAX;status>=CODECS_STATUS__MIN;--status) 309 for(status=CODECS_STATUS__MAX;status>=CODECS_STATUS__MIN;--status)
308 if(init_video(sh_video,NULL,video_fm,status)) break; 310 if(init_video(sh_video,NULL,video_fm,status, &selected)) break;
309 } 311 }
310 } 312 }
311 if(!sh_video->inited) 313 if(!sh_video->inited)
312 for(status=CODECS_STATUS__MAX;status>=CODECS_STATUS__MIN;--status) 314 for(status=CODECS_STATUS__MAX;status>=CODECS_STATUS__MIN;--status)
313 if(init_video(sh_video,NULL,NULL,status)) break; 315 if(init_video(sh_video,NULL,NULL,status, &selected)) break;
314 } 316 }
315 } 317 }
318 stringset_free(&selected);
316 319
317 if(!sh_video->inited){ 320 if(!sh_video->inited){
318 mp_msg(MSGT_DECVIDEO,MSGL_ERR,MSGTR_CantFindVideoCodec,sh_video->format); 321 mp_msg(MSGT_DECVIDEO,MSGL_ERR,MSGTR_CantFindVideoCodec,sh_video->format);
319 mp_msg(MSGT_DECAUDIO,MSGL_HINT, MSGTR_RTFMCodecs); 322 mp_msg(MSGT_DECAUDIO,MSGL_HINT, MSGTR_RTFMCodecs);
320 return 0; // failed 323 return 0; // failed