mirror of
http://www.pogo.org.uk/~mark/trx.git
synced 2024-11-24 11:25:06 +01:00
Timestamp according to RFC
This commit is contained in:
parent
43f31b8e17
commit
b1dab96f00
10
rx.c
10
rx.c
@ -91,7 +91,8 @@ static int play_one_frame(void *packet,
|
|||||||
static int run_rx(RtpSession *session,
|
static int run_rx(RtpSession *session,
|
||||||
OpusDecoder *decoder,
|
OpusDecoder *decoder,
|
||||||
snd_pcm_t *snd,
|
snd_pcm_t *snd,
|
||||||
const unsigned int channels)
|
const unsigned int channels,
|
||||||
|
const unsigned int rate)
|
||||||
{
|
{
|
||||||
int ts = 0;
|
int ts = 0;
|
||||||
|
|
||||||
@ -118,7 +119,10 @@ static int run_rx(RtpSession *session,
|
|||||||
if (r == -1)
|
if (r == -1)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
ts += r;
|
/* Follow the RFC, 48kHz is reference rate for
|
||||||
|
* timestamps */
|
||||||
|
|
||||||
|
ts += r * 48000 / rate;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -227,7 +231,7 @@ int main(int argc, char *argv[])
|
|||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
go_realtime();
|
go_realtime();
|
||||||
r = run_rx(session, decoder, snd, channels);
|
r = run_rx(session, decoder, snd, channels, rate);
|
||||||
|
|
||||||
if (snd_pcm_close(snd) < 0)
|
if (snd_pcm_close(snd) < 0)
|
||||||
abort();
|
abort();
|
||||||
|
17
tx.c
17
tx.c
@ -57,13 +57,14 @@ static int send_one_frame(snd_pcm_t *snd,
|
|||||||
const snd_pcm_uframes_t samples,
|
const snd_pcm_uframes_t samples,
|
||||||
OpusEncoder *encoder,
|
OpusEncoder *encoder,
|
||||||
const size_t bytes_per_frame,
|
const size_t bytes_per_frame,
|
||||||
|
const unsigned int ts_per_frame,
|
||||||
RtpSession *session)
|
RtpSession *session)
|
||||||
{
|
{
|
||||||
float *pcm;
|
float *pcm;
|
||||||
void *packet;
|
void *packet;
|
||||||
ssize_t z;
|
ssize_t z;
|
||||||
snd_pcm_sframes_t f;
|
snd_pcm_sframes_t f;
|
||||||
static int ts = 0;
|
static unsigned int ts = 0;
|
||||||
|
|
||||||
pcm = alloca(sizeof(float) * samples * channels);
|
pcm = alloca(sizeof(float) * samples * channels);
|
||||||
packet = alloca(bytes_per_frame);
|
packet = alloca(bytes_per_frame);
|
||||||
@ -83,7 +84,7 @@ static int send_one_frame(snd_pcm_t *snd,
|
|||||||
}
|
}
|
||||||
|
|
||||||
rtp_session_send_with_ts(session, packet, z, ts);
|
rtp_session_send_with_ts(session, packet, z, ts);
|
||||||
ts += samples;
|
ts += ts_per_frame;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -93,13 +94,14 @@ static int run_tx(snd_pcm_t *snd,
|
|||||||
const snd_pcm_uframes_t frame,
|
const snd_pcm_uframes_t frame,
|
||||||
OpusEncoder *encoder,
|
OpusEncoder *encoder,
|
||||||
const size_t bytes_per_frame,
|
const size_t bytes_per_frame,
|
||||||
|
const unsigned int ts_per_frame,
|
||||||
RtpSession *session)
|
RtpSession *session)
|
||||||
{
|
{
|
||||||
for (;;) {
|
for (;;) {
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
r = send_one_frame(snd, channels, frame,
|
r = send_one_frame(snd, channels, frame,
|
||||||
encoder, bytes_per_frame,
|
encoder, bytes_per_frame, ts_per_frame,
|
||||||
session);
|
session);
|
||||||
if (r == -1)
|
if (r == -1)
|
||||||
return -1;
|
return -1;
|
||||||
@ -148,6 +150,7 @@ int main(int argc, char *argv[])
|
|||||||
{
|
{
|
||||||
int r, error;
|
int r, error;
|
||||||
size_t bytes_per_frame;
|
size_t bytes_per_frame;
|
||||||
|
unsigned int ts_per_frame;
|
||||||
snd_pcm_t *snd;
|
snd_pcm_t *snd;
|
||||||
OpusEncoder *encoder;
|
OpusEncoder *encoder;
|
||||||
RtpSession *session;
|
RtpSession *session;
|
||||||
@ -215,6 +218,11 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
bytes_per_frame = kbps * 1024 * frame / rate / 8;
|
bytes_per_frame = kbps * 1024 * frame / rate / 8;
|
||||||
|
|
||||||
|
/* Follow the RFC, 48kHz is reference rate for
|
||||||
|
* timestamps */
|
||||||
|
|
||||||
|
ts_per_frame = frame * 48000 / rate;
|
||||||
|
|
||||||
ortp_init();
|
ortp_init();
|
||||||
ortp_scheduler_init();
|
ortp_scheduler_init();
|
||||||
ortp_set_log_level_mask(ORTP_MESSAGE|ORTP_WARNING|ORTP_ERROR);
|
ortp_set_log_level_mask(ORTP_MESSAGE|ORTP_WARNING|ORTP_ERROR);
|
||||||
@ -232,7 +240,8 @@ int main(int argc, char *argv[])
|
|||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
go_realtime();
|
go_realtime();
|
||||||
r = run_tx(snd, channels, frame, encoder, bytes_per_frame, session);
|
r = run_tx(snd, channels, frame, encoder, bytes_per_frame,
|
||||||
|
ts_per_frame, session);
|
||||||
|
|
||||||
if (snd_pcm_close(snd) < 0)
|
if (snd_pcm_close(snd) < 0)
|
||||||
abort();
|
abort();
|
||||||
|
Loading…
Reference in New Issue
Block a user