Beispiel #1
0
BOOL SCALE::InitScaleParam (HWND hwnd)
{
	char buffer[OBJECTNAMESIZE] ;

	AObjGetName(oiScale, buffer, OBJECTNAMESIZE) ;
	SetWindowText(hwnd, buffer) ;
	AUtlSetTitleFont(OTYPE_SCAL, NULL, GetDlgItem(hwnd, IDD_OBJECT));
	AUtlCenterDialog(hwnd, 0);

	GetBitmapHandle () ;
	mousedown = FALSE ;
	nVscrollPos = nHscrollPos = 0 ;
	nVfirstPixel = 0 ;
	nHfirstPixel = 0 ;

	SetScaleParam(hwnd) ;
	CreateLayoutWindow (hwnd) ;
	return FALSE ;
}
int OpenFile(const char* filename)
{
	InitDriver();

	int ret = CreateOcxByFile(filename);

	if(ret != ENERR)
	{
		printf("Open Stream fail\n");
		return ret;
	}

	int pix = Manager.avParams.pixFormat;
	int w = Manager.avParams.width;
	int h = Manager.avParams.height;

	CallBack callfun = Manager.avParams.callFunc;
	void *arg = Manager.avParams.arg;

	memset(&Manager,0,sizeof(AvManager));
	
	SetPlayParams(pix,w,h,callfun,arg);

	pix = Manager.avParams.pixFormat;
	w = Manager.avParams.width;
	h = Manager.avParams.height;

	printf("pix=%d,w=%d,h=%d\n",pix,w,h);

	if(Manager.avParams.arg)
		printf("Have some parameters\n");

	if(Manager.avParams.callFunc)
		printf("Have som function!\n");

	InitScaleEngine();

	int audio = IsExistAuido();
	int video = IsExistVideo();

	Manager.playAudio = audio;
	Manager.playVideo = video;

	Manager.playerClock = 0;

	if(audio)
	{
		printf("Set Audio Params!\n");
		Manager.ap = GetOcxAudioParam();
		InitWaveEngine(Manager.ap.m_bAudioFreq,Manager.ap.m_bAudioFormat,Manager.ap.m_bAudioChannel);
		Manager.audioBasePara = 2*Manager.ap.m_bAudioFreq*Manager.ap.m_bAudioChannel;
		Manager.audioTimeBase = GetTimeBase(AUDIO);
	}

	if(video)
	{
		printf("Set video params!\n");
		Manager.vp = GetOcxVideoParam();
		SetScaleParam(PIX_FMT_YUV420P,Manager.vp.m_bVideoWidth,Manager.vp.m_bVideoHeight,pix,w,h);
		if(Manager.vp.m_bVideoFrameRate > 0 && Manager.vp.m_bVideoFrameRate <= 100)
			Manager.delayWithoutAudioTime = (1.0/Manager.vp.m_bVideoFrameRate);
		else
		{
			Manager.vp.m_bVideoFrameRate = 25;
			Manager.delayWithoutAudioTime = (1.0/25);
		}

		Manager.videoTimeBase = GetTimeBase(VIDEO);

		printf("Delay frame per time = %f,frame/per = %d\n",Manager.delayWithoutAudioTime,Manager.vp.m_bVideoFrameRate);
	}

	Manager.duration = GetDuration();

	printf("Duration = %f\n",Manager.duration);

	Manager.avCommand = NONE_CMD;
	Manager.avState = PLAY;
	Manager.ManagerOver = FALSE;
	Manager.autoEnd = FALSE;
	Manager.avPos = 0;
	Manager.avSeek = FALSE;
	Manager.masterClkByAV = NONE;
	Manager.delay_timer = (double)GetTimeHere()/AV_TIME_BASE;
	Manager.last_delay = 40e-3;
	Manager.last_pts = 0;

	Manager.managerEnd = FALSE;

	Manager.audioClock = 0;
	Manager.videoClock = 0;

	if(Manager.playAudio)
	{
		
		Manager.MediaAudio = InitQueueBuffer();
	
		if(!Manager.MediaAudio)
			return EALLOC;

		pthread_create(&Manager.renderAudio,NULL,&RenderAudio,&Manager);

		if(!Manager.renderAudio)
		{
			printf("Can not create render audio thread!\n");
			return EALLOC;
		}
	}

	if(Manager.playVideo)
	{

		Manager.MediaVideo = InitQueueBuffer();
	
		if(!Manager.MediaVideo)
			return EALLOC;

		Manager.MediaPicture = InitQueueBuffer();

		if(!Manager.MediaPicture)
			return EALLOC;

		pthread_create(&Manager.synProcess,NULL,&SynProcess,&Manager);

		if(!Manager.synProcess)
		{
			printf("Start syn thread error!\n");
			return EALLOC;
		}

		usSleep(20);

		pthread_create(&Manager.renderVideo,NULL,&RenderVideo,&Manager);

		if(!Manager.renderVideo)
		{
			printf("Can not create render video thread!\n");
			return EALLOC;
		}
	}

	pthread_create(&Manager.readAvEngine,NULL,&ReadAvData,&Manager);

	if(!Manager.readAvEngine)
	{
		printf("Can not create read thread!\n");
		return EALLOC;
	}

	Manager.already = TRUE;

	return ENERR;
}