コード例 #1
0
ファイル: LaunchBrowser.cpp プロジェクト: MOURAD24/SearchClip
void LaunchBrowser()
{
	wstring clip;
	if(GetClipboardAsString(clip))
	{
		clip = trim(clip);

		if(!IsURL(clip))
		{
			clip = Replace(SearchEngine::GetCurrent().FormatString(), TEXT("${CLIP}"), clip);
		}

		clip = URLSanitize(clip);

		STARTUPINFO startupInfo = { 0 };
		PROCESS_INFORMATION processInformation = { 0 };

		startupInfo.cb = sizeof(startupInfo);
		startupInfo.wShowWindow = SW_SHOWMAXIMIZED;
		startupInfo.dwFlags = STARTF_USESHOWWINDOW;

		WCHAR commandLine[16384];
		wcscpy_s(commandLine, (Browser::GetCurrent().ExecutableFilename() + TEXT(" ") + Browser::GetCurrent().CommandLine() + TEXT(" ") + clip).c_str());

		CreateProcess(NULL, commandLine, NULL, NULL, FALSE, 0L, NULL, NULL, &startupInfo, &processInformation);
	}
}
コード例 #2
0
ファイル: postproc.cpp プロジェクト: rauls/iReporter
short CopyFileTo( char *src,char *dest )
{
	if ( !IsURL( dest ) ){
#if DEF_WINDOWS
		return CopyFile( src, dest, 0 );
#endif
	}
	return 0;
}
コード例 #3
0
ファイル: log_io.cpp プロジェクト: rauls/iReporter
long LogOpenQuiet( char *filename, __int64 *filelen )
{
	char	rawfileName[256];
	long	hnd = 0;

	DateFixFilename( filename, rawfileName );

	// Check if we trying to open a shortcut
	if ( IsShortCut( rawfileName ) ){
		char linkpath[256];
		mystrcpy( linkpath, rawfileName );
#if DEF_WINDOWS
		GetShortCut( linkpath, rawfileName );
#endif
	}

	// Now see if the we want to open a short cut to a URL
	if ( IsURLShortCut( rawfileName ) ){
		char linkpath[256];
		mystrcpy( linkpath, rawfileName );
#if DEF_WINDOWS
		GetURLShortCut( linkpath, rawfileName );
#endif
	}

	// Check for a just a plain URL
	if ( IsURL( rawfileName ) ){
		StatusSetID( IDS_REMOTELOG , strrchr( rawfileName,'/' ) );
		hnd = (long)INetOpen( rawfileName, filelen );
		return hnd;
	}

	// Check other types
	char format[100];
	// determine if its PKZIP file and if so... dont open it, YET
	if ( IsFileInvalid( rawfileName, format ) )
		return 0;

#ifndef DEF_MAC
	if ( IsPKZIP( rawfileName ) )
		hnd = (long)UnzipOpen( rawfileName, NULL );
	else
#ifdef _BZLIB_H
	if ( aIsBzFile( rawfileName ) )		// PLEASE DO THIS SOON FOR MAC.... at least for manual completeness, hey OSX people will love it.
		hnd = (long)BZ2_bzopen( rawfileName, "rb" );
	else 
#endif
#endif
	{
		hnd = (long)gzopen( rawfileName, "rb" );
	}

	if ( filelen && hnd )
		*filelen = GetFileLength( rawfileName );

	return hnd;
}
コード例 #4
0
bool CAVPlayer::Play(const std::string &strPath)
{
    if (! m_pVLC_Inst)
    {// 如果播放引擎没有创建,则创建它
        Init();
    }

    if(strPath.empty() || ! m_pVLC_Inst)
    {// 如果链接地址为空,或播放引擎没创建,则直接返回
        return false;
    }

    // 验证地址是网络地址,还是本地地址
    bool bURL = false;
	bURL = IsURL(strPath);

    Stop();

    bool bRet = false;
    libvlc_media_t *m = NULL;

    if (bURL)
    {// 网络路径
        m = libvlc_media_new_location(m_pVLC_Inst, strPath.c_str());
    } 
    else
    {// 本地路径
        m = libvlc_media_new_path(m_pVLC_Inst, strPath.c_str());
    }

    if (m)
    {
        if (m_pVLC_Player = libvlc_media_player_new_from_media(m))
        {
            libvlc_media_player_set_hwnd(m_pVLC_Player, m_hWnd);
            libvlc_media_player_play(m_pVLC_Player);
			m_bStatus = em_play;//播放状态
            // 事件管理
            libvlc_event_manager_t *vlc_evt_man = libvlc_media_player_event_manager(m_pVLC_Player);
            libvlc_event_attach(vlc_evt_man, libvlc_MediaPlayerPlaying,CAVPlayer::OnVLC_Event, this);
            libvlc_event_attach(vlc_evt_man, libvlc_MediaPlayerPositionChanged, CAVPlayer::OnVLC_Event, this);
            libvlc_event_attach(vlc_evt_man, libvlc_MediaPlayerEndReached, CAVPlayer::OnVLC_Event, this);
            bRet = true;
        }

        libvlc_media_release(m);
    }

    return bRet;
}
コード例 #5
0
ファイル: postproc.cpp プロジェクト: rauls/iReporter
int UploadFiles( void *fs, char *dest, char *sourcepath, char *ftppath, int deletesourcefiles )
{
	long	sourcepathlen;
	LLStructRecPtr next;
	long	count=0, filenum, perc, ret;

	next = gFopenHistoryPtr;
	sourcepathlen = strlen( sourcepath );

	filenum = LListGetTotal( gFopenHistoryPtr );

	while( next && !IsStopped() && fs )
	{
		perc = ((100*count)/filenum);
		StatusWindowSetProgress( perc, NULL );
	
		if ( IsURL( dest ) ){
			char remoteFullPath[512], localPath[512], *fileName;

			fileName = (char*)next->data + sourcepathlen;
			sprintf( remoteFullPath, "%s%s", ftppath, fileName );
			mystrcpy( localPath, (char*)next->data );

			ret = FtpFileUpload( fs, localPath, remoteFullPath, fileName );
			switch( ret )
			{
				case FTPERR_NOFILE:
					ErrorMsg( "Cannot open local file ...\n%s", localPath );
					return -1;
				case FTPERR_STOPPED:
					return -1;
				case FTPERR_CANTMAKEDIR:
					if ( CautionMsg( "Could not make directory %s on ftp server .\nMaybe path does not exist?", ftppath ) )
						return -2;
					break;
			}
		}

		// Delete source file after uploading.
		if( deletesourcefiles )
		{
			ret = remove( (char*)next->data );
		}
		next = next->next;
		count++;
	}
	return count;
}
コード例 #6
0
ファイル: log_io.cpp プロジェクト: rauls/iReporter
short ValidateFile( char *filetocheck )
{
	//struct	stat	fileStat;
	long	hnd;

	if ( IsURL( filetocheck ) ){
		return 1;
	} else {
		hnd = LogOpen( filetocheck, NULL );
	}
	//err = stat( filetocheck, &fileStat );

	if ( hnd ){
		LogClose( hnd, filetocheck );
		return 1;
	}
	return 0;
}
コード例 #7
0
ファイル: log_io.cpp プロジェクト: rauls/iReporter
long LogRead( void *refNum, char *filename, char *databuffer, long ReadCount )
{
	if ( refNum ){
#ifndef DEF_MAC
		if ( IsURL( filename )  )
			return NetRead( (void*)refNum, databuffer, ReadCount );
		else 
		if ( IsPKZIP( filename ) )
			return UnzipGetData( (void*)refNum, (unsigned char *)databuffer, (size_t)ReadCount );
		else 
#ifdef _BZLIB_H
		if ( IsBZIP( filename ) )	// please let the mac do this one day... for completeness sake and less #ifdefs
			return BZ2_bzread( (void*)refNum, databuffer, ReadCount );
		else
#endif
#endif
			return gzread( (gzFile)refNum, databuffer, ReadCount );
	}
	return 0;
}
コード例 #8
0
void wxGISFeatureDetailsPanel::FillPanel(const wxGISFeature &Feature)
{
    //TODO: rewrite using OLCIgnoreFields
	m_Feature = Feature;
	Clear();
	for(int i = 0; i < Feature.GetFieldCount(); ++i)
	{
		if(m_anExcludeFields.Index(i) != wxNOT_FOUND)
			continue;

        wxString sName = Feature.GetFieldName(i);

		long pos = m_listCtrl->InsertItem(i, sName, 2);

        wxListItem item_val;
        item_val.SetColumn(1);
        wxString sValue = Feature.GetFieldAsString(i);
        item_val.SetText(sValue);
        item_val.SetId(pos);
		m_listCtrl->SetItem(item_val);

        if(IsURL(sValue))
        {
            wxFont Font = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT);
            Font.SetUnderlined(true);
            m_listCtrl->SetItemFont(pos, Font);
            m_listCtrl->SetItemTextColour(pos, wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHT));
        }
        else if(IsLocalURL(sValue))
        {
            wxFont Font = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT);
            Font.SetUnderlined(true);
            m_listCtrl->SetItemFont(pos, Font);
            m_listCtrl->SetItemTextColour(pos, wxSystemSettings::GetColour(wxSYS_COLOUR_GRAYTEXT));
        }
		m_listCtrl->SetItemData(pos, (long)i);
	}
	//m_listCtrl->Update();
    FIELDSORTDATA sortdata = {m_nSortAsc, m_currentSortCol, m_Feature};
	m_listCtrl->SortItems(FieldValueCompareFunction, (long)&sortdata);
}
コード例 #9
0
void wxGISFeatureDetailsPanel::OnMouseMove(wxMouseEvent& event)
{
    event.Skip(true);

    int flags;
    long item = m_listCtrl->HitTest(event.GetPosition(), flags);
    if ((item > -1) && (flags & wxLIST_HITTEST_ONITEM))
    {
        wxListItem row_info;
        row_info.m_itemId = item;
        row_info.m_col = 1;
        row_info.m_mask = wxLIST_MASK_TEXT;
        m_listCtrl->GetItem( row_info );
        if(IsURL(row_info.m_text) || IsLocalURL(row_info.m_text))
        {
            m_listCtrl->SetCursor(wxCursor(wxCURSOR_HAND));
            return;
        }
    }
    m_listCtrl->SetCursor(wxCursor(wxCURSOR_ARROW));
}
コード例 #10
0
ファイル: engine_dbio.cpp プロジェクト: rauls/iReporter
static gzFile DBIO_OpenFile( const char *filename )
{
	char rawfileName[256];

	strcpy( rawfileName, filename );

	DateFixFilename( rawfileName, 0 );

	if ( IsShortCut( rawfileName ) ){
		char linkpath[256];
		mystrcpy( linkpath, rawfileName );
#if DEF_WINDOWS
		GetShortCut( linkpath, rawfileName );
#endif
	}

	gzFile fh=0;

	if ( !IsURL( rawfileName ) )
	{
		char format[256];

		// determine if its PKZIP file and if so... dont open it, YET
		if ( IsFileInvalid( rawfileName, format ) )
		{
			OutDebugs( "Cannot open %s because it is a %s file.", rawfileName, format );
			return 0;
		}
		else 
		{
			if ( IsBzFile( rawfileName ) )
				; // fh=bzopen( rawfileName, "rb" ); removed for compat build RHF
			else
				fh=gzopen( rawfileName, "rb" );
		}
	}
	return fh;
}
コード例 #11
0
ファイル: log_io.cpp プロジェクト: rauls/iReporter
/*

FormatMessage(     FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
    NULL,    GetLastError(),
    MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
    (LPTSTR) &lpMsgBuf,    0,    NULL );

  */
