summaryrefslogtreecommitdiff
path: root/include/kitchensink
diff options
context:
space:
mode:
authorTuomas Virtanen <katajakasa@gmail.com>2018-06-24 23:30:42 +0300
committerTuomas Virtanen <katajakasa@gmail.com>2018-06-24 23:30:42 +0300
commitd7d5cb75e6fa7f0d2eaeb9cdaf2812dc4c5be466 (patch)
tree63a68f7fceb4d4a9c06a0e5054375da0477f081f /include/kitchensink
parent1d06ec23f264e18a188bf46b72c8794c82c4b89e (diff)
API rework #36, #37
Diffstat (limited to 'include/kitchensink')
-rw-r--r--include/kitchensink/internal/audio/kitaudio.h5
-rw-r--r--include/kitchensink/internal/kitdecoder.h24
-rw-r--r--include/kitchensink/internal/kitlibstate.h5
-rw-r--r--include/kitchensink/internal/subtitle/kitsubtitle.h5
-rw-r--r--include/kitchensink/internal/subtitle/renderers/kitsubrenderer.h1
-rw-r--r--include/kitchensink/internal/video/kitvideo.h7
-rw-r--r--include/kitchensink/kitchensink.h3
-rw-r--r--include/kitchensink/kitcodec.h21
-rw-r--r--include/kitchensink/kitformat.h24
-rw-r--r--include/kitchensink/kitformats.h38
-rw-r--r--include/kitchensink/kitlib.h22
-rw-r--r--include/kitchensink/kitplayer.h46
-rw-r--r--include/kitchensink/kitsource.h13
13 files changed, 120 insertions, 94 deletions
diff --git a/include/kitchensink/internal/audio/kitaudio.h b/include/kitchensink/internal/audio/kitaudio.h
index 105c9f6..e42770b 100644
--- a/include/kitchensink/internal/audio/kitaudio.h
+++ b/include/kitchensink/internal/audio/kitaudio.h
@@ -2,11 +2,10 @@
#define KITAUDIO_H
#include "kitchensink/kitconfig.h"
-#include "kitchensink/kitformats.h"
-#include "kitchensink/kitplayer.h"
+#include "kitchensink/kitsource.h"
#include "kitchensink/internal/kitdecoder.h"
-KIT_LOCAL Kit_Decoder* Kit_CreateAudioDecoder(const Kit_Source *src, int stream_index, Kit_AudioFormat *format);
+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);
#endif // KITAUDIO_H
diff --git a/include/kitchensink/internal/kitdecoder.h b/include/kitchensink/internal/kitdecoder.h
index b4b3f36..0e89aea 100644
--- a/include/kitchensink/internal/kitdecoder.h
+++ b/include/kitchensink/internal/kitdecoder.h
@@ -7,6 +7,8 @@
#include <libavcodec/avcodec.h>
#include <libavformat/avformat.h>
+#include "kitchensink/kitformat.h"
+#include "kitchensink/kitcodec.h"
#include "kitchensink/kitconfig.h"
#include "kitchensink/kitsource.h"
#include "kitchensink/internal/utils/kitbuffer.h"
@@ -24,6 +26,7 @@ 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
+ Kit_OutputFormat output; ///< Output format for the decoder
AVCodecContext *codec_ctx; ///< FFMpeg internal: Codec context
AVFormatContext *format_ctx; ///< FFMpeg internal: Format context (owner: Kit_Source)
@@ -37,24 +40,33 @@ KIT_LOCAL struct Kit_Decoder {
};
KIT_LOCAL Kit_Decoder* Kit_CreateDecoder(const Kit_Source *src, int stream_index,
- int out_b_size, dec_free_packet_cb free_out_cb);
-KIT_LOCAL int Kit_SetDecoderStreamIndex(Kit_Decoder *dec, int stream_index);
+ int out_b_size, dec_free_packet_cb free_out_cb,
+ int thread_count);
+KIT_LOCAL void Kit_CloseDecoder(Kit_Decoder *dec);
+
+KIT_LOCAL int Kit_GetDecoderStreamIndex(const Kit_Decoder *dec);
+KIT_LOCAL int Kit_GetDecoderCodecInfo(const Kit_Decoder *dec, Kit_Codec *codec);
+KIT_LOCAL int Kit_GetDecoderOutputFormat(const Kit_Decoder *dec, Kit_OutputFormat *output);
+
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 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 void Kit_ClearDecoderInput(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_ReadDecoderOutput(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_LockDecoderOutput(Kit_Decoder *dec);
KIT_LOCAL void Kit_UnlockDecoderOutput(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/kitlibstate.h b/include/kitchensink/internal/kitlibstate.h
index ad515b9..b92cebb 100644
--- a/include/kitchensink/internal/kitlibstate.h
+++ b/include/kitchensink/internal/kitlibstate.h
@@ -6,6 +6,11 @@
typedef struct Kit_LibraryState {
unsigned int init_flags;
+ unsigned int thread_count;
+ unsigned int font_hinting;
+ unsigned int video_buf_frames;
+ unsigned int audio_buf_frames;
+ unsigned int subtitle_buf_frames;
ASS_Library *libass_handle;
void *ass_so_handle;
} Kit_LibraryState;
diff --git a/include/kitchensink/internal/subtitle/kitsubtitle.h b/include/kitchensink/internal/subtitle/kitsubtitle.h
index 9f83e3d..8de101b 100644
--- a/include/kitchensink/internal/subtitle/kitsubtitle.h
+++ b/include/kitchensink/internal/subtitle/kitsubtitle.h
@@ -4,12 +4,11 @@
#include <SDL2/SDL_render.h>
#include "kitchensink/kitconfig.h"
-#include "kitchensink/kitformats.h"
-#include "kitchensink/kitplayer.h"
+#include "kitchensink/kitsource.h"
#include "kitchensink/internal/kitdecoder.h"
KIT_LOCAL Kit_Decoder* Kit_CreateSubtitleDecoder(
- const Kit_Source *src, int stream_index, Kit_SubtitleFormat *format, int video_w, int video_h, int screen_w, int screen_h);
+ const Kit_Source *src, int stream_index, int video_w, int video_h, int screen_w, int screen_h);
KIT_LOCAL int Kit_GetSubtitleDecoderData(
Kit_Decoder *dec, SDL_Texture *texture, SDL_Rect *sources, SDL_Rect *targets, int limit);
KIT_LOCAL void Kit_SetSubtitleDecoderSize(Kit_Decoder *dec, int w, int h);
diff --git a/include/kitchensink/internal/subtitle/renderers/kitsubrenderer.h b/include/kitchensink/internal/subtitle/renderers/kitsubrenderer.h
index 84b815b..e07aa55 100644
--- a/include/kitchensink/internal/subtitle/renderers/kitsubrenderer.h
+++ b/include/kitchensink/internal/subtitle/renderers/kitsubrenderer.h
@@ -2,7 +2,6 @@
#define KITSUBRENDERER_H
#include "kitchensink/kitsource.h"
-#include "kitchensink/kitformats.h"
typedef struct Kit_SubtitleRenderer Kit_SubtitleRenderer;
typedef struct Kit_TextureAtlas Kit_TextureAtlas;
diff --git a/include/kitchensink/internal/video/kitvideo.h b/include/kitchensink/internal/video/kitvideo.h
index 1e158a7..0733177 100644
--- a/include/kitchensink/internal/video/kitvideo.h
+++ b/include/kitchensink/internal/video/kitvideo.h
@@ -1,12 +1,13 @@
#ifndef KITVIDEO_H
#define KITVIDEO_H
+#include <SDL2/SDL_render.h>
+
#include "kitchensink/kitconfig.h"
-#include "kitchensink/kitformats.h"
-#include "kitchensink/kitplayer.h"
+#include "kitchensink/kitsource.h"
#include "kitchensink/internal/kitdecoder.h"
-KIT_LOCAL Kit_Decoder* Kit_CreateVideoDecoder(const Kit_Source *src, int stream_index, Kit_VideoFormat *format);
+KIT_LOCAL Kit_Decoder* Kit_CreateVideoDecoder(const Kit_Source *src, int stream_index);
KIT_LOCAL int Kit_GetVideoDecoderData(Kit_Decoder *dec, SDL_Texture *texture);
#endif // KITVIDEO_H
diff --git a/include/kitchensink/kitchensink.h b/include/kitchensink/kitchensink.h
index 6c5da35..568c0d8 100644
--- a/include/kitchensink/kitchensink.h
+++ b/include/kitchensink/kitchensink.h
@@ -3,7 +3,8 @@
#include "kitchensink/kitlib.h"
#include "kitchensink/kiterror.h"
-#include "kitchensink/kitformats.h"
+#include "kitchensink/kitformat.h"
+#include "kitchensink/kitcodec.h"
#include "kitchensink/kitsource.h"
#include "kitchensink/kitplayer.h"
#include "kitchensink/kitutils.h"
diff --git a/include/kitchensink/kitcodec.h b/include/kitchensink/kitcodec.h
new file mode 100644
index 0000000..76b53a4
--- /dev/null
+++ b/include/kitchensink/kitcodec.h
@@ -0,0 +1,21 @@
+#ifndef KITCODEC_H
+#define KITCODEC_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define KIT_CODEC_NAME_MAX 8
+#define KIT_CODEC_DESC_MAX 48
+
+typedef struct Kit_Codec {
+ unsigned int threads; ///< Currently enabled threads
+ char name[KIT_CODEC_NAME_MAX]; ///< Codec short name, eg. "ogg" or "webm"
+ char description[KIT_CODEC_DESC_MAX]; ///< Codec longer, more descriptive name
+} Kit_Codec;
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif // KITCODEC_H
diff --git a/include/kitchensink/kitformat.h b/include/kitchensink/kitformat.h
new file mode 100644
index 0000000..4c428c5
--- /dev/null
+++ b/include/kitchensink/kitformat.h
@@ -0,0 +1,24 @@
+#ifndef KITFORMAT_H
+#define KITFORMAT_H
+
+#include <stdbool.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef struct Kit_OutputFormat {
+ unsigned int format; ///< SDL Format
+ bool is_signed; ///< Signedness (if audio)
+ int bytes; ///< Bytes per sample per channel (if audio)
+ int samplerate; ///< Sampling rate (if audio)
+ int channels; ///< Channels (if audio)
+ int width; ///< Width in pixels (if video)
+ int height; ///< Height in pixels (if video)
+} Kit_OutputFormat;
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif // KITFORMAT_H
diff --git a/include/kitchensink/kitformats.h b/include/kitchensink/kitformats.h
deleted file mode 100644
index 80bfd4f..0000000
--- a/include/kitchensink/kitformats.h
+++ /dev/null
@@ -1,38 +0,0 @@
-#ifndef KITFORMATS_H
-#define KITFORMATS_H
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#include <stdbool.h>
-
-typedef struct Kit_AudioFormat {
- int stream_index; ///< 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_index; ///< 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_index; ///< Stream index
- bool is_enabled; ///< Is stream enabled
- unsigned int format; ///< SDL Pixel Format
-} Kit_SubtitleFormat;
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif // KITFORMATS_H
diff --git a/include/kitchensink/kitlib.h b/include/kitchensink/kitlib.h
index d8c3bb9..85ce2d4 100644
--- a/include/kitchensink/kitlib.h
+++ b/include/kitchensink/kitlib.h
@@ -1,22 +1,34 @@
#ifndef KITLIB_H
#define KITLIB_H
-#include "kitchensink/kiterror.h"
-#include "kitchensink/kitsource.h"
-#include "kitchensink/kitplayer.h"
-#include "kitchensink/kitutils.h"
#include "kitchensink/kitconfig.h"
#ifdef __cplusplus
extern "C" {
#endif
+enum { // These should match libass
+ KIT_FONT_HINTING_NONE = 0,
+ KIT_FONT_HINTING_LIGHT,
+ KIT_FONT_HINTING_NORMAL,
+ KIT_FONT_HINTING_NATIVE,
+ KIT_FONT_HINTING_COUNT
+};
+
typedef struct Kit_Version {
unsigned char major;
unsigned char minor;
unsigned char patch;
} Kit_Version;
+typedef enum Kit_HintType {
+ KIT_HINT_FONT_HINTING,
+ KIT_HINT_THREAD_COUNT,
+ KIT_HINT_VIDEO_BUFFER_FRAMES,
+ KIT_HINT_AUDIO_BUFFER_FRAMES,
+ KIT_HINT_SUBTITLE_BUFFER_FRAMES
+} Kit_HintType;
+
enum {
KIT_INIT_NETWORK = 0x1,
KIT_INIT_ASS = 0x2
@@ -24,6 +36,8 @@ enum {
KIT_API int Kit_Init(unsigned int flags);
KIT_API void Kit_Quit();
+KIT_API void Kit_SetHint(Kit_HintType type, int value);
+KIT_API int Kit_GetHint(Kit_HintType type);
KIT_API void Kit_GetVersion(Kit_Version *version);
#ifdef __cplusplus
diff --git a/include/kitchensink/kitplayer.h b/include/kitchensink/kitplayer.h
index 04e1a0b..27e268d 100644
--- a/include/kitchensink/kitplayer.h
+++ b/include/kitchensink/kitplayer.h
@@ -3,7 +3,8 @@
#include "kitchensink/kitsource.h"
#include "kitchensink/kitconfig.h"
-#include "kitchensink/kitformats.h"
+#include "kitchensink/kitformat.h"
+#include "kitchensink/kitcodec.h"
#include <SDL2/SDL_render.h>
#include <SDL2/SDL_thread.h>
@@ -16,9 +17,6 @@
extern "C" {
#endif
-#define KIT_CODECMAX 16
-#define KIT_CODECNAMEMAX 128
-
typedef enum Kit_PlayerState {
KIT_STOPPED = 0, ///< Playback stopped or has not started yet.
KIT_PLAYING, ///< Playback started & player is actively decoding.
@@ -27,29 +25,23 @@ typedef enum Kit_PlayerState {
} Kit_PlayerState;
typedef struct Kit_Player {
- Kit_PlayerState state; ///< Playback state
- Kit_VideoFormat vformat; ///< Video format information
- Kit_AudioFormat aformat; ///< Audio format information
- Kit_SubtitleFormat sformat; ///< Subtitle format information
- 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_PlayerState state; ///< Playback state
+ void *decoders[3]; ///< Decoder contexts
+ 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_PlayerStreamInfo {
+ Kit_Codec codec;
+ Kit_OutputFormat output;
+} Kit_PlayerStreamInfo;
+
typedef struct Kit_PlayerInfo {
- char acodec[KIT_CODECMAX]; ///< Audio codec short name, eg "ogg", "mp3"
- char acodec_name[KIT_CODECNAMEMAX]; ///< Audio codec long, more descriptive name
- char vcodec[KIT_CODECMAX]; ///< Video codec short name, eg. "x264"
- char vcodec_name[KIT_CODECNAMEMAX]; ///< Video codec long, more descriptive name
- char scodec[KIT_CODECMAX]; ///< Subtitle codec short name, eg. "ass"
- char scodec_name[KIT_CODECNAMEMAX]; ///< Subtitle codec long, more descriptive name
- Kit_VideoFormat video; ///< Video format information
- Kit_AudioFormat audio; ///< Audio format information
- Kit_SubtitleFormat subtitle; ///< Subtitle format information
+ Kit_PlayerStreamInfo video;
+ Kit_PlayerStreamInfo audio;
+ Kit_PlayerStreamInfo subtitle;
} Kit_PlayerInfo;
KIT_API Kit_Player* Kit_CreatePlayer(const Kit_Source *src,
@@ -61,9 +53,9 @@ KIT_API Kit_Player* Kit_CreatePlayer(const Kit_Source *src,
KIT_API void Kit_ClosePlayer(Kit_Player *player);
KIT_API void Kit_SetPlayerScreenSize(Kit_Player *player, int w, int h);
-KIT_API int Kit_SetPlayerVideoStream(Kit_Player *player, int index);
-KIT_API int Kit_SetPlayerAudioStream(Kit_Player *player, int index);
-KIT_API int Kit_SetPlayerSubtitleStream(Kit_Player *player, int index);
+KIT_API int Kit_GetPlayerVideoStream(const Kit_Player *player);
+KIT_API int Kit_GetPlayerAudioStream(const Kit_Player *player);
+KIT_API int Kit_GetPlayerSubtitleStream(const Kit_Player *player);
KIT_API int Kit_UpdatePlayer(Kit_Player *player);
KIT_API int Kit_GetPlayerVideoData(Kit_Player *player, SDL_Texture *texture);
diff --git a/include/kitchensink/kitsource.h b/include/kitchensink/kitsource.h
index 0ca8e26..db6ee21 100644
--- a/include/kitchensink/kitsource.h
+++ b/include/kitchensink/kitsource.h
@@ -8,9 +8,6 @@
extern "C" {
#endif
-#define KIT_CODECNAMESIZE 32
-#define KIT_CODECLONGNAMESIZE 128
-
typedef enum Kit_StreamType {
KIT_STREAMTYPE_UNKNOWN, ///< Unknown stream type
KIT_STREAMTYPE_VIDEO, ///< Video stream
@@ -21,14 +18,14 @@ typedef enum Kit_StreamType {
} Kit_StreamType;
typedef struct Kit_Source {
- void *format_ctx; ///< FFmpeg: Videostream format context
- void *avio_ctx; ///< FFmpeg: AVIO context
+ void *format_ctx; ///< FFmpeg: Videostream format context
+ void *avio_ctx; ///< FFmpeg: AVIO context
} Kit_Source;
-typedef struct Kit_StreamInfo {
+typedef struct Kit_SourceStreamInfo {
int index; ///< Stream index
Kit_StreamType type; ///< Stream type
-} Kit_StreamInfo;
+} Kit_SourceStreamInfo;
typedef int (*Kit_ReadCallback)(void*, uint8_t*, int);
typedef int64_t (*Kit_SeekCallback)(void*, int64_t, int);
@@ -37,7 +34,7 @@ KIT_API Kit_Source* Kit_CreateSourceFromUrl(const char *path);
KIT_API Kit_Source* Kit_CreateSourceFromCustom(Kit_ReadCallback read_cb, Kit_SeekCallback seek_cb, void *userdata);
KIT_API void Kit_CloseSource(Kit_Source *src);
-KIT_API int Kit_GetSourceStreamInfo(const Kit_Source *src, Kit_StreamInfo *info, int index);
+KIT_API int Kit_GetSourceStreamInfo(const Kit_Source *src, Kit_SourceStreamInfo *info, int index);
KIT_API int Kit_GetSourceStreamCount(const Kit_Source *src);
KIT_API int Kit_GetBestSourceStream(const Kit_Source *src, const Kit_StreamType type);