diff options
author | Andy Green <andy.green@linaro.org> | 2012-11-14 10:42:48 +0800 |
---|---|---|
committer | Andy Green <andy.green@linaro.org> | 2012-11-14 10:42:48 +0800 |
commit | 329b4f532f597ba8b6d2d93508f0c363a9072815 (patch) | |
tree | 644f7365f2c417d429bc04e2a9dccc7840b60098 /fmb_player_apl/src/com/FmbComFile.c |
initial commit
Diffstat (limited to 'fmb_player_apl/src/com/FmbComFile.c')
-rw-r--r-- | fmb_player_apl/src/com/FmbComFile.c | 361 |
1 files changed, 361 insertions, 0 deletions
diff --git a/fmb_player_apl/src/com/FmbComFile.c b/fmb_player_apl/src/com/FmbComFile.c new file mode 100644 index 0000000..d8c36c0 --- /dev/null +++ b/fmb_player_apl/src/com/FmbComFile.c @@ -0,0 +1,361 @@ +/** +* @brief Operate the file. +* @since 2009/01/08 +* @note None +* @attention None +* <B><I>COPYRIGHT FUJITSU LIMITED 2009</I></B> +*/ + +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + */ + +#include <unistd.h> +#include <string.h> +#include <fcntl.h> +#include <errno.h> +#include <sys/stat.h> + +#include "FmbCmn.h" + + +static FILE* _fp = NULL; +static const char *_configString={ +"\ +[com]\n\ +tsFormatInput=%d\n\ +tsFormatOutput=%d\n\ +PidValueInputVideoPid=0x%x\n\ +PidValueInputAudioPid=0x%x\n\ +PidValueInputPmtPid=0x%x\n\ +PidValueInputSitPid=0x%x\n\ +PidValueInputPcrPid=0x%x\n\ +PidValueOutputVideoPid=0x%x\n\ +PidValueOutputAudioPid=0x%x\n\ +PidValueOutputPmtPid=0x%x\n\ +PidValueOutputSitPid=0x%x\n\ +PidValueOutputPcrPid=0x%x\n\ +firmPath=%s\n\ +[enc]\n\ +inputPort=%d\n\ +outputPort=%d\n\ +outputfile=%s\n\ +videoFmt=%d\n\ +videoFrm=%d\n\ +videoScr=%d\n\ +audioFmt=%d\n\ +bitrateCalckind=%d\n\ +videoRateCtl=%d\n\ +videoBitrateCbr=%d\n\ +videoBitrateVbrAverage=%d\n\ +videoBitrateVbrPeak=%d\n\ +audioBitrateCbrMpeg1l2=%d\n\ +audioBitrateCbrAc3=%d\n\ +audioBitrateCbrLpcm=%d\n\ +audioBitrateCbrAac=%d\n\ +audioBitrateVbrAverage=%d\n\ +audioBitrateVbrPeak=%d\n\ +systemMuxRate=%d\n\ +audioLpcm=%d\n\ +[dec]\n\ +inputPort=%d\n\ +outputPort=%d\n\ +inputfile=%s\n\ +videoFmt=%d\n\ +videoFrm=%d\n\ +audioFmt=%d\n\ +" +}; + +extern const int g_ReloadAudio[FMB_AUDIO_FORMAT_KIND]; + +/** +* @brief Open a Config file. +* @param[in] filepth file path name +* @return TRUE Normal end +* @return FALSE Not Save +* @note None +* @attention None +*/ +BOOL FmbConfigFileOpen(char* filepath ,char* att) +{ + + char* err_cause; + + FMB_FUNC(TRUE); + + if(_fp != NULL){ + fclose(_fp); + _fp = NULL; + } + + _fp = fopen(filepath , att); + + if(_fp == NULL){ + err_cause = strerror(errno); + LogFmb("%s stat info:(%d)-%s",filepath ,errno, err_cause); + FMB_FUNC(FALSE); + return FALSE; + } + + FMB_FUNC(FALSE); + return TRUE; +} +/** +* @brief Close a Config file. +* @param[in] none. +* @return TRUE Normal end +* @return FALSE Abnormal end +* @note None +* @attention None +*/ +BOOL FmbConfigFileClose(void) +{ + + + FMB_FUNC(TRUE); + + if(_fp != NULL){ + fclose(_fp); + _fp = NULL; + } + + FMB_FUNC(FALSE); + return TRUE; +} + +/** +* @brief Save a Config file. +* @param[in] none. +* @return TRUE Normal end +* @return FALSE Abnormal end +* @note None +* @attention None +*/ +BOOL FmbConfigFileSave(void) +{ + + + FMB_FUNC(TRUE); + + fprintf (_fp,_configString , + gp_FmbComProperty->tsFormat[FMBEnmInputTsPacket], + gp_FmbComProperty->tsFormat[FMBEnmOutputTsPacket], + gp_FmbComProperty->PidValue[FMBEnmInputVideoPid], + gp_FmbComProperty->PidValue[FMBEnmInputAudioPid], + gp_FmbComProperty->PidValue[FMBEnmInputPmtPid], + gp_FmbComProperty->PidValue[FMBEnmInputSitPid], + gp_FmbComProperty->PidValue[FMBEnmInputPcrPid], + gp_FmbComProperty->PidValue[FMBEnmOutputVideoPid], + gp_FmbComProperty->PidValue[FMBEnmOutputAudioPid], + gp_FmbComProperty->PidValue[FMBEnmOutputPmtPid], + gp_FmbComProperty->PidValue[FMBEnmOutputSitPid], + gp_FmbComProperty->PidValue[FMBEnmOutputPcrPid], + gp_FmbInfo->firmPath_A, + gp_FmbProperty[FMBEnmFuncModeEnc].inputPort, + gp_FmbProperty[FMBEnmFuncModeEnc].outputPort, + gp_FmbProperty[FMBEnmFuncModeEnc].outputfile, + gp_FmbProperty[FMBEnmFuncModeEnc].videoFmt, + gp_FmbProperty[FMBEnmFuncModeEnc].videoFrm, + gp_FmbProperty[FMBEnmFuncModeEnc].videoScalerEnc, + gp_FmbProperty[FMBEnmFuncModeEnc].audioFmt, + gp_FmbProperty[FMBEnmFuncModeEnc].videoBitrateProp.bitrateCalckind, + gp_FmbProperty[FMBEnmFuncModeEnc].videoBitrateProp.videoRateCtl, + gp_FmbProperty[FMBEnmFuncModeEnc].videoBitrateProp.videoBitrateCbr, + gp_FmbProperty[FMBEnmFuncModeEnc].videoBitrateProp.videoBitrateVbrAverage, + gp_FmbProperty[FMBEnmFuncModeEnc].videoBitrateProp.videoBitrateVbrPeak, + gp_FmbProperty[FMBEnmFuncModeEnc].audioBitrateCbr[FMBEnmAudioFmtMpeg1l2], + gp_FmbProperty[FMBEnmFuncModeEnc].audioBitrateCbr[FMBEnmAudioFmtAc3], + gp_FmbProperty[FMBEnmFuncModeEnc].audioBitrateCbr[FMBEnmAudioFmtLpcm], + gp_FmbProperty[FMBEnmFuncModeEnc].audioBitrateCbr[FMBEnmAudioFmtAac], + gp_FmbProperty[FMBEnmFuncModeEnc].audioBitrateVbrAverage, + gp_FmbProperty[FMBEnmFuncModeEnc].audioBitrateVbrPeak, + gp_FmbProperty[FMBEnmFuncModeEnc].videoBitrateProp.systemMuxRate, + gp_FmbProperty[FMBEnmFuncModeEnc].audioLpcm, + gp_FmbProperty[FMBEnmFuncModeDec].inputPort, + gp_FmbProperty[FMBEnmFuncModeDec].outputPort, + gp_FmbProperty[FMBEnmFuncModeDec].inputfile, + gp_FmbProperty[FMBEnmFuncModeDec].videoFmt, + gp_FmbProperty[FMBEnmFuncModeDec].videoFrm, + gp_FmbProperty[FMBEnmFuncModeDec].audioFmt + ); + + + FMB_FUNC(FALSE); + return TRUE; +} + +/** +* @brief Load a Config file. +* @param[in] none. +* @return TRUE Normal end +* @return FALSE Abnormal end +* @note None +* @attention None +*/ +BOOL FmbConfigFileLoad(void) +{ + + FMB_FUNC(TRUE); + + fscanf (_fp,_configString , + &gp_FmbComProperty->tsFormat[FMBEnmInputTsPacket], + &gp_FmbComProperty->tsFormat[FMBEnmOutputTsPacket], + &gp_FmbComProperty->PidValue[FMBEnmInputVideoPid], + &gp_FmbComProperty->PidValue[FMBEnmInputAudioPid], + &gp_FmbComProperty->PidValue[FMBEnmInputPmtPid], + &gp_FmbComProperty->PidValue[FMBEnmInputSitPid], + &gp_FmbComProperty->PidValue[FMBEnmInputPcrPid], + &gp_FmbComProperty->PidValue[FMBEnmOutputVideoPid], + &gp_FmbComProperty->PidValue[FMBEnmOutputAudioPid], + &gp_FmbComProperty->PidValue[FMBEnmOutputPmtPid], + &gp_FmbComProperty->PidValue[FMBEnmOutputSitPid], + &gp_FmbComProperty->PidValue[FMBEnmOutputPcrPid], + &gp_FmbInfo->firmPath_A, + &gp_FmbProperty[FMBEnmFuncModeEnc].inputPort, + &gp_FmbProperty[FMBEnmFuncModeEnc].outputPort, + &gp_FmbProperty[FMBEnmFuncModeEnc].outputfile, + &gp_FmbProperty[FMBEnmFuncModeEnc].videoFmt, + &gp_FmbProperty[FMBEnmFuncModeEnc].videoFrm, + &gp_FmbProperty[FMBEnmFuncModeEnc].videoScalerEnc, + &gp_FmbProperty[FMBEnmFuncModeEnc].audioFmt, + &gp_FmbProperty[FMBEnmFuncModeEnc].videoBitrateProp.bitrateCalckind, + &gp_FmbProperty[FMBEnmFuncModeEnc].videoBitrateProp.videoRateCtl, + &gp_FmbProperty[FMBEnmFuncModeEnc].videoBitrateProp.videoBitrateCbr, + &gp_FmbProperty[FMBEnmFuncModeEnc].videoBitrateProp.videoBitrateVbrAverage, + &gp_FmbProperty[FMBEnmFuncModeEnc].videoBitrateProp.videoBitrateVbrPeak, + &gp_FmbProperty[FMBEnmFuncModeEnc].audioBitrateCbr[FMBEnmAudioFmtMpeg1l2], + &gp_FmbProperty[FMBEnmFuncModeEnc].audioBitrateCbr[FMBEnmAudioFmtAc3], + &gp_FmbProperty[FMBEnmFuncModeEnc].audioBitrateCbr[FMBEnmAudioFmtLpcm], + &gp_FmbProperty[FMBEnmFuncModeEnc].audioBitrateCbr[FMBEnmAudioFmtAac], + &gp_FmbProperty[FMBEnmFuncModeEnc].audioBitrateVbrAverage, + &gp_FmbProperty[FMBEnmFuncModeEnc].audioBitrateVbrPeak, + &gp_FmbProperty[FMBEnmFuncModeEnc].videoBitrateProp.systemMuxRate, + &gp_FmbProperty[FMBEnmFuncModeEnc].audioLpcm, + &gp_FmbProperty[FMBEnmFuncModeDec].inputPort, + &gp_FmbProperty[FMBEnmFuncModeDec].outputPort, + &gp_FmbProperty[FMBEnmFuncModeDec].inputfile, + &gp_FmbProperty[FMBEnmFuncModeDec].videoFmt, + &gp_FmbProperty[FMBEnmFuncModeDec].videoFrm, + &gp_FmbProperty[FMBEnmFuncModeDec].audioFmt + ); + + gp_FmbProperty[FMBEnmFuncModeEnc].audioFmtReload = g_ReloadAudio[gp_FmbProperty[FMBEnmFuncModeEnc].audioFmt]; + gp_FmbProperty[FMBEnmFuncModeDec].audioFmtReload = g_ReloadAudio[gp_FmbProperty[FMBEnmFuncModeDec].audioFmt]; + + FMB_FUNC(FALSE); + return TRUE; +} +/** +* @brief Get the stream file size. +* @param[in] FmbFileTypeEnum file kind(input file : FmbEnmInFile / output file : FmbEnmOutFile) +* @return size +* @note None +* @attention None +*/ +__off64_t FmbGetFileSize(char* filepath ) +{ + int rc; + struct stat64 st; + char* err_cause; + + FMB_FUNC(TRUE); + + rc = stat64(filepath,&st); + if ( rc != 0){ + err_cause = strerror(errno); + LogFmb("%s stat info:(%d)-%s",filepath ,errno, err_cause); + FMB_FUNC(FALSE); + return 0; + } + + FMB_FUNC(FALSE); + return st.st_size; +} + +/** +* @brief Check the file. +* @param[in] filepth file path name +* @return TRUE Normal end +* @return FALSE No file +* @note None +* @attention None +*/ +BOOL FmbIsExistenceFile(char* filepath ) +{ + int rc; + struct stat64 st; + ino_t inode=0; + char* err_cause; + + FMB_FUNC(TRUE); + + rc = stat64(filepath,&st); + if ( rc == 0){ + inode = st.st_ino; + LogFmb("%s stat info:inode (%d)",filepath,inode); + } + else{ + err_cause = strerror(errno); + LogFmb("%s stat info:(%d)-%s",filepath ,errno, err_cause); + FMB_FUNC(FALSE); + return FALSE; + } + + FMB_FUNC(FALSE); + return TRUE; +} + + +/** +* @brief Check the diffarent file. +* @param[in] in_filepath input file path name +* @param[in] out_filepath output file path name +* @return TRUE Normal end +* @return FALSE Same file +* @note None +* @attention None +*/ +BOOL FmbIsDifferentFile(char* in_filepath , char* out_filepath) +{ + int rc; + struct stat64 st; + ino_t in_inode=0; + ino_t out_inode=0; + char* err_cause; + + FMB_FUNC(TRUE); + + rc = stat64(in_filepath,&st); + if ( rc == 0){ + in_inode = st.st_ino; + LogFmb("%s stat info:inode (%d)",in_filepath,in_inode); + } + else{ + err_cause = strerror(errno); + LogFmb("%s stat info:(%d)-%s",in_filepath ,errno, err_cause); + } + + rc = stat64(out_filepath,&st); + if ( rc == 0){ + out_inode = st.st_ino; + LogFmb("%s stat info:inode (%d)",out_filepath,out_inode); + } + else{ + err_cause = strerror(errno); + LogFmb("%s stat info:(%d)-%s",out_filepath ,errno, err_cause); + } + + if (in_inode!=0 && out_inode!=0){ + if ( in_inode == out_inode ){ + FMB_FUNC(FALSE); + return FALSE; + } + } + + FMB_FUNC(FALSE); + return TRUE; +} |