summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/kitchensink/internal/audio/kitaudio.h2
-rw-r--r--include/kitchensink/internal/kitdecoder.h6
-rw-r--r--include/kitchensink/internal/subtitle/kitsubtitle.h6
-rw-r--r--src/internal/audio/kitaudio.c22
-rw-r--r--src/internal/kitdecoder.c32
-rw-r--r--src/internal/subtitle/kitatlas.c19
-rw-r--r--src/internal/subtitle/kitsubtitle.c22
-rw-r--r--src/internal/subtitle/renderers/kitsubass.c35
-rw-r--r--src/internal/subtitle/renderers/kitsubimage.c15
-rw-r--r--src/internal/video/kitvideo.c20
-rw-r--r--src/kitlib.c8
-rw-r--r--src/kitplayer.c30
-rw-r--r--src/kitsource.c28
13 files changed, 125 insertions, 120 deletions
diff --git a/include/kitchensink/internal/audio/kitaudio.h b/include/kitchensink/internal/audio/kitaudio.h
index c3db420..0558343 100644
--- a/include/kitchensink/internal/audio/kitaudio.h
+++ b/include/kitchensink/internal/audio/kitaudio.h
@@ -7,6 +7,6 @@
KIT_LOCAL Kit_Decoder* Kit_CreateAudioDecoder(const Kit_Source *src, int stream_index);
KIT_LOCAL int Kit_GetAudioDecoderData(Kit_Decoder *dec, unsigned char *buf, int len);
-KIT_LOCAL double Kit_GetAudioDecoderPTS(Kit_Decoder *dec);
+KIT_LOCAL double Kit_GetAudioDecoderPTS(const Kit_Decoder *dec);
#endif // KITAUDIO_H
diff --git a/include/kitchensink/internal/kitdecoder.h b/include/kitchensink/internal/kitdecoder.h
index a3f6b61..e12c5fe 100644
--- a/include/kitchensink/internal/kitdecoder.h
+++ b/include/kitchensink/internal/kitdecoder.h
@@ -55,7 +55,7 @@ KIT_LOCAL void Kit_SetDecoderClockSync(Kit_Decoder *dec, double sync);
KIT_LOCAL void Kit_ChangeDecoderClockSync(Kit_Decoder *dec, double sync);
KIT_LOCAL int Kit_RunDecoder(Kit_Decoder *dec);
-KIT_LOCAL void Kit_ClearDecoderBuffers(Kit_Decoder *dec);
+KIT_LOCAL void Kit_ClearDecoderBuffers(const Kit_Decoder *dec);
KIT_LOCAL bool Kit_CanWriteDecoderInput(const Kit_Decoder *dec);
KIT_LOCAL int Kit_WriteDecoderInput(const Kit_Decoder *dec, AVPacket *packet);
@@ -73,7 +73,7 @@ KIT_LOCAL void Kit_AdvanceDecoderOutput(const Kit_Decoder *dec);
KIT_LOCAL void Kit_ForEachDecoderOutput(const Kit_Decoder *dec, Kit_ForEachItemCallback foreach_cb, void *userdata);
KIT_LOCAL unsigned int Kit_GetDecoderOutputLength(const Kit_Decoder *dec);
-KIT_LOCAL int Kit_LockDecoderOutput(Kit_Decoder *dec);
-KIT_LOCAL void Kit_UnlockDecoderOutput(Kit_Decoder *dec);
+KIT_LOCAL int Kit_LockDecoderOutput(const Kit_Decoder *dec);
+KIT_LOCAL void Kit_UnlockDecoderOutput(const Kit_Decoder *dec);
#endif // KITDECODER_H
diff --git a/include/kitchensink/internal/subtitle/kitsubtitle.h b/include/kitchensink/internal/subtitle/kitsubtitle.h
index 09aabec..09ce8ad 100644
--- a/include/kitchensink/internal/subtitle/kitsubtitle.h
+++ b/include/kitchensink/internal/subtitle/kitsubtitle.h
@@ -9,9 +9,9 @@
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, double sync_ts);
-KIT_LOCAL void Kit_SetSubtitleDecoderSize(Kit_Decoder *dec, int w, int h);
+KIT_LOCAL void Kit_GetSubtitleDecoderTexture(const Kit_Decoder *dec, SDL_Texture *texture, double sync_ts);
+KIT_LOCAL void Kit_SetSubtitleDecoderSize(const 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);
+ const Kit_Decoder *dec, const SDL_Texture *texture, SDL_Rect *sources, SDL_Rect *targets, int limit);
#endif // KITSUBTITLE_H
diff --git a/src/internal/audio/kitaudio.c b/src/internal/audio/kitaudio.c
index 04dd4f1..b950fd9 100644
--- a/src/internal/audio/kitaudio.c
+++ b/src/internal/audio/kitaudio.c
@@ -182,8 +182,8 @@ static int dec_decode_audio_cb(Kit_Decoder *dec, AVPacket *in_packet) {
return 0;
}
#else
-static void dec_read_audio(Kit_Decoder *dec) {
- Kit_AudioDecoder *audio_dec = dec->userdata;
+static void dec_read_audio(const Kit_Decoder *dec) {
+ const Kit_AudioDecoder *audio_dec = dec->userdata;
int len;
int dst_linesize;
int dst_nb_samples;
@@ -288,20 +288,20 @@ Kit_Decoder* Kit_CreateAudioDecoder(const Kit_Source *src, int stream_index) {
free_out_audio_packet_cb,
state->thread_count);
if(dec == NULL) {
- goto exit_0;
+ goto EXIT_0;
}
// ... then allocate the audio decoder
Kit_AudioDecoder *audio_dec = calloc(1, sizeof(Kit_AudioDecoder));
if(audio_dec == NULL) {
- goto exit_1;
+ goto EXIT_1;
}
// Create temporary audio frame
audio_dec->scratch_frame = av_frame_alloc();
if(audio_dec->scratch_frame == NULL) {
Kit_SetError("Unable to initialize temporary audio frame");
- goto exit_2;
+ goto EXIT_2;
}
// Set format configs
@@ -326,7 +326,7 @@ Kit_Decoder* Kit_CreateAudioDecoder(const Kit_Source *src, int stream_index) {
if(swr_init(audio_dec->swr) != 0) {
Kit_SetError("Unable to initialize audio resampler context");
- goto exit_3;
+ goto EXIT_3;
}
// Set callbacks and userdata, and we're go
@@ -336,17 +336,17 @@ Kit_Decoder* Kit_CreateAudioDecoder(const Kit_Source *src, int stream_index) {
dec->output = output;
return dec;
-exit_3:
+EXIT_3:
av_frame_free(&audio_dec->scratch_frame);
-exit_2:
+EXIT_2:
free(audio_dec);
-exit_1:
+EXIT_1:
Kit_CloseDecoder(dec);
-exit_0:
+EXIT_0:
return NULL;
}
-double Kit_GetAudioDecoderPTS(Kit_Decoder *dec) {
+double Kit_GetAudioDecoderPTS(const Kit_Decoder *dec) {
const Kit_AudioPacket *packet = Kit_PeekDecoderOutput(dec);
if(packet == NULL) {
return -1.0;
diff --git a/src/internal/kitdecoder.c b/src/internal/kitdecoder.c
index 530473e..c5b5589 100644
--- a/src/internal/kitdecoder.c
+++ b/src/internal/kitdecoder.c
@@ -21,7 +21,7 @@ Kit_Decoder* Kit_CreateDecoder(const Kit_Source *src, int stream_index,
AVCodecContext *codec_ctx = NULL;
AVDictionary *codec_opts = NULL;
- AVCodec *codec = NULL;
+ const AVCodec *codec = NULL;
AVFormatContext *format_ctx = src->format_ctx;
int bsizes[2] = {BUFFER_IN_SIZE, out_b_size};
dec_free_packet_cb free_hooks[2] = {free_in_video_packet_cb, free_out_cb};
@@ -29,14 +29,14 @@ Kit_Decoder* Kit_CreateDecoder(const Kit_Source *src, int stream_index,
// Make sure index seems correct
if(stream_index >= (int)format_ctx->nb_streams || stream_index < 0) {
Kit_SetError("Invalid stream %d", stream_index);
- goto exit_0;
+ goto EXIT_0;
}
// Allocate decoder and make sure allocation was a success
Kit_Decoder *dec = calloc(1, sizeof(Kit_Decoder));
if(dec == NULL) {
Kit_SetError("Unable to allocate kit decoder for stream %d", stream_index);
- goto exit_0;
+ goto EXIT_0;
}
// Find audio decoder
@@ -47,14 +47,14 @@ Kit_Decoder* Kit_CreateDecoder(const Kit_Source *src, int stream_index,
#endif
if(codec == NULL) {
Kit_SetError("No suitable decoder found for stream %d", stream_index);
- goto exit_1;
+ goto EXIT_1;
}
// Allocate a context for the codec
codec_ctx = avcodec_alloc_context3(codec);
if(codec_ctx == NULL) {
Kit_SetError("Unable to allocate codec context for stream %d", stream_index);
- goto exit_1;
+ goto EXIT_1;
}
// Copy params
@@ -65,7 +65,7 @@ Kit_Decoder* Kit_CreateDecoder(const Kit_Source *src, int stream_index,
#endif
{
Kit_SetError("Unable to copy codec context for stream %d", stream_index);
- goto exit_2;
+ goto EXIT_2;
}
// Required by ffmpeg for now when using the new API.
@@ -85,7 +85,7 @@ Kit_Decoder* Kit_CreateDecoder(const Kit_Source *src, int stream_index,
// Open the stream
if(avcodec_open2(codec_ctx, codec, &codec_opts) < 0) {
Kit_SetError("Unable to open codec for stream %d", stream_index);
- goto exit_2;
+ goto EXIT_2;
}
// Set index and codec
@@ -98,7 +98,7 @@ Kit_Decoder* Kit_CreateDecoder(const Kit_Source *src, int stream_index,
dec->buffer[i] = Kit_CreateBuffer(bsizes[i], free_hooks[i]);
if(dec->buffer[i] == NULL) {
Kit_SetError("Unable to allocate buffer for stream %d: %s", stream_index, SDL_GetError());
- goto exit_3;
+ goto EXIT_3;
}
}
@@ -106,23 +106,23 @@ Kit_Decoder* Kit_CreateDecoder(const Kit_Source *src, int stream_index,
dec->output_lock = SDL_CreateMutex();
if(dec->output_lock == NULL) {
Kit_SetError("Unable to allocate mutex for stream %d: %s", stream_index, SDL_GetError());
- goto exit_3;
+ goto EXIT_3;
}
// That's that
return dec;
-exit_3:
+EXIT_3:
for(int i = 0; i < KIT_DEC_BUF_COUNT; i++) {
Kit_DestroyBuffer(dec->buffer[i]);
}
avcodec_close(codec_ctx);
-exit_2:
+EXIT_2:
av_dict_free(&codec_opts);
avcodec_free_context(&codec_ctx);
-exit_1:
+EXIT_1:
free(dec);
-exit_0:
+EXIT_0:
return NULL;
}
@@ -170,7 +170,7 @@ int Kit_RunDecoder(Kit_Decoder *dec) {
return 0;
}
-void Kit_ClearDecoderBuffers(Kit_Decoder *dec) {
+void Kit_ClearDecoderBuffers(const Kit_Decoder *dec) {
if(dec == NULL) return;
Kit_ClearDecoderInput(dec);
Kit_ClearDecoderOutput(dec);
@@ -325,10 +325,10 @@ unsigned int Kit_GetDecoderOutputLength(const Kit_Decoder *dec) {
return len;
}
-int Kit_LockDecoderOutput(Kit_Decoder *dec) {
+int Kit_LockDecoderOutput(const Kit_Decoder *dec) {
return SDL_LockMutex(dec->output_lock);
}
-void Kit_UnlockDecoderOutput(Kit_Decoder *dec) {
+void Kit_UnlockDecoderOutput(const Kit_Decoder *dec) {
SDL_UnlockMutex(dec->output_lock);
}
diff --git a/src/internal/subtitle/kitatlas.c b/src/internal/subtitle/kitatlas.c
index e7bb654..31a4800 100644
--- a/src/internal/subtitle/kitatlas.c
+++ b/src/internal/subtitle/kitatlas.c
@@ -13,7 +13,7 @@ static int min(int a, int b) {
Kit_TextureAtlas* Kit_CreateAtlas() {
Kit_TextureAtlas *atlas = calloc(1, sizeof(Kit_TextureAtlas));
if(atlas == NULL) {
- goto exit_0;
+ goto EXIT_0;
}
atlas->cur_items = 0;
atlas->max_items = 1024;
@@ -24,22 +24,22 @@ Kit_TextureAtlas* Kit_CreateAtlas() {
// Allocate items. These hold the surfaces that should be in atlas
atlas->items = calloc(atlas->max_items, sizeof(Kit_TextureAtlasItem));
if(atlas->items == NULL) {
- goto exit_1;
+ goto EXIT_1;
}
// Allocate shelves. These describe the used space of the atlas
atlas->shelves = calloc(atlas->max_shelves, sizeof(Kit_Shelf));
if(atlas->shelves == NULL) {
- goto exit_2;
+ goto EXIT_2;
}
return atlas;
-exit_2:
+EXIT_2:
free(atlas->items);
-exit_1:
+EXIT_1:
free(atlas);
-exit_0:
+EXIT_0:
return NULL;
}
@@ -56,7 +56,7 @@ void Kit_FreeAtlas(Kit_TextureAtlas *atlas) {
free(atlas);
}
-void Kit_SetItemAllocation(Kit_TextureAtlasItem *item, SDL_Surface *surface, int shelf, int slot, int x, int y) {
+void Kit_SetItemAllocation(Kit_TextureAtlasItem *item, const SDL_Surface *surface, int shelf, int slot, int x, int y) {
assert(item != NULL);
item->cur_shelf = shelf;
@@ -67,7 +67,7 @@ void Kit_SetItemAllocation(Kit_TextureAtlasItem *item, SDL_Surface *surface, int
item->source.h = surface->h;
}
-int Kit_FindFreeAtlasSlot(Kit_TextureAtlas *atlas, SDL_Surface *surface, Kit_TextureAtlasItem *item) {
+int Kit_FindFreeAtlasSlot(const Kit_TextureAtlas *atlas, const SDL_Surface *surface, Kit_TextureAtlasItem *item) {
assert(atlas != NULL);
assert(item != NULL);
@@ -145,10 +145,11 @@ void Kit_CheckAtlasTextureSize(Kit_TextureAtlas *atlas, SDL_Texture *texture) {
int Kit_GetAtlasItems(const Kit_TextureAtlas *atlas, SDL_Rect *sources, SDL_Rect *targets, int limit) {
assert(atlas != NULL);
assert(limit >= 0);
+ const Kit_TextureAtlasItem *item = NULL;
int max_count = min(atlas->cur_items, limit);
for(int i = 0; i < max_count; i++) {
- Kit_TextureAtlasItem *item = &atlas->items[i];
+ item = &atlas->items[i];
if(sources != NULL)
memcpy(&sources[i], &item->source, sizeof(SDL_Rect));
if(targets != NULL)
diff --git a/src/internal/subtitle/kitsubtitle.c b/src/internal/subtitle/kitsubtitle.c
index e222794..32c8a9b 100644
--- a/src/internal/subtitle/kitsubtitle.c
+++ b/src/internal/subtitle/kitsubtitle.c
@@ -106,14 +106,14 @@ Kit_Decoder* Kit_CreateSubtitleDecoder(const Kit_Source *src, int stream_index,
state->thread_count);
if(dec == NULL) {
Kit_SetError("Unable to allocate subtitle decoder");
- goto exit_0;
+ goto EXIT_0;
}
// ... then allocate the subtitle decoder
Kit_SubtitleDecoder *subtitle_dec = calloc(1, sizeof(Kit_SubtitleDecoder));
if(subtitle_dec == NULL) {
Kit_SetError("Unable to allocate subtitle decoder");
- goto exit_1;
+ goto EXIT_1;
}
// Set format. Note that is_enabled may be changed below ...
@@ -144,14 +144,14 @@ Kit_Decoder* Kit_CreateSubtitleDecoder(const Kit_Source *src, int stream_index,
break;
}
if(subtitle_dec->renderer == NULL) {
- goto exit_2;
+ goto EXIT_2;
}
// Allocate texture atlas for subtitle rectangles
subtitle_dec->atlas = Kit_CreateAtlas();
if(subtitle_dec->atlas == NULL) {
Kit_SetError("Unable to allocate subtitle texture atlas");
- goto exit_3;
+ goto EXIT_3;
}
// Set callbacks and userdata, and we're go
@@ -161,23 +161,23 @@ Kit_Decoder* Kit_CreateSubtitleDecoder(const Kit_Source *src, int stream_index,
dec->output = output;
return dec;
-exit_3:
+EXIT_3:
Kit_CloseSubtitleRenderer(subtitle_dec->renderer);
-exit_2:
+EXIT_2:
free(subtitle_dec);
-exit_1:
+EXIT_1:
Kit_CloseDecoder(dec);
-exit_0:
+EXIT_0:
return NULL;
}
-void Kit_SetSubtitleDecoderSize(Kit_Decoder *dec, int screen_w, int screen_h) {
+void Kit_SetSubtitleDecoderSize(const Kit_Decoder *dec, int screen_w, int screen_h) {
assert(dec != NULL);
const Kit_SubtitleDecoder *subtitle_dec = dec->userdata;
Kit_SetSubtitleRendererSize(subtitle_dec->renderer, screen_w, screen_h);
}
-void Kit_GetSubtitleDecoderTexture(Kit_Decoder *dec, SDL_Texture *texture, double sync_ts) {
+void Kit_GetSubtitleDecoderTexture(const Kit_Decoder *dec, SDL_Texture *texture, double sync_ts) {
assert(dec != NULL);
assert(texture != NULL);
@@ -185,7 +185,7 @@ void Kit_GetSubtitleDecoderTexture(Kit_Decoder *dec, SDL_Texture *texture, doubl
Kit_GetSubtitleRendererData(subtitle_dec->renderer, subtitle_dec->atlas, texture, sync_ts);
}
-int Kit_GetSubtitleDecoderInfo(Kit_Decoder *dec, SDL_Texture *texture, SDL_Rect *sources, SDL_Rect *targets, int limit) {
+int Kit_GetSubtitleDecoderInfo(const Kit_Decoder *dec, const SDL_Texture *texture, SDL_Rect *sources, SDL_Rect *targets, int limit) {
const Kit_SubtitleDecoder *subtitle_dec = dec->userdata;
return Kit_GetAtlasItems(subtitle_dec->atlas, sources, targets, limit);
}
diff --git a/src/internal/subtitle/renderers/kitsubass.c b/src/internal/subtitle/renderers/kitsubass.c
index b2c37c8..49ac13f 100644
--- a/src/internal/subtitle/renderers/kitsubass.c
+++ b/src/internal/subtitle/renderers/kitsubass.c
@@ -17,12 +17,12 @@ typedef struct Kit_ASSSubtitleRenderer {
ASS_Track *track;
} Kit_ASSSubtitleRenderer;
-static void Kit_ProcessAssImage(SDL_Surface *surface, const ASS_Image *img) {
+static void Kit_ProcessAssImage(const SDL_Surface *surface, const ASS_Image *img) {
unsigned char r = ((img->color) >> 24) & 0xFF;
unsigned char g = ((img->color) >> 16) & 0xFF;
unsigned char b = ((img->color) >> 8) & 0xFF;
unsigned char a = 0xFF - ((img->color) & 0xFF);
- unsigned char *src = img->bitmap;
+ const unsigned char *src = img->bitmap;
unsigned char *dst = surface->pixels;
unsigned int x;
unsigned int y;
@@ -45,8 +45,8 @@ static void ren_render_ass_cb(Kit_SubtitleRenderer *ren, void *src, double pts,
assert(ren != NULL);
assert(src != NULL);
- Kit_ASSSubtitleRenderer *ass_ren = ren->userdata;
- AVSubtitle *sub = src;
+ const Kit_ASSSubtitleRenderer *ass_ren = ren->userdata;
+ const AVSubtitle *sub = src;
// Read incoming subtitle packets to libASS
long long start_ms = (start + pts) * 1000;
@@ -84,9 +84,9 @@ static void ren_close_ass_cb(Kit_SubtitleRenderer *ren) {
}
static int ren_get_ass_data_cb(Kit_SubtitleRenderer *ren, Kit_TextureAtlas *atlas, SDL_Texture *texture, double current_pts) {
- Kit_ASSSubtitleRenderer *ass_ren = ren->userdata;
+ const Kit_ASSSubtitleRenderer *ass_ren = ren->userdata;
SDL_Surface *dst = NULL;
- ASS_Image *src = NULL;
+ const ASS_Image *src = NULL;
int change = 0;
long long now = current_pts * 1000;
@@ -125,7 +125,7 @@ static int ren_get_ass_data_cb(Kit_SubtitleRenderer *ren, Kit_TextureAtlas *atla
}
static void ren_set_ass_size_cb(Kit_SubtitleRenderer *ren, int w, int h) {
- Kit_ASSSubtitleRenderer *ass_ren = ren->userdata;
+ const Kit_ASSSubtitleRenderer *ass_ren = ren->userdata;
ass_set_frame_size(ass_ren->renderer, w, h);
}
@@ -146,30 +146,31 @@ Kit_SubtitleRenderer* Kit_CreateASSSubtitleRenderer(Kit_Decoder *dec, int video_
// First allocate the generic decoder component
Kit_SubtitleRenderer *ren = Kit_CreateSubtitleRenderer(dec);
if(ren == NULL) {
- goto exit_0;
+ goto EXIT_0;
}
// Next, allocate ASS subtitle renderer context.
Kit_ASSSubtitleRenderer *ass_ren = calloc(1, sizeof(Kit_ASSSubtitleRenderer));
if(ass_ren == NULL) {
Kit_SetError("Unable to allocate ass subtitle renderer");
- goto exit_1;
+ goto EXIT_1;
}
// Initialize libass renderer
ASS_Renderer *ass_renderer = ass_renderer_init(state->libass_handle);
if(ass_renderer == NULL) {
Kit_SetError("Unable to initialize libass renderer");
- goto exit_2;
+ goto EXIT_2;
}
// Read fonts from attachment streams and give them to libass
+ const AVStream *st = NULL;
for(int j = 0; j < dec->format_ctx->nb_streams; j++) {
- AVStream *st = dec->format_ctx->streams[j];
+ st = dec->format_ctx->streams[j];
#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(57, 48, 101)
AVCodecContext *codec = st->codec;
#else
- AVCodecParameters *codec = st->codecpar;
+ const AVCodecParameters *codec = st->codecpar;
#endif
if(codec->codec_type == AVMEDIA_TYPE_ATTACHMENT && attachment_is_font(st)) {
const AVDictionaryEntry *tag = av_dict_get(
@@ -201,7 +202,7 @@ Kit_SubtitleRenderer* Kit_CreateASSSubtitleRenderer(Kit_Decoder *dec, int video_
ASS_Track *ass_track = ass_new_track(state->libass_handle);
if(ass_track == NULL) {
Kit_SetError("Unable to initialize libass track");
- goto exit_3;
+ goto EXIT_3;
}
// Set up libass track headers (ffmpeg provides these)
@@ -222,12 +223,12 @@ Kit_SubtitleRenderer* Kit_CreateASSSubtitleRenderer(Kit_Decoder *dec, int video_
ren->userdata = ass_ren;
return ren;
-exit_3:
+EXIT_3:
ass_renderer_done(ass_renderer);
-exit_2:
+EXIT_2:
free(ass_ren);
-exit_1:
+EXIT_1:
Kit_CloseSubtitleRenderer(ren);
-exit_0:
+EXIT_0:
return NULL;
}
diff --git a/src/internal/subtitle/renderers/kitsubimage.c b/src/internal/subtitle/renderers/kitsubimage.c
index b9a8e48..25da545 100644
--- a/src/internal/subtitle/renderers/kitsubimage.c
+++ b/src/internal/subtitle/renderers/kitsubimage.c
@@ -21,7 +21,7 @@ static void ren_render_image_cb(Kit_SubtitleRenderer *ren, void *sub_src, double
assert(ren != NULL);
assert(sub_src != NULL);
- AVSubtitle *sub = sub_src;
+ const AVSubtitle *sub = sub_src;
SDL_Surface *dst = NULL;
SDL_Surface *src = NULL;
double start_pts = pts + start;
@@ -35,8 +35,9 @@ static void ren_render_image_cb(Kit_SubtitleRenderer *ren, void *sub_src, double
}
// Convert subtitle images from paletted to RGBA8888
+ const AVSubtitleRect *r = NULL;
for(int n = 0; n < sub->num_rects; n++) {
- AVSubtitleRect *r = sub->rects[n];
+ r = sub->rects[n];
if(r->type != SUBTITLE_BITMAP)
continue;
@@ -60,7 +61,7 @@ static void ren_render_image_cb(Kit_SubtitleRenderer *ren, void *sub_src, double
}
static int ren_get_img_data_cb(Kit_SubtitleRenderer *ren, Kit_TextureAtlas *atlas, SDL_Texture *texture, double current_pts) {
- Kit_ImageSubtitleRenderer *img_ren = ren->userdata;
+ const Kit_ImageSubtitleRenderer *img_ren = ren->userdata;
Kit_SubtitlePacket *packet = NULL;
Kit_CheckAtlasTextureSize(atlas, texture);
@@ -117,14 +118,14 @@ Kit_SubtitleRenderer* Kit_CreateImageSubtitleRenderer(Kit_Decoder *dec, int vide
// Allocate a new renderer
Kit_SubtitleRenderer *ren = Kit_CreateSubtitleRenderer(dec);
if(ren == NULL) {
- goto exit_0;
+ goto EXIT_0;
}
// Allocate image renderer internal context
Kit_ImageSubtitleRenderer *img_ren = calloc(1, sizeof(Kit_ImageSubtitleRenderer));
if(img_ren == NULL) {
Kit_SetError("Unable to allocate image subtitle renderer");
- goto exit_1;
+ goto EXIT_1;
}
// Only renderer required, no other data.
@@ -139,8 +140,8 @@ Kit_SubtitleRenderer* Kit_CreateImageSubtitleRenderer(Kit_Decoder *dec, int vide
ren->userdata = img_ren;
return ren;
-exit_1:
+EXIT_1:
Kit_CloseSubtitleRenderer(ren);
-exit_0:
+EXIT_0:
return NULL;
}
diff --git a/src/internal/video/kitvideo.c b/src/internal/video/kitvideo.c
index a29d58d..d2e0272 100644
--- a/src/internal/video/kitvideo.c
+++ b/src/internal/video/kitvideo.c
@@ -154,8 +154,8 @@ static int dec_decode_video_cb(Kit_Decoder *dec, AVPacket *in_packet) {
return 0;
}
#else
-static void dec_read_video(Kit_Decoder *dec) {
- Kit_VideoDecoder *video_dec = dec->userdata;
+static void dec_read_video(const Kit_Decoder *dec) {
+ const Kit_VideoDecoder *video_dec = dec->userdata;
AVFrame *out_frame = NULL;
Kit_VideoPacket *out_packet = NULL;
double pts;
@@ -242,20 +242,20 @@ Kit_Decoder* Kit_CreateVideoDecoder(const Kit_Source *src, int stream_index) {
free_out_video_packet_cb,
state->thread_count);
if(dec == NULL) {
- goto exit_0;
+ goto EXIT_0;
}
// ... then allocate the video decoder
Kit_VideoDecoder *video_dec = calloc(1, sizeof(Kit_VideoDecoder));
if(video_dec == NULL) {
- goto exit_1;
+ goto EXIT_1;
}
// Create temporary video frame
video_dec->scratch_frame = av_frame_alloc();
if(video_dec->scratch_frame == NULL) {
Kit_SetError("Unable to initialize temporary video frame");
- goto exit_2;
+ goto EXIT_2;
}
// Find best output format for us
@@ -281,7 +281,7 @@ Kit_Decoder* Kit_CreateVideoDecoder(const Kit_Source *src, int stream_index) {
NULL, NULL, NULL);
if(video_dec->sws == NULL) {
Kit_SetError("Unable to initialize video converter context");
- goto exit_3;
+ goto EXIT_3;
}
// Set callbacks and userdata, and we're go
@@ -291,13 +291,13 @@ Kit_Decoder* Kit_CreateVideoDecoder(const Kit_Source *src, int stream_index) {
dec->output = output;
return dec;
-exit_3:
+EXIT_3:
av_frame_free(&video_dec->scratch_frame);
-exit_2:
+EXIT_2:
free(video_dec);
-exit_1:
+EXIT_1:
Kit_CloseDecoder(dec);
-exit_0:
+EXIT_0:
return NULL;
}
diff --git a/src/kitlib.c b/src/kitlib.c
index 21de714..c3f98e4 100644
--- a/src/kitlib.c
+++ b/src/kitlib.c
@@ -45,7 +45,7 @@ int Kit_Init(unsigned int flags) {
if(state->init_flags != 0) {
Kit_SetError("SDL_kitchensink is already initialized");
- goto exit_0;
+ goto EXIT_0;
}
#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(58, 9, 100)
@@ -58,17 +58,17 @@ int Kit_Init(unsigned int flags) {
if(flags & KIT_INIT_ASS) {
if(Kit_InitASS(state) != 0) {
Kit_SetError("Failed to initialize libass");
- goto exit_1;
+ goto EXIT_1;
}
}
state->init_flags = flags;
return 0;
-exit_1:
+EXIT_1:
avformat_network_deinit();
-exit_0:
+EXIT_0:
return 1;
}
diff --git a/src/kitplayer.c b/src/kitplayer.c
index 39f1cb1..bfe6e9a 100644
--- a/src/kitplayer.c
+++ b/src/kitplayer.c
@@ -24,12 +24,13 @@ enum DecoderIndex {
static int _DemuxStream(const Kit_Player *player) {
assert(player != NULL);
AVFormatContext *format_ctx = player->src->format_ctx;
+ const Kit_Decoder *dec = NULL;
// If any buffer is full, just stop here for now.
// Since we don't know what kind of data is going to come out of av_read_frame, we really
// want to make sure we are prepared for everything :)
for(int i = 0; i < KIT_DEC_COUNT; i++) {
- Kit_Decoder *dec = player->decoders[i];
+ dec = player->decoders[i];
if(dec == NULL)
continue;
if(!Kit_CanWriteDecoderInput(dec))
@@ -45,7 +46,7 @@ static int _DemuxStream(const Kit_Player *player) {
// Check if this is a packet we need to handle and pass it on
for(int i = 0; i < KIT_DEC_COUNT; i++) {
- Kit_Decoder *dec = player->decoders[i];
+ dec = player->decoders[i];
if(dec == NULL)
continue;
if(dec->stream_index == packet->stream_index) {
@@ -61,8 +62,9 @@ static int _DemuxStream(const Kit_Player *player) {
}
static bool _IsOutputEmpty(const Kit_Player *player) {
+ const Kit_Decoder *dec = NULL;
for(int i = 0; i < KIT_DEC_COUNT; i++) {
- Kit_Decoder *dec = player->decoders[i];
+ dec = player->decoders[i];
if(dec == NULL)
continue;
if(Kit_PeekDecoderOutput(dec))
@@ -154,25 +156,25 @@ Kit_Player* Kit_CreatePlayer(const Kit_Source *src,
if(video_stream_index < 0 && subtitle_stream_index >= 0) {
Kit_SetError("Subtitle stream selected without video stream");
- goto exit_0;
+ goto EXIT_0;
}
Kit_Player *player = calloc(1, sizeof(Kit_Player));
if(player == NULL) {
Kit_SetError("Unable to allocate player");
- goto exit_0;
+ goto EXIT_0;
}
// Initialize audio decoder
player->decoders[KIT_AUDIO_DEC] = Kit_CreateAudioDecoder(src, audio_stream_index);
if(player->decoders[KIT_AUDIO_DEC] == NULL && audio_stream_index >= 0) {
- goto exit_1;
+ goto EXIT_1;
}
// Initialize video decoder
player->decoders[KIT_VIDEO_DEC] = Kit_CreateVideoDecoder(src, video_stream_index);
if(player->decoders[KIT_VIDEO_DEC] == NULL && video_stream_index >= 0) {
- goto exit_2;
+ goto EXIT_2;
}
// Initialize subtitle decoder.
@@ -181,35 +183,35 @@ Kit_Player* Kit_CreatePlayer(const Kit_Source *src,
player->decoders[KIT_SUBTITLE_DEC] = Kit_CreateSubtitleDecoder(
src, subtitle_stream_index, output.width, output.height, screen_w, screen_h);
if(player->decoders[KIT_SUBTITLE_DEC] == NULL && subtitle_stream_index >= 0) {
- goto exit_2;
+ goto EXIT_2;
}
// Decoder thread lock
player->dec_lock = SDL_CreateMutex();
if(player->dec_lock == NULL) {
Kit_SetError("Unable to create a decoder thread lock mutex: %s", SDL_GetError());
- goto exit_2;
+ goto EXIT_2;
}
// Decoder thread
player->dec_thread = SDL_CreateThread(_DecoderThread, "Kit Decoder Thread", player);
if(player->dec_thread == NULL) {
Kit_SetError("Unable to create a decoder thread: %s", SDL_GetError());
- goto exit_3;
+ goto EXIT_3;
}
player->src = src;
return player;
-exit_3:
+EXIT_3:
SDL_DestroyMutex(player->dec_lock);
-exit_2:
+EXIT_2:
for(int i = 0; i < KIT_DEC_COUNT; i++) {
Kit_CloseDecoder(player->decoders[i]);
}
-exit_1:
+EXIT_1:
free(player);
-exit_0:
+EXIT_0:
return NULL;
}
diff --git a/src/kitsource.c b/src/kitsource.c
index f9ec228..4c01466 100644
--- a/src/kitsource.c
+++ b/src/kitsource.c
@@ -34,19 +34,19 @@ Kit_Source* Kit_CreateSourceFromUrl(const char *url) {
// Attempt to open source
if(avformat_open_input((AVFormatContext **)&src->format_ctx, url, NULL, NULL) < 0) {
Kit_SetError("Unable to open source Url");
- goto exit_0;
+ goto EXIT_0;
}
// Scan source information (may seek forwards)
if(_ScanSource(src->format_ctx)) {
- goto exit_1;
+ goto EXIT_1;
}
return src;
-exit_1:
+EXIT_1:
avformat_close_input((AVFormatContext **)&src->format_ctx);
-exit_0:
+EXIT_0:
free(src);
return NULL;
}
@@ -63,20 +63,20 @@ Kit_Source* Kit_CreateSourceFromCustom(Kit_ReadCallback read_cb, Kit_SeekCallbac
uint8_t *avio_buf = av_malloc(AVIO_BUF_SIZE);
if(avio_buf == NULL) {
Kit_SetError("Unable to allocate avio buffer");
- goto exit_0;
+ goto EXIT_0;
}
AVFormatContext *format_ctx = avformat_alloc_context();
if(format_ctx == NULL) {
Kit_SetError("Unable to allocate format context");
- goto exit_1;
+ goto EXIT_1;
}
AVIOContext *avio_ctx = avio_alloc_context(
avio_buf, AVIO_BUF_SIZE, 0, userdata, read_cb, 0, seek_cb);
if(avio_ctx == NULL) {
Kit_SetError("Unable to allocate avio context");
- goto exit_2;
+ goto EXIT_2;
}
// Set the format as AVIO format
@@ -85,12 +85,12 @@ Kit_Source* Kit_CreateSourceFromCustom(Kit_ReadCallback read_cb, Kit_SeekCallbac
// Attempt to open source
if(avformat_open_input(&format_ctx, "", NULL, NULL) < 0) {
Kit_SetError("Unable to open custom source");
- goto exit_3;
+ goto EXIT_3;
}
// Scan source information (may seek forwards)
if(_ScanSource(format_ctx)) {
- goto exit_4;
+ goto EXIT_4;
}
// Set internals
@@ -98,15 +98,15 @@ Kit_Source* Kit_CreateSourceFromCustom(Kit_ReadCallback read_cb, Kit_SeekCallbac
src->avio_ctx = avio_ctx;
return src;
-exit_4:
+EXIT_4:
avformat_close_input(&format_ctx);
-exit_3:
+EXIT_3:
av_freep(&avio_ctx);
-exit_2:
+EXIT_2:
avformat_free_context(format_ctx);
-exit_1:
+EXIT_1:
av_freep(&avio_buf);
-exit_0:
+EXIT_0:
free(src);
return NULL;
}