Exemplo n.º 1
0
bool OMXAudioPlayer::close()
{
    doAbort  = true;
    doFlush   = true;

    flush();

    if(ThreadHandle())
    {
        lock();
        pthread_cond_broadcast(&m_packet_cond);
        unlock();

        StopThread("OMXAudioPlayer");
    }

    closeDecoder();
    closeCodec();

    isOpen          = false;
    currentPTS   = DVD_NOPTS_VALUE;
    speed         = DVD_PLAYSPEED_NORMAL;


    return true;
}
Exemplo n.º 2
0
void DataSource::close() {
    av_free(m_rawFrame);
    closeCodec();
    closeInputFile();
}
Exemplo n.º 3
0
bool OMXAudioPlayer::decode(OMXPacket *pkt)
{
    if(!pkt)
    {
        return false;
    }

    /* last decoder reinit went wrong */
    if(!decoder || !audioCodecOMX)
    {
        return true;
    }

    if(!omxReader->isActive(OMXSTREAM_AUDIO, pkt->stream_index))
    {
        return true;
    }

    int channels = pkt->hints.channels;

    /* 6 channel have to be mapped to 8 for PCM */
    if(channels == 6)
    {
        channels = 8;
    }

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

    /* only check bitrate changes on AV_CODEC_ID_DTS, AV_CODEC_ID_AC3, AV_CODEC_ID_EAC3 */
    if(omxStreamInfo.codec != AV_CODEC_ID_DTS && omxStreamInfo.codec != AV_CODEC_ID_AC3 && omxStreamInfo.codec != AV_CODEC_ID_EAC3)
    {
        new_bitrate = old_bitrate = 0;
    }

    /* audio codec changed. reinit device and decoder */
    if(omxStreamInfo.codec!= pkt->hints.codec ||
            omxStreamInfo.channels != channels ||
            omxStreamInfo.samplerate != pkt->hints.samplerate ||
            old_bitrate != new_bitrate ||
            omxStreamInfo.bitspersample != pkt->hints.bitspersample)
    {

        closeDecoder();
        closeCodec();

        omxStreamInfo = pkt->hints;


        ofLogError(__func__) << "AUDIO ERROR " << __LINE__ << " omxStreamInfo: " << omxStreamInfo.toString();
        hasErrors = true;
        return false;
    }

#if 1
    if(!((int)decoder->GetSpace() > pkt->size))
    {
        omxClock->sleep(10);
    }

    if((int)decoder->GetSpace() > pkt->size)
    {
        if(pkt->pts != DVD_NOPTS_VALUE)
        {
            currentPTS = pkt->pts;
        }
        else if(pkt->dts != DVD_NOPTS_VALUE)
        {
            currentPTS = pkt->dts;
        }

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

        while(data_len > 0)
        {
            int len = audioCodecOMX->decode((BYTE *)data_dec, data_len);
            if( (len < 0) || (len >  data_len) )
            {
                audioCodecOMX->Reset();
                break;
            }

            data_dec+= len;
            data_len -= len;

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

            if(decoded_size <=0)
            {
                continue;
            }

            int ret = 0;

            ret = decoder->addPackets(decoded, decoded_size, pkt->dts, pkt->pts);

            if(ret != decoded_size)
            {
                ofLogError(__func__) << "ret : " << ret << " NOT EQUAL TO " << decoded_size;
            }
        }

        return true;
    }
    else
    {
        return false;
    }
#endif
}