-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathOhmMsg.h
227 lines (192 loc) · 6.66 KB
/
OhmMsg.h
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
#ifndef HEADER_OHMMSG
#define HEADER_OHMMSG
#include <OpenHome/OhNetTypes.h>
#include <OpenHome/Buffer.h>
#include <OpenHome/Private/Thread.h>
#include <OpenHome/Private/Fifo.h>
#include "Ohm.h"
namespace OpenHome {
namespace Av {
class OhmMsgAudio;
class OhmMsgTrack;
class OhmMsgMetatext;
class OhmMsgFactory;
class IOhmMsgProcessor
{
public:
virtual void Process(OhmMsgAudio& aMsg) = 0;
virtual void Process(OhmMsgTrack& aMsg) = 0;
virtual void Process(OhmMsgMetatext& aMsg) = 0;
virtual ~IOhmMsgProcessor() {}
};
class OhmMsg
{
public:
virtual ~OhmMsg();
void AddRef();
void RemoveRef();
TUint ResendCount() const;
void IncrementResendCount();
TBool TxTimestamped() const;
TBool RxTimestamped() const;
TUint TxTimestamp() const;
TUint RxTimestamp() const;
void SetTxTimestamp(TUint aValue);
void SetRxTimestamp(TUint aValue);
virtual void Process(IOhmMsgProcessor& aProcessor) = 0;
virtual void Externalise(IWriter& aWriter) = 0;
protected:
OhmMsg(OhmMsgFactory& aFactory);
void Create();
private:
OhmMsgFactory* iFactory;
TUint iRefCount;
TUint iResendCount;
TBool iTxTimestamped;
TBool iRxTimestamped;
TUint iTxTimestamp;
TUint iRxTimestamp;
};
class OhmMsgAudio : public OhmMsg
{
friend class OhmMsgFactory;
public:
static const TUint kMaxSampleBytes = 8 * 1024;
static const TUint kMaxCodecBytes = 256;
private:
static const TUint kHeaderBytes = 50; // not including codec name
static const TUint kReserved = 0;
static const TUint kFlagHalt = 1;
static const TUint kFlagLossless = 2;
static const TUint kFlagTimestamped = 4;
static const TUint kFlagResent = 8;
public:
TBool Halt() const;
TBool Lossless() const;
TBool Timestamped() const;
TBool Resent() const;
TUint Samples() const;
TUint Frame() const;
TUint NetworkTimestamp() const;
TUint MediaLatency() const;
TUint MediaTimestamp() const;
TUint64 SampleStart() const;
TUint64 SamplesTotal() const;
TUint SampleRate() const;
TUint BitRate() const;
TInt VolumeOffset() const;
TUint BitDepth() const;
TUint Channels() const;
const Brx& Codec() const;
const Brx& Audio() const;
void SetResent(TBool aValue);
virtual void Process(IOhmMsgProcessor& aProcessor);
virtual void Externalise(IWriter& aWriter);
private:
OhmMsgAudio(OhmMsgFactory& aFactory);
void Create(IReader& aReader, const OhmHeader& aHeader);
void Create(TBool aHalt, TBool aLossless, TBool aTimestamped, TBool aResent, TUint aSamples, TUint aFrame, TUint aNetworkTimestamp, TUint aMediaLatency, TUint aMediaTimestamp, TUint64 aSampleStart, TUint64 aSamplesTotal, TUint aSampleRate, TUint aBitRate, TUint aVolumeOffset, TUint aBitDepth, TUint aChannels, const Brx& aCodec, const Brx& aAudio);
private:
TBool iHalt;
TBool iLossless;
TBool iTimestamped;
TBool iResent;
TUint iSamples;
TUint iFrame;
TUint iNetworkTimestamp;
TUint iMediaLatency;
TUint iMediaTimestamp;
TUint64 iSampleStart;
TUint64 iSamplesTotal;
TUint iSampleRate;
TUint iBitRate;
TInt iVolumeOffset;
TUint iBitDepth;
TUint iChannels;
Bws<kMaxCodecBytes> iCodec;
Bws<kMaxSampleBytes> iAudio;
};
class OhmMsgTrack : public OhmMsg
{
friend class OhmMsgFactory;
public:
static const TUint kMaxUriBytes = 1 * 1024;
static const TUint kMaxMetadataBytes = 4 * 1024;
private:
static const TUint kHeaderBytes = 12;
public:
TUint Sequence() const;
const Brx& Uri() const;
const Brx& Metadata() const;
virtual void Process(IOhmMsgProcessor& aProcessor);
virtual void Externalise(IWriter& aWriter);
private:
OhmMsgTrack(OhmMsgFactory& aFactory);
void Create(IReader& aReader, const OhmHeader& aHeader);
void Create(TUint aSequence, const Brx& aUri, const Brx& aMetadata);
private:
TUint iSequence;
Bws<kMaxUriBytes> iUri;
Bws<kMaxMetadataBytes> iMetadata;
};
class OhmMsgMetatext : public OhmMsg
{
friend class OhmMsgFactory;
public:
static const TUint kMaxMetatextBytes = 1 * 1024;
private:
static const TUint kHeaderBytes = 8;
public:
TUint Sequence() const;
const Brx& Metatext() const;
virtual void Process(IOhmMsgProcessor& aProcessor);
virtual void Externalise(IWriter& aWriter);
private:
OhmMsgMetatext(OhmMsgFactory& aFactory);
void Create(IReader& aReader, const OhmHeader& aHeader);
void Create(TUint aSequence, const Brx& aMetatext);
private:
TUint iSequence;
Bws<kMaxMetatextBytes> iMetatext;
};
class IOhmMsgFactory
{
public:
virtual OhmMsg& Create(IReader& aReader, const OhmHeader& aHeader) = 0;
virtual OhmMsgAudio& CreateAudio(IReader& aReader, const OhmHeader& aHeader) = 0;
virtual OhmMsgTrack& CreateTrack(IReader& aReader, const OhmHeader& aHeader) = 0;
virtual OhmMsgMetatext& CreateMetatext(IReader& aReader, const OhmHeader& aHeader) = 0;
virtual OhmMsgAudio& CreateAudio(TBool aHalt, TBool aLossless, TBool aTimestamped, TBool aResent, TUint aSamples, TUint aFrame, TUint aNetworkTimestamp, TUint aMediaLatency, TUint aMediaTimestamp, TUint64 aSampleStart, TUint64 aSamplesTotal, TUint aSampleRate, TUint aBitRate, TUint aVolumeOffset, TUint aBitDepth, TUint aChannels, const Brx& aCodec, const Brx& aAudio) = 0;
virtual OhmMsgTrack& CreateTrack(TUint aSequence, const Brx& aUri, const Brx& aMetadata) = 0;
virtual OhmMsgMetatext& CreateMetatext(TUint aSequence, const Brx& aMetatext) = 0;
virtual ~IOhmMsgFactory() {}
};
class OhmMsgFactory : public IOhmMsgFactory, public IOhmMsgProcessor
{
friend class OhmMsg;
public:
OhmMsgFactory(TUint aAudioCount, TUint aTrackCount, TUint aMetatextCount);
virtual OhmMsg& Create(IReader& aReader, const OhmHeader& aHeader);
virtual OhmMsgAudio& CreateAudio(IReader& aReader, const OhmHeader& aHeader);
virtual OhmMsgTrack& CreateTrack(IReader& aReader, const OhmHeader& aHeader);
virtual OhmMsgMetatext& CreateMetatext(IReader& aReader, const OhmHeader& aHeader);
virtual OhmMsgAudio& CreateAudio(TBool aHalt, TBool aLossless, TBool aTimestamped, TBool aResent, TUint aSamples, TUint aFrame, TUint aNetworkTimestamp, TUint aMediaLatency, TUint aMediaTimestamp, TUint64 aSampleStart, TUint64 aSamplesTotal, TUint aSampleRate, TUint aBitRate, TUint aVolumeOffset, TUint aBitDepth, TUint aChannels, const Brx& aCodec, const Brx& aAudio);
virtual OhmMsgTrack& CreateTrack(TUint aSequence, const Brx& aUri, const Brx& aMetadata);
virtual OhmMsgMetatext& CreateMetatext(TUint aSequence, const Brx& aMetatext);
~OhmMsgFactory();
private:
void Lock();
void Unlock();
void Destroy(OhmMsg& aMsg);
void Process(OhmMsgAudio& aMsg);
void Process(OhmMsgTrack& aMsg);
void Process(OhmMsgMetatext& aMsg);
private:
Fifo<OhmMsgAudio*> iFifoAudio;
Fifo<OhmMsgTrack*> iFifoTrack;
Fifo<OhmMsgMetatext*> iFifoMetatext;
Mutex iMutex;
};
} // namespace Av
} // namespace OpenHome
#endif // HEADER_OHMMSG