Skip to content

Commit

Permalink
MP2: Bugfix: low latency streams audio broken (poor pts timing calcul…
Browse files Browse the repository at this point in the history
…ations - fixed).
  • Loading branch information
Steven Toth committed Jul 11, 2018
1 parent ffffe50 commit 8eceecc
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions encoders/audio/mp2/twolame.c
Original file line number Diff line number Diff line change
Expand Up @@ -208,16 +208,19 @@ static void *start_encoder_mp2( void *ptr )
av_fifo_generic_read( fifo, coded_frame->data, frame_size, NULL );
memcpy(&coded_frame->avfm, &avfm, sizeof(avfm));

/* a = (27000000 / 1000) * 96 - Calculate 96ms in units of a 27MHz clock.
* a = 2592000
* Output PTS packets (27MHz) are rounded to nearest 96ms interval on a 27MHz clock.
/* In low latency mode, obe configures a single MP2 frame in every pes (enc_params->frames_per_pes), with a PTS interval of 24ms.
* In norm latency mode, obe configures N MP2 frames in every pes, with a PTS interval of N*24ms.
* Typically, we see 96MS PTS increments in the transport packets, buts its equally valid to see 24ms.
* Depending on what latency mode we're in, we need to round to the nearest '24ms or N*' interval.
* Output PTS packets (27MHz) are rounded to nearest 24ms or N*24ms (typically 96ms for norm lat) interval on a 27MHz clock.
*/
/* The outgoing PTS is rounded and based on recent h/w clock, so massive leaps in
* the h/w clock are automatically compensated for.
* 648000 represents number of ticks in 27Mhz clock for 24ms, the smallest MP2 framesize we can deliver.
*/
int64_t rounded_pts = av_rescale(coded_frame->avfm.audio_pts, OBE_CLOCK, 2592000);
int64_t rounded_pts = av_rescale(coded_frame->avfm.audio_pts, OBE_CLOCK, 648000 * enc_params->frames_per_pes);
rounded_pts /= OBE_CLOCK;
rounded_pts *= 2592000;
rounded_pts *= (648000 * enc_params->frames_per_pes);
coded_frame->pts = rounded_pts;
coded_frame->pts += ((int64_t)stream->audio_offset_ms * 27000);

Expand Down

0 comments on commit 8eceecc

Please sign in to comment.