From fd7bbceb6321250ed5d80103d13e9d7584b552ac Mon Sep 17 00:00:00 2001 From: Tuomas Virtanen Date: Tue, 12 Sep 2017 00:06:31 +0300 Subject: Split kitplayer.c to multiple files --- include/kitchensink/internal/kitaudio.h | 28 ++++++++++++++++++++++++++++ include/kitchensink/internal/kitcontrol.h | 24 ++++++++++++++++++++++++ include/kitchensink/internal/kithelpers.h | 11 +++++++++++ include/kitchensink/internal/kitsubtitle.h | 24 ++++++++++++++++++++++++ include/kitchensink/internal/kitvideo.h | 22 ++++++++++++++++++++++ include/kitchensink/kitchensink.h | 1 + include/kitchensink/kitformats.h | 29 +++++++++++++++++++++++++++++ include/kitchensink/kitplayer.h | 24 +----------------------- 8 files changed, 140 insertions(+), 23 deletions(-) create mode 100644 include/kitchensink/internal/kitaudio.h create mode 100644 include/kitchensink/internal/kitcontrol.h create mode 100644 include/kitchensink/internal/kithelpers.h create mode 100644 include/kitchensink/internal/kitsubtitle.h create mode 100644 include/kitchensink/internal/kitvideo.h create mode 100644 include/kitchensink/kitformats.h (limited to 'include') diff --git a/include/kitchensink/internal/kitaudio.h b/include/kitchensink/internal/kitaudio.h new file mode 100644 index 0000000..e1c9ffb --- /dev/null +++ b/include/kitchensink/internal/kitaudio.h @@ -0,0 +1,28 @@ +#ifndef KITAUDIO_H +#define KITAUDIO_H + +#define __STDC_FORMAT_MACROS +#include +#include + +#include "kitchensink/kitconfig.h" +#include "kitchensink/kitformats.h" +#include "kitchensink/kitplayer.h" +#include "kitchensink/internal/kitringbuffer.h" + +#define KIT_ABUFFERSIZE 64 + +typedef struct Kit_AudioPacket { + double pts; + size_t original_size; + Kit_RingBuffer *rb; +} Kit_AudioPacket; + +KIT_LOCAL Kit_AudioPacket* _CreateAudioPacket(const char* data, size_t len, double pts); +KIT_LOCAL void _FreeAudioPacket(void *ptr); +KIT_LOCAL enum AVSampleFormat _FindAVSampleFormat(int format); +KIT_LOCAL unsigned int _FindAVChannelLayout(int channels); +KIT_LOCAL void _FindAudioFormat(enum AVSampleFormat fmt, int *bytes, bool *is_signed, unsigned int *format); +KIT_LOCAL void _HandleAudioPacket(Kit_Player *player, AVPacket *packet); + +#endif // KITAUDIO_H diff --git a/include/kitchensink/internal/kitcontrol.h b/include/kitchensink/internal/kitcontrol.h new file mode 100644 index 0000000..eaad484 --- /dev/null +++ b/include/kitchensink/internal/kitcontrol.h @@ -0,0 +1,24 @@ +#ifndef KITCONTROL_H +#define KITCONTROL_H + +#include "kitchensink/kitconfig.h" +#include "kitchensink/kitplayer.h" + +#define KIT_CBUFFERSIZE 8 + +typedef enum Kit_ControlPacketType { + KIT_CONTROL_SEEK, + KIT_CONTROL_FLUSH +} Kit_ControlPacketType; + +typedef struct Kit_ControlPacket { + Kit_ControlPacketType type; + double value1; +} Kit_ControlPacket; + +KIT_LOCAL Kit_ControlPacket* _CreateControlPacket(Kit_ControlPacketType type, double value1); +KIT_LOCAL void _FreeControlPacket(void *ptr); +KIT_LOCAL void _HandleFlushCommand(Kit_Player *player, Kit_ControlPacket *packet); +KIT_LOCAL void _HandleSeekCommand(Kit_Player *player, Kit_ControlPacket *packet); + +#endif // KITCONTROL_H diff --git a/include/kitchensink/internal/kithelpers.h b/include/kitchensink/internal/kithelpers.h new file mode 100644 index 0000000..5b94a7a --- /dev/null +++ b/include/kitchensink/internal/kithelpers.h @@ -0,0 +1,11 @@ +#ifndef KITHELPERS_H +#define KITHELPERS_H + +#include +#include +#include "kitchensink/kitconfig.h" + +KIT_LOCAL double _GetSystemTime(); +KIT_LOCAL bool attachment_is_font(AVStream *stream); + +#endif // KITHELPERS_H diff --git a/include/kitchensink/internal/kitsubtitle.h b/include/kitchensink/internal/kitsubtitle.h new file mode 100644 index 0000000..4582744 --- /dev/null +++ b/include/kitchensink/internal/kitsubtitle.h @@ -0,0 +1,24 @@ +#ifndef KITSUBTITLE_H +#define KITSUBTITLE_H + +#include + +#include "kitchensink/kitconfig.h" +#include "kitchensink/kitplayer.h" + +#define KIT_SBUFFERSIZE 512 + +typedef struct Kit_SubtitlePacket { + double pts_start; + double pts_end; + SDL_Rect *rect; + SDL_Surface *surface; + SDL_Texture *texture; +} Kit_SubtitlePacket; + +KIT_LOCAL Kit_SubtitlePacket* _CreateSubtitlePacket(double pts_start, double pts_end, SDL_Rect *rect, SDL_Surface *surface); +KIT_LOCAL void _FreeSubtitlePacket(void *ptr); +KIT_LOCAL void _HandleBitmapSubtitle(Kit_SubtitlePacket** spackets, int *n, Kit_Player *player, double pts, AVSubtitle *sub, AVSubtitleRect *rect); +KIT_LOCAL void _HandleSubtitlePacket(Kit_Player *player, AVPacket *packet); + +#endif // KITSUBTITLE_H diff --git a/include/kitchensink/internal/kitvideo.h b/include/kitchensink/internal/kitvideo.h new file mode 100644 index 0000000..f1cb4ff --- /dev/null +++ b/include/kitchensink/internal/kitvideo.h @@ -0,0 +1,22 @@ +#ifndef KITVIDEO_H +#define KITVIDEO_H + +#include + +#include "kitchensink/kitconfig.h" +#include "kitchensink/kitplayer.h" + +#define KIT_VBUFFERSIZE 3 + +typedef struct Kit_VideoPacket { + double pts; + AVFrame *frame; +} Kit_VideoPacket; + +KIT_LOCAL Kit_VideoPacket* _CreateVideoPacket(AVFrame *frame, double pts); +KIT_LOCAL void _FreeVideoPacket(void *ptr); +KIT_LOCAL void _FindPixelFormat(enum AVPixelFormat fmt, unsigned int *out_fmt); +KIT_LOCAL enum AVPixelFormat _FindAVPixelFormat(unsigned int fmt); +KIT_LOCAL void _HandleVideoPacket(Kit_Player *player, AVPacket *packet); + +#endif // KITVIDEO_H diff --git a/include/kitchensink/kitchensink.h b/include/kitchensink/kitchensink.h index be318a5..6c5da35 100644 --- a/include/kitchensink/kitchensink.h +++ b/include/kitchensink/kitchensink.h @@ -3,6 +3,7 @@ #include "kitchensink/kitlib.h" #include "kitchensink/kiterror.h" +#include "kitchensink/kitformats.h" #include "kitchensink/kitsource.h" #include "kitchensink/kitplayer.h" #include "kitchensink/kitutils.h" diff --git a/include/kitchensink/kitformats.h b/include/kitchensink/kitformats.h new file mode 100644 index 0000000..ef86826 --- /dev/null +++ b/include/kitchensink/kitformats.h @@ -0,0 +1,29 @@ +#ifndef KITFORMATS_H +#define KITFORMATS_H + +#include + +typedef struct Kit_AudioFormat { + int stream_idx; ///< Stream index + bool is_enabled; ///< Is stream enabled + unsigned int format; ///< SDL Audio Format + bool is_signed; ///< Signedness + int bytes; ///< Bytes per sample per channel + int samplerate; ///< Sampling rate + int channels; ///< Channels +} Kit_AudioFormat; + +typedef struct Kit_VideoFormat { + int stream_idx; ///< Stream index + bool is_enabled; ///< Is stream enabled + unsigned int format; ///< SDL Pixel Format + int width; ///< Width in pixels + int height; ///< Height in pixels +} Kit_VideoFormat; + +typedef struct Kit_SubtitleFormat { + int stream_idx; ///< Stream index + bool is_enabled; ///< Is stream enabled +} Kit_SubtitleFormat; + +#endif // KITFORMATS_H diff --git a/include/kitchensink/kitplayer.h b/include/kitchensink/kitplayer.h index b9ea1c7..9505208 100644 --- a/include/kitchensink/kitplayer.h +++ b/include/kitchensink/kitplayer.h @@ -3,6 +3,7 @@ #include "kitchensink/kitsource.h" #include "kitchensink/kitconfig.h" +#include "kitchensink/kitformats.h" #include #include @@ -24,29 +25,6 @@ typedef enum Kit_PlayerState { KIT_CLOSED ///< Playback is stopped and player is closing. } Kit_PlayerState; -typedef struct Kit_AudioFormat { - int stream_idx; ///< Stream index - bool is_enabled; ///< Is stream enabled - unsigned int format; ///< SDL Audio Format - bool is_signed; ///< Signedness - int bytes; ///< Bytes per sample per channel - int samplerate; ///< Sampling rate - int channels; ///< Channels -} Kit_AudioFormat; - -typedef struct Kit_VideoFormat { - int stream_idx; ///< Stream index - bool is_enabled; ///< Is stream enabled - unsigned int format; ///< SDL Pixel Format - int width; ///< Width in pixels - int height; ///< Height in pixels -} Kit_VideoFormat; - -typedef struct Kit_SubtitleFormat { - int stream_idx; ///< Stream index - bool is_enabled; ///< Is stream enabled -} Kit_SubtitleFormat; - typedef struct Kit_Player { // Local state Kit_PlayerState state; ///< Playback state -- cgit v1.2.3 From fdaaf05142e446f1047487763585c3a16801580c Mon Sep 17 00:00:00 2001 From: Tuomas Virtanen Date: Fri, 22 Sep 2017 15:14:58 +0300 Subject: Split decoding to separate files --- include/kitchensink/internal/kitaudio.h | 22 ++---------- include/kitchensink/internal/kitcontrol.h | 24 ------------- include/kitchensink/internal/kitdecoder.h | 54 ++++++++++++++++++++++++++++++ include/kitchensink/internal/kitlog.h | 11 ++++++ include/kitchensink/internal/kitsubtitle.h | 20 +++-------- include/kitchensink/internal/kitvideo.h | 18 +++------- include/kitchensink/kitformats.h | 6 ++-- include/kitchensink/kitplayer.h | 51 ++++++---------------------- include/kitchensink/kitsource.h | 8 ++--- 9 files changed, 95 insertions(+), 119 deletions(-) delete mode 100644 include/kitchensink/internal/kitcontrol.h create mode 100644 include/kitchensink/internal/kitdecoder.h create mode 100644 include/kitchensink/internal/kitlog.h (limited to 'include') diff --git a/include/kitchensink/internal/kitaudio.h b/include/kitchensink/internal/kitaudio.h index e1c9ffb..ac6753b 100644 --- a/include/kitchensink/internal/kitaudio.h +++ b/include/kitchensink/internal/kitaudio.h @@ -1,28 +1,12 @@ #ifndef KITAUDIO_H #define KITAUDIO_H -#define __STDC_FORMAT_MACROS -#include -#include - #include "kitchensink/kitconfig.h" #include "kitchensink/kitformats.h" #include "kitchensink/kitplayer.h" -#include "kitchensink/internal/kitringbuffer.h" - -#define KIT_ABUFFERSIZE 64 - -typedef struct Kit_AudioPacket { - double pts; - size_t original_size; - Kit_RingBuffer *rb; -} Kit_AudioPacket; +#include "kitchensink/internal/kitdecoder.h" -KIT_LOCAL Kit_AudioPacket* _CreateAudioPacket(const char* data, size_t len, double pts); -KIT_LOCAL void _FreeAudioPacket(void *ptr); -KIT_LOCAL enum AVSampleFormat _FindAVSampleFormat(int format); -KIT_LOCAL unsigned int _FindAVChannelLayout(int channels); -KIT_LOCAL void _FindAudioFormat(enum AVSampleFormat fmt, int *bytes, bool *is_signed, unsigned int *format); -KIT_LOCAL void _HandleAudioPacket(Kit_Player *player, AVPacket *packet); +KIT_LOCAL Kit_Decoder* Kit_CreateAudioDecoder(const Kit_Source *src, Kit_AudioFormat *format); +KIT_LOCAL int Kit_GetAudioDecoderData(Kit_Decoder *dec, unsigned char *buf, int len); #endif // KITAUDIO_H diff --git a/include/kitchensink/internal/kitcontrol.h b/include/kitchensink/internal/kitcontrol.h deleted file mode 100644 index eaad484..0000000 --- a/include/kitchensink/internal/kitcontrol.h +++ /dev/null @@ -1,24 +0,0 @@ -#ifndef KITCONTROL_H -#define KITCONTROL_H - -#include "kitchensink/kitconfig.h" -#include "kitchensink/kitplayer.h" - -#define KIT_CBUFFERSIZE 8 - -typedef enum Kit_ControlPacketType { - KIT_CONTROL_SEEK, - KIT_CONTROL_FLUSH -} Kit_ControlPacketType; - -typedef struct Kit_ControlPacket { - Kit_ControlPacketType type; - double value1; -} Kit_ControlPacket; - -KIT_LOCAL Kit_ControlPacket* _CreateControlPacket(Kit_ControlPacketType type, double value1); -KIT_LOCAL void _FreeControlPacket(void *ptr); -KIT_LOCAL void _HandleFlushCommand(Kit_Player *player, Kit_ControlPacket *packet); -KIT_LOCAL void _HandleSeekCommand(Kit_Player *player, Kit_ControlPacket *packet); - -#endif // KITCONTROL_H diff --git a/include/kitchensink/internal/kitdecoder.h b/include/kitchensink/internal/kitdecoder.h new file mode 100644 index 0000000..9d6f84d --- /dev/null +++ b/include/kitchensink/internal/kitdecoder.h @@ -0,0 +1,54 @@ +#ifndef KITDECODER_H +#define KITDECODER_H + +#include + +#include +#include +#include + +#include "kitchensink/kitconfig.h" +#include "kitchensink/kitsource.h" +#include "kitchensink/internal/kitbuffer.h" + +#define KIT_DEC_IN 0 +#define KIT_DEC_OUT 1 + +typedef struct Kit_Decoder Kit_Decoder; + +typedef int (*dec_decode_cb)(Kit_Decoder *dec, AVPacket *in_packet); +typedef void (*dec_close_cb)(Kit_Decoder *dec); +typedef void (*dec_free_packet_cb)(void *packet); + +KIT_LOCAL struct Kit_Decoder { + int stream_index; ///< Source stream index for the current stream + double clock_sync; ///< Sync source for current stream + double clock_pos; ///< Current pts for the stream + + AVCodecContext *codec_ctx; ///< FFMpeg internal: Codec context + AVFormatContext *format_ctx; ///< FFMpeg internal: Format context (owner: Kit_Source) + + SDL_mutex *lock[2]; ///< Threading locks for input and output buffers + Kit_Buffer *buffer[2]; ///< Buffers for incoming and decoded packets + + void *userdata; ///< Decoder specific information (Audio, video, subtitle context) + dec_decode_cb dec_decode; ///< Decoder decoding function callback + dec_close_cb dec_close; ///< Decoder close function callback +}; + +KIT_LOCAL Kit_Decoder* Kit_CreateDecoder(const Kit_Source *src, int stream_index, + int in_b_size, int out_b_size, + dec_free_packet_cb free_out_cb); +KIT_LOCAL void Kit_SetDecoderClockSync(Kit_Decoder *dec, double sync); +KIT_LOCAL void Kit_ChangeDecoderClockSync(Kit_Decoder *dec, double sync); +KIT_LOCAL bool Kit_CanWriteDecoderInput(Kit_Decoder *dec); +KIT_LOCAL int Kit_WriteDecoderInput(Kit_Decoder *dec, AVPacket *packet); +KIT_LOCAL AVPacket* Kit_ReadDecoderInput(Kit_Decoder *dec); +KIT_LOCAL int Kit_WriteDecoderOutput(Kit_Decoder *dec, void *packet); +KIT_LOCAL void* Kit_PeekDecoderOutput(Kit_Decoder *dec); +KIT_LOCAL void Kit_AdvanceDecoderOutput(Kit_Decoder *dec); +KIT_LOCAL void Kit_ClearDecoderBuffers(Kit_Decoder *dec); +KIT_LOCAL int Kit_RunDecoder(Kit_Decoder *dec); +KIT_LOCAL void Kit_CloseDecoder(Kit_Decoder *dec); + +#endif // KITDECODER_H diff --git a/include/kitchensink/internal/kitlog.h b/include/kitchensink/internal/kitlog.h new file mode 100644 index 0000000..1a56e53 --- /dev/null +++ b/include/kitchensink/internal/kitlog.h @@ -0,0 +1,11 @@ +#ifndef KITLOG_H +#define KITLOG_H + +#ifdef NDEBUG + #define LOG(...) +#else + #include + #define LOG(...) fprintf(stderr, __VA_ARGS__) +#endif + +#endif // KITLOG_H diff --git a/include/kitchensink/internal/kitsubtitle.h b/include/kitchensink/internal/kitsubtitle.h index 4582744..5296aef 100644 --- a/include/kitchensink/internal/kitsubtitle.h +++ b/include/kitchensink/internal/kitsubtitle.h @@ -1,24 +1,14 @@ #ifndef KITSUBTITLE_H #define KITSUBTITLE_H -#include +#include #include "kitchensink/kitconfig.h" +#include "kitchensink/kitformats.h" #include "kitchensink/kitplayer.h" +#include "kitchensink/internal/kitdecoder.h" -#define KIT_SBUFFERSIZE 512 - -typedef struct Kit_SubtitlePacket { - double pts_start; - double pts_end; - SDL_Rect *rect; - SDL_Surface *surface; - SDL_Texture *texture; -} Kit_SubtitlePacket; - -KIT_LOCAL Kit_SubtitlePacket* _CreateSubtitlePacket(double pts_start, double pts_end, SDL_Rect *rect, SDL_Surface *surface); -KIT_LOCAL void _FreeSubtitlePacket(void *ptr); -KIT_LOCAL void _HandleBitmapSubtitle(Kit_SubtitlePacket** spackets, int *n, Kit_Player *player, double pts, AVSubtitle *sub, AVSubtitleRect *rect); -KIT_LOCAL void _HandleSubtitlePacket(Kit_Player *player, AVPacket *packet); +KIT_LOCAL Kit_Decoder* Kit_CreateSubtitleDecoder(const Kit_Source *src, Kit_SubtitleFormat *format, int w, int h); +KIT_LOCAL int Kit_GetSubtitleDecoderData(Kit_Decoder *dec, SDL_Renderer *renderer); #endif // KITSUBTITLE_H diff --git a/include/kitchensink/internal/kitvideo.h b/include/kitchensink/internal/kitvideo.h index f1cb4ff..5a5624f 100644 --- a/include/kitchensink/internal/kitvideo.h +++ b/include/kitchensink/internal/kitvideo.h @@ -1,22 +1,12 @@ #ifndef KITVIDEO_H #define KITVIDEO_H -#include - #include "kitchensink/kitconfig.h" +#include "kitchensink/kitformats.h" #include "kitchensink/kitplayer.h" +#include "kitchensink/internal/kitdecoder.h" -#define KIT_VBUFFERSIZE 3 - -typedef struct Kit_VideoPacket { - double pts; - AVFrame *frame; -} Kit_VideoPacket; - -KIT_LOCAL Kit_VideoPacket* _CreateVideoPacket(AVFrame *frame, double pts); -KIT_LOCAL void _FreeVideoPacket(void *ptr); -KIT_LOCAL void _FindPixelFormat(enum AVPixelFormat fmt, unsigned int *out_fmt); -KIT_LOCAL enum AVPixelFormat _FindAVPixelFormat(unsigned int fmt); -KIT_LOCAL void _HandleVideoPacket(Kit_Player *player, AVPacket *packet); +KIT_LOCAL Kit_Decoder* Kit_CreateVideoDecoder(const Kit_Source *src, Kit_VideoFormat *format); +KIT_LOCAL int Kit_GetVideoDecoderData(Kit_Decoder *dec, SDL_Texture *texture); #endif // KITVIDEO_H diff --git a/include/kitchensink/kitformats.h b/include/kitchensink/kitformats.h index ef86826..a1cc61e 100644 --- a/include/kitchensink/kitformats.h +++ b/include/kitchensink/kitformats.h @@ -4,7 +4,7 @@ #include typedef struct Kit_AudioFormat { - int stream_idx; ///< Stream index + int stream_index; ///< Stream index bool is_enabled; ///< Is stream enabled unsigned int format; ///< SDL Audio Format bool is_signed; ///< Signedness @@ -14,7 +14,7 @@ typedef struct Kit_AudioFormat { } Kit_AudioFormat; typedef struct Kit_VideoFormat { - int stream_idx; ///< Stream index + int stream_index; ///< Stream index bool is_enabled; ///< Is stream enabled unsigned int format; ///< SDL Pixel Format int width; ///< Width in pixels @@ -22,7 +22,7 @@ typedef struct Kit_VideoFormat { } Kit_VideoFormat; typedef struct Kit_SubtitleFormat { - int stream_idx; ///< Stream index + int stream_index; ///< Stream index bool is_enabled; ///< Is stream enabled } Kit_SubtitleFormat; diff --git a/include/kitchensink/kitplayer.h b/include/kitchensink/kitplayer.h index 9505208..a33828b 100644 --- a/include/kitchensink/kitplayer.h +++ b/include/kitchensink/kitplayer.h @@ -8,6 +8,7 @@ #include #include #include +#include #include @@ -26,47 +27,17 @@ typedef enum Kit_PlayerState { } Kit_PlayerState; typedef struct Kit_Player { - // Local state - Kit_PlayerState state; ///< Playback state - Kit_VideoFormat vformat; ///< Video format information - Kit_AudioFormat aformat; ///< Audio format information + Kit_PlayerState state; ///< Playback state + Kit_VideoFormat vformat; ///< Video format information + Kit_AudioFormat aformat; ///< Audio format information Kit_SubtitleFormat sformat; ///< Subtitle format information - - // Synchronization - double clock_sync; ///< Clock sync point - double pause_start; ///< Timestamp of pause beginning - double vclock_pos; ///< Video stream last pts - - // Threading - SDL_Thread *dec_thread; ///< Decoder thread - SDL_mutex *vmutex; ///< Video stream buffer lock - SDL_mutex *amutex; ///< Audio stream buffer lock - SDL_mutex *smutex; ///< Subtitle stream buffer lock - SDL_mutex *cmutex; ///< Control stream buffer lock - - // Buffers - void *abuffer; ///< Audio stream buffer - void *vbuffer; ///< Video stream buffer - void *sbuffer; ///< Subtitle stream buffer - void *cbuffer; ///< Control stream buffer - - // FFmpeg internal state - void *vcodec_ctx; ///< FFmpeg: Video codec context - void *acodec_ctx; ///< FFmpeg: Audio codec context - void *scodec_ctx; ///< FFmpeg: Subtitle codec context - void *tmp_vframe; ///< FFmpeg: Preallocated temporary video frame - void *tmp_aframe; ///< FFmpeg: Preallocated temporary audio frame - void *tmp_sframe; ///< FFmpeg: Preallocated temporary subtitle frame - void *swr; ///< FFmpeg: Audio resampler - void *sws; ///< FFmpeg: Video converter - - // libass - void *ass_renderer; - void *ass_track; - - // Other - uint8_t seek_flag; - const Kit_Source *src; ///< Reference to Audio/Video source + void *audio_dec; ///< Audio decoder context (or NULL) + void *video_dec; ///< Video decoder context (or NULL) + void *subtitle_dec; ///< Subtitle decoder context (or NULL) + SDL_Thread *dec_thread; ///< Decoder thread + SDL_mutex *dec_lock; ///< Decoder lock + const Kit_Source *src; ///< Reference to Audio/Video source + double pause_started; ///< Temporary flag for handling pauses } Kit_Player; typedef struct Kit_PlayerInfo { diff --git a/include/kitchensink/kitsource.h b/include/kitchensink/kitsource.h index ed1711f..ea85d57 100644 --- a/include/kitchensink/kitsource.h +++ b/include/kitchensink/kitsource.h @@ -20,10 +20,10 @@ typedef enum Kit_StreamType { } Kit_StreamType; typedef struct Kit_Source { - int astream_idx; ///< Audio stream index - int vstream_idx; ///< Video stream index - int sstream_idx; ///< Subtitle stream index - void *format_ctx; ///< FFmpeg: Videostream format context + int audio_stream_index; ///< Audio stream index + int video_stream_index; ///< Video stream index + int subtitle_stream_index; ///< Subtitle stream index + void *format_ctx; ///< FFmpeg: Videostream format context } Kit_Source; typedef struct Kit_Stream { -- cgit v1.2.3 From 2267d51d2b402c377a21bf03be6fc51b251f063b Mon Sep 17 00:00:00 2001 From: Tuomas Virtanen Date: Fri, 22 Sep 2017 20:58:25 +0300 Subject: Decoder cleanups --- include/kitchensink/internal/kitdecoder.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'include') diff --git a/include/kitchensink/internal/kitdecoder.h b/include/kitchensink/internal/kitdecoder.h index 9d6f84d..191113b 100644 --- a/include/kitchensink/internal/kitdecoder.h +++ b/include/kitchensink/internal/kitdecoder.h @@ -37,8 +37,7 @@ KIT_LOCAL struct Kit_Decoder { }; KIT_LOCAL Kit_Decoder* Kit_CreateDecoder(const Kit_Source *src, int stream_index, - int in_b_size, int out_b_size, - dec_free_packet_cb free_out_cb); + int out_b_size, dec_free_packet_cb free_out_cb); KIT_LOCAL void Kit_SetDecoderClockSync(Kit_Decoder *dec, double sync); KIT_LOCAL void Kit_ChangeDecoderClockSync(Kit_Decoder *dec, double sync); KIT_LOCAL bool Kit_CanWriteDecoderInput(Kit_Decoder *dec); -- cgit v1.2.3 From eace70f1c1c7ba7339713666a76213acf1125202 Mon Sep 17 00:00:00 2001 From: Tuomas Virtanen Date: Mon, 15 Jan 2018 20:04:09 +0200 Subject: Dump reorganized code --- include/kitchensink/internal/audio/kitaudio.h | 12 ++++++++++ include/kitchensink/internal/kitaudio.h | 12 ---------- include/kitchensink/internal/kitbuffer.h | 28 ---------------------- include/kitchensink/internal/kitdecoder.h | 4 +++- include/kitchensink/internal/kithelpers.h | 11 --------- include/kitchensink/internal/kitlist.h | 26 -------------------- include/kitchensink/internal/kitlog.h | 11 --------- include/kitchensink/internal/kitringbuffer.h | 23 ------------------ include/kitchensink/internal/kitsubtitle.h | 14 ----------- include/kitchensink/internal/kitvideo.h | 12 ---------- .../kitchensink/internal/subtitle/kitsubtitle.h | 14 +++++++++++ .../internal/subtitle/renderers/kitsubass.h | 10 ++++++++ .../internal/subtitle/renderers/kitsubimage.h | 6 +++++ .../internal/subtitle/renderers/kitsubrenderer.h | 22 +++++++++++++++++ include/kitchensink/internal/utils/kitbuffer.h | 28 ++++++++++++++++++++++ include/kitchensink/internal/utils/kithelpers.h | 11 +++++++++ include/kitchensink/internal/utils/kitlog.h | 11 +++++++++ include/kitchensink/internal/utils/kitringbuffer.h | 23 ++++++++++++++++++ include/kitchensink/internal/video/kitvideo.h | 12 ++++++++++ include/kitchensink/kitformats.h | 1 + include/kitchensink/kitlib.h | 4 ++-- include/kitchensink/kitplayer.h | 10 ++++---- 22 files changed, 160 insertions(+), 145 deletions(-) create mode 100644 include/kitchensink/internal/audio/kitaudio.h delete mode 100644 include/kitchensink/internal/kitaudio.h delete mode 100644 include/kitchensink/internal/kitbuffer.h delete mode 100644 include/kitchensink/internal/kithelpers.h delete mode 100644 include/kitchensink/internal/kitlist.h delete mode 100644 include/kitchensink/internal/kitlog.h delete mode 100644 include/kitchensink/internal/kitringbuffer.h delete mode 100644 include/kitchensink/internal/kitsubtitle.h delete mode 100644 include/kitchensink/internal/kitvideo.h create mode 100644 include/kitchensink/internal/subtitle/kitsubtitle.h create mode 100644 include/kitchensink/internal/subtitle/renderers/kitsubass.h create mode 100644 include/kitchensink/internal/subtitle/renderers/kitsubimage.h create mode 100644 include/kitchensink/internal/subtitle/renderers/kitsubrenderer.h create mode 100644 include/kitchensink/internal/utils/kitbuffer.h create mode 100644 include/kitchensink/internal/utils/kithelpers.h create mode 100644 include/kitchensink/internal/utils/kitlog.h create mode 100644 include/kitchensink/internal/utils/kitringbuffer.h create mode 100644 include/kitchensink/internal/video/kitvideo.h (limited to 'include') diff --git a/include/kitchensink/internal/audio/kitaudio.h b/include/kitchensink/internal/audio/kitaudio.h new file mode 100644 index 0000000..ac6753b --- /dev/null +++ b/include/kitchensink/internal/audio/kitaudio.h @@ -0,0 +1,12 @@ +#ifndef KITAUDIO_H +#define KITAUDIO_H + +#include "kitchensink/kitconfig.h" +#include "kitchensink/kitformats.h" +#include "kitchensink/kitplayer.h" +#include "kitchensink/internal/kitdecoder.h" + +KIT_LOCAL Kit_Decoder* Kit_CreateAudioDecoder(const Kit_Source *src, Kit_AudioFormat *format); +KIT_LOCAL int Kit_GetAudioDecoderData(Kit_Decoder *dec, unsigned char *buf, int len); + +#endif // KITAUDIO_H diff --git a/include/kitchensink/internal/kitaudio.h b/include/kitchensink/internal/kitaudio.h deleted file mode 100644 index ac6753b..0000000 --- a/include/kitchensink/internal/kitaudio.h +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef KITAUDIO_H -#define KITAUDIO_H - -#include "kitchensink/kitconfig.h" -#include "kitchensink/kitformats.h" -#include "kitchensink/kitplayer.h" -#include "kitchensink/internal/kitdecoder.h" - -KIT_LOCAL Kit_Decoder* Kit_CreateAudioDecoder(const Kit_Source *src, Kit_AudioFormat *format); -KIT_LOCAL int Kit_GetAudioDecoderData(Kit_Decoder *dec, unsigned char *buf, int len); - -#endif // KITAUDIO_H diff --git a/include/kitchensink/internal/kitbuffer.h b/include/kitchensink/internal/kitbuffer.h deleted file mode 100644 index 4d0f8cc..0000000 --- a/include/kitchensink/internal/kitbuffer.h +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef KITBUFFER_H -#define KITBUFFER_H - -#include "kitchensink/kitconfig.h" - -typedef struct Kit_Buffer Kit_Buffer; - -typedef void (*Kit_BufferFreeCallback)(void*); - -struct Kit_Buffer { - unsigned int read_p; - unsigned int write_p; - unsigned int size; - Kit_BufferFreeCallback free_cb; - void **data; -}; - -KIT_LOCAL Kit_Buffer* Kit_CreateBuffer(unsigned int size, Kit_BufferFreeCallback free_cb); -KIT_LOCAL void Kit_DestroyBuffer(Kit_Buffer *buffer); - -KIT_LOCAL void Kit_ClearBuffer(Kit_Buffer *buffer); -KIT_LOCAL void* Kit_ReadBuffer(Kit_Buffer *buffer); -KIT_LOCAL void* Kit_PeekBuffer(const Kit_Buffer *buffer); -KIT_LOCAL void Kit_AdvanceBuffer(Kit_Buffer *buffer); -KIT_LOCAL int Kit_WriteBuffer(Kit_Buffer *buffer, void *ptr); -KIT_LOCAL int Kit_IsBufferFull(const Kit_Buffer *buffer); - -#endif // KITBUFFER_H diff --git a/include/kitchensink/internal/kitdecoder.h b/include/kitchensink/internal/kitdecoder.h index 191113b..5d494e8 100644 --- a/include/kitchensink/internal/kitdecoder.h +++ b/include/kitchensink/internal/kitdecoder.h @@ -9,7 +9,7 @@ #include "kitchensink/kitconfig.h" #include "kitchensink/kitsource.h" -#include "kitchensink/internal/kitbuffer.h" +#include "kitchensink/internal/utils/kitbuffer.h" #define KIT_DEC_IN 0 #define KIT_DEC_OUT 1 @@ -48,6 +48,8 @@ KIT_LOCAL void* Kit_PeekDecoderOutput(Kit_Decoder *dec); KIT_LOCAL void Kit_AdvanceDecoderOutput(Kit_Decoder *dec); KIT_LOCAL void Kit_ClearDecoderBuffers(Kit_Decoder *dec); KIT_LOCAL int Kit_RunDecoder(Kit_Decoder *dec); +KIT_LOCAL void Kit_ClearDecoderInput(Kit_Decoder *dec); +KIT_LOCAL void Kit_ClearDecoderOutput(Kit_Decoder *dec); KIT_LOCAL void Kit_CloseDecoder(Kit_Decoder *dec); #endif // KITDECODER_H diff --git a/include/kitchensink/internal/kithelpers.h b/include/kitchensink/internal/kithelpers.h deleted file mode 100644 index 5b94a7a..0000000 --- a/include/kitchensink/internal/kithelpers.h +++ /dev/null @@ -1,11 +0,0 @@ -#ifndef KITHELPERS_H -#define KITHELPERS_H - -#include -#include -#include "kitchensink/kitconfig.h" - -KIT_LOCAL double _GetSystemTime(); -KIT_LOCAL bool attachment_is_font(AVStream *stream); - -#endif // KITHELPERS_H diff --git a/include/kitchensink/internal/kitlist.h b/include/kitchensink/internal/kitlist.h deleted file mode 100644 index 85e3e3f..0000000 --- a/include/kitchensink/internal/kitlist.h +++ /dev/null @@ -1,26 +0,0 @@ -#ifndef KITLIST_H -#define KITLIST_H - -#include "kitchensink/kitconfig.h" - -typedef struct Kit_List Kit_List; - -typedef void (*Kit_ListFreeCallback)(void*); - -struct Kit_List { - unsigned int size; - unsigned int length; - Kit_ListFreeCallback free_cb; - void **data; -}; - -KIT_LOCAL Kit_List* Kit_CreateList(unsigned int size, Kit_ListFreeCallback free_cb); -KIT_LOCAL void Kit_DestroyList(Kit_List *list); - -KIT_LOCAL void Kit_ClearList(Kit_List *list); -KIT_LOCAL void Kit_RemoveFromList(Kit_List *list, unsigned int iterator); -KIT_LOCAL void* Kit_IterateList(const Kit_List *list, unsigned int *iterator); -KIT_LOCAL int Kit_WriteList(Kit_List *list, void *ptr); -KIT_LOCAL int Kit_GetListLength(const Kit_List *list); - -#endif // KITLIST_H diff --git a/include/kitchensink/internal/kitlog.h b/include/kitchensink/internal/kitlog.h deleted file mode 100644 index 1a56e53..0000000 --- a/include/kitchensink/internal/kitlog.h +++ /dev/null @@ -1,11 +0,0 @@ -#ifndef KITLOG_H -#define KITLOG_H - -#ifdef NDEBUG - #define LOG(...) -#else - #include - #define LOG(...) fprintf(stderr, __VA_ARGS__) -#endif - -#endif // KITLOG_H diff --git a/include/kitchensink/internal/kitringbuffer.h b/include/kitchensink/internal/kitringbuffer.h deleted file mode 100644 index 2f67520..0000000 --- a/include/kitchensink/internal/kitringbuffer.h +++ /dev/null @@ -1,23 +0,0 @@ -#ifndef KITRINGBUFFER_H -#define KITRINGBUFFER_H - -#include "kitchensink/kitconfig.h" - -typedef struct Kit_RingBuffer { - int size; - int len; - int wpos, rpos; - char* data; -} Kit_RingBuffer; - -KIT_LOCAL Kit_RingBuffer* Kit_CreateRingBuffer(unsigned int size); -KIT_LOCAL void Kit_DestroyRingBuffer(Kit_RingBuffer* rb); -KIT_LOCAL int Kit_WriteRingBuffer(Kit_RingBuffer *rb, const char* data, int len); -KIT_LOCAL int Kit_ReadRingBuffer(Kit_RingBuffer *rb, char* data, int len); -KIT_LOCAL int Kit_PeekRingBuffer(const Kit_RingBuffer *rb, char* data, int len); -KIT_LOCAL int Kit_AdvanceRingBuffer(Kit_RingBuffer *rb, int len); -KIT_LOCAL int Kit_GetRingBufferLength(const Kit_RingBuffer *rb); -KIT_LOCAL int Kit_GetRingBufferSize(const Kit_RingBuffer *rb); -KIT_LOCAL int Kit_GetRingBufferFree(const Kit_RingBuffer *rb); - -#endif // KITRINGBUFFER_H diff --git a/include/kitchensink/internal/kitsubtitle.h b/include/kitchensink/internal/kitsubtitle.h deleted file mode 100644 index 5296aef..0000000 --- a/include/kitchensink/internal/kitsubtitle.h +++ /dev/null @@ -1,14 +0,0 @@ -#ifndef KITSUBTITLE_H -#define KITSUBTITLE_H - -#include - -#include "kitchensink/kitconfig.h" -#include "kitchensink/kitformats.h" -#include "kitchensink/kitplayer.h" -#include "kitchensink/internal/kitdecoder.h" - -KIT_LOCAL Kit_Decoder* Kit_CreateSubtitleDecoder(const Kit_Source *src, Kit_SubtitleFormat *format, int w, int h); -KIT_LOCAL int Kit_GetSubtitleDecoderData(Kit_Decoder *dec, SDL_Renderer *renderer); - -#endif // KITSUBTITLE_H diff --git a/include/kitchensink/internal/kitvideo.h b/include/kitchensink/internal/kitvideo.h deleted file mode 100644 index 5a5624f..0000000 --- a/include/kitchensink/internal/kitvideo.h +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef KITVIDEO_H -#define KITVIDEO_H - -#include "kitchensink/kitconfig.h" -#include "kitchensink/kitformats.h" -#include "kitchensink/kitplayer.h" -#include "kitchensink/internal/kitdecoder.h" - -KIT_LOCAL Kit_Decoder* Kit_CreateVideoDecoder(const Kit_Source *src, Kit_VideoFormat *format); -KIT_LOCAL int Kit_GetVideoDecoderData(Kit_Decoder *dec, SDL_Texture *texture); - -#endif // KITVIDEO_H diff --git a/include/kitchensink/internal/subtitle/kitsubtitle.h b/include/kitchensink/internal/subtitle/kitsubtitle.h new file mode 100644 index 0000000..51de9b9 --- /dev/null +++ b/include/kitchensink/internal/subtitle/kitsubtitle.h @@ -0,0 +1,14 @@ +#ifndef KITSUBTITLE_H +#define KITSUBTITLE_H + +#include + +#include "kitchensink/kitconfig.h" +#include "kitchensink/kitformats.h" +#include "kitchensink/kitplayer.h" +#include "kitchensink/internal/kitdecoder.h" + +KIT_LOCAL Kit_Decoder* Kit_CreateSubtitleDecoder(const Kit_Source *src, Kit_SubtitleFormat *format, int w, int h); +KIT_LOCAL int Kit_GetSubtitleDecoderData(Kit_Decoder *dec, SDL_Texture *texture); + +#endif // KITSUBTITLE_H diff --git a/include/kitchensink/internal/subtitle/renderers/kitsubass.h b/include/kitchensink/internal/subtitle/renderers/kitsubass.h new file mode 100644 index 0000000..39df3ac --- /dev/null +++ b/include/kitchensink/internal/subtitle/renderers/kitsubass.h @@ -0,0 +1,10 @@ +#ifndef KITSUBASS_H +#define KITSUBASS_H + +#include "kitchensink/kitconfig.h" +#include "kitchensink/internal/kitdecoder.h" +#include "kitchensink/internal/subtitle/renderers/kitsubrenderer.h" + +KIT_LOCAL Kit_SubtitleRenderer* Kit_CreateASSSubtitleRenderer(const Kit_Decoder *dec, int w, int h); + +#endif // KITSUBASS_H diff --git a/include/kitchensink/internal/subtitle/renderers/kitsubimage.h b/include/kitchensink/internal/subtitle/renderers/kitsubimage.h new file mode 100644 index 0000000..d26b67e --- /dev/null +++ b/include/kitchensink/internal/subtitle/renderers/kitsubimage.h @@ -0,0 +1,6 @@ +#ifndef KITSUBIMAGE_H +#define KITSUBIMAGE_H + + + +#endif // KITSUBIMAGE_H diff --git a/include/kitchensink/internal/subtitle/renderers/kitsubrenderer.h b/include/kitchensink/internal/subtitle/renderers/kitsubrenderer.h new file mode 100644 index 0000000..b24161a --- /dev/null +++ b/include/kitchensink/internal/subtitle/renderers/kitsubrenderer.h @@ -0,0 +1,22 @@ +#ifndef KITSUBRENDERER_H +#define KITSUBRENDERER_H + +#include "kitchensink/kitsource.h" +#include "kitchensink/kitformats.h" + +typedef struct Kit_SubtitleRenderer Kit_SubtitleRenderer; + +typedef int (*ren_render_cb)(Kit_SubtitleRenderer *ren, void *src, double start_pts, void *surface); +typedef void (*ren_close_cb)(Kit_SubtitleRenderer *ren); + +struct Kit_SubtitleRenderer { + void *userdata; + ren_render_cb ren_render; ///< Subtitle rendering function callback + ren_close_cb ren_close; ///< Subtitle renderer close function callback +}; + +KIT_LOCAL Kit_SubtitleRenderer* Kit_CreateSubtitleRenderer(); +KIT_LOCAL int Kit_RunSubtitleRenderer(Kit_SubtitleRenderer *ren, void *src, double start_pts, void *surface); +KIT_LOCAL void Kit_CloseSubtitleRenderer(Kit_SubtitleRenderer *ren); + +#endif // KITSUBRENDERER_H diff --git a/include/kitchensink/internal/utils/kitbuffer.h b/include/kitchensink/internal/utils/kitbuffer.h new file mode 100644 index 0000000..4d0f8cc --- /dev/null +++ b/include/kitchensink/internal/utils/kitbuffer.h @@ -0,0 +1,28 @@ +#ifndef KITBUFFER_H +#define KITBUFFER_H + +#include "kitchensink/kitconfig.h" + +typedef struct Kit_Buffer Kit_Buffer; + +typedef void (*Kit_BufferFreeCallback)(void*); + +struct Kit_Buffer { + unsigned int read_p; + unsigned int write_p; + unsigned int size; + Kit_BufferFreeCallback free_cb; + void **data; +}; + +KIT_LOCAL Kit_Buffer* Kit_CreateBuffer(unsigned int size, Kit_BufferFreeCallback free_cb); +KIT_LOCAL void Kit_DestroyBuffer(Kit_Buffer *buffer); + +KIT_LOCAL void Kit_ClearBuffer(Kit_Buffer *buffer); +KIT_LOCAL void* Kit_ReadBuffer(Kit_Buffer *buffer); +KIT_LOCAL void* Kit_PeekBuffer(const Kit_Buffer *buffer); +KIT_LOCAL void Kit_AdvanceBuffer(Kit_Buffer *buffer); +KIT_LOCAL int Kit_WriteBuffer(Kit_Buffer *buffer, void *ptr); +KIT_LOCAL int Kit_IsBufferFull(const Kit_Buffer *buffer); + +#endif // KITBUFFER_H diff --git a/include/kitchensink/internal/utils/kithelpers.h b/include/kitchensink/internal/utils/kithelpers.h new file mode 100644 index 0000000..5b94a7a --- /dev/null +++ b/include/kitchensink/internal/utils/kithelpers.h @@ -0,0 +1,11 @@ +#ifndef KITHELPERS_H +#define KITHELPERS_H + +#include +#include +#include "kitchensink/kitconfig.h" + +KIT_LOCAL double _GetSystemTime(); +KIT_LOCAL bool attachment_is_font(AVStream *stream); + +#endif // KITHELPERS_H diff --git a/include/kitchensink/internal/utils/kitlog.h b/include/kitchensink/internal/utils/kitlog.h new file mode 100644 index 0000000..1a56e53 --- /dev/null +++ b/include/kitchensink/internal/utils/kitlog.h @@ -0,0 +1,11 @@ +#ifndef KITLOG_H +#define KITLOG_H + +#ifdef NDEBUG + #define LOG(...) +#else + #include + #define LOG(...) fprintf(stderr, __VA_ARGS__) +#endif + +#endif // KITLOG_H diff --git a/include/kitchensink/internal/utils/kitringbuffer.h b/include/kitchensink/internal/utils/kitringbuffer.h new file mode 100644 index 0000000..2f67520 --- /dev/null +++ b/include/kitchensink/internal/utils/kitringbuffer.h @@ -0,0 +1,23 @@ +#ifndef KITRINGBUFFER_H +#define KITRINGBUFFER_H + +#include "kitchensink/kitconfig.h" + +typedef struct Kit_RingBuffer { + int size; + int len; + int wpos, rpos; + char* data; +} Kit_RingBuffer; + +KIT_LOCAL Kit_RingBuffer* Kit_CreateRingBuffer(unsigned int size); +KIT_LOCAL void Kit_DestroyRingBuffer(Kit_RingBuffer* rb); +KIT_LOCAL int Kit_WriteRingBuffer(Kit_RingBuffer *rb, const char* data, int len); +KIT_LOCAL int Kit_ReadRingBuffer(Kit_RingBuffer *rb, char* data, int len); +KIT_LOCAL int Kit_PeekRingBuffer(const Kit_RingBuffer *rb, char* data, int len); +KIT_LOCAL int Kit_AdvanceRingBuffer(Kit_RingBuffer *rb, int len); +KIT_LOCAL int Kit_GetRingBufferLength(const Kit_RingBuffer *rb); +KIT_LOCAL int Kit_GetRingBufferSize(const Kit_RingBuffer *rb); +KIT_LOCAL int Kit_GetRingBufferFree(const Kit_RingBuffer *rb); + +#endif // KITRINGBUFFER_H diff --git a/include/kitchensink/internal/video/kitvideo.h b/include/kitchensink/internal/video/kitvideo.h new file mode 100644 index 0000000..5a5624f --- /dev/null +++ b/include/kitchensink/internal/video/kitvideo.h @@ -0,0 +1,12 @@ +#ifndef KITVIDEO_H +#define KITVIDEO_H + +#include "kitchensink/kitconfig.h" +#include "kitchensink/kitformats.h" +#include "kitchensink/kitplayer.h" +#include "kitchensink/internal/kitdecoder.h" + +KIT_LOCAL Kit_Decoder* Kit_CreateVideoDecoder(const Kit_Source *src, Kit_VideoFormat *format); +KIT_LOCAL int Kit_GetVideoDecoderData(Kit_Decoder *dec, SDL_Texture *texture); + +#endif // KITVIDEO_H diff --git a/include/kitchensink/kitformats.h b/include/kitchensink/kitformats.h index a1cc61e..129047b 100644 --- a/include/kitchensink/kitformats.h +++ b/include/kitchensink/kitformats.h @@ -24,6 +24,7 @@ typedef struct Kit_VideoFormat { typedef struct Kit_SubtitleFormat { int stream_index; ///< Stream index bool is_enabled; ///< Is stream enabled + unsigned int format; ///< SDL Pixel Format } Kit_SubtitleFormat; #endif // KITFORMATS_H diff --git a/include/kitchensink/kitlib.h b/include/kitchensink/kitlib.h index 9a827be..d8c3bb9 100644 --- a/include/kitchensink/kitlib.h +++ b/include/kitchensink/kitlib.h @@ -18,8 +18,8 @@ typedef struct Kit_Version { } Kit_Version; enum { - KIT_INIT_FORMATS = 0x1, - KIT_INIT_NETWORK = 0x2, + KIT_INIT_NETWORK = 0x1, + KIT_INIT_ASS = 0x2 }; KIT_API int Kit_Init(unsigned int flags); diff --git a/include/kitchensink/kitplayer.h b/include/kitchensink/kitplayer.h index a33828b..a5c93a2 100644 --- a/include/kitchensink/kitplayer.h +++ b/include/kitchensink/kitplayer.h @@ -21,9 +21,9 @@ extern "C" { typedef enum Kit_PlayerState { KIT_STOPPED = 0, ///< Playback stopped or has not started yet. - KIT_PLAYING, ///< Playback started & player is actively decoding. - KIT_PAUSED, ///< Playback paused; player is actively decoding but no new data is given out. - KIT_CLOSED ///< Playback is stopped and player is closing. + KIT_PLAYING, ///< Playback started & player is actively decoding. + KIT_PAUSED, ///< Playback paused; player is actively decoding but no new data is given out. + KIT_CLOSED ///< Playback is stopped and player is closing. } Kit_PlayerState; typedef struct Kit_Player { @@ -57,8 +57,8 @@ KIT_API void Kit_ClosePlayer(Kit_Player *player); KIT_API int Kit_UpdatePlayer(Kit_Player *player); KIT_API int Kit_GetVideoData(Kit_Player *player, SDL_Texture *texture); -KIT_API int Kit_GetSubtitleData(Kit_Player *player, SDL_Renderer *renderer); -KIT_API int Kit_GetAudioData(Kit_Player *player, unsigned char *buffer, int length, int cur_buf_len); +KIT_API int Kit_GetSubtitleData(Kit_Player *player, SDL_Texture *texture); +KIT_API int Kit_GetAudioData(Kit_Player *player, unsigned char *buffer, int length); KIT_API void Kit_GetPlayerInfo(const Kit_Player *player, Kit_PlayerInfo *info); KIT_API Kit_PlayerState Kit_GetPlayerState(const Kit_Player *player); -- cgit v1.2.3 From be594be5832e05d51cced3921dcdca05765f8460 Mon Sep 17 00:00:00 2001 From: Tuomas Virtanen Date: Mon, 26 Mar 2018 01:24:49 +0300 Subject: Toy around more with ass/ssa subtitles --- include/kitchensink/internal/kitdecoder.h | 1 + .../kitchensink/internal/subtitle/kitsubtitlepacket.h | 18 ++++++++++++++++++ .../internal/subtitle/renderers/kitsubrenderer.h | 5 +++-- include/kitchensink/internal/utils/kitbuffer.h | 2 ++ include/kitchensink/internal/utils/kitlog.h | 2 ++ 5 files changed, 26 insertions(+), 2 deletions(-) create mode 100644 include/kitchensink/internal/subtitle/kitsubtitlepacket.h (limited to 'include') diff --git a/include/kitchensink/internal/kitdecoder.h b/include/kitchensink/internal/kitdecoder.h index 5d494e8..6ec209e 100644 --- a/include/kitchensink/internal/kitdecoder.h +++ b/include/kitchensink/internal/kitdecoder.h @@ -46,6 +46,7 @@ KIT_LOCAL AVPacket* Kit_ReadDecoderInput(Kit_Decoder *dec); KIT_LOCAL int Kit_WriteDecoderOutput(Kit_Decoder *dec, void *packet); KIT_LOCAL void* Kit_PeekDecoderOutput(Kit_Decoder *dec); KIT_LOCAL void Kit_AdvanceDecoderOutput(Kit_Decoder *dec); +KIT_LOCAL void Kit_ForEachDecoderOutput(Kit_Decoder *dec, Kit_ForEachItemCallback foreach_cb, void *userdata); KIT_LOCAL void Kit_ClearDecoderBuffers(Kit_Decoder *dec); KIT_LOCAL int Kit_RunDecoder(Kit_Decoder *dec); KIT_LOCAL void Kit_ClearDecoderInput(Kit_Decoder *dec); diff --git a/include/kitchensink/internal/subtitle/kitsubtitlepacket.h b/include/kitchensink/internal/subtitle/kitsubtitlepacket.h new file mode 100644 index 0000000..989cde7 --- /dev/null +++ b/include/kitchensink/internal/subtitle/kitsubtitlepacket.h @@ -0,0 +1,18 @@ +#ifndef KITSUBTITLEPACKET_H +#define KITSUBTITLEPACKET_H + +#include + +typedef struct Kit_SubtitlePacket { + double pts_start; + double pts_end; + int x; + int y; + SDL_Surface *surface; +} Kit_SubtitlePacket; + +Kit_SubtitlePacket* Kit_CreateSubtitlePacket( + double pts_start, double pts_end, int pos_x, int pos_y, SDL_Surface *surface); +void Kit_FreeSubtitlePacket(Kit_SubtitlePacket *packet); + +#endif // KITSUBTITLEPACKET_H diff --git a/include/kitchensink/internal/subtitle/renderers/kitsubrenderer.h b/include/kitchensink/internal/subtitle/renderers/kitsubrenderer.h index b24161a..e237546 100644 --- a/include/kitchensink/internal/subtitle/renderers/kitsubrenderer.h +++ b/include/kitchensink/internal/subtitle/renderers/kitsubrenderer.h @@ -5,8 +5,9 @@ #include "kitchensink/kitformats.h" typedef struct Kit_SubtitleRenderer Kit_SubtitleRenderer; +//typedef struct Kit_SubtitlePacket Kit_SubtitlePacket; -typedef int (*ren_render_cb)(Kit_SubtitleRenderer *ren, void *src, double start_pts, void *surface); +typedef Kit_SubtitlePacket* (*ren_render_cb)(Kit_SubtitleRenderer *ren, void *src, double start_pts, double end_pts); typedef void (*ren_close_cb)(Kit_SubtitleRenderer *ren); struct Kit_SubtitleRenderer { @@ -16,7 +17,7 @@ struct Kit_SubtitleRenderer { }; KIT_LOCAL Kit_SubtitleRenderer* Kit_CreateSubtitleRenderer(); -KIT_LOCAL int Kit_RunSubtitleRenderer(Kit_SubtitleRenderer *ren, void *src, double start_pts, void *surface); +KIT_LOCAL Kit_SubtitlePacket* Kit_RunSubtitleRenderer(Kit_SubtitleRenderer *ren, void *src, double start_pts, double end_pts); KIT_LOCAL void Kit_CloseSubtitleRenderer(Kit_SubtitleRenderer *ren); #endif // KITSUBRENDERER_H diff --git a/include/kitchensink/internal/utils/kitbuffer.h b/include/kitchensink/internal/utils/kitbuffer.h index 4d0f8cc..67d93c3 100644 --- a/include/kitchensink/internal/utils/kitbuffer.h +++ b/include/kitchensink/internal/utils/kitbuffer.h @@ -6,6 +6,7 @@ typedef struct Kit_Buffer Kit_Buffer; typedef void (*Kit_BufferFreeCallback)(void*); +typedef void (*Kit_ForEachItemCallback)(void*, void *userdata); struct Kit_Buffer { unsigned int read_p; @@ -23,6 +24,7 @@ KIT_LOCAL void* Kit_ReadBuffer(Kit_Buffer *buffer); KIT_LOCAL void* Kit_PeekBuffer(const Kit_Buffer *buffer); KIT_LOCAL void Kit_AdvanceBuffer(Kit_Buffer *buffer); KIT_LOCAL int Kit_WriteBuffer(Kit_Buffer *buffer, void *ptr); +KIT_LOCAL void Kit_ForEachItemInBuffer(const Kit_Buffer *buffer, Kit_ForEachItemCallback cb, void *userdata); KIT_LOCAL int Kit_IsBufferFull(const Kit_Buffer *buffer); #endif // KITBUFFER_H diff --git a/include/kitchensink/internal/utils/kitlog.h b/include/kitchensink/internal/utils/kitlog.h index 1a56e53..56ff493 100644 --- a/include/kitchensink/internal/utils/kitlog.h +++ b/include/kitchensink/internal/utils/kitlog.h @@ -3,9 +3,11 @@ #ifdef NDEBUG #define LOG(...) + #define LOGFLUSH() #else #include #define LOG(...) fprintf(stderr, __VA_ARGS__) + #define LOGFLUSH() fflush(stderr) #endif #endif // KITLOG_H -- cgit v1.2.3 From 1af119147925100600f655360b8199914e900d94 Mon Sep 17 00:00:00 2001 From: Tuomas Virtanen Date: Mon, 26 Mar 2018 01:51:16 +0300 Subject: Remove unneccessary logging --- include/kitchensink/internal/utils/kitlog.h | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'include') diff --git a/include/kitchensink/internal/utils/kitlog.h b/include/kitchensink/internal/utils/kitlog.h index 56ff493..6b24763 100644 --- a/include/kitchensink/internal/utils/kitlog.h +++ b/include/kitchensink/internal/utils/kitlog.h @@ -3,11 +3,9 @@ #ifdef NDEBUG #define LOG(...) - #define LOGFLUSH() #else #include - #define LOG(...) fprintf(stderr, __VA_ARGS__) - #define LOGFLUSH() fflush(stderr) + #define LOG(...) fprintf(stderr, __VA_ARGS__); fflush(stderr) #endif #endif // KITLOG_H -- cgit v1.2.3 From 176a33ef7c50c51d6c86400b635d4e7bb132f968 Mon Sep 17 00:00:00 2001 From: Tuomas Virtanen Date: Mon, 26 Mar 2018 04:06:51 +0300 Subject: Add support for bitmap subtitles --- include/kitchensink/internal/subtitle/renderers/kitsubimage.h | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'include') diff --git a/include/kitchensink/internal/subtitle/renderers/kitsubimage.h b/include/kitchensink/internal/subtitle/renderers/kitsubimage.h index d26b67e..706f1f0 100644 --- a/include/kitchensink/internal/subtitle/renderers/kitsubimage.h +++ b/include/kitchensink/internal/subtitle/renderers/kitsubimage.h @@ -1,6 +1,10 @@ #ifndef KITSUBIMAGE_H #define KITSUBIMAGE_H +#include "kitchensink/kitconfig.h" +#include "kitchensink/internal/kitdecoder.h" +#include "kitchensink/internal/subtitle/renderers/kitsubrenderer.h" +KIT_LOCAL Kit_SubtitleRenderer* Kit_CreateImageSubtitleRenderer(const Kit_Decoder *dec, int w, int h); #endif // KITSUBIMAGE_H -- cgit v1.2.3 From 8bdc67e490f38d645ad6bbd230c9e16d8eba4099 Mon Sep 17 00:00:00 2001 From: Tuomas Virtanen Date: Mon, 26 Mar 2018 04:13:37 +0300 Subject: More compiler warning cleanups --- include/kitchensink/internal/subtitle/kitsubtitlepacket.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include') diff --git a/include/kitchensink/internal/subtitle/kitsubtitlepacket.h b/include/kitchensink/internal/subtitle/kitsubtitlepacket.h index 989cde7..e3ae4e4 100644 --- a/include/kitchensink/internal/subtitle/kitsubtitlepacket.h +++ b/include/kitchensink/internal/subtitle/kitsubtitlepacket.h @@ -1,7 +1,7 @@ #ifndef KITSUBTITLEPACKET_H #define KITSUBTITLEPACKET_H -#include +#include typedef struct Kit_SubtitlePacket { double pts_start; -- cgit v1.2.3 From 2843974d284cb2046318d2da5fcedc95104e88d9 Mon Sep 17 00:00:00 2001 From: Tuomas Virtanen Date: Mon, 26 Mar 2018 15:15:19 +0300 Subject: Allow runtime loading of libass library. Previously libass could only be statically linked. Now we allow runtime loading of the library on request (just like other SDL libraries do). --- include/kitchensink/internal/kitlibstate.h | 3 +- include/kitchensink/internal/libass.h | 57 ++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 include/kitchensink/internal/libass.h (limited to 'include') diff --git a/include/kitchensink/internal/kitlibstate.h b/include/kitchensink/internal/kitlibstate.h index e16a5c9..ad515b9 100644 --- a/include/kitchensink/internal/kitlibstate.h +++ b/include/kitchensink/internal/kitlibstate.h @@ -1,12 +1,13 @@ #ifndef KITLIBSTATE_H #define KITLIBSTATE_H -#include +#include "kitchensink/internal/libass.h" #include "kitchensink/kitconfig.h" typedef struct Kit_LibraryState { unsigned int init_flags; ASS_Library *libass_handle; + void *ass_so_handle; } Kit_LibraryState; KIT_LOCAL Kit_LibraryState* Kit_GetLibraryState(); diff --git a/include/kitchensink/internal/libass.h b/include/kitchensink/internal/libass.h new file mode 100644 index 0000000..0c9730a --- /dev/null +++ b/include/kitchensink/internal/libass.h @@ -0,0 +1,57 @@ +#ifndef KITLIBASS_H +#define KITLIBASS_H + +#ifndef USE_DYNAMIC_LIBASS + +#include + +#else // USE_DYNAMIC_LIBASS + +#include +#include + +typedef struct ass_library ASS_Library; +typedef struct ass_renderer ASS_Renderer; +typedef struct ass_track ASS_Track; + +typedef struct ass_image { + int w, h; + int stride; + unsigned char *bitmap; + uint32_t color; + int dst_x, dst_y; + struct ass_image *next; + enum { + IMAGE_TYPE_CHARACTER, + IMAGE_TYPE_OUTLINE, + IMAGE_TYPE_SHADOW + } type; +} ASS_Image; + +typedef enum { + ASS_HINTING_NONE = 0, + ASS_HINTING_LIGHT, + ASS_HINTING_NORMAL, + ASS_HINTING_NATIVE +} ASS_Hinting; + +ASS_Library* (*ass_library_init)(void); +void (*ass_library_done)(ASS_Library *priv); +void (*ass_process_codec_private)(ASS_Track *track, char *data, int size); +void (*ass_set_message_cb)(ASS_Library *priv, void (*msg_cb)(int level, const char *fmt, va_list args, void *data), void *data); +ASS_Renderer* (*ass_renderer_init)(ASS_Library *); +void (*ass_renderer_done)(ASS_Renderer *priv); +void (*ass_set_frame_size)(ASS_Renderer *priv, int w, int h); +void (*ass_set_hinting)(ASS_Renderer *priv, ASS_Hinting ht); +void (*ass_set_fonts)(ASS_Renderer *priv, const char *default_font, const char *default_family, int dfp, const char *config, int update); +ASS_Image* (*ass_render_frame)(ASS_Renderer *priv, ASS_Track *track, long long now, int *detect_change); +ASS_Track* (*ass_new_track)(ASS_Library *); +void (*ass_free_track)(ASS_Track *track); +void (*ass_process_data)(ASS_Track *track, char *data, int size); +void (*ass_add_font)(ASS_Library *library, char *name, char *data, int data_size); + +int load_libass(void *handle); + +#endif // USE_DYNAMIC_LIBASS + +#endif // KITLIBASS_H -- cgit v1.2.3 From 9777f2b386f7846fe5ebfe04d3086c157baea2db Mon Sep 17 00:00:00 2001 From: Tuomas Virtanen Date: Mon, 26 Mar 2018 18:22:59 +0300 Subject: Cleanup and function renames --- include/kitchensink/internal/subtitle/kitsubtitle.h | 2 +- include/kitchensink/internal/video/kitvideo.h | 2 +- include/kitchensink/kitplayer.h | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) (limited to 'include') diff --git a/include/kitchensink/internal/subtitle/kitsubtitle.h b/include/kitchensink/internal/subtitle/kitsubtitle.h index 51de9b9..a8b4cc0 100644 --- a/include/kitchensink/internal/subtitle/kitsubtitle.h +++ b/include/kitchensink/internal/subtitle/kitsubtitle.h @@ -9,6 +9,6 @@ #include "kitchensink/internal/kitdecoder.h" KIT_LOCAL Kit_Decoder* Kit_CreateSubtitleDecoder(const Kit_Source *src, Kit_SubtitleFormat *format, int w, int h); -KIT_LOCAL int Kit_GetSubtitleDecoderData(Kit_Decoder *dec, SDL_Texture *texture); +KIT_LOCAL int Kit_GetSubtitleDecoderDataTexture(Kit_Decoder *dec, SDL_Texture *texture); #endif // KITSUBTITLE_H diff --git a/include/kitchensink/internal/video/kitvideo.h b/include/kitchensink/internal/video/kitvideo.h index 5a5624f..6978d9f 100644 --- a/include/kitchensink/internal/video/kitvideo.h +++ b/include/kitchensink/internal/video/kitvideo.h @@ -7,6 +7,6 @@ #include "kitchensink/internal/kitdecoder.h" KIT_LOCAL Kit_Decoder* Kit_CreateVideoDecoder(const Kit_Source *src, Kit_VideoFormat *format); -KIT_LOCAL int Kit_GetVideoDecoderData(Kit_Decoder *dec, SDL_Texture *texture); +KIT_LOCAL int Kit_GetVideoDecoderDataTexture(Kit_Decoder *dec, SDL_Texture *texture); #endif // KITVIDEO_H diff --git a/include/kitchensink/kitplayer.h b/include/kitchensink/kitplayer.h index a5c93a2..4c80e9a 100644 --- a/include/kitchensink/kitplayer.h +++ b/include/kitchensink/kitplayer.h @@ -56,8 +56,8 @@ KIT_API Kit_Player* Kit_CreatePlayer(const Kit_Source *src); KIT_API void Kit_ClosePlayer(Kit_Player *player); KIT_API int Kit_UpdatePlayer(Kit_Player *player); -KIT_API int Kit_GetVideoData(Kit_Player *player, SDL_Texture *texture); -KIT_API int Kit_GetSubtitleData(Kit_Player *player, SDL_Texture *texture); +KIT_API int Kit_GetVideoDataTexture(Kit_Player *player, SDL_Texture *texture); +KIT_API int Kit_GetSubtitleDataTexture(Kit_Player *player, SDL_Texture *texture); KIT_API int Kit_GetAudioData(Kit_Player *player, unsigned char *buffer, int length); KIT_API void Kit_GetPlayerInfo(const Kit_Player *player, Kit_PlayerInfo *info); -- cgit v1.2.3