Fix bug where packets weren't interleaving

Packets were not interleaving, thus new data was being sent out with
potentially non-monotonically increasing timestamps
This commit is contained in:
jp9000 2014-04-14 02:02:59 -07:00
parent 8fa44b0012
commit a4a52d1c87
2 changed files with 20 additions and 7 deletions

View File

@ -421,13 +421,12 @@ static void interleave_packets(void *data, struct encoder_packet *packet)
/* when both video and audio have been received, we're ready
* to start sending out packets (one at a time) */
if (!output->interleaved_wait &&
output->received_audio &&
output->received_video)
send_interleaved(output);
if (output->interleaved_wait > 0)
output->interleaved_wait--;
if (output->received_audio && output->received_video) {
if (output->interleaved_wait > 0)
output->interleaved_wait--;
else
send_interleaved(output);
}
}
pthread_mutex_unlock(&output->interleaved_mutex);

View File

@ -126,6 +126,10 @@ static uint32_t get_ms_time(struct encoder_packet *packet, int64_t val)
return (uint32_t)(val * MILLISECOND_DEN / packet->timebase_den);
}
#ifdef DEBUG_TIMESTAMPS
static int32_t last_time = 0;
#endif
static void flv_video(struct serializer *s, struct encoder_packet *packet,
bool is_header)
{
@ -139,6 +143,11 @@ static void flv_video(struct serializer *s, struct encoder_packet *packet,
#ifdef DEBUG_TIMESTAMPS
blog(LOG_DEBUG, "Video: %lu", time_ms);
if (last_time > time_ms)
blog(LOG_DEBUG, "Non-monotonic");
last_time = time_ms;
#endif
s_wb24(s, (uint32_t)packet->size + 5);
@ -168,6 +177,11 @@ static void flv_audio(struct serializer *s, struct encoder_packet *packet,
#ifdef DEBUG_TIMESTAMPS
blog(LOG_DEBUG, "Audio: %lu", time_ms);
if (last_time > time_ms)
blog(LOG_DEBUG, "Non-monotonic");
last_time = time_ms;
#endif
s_wb24(s, (uint32_t)packet->size + 2);