-
Notifications
You must be signed in to change notification settings - Fork 4
/
audioappsrc.cpp
65 lines (53 loc) · 1.46 KB
/
audioappsrc.cpp
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
#include "audioappsrc.h"
AudioAppSrc::AudioAppSrc(QObject *parent) :
QObject(parent), QGst::Utils::ApplicationSource()
{
preAlloc = false;
}
void AudioAppSrc::needData(uint length)
{
//qDebug() << "AudioAppSrc NEED DATA. PREALLOC" << preAlloc << "Length:" << length;
if (preAlloc)
{
if (!buffer.isNull())
{
buffer.clear();
}
// Create and allocate the buffer here so we don't need to malloc the space twice and shuffle the data between threads too often
buffer = QGst::Buffer::create(length);
buffer->map(mapInfo, QGst::MapWrite);
emit sigNeedData(length, (char*)mapInfo.data());
}
else
{
emit sigNeedData(length, 0);
}
}
void AudioAppSrc::enoughData()
{
//qDebug() << "AudioAppSrc ENOUGH DATA";
}
void AudioAppSrc::pushAudioBuffer()
{
if ((!preAlloc) || (buffer.isNull()))
{
return;
}
buffer->unmap(mapInfo);
//qDebug() << "AudioAppSrc PUSHBUFFER. PREALLOC" << preAlloc << "Length:" << buffer->size();
pushBuffer(buffer);
}
void AudioAppSrc::pushAudioBuffer(QByteArray data)
{
if (preAlloc)
{
return;
}
QGst::BufferPtr buf = QGst::Buffer::create(data.size());
QGst::MapInfo map;
buf->map(map, QGst::MapWrite);
memcpy(map.data(), data.data(), map.size());
buf->unmap(map);
//qDebug() << "AudioAppSrc PUSHBUFFER. PREALLOC" << preAlloc << "Length:" << buffer->size();
pushBuffer(buf);
}