diff options
author | Tuomas Virtanen <katajakasa@gmail.com> | 2016-01-14 04:22:02 +0200 |
---|---|---|
committer | Tuomas Virtanen <katajakasa@gmail.com> | 2016-01-14 04:22:02 +0200 |
commit | fb8b8f3b6b8b1905a3811ef3a6c396d0f3dc26a6 (patch) | |
tree | 0ed689179645fcde899f52e30fab4988891e2e7a /include | |
parent | 28e4719f81e84b54e397970d09a85accd2d35543 (diff) |
Add seeking
Diffstat (limited to 'include')
-rw-r--r-- | include/kitchensink/kitchensink.h | 1 | ||||
-rw-r--r-- | include/kitchensink/kitplayer.h | 95 | ||||
-rw-r--r-- | include/kitchensink/kitsource.h | 32 | ||||
-rw-r--r-- | include/kitchensink/kitutils.h | 18 |
4 files changed, 92 insertions, 54 deletions
diff --git a/include/kitchensink/kitchensink.h b/include/kitchensink/kitchensink.h index 3120db7..0d40442 100644 --- a/include/kitchensink/kitchensink.h +++ b/include/kitchensink/kitchensink.h @@ -4,6 +4,7 @@ #include "kitchensink/kiterror.h" #include "kitchensink/kitsource.h" #include "kitchensink/kitplayer.h" +#include "kitchensink/kitutils.h" #include "kitchensink/kitconfig.h" #ifdef __cplusplus diff --git a/include/kitchensink/kitplayer.h b/include/kitchensink/kitplayer.h index 4d99e26..a0f97ad 100644 --- a/include/kitchensink/kitplayer.h +++ b/include/kitchensink/kitplayer.h @@ -17,55 +17,70 @@ extern "C" { #define KIT_CODECNAMEMAX 128 typedef enum Kit_PlayerState { - KIT_STOPPED = 0, - KIT_PLAYING, - KIT_PAUSED, - KIT_CLOSED + 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_PlayerState; typedef struct Kit_AudioFormat { - bool is_enabled; // Is stream enabled - unsigned int format; - bool is_signed; - int bytes; - int samplerate; - int channels; + 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 { - bool is_enabled; // Is stream enabled - unsigned int format; - int width; - int height; + 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_Player { - Kit_PlayerState state; - Kit_VideoFormat vformat; - Kit_AudioFormat aformat; - double clock_sync; // Clock sync point - double pause_start; // Timestamp of pause beginning - SDL_Thread *dec_thread; - SDL_mutex *vmutex; - SDL_mutex *amutex; - void *abuffer; - void *vbuffer; - void *vcodec_ctx; - void *acodec_ctx; - void *tmp_vframe; - void *tmp_aframe; - void *swr; - void *sws; - const Kit_Source *src; + // Local state + Kit_PlayerState state; ///< Playback state + Kit_VideoFormat vformat; ///< Video format information + Kit_AudioFormat aformat; ///< Audio 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 *cmutex; ///< Control stream buffer lock + + // Buffers + void *abuffer; ///<Audio stream buffer + void *vbuffer; ///< Video 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 *tmp_vframe; ///< FFmpeg: Preallocated temporary video frame + void *tmp_aframe; ///< FFmpeg: Preallocated temporary audio frame + void *swr; ///< FFmpeg: Audio resampler + void *sws; ///< FFmpeg: Video converter + + // Other + uint8_t seek_flag; + const Kit_Source *src; ///< Reference to Audio/Video source } Kit_Player; typedef struct Kit_PlayerInfo { - char acodec[KIT_CODECMAX]; - char acodec_name[KIT_CODECNAMEMAX]; - char vcodec[KIT_CODECMAX]; - char vcodec_name[KIT_CODECNAMEMAX]; - Kit_VideoFormat video; - Kit_AudioFormat audio; + 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 + Kit_VideoFormat video; ///< Video format information + Kit_AudioFormat audio; ///< Audio format information } Kit_PlayerInfo; KIT_API Kit_Player* Kit_CreatePlayer(const Kit_Source *src); @@ -73,7 +88,7 @@ KIT_API void Kit_ClosePlayer(Kit_Player *player); KIT_API int Kit_UpdatePlayer(Kit_Player *player); KIT_API int Kit_RefreshTexture(Kit_Player *player, SDL_Texture *texture); -KIT_API int Kit_GetAudioData(Kit_Player *player, unsigned char *buffer, size_t length, size_t cur_buf_len); +KIT_API int Kit_GetAudioData(Kit_Player *player, unsigned char *buffer, int length, int cur_buf_len); KIT_API void Kit_GetPlayerInfo(const Kit_Player *player, Kit_PlayerInfo *info); KIT_API Kit_PlayerState Kit_GetPlayerState(const Kit_Player *player); @@ -81,6 +96,10 @@ KIT_API void Kit_PlayerPlay(Kit_Player *player); KIT_API void Kit_PlayerStop(Kit_Player *player); KIT_API void Kit_PlayerPause(Kit_Player *player); +KIT_API int Kit_PlayerSeek(Kit_Player *player, double time); +KIT_API double Kit_GetPlayerDuration(const Kit_Player *player); +KIT_API double Kit_GetPlayerPosition(const Kit_Player *player); + #ifdef __cplusplus } #endif diff --git a/include/kitchensink/kitsource.h b/include/kitchensink/kitsource.h index 43b9d2b..aef9764 100644 --- a/include/kitchensink/kitsource.h +++ b/include/kitchensink/kitsource.h @@ -10,24 +10,24 @@ extern "C" { #define KIT_CODECNAMESIZE 32 #define KIT_CODECLONGNAMESIZE 128 -typedef enum Kit_streamtype { - KIT_STREAMTYPE_UNKNOWN, - KIT_STREAMTYPE_VIDEO, - KIT_STREAMTYPE_AUDIO, - KIT_STREAMTYPE_DATA, - KIT_STREAMTYPE_SUBTITLE, - KIT_STREAMTYPE_ATTACHMENT -} Kit_streamtype; +typedef enum Kit_StreamType { + KIT_STREAMTYPE_UNKNOWN, ///< Unknown stream type + KIT_STREAMTYPE_VIDEO, ///< Video stream + KIT_STREAMTYPE_AUDIO, ///< Audio stream + KIT_STREAMTYPE_DATA, ///< Data stream + KIT_STREAMTYPE_SUBTITLE, ///< Subtitle streawm + KIT_STREAMTYPE_ATTACHMENT ///< Attachment stream (images, etc) +} Kit_StreamType; typedef struct Kit_Source { - int astream_idx; - int vstream_idx; - void *format_ctx; + int astream_idx; ///< Audiostream index + int vstream_idx; ///< Videostream index + void *format_ctx; ///< FFmpeg: Videostream format context } Kit_Source; typedef struct Kit_Stream { - int index; - Kit_streamtype type; + int index; ///< Stream index + Kit_StreamType type; ///< Stream type } Kit_StreamInfo; KIT_API Kit_Source* Kit_CreateSourceFromUrl(const char *path); @@ -35,9 +35,9 @@ 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_GetSourceStreamCount(const Kit_Source *src); -KIT_API int Kit_GetBestSourceStream(const Kit_Source *src, const Kit_streamtype type); -KIT_API int Kit_SetSourceStream(Kit_Source *src, const Kit_streamtype type, int index); -KIT_API int Kit_GetSourceStream(const Kit_Source *src, const Kit_streamtype type); +KIT_API int Kit_GetBestSourceStream(const Kit_Source *src, const Kit_StreamType type); +KIT_API int Kit_SetSourceStream(Kit_Source *src, const Kit_StreamType type, int index); +KIT_API int Kit_GetSourceStream(const Kit_Source *src, const Kit_StreamType type); #ifdef __cplusplus } diff --git a/include/kitchensink/kitutils.h b/include/kitchensink/kitutils.h new file mode 100644 index 0000000..af3307c --- /dev/null +++ b/include/kitchensink/kitutils.h @@ -0,0 +1,18 @@ +#ifndef KITUTILS_H +#define KITUTILS_H + +#include "kitchensink/kitconfig.h" + +#ifdef __cplusplus +extern "C" { +#endif + +KIT_API const char* Kit_GetSDLAudioFormatString(unsigned int type); +KIT_API const char* Kit_GetSDLPixelFormatString(unsigned int type); +KIT_API const char* Kit_GetKitStreamTypeString(unsigned int type); + +#ifdef __cplusplus +} +#endif + +#endif // KITUTILS_H |