Exemplo n.º 1
0
int cmdBypassData(IF4Wrapper *pWrapper, MIBValue *pValue, int cnt)
{
    char        szGUID[17];
    UINT        trSeq;
    BYTE        seq;
    WORD        len;
    char *      szData;
    UINT        invokeTime;
    UINT        waitingGap;
//    TIMESTAMP   stamp;

#if 0
    XDEBUG("Param Cnt : %d\r\n", cnt);
#endif
    if(cnt < 7) return IF4ERR_INVALID_PARAM;

    EUI64ToStr((EUI64 *)pValue[0].stream.p, szGUID);
    trSeq = pValue[1].stream.u32;
    seq = pValue[2].stream.u8;
    len = pValue[3].stream.u16;
    szData = (char *)pValue[4].stream.p;
    invokeTime = pValue[5].stream.u32;
    waitingGap = pValue[6].stream.u32;

#if 0
    GETTIMESTAMP(&stamp, (time_t *)&invokeTime);
    XDEBUG("%04d/%02d/%02d %02d:%02d:%02d %s trSeq=%d seq=%d len=%d wait=%d\r\n",
            stamp.year, stamp.mon, stamp.day, stamp.hour, stamp.day, stamp.min,
            szGUID, trSeq, seq, len, waitingGap);
    XDUMP(szData, len, TRUE);
#endif
    DumpRequest("111.1", "cmdBypassData", pValue, cnt);

	return IF4ERR_NOERROR;
}
Exemplo n.º 2
0
int if4timestamp(char * ipaddr, int port)
{
    TIMESTAMP tmEvent;
    IF4Invoke * pInvoke = NULL;
    int         nError,i;

    SET_DEBUG_MODE(0);
    CIF4Invoke  invoke(ipaddr, port, 3);

    GETTIMESTAMP(&tmEvent, NULL);

    invoke.AddParamFormat("1.16", VARSMI_TIMESTAMP, &tmEvent, sizeof(TIMESTAMP));

    pInvoke = (IF4Invoke *)invoke.GetHandle();
    nError = IF4API_Command(pInvoke, "130.4", IF4_CMDATTR_REQUEST | IF4_CMDATTR_RESPONSE);

    if(nError != IF4ERR_NOERROR) return -nError;

    for(i=0;i< pInvoke->nResultCount; i++)
    {
        memcpy(&tmEvent, pInvoke->pResult[i]->stream.p, sizeof(TIMESTAMP));
        XDEBUG("TIMESTAMP(C): %04d/%02d/%02d %02d:%02d:%02d\n", 
                tmEvent.year, tmEvent.mon, tmEvent.day, tmEvent.hour, tmEvent.min, tmEvent.sec);
    }

    return nError;
}
Exemplo n.º 3
0
BOOL SendEvent(char *szOid, CIF4Invoke *pInvoke)
{
    char    *pszAddress;
    int     i, nPort, nError = 0;
    TIMESTAMP tmEvent;

    if (pInvoke == NULL)
        return TRUE;

    GETTIMESTAMP(&tmEvent, NULL);

    for(i=0; i<3; i++)
    {
        pszAddress = pInvoke->GetAddress();
        nPort      = pInvoke->GetPort();

        XDEBUG("EVENT(%s) Send to %s:%d (try=%d).\xd\xa",
            szOid, pszAddress ? pszAddress : "", nPort, i+1);

        try
        {
            nError = pInvoke->Event(szOid, IF4_SRC_MCU, NULL, &tmEvent);
        }
        catch(...)
        {
            XDEBUG("***** Event(%s) Sending Exception.\xd\xa", szOid);
            nError = IF4ERR_SYSTEM_ERROR;
            break;
        }
        XDEBUG("EVENT(%s) Sending %s.\xd\xa", szOid, nError == IF4ERR_NOERROR ? "Done" : "Fail");

        if (nError == IF4ERR_NOERROR)
            break;
    }
    return (nError == IF4ERR_NOERROR) ? TRUE : FALSE;
}
Exemplo n.º 4
0
//-----------------------------------------------------------------------------
// Name: DXUtil_Timer()
// Desc: Performs timer opertations. Use the following commands:
//          TIMER_RESET           - to reset the timer
//          TIMER_START           - to start the timer
//          TIMER_STOP            - to stop (or pause) the timer
//          TIMER_ADVANCE         - to advance the timer by 0.1 seconds
//          TIMER_GETABSOLUTETIME - to get the absolute system time
//          TIMER_GETAPPTIME      - to get the current time
//          TIMER_GETELAPSEDTIME  - to get the time that elapsed between 
//                                  TIMER_GETELAPSEDTIME calls
//-----------------------------------------------------------------------------
FLOAT __stdcall DXUtil_Timer( TIMER_COMMAND command )
{
    static BOOL     m_bTimerInitialized = FALSE;
    static BOOL     m_bUsingQPF         = FALSE;
    static BOOL     m_bTimerStopped     = TRUE;
    static LONGLONG m_llQPFTicksPerSec  = 0;

    // Initialize the timer
    if( FALSE == m_bTimerInitialized )
    {
        m_bTimerInitialized = TRUE;

        // Use QueryPerformanceFrequency() to get frequency of timer.  If QPF is
        // not supported, we will timeGetTime() which returns milliseconds.
        LARGE_INTEGER qwTicksPerSec;
        m_bUsingQPF = QueryPerformanceFrequency( &qwTicksPerSec );
        if( m_bUsingQPF )
            m_llQPFTicksPerSec = qwTicksPerSec.QuadPart;
    }

    if( m_bUsingQPF )
    {
        static LONGLONG m_llStopTime        = 0;
        static LONGLONG m_llLastElapsedTime = 0;
        static LONGLONG m_llBaseTime        = 0;
        double fTime;
        double fElapsedTime;
        LARGE_INTEGER qwTime;
        
        // Get either the current time or the stop time, depending
        // on whether we're stopped and what command was sent
        if( m_llStopTime != 0 && command != TIMER_START && command != TIMER_GETABSOLUTETIME)
            qwTime.QuadPart = m_llStopTime;
        else
            QueryPerformanceCounter( &qwTime );

        // Return the elapsed time
        if( command == TIMER_GETELAPSEDTIME )
        {
            fElapsedTime = (double) ( qwTime.QuadPart - m_llLastElapsedTime ) / (double) m_llQPFTicksPerSec;
            m_llLastElapsedTime = qwTime.QuadPart;
            return (FLOAT) fElapsedTime;
        }
    
        // Return the current time
        if( command == TIMER_GETAPPTIME )
        {
            double fAppTime = (double) ( qwTime.QuadPart - m_llBaseTime ) / (double) m_llQPFTicksPerSec;
            return (FLOAT) fAppTime;
        }
    
        // Reset the timer
        if( command == TIMER_RESET )
        {
            m_llBaseTime        = qwTime.QuadPart;
            m_llLastElapsedTime = qwTime.QuadPart;
            m_llStopTime        = 0;
            m_bTimerStopped     = FALSE;
            return 0.0f;
        }
    
        // Start the timer
        if( command == TIMER_START )
        {
            if( m_bTimerStopped )
                m_llBaseTime += qwTime.QuadPart - m_llStopTime;
            m_llStopTime = 0;
            m_llLastElapsedTime = qwTime.QuadPart;
            m_bTimerStopped = FALSE;
            return 0.0f;
        }
    
        // Stop the timer
        if( command == TIMER_STOP )
        {
            if( !m_bTimerStopped )
            {
                m_llStopTime = qwTime.QuadPart;
                m_llLastElapsedTime = qwTime.QuadPart;
                m_bTimerStopped = TRUE;
            }
            return 0.0f;
        }
    
        // Advance the timer by 1/10th second
        if( command == TIMER_ADVANCE )
        {
            m_llStopTime += m_llQPFTicksPerSec/10;
            return 0.0f;
        }

        if( command == TIMER_GETABSOLUTETIME )
        {
            fTime = qwTime.QuadPart / (double) m_llQPFTicksPerSec;
            return (FLOAT) fTime;
        }

        return -1.0f; // Invalid command specified
    }
    else
    {
        // Get the time using timeGetTime()
        static double m_fLastElapsedTime  = 0.0;
        static double m_fBaseTime         = 0.0;
        static double m_fStopTime         = 0.0;
        double fTime;
        double fElapsedTime;
        
        // Get either the current time or the stop time, depending
        // on whether we're stopped and what command was sent
        if( m_fStopTime != 0.0 && command != TIMER_START && command != TIMER_GETABSOLUTETIME)
            fTime = m_fStopTime;
        else
            fTime = GETTIMESTAMP() * 0.001;
    
        // Return the elapsed time
        if( command == TIMER_GETELAPSEDTIME )
        {   
            fElapsedTime = (double) (fTime - m_fLastElapsedTime);
            m_fLastElapsedTime = fTime;
            return (FLOAT) fElapsedTime;
        }
    
        // Return the current time
        if( command == TIMER_GETAPPTIME )
        {
            return (FLOAT) (fTime - m_fBaseTime);
        }
    
        // Reset the timer
        if( command == TIMER_RESET )
        {
            m_fBaseTime         = fTime;
            m_fLastElapsedTime  = fTime;
            m_fStopTime         = 0;
            m_bTimerStopped     = FALSE;
            return 0.0f;
        }
    
        // Start the timer
        if( command == TIMER_START )
        {
            if( m_bTimerStopped )
                m_fBaseTime += fTime - m_fStopTime;
            m_fStopTime = 0.0f;
            m_fLastElapsedTime  = fTime;
            m_bTimerStopped = FALSE;
            return 0.0f;
        }
    
        // Stop the timer
        if( command == TIMER_STOP )
        {
            if( !m_bTimerStopped )
            {
                m_fStopTime = fTime;
                m_fLastElapsedTime  = fTime;
                m_bTimerStopped = TRUE;
            }
            return 0.0f;
        }
    
        // Advance the timer by 1/10th second
        if( command == TIMER_ADVANCE )
        {
            m_fStopTime += 0.1f;
            return 0.0f;
        }

        if( command == TIMER_GETABSOLUTETIME )
        {
            return (FLOAT) fTime;
        }

        return -1.0f; // Invalid command specified
    }
}
Exemplo n.º 5
0
AACStream::AACStream(BaseProtocol *pProtocol,
		StreamsManager *pStreamsManager, string name, BaseAudioCaptureDevice *pAudioCapDevice)
