-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathAudioPlay.cpp
More file actions
75 lines (69 loc) · 1.31 KB
/
AudioPlay.cpp
File metadata and controls
75 lines (69 loc) · 1.31 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
#include "stdafx.h"
#include "AudioPlay.h"
AudioPlayer::AudioPlayer()
:frame_queue(10)
{
last_frame = NULL;
}
AudioPlayer::~AudioPlayer()
{
frame_queue.Clear(true);
frame_queue.Restart();
if(last_frame != NULL) FreeAVFrame(&last_frame);
last_frame = NULL;
}
EvoQueue<AVFrame, FreeAVFrame> & AudioPlayer::GetQueue()
{
return frame_queue;
}
//²»ÄÜ×èÈû£¡
AVFrame* AudioPlayer::GetAudioData()
{
AVFrame * frame = last_frame; last_frame = NULL;
if(frame == NULL) frame = frame_queue.Dequeue(1);
if (Sync != NULL)
{
while (true)
{
if (frame != NULL)
{
int ret = Sync->CheckForAudioSynchronise(frame->pts, audioSource.samples, audioSource.freq);
if (ret < 0)
{
FreeAVFrame(&frame);
frame = frame_queue.Dequeue(1);
}
else if (ret > 0)
{
/*last_frame = frame;
return NULL;*/
}
else
{
break;
}
}
else
{
break;
}
}
}
if (frame != NULL)
{
lastTimeStamp = frame->pts;
}
return frame;
}
void AudioPlayer::FillAudioBuffer(Uint8 *stream, int len)
{
SDLControl::FillAudioBuffer(stream,len);
if (Sync != NULL)
{
Sync->ApplyAudioStamp(lastTimeStamp, audioSource.samples, audioSource.freq);
}
}
void AudioPlayer::AttachSync(MediaSynchronise *sync)
{
Sync = sync;
}