Alejandro Acuña
2024-08-12 1876e65234c20209001178705cfa50d8f9ded67a
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
// RTPAudioStream.h: interface for the RTPAudioStream class.
//
//////////////////////////////////////////////////////////////////////
 
#ifndef AFX_RTPAUDIOSTREAM_H__1CB0DE48_EADE_4C23_9C56_C8ECDE1A90AD__INCLUDED_
#define AFX_RTPAUDIOSTREAM_H__1CB0DE48_EADE_4C23_9C56_C8ECDE1A90AD__INCLUDED_
 
#include <queue>
#include <functional>
#include "AudioSample.h"
#include "../../Tracer/Tracer.h"
 
 
class RTPCompareLess
{
public:
    bool operator() (AudioSample *sample1, AudioSample *sample2)
    {
        return *sample1 < *sample2;
    }
};
 
class RTPCompareGreater
{
public:
    bool operator() (AudioSample *sample1, AudioSample *sample2)
    {
        return *sample1 >= *sample2;
    }
};
 
class RTPAudioStream : public TraceUser
{
public:
    RTPAudioStream(unsigned long ssrc);
    virtual ~RTPAudioStream();
    int SetRestartThreshold(int depthInMillisec);
    int InsertRTPPacket(AudioSample *audioSample);
    int GiveNextRTPPacket(AudioSample **pOutSample);
    int NumQueuedPackets();
    int JitterBufferDepth();    // Current depth of the jitter buffer in milliseconds
    unsigned long SSRC();
protected:
    int SetTraceLevel();
private:
    int SetLastTransmittedPacket(AudioSample *);
    int TimeDifference(unsigned long timestamp1, unsigned long timestamp2);
    int TimeDifference(AudioSample *, AudioSample *);
    int TimeDifferenceMillisec(AudioSample *, AudioSample *);
    int Clear();
    int AddPacket(AudioSample *);
    int PopNextPacket(AudioSample **pAudioSample);
    int PopNextPacketForTransmit(AudioSample **pOutSample);
private:
//  typedef std::priority_queue<AudioSample *, std::vector<AudioSample * >, std::greater_equal<AudioSample *> > PACKET_QUEUE;
    typedef std::priority_queue<AudioSample *, std::vector<AudioSample * >, RTPCompareGreater > PACKET_QUEUE;
    PACKET_QUEUE packetQueue;   // protected by packetQueueMutex
    unsigned long ssrc;
    int jitterBufferDepth;      // protected by packetQueueMutex
    int restartThreshold;
    unsigned long lastOutputTimestamp;
    unsigned long lastOutputDuration;
    AudioSample *lastPacketTransmitted;
    int lastPacketRepeatCount;
    int numSIDPackets;
    bool silenceIntervalInProgress;
    bool dynamicJitterBuffer;
    CRITICAL_SECTION packetQueueMutex;
    CRITICAL_SECTION audioStreamMutex;
};
 
#endif // !defined(AFX_RTPAUDIOSTREAM_H__1CB0DE48_EADE_4C23_9C56_C8ECDE1A90AD__INCLUDED_)