: AudioStream(pProtocol, pStreamsManager, ST_IN_AUDIO_AAC, name, pAudioCapDevice)
{
  _pAACstreamCapabilities= new StreamCapabilities();

  INFO("Initial AACStream...!!\n");

#ifdef AACSTREAM_DEBUG
  if((pfOutputMIC=fopen("MICIn.pcm", "wb")) == NULL){
    FATAL("Open output file 'MICIn.pcm' fail... !!\n");
    exit(1);
  }
#endif

  sampleRate = pAudioCapDevice->GetSampleRate();
  numOfChannel = pAudioCapDevice->GetNumberOfChannels();
  //bitsPerSample = instance->GetBitsPerSample();
  bitsPerSample = 16;
  INFO("PCM input SampleRate=%d, Channel=%d, BitsPerChannel=%d...!!\n", sampleRate, numOfChannel, bitsPerSample);

  if((sampleRate==0)||(numOfChannel==0)||(bitsPerSample==0)){
    FATAL("Error, Audio Parameters Setting Fail in ALSA... !!\n");
    exit(1);
  }

  /* open the encoder library */
  hEncoder = faacEncOpen(sampleRate, numOfChannel, &samplesInput, &maxBytesOutput);
  if(!hEncoder){
    FATAL("Error, faacEncOpen fail... !!\n");
    exit(1);
  }

#ifdef AACSTREAM_DEBUG
  DEBUG("\nsamplesInput=%ld, maxBytesOutput=%ld... !!\n",samplesInput, maxBytesOutput);
#endif

  INFO("AACStream Input Framelength=%ld, Output MaxBits=%ld...!!\n",samplesInput/numOfChannel, maxBytesOutput*8);

  pcmAACbuf = (short *)malloc(samplesInput*sizeof(short)); //AAC input:frame = samplesInput/2 Channel, 16bits/channel
  pcmAACbufPt= pcmAACbuf;
  bitbuf = (unsigned char*)malloc(maxBytesOutput*sizeof(unsigned char));

  /* put the options in the configuration struct */
  myFormat = faacEncGetCurrentConfiguration(hEncoder);
  myFormat->aacObjectType = LOW;             //LOW, MAIN, LTP
#ifdef AACSTREAM_DEBUG
  myFormat->mpegVersion = MPEG2;             //MPEG2, MPEG4
  myFormat->outputFormat = ADTS_STREAM;      //RAW_STREAM = 0(MP4), ADTS_STREAM = 1(AAC)
#else
  myFormat->mpegVersion = MPEG4;             //MPEG2, MPEG4
  myFormat->outputFormat = RAW_STREAM;      //RAW_STREAM = 0(MP4), ADTS_STREAM = 1(AAC)
#endif
  myFormat->useTns = 0;                      //TNS->0:disable, TNS->1:enable
  myFormat->allowMidside = 1;                //M/S:1->enable, 0->disable
  myFormat->bandWidth = 0;                   //default
//  myFormat->inputFormat = FAAC_INPUT_FLOAT;  //32bits
  myFormat->inputFormat = FAAC_INPUT_16BIT;    //16bits

  myFormat->bitRate=32000; //The minimum bitrate is 32kbps: 1 channel

  if (!faacEncSetConfiguration(hEncoder, myFormat)) {
        FATAL("Error, Unsupported faac output format..!!\n");
	exit(1);
  }

  INFO("AACStream average bitrate (ABR) bitrate/channel=%ld...!!\n",myFormat->bitRate);
  INFO("AACStream variable bitrate (VBR) quantizer quality in percent=%ld...!!\n",myFormat->quantqual);
  INFO("AACStream use object type LC (Low Complexity, default)=%d...!!\n",myFormat->aacObjectType);
  INFO("AACStream disable TNS, temporal noise shaping...!!\n");
  INFO("AACStream enable mid/side coding...!!\n");

  GETTIMESTAMP(ats);
  aacDuration=(1000.0/(double)sampleRate)*(double)(samplesInput/numOfChannel); //m second
  _pAACstreamCapabilities->aac.InitAACCapability(sampleRate, numOfChannel, bitsPerSample, (samplesInput/numOfChannel),
                                                 (myFormat->bitRate*numOfChannel),aacDuration);  //bitrate: 2 channel
  INFO("AACStream Frame Length Duration Time=%fm second...!!\n",aacDuration );
  _pAACstreamCapabilities->audioCodecId = CODEC_AUDIO_AAC;


#ifdef AACSTREAM_DEBUG
  if((pfOutputAAC=fopen("MICOut.aac", "wb")) == NULL){
    FATAL("Open output file 'MICOut.aac' fail... !!\n");
    exit(1);
  }
  DEBUG("Initial AACStream End..!!\n");
#endif


}
Exemplo n.º 6
0
MP3Stream::MP3Stream(StreamsManager *pStreamsManager, string name)
: BaseAudioStream(pStreamsManager, ST_IN_AUDIO_MP3, name)
{
  BaseAudioDevice *pAudioCapDevice= reinterpret_cast<BaseAudioDevice*> (HardwareManager::GetHardwareInstance(HT_MIC));
  _pMP3streamCapabilities= new StreamCapabilities();

  //pcmbuf = new uint8_t (PCM_PAGE_SIZE);
  //mp3 config
  L3_set_config_mpeg_defaults(&_mp3config.mpeg);
  //wave config
  _sampleRate = pAudioCapDevice->GetSampleRate();
  _numOfChannel = pAudioCapDevice->GetNumberOfChannels();
  _bitsPerSample = pAudioCapDevice->GetBitsPerSample();
  _bitRate = _mp3config.mpeg.bitr;//

  //set wave type, TODO: removed
  _mp3config.wave.type = WAVE_RIFF_PCM;
  _mp3config.wave.channels = _numOfChannel; //mono
  _mp3config.wave.samplerate = _sampleRate;
  _mp3config.wave.bits = _bitsPerSample;

  //config sample rate index, and bit rate
  _mp3config.mpeg.samplerate_index = L3_find_samplerate_index(_sampleRate, _mp3config.mpeg.type);
  if ( _mp3config.mpeg.samplerate_index < 0)
    FATAL ("invalid sample rate in mp3stream ctor"); //TODO: should throw an execption

  _mp3config.mpeg.bitrate_index = L3_find_bitrate_index(_mp3config.mpeg.bitr, _mp3config.mpeg.type);
  if (_mp3config.mpeg.bitrate_index < 0)
    FATAL ("invliad bit rate in mpstream ctor");


  open_bit_stream_w(&_bs, BITSSIZE);
  memset ((char*) &_side_info, 0, sizeof(L3_side_info_t));
  L3_subband_initialise();
  L3_mdct_initialise();
  L3_loop_initialise();
  _mp3config.mpeg.mode_gr = (_mp3config.mpeg.type==1)? 2: 1;
  _samplesInput = _mp3config.mpeg.samples_per_frame = (_mp3config.mpeg.type==1)? 1152:576;
  //config->mpeg.total_frames = ();
  _mp3config.mpeg.bits_per_slot = 8;
  _sideinfo_len = 32;

  if (_mp3config.mpeg.type==1) {
    if (_numOfChannel==1)
      _sideinfo_len += 136;
    else
      _sideinfo_len += 256;
  }
  else {  //mpeg2
    if (_numOfChannel==1)
      _sideinfo_len += 72;
    else
      _sideinfo_len += 136;
  }

  if (_mp3config.mpeg.crc) _sideinfo_len += 16;

  _avg_slots_per_frame   = ((double)_samplesInput /
                           ((double)_sampleRate/1000)) *
                          ((double)_bitRate /
                           (double)_mp3config.mpeg.bits_per_slot);

  _whole_slots_per_frame = (int)_avg_slots_per_frame;
  _frac_slots_per_frame = _avg_slots_per_frame - (double)_whole_slots_per_frame;
  _slot_lag = -_frac_slots_per_frame;

  if (_frac_slots_per_frame==0)
    _mp3config.mpeg.padding = 0;

  DEBUG ("mp3 stream info: _sideinfo_len:%d sampleInput:%d bitRate:%d sampleRate:%d avg slots per frame:%d",
    _sideinfo_len,
    _samplesInput,
    _bitRate,
    _sampleRate,
    _avg_slots_per_frame);


  GETTIMESTAMP(ats);
  mp3Duration=(1000.0/(double)_sampleRate)*(double)(_samplesInput/_numOfChannel); //m second
  _pMP3streamCapabilities->aac.InitAACCapability(_sampleRate, _numOfChannel, _bitsPerSample, (samplesInput/_numOfChannel),
                                                 (_bitRate* 1000 *_numOfChannel), mp3Duration);  //bitrate: 2 channel
  _pMP3streamCapabilities->audioCodecId = CODEC_AUDIO_MP3;

#ifdef MP3STREAM_DEBUG
  if((pfOutputMP3=fopen("MICOut.mp3", "wb")) == NULL){
    FATAL("Open output file 'MICOut.mp3' fail... !!\n");
    exit(1);
  }
  if((pfPCM=fopen("MICOut.wav", "wb")) == NULL){
    FATAL("Open output file 'MICOut.mp3' fail... !!\n");
    exit(1);
  }
  DEBUG("Initial MP3Stream End..!!\n");
#endif


}