@@ -34,7 +34,7 @@ namespace audio_tools {
34
34
*
35
35
* @note Implementations must provide format() method for SDP generation
36
36
* @ingroup rtsp
37
- * @author Thomas Pfitzinger
37
+ * @author Phil Schatzmann
38
38
* @version 0.1.1
39
39
*/
40
40
@@ -131,20 +131,6 @@ class RTSPFormatPCM : public RTSPFormat {
131
131
setTimerPeriodUs (getTimerPeriod (this ->fragment_size ));
132
132
}
133
133
134
- /* *
135
- * @brief Get the timer period for streaming
136
- * @return Timer period in microseconds between audio packets
137
- */
138
- int getTimerPeriod (int fragmentSize) {
139
- // Calculate how many samples are in the fragment
140
- int samples_per_fragment = timestampIncrement ();
141
- // Calculate how long it takes to play these samples at the given sample
142
- // rate
143
- int timer_period =
144
- (samples_per_fragment * 1000000 ) / cfg.sample_rate ; // microseconds
145
- return timer_period;
146
- }
147
-
148
134
/* *
149
135
* @brief Provide format 10 or 11
150
136
*
@@ -160,8 +146,7 @@ class RTSPFormatPCM : public RTSPFormat {
160
146
" m=audio 0 RTP/AVP %d\r\n " // UDP sessions with format 10 or 11
161
147
" a=rtpmap:%s\r\n "
162
148
" a=rate:%i\r\n " , // provide sample rate
163
- format (channels ()), payloadFormat (sampleRate (), channels ()),
164
- sampleRate ());
149
+ rtpPayloadType (), payloadFormat (), sampleRate ());
165
150
LOGI (" ftsp format: %s" , buffer);
166
151
return (const char *)buffer;
167
152
}
@@ -176,58 +161,70 @@ class RTSPFormatPCM : public RTSPFormat {
176
161
// convert to network format (big endian)
177
162
int16_t *pt_16 = (int16_t *)data;
178
163
for (int j = 0 ; j < samples / 2 ; j++) {
179
- uint16_t v = (uint16_t )pt_16[j];
180
- v = (uint16_t )((v << 8 ) | (v >> 8 ));
181
- pt_16[j] = (int16_t )v;
164
+ pt_16[j] = htons (pt_16[j]);
182
165
}
183
166
return samples;
184
167
}
185
168
186
169
AudioInfo info () { return cfg; }
187
170
188
- int sampleRate () { return cfg.sample_rate ; }
189
- int channels () { return cfg.channels ; }
190
- int bytesPerSample () { return cfg.bits_per_sample / 8 ; }
191
-
192
171
AudioInfo defaultConfig () override { return AudioInfo (16000 , 1 , 16 ); }
193
172
194
- protected:
195
- char payload_fromat[30 ];
196
-
197
- const char *payloadFormat (int sampleRate, int channels) {
198
- // see https://en.wikipedia.org/wiki/RTP_payload_formats
199
- // 11 L16/%i/%i
200
-
201
- switch (channels) {
173
+ int rtpPayloadType () override {
174
+ int result = 0 ;
175
+ switch (channels ()) {
202
176
case 1 :
203
- snprintf (payload_fromat, 30 , " %d L16/%i/%i" , format (channels),
204
- sampleRate, channels);
177
+ result = 11 ;
205
178
break ;
206
179
case 2 :
207
- snprintf (payload_fromat, 30 , " %d L16/%i/%i" , format (channels),
208
- sampleRate, channels);
180
+ result = 10 ;
209
181
break ;
210
182
default :
211
183
LOGE (" unsupported audio type" );
212
184
break ;
213
185
}
214
- return payload_fromat ;
186
+ return result ;
215
187
}
216
188
217
- int format (int channels) {
218
- int result = 0 ;
219
- switch (channels) {
189
+ protected:
190
+ char payload_fromat[30 ];
191
+
192
+ int sampleRate () { return cfg.sample_rate ; }
193
+ int channels () { return cfg.channels ; }
194
+ int bytesPerSample () { return cfg.bits_per_sample / 8 ; }
195
+
196
+ /* *
197
+ * @brief Get the timer period for streaming
198
+ * @return Timer period in microseconds between audio packets
199
+ */
200
+ int getTimerPeriod (int fragmentSize) {
201
+ // Calculate how many samples are in the fragment
202
+ int samples_per_fragment = timestampIncrement ();
203
+ // Calculate how long it takes to play these samples at the given sample
204
+ // rate
205
+ int timer_period =
206
+ (samples_per_fragment * 1000000 ) / cfg.sample_rate ; // microseconds
207
+ return timer_period;
208
+ }
209
+
210
+
211
+ // see https://en.wikipedia.org/wiki/RTP_payload_formats
212
+ // 11 L16/%i/%i
213
+ const char *payloadFormat () {
214
+ switch (channels ()) {
220
215
case 1 :
221
- result = 11 ;
216
+ snprintf (payload_fromat, 30 , " %d L16/%i/%i" , rtpPayloadType (),
217
+ sampleRate (), channels ());
222
218
break ;
223
219
case 2 :
224
- result = 10 ;
220
+ snprintf (payload_fromat, 30 , " %d L16/%i/%i" , rtpPayloadType (),
221
+ sampleRate (), channels ());
225
222
break ;
226
223
default :
227
224
LOGE (" unsupported audio type" );
228
225
break ;
229
226
}
230
- return result ;
227
+ return payload_fromat ;
231
228
}
232
229
};
233
230
0 commit comments