Browse Source

TT#98901 keep track of head PTS in packetiser

Change-Id: I3439318037da535701f84b070b107ae19ca3e261
pull/1164/head
Richard Fuchs 5 years ago
parent
commit
25d90cea0d
2 changed files with 9 additions and 1 deletions
  1. +8
    -1
      lib/codeclib.c
  2. +1
    -0
      lib/codeclib.h

+ 8
- 1
lib/codeclib.c View File

@ -1349,9 +1349,13 @@ static int packetizer_samplestream(AVPacket *pkt, GString *buf, str *input_outpu
// most common case: new input packet has just enough (or more) data as what we need
if (G_LIKELY(pkt && buf->len == 0 && pkt->size >= input_output->len)) {
memcpy(input_output->s, pkt->data, input_output->len);
if (pkt->size > input_output->len) // any leftovers?
// any leftovers?
if (pkt->size > input_output->len) {
g_string_append_len(buf, (char *) pkt->data + input_output->len,
pkt->size - input_output->len);
enc->packet_pts = pkt->pts + input_output->len
* (enc->def->bits_per_sample * enc->def->clockrate_mult / 8);
}
return buf->len >= input_output->len ? 1 : 0;
}
// we have to move data around. append input packet to buffer if we have one
@ -1363,6 +1367,9 @@ static int packetizer_samplestream(AVPacket *pkt, GString *buf, str *input_outpu
// copy requested data into provided output buffer and remove from interim buffer
memcpy(input_output->s, buf->str, input_output->len);
g_string_erase(buf, 0, input_output->len);
// adjust output pts
enc->avpkt.pts = enc->packet_pts;
enc->packet_pts += input_output->len * (enc->def->bits_per_sample * enc->def->clockrate_mult / 8);
return buf->len >= input_output->len ? 1 : 0;
}


+ 1
- 0
lib/codeclib.h View File

@ -239,6 +239,7 @@ struct encoder_s {
AVPacket avpkt;
AVAudioFifo *fifo;
int64_t fifo_pts; // pts of first data in fifo
int64_t packet_pts; // first pts of data in packetizer buffer
int ptime;
int bitrate;
int samples_per_frame; // for encoding


Loading…
Cancel
Save