Ejemplo n.º 1
0
bool OMXPlayerVideo::Open(OMXClock *av_clock, const OMXVideoConfig &config)
{
  if (!m_dllAvUtil.Load() || !m_dllAvCodec.Load() || !m_dllAvFormat.Load() || !av_clock)
    return false;
  
  if(ThreadHandle())
    Close();

  m_dllAvFormat.av_register_all();

  m_config      = config;
  m_av_clock    = av_clock;
  m_fps         = 25.0f;
  m_frametime   = 0;
  m_iCurrentPts = DVD_NOPTS_VALUE;
  m_bAbort      = false;
  m_flush       = false;
  m_cached_size = 0;
  m_iVideoDelay = 0;

  if(!OpenDecoder())
  {
    Close();
    return false;
  }

  if(m_config.use_thread)
    Create();

  m_open        = true;

  return true;
}
Ejemplo n.º 2
0
bool CMpegAudioDecoder::ResetDecoder()
{
	if (!m_bInitialized)
		return false;

	return OpenDecoder();
}
Ejemplo n.º 3
0
bool CAacDecoder::ResetDecoder()
{
	if (m_hDecoder == NULL)
		return false;

	return OpenDecoder();
}
Ejemplo n.º 4
0
bool OMXPlayerAudio::Open(COMXStreamInfo& hints, OMXClock *av_clock, OMXReader *omx_reader,
                          std::string device, bool passthrough, bool hw_decode,
                          bool boost_on_downmix, bool use_thread)
{
	if(ThreadHandle())
	{
		Close();
	}

	if (!av_clock)
	{
		return false;
	}


	m_hints       = hints;
	m_av_clock    = av_clock;
	m_omx_reader  = omx_reader;
	m_device      = device;
	m_passthrough = COMXAudio::ENCODED_NONE;
	m_hw_decode   = false;
	m_use_passthrough = passthrough;
	m_use_hw_decode   = hw_decode;
	m_boost_on_downmix = boost_on_downmix;
	m_iCurrentPts = DVD_NOPTS_VALUE;
	m_bAbort      = false;
	m_use_thread  = use_thread;
	m_flush       = false;
	m_cached_size = 0;
	m_pAudioCodec = NULL;
	m_pChannelMap = NULL;
	m_speed       = DVD_PLAYSPEED_NORMAL;

// m_av_clock->SetMasterClock(false);

	m_player_error = OpenAudioCodec();
	if(!m_player_error)
	{
		Close();
		return false;
	}

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

	if(m_use_thread)
	{
		Create();
	}

	m_open        = true;

	return true;
}
Ejemplo n.º 5
0
bool CMpegAudioDecoder::Open()
{
	if (!OpenDecoder())
		return false;

	ClearAudioInfo();

	return true;
}
Ejemplo n.º 6
0
bool OMXPlayerVideo::Open(
        COMXStreamInfo &hints,
        OMXClock *av_clock,
        OMX_TextureData*& textureData,
        EDEINTERLACEMODE deinterlace,
        OMX_IMAGEFILTERANAGLYPHTYPE anaglyph,
        bool hdmi_clock_sync,
        bool use_thread,
        float display_aspect,
        int display,
        int layer,
        float queue_size,
        float fifo_size
        )
{
  if (!m_dllAvUtil.Load() || !m_dllAvCodec.Load() || !m_dllAvFormat.Load() || !av_clock)
    return false;
  
  if(ThreadHandle())
    Close();

  m_dllAvFormat.av_register_all();

  m_hints       = hints;
  m_av_clock    = av_clock;
  m_fps         = 25.0f;
  m_frametime   = 0;
  m_Deinterlace = deinterlace;
  m_anaglyph    = anaglyph;
  m_display_aspect = display_aspect;
  m_iCurrentPts = DVD_NOPTS_VALUE;
  m_bAbort      = false;
  m_use_thread  = use_thread;
  m_flush       = false;
  m_cached_size = 0;
  m_iVideoDelay = 0;
  m_hdmi_clock_sync = hdmi_clock_sync;
  m_display     = display;
  m_layer       = layer;
  if (queue_size != 0.0)
    m_max_data_size = queue_size * 1024 * 1024;
  if (fifo_size != 0.0)
    m_fifo_size = fifo_size;

  if(!OpenDecoder(textureData))
  {
    Close();
    return false;
  }

  if(m_use_thread)
    Create();

  m_open        = true;

  return true;
}
Ejemplo n.º 7
0
bool OMXPlayerAudio::Open(COMXStreamInfo &hints, OMXClock *av_clock, OMXReader *omx_reader,
                          std::string device, bool passthrough, bool hw_decode,
                          bool boost_on_downmix, bool use_thread, bool is_live, enum PCMLayout layout, float queue_size, float fifo_size)
{
  if(ThreadHandle())
    Close();

  if (!m_dllAvUtil.Load() || !m_dllAvCodec.Load() || !m_dllAvFormat.Load() || !av_clock)
    return false;
  
  m_dllAvFormat.av_register_all();

  m_hints       = hints;
  m_av_clock    = av_clock;
  m_omx_reader  = omx_reader;
  m_device      = device;
  m_passthrough = false;
  m_hw_decode   = false;
  m_use_passthrough = passthrough;
  m_use_hw_decode   = hw_decode;
  m_boost_on_downmix = boost_on_downmix;
  m_iCurrentPts = DVD_NOPTS_VALUE;
  m_bAbort      = false;
  m_use_thread  = use_thread;
  m_flush       = false;
  m_flush_requested = false;
  m_live        = is_live;
  m_layout      = layout;
  m_cached_size = 0;
  m_pAudioCodec = NULL;
  if (queue_size != 0.0)
    m_max_data_size = queue_size * 1024 * 1024;
  if (fifo_size != 0.0)
    m_fifo_size = fifo_size;

  m_player_error = OpenAudioCodec();
  if(!m_player_error)
  {
    Close();
    return false;
  }

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

  if(m_use_thread)
    Create();

  m_open        = true;

  return true;
}
Ejemplo n.º 8
0
static int OpenPacketizer( vlc_object_t *p_this )
{
    decoder_t *p_dec = (decoder_t*)p_this;

    int i_ret = OpenDecoder( p_this );

    if( i_ret == VLC_SUCCESS ) p_dec->p_sys->b_packetizer = VLC_TRUE;

    return i_ret;
}
Ejemplo n.º 9
0
bool CAacDecoder::Open()
{
	if (!OpenDecoder())
		return false;

	m_AdtsParser.Reset();
	ClearAudioInfo();

	return true;
}
Ejemplo n.º 10
0
bool OMXPlayerVideo::Open(
        COMXStreamInfo &hints,
        OMXClock *av_clock,
        uint& textureId,
        bool deinterlace,
        bool mpeg,
        bool hdmi_clock_sync,
        bool use_thread,
        float display_aspect
        )
{
  if (!m_dllAvUtil.Load() || !m_dllAvCodec.Load() || !m_dllAvFormat.Load() || !av_clock)
    return false;
  
  if(ThreadHandle())
    Close();

  m_dllAvFormat.av_register_all();

  m_hints       = hints;
  m_av_clock    = av_clock;
  m_fps         = 25.0f;
  m_frametime   = 0;
  m_Deinterlace = deinterlace;
  m_display_aspect = display_aspect;
  m_bMpeg       = mpeg;
  m_iCurrentPts = DVD_NOPTS_VALUE;
  m_bAbort      = false;
  m_use_thread  = use_thread;
  m_flush       = false;
  m_cached_size = 0;
  m_iVideoDelay = 0;
  m_hdmi_clock_sync = hdmi_clock_sync;
  m_pts         = 0;
  m_syncclock   = true;
  m_speed       = DVD_PLAYSPEED_NORMAL;
  m_iSubtitleDelay = 0;
  m_pSubtitleCodec = NULL;

  m_FlipTimeStamp = m_av_clock->GetAbsoluteClock();

  if(!OpenDecoder(textureId))
  {
    Close();
    return false;
  }

  if(m_use_thread)
    Create();

  m_open        = true;

  return true;
}
Ejemplo n.º 11
0
bool OMXPlayerVideo::OpenStream(CDVDStreamInfo &hints)
{
  /*
  if(IsRunning())
    CloseStream(false);
  */

  m_hints       = hints;
  m_Deinterlace = ( CMediaSettings::Get().GetCurrentVideoSettings().m_DeinterlaceMode == VS_DEINTERLACEMODE_OFF ) ? false : true;
  m_hdmi_clock_sync = (g_guiSettings.GetInt("videoplayer.adjustrefreshrate") != ADJUST_REFRESHRATE_OFF);
  m_started     = false;
  m_flush       = false;
  m_stalled     = m_messageQueue.GetPacketCount(CDVDMsg::DEMUXER_PACKET) == 0;
  m_autosync    = 1;
  m_iSleepEndTime = DVD_NOPTS_VALUE;
  // force SetVideoRect to be called initially
  m_dst_rect.SetRect(0, 0, 0, 0);

  m_audio_count = m_av_clock->HasAudio();

  if (!m_DllBcmHost.Load())
    return false;

  if(!OpenDecoder())
  {
    return false;
  }

  if(m_messageQueue.IsInited())
    m_messageQueue.Put(new COMXMsgVideoCodecChange(hints, NULL), 0);
  else
  {
    if(!OpenStream(hints, NULL))
      return false;
    CLog::Log(LOGNOTICE, "Creating video thread");
    m_messageQueue.Init();
    Create();
  }

  /*
  if(!OpenStream(hints, NULL))
    return false;

  CLog::Log(LOGNOTICE, "Creating video thread");
  m_messageQueue.Init();
  Create();
  */

  m_open        = true;
  m_send_eos    = false;

  return true;
}
Ejemplo n.º 12
0
static int OpenPacketizer( vlc_object_t *p_this )
{
    decoder_t *p_dec = (decoder_t*)p_this;

    int i_ret = OpenDecoder( p_this );

    if( i_ret == VLC_SUCCESS )
    {
        p_dec->p_sys->b_packetizer = VLC_TRUE;
        p_dec->fmt_out.i_codec = VLC_FOURCC( 't', 'h', 'e', 'o' );
    }

    return i_ret;
}
Ejemplo n.º 13
0
bool OMXPlayerVideo::OpenStream(CDVDStreamInfo &hints)
{
  /*
  if(IsRunning())
    CloseStream(false);
  */

  m_hints       = hints;
  m_Deinterlace = ( g_settings.m_currentVideoSettings.m_DeinterlaceMode == VS_DEINTERLACEMODE_OFF ) ? false : true;
  m_flush       = false;
  m_hdmi_clock_sync = g_guiSettings.GetBool("videoplayer.adjustrefreshrate");
  m_started     = false;
  m_stalled     = m_messageQueue.GetPacketCount(CDVDMsg::DEMUXER_PACKET) == 0;
  m_autosync    = 1;

  m_audio_count = m_av_clock->HasAudio();

  if (!m_DllBcmHost.Load())
    return false;

  if(!OpenDecoder())
  {
    return false;
  }

  if(m_messageQueue.IsInited())
    m_messageQueue.Put(new COMXMsgAudioCodecChange(hints, NULL), 0);
  else
  {
    if(!OpenStream(hints, NULL))
      return false;
    CLog::Log(LOGNOTICE, "Creating video thread");
    m_messageQueue.Init();
    Create();
  }

  /*
  if(!OpenStream(hints, NULL))
    return false;

  CLog::Log(LOGNOTICE, "Creating video thread");
  m_messageQueue.Init();
  Create();
  */

  m_open        = true;

  return true;
}
Ejemplo n.º 14
0
bool OMXPlayerVideo::Open(COMXStreamInfo &hints, OMXClock *av_clock, const CRect& DestRect, EDEINTERLACEMODE deinterlace, bool hdmi_clock_sync, bool use_thread,
                             float display_aspect, float queue_size, float fifo_size)
{
  if (!m_dllAvUtil.Load() || !m_dllAvCodec.Load() || !m_dllAvFormat.Load() || !av_clock)
    return false;
  
  if(ThreadHandle())
    Close();

  m_dllAvFormat.av_register_all();

  m_hints       = hints;
  m_av_clock    = av_clock;
  m_fps         = 25.0f;
  m_frametime   = 0;
  m_Deinterlace = deinterlace;
  m_display_aspect = display_aspect;
  m_iCurrentPts = DVD_NOPTS_VALUE;
  m_bAbort      = false;
  m_use_thread  = use_thread;
  m_flush       = false;
  m_cached_size = 0;
  m_iVideoDelay = 0;
  m_hdmi_clock_sync = hdmi_clock_sync;
  m_iSubtitleDelay = 0;
  m_pSubtitleCodec = NULL;
  m_DestRect    = DestRect;
  if (queue_size != 0.0)
    m_max_data_size = queue_size * 1024 * 1024;
  if (fifo_size != 0.0)
    m_fifo_size = fifo_size;

  if(!OpenDecoder())
  {
    Close();
    return false;
  }

  if(m_use_thread)
    Create();

  m_open        = true;

  return true;
}
bool OMXEGLImagePlayer::Open(COMXStreamInfo &hints, OMXClock *av_clock, EGLImageKHR eglImage_)
{
	eglImage = eglImage_;
	ofLogVerbose() << "OMXEGLImagePlayer::maxDataSize may need to be reduced for 256 boards, memory intensive apps";

  if (!m_dllAvUtil.Load() || !m_dllAvCodec.Load() || !m_dllAvFormat.Load() || !av_clock)
  {
	  return false;
  }

	if(ThreadHandle())
	{
		Close();
	}

	m_dllAvFormat.av_register_all();

	m_hints       = hints;
	m_av_clock    = av_clock;
	m_fps         = 25.0f;
	m_frametime   = 0;
	m_iCurrentPts = DVD_NOPTS_VALUE;
	m_bAbort      = false;
	m_flush       = false;
	m_cached_size = 0;
	m_iVideoDelay = 0;
	m_pts         = 0;
	m_syncclock   = true;
	m_speed       = DVD_PLAYSPEED_NORMAL;
	m_FlipTimeStamp = m_av_clock->GetAbsoluteClock();

	if(!OpenDecoder())
	{
		Close();
		return false;
	}

	Create();
	

	m_open        = true;

	return true;
}
Ejemplo n.º 16
0
bool OMXPlayerAudio::Open(OMXClock *av_clock, const OMXAudioConfig &config, OMXReader *omx_reader)
{
    if(ThreadHandle())
        Close();

    if (!m_dllAvUtil.Load() || !m_dllAvCodec.Load() || !m_dllAvFormat.Load() || !av_clock)
        return false;

    m_dllAvFormat.av_register_all();

    m_config      = config;
    m_av_clock    = av_clock;
    m_omx_reader  = omx_reader;
    m_passthrough = false;
    m_hw_decode   = false;
    m_iCurrentPts = DVD_NOPTS_VALUE;
    m_bAbort      = false;
    m_flush       = false;
    m_flush_requested = false;
    m_cached_size = 0;
    m_pAudioCodec = NULL;

    m_player_error = OpenAudioCodec();
    if(!m_player_error)
    {
        Close();
        return false;
    }

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

    if(m_config.use_thread)
        Create();

    m_open        = true;

    return true;
}
Ejemplo n.º 17
0
bool OMXPlayerVideo::OpenStream(CDVDStreamInfo &hints)
{
  m_hints       = hints;
  m_hdmi_clock_sync = (CSettings::Get().GetInt("videoplayer.adjustrefreshrate") != ADJUST_REFRESHRATE_OFF);
  m_started     = false;
  m_flush       = false;
  m_stalled     = m_messageQueue.GetPacketCount(CDVDMsg::DEMUXER_PACKET) == 0;
  m_nextOverlay = DVD_NOPTS_VALUE;
  // force SetVideoRect to be called initially
  m_dst_rect.SetRect(0, 0, 0, 0);

  if (!m_DllBcmHost.Load())
    return false;

  if(!OpenDecoder())
  {
    return false;
  }

  if(m_messageQueue.IsInited())
    m_messageQueue.Put(new COMXMsgVideoCodecChange(hints, NULL), 0);
  else
  {
    if(!OpenStream(hints, NULL))
      return false;
    CLog::Log(LOGNOTICE, "Creating video thread");
    m_messageQueue.Init();
    Create();
  }

  m_open        = true;
  m_iCurrentPts = DVD_NOPTS_VALUE;
  m_nextOverlay = DVD_NOPTS_VALUE;

  return true;
}
Ejemplo n.º 18
0
bool OMXPlayerAudio::Decode(DemuxPacket *pkt, bool bDropPacket)
{
  if(!pkt || m_bad_state || !m_pAudioCodec)
    return false;

  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) && !bDropPacket)
  {
    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())
      {
        m_DecoderOpen = OpenDecoder();
        if(!m_DecoderOpen)
          return false;
      }

      while(!m_bStop)
      {
        // discard if flushing as clocks may be stopped and we'll never submit it
        if(m_flush)
          break;

        if(m_omxAudio.GetSpace() < (unsigned int)decoded_size)
        {
          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);
          }
        }

        break;

      }
    }
  }
  else if(!bDropPacket)
  {
    if(CodecChange())
    {
      m_DecoderOpen = OpenDecoder();
      if(!m_DecoderOpen)
        return false;
    }

    while(!m_bStop)
    {
      if(m_flush)
        break;

      if(m_omxAudio.GetSpace() < (unsigned int)pkt->iSize)
      {
        Sleep(10);
        continue;
      }
        
      if(!bDropPacket)
      {
        if(m_silence)
          memset(pkt->pData, 0x0, pkt->iSize);

        m_omxAudio.AddPackets(pkt->pData, pkt->iSize, m_audioClock, m_audioClock);
      }

      m_audioStats.AddSampleBytes(pkt->iSize);

      break;
    }
  }

  if(bDropPacket)
    m_stalled = false;

  // signal to our parent that we have initialized
  if(m_started == false)
  {
    m_started = true;
    m_messageParent.Put(new CDVDMsgInt(CDVDMsg::PLAYER_STARTED, DVDPLAYER_AUDIO));
  }

  return true;
}
Ejemplo 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;
}
Ejemplo n.º 20
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;
  }
