Exemplo n.º 1
0
bool OMXPlayerAudio::Close()
{
	m_bAbort  = true;
	m_flush   = true;

	Flush();

	if(ThreadHandle())
	{
		Lock();
		pthread_cond_broadcast(&m_packet_cond);
		UnLock();

		StopThread("OMXPlayerAudio");
	}

	CloseDecoder();
	CloseAudioCodec();

	m_open          = false;
	m_stream_id     = -1;
	m_iCurrentPts   = DVD_NOPTS_VALUE;
	m_pStream       = NULL;
	m_speed         = DVD_PLAYSPEED_NORMAL;


	return true;
}
Exemplo n.º 2
0
bool OMXPlayerAudio::CloseStream(bool bWaitForBuffers)
{
  // wait until buffers are empty
  if (bWaitForBuffers && m_speed > 0) m_messageQueue.WaitUntilEmpty();

  m_messageQueue.Abort();

  if(IsRunning())
    StopThread();

  m_messageQueue.End();

  if (m_pAudioCodec)
  {
    m_pAudioCodec->Dispose();
    delete m_pAudioCodec;
    m_pAudioCodec = NULL;
  }

  CloseDecoder();

  m_speed         = DVD_PLAYSPEED_NORMAL;
  m_started       = false;

  return true;
}
Exemplo n.º 3
0
bool CAacDecoder::OpenDecoder()
{
	CloseDecoder();

	// FAAD2オープン
	m_hDecoder = ::NeAACDecOpen();
	if (m_hDecoder == NULL)
		return false;

	// デフォルト設定取得
	NeAACDecConfigurationPtr pDecodeConfig = ::NeAACDecGetCurrentConfiguration(m_hDecoder);

	// デコーダ設定
	pDecodeConfig->defObjectType = LC;
	pDecodeConfig->defSampleRate = 48000UL;
	pDecodeConfig->outputFormat = FAAD_FMT_16BIT;
	pDecodeConfig->downMatrix = 0;
	pDecodeConfig->useOldADTSFormat = 0;

	if (!::NeAACDecSetConfiguration(m_hDecoder, pDecodeConfig)) {
		Close();
		return false;
	}

	m_bInitRequest = true;
	m_LastChannelConfig = 0xFF;
	m_bDecodeError = false;

	return true;
}
Exemplo n.º 4
0
bool OMXPlayerVideo::OpenDecoder()
{
  if (m_hints.fpsrate && m_hints.fpsscale)
    m_fps = DVD_TIME_BASE / OMXReader::NormalizeFrameduration((double)DVD_TIME_BASE * m_hints.fpsscale / m_hints.fpsrate);
  else
    m_fps = 25;

  if( m_fps > 100 || m_fps < 5 )
  {
    printf("Invalid framerate %d, using forced 25fps and just trust timestamps\n", (int)m_fps);
    m_fps = 25;
  }

  m_frametime = (double)DVD_TIME_BASE / m_fps;

  m_decoder = new COMXVideo();
  if(!m_decoder->Open(m_hints, m_av_clock, m_Deinterlace, m_hdmi_clock_sync))
  {
    CloseDecoder();
    return false;
  }
  else
  {
    printf("Video codec %s width %d height %d profile %d fps %f\n",
        m_decoder->GetDecoderName().c_str() , m_hints.width, m_hints.height, m_hints.profile, m_fps);
  }

  if(m_av_clock)
    m_av_clock->SetRefreshRate(m_fps);

  return true;
}
Exemplo n.º 5
0
bool OMXPlayerAudio::Close()
{
  m_bAbort  = true;

  Flush();

  if(ThreadHandle())
  {
    Lock();
    pthread_cond_broadcast(&m_packet_cond);
    UnLock();

    StopThread();
  }

  CloseDecoder();
  CloseAudioCodec();

  m_open          = false;
  m_stream_id     = -1;
  m_iCurrentPts   = DVD_NOPTS_VALUE;
  m_pStream       = NULL;

  m_dllAvUtil.Unload();
  m_dllAvCodec.Unload();
  m_dllAvFormat.Unload();

  return true;
}
Exemplo n.º 6
0
bool OMXPlayerVideoBase::Close()
{
	m_bAbort  = true;
	m_flush   = true;
	
	Flush();
	
	if(ThreadHandle())
	{
		Lock();
		pthread_cond_broadcast(&m_packet_cond);
		UnLock();
		
		StopThread();
	}
	
	CloseDecoder();
	
	m_dllAvUtil.Unload();
	m_dllAvCodec.Unload();
	m_dllAvFormat.Unload();
	
	m_open          = false;
	m_stream_id     = -1;
	m_iCurrentPts   = DVD_NOPTS_VALUE;
	m_pStream       = NULL;
	m_pts           = 0;
	m_speed         = DVD_PLAYSPEED_NORMAL;
	
	return true;
}
Exemplo n.º 7
0
bool OMXPlayerVideo::OpenDecoder()
{
  if (m_hints.fpsrate && m_hints.fpsscale)
    m_fps = DVD_TIME_BASE / OMXReader::NormalizeFrameduration((double)DVD_TIME_BASE * m_hints.fpsscale / m_hints.fpsrate);
  else
    m_fps = 25;

  if( m_fps > 100 || m_fps < 5 )
  {
    printf("Invalid framerate %d, using forced 25fps and just trust timestamps\n", (int)m_fps);
    m_fps = 25;
  }

  m_frametime = (double)DVD_TIME_BASE / m_fps;

  m_decoder = new COMXVideo();
  if(!m_decoder->Open(m_hints, m_av_clock, m_DestRect, m_display_aspect, m_Deinterlace, m_hdmi_clock_sync, m_fifo_size))
  {
    CloseDecoder();
    return false;
  }
  else
  {
    printf("Video codec %s width %d height %d profile %d fps %f\n",
        m_decoder->GetDecoderName().c_str() , m_hints.width, m_hints.height, m_hints.profile, m_fps);
  }

  // start from assuming all recent frames had valid pts
  m_history_valid_pts = ~0;

  return true;
}
void CMpeg2DecoderDXVA2::CloseDecoderService()
{
	DBG_TRACE(TEXT("CMpeg2DecoderDXVA2::CloseDecoderService()"));

	CloseDecoder();

	SafeRelease(m_pDecoderService);
	SafeRelease(m_pDeviceManager);
	m_pFilter = nullptr;
	m_SurfaceFormat = D3DFMT_UNKNOWN;
}
Exemplo n.º 9
0
bool CMpegAudioDecoder::OpenDecoder()
{
	CloseDecoder();

	mad_stream_init(&m_MadStream);
	mad_frame_init(&m_MadFrame);
	mad_synth_init(&m_MadSynth);

	m_bInitialized = true;
	m_bDecodeError = false;

	return true;
}
bool OMXEGLImagePlayer::OpenDecoder()
{
	if (m_hints.fpsrate && m_hints.fpsscale)
	{
		m_fps = DVD_TIME_BASE / OMXReader::NormalizeFrameduration((double)DVD_TIME_BASE * m_hints.fpsscale / m_hints.fpsrate);
	}else
	{
		m_fps = 25;
	}

	if( m_fps > 100 || m_fps < 5 )
	{
		ofLog(OF_LOG_VERBOSE, "OMXEGLImagePlayer::OpenDecoder: Invalid framerate %d, using forced 25fps and just trust timestamps\n", (int)m_fps);
		m_fps = 25;
	}

	m_frametime = (double)DVD_TIME_BASE / m_fps;

	m_decoder = new OMXEGLImage();
	if(!m_decoder->Open(m_hints, m_av_clock, eglImage))
	{
		CloseDecoder();
		return false;
	}
	else
	{
		if (doDebugging) 
		{
			m_decoder->doDebugging = true;
		}
	  
		ofLog(OF_LOG_VERBOSE, "Video codec %s width %d height %d profile %d fps %f\n",
			  m_decoder->GetDecoderName().c_str() , m_hints.width, m_hints.height, m_hints.profile, m_fps);
	}

	if(m_av_clock)
	{
		m_av_clock->SetRefreshRate(m_fps);
	}
	
	return true;
}
Exemplo n.º 11
0
bool OMXPlayerVideo::Close()
{
  m_bAbort  = true;

  Flush();

  if(ThreadHandle())
  {
    Lock();
    pthread_cond_broadcast(&m_packet_cond);
    UnLock();

    StopThread();
  }

  CloseDecoder();

  m_open          = false;
  m_stream_id     = -1;
  m_iCurrentPts   = DVD_NOPTS_VALUE;
  m_pStream       = NULL;

  return true;
}
Exemplo n.º 12
0
void CMpegAudioDecoder::Close()
{
	CloseDecoder();
}
HRESULT CMpeg2DecoderDXVA2::CreateDecoder(IDirect3DSurface9 **ppSurface, int SurfaceCount)
{
	DBG_TRACE(TEXT("CMpeg2DecoderDXVA2::CreateDecoder()"));

	if (!ppSurface)
		return E_POINTER;
	if (!m_pFilter || !m_pDecoderService)
		return E_UNEXPECTED;

	CloseDecoder();

	HRESULT hr;

	GUID guidDecoder;
	if (!FindDecoder(&guidDecoder, nullptr, &m_SurfaceFormat, 1)) {
		DBG_ERROR(TEXT("Decoder not found"));
		return E_FAIL;
	}

	DXVA2_VideoDesc VideoDesc = {};

	VideoDesc.SampleWidth = m_pFilter->GetAlignedWidth();
	VideoDesc.SampleHeight = m_pFilter->GetAlignedHeight();
	VideoDesc.SampleFormat.SampleFormat = DXVA2_SampleFieldInterleavedEvenFirst;
	VideoDesc.SampleFormat.VideoChromaSubsampling = DXVA2_VideoChromaSubsampling_MPEG2;
	VideoDesc.SampleFormat.NominalRange = DXVA2_NominalRange_16_235;
	VideoDesc.SampleFormat.VideoTransferMatrix = DXVA2_VideoTransferMatrix_BT709;
	VideoDesc.SampleFormat.VideoLighting = DXVA2_VideoLighting_dim;
	VideoDesc.SampleFormat.VideoPrimaries = DXVA2_VideoPrimaries_BT709;
	VideoDesc.SampleFormat.VideoTransferFunction = DXVA2_VideoTransFunc_709;
	VideoDesc.Format = m_SurfaceFormat;

	UINT Count;
	DXVA2_ConfigPictureDecode *pConfigs;
	hr = m_pDecoderService->GetDecoderConfigurations(
		guidDecoder, &VideoDesc, nullptr, &Count, &pConfigs);
	if (FAILED(hr)) {
		DBG_ERROR(TEXT("GetDecoderConfigurations() failed (%x)"), hr);
		return hr;
	}

	int SelConfig = -1;
	for (UINT i = 0; i < Count; i++) {
		if (pConfigs[i].ConfigBitstreamRaw == 1) {
			SelConfig = i;
			break;
		}
	}
	if (SelConfig < 0) {
		::CoTaskMemFree(pConfigs);
		return E_FAIL;
	}

	IDirectXVideoDecoder *pVideoDecoder;
	hr = m_pDecoderService->CreateVideoDecoder(
		guidDecoder,
		&VideoDesc,
		&pConfigs[SelConfig],
		ppSurface,
		SurfaceCount,
		&pVideoDecoder);
	::CoTaskMemFree(pConfigs);
	if (FAILED(hr)) {
		DBG_ERROR(TEXT("CreateVideoDecoder() failed (%x)"), hr);
		return hr;
	}
	m_pVideoDecoder = pVideoDecoder;

	return hr;
}
Exemplo n.º 14
0
bool OMXPlayerAudio::Decode(OMXPacket *pkt)
{
  if(!pkt)
    return false;

  /* last decoder reinit went wrong */
  if(!m_decoder || !m_pAudioCodec)
    return true;

  if(!m_omx_reader->IsActive(OMXSTREAM_AUDIO, pkt->stream_index))
    return true; 

  int channels = pkt->hints.channels;

  unsigned int old_bitrate = m_hints.bitrate;
  unsigned int new_bitrate = pkt->hints.bitrate;

  /* only check bitrate changes on CODEC_ID_DTS, CODEC_ID_AC3, CODEC_ID_EAC3 */
  if(m_hints.codec != CODEC_ID_DTS && m_hints.codec != CODEC_ID_AC3 && m_hints.codec != CODEC_ID_EAC3)
  {
    new_bitrate = old_bitrate = 0;
  }

  /* audio codec changed. reinit device and decoder */
  if(m_hints.codec         != pkt->hints.codec ||
     m_hints.channels      != channels ||
     m_hints.samplerate    != pkt->hints.samplerate ||
     old_bitrate           != new_bitrate ||
     m_hints.bitspersample != pkt->hints.bitspersample)
  {
    printf("C : %d %d %d %d %d\n", m_hints.codec, m_hints.channels, m_hints.samplerate, m_hints.bitrate, m_hints.bitspersample);
    printf("N : %d %d %d %d %d\n", pkt->hints.codec, channels, pkt->hints.samplerate, pkt->hints.bitrate, pkt->hints.bitspersample);

    m_av_clock->OMXPause();

    CloseDecoder();
    CloseAudioCodec();

    m_hints = pkt->hints;

    m_player_error = OpenAudioCodec();
    if(!m_player_error)
      return false;

    m_player_error = OpenDecoder();
    if(!m_player_error)
      return false;

    m_av_clock->OMXStateExecute();
    m_av_clock->OMXReset();
    m_av_clock->OMXResume();

  }

  if(!((int)m_decoder->GetSpace() > pkt->size))
    OMXClock::OMXSleep(10);

  if((int)m_decoder->GetSpace() > pkt->size)
  {
    if(pkt->dts != DVD_NOPTS_VALUE)
      m_iCurrentPts = pkt->dts;

    m_av_clock->SetPTS(m_iCurrentPts);

    const uint8_t *data_dec = pkt->data;
    int            data_len = pkt->size;

    if(!m_passthrough && !m_hw_decode)
    {
      while(data_len > 0)
      {
        int len = m_pAudioCodec->Decode((BYTE *)data_dec, data_len);
        if( (len < 0) || (len >  data_len) )
        {
          m_pAudioCodec->Reset();
          break;
        }

        data_dec+= len;
        data_len -= len;

        uint8_t *decoded;
        int decoded_size = m_pAudioCodec->GetData(&decoded);

        if(decoded_size <=0)
          continue;

        int ret = 0;

        if(m_bMpeg)
          ret = m_decoder->AddPackets(decoded, decoded_size, DVD_NOPTS_VALUE, DVD_NOPTS_VALUE);
        else
          ret = m_decoder->AddPackets(decoded, decoded_size, m_iCurrentPts, m_iCurrentPts);

        if(ret != decoded_size)
        {
          printf("error ret %d decoded_size %d\n", ret, decoded_size);
        }

        int n = (m_hints.channels * 32 * m_hints.samplerate)>>3;
        if (n > 0 && m_iCurrentPts != DVD_NOPTS_VALUE)
          m_iCurrentPts += ((double)decoded_size * DVD_TIME_BASE) / n;

        HandleSyncError((((double)decoded_size * DVD_TIME_BASE) / n), m_iCurrentPts);
      }
    }
    else
    {
      if(m_bMpeg)
        m_decoder->AddPackets(pkt->data, pkt->size, DVD_NOPTS_VALUE, DVD_NOPTS_VALUE);
      else
        m_decoder->AddPackets(pkt->data, pkt->size, m_iCurrentPts, m_iCurrentPts);

      HandleSyncError(0, m_iCurrentPts);
    }

    m_av_clock->SetAudioClock(m_iCurrentPts);
    return true;
  }
Exemplo n.º 15
0
bool OMXPlayerAudio::Decode(OMXPacket *pkt)
{
  if(!pkt)
    return false;

  /* last decoder reinit went wrong */
  if(!m_decoder || !m_pAudioCodec)
    return true;

  if(!m_omx_reader->IsActive(OMXSTREAM_AUDIO, pkt->stream_index))
    return true; 

  int channels = pkt->hints.channels;

  /* 6 channel have to be mapped to 8 for PCM */
  if(!m_passthrough && !m_hw_decode)
  {
    if(channels == 6)
      channels = 8;
  }
 
  unsigned int old_bitrate = m_hints.bitrate;
  unsigned int new_bitrate = pkt->hints.bitrate;

  /* only check bitrate changes on CODEC_ID_DTS, CODEC_ID_AC3, CODEC_ID_EAC3 */
  if(m_hints.codec != CODEC_ID_DTS && m_hints.codec != CODEC_ID_AC3 && m_hints.codec != CODEC_ID_EAC3)
  {
    new_bitrate = old_bitrate = 0;
  }

  /* audio codec changed. reinit device and decoder */
  if(m_hints.codec         != pkt->hints.codec ||
     m_hints.channels      != channels ||
     m_hints.samplerate    != pkt->hints.samplerate ||
     old_bitrate           != new_bitrate ||
     m_hints.bitspersample != pkt->hints.bitspersample)
  {
    ofLog(OF_LOG_VERBOSE, "C : %d %d %d %d %d\n", m_hints.codec, m_hints.channels, m_hints.samplerate, m_hints.bitrate, m_hints.bitspersample);
     ofLog(OF_LOG_VERBOSE, "N : %d %d %d %d %d\n", pkt->hints.codec, channels, pkt->hints.samplerate, pkt->hints.bitrate, pkt->hints.bitspersample);


    CloseDecoder();
    CloseAudioCodec();

    m_hints = pkt->hints;

    m_player_error = OpenAudioCodec();
    if(!m_player_error)
      return false;

    m_player_error = OpenDecoder();
    if(!m_player_error)
      return false;

    m_av_clock->OMXStateExecute();
    m_av_clock->OMXReset();
    m_av_clock->OMXResume();

  }

  if(!((int)m_decoder->GetSpace() > pkt->size))
    OMXClock::OMXSleep(10);

  if((int)m_decoder->GetSpace() > pkt->size)
  {
	  if(pkt->pts != DVD_NOPTS_VALUE)
		  m_iCurrentPts = pkt->pts;
	  else if(pkt->dts != DVD_NOPTS_VALUE)
		  m_iCurrentPts = pkt->dts;

    const uint8_t *data_dec = pkt->data;
    int            data_len = pkt->size;

    if(!m_passthrough && !m_hw_decode)
    {
      while(data_len > 0)
      {
        int len = m_pAudioCodec->Decode((BYTE *)data_dec, data_len);
        if( (len < 0) || (len >  data_len) )
        {
          m_pAudioCodec->Reset();
          break;
        }

        data_dec+= len;
        data_len -= len;

        uint8_t *decoded;
        int decoded_size = m_pAudioCodec->GetData(&decoded);

        if(decoded_size <=0)
          continue;

        int ret = 0;

        ret = m_decoder->AddPackets(decoded, decoded_size, pkt->dts, pkt->pts);

        if(ret != decoded_size)
        {
          ofLog(OF_LOG_VERBOSE, "error ret %d decoded_size %d\n", ret, decoded_size);
        }
      }
    }
    else
    {
		m_decoder->AddPackets(pkt->data, pkt->size, pkt->dts, pkt->pts);
    }
    return true;
  }
  else
  {
    return false;
  }
}
Exemplo n.º 16
0
bool OMXPlayerAudio::Decode(DemuxPacket *pkt, bool bDropPacket)
{
  if(!pkt)
    return false;

  /* last decoder reinit went wrong */
  if(!m_pAudioCodec)
    return true;

  if(pkt->dts != DVD_NOPTS_VALUE)
    m_audioClock = pkt->dts;

  const uint8_t *data_dec = pkt->pData;
  int            data_len = pkt->iSize;

  if(!OMX_IS_RAW(m_format.m_dataFormat))
  {
    while(!m_bStop && data_len > 0)
    {
      int len = m_pAudioCodec->Decode((BYTE *)data_dec, data_len);
      if( (len < 0) || (len >  data_len) )
      {
        m_pAudioCodec->Reset();
        break;
      }

      data_dec+= len;
      data_len -= len;

      uint8_t *decoded;
      int decoded_size = m_pAudioCodec->GetData(&decoded);

      if(decoded_size <=0)
        continue;

      int ret = 0;

      m_audioStats.AddSampleBytes(decoded_size);

      if(CodecChange())
      {
        CloseDecoder();

        m_DecoderOpen = OpenDecoder();
        if(!m_DecoderOpen)
          return false;
      }

      while(!m_bStop)
      {
        if(m_flush)
        {
          m_flush = false;
          break;
        }

        if(m_omxAudio.GetSpace() < (unsigned int)pkt->iSize)
        {
          Sleep(10);
          continue;
        }
        
        if(!bDropPacket)
        {
          // Zero out the frame data if we are supposed to silence the audio
          if(m_silence)
            memset(decoded, 0x0, decoded_size);

          ret = m_omxAudio.AddPackets(decoded, decoded_size, m_audioClock, m_audioClock);

          if(ret != decoded_size)
          {
            CLog::Log(LOGERROR, "error ret %d decoded_size %d\n", ret, decoded_size);
          }
        }

        int n = (m_nChannels * m_hints.bitspersample * m_hints.samplerate)>>3;
        if (n > 0)
          m_audioClock += ((double)decoded_size * DVD_TIME_BASE) / n;

        if(m_speed == DVD_PLAYSPEED_NORMAL)
          HandleSyncError((((double)decoded_size * DVD_TIME_BASE) / n));
        break;

      }
    }
  }
  else
  {
    if(CodecChange())
Exemplo n.º 17
0
/*!
 ***********************************************************************
 * \brief
 *    main function for JM decoder
 ***********************************************************************
 */
int main(int argc, char **argv)
{
	struct timeval start, end;
	gettimeofday( &start, NULL );
	
  int iRet;
  //DecodedPicList *pDecPicList;
  int iFramesDecoded=0;
  InputParameters InputParams;

  if((g_encrypt_fileh = fopen(g_encrypt_file, "w+")) == NULL)
  {
	  printf("encrypt file open fail!\n");
	  return -1;
  }

#if H264_KEY_LOG 
  if((g_key_log_fileh = fopen(g_key_log_file, "a+")) == NULL)
  {
	  printf("encrypt file open fail!\n");
	  return -1;
  }
#endif  

  //init_time();

  //get input parameters;
  Configure(&InputParams, argc, argv);

	//open decoder;
  iRet = OpenDecoder(&InputParams);	//打开trace,h264bitstream文件
  if(iRet != DEC_OPEN_NOERR)
  {
    fprintf(stderr, "Open encoder failed: 0x%x!\n", iRet);
    return -1; //failed;
  }

	p_Dec->nalu_pos_array = calloc(200,sizeof(int));
	
  do
  {
    iRet = DecodeOneFrame();	
  }while((iRet == DEC_SUCCEED) && ((p_Dec->p_Inp->iDecFrmNum==0) || (iFramesDecoded<p_Dec->p_Inp->iDecFrmNum)));
	
  iRet = FinitDecoder();
  iRet = CloseDecoder();	//包含report输出

  
  printf("%d frames are decoded.\n", iFramesDecoded);
  printf("%ld MVs found!\n", NumberOfMV);
  printf("%ld P MVs found!\n", NumberOfBMV);
  printf("%ld B MVs found!\n", NumberOfPMV);
  
#if TRACE
	printf("defined trace!\n");
#endif  

#if H264_KEY_LOG
	char s[200];
	snprintf(s,200,"max_mvd_BOffset: %4d, min_KeyData_Len: %2d, max_KeyData_Len: %4d\n",
	p_Dec->max_MVD_BOffset,p_Dec->min_KeyData_Len,p_Dec->max_KeyData_Len);		
	//fwrite(s,strlen(s),1,g_key_log_fileh);

	char s2[200];

	int i =0;
	for(;i<p_Dec->nalu_pos_array_idx;++i)
	{
		snprintf(s2,200,"%2d: %5d\n",i,p_Dec->nalu_pos_array[i]);		
		fwrite(s2,strlen(s2),1,g_key_log_fileh);		
	}
	fclose(g_key_log_fileh);	
#else	
	fclose(g_encrypt_fileh);
#endif

	gettimeofday( &end, NULL );
	long int time_us = 1000000 * ( end.tv_sec - start.tv_sec ) + end.tv_usec - start.tv_usec;
	printf("run time: %ld us\n",time_us);
  return 0;
}
Exemplo n.º 18
0
bool OMXPlayerAudio::Decode(OMXPacket *pkt)
{
  if(!pkt)
    return false;

  /* last decoder reinit went wrong */
  if(!m_decoder || !m_pAudioCodec)
    return true;

  if(!m_omx_reader->IsActive(OMXSTREAM_AUDIO, pkt->stream_index))
    return true; 

  int channels = pkt->hints.channels;

  unsigned int old_bitrate = m_hints.bitrate;
  unsigned int new_bitrate = pkt->hints.bitrate;

  /* only check bitrate changes on CODEC_ID_DTS, CODEC_ID_AC3, CODEC_ID_EAC3 */
  if(m_hints.codec != CODEC_ID_DTS && m_hints.codec != CODEC_ID_AC3 && m_hints.codec != CODEC_ID_EAC3)
  {
    new_bitrate = old_bitrate = 0;
  }

  // for passthrough we only care about the codec and the samplerate
  bool minor_change = channels                 != m_hints.channels ||
                      pkt->hints.bitspersample != m_hints.bitspersample ||
                      old_bitrate              != new_bitrate;

  if(pkt->hints.codec          != m_hints.codec ||
     pkt->hints.samplerate     != m_hints.samplerate ||
     (!m_passthrough && minor_change))
  {
    printf("C : %d %d %d %d %d\n", m_hints.codec, m_hints.channels, m_hints.samplerate, m_hints.bitrate, m_hints.bitspersample);
    printf("N : %d %d %d %d %d\n", pkt->hints.codec, channels, pkt->hints.samplerate, pkt->hints.bitrate, pkt->hints.bitspersample);


    CloseDecoder();
    CloseAudioCodec();

    m_hints = pkt->hints;

    m_player_error = OpenAudioCodec();
    if(!m_player_error)
      return false;

    m_player_error = OpenDecoder();
    if(!m_player_error)
      return false;
  }

  CLog::Log(LOGINFO, "CDVDPlayerAudio::Decode dts:%.0f pts:%.0f size:%d", pkt->dts, pkt->pts, pkt->size);

  if(pkt->pts != DVD_NOPTS_VALUE)
    m_iCurrentPts = pkt->pts;
  else if(pkt->dts != DVD_NOPTS_VALUE)
    m_iCurrentPts = pkt->dts;

  const uint8_t *data_dec = pkt->data;
  int            data_len = pkt->size;

  if(!m_passthrough && !m_hw_decode)
  {
    while(data_len > 0)
    {
      int len = m_pAudioCodec->Decode((BYTE *)data_dec, data_len);
      if( (len < 0) || (len >  data_len) )
      {
        m_pAudioCodec->Reset();
        break;
      }

      data_dec+= len;
      data_len -= len;

      uint8_t *decoded;
      int decoded_size = m_pAudioCodec->GetData(&decoded);

      if(decoded_size <=0)
        continue;

      while((int) m_decoder->GetSpace() < decoded_size)
      {
        OMXClock::OMXSleep(10);
        if(m_flush_requested) return true;
      }

      int ret = 0;

      ret = m_decoder->AddPackets(decoded, decoded_size, pkt->dts, pkt->pts);
      if(ret != decoded_size)
      {
        printf("error ret %d decoded_size %d\n", ret, decoded_size);
      }
    }
  }
  else
  {
    while((int) m_decoder->GetSpace() < pkt->size)
    {
      OMXClock::OMXSleep(10);
      if(m_flush_requested) return true;
    }

    m_decoder->AddPackets(pkt->data, pkt->size, pkt->dts, pkt->pts);
  }

  return true;
}
Exemplo n.º 19
0
int main(int argc, char **argv)
{
	struct timeval start, end1, end2;
	long int time_us1,time_us2;
	gettimeofday( &start, NULL );
	
  int iRet;
  InputParameters InputParams;
  init_time();

  //get input parameters;
  Configure(&InputParams, argc, argv);
  //open decoder;
  iRet = OpenDecoder(&InputParams);
  if(iRet != DEC_OPEN_NOERR)
  {
    fprintf(stderr, "Open encoder failed: 0x%x!\n", iRet);
    return -1; //failed;
  }

	init_GenKeyPar();
	
  //decoding;
  do
  {
    iRet = DecodeOneFrame();
    if(iRet==DEC_EOS || iRet==DEC_SUCCEED)
    {

    }
    else
    {
      //error handling;
      fprintf(stderr, "Error in decoding process: 0x%x\n", iRet);
    }
  }while((iRet == DEC_SUCCEED) /*&& ((p_Dec->p_Inp->iDecFrmNum==0) || (iFramesDecoded<p_Dec->p_Inp->iDecFrmNum))*/);

	gettimeofday( &end1, NULL );
	time_us1 = 1000000 * ( end1.tv_sec - start.tv_sec ) + end1.tv_usec - start.tv_usec;
	printf("\nrun time0: %ld us\n",time_us1);

	//encrypt the H.264 file
	printf("key unit count: %d\n",g_KeyUnitIdx);

	int ret;
	void* status;
	pthread_attr_t attr;

	/*********use multi thread********/
	if(p_Dec->p_Inp->multi_thread == 1)
	{
		pthread_attr_t attr;
						
		ret = pthread_attr_destroy(&p_Dec->thread_attr);
		if (ret != 0)
		{
			printf("pthread_attr_destroy error: %s\n",strerror(ret));
		}
	}

	ThreadUnitPar* par = NULL;
	par = (ThreadUnitPar*)malloc(sizeof(ThreadUnitPar));
	if(!par)
	{
		printf("malloc failed!\n");
		exit(1);
	}
	memset(par,0,sizeof(ThreadUnitPar));
	
	if(p_Dec->p_Inp->multi_thread)  
	{
		//deal with the rest KU buffer data
		if(g_KeyUnitBufferLen <= MAX_THREAD_DO_KEY_UNIT_CNT)
		{
			par->buffer_start = g_KeyUnitIdx - g_KeyUnitBufferLen;
			par->buffer_len = g_KeyUnitBufferLen;
			par->cur_absolute_offset = g_ThreadParCurPos;
			Encrypt(par);
		}

		int i;
		for(i = 0; i < p_Dec->pid_id; ++i)
		{
			pthread_join(p_Dec->pid[i], &status);
		}
	}
	else
	{		
		par->buffer_start = 0;
		par->buffer_len = g_KeyUnitIdx;
		par->cur_absolute_offset = g_pKeyUnitBuffer[0].byte_offset;
		Encrypt(par);
		//encryt_thread(par);
	}

	gettimeofday( &end2, NULL );
	time_us2 = 1000000 * ( end2.tv_sec - end1.tv_sec ) + end2.tv_usec - end1.tv_usec;
	printf("run time1: %ld us\n",time_us2);

	//print_KeyUnit();

	deinit_GenKeyPar();
  iRet = FinitDecoder();
  iRet = CloseDecoder();	

	fflush(NULL);
	printf("run time(all): %ld us\n", time_us1+time_us2);
  return 0;
}
Exemplo n.º 20
0
void CAacDecoder::Close()
{
	CloseDecoder();
	m_AdtsParser.Reset();
	m_pAdtsFrame = NULL;
}