Exemplo n.º 1
0
static int init_audio(sh_audio_t *sh_audio, char *codecname, char *afm,
		      int status, stringset_t *selected)
{
    unsigned int orig_fourcc = sh_audio->wf ? sh_audio->wf->wFormatTag : 0;
    int force = 0;
    if (codecname && codecname[0] == '+') {
	codecname = &codecname[1];
	force = 1;
    }
    sh_audio->codec = NULL;
    while (1) {
	const ad_functions_t *mpadec;
	int i;
	sh_audio->ad_driver = 0;
	// restore original fourcc:
	if (sh_audio->wf)
	    sh_audio->wf->wFormatTag = i = orig_fourcc;
	if (!(sh_audio->codec = find_audio_codec(sh_audio->format,
						 sh_audio->wf ? (&i) : NULL,
						 sh_audio->codec, force)))
	    break;
	if (sh_audio->wf)
	    sh_audio->wf->wFormatTag = i;
	// ok we found one codec
	if (stringset_test(selected, sh_audio->codec->name))
	    continue;	// already tried & failed
	if (codecname && strcmp(sh_audio->codec->name, codecname))
	    continue;	// -ac
	if (afm && strcmp(sh_audio->codec->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
	// 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))
		break;
	mpadec = mpcodecs_ad_drivers[i];
#ifdef CONFIG_DYNAMIC_PLUGINS
	if (!mpadec) {
	    /* try to open shared decoder plugin */
	    int buf_len;
	    char *buf;
	    ad_functions_t *funcs_sym;
	    ad_info_t *info_sym;

	    buf_len =
		strlen(MPLAYER_LIBDIR) + strlen(sh_audio->codec->drv) + 16;
	    buf = malloc(buf_len);
	    if (!buf)
		break;
	    snprintf(buf, buf_len, "%s/mplayer/ad_%s.so", MPLAYER_LIBDIR,
		     sh_audio->codec->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);
	    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))
		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);
	}
#endif
	if (!mpadec) {		// driver not available (==compiled in)
	    mp_tmsg(MSGT_DECAUDIO, MSGL_ERR,
		   "Requested audio codec family [%s] (afm=%s) not available.\nEnable it at compilation.\n",
		   sh_audio->codec->name, sh_audio->codec->drv);
	    continue;
	}
	// it's available, let's try to init!
	// init()
	mp_tmsg(MSGT_DECAUDIO, MSGL_INFO, "Opening audio decoder: [%s] %s\n",
	       mpadec->info->short_name, mpadec->info->name);
	sh_audio->ad_driver = mpadec;
	if (!init_audio_codec(sh_audio)) {
	    mp_tmsg(MSGT_DECAUDIO, MSGL_WARN,
                    "Could not open audio decoder %s.\n",
                    mpadec->info->short_name);
	    continue;		// try next...
	}
	// Yeah! We got it!
	return 1;
    }
    return 0;
}
Exemplo n.º 2
0
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;
    sh_video->vf_initialized=0;
    if (codecname && codecname[0] == '+') {
      codecname = &codecname[1];
      force = 1;
    }

    while(1){
	int i;
	int orig_w, orig_h;
	// restore original fourcc:
	if(sh_video->bih) sh_video->bih->biCompression=orig_fourcc;
	if(!(sh_video->codec=find_video_codec(sh_video->format,
          sh_video->bih?((unsigned int*) &sh_video->bih->biCompression):NULL,
          sh_video->codec,force) )) break;
	// ok we found one codec
	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
	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;
	    if(!strcmp(mpcodecs_vd_drivers[i]->info->short_name,sh_video->codec->drv)) break;
	mpvdec=mpcodecs_vd_drivers[i];
#ifdef CONFIG_DYNAMIC_PLUGINS
	if (!mpvdec)
	{
	    /* try to open shared decoder plugin */
	    int buf_len;
	    char *buf;
	    vd_functions_t *funcs_sym;
	    vd_info_t *info_sym;

	    buf_len = strlen(MPLAYER_LIBDIR)+strlen(sh_video->codec->drv)+16;
	    buf = malloc(buf_len);
	    if (!buf)
		break;
	    snprintf(buf, buf_len, "%s/mplayer/vd_%s.so", MPLAYER_LIBDIR, sh_video->codec->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);
	    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))
		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);
	}
#endif
	if(!mpvdec){ // driver not available (==compiled in)
	    mp_msg(MSGT_DECVIDEO,MSGL_WARN,MSGTR_VideoCodecFamilyNotAvailableStr,
		sh_video->codec->name, sh_video->codec->drv);
	    continue;
	}
	orig_w = sh_video->bih ? sh_video->bih->biWidth : sh_video->disp_w;
	orig_h = sh_video->bih ? sh_video->bih->biHeight : sh_video->disp_h;
	sh_video->disp_w = orig_w;
	sh_video->disp_h = orig_h;
	// it's available, let's try to init!
	if(sh_video->codec->flags & CODECS_FLAG_ALIGN16){
	    // align width/height to n*16
		sh_video->disp_w=(sh_video->disp_w+15)&(~15);
		sh_video->disp_h=(sh_video->disp_h+15)&(~15);
	}
	if (sh_video->bih) {
		sh_video->bih->biWidth = sh_video->disp_w;
		sh_video->bih->biHeight = sh_video->disp_h;
	}
	// init()
	mp_msg(MSGT_DECVIDEO,MSGL_INFO,MSGTR_OpeningVideoDecoder,mpvdec->info->short_name,mpvdec->info->name);
	// clear vf init error, it is no longer relevant
	if (sh_video->vf_initialized < 0)
		sh_video->vf_initialized = 0;
	if(!mpvdec->init(sh_video)){
	    mp_msg(MSGT_DECVIDEO,MSGL_INFO,MSGTR_VDecoderInitFailed);
	    sh_video->disp_w=orig_w;
	    sh_video->disp_h=orig_h;
	    if (sh_video->bih) {
		sh_video->bih->biWidth = sh_video->disp_w;
		sh_video->bih->biHeight = sh_video->disp_h;
	    }
	    continue; // try next...
	}
	// Yeah! We got it!
	sh_video->initialized=1;
	return 1;
    }
    return 0;
}