Ejemplo n.º 21
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;
}
Ejemplo n.º 22
0
bool OMXPlayerAudio::Decode(DemuxPacket *pkt, bool bDropPacket)
{
  if(!pkt || m_bad_state || !m_pAudioCodec)
    return false;

  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())
      {
        m_DecoderOpen = OpenDecoder();
        if(!m_DecoderOpen)
          return false;
      }

      while(!m_bStop)
      {
        HandlePlayspeed(bDropPacket);
        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())
Ejemplo n.º 23
0
bool OMXPlayerAudio::Open(COMXStreamInfo &hints, OMXClock *av_clock, OMXReader *omx_reader,
                          std::string device, bool passthrough, long initialVolume, bool hw_decode,
                          bool boost_on_downmix, bool use_thread, float queue_size, float fifo_size)
{
  if(ThreadHandle())
    Close();

  if (!m_dllAvUtil.Load() || !m_dllAvCodec.Load() || !m_dllAvFormat.Load() || !av_clock)
    return false;
  
  m_dllAvFormat.av_register_all();

  m_hints       = hints;
  m_av_clock    = av_clock;
  m_omx_reader  = omx_reader;
  m_device      = device;
  m_passthrough = IAudioRenderer::ENCODED_NONE;
  m_hw_decode   = false;
  m_use_passthrough = passthrough;
  m_use_hw_decode   = hw_decode;
  m_boost_on_downmix = boost_on_downmix;
  m_iCurrentPts = DVD_NOPTS_VALUE;
  m_bAbort      = false;
  m_bMpeg       = m_omx_reader->IsMpegVideo();
  m_use_thread  = use_thread;
  m_flush       = false;
  m_cached_size = 0;
  m_pAudioCodec = NULL;
  m_pChannelMap = NULL;
  m_speed       = DVD_PLAYSPEED_NORMAL;
  m_initialVolume = initialVolume;
  if (queue_size != 0.0)
    m_max_data_size = queue_size * 1024 * 1024;
  if (fifo_size != 0.0)
    m_fifo_size = fifo_size;

  m_error = 0;
  m_errorbuff = 0;
  m_errorcount = 0;
  m_integral = 0;
  m_skipdupcount = 0;
  m_prevskipped = false;
  m_syncclock = true;
  m_errortime = m_av_clock->CurrentHostCounter();

  m_freq = m_av_clock->CurrentHostFrequency();

  m_av_clock->SetMasterClock(false);

  m_player_error = OpenAudioCodec();
  if(!m_player_error)
  {
    Close();
    return false;
  }

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

  if(m_use_thread)
    Create();

  m_open        = true;

  return true;
}
Ejemplo n.º 24
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;
}
Ejemplo n.º 25
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;
  }
}
Ejemplo n.º 26
0
static int OpenDecoderNdk(vlc_object_t *p_this)
{
    return OpenDecoder(p_this, MediaCodecNdk_Init);
}
Ejemplo n.º 27
0
bool OMXPlayerAudio::Decode(DemuxPacket *pkt, bool bDropPacket, bool bTrickPlay)
{
  if(!pkt || m_bad_state || !m_pAudioCodec)
    return false;

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

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

  if (bTrickPlay)
  {
    settings_changed = true;
  }
  else if(m_format.m_dataFormat != AE_FMT_RAW && !bDropPacket)
  {
    double dts = pkt->dts, pts=pkt->pts;
    while(!m_bStop && data_len > 0)
    {
      int len = m_pAudioCodec->Decode((BYTE *)data_dec, data_len, dts, pts);
      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, dts, pts);

      if(decoded_size <=0)
        continue;

      int ret = 0;

      m_audioStats.AddSampleBytes(decoded_size);

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

      while(!m_bStop)
      {
        // discard if flushing as clocks may be stopped and we'll never submit it
        if(m_flush)
          break;

        if(m_omxAudio.GetSpace() < (unsigned int)decoded_size)
        {
          Sleep(10);
          continue;
        }
        
        if(!bDropPacket)
        {
          ret = m_omxAudio.AddPackets(decoded, decoded_size, dts, pts, m_pAudioCodec->GetFrameSize(), settings_changed);
          if(ret != decoded_size)
          {
            CLog::Log(LOGERROR, "error ret %d decoded_size %d\n", ret, decoded_size);
          }
        }

        break;

      }
    }
  }
  else if(!bDropPacket)
  {
    if(CodecChange())
    {
      m_DecoderOpen = OpenDecoder();
      if(!m_DecoderOpen)
        return false;
    }

    while(!m_bStop)
    {
      if(m_flush)
        break;

      if(m_omxAudio.GetSpace() < (unsigned int)pkt->iSize)
      {
        Sleep(10);
        continue;
      }
        
      if(!bDropPacket)
      {
        m_omxAudio.AddPackets(pkt->pData, pkt->iSize, m_audioClock, m_audioClock, 0, settings_changed);
      }

      m_audioStats.AddSampleBytes(pkt->iSize);

      break;
    }
  }

  if(bDropPacket || bTrickPlay)
    m_stalled = false;

  // signal to our parent that we have initialized
  if (m_syncState == IDVDStreamPlayer::SYNC_STARTING && !bDropPacket && settings_changed)
  {
    m_syncState = IDVDStreamPlayer::SYNC_WAITSYNC;
    SStartMsg msg;
    msg.player = VideoPlayer_AUDIO;
    msg.cachetotal = DVD_SEC_TO_TIME(m_omxAudio.GetCacheTotal());
    msg.cachetime = DVD_SEC_TO_TIME(m_omxAudio.GetCacheTime());
    msg.timestamp = m_audioClock;
    m_messageParent.Put(new CDVDMsgType<SStartMsg>(CDVDMsg::PLAYER_STARTED, msg));
  }

  return true;
}
Ejemplo n.º 28
0
static int OpenDecoderJni(vlc_object_t *p_this)
{
    return OpenDecoder(p_this, MediaCodecJni_Init);
}