summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTuomas Virtanen <katajakasa@gmail.com>2018-11-15 00:54:21 +0200
committerTuomas Virtanen <katajakasa@gmail.com>2018-11-15 00:54:21 +0200
commitf7d7216cffb27789229d3dbb5e05e8e833f492d5 (patch)
treec69fa0ecb82ef4422e71458dc1110d74604b2c15
parent76bc8c49d46be38f6d4a65a810f8ef64923daef9 (diff)
Fix last playback problems with new decoders
-rw-r--r--examples/example_complex.c6
-rw-r--r--include/kitchensink/internal/subtitle/kitsubtitle.h2
-rw-r--r--src/internal/kitdecoder.c2
-rw-r--r--src/internal/subtitle/kitsubtitle.c5
-rw-r--r--src/internal/subtitle/renderers/kitsubass.c2
-rw-r--r--src/internal/video/kitvideo.c33
-rw-r--r--src/kitlib.c6
-rw-r--r--src/kitplayer.c11
8 files changed, 37 insertions, 30 deletions
diff --git a/examples/example_complex.c b/examples/example_complex.c
index aeda110..9f5d8aa 100644
--- a/examples/example_complex.c
+++ b/examples/example_complex.c
@@ -109,7 +109,11 @@ int main(int argc, char *argv[]) {
}
// Allow Kit to use more threads
- Kit_SetHint(KIT_HINT_THREAD_COUNT, SDL_GetCPUCount() <= 8 ? SDL_GetCPUCount() : 8);
+ Kit_SetHint(KIT_HINT_THREAD_COUNT, SDL_GetCPUCount());
+
+ // Lots of buffers for smooth playback (will eat up more memory, too).
+ Kit_SetHint(KIT_HINT_VIDEO_BUFFER_FRAMES, 5);
+ Kit_SetHint(KIT_HINT_AUDIO_BUFFER_FRAMES, 192);
// Open up the sourcefile.
// This can be a local file, network url, ...
diff --git a/include/kitchensink/internal/subtitle/kitsubtitle.h b/include/kitchensink/internal/subtitle/kitsubtitle.h
index 8bb2a62..09aabec 100644
--- a/include/kitchensink/internal/subtitle/kitsubtitle.h
+++ b/include/kitchensink/internal/subtitle/kitsubtitle.h
@@ -9,7 +9,7 @@
KIT_LOCAL Kit_Decoder* Kit_CreateSubtitleDecoder(
const Kit_Source *src, int stream_index, int video_w, int video_h, int screen_w, int screen_h);
-KIT_LOCAL void Kit_GetSubtitleDecoderTexture(Kit_Decoder *dec, SDL_Texture *texture);
+KIT_LOCAL void Kit_GetSubtitleDecoderTexture(Kit_Decoder *dec, SDL_Texture *texture, double sync_ts);
KIT_LOCAL void Kit_SetSubtitleDecoderSize(Kit_Decoder *dec, int w, int h);
KIT_LOCAL int Kit_GetSubtitleDecoderInfo(
Kit_Decoder *dec, SDL_Texture *texture, SDL_Rect *sources, SDL_Rect *targets, int limit);
diff --git a/src/internal/kitdecoder.c b/src/internal/kitdecoder.c
index 426e32c..6f8aab3 100644
--- a/src/internal/kitdecoder.c
+++ b/src/internal/kitdecoder.c
@@ -6,7 +6,7 @@
#include "kitchensink/internal/kitdecoder.h"
#include "kitchensink/kiterror.h"
-#define BUFFER_IN_SIZE 256
+#define BUFFER_IN_SIZE 384
static void free_in_video_packet_cb(void *packet) {
av_packet_free((AVPacket**)&packet);
diff --git a/src/internal/subtitle/kitsubtitle.c b/src/internal/subtitle/kitsubtitle.c
index bd28fac..024179e 100644
--- a/src/internal/subtitle/kitsubtitle.c
+++ b/src/internal/subtitle/kitsubtitle.c
@@ -177,14 +177,11 @@ void Kit_SetSubtitleDecoderSize(Kit_Decoder *dec, int screen_w, int screen_h) {
Kit_SetSubtitleRendererSize(subtitle_dec->renderer, screen_w, screen_h);
}
-void Kit_GetSubtitleDecoderTexture(Kit_Decoder *dec, SDL_Texture *texture) {
+void Kit_GetSubtitleDecoderTexture(Kit_Decoder *dec, SDL_Texture *texture, double sync_ts) {
assert(dec != NULL);
assert(texture != NULL);
Kit_SubtitleDecoder *subtitle_dec = dec->userdata;
- double sync_ts = _GetSystemTime() - dec->clock_sync;
-
- // Tell the renderer to render content to atlas
Kit_GetSubtitleRendererData(subtitle_dec->renderer, subtitle_dec->atlas, texture, sync_ts);
}
diff --git a/src/internal/subtitle/renderers/kitsubass.c b/src/internal/subtitle/renderers/kitsubass.c
index c229406..4c48f75 100644
--- a/src/internal/subtitle/renderers/kitsubass.c
+++ b/src/internal/subtitle/renderers/kitsubass.c
@@ -88,7 +88,7 @@ static int ren_get_ass_data_cb(Kit_SubtitleRenderer *ren, Kit_TextureAtlas *atla
SDL_Surface *dst = NULL;
ASS_Image *src = NULL;
int change = 0;
- unsigned int now = current_pts * 1000;
+ long long now = current_pts * 1000;
if(Kit_LockDecoderOutput(ren->dec) == 0) {
// Tell ASS to render some images
diff --git a/src/internal/video/kitvideo.c b/src/internal/video/kitvideo.c
index 112efc0..1f2bed9 100644
--- a/src/internal/video/kitvideo.c
+++ b/src/internal/video/kitvideo.c
@@ -154,27 +154,15 @@ static int dec_decode_video_cb(Kit_Decoder *dec, AVPacket *in_packet) {
return 0;
}
#else
-static int dec_decode_video_cb(Kit_Decoder *dec, AVPacket *in_packet) {
- assert(dec != NULL);
- assert(in_packet != NULL);
-
+static void dec_read_video(Kit_Decoder *dec) {
Kit_VideoDecoder *video_dec = dec->userdata;
AVFrame *out_frame = NULL;
Kit_VideoPacket *out_packet = NULL;
double pts;
- int ret;
-
- // Write packet to the decoder for handling.
- ret = avcodec_send_packet(dec->codec_ctx, in_packet);
- if(ret < 0) {
- return 1;
- }
+ int ret = 0;
- // Pull decoded frames out when ready and if we have room in decoder output buffer
- LOG("OUT\n");
while(!ret && Kit_CanWriteDecoderOutput(dec)) {
ret = avcodec_receive_frame(dec->codec_ctx, video_dec->scratch_frame);
- LOG("DEC FRAME\n");
if(!ret) {
out_frame = av_frame_alloc();
av_image_alloc(
@@ -204,6 +192,23 @@ static int dec_decode_video_cb(Kit_Decoder *dec, AVPacket *in_packet) {
Kit_WriteDecoderOutput(dec, out_packet);
}
}
+}
+
+static int dec_decode_video_cb(Kit_Decoder *dec, AVPacket *in_packet) {
+ assert(dec != NULL);
+ assert(in_packet != NULL);
+
+ // Try to clear the buffer first. We might have too much content in the ffmpeg buffer,
+ /// so we want to clear it of outgoing data if we can.
+ dec_read_video(dec);
+
+ // Write packet to the decoder for handling.
+ if(avcodec_send_packet(dec->codec_ctx, in_packet) < 0) {
+ return 1;
+ }
+
+ // Some input data was put in succesfully, so try again to get frames.
+ dec_read_video(dec);
return 0;
}
#endif
diff --git a/src/kitlib.c b/src/kitlib.c
index 9cfd13e..e823c52 100644
--- a/src/kitlib.c
+++ b/src/kitlib.c
@@ -94,13 +94,13 @@ void Kit_SetHint(Kit_HintType type, int value) {
state->font_hinting = max(min(value, KIT_FONT_HINTING_COUNT), 0);
break;
case KIT_HINT_VIDEO_BUFFER_FRAMES:
- state->video_buf_frames = min(value, 1);
+ state->video_buf_frames = max(value, 1);
break;
case KIT_HINT_AUDIO_BUFFER_FRAMES:
- state->audio_buf_frames = min(value, 1);
+ state->audio_buf_frames = max(value, 1);
break;
case KIT_HINT_SUBTITLE_BUFFER_FRAMES:
- state->subtitle_buf_frames = min(value, 1);
+ state->subtitle_buf_frames = max(value, 1);
break;
}
}
diff --git a/src/kitplayer.c b/src/kitplayer.c
index 0baf57b..f852e48 100644
--- a/src/kitplayer.c
+++ b/src/kitplayer.c
@@ -310,14 +310,15 @@ int Kit_GetPlayerSubtitleData(Kit_Player *player, SDL_Texture *texture, SDL_Rect
assert(targets != NULL);
assert(limit >= 0);
- Kit_Decoder *dec = player->decoders[KIT_SUBTITLE_DEC];
- if(dec == NULL) {
+ Kit_Decoder *sub_dec = player->decoders[KIT_SUBTITLE_DEC];
+ Kit_Decoder *video_dec = player->decoders[KIT_VIDEO_DEC];
+ if(sub_dec == NULL || video_dec == NULL) {
return 0;
}
// If paused, just return the current items
if(player->state == KIT_PAUSED) {
- return Kit_GetSubtitleDecoderInfo(dec, texture, sources, targets, limit);
+ return Kit_GetSubtitleDecoderInfo(sub_dec, texture, sources, targets, limit);
}
// If stopped, do nothing.
@@ -326,8 +327,8 @@ int Kit_GetPlayerSubtitleData(Kit_Player *player, SDL_Texture *texture, SDL_Rect
}
// Refresh texture, then refresh rects and return number of items in the texture.
- Kit_GetSubtitleDecoderTexture(dec, texture);
- return Kit_GetSubtitleDecoderInfo(dec, texture, sources, targets, limit);
+ Kit_GetSubtitleDecoderTexture(sub_dec, texture, video_dec->clock_pos);
+ return Kit_GetSubtitleDecoderInfo(sub_dec, texture, sources, targets, limit);
}
void Kit_GetPlayerInfo(const Kit_Player *player, Kit_PlayerInfo *info) {