2013-07-12 10:33:38 +04:00
|
|
|
|
|
|
|
#include <unistd.h>
|
|
|
|
|
2012-12-27 06:48:17 +04:00
|
|
|
#include "playaudio.h"
|
|
|
|
#include <QDebug>
|
|
|
|
|
|
|
|
PlayAudio::PlayAudio(QObject *parent,
|
|
|
|
QQueue<MediaPacket *> *audioQueue,
|
|
|
|
QMutex *sendMutex,
|
|
|
|
void *channel,
|
|
|
|
int stream_id) :
|
|
|
|
QObject(parent)
|
|
|
|
{
|
|
|
|
this->audioQueue = audioQueue;
|
|
|
|
this->sendMutex = sendMutex;
|
|
|
|
this->channel = channel;
|
|
|
|
this->stream_id = stream_id;
|
|
|
|
this->vcrFlag = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PlayAudio::play()
|
|
|
|
{
|
|
|
|
MediaPacket *pkt;
|
|
|
|
|
|
|
|
while (1)
|
|
|
|
{
|
|
|
|
vcrMutex.lock();
|
|
|
|
switch (vcrFlag)
|
|
|
|
{
|
|
|
|
case VCR_PLAY:
|
|
|
|
vcrFlag = 0;
|
|
|
|
vcrMutex.unlock();
|
|
|
|
continue;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case VCR_PAUSE:
|
|
|
|
vcrMutex.unlock();
|
|
|
|
usleep(1000 * 100);
|
|
|
|
continue;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case VCR_STOP:
|
|
|
|
vcrMutex.unlock();
|
|
|
|
clearAudioQ();
|
|
|
|
usleep(1000 * 100);
|
|
|
|
continue;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
vcrMutex.unlock();
|
|
|
|
goto label1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
label1:
|
|
|
|
|
2013-11-08 23:20:38 +04:00
|
|
|
printf("audio\n");
|
2012-12-27 06:48:17 +04:00
|
|
|
if (audioQueue->isEmpty())
|
|
|
|
{
|
|
|
|
qDebug() << "PlayAudio::play: GOT EMPTY";
|
2013-11-11 13:52:14 +04:00
|
|
|
usleep(1000 * 10);
|
2012-12-27 06:48:17 +04:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2013-11-11 13:52:14 +04:00
|
|
|
printf("");
|
2012-12-27 06:48:17 +04:00
|
|
|
pkt = audioQueue->dequeue();
|
|
|
|
sendMutex->lock();
|
|
|
|
send_audio_pkt(channel, stream_id, pkt->av_pkt);
|
|
|
|
sendMutex->unlock();
|
|
|
|
usleep(pkt->delay_in_us);
|
2013-01-16 22:31:11 +04:00
|
|
|
delete pkt;
|
2012-12-27 06:48:17 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void PlayAudio::setVcrOp(int op)
|
|
|
|
{
|
|
|
|
vcrMutex.lock();
|
|
|
|
this->vcrFlag = op;
|
|
|
|
vcrMutex.unlock();
|
|
|
|
}
|
|
|
|
|
|
|
|
void PlayAudio::clearAudioQ()
|
|
|
|
{
|
|
|
|
MediaPacket *pkt;
|
|
|
|
|
|
|
|
while (!audioQueue->isEmpty())
|
|
|
|
{
|
|
|
|
pkt = audioQueue->dequeue();
|
|
|
|
av_free_packet((AVPacket *) pkt->av_pkt);
|
|
|
|
delete pkt;
|
|
|
|
}
|
|
|
|
}
|