Exemplo n.º 1
0
/**
 * @brief VoiceEndpoint::handleFrame
 * @param data
 * Handles raw unframed packet for audio endpoint
 * It handles both - bitstream and stop packet
 * When bitstream stops it fires a timer to detect timeout and cleanup session
 * Important: response should be made within 2000ms window after stop
 */
void VoiceEndpoint::handleFrame(const QByteArray &data)
{
    WatchDataReader reader(data);
    quint8 cmd = reader.read<quint8>();
    quint16 sid = reader.readLE<quint16>();

    if(cmd == FrmDataTransfer) {
        if(sid == m_sessId) {
            AudioStream str;
            str.count = reader.read<quint8>();
            for(int i=0;i<str.count;i++) {
                Frame frm;
                frm.length = reader.read<quint8>();
                frm.data = reader.readBytes(frm.length);
                str.frames.append(frm);
            }
            emit audioFrame(sid,str);
            m_sesPhase = PhAudioStarted;
        } else {
            stopAudioStream(sid);
        }
    } else if(cmd == FrmStopTransfer) {
        if(sid != m_sessId)
            return;
        if(m_sesTimer)
            killTimer(m_sesTimer);
        qDebug() << "Pebble finished sending audio at session" << m_sessId;
        emit audioFrame(m_sessId,AudioStream());
        m_sesPhase = PhAudioStopped;
        m_sesTimer = startTimer(1500);
    } else {
        qWarning() << "Unknown audio frame type" << data.toHex();
    }
}
Exemplo n.º 2
0
void AudioDecoder::flushAudioBuffer() {
	if (m_audioBuffer.empty()) {
		// Nothing to do here
		return;
	}

	AudioFramePtr audioFrame(new AudioFrame());
	audioFrame->channels = OUT_NUM_CHANNELS;
	audioFrame->rate = OUT_SAMPLE_RATE;

	audioFrame->audioData.assign(m_audioBuffer.begin(), m_audioBuffer.end());

	pushFrame(std::move(audioFrame));
	m_audioBuffer.clear();
}
Exemplo n.º 3
0
uint8_t DIA_builtin(void)
{
  uint32_t altivec=0,mad=0,a52dec=0,xvid4=0,X264=0,freetype=0,esd=0,arts=0,vorbis=0,win32=0;
  uint32_t faac=0,faad=0,libdca=0,aften=0,libamrnb=0,lame=0,sdl=0,oss=0,xvideo=0,x86=0,x86_64=0,alsa=0;
  uint32_t adm_powerpc=0,adm_gettext=0,adm_fontconfig=0;
#ifdef USE_FONTCONFIG
  adm_fontconfig=1;
#endif
#ifdef USE_ALTIVEC
        altivec=1;
#endif
#ifdef USE_MP3
        mad=1;
#endif
#ifdef USE_AC3
        a52dec=1;
#endif
#ifdef USE_XVID_4
        xvid4=1;
#endif
#ifdef USE_X264
        X264=1;
#endif
#ifdef USE_FREETYPE
        freetype=1;
#endif
#ifdef USE_ESD
        esd=1;
#endif
#ifdef USE_ARTS
        arts=1;
#endif
#ifdef USE_VORBIS
        vorbis=1;
#endif
#ifdef ADM_WIN32
        win32=1;
#endif
#ifdef USE_FAAC
        faac=1;
#endif
#ifdef USE_FAAD
        faad=1;
#endif
#ifdef USE_LIBDCA
	if (dca->isAvailable())
        libdca=1;
#endif
#ifdef USE_AFTEN
        aften=1;
#endif
#ifdef USE_AMR_NB
	if (amrnb->isAvailable())
		libamrnb=1;
#endif
#ifdef HAVE_LIBMP3LAME
	lame=1;
#endif
#ifdef USE_SDL
	sdl=1;
#endif
#ifdef OSS_SUPPORT
	oss=1;
#endif
#ifdef ALSA_SUPPORT
	alsa=1;
#endif

#ifdef USE_XV
	xvideo=1;
#endif
#ifdef ARCH_X86
	x86=1;
#endif
#ifdef ARCH_X86_64
	x86_64=1;
#endif
#ifdef ARCH_POWERPC
	adm_powerpc=1;
#endif
#ifdef HAVE_GETTEXT
	adm_gettext=1;
#endif
    
	diaElemFrame videoFrame(QT_TR_NOOP("Video Codecs"));
	diaElemNotch tXvid4(xvid4, QT_TR_NOOP("Xvid"));
	diaElemNotch tX264(X264, QT_TR_NOOP("x264"));

	videoFrame.swallow(&tXvid4);
	videoFrame.swallow(&tX264);

	diaElemFrame audioFrame(QT_TR_NOOP("Audio Codecs"));	
	diaElemNotch tAften(aften, QT_TR_NOOP("Aften"));	
	diaElemNotch tLibamrnb(libamrnb, QT_TR_NOOP("amrnb"));
    diaElemNotch tFaac(faac, QT_TR_NOOP("FAAC"));
    diaElemNotch tFaad(faad, QT_TR_NOOP("FAAD2"));
	diaElemNotch tLame(lame, QT_TR_NOOP("LAME"));
	diaElemNotch tA52dec(a52dec, QT_TR_NOOP("liba52"));
	diaElemNotch tLibdca(libdca, QT_TR_NOOP("libdca"));
	diaElemNotch tMad(mad, QT_TR_NOOP("MAD"));
	diaElemNotch tVorbis(vorbis, QT_TR_NOOP("Vorbis"));

	audioFrame.swallow(&tAften);
	audioFrame.swallow(&tLibamrnb);	
	audioFrame.swallow(&tFaac);
	audioFrame.swallow(&tFaad);
	audioFrame.swallow(&tLame);
	audioFrame.swallow(&tA52dec);
	audioFrame.swallow(&tLibdca);
	audioFrame.swallow(&tMad);
	audioFrame.swallow(&tVorbis);

	diaElemNotch tArts(arts, QT_TR_NOOP("aRts"));
	diaElemNotch tEsd(esd, QT_TR_NOOP("ESD"));
        diaElemNotch tFontConfig(adm_fontconfig, QT_TR_NOOP("Fontconfig"));
	diaElemNotch tFreetype(freetype, QT_TR_NOOP("FreeType 2"));
	diaElemNotch tGettext(adm_gettext, QT_TR_NOOP("Gettext"));
        diaElemNotch tAlsa(alsa, QT_TR_NOOP("ALSA"));
	diaElemNotch tOss(oss, QT_TR_NOOP("OSS"));
	diaElemNotch tSdl(sdl, QT_TR_NOOP("SDL"));
	diaElemNotch tXvideo(xvideo, QT_TR_NOOP("XVideo"));

	diaElemNotch tAltivec(altivec, QT_TR_NOOP("AltiVec"));
	diaElemNotch tPowerPc(adm_powerpc, QT_TR_NOOP("PowerPC"));
	diaElemNotch tX86(x86, QT_TR_NOOP("x86"));
	diaElemNotch tX86_64(x86_64, QT_TR_NOOP("x86-64"));


	diaElem *codecElems[] = {&videoFrame, &audioFrame};
	diaElem *libsElems[] = {&tArts, &tEsd, &tFontConfig, &tFreetype, &tGettext, &tAlsa, &tOss, &tSdl, &tXvideo};
	diaElem *CPUElems[] = {&tAltivec, &tPowerPc, &tX86, &tX86_64};

	diaElemTabs tabCodec(QT_TR_NOOP("Codecs"), 2, codecElems);
	diaElemTabs tabLibs(QT_TR_NOOP("Libraries"), 9, libsElems);
	diaElemTabs tabCPU(QT_TR_NOOP("CPU"), 4, CPUElems);

	diaElemTabs *tabs[] = {&tabCodec, &tabLibs, &tabCPU};

    diaFactoryRunTabs(QT_TR_NOOP("Built-in Support"), 3, tabs);

    return 1;
}
Exemplo n.º 4
0
void CCAudioDecoder::Run()
{
    AudioDecoderStatus status = AUDIO_DECODER_STATUS_ENUM_UNKNOW;

    AVFormatContext* pAVFormatCtx = NULL;
    AVCodecContext* pAudioCodecCtx = NULL;
    AVRational audioTimeBase;

    AVFrame* pDecodedFrame = NULL;
    int gotFrame = 0;
    int decodedLen = 0;

    int audioFrameQueueSize = 0;

    bool bDataManagerEof = false;

    while(m_bRunning)
    {
        SmartPtr<Event> event;
        if(PopFrontMessage(event))
        {
            switch(event.GetPtr()->type)
            {
                case MESSAGE_TYPE_ENUM_FINDED_AUDIO_STREAM:
                {
                    CCChannels channels = -1;
                    CCRates rates = -1 ;
                    CCType type = CCType::unknow;
                    int asIndex = -1;

                    std::vector<Any> audioStreamInfo
                                        = any_cast<std::vector<Any> >(event.GetPtr()->anyParams);
                    pAVFormatCtx = any_cast<AVFormatContext*>(audioStreamInfo[0]);
                    asIndex = any_cast<int>(audioStreamInfo[1]);

                    GetCodecContext(pAVFormatCtx, asIndex, &pAudioCodecCtx, &audioTimeBase);
                    int ret = GetAudioInformation(pAudioCodecCtx, &channels, &rates, &type);

                    if(ret == 0)
                    {
                        std::vector<Any> audioInformartion;
                        audioInformartion.push_back(Any(channels));
                        audioInformartion.push_back(Any(rates));
                        audioInformartion.push_back(Any(type));

                        PostMessage(MESSAGE_OBJECT_ENUM_AUDIO_DECODER,
                                    MESSAGE_OBJECT_ENUM_AUDIO_RENDER,
                                    MESSAGE_TYPE_ENUM_GET_AUDIO_INFORMATION,
                                    Any(audioInformartion));
                        //crate the frame buffer size
                        pDecodedFrame = avcodec_alloc_frame();

                        PostMessage(MESSAGE_OBJECT_ENUM_AUDIO_DECODER,
                                    MESSAGE_OBJECT_ENUM_DATA_MANAGER,
                                    MESSAGE_TYPE_ENUM_AUDIO_DECODER_READY,
                                    Any());

                        //turn the audio decoder status to working
                        status = AUDIO_DECODER_STATUS_ENUM_WORKING;
                    }
                }
                break;
                case MESSAGE_TYPE_ENUM_GET_AUDIO_PACKET:
                {
                    SmartPtr<CCPacket> shdPacket =
                                            any_cast<SmartPtr<CCPacket> >(event.GetPtr()->anyParams);
                    m_audioPacketQueue.push(shdPacket);
                }
                break;
                case MESSAGE_TYPE_ENUM_AUDIO_RENDER_A_FRAME:
                {
                    //status = AUDIO_DECODER_STATUS_ENUM_SLEEPING;
                    //update
                    audioFrameQueueSize --;
                }
                break;
                case MESSAGE_TYPE_ENUM_DATA_MANAGER_EOF:
                {
                    bDataManagerEof = true;
                }
                break;
                case MESSAGE_TYPE_ENUM_CLIENT_STOP:
                {
                    status = AUDIO_DECODER_STATUS_ENUM_DEADED;
                }
                break;
            } // end switch case
        }// end if get a message

        //working in somethings
        switch(status)
        {
            case AUDIO_DECODER_STATUS_ENUM_WORKING:
            {
                //std::cout << "Audio Decoder are working" << std::endl;

                if(audioFrameQueueSize < MAX_AUDIO_FRAME_QUEUE_SIZE)
                {
                    if(!m_audioPacketQueue.empty())
                    {
                        //static int count = 0;
                        //std::cout << "decoder a audio packet" << ++count << std::endl;

                        SmartPtr<CCPacket> shdPacket = m_audioPacketQueue.front();
                        m_audioPacketQueue.pop();

                        AVPacket packet = shdPacket.GetPtr()->GetPacket();

                        while(packet.size > 0)
                        {
                            avcodec_get_frame_defaults(pDecodedFrame);

                            decodedLen = avcodec_decode_audio4(pAudioCodecCtx,
                                                               pDecodedFrame,
                                                               &gotFrame,
                                                               &packet);

                            packet.data += decodedLen;
                            packet.size -= decodedLen;

                            if(gotFrame)
                            {
                                //std::cout << "Get a frame" << std::endl;
                                //count = 0;
                                //increment the queue size count
                                audioFrameQueueSize ++;

                                int decodedDataSize = av_samples_get_buffer_size(NULL,
                                                                        pAudioCodecCtx->channels,
                                                                        pDecodedFrame->nb_samples,
                                                                        pAudioCodecCtx->sample_fmt,
                                                                        1);

                                SmartPtr<AudioFrame> audioFrame(new AudioFrame(pDecodedFrame->data[0], decodedDataSize));
                                PostMessage(MESSAGE_OBJECT_ENUM_AUDIO_DECODER,
                                            MESSAGE_OBJECT_ENUM_AUDIO_RENDER,
                                            MESSAGE_TYPE_ENUM_GET_AUDIO_FRAME,
                                            Any(audioFrame));
                            }
                        }// end while decoder packet


                        //tell the datamanager we have decoded a packet
                        PostMessage(MESSAGE_OBJECT_ENUM_AUDIO_DECODER,
                                    MESSAGE_OBJECT_ENUM_DATA_MANAGER,
                                    MESSAGE_TYPE_ENUM_AUDIO_DEOCDER_A_PACKET,
                                    Any());
                    }// end the packet queue is not empty
                }// end not enough audio frame
                else if(bDataManagerEof)//there is no data for data manager
                {
                    PostMessage(MESSAGE_OBJECT_ENUM_AUDIO_DECODER,
                                MESSAGE_OBJECT_ENUM_AUDIO_RENDER,
                                MESSAGE_TYPE_ENUM_DATA_MANAGER_EOF,
                                Any());
                    m_bRunning = false;

                    continue;
                }else
                {
                    Sleep(10);
                }
            }
            break;
            case AUDIO_DECODER_STATUS_ENUM_SLEEPING:
            {
                Sleep(50);
            }
            break;
            case AUDIO_DECODER_STATUS_ENUM_UNKNOW:
            {

            }
            break;
            case AUDIO_DECODER_STATUS_ENUM_DEADED:
            {
                m_bRunning = false;
                continue;
            }
            break;
        }// end switch case
    }

    std::cout << "The audio decoder is deaded" << std::endl;
}