summaryrefslogtreecommitdiff
path: root/src/internal/audio/kitaudio.c
diff options
context:
space:
mode:
authorTuomas Virtanen <katajakasa@gmail.com>2018-09-29 18:46:08 +0300
committerTuomas Virtanen <katajakasa@gmail.com>2018-09-29 18:46:08 +0300
commit108948c94a9ee7b115b0448fb3051e5666eec0f3 (patch)
treeb2cb558e34b1b376303cb157db73a1ac621da9e1 /src/internal/audio/kitaudio.c
parent41c8ad5142e4de9b6c667840b9b5b4b66be3f71e (diff)
Improved frameskip
Diffstat (limited to 'src/internal/audio/kitaudio.c')
-rw-r--r--src/internal/audio/kitaudio.c28
1 files changed, 19 insertions, 9 deletions
diff --git a/src/internal/audio/kitaudio.c b/src/internal/audio/kitaudio.c
index e399ff2..a1fbd63 100644
--- a/src/internal/audio/kitaudio.c
+++ b/src/internal/audio/kitaudio.c
@@ -15,7 +15,7 @@
#include "kitchensink/internal/utils/kitringbuffer.h"
#include "kitchensink/internal/utils/kitlog.h"
-#define AUDIO_SYNC_THRESHOLD 0.05
+#define KIT_AUDIO_SYNC_THRESHOLD 0.05
typedef struct Kit_AudioDecoder {
SwrContext *swr;
@@ -275,6 +275,7 @@ double Kit_GetAudioDecoderPTS(Kit_Decoder *dec) {
int Kit_GetAudioDecoderData(Kit_Decoder *dec, unsigned char *buf, int len) {
assert(dec != NULL);
+ Kit_AudioPacket *next_packet = NULL;
Kit_AudioPacket *packet = Kit_PeekDecoderOutput(dec);
if(packet == NULL) {
return 0;
@@ -285,20 +286,29 @@ int Kit_GetAudioDecoderData(Kit_Decoder *dec, unsigned char *buf, int len) {
double bytes_per_second = bytes_per_sample * dec->output.samplerate;
double sync_ts = _GetSystemTime() - dec->clock_sync;
- if(packet->pts > sync_ts + AUDIO_SYNC_THRESHOLD) {
+ if(packet->pts > sync_ts + KIT_AUDIO_SYNC_THRESHOLD) {
return 0;
- } else if(packet->pts < sync_ts - AUDIO_SYNC_THRESHOLD) {
+ } else if(packet->pts < sync_ts - KIT_AUDIO_SYNC_THRESHOLD) {
// Audio is lagging, skip until good pts is found
+ LOG("A LAG %f < %f\n", packet->pts, sync_ts - KIT_AUDIO_SYNC_THRESHOLD);
+ Kit_AdvanceDecoderOutput(dec);
while(1) {
- Kit_AdvanceDecoderOutput(dec);
- free_out_audio_packet_cb(packet);
- packet = Kit_PeekDecoderOutput(dec);
+ next_packet = Kit_ReadDecoderOutput(dec);
+
+ // If next packet is valid, remove this one and jump to next.
+ if(next_packet != NULL) {
+ Kit_AdvanceDecoderOutput(dec);
+ free_out_audio_packet_cb(packet);
+ packet = next_packet;
+ }
+
+ // If we still have NULL packet, stop here.
if(packet == NULL) {
break;
- } else {
- dec->clock_pos = packet->pts;
}
- if(packet->pts > sync_ts - AUDIO_SYNC_THRESHOLD) {
+
+ dec->clock_pos = packet->pts;
+ if(packet->pts > sync_ts - KIT_AUDIO_SYNC_THRESHOLD) {
break;
}
}