-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathFFMpegAudio.cpp
More file actions
84 lines (61 loc) · 2.01 KB
/
Copy pathFFMpegAudio.cpp
File metadata and controls
84 lines (61 loc) · 2.01 KB
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
#include "FFMpegInput.h"
#include <Audioclient.h>
bool FFMpegAudioSource::GetNextBuffer(void **buffer, UINT *numFrames, QWORD *timestamp)
{
if(sampleBuffer.Num() >= sampleSegmentSize)
{
OSEnterMutex(hAudioMutex);
mcpy(outputBuffer.Array(), sampleBuffer.Array(), sampleSegmentSize);
sampleBuffer.RemoveRange(0, sampleSegmentSize);
OSLeaveMutex(hAudioMutex);
*buffer = outputBuffer.Array();
*numFrames = sampleFrameCount;
*timestamp = API->GetAudioTime();//+GetTimeOffset();
return true;
}
return false;
}
void FFMpegAudioSource::ReleaseBuffer()
{
}
CTSTR FFMpegAudioSource::GetDeviceName() const
{
return NULL;
}
bool FFMpegAudioSource::Initialize(FFMpegSource *parent)
{
device = parent;
hAudioMutex = OSCreateMutex();
//---------------------------------
bool bFloat = false;
UINT inputChannels;
UINT inputSamplesPerSec;
UINT inputBitsPerSample;
UINT inputBlockSize;
DWORD inputChannelMask;
//---------------------------------
//32/8/n - AV_SAMPLE_FMT_S32
//16/4/n - AV_SAMPLE_FMT_S16
//16/8/y - AV_SAMPLE_FMT_FLT
inputBitsPerSample = 16;//device->audioFormat.wBitsPerSample;
inputBlockSize = 4;//device->audioFormat.nBlockAlign;
inputChannelMask = 0;
inputChannels = 2;//device->audioFormat.nChannels;
inputSamplesPerSec = 44100;//device->audioFormat.nSamplesPerSec;
sampleFrameCount = inputSamplesPerSec/25; //framerate? why was 100?
sampleSegmentSize = inputBlockSize*sampleFrameCount;
outputBuffer.SetSize(sampleSegmentSize);
InitAudioData(bFloat, inputChannels, inputSamplesPerSec, inputBitsPerSample, inputBlockSize, inputChannelMask, false);
return true;
}
FFMpegAudioSource::~FFMpegAudioSource()
{
if(hAudioMutex)
OSCloseMutex(hAudioMutex);
}
void FFMpegAudioSource::writeSample(uint8_t *data, int length)
{
OSEnterMutex(hAudioMutex);
sampleBuffer.AppendArray(data, length);
OSLeaveMutex(hAudioMutex);
}