long LogClose( long logref, char *filename )
{
	long ret = 0;
	if ( logref )
	{
		// It would be easy to support ZIP/BZIP2 for mac...  
#ifndef DEF_MAC
		if ( IsURL( filename ) )
			NetClose( (void*)logref );
		else
		if ( IsPKZIP( filename ) )
			UnzipClose( (void*)logref );
		else
 #ifdef _BZLIB_H
		if ( IsBZIP( filename ) )
			BZ2_bzclose( (void*)logref );
		else
 #endif
#endif
			ret = gzclose( (gzFile)logref );
	}
	return ret;
}
コード例 #12
0
ファイル: MainWndCmd.cpp プロジェクト: afriza/GSPlayer
void CMainWnd::OnPlayPrev()
{
	BOOL fPlay = MAP_GetStatus(m_hMap) != MAP_STATUS_STOP;

	// ファイル再生の時に再生時間が2秒以上なら先頭に
	// 2秒未満の場合は前の曲
	FILEINFO* pInfo = GetInfo(GetCurrentFile());
	if (pInfo && !IsURL(pInfo->szPath)) {
		long lCurrent = MAP_GetCurrent(m_hMap);
		if (fPlay && lCurrent > 2000) {
			MAP_Seek(m_hMap, 0);
			return;
		}
	}

	int nPrev = GetPrevIndex();
	if (nPrev == OPEN_NONE)
		return;

	Open(nPrev);
	if (fPlay)
		Play();
}
コード例 #13
0
ファイル: SyncDlg.cpp プロジェクト: Blonder/TortoiseGit
void CSyncDlg::OnBnClickedButtonPull()
{
	int CurrentEntry;
	CurrentEntry = (int)this->m_ctrlPull.GetCurrentEntry();
	this->m_regPullButton = CurrentEntry;

	this->m_bAbort=false;
	this->m_GitCmdList.clear();
	m_ctrlCmdOut.SetWindowTextW(_T(""));
	m_LogText = "";

	this->UpdateData();
	UpdateCombox();

	if (g_Git.GetHash(m_oldHash, _T("HEAD")))
	{
		MessageBox(g_Git.GetGitLastErr(_T("Could not get HEAD hash.")), _T("TortoiseGit"), MB_ICONERROR);
		return;
	}

	m_refList.Clear();
	m_newHashMap.clear();
	m_oldHashMap.clear();

	if( CurrentEntry == 0)
	{
		CGitHash localBranchHash;
		if (g_Git.GetHash(localBranchHash, m_strLocalBranch))
		{
			MessageBox(g_Git.GetGitLastErr(_T("Could not get hash of \"") + m_strLocalBranch + _T("\".")), _T("TortoiseGit"), MB_ICONERROR);
			return;
		}
		if (localBranchHash != m_oldHash)
		{
			CMessageBox::Show(NULL, IDS_PROC_SYNC_PULLWRONGBRANCH, IDS_APPNAME, MB_OK | MB_ICONERROR);
			return;
		}
	}

	if(this->m_strURL.IsEmpty())
	{
		CMessageBox::Show(NULL, IDS_PROC_GITCONFIG_URLEMPTY, IDS_APPNAME, MB_OK | MB_ICONERROR);
		return;
	}

	if (m_bAutoLoadPuttyKey && CurrentEntry != 3) // CurrentEntry (Remote Update) handles this on its own)
	{
		CAppUtils::LaunchPAgent(NULL,&this->m_strURL);
	}

	this->SwitchToRun();

	CString force;
	if(this->m_bForce)
		force = _T(" --force ");

	CString cmd;

	ShowTab(IDC_CMD_LOG);

	this->m_ctrlTabCtrl.ShowTab(IDC_REFLIST-1,true);
	this->m_ctrlTabCtrl.ShowTab(IDC_IN_LOGLIST-1,false);
	this->m_ctrlTabCtrl.ShowTab(IDC_IN_CHANGELIST-1,false);
	this->m_ctrlTabCtrl.ShowTab(IDC_IN_CONFLICT-1,false);

	///Pull
	if(CurrentEntry == 0) //Pull
	{
		CString remotebranch;
		remotebranch = m_strRemoteBranch;

		if(!IsURL())
		{
			CString configName;
			configName.Format(L"branch.%s.merge", this->m_strLocalBranch);
			CString pullBranch = CGit::StripRefName(g_Git.GetConfigValue(configName));

			configName.Format(L"branch.%s.remote", m_strLocalBranch);
			CString pullRemote = g_Git.GetConfigValue(configName);

			if(pullBranch == remotebranch && pullRemote == this->m_strURL)
				remotebranch.Empty();
		}

		if(m_Gitverion >= 0x01070203) //above 1.7.0.2
			force += _T("--progress ");

		cmd.Format(_T("git.exe pull -v %s \"%s\" %s"),
				force,
				m_strURL,
				remotebranch);

		m_CurrentCmd = GIT_COMMAND_PULL;
		m_GitCmdList.push_back(cmd);

		m_pThread = AfxBeginThread(ProgressThreadEntry, this, THREAD_PRIORITY_NORMAL,0,CREATE_SUSPENDED);
		if (m_pThread==NULL)
		{
		//		ReportError(CString(MAKEINTRESOURCE(IDS_ERR_THREADSTARTFAILED)));
		}
		else
		{
			m_pThread->m_bAutoDelete = TRUE;
			m_pThread->ResumeThread();
		}

	}

	///Fetch
	if(CurrentEntry == 1 || CurrentEntry ==2 ) //Fetch
	{
		CString remotebranch;
		if(this->IsURL() || m_strRemoteBranch.IsEmpty())
		{
			remotebranch=this->m_strRemoteBranch;

		}
		else
		{
			remotebranch.Format(_T("remotes/%s/%s"),
								m_strURL,m_strRemoteBranch);
			CGitHash remoteBranchHash;
			g_Git.GetHash(remoteBranchHash, remotebranch);
			if (remoteBranchHash.IsEmpty())
				remotebranch=m_strRemoteBranch;
			else
				remotebranch=m_strRemoteBranch+_T(":")+remotebranch;
		}

		if(CurrentEntry == 1)
			m_CurrentCmd = GIT_COMMAND_FETCH;
		else
			m_CurrentCmd = GIT_COMMAND_FETCHANDREBASE;

		if (g_Git.UsingLibGit2(CGit::GIT_CMD_FETCH))
		{
			CString refspec;
			// current libgit2 only supports well formated refspec
			refspec.Format(_T("refs/heads/%s:refs/remotes/%s/%s"), m_strRemoteBranch, m_strURL, m_strRemoteBranch);
			m_GitProgressList.SetUrl(m_strURL);
			m_GitProgressList.SetRefSpec(refspec);
			m_GitProgressList.SetCommand(CGitProgressList::GitProgress_Fetch);
			m_GitProgressList.Init();
			ShowTab(IDC_CMD_GIT_PROG);
		}
		else
		{
			if(m_Gitverion >= 0x01070203) //above 1.7.0.2
				force += _T("--progress ");

			cmd.Format(_T("git.exe fetch -v %s \"%s\" %s"),
					force,
					m_strURL,
					remotebranch);

			m_GitCmdList.push_back(cmd);

			m_pThread = AfxBeginThread(ProgressThreadEntry, this, THREAD_PRIORITY_NORMAL,0,CREATE_SUSPENDED);
			if (m_pThread==NULL)
			{
			//		ReportError(CString(MAKEINTRESOURCE(IDS_ERR_THREADSTARTFAILED)));
			}
			else
			{
				m_pThread->m_bAutoDelete = TRUE;
				m_pThread->ResumeThread();
			}
		}
	}

	///Remote Update
	if(CurrentEntry == 3)
	{
		if (m_bAutoLoadPuttyKey)
		{
			STRING_VECTOR list;
			if (!g_Git.GetRemoteList(list))
			{
				for (size_t i = 0; i < list.size(); ++i)
					CAppUtils::LaunchPAgent(NULL, &list[i]);
			}
		}

		m_CurrentCmd = GIT_COMMAND_REMOTE;
		cmd=_T("git.exe remote update");
		m_GitCmdList.push_back(cmd);

		InterlockedExchange(&m_bBlock, TRUE);

		m_pThread = AfxBeginThread(ProgressThreadEntry, this, THREAD_PRIORITY_NORMAL,0,CREATE_SUSPENDED);
		if (m_pThread==NULL)
		{
		//		ReportError(CString(MAKEINTRESOURCE(IDS_ERR_THREADSTARTFAILED)));
			InterlockedExchange(&m_bBlock, FALSE);
		}
		else
		{
			m_pThread->m_bAutoDelete = TRUE;
			m_pThread->ResumeThread();
		}
	}

	///Cleanup stale remote banches
	if(CurrentEntry == 4)
	{
		m_CurrentCmd = GIT_COMMAND_REMOTE;
		cmd.Format(_T("git.exe remote prune \"%s\""), m_strURL);
		m_GitCmdList.push_back(cmd);

		InterlockedExchange(&m_bBlock, TRUE);

		m_pThread = AfxBeginThread(ProgressThreadEntry, this, THREAD_PRIORITY_NORMAL,0,CREATE_SUSPENDED);
		if (m_pThread==NULL)
		{
		//		ReportError(CString(MAKEINTRESOURCE(IDS_ERR_THREADSTARTFAILED)));
			InterlockedExchange(&m_bBlock, FALSE);
		}
		else
		{
			m_pThread->m_bAutoDelete = TRUE;
			m_pThread->ResumeThread();
		}
	}
}
コード例 #14
0
ファイル: SyncDlg.cpp プロジェクト: Blonder/TortoiseGit
void CSyncDlg::FetchOutList(bool force)
{
	if(!m_bInited)
		return;
	m_OutChangeFileList.Clear();
	this->m_OutLogList.Clear();

	CString remote;
	this->m_ctrlURL.GetWindowText(remote);
	CString remotebranch;
	this->m_ctrlRemoteBranch.GetWindowText(remotebranch);
	remotebranch=remote+_T("/")+remotebranch;
	CGitHash remotebranchHash;
	g_Git.GetHash(remotebranchHash, remotebranch);

	if(IsURL())
	{
		CString str;
		str.LoadString(IDS_PROC_SYNC_PUSH_UNKNOWN);
		m_OutLogList.ShowText(str);
		this->m_ctrlTabCtrl.ShowTab(m_OutChangeFileList.GetDlgCtrlID()-1,FALSE);
		m_OutLocalBranch.Empty();
		m_OutRemoteBranch.Empty();

		this->GetDlgItem(IDC_BUTTON_EMAIL)->EnableWindow(FALSE);
		return ;

	}
	else if(remotebranchHash.IsEmpty())
	{
		CString str;
		str.Format(IDS_PROC_SYNC_PUSH_UNKNOWNBRANCH, remotebranch);
		m_OutLogList.ShowText(str);
		this->m_ctrlTabCtrl.ShowTab(m_OutChangeFileList.GetDlgCtrlID()-1,FALSE);
		m_OutLocalBranch.Empty();
		m_OutRemoteBranch.Empty();

		this->GetDlgItem(IDC_BUTTON_EMAIL)->EnableWindow(FALSE);
		return ;
	}
	else
	{
		CString localbranch;
		localbranch=this->m_ctrlLocalBranch.GetString();

		if(localbranch != m_OutLocalBranch || m_OutRemoteBranch != remotebranch || force)
		{
			m_OutLogList.ClearText();

			CGitHash base, localBranchHash;
			bool isFastForward = g_Git.IsFastForward(remotebranch, localbranch, &base);

			if (g_Git.GetHash(localBranchHash, localbranch))
			{
				MessageBox(g_Git.GetGitLastErr(_T("Could not get hash of \"") + localbranch + _T("\".")), _T("TortoiseGit"), MB_ICONERROR);
				return;
			}
			if (remotebranchHash == localBranchHash)
			{
				CString str;
				str.Format(IDS_PROC_SYNC_COMMITSAHEAD, 0, remotebranch);
				m_OutLogList.ShowText(str);
				this->m_ctrlStatus.SetWindowText(str);
				this->m_ctrlTabCtrl.ShowTab(m_OutChangeFileList.GetDlgCtrlID()-1,FALSE);
				this->GetDlgItem(IDC_BUTTON_EMAIL)->EnableWindow(FALSE);
			}
			else if (isFastForward || m_bForce)
			{
				CString range;
				range.Format(_T("%s..%s"), g_Git.FixBranchName(remotebranch), g_Git.FixBranchName(localbranch));
				//fast forward
				m_OutLogList.FillGitLog(nullptr, &range, CGit::LOG_INFO_STAT | CGit::LOG_INFO_FILESTATE | CGit::LOG_INFO_SHOW_MERGEDFILE);
				CString str;
				str.Format(IDS_PROC_SYNC_COMMITSAHEAD, m_OutLogList.GetItemCount(), remotebranch);
				this->m_ctrlStatus.SetWindowText(str);

				if (isFastForward)
					AddDiffFileList(&m_OutChangeFileList, &m_arOutChangeList, localbranch, remotebranch);
				else
				{
					AddDiffFileList(&m_OutChangeFileList, &m_arOutChangeList, localbranch, base.ToString());
				}

				this->m_ctrlTabCtrl.ShowTab(m_OutChangeFileList.GetDlgCtrlID()-1,TRUE);
				this->GetDlgItem(IDC_BUTTON_EMAIL)->EnableWindow(TRUE);
			}
			else
			{
				CString str;
				str.Format(IDS_PROC_SYNC_NOFASTFORWARD, localbranch, remotebranch);
				m_OutLogList.ShowText(str);
				this->m_ctrlStatus.SetWindowText(str);
				this->m_ctrlTabCtrl.ShowTab(m_OutChangeFileList.GetDlgCtrlID() - 1, FALSE);
				this->GetDlgItem(IDC_BUTTON_EMAIL)->EnableWindow(FALSE);
			}
		}
		this->m_OutLocalBranch=localbranch;
		this->m_OutRemoteBranch=remotebranch;
	}

}
コード例 #15
0
ファイル: log_io.cpp プロジェクト: rauls/iReporter
// dynamic buffer/varialbe log reader, the must to use
short MLogReadLine( LogReadDataP fp, long logref, char *filename, long flags )
{
	short 	rindex=0,
			running=1;

	if ( IsURL( filename ) )
		fp->ReadCount = NETREADBUFFSIZE;
	else
		fp->ReadCount = fp->buff1Size;

	if ( fp->buff == (char*)-1 ){	// go back to beginning of buffer
		fp->readIndex=0;				
		fp->posIndex = 0;
		fp->ReadBuff = fp->ReadBuff1;
	} else
	if ( fp->buff ) {
		char	c,lc, *src, *dst, eol=0;
		src = fp->ReadBuff + fp->readIndex;
		dst = fp->buff;

		while(running && src ) {	
			// if the buffer is empty, top it up first to prevent overun
			if (fp->readIndex >= fp->buffCount) {
				fp->buffCount = fp->ReadCount = LogRead( (void*)logref, filename, fp->ReadBuff, fp->ReadCount );
#ifdef DEF_DEBUG
				OutDebugs( "LogRead() %d bytes from %s", fp->ReadCount, filename );
#endif
				if (fp->buffCount<=0 && fp->buffCount>=-9) {
					*dst = 0;	running = 0;
				}
				fp->readIndex = 0;		//store the index to the bytes read
				src = fp->ReadBuff;
			} else {
				c = *(src++);
				*dst = c;

				// check if the line has finished (We dont need multiline for clusters)
				//if ( flags & LOGIO_MULTILINE ){
				//	if ( lc == '\n' && c == '\n' )
				//		eol = 1;
				//} else 
				{
					if ( c == '\r' || c == '\n' ){
						eol = 1;
						if ( *src == '\n' ){
							src++; rindex++;  fp->readIndex++;
						}
					}
				}
 
				if ( eol || (rindex >= 10240) ){
					running = 0;		//buff[rindex]=0;
					*dst = 0;
				}

				dst++;
				lc = c;
				rindex++;
				fp->readIndex++;
			}
		}
	} else {
		//initialise readahead routines when buffer is nil
		//buffCount = ReadCount = TellThreadtoRead( refNum );
		fp->buffCount = fp->ReadCount = LogRead( (void*)logref, filename, fp->ReadBuff, 8000 );
		fp->readIndex = 0;
		fp->posIndex = 0;
	}

	fp->posIndex += rindex;
	if ( rindex>0 )
		return 1;
	else
		return 0;
}
コード例 #16
0
int main(int argc, char *argv[])
{
  signal(SIGINT, sig_handler);

  if (isatty(STDIN_FILENO))
  {
    struct termios new_termios;

    tcgetattr(STDIN_FILENO, &orig_termios);

    new_termios             = orig_termios;
    new_termios.c_lflag     &= ~(ICANON | ECHO | ECHOCTL | ECHONL);
    new_termios.c_cflag     |= HUPCL;
    new_termios.c_cc[VMIN]  = 0;


    tcsetattr(STDIN_FILENO, TCSANOW, &new_termios);
    atexit(restore_termios);
  }
  else
  {
    orig_fl = fcntl(STDIN_FILENO, F_GETFL);
    fcntl(STDIN_FILENO, F_SETFL, orig_fl | O_NONBLOCK);
    atexit(restore_fl);
  }

  std::string            m_filename;
  double                m_incr                = 0;
  CRBP                  g_RBP;
  COMXCore              g_OMX;
  bool                  m_stats               = false;
  bool                  m_dump_format         = false;
  FORMAT_3D_T           m_3d                  = CONF_FLAGS_FORMAT_NONE;
  bool                  m_refresh             = false;
  double                startpts              = 0;
  CRect                 DestRect              = {0,0,0,0};
  TV_DISPLAY_STATE_T   tv_state;

  const int font_opt      = 0x100;
  const int font_size_opt = 0x101;
  const int align_opt     = 0x102;
  const int subtitles_opt = 0x103;
  const int lines_opt     = 0x104;
  const int pos_opt       = 0x105;
  const int boost_on_downmix_opt = 0x200;

  struct option longopts[] = {
    { "info",         no_argument,        NULL,          'i' },
    { "help",         no_argument,        NULL,          'h' },
    { "aidx",         required_argument,  NULL,          'n' },
    { "adev",         required_argument,  NULL,          'o' },
    { "stats",        no_argument,        NULL,          's' },
    { "passthrough",  no_argument,        NULL,          'p' },
    { "deinterlace",  no_argument,        NULL,          'd' },
    { "hw",           no_argument,        NULL,          'w' },
    { "3d",           required_argument,  NULL,          '3' },
    { "hdmiclocksync", no_argument,       NULL,          'y' },
    { "nohdmiclocksync", no_argument,     NULL,          'z' },
    { "refresh",      no_argument,        NULL,          'r' },
    { "sid",          required_argument,  NULL,          't' },
    { "pos",          required_argument,  NULL,          'l' },    
    { "font",         required_argument,  NULL,          font_opt },
    { "font-size",    required_argument,  NULL,          font_size_opt },
    { "align",        required_argument,  NULL,          align_opt },
    { "subtitles",    required_argument,  NULL,          subtitles_opt },
    { "lines",        required_argument,  NULL,          lines_opt },
    { "win",          required_argument,  NULL,          pos_opt },
    { "boost-on-downmix", no_argument,    NULL,          boost_on_downmix_opt },
    { 0, 0, 0, 0 }
  };

  int c;
  std::string mode;
  while ((c = getopt_long(argc, argv, "wihn:l:o:cslpd3:yzt:r", longopts, NULL)) != -1)
  {
    switch (c) 
    {
      case 'r':
        m_refresh = true;
        break;
      case 'y':
        m_hdmi_clock_sync = true;
        break;
      case 'z':
        m_no_hdmi_clock_sync = true;
        break;
      case '3':
        mode = optarg;
        if(mode != "SBS" && mode != "TB")
        {
          print_usage();
          return 0;
        }
        if(mode == "TB")
          m_3d = CONF_FLAGS_FORMAT_TB;
        else
          m_3d = CONF_FLAGS_FORMAT_SBS;
        break;
      case 'd':
        m_Deinterlace = true;
        break;
      case 'w':
        m_use_hw_audio = true;
        break;
      case 'p':
        m_passthrough = true;
        break;
      case 's':
        m_stats = true;
        break;
      case 'o':
        deviceString = optarg;
        if(deviceString != "local" && deviceString != "hdmi")
        {
          print_usage();
          return 0;
        }
        deviceString = "omx:" + deviceString;
        break;
      case 'i':
        m_dump_format = true;
        break;
      case 't':
        m_subtitle_index = atoi(optarg) - 1;
        if(m_subtitle_index < 0)
          m_subtitle_index = 0;
        break;
      case 'n':
        m_audio_index_use = atoi(optarg) - 1;
        if(m_audio_index_use < 0)
          m_audio_index_use = 0;
        break;
      case 'l':
        m_seek_pos = atoi(optarg) ;
        if (m_seek_pos < 0)
            m_seek_pos = 0;
        break;
      case font_opt:
        m_font_path = optarg;
        m_has_font = true;
        break;
      case font_size_opt:
        {
          const int thousands = atoi(optarg);
          if (thousands > 0)
            m_font_size = thousands*0.001f;
        }
        break;
      case align_opt:
        m_centered = !strcmp(optarg, "center");
        break;
      case subtitles_opt:
        m_external_subtitles_path = optarg;
        m_has_external_subtitles = true;
        break;
      case lines_opt:
        m_subtitle_lines = std::max(atoi(optarg), 1);
        break;
      case pos_opt:
	sscanf(optarg, "%f %f %f %f", &DestRect.x1, &DestRect.y1, &DestRect.x2, &DestRect.y2);
        break;
      case boost_on_downmix_opt:
        m_boost_on_downmix = true;
        break;
      case 0:
        break;
      case 'h':
        print_usage();
        return 0;
        break;
      case ':':
        return 0;
        break;
      default:
        return 0;
        break;
    }
  }

  if (optind >= argc) {
    print_usage();
    return 0;
  }

  m_filename = argv[optind];

  auto PrintFileNotFound = [](const std::string& path)
  {
    printf("File \"%s\" not found.\n", path.c_str());
  };

  bool filename_is_URL = IsURL(m_filename);

  if(!filename_is_URL && !Exists(m_filename))
  {
    PrintFileNotFound(m_filename);
    return 0;
  }

  if(m_has_font && !Exists(m_font_path))
  {
    PrintFileNotFound(m_font_path);
    return 0;
  }

  if(m_has_external_subtitles && !Exists(m_external_subtitles_path))
  {
    PrintFileNotFound(m_external_subtitles_path);
    return 0;
  }

  if(!m_has_external_subtitles && !filename_is_URL)
  {
    auto subtitles_path = m_filename.substr(0, m_filename.find_last_of(".")) +
                          ".srt";

    if(Exists(subtitles_path))
    {
      m_external_subtitles_path = subtitles_path;
      m_has_external_subtitles = true;
    }
  }

  CLog::Init("./");

  g_RBP.Initialize();
  g_OMX.Initialize();

  m_av_clock = new OMXClock();

  m_thread_player = true;

  if(!m_omx_reader.Open(m_filename.c_str(), m_dump_format))
    goto do_exit;

  if(m_dump_format)
    goto do_exit;

  m_bMpeg         = m_omx_reader.IsMpegVideo();
  m_has_video     = m_omx_reader.VideoStreamCount();
  m_has_audio     = m_omx_reader.AudioStreamCount();
  m_has_subtitle  = m_has_external_subtitles ||
                    m_omx_reader.SubtitleStreamCount();

  if(m_filename.find("3DSBS") != string::npos || m_filename.find("HSBS") != string::npos)
    m_3d = CONF_FLAGS_FORMAT_SBS;
  else if(m_filename.find("3DTAB") != string::npos || m_filename.find("HTAB") != string::npos)
    m_3d = CONF_FLAGS_FORMAT_TB;

  // 3d modes don't work without switch hdmi mode
  if (m_3d != CONF_FLAGS_FORMAT_NONE)
    m_refresh = true;

  // you really don't want want to match refresh rate without hdmi clock sync
  if (m_refresh && !m_no_hdmi_clock_sync)
    m_hdmi_clock_sync = true;

  if(!m_av_clock->OMXInitialize(m_has_video, m_has_audio))
    goto do_exit;

  if(m_hdmi_clock_sync && !m_av_clock->HDMIClockSync())
      goto do_exit;

  m_omx_reader.GetHints(OMXSTREAM_AUDIO, m_hints_audio);
  m_omx_reader.GetHints(OMXSTREAM_VIDEO, m_hints_video);

  if(m_audio_index_use != -1)
    m_omx_reader.SetActiveStream(OMXSTREAM_AUDIO, m_audio_index_use);
          
  if(m_has_video && m_refresh)
  {
    memset(&tv_state, 0, sizeof(TV_DISPLAY_STATE_T));
    m_BcmHost.vc_tv_get_display_state(&tv_state);

    SetVideoMode(m_hints_video.width, m_hints_video.height, m_hints_video.fpsrate, m_hints_video.fpsscale, m_3d);
  }
  // get display aspect
  TV_DISPLAY_STATE_T current_tv_state;
  memset(&current_tv_state, 0, sizeof(TV_DISPLAY_STATE_T));
  m_BcmHost.vc_tv_get_display_state(&current_tv_state);
  if(current_tv_state.state & ( VC_HDMI_HDMI | VC_HDMI_DVI )) {
    //HDMI or DVI on
    m_display_aspect = get_display_aspect_ratio((HDMI_ASPECT_T)current_tv_state.display.hdmi.aspect_ratio);
  } else {
    //composite on
    m_display_aspect = get_display_aspect_ratio((SDTV_ASPECT_T)current_tv_state.display.sdtv.display_options.aspect);
  }
  m_display_aspect *= (float)current_tv_state.display.hdmi.height/(float)current_tv_state.display.hdmi.width;

  // seek on start
  if (m_seek_pos !=0 && m_omx_reader.CanSeek()) {
        printf("Seeking start of video to %i seconds\n", m_seek_pos);
        m_omx_reader.SeekTime(m_seek_pos * 1000.0f, 0, &startpts);  // from seconds to DVD_TIME_BASE
  }
  
  if(m_has_video && !m_player_video.Open(m_hints_video, m_av_clock, DestRect, m_Deinterlace,  m_bMpeg,
                                         m_hdmi_clock_sync, m_thread_player, m_display_aspect))
    goto do_exit;

  {
    std::vector<Subtitle> external_subtitles;
    if(m_has_external_subtitles &&
       !ReadSrt(m_external_subtitles_path, external_subtitles))
    {
       puts("Unable to read the subtitle file.");
       goto do_exit;
    }

    if(m_has_subtitle &&
       !m_player_subtitles.Open(m_omx_reader.SubtitleStreamCount(),
                                std::move(external_subtitles),
                                m_font_path,
                                m_font_size,
                                m_centered,
                                m_subtitle_lines,
                                m_av_clock))
      goto do_exit;
  }

  if(m_has_subtitle)
  {
    if(!m_has_external_subtitles)
    {
      if(m_subtitle_index != -1)
      {
        m_player_subtitles.SetActiveStream(
          std::min(m_subtitle_index, m_omx_reader.SubtitleStreamCount()-1));
      }
      m_player_subtitles.SetUseExternalSubtitles(false);
    }

    if(m_subtitle_index == -1 && !m_has_external_subtitles)
      m_player_subtitles.SetVisible(false);
  }

  m_omx_reader.GetHints(OMXSTREAM_AUDIO, m_hints_audio);

  if(m_has_audio && !m_player_audio.Open(m_hints_audio, m_av_clock, &m_omx_reader, deviceString, 
                                         m_passthrough, m_use_hw_audio,
                                         m_boost_on_downmix, m_thread_player))
    goto do_exit;

  m_av_clock->SetSpeed(DVD_PLAYSPEED_NORMAL);
  m_av_clock->OMXStateExecute();
  m_av_clock->OMXStart(0.0);

  struct timespec starttime, endtime;

  PrintSubtitleInfo();

  while(!m_stop)
  {
    int ch[8];
    int chnum = 0;

    if(g_abort)
      goto do_exit;
    
    while((ch[chnum] = getchar()) != EOF) chnum++;
    if (chnum > 1) ch[0] = ch[chnum - 1] | (ch[chnum - 2] << 8);

    switch(ch[0])
    {
      case 'z':
        m_tv_show_info = !m_tv_show_info;
        vc_tv_show_info(m_tv_show_info);
        break;
      case '1':
        SetSpeed(m_av_clock->OMXPlaySpeed() - 1);
        break;
      case '2':
        SetSpeed(m_av_clock->OMXPlaySpeed() + 1);
        break;
      case 'j':
        if(m_has_audio)
        {
          int new_index = m_omx_reader.GetAudioIndex() - 1;
          if (new_index >= 0)
            m_omx_reader.SetActiveStream(OMXSTREAM_AUDIO, new_index);
        }
        break;
      case 'k':
        if(m_has_audio)
          m_omx_reader.SetActiveStream(OMXSTREAM_AUDIO, m_omx_reader.GetAudioIndex() + 1);
        break;
      case 'i':
        if(m_omx_reader.GetChapterCount() > 0)
        {
          m_omx_reader.SeekChapter(m_omx_reader.GetChapter() - 1, &startpts);
          FlushStreams(startpts);
        }
        else
        {
          m_incr = -600.0;
        }
        break;
      case 'o':
        if(m_omx_reader.GetChapterCount() > 0)
        {
          m_omx_reader.SeekChapter(m_omx_reader.GetChapter() + 1, &startpts);
          FlushStreams(startpts);
        }
        else
        {
          m_incr = 600.0;
        }
        break;
      case 'n':
        if(m_has_subtitle)
        {
          if(!m_player_subtitles.GetUseExternalSubtitles())
          {
            if (m_player_subtitles.GetActiveStream() == 0)
            {
              if(m_has_external_subtitles)
                m_player_subtitles.SetUseExternalSubtitles(true);
            }
            else
            {
              m_player_subtitles.SetActiveStream(
                m_player_subtitles.GetActiveStream()-1);
            }
          }

          m_player_subtitles.SetVisible(true);
          PrintSubtitleInfo();
        }
        break;
      case 'm':
        if(m_has_subtitle)
        {
          if(m_player_subtitles.GetUseExternalSubtitles())
          {
            if(m_omx_reader.SubtitleStreamCount())
            {
              assert(m_player_subtitles.GetActiveStream() == 0);
              m_player_subtitles.SetUseExternalSubtitles(false);
            }
          }
          else
          {
            auto new_index = m_player_subtitles.GetActiveStream()+1;
            if(new_index < (size_t) m_omx_reader.SubtitleStreamCount())
              m_player_subtitles.SetActiveStream(new_index);
          }

          m_player_subtitles.SetVisible(true);
          PrintSubtitleInfo();
        }
        break;
      case 's':
        if(m_has_subtitle)
        {
          m_player_subtitles.SetVisible(!m_player_subtitles.GetVisible());
          PrintSubtitleInfo();
        }
        break;
      case 'd':
        if(m_has_subtitle && m_player_subtitles.GetVisible())
        {
          m_player_subtitles.SetDelay(m_player_subtitles.GetDelay() - 250);
          PrintSubtitleInfo();
        }
        break;
      case 'f':
        if(m_has_subtitle && m_player_subtitles.GetVisible())
        {
          m_player_subtitles.SetDelay(m_player_subtitles.GetDelay() + 250);
          PrintSubtitleInfo();
        }
        break;
      case 'q':
        m_stop = true;
        goto do_exit;
        break;
      case 0x5b44: // key left
        if(m_omx_reader.CanSeek()) m_incr = -30.0;
        break;
      case 0x5b43: // key right
        if(m_omx_reader.CanSeek()) m_incr = 30.0;
        break;
      case 0x5b41: // key up
        if(m_omx_reader.CanSeek()) m_incr = 600.0;
        break;
      case 0x5b42: // key down
        if(m_omx_reader.CanSeek()) m_incr = -600.0;
        break;
      case ' ':
      case 'p':
        m_Pause = !m_Pause;
        if(m_Pause)
        {
          SetSpeed(OMX_PLAYSPEED_PAUSE);
          m_av_clock->OMXPause();
          if(m_has_subtitle)
            m_player_subtitles.Pause();
        }
        else
        {
          if(m_has_subtitle)
            m_player_subtitles.Resume();
          SetSpeed(OMX_PLAYSPEED_NORMAL);
          m_av_clock->OMXResume();
        }
        break;
      case '-':
        m_player_audio.SetCurrentVolume(m_player_audio.GetCurrentVolume() - 300);
        printf("Current Volume: %.2fdB\n", m_player_audio.GetCurrentVolume() / 100.0f);
        break;
      case '+':
        m_player_audio.SetCurrentVolume(m_player_audio.GetCurrentVolume() + 300);
        printf("Current Volume: %.2fdB\n", m_player_audio.GetCurrentVolume() / 100.0f);
        break;
      default:
        break;
    }

    if(m_Pause)
    {
      OMXClock::OMXSleep(2);
      continue;
    }

    if(m_incr != 0 && !m_bMpeg)
    {
      int    seek_flags   = 0;
      double seek_pos     = 0;
      double pts          = 0;

      if(m_has_subtitle)
        m_player_subtitles.Pause();

      m_av_clock->OMXStop();

      pts = m_av_clock->GetPTS();

      seek_pos = (pts / DVD_TIME_BASE) + m_incr;
      seek_flags = m_incr < 0.0f ? AVSEEK_FLAG_BACKWARD : 0;

      seek_pos *= 1000.0f;

      m_incr = 0;

      if(m_omx_reader.SeekTime(seek_pos, seek_flags, &startpts))
        FlushStreams(startpts);

      m_player_video.Close();
      if(m_has_video && !m_player_video.Open(m_hints_video, m_av_clock, DestRect, m_Deinterlace, m_bMpeg,
                                         m_hdmi_clock_sync, m_thread_player, m_display_aspect))
        goto do_exit;

      m_av_clock->OMXStart(startpts);
      
      if(m_has_subtitle)
        m_player_subtitles.Resume();
    }

    /* player got in an error state */
    if(m_player_audio.Error())
    {
      printf("audio player error. emergency exit!!!\n");
      goto do_exit;
    }

    if(m_stats)
    {
      printf("V : %8.02f %8d %8d A : %8.02f %8.02f Cv : %8d Ca : %8d                            \r",
             m_av_clock->OMXMediaTime(), m_player_video.GetDecoderBufferSize(),
             m_player_video.GetDecoderFreeSpace(), m_player_audio.GetCurrentPTS() / DVD_TIME_BASE, 
             m_player_audio.GetDelay(), m_player_video.GetCached(), m_player_audio.GetCached());
    }

    if(m_omx_reader.IsEof() && !m_omx_pkt)
    {
      if (!m_player_audio.GetCached() && !m_player_video.GetCached())
        break;

      // Abort audio buffering, now we're on our own
      if (m_buffer_empty)
        m_av_clock->OMXResume();

      OMXClock::OMXSleep(10);
      continue;
    }

    /* when the audio buffer runs under 0.1 seconds we buffer up */
    if(m_has_audio)
    {
      if(m_player_audio.GetDelay() < 0.1f && !m_buffer_empty)
      {
        if(!m_av_clock->OMXIsPaused())
        {
          m_av_clock->OMXPause();
          //printf("buffering start\n");
          m_buffer_empty = true;
          clock_gettime(CLOCK_REALTIME, &starttime);
        }
      }
      if(m_player_audio.GetDelay() > (AUDIO_BUFFER_SECONDS * 0.75f) && m_buffer_empty)
      {
        if(m_av_clock->OMXIsPaused())
        {
          m_av_clock->OMXResume();
          //printf("buffering end\n");
          m_buffer_empty = false;
        }
      }
      if(m_buffer_empty)
      {
        clock_gettime(CLOCK_REALTIME, &endtime);
        if((endtime.tv_sec - starttime.tv_sec) > 1)
        {
          m_buffer_empty = false;
          m_av_clock->OMXResume();
          //printf("buffering timed out\n");
        }
      }
    }

    if(!m_omx_pkt)
      m_omx_pkt = m_omx_reader.Read();

    if(m_has_video && m_omx_pkt && m_omx_reader.IsActive(OMXSTREAM_VIDEO, m_omx_pkt->stream_index))
    {
      if(m_player_video.AddPacket(m_omx_pkt))
        m_omx_pkt = NULL;
      else
        OMXClock::OMXSleep(10);

      if(m_tv_show_info)
      {
        char response[80];
        vc_gencmd(response, sizeof response, "render_bar 4 video_fifo %d %d %d %d", 
                m_player_video.GetDecoderBufferSize()-m_player_video.GetDecoderFreeSpace(),
                0 , 0, m_player_video.GetDecoderBufferSize());
        vc_gencmd(response, sizeof response, "render_bar 5 audio_fifo %d %d %d %d", 
                (int)(100.0*m_player_audio.GetDelay()), 0, 0, 100*AUDIO_BUFFER_SECONDS);
      }
    }
    else if(m_has_audio && m_omx_pkt && m_omx_pkt->codec_type == AVMEDIA_TYPE_AUDIO)
    {
      if(m_player_audio.AddPacket(m_omx_pkt))
        m_omx_pkt = NULL;
      else
        OMXClock::OMXSleep(10);
    }
    else if(m_has_subtitle && m_omx_pkt &&
            m_omx_pkt->codec_type == AVMEDIA_TYPE_SUBTITLE)
    {
      auto result = m_player_subtitles.AddPacket(m_omx_pkt,
                      m_omx_reader.GetRelativeIndex(m_omx_pkt->stream_index));
      if (result)
        m_omx_pkt = NULL;
      else
        OMXClock::OMXSleep(10);
    }
    else
    {
      if(m_omx_pkt)
      {
        m_omx_reader.FreePacket(m_omx_pkt);
        m_omx_pkt = NULL;
      }
    }
  }

do_exit:
  printf("\n");

  if(!m_stop && !g_abort)
  {
    if(m_has_audio)
      m_player_audio.WaitCompletion();
    else if(m_has_video)
      m_player_video.WaitCompletion();
  }

  if(m_has_video && m_refresh && tv_state.display.hdmi.group && tv_state.display.hdmi.mode)
  {
    m_BcmHost.vc_tv_hdmi_power_on_explicit_new(HDMI_MODE_HDMI, (HDMI_RES_GROUP_T)tv_state.display.hdmi.group, tv_state.display.hdmi.mode);
  }

  m_av_clock->OMXStop();
  m_av_clock->OMXStateIdle();

  m_player_subtitles.Close();
  m_player_video.Close();
  m_player_audio.Close();

  if(m_omx_pkt)
  {
    m_omx_reader.FreePacket(m_omx_pkt);
    m_omx_pkt = NULL;
  }

  m_omx_reader.Close();

  vc_tv_show_info(0);

  g_OMX.Deinitialize();
  g_RBP.Deinitialize();

  printf("have a nice day ;)\n");
  return 1;
}
コード例 #17
0
ファイル: postproc.cpp プロジェクト: rauls/iReporter
// This now supports gzip or bzip2 to compress with.
long CompressLogFiles( char **logfiles, long n, int type, int deletelog )
{
	long	count,  dataread, dataout, perc;
	char	newlogname[512],
			*logFN;
	long	failed = 1;

	for( count=0; count<n ; count++){
		logFN = logfiles[count];

		if ( strstr( logFN, ".gz" ) && type==0 )
			continue;
		if ( !IsURL(logFN) )
		{
			void *fp;
			void *outfp;
			char *ram, *p;
			long blocksize = 1024*32;

			StopAll( 0 );

			if ( ram = (char*)malloc( blocksize ) ){
				__int64 dataleft, length;

				if ( fp=(void*)LogOpen( logFN, &length ) ){
					int ret;

					sprintf( newlogname, "%s.gz", logFN );

					switch( type ){
						default:
						case COMPRESS_GZIP :
							sprintf( newlogname, "%s.gz", logFN );
							if ( p = strstr( newlogname, ".bz2" ) )
								mystrcpy( p, ".gz" );
							outfp = gzopen( newlogname, "wb6" );
							break;
#ifdef  _BZLIB_H
						// bzip2 is about 15X slower for 1/2 the size files, level6 is the best time-vs-size level roughly
						case COMPRESS_BZIP2 :
							sprintf( newlogname, "%s.bz2", logFN );
							if ( p = strstr( newlogname, ".gz" ) )
								mystrcpy( p, ".bz2" );
							outfp = BZ2_bzopen( newlogname, "wb6" );
							break;
#endif
					}

					dataout = 0;
					if ( outfp ){
						dataleft = length;
						dataread = 1;
						while( dataread>0 && !IsStopped() ){
							//OutDebugs( "dataleft = %d", dataleft );
							perc = (long)(100*((length-dataleft)/(float)length));
							//sprintf( msgtext, "Compressing %s ...", 100*((length-dataleft)/length) );
							ShowProgress( perc, FALSE, NULL );
							StatusSetID( IDS_COMPRESSING, perc, dataout/1024 );

							dataread = LogRead( fp, logFN, ram, blocksize );

							if ( dataread>0 )
							{
								dataleft -= dataread;
	
								if ( type == COMPRESS_GZIP )	dataout+=gzwrite( outfp, ram , dataread );
#ifdef _BZLIB_H
								if ( type == COMPRESS_BZIP2 )	dataout+=BZ2_bzwrite( outfp, ram , dataread );
#endif
							}
						}
						if ( type == COMPRESS_GZIP )	gzclose( outfp );
#ifdef _BZLIB_H
						if ( type == COMPRESS_BZIP2 )	BZ2_bzclose( outfp );
#endif
						if ( !IsStopped() ){
							__int64 newsize;
							FILE *newfp;
							failed = 0;
							if ( (newfp = fopen( newlogname, "ab+" )) ) {
								newsize = GetFPLength( newfp );

								if ( type == COMPRESS_BZIP2 ){
									long value;
									value = 0;
									fwrite( &value, 1, 4, newfp );
									value = (long)length;
									fwrite( &value, 1, 4, newfp );
								}
								fclose(newfp);
							}
							StatusSetID( IDS_COMPRESSDONE, dataout/1024, newsize/1024, 100*newsize/dataout );
						} else
							StatusSet( "Stopped" );

					}
					ret = LogClose( (long)fp, logFN );
					if ( deletelog && !failed){
						remove( logFN );
					}
				}
				free( ram );
			}
		}
	}
	return failed;
}
コード例 #18
0
void CSyncDlg::FetchOutList(bool force)
{
	if(!m_bInited)
		return;
	m_OutChangeFileList.Clear();
	this->m_OutLogList.Clear();

	CString remote;
	this->m_ctrlURL.GetWindowText(remote);
	CString remotebranch;
	this->m_ctrlRemoteBranch.GetWindowText(remotebranch);
	remotebranch=remote+_T("/")+remotebranch;

	if(IsURL())
	{
		CString str;
		str=_T("Don't know what will push because you enter URL");
		m_OutLogList.ShowText(str);
		this->m_ctrlTabCtrl.ShowTab(m_OutChangeFileList.GetDlgCtrlID()-1,FALSE);
		m_OutLocalBranch.Empty();
		m_OutRemoteBranch.Empty();

		this->GetDlgItem(IDC_BUTTON_EMAIL)->EnableWindow(FALSE);
		return ;

	}
	else if(g_Git.GetHash(remotebranch).IsEmpty())
	{
		CString str;
		str.Format(_T("Don't know what will push because unknown \"%s\""),remotebranch);
		m_OutLogList.ShowText(str);
		this->m_ctrlTabCtrl.ShowTab(m_OutChangeFileList.GetDlgCtrlID()-1,FALSE);
		m_OutLocalBranch.Empty();
		m_OutRemoteBranch.Empty();

		this->GetDlgItem(IDC_BUTTON_EMAIL)->EnableWindow(FALSE);
		return ;
	}
	else
	{
		CString localbranch;
		localbranch=this->m_ctrlLocalBranch.GetString();

		if(localbranch != m_OutLocalBranch || m_OutRemoteBranch != remotebranch || force)
		{
			m_OutLogList.ClearText();
			m_OutLogList.FillGitLog(NULL,CGit::	LOG_INFO_STAT| CGit::LOG_INFO_FILESTATE | CGit::LOG_INFO_SHOW_MERGEDFILE,
				&remotebranch,&localbranch);

			CString str;
			if(m_OutLogList.GetItemCount() == 0)
			{
				str.Format(_T("No commits ahead \"%s\""),remotebranch);
				m_OutLogList.ShowText(str);
				this->m_ctrlStatus.SetWindowText(str);
				this->m_ctrlTabCtrl.ShowTab(m_OutChangeFileList.GetDlgCtrlID()-1,FALSE);
				this->GetDlgItem(IDC_BUTTON_EMAIL)->EnableWindow(FALSE);
			}
			else
			{
				str.Format(_T("%d commits ahead \"%s\""),m_OutLogList.GetItemCount(),remotebranch);
				this->m_ctrlStatus.SetWindowText(str);

				AddDiffFileList(&m_OutChangeFileList,&m_arOutChangeList,localbranch,remotebranch);

				this->m_ctrlTabCtrl.ShowTab(m_OutChangeFileList.GetDlgCtrlID()-1,TRUE);
				this->GetDlgItem(IDC_BUTTON_EMAIL)->EnableWindow(TRUE);
			}
		}
		this->m_OutLocalBranch=localbranch;
		this->m_OutRemoteBranch=remotebranch;
	}

}
コード例 #19
0
ファイル: postproc.cpp プロジェクト: rauls/iReporter
int PostProc_UploadReport( const char *uploadURL, int deletereport, int zipreport, char *reportLocation )
{
	if ( gFopenHistoryPtr && !IsStopped() )
	{
		char	sourcepath[256];
		char	server[256], ftppath[256], name[64], passwd[32];
		char	*source;
		void	*fs;

		if ( IsURL( uploadURL ) )
		{
			char msg[256];
			ExtractUserFromURL( (char*)uploadURL, server, name, passwd, ftppath );
			DateFixFilename( ftppath, 0 );
			fs = (void*)FtpServerOpen( server, name, passwd );
			if ( fs ){
				sprintf( msg, "FTP %s@%s/%s", name,server,ftppath );
				StatusSet( msg );
			} else 
			{
				FtpServerOpenError( server );
				return 1;
			}
		}

		PathFromFullPath( reportLocation, sourcepath );
		DateFixFilename( sourcepath, 0 );

		// ---------------- UPLOAD ALL INDIVIDUAL FILES
		if ( !zipreport )
		{
			long files;
			files = UploadFiles( fs, (char*)uploadURL, sourcepath, ftppath, deletereport );
			if ( files>0 )
				OutDebugs( "%d files uploaded.", files );
			else
				OutDebugs( "Upload canceled" );

			FtpClose( fs );
			OutDebugs( "Ftp Site Closed" );
		} else
		// ----------------- UPLOAD SINGLE ZIP REPORT
		{
			long	uploadStatus = 0;
			char	srczipname[256];
			char	newfilename[256];

			mystrcpy( srczipname, reportLocation );
			DateFixFilename( srczipname, 0 );
			PathFromFullPath( srczipname, sourcepath );

			if ( !strstr( srczipname, ".zip" ) )
			{
				source = strrchr( srczipname, '.' );
				if ( source )
					mystrcpy( source, ".zip" );
				else
					return 3;
			}
			source = srczipname;

			// Find the FILENAME Component
			if ( strstr( srczipname, sourcepath ) )
			{
				source += strlen( sourcepath );
			}

			// generate remote full path PATH+NAME
			CopyFilenameUsingPath( newfilename, (char*)uploadURL, source );

			// Ok things are ok, lets now upload the zip file
			if ( IsURL( uploadURL ) )
			{
				char fullURLPath[256];
				sprintf( fullURLPath, "%s%s", ftppath, source );

				// upload the zip file
				uploadStatus = FtpFileUpload( fs, srczipname, fullURLPath, source );
				if ( uploadStatus == FTPERR_CANTMAKEDIR )
					ErrorMsg( "Could not make directory %s on ftp server .\nMaybe path does not exist?", ftppath );

				FtpClose( fs );
			}

			if( deletereport && uploadStatus == FTPERR_COMPLETE )
			{
				OutDebugs( "Deleting local zip file %s", srczipname );
				remove( srczipname );
			}
		}
	}
	return 0;
}
コード例 #20
0
void
nsTreeSanitizer::SanitizeAttributes(mozilla::dom::Element* aElement,
                                    nsTHashtable<nsISupportsHashKey>* aAllowed,
                                    nsIAtom*** aURLs,
                                    bool aAllowXLink,
                                    bool aAllowStyle,
                                    bool aAllowDangerousSrc)
{
  PRUint32 ac = aElement->GetAttrCount();

  nsresult rv;

  for (PRInt32 i = ac - 1; i >= 0; --i) {
    rv = NS_OK;
    const nsAttrName* attrName = aElement->GetAttrNameAt(i);
    PRInt32 attrNs = attrName->NamespaceID();
    nsCOMPtr<nsIAtom> attrLocal = attrName->LocalName();

    if (kNameSpaceID_None == attrNs) {
      if (aAllowStyle && nsGkAtoms::style == attrLocal) {
        nsCOMPtr<nsIURI> baseURI = aElement->GetBaseURI();
        nsIDocument* document = aElement->GetOwnerDoc();
        // Pass the CSS Loader object to the parser, to allow parser error
        // reports to include the outer window ID.
        nsCSSParser parser(document->CSSLoader());
        nsRefPtr<mozilla::css::StyleRule> rule;
        nsAutoString value;
        aElement->GetAttr(attrNs, attrLocal, value);
        rv = parser.ParseStyleAttribute(value,
                                        document->GetDocumentURI(),
                                        baseURI,
                                        document->NodePrincipal(),
                                        getter_AddRefs(rule));
        if (NS_SUCCEEDED(rv)) {
          nsAutoString cleanValue;
          if (SanitizeStyleRule(rule, cleanValue)) {
            aElement->SetAttr(kNameSpaceID_None,
                              nsGkAtoms::style,
                              cleanValue,
                              PR_FALSE);
          }
        }
        continue;
      }
      if (aAllowDangerousSrc && nsGkAtoms::src == attrLocal) {
        continue;
      }
      if (IsURL(aURLs, attrLocal)) {
        if (SanitizeURL(aElement, attrNs, attrLocal)) {
          // in case the attribute removal shuffled the attribute order, start
          // the loop again.
          --ac;
          i = ac; // i will be decremented immediately thanks to the for loop
        }
        continue;
      }
      if (aAllowed->GetEntry(attrLocal) &&
          !(attrLocal == nsGkAtoms::rel &&
            aElement->IsHTML(nsGkAtoms::link)) &&
          !(attrLocal == nsGkAtoms::name &&
            aElement->IsHTML(nsGkAtoms::meta))) {
        // name="" and rel="" are whitelisted, but treat them as blacklisted
        // for <meta name> and <link rel> to avoid document-wide metadata
        // or styling overrides with non-conforming <meta name itemprop> or
        // <link rel itemprop>
        continue;
      }
      const PRUnichar* localStr = attrLocal->GetUTF16String();
      // Allow underscore to cater to the MCE editor library.
      // Allow data-* on SVG and MathML, too, as a forward-compat measure.
      if (*localStr == '_' || (attrLocal->GetLength() > 5 && localStr[0] == 'd'
          && localStr[1] == 'a' && localStr[2] == 't' && localStr[3] == 'a'
          && localStr[4] == '-')) {
        continue;
      }
      // else not allowed
    } else if (kNameSpaceID_XML == attrNs) {
      if (nsGkAtoms::base == attrLocal) {
        if (SanitizeURL(aElement, attrNs, attrLocal)) {
          // in case the attribute removal shuffled the attribute order, start
          // the loop again.
          --ac;
          i = ac; // i will be decremented immediately thanks to the for loop
        }
        continue;
      }
      if (nsGkAtoms::lang == attrLocal || nsGkAtoms::space == attrLocal) {
        continue;
      }
      // else not allowed
    } else if (aAllowXLink && kNameSpaceID_XLink == attrNs) {
      if (nsGkAtoms::href == attrLocal) {
        if (SanitizeURL(aElement, attrNs, attrLocal)) {
          // in case the attribute removal shuffled the attribute order, start
          // the loop again.
          --ac;
          i = ac; // i will be decremented immediately thanks to the for loop
        }
        continue;
      }
      if (nsGkAtoms::type == attrLocal || nsGkAtoms::title == attrLocal
          || nsGkAtoms::show == attrLocal || nsGkAtoms::actuate == attrLocal) {
        continue;
      }
      // else not allowed
    }
    aElement->UnsetAttr(kNameSpaceID_None, attrLocal, PR_FALSE);
    // in case the attribute removal shuffled the attribute order, start the
    // loop again.
    --ac;
    i = ac; // i will be decremented immediately thanks to the for loop
  }

#ifdef MOZ_MEDIA
  // If we've got HTML audio or video, add the controls attribute, because
  // otherwise the content is unplayable with scripts removed.
  if (aElement->IsHTML(nsGkAtoms::video) ||
      aElement->IsHTML(nsGkAtoms::audio)) {
    aElement->SetAttr(kNameSpaceID_None,
                      nsGkAtoms::controls,
                      EmptyString(),
                      PR_FALSE);
  }
#endif
}
コード例 #21
0
ファイル: SyncVideo.cpp プロジェクト: Charles32/SyncVideoPi
int SyncVideo::play()
{
// signal(SIGINT, sig_handler);
bool m_first = true;
#if WANT_KEYS
  if (isatty(STDIN_FILENO))
  {
    struct termios new_termios;

    tcgetattr(STDIN_FILENO, &orig_termios);

    new_termios             = orig_termios;
    new_termios.c_lflag     &= ~(ICANON | ECHO | ECHOCTL | ECHONL);
    new_termios.c_cflag     |= HUPCL;
    new_termios.c_cc[VMIN]  = 0;


    tcsetattr(STDIN_FILENO, TCSANOW, &new_termios);
    atexit(restore_termios);
  }
  else
  {
    orig_fl = fcntl(STDIN_FILENO, F_GETFL);
    fcntl(STDIN_FILENO, F_SETFL, orig_fl | O_NONBLOCK);
    atexit(restore_fl);
  }
#endif /* WANT_KEYS */

  
  double                m_incr                = 0;
  CRBP                  g_RBP;
  COMXCore              g_OMX;
  bool                  m_quiet               = false;
  bool                  m_stats               = false;
  bool                  m_dump_format         = false;
  FORMAT_3D_T           m_3d                  = CONF_FLAGS_FORMAT_NONE;
  bool                  m_refresh             = false;
  double                startpts              = 0;
  CRect                 DestRect              = {0,0,0,0};
  TV_DISPLAY_STATE_T   tv_state;
  GError                *error = NULL;

  const int font_opt      = 0x100;
  const int font_size_opt = 0x101;
  const int align_opt     = 0x102;
  const int subtitles_opt = 0x103;
  const int lines_opt     = 0x104;
  const int pos_opt       = 0x105;
  const int vol_opt       = 0x106;
  const int boost_on_downmix_opt = 0x200;
  const int tile_code_opt = 0x300;
  const int frame_size_opt = 0x301;

  //LOOP
  double loop_offset     = 0.0;
  double last_packet_pts = 0.0;
  double last_packet_dts = 0.0;
  double last_packet_duration = 0.0;

  
 //  int c;
 //  std::string mode;
 //  while ((c = getopt_long(argc, argv, "wihn:l:o:cqslpd3:yzt:rW:T:O:F:AR:C:", longopts, NULL)) != -1)
 //  {
 //    switch (c) 
 //    {
 //      case 'q':
 //        m_quiet = true;
 //        break;
    
 //      case 'l':
 //        m_seek_pos = atoi(optarg) ;
 //        if (m_seek_pos < 0)
 //            m_seek_pos = 0;
 //        break;
 
 //      case pos_opt:
	// sscanf(optarg, "%f %f %f %f", &DestRect.x1, &DestRect.y1, &DestRect.x2, &DestRect.y2);
 //        break;
 
 //      case tile_code_opt:
	// if (! m_tilemap) m_tilemap = pwtilemap_create();
	// pwtilemap_set_tilecode(m_tilemap, atoi(optarg));
	// break;
 //      case frame_size_opt:
	// {
	//   float fx, fy;
	//   char c;
	//   if (! m_tilemap) m_tilemap = pwtilemap_create();
	//   if (sscanf(optarg, "%gx%g%c", &fx, &fy, &c) != 2) {
	//     fprintf(stderr, "pwomxplayer --frame-size: invalid FXxFY\n");
	//     return 2;
	//   }
	//   pwtilemap_set_framesize(m_tilemap, fx, fy);
	// }
	// break;
 //      case 'W':
	// {
	//   PwRect wall;
	//   if (! m_tilemap) m_tilemap = pwtilemap_create();
	//   if (! pwrect_from_string(&wall, optarg, &error)) {
	//     fprintf(stderr, "pwomxplayer --wall: %s\n", error->message);
	//     return 2;
	//   } else {
	//     pwtilemap_set_wall(m_tilemap, &wall);
	//   }
	// }
	// break;
 //      case 'T':
	// {
	//   PwRect tile;
	//   if (! m_tilemap) m_tilemap = pwtilemap_create();
	//   if (! pwrect_from_string(&tile, optarg, &error)) {
	//     fprintf(stderr, "pwomxplayer --tile: %s\n", error->message);
	//     return 2;
	//   } else {
	//     pwtilemap_set_tile(m_tilemap, &tile);
	//   }
	// }
	// break;
 //      case 'O':
	// {
	//   PwOrient orient;
	//   if (! m_tilemap) m_tilemap = pwtilemap_create();
	//   if (! pworient_from_string(&orient, optarg, &error)) {
	//     fprintf(stderr, "pwomxplayer --orient: %s\n", error->message);
	//     return 2;
	//   } else {
	//     pwtilemap_set_orient(m_tilemap, orient);
	//   }
	// }
	// break;
 //      case 'F':
	// {
	//   PwFit fit;
	//   if (! m_tilemap) m_tilemap = pwtilemap_create();
	//   if (! pwfit_from_string(&fit, optarg, &error)) {
	//     fprintf(stderr, "pwomxplayer --fit: %s\n", error->message);
	//     return 2;
	//   } else {
	//     pwtilemap_set_fit(m_tilemap, fit);
	//   }
	// }
	// break;
 //      case 'A':
	// if (! m_tilemap) m_tilemap = pwtilemap_create();
	// pwtilemap_set_auto(m_tilemap);
	// break;
 //      case 'R':
	// if (! m_tilemap) m_tilemap = pwtilemap_create();
	// pwtilemap_set_role(m_tilemap, optarg);
	// break;
 //      case 'C':
	// if (! m_tilemap) m_tilemap = pwtilemap_create();
	// pwtilemap_set_config(m_tilemap, optarg);
	// break;
 //      case 0:
 //        break;
 //      case 'h':
 //        print_usage();
 //        return 0;
 //        break;
 //      case ':':
 //        return 0;
 //        break;
 //      default:
 //        return 0;
 //        break;
 //    }
 //  }

  

  


//changement de taille ICI
  if(m_wallWidth > 0 && m_wallHeight > 0)
  {
    ostringstream  wallStr;
    wallStr << m_wallWidth << "x" << m_wallHeight << "+0+0";
    cout << "WALL " << wallStr.str() << endl;
    PwRect wall;
    if (! m_tilemap) m_tilemap = pwtilemap_create();
    if (! pwrect_from_string(&wall, wallStr.str().c_str(), &error)) {
      fprintf(stderr, "pwomxplayer --wall: %s\n", error->message);
      return 2;
    } else {
      pwtilemap_set_wall(m_tilemap, &wall);
    }
  }

  if(m_tileWidth > 0 && m_tileHeight > 0 && m_tileX >= 0 && m_tileY >= 0)
  {
    ostringstream tileStr;
    tileStr << m_tileWidth << "x" << m_tileHeight << "+" << m_tileX  << "+" << m_tileY;
    cout << "TILE " << tileStr.str() << endl;
    PwRect tile;  
    if (! m_tilemap) m_tilemap = pwtilemap_create();
    if (! pwrect_from_string(&tile, tileStr.str().c_str(), &error)) {
      fprintf(stderr, "pwomxplayer --tile: %s\n", error->message);
      return 2;
    } else {
      pwtilemap_set_tile(m_tilemap, &tile);
    }
  }


  auto PrintFileNotFound = [](const std::string& path)
  {
    printf("File \"%s\" not found.\n", path.c_str());
  };

  bool filename_is_URL = IsURL(m_filename);

  if(!filename_is_URL && !Exists(m_filename))
  {
    PrintFileNotFound(m_filename);
    return 0;
  }

  if(m_has_font && !Exists(m_font_path))
  {
    PrintFileNotFound(m_font_path);
    return 0;
  }

  if(m_has_external_subtitles && !Exists(m_external_subtitles_path))
  {
    PrintFileNotFound(m_external_subtitles_path);
    return 0;
  }

  if(!m_has_external_subtitles && !filename_is_URL)
  {
    auto subtitles_path = m_filename.substr(0, m_filename.find_last_of(".")) +
                          ".srt";

    if(Exists(subtitles_path))
    {
      m_external_subtitles_path = subtitles_path;
      m_has_external_subtitles = true;
    }
  }

  if (m_tilemap != NULL) {
    if (! pwtilemap_define(m_tilemap, &error)) {
      fprintf(stderr, "pwomxplayer: %s\n", error->message);
      return 1;
    }
  }


  g_RBP.Initialize();
  g_OMX.Initialize();

  m_av_clock = new OMXClock();

  m_thread_player = true;

  if(!m_omx_reader.Open(m_filename.c_str(), m_dump_format, ! m_quiet))
    goto do_exit;

  if(m_dump_format)
    goto do_exit;

  //LOOP
  if(m_loop && !m_omx_reader.CanSeek()) {
    printf("Looping requested on an input that doesn't support seeking\n");
    goto do_exit;
  }

  struct timeval now;
  gettimeofday(&now, NULL);

  //start date is over and we can navigate through the stream
  if(m_dateStart < now.tv_sec && m_omx_reader.CanSeek())
  {

    if(m_omx_reader.GetStreamLength() < 15000)
    {
      
      struct tm * timeinfo;
      char buffer [80];

      timeinfo = localtime (&(m_dateStart));
      strftime (buffer,80," %I:%M:%S%p.",timeinfo);
      printf("previous time %s\n", buffer);

      m_seek_pos = 0;
      m_dateStart = now.tv_sec + 15 + m_omx_reader.GetStreamLength()/1000 - ((now.tv_sec+15)%(m_omx_reader.GetStreamLength()/1000));
      

      timeinfo = localtime (&(m_dateStart));
      strftime (buffer,80," %I:%M:%S%p.",timeinfo);
      printf("after time %s\n", buffer);


    }else
    {
      //but there is still some video to play (with a safety)
      if(m_dateEnd > now.tv_sec + 15)
      {
        printf("Start on the go\n");
        m_seek_pos = now.tv_sec - m_dateStart + 15;

        if(m_seek_pos > m_omx_reader.GetStreamLength()/1000 && m_loop)
        {
          printf("seekpos %i\n", m_seek_pos);
          printf("duration %i\n", m_omx_reader.GetStreamLength());
          m_seek_pos = m_seek_pos % (m_omx_reader.GetStreamLength()/1000);
          printf("new seekpos %i\n", m_seek_pos);
        }

        m_dateStart = now.tv_sec + 15;
      }
    }
  }


  m_bMpeg         = m_omx_reader.IsMpegVideo();
  m_has_video     = m_omx_reader.VideoStreamCount();
  m_has_audio     = m_omx_reader.AudioStreamCount();
  m_has_subtitle  = m_has_external_subtitles ||
                    m_omx_reader.SubtitleStreamCount();

  if(m_filename.find("3DSBS") != string::npos || m_filename.find("HSBS") != string::npos)
    m_3d = CONF_FLAGS_FORMAT_SBS;
  else if(m_filename.find("3DTAB") != string::npos || m_filename.find("HTAB") != string::npos)
    m_3d = CONF_FLAGS_FORMAT_TB;

  // 3d modes don't work without switch hdmi mode
  if (m_3d != CONF_FLAGS_FORMAT_NONE)
    m_refresh = true;

  // you really don't want want to match refresh rate without hdmi clock sync
  if (m_refresh && !m_no_hdmi_clock_sync)
    m_hdmi_clock_sync = true;

  if(!m_av_clock->OMXInitialize(m_has_video, m_has_audio))
    goto do_exit;

  if(m_hdmi_clock_sync && !m_av_clock->HDMIClockSync())
      goto do_exit;

  m_omx_reader.GetHints(OMXSTREAM_AUDIO, m_hints_audio);
  m_omx_reader.GetHints(OMXSTREAM_VIDEO, m_hints_video);

  if(m_audio_index_use != -1)
    m_omx_reader.SetActiveStream(OMXSTREAM_AUDIO, m_audio_index_use);
          
  if(m_has_video && m_refresh)
  {
    memset(&tv_state, 0, sizeof(TV_DISPLAY_STATE_T));
    m_BcmHost.vc_tv_get_display_state(&tv_state);

    SetVideoMode(m_hints_video.width, m_hints_video.height, m_hints_video.fpsrate, m_hints_video.fpsscale, m_3d, ! m_quiet);
  }
  // get display aspect
  TV_DISPLAY_STATE_T current_tv_state;
  memset(&current_tv_state, 0, sizeof(TV_DISPLAY_STATE_T));
  m_BcmHost.vc_tv_get_display_state(&current_tv_state);
  if(current_tv_state.state & ( VC_HDMI_HDMI | VC_HDMI_DVI )) {
    //HDMI or DVI on
    m_display_aspect = get_display_aspect_ratio((HDMI_ASPECT_T)current_tv_state.display.hdmi.aspect_ratio);
  } else {
    //composite on
    m_display_aspect = get_display_aspect_ratio((SDTV_ASPECT_T)current_tv_state.display.sdtv.display_options.aspect);
  }
  m_display_aspect *= (float)current_tv_state.display.hdmi.height/(float)current_tv_state.display.hdmi.width;

  if (m_tilemap != NULL) {
    PwIntRect screen;
    PWRECT_SET0(screen,
		current_tv_state.display.hdmi.width,
		current_tv_state.display.hdmi.height);
    pwtilemap_set_screen(m_tilemap, &screen);
  }

  // seek on start
  if (m_seek_pos !=0 && m_omx_reader.CanSeek()) {
    if (! m_quiet)
      printf("Seeking start of video to %i seconds\n", m_seek_pos);
    m_omx_reader.SeekTime(m_seek_pos * 1000.0f, 0, &startpts);  // from seconds to DVD_TIME_BASE
  }
  
  if(m_has_video && !m_player_video.Open(m_hints_video, m_av_clock, m_tilemap, DestRect, ! m_quiet, m_Deinterlace,  m_bMpeg,
                                         m_hdmi_clock_sync, m_thread_player, m_display_aspect))
    goto do_exit;

  {
    std::vector<Subtitle> external_subtitles;
    if(m_has_external_subtitles &&
       !ReadSrt(m_external_subtitles_path, external_subtitles))
    {
       puts("Unable to read the subtitle file.");
       goto do_exit;
    }

    if(m_has_subtitle &&
       !m_player_subtitles.Open(m_omx_reader.SubtitleStreamCount(),
                                std::move(external_subtitles),
                                m_font_path,
                                m_font_size,
                                m_centered,
                                m_subtitle_lines,
                                m_av_clock))
      goto do_exit;
  }

  if(m_has_subtitle)
  {
    if(!m_has_external_subtitles)
    {
      if(m_subtitle_index != -1)
      {
        m_player_subtitles.SetActiveStream(
          std::min(m_subtitle_index, m_omx_reader.SubtitleStreamCount()-1));
      }
      m_player_subtitles.SetUseExternalSubtitles(false);
    }

    if(m_subtitle_index == -1 && !m_has_external_subtitles)
      m_player_subtitles.SetVisible(false);
  }

  m_omx_reader.GetHints(OMXSTREAM_AUDIO, m_hints_audio);

  if (deviceString == "")
  {
    if (m_BcmHost.vc_tv_hdmi_audio_supported(EDID_AudioFormat_ePCM, 2, EDID_AudioSampleRate_e44KHz, EDID_AudioSampleSize_16bit ) == 0)
      deviceString = "omx:hdmi";
    else
      deviceString = "omx:local";
  }

  if(m_has_audio && !m_player_audio.Open(m_hints_audio, m_av_clock, &m_omx_reader, deviceString, 
                                         m_passthrough, m_initialVolume, m_use_hw_audio,
                                         m_boost_on_downmix, m_thread_player))
    goto do_exit;

   


  m_av_clock->SetSpeed(DVD_PLAYSPEED_NORMAL);
  m_av_clock->OMXStateExecute();
  m_av_clock->OMXStart(0.0);

  struct timespec starttime, endtime;

  if (! m_quiet)
    PrintSubtitleInfo();



  while(!m_stop)
  {
    //verifie le temps de fin
    struct timeval now;
    gettimeofday(&now, NULL);
    if(now.tv_sec > m_dateEnd)
    {
      Stop();
      goto do_exit;
    }



    if(SyncVideo::g_abort)
      goto do_exit;

// #if WANT_KEYS
//     int ch[8];
//     int chnum = 0;
// #endif

    
// #if WANT_KEYS
//     while((ch[chnum] = getchar()) != EOF) chnum++;
//     if (chnum > 1) ch[0] = ch[chnum - 1] | (ch[chnum - 2] << 8);

//     switch(ch[0])
//     {
//       case 'z':
//         m_tv_show_info = !m_tv_show_info;
//         vc_tv_show_info(m_tv_show_info);
//         break;
//       case '1':
//         SetSpeed(m_av_clock->OMXPlaySpeed() - 1);
//         break;
//       case '2':
//         SetSpeed(m_av_clock->OMXPlaySpeed() + 1);
//         break;
//       case 'j':
//         if(m_has_audio)
//         {
//           int new_index = m_omx_reader.GetAudioIndex() - 1;
//           if (new_index >= 0)
//             m_omx_reader.SetActiveStream(OMXSTREAM_AUDIO, new_index);
//         }
//         break;
//       case 'k':
//         if(m_has_audio)
//           m_omx_reader.SetActiveStream(OMXSTREAM_AUDIO, m_omx_reader.GetAudioIndex() + 1);
//         break;
//       case 'i':
//         if(m_omx_reader.GetChapterCount() > 0)
//         {
//           m_omx_reader.SeekChapter(m_omx_reader.GetChapter() - 1, &startpts);
//           FlushStreams(startpts);
//         }
//         else
//         {
//           m_incr = -600.0;
//         }
//         break;
//       case 'o':
//         if(m_omx_reader.GetChapterCount() > 0)
//         {
//           m_omx_reader.SeekChapter(m_omx_reader.GetChapter() + 1, &startpts);
//           FlushStreams(startpts);
//         }
//         else
//         {
//           m_incr = 600.0;
//         }
//         break;
//       case 'n':
//         if(m_has_subtitle)
//         {
//           if(!m_player_subtitles.GetUseExternalSubtitles())
//           {
//             if (m_player_subtitles.GetActiveStream() == 0)
//             {
//               if(m_has_external_subtitles)
//                 m_player_subtitles.SetUseExternalSubtitles(true);
//             }
//             else
//             {
//               m_player_subtitles.SetActiveStream(
//                 m_player_subtitles.GetActiveStream()-1);
//             }
//           }

//           m_player_subtitles.SetVisible(true);
//           PrintSubtitleInfo();
//         }
//         break;
//       case 'm':
//         if(m_has_subtitle)
//         {
//           if(m_player_subtitles.GetUseExternalSubtitles())
//           {
//             if(m_omx_reader.SubtitleStreamCount())
//             {
//               assert(m_player_subtitles.GetActiveStream() == 0);
//               m_player_subtitles.SetUseExternalSubtitles(false);
//             }
//           }
//           else
//           {
//             auto new_index = m_player_subtitles.GetActiveStream()+1;
//             if(new_index < (size_t) m_omx_reader.SubtitleStreamCount())
//               m_player_subtitles.SetActiveStream(new_index);
//           }

//           m_player_subtitles.SetVisible(true);
//           PrintSubtitleInfo();
//         }
//         break;
//       case 's':
//         if(m_has_subtitle)
//         {
//           m_player_subtitles.SetVisible(!m_player_subtitles.GetVisible());
//           PrintSubtitleInfo();
//         }
//         break;
//       case 'd':
//         if(m_has_subtitle && m_player_subtitles.GetVisible())
//         {
//           m_player_subtitles.SetDelay(m_player_subtitles.GetDelay() - 250);
//           PrintSubtitleInfo();
//         }
//         break;
//       case 'f':
//         if(m_has_subtitle && m_player_subtitles.GetVisible())
//         {
//           m_player_subtitles.SetDelay(m_player_subtitles.GetDelay() + 250);
//           PrintSubtitleInfo();
//         }
//         break;
//       case 'q': case 27:
//         m_stop = true;
//         goto do_exit;
//         break;
//       case 0x5b44: // key left
//         if(m_omx_reader.CanSeek()) m_incr = -30.0;
//         break;
//       case 0x5b43: // key right
//         if(m_omx_reader.CanSeek()) m_incr = 30.0;
//         break;
//       case 0x5b41: // key up
//         if(m_omx_reader.CanSeek()) m_incr = 600.0;
//         break;
//       case 0x5b42: // key down
//         if(m_omx_reader.CanSeek()) m_incr = -600.0;
//         break;
//       case ' ':
//       case 'p':
//         m_Pause = !m_Pause;
//         if(m_Pause)
//         {
//           SetSpeed(OMX_PLAYSPEED_PAUSE);
//           m_av_clock->OMXPause();
//           if(m_has_subtitle)
//             m_player_subtitles.Pause();
//         }
//         else
//         {
//           if(m_has_subtitle)
//             m_player_subtitles.Resume();
//           SetSpeed(OMX_PLAYSPEED_NORMAL);
//           m_av_clock->OMXResume();
//         }
//         break;
//       case '-':
//         m_player_audio.SetCurrentVolume(m_player_audio.GetCurrentVolume() - 300);
//         if (! m_quiet)
// 	  printf("Current Volume: %.2fdB\n", m_player_audio.GetCurrentVolume() / 100.0f);
//         break;
//       case '+': case '=':
//         m_player_audio.SetCurrentVolume(m_player_audio.GetCurrentVolume() + 300);
//         if (! m_quiet)
// 	  printf("Current Volume: %.2fdB\n", m_player_audio.GetCurrentVolume() / 100.0f);
//         break;
//       default:
//         break;
//     }
// #endif /* WANT_KEYS */

    if(m_Pause)
    {
      OMXClock::OMXSleep(2);
      continue;
    }

    if(m_incr != 0 && !m_bMpeg)
    {
      int    seek_flags   = 0;
      double seek_pos     = 0;
      double pts          = 0;

      if(m_has_subtitle)
        m_player_subtitles.Pause();

      m_av_clock->OMXStop();

      pts = m_av_clock->GetPTS();

      seek_pos = (pts / DVD_TIME_BASE) + m_incr;
      seek_flags = m_incr < 0.0f ? AVSEEK_FLAG_BACKWARD : 0;

      seek_pos *= 1000.0f;

      m_incr = 0;

      if(m_omx_reader.SeekTime(seek_pos, seek_flags, &startpts))
        FlushStreams(startpts);

      m_player_video.Close();
      if(m_has_video && !m_player_video.Open(m_hints_video, m_av_clock, m_tilemap, DestRect, ! m_quiet, m_Deinterlace, m_bMpeg,
                                         m_hdmi_clock_sync, m_thread_player, m_display_aspect))
        goto do_exit;

      m_av_clock->OMXStart(startpts);
      
      if(m_has_subtitle)
        m_player_subtitles.Resume();
    }

    /* player got in an error state */
    if(m_player_audio.Error())
    {
      fprintf(stderr, "audio player error. emergency exit!!!\n");
      goto do_exit;
    }

    if(m_stats)
    {
      printf("V : %8.02f %8d %8d A : %8.02f %8.02f Cv : %8d Ca : %8d                            \r",
             m_av_clock->OMXMediaTime(), m_player_video.GetDecoderBufferSize(),
             m_player_video.GetDecoderFreeSpace(), m_player_audio.GetCurrentPTS() / DVD_TIME_BASE, 
             m_player_audio.GetDelay(), m_player_video.GetCached(), m_player_audio.GetCached());
    }



    //DEBUT LOOP
    if(m_loop && m_omx_reader.IsEof() && !m_omx_pkt && m_isOver) {
      m_isOver = false;
      CLog::Log(LOGINFO, "EOF detected; looping requested");
      printf("RESTART !!\n");
      m_incr = -DBL_MAX;
      m_first= true;
      
      struct timeval now;
      gettimeofday(&now, NULL); 
      m_dateStart += (m_omx_reader.GetStreamLength()/1000) + 2 - m_seek_pos;
      printf("length of stream %i\n", m_omx_reader.GetStreamLength()/1000);
      printf("seek %i\n", m_seek_pos);
      m_seek_pos = 0;
    }







    if(m_omx_reader.IsEof() && !m_omx_pkt)
    {
      if (!m_player_audio.GetCached() && !m_player_video.GetCached())
      {
        if(m_loop)
        {
          cout << "abort ABORT !!" << endl;
          m_isOver = true;
          if(m_has_audio)
            m_player_audio.WaitCompletion();
          else if(m_has_video)
            m_player_video.WaitCompletion();


        }else
        {
          break;
        }
      }

      // Abort audio buffering, now we're on our own
      if (m_buffer_empty && m_first)
      {
        printf("en attente (empty buffer)\n");
        m_timer.SleepUntilTime(m_dateStart);
        printf("GO\n");
        m_av_clock->OMXResume();
        m_first = false;
      }

      OMXClock::OMXSleep(10);
      continue;
    }

    /* when the audio buffer runs under 0.1 seconds we buffer up */
    if(m_has_audio)
    {
      if(m_player_audio.GetDelay() < 0.1f && !m_buffer_empty)
      {
        if(!m_av_clock->OMXIsPaused())
        {
          m_av_clock->OMXPause();
          //printf("buffering start\n");
          m_buffer_empty = true;
          clock_gettime(CLOCK_REALTIME, &starttime);
        }
      }
      // printf("A\n");
      if(m_player_audio.GetDelay() > (AUDIO_BUFFER_SECONDS * 0.75f) && m_buffer_empty)
      {
        if(m_av_clock->OMXIsPaused())
        {
          printf("en attente\n");
          m_timer.SleepUntilTime(m_dateStart);
          m_av_clock->OMXResume();
          printf("GO\n");
          m_buffer_empty = false;
        }
      }
      if(m_buffer_empty)
      {
        clock_gettime(CLOCK_REALTIME, &endtime);
        if((endtime.tv_sec - starttime.tv_sec) > 1)
        {
          m_buffer_empty = false;
          m_av_clock->OMXResume();
          //printf("buffering timed out\n");
        }
      }
    }

    if(!m_omx_pkt)
      m_omx_pkt = m_omx_reader.Read();

    if(m_has_video && m_omx_pkt && m_omx_reader.IsActive(OMXSTREAM_VIDEO, m_omx_pkt->stream_index))
    {
      if(m_player_video.AddPacket(m_omx_pkt))
        m_omx_pkt = NULL;
      else
        OMXClock::OMXSleep(10);

      if(m_tv_show_info)
      {
        char response[80];
        vc_gencmd(response, sizeof response, "render_bar 4 video_fifo %d %d %d %d", 
                m_player_video.GetDecoderBufferSize()-m_player_video.GetDecoderFreeSpace(),
                0 , 0, m_player_video.GetDecoderBufferSize());
        vc_gencmd(response, sizeof response, "render_bar 5 audio_fifo %d %d %d %d", 
                (int)(100.0*m_player_audio.GetDelay()), 0, 0, 100*AUDIO_BUFFER_SECONDS);
      }
    }
    else if(m_has_audio && m_omx_pkt && m_omx_pkt->codec_type == AVMEDIA_TYPE_AUDIO)
    {
      if(m_player_audio.AddPacket(m_omx_pkt))
        m_omx_pkt = NULL;
      else
        OMXClock::OMXSleep(10);
    }
    else if(m_has_subtitle && m_omx_pkt &&
            m_omx_pkt->codec_type == AVMEDIA_TYPE_SUBTITLE)
    {
      auto result = m_player_subtitles.AddPacket(m_omx_pkt,
                      m_omx_reader.GetRelativeIndex(m_omx_pkt->stream_index));
      if (result)
        m_omx_pkt = NULL;
      else
        OMXClock::OMXSleep(10);
    }
    else
    {
      if(m_omx_pkt)
      {
        m_omx_reader.FreePacket(m_omx_pkt);
        m_omx_pkt = NULL;
      }
    }
  }

do_exit:
  if (m_stats)
    printf("\n");

  if(!m_stop && !SyncVideo::g_abort)
  {
    cout << "WAIT" << endl;
    if(m_has_audio)
      m_player_audio.WaitCompletion();
    else if(m_has_video)
      m_player_video.WaitCompletion();

    cout << "WAIT OVER" << endl;
  }

  if(m_has_video && m_refresh && tv_state.display.hdmi.group && tv_state.display.hdmi.mode)
  {
    m_BcmHost.vc_tv_hdmi_power_on_explicit_new(HDMI_MODE_HDMI, (HDMI_RES_GROUP_T)tv_state.display.hdmi.group, tv_state.display.hdmi.mode);
  }

  m_av_clock->OMXStop();
  m_av_clock->OMXStateIdle();

  m_player_subtitles.Close();
  m_player_video.Close();
  m_player_audio.Close();

  if(m_omx_pkt)
  {
    m_omx_reader.FreePacket(m_omx_pkt);
    m_omx_pkt = NULL;
  }

  m_omx_reader.Close();

  vc_tv_show_info(0);

  g_OMX.Deinitialize();
  g_RBP.Deinitialize();

  if (! m_quiet)
    printf("have a nice day ;)\n");
  return 1;
}
コード例 #22
0
void CSyncDlg::OnBnClickedButtonPull()
{
	int CurrentEntry;
	CurrentEntry = this->m_ctrlPull.GetCurrentEntry();
	this->m_regPullButton = CurrentEntry;

	this->m_bAbort=false;
	this->m_GitCmdList.clear();

	this->UpdateData();
	UpdateCombox();

	m_oldHash = g_Git.GetHash(_T("HEAD"));

	if( CurrentEntry == 0)
	{
		if( g_Git.GetHash(this->m_strLocalBranch) != m_oldHash)
		{
			CMessageBox::Show(NULL,_T("Pull require local branch must be current branch"),_T("TortoiseGit"),MB_OK|MB_ICONERROR);
			return;
		}
	}

	if(this->m_strURL.IsEmpty())
	{
		CMessageBox::Show(NULL,_T("URL can't Empty"),_T("TortoiseGit"),MB_OK|MB_ICONERROR);
		return;
	}

	if(this->m_bAutoLoadPuttyKey)
	{
		CAppUtils::LaunchPAgent(NULL,&this->m_strURL);
	}

	this->SwitchToRun();

	CString force;
	if(this->m_bForce)
		force = _T(" --force ");

	CString cmd;

	ShowTab(IDC_CMD_LOG);

	this->m_ctrlTabCtrl.ShowTab(IDC_IN_LOGLIST-1,false);
	this->m_ctrlTabCtrl.ShowTab(IDC_IN_CHANGELIST-1,false);
	this->m_ctrlTabCtrl.ShowTab(IDC_IN_CONFLICT-1,false);

	this->GetDlgItem(IDC_BUTTON_COMMIT)->ShowWindow(SW_HIDE);

	///Pull
	if(CurrentEntry == 0) //Pull
	{
		CString remotebranch;
		remotebranch = m_strRemoteBranch;

		if(!IsURL())
		{
			CString configName;
			configName.Format(L"branch.%s.merge", this->m_strLocalBranch);
			CString pullBranch = CGit::StripRefName(g_Git.GetConfigValue(configName));

			configName.Format(L"branch.%s.remote", m_strLocalBranch);
			CString pullRemote = g_Git.GetConfigValue(configName);

			if(pullBranch == remotebranch && pullRemote == this->m_strURL)
				remotebranch.Empty();
		}

		if(m_Gitverion >= 0x01070203) //above 1.7.0.2
			force += _T("--progress ");

		cmd.Format(_T("git.exe pull -v %s \"%s\" %s"),
				force,
				m_strURL,
				remotebranch);

		m_CurrentCmd = GIT_COMMAND_PULL;
		m_GitCmdList.push_back(cmd);

		m_pThread = AfxBeginThread(ProgressThreadEntry, this, THREAD_PRIORITY_NORMAL,0,CREATE_SUSPENDED);
		if (m_pThread==NULL)
		{
		//		ReportError(CString(MAKEINTRESOURCE(IDS_ERR_THREADSTARTFAILED)));
		}
		else
		{
			m_pThread->m_bAutoDelete = TRUE;
			m_pThread->ResumeThread();
		}

	}

	///Fetch
	if(CurrentEntry == 1 || CurrentEntry ==2 ) //Fetch
	{
		CString remotebranch;
		if(this->IsURL() || m_strRemoteBranch.IsEmpty())
		{
			remotebranch=this->m_strRemoteBranch;

		}
		else
		{
			remotebranch.Format(_T("remotes/%s/%s"),
								m_strURL,m_strRemoteBranch);
			if(g_Git.GetHash(remotebranch).IsEmpty())
				remotebranch=m_strRemoteBranch;
			else
				remotebranch=m_strRemoteBranch+_T(":")+remotebranch;
		}

		if(m_Gitverion >= 0x01070203) //above 1.7.0.2
			force += _T("--progress ");

		cmd.Format(_T("git.exe fetch -v %s \"%s\" %s"),
				force,
				m_strURL,
				remotebranch);

		if(CurrentEntry == 1)
			m_CurrentCmd = GIT_COMMAND_FETCH;
		else
			m_CurrentCmd = GIT_COMMAND_FETCHANDREBASE;
		m_GitCmdList.push_back(cmd);

		m_pThread = AfxBeginThread(ProgressThreadEntry, this, THREAD_PRIORITY_NORMAL,0,CREATE_SUSPENDED);
		if (m_pThread==NULL)
		{
		//		ReportError(CString(MAKEINTRESOURCE(IDS_ERR_THREADSTARTFAILED)));
		}
		else
		{
			m_pThread->m_bAutoDelete = TRUE;
			m_pThread->ResumeThread();
		}
	}

	///Remote Update
	if(CurrentEntry == 3)
	{
		m_CurrentCmd = GIT_COMMAND_REMOTE;
		cmd=_T("git.exe remote update");
		m_GitCmdList.push_back(cmd);

		InterlockedExchange(&m_bBlock, TRUE);

		m_pThread = AfxBeginThread(ProgressThreadEntry, this, THREAD_PRIORITY_NORMAL,0,CREATE_SUSPENDED);
		if (m_pThread==NULL)
		{
		//		ReportError(CString(MAKEINTRESOURCE(IDS_ERR_THREADSTARTFAILED)));
			InterlockedExchange(&m_bBlock, FALSE);
		}
		else
		{
			m_pThread->m_bAutoDelete = TRUE;
			m_pThread->ResumeThread();
		}
	}
}
コード例 #23
0
ファイル: log_io.cpp プロジェクト: rauls/iReporter
// static variable reader, not thread safe
short LogReadLineEx( char *buff, long logref, char *filename, long flags )
{
	short 	rindex=0,
			running=1;

	if ( IsURL( filename ) || *filename == '\\' )
		ReadCount = NETREADBUFFSIZE;
	else
		ReadCount = READBUFFSIZE;

	if ( buff == (char*)-1 ){	// go back to beginning of buffer
		readIndex=0;				
		posIndex = 0;
		ReadBuff = ReadBuff1;
	} else
	if ( buff ) {
		register char	c,lc,*src, *dst, eol=0;
		src = ReadBuff + readIndex;
		dst = buff;

		while(running) {	
			// if the buffer is empty, top it up first to prevent overun
			if (readIndex >= buffCount) {
				// dual thread reading...
				//buffCount = ReadCount = TellThreadtoRead( refNum );
				// syncrounous reading
				buffCount = ReadCount = LogRead( (void*)logref, filename, ReadBuff, ReadCount );
#ifdef DEF_DEBUG
				OutDebugs( "LogRead() more %d bytes from %s", buffCount, filename );
#endif

				if (buffCount<=0 && buffCount>=-9) {
					*dst = 0;		//buff[rindex]='\0';
					running = 0;
				}
				readIndex = 0;		//store the index to the bytes read
				src = ReadBuff;
			} else {
				c = *(src++);		//c = ReadBuff[readIndex];
				*dst = c;			//buff[rindex] = c;

				// check if the line has finished
				if ( flags & LOGIO_MULTILINE ){
					if ( lc == '\n' && c == '\n' )
						eol = 1;
				} else {
					if ( c == '\r' || c == '\n' )
					{
						eol = 1;
						while ( *src == '\r' || *src == '\n' )
						{
							src++; // Skip over extra end-of-line chars
							readIndex++;
							rindex++;
						}
					}
				}

				if ( eol || (rindex >= (10240-1)) ){
					running = 0;
					*dst = 0;		//buff[rindex]=0;
				}

				dst++;
				lc=c;
				rindex++;
				readIndex++;
			}
		}
	} else {
		//initialise readahead routines when buffer is nil
		//buffCount = ReadCount = TellThreadtoRead( refNum );
		ReadBuff = ReadBuff2;
		ReadCount = 4*1024;
#ifdef DEF_DEBUG
		OutDebugs( "LogRead(): try %d bytes from %s", ReadCount, filename );
#endif
		buffCount = ReadCount = LogRead( (void*)logref, filename, ReadBuff, ReadCount );
#ifdef DEF_DEBUG
		OutDebugs( "LogRead(): done %d bytes from %s", buffCount, filename );
#endif
		if ( buffCount > 0 )
			memcpy( ReadBuff1, ReadBuff, buffCount );
		readIndex = 0;	//store the index to the bytes read
		posIndex = 0;
	}

	posIndex += rindex;
	if (rindex>0) 
		return 1;
	else
		return 0;
}
コード例 #24
0
ファイル: postproc.cpp プロジェクト: rauls/iReporter
int PostProc_UploadLogs( char *uploadloglocation, int deletelog, int compressed_logs, char **files , long fileCount )
{
	char	newfilename[256];
	char	sourcepath[256];

	if ( files && fileCount )
	{
		char	*source, *p;
		long	count=0, filenum, perc, doftp=FALSE, ret;
		LLStructRecPtr next = gFopenHistoryPtr;
		char	server[128];
		char	ftppath[256],
				file[128];
		char	name[64];
		char	passwd[32];
		char	msg[256];
		void	*fs;

		if ( IsURL( uploadloglocation ) )
		{
			ExtractUserFromURL( uploadloglocation, server, name, passwd, ftppath );
			fs = (void*)FtpServerOpen( server, name, passwd );
			if ( fs ){
				doftp = TRUE;
				sprintf( msg, "FTP: %s@%s/%s", name,server,ftppath );
				StatusSet( msg );
			} else {
				FtpServerOpenError( server );
				return 1;
			}
		} else
			StatusSetID( IDS_COPYINGFILE, "." );

		// upload log files.....
		if ( fs )
		{
			count = 0;
			filenum = fileCount;

			// go through all logs.....
			while( files[count] && !IsStopped() )
			{
				perc = ((100*count)/filenum);
				StatusWindowSetProgress( perc, NULL );

				PathFromFullPath( files[count], sourcepath );
				source = files[count];
				if ( strstr( source, sourcepath ) )
				{
					source += strlen( sourcepath );
				}

				// Upload LOGS
				if ( doftp )
				{
					long upstatus;
					p = files[count] + strlen( sourcepath );
					if ( compressed_logs && !strstr( p, ".gz" ) ) 
						sprintf( file, "%s%s.gz", ftppath, p );
					else
						sprintf( file, "%s%s", ftppath, p );

					upstatus = FtpFileUpload( fs, files[count], file, p );
					if ( upstatus == FTPERR_COMPLETE  )
					{
						if( deletelog )
							ret = remove( files[count] );
					}
				}
				else 
				{
					CopyFilenameUsingPath( newfilename, uploadloglocation, source );
				}
				count++;
			}
		}

		if ( doftp )
			FtpClose( fs );
	} else
		return 2;
	return 0;
}
コード例 #25
0
ファイル: postproc.cpp プロジェクト: rauls/iReporter
int PreProc_FtpDownloadFiles( char *downloadURL, char *tempLocation, int deleteFiles )
{

	if ( IsURL( downloadURL ) && !IsStopped() )
	{
		char	*p;
		long	count=0, filenum;
		char	server[128], path[256], name[64], passwd[32];
#if DEF_WINDOWS
		WIN32_FIND_DATA  lpFindFileData;
		HINTERNET hFind, fs;

		char msg[256];

		ExtractUserFromURL(  downloadURL, server, name, passwd, path );
		DateFixFilename( path, 0 );

		OutDebugs( "Doing PreProcess Download %s...", path );

		fs = (void*)FtpServerOpen( server, name, passwd );

		if ( !fs )
		{
			FtpServerOpenError( server );
			return -1;
		}

		if ( fs )
		{
			long flags = INTERNET_FLAG_NO_CACHE_WRITE;
			char newpath[512];

			// *****************************************************************
			// To be more friendly with various FTP servers, we need to break
			// up the filename from the directory that it is contained in.
			// We can then change to the directory prior to fetching the file.
			// The issue here is that some FTP servers can not get a file that
			// has path information in it (ie: /directory1/dir2/file.dat)
			// *****************************************************************
			int iLen;
			for (iLen=mystrlen(path);iLen && path[iLen]!='/';--iLen)
				;
			if (!iLen)	// then there is no '/'
			{
				mystrcpy( newpath, path+1 );
			}
			else
			{
				path[iLen] = NULL;	// Set the '/' to a NULL so we have a path up to the name.
				if (!::FtpSetCurrentDirectory(fs,"/"))	// Set it to root just to be sure.
				{
					// we have a problem, however there is no real way to action this.
					// so lets just hope that the fetch will still work.
				}

				if (!::FtpSetCurrentDirectory(fs,path))
				{
					// again.
					// we have a problem, however there is no real way to action this.
					// so lets just hope that the fetch will still work.
					path[iLen] = '/';
				}

				mystrcpy( newpath, path+iLen+1 );
			}


			hFind = FtpFindFirstFile( fs, newpath, &lpFindFileData, flags , 0 );
			if ( !hFind ){
				unsigned long len = 512;
				FtpServerClose( fs );

				OutDebugs( "%s Not Found....Trying root level path instead...", newpath );
				fs = (void*)FtpServerOpen( server, name, passwd );
				if ( fs )
				{
					FtpGetCurrentDirectory( fs, newpath, &len );
					strcat( newpath, path );
					hFind = FtpFindFirstFile( fs, newpath, &lpFindFileData, flags , 0 );
				} else
					FtpServerOpenError( server );
			}

			if ( hFind )
				OutDebugs( "Ftp File Found %s size = %d", lpFindFileData.cFileName, lpFindFileData.nFileSizeLow );
			else {
				ErrorMsg( "Cannot open ftp file ...\n%s\nBecause %s", newpath, NetworkErr(NULL) );
				FtpServerClose( fs );
				return -1;
			}

			filenum = 0;

			while( hFind && !IsStopped() )
			{
				long ret;
				char ftpfilename[256], localfilename[256];

				if( hFind )
				{
					ftpfilename[0] = 0;
					if ( !strchr( lpFindFileData.cFileName , '/' ) ){
						// only if NEWPATH has a / in it copy it.
						
						if ( strchr( newpath , '/' ) ){
							mystrcpy( ftpfilename, newpath );
							p = strrchr( ftpfilename, '/');
							if ( p ) *p = 0;
						}
						strcat( ftpfilename, "/" );
						strcat( ftpfilename, lpFindFileData.cFileName );
					} else
						mystrcpy( ftpfilename, lpFindFileData.cFileName );

					// Figure out local file name
					if ( *tempLocation == 0 || GetFileAttributes( tempLocation ) != FILE_ATTRIBUTE_DIRECTORY )
					{
						sprintf( msg, "%%TEMP%%\\%s", FileFromPath( ftpfilename,NULL ) );
						ExpandEnvironmentStrings( msg, localfilename, 255 );
						StatusSetID(  IDS_STOREFILEINTEMP  );
						OutDebugs( "Using system temp location %s", localfilename );
					} else {
						PathFromFullPath( tempLocation, localfilename );
						if( strlen( localfilename ) )
						{
							strcat ( localfilename, "\\" );
							p = FileFromPath( ftpfilename,NULL );
							if ( !p ) p = "temp.log";
							strcat ( localfilename, p );
						} else
							mystrcpy( localfilename, "temp.log" );
						OutDebugs( "Using user temp location %s", localfilename );
					}

					OutDebugs( "Trying to download %d byte file '%s' into '%s' ...", lpFindFileData.nFileSizeLow, ftpfilename, localfilename );

					ret = FtpFileDownload( fs, downloadURL, localfilename, ftpfilename, lpFindFileData.nFileSizeLow );
					if ( ret > 0 )
					{
						if ( deleteFiles ){			// delete remote ftp file after downloading
							StatusSetID( IDS_DELETEFTP, ftpfilename );
							FtpDelFile( fs, ftpfilename );
						}
						AddFileToLogQ( localfilename, filenum++ );
					} else {
						OutDebugs( "error downloading (%d)", ret );
						ErrorMsg( "Cannot download file %s\n%s", NetworkErr(NULL) );
						hFind = NULL;
						FtpServerClose( fs );
						return -2;
					}
					//------------------------
				} //if( hFind )

				if ( hFind ) {
					if( InternetFindNextFile( hFind, &lpFindFileData ) == FALSE )
						hFind = NULL;
				}
			} //while
			FtpServerClose( fs );
		} 
#endif
	}
	return IsStopped();
}
コード例 #26
0
ファイル: Convert.cpp プロジェクト: BlackMael/DirectEncode
HRESULT CConvert::StartConversion()
{
	StopConversion();
	
	printf("Initialising conversion...\n");
	
	bool bIsURL = IsURL(m_pSettings->strInputFile);
	if (bIsURL)
		return StartConversionDirect();

	HRESULT hr = MakeNotificationWindow();
	if (FAILED(hr))
		return hr;

	m_pSettings->ApplySettingsToFilter(m_pMPEGWriter);

	m_nLastEncodedFrameCount = 0;

	hr = CoCreateInstance(CLSID_CaptureGraphBuilder2, 
                          NULL, CLSCTX_INPROC_SERVER,
						  IID_ICaptureGraphBuilder2, 
						  (void **)&m_pBuilder);
	
	if (FAILED(hr))
	{
		StopConversion();
		ThrowError(hr, "GraphBuilder could not be created");
		return hr;
	}

	if (wcscmp(m_pSettings->strInputFile, m_pSettings->strOutputFile) == 0)
	{
		StopConversion();
		ThrowError(E_FAIL, "The source and target files are the same.");
		return E_FAIL;
	}

    // make the timeline
    hr = CoCreateInstance(CLSID_AMTimeline, 
                         NULL, 
                         CLSCTX_INPROC_SERVER, 
                         IID_IAMTimeline, 
                         (void**) &m_pTimeline);

    if(FAILED( hr ))
	{
		StopConversion();
		ThrowError(hr, "Timeline could not be created");
        return hr;
	}

	BOOL bOutputHasVideo = TRUE;
	/*
	switch (m_audioFormat)
	{
	case formatMP3:
	case formatWAV:
		bOutputHasVideo = FALSE; 
		break;
	}*/

	double dFramerate = 0;
	BOOL bVideo = FALSE;
	BOOL bAudio = FALSE;
	long nWidth = 0;
	long nHeight = 0;
	
	hr = GetFileInfo(m_pSettings->strInputFile, &dFramerate, &m_dSourceLength, &bVideo, &bAudio, &nWidth, &nHeight, 0, 0);

	if (!bIsURL && FAILED(hr))
	{
		StopConversion();
		ThrowError(E_FAIL, "The source file could not be read. The conversion cannot proceed");
		return E_FAIL;
	}

	/*
	if ((bAudio && !bVideo || !bOutputHasVideo) && m_bLimitAudio)
	{
		SetStopTime(30);
	}
	*/

	/*
	if (m_dSourceLength == 0 && nWidth && nHeight)
	{
		// picture. We will encode as mpeg still image
		m_dSourceLength = 0.429f;
	}
	else */if (m_dSourceLength == 0)
	{
		StopConversion();
		ThrowError(E_FAIL, "The source file had a duration of 0 seconds. The conversion cannot proceed");
		return E_FAIL;
	}

	if (bVideo && (nWidth == 0 || nHeight == 0))
	{
		StopConversion();
		ThrowError(E_FAIL, "The source video could not be read. The conversion cannot proceed");
		return E_FAIL;
	}


	if (bVideo && bOutputHasVideo)
	{
		hr = AddVideoGroup(dFramerate, nWidth, nHeight);
		if (FAILED(hr))
		{
			StopConversion();
			ThrowError(hr, "Video group could not be added to timeline");
			_ASSERT(FALSE);
			return hr;
		}
	}

	if (bAudio)
	{
		hr = AddAudioGroup();
		if (FAILED(hr))
		{
			_ASSERT(FALSE);
			StopConversion();
			ThrowError(hr, "Audio group could not be added to timeline");
			return hr;
		}
	}

	if (bVideo && bOutputHasVideo)
	{
		hr = AddVideoTracks();
		if (FAILED(hr))
		{
			_ASSERT(FALSE);
			StopConversion();
			ThrowError(hr, "Video track could not be added to timeline");
			return hr;
		}
	}

	if (bAudio)
	{
		hr = AddAudioTracks();
		if (FAILED(hr))
		{
			_ASSERT(FALSE);
			StopConversion();
			ThrowError(hr, "Audio track could not be added to timeline");
			return hr;
		}
	}

	if (bVideo && bOutputHasVideo)
	{
		hr = AddVideoSourceFiles();
		if (FAILED(hr))
		{
			_ASSERT(FALSE);
			StopConversion();
			ThrowError(hr, "Video source file could not be added to timeline");
			return hr;
		}
	}
	
	if (bAudio)
	{
		hr = AddAudioSourceFiles();
		if (FAILED(hr))
		{
			_ASSERT(FALSE);
			StopConversion();
			ThrowError(hr, "Audio source file could not be added to timeline");
			
			return hr;
		}
	}

    hr = m_pTimeline->ValidateSourceNames(SFN_VALIDATEF_CHECK|SFN_VALIDATEF_POPUP|SFN_VALIDATEF_REPLACE, NULL, 0);
    _ASSERT(!FAILED(hr));

    hr = CoCreateInstance(CLSID_RenderEngine, NULL, CLSCTX_INPROC_SERVER, IID_IRenderEngine, (void**) &m_pRenderEngine);
    if (FAILED(hr))
	{
		StopConversion();
		ThrowError(hr, "Render engine could not be created");
		return hr;
	}

    hr = m_pRenderEngine->SetTimelineObject( m_pTimeline );
    if (FAILED(hr))
	{
		StopConversion();
		ThrowError(hr, "Timeline object corrupt. Bad timeline!");		
		return hr;
	}

	if (m_pSettings->dStartTime || m_pSettings->dEndTime)
	{
		hr = m_pRenderEngine->SetRenderRange((__int64)(m_pSettings->dStartTime * UNITS), (__int64)(m_pSettings->dEndTime * UNITS));
		if (FAILED(hr))
		{
			_ASSERT(FALSE);
		}
	}

    hr = m_pRenderEngine->ConnectFrontEnd();
	if (FAILED(hr))
	{
		StopConversion();
		ThrowError(hr, "File could not be rendered");
		return hr;
	}

	hr = S_OK;
	hr = m_pRenderEngine->GetFilterGraph( &m_pGraph );
	hr |= m_pBuilder->SetFiltergraph(m_pGraph);
	if (FAILED(hr))
	{
		StopConversion();
		ThrowError(hr, "Filter graph could not be retrieved");
		return hr;
	}


	CComPtr<IPin> pVideoOutPin;
	CComPtr<IPin> pAudioOutPin;

	// if it has an audio stream, but no video stream, or does not need video out
	if (bAudio && (!bVideo || !bOutputHasVideo))
	{
		hr = m_pRenderEngine->GetGroupOutputPin(0, &pAudioOutPin);
	}
	else
	{
		hr = m_pRenderEngine->GetGroupOutputPin(0, &pVideoOutPin);
		hr = m_pRenderEngine->GetGroupOutputPin(1, &pAudioOutPin);
	}

	hr = RenderOutput(m_pBuilder, m_pGraph, m_pRenderEngine, NULL, pVideoOutPin, pAudioOutPin, NULL);
	if (FAILED(hr))
	{
		ThrowError(hr, "The output could not be rendered");
		_ASSERT(FALSE);
		StopConversion();
		return hr;
	}
	
	if (CheckVisibility() == S_OK)
	{
		m_pVideoWindow->put_Owner((OAHWND)m_hwndPreviewWnd);
		Resize(m_rcWin);
		m_pVideoWindow->put_WindowStyle(WS_CHILD | WS_CLIPSIBLINGS | WS_CLIPCHILDREN);
	}


	// PromptForGraph(m_pGraph, "edit");

	if (m_pCallback)
		m_pCallback->ConversionAboutToRun();


	hr = Run();
	_ASSERT(SUCCEEDED(hr));
	if (FAILED(hr))
	{
		StopConversion();
		ThrowError(hr, "Everything was initialized okay, but the actual conversion could not start. Please check that you can write to the output file.");
	}

	return hr;
}