int Play_Decoder()
{
    int i;
    int Size=0;
    DEBUG_PRINT("Inside %s \n", __FUNCTION__);
    OMX_ERRORTYPE ret;
    OMX_INDEXTYPE index;

    DEBUG_PRINT("sizeof[%d]\n", sizeof(OMX_BUFFERHEADERTYPE));

    /* open the i/p and o/p files based on the video file format passed */
    if(open_audio_file()) {
        DEBUG_PRINT("\n Returning -1");
    return -1;
    }

    /*  Configuration of Input Port definition */

    /* Query the decoder input min buf requirements */
    CONFIG_VERSION_SIZE(inputportFmt);

    /* Port for which the Client needs to obtain info */
    inputportFmt.nPortIndex = portParam.nStartPortNumber;

    OMX_GetParameter(aac_dec_handle,OMX_IndexParamPortDefinition,&inputportFmt);
    DEBUG_PRINT ("\nDec: Input Buffer Count %lu\n", inputportFmt.nBufferCountMin);
    DEBUG_PRINT ("\nDec: Input Buffer Size %lu\n", inputportFmt.nBufferSize);

    if(OMX_DirInput != inputportFmt.eDir) {
        DEBUG_PRINT ("\nDec: Expect Input Port\n");
    return -1;
    }

    inputportFmt.nBufferCountActual = inputportFmt.nBufferCountMin + 5;
    OMX_SetParameter(aac_dec_handle,OMX_IndexParamPortDefinition,&inputportFmt);
    OMX_GetExtensionIndex(aac_dec_handle,"OMX.Qualcomm.index.audio.sessionId",&index);
    OMX_GetParameter(aac_dec_handle,index,&streaminfoparam);
#ifdef AUDIOV2
    session_id = streaminfoparam.sessionId;
	devmgr_fd = open("/data/omx_devmgr", O_WRONLY);
	if(devmgr_fd >= 0)
	{
		control = 0;
		write_devctlcmd(devmgr_fd, "-cmd=register_session_rx -sid=", session_id);
	}
	else
	{
		/*control = msm_mixer_open("/dev/snd/controlC0", 0);
		if(control < 0)
		printf("ERROR opening the device\n");
		device_id = msm_get_device(device);
		device_id = 2;
		DEBUG_PRINT ("\ndevice_id = %d\n",device_id);
		DEBUG_PRINT("\nsession_id = %d\n",session_id);
		if (msm_en_device(device_id, 1))
		{
			perror("could not enable device\n");
			return -1;
		}

		if (msm_route_stream(1,session_id,device_id, 1))
		{
			perror("could not set stream routing\n");
			return -1;
		}
		*/
	}
#endif
    /*  Configuration of Ouput Port definition */

    /* Query the decoder outport's min buf requirements */
    CONFIG_VERSION_SIZE(outputportFmt);
    /* Port for which the Client needs to obtain info */
    outputportFmt.nPortIndex = portParam.nStartPortNumber + 1;

    OMX_GetParameter(aac_dec_handle,OMX_IndexParamPortDefinition,&outputportFmt);
    DEBUG_PRINT ("\nDec: Output Buffer Count %lu\n", outputportFmt.nBufferCountMin);
    DEBUG_PRINT ("\nDec: Output Buffer Size %lu\n", outputportFmt.nBufferSize);

    if(OMX_DirOutput != outputportFmt.eDir) {
        DEBUG_PRINT ("\nDec: Expect Output Port\n");
    return -1;
    }

    outputportFmt.nBufferCountActual = outputportFmt.nBufferCountMin + 3;
    OMX_SetParameter(aac_dec_handle,OMX_IndexParamPortDefinition,&outputportFmt);

    CONFIG_VERSION_SIZE(aacparam);
    aacparam.nPortIndex   =  0;
    aacparam.nChannels    =  channels; //2 ; /* 1-> mono 2-> stereo*/
    aacparam.nBitRate     =  samplerate; //SAMPLE_RATE;
    aacparam.nSampleRate  =  samplerate; //SAMPLE_RATE;
    aacparam.eChannelMode =  OMX_AUDIO_ChannelModeStereo;
    if (sbr_ps_enabled == 0 )
        aacparam.eAACProfile = OMX_AUDIO_AACObjectLC;
    else if (sbr_ps_enabled == 1 )
        aacparam.eAACProfile = OMX_AUDIO_AACObjectHE;
    else if (sbr_ps_enabled == 2 )
        aacparam.eAACProfile = OMX_AUDIO_AACObjectHE_PS;
    aacparam.eAACStreamFormat    =  OMX_AUDIO_AACStreamFormatMP2ADTS;
    OMX_SetParameter(aac_dec_handle,OMX_IndexParamAudioAac,&aacparam);


    DEBUG_PRINT ("\nOMX_SendCommand Decoder -> IDLE\n");
    OMX_SendCommand(aac_dec_handle, OMX_CommandStateSet, OMX_StateIdle,0);
    /* wait_for_event(); should not wait here event complete status will
       not come until enough buffer are allocated */

    input_buf_cnt = inputportFmt.nBufferCountActual; //  inputportFmt.nBufferCountMin + 5;
    DEBUG_PRINT("Transition to Idle State succesful...\n");
    /* Allocate buffer on decoder's i/p port */
    error = Allocate_Buffer(aac_dec_handle, &pInputBufHdrs, inputportFmt.nPortIndex,
                            input_buf_cnt, inputportFmt.nBufferSize);
    if (error != OMX_ErrorNone) {
        DEBUG_PRINT ("\nOMX_AllocateBuffer Input buffer error\n");
    return -1;
    }
    else {
        DEBUG_PRINT ("\nOMX_AllocateBuffer Input buffer success\n");
    }

    output_buf_cnt = outputportFmt.nBufferCountActual; // outputportFmt.nBufferCountMin ;

    /* Allocate buffer on decoder's O/Pp port */
    error = Allocate_Buffer(aac_dec_handle, &pOutputBufHdrs, outputportFmt.nPortIndex,
                            output_buf_cnt, outputportFmt.nBufferSize);
    if (error != OMX_ErrorNone) {
        DEBUG_PRINT ("\nOMX_AllocateBuffer Output buffer error\n");
    return -1;
    }
    else {
        DEBUG_PRINT ("\nOMX_AllocateBuffer Output buffer success\n");
    }

    wait_for_event();


    DEBUG_PRINT ("\nOMX_SendCommand Decoder -> Executing\n");
    OMX_SendCommand(aac_dec_handle, OMX_CommandStateSet, OMX_StateExecuting,0);
    wait_for_event();

    DEBUG_PRINT(" Start sending OMX_FILLthisbuffer\n");
    for(i=0; i < output_buf_cnt; i++) {
        DEBUG_PRINT ("\nOMX_FillThisBuffer on output buf no.%d\n",i);
        pOutputBufHdrs[i]->nOutputPortIndex = 1;
        pOutputBufHdrs[i]->nFlags = 0;
        ret = OMX_FillThisBuffer(aac_dec_handle, pOutputBufHdrs[i]);
        if (OMX_ErrorNone != ret) {
            DEBUG_PRINT("OMX_FillThisBuffer failed with result %d\n", ret);
        }
        else {
            DEBUG_PRINT("OMX_FillThisBuffer success!\n");
        }
    }

    DEBUG_PRINT(" Start sending OMX_emptythisbuffer\n");
    for (i = 0;i < input_buf_cnt;i++) {
        DEBUG_PRINT ("\nOMX_EmptyThisBuffer on Input buf no.%d\n",i);
        pInputBufHdrs[i]->nInputPortIndex = 0;
        Size = Read_Buffer(pInputBufHdrs[i]);
        if(Size <=0 ){
          DEBUG_PRINT("NO DATA READ\n");
          //bInputEosReached = true;
          bEosOnInputBuf = true;
          pInputBufHdrs[i]->nFlags= OMX_BUFFERFLAG_EOS;
        }
        pInputBufHdrs[i]->nFilledLen = Size;
        pInputBufHdrs[i]->nInputPortIndex = 0;
        used_ip_buf_cnt++;
        ret = OMX_EmptyThisBuffer(aac_dec_handle, pInputBufHdrs[i]);
        if (OMX_ErrorNone != ret) {
            DEBUG_PRINT("OMX_EmptyThisBuffer failed with result %d\n", ret);
        }
        else {
            DEBUG_PRINT("OMX_EmptyThisBuffer success!\n");
        }
        if(Size <=0 ){
            break;//eos reached
        }
    }
    pthread_mutex_lock(&etb_lock);
    if(etb_done)
    {
        DEBUG_PRINT("Component is waiting for EBD to be released.\n");
        etb_event_complete();
    }
    else
    {
        DEBUG_PRINT("\n****************************\n");
        DEBUG_PRINT("EBD not yet happened ...\n");
        DEBUG_PRINT("\n****************************\n");
        etb_done++;
    }
    pthread_mutex_unlock(&etb_lock);
    while(1)
    {
        wait_for_event();
        if(bOutputEosReached)
        {
            bReconfigureOutputPort = 0;
            printf("bOutputEosReached breaking\n");
            break;
        }
        else
        {
            if(bReconfigureOutputPort)
               process_portreconfig();
        }
    }
    return 0;
}
Exemple #2
0
int Play_Decoder()
{
    int i;
    int Size=0;
    DEBUG_PRINT("Inside %s \n", __FUNCTION__);
    OMX_ERRORTYPE ret;
    OMX_STATETYPE state;
    unsigned int bufCnt=0;
#ifdef PCM_PLAYBACK
        struct msm_audio_pcm_config drv_pcm_config;
#endif  // PCM_PLAYBACK

    DEBUG_PRINT("sizeof[%d]\n", sizeof(OMX_BUFFERHEADERTYPE));

    /* open the i/p and o/p files based on the video file format passed */
    if(open_audio_file()) {
        DEBUG_PRINT("\n Returning -1");
    return -1;
    }
    /* Query the decoder input min buf requirements */
    CONFIG_VERSION_SIZE(inputportFmt);

    /* Port for which the Client needs to obtain info */
    inputportFmt.nPortIndex = portParam.nStartPortNumber;

    OMX_GetParameter(aac_dec_handle,OMX_IndexParamPortDefinition,&inputportFmt);
    DEBUG_PRINT ("\nDec: Input Buffer Count %d\n", inputportFmt.nBufferCountMin);
    DEBUG_PRINT ("\nDec: Input Buffer Size %d\n", inputportFmt.nBufferSize);

    if(OMX_DirInput != inputportFmt.eDir) {
        DEBUG_PRINT ("\nDec: Expect Input Port\n");
    return -1;
    }

if(tunnel == 0)
{
    /* Query the decoder outport's min buf requirements */
    CONFIG_VERSION_SIZE(outputportFmt);
    /* Port for which the Client needs to obtain info */
    outputportFmt.nPortIndex = portParam.nStartPortNumber + 1;

    OMX_GetParameter(aac_dec_handle,OMX_IndexParamPortDefinition,&outputportFmt);
    DEBUG_PRINT ("\nDec: Output Buffer Count %d\n", outputportFmt.nBufferCountMin);
    DEBUG_PRINT ("\nDec: Output Buffer Size %d\n", outputportFmt.nBufferSize);

    if(OMX_DirOutput != outputportFmt.eDir) {
        DEBUG_PRINT ("\nDec: Expect Output Port\n");
    return -1;
    }
}

    CONFIG_VERSION_SIZE(aacparam);


    aacparam.nPortIndex   =  0;
    aacparam.nChannels    =  channels; //2 ; /* 1-> mono 2-> stereo*/
    aacparam.nBitRate     =  samplerate; //SAMPLE_RATE;
    aacparam.nSampleRate  =  samplerate; //SAMPLE_RATE;
    aacparam.eChannelMode =  OMX_AUDIO_ChannelModeStereo;
    if (sbr_ps_enabled == 0 )
        aacparam.eAACProfile = OMX_AUDIO_AACObjectLC;
    else if (sbr_ps_enabled == 1 )
        aacparam.eAACProfile = OMX_AUDIO_AACObjectHE;
    else if (sbr_ps_enabled == 2 )
        aacparam.eAACProfile = OMX_AUDIO_AACObjectHE_PS;
    aacparam.eAACStreamFormat    =  OMX_AUDIO_AACStreamFormatMP2ADTS;
    OMX_SetParameter(aac_dec_handle,OMX_IndexParamAudioAac,&aacparam);


#ifdef PCM_PLAYBACK
if(pcmplayback == 1)
{
          DEBUG_PRINT(" open pcm device \n");
          m_pcmdrv_fd = open("/dev/msm_pcm_out", O_RDWR);
          if (m_pcmdrv_fd < 0) {
            DEBUG_PRINT("Play_Decoder: cannot open audio device");

          }
          DEBUG_PRINT(" Play_Decoder: open pcm device successfull\n");
}
#endif  // PCM_PLAYBACK


#ifdef PCM_PLAYBACK
if(pcmplayback == 1)
{
        DEBUG_PRINT("configure Driver for PCM playback \n");
        ioctl(m_pcmdrv_fd, AUDIO_GET_CONFIG, &drv_pcm_config);
        drv_pcm_config.sample_rate = samplerate; //SAMPLE_RATE; //m_adec_param.nSampleRate;
        drv_pcm_config.channel_count = channels; //STEREO;
       // drv_pcm_config.in_buf_size  = OMX_AAC_OUTPUT_BUFFER_SIZE ;
        ioctl(m_pcmdrv_fd, AUDIO_SET_CONFIG, &drv_pcm_config);
      //  ioctl(m_pcmdrv_fd, AUDIO_START, 0);
}
#endif //PCM_PLAYBACK


    DEBUG_PRINT ("\nOMX_SendCommand Decoder -> IDLE\n");
    OMX_SendCommand(aac_dec_handle, OMX_CommandStateSet, OMX_StateIdle,0);
    /* wait_for_event(); should not wait here event complete status will
       not come until enough buffer are allocated */

    input_buf_cnt = inputportFmt.nBufferCountMin + 5;
    DEBUG_PRINT("Transition to Idle State succesful...\n");
    /* Allocate buffer on decoder's i/p port */
    error = Allocate_Buffer(aac_dec_handle, &pInputBufHdrs, inputportFmt.nPortIndex,
                            input_buf_cnt, inputportFmt.nBufferSize);
    if (error != OMX_ErrorNone) {
        DEBUG_PRINT ("\nOMX_AllocateBuffer Input buffer error\n");
    return -1;
    }
    else {
        DEBUG_PRINT ("\nOMX_AllocateBuffer Input buffer success\n");
    }

if(tunnel == 0)
{
    output_buf_cnt = outputportFmt.nBufferCountMin ;

    /* Allocate buffer on decoder's O/Pp port */
    error = Allocate_Buffer(aac_dec_handle, &pOutputBufHdrs, outputportFmt.nPortIndex,
                            output_buf_cnt, outputportFmt.nBufferSize);
    if (error != OMX_ErrorNone) {
        DEBUG_PRINT ("\nOMX_AllocateBuffer Output buffer error\n");
    return -1;
    }
    else {
        DEBUG_PRINT ("\nOMX_AllocateBuffer Output buffer success\n");
    }
}

    wait_for_event();


if (tunnel == 1)
{
    DEBUG_PRINT ("\nOMX_SendCommand to enable TUNNEL MODE during IDLE\n");
    OMX_SendCommand(aac_dec_handle, OMX_CommandPortDisable,1,0);
    wait_for_event();
}

    DEBUG_PRINT ("\nOMX_SendCommand Decoder -> Executing\n");
    OMX_SendCommand(aac_dec_handle, OMX_CommandStateSet, OMX_StateExecuting,0);
    wait_for_event();

    DEBUG_PRINT(" Start sending OMX_emptythisbuffer\n");
    for (i = 0;i < input_buf_cnt;i++) {
        DEBUG_PRINT ("\nOMX_EmptyThisBuffer on Input buf no.%d\n",i);
        pInputBufHdrs[i]->nInputPortIndex = 0;
        Size = Read_Buffer(pInputBufHdrs[i]);
        if(Size <=0 ){
          DEBUG_PRINT("NO DATA READ\n");
        }
        pInputBufHdrs[i]->nFilledLen = Size;
        pInputBufHdrs[i]->nInputPortIndex = 0;
        used_ip_buf_cnt++;
        ret = OMX_EmptyThisBuffer(aac_dec_handle, pInputBufHdrs[i]);
        if (OMX_ErrorNone != ret) {
            DEBUG_PRINT("OMX_EmptyThisBuffer failed with result %d\n", ret);
        }
        else {
            DEBUG_PRINT("OMX_EmptyThisBuffer success!\n");
        }
    }

    // wait for port settings changed event
    wait_for_event();
    DEBUG_PRINT("************************************");
    DEBUG_PRINT("RECIEVED EVENT PORT SETTINGS CHANGED EVENT\n");
    DEBUG_PRINT("******************************************\n");

    DEBUG_PRINT("************************************");
    DEBUG_PRINT("NOW SENDING FLUSH CMD\n");
    DEBUG_PRINT("******************************************\n");
    OMX_SendCommand(aac_dec_handle, OMX_CommandFlush, 1, 0);

    wait_for_event();
    DEBUG_PRINT("************************************");
    DEBUG_PRINT("RECIEVED FLUSH EVENT CMPL\n");
    DEBUG_PRINT("******************************************\n");

    // Send DISABLE command
    OMX_SendCommand(aac_dec_handle, OMX_CommandPortDisable, 1, 0);

    DEBUG_PRINT("******************************************\n");
    DEBUG_PRINT("FREEING BUFFERS output_buf_cnt=%d\n",output_buf_cnt);
    DEBUG_PRINT("******************************************\n");
    // Free output Buffer
    for(bufCnt=0; bufCnt < output_buf_cnt; ++bufCnt) {
        OMX_FreeBuffer(aac_dec_handle, 1, pOutputBufHdrs[bufCnt]);
    }

    // wait for Disable event to come back
    wait_for_event();
    DEBUG_PRINT("******************************************\n");
    DEBUG_PRINT("DISABLE EVENT RECD\n");
    DEBUG_PRINT("******************************************\n");

        // Send Enable command
    OMX_SendCommand(aac_dec_handle, OMX_CommandPortEnable, 1, 0);

    // AllocateBuffers
    DEBUG_PRINT("******************************************\n");
    DEBUG_PRINT("ALLOC BUFFER AFTER PORT REENABLE");
    DEBUG_PRINT("******************************************\n");
    /* Allocate buffer on decoder's o/p port */
    error = Allocate_Buffer(aac_dec_handle, &pOutputBufHdrs, outputportFmt.nPortIndex,
                            output_buf_cnt, outputportFmt.nBufferSize);
    if (error != OMX_ErrorNone) {
        DEBUG_PRINT ("\nOMX_AllocateBuffer Output buffer error output_buf_cnt=%d\n",output_buf_cnt);
        return -1;
    }
    else
    {
        DEBUG_PRINT ("\nOMX_AllocateBuffer Output buffer success output_buf_cnt=%d\n",output_buf_cnt);
    }

    DEBUG_PRINT("******************************************\n");
    DEBUG_PRINT("ENABLE EVENTiHANDLER RECD\n");
    DEBUG_PRINT("******************************************\n");
    // wait for enable event to come back
    wait_for_event();

    DEBUG_PRINT("******************************************\n");
    DEBUG_PRINT("FTB after PORT RENABLE\n");
    DEBUG_PRINT("******************************************\n");
    for(i=0; i < output_buf_cnt; i++) {
        DEBUG_PRINT ("\nOMX_FillThisBuffer on output buf no.%d\n",i);
        pOutputBufHdrs[i]->nOutputPortIndex = 1;
        //pOutputBufHdrs[i]->nFlags &= ~OMX_BUFFERFLAG_EOS;
        ret = OMX_FillThisBuffer(aac_dec_handle, pOutputBufHdrs[i]);
        if (OMX_ErrorNone != ret) {
            DEBUG_PRINT("OMX_FillThisBuffer failed with result %d\n", ret);
    }
        else {
            DEBUG_PRINT("OMX_FillThisBuffer success!\n");
    }
    }

    return 0;
}
void process_portreconfig ( )
{
    int bufCnt,i=0;
    OMX_ERRORTYPE ret;
    struct msm_audio_config drv_pcm_config;
    //wait_for_event();
    DEBUG_PRINT("************************************");
    DEBUG_PRINT("RECIEVED EVENT PORT SETTINGS CHANGED EVENT\n");
    DEBUG_PRINT("******************************************\n");

    // wait for port settings changed event
    DEBUG_PRINT("************************************");
    DEBUG_PRINT("NOW SENDING FLUSH CMD\n");
    DEBUG_PRINT("******************************************\n");
    flushinprogress = 1;
    OMX_SendCommand(aac_dec_handle, OMX_CommandFlush, 1, 0);

    wait_for_event();
    DEBUG_PRINT("************************************");
    DEBUG_PRINT("RECIEVED FLUSH EVENT CMPL\n");
    DEBUG_PRINT("******************************************\n");

    // Send DISABLE command
    OMX_SendCommand(aac_dec_handle, OMX_CommandPortDisable, 1, 0);

    DEBUG_PRINT("******************************************\n");
    DEBUG_PRINT("FREEING BUFFERS output_buf_cnt=%d\n",output_buf_cnt);
    DEBUG_PRINT("******************************************\n");
    // Free output Buffer
    for(bufCnt=0; bufCnt < output_buf_cnt; ++bufCnt) {
        OMX_FreeBuffer(aac_dec_handle, 1, pOutputBufHdrs[bufCnt]);
    }

    // wait for Disable event to come back
    wait_for_event();
    DEBUG_PRINT("******************************************\n");
    DEBUG_PRINT("DISABLE EVENT RECD\n");
    DEBUG_PRINT("******************************************\n");

        // Send Enable command
    OMX_SendCommand(aac_dec_handle, OMX_CommandPortEnable, 1, 0);
    flushinprogress = 0;
    // AllocateBuffers
    DEBUG_PRINT("******************************************\n");
    DEBUG_PRINT("ALLOC BUFFER AFTER PORT REENABLE");
    DEBUG_PRINT("******************************************\n");
    /* Allocate buffer on decoder's o/p port */
    error = Allocate_Buffer(aac_dec_handle, &pOutputBufHdrs, outputportFmt.nPortIndex,
                            output_buf_cnt, outputportFmt.nBufferSize);
    if (error != OMX_ErrorNone) {
        DEBUG_PRINT ("\nOMX_AllocateBuffer Output buffer error output_buf_cnt=%d\n",output_buf_cnt);
        //return -1;
    }
    else
    {
        DEBUG_PRINT ("\nOMX_AllocateBuffer Output buffer success output_buf_cnt=%d\n",output_buf_cnt);
    }

    DEBUG_PRINT("******************************************\n");
    DEBUG_PRINT("ENABLE EVENTiHANDLER RECD\n");
    DEBUG_PRINT("******************************************\n");
    // wait for enable event to come back
    wait_for_event();
    DEBUG_PRINT(" Calling stop on pcm driver...\n");
    if(pcmplayback && start_done)
    {
        while (fsync(m_pcmdrv_fd) < 0) {
        printf(" fsync failed\n");
        sleep(1);
        }
        ioctl(m_pcmdrv_fd, AUDIO_STOP, 0);
        ioctl(m_pcmdrv_fd, AUDIO_FLUSH, 0);
        sleep(3);
        DEBUG_PRINT("AUDIO_STOP\n");
        OMX_GetParameter(aac_dec_handle,OMX_IndexParamAudioAac,&aacparam);
        drv_pcm_config.sample_rate = aacparam.nSampleRate;
        drv_pcm_config.channel_count = aacparam.nChannels;
        printf("sample =%lu channel = %lu\n",aacparam.nSampleRate,aacparam.nChannels);
        ioctl(m_pcmdrv_fd, AUDIO_SET_CONFIG, &drv_pcm_config);
        DEBUG_PRINT("Configure Driver for PCM playback \n");
        start_done = 0;
        bReconfigureOutputPort = 0;
    }

    DEBUG_PRINT("******************************************\n");
    DEBUG_PRINT("FTB after PORT RENABLE\n");
    DEBUG_PRINT("******************************************\n");
    for(i=0; i < output_buf_cnt; i++) {
        DEBUG_PRINT ("\nOMX_FillThisBuffer on output buf no.%d\n",i);
        pOutputBufHdrs[i]->nOutputPortIndex = 1;
        //pOutputBufHdrs[i]->nFlags &= ~OMX_BUFFERFLAG_EOS;
        ret = OMX_FillThisBuffer(aac_dec_handle, pOutputBufHdrs[i]);
        if (OMX_ErrorNone != ret) {
            DEBUG_PRINT("OMX_FillThisBuffer failed with result %d\n", ret);
        }
        else {
            DEBUG_PRINT("OMX_FillThisBuffer success!\n");
    }
   }
}