summaryrefslogtreecommitdiff
path: root/src/internal
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
parent41c8ad5142e4de9b6c667840b9b5b4b66be3f71e (diff)
Improved frameskip
Diffstat (limited to 'src/internal')
-rw-r--r--src/internal/audio/kitaudio.c28
-rw-r--r--src/internal/video/kitvideo.c22
2 files changed, 35 insertions, 15 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;
}
}
diff --git a/src/internal/video/kitvideo.c b/src/internal/video/kitvideo.c
index 350d3c5..d0dd74b 100644
--- a/src/internal/video/kitvideo.c
+++ b/src/internal/video/kitvideo.c
@@ -12,7 +12,7 @@
#include "kitchensink/internal/video/kitvideo.h"
#include "kitchensink/internal/utils/kitlog.h"
-#define KIT_VIDEO_SYNC_THRESHOLD 0.01
+#define KIT_VIDEO_SYNC_THRESHOLD 0.02
enum AVPixelFormat supported_list[] = {
AV_PIX_FMT_YUV420P,
@@ -248,6 +248,7 @@ int Kit_GetVideoDecoderData(Kit_Decoder *dec, SDL_Texture *texture) {
assert(dec != NULL);
assert(texture != NULL);
+ Kit_VideoPacket *next_packet = NULL;
Kit_VideoPacket *packet = Kit_PeekDecoderOutput(dec);
if(packet == NULL) {
return 0;
@@ -261,15 +262,24 @@ int Kit_GetVideoDecoderData(Kit_Decoder *dec, SDL_Texture *texture) {
return 0;
} else if(packet->pts < sync_ts - KIT_VIDEO_SYNC_THRESHOLD) {
// Video is lagging, skip until we find a good PTS to continue from.
+ LOG("V LAG %f < %f\n", packet->pts, sync_ts - KIT_VIDEO_SYNC_THRESHOLD);
+ Kit_AdvanceDecoderOutput(dec);
while(packet != NULL) {
- Kit_AdvanceDecoderOutput(dec);
- free_out_video_packet_cb(packet);
- packet = Kit_PeekDecoderOutput(dec);
+ next_packet = Kit_PeekDecoderOutput(dec);
+
+ // If next packet is valid, remove this one and jump to next.
+ if(next_packet != NULL) {
+ Kit_AdvanceDecoderOutput(dec);
+ free_out_video_packet_cb(packet);
+ packet = next_packet;
+ }
+
+ // If we still have NULL packet, stop here.
if(packet == NULL) {
break;
- } else {
- dec->clock_pos = packet->pts;
}
+
+ dec->clock_pos = packet->pts;
if(packet->pts > sync_ts - KIT_VIDEO_SYNC_THRESHOLD) {
break;
}