blob: bab7d38b71f19b2a12fea36c5cf874f0430b16bc (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
|
#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:
if (audioQueue->isEmpty())
{
qDebug() << "PlayAudio::play: GOT EMPTY";
usleep(1000 * 100);
continue;
}
pkt = audioQueue->dequeue();
sendMutex->lock();
send_audio_pkt(channel, stream_id, pkt->av_pkt);
sendMutex->unlock();
usleep(pkt->delay_in_us);
delete pkt;
}
}
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;
}
}
|