summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDidier Raboud <odyx@debian.org>2017-10-20 14:01:07 +0200
committerDidier Raboud <odyx@debian.org>2017-10-20 14:01:07 +0200
commit81cba7886537400f5505cf5d91e7558510844b51 (patch)
treed3adfb29ca7a71a9cd116e5bf4b5f3f62dd194f8
Import sdl-kitchensink_0.0.7.orig.tar.gz
[dgit import orig sdl-kitchensink_0.0.7.orig.tar.gz]
-rw-r--r--.gitignore40
-rw-r--r--.travis.yml59
-rw-r--r--CMakeLists.txt89
-rw-r--r--LICENSE22
-rw-r--r--README.md101
-rw-r--r--cmake/FindSDL2.cmake54
-rw-r--r--cmake/Findass.cmake43
-rw-r--r--cmake/Findcunit.cmake41
-rw-r--r--cmake/Findffmpeg.cmake74
-rw-r--r--doc/Doxyfile1892
-rw-r--r--doc/FRONT.md43
-rw-r--r--doc/generate.sh3
-rw-r--r--examples/example_audio.c152
-rw-r--r--examples/example_video.c345
-rw-r--r--include/kitchensink/internal/kitbuffer.h28
-rw-r--r--include/kitchensink/internal/kitlibstate.h14
-rw-r--r--include/kitchensink/internal/kitlist.h26
-rw-r--r--include/kitchensink/internal/kitringbuffer.h23
-rw-r--r--include/kitchensink/kitchensink.h11
-rw-r--r--include/kitchensink/kitconfig.h26
-rw-r--r--include/kitchensink/kiterror.h18
-rw-r--r--include/kitchensink/kitlib.h33
-rw-r--r--include/kitchensink/kitplayer.h128
-rw-r--r--include/kitchensink/kitsource.h47
-rw-r--r--include/kitchensink/kitutils.h18
-rw-r--r--src/kitbuffer.c83
-rw-r--r--src/kiterror.c34
-rw-r--r--src/kitlib.c51
-rw-r--r--src/kitlibstate.c7
-rw-r--r--src/kitlist.c79
-rw-r--r--src/kitplayer.c1498
-rw-r--r--src/kitringbuffer.c172
-rw-r--r--src/kitsource.c130
-rw-r--r--src/kitutils.c73
-rw-r--r--tests/CMakeLists.txt18
-rw-r--r--tests/data/CEP140_512kb.mp4bin0 -> 3628135 bytes
-rw-r--r--tests/test_lib.c28
-rw-r--r--tests/test_source.c48
-rw-r--r--travis/ffmpeg.sh12
-rw-r--r--travis/sdl2.sh13
40 files changed, 5576 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..673b0ca
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,40 @@
+# Object files
+*.o
+*.ko
+*.obj
+*.elf
+
+# Precompiled Headers
+*.gch
+*.pch
+
+# Libraries
+*.lib
+*.a
+*.la
+*.lo
+
+# Shared objects (inc. Windows DLLs)
+*.dll
+*.so
+*.so.*
+*.dylib
+
+# Executables
+*.exe
+*.out
+*.app
+*.i*86
+*.x86_64
+*.hex
+
+# Debug files
+*.dSYM/
+
+# VSCode
+.vscode
+
+# Other
+build/
+doc/doxygen_sqlite3.db
+doc/html
diff --git a/.travis.yml b/.travis.yml
new file mode 100644
index 0000000..89a45bf
--- /dev/null
+++ b/.travis.yml
@@ -0,0 +1,59 @@
+language: c
+
+sudo: false
+
+env:
+ global:
+ - secure: "p7KivdPu+pWYLI95Rmtu8FgOPWUq36TiXr9kH5rDyuqg2iz3DAt8unDYXWGfSn9p6OzfchBd2WsGMMvbvICfBNm+uOjrQwWwW6SBENLNyGDiGKQd4coAmUF247UXY+CslRQrSuciajrNSrBIPOL4EjvlMmV8N5kwDrFB8QktgxyLf35vbNAc8vkoUdFu7vUzt2MISIA1rrWcOUjDaM6vqovzosr/LzDwwjj3HX92ys2YZh2m1V7BOMLuNRLW7pou3ge4VmXdTVIyFcEEG1Nqk1apeX9ZEsw0IQ6xLfcOJbqg5CSIFrkGhdlM1L+u7ThBBa+EZU9EZr6qYnVvHMRU1xyCFEJvGMr9FhS9ZnzPxOxz0BG/qkDbtkQtPtkPobb/325b7/jpDNZFXj6/kErdLjsClP1jUnFmj3jkcOXYsGlz4Osl7tih4a52VLWhzL7Lz7XxmZ9KUOJPuofg2CT0eUa1w+OAtA/tB7molRo2AowmfuN+PvNcmE16cFtveFqAArnN0R7st91SkyGZNRTumDfb7rh9coAboFEZU7vKYnCk7Tt7Atp43HnqnX0ywvxqEmHY7yYQQE1Z/1Mw0+6JnHuEaFp0Q5aU/KJmGXae6v0HqvGqvr8mCjsm0LMAxtRb6tb5zbtGCKwEd3HaDA/i3B9xLDBebbIxjMBjDdvAn9Q="
+ - CMAKE_PREFIX_PATH=$HOME/local
+
+cache:
+ directories:
+ - $HOME/local
+
+compiler:
+ - gcc
+
+install:
+ - chmod +x ${TRAVIS_BUILD_DIR}/travis/sdl2.sh
+ - chmod +x ${TRAVIS_BUILD_DIR}/travis/ffmpeg.sh
+ - ${TRAVIS_BUILD_DIR}/travis/sdl2.sh
+ - ${TRAVIS_BUILD_DIR}/travis/ffmpeg.sh
+
+script: if [ "${COVERITY_SCAN_BRANCH}" != 1 ]; then cd $TRAVIS_BUILD_DIR && cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_COMPILER=/usr/bin/gcc-5 -DBUILD_EXAMPLES=On -DBUILD_TESTS=Off . && make; fi
+
+notifications:
+ email: false
+
+addons:
+ coverity_scan:
+ project:
+ name: "katajakasa/SDL_kitchensink"
+ description: "A Simple SDL2 / FFmpeg library for audio/video playback written in C99"
+ notification_email: katajakasa@gmail.com
+ build_command_prepend: "cov-configure --comptype gcc --compiler gcc-5 --template && cmake -DCMAKE_C_COMPILER=/usr/bin/gcc-5 -DCMAKE_BUILD_TYPE=Debug ."
+ build_command: "make"
+ branch_pattern: coverity_scan
+ apt:
+ sources:
+ - ubuntu-toolchain-r-test
+ - george-edison55-precise-backports
+ packages:
+ - libc6-dev
+ - yasm
+ - gcc-5
+ - gettext
+ - libcunit1
+ - libcunit1-dev
+ - libasound2-dev
+ - libpulse-dev
+ - libx11-dev
+ - libxext-dev
+ - libxrandr-dev
+ - libxi-dev
+ - libxxf86vm-dev
+ - libxss-dev
+ - libudev-dev
+ - cmake
+ - cmake-data
+ - libass-dev
diff --git a/CMakeLists.txt b/CMakeLists.txt
new file mode 100644
index 0000000..7ed58af
--- /dev/null
+++ b/CMakeLists.txt
@@ -0,0 +1,89 @@
+cmake_minimum_required(VERSION 3.0)
+project(SDL_kitchensink C)
+set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
+
+set(KIT_VERSION_MAJOR "0")
+set(KIT_VERSION_MINOR "0")
+set(KIT_VERSION_PATCH "7")
+set(KIT_VERSION ${KIT_VERSION_MAJOR}.${KIT_VERSION_MINOR}.${KIT_VERSION_PATCH})
+add_definitions(
+ -DKIT_VERSION_MAJOR=${KIT_VERSION_MAJOR}
+ -DKIT_VERSION_MINOR=${KIT_VERSION_MINOR}
+ -DKIT_VERSION_PATCH=${KIT_VERSION_PATCH}
+)
+
+set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -std=c99")
+set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -ggdb -pedantic -Werror -fno-omit-frame-pointer")
+set(CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO} -ggdb -O2 -fno-omit-frame-pointer -DNDEBUG")
+set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -O2 -DNDEBUG")
+set(CMAKE_C_FLAGS_MINSIZEREL "${CMAKE_C_FLAGS_MINSIZEREL} -Os -DNDEBUG")
+
+option(BUILD_EXAMPLES "Build examples" OFF)
+option(BUILD_TESTS "Build unittests" OFF)
+
+find_package(SDL2)
+find_package(ass)
+find_package(ffmpeg COMPONENTS avcodec avformat avutil swscale swresample)
+
+if(BUILD_TESTS)
+ add_subdirectory(tests)
+endif()
+
+include_directories(
+ include/
+ ${SDL2_INCLUDE_DIRS}
+ ${FFMPEG_INCLUDE_DIRS}
+ ${ASS_INCLUDE_DIRS}
+)
+
+FILE(GLOB SOURCES "src/*.c")
+FILE(GLOB HEADERS "include/kitchensink/*.h")
+
+add_library(SDL_kitchensink SHARED ${SOURCES})
+add_library(SDL_kitchensink_static STATIC ${SOURCES})
+
+set_target_properties(SDL_kitchensink PROPERTIES VERSION ${KIT_VERSION})
+set_target_properties(SDL_kitchensink PROPERTIES SOVERSION ${KIT_VERSION_MAJOR})
+set_target_properties(SDL_kitchensink PROPERTIES DEBUG_POSTFIX "d")
+set_target_properties(SDL_kitchensink_static PROPERTIES DEBUG_POSTFIX "d")
+target_compile_definitions(SDL_kitchensink PRIVATE "KIT_DLL;KIT_DLL_EXPORTS")
+target_compile_options(SDL_kitchensink PRIVATE "-fvisibility=hidden")
+
+target_link_libraries(SDL_kitchensink
+ ${SDL2_LIBRARIES}
+ ${FFMPEG_LIBRARIES}
+ ${ASS_LIBRARIES}
+)
+
+if(BUILD_EXAMPLES)
+ add_executable(exampleaudio examples/example_audio.c)
+ add_executable(examplevideo examples/example_video.c)
+
+ if(MINGW)
+ target_link_libraries(exampleaudio mingw32)
+ target_link_libraries(examplevideo mingw32)
+ endif()
+
+ target_link_libraries(exampleaudio
+ SDL_kitchensink_static
+ ${SDL2_LIBRARIES}
+ ${FFMPEG_LIBRARIES}
+ ${ASS_LIBRARIES}
+ )
+ target_link_libraries(examplevideo
+ SDL_kitchensink_static
+ ${SDL2_LIBRARIES}
+ ${FFMPEG_LIBRARIES}
+ ${ASS_LIBRARIES}
+ )
+endif()
+
+# Installation
+include(GNUInstallDirs)
+
+INSTALL(FILES ${HEADERS} DESTINATION include/kitchensink/)
+INSTALL(TARGETS SDL_kitchensink SDL_kitchensink_static
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+ ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
+)
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..bec844e
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,22 @@
+The MIT License (MIT)
+
+Copyright (c) 2016 Tuomas Virtanen
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
+
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..037626a
--- /dev/null
+++ b/README.md
@@ -0,0 +1,101 @@
+# SDL_kitchensink
+
+[![Build Status](https://travis-ci.org/katajakasa/SDL_kitchensink.svg?branch=master)](https://travis-ci.org/katajakasa/SDL_kitchensink)
+[![Coverity Scan Build Status](https://scan.coverity.com/projects/7585/badge.svg)](https://scan.coverity.com/projects/katajakasa-sdl_kitchensink)
+
+FFmpeg and SDL2 based library for audio and video playback, written in C99.
+
+This library is still very much todo, but it's slowly getting there.
+
+Features:
+* Decoding video & audio via FFmpeg
+* Dumping video data on SDL_textures
+* Dumping audio data in the usual mono/stereo interleaved formats
+* Automatic audio and video conversion to SDL2 friendly formats
+* Synchronizing video & audio to clock
+* Seeking forwards and backwards
+* Bitmap & libass subtitle support. No text (srt, sub) support yet.
+
+## 1. Library requirements
+
+Build requirements:
+* CMake (>=3.0)
+* GCC (C99 support required)
+
+Library requirements:
+* SDL2 (>=2.0.3) (Note! Examples require 2.0.4!)
+* FFmpeg (>=3.0)
+* libass
+* CUnit (optional, for unittests)
+
+Note that Clang might work, but is not tested. Older SDL2 and FFmpeg library versions
+may or may not work; versions noted here are the only ones tested.
+
+### 1.1. Debian / Ubuntu
+
+```
+sudo apt-get install libsdl2-dev libavcodec-dev libavdevice-dev libavfilter-dev \
+libavformat-dev libavresample-dev libavutil-dev libswresample-dev libswscale-dev \
+libpostproc-dev libass-dev
+```
+
+### 1.2. MSYS2 64bit
+
+These are for x86_64. For 32bit installation, just change the package names a bit .
+```
+pacman -S mingw-w64-x86_64-SDL2 mingw-w64-x86_64-ffmpeg mingw-w64-x86_64-libass
+```
+
+## 2. Compiling
+
+By default, both static and dynamic libraries are built.
+* Dynamic library is called libSDL_kitchensink.dll or .so
+* Static library is called libSDL_kitchensink_static.a
+* If you build in debug mode (```-DCMAKE_BUILD_TYPE=Debug```), libraries will be postfixed with 'd'.
+
+Change CMAKE_INSTALL_PREFIX as necessary to change the installation path. The files will be installed to
+* CMAKE_INSTALL_PREFIX/lib for libraries (.dll.a, .a, etc.)
+* CMAKE_INSTALL_PREFIX/bin for binaries (.dll, .so)
+* CMAKE_INSTALL_PREFIX/include for headers
+
+### 2.1. Building the libraries on Debian/Ubuntu
+
+1. ```mkdir build && cd build```
+2. ```cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr/local ..```
+3. ```make -j```
+4. ```sudo make install```
+
+### 2.2. Building the libraries on MSYS2
+
+1. ```mkdir build && cd build```
+2. ```cmake -G "MSYS Makefiles" -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr/local ..```
+3. ```make```
+4. ```make install```
+
+### 2.3. Building examples
+
+Just add ```-DBUILD_EXAMPLES=1``` to cmake arguments and rebuild.
+
+### 2.4. Building unittests
+
+Make sure CUnit is installed, then add ```-DBUILD_UNITTESTS=1``` to the cmake arguments and rebuild.
+
+You can run unittests by running ```make unittest```.
+
+## 3. License
+
+MIT. Please see ```LICENSE``` for details.
+
+Note that FFmpeg has a rather complex license. Please take a look at [FFmpeg Legal page](http://ffmpeg.org/legal.html)
+for details.
+
+## 4. Why SDL_kitchensink
+
+Because pulling major blob of library code like ffmpeg feels like bringing in a whole house with its
+kitchensink and everything to the project. Also, it sounded funny. Also, SDL_ffmpeg is already reserved :(
+
+## 5. Examples
+
+Please see examples directory. You can also take a look at unittests for some help.
+Note that examples are NOT meant for any kind of real life use; they are only meant to
+show simple use cases for the library.
diff --git a/cmake/FindSDL2.cmake b/cmake/FindSDL2.cmake
new file mode 100644
index 0000000..8102832
--- /dev/null
+++ b/cmake/FindSDL2.cmake
@@ -0,0 +1,54 @@
+# A Simple SDL2 Finder.
+# (c) Tuomas Virtanen 2016 (Licensed under MIT license)
+# Usage:
+# find_package(SDL2)
+#
+# Declares:
+# * SDL2_FOUND
+# * SDL2_INCLUDE_DIRS
+# * SDL2_LIBRARIES
+#
+
+set(SDL2_SEARCH_PATHS
+ /usr/local/
+ /usr/
+ /opt
+)
+
+find_path(SDL2_INCLUDE_DIR SDL2/SDL.h
+ HINTS
+ PATH_SUFFIXES include
+ PATHS ${SDL2_SEARCH_PATHS}
+)
+
+find_library(SDL2_LIBRARY
+ NAMES SDL2
+ HINTS
+ PATH_SUFFIXES lib
+ PATHS ${SDL2_SEARCH_PATHS}
+)
+
+if(MINGW)
+ find_library(SDL2MAIN_LIBRARY
+ NAMES SDL2main
+ HINTS
+ PATH_SUFFIXES lib
+ PATHS ${SDL2_SEARCH_PATHS}
+ )
+else()
+ set(SDL2MAIN_LIBRARY "")
+endif()
+
+if(SDL2_INCLUDE_DIR AND SDL2_LIBRARY)
+ set(SDL2_FOUND TRUE)
+endif()
+
+if(SDL2_FOUND)
+ set(SDL2_LIBRARIES ${SDL2MAIN_LIBRARY} ${SDL2_LIBRARY})
+ set(SDL2_INCLUDE_DIRS ${SDL2_INCLUDE_DIR})
+ message(STATUS "Found SDL2: ${SDL2_LIBRARIES}")
+else()
+ message(WARNING "Could not find SDL2")
+endif()
+
+mark_as_advanced(SDL2MAIN_LIBRARY SDL2_LIBRARY SDL2_INCLUDE_DIR SDL2_SEARCH_PATHS)
diff --git a/cmake/Findass.cmake b/cmake/Findass.cmake
new file mode 100644
index 0000000..bbc88d5
--- /dev/null
+++ b/cmake/Findass.cmake
@@ -0,0 +1,43 @@
+# A Simple libass Finder.
+# (c) Tuomas Virtanen 2016 (Licensed under MIT license)
+# Usage:
+# find_package(ass)
+#
+# Declares:
+# * ASS_FOUND
+# * ASS_INCLUDE_DIRS
+# * ASS_LIBRARIES
+#
+
+set(ASS_SEARCH_PATHS
+ /usr/local/
+ /usr/
+ /opt
+)
+
+find_path(ASS_INCLUDE_DIR ass/ass.h
+ HINTS
+ PATH_SUFFIXES include
+ PATHS ${ASS_SEARCH_PATHS}
+)
+
+find_library(ASS_LIBRARY
+ NAMES ass
+ HINTS
+ PATH_SUFFIXES lib
+ PATHS ${ASS_SEARCH_PATHS}
+)
+
+if(ASS_INCLUDE_DIR AND ASS_LIBRARY)
+ set(ASS_FOUND TRUE)
+endif()
+
+if(ASS_FOUND)
+ set(ASS_LIBRARIES ${ASS_LIBRARY})
+ set(ASS_INCLUDE_DIRS ${ASS_INCLUDE_DIR})
+ message(STATUS "Found libass: ${ASS_LIBRARIES}")
+else()
+ message(WARNING "Could not find libass")
+endif()
+
+mark_as_advanced(ASS_LIBRARY ASS_INCLUDE_DIR ASS_SEARCH_PATHS)
diff --git a/cmake/Findcunit.cmake b/cmake/Findcunit.cmake
new file mode 100644
index 0000000..ae81cf1
--- /dev/null
+++ b/cmake/Findcunit.cmake
@@ -0,0 +1,41 @@
+# A Simple CUnit Finder.
+# (c) Tuomas Virtanen 2016 (Licensed under MIT license)
+# Usage:
+# find_package(cunit)
+#
+# Declares:
+# * CUNIT_FOUND
+# * CUNIT_INCLUDE_DIRS
+# * CUNIT_LIBRARIES
+#
+
+set(CUNIT_SEARCH_PATHS
+ /usr/local/
+ /usr
+ /opt
+)
+
+find_path(CUNIT_INCLUDE_DIR CUnit/CUnit.h
+ HINTS
+ PATH_SUFFIXES include
+ PATHS ${CUNIT_SEARCH_PATHS}
+)
+find_library(CUNIT_LIBRARY cunit
+ HINTS
+ PATH_SUFFIXES lib
+ PATHS ${CUNIT_SEARCH_PATHS}
+)
+
+if(CUNIT_INCLUDE_DIR AND CUNIT_LIBRARY)
+ set(CUNIT_FOUND TRUE)
+endif()
+
+if(CUNIT_FOUND)
+ set(CUNIT_LIBRARIES ${CUNIT_LIBRARY})
+ set(CUNIT_INCLUDE_DIRS ${CUNIT_INCLUDE_DIR})
+ message(STATUS "Found CUnit: ${CUNIT_LIBRARY}")
+else()
+ message(WARNING "Could not find CUnit.")
+endif()
+
+mark_as_advanced(CUNIT_LIBRARY CUNIT_INCLUDE_DIR)
diff --git a/cmake/Findffmpeg.cmake b/cmake/Findffmpeg.cmake
new file mode 100644
index 0000000..fdb6246
--- /dev/null
+++ b/cmake/Findffmpeg.cmake
@@ -0,0 +1,74 @@
+# A Simple FFMPEG Finder.
+# (c) Tuomas Virtanen 2016 (Licensed under MIT license)
+# Usage:
+# find_package(ffmpeg COMPONENTS avcodec avutil ...)
+#
+# Declares:
+# * FFMPEG_FOUND
+# * FFMPEG_INCLUDE_DIRS
+# * FFMPEG_LIBRARIES
+#
+# Also declares ${component}_FOUND for each component, eg. avcodec_FOUND etc.
+#
+
+set(FFMPEG_SEARCH_PATHS
+ /usr/local
+ /usr
+ /opt
+)
+
+set(FFMPEG_COMPONENTS
+ avcodec
+ avformat
+ avdevice
+ avfilter
+ avresample
+ avutil
+ swresample
+ swscale
+)
+
+set(FFMPEG_INCLUDE_DIRS)
+set(FFMPEG_LIBRARIES)
+set(FFMPEG_FOUND TRUE)
+
+# Walk through all components declared above, and try to find the ones that have been asked
+foreach(comp ${FFMPEG_COMPONENTS})
+ list(FIND ffmpeg_FIND_COMPONENTS ${comp} _index)
+ if(${_index} GREATER -1)
+ # Component requested, try to look up the library and header for it.
+ find_path(${comp}_INCLUDE_DIR lib${comp}/${comp}.h
+ HINTS
+ PATH_SUFFIXES include
+ PATHS ${FFMPEG_SEARCH_PATHS}
+ )
+ find_library(${comp}_LIBRARY ${comp}
+ HINTS
+ PATH_SUFFIXES lib
+ PATHS ${FFMPEG_SEARCH_PATHS}
+ )
+
+ # If library and header was found, set proper variables
+ # Otherwise print out a warning!
+ if(${comp}_LIBRARY AND ${comp}_INCLUDE_DIR)
+ set(${comp}_FOUND TRUE)
+ list(APPEND FFMPEG_INCLUDE_DIRS ${${comp}_INCLUDE_DIR})
+ list(APPEND FFMPEG_LIBRARIES ${${comp}_LIBRARY})
+ else()
+ set(FFMPEG_FOUND FALSE)
+ set(${comp}_FOUND FALSE)
+ message(WARNING "Could not find component: ${comp}")
+ endif()
+
+ # Mark the temporary variables as hidden in the ui
+ mark_as_advanced(${${comp}_LIBRARY} ${${comp}_INCLUDE_DIR})
+ endif()
+endforeach()
+
+if(FFMPEG_FOUND)
+ message(STATUS "Found FFMPEG: ${FFMPEG_LIBRARIES}")
+else()
+ message(WARNING "Could not find FFMPEG")
+endif()
+
+mark_as_advanced(FFMPEG_COMPONENTS FFMPEG_SEARCH_PATHS)
diff --git a/doc/Doxyfile b/doc/Doxyfile
new file mode 100644
index 0000000..7bb5ca0
--- /dev/null
+++ b/doc/Doxyfile
@@ -0,0 +1,1892 @@
+# Doxyfile 1.8.3.1
+
+#---------------------------------------------------------------------------
+# Project related configuration options
+#---------------------------------------------------------------------------
+
+# This tag specifies the encoding used for all characters in the config file
+# that follow. The default is UTF-8 which is also the encoding used for all
+# text before the first occurrence of this tag. Doxygen uses libiconv (or the
+# iconv built into libc) for the transcoding. See
+# http://www.gnu.org/software/libiconv for the list of possible encodings.
+
+DOXYFILE_ENCODING = UTF-8
+
+# The PROJECT_NAME tag is a single word (or sequence of words) that should
+# identify the project. Note that if you do not use Doxywizard you need
+# to put quotes around the project name if it contains spaces.
+
+PROJECT_NAME = SDL_kitchensink
+
+# The PROJECT_NUMBER tag can be used to enter a project or revision number.
+# This could be handy for archiving the generated documentation or
+# if some version control system is used.
+
+PROJECT_NUMBER =
+
+# Using the PROJECT_BRIEF tag one can provide an optional one line description
+# for a project that appears at the top of each page and should give viewer
+# a quick idea about the purpose of the project. Keep the description short.
+
+PROJECT_BRIEF = "A Simple SDL2 / FFmpeg library for audio/video playback written in C99"
+
+# With the PROJECT_LOGO tag one can specify an logo or icon that is
+# included in the documentation. The maximum height of the logo should not
+# exceed 55 pixels and the maximum width should not exceed 200 pixels.
+# Doxygen will copy the logo to the output directory.
+
+PROJECT_LOGO =
+
+# The OUTPUT_DIRECTORY tag is used to specify the (relative or absolute)
+# base path where the generated documentation will be put.
+# If a relative path is entered, it will be relative to the location
+# where doxygen was started. If left blank the current directory will be used.
+
+OUTPUT_DIRECTORY = .
+
+# If the CREATE_SUBDIRS tag is set to YES, then doxygen will create
+# 4096 sub-directories (in 2 levels) under the output directory of each output
+# format and will distribute the generated files over these directories.
+# Enabling this option can be useful when feeding doxygen a huge amount of
+# source files, where putting all generated files in the same directory would
+# otherwise cause performance problems for the file system.
+
+CREATE_SUBDIRS = NO
+
+# The OUTPUT_LANGUAGE tag is used to specify the language in which all
+# documentation generated by doxygen is written. Doxygen will use this
+# information to generate all constant output in the proper language.
+# The default language is English, other supported languages are:
+# Afrikaans, Arabic, Brazilian, Catalan, Chinese, Chinese-Traditional,
+# Croatian, Czech, Danish, Dutch, Esperanto, Farsi, Finnish, French, German,
+# Greek, Hungarian, Italian, Japanese, Japanese-en (Japanese with English
+# messages), Korean, Korean-en, Lithuanian, Norwegian, Macedonian, Persian,
+# Polish, Portuguese, Romanian, Russian, Serbian, Serbian-Cyrillic, Slovak,
+# Slovene, Spanish, Swedish, Ukrainian, and Vietnamese.
+
+OUTPUT_LANGUAGE = English
+
+# If the BRIEF_MEMBER_DESC tag is set to YES (the default) Doxygen will
+# include brief member descriptions after the members that are listed in
+# the file and class documentation (similar to JavaDoc).
+# Set to NO to disable this.
+
+BRIEF_MEMBER_DESC = YES
+
+# If the REPEAT_BRIEF tag is set to YES (the default) Doxygen will prepend
+# the brief description of a member or function before the detailed description.
+# Note: if both HIDE_UNDOC_MEMBERS and BRIEF_MEMBER_DESC are set to NO, the
+# brief descriptions will be completely suppressed.
+
+REPEAT_BRIEF = YES
+
+# This tag implements a quasi-intelligent brief description abbreviator
+# that is used to form the text in various listings. Each string
+# in this list, if found as the leading text of the brief description, will be
+# stripped from the text and the result after processing the whole list, is
+# used as the annotated text. Otherwise, the brief description is used as-is.
+# If left blank, the following values are used ("$name" is automatically
+# replaced with the name of the entity): "The $name class" "The $name widget"
+# "The $name file" "is" "provides" "specifies" "contains"
+# "represents" "a" "an" "the"
+
+ABBREVIATE_BRIEF = "The $name class" \
+ "The $name widget" \
+ "The $name file" \
+ is \
+ provides \
+ specifies \
+ contains \
+ represents \
+ a \
+ an \
+ the
+
+# If the ALWAYS_DETAILED_SEC and REPEAT_BRIEF tags are both set to YES then
+# Doxygen will generate a detailed section even if there is only a brief
+# description.
+
+ALWAYS_DETAILED_SEC = NO
+
+# If the INLINE_INHERITED_MEMB tag is set to YES, doxygen will show all
+# inherited members of a class in the documentation of that class as if those
+# members were ordinary class members. Constructors, destructors and assignment
+# operators of the base classes will not be shown.
+
+INLINE_INHERITED_MEMB = NO
+
+# If the FULL_PATH_NAMES tag is set to YES then Doxygen will prepend the full
+# path before files name in the file list and in the header files. If set
+# to NO the shortest path that makes the file name unique will be used.
+
+FULL_PATH_NAMES = YES
+
+# If the FULL_PATH_NAMES tag is set to YES then the STRIP_FROM_PATH tag
+# can be used to strip a user-defined part of the path. Stripping is
+# only done if one of the specified strings matches the left-hand part of
+# the path. The tag can be used to show relative paths in the file list.
+# If left blank the directory from which doxygen is run is used as the
+# path to strip. Note that you specify absolute paths here, but also
+# relative paths, which will be relative from the directory where doxygen is
+# started.
+
+STRIP_FROM_PATH = ../..
+
+# The STRIP_FROM_INC_PATH tag can be used to strip a user-defined part of
+# the path mentioned in the documentation of a class, which tells
+# the reader which header file to include in order to use a class.
+# If left blank only the name of the header file containing the class
+# definition is used. Otherwise one should specify the include paths that
+# are normally passed to the compiler using the -I flag.
+
+STRIP_FROM_INC_PATH =
+
+# If the SHORT_NAMES tag is set to YES, doxygen will generate much shorter
+# (but less readable) file names. This can be useful if your file system
+# doesn't support long names like on DOS, Mac, or CD-ROM.
+
+SHORT_NAMES = NO
+
+# If the JAVADOC_AUTOBRIEF tag is set to YES then Doxygen
+# will interpret the first line (until the first dot) of a JavaDoc-style
+# comment as the brief description. If set to NO, the JavaDoc
+# comments will behave just like regular Qt-style comments
+# (thus requiring an explicit @brief command for a brief description.)
+
+JAVADOC_AUTOBRIEF = NO
+
+# If the QT_AUTOBRIEF tag is set to YES then Doxygen will
+# interpret the first line (until the first dot) of a Qt-style
+# comment as the brief description. If set to NO, the comments
+# will behave just like regular Qt-style comments (thus requiring
+# an explicit \brief command for a brief description.)
+
+QT_AUTOBRIEF = NO
+
+# The MULTILINE_CPP_IS_BRIEF tag can be set to YES to make Doxygen
+# treat a multi-line C++ special comment block (i.e. a block of //! or ///
+# comments) as a brief description. This used to be the default behaviour.
+# The new default is to treat a multi-line C++ comment block as a detailed
+# description. Set this tag to YES if you prefer the old behaviour instead.
+
+MULTILINE_CPP_IS_BRIEF = NO
+
+# If the INHERIT_DOCS tag is set to YES (the default) then an undocumented
+# member inherits the documentation from any documented member that it
+# re-implements.
+
+INHERIT_DOCS = YES
+
+# If the SEPARATE_MEMBER_PAGES tag is set to YES, then doxygen will produce
+# a new page for each member. If set to NO, the documentation of a member will
+# be part of the file/class/namespace that contains it.
+
+SEPARATE_MEMBER_PAGES = NO
+
+# The TAB_SIZE tag can be used to set the number of spaces in a tab.
+# Doxygen uses this value to replace tabs by spaces in code fragments.
+
+TAB_SIZE = 4
+
+# This tag can be used to specify a number of aliases that acts
+# as commands in the documentation. An alias has the form "name=value".
+# For example adding "sideeffect=\par Side Effects:\n" will allow you to
+# put the command \sideeffect (or @sideeffect) in the documentation, which
+# will result in a user-defined paragraph with heading "Side Effects:".
+# You can put \n's in the value part of an alias to insert newlines.
+
+ALIASES =
+
+# This tag can be used to specify a number of word-keyword mappings (TCL only).
+# A mapping has the form "name=value". For example adding
+# "class=itcl::class" will allow you to use the command class in the
+# itcl::class meaning.
+
+TCL_SUBST =
+
+# Set the OPTIMIZE_OUTPUT_FOR_C tag to YES if your project consists of C
+# sources only. Doxygen will then generate output that is more tailored for C.
+# For instance, some of the names that are used will be different. The list
+# of all members will be omitted, etc.
+
+OPTIMIZE_OUTPUT_FOR_C = YES
+
+# Set the OPTIMIZE_OUTPUT_JAVA tag to YES if your project consists of Java
+# sources only. Doxygen will then generate output that is more tailored for
+# Java. For instance, namespaces will be presented as packages, qualified
+# scopes will look different, etc.
+
+OPTIMIZE_OUTPUT_JAVA = NO
+
+# Set the OPTIMIZE_FOR_FORTRAN tag to YES if your project consists of Fortran
+# sources only. Doxygen will then generate output that is more tailored for
+# Fortran.
+
+OPTIMIZE_FOR_FORTRAN = NO
+
+# Set the OPTIMIZE_OUTPUT_VHDL tag to YES if your project consists of VHDL
+# sources. Doxygen will then generate output that is tailored for
+# VHDL.
+
+OPTIMIZE_OUTPUT_VHDL = NO
+
+# Doxygen selects the parser to use depending on the extension of the files it
+# parses. With this tag you can assign which parser to use for a given
+# extension. Doxygen has a built-in mapping, but you can override or extend it
+# using this tag. The format is ext=language, where ext is a file extension,
+# and language is one of the parsers supported by doxygen: IDL, Java,
+# Javascript, CSharp, C, C++, D, PHP, Objective-C, Python, Fortran, VHDL, C,
+# C++. For instance to make doxygen treat .inc files as Fortran files (default
+# is PHP), and .f files as C (default is Fortran), use: inc=Fortran f=C. Note
+# that for custom extensions you also need to set FILE_PATTERNS otherwise the
+# files are not read by doxygen.
+
+EXTENSION_MAPPING =
+
+# If MARKDOWN_SUPPORT is enabled (the default) then doxygen pre-processes all
+# comments according to the Markdown format, which allows for more readable
+# documentation. See http://daringfireball.net/projects/markdown/ for details.
+# The output of markdown processing is further processed by doxygen, so you
+# can mix doxygen, HTML, and XML commands with Markdown formatting.
+# Disable only in case of backward compatibilities issues.
+
+MARKDOWN_SUPPORT = YES
+
+# When enabled doxygen tries to link words that correspond to documented classes,
+# or namespaces to their corresponding documentation. Such a link can be
+# prevented in individual cases by by putting a % sign in front of the word or
+# globally by setting AUTOLINK_SUPPORT to NO.
+
+AUTOLINK_SUPPORT = YES
+
+# If you use STL classes (i.e. std::string, std::vector, etc.) but do not want
+# to include (a tag file for) the STL sources as input, then you should
+# set this tag to YES in order to let doxygen match functions declarations and
+# definitions whose arguments contain STL classes (e.g. func(std::string); v.s.
+# func(std::string) {}). This also makes the inheritance and collaboration
+# diagrams that involve STL classes more complete and accurate.
+
+BUILTIN_STL_SUPPORT = NO
+
+# If you use Microsoft's C++/CLI language, you should set this option to YES to
+# enable parsing support.
+
+CPP_CLI_SUPPORT = NO
+
+# Set the SIP_SUPPORT tag to YES if your project consists of sip sources only.
+# Doxygen will parse them like normal C++ but will assume all classes use public
+# instead of private inheritance when no explicit protection keyword is present.
+
+SIP_SUPPORT = NO
+
+# For Microsoft's IDL there are propget and propput attributes to indicate
+# getter and setter methods for a property. Setting this option to YES (the
+# default) will make doxygen replace the get and set methods by a property in
+# the documentation. This will only work if the methods are indeed getting or
+# setting a simple type. If this is not the case, or you want to show the
+# methods anyway, you should set this option to NO.
+
+IDL_PROPERTY_SUPPORT = YES
+
+# If member grouping is used in the documentation and the DISTRIBUTE_GROUP_DOC
+# tag is set to YES, then doxygen will reuse the documentation of the first
+# member in the group (if any) for the other members of the group. By default
+# all members of a group must be documented explicitly.
+
+DISTRIBUTE_GROUP_DOC = NO
+
+# Set the SUBGROUPING tag to YES (the default) to allow class member groups of
+# the same type (for instance a group of public functions) to be put as a
+# subgroup of that type (e.g. under the Public Functions section). Set it to
+# NO to prevent subgrouping. Alternatively, this can be done per class using
+# the \nosubgrouping command.
+
+SUBGROUPING = YES
+
+# When the INLINE_GROUPED_CLASSES tag is set to YES, classes, structs and
+# unions are shown inside the group in which they are included (e.g. using
+# @ingroup) instead of on a separate page (for HTML and Man pages) or
+# section (for LaTeX and RTF).
+
+INLINE_GROUPED_CLASSES = NO
+
+# When the INLINE_SIMPLE_STRUCTS tag is set to YES, structs, classes, and
+# unions with only public data fields will be shown inline in the documentation
+# of the scope in which they are defined (i.e. file, namespace, or group
+# documentation), provided this scope is documented. If set to NO (the default),
+# structs, classes, and unions are shown on a separate page (for HTML and Man
+# pages) or section (for LaTeX and RTF).
+
+INLINE_SIMPLE_STRUCTS = NO
+
+# When TYPEDEF_HIDES_STRUCT is enabled, a typedef of a struct, union, or enum
+# is documented as struct, union, or enum with the name of the typedef. So
+# typedef struct TypeS {} TypeT, will appear in the documentation as a struct
+# with name TypeT. When disabled the typedef will appear as a member of a file,
+# namespace, or class. And the struct will be named TypeS. This can typically
+# be useful for C code in case the coding convention dictates that all compound
+# types are typedef'ed and only the typedef is referenced, never the tag name.
+
+TYPEDEF_HIDES_STRUCT = NO
+
+# The SYMBOL_CACHE_SIZE determines the size of the internal cache use to
+# determine which symbols to keep in memory and which to flush to disk.
+# When the cache is full, less often used symbols will be written to disk.
+# For small to medium size projects (<1000 input files) the default value is
+# probably good enough. For larger projects a too small cache size can cause
+# doxygen to be busy swapping symbols to and from disk most of the time
+# causing a significant performance penalty.
+# If the system has enough physical memory increasing the cache will improve the
+# performance by keeping more symbols in memory. Note that the value works on
+# a logarithmic scale so increasing the size by one will roughly double the
+# memory usage. The cache size is given by this formula:
+# 2^(16+SYMBOL_CACHE_SIZE). The valid range is 0..9, the default is 0,
+# corresponding to a cache size of 2^16 = 65536 symbols.
+
+SYMBOL_CACHE_SIZE = 0
+
+# Similar to the SYMBOL_CACHE_SIZE the size of the symbol lookup cache can be
+# set using LOOKUP_CACHE_SIZE. This cache is used to resolve symbols given
+# their name and scope. Since this can be an expensive process and often the
+# same symbol appear multiple times in the code, doxygen keeps a cache of
+# pre-resolved symbols. If the cache is too small doxygen will become slower.
+# If the cache is too large, memory is wasted. The cache size is given by this
+# formula: 2^(16+LOOKUP_CACHE_SIZE). The valid range is 0..9, the default is 0,
+# corresponding to a cache size of 2^16 = 65536 symbols.
+
+LOOKUP_CACHE_SIZE = 0
+
+#---------------------------------------------------------------------------
+# Build related configuration options
+#---------------------------------------------------------------------------
+
+# If the EXTRACT_ALL tag is set to YES doxygen will assume all entities in
+# documentation are documented, even if no documentation was available.
+# Private class members and static file members will be hidden unless
+# the EXTRACT_PRIVATE and EXTRACT_STATIC tags are set to YES
+
+EXTRACT_ALL = NO
+
+# If the EXTRACT_PRIVATE tag is set to YES all private members of a class
+# will be included in the documentation.
+
+EXTRACT_PRIVATE = NO
+
+# If the EXTRACT_PACKAGE tag is set to YES all members with package or internal
+# scope will be included in the documentation.
+
+EXTRACT_PACKAGE = NO
+
+# If the EXTRACT_STATIC tag is set to YES all static members of a file
+# will be included in the documentation.
+
+EXTRACT_STATIC = NO
+
+# If the EXTRACT_LOCAL_CLASSES tag is set to YES classes (and structs)
+# defined locally in source files will be included in the documentation.
+# If set to NO only classes defined in header files are included.
+
+EXTRACT_LOCAL_CLASSES = YES
+
+# This flag is only useful for Objective-C code. When set to YES local
+# methods, which are defined in the implementation section but not in
+# the interface are included in the documentation.
+# If set to NO (the default) only methods in the interface are included.
+
+EXTRACT_LOCAL_METHODS = NO
+
+# If this flag is set to YES, the members of anonymous namespaces will be
+# extracted and appear in the documentation as a namespace called
+# 'anonymous_namespace{file}', where file will be replaced with the base
+# name of the file that contains the anonymous namespace. By default
+# anonymous namespaces are hidden.
+
+EXTRACT_ANON_NSPACES = NO
+
+# If the HIDE_UNDOC_MEMBERS tag is set to YES, Doxygen will hide all
+# undocumented members of documented classes, files or namespaces.
+# If set to NO (the default) these members will be included in the
+# various overviews, but no documentation section is generated.
+# This option has no effect if EXTRACT_ALL is enabled.
+
+HIDE_UNDOC_MEMBERS = NO
+
+# If the HIDE_UNDOC_CLASSES tag is set to YES, Doxygen will hide all
+# undocumented classes that are normally visible in the class hierarchy.
+# If set to NO (the default) these classes will be included in the various
+# overviews. This option has no effect if EXTRACT_ALL is enabled.
+
+HIDE_UNDOC_CLASSES = NO
+
+# If the HIDE_FRIEND_COMPOUNDS tag is set to YES, Doxygen will hide all
+# friend (class|struct|union) declarations.
+# If set to NO (the default) these declarations will be included in the
+# documentation.
+
+HIDE_FRIEND_COMPOUNDS = NO
+
+# If the HIDE_IN_BODY_DOCS tag is set to YES, Doxygen will hide any
+# documentation blocks found inside the body of a function.
+# If set to NO (the default) these blocks will be appended to the
+# function's detailed documentation block.
+
+HIDE_IN_BODY_DOCS = NO
+
+# The INTERNAL_DOCS tag determines if documentation
+# that is typed after a \internal command is included. If the tag is set
+# to NO (the default) then the documentation will be excluded.
+# Set it to YES to include the internal documentation.
+
+INTERNAL_DOCS = NO
+
+# If the CASE_SENSE_NAMES tag is set to NO then Doxygen will only generate
+# file names in lower-case letters. If set to YES upper-case letters are also
+# allowed. This is useful if you have classes or files whose names only differ
+# in case and if your file system supports case sensitive file names. Windows
+# and Mac users are advised to set this option to NO.
+
+CASE_SENSE_NAMES = NO
+
+# If the HIDE_SCOPE_NAMES tag is set to NO (the default) then Doxygen
+# will show members with their full class and namespace scopes in the
+# documentation. If set to YES the scope will be hidden.
+
+HIDE_SCOPE_NAMES = YES
+
+# If the SHOW_INCLUDE_FILES tag is set to YES (the default) then Doxygen
+# will put a list of the files that are included by a file in the documentation
+# of that file.
+
+SHOW_INCLUDE_FILES = YES
+
+# If the FORCE_LOCAL_INCLUDES tag is set to YES then Doxygen
+# will list include files with double quotes in the documentation
+# rather than with sharp brackets.
+
+FORCE_LOCAL_INCLUDES = NO
+
+# If the INLINE_INFO tag is set to YES (the default) then a tag [inline]
+# is inserted in the documentation for inline members.
+
+INLINE_INFO = YES
+
+# If the SORT_MEMBER_DOCS tag is set to YES (the default) then doxygen
+# will sort the (detailed) documentation of file and class members
+# alphabetically by member name. If set to NO the members will appear in
+# declaration order.
+
+SORT_MEMBER_DOCS = YES
+
+# If the SORT_BRIEF_DOCS tag is set to YES then doxygen will sort the
+# brief documentation of file, namespace and class members alphabetically
+# by member name. If set to NO (the default) the members will appear in
+# declaration order.
+
+SORT_BRIEF_DOCS = NO
+
+# If the SORT_MEMBERS_CTORS_1ST tag is set to YES then doxygen
+# will sort the (brief and detailed) documentation of class members so that
+# constructors and destructors are listed first. If set to NO (the default)
+# the constructors will appear in the respective orders defined by
+# SORT_MEMBER_DOCS and SORT_BRIEF_DOCS.
+# This tag will be ignored for brief docs if SORT_BRIEF_DOCS is set to NO
+# and ignored for detailed docs if SORT_MEMBER_DOCS is set to NO.
+
+SORT_MEMBERS_CTORS_1ST = NO
+
+# If the SORT_GROUP_NAMES tag is set to YES then doxygen will sort the
+# hierarchy of group names into alphabetical order. If set to NO (the default)
+# the group names will appear in their defined order.
+
+SORT_GROUP_NAMES = NO
+
+# If the SORT_BY_SCOPE_NAME tag is set to YES, the class list will be
+# sorted by fully-qualified names, including namespaces. If set to
+# NO (the default), the class list will be sorted only by class name,
+# not including the namespace part.
+# Note: This option is not very useful if HIDE_SCOPE_NAMES is set to YES.
+# Note: This option applies only to the class list, not to the
+# alphabetical list.
+
+SORT_BY_SCOPE_NAME = NO
+
+# If the STRICT_PROTO_MATCHING option is enabled and doxygen fails to
+# do proper type resolution of all parameters of a function it will reject a
+# match between the prototype and the implementation of a member function even
+# if there is only one candidate or it is obvious which candidate to choose
+# by doing a simple string match. By disabling STRICT_PROTO_MATCHING doxygen
+# will still accept a match between prototype and implementation in such cases.
+
+STRICT_PROTO_MATCHING = NO
+
+# The GENERATE_TODOLIST tag can be used to enable (YES) or
+# disable (NO) the todo list. This list is created by putting \todo
+# commands in the documentation.
+
+GENERATE_TODOLIST = YES
+
+# The GENERATE_TESTLIST tag can be used to enable (YES) or
+# disable (NO) the test list. This list is created by putting \test
+# commands in the documentation.
+
+GENERATE_TESTLIST = YES
+
+# The GENERATE_BUGLIST tag can be used to enable (YES) or
+# disable (NO) the bug list. This list is created by putting \bug
+# commands in the documentation.
+
+GENERATE_BUGLIST = YES
+
+# The GENERATE_DEPRECATEDLIST tag can be used to enable (YES) or
+# disable (NO) the deprecated list. This list is created by putting
+# \deprecated commands in the documentation.
+
+GENERATE_DEPRECATEDLIST= YES
+
+# The ENABLED_SECTIONS tag can be used to enable conditional
+# documentation sections, marked by \if section-label ... \endif
+# and \cond section-label ... \endcond blocks.
+
+ENABLED_SECTIONS =
+
+# The MAX_INITIALIZER_LINES tag determines the maximum number of lines
+# the initial value of a variable or macro consists of for it to appear in
+# the documentation. If the initializer consists of more lines than specified
+# here it will be hidden. Use a value of 0 to hide initializers completely.
+# The appearance of the initializer of individual variables and macros in the
+# documentation can be controlled using \showinitializer or \hideinitializer
+# command in the documentation regardless of this setting.
+
+MAX_INITIALIZER_LINES = 30
+
+# Set the SHOW_USED_FILES tag to NO to disable the list of files generated
+# at the bottom of the documentation of classes and structs. If set to YES the
+# list will mention the files that were used to generate the documentation.
+
+SHOW_USED_FILES = YES
+
+# Set the SHOW_FILES tag to NO to disable the generation of the Files page.
+# This will remove the Files entry from the Quick Index and from the
+# Folder Tree View (if specified). The default is YES.
+
+SHOW_FILES = YES
+
+# Set the SHOW_NAMESPACES tag to NO to disable the generation of the
+# Namespaces page. This will remove the Namespaces entry from the Quick Index
+# and from the Folder Tree View (if specified). The default is YES.
+
+SHOW_NAMESPACES = YES
+
+# The FILE_VERSION_FILTER tag can be used to specify a program or script that
+# doxygen should invoke to get the current version for each file (typically from
+# the version control system). Doxygen will invoke the program by executing (via
+# popen()) the command <command> <input-file>, where <command> is the value of
+# the FILE_VERSION_FILTER tag, and <input-file> is the name of an input file
+# provided by doxygen. Whatever the program writes to standard output
+# is used as the file version. See the manual for examples.
+
+FILE_VERSION_FILTER =
+
+# The LAYOUT_FILE tag can be used to specify a layout file which will be parsed
+# by doxygen. The layout file controls the global structure of the generated
+# output files in an output format independent way. To create the layout file
+# that represents doxygen's defaults, run doxygen with the -l option.
+# You can optionally specify a file name after the option, if omitted
+# DoxygenLayout.xml will be used as the name of the layout file.
+
+LAYOUT_FILE =
+
+# The CITE_BIB_FILES tag can be used to specify one or more bib files
+# containing the references data. This must be a list of .bib files. The
+# .bib extension is automatically appended if omitted. Using this command
+# requires the bibtex tool to be installed. See also
+# http://en.wikipedia.org/wiki/BibTeX for more info. For LaTeX the style
+# of the bibliography can be controlled using LATEX_BIB_STYLE. To use this
+# feature you need bibtex and perl available in the search path. Do not use
+# file names with spaces, bibtex cannot handle them.
+
+CITE_BIB_FILES =
+
+#---------------------------------------------------------------------------
+# configuration options related to warning and progress messages
+#---------------------------------------------------------------------------
+
+# The QUIET tag can be used to turn on/off the messages that are generated
+# by doxygen. Possible values are YES and NO. If left blank NO is used.
+
+QUIET = NO
+
+# The WARNINGS tag can be used to turn on/off the warning messages that are
+# generated by doxygen. Possible values are YES and NO. If left blank
+# NO is used.
+
+WARNINGS = YES
+
+# If WARN_IF_UNDOCUMENTED is set to YES, then doxygen will generate warnings
+# for undocumented members. If EXTRACT_ALL is set to YES then this flag will
+# automatically be disabled.
+
+WARN_IF_UNDOCUMENTED = YES
+
+# If WARN_IF_DOC_ERROR is set to YES, doxygen will generate warnings for
+# potential errors in the documentation, such as not documenting some
+# parameters in a documented function, or documenting parameters that
+# don't exist or using markup commands wrongly.
+
+WARN_IF_DOC_ERROR = YES
+
+# The WARN_NO_PARAMDOC option can be enabled to get warnings for
+# functions that are documented, but have no documentation for their parameters
+# or return value. If set to NO (the default) doxygen will only warn about
+# wrong or incomplete parameter documentation, but not about the absence of
+# documentation.
+
+WARN_NO_PARAMDOC = NO
+
+# The WARN_FORMAT tag determines the format of the warning messages that
+# doxygen can produce. The string should contain the $file, $line, and $text
+# tags, which will be replaced by the file and line number from which the
+# warning originated and the warning text. Optionally the format may contain
+# $version, which will be replaced by the version of the file (if it could
+# be obtained via FILE_VERSION_FILTER)
+
+WARN_FORMAT = "$file:$line: $text"
+
+# The WARN_LOGFILE tag can be used to specify a file to which warning
+# and error messages should be written. If left blank the output is written
+# to stderr.
+
+WARN_LOGFILE =
+
+#---------------------------------------------------------------------------
+# configuration options related to the input files
+#---------------------------------------------------------------------------
+
+# The INPUT tag can be used to specify the files and/or directories that contain
+# documented source files. You may enter file names like "myfile.cpp" or
+# directories like "/usr/src/myproject". Separate the files or directories
+# with spaces.
+
+INPUT = ../include/ FRONT.md
+
+# This tag can be used to specify the character encoding of the source files
+# that doxygen parses. Internally doxygen uses the UTF-8 encoding, which is
+# also the default input encoding. Doxygen uses libiconv (or the iconv built
+# into libc) for the transcoding. See http://www.gnu.org/software/libiconv for
+# the list of possible encodings.
+
+INPUT_ENCODING = UTF-8
+
+# If the value of the INPUT tag contains directories, you can use the
+# FILE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp
+# and *.h) to filter out the source-files in the directories. If left
+# blank the following patterns are tested:
+# *.c *.cc *.cxx *.cpp *.c++ *.d *.java *.ii *.ixx *.ipp *.i++ *.inl *.h *.hh
+# *.hxx *.hpp *.h++ *.idl *.odl *.cs *.php *.php3 *.inc *.m *.mm *.dox *.py
+# *.f90 *.f *.for *.vhd *.vhdl
+
+FILE_PATTERNS = *.c \
+ *.cc \
+ *.cxx \
+ *.cpp \
+ *.c++ \
+ *.d \
+ *.java \
+ *.ii \
+ *.ixx \
+ *.ipp \
+ *.i++ \
+ *.inl \
+ *.h \
+ *.hh \
+ *.hxx \
+ *.hpp \
+ *.h++ \
+ *.idl \
+ *.odl \
+ *.cs \
+ *.php \
+ *.php3 \
+ *.inc \
+ *.m \
+ *.markdown \
+ *.md \
+ *.mm \
+ *.dox \
+ *.py \
+ *.f90 \
+ *.f \
+ *.for \
+ *.vhd \
+ *.vhdl
+
+# The RECURSIVE tag can be used to turn specify whether or not subdirectories
+# should be searched for input files as well. Possible values are YES and NO.
+# If left blank NO is used.
+
+RECURSIVE = YES
+
+# The EXCLUDE tag can be used to specify files and/or directories that should be
+# excluded from the INPUT source files. This way you can easily exclude a
+# subdirectory from a directory tree whose root is specified with the INPUT tag.
+# Note that relative paths are relative to the directory from which doxygen is
+# run.
+
+EXCLUDE =
+
+# The EXCLUDE_SYMLINKS tag can be used to select whether or not files or
+# directories that are symbolic links (a Unix file system feature) are excluded
+# from the input.
+
+EXCLUDE_SYMLINKS = NO
+
+# If the value of the INPUT tag contains directories, you can use the
+# EXCLUDE_PATTERNS tag to specify one or more wildcard patterns to exclude
+# certain files from those directories. Note that the wildcards are matched
+# against the file with absolute path, so to exclude all test directories
+# for example use the pattern */test/*
+
+EXCLUDE_PATTERNS = */internal/*
+
+# The EXCLUDE_SYMBOLS tag can be used to specify one or more symbol names
+# (namespaces, classes, functions, etc.) that should be excluded from the
+# output. The symbol name can be a fully qualified name, a word, or if the
+# wildcard * is used, a substring. Examples: ANamespace, AClass,
+# AClass::ANamespace, ANamespace::*Test
+
+EXCLUDE_SYMBOLS =
+
+# The EXAMPLE_PATH tag can be used to specify one or more files or
+# directories that contain example code fragments that are included (see
+# the \include command).
+
+EXAMPLE_PATH =
+
+# If the value of the EXAMPLE_PATH tag contains directories, you can use the
+# EXAMPLE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp
+# and *.h) to filter out the source-files in the directories. If left
+# blank all files are included.
+
+EXAMPLE_PATTERNS = *
+
+# If the EXAMPLE_RECURSIVE tag is set to YES then subdirectories will be
+# searched for input files to be used with the \include or \dontinclude
+# commands irrespective of the value of the RECURSIVE tag.
+# Possible values are YES and NO. If left blank NO is used.
+
+EXAMPLE_RECURSIVE = NO
+
+# The IMAGE_PATH tag can be used to specify one or more files or
+# directories that contain image that are included in the documentation (see
+# the \image command).
+
+IMAGE_PATH =
+
+# The INPUT_FILTER tag can be used to specify a program that doxygen should
+# invoke to filter for each input file. Doxygen will invoke the filter program
+# by executing (via popen()) the command <filter> <input-file>, where <filter>
+# is the value of the INPUT_FILTER tag, and <input-file> is the name of an
+# input file. Doxygen will then use the output that the filter program writes
+# to standard output. If FILTER_PATTERNS is specified, this tag will be
+# ignored.
+
+INPUT_FILTER =
+
+# The FILTER_PATTERNS tag can be used to specify filters on a per file pattern
+# basis. Doxygen will compare the file name with each pattern and apply the
+# filter if there is a match. The filters are a list of the form:
+# pattern=filter (like *.cpp=my_cpp_filter). See INPUT_FILTER for further
+# info on how filters are used. If FILTER_PATTERNS is empty or if
+# non of the patterns match the file name, INPUT_FILTER is applied.
+
+FILTER_PATTERNS =
+
+# If the FILTER_SOURCE_FILES tag is set to YES, the input filter (if set using
+# INPUT_FILTER) will be used to filter the input files when producing source
+# files to browse (i.e. when SOURCE_BROWSER is set to YES).
+
+FILTER_SOURCE_FILES = NO
+
+# The FILTER_SOURCE_PATTERNS tag can be used to specify source filters per file
+# pattern. A pattern will override the setting for FILTER_PATTERN (if any)
+# and it is also possible to disable source filtering for a specific pattern
+# using *.ext= (so without naming a filter). This option only has effect when
+# FILTER_SOURCE_FILES is enabled.
+
+FILTER_SOURCE_PATTERNS =
+
+# If the USE_MD_FILE_AS_MAINPAGE tag refers to the name of a markdown file that
+# is part of the input, its contents will be placed on the main page (index.html).
+# This can be useful if you have a project on for instance GitHub and want reuse
+# the introduction page also for the doxygen output.
+
+USE_MDFILE_AS_MAINPAGE = FRONT.md
+
+#---------------------------------------------------------------------------
+# configuration options related to source browsing
+#---------------------------------------------------------------------------
+
+# If the SOURCE_BROWSER tag is set to YES then a list of source files will
+# be generated. Documented entities will be cross-referenced with these sources.
+# Note: To get rid of all source code in the generated output, make sure also
+# VERBATIM_HEADERS is set to NO.
+
+SOURCE_BROWSER = NO
+
+# Setting the INLINE_SOURCES tag to YES will include the body
+# of functions and classes directly in the documentation.
+
+INLINE_SOURCES = NO
+
+# Setting the STRIP_CODE_COMMENTS tag to YES (the default) will instruct
+# doxygen to hide any special comment blocks from generated source code
+# fragments. Normal C, C++ and Fortran comments will always remain visible.
+
+STRIP_CODE_COMMENTS = YES
+
+# If the REFERENCED_BY_RELATION tag is set to YES
+# then for each documented function all documented
+# functions referencing it will be listed.
+
+REFERENCED_BY_RELATION = NO
+
+# If the REFERENCES_RELATION tag is set to YES
+# then for each documented function all documented entities
+# called/used by that function will be listed.
+
+REFERENCES_RELATION = NO
+
+# If the REFERENCES_LINK_SOURCE tag is set to YES (the default)
+# and SOURCE_BROWSER tag is set to YES, then the hyperlinks from
+# functions in REFERENCES_RELATION and REFERENCED_BY_RELATION lists will
+# link to the source code. Otherwise they will link to the documentation.
+
+REFERENCES_LINK_SOURCE = YES
+
+# If the USE_HTAGS tag is set to YES then the references to source code
+# will point to the HTML generated by the htags(1) tool instead of doxygen
+# built-in source browser. The htags tool is part of GNU's global source
+# tagging system (see http://www.gnu.org/software/global/global.html). You
+# will need version 4.8.6 or higher.
+
+USE_HTAGS = NO
+
+# If the VERBATIM_HEADERS tag is set to YES (the default) then Doxygen
+# will generate a verbatim copy of the header file for each class for
+# which an include is specified. Set to NO to disable this.
+
+VERBATIM_HEADERS = YES
+
+#---------------------------------------------------------------------------
+# configuration options related to the alphabetical class index
+#---------------------------------------------------------------------------
+
+# If the ALPHABETICAL_INDEX tag is set to YES, an alphabetical index
+# of all compounds will be generated. Enable this if the project
+# contains a lot of classes, structs, unions or interfaces.
+
+ALPHABETICAL_INDEX = YES
+
+# If the alphabetical index is enabled (see ALPHABETICAL_INDEX) then
+# the COLS_IN_ALPHA_INDEX tag can be used to specify the number of columns
+# in which this list will be split (can be a number in the range [1..20])
+
+COLS_IN_ALPHA_INDEX = 5
+
+# In case all classes in a project start with a common prefix, all
+# classes will be put under the same header in the alphabetical index.
+# The IGNORE_PREFIX tag can be used to specify one or more prefixes that
+# should be ignored while generating the index headers.
+
+IGNORE_PREFIX =
+
+#---------------------------------------------------------------------------
+# configuration options related to the HTML output
+#---------------------------------------------------------------------------
+
+# If the GENERATE_HTML tag is set to YES (the default) Doxygen will
+# generate HTML output.
+
+GENERATE_HTML = YES
+
+# The HTML_OUTPUT tag is used to specify where the HTML docs will be put.
+# If a relative path is entered the value of OUTPUT_DIRECTORY will be
+# put in front of it. If left blank `html' will be used as the default path.
+
+HTML_OUTPUT = html
+
+# The HTML_FILE_EXTENSION tag can be used to specify the file extension for
+# each generated HTML page (for example: .htm,.php,.asp). If it is left blank
+# doxygen will generate files with .html extension.
+
+HTML_FILE_EXTENSION = .html
+
+# The HTML_HEADER tag can be used to specify a personal HTML header for
+# each generated HTML page. If it is left blank doxygen will generate a
+# standard header. Note that when using a custom header you are responsible
+# for the proper inclusion of any scripts and style sheets that doxygen
+# needs, which is dependent on the configuration options used.
+# It is advised to generate a default header using "doxygen -w html
+# header.html footer.html stylesheet.css YourConfigFile" and then modify
+# that header. Note that the header is subject to change so you typically
+# have to redo this when upgrading to a newer version of doxygen or when
+# changing the value of configuration settings such as GENERATE_TREEVIEW!
+
+HTML_HEADER =
+
+# The HTML_FOOTER tag can be used to specify a personal HTML footer for
+# each generated HTML page. If it is left blank doxygen will generate a
+# standard footer.
+
+HTML_FOOTER =
+
+# The HTML_STYLESHEET tag can be used to specify a user-defined cascading
+# style sheet that is used by each HTML page. It can be used to
+# fine-tune the look of the HTML output. If left blank doxygen will
+# generate a default style sheet. Note that it is recommended to use
+# HTML_EXTRA_STYLESHEET instead of this one, as it is more robust and this
+# tag will in the future become obsolete.
+
+HTML_STYLESHEET =
+
+# The HTML_EXTRA_STYLESHEET tag can be used to specify an additional
+# user-defined cascading style sheet that is included after the standard
+# style sheets created by doxygen. Using this option one can overrule
+# certain style aspects. This is preferred over using HTML_STYLESHEET
+# since it does not replace the standard style sheet and is therefor more
+# robust against future updates. Doxygen will copy the style sheet file to
+# the output directory.
+
+HTML_EXTRA_STYLESHEET =
+
+# The HTML_EXTRA_FILES tag can be used to specify one or more extra images or
+# other source files which should be copied to the HTML output directory. Note
+# that these files will be copied to the base HTML output directory. Use the
+# $relpath$ marker in the HTML_HEADER and/or HTML_FOOTER files to load these
+# files. In the HTML_STYLESHEET file, use the file name only. Also note that
+# the files will be copied as-is; there are no commands or markers available.
+
+HTML_EXTRA_FILES =
+
+# The HTML_COLORSTYLE_HUE tag controls the color of the HTML output.
+# Doxygen will adjust the colors in the style sheet and background images
+# according to this color. Hue is specified as an angle on a colorwheel,
+# see http://en.wikipedia.org/wiki/Hue for more information.
+# For instance the value 0 represents red, 60 is yellow, 120 is green,
+# 180 is cyan, 240 is blue, 300 purple, and 360 is red again.
+# The allowed range is 0 to 359.
+
+HTML_COLORSTYLE_HUE = 220
+
+# The HTML_COLORSTYLE_SAT tag controls the purity (or saturation) of
+# the colors in the HTML output. For a value of 0 the output will use
+# grayscales only. A value of 255 will produce the most vivid colors.
+
+HTML_COLORSTYLE_SAT = 100
+
+# The HTML_COLORSTYLE_GAMMA tag controls the gamma correction applied to
+# the luminance component of the colors in the HTML output. Values below
+# 100 gradually make the output lighter, whereas values above 100 make
+# the output darker. The value divided by 100 is the actual gamma applied,
+# so 80 represents a gamma of 0.8, The value 220 represents a gamma of 2.2,
+# and 100 does not change the gamma.
+
+HTML_COLORSTYLE_GAMMA = 80
+
+# If the HTML_TIMESTAMP tag is set to YES then the footer of each generated HTML
+# page will contain the date and time when the page was generated. Setting
+# this to NO can help when comparing the output of multiple runs.
+
+HTML_TIMESTAMP = YES
+
+# If the HTML_DYNAMIC_SECTIONS tag is set to YES then the generated HTML
+# documentation will contain sections that can be hidden and shown after the
+# page has loaded.
+
+HTML_DYNAMIC_SECTIONS = NO
+
+# With HTML_INDEX_NUM_ENTRIES one can control the preferred number of
+# entries shown in the various tree structured indices initially; the user
+# can expand and collapse entries dynamically later on. Doxygen will expand
+# the tree to such a level that at most the specified number of entries are
+# visible (unless a fully collapsed tree already exceeds this amount).
+# So setting the number of entries 1 will produce a full collapsed tree by
+# default. 0 is a special value representing an infinite number of entries
+# and will result in a full expanded tree by default.
+
+HTML_INDEX_NUM_ENTRIES = 100
+
+# If the GENERATE_DOCSET tag is set to YES, additional index files
+# will be generated that can be used as input for Apple's Xcode 3
+# integrated development environment, introduced with OSX 10.5 (Leopard).
+# To create a documentation set, doxygen will generate a Makefile in the
+# HTML output directory. Running make will produce the docset in that
+# directory and running "make install" will install the docset in
+# ~/Library/Developer/Shared/Documentation/DocSets so that Xcode will find
+# it at startup.
+# See http://developer.apple.com/tools/creatingdocsetswithdoxygen.html
+# for more information.
+
+GENERATE_DOCSET = NO
+
+# When GENERATE_DOCSET tag is set to YES, this tag determines the name of the
+# feed. A documentation feed provides an umbrella under which multiple
+# documentation sets from a single provider (such as a company or product suite)
+# can be grouped.
+
+DOCSET_FEEDNAME = "Doxygen generated docs"
+
+# When GENERATE_DOCSET tag is set to YES, this tag specifies a string that
+# should uniquely identify the documentation set bundle. This should be a
+# reverse domain-name style string, e.g. com.mycompany.MyDocSet. Doxygen
+# will append .docset to the name.
+
+DOCSET_BUNDLE_ID = org.doxygen.Project
+
+# When GENERATE_PUBLISHER_ID tag specifies a string that should uniquely
+# identify the documentation publisher. This should be a reverse domain-name
+# style string, e.g. com.mycompany.MyDocSet.documentation.
+
+DOCSET_PUBLISHER_ID = org.doxygen.Publisher
+
+# The GENERATE_PUBLISHER_NAME tag identifies the documentation publisher.
+
+DOCSET_PUBLISHER_NAME = Publisher
+
+# If the GENERATE_HTMLHELP tag is set to YES, additional index files
+# will be generated that can be used as input for tools like the
+# Microsoft HTML help workshop to generate a compiled HTML help file (.chm)
+# of the generated HTML documentation.
+
+GENERATE_HTMLHELP = NO
+
+# If the GENERATE_HTMLHELP tag is set to YES, the CHM_FILE tag can
+# be used to specify the file name of the resulting .chm file. You
+# can add a path in front of the file if the result should not be
+# written to the html output directory.
+
+CHM_FILE =
+
+# If the GENERATE_HTMLHELP tag is set to YES, the HHC_LOCATION tag can
+# be used to specify the location (absolute path including file name) of
+# the HTML help compiler (hhc.exe). If non-empty doxygen will try to run
+# the HTML help compiler on the generated index.hhp.
+
+HHC_LOCATION =
+
+# If the GENERATE_HTMLHELP tag is set to YES, the GENERATE_CHI flag
+# controls if a separate .chi index file is generated (YES) or that
+# it should be included in the master .chm file (NO).
+
+GENERATE_CHI = NO
+
+# If the GENERATE_HTMLHELP tag is set to YES, the CHM_INDEX_ENCODING
+# is used to encode HtmlHelp index (hhk), content (hhc) and project file
+# content.
+
+CHM_INDEX_ENCODING =
+
+# If the GENERATE_HTMLHELP tag is set to YES, the BINARY_TOC flag
+# controls whether a binary table of contents is generated (YES) or a
+# normal table of contents (NO) in the .chm file.
+
+BINARY_TOC = NO
+
+# The TOC_EXPAND flag can be set to YES to add extra items for group members
+# to the contents of the HTML help documentation and to the tree view.
+
+TOC_EXPAND = NO
+
+# If the GENERATE_QHP tag is set to YES and both QHP_NAMESPACE and
+# QHP_VIRTUAL_FOLDER are set, an additional index file will be generated
+# that can be used as input for Qt's qhelpgenerator to generate a
+# Qt Compressed Help (.qch) of the generated HTML documentation.
+
+GENERATE_QHP = NO
+
+# If the QHG_LOCATION tag is specified, the QCH_FILE tag can
+# be used to specify the file name of the resulting .qch file.
+# The path specified is relative to the HTML output folder.
+
+QCH_FILE =
+
+# The QHP_NAMESPACE tag specifies the namespace to use when generating
+# Qt Help Project output. For more information please see
+# http://doc.trolltech.com/qthelpproject.html#namespace
+
+QHP_NAMESPACE = org.doxygen.Project
+
+# The QHP_VIRTUAL_FOLDER tag specifies the namespace to use when generating
+# Qt Help Project output. For more information please see
+# http://doc.trolltech.com/qthelpproject.html#virtual-folders
+
+QHP_VIRTUAL_FOLDER = doc
+
+# If QHP_CUST_FILTER_NAME is set, it specifies the name of a custom filter to
+# add. For more information please see
+# http://doc.trolltech.com/qthelpproject.html#custom-filters
+
+QHP_CUST_FILTER_NAME =
+
+# The QHP_CUST_FILT_ATTRS tag specifies the list of the attributes of the
+# custom filter to add. For more information please see
+# <a href="http://doc.trolltech.com/qthelpproject.html#custom-filters">
+# Qt Help Project / Custom Filters</a>.
+
+QHP_CUST_FILTER_ATTRS =
+
+# The QHP_SECT_FILTER_ATTRS tag specifies the list of the attributes this
+# project's
+# filter section matches.
+# <a href="http://doc.trolltech.com/qthelpproject.html#filter-attributes">
+# Qt Help Project / Filter Attributes</a>.
+
+QHP_SECT_FILTER_ATTRS =
+
+# If the GENERATE_QHP tag is set to YES, the QHG_LOCATION tag can
+# be used to specify the location of Qt's qhelpgenerator.
+# If non-empty doxygen will try to run qhelpgenerator on the generated
+# .qhp file.
+
+QHG_LOCATION =
+
+# If the GENERATE_ECLIPSEHELP tag is set to YES, additional index files
+# will be generated, which together with the HTML files, form an Eclipse help
+# plugin. To install this plugin and make it available under the help contents
+# menu in Eclipse, the contents of the directory containing the HTML and XML
+# files needs to be copied into the plugins directory of eclipse. The name of
+# the directory within the plugins directory should be the same as
+# the ECLIPSE_DOC_ID value. After copying Eclipse needs to be restarted before
+# the help appears.
+
+GENERATE_ECLIPSEHELP = NO
+
+# A unique identifier for the eclipse help plugin. When installing the plugin
+# the directory name containing the HTML and XML files should also have
+# this name.
+
+ECLIPSE_DOC_ID = org.doxygen.Project
+
+# The DISABLE_INDEX tag can be used to turn on/off the condensed index (tabs)
+# at top of each HTML page. The value NO (the default) enables the index and
+# the value YES disables it. Since the tabs have the same information as the
+# navigation tree you can set this option to NO if you already set
+# GENERATE_TREEVIEW to YES.
+
+DISABLE_INDEX = NO
+
+# The GENERATE_TREEVIEW tag is used to specify whether a tree-like index
+# structure should be generated to display hierarchical information.
+# If the tag value is set to YES, a side panel will be generated
+# containing a tree-like index structure (just like the one that
+# is generated for HTML Help). For this to work a browser that supports
+# JavaScript, DHTML, CSS and frames is required (i.e. any modern browser).
+# Windows users are probably better off using the HTML help feature.
+# Since the tree basically has the same information as the tab index you
+# could consider to set DISABLE_INDEX to NO when enabling this option.
+
+GENERATE_TREEVIEW = NO
+
+# The ENUM_VALUES_PER_LINE tag can be used to set the number of enum values
+# (range [0,1..20]) that doxygen will group on one line in the generated HTML
+# documentation. Note that a value of 0 will completely suppress the enum
+# values from appearing in the overview section.
+
+ENUM_VALUES_PER_LINE = 4
+
+# If the treeview is enabled (see GENERATE_TREEVIEW) then this tag can be
+# used to set the initial width (in pixels) of the frame in which the tree
+# is shown.
+
+TREEVIEW_WIDTH = 250
+
+# When the EXT_LINKS_IN_WINDOW option is set to YES doxygen will open
+# links to external symbols imported via tag files in a separate window.
+
+EXT_LINKS_IN_WINDOW = NO
+
+# Use this tag to change the font size of Latex formulas included
+# as images in the HTML documentation. The default is 10. Note that
+# when you change the font size after a successful doxygen run you need
+# to manually remove any form_*.png images from the HTML output directory
+# to force them to be regenerated.
+
+FORMULA_FONTSIZE = 10
+
+# Use the FORMULA_TRANPARENT tag to determine whether or not the images
+# generated for formulas are transparent PNGs. Transparent PNGs are
+# not supported properly for IE 6.0, but are supported on all modern browsers.
+# Note that when changing this option you need to delete any form_*.png files
+# in the HTML output before the changes have effect.
+
+FORMULA_TRANSPARENT = YES
+
+# Enable the USE_MATHJAX option to render LaTeX formulas using MathJax
+# (see http://www.mathjax.org) which uses client side Javascript for the
+# rendering instead of using prerendered bitmaps. Use this if you do not
+# have LaTeX installed or if you want to formulas look prettier in the HTML
+# output. When enabled you may also need to install MathJax separately and
+# configure the path to it using the MATHJAX_RELPATH option.
+
+USE_MATHJAX = NO
+
+# When MathJax is enabled you can set the default output format to be used for
+# thA MathJax output. Supported types are HTML-CSS, NativeMML (i.e. MathML) and
+# SVG. The default value is HTML-CSS, which is slower, but has the best
+# compatibility.
+
+MATHJAX_FORMAT = HTML-CSS
+
+# When MathJax is enabled you need to specify the location relative to the
+# HTML output directory using the MATHJAX_RELPATH option. The destination
+# directory should contain the MathJax.js script. For instance, if the mathjax
+# directory is located at the same level as the HTML output directory, then
+# MATHJAX_RELPATH should be ../mathjax. The default value points to
+# the MathJax Content Delivery Network so you can quickly see the result without
+# installing MathJax. However, it is strongly recommended to install a local
+# copy of MathJax from http://www.mathjax.org before deployment.
+
+MATHJAX_RELPATH = http://cdn.mathjax.org/mathjax/latest
+
+# The MATHJAX_EXTENSIONS tag can be used to specify one or MathJax extension
+# names that should be enabled during MathJax rendering.
+
+MATHJAX_EXTENSIONS =
+
+# When the SEARCHENGINE tag is enabled doxygen will generate a search box
+# for the HTML output. The underlying search engine uses javascript
+# and DHTML and should work on any modern browser. Note that when using
+# HTML help (GENERATE_HTMLHELP), Qt help (GENERATE_QHP), or docsets
+# (GENERATE_DOCSET) there is already a search function so this one should
+# typically be disabled. For large projects the javascript based search engine
+# can be slow, then enabling SERVER_BASED_SEARCH may provide a better solution.
+
+SEARCHENGINE = YES
+
+# When the SERVER_BASED_SEARCH tag is enabled the search engine will be
+# implemented using a web server instead of a web client using Javascript.
+# There are two flavours of web server based search depending on the
+# EXTERNAL_SEARCH setting. When disabled, doxygen will generate a PHP script for
+# searching and an index file used by the script. When EXTERNAL_SEARCH is
+# enabled the indexing and searching needs to be provided by external tools.
+# See the manual for details.
+
+SERVER_BASED_SEARCH = NO
+
+# When EXTERNAL_SEARCH is enabled doxygen will no longer generate the PHP
+# script for searching. Instead the search results are written to an XML file
+# which needs to be processed by an external indexer. Doxygen will invoke an
+# external search engine pointed to by the SEARCHENGINE_URL option to obtain
+# the search results. Doxygen ships with an example indexer (doxyindexer) and
+# search engine (doxysearch.cgi) which are based on the open source search engine
+# library Xapian. See the manual for configuration details.
+
+EXTERNAL_SEARCH = NO
+
+# The SEARCHENGINE_URL should point to a search engine hosted by a web server
+# which will returned the search results when EXTERNAL_SEARCH is enabled.
+# Doxygen ships with an example search engine (doxysearch) which is based on
+# the open source search engine library Xapian. See the manual for configuration
+# details.
+
+SEARCHENGINE_URL =
+
+# When SERVER_BASED_SEARCH and EXTERNAL_SEARCH are both enabled the unindexed
+# search data is written to a file for indexing by an external tool. With the
+# SEARCHDATA_FILE tag the name of this file can be specified.
+
+SEARCHDATA_FILE = searchdata.xml
+
+# When SERVER_BASED_SEARCH AND EXTERNAL_SEARCH are both enabled the
+# EXTERNAL_SEARCH_ID tag can be used as an identifier for the project. This is
+# useful in combination with EXTRA_SEARCH_MAPPINGS to search through multiple
+# projects and redirect the results back to the right project.
+
+EXTERNAL_SEARCH_ID =
+
+# The EXTRA_SEARCH_MAPPINGS tag can be used to enable searching through doxygen
+# projects other than the one defined by this configuration file, but that are
+# all added to the same external search index. Each project needs to have a
+# unique id set via EXTERNAL_SEARCH_ID. The search mapping then maps the id
+# of to a relative location where the documentation can be found.
+# The format is: EXTRA_SEARCH_MAPPINGS = id1=loc1 id2=loc2 ...
+
+EXTRA_SEARCH_MAPPINGS =
+
+#---------------------------------------------------------------------------
+# configuration options related to the LaTeX output
+#---------------------------------------------------------------------------
+
+# If the GENERATE_LATEX tag is set to YES (the default) Doxygen will
+# generate Latex output.
+
+GENERATE_LATEX = NO
+
+# The LATEX_OUTPUT tag is used to specify where the LaTeX docs will be put.
+# If a relative path is entered the value of OUTPUT_DIRECTORY will be
+# put in front of it. If left blank `latex' will be used as the default path.
+
+LATEX_OUTPUT = latex
+
+# The LATEX_CMD_NAME tag can be used to specify the LaTeX command name to be
+# invoked. If left blank `latex' will be used as the default command name.
+# Note that when enabling USE_PDFLATEX this option is only used for
+# generating bitmaps for formulas in the HTML output, but not in the
+# Makefile that is written to the output directory.
+
+LATEX_CMD_NAME = latex
+
+# The MAKEINDEX_CMD_NAME tag can be used to specify the command name to
+# generate index for LaTeX. If left blank `makeindex' will be used as the
+# default command name.
+
+MAKEINDEX_CMD_NAME = makeindex
+
+# If the COMPACT_LATEX tag is set to YES Doxygen generates more compact
+# LaTeX documents. This may be useful for small projects and may help to
+# save some trees in general.
+
+COMPACT_LATEX = NO
+
+# The PAPER_TYPE tag can be used to set the paper type that is used
+# by the printer. Possible values are: a4, letter, legal and
+# executive. If left blank a4wide will be used.
+
+PAPER_TYPE = a4
+
+# The EXTRA_PACKAGES tag can be to specify one or more names of LaTeX
+# packages that should be included in the LaTeX output.
+
+EXTRA_PACKAGES =
+
+# The LATEX_HEADER tag can be used to specify a personal LaTeX header for
+# the generated latex document. The header should contain everything until
+# the first chapter. If it is left blank doxygen will generate a
+# standard header. Notice: only use this tag if you know what you are doing!
+
+LATEX_HEADER =
+
+# The LATEX_FOOTER tag can be used to specify a personal LaTeX footer for
+# the generated latex document. The footer should contain everything after
+# the last chapter. If it is left blank doxygen will generate a
+# standard footer. Notice: only use this tag if you know what you are doing!
+
+LATEX_FOOTER =
+
+# If the PDF_HYPERLINKS tag is set to YES, the LaTeX that is generated
+# is prepared for conversion to pdf (using ps2pdf). The pdf file will
+# contain links (just like the HTML output) instead of page references
+# This makes the output suitable for online browsing using a pdf viewer.
+
+PDF_HYPERLINKS = YES
+
+# If the USE_PDFLATEX tag is set to YES, pdflatex will be used instead of
+# plain latex in the generated Makefile. Set this option to YES to get a
+# higher quality PDF documentation.
+
+USE_PDFLATEX = YES
+
+# If the LATEX_BATCHMODE tag is set to YES, doxygen will add the \\batchmode.
+# command to the generated LaTeX files. This will instruct LaTeX to keep
+# running if errors occur, instead of asking the user for help.
+# This option is also used when generating formulas in HTML.
+
+LATEX_BATCHMODE = NO
+
+# If LATEX_HIDE_INDICES is set to YES then doxygen will not
+# include the index chapters (such as File Index, Compound Index, etc.)
+# in the output.
+
+LATEX_HIDE_INDICES = NO
+
+# If LATEX_SOURCE_CODE is set to YES then doxygen will include
+# source code with syntax highlighting in the LaTeX output.
+# Note that which sources are shown also depends on other settings
+# such as SOURCE_BROWSER.
+
+LATEX_SOURCE_CODE = NO
+
+# The LATEX_BIB_STYLE tag can be used to specify the style to use for the
+# bibliography, e.g. plainnat, or ieeetr. The default style is "plain". See
+# http://en.wikipedia.org/wiki/BibTeX for more info.
+
+LATEX_BIB_STYLE = plain
+
+#---------------------------------------------------------------------------
+# configuration options related to the RTF output
+#---------------------------------------------------------------------------
+
+# If the GENERATE_RTF tag is set to YES Doxygen will generate RTF output
+# The RTF output is optimized for Word 97 and may not look very pretty with
+# other RTF readers or editors.
+
+GENERATE_RTF = NO
+
+# The RTF_OUTPUT tag is used to specify where the RTF docs will be put.
+# If a relative path is entered the value of OUTPUT_DIRECTORY will be
+# put in front of it. If left blank `rtf' will be used as the default path.
+
+RTF_OUTPUT = rtf
+
+# If the COMPACT_RTF tag is set to YES Doxygen generates more compact
+# RTF documents. This may be useful for small projects and may help to
+# save some trees in general.
+
+COMPACT_RTF = NO
+
+# If the RTF_HYPERLINKS tag is set to YES, the RTF that is generated
+# will contain hyperlink fields. The RTF file will
+# contain links (just like the HTML output) instead of page references.
+# This makes the output suitable for online browsing using WORD or other
+# programs which support those fields.
+# Note: wordpad (write) and others do not support links.
+
+RTF_HYPERLINKS = NO
+
+# Load style sheet definitions from file. Syntax is similar to doxygen's
+# config file, i.e. a series of assignments. You only have to provide
+# replacements, missing definitions are set to their default value.
+
+RTF_STYLESHEET_FILE =
+
+# Set optional variables used in the generation of an rtf document.
+# Syntax is similar to doxygen's config file.
+
+RTF_EXTENSIONS_FILE =
+
+#---------------------------------------------------------------------------
+# configuration options related to the man page output
+#---------------------------------------------------------------------------
+
+# If the GENERATE_MAN tag is set to YES (the default) Doxygen will
+# generate man pages
+
+GENERATE_MAN = NO
+
+# The MAN_OUTPUT tag is used to specify where the man pages will be put.
+# If a relative path is entered the value of OUTPUT_DIRECTORY will be
+# put in front of it. If left blank `man' will be used as the default path.
+
+MAN_OUTPUT = man
+
+# The MAN_EXTENSION tag determines the extension that is added to
+# the generated man pages (default is the subroutine's section .3)
+
+MAN_EXTENSION = .3
+
+# If the MAN_LINKS tag is set to YES and Doxygen generates man output,
+# then it will generate one additional man file for each entity
+# documented in the real man page(s). These additional files
+# only source the real man page, but without them the man command
+# would be unable to find the correct page. The default is NO.
+
+MAN_LINKS = NO
+
+#---------------------------------------------------------------------------
+# configuration options related to the XML output
+#---------------------------------------------------------------------------
+
+# If the GENERATE_XML tag is set to YES Doxygen will
+# generate an XML file that captures the structure of
+# the code including all documentation.
+
+GENERATE_XML = NO
+
+# The XML_OUTPUT tag is used to specify where the XML pages will be put.
+# If a relative path is entered the value of OUTPUT_DIRECTORY will be
+# put in front of it. If left blank `xml' will be used as the default path.
+
+XML_OUTPUT = xml
+
+# The XML_SCHEMA tag can be used to specify an XML schema,
+# which can be used by a validating XML parser to check the
+# syntax of the XML files.
+
+XML_SCHEMA =
+
+# The XML_DTD tag can be used to specify an XML DTD,
+# which can be used by a validating XML parser to check the
+# syntax of the XML files.
+
+XML_DTD =
+
+# If the XML_PROGRAMLISTING tag is set to YES Doxygen will
+# dump the program listings (including syntax highlighting
+# and cross-referencing information) to the XML output. Note that
+# enabling this will significantly increase the size of the XML output.
+
+XML_PROGRAMLISTING = YES
+
+#---------------------------------------------------------------------------
+# configuration options for the AutoGen Definitions output
+#---------------------------------------------------------------------------
+
+# If the GENERATE_AUTOGEN_DEF tag is set to YES Doxygen will
+# generate an AutoGen Definitions (see autogen.sf.net) file
+# that captures the structure of the code including all
+# documentation. Note that this feature is still experimental
+# and incomplete at the moment.
+
+GENERATE_AUTOGEN_DEF = NO
+
+#---------------------------------------------------------------------------
+# configuration options related to the Perl module output
+#---------------------------------------------------------------------------
+
+# If the GENERATE_PERLMOD tag is set to YES Doxygen will
+# generate a Perl module file that captures the structure of
+# the code including all documentation. Note that this
+# feature is still experimental and incomplete at the
+# moment.
+
+GENERATE_PERLMOD = NO
+
+# If the PERLMOD_LATEX tag is set to YES Doxygen will generate
+# the necessary Makefile rules, Perl scripts and LaTeX code to be able
+# to generate PDF and DVI output from the Perl module output.
+
+PERLMOD_LATEX = NO
+
+# If the PERLMOD_PRETTY tag is set to YES the Perl module output will be
+# nicely formatted so it can be parsed by a human reader. This is useful
+# if you want to understand what is going on. On the other hand, if this
+# tag is set to NO the size of the Perl module output will be much smaller
+# and Perl will parse it just the same.
+
+PERLMOD_PRETTY = YES
+
+# The names of the make variables in the generated doxyrules.make file
+# are prefixed with the string contained in PERLMOD_MAKEVAR_PREFIX.
+# This is useful so different doxyrules.make files included by the same
+# Makefile don't overwrite each other's variables.
+
+PERLMOD_MAKEVAR_PREFIX =
+
+#---------------------------------------------------------------------------
+# Configuration options related to the preprocessor
+#---------------------------------------------------------------------------
+
+# If the ENABLE_PREPROCESSING tag is set to YES (the default) Doxygen will
+# evaluate all C-preprocessor directives found in the sources and include
+# files.
+
+ENABLE_PREPROCESSING = YES
+
+# If the MACRO_EXPANSION tag is set to YES Doxygen will expand all macro
+# names in the source code. If set to NO (the default) only conditional
+# compilation will be performed. Macro expansion can be done in a controlled
+# way by setting EXPAND_ONLY_PREDEF to YES.
+
+MACRO_EXPANSION = NO
+
+# If the EXPAND_ONLY_PREDEF and MACRO_EXPANSION tags are both set to YES
+# then the macro expansion is limited to the macros specified with the
+# PREDEFINED and EXPAND_AS_DEFINED tags.
+
+EXPAND_ONLY_PREDEF = NO
+
+# If the SEARCH_INCLUDES tag is set to YES (the default) the includes files
+# pointed to by INCLUDE_PATH will be searched when a #include is found.
+
+SEARCH_INCLUDES = YES
+
+# The INCLUDE_PATH tag can be used to specify one or more directories that
+# contain include files that are not input files but should be processed by
+# the preprocessor.
+
+INCLUDE_PATH =
+
+# You can use the INCLUDE_FILE_PATTERNS tag to specify one or more wildcard
+# patterns (like *.h and *.hpp) to filter out the header-files in the
+# directories. If left blank, the patterns specified with FILE_PATTERNS will
+# be used.
+
+INCLUDE_FILE_PATTERNS =
+
+# The PREDEFINED tag can be used to specify one or more macro names that
+# are defined before the preprocessor is started (similar to the -D option of
+# gcc). The argument of the tag is a list of macros of the form: name
+# or name=definition (no spaces). If the definition and the = are
+# omitted =1 is assumed. To prevent a macro definition from being
+# undefined via #undef or recursively expanded use the := operator
+# instead of the = operator.
+
+PREDEFINED =
+
+# If the MACRO_EXPANSION and EXPAND_ONLY_PREDEF tags are set to YES then
+# this tag can be used to specify a list of macro names that should be expanded.
+# The macro definition that is found in the sources will be used.
+# Use the PREDEFINED tag if you want to use a different macro definition that
+# overrules the definition found in the source code.
+
+EXPAND_AS_DEFINED =
+
+# If the SKIP_FUNCTION_MACROS tag is set to YES (the default) then
+# doxygen's preprocessor will remove all references to function-like macros
+# that are alone on a line, have an all uppercase name, and do not end with a
+# semicolon, because these will confuse the parser if not removed.
+
+SKIP_FUNCTION_MACROS = YES
+
+#---------------------------------------------------------------------------
+# Configuration::additions related to external references
+#---------------------------------------------------------------------------
+
+# The TAGFILES option can be used to specify one or more tagfiles. For each
+# tag file the location of the external documentation should be added. The
+# format of a tag file without this location is as follows:
+# TAGFILES = file1 file2 ...
+# Adding location for the tag files is done as follows:
+# TAGFILES = file1=loc1 "file2 = loc2" ...
+# where "loc1" and "loc2" can be relative or absolute paths
+# or URLs. Note that each tag file must have a unique name (where the name does
+# NOT include the path). If a tag file is not located in the directory in which
+# doxygen is run, you must also specify the path to the tagfile here.
+
+TAGFILES =
+
+# When a file name is specified after GENERATE_TAGFILE, doxygen will create
+# a tag file that is based on the input files it reads.
+
+GENERATE_TAGFILE =
+
+# If the ALLEXTERNALS tag is set to YES all external classes will be listed
+# in the class index. If set to NO only the inherited external classes
+# will be listed.
+
+ALLEXTERNALS = NO
+
+# If the EXTERNAL_GROUPS tag is set to YES all external groups will be listed
+# in the modules index. If set to NO, only the current project's groups will
+# be listed.
+
+EXTERNAL_GROUPS = YES
+
+# The PERL_PATH should be the absolute path and name of the perl script
+# interpreter (i.e. the result of `which perl').
+
+PERL_PATH = /usr/bin/perl
+
+#---------------------------------------------------------------------------
+# Configuration options related to the dot tool
+#---------------------------------------------------------------------------
+
+# If the CLASS_DIAGRAMS tag is set to YES (the default) Doxygen will
+# generate a inheritance diagram (in HTML, RTF and LaTeX) for classes with base
+# or super classes. Setting the tag to NO turns the diagrams off. Note that
+# this option also works with HAVE_DOT disabled, but it is recommended to
+# install and use dot, since it yields more powerful graphs.
+
+CLASS_DIAGRAMS = YES
+
+# You can define message sequence charts within doxygen comments using the \msc
+# command. Doxygen will then run the mscgen tool (see
+# http://www.mcternan.me.uk/mscgen/) to produce the chart and insert it in the
+# documentation. The MSCGEN_PATH tag allows you to specify the directory where
+# the mscgen tool resides. If left empty the tool is assumed to be found in the
+# default search path.
+
+MSCGEN_PATH =
+
+# If set to YES, the inheritance and collaboration graphs will hide
+# inheritance and usage relations if the target is undocumented
+# or is not a class.
+
+HIDE_UNDOC_RELATIONS = YES
+
+# If you set the HAVE_DOT tag to YES then doxygen will assume the dot tool is
+# available from the path. This tool is part of Graphviz, a graph visualization
+# toolkit from AT&T and Lucent Bell Labs. The other options in this section
+# have no effect if this option is set to NO (the default)
+
+HAVE_DOT = NO
+
+# The DOT_NUM_THREADS specifies the number of dot invocations doxygen is
+# allowed to run in parallel. When set to 0 (the default) doxygen will
+# base this on the number of processors available in the system. You can set it
+# explicitly to a value larger than 0 to get control over the balance
+# between CPU load and processing speed.
+
+DOT_NUM_THREADS = 0
+
+# By default doxygen will use the Helvetica font for all dot files that
+# doxygen generates. When you want a differently looking font you can specify
+# the font name using DOT_FONTNAME. You need to make sure dot is able to find
+# the font, which can be done by putting it in a standard location or by setting
+# the DOTFONTPATH environment variable or by setting DOT_FONTPATH to the
+# directory containing the font.
+
+DOT_FONTNAME = Helvetica
+
+# The DOT_FONTSIZE tag can be used to set the size of the font of dot graphs.
+# The default size is 10pt.
+
+DOT_FONTSIZE = 10
+
+# By default doxygen will tell dot to use the Helvetica font.
+# If you specify a different font using DOT_FONTNAME you can use DOT_FONTPATH to
+# set the path where dot can find it.
+
+DOT_FONTPATH =
+
+# If the CLASS_GRAPH and HAVE_DOT tags are set to YES then doxygen
+# will generate a graph for each documented class showing the direct and
+# indirect inheritance relations. Setting this tag to YES will force the
+# CLASS_DIAGRAMS tag to NO.
+
+CLASS_GRAPH = YES
+
+# If the COLLABORATION_GRAPH and HAVE_DOT tags are set to YES then doxygen
+# will generate a graph for each documented class showing the direct and
+# indirect implementation dependencies (inheritance, containment, and
+# class references variables) of the class with other documented classes.
+
+COLLABORATION_GRAPH = YES
+
+# If the GROUP_GRAPHS and HAVE_DOT tags are set to YES then doxygen
+# will generate a graph for groups, showing the direct groups dependencies
+
+GROUP_GRAPHS = YES
+
+# If the UML_LOOK tag is set to YES doxygen will generate inheritance and
+# collaboration diagrams in a style similar to the OMG's Unified Modeling
+# Language.
+
+UML_LOOK = NO
+
+# If the UML_LOOK tag is enabled, the fields and methods are shown inside
+# the class node. If there are many fields or methods and many nodes the
+# graph may become too big to be useful. The UML_LIMIT_NUM_FIELDS
+# threshold limits the number of items for each type to make the size more
+# managable. Set this to 0 for no limit. Note that the threshold may be
+# exceeded by 50% before the limit is enforced.
+
+UML_LIMIT_NUM_FIELDS = 10
+
+# If set to YES, the inheritance and collaboration graphs will show the
+# relations between templates and their instances.
+
+TEMPLATE_RELATIONS = NO
+
+# If the ENABLE_PREPROCESSING, SEARCH_INCLUDES, INCLUDE_GRAPH, and HAVE_DOT
+# tags are set to YES then doxygen will generate a graph for each documented
+# file showing the direct and indirect include dependencies of the file with
+# other documented files.
+
+INCLUDE_GRAPH = YES
+
+# If the ENABLE_PREPROCESSING, SEARCH_INCLUDES, INCLUDED_BY_GRAPH, and
+# HAVE_DOT tags are set to YES then doxygen will generate a graph for each
+# documented header file showing the documented files that directly or
+# indirectly include this file.
+
+INCLUDED_BY_GRAPH = YES
+
+# If the CALL_GRAPH and HAVE_DOT options are set to YES then
+# doxygen will generate a call dependency graph for every global function
+# or class method. Note that enabling this option will significantly increase
+# the time of a run. So in most cases it will be better to enable call graphs
+# for selected functions only using the \callgraph command.
+
+CALL_GRAPH = NO
+
+# If the CALLER_GRAPH and HAVE_DOT tags are set to YES then
+# doxygen will generate a caller dependency graph for every global function
+# or class method. Note that enabling this option will significantly increase
+# the time of a run. So in most cases it will be better to enable caller
+# graphs for selected functions only using the \callergraph command.
+
+CALLER_GRAPH = NO
+
+# If the GRAPHICAL_HIERARCHY and HAVE_DOT tags are set to YES then doxygen
+# will generate a graphical hierarchy of all classes instead of a textual one.
+
+GRAPHICAL_HIERARCHY = YES
+
+# If the DIRECTORY_GRAPH and HAVE_DOT tags are set to YES
+# then doxygen will show the dependencies a directory has on other directories
+# in a graphical way. The dependency relations are determined by the #include
+# relations between the files in the directories.
+
+DIRECTORY_GRAPH = YES
+
+# The DOT_IMAGE_FORMAT tag can be used to set the image format of the images
+# generated by dot. Possible values are svg, png, jpg, or gif.
+# If left blank png will be used. If you choose svg you need to set
+# HTML_FILE_EXTENSION to xhtml in order to make the SVG files
+# visible in IE 9+ (other browsers do not have this requirement).
+
+DOT_IMAGE_FORMAT = png
+
+# If DOT_IMAGE_FORMAT is set to svg, then this option can be set to YES to
+# enable generation of interactive SVG images that allow zooming and panning.
+# Note that this requires a modern browser other than Internet Explorer.
+# Tested and working are Firefox, Chrome, Safari, and Opera. For IE 9+ you
+# need to set HTML_FILE_EXTENSION to xhtml in order to make the SVG files
+# visible. Older versions of IE do not have SVG support.
+
+INTERACTIVE_SVG = NO
+
+# The tag DOT_PATH can be used to specify the path where the dot tool can be
+# found. If left blank, it is assumed the dot tool can be found in the path.
+
+DOT_PATH =
+
+# The DOTFILE_DIRS tag can be used to specify one or more directories that
+# contain dot files that are included in the documentation (see the
+# \dotfile command).
+
+DOTFILE_DIRS =
+
+# The MSCFILE_DIRS tag can be used to specify one or more directories that
+# contain msc files that are included in the documentation (see the
+# \mscfile command).
+
+MSCFILE_DIRS =
+
+# The DOT_GRAPH_MAX_NODES tag can be used to set the maximum number of
+# nodes that will be shown in the graph. If the number of nodes in a graph
+# becomes larger than this value, doxygen will truncate the graph, which is
+# visualized by representing a node as a red box. Note that doxygen if the
+# number of direct children of the root node in a graph is already larger than
+# DOT_GRAPH_MAX_NODES then the graph will not be shown at all. Also note
+# that the size of a graph can be further restricted by MAX_DOT_GRAPH_DEPTH.
+
+DOT_GRAPH_MAX_NODES = 50
+
+# The MAX_DOT_GRAPH_DEPTH tag can be used to set the maximum depth of the
+# graphs generated by dot. A depth value of 3 means that only nodes reachable
+# from the root by following a path via at most 3 edges will be shown. Nodes
+# that lay further from the root node will be omitted. Note that setting this
+# option to 1 or 2 may greatly reduce the computation time needed for large
+# code bases. Also note that the size of a graph can be further restricted by
+# DOT_GRAPH_MAX_NODES. Using a depth of 0 means no depth restriction.
+
+MAX_DOT_GRAPH_DEPTH = 0
+
+# Set the DOT_TRANSPARENT tag to YES to generate images with a transparent
+# background. This is disabled by default, because dot on Windows does not
+# seem to support this out of the box. Warning: Depending on the platform used,
+# enabling this option may lead to badly anti-aliased labels on the edges of
+# a graph (i.e. they become hard to read).
+
+DOT_TRANSPARENT = NO
+
+# Set the DOT_MULTI_TARGETS tag to YES allow dot to generate multiple output
+# files in one run (i.e. multiple -o and -T options on the command line). This
+# makes dot run faster, but since only newer versions of dot (>1.8.10)
+# support this, this feature is disabled by default.
+
+DOT_MULTI_TARGETS = NO
+
+# If the GENERATE_LEGEND tag is set to YES (the default) Doxygen will
+# generate a legend page explaining the meaning of the various boxes and
+# arrows in the dot generated graphs.
+
+GENERATE_LEGEND = YES
+
+# If the DOT_CLEANUP tag is set to YES (the default) Doxygen will
+# remove the intermediate dot files that are used to generate
+# the various graphs.
+
+DOT_CLEANUP = YES
diff --git a/doc/FRONT.md b/doc/FRONT.md
new file mode 100644
index 0000000..3bc6c4c
--- /dev/null
+++ b/doc/FRONT.md
@@ -0,0 +1,43 @@
+# SDL_kitchensink
+
+## Overview
+
+FFmpeg and SDL2 based library for audio and video playback, written in C99.
+Please see [github.com/katajakasa/SDL_kitchensink](https://github.com/katajakasa/SDL_kitchensink)
+for project details and source code.
+
+Features:
+* Decoding video & audio via FFmpeg
+* Dumping video data on SDL_textures
+* Dumping audio data in the usual mono/stereo interleaved formats
+* Automatic audio and video conversion to SDL2 friendly formats
+* Synchronizing video & audio to clock
+* Seeking forwards and backwards
+* Bitmap & libass subtitle support. No text (srt, sub) support yet.
+
+Note that FFmpeg has a rather complex license. Please take a look at
+[FFmpeg Legal page](http://ffmpeg.org/legal.html) for details.
+
+## License
+
+The MIT License (MIT)
+
+Copyright (c) 2016 Tuomas Virtanen
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
diff --git a/doc/generate.sh b/doc/generate.sh
new file mode 100644
index 0000000..6307434
--- /dev/null
+++ b/doc/generate.sh
@@ -0,0 +1,3 @@
+#!/bin/sh
+
+doxygen Doxyfile \ No newline at end of file
diff --git a/examples/example_audio.c b/examples/example_audio.c
new file mode 100644
index 0000000..9780c26
--- /dev/null
+++ b/examples/example_audio.c
@@ -0,0 +1,152 @@
+#include <kitchensink/kitchensink.h>
+#include <SDL2/SDL.h>
+#include <stdio.h>
+#include <stdbool.h>
+
+/*
+* Requires SDL2 2.0.4 !
+*
+* Note! This example does not do proper error handling etc.
+* It is for example use only!
+*/
+
+#define AUDIOBUFFER_SIZE (16384)
+
+const char *stream_types[] = {
+ "KIT_STREAMTYPE_UNKNOWN",
+ "KIT_STREAMTYPE_VIDEO",
+ "KIT_STREAMTYPE_AUDIO",
+ "KIT_STREAMTYPE_DATA",
+ "KIT_STREAMTYPE_SUBTITLE",
+ "KIT_STREAMTYPE_ATTACHMENT"
+};
+
+int main(int argc, char *argv[]) {
+ int err = 0, ret = 0;
+ const char* filename = NULL;
+
+ // Events
+ bool run = true;
+
+ // Kitchensink
+ Kit_Source *src = NULL;
+ Kit_Player *player = NULL;
+
+ // Audio playback
+ SDL_AudioSpec wanted_spec, audio_spec;
+ SDL_AudioDeviceID audio_dev;
+ char audiobuf[AUDIOBUFFER_SIZE];
+
+ // Get filename to open
+ if(argc != 2) {
+ fprintf(stderr, "Usage: exampleplay <filename>\n");
+ return 0;
+ }
+ filename = argv[1];
+
+ // Init SDL
+ err = SDL_Init(SDL_INIT_AUDIO);
+ if(err != 0) {
+ fprintf(stderr, "Unable to initialize SDL!\n");
+ return 1;
+ }
+
+ err = Kit_Init(KIT_INIT_FORMATS|KIT_INIT_NETWORK);
+ if(err != 0) {
+ fprintf(stderr, "Unable to initialize Kitchensink: %s", Kit_GetError());
+ return 1;
+ }
+
+ // Open up the sourcefile.
+ src = Kit_CreateSourceFromUrl(filename);
+ if(src == NULL) {
+ fprintf(stderr, "Unable to load file '%s': %s\n", filename, Kit_GetError());
+ return 1;
+ }
+
+ // Disable any video and subtitle streams. If we leave these enabled and then don't
+ // clear the buffers for these sometimes, decoding will block.
+ Kit_SetSourceStream(src, KIT_STREAMTYPE_SUBTITLE, -1);
+ Kit_SetSourceStream(src, KIT_STREAMTYPE_VIDEO, -1);
+
+ // Print stream information
+ Kit_StreamInfo sinfo;
+ fprintf(stderr, "Source streams:\n");
+ for(int i = 0; i < Kit_GetSourceStreamCount(src); i++) {
+ err = Kit_GetSourceStreamInfo(src, &sinfo, i);
+ if(err) {
+ fprintf(stderr, "Unable to fetch stream #%d information: %s.\n", i, Kit_GetError());
+ return 1;
+ }
+ fprintf(stderr, " * Stream #%d: %s\n", i, stream_types[sinfo.type]);
+ }
+
+ // Create the player
+ player = Kit_CreatePlayer(src);
+ if(player == NULL) {
+ fprintf(stderr, "Unable to create player: %s\n", Kit_GetError());
+ return 1;
+ }
+
+ // Print some information
+ Kit_PlayerInfo pinfo;
+ Kit_GetPlayerInfo(player, &pinfo);
+
+ if(!pinfo.audio.is_enabled) {
+ fprintf(stderr, "File contains no audio!\n");
+ return 1;
+ }
+
+ fprintf(stderr, "Media information:\n");
+ fprintf(stderr, " * Audio: %s (%s), %dHz, %dch, %db, %s\n",
+ pinfo.acodec,
+ pinfo.acodec_name,
+ pinfo.audio.samplerate,
+ pinfo.audio.channels,
+ pinfo.audio.bytes,
+ pinfo.audio.is_signed ? "signed" : "unsigned");
+
+ // Init audio
+ SDL_memset(&wanted_spec, 0, sizeof(wanted_spec));
+ wanted_spec.freq = pinfo.audio.samplerate;
+ wanted_spec.format = pinfo.audio.format;
+ wanted_spec.channels = pinfo.audio.channels;
+ audio_dev = SDL_OpenAudioDevice(NULL, 0, &wanted_spec, &audio_spec, 0);
+ SDL_PauseAudioDevice(audio_dev, 0);
+
+ // Flush output just in case
+ fflush(stderr);
+
+ // Start playback
+ Kit_PlayerPlay(player);
+
+ while(run) {
+ if(Kit_GetPlayerState(player) == KIT_STOPPED) {
+ run = false;
+ continue;
+ }
+
+ // Refresh audio
+ ret = SDL_GetQueuedAudioSize(audio_dev);
+ if(ret < AUDIOBUFFER_SIZE) {
+ ret = Kit_GetAudioData(player, (unsigned char*)audiobuf, AUDIOBUFFER_SIZE, 0);
+ if(ret > 0) {
+ SDL_LockAudio();
+ SDL_QueueAudio(audio_dev, audiobuf, ret);
+ SDL_UnlockAudio();
+ SDL_PauseAudioDevice(audio_dev, 0);
+ }
+ }
+
+ SDL_Delay(1);
+ }
+
+ SDL_CloseAudioDevice(audio_dev);
+
+ Kit_ClosePlayer(player);
+ Kit_CloseSource(src);
+
+ Kit_Quit();
+ SDL_Quit();
+ return 0;
+}
diff --git a/examples/example_video.c b/examples/example_video.c
new file mode 100644
index 0000000..1f411ca
--- /dev/null
+++ b/examples/example_video.c
@@ -0,0 +1,345 @@
+#include <kitchensink/kitchensink.h>
+#include <SDL2/SDL.h>
+#include <stdio.h>
+#include <stdbool.h>
+
+/*
+* Requires SDL2 2.0.4 !
+*
+* Note! This example does not do proper error handling etc.
+* It is for example use only!
+*/
+
+#define AUDIOBUFFER_SIZE (32768)
+
+
+void render_gui(SDL_Renderer *renderer, double percent) {
+ // Get window size
+ int size_w, size_h;
+ SDL_RenderGetLogicalSize(renderer, &size_w, &size_h);
+
+ // Render progress bar
+ SDL_SetRenderDrawColor(renderer, 50, 50, 50, 255);
+ SDL_Rect progress_border;
+ progress_border.x = 28;
+ progress_border.y = size_h - 61;
+ progress_border.w = size_w - 57;
+ progress_border.h = 22;
+ SDL_RenderFillRect(renderer, &progress_border);
+
+ SDL_SetRenderDrawColor(renderer, 155, 155, 155, 255);
+ SDL_Rect progress_bottom;
+ progress_bottom.x = 30;
+ progress_bottom.y = size_h - 60;
+ progress_bottom.w = size_w - 60;
+ progress_bottom.h = 20;
+ SDL_RenderFillRect(renderer, &progress_bottom);
+
+ SDL_SetRenderDrawColor(renderer, 100, 100, 100, 255);
+ SDL_Rect progress_top;
+ progress_top.x = 30;
+ progress_top.y = size_h - 60;
+ progress_top.w = (size_w - 60) * percent;
+ progress_top.h = 20;
+ SDL_RenderFillRect(renderer, &progress_top);
+}
+
+int main(int argc, char *argv[]) {
+ int err = 0, ret = 0;
+ const char* filename = NULL;
+
+ // Video
+ SDL_Window *window = NULL;
+ SDL_Renderer *renderer = NULL;
+
+ // Events
+ SDL_Event event;
+ bool run = true;
+
+ // Kitchensink
+ Kit_Source *src = NULL;
+ Kit_Player *player = NULL;
+
+ // Audio playback
+ SDL_AudioSpec wanted_spec, audio_spec;
+ SDL_AudioDeviceID audio_dev;
+ char audiobuf[AUDIOBUFFER_SIZE];
+
+ // Get filename to open
+ if(argc != 2) {
+ fprintf(stderr, "Usage: exampleplay <filename>\n");
+ return 0;
+ }
+ filename = argv[1];
+
+ // Init SDL
+ err = SDL_Init(SDL_INIT_VIDEO|SDL_INIT_AUDIO);
+ if(err != 0) {
+ fprintf(stderr, "Unable to initialize SDL2!\n");
+ return 1;
+ }
+
+ // Attempt to acquire opengl driver context
+ SDL_SetHint(SDL_HINT_RENDER_DRIVER, "opengl");
+
+ // Create a resizable window.
+ window = SDL_CreateWindow("Example Player", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 1280, 720, SDL_WINDOW_RESIZABLE);
+ if(window == NULL) {
+ fprintf(stderr, "Unable to create a new window!\n");
+ return 1;
+ }
+
+ // Create an accelerated renderer. Enable vsync, so we don't need to play around with SDL_Delay.
+ renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED|SDL_RENDERER_PRESENTVSYNC);
+ if(window == NULL) {
+ fprintf(stderr, "Unable to create a renderer!\n");
+ return 1;
+ }
+
+ // We want to alphablend textures, so switch that on
+ if(SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_BLEND) < 0) {
+ fprintf(stderr, "Unable to set blendmode!\n");
+ return 1;
+ }
+
+ // Ask for linear texture scaling (better quality)
+ SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "linear");
+
+ // Initialize Kitchensink with network support and all formats.
+ err = Kit_Init(KIT_INIT_FORMATS|KIT_INIT_NETWORK);
+ if(err != 0) {
+ fprintf(stderr, "Unable to initialize Kitchensink: %s", Kit_GetError());
+ return 1;
+ }
+
+ // Open up the sourcefile.
+ // This can be a local file, network url, ...
+ src = Kit_CreateSourceFromUrl(filename);
+ if(src == NULL) {
+ fprintf(stderr, "Unable to load file '%s': %s\n", filename, Kit_GetError());
+ return 1;
+ }
+
+ // Print stream information
+ Kit_StreamInfo sinfo;
+ fprintf(stderr, "Source streams:\n");
+ for(int i = 0; i < Kit_GetSourceStreamCount(src); i++) {
+ err = Kit_GetSourceStreamInfo(src, &sinfo, i);
+ if(err) {
+ fprintf(stderr, "Unable to fetch stream #%d information: %s.\n", i, Kit_GetError());
+ return 1;
+ }
+ fprintf(stderr, " * Stream #%d: %s\n", i, Kit_GetKitStreamTypeString(sinfo.type));
+ }
+
+ // Create the player
+ player = Kit_CreatePlayer(src);
+ if(player == NULL) {
+ fprintf(stderr, "Unable to create player: %s\n", Kit_GetError());
+ return 1;
+ }
+
+ // Print some information
+ Kit_PlayerInfo pinfo;
+ Kit_GetPlayerInfo(player, &pinfo);
+
+ if(!pinfo.video.is_enabled) {
+ fprintf(stderr, "File contains no video!\n");
+ return 1;
+ }
+
+ fprintf(stderr, "Media information:\n");
+ if(pinfo.audio.is_enabled) {
+ fprintf(stderr, " * Audio: %s (%s), %dHz, %dch, %db, %s\n",
+ pinfo.acodec,
+ pinfo.acodec_name,
+ pinfo.audio.samplerate,
+ pinfo.audio.channels,
+ pinfo.audio.bytes,
+ pinfo.audio.is_signed ? "signed" : "unsigned");
+ }
+ fprintf(stderr, " * Video: %s (%s), %dx%d\n",
+ pinfo.vcodec,
+ pinfo.vcodec_name,
+ pinfo.video.width,
+ pinfo.video.height);
+ if(pinfo.subtitle.is_enabled) {
+ fprintf(stderr, " * Subtitle: %s (%s)\n",
+ pinfo.scodec,
+ pinfo.scodec_name);
+ }
+ fprintf(stderr, "Duration: %f seconds\n", Kit_GetPlayerDuration(player));
+
+ // Init audio
+ SDL_memset(&wanted_spec, 0, sizeof(wanted_spec));
+ wanted_spec.freq = pinfo.audio.samplerate;
+ wanted_spec.format = pinfo.audio.format;
+ wanted_spec.channels = pinfo.audio.channels;
+ audio_dev = SDL_OpenAudioDevice(NULL, 0, &wanted_spec, &audio_spec, 0);
+ SDL_PauseAudioDevice(audio_dev, 0);
+
+ // Print some format info
+ fprintf(stderr, "Texture type: %s\n", Kit_GetSDLPixelFormatString(pinfo.video.format));
+ fprintf(stderr, "Audio format: %s\n", Kit_GetSDLAudioFormatString(pinfo.audio.format));
+
+ // Initialize textures
+ SDL_Texture *video_tex = SDL_CreateTexture(
+ renderer,
+ pinfo.video.format,
+ SDL_TEXTUREACCESS_STATIC,
+ pinfo.video.width,
+ pinfo.video.height);
+ if(video_tex == NULL) {
+ fprintf(stderr, "Error while attempting to create a video texture\n");
+ return 1;
+ }
+
+ fflush(stderr);
+
+ // Set logical size for the renderer. This way when we scale, we keep aspect ratio.
+ SDL_RenderSetLogicalSize(renderer, pinfo.video.width, pinfo.video.height);
+
+ // Start playback
+ Kit_PlayerPlay(player);
+
+ // Get movie area size
+ int mouse_x = 0, mouse_y = 0;
+ int size_w = 0, size_h = 0;
+ SDL_RenderGetLogicalSize(renderer, &size_w, &size_h);
+ bool gui_enabled = false;
+ bool fullscreen = false;
+ while(run) {
+ if(Kit_GetPlayerState(player) == KIT_STOPPED) {
+ run = false;
+ continue;
+ }
+
+ // Check for events
+ const Uint8 *state;
+ while(SDL_PollEvent(&event)) {
+ switch(event.type) {
+ case SDL_KEYUP:
+ if(event.key.keysym.sym == SDLK_ESCAPE) {
+ run = false;
+ }
+ if(event.key.keysym.sym == SDLK_q) {
+ // Start or unpause the video
+ Kit_PlayerPlay(player);
+ }
+ if(event.key.keysym.sym == SDLK_w) {
+ // Pause playback
+ Kit_PlayerPause(player);
+ }
+ if(event.key.keysym.sym == SDLK_e) {
+ // Stop playback (will close the window)
+ Kit_PlayerStop(player);
+ }
+ if(event.key.keysym.sym == SDLK_RIGHT) {
+ // Skip 10 seconds forwards or to the end of the file
+ if(Kit_PlayerSeek(player, 10.0) != 0) {
+ fprintf(stderr, "%s\n", Kit_GetError());
+ }
+ }
+ if(event.key.keysym.sym == SDLK_LEFT) {
+ // Seek 10 seconds backwards or to the start of the file
+ if(Kit_PlayerSeek(player, -10.0) != 0) {
+ fprintf(stderr, "%s\n", Kit_GetError());
+ }
+ }
+ break;
+
+ case SDL_KEYDOWN:
+ // Find alt+enter
+ state = SDL_GetKeyboardState(NULL);
+ if(state[SDL_SCANCODE_RETURN] && state[SDL_SCANCODE_LALT]) {
+ if(!fullscreen) {
+ SDL_SetWindowFullscreen(window, SDL_WINDOW_FULLSCREEN_DESKTOP);
+ } else {
+ SDL_SetWindowFullscreen(window, 0);
+ }
+ fullscreen = !fullscreen;
+ }
+ break;
+
+ case SDL_MOUSEMOTION:
+ mouse_x = event.motion.x;
+ mouse_y = event.motion.y;
+ break;
+
+ case SDL_MOUSEBUTTONUP:
+ // Handle user clicking the progress bar
+ if(mouse_x >= 30 && mouse_x <= size_w-30 && mouse_y >= size_h - 60 && mouse_y <= size_h - 40) {
+ double pos = ((double)mouse_x - 30) / ((double)size_w - 60);
+ double m_time = Kit_GetPlayerDuration(player) * pos - Kit_GetPlayerPosition(player);
+ if(Kit_PlayerSeek(player, m_time) != 0) {
+ fprintf(stderr, "%s\n", Kit_GetError());
+ }
+ } else {
+ // Handle pause
+ if(Kit_GetPlayerState(player) == KIT_PAUSED) {
+ Kit_PlayerPlay(player);
+ } else {
+ Kit_PlayerPause(player);
+ }
+ }
+ break;
+
+ case SDL_QUIT:
+ run = false;
+ break;
+ }
+ }
+
+ // Enable GUI if mouse is hovering over the bottom third of the screen
+ int limit = (pinfo.video.height / 3) * 2;
+ gui_enabled = (mouse_y >= limit);
+
+ // Refresh audio
+ if(SDL_GetQueuedAudioSize(audio_dev) < AUDIOBUFFER_SIZE) {
+ int need = AUDIOBUFFER_SIZE - ret;
+
+ SDL_LockAudio();
+ while(need > 0) {
+ ret = Kit_GetAudioData(player, (unsigned char*)audiobuf, AUDIOBUFFER_SIZE, (size_t)SDL_GetQueuedAudioSize(audio_dev));
+ need -= ret;
+ if(ret > 0) {
+ SDL_QueueAudio(audio_dev, audiobuf, ret);
+ } else {
+ break;
+ }
+ }
+ SDL_UnlockAudio();
+ SDL_PauseAudioDevice(audio_dev, 0);
+ }
+
+ // Clear screen with black
+ SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255);
+ SDL_RenderClear(renderer);
+
+ // Refresh videotexture and render it
+ Kit_GetVideoData(player, video_tex);
+ SDL_RenderCopy(renderer, video_tex, NULL, NULL);
+ Kit_GetSubtitleData(player, renderer);
+
+ // Render GUI
+ if(gui_enabled) {
+ double percent = Kit_GetPlayerPosition(player) / Kit_GetPlayerDuration(player);
+ render_gui(renderer, percent);
+ }
+
+ // Render to screen + wait for vsync
+ SDL_RenderPresent(renderer);
+ }
+
+ SDL_DestroyTexture(video_tex);
+ SDL_CloseAudioDevice(audio_dev);
+
+ Kit_ClosePlayer(player);
+ Kit_CloseSource(src);
+
+ Kit_Quit();
+ SDL_DestroyRenderer(renderer);
+ SDL_DestroyWindow(window);
+ SDL_Quit();
+ return 0;
+}
diff --git a/include/kitchensink/internal/kitbuffer.h b/include/kitchensink/internal/kitbuffer.h
new file mode 100644
index 0000000..4d0f8cc
--- /dev/null
+++ b/include/kitchensink/internal/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/kitlibstate.h b/include/kitchensink/internal/kitlibstate.h
new file mode 100644
index 0000000..e16a5c9
--- /dev/null
+++ b/include/kitchensink/internal/kitlibstate.h
@@ -0,0 +1,14 @@
+#ifndef KITLIBSTATE_H
+#define KITLIBSTATE_H
+
+#include <ass/ass.h>
+#include "kitchensink/kitconfig.h"
+
+typedef struct Kit_LibraryState {
+ unsigned int init_flags;
+ ASS_Library *libass_handle;
+} Kit_LibraryState;
+
+KIT_LOCAL Kit_LibraryState* Kit_GetLibraryState();
+
+#endif // KITLIBSTATE_H
diff --git a/include/kitchensink/internal/kitlist.h b/include/kitchensink/internal/kitlist.h
new file mode 100644
index 0000000..85e3e3f
--- /dev/null
+++ b/include/kitchensink/internal/kitlist.h
@@ -0,0 +1,26 @@
+#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/kitringbuffer.h b/include/kitchensink/internal/kitringbuffer.h
new file mode 100644
index 0000000..2f67520
--- /dev/null
+++ b/include/kitchensink/internal/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/kitchensink.h b/include/kitchensink/kitchensink.h
new file mode 100644
index 0000000..be318a5
--- /dev/null
+++ b/include/kitchensink/kitchensink.h
@@ -0,0 +1,11 @@
+#ifndef KITCHENSINK_H
+#define KITCHENSINK_H
+
+#include "kitchensink/kitlib.h"
+#include "kitchensink/kiterror.h"
+#include "kitchensink/kitsource.h"
+#include "kitchensink/kitplayer.h"
+#include "kitchensink/kitutils.h"
+#include "kitchensink/kitconfig.h"
+
+#endif // KITCHENSINK_H
diff --git a/include/kitchensink/kitconfig.h b/include/kitchensink/kitconfig.h
new file mode 100644
index 0000000..e8b2d01
--- /dev/null
+++ b/include/kitchensink/kitconfig.h
@@ -0,0 +1,26 @@
+#ifndef KITCONFIG_H
+#define KITCONFIG_H
+
+#if defined _WIN32 || defined __CYGWIN__
+ #define KIT_DLL_IMPORT __declspec(dllimport)
+ #define KIT_DLL_EXPORT __declspec(dllexport)
+ #define KIT_DLL_LOCAL
+#else
+ #define KIT_DLL_IMPORT __attribute__ ((visibility ("default")))
+ #define KIT_DLL_EXPORT __attribute__ ((visibility ("default")))
+ #define KIT_DLL_LOCAL __attribute__ ((visibility ("hidden")))
+#endif
+
+#ifdef KIT_DLL
+ #ifdef KIT_DLL_EXPORTS
+ #define KIT_API KIT_DLL_EXPORT
+ #else
+ #define KIT_API KIT_DLL_IMPORT
+ #endif
+ #define KIT_LOCAL KIT_DLL_LOCAL
+#else
+ #define KIT_API
+ #define KIT_LOCAL
+#endif
+
+#endif // KITCONFIG_H
diff --git a/include/kitchensink/kiterror.h b/include/kitchensink/kiterror.h
new file mode 100644
index 0000000..824ea8c
--- /dev/null
+++ b/include/kitchensink/kiterror.h
@@ -0,0 +1,18 @@
+#ifndef KITERROR_H
+#define KITERROR_H
+
+#include "kitchensink/kitconfig.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+KIT_API const char* Kit_GetError();
+KIT_API void Kit_SetError(const char* fmt, ...);
+KIT_API void Kit_ClearError();
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif // KITERROR_H
diff --git a/include/kitchensink/kitlib.h b/include/kitchensink/kitlib.h
new file mode 100644
index 0000000..9a827be
--- /dev/null
+++ b/include/kitchensink/kitlib.h
@@ -0,0 +1,33 @@
+#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
+
+typedef struct Kit_Version {
+ unsigned char major;
+ unsigned char minor;
+ unsigned char patch;
+} Kit_Version;
+
+enum {
+ KIT_INIT_FORMATS = 0x1,
+ KIT_INIT_NETWORK = 0x2,
+};
+
+KIT_API int Kit_Init(unsigned int flags);
+KIT_API void Kit_Quit();
+KIT_API void Kit_GetVersion(Kit_Version *version);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif // KITLIB_H
diff --git a/include/kitchensink/kitplayer.h b/include/kitchensink/kitplayer.h
new file mode 100644
index 0000000..b9ea1c7
--- /dev/null
+++ b/include/kitchensink/kitplayer.h
@@ -0,0 +1,128 @@
+#ifndef KITPLAYER_H
+#define KITPLAYER_H
+
+#include "kitchensink/kitsource.h"
+#include "kitchensink/kitconfig.h"
+
+#include <SDL2/SDL_render.h>
+#include <SDL2/SDL_thread.h>
+#include <SDL2/SDL_surface.h>
+
+#include <stdbool.h>
+
+#ifdef __cplusplus
+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.
+ 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 {
+ 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
+ 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
+} Kit_Player;
+
+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_PlayerInfo;
+
+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_Renderer *renderer);
+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);
+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
+
+#endif // KITPLAYER_H
diff --git a/include/kitchensink/kitsource.h b/include/kitchensink/kitsource.h
new file mode 100644
index 0000000..ed1711f
--- /dev/null
+++ b/include/kitchensink/kitsource.h
@@ -0,0 +1,47 @@
+#ifndef KITSOURCE_H
+#define KITSOURCE_H
+
+#include "kitchensink/kitconfig.h"
+
+#ifdef __cplusplus
+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
+ 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; ///< Audio stream index
+ int vstream_idx; ///< Video stream index
+ int sstream_idx; ///< Subtitle stream index
+ void *format_ctx; ///< FFmpeg: Videostream format context
+} Kit_Source;
+
+typedef struct Kit_Stream {
+ int index; ///< Stream index
+ Kit_StreamType type; ///< Stream type
+} Kit_StreamInfo;
+
+KIT_API Kit_Source* Kit_CreateSourceFromUrl(const char *path);
+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);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif // KITSOURCE_H
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
diff --git a/src/kitbuffer.c b/src/kitbuffer.c
new file mode 100644
index 0000000..5c492ea
--- /dev/null
+++ b/src/kitbuffer.c
@@ -0,0 +1,83 @@
+#include "kitchensink/internal/kitbuffer.h"
+
+#include <stdlib.h>
+#include <assert.h>
+
+Kit_Buffer* Kit_CreateBuffer(unsigned int size, Kit_BufferFreeCallback free_cb) {
+ Kit_Buffer *b = calloc(1, sizeof(Kit_Buffer));
+ if(b == NULL) {
+ return NULL;
+ }
+ b->size = size;
+ b->free_cb = free_cb;
+ b->data = calloc(size, sizeof(void*));
+ if(b->data == NULL) {
+ free(b);
+ return NULL;
+ }
+ return b;
+}
+
+void Kit_DestroyBuffer(Kit_Buffer *buffer) {
+ if(buffer == NULL) return;
+ Kit_ClearBuffer(buffer);
+ free(buffer->data);
+ free(buffer);
+}
+
+void Kit_ClearBuffer(Kit_Buffer *buffer) {
+ void *data;
+ while((data = Kit_ReadBuffer(buffer)) != NULL) {
+ buffer->free_cb(data);
+ }
+}
+
+void* Kit_ReadBuffer(Kit_Buffer *buffer) {
+ assert(buffer != NULL);
+ if(buffer->read_p < buffer->write_p) {
+ void *out = buffer->data[buffer->read_p % buffer->size];
+ buffer->data[buffer->read_p % buffer->size] = NULL;
+ buffer->read_p++;
+ if(buffer->read_p >= buffer->size) {
+ buffer->read_p = buffer->read_p % buffer->size;
+ buffer->write_p = buffer->write_p % buffer->size;
+ }
+ return out;
+ }
+ return NULL;
+}
+
+KIT_LOCAL void* Kit_PeekBuffer(const Kit_Buffer *buffer) {
+ assert(buffer != NULL);
+ return buffer->data[buffer->read_p % buffer->size];
+}
+
+KIT_LOCAL void Kit_AdvanceBuffer(Kit_Buffer *buffer) {
+ assert(buffer != NULL);
+ if(buffer->read_p < buffer->write_p) {
+ buffer->data[buffer->read_p % buffer->size] = NULL;
+ buffer->read_p++;
+ if(buffer->read_p >= buffer->size) {
+ buffer->read_p = buffer->read_p % buffer->size;
+ buffer->write_p = buffer->write_p % buffer->size;
+ }
+ }
+}
+
+int Kit_WriteBuffer(Kit_Buffer *buffer, void *ptr) {
+ assert(buffer != NULL);
+ assert(ptr != NULL);
+
+ if(!Kit_IsBufferFull(buffer)) {
+ buffer->data[buffer->write_p % buffer->size] = ptr;
+ buffer->write_p++;
+ return 0;
+ }
+ return 1;
+}
+
+int Kit_IsBufferFull(const Kit_Buffer *buffer) {
+ int len = buffer->write_p - buffer->read_p;
+ int k = (len >= buffer->size);
+ return k;
+}
diff --git a/src/kiterror.c b/src/kiterror.c
new file mode 100644
index 0000000..2c87414
--- /dev/null
+++ b/src/kiterror.c
@@ -0,0 +1,34 @@
+#include "kitchensink/kitchensink.h"
+
+#include <stdlib.h>
+#include <stdarg.h>
+#include <stdio.h>
+#include <stdbool.h>
+#include <assert.h>
+
+#define KIT_ERRBUFSIZE 1024
+
+static char _error_available = false;
+static char _error_message[KIT_ERRBUFSIZE] = "\0";
+
+const char* Kit_GetError() {
+ if(_error_available) {
+ _error_available = false;
+ return _error_message;
+ }
+ return NULL;
+}
+
+void Kit_SetError(const char* fmt, ...) {
+ assert(fmt != NULL);
+ va_list args;
+ va_start(args, fmt);
+ vsnprintf(_error_message, KIT_ERRBUFSIZE, (char*)fmt, args);
+ va_end(args);
+ _error_available = true;
+}
+
+void Kit_ClearError() {
+ _error_message[0] = 0;
+ _error_available = false;
+}
diff --git a/src/kitlib.c b/src/kitlib.c
new file mode 100644
index 0000000..e5f1277
--- /dev/null
+++ b/src/kitlib.c
@@ -0,0 +1,51 @@
+#include "kitchensink/kitchensink.h"
+#include "kitchensink/internal/kitlibstate.h"
+#include <libavformat/avformat.h>
+#include <ass/ass.h>
+#include <assert.h>
+
+// No-op
+void _libass_msg_callback(int level, const char *fmt, va_list va, void *data) {}
+
+int Kit_Init(unsigned int flags) {
+ Kit_LibraryState *state = Kit_GetLibraryState();
+
+ if(state->init_flags != 0) {
+ Kit_SetError("Kitchensink is already initialized.");
+ return 1;
+ }
+ if(flags & KIT_INIT_NETWORK) {
+ avformat_network_init();
+ }
+ if(flags & KIT_INIT_FORMATS) {
+ av_register_all();
+ }
+
+ state->init_flags = flags;
+
+ // Init libass
+ state->libass_handle = ass_library_init();
+
+ // Make libass message spam go away
+ ass_set_message_cb(state->libass_handle, _libass_msg_callback, NULL);
+
+ return 0;
+}
+
+void Kit_Quit() {
+ Kit_LibraryState *state = Kit_GetLibraryState();
+
+ if(state->init_flags & KIT_INIT_NETWORK) {
+ avformat_network_deinit();
+ }
+ state->init_flags = 0;
+
+ ass_library_done(state->libass_handle);
+}
+
+void Kit_GetVersion(Kit_Version *version) {
+ assert(version != NULL);
+ version->major = KIT_VERSION_MAJOR;
+ version->minor = KIT_VERSION_MINOR;
+ version->patch = KIT_VERSION_PATCH;
+}
diff --git a/src/kitlibstate.c b/src/kitlibstate.c
new file mode 100644
index 0000000..0dd4e6b
--- /dev/null
+++ b/src/kitlibstate.c
@@ -0,0 +1,7 @@
+#include "kitchensink/internal/kitlibstate.h"
+
+static Kit_LibraryState _librarystate = {0, NULL};
+
+Kit_LibraryState* Kit_GetLibraryState() {
+ return &_librarystate;
+}
diff --git a/src/kitlist.c b/src/kitlist.c
new file mode 100644
index 0000000..b6d861c
--- /dev/null
+++ b/src/kitlist.c
@@ -0,0 +1,79 @@
+#include "kitchensink/internal/kitlist.h"
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <assert.h>
+
+Kit_List* Kit_CreateList(unsigned int size, Kit_ListFreeCallback free_cb) {
+ Kit_List *m = calloc(1, sizeof(Kit_List));
+ if(m == NULL) {
+ return NULL;
+ }
+ m->size = size;
+ m->free_cb = free_cb;
+ m->data = calloc(size, sizeof(void*));
+ if(m->data == NULL) {
+ free(m);
+ return NULL;
+ }
+ return m;
+}
+
+void Kit_DestroyList(Kit_List *list) {
+ if(list == NULL) return;
+ Kit_ClearList(list);
+ free(list->data);
+ free(list);
+}
+
+void Kit_ClearList(Kit_List *list) {
+ assert(list != NULL);
+ for(unsigned int i = 0; i < list->size; i++) {
+ if(list->data[i] != NULL) {
+ list->free_cb(list->data[i]);
+ list->data[i] = NULL;
+ }
+ }
+ list->length = 0;
+}
+
+void Kit_RemoveFromList(Kit_List *list, unsigned int iterator) {
+ assert(list != NULL);
+ list->free_cb(list->data[iterator-1]);
+ list->data[iterator-1] = NULL;
+ list->length--;
+}
+
+void* Kit_IterateList(const Kit_List *list, unsigned int *iterator) {
+ assert(list != NULL);
+ assert(iterator != NULL);
+ while((*iterator) < list->size) {
+ void *ptr = list->data[(*iterator)];
+ *iterator += 1;
+ if(ptr != NULL) {
+ return ptr;
+ }
+ }
+ return NULL;
+}
+
+int Kit_WriteList(Kit_List *list, void *ptr) {
+ assert(list != NULL);
+ assert(ptr != NULL);
+ if(list->length >= list->size) {
+ return 1;
+ }
+ for(unsigned int i = 0; i < list->size; i++) {
+ if(list->data[i] == NULL) {
+ list->data[i] = ptr;
+ list->length++;
+ return 0;
+ }
+ }
+ return 1;
+}
+
+int Kit_GetListLength(const Kit_List *list) {
+ assert(list != NULL);
+ return list->length;
+}
diff --git a/src/kitplayer.c b/src/kitplayer.c
new file mode 100644
index 0000000..9f8a963
--- /dev/null
+++ b/src/kitplayer.c
@@ -0,0 +1,1498 @@
+#include "kitchensink/kitplayer.h"
+#include "kitchensink/kiterror.h"
+#include "kitchensink/internal/kitbuffer.h"
+#include "kitchensink/internal/kitringbuffer.h"
+#include "kitchensink/internal/kitlist.h"
+#include "kitchensink/internal/kitlibstate.h"
+
+#include <libavcodec/avcodec.h>
+#include <libavformat/avformat.h>
+#include <libswscale/swscale.h>
+#include <libswresample/swresample.h>
+#include <libavutil/pixfmt.h>
+#include <libavutil/time.h>
+#include <libavutil/samplefmt.h>
+#include <libavutil/avstring.h>
+#include <libavutil/imgutils.h>
+
+#include <SDL2/SDL.h>
+#include <ass/ass.h>
+
+#include <stdlib.h>
+#include <string.h>
+#include <assert.h>
+#include <math.h>
+#define __STDC_FORMAT_MACROS
+#include <inttypes.h>
+
+// For compatibility
+#ifndef ASS_FONTPROVIDER_AUTODETECT
+#define ASS_FONTPROVIDER_AUTODETECT 1
+#endif
+
+// Threshold is in seconds
+#define VIDEO_SYNC_THRESHOLD 0.01
+#define AUDIO_SYNC_THRESHOLD 0.05
+
+// Buffersizes
+#define KIT_VBUFFERSIZE 3
+#define KIT_ABUFFERSIZE 64
+#define KIT_CBUFFERSIZE 8
+#define KIT_SBUFFERSIZE 512
+
+typedef enum Kit_ControlPacketType {
+ KIT_CONTROL_SEEK,
+ KIT_CONTROL_FLUSH
+} Kit_ControlPacketType;
+
+typedef struct Kit_VideoPacket {
+ double pts;
+ AVFrame *frame;
+} Kit_VideoPacket;
+
+typedef struct Kit_AudioPacket {
+ double pts;
+ size_t original_size;
+ Kit_RingBuffer *rb;
+} Kit_AudioPacket;
+
+typedef struct Kit_ControlPacket {
+ Kit_ControlPacketType type;
+ double value1;
+} Kit_ControlPacket;
+
+typedef struct Kit_SubtitlePacket {
+ double pts_start;
+ double pts_end;
+ SDL_Rect *rect;
+ SDL_Surface *surface;
+ SDL_Texture *texture;
+} Kit_SubtitlePacket;
+
+static int _InitCodecs(Kit_Player *player, const Kit_Source *src) {
+ assert(player != NULL);
+ assert(src != NULL);
+
+ AVCodecContext *acodec_ctx = NULL;
+ AVCodecContext *vcodec_ctx = NULL;
+ AVCodecContext *scodec_ctx = NULL;
+ AVCodec *acodec = NULL;
+ AVCodec *vcodec = NULL;
+ AVCodec *scodec = NULL;
+ AVFormatContext *format_ctx = (AVFormatContext *)src->format_ctx;
+
+ // Make sure index seems correct
+ if(src->astream_idx >= (int)format_ctx->nb_streams) {
+ Kit_SetError("Invalid audio stream index: %d", src->astream_idx);
+ goto exit_0;
+ } else if(src->astream_idx >= 0) {
+ // Find audio decoder
+ acodec = avcodec_find_decoder(format_ctx->streams[src->astream_idx]->codec->codec_id);
+ if(!acodec) {
+ Kit_SetError("No suitable audio decoder found");
+ goto exit_0;
+ }
+
+ // Copy the original audio codec context
+ acodec_ctx = avcodec_alloc_context3(acodec);
+ if(avcodec_copy_context(acodec_ctx, format_ctx->streams[src->astream_idx]->codec) != 0) {
+ Kit_SetError("Unable to copy audio codec context");
+ goto exit_0;
+ }
+
+ // Create an audio decoder context
+ if(avcodec_open2(acodec_ctx, acodec, NULL) < 0) {
+ Kit_SetError("Unable to allocate audio codec context");
+ goto exit_1;
+ }
+ }
+
+ // Make sure index seems correct
+ if(src->vstream_idx >= (int)format_ctx->nb_streams) {
+ Kit_SetError("Invalid video stream index: %d", src->vstream_idx);
+ goto exit_2;
+ } else if(src->vstream_idx >= 0) {
+ // Find video decoder
+ vcodec = avcodec_find_decoder(format_ctx->streams[src->vstream_idx]->codec->codec_id);
+ if(!vcodec) {
+ Kit_SetError("No suitable video decoder found");
+ goto exit_2;
+ }
+
+ // Copy the original video codec context
+ vcodec_ctx = avcodec_alloc_context3(vcodec);
+ if(avcodec_copy_context(vcodec_ctx, format_ctx->streams[src->vstream_idx]->codec) != 0) {
+ Kit_SetError("Unable to copy video codec context");
+ goto exit_2;
+ }
+
+ // Create a video decoder context
+ if(avcodec_open2(vcodec_ctx, vcodec, NULL) < 0) {
+ Kit_SetError("Unable to allocate video codec context");
+ goto exit_3;
+ }
+ }
+
+ if(src->sstream_idx >= (int)format_ctx->nb_streams) {
+ Kit_SetError("Invalid subtitle stream index: %d", src->sstream_idx);
+ goto exit_2;
+ } else if(src->sstream_idx >= 0) {
+ // Find subtitle decoder
+ scodec = avcodec_find_decoder(format_ctx->streams[src->sstream_idx]->codec->codec_id);
+ if(!scodec) {
+ Kit_SetError("No suitable subtitle decoder found");
+ goto exit_4;
+ }
+
+ // Copy the original subtitle codec context
+ scodec_ctx = avcodec_alloc_context3(scodec);
+ if(avcodec_copy_context(scodec_ctx, format_ctx->streams[src->sstream_idx]->codec) != 0) {
+ Kit_SetError("Unable to copy subtitle codec context");
+ goto exit_4;
+ }
+
+ // Create a subtitle decoder context
+ if(avcodec_open2(scodec_ctx, scodec, NULL) < 0) {
+ Kit_SetError("Unable to allocate subtitle codec context");
+ goto exit_5;
+ }
+ }
+
+ player->acodec_ctx = acodec_ctx;
+ player->vcodec_ctx = vcodec_ctx;
+ player->scodec_ctx = scodec_ctx;
+ player->src = src;
+ return 0;
+
+exit_5:
+ avcodec_free_context(&scodec_ctx);
+exit_4:
+ avcodec_close(vcodec_ctx);
+exit_3:
+ avcodec_free_context(&vcodec_ctx);
+exit_2:
+ avcodec_close(acodec_ctx);
+exit_1:
+ avcodec_free_context(&acodec_ctx);
+exit_0:
+ return 1;
+}
+
+static int reset_libass_track(Kit_Player *player) {
+ AVCodecContext *scodec_ctx = player->scodec_ctx;
+
+ if(scodec_ctx == NULL) {
+ return 0;
+ }
+
+ // Flush libass track events
+ ass_flush_events(player->ass_track);
+ return 0;
+}
+
+static void _FindPixelFormat(enum AVPixelFormat fmt, unsigned int *out_fmt) {
+ switch(fmt) {
+ case AV_PIX_FMT_YUV420P9:
+ case AV_PIX_FMT_YUV420P10:
+ case AV_PIX_FMT_YUV420P12:
+ case AV_PIX_FMT_YUV420P14:
+ case AV_PIX_FMT_YUV420P16:
+ case AV_PIX_FMT_YUV420P:
+ *out_fmt = SDL_PIXELFORMAT_YV12;
+ break;
+ case AV_PIX_FMT_YUYV422:
+ *out_fmt = SDL_PIXELFORMAT_YUY2;
+ break;
+ case AV_PIX_FMT_UYVY422:
+ *out_fmt = SDL_PIXELFORMAT_UYVY;
+ break;
+ default:
+ *out_fmt = SDL_PIXELFORMAT_ABGR8888;
+ break;
+ }
+}
+
+static void _FindAudioFormat(enum AVSampleFormat fmt, int *bytes, bool *is_signed, unsigned int *format) {
+ switch(fmt) {
+ case AV_SAMPLE_FMT_U8:
+ *bytes = 1;
+ *is_signed = false;
+ *format = AUDIO_U8;
+ break;
+ case AV_SAMPLE_FMT_S16:
+ *bytes = 2;
+ *is_signed = true;
+ *format = AUDIO_S16SYS;
+ break;
+ case AV_SAMPLE_FMT_S32:
+ *bytes = 4;
+ *is_signed = true;
+ *format = AUDIO_S32SYS;
+ break;
+ default:
+ *bytes = 2;
+ *is_signed = true;
+ *format = AUDIO_S16SYS;
+ break;
+ }
+}
+
+static enum AVPixelFormat _FindAVPixelFormat(unsigned int fmt) {
+ switch(fmt) {
+ case SDL_PIXELFORMAT_IYUV: return AV_PIX_FMT_YUV420P;
+ case SDL_PIXELFORMAT_YV12: return AV_PIX_FMT_YUV420P;
+ case SDL_PIXELFORMAT_YUY2: return AV_PIX_FMT_YUYV422;
+ case SDL_PIXELFORMAT_UYVY: return AV_PIX_FMT_UYVY422;
+ case SDL_PIXELFORMAT_ARGB8888: return AV_PIX_FMT_BGRA;
+ case SDL_PIXELFORMAT_ABGR8888: return AV_PIX_FMT_RGBA;
+ default:
+ return AV_PIX_FMT_NONE;
+ }
+}
+
+static enum AVSampleFormat _FindAVSampleFormat(int format) {
+ switch(format) {
+ case AUDIO_U8: return AV_SAMPLE_FMT_U8;
+ case AUDIO_S16SYS: return AV_SAMPLE_FMT_S16;
+ case AUDIO_S32SYS: return AV_SAMPLE_FMT_S32;
+ default:
+ return AV_SAMPLE_FMT_NONE;
+ }
+}
+
+static unsigned int _FindAVChannelLayout(int channels) {
+ switch(channels) {
+ case 1: return AV_CH_LAYOUT_MONO;
+ case 2: return AV_CH_LAYOUT_STEREO;
+ case 4: return AV_CH_LAYOUT_QUAD;
+ case 6: return AV_CH_LAYOUT_5POINT1;
+ default: return AV_CH_LAYOUT_STEREO_DOWNMIX;
+ }
+}
+
+static Kit_VideoPacket* _CreateVideoPacket(AVFrame *frame, double pts) {
+ Kit_VideoPacket *p = calloc(1, sizeof(Kit_VideoPacket));
+ p->frame = frame;
+ p->pts = pts;
+ return p;
+}
+
+static void _FreeVideoPacket(void *ptr) {
+ Kit_VideoPacket *packet = ptr;
+ av_freep(&packet->frame->data[0]);
+ av_frame_free(&packet->frame);
+ free(packet);
+}
+
+static Kit_AudioPacket* _CreateAudioPacket(const char* data, size_t len, double pts) {
+ Kit_AudioPacket *p = calloc(1, sizeof(Kit_AudioPacket));
+ p->rb = Kit_CreateRingBuffer(len);
+ Kit_WriteRingBuffer(p->rb, data, len);
+ p->pts = pts;
+ return p;
+}
+
+static void _FreeAudioPacket(void *ptr) {
+ Kit_AudioPacket *packet = ptr;
+ Kit_DestroyRingBuffer(packet->rb);
+ free(packet);
+}
+
+static Kit_ControlPacket* _CreateControlPacket(Kit_ControlPacketType type, double value1) {
+ Kit_ControlPacket *p = calloc(1, sizeof(Kit_ControlPacket));
+ p->type = type;
+ p->value1 = value1;
+ return p;
+}
+
+static void _FreeControlPacket(void *ptr) {
+ Kit_ControlPacket *packet = ptr;
+ free(packet);
+}
+
+
+static Kit_SubtitlePacket* _CreateSubtitlePacket(double pts_start, double pts_end, SDL_Rect *rect, SDL_Surface *surface) {
+ Kit_SubtitlePacket *p = calloc(1, sizeof(Kit_SubtitlePacket));
+ p->pts_start = pts_start;
+ p->pts_end = pts_end;
+ p->surface = surface;
+ p->rect = rect;
+ p->texture = NULL; // Cached texture
+ return p;
+}
+
+static void _FreeSubtitlePacket(void *ptr) {
+ Kit_SubtitlePacket *packet = ptr;
+ SDL_FreeSurface(packet->surface);
+ if(packet->texture) {
+ SDL_DestroyTexture(packet->texture);
+ }
+ free(packet->rect);
+ free(packet);
+}
+
+static double _GetSystemTime() {
+ return (double)av_gettime() / 1000000.0;
+}
+
+static void _HandleVideoPacket(Kit_Player *player, AVPacket *packet) {
+ assert(player != NULL);
+ assert(packet != NULL);
+
+ int frame_finished;
+ AVCodecContext *vcodec_ctx = (AVCodecContext*)player->vcodec_ctx;
+ AVFormatContext *fmt_ctx = (AVFormatContext *)player->src->format_ctx;
+ AVFrame *iframe = player->tmp_vframe;
+
+ while(packet->size > 0) {
+ int len = avcodec_decode_video2(vcodec_ctx, player->tmp_vframe, &frame_finished, packet);
+ if(len < 0) {
+ return;
+ }
+
+ if(frame_finished) {
+ // Target frame
+ AVFrame *oframe = av_frame_alloc();
+ av_image_alloc(
+ oframe->data,
+ oframe->linesize,
+ vcodec_ctx->width,
+ vcodec_ctx->height,
+ _FindAVPixelFormat(player->vformat.format),
+ 1);
+
+ // Scale from source format to target format, don't touch the size
+ sws_scale(
+ (struct SwsContext *)player->sws,
+ (const unsigned char * const *)iframe->data,
+ iframe->linesize,
+ 0,
+ vcodec_ctx->height,
+ oframe->data,
+ oframe->linesize);
+
+ // Get pts
+ double pts = 0;
+ if(packet->dts != AV_NOPTS_VALUE) {
+ pts = av_frame_get_best_effort_timestamp(player->tmp_vframe);
+ pts *= av_q2d(fmt_ctx->streams[player->src->vstream_idx]->time_base);
+ }
+
+ // Just seeked, set sync clock & pos.
+ if(player->seek_flag == 1) {
+ player->vclock_pos = pts;
+ player->clock_sync = _GetSystemTime() - pts;
+ player->seek_flag = 0;
+ }
+
+ // Lock, write to audio buffer, unlock
+ Kit_VideoPacket *vpacket = _CreateVideoPacket(oframe, pts);
+ bool done = false;
+ if(SDL_LockMutex(player->vmutex) == 0) {
+ if(Kit_WriteBuffer((Kit_Buffer*)player->vbuffer, vpacket) == 0) {
+ done = true;
+ }
+ SDL_UnlockMutex(player->vmutex);
+ }
+
+ // Unable to write packet, free it.
+ if(!done) {
+ _FreeVideoPacket(vpacket);
+ }
+ }
+ packet->size -= len;
+ packet->data += len;
+ }
+}
+
+static void _HandleAudioPacket(Kit_Player *player, AVPacket *packet) {
+ assert(player != NULL);
+ assert(packet != NULL);
+
+ int frame_finished;
+ int len, len2;
+ int dst_linesize;
+ int dst_nb_samples, dst_bufsize;
+ unsigned char **dst_data;
+ AVCodecContext *acodec_ctx = (AVCodecContext*)player->acodec_ctx;
+ AVFormatContext *fmt_ctx = (AVFormatContext *)player->src->format_ctx;
+ struct SwrContext *swr = (struct SwrContext *)player->swr;
+ AVFrame *aframe = (AVFrame*)player->tmp_aframe;
+
+ while(packet->size > 0) {
+ len = avcodec_decode_audio4(acodec_ctx, aframe, &frame_finished, packet);
+ if(len < 0) {
+ return;
+ }
+
+ if(frame_finished) {
+ dst_nb_samples = av_rescale_rnd(
+ aframe->nb_samples,
+ player->aformat.samplerate,
+ acodec_ctx->sample_rate,
+ AV_ROUND_UP);
+
+ av_samples_alloc_array_and_samples(
+ &dst_data,
+ &dst_linesize,
+ player->aformat.channels,
+ dst_nb_samples,
+ _FindAVSampleFormat(player->aformat.format),
+ 0);
+
+ len2 = swr_convert(
+ swr,
+ dst_data,
+ aframe->nb_samples,
+ (const unsigned char **)aframe->extended_data,
+ aframe->nb_samples);
+
+ dst_bufsize = av_samples_get_buffer_size(
+ &dst_linesize,
+ player->aformat.channels,
+ len2,
+ _FindAVSampleFormat(player->aformat.format), 1);
+
+ // Get pts
+ double pts = 0;
+ if(packet->dts != AV_NOPTS_VALUE) {
+ pts = av_frame_get_best_effort_timestamp(player->tmp_aframe);
+ pts *= av_q2d(fmt_ctx->streams[player->src->astream_idx]->time_base);
+ }
+
+ // Just seeked, set sync clock & pos.
+ if(player->seek_flag == 1) {
+ player->vclock_pos = pts;
+ player->clock_sync = _GetSystemTime() - pts;
+ player->seek_flag = 0;
+ }
+
+ // Lock, write to audio buffer, unlock
+ Kit_AudioPacket *apacket = _CreateAudioPacket((char*)dst_data[0], (size_t)dst_bufsize, pts);
+ bool done = false;
+ if(SDL_LockMutex(player->amutex) == 0) {
+ if(Kit_WriteBuffer((Kit_Buffer*)player->abuffer, apacket) == 0) {
+ done = true;
+ }
+ SDL_UnlockMutex(player->amutex);
+ }
+
+ // Couldn't write packet, free memory
+ if(!done) {
+ _FreeAudioPacket(apacket);
+ }
+
+ av_freep(&dst_data[0]);
+ av_freep(&dst_data);
+ }
+
+ packet->size -= len;
+ packet->data += len;
+ }
+}
+
+static void _HandleBitmapSubtitle(Kit_SubtitlePacket** spackets, int *n, Kit_Player *player, double pts, AVSubtitle *sub, AVSubtitleRect *rect) {
+ if(rect->nb_colors == 256) {
+ // Paletted image based subtitles. Convert and set palette.
+ SDL_Surface *s = SDL_CreateRGBSurfaceFrom(
+ rect->data[0],
+ rect->w, rect->h, 8,
+ rect->linesize[0],
+ 0, 0, 0, 0);
+
+ SDL_SetPaletteColors(s->format->palette, (SDL_Color*)rect->data[1], 0, 256);
+
+ Uint32 rmask, gmask, bmask, amask;
+ #if SDL_BYTEORDER == SDL_BIG_ENDIAN
+ rmask = 0xff000000;
+ gmask = 0x00ff0000;
+ bmask = 0x0000ff00;
+ amask = 0x000000ff;
+ #else
+ rmask = 0x000000ff;
+ gmask = 0x0000ff00;
+ bmask = 0x00ff0000;
+ amask = 0xff000000;
+ #endif
+ SDL_Surface *tmp = SDL_CreateRGBSurface(
+ 0, rect->w, rect->h, 32,
+ rmask, gmask, bmask, amask);
+ SDL_BlitSurface(s, NULL, tmp, NULL);
+ SDL_FreeSurface(s);
+
+ SDL_Rect *dst_rect = malloc(sizeof(SDL_Rect));
+ dst_rect->x = rect->x;
+ dst_rect->y = rect->y;
+ dst_rect->w = rect->w;
+ dst_rect->h = rect->h;
+
+ double start = pts + (sub->start_display_time / 1000.0f);
+ double end = -1;
+ if(sub->end_display_time < UINT_MAX) {
+ end = pts + (sub->end_display_time / 1000.0f);
+ }
+
+ spackets[(*n)++] = _CreateSubtitlePacket(start, end, dst_rect, tmp);
+ }
+}
+
+static void _ProcessAssSubtitleRect(Kit_Player *player, AVSubtitleRect *rect) {
+ ass_process_data((ASS_Track*)player->ass_track, rect->ass, strlen(rect->ass));
+}
+
+static void _ProcessAssImage(SDL_Surface *surface, const ASS_Image *img) {
+ int x, y;
+ // libass headers claim img->color is RGBA, but the alpha is 0.
+ unsigned char r = ((img->color) >> 24) & 0xFF;
+ unsigned char g = ((img->color) >> 16) & 0xFF;
+ unsigned char b = ((img->color) >> 8) & 0xFF;
+ unsigned char *src = img->bitmap;
+ unsigned char *dst = (unsigned char*)surface->pixels;
+
+ for(y = 0; y < img->h; y++) {
+ for(x = 0; x < img->w; x++) {
+ dst[x * 4 + 0] = r;
+ dst[x * 4 + 1] = g;
+ dst[x * 4 + 2] = b;
+ dst[x * 4 + 3] = src[x];
+ }
+ src += img->stride;
+ dst += surface->pitch;
+ }
+}
+
+static void _HandleAssSubtitle(Kit_SubtitlePacket** spackets, int *n, Kit_Player *player, double pts, AVSubtitle *sub) {
+ double start = pts + (sub->start_display_time / 1000.0f);
+ double end = pts + (sub->end_display_time / 1000.0f);
+
+ // Process current chunk of data
+ unsigned int now = start * 1000;
+ int change = 0;
+ ASS_Image *images = ass_render_frame((ASS_Renderer*)player->ass_renderer, (ASS_Track*)player->ass_track, now, &change);
+
+ // Convert to SDL_Surfaces
+ if(change > 0) {
+ ASS_Image *now = images;
+ if(now != NULL) {
+ do {
+ Uint32 rmask, gmask, bmask, amask;
+ #if SDL_BYTEORDER == SDL_BIG_ENDIAN
+ rmask = 0xff000000;
+ gmask = 0x00ff0000;
+ bmask = 0x0000ff00;
+ amask = 0x000000ff;
+ #else
+ rmask = 0x000000ff;
+ gmask = 0x0000ff00;
+ bmask = 0x00ff0000;
+ amask = 0xff000000;
+ #endif
+ SDL_Surface *tmp = SDL_CreateRGBSurface(
+ 0, now->w, now->h, 32,
+ rmask, gmask, bmask, amask);
+
+ _ProcessAssImage(tmp, now);
+
+ SDL_Rect *dst_rect = malloc(sizeof(SDL_Rect));
+ dst_rect->x = now->dst_x;
+ dst_rect->y = now->dst_y;
+ dst_rect->w = now->w;
+ dst_rect->h = now->h;
+
+ spackets[(*n)++] = _CreateSubtitlePacket(start, end, dst_rect, tmp);
+ } while((now = now->next) != NULL);
+ }
+ }
+}
+
+static void _HandleSubtitlePacket(Kit_Player *player, AVPacket *packet) {
+ assert(player != NULL);
+ assert(packet != NULL);
+
+ int frame_finished;
+ int len;
+ AVCodecContext *scodec_ctx = (AVCodecContext*)player->scodec_ctx;
+ AVFormatContext *fmt_ctx = (AVFormatContext *)player->src->format_ctx;
+ Kit_SubtitlePacket *tmp = NULL;
+ unsigned int it;
+ AVSubtitle sub;
+ memset(&sub, 0, sizeof(AVSubtitle));
+
+ if(packet->size > 0) {
+ len = avcodec_decode_subtitle2(scodec_ctx, &sub, &frame_finished, packet);
+ if(len < 0) {
+ return;
+ }
+
+ if(frame_finished) {
+ // Get pts
+ double pts = 0;
+ if(packet->dts != AV_NOPTS_VALUE) {
+ pts = packet->pts;
+ pts *= av_q2d(fmt_ctx->streams[player->src->sstream_idx]->time_base);
+ }
+
+ // Convert subtitles to SDL_Surface and create a packet
+ Kit_SubtitlePacket *spackets[KIT_SBUFFERSIZE];
+ memset(spackets, 0, sizeof(Kit_SubtitlePacket*) * KIT_SBUFFERSIZE);
+
+ int n = 0;
+ bool has_ass = false;
+ for(int r = 0; r < sub.num_rects; r++) {
+ switch(sub.rects[r]->type) {
+ case SUBTITLE_BITMAP:
+ _HandleBitmapSubtitle(spackets, &n, player, pts, &sub, sub.rects[r]);
+ break;
+ case SUBTITLE_ASS:
+ _ProcessAssSubtitleRect(player, sub.rects[r]);
+ has_ass = true;
+ break;
+ case SUBTITLE_TEXT:
+ break;
+ case SUBTITLE_NONE:
+ break;
+ }
+ }
+
+ // Process libass content
+ if(has_ass) {
+ _HandleAssSubtitle(spackets, &n, player, pts, &sub);
+ }
+
+ // Lock, write to subtitle buffer, unlock
+ if(SDL_LockMutex(player->smutex) == 0) {
+ if(has_ass) {
+ Kit_ClearList((Kit_List*)player->sbuffer);
+ } else {
+ // Clear out old subtitles that should only be valid until next (this) subtitle
+ it = 0;
+ while((tmp = Kit_IterateList((Kit_List*)player->sbuffer, &it)) != NULL) {
+ if(tmp->pts_end < 0) {
+ Kit_RemoveFromList((Kit_List*)player->sbuffer, it);
+ }
+ }
+ }
+
+ // Add new subtitle
+ for(int i = 0; i < KIT_SBUFFERSIZE; i++) {
+ Kit_SubtitlePacket *spacket = spackets[i];
+ if(spacket != NULL) {
+ if(Kit_WriteList((Kit_List*)player->sbuffer, spacket) == 0) {
+ spackets[i] = NULL;
+ }
+ }
+ }
+
+ // Unlock subtitle buffer
+ SDL_UnlockMutex(player->smutex);
+ }
+
+ // Couldn't write packet, free memory
+ for(int i = 0; i < KIT_SBUFFERSIZE; i++) {
+ if(spackets[i] != NULL) {
+ _FreeSubtitlePacket(spackets[i]);
+ }
+ }
+ }
+ }
+}
+
+static void _HandlePacket(Kit_Player *player, AVPacket *packet) {
+ // Check if this is a packet we need to handle and pass it on
+ if(player->vcodec_ctx != NULL && packet->stream_index == player->src->vstream_idx) {
+ _HandleVideoPacket(player, packet);
+ }
+ else if(player->acodec_ctx != NULL && packet->stream_index == player->src->astream_idx) {
+ _HandleAudioPacket(player, packet);
+ }
+ else if(player->scodec_ctx != NULL && packet->stream_index == player->src->sstream_idx) {
+ _HandleSubtitlePacket(player, packet);
+ }
+}
+
+static void _HandleFlushCommand(Kit_Player *player, Kit_ControlPacket *packet) {
+ if(player->abuffer != NULL) {
+ if(SDL_LockMutex(player->amutex) == 0) {
+ Kit_ClearBuffer((Kit_Buffer*)player->abuffer);
+ SDL_UnlockMutex(player->amutex);
+ }
+ }
+ if(player->vbuffer != NULL) {
+ if(SDL_LockMutex(player->vmutex) == 0) {
+ Kit_ClearBuffer((Kit_Buffer*)player->vbuffer);
+ SDL_UnlockMutex(player->vmutex);
+ }
+ }
+ if(player->sbuffer != NULL) {
+ if(SDL_LockMutex(player->smutex) == 0) {
+ Kit_ClearList((Kit_List*)player->sbuffer);
+ SDL_UnlockMutex(player->smutex);
+ }
+ }
+ reset_libass_track(player);
+}
+
+static void _HandleSeekCommand(Kit_Player *player, Kit_ControlPacket *packet) {
+ AVFormatContext *fmt_ctx = (AVFormatContext *)player->src->format_ctx;
+
+ // Find and limit absolute position
+ double seek = packet->value1;
+ double duration = Kit_GetPlayerDuration(player);
+ if(player->vclock_pos + seek <= 0) {
+ seek = -player->vclock_pos;
+ }
+ if(player->vclock_pos + seek >= duration) {
+ seek = duration - player->vclock_pos;
+ }
+ double absolute_pos = player->vclock_pos + seek;
+ int64_t seek_target = absolute_pos * AV_TIME_BASE;
+
+ // Seek to timestamp.
+ avformat_seek_file(fmt_ctx, -1, INT64_MIN, seek_target, INT64_MAX, 0);
+ if(player->vcodec_ctx != NULL)
+ avcodec_flush_buffers(player->vcodec_ctx);
+ if(player->acodec_ctx != NULL)
+ avcodec_flush_buffers(player->acodec_ctx);
+
+ // On first packet, set clock and current position
+ player->seek_flag = 1;
+}
+
+static void _HandleControlPacket(Kit_Player *player, Kit_ControlPacket *packet) {
+ switch(packet->type) {
+ case KIT_CONTROL_FLUSH:
+ _HandleFlushCommand(player, packet);
+ break;
+ case KIT_CONTROL_SEEK:
+ _HandleSeekCommand(player, packet);
+ break;
+ }
+}
+
+// Return 0 if stream is good but nothing else to do for now
+// Return -1 if there is still work to be done
+// Return 1 if there was an error or stream end
+static int _UpdatePlayer(Kit_Player *player) {
+ assert(player != NULL);
+
+ AVFormatContext *format_ctx = (AVFormatContext*)player->src->format_ctx;
+
+ // Handle control queue
+ if(SDL_LockMutex(player->cmutex) == 0) {
+ Kit_ControlPacket *cpacket;
+ while((cpacket = (Kit_ControlPacket*)Kit_ReadBuffer(player->cbuffer)) != NULL) {
+ _HandleControlPacket(player, cpacket);
+ _FreeControlPacket(cpacket);
+ }
+ SDL_UnlockMutex(player->cmutex);
+ }
+
+ // If either 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 :)
+ if(player->vcodec_ctx != NULL) {
+ if(SDL_LockMutex(player->vmutex) == 0) {
+ int ret = Kit_IsBufferFull(player->vbuffer);
+ SDL_UnlockMutex(player->vmutex);
+ if(ret == 1) {
+ return 0;
+ }
+ }
+ }
+ if(player->acodec_ctx != NULL) {
+ if(SDL_LockMutex(player->amutex) == 0) {
+ int ret = Kit_IsBufferFull(player->abuffer);
+ SDL_UnlockMutex(player->amutex);
+ if(ret == 1) {
+ return 0;
+ }
+ }
+ }
+
+ // Attempt to read frame. Just return here if it fails.
+ AVPacket packet;
+ if(av_read_frame(format_ctx, &packet) < 0) {
+ return 1;
+ }
+ _HandlePacket(player, &packet);
+ av_packet_unref(&packet);
+ return -1;
+}
+
+static int _DecoderThread(void *ptr) {
+ Kit_Player *player = (Kit_Player*)ptr;
+ bool is_running = true;
+ bool is_playing = true;
+ int ret;
+
+ while(is_running) {
+ if(player->state == KIT_CLOSED) {
+ is_running = false;
+ continue;
+ }
+ if(player->state == KIT_PLAYING) {
+ is_playing = true;
+ }
+ while(is_running && is_playing) {
+ if(player->state == KIT_CLOSED) {
+ is_running = false;
+ continue;
+ }
+ if(player->state == KIT_STOPPED) {
+ is_playing = false;
+ continue;
+ }
+
+ // Get more data from demuxer, decode. Wait a bit if there's no more work for now.
+ ret = _UpdatePlayer(player);
+ if(ret == 1) {
+ player->state = KIT_STOPPED;
+ } else if(ret == 0) {
+ SDL_Delay(1);
+ }
+ }
+
+ // Just idle while waiting for work.
+ SDL_Delay(10);
+ }
+
+ return 0;
+}
+
+static const char * const font_mime[] = {
+ "application/x-font-ttf",
+ "application/x-font-truetype",
+ "application/x-truetype-font",
+ "application/x-font-opentype",
+ "application/vnd.ms-opentype",
+ "application/font-sfnt",
+ NULL
+};
+
+static bool attachment_is_font(AVStream *stream) {
+ AVDictionaryEntry *tag = av_dict_get(stream->metadata, "mimetype", NULL, AV_DICT_MATCH_CASE);
+ if(tag) {
+ for(int n = 0; font_mime[n]; n++) {
+ if(av_strcasecmp(font_mime[n], tag->value) == 0) {
+ return true;
+ }
+ }
+ }
+ return false;
+}
+
+Kit_Player* Kit_CreatePlayer(const Kit_Source *src) {
+ assert(src != NULL);
+
+ Kit_Player *player = calloc(1, sizeof(Kit_Player));
+ if(player == NULL) {
+ Kit_SetError("Unable to allocate player");
+ return NULL;
+ }
+
+ AVCodecContext *acodec_ctx = NULL;
+ AVCodecContext *vcodec_ctx = NULL;
+ AVCodecContext *scodec_ctx = NULL;
+
+ // Initialize codecs
+ if(_InitCodecs(player, src) != 0) {
+ goto error;
+ }
+
+ // Init audio codec information if audio codec is initialized
+ acodec_ctx = (AVCodecContext*)player->acodec_ctx;
+ if(acodec_ctx != NULL) {
+ player->aformat.samplerate = acodec_ctx->sample_rate;
+ player->aformat.channels = acodec_ctx->channels > 2 ? 2 : acodec_ctx->channels;
+ player->aformat.is_enabled = true;
+ player->aformat.stream_idx = src->astream_idx;
+ _FindAudioFormat(acodec_ctx->sample_fmt, &player->aformat.bytes, &player->aformat.is_signed, &player->aformat.format);
+
+ player->swr = swr_alloc_set_opts(
+ NULL,
+ _FindAVChannelLayout(player->aformat.channels), // Target channel layout
+ _FindAVSampleFormat(player->aformat.format), // Target fmt
+ player->aformat.samplerate, // Target samplerate
+ acodec_ctx->channel_layout, // Source channel layout
+ acodec_ctx->sample_fmt, // Source fmt
+ acodec_ctx->sample_rate, // Source samplerate
+ 0, NULL);
+ if(swr_init((struct SwrContext *)player->swr) != 0) {
+ Kit_SetError("Unable to initialize audio converter context");
+ goto error;
+ }
+
+ player->abuffer = Kit_CreateBuffer(KIT_ABUFFERSIZE, _FreeAudioPacket);
+ if(player->abuffer == NULL) {
+ Kit_SetError("Unable to initialize audio ringbuffer");
+ goto error;
+ }
+
+ player->tmp_aframe = av_frame_alloc();
+ if(player->tmp_aframe == NULL) {
+ Kit_SetError("Unable to initialize temporary audio frame");
+ goto error;
+ }
+ }
+
+ // Initialize video codec information is initialized
+ vcodec_ctx = (AVCodecContext*)player->vcodec_ctx;
+ if(vcodec_ctx != NULL) {
+ player->vformat.is_enabled = true;
+ player->vformat.width = vcodec_ctx->width;
+ player->vformat.height = vcodec_ctx->height;
+ player->vformat.stream_idx = src->vstream_idx;
+ _FindPixelFormat(vcodec_ctx->pix_fmt, &player->vformat.format);
+
+ player->sws = sws_getContext(
+ vcodec_ctx->width, // Source w
+ vcodec_ctx->height, // Source h
+ vcodec_ctx->pix_fmt, // Source fmt
+ vcodec_ctx->width, // Target w
+ vcodec_ctx->height, // Target h
+ _FindAVPixelFormat(player->vformat.format), // Target fmt
+ SWS_BICUBIC,
+ NULL, NULL, NULL);
+ if((struct SwsContext *)player->sws == NULL) {
+ Kit_SetError("Unable to initialize video converter context");
+ goto error;
+ }
+
+ player->vbuffer = Kit_CreateBuffer(KIT_VBUFFERSIZE, _FreeVideoPacket);
+ if(player->vbuffer == NULL) {
+ Kit_SetError("Unable to initialize video ringbuffer");
+ goto error;
+ }
+
+ player->tmp_vframe = av_frame_alloc();
+ if(player->tmp_vframe == NULL) {
+ Kit_SetError("Unable to initialize temporary video frame");
+ goto error;
+ }
+ }
+
+ // Initialize subtitle codec
+ scodec_ctx = (AVCodecContext*)player->scodec_ctx;
+ if(scodec_ctx != NULL) {
+ player->sformat.is_enabled = true;
+ player->sformat.stream_idx = src->sstream_idx;
+
+ // subtitle packet buffer
+ player->sbuffer = Kit_CreateList(KIT_SBUFFERSIZE, _FreeSubtitlePacket);
+ if(player->sbuffer == NULL) {
+ Kit_SetError("Unable to initialize active subtitle list");
+ goto error;
+ }
+
+ // Initialize libass renderer
+ Kit_LibraryState *state = Kit_GetLibraryState();
+ player->ass_renderer = ass_renderer_init(state->libass_handle);
+ if(player->ass_renderer == NULL) {
+ Kit_SetError("Unable to initialize libass renderer");
+ goto error;
+ }
+
+ // Read fonts from attachment streams and give them to libass
+ AVFormatContext *format_ctx = player->src->format_ctx;
+ for (int j = 0; j < format_ctx->nb_streams; j++) {
+ AVStream *st = format_ctx->streams[j];
+ if(st->codec->codec_type == AVMEDIA_TYPE_ATTACHMENT && attachment_is_font(st)) {
+ const AVDictionaryEntry *tag = av_dict_get(
+ st->metadata,
+ "filename",
+ NULL,
+ AV_DICT_MATCH_CASE);
+ if(tag) {
+ ass_add_font(
+ state->libass_handle,
+ tag->value,
+ (char*)st->codec->extradata,
+ st->codec->extradata_size);
+ }
+ }
+ }
+
+ // Init libass fonts and window frame size
+ ass_set_fonts(player->ass_renderer, NULL, "sans-serif", ASS_FONTPROVIDER_AUTODETECT, NULL, 1);
+ ass_set_frame_size(player->ass_renderer, vcodec_ctx->width, vcodec_ctx->height);
+ ass_set_hinting(player->ass_renderer, ASS_HINTING_NONE);
+
+ // Initialize libass track
+ player->ass_track = ass_new_track(state->libass_handle);
+ if(player->ass_track == NULL) {
+ Kit_SetError("Unable to initialize libass track");
+ goto error;
+ }
+
+ // Set up libass track headers (ffmpeg provides these)
+ if(scodec_ctx->subtitle_header) {
+ ass_process_codec_private(
+ (ASS_Track*)player->ass_track,
+ (char*)scodec_ctx->subtitle_header,
+ scodec_ctx->subtitle_header_size);
+ }
+ }
+
+ player->cbuffer = Kit_CreateBuffer(KIT_CBUFFERSIZE, _FreeControlPacket);
+ if(player->cbuffer == NULL) {
+ Kit_SetError("Unable to initialize control ringbuffer");
+ goto error;
+ }
+
+ player->vmutex = SDL_CreateMutex();
+ if(player->vmutex == NULL) {
+ Kit_SetError("Unable to allocate video mutex");
+ goto error;
+ }
+
+ player->amutex = SDL_CreateMutex();
+ if(player->amutex == NULL) {
+ Kit_SetError("Unable to allocate audio mutex");
+ goto error;
+ }
+
+ player->cmutex = SDL_CreateMutex();
+ if(player->cmutex == NULL) {
+ Kit_SetError("Unable to allocate control buffer mutex");
+ goto error;
+ }
+
+ player->smutex = SDL_CreateMutex();
+ if(player->smutex == NULL) {
+ Kit_SetError("Unable to allocate subtitle buffer mutex");
+ goto error;
+ }
+
+ 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 error;
+ }
+
+ return player;
+
+error:
+ if(player->amutex != NULL) {
+ SDL_DestroyMutex(player->amutex);
+ }
+ if(player->vmutex != NULL) {
+ SDL_DestroyMutex(player->vmutex);
+ }
+ if(player->cmutex != NULL) {
+ SDL_DestroyMutex(player->cmutex);
+ }
+ if(player->smutex != NULL) {
+ SDL_DestroyMutex(player->smutex);
+ }
+ if(player->tmp_aframe != NULL) {
+ av_frame_free((AVFrame**)&player->tmp_aframe);
+ }
+ if(player->tmp_vframe != NULL) {
+ av_frame_free((AVFrame**)&player->tmp_vframe);
+ }
+
+ Kit_DestroyBuffer((Kit_Buffer*)player->vbuffer);
+ Kit_DestroyBuffer((Kit_Buffer*)player->abuffer);
+ Kit_DestroyBuffer((Kit_Buffer*)player->cbuffer);
+ Kit_DestroyList((Kit_List*)player->sbuffer);
+
+ if(player->sws != NULL) {
+ sws_freeContext((struct SwsContext *)player->sws);
+ }
+ if(player->swr != NULL) {
+ swr_free((struct SwrContext **)player->swr);
+ }
+
+ if(player->ass_track != NULL) {
+ ass_free_track((ASS_Track*)player->ass_track);
+ }
+ if(player->ass_renderer != NULL) {
+ ass_renderer_done((ASS_Renderer *)player->ass_renderer);
+ }
+ if(player != NULL) {
+ free(player);
+ }
+ return NULL;
+}
+
+void Kit_ClosePlayer(Kit_Player *player) {
+ if(player == NULL) return;
+
+ // Kill the decoder thread
+ player->state = KIT_CLOSED;
+ SDL_WaitThread(player->dec_thread, NULL);
+ SDL_DestroyMutex(player->vmutex);
+ SDL_DestroyMutex(player->amutex);
+ SDL_DestroyMutex(player->cmutex);
+ SDL_DestroyMutex(player->smutex);
+
+ // Free up converters
+ if(player->sws != NULL) {
+ sws_freeContext((struct SwsContext *)player->sws);
+ }
+ if(player->swr != NULL) {
+ swr_free((struct SwrContext **)&player->swr);
+ }
+
+ // Free temporary frames
+ if(player->tmp_vframe != NULL) {
+ av_frame_free((AVFrame**)&player->tmp_vframe);
+ }
+ if(player->tmp_aframe != NULL) {
+ av_frame_free((AVFrame**)&player->tmp_aframe);
+ }
+
+ // Free contexts
+ avcodec_close((AVCodecContext*)player->acodec_ctx);
+ avcodec_close((AVCodecContext*)player->vcodec_ctx);
+ avcodec_close((AVCodecContext*)player->scodec_ctx);
+ avcodec_free_context((AVCodecContext**)&player->acodec_ctx);
+ avcodec_free_context((AVCodecContext**)&player->vcodec_ctx);
+ avcodec_free_context((AVCodecContext**)&player->scodec_ctx);
+
+ // Free local audio buffers
+ Kit_DestroyBuffer((Kit_Buffer*)player->cbuffer);
+ Kit_DestroyBuffer((Kit_Buffer*)player->abuffer);
+ Kit_DestroyBuffer((Kit_Buffer*)player->vbuffer);
+ Kit_DestroyList((Kit_List*)player->sbuffer);
+
+ // Free libass context
+ if(player->ass_track != NULL) {
+ ass_free_track((ASS_Track*)player->ass_track);
+ }
+ if(player->ass_renderer != NULL) {
+ ass_renderer_done((ASS_Renderer *)player->ass_renderer);
+ }
+
+ // Free the player structure itself
+ free(player);
+}
+
+int Kit_GetVideoData(Kit_Player *player, SDL_Texture *texture) {
+ assert(player != NULL);
+
+ if(player->src->vstream_idx == -1) {
+ return 0;
+ }
+
+ assert(texture != NULL);
+
+ // If paused or stopped, do nothing
+ if(player->state == KIT_PAUSED) {
+ return 0;
+ }
+ if(player->state == KIT_STOPPED) {
+ return 0;
+ }
+
+ // Read a packet from buffer, if one exists. Stop here if not.
+ Kit_VideoPacket *packet = NULL;
+ Kit_VideoPacket *n_packet = NULL;
+ if(SDL_LockMutex(player->vmutex) == 0) {
+ packet = (Kit_VideoPacket*)Kit_PeekBuffer((Kit_Buffer*)player->vbuffer);
+ if(packet == NULL) {
+ SDL_UnlockMutex(player->vmutex);
+ return 0;
+ }
+
+ // Print some data
+ double cur_video_ts = _GetSystemTime() - player->clock_sync;
+
+ // Check if we want the packet
+ if(packet->pts > cur_video_ts + VIDEO_SYNC_THRESHOLD) {
+ // Video is ahead, don't show yet.
+ SDL_UnlockMutex(player->vmutex);
+ return 0;
+ } else if(packet->pts < cur_video_ts - VIDEO_SYNC_THRESHOLD) {
+ // Video is lagging, skip until we find a good PTS to continue from.
+ while(packet != NULL) {
+ Kit_AdvanceBuffer((Kit_Buffer*)player->vbuffer);
+ n_packet = (Kit_VideoPacket*)Kit_PeekBuffer((Kit_Buffer*)player->vbuffer);
+ if(n_packet == NULL) {
+ break;
+ }
+ _FreeVideoPacket(packet);
+ packet = n_packet;
+ if(packet->pts > cur_video_ts - VIDEO_SYNC_THRESHOLD) {
+ break;
+ }
+ }
+ }
+
+ // Advance buffer one frame forwards
+ Kit_AdvanceBuffer((Kit_Buffer*)player->vbuffer);
+ player->vclock_pos = packet->pts;
+
+ // Update textures as required. Handle UYV frames separately.
+ if(player->vformat.format == SDL_PIXELFORMAT_YV12
+ || player->vformat.format == SDL_PIXELFORMAT_IYUV)
+ {
+ SDL_UpdateYUVTexture(
+ texture, NULL,
+ packet->frame->data[0], packet->frame->linesize[0],
+ packet->frame->data[1], packet->frame->linesize[1],
+ packet->frame->data[2], packet->frame->linesize[2]);
+ }
+ else {
+ SDL_UpdateTexture(
+ texture, NULL,
+ packet->frame->data[0],
+ packet->frame->linesize[0]);
+ }
+
+ _FreeVideoPacket(packet);
+ SDL_UnlockMutex(player->vmutex);
+ } else {
+ Kit_SetError("Unable to lock video buffer mutex");
+ return 1;
+ }
+
+ return 0;
+}
+
+int Kit_GetSubtitleData(Kit_Player *player, SDL_Renderer *renderer) {
+ assert(player != NULL);
+
+ // If there is no audio stream, don't bother.
+ if(player->src->sstream_idx == -1) {
+ return 0;
+ }
+
+ assert(renderer != NULL);
+
+ // If paused or stopped, do nothing
+ if(player->state == KIT_PAUSED) {
+ return 0;
+ }
+ if(player->state == KIT_STOPPED) {
+ return 0;
+ }
+
+ unsigned int it;
+ Kit_SubtitlePacket *packet = NULL;
+
+ // Current sync timestamp
+ double cur_subtitle_ts = _GetSystemTime() - player->clock_sync;
+
+ // Read a packet from buffer, if one exists. Stop here if not.
+ if(SDL_LockMutex(player->smutex) == 0) {
+ // Check if refresh is required and remove old subtitles
+ it = 0;
+ while((packet = Kit_IterateList((Kit_List*)player->sbuffer, &it)) != NULL) {
+ if(packet->pts_end >= 0 && packet->pts_end < cur_subtitle_ts) {
+ Kit_RemoveFromList((Kit_List*)player->sbuffer, it);
+ }
+ }
+
+ // Render subtitle bitmaps
+ it = 0;
+ while((packet = Kit_IterateList((Kit_List*)player->sbuffer, &it)) != NULL) {
+ if(packet->texture == NULL) {
+ packet->texture = SDL_CreateTextureFromSurface(renderer, packet->surface);
+ SDL_SetTextureBlendMode(packet->texture, SDL_BLENDMODE_BLEND);
+ }
+ SDL_RenderCopy(renderer, packet->texture, NULL, packet->rect);
+ }
+
+ // Unlock subtitle buffer mutex.
+ SDL_UnlockMutex(player->smutex);
+ } else {
+ Kit_SetError("Unable to lock subtitle buffer mutex");
+ return 0;
+ }
+
+ return 0;
+}
+
+int Kit_GetAudioData(Kit_Player *player, unsigned char *buffer, int length, int cur_buf_len) {
+ assert(player != NULL);
+
+ // If there is no audio stream, don't bother.
+ if(player->src->astream_idx == -1) {
+ return 0;
+ }
+
+ // If asked for nothing, don't return anything either :P
+ if(length == 0) {
+ return 0;
+ }
+
+ assert(buffer != NULL);
+
+ // If paused or stopped, do nothing
+ if(player->state == KIT_PAUSED) {
+ return 0;
+ }
+ if(player->state == KIT_STOPPED) {
+ return 0;
+ }
+
+ // Read a packet from buffer, if one exists. Stop here if not.
+ int ret = 0;
+ Kit_AudioPacket *packet = NULL;
+ Kit_AudioPacket *n_packet = NULL;
+ if(SDL_LockMutex(player->amutex) == 0) {
+ packet = (Kit_AudioPacket*)Kit_PeekBuffer((Kit_Buffer*)player->abuffer);
+ if(packet == NULL) {
+ SDL_UnlockMutex(player->amutex);
+ return 0;
+ }
+
+ int bytes_per_sample = player->aformat.bytes * player->aformat.channels;
+ double bps = bytes_per_sample * player->aformat.samplerate;
+ double cur_audio_ts = _GetSystemTime() - player->clock_sync + ((double)cur_buf_len / bps);
+ double diff = cur_audio_ts - packet->pts;
+ int diff_samples = fabs(diff) * player->aformat.samplerate;
+
+ if(packet->pts > cur_audio_ts + AUDIO_SYNC_THRESHOLD) {
+ // Audio is ahead, fill buffer with some silence
+ int max_diff_samples = length / bytes_per_sample;
+ int max_samples = (max_diff_samples < diff_samples) ? max_diff_samples : diff_samples;
+
+ av_samples_set_silence(
+ &buffer,
+ 0, // Offset
+ max_samples,
+ player->aformat.channels,
+ _FindAVSampleFormat(player->aformat.format));
+
+ int diff_bytes = max_samples * bytes_per_sample;
+
+ SDL_UnlockMutex(player->amutex);
+ return diff_bytes;
+
+ } else if(packet->pts < cur_audio_ts - AUDIO_SYNC_THRESHOLD) {
+ // Audio is lagging, skip until good pts is found
+
+ while(1) {
+ Kit_AdvanceBuffer((Kit_Buffer*)player->abuffer);
+ n_packet = (Kit_AudioPacket*)Kit_PeekBuffer((Kit_Buffer*)player->abuffer);
+ if(n_packet != NULL) {
+ packet = n_packet;
+ } else {
+ break;
+ }
+ if(packet->pts > cur_audio_ts - AUDIO_SYNC_THRESHOLD) {
+ break;
+ }
+ }
+ }
+
+ if(length > 0) {
+ ret = Kit_ReadRingBuffer(packet->rb, (char*)buffer, length);
+ }
+
+ if(Kit_GetRingBufferLength(packet->rb) == 0) {
+ Kit_AdvanceBuffer((Kit_Buffer*)player->abuffer);
+ _FreeAudioPacket(packet);
+ } else {
+ double adjust = (double)ret / bps;
+ packet->pts += adjust;
+ }
+
+ SDL_UnlockMutex(player->amutex);
+ } else {
+ Kit_SetError("Unable to lock audio buffer mutex");
+ return 0;
+ }
+
+ return ret;
+}
+
+void Kit_GetPlayerInfo(const Kit_Player *player, Kit_PlayerInfo *info) {
+ assert(player != NULL);
+ assert(info != NULL);
+
+ AVCodecContext *acodec_ctx = (AVCodecContext*)player->acodec_ctx;
+ AVCodecContext *vcodec_ctx = (AVCodecContext*)player->vcodec_ctx;
+ AVCodecContext *scodec_ctx = (AVCodecContext*)player->scodec_ctx;
+
+ // Reset everything to 0. We might not fill all fields.
+ memset(info, 0, sizeof(Kit_PlayerInfo));
+
+ if(acodec_ctx != NULL) {
+ strncpy(info->acodec, acodec_ctx->codec->name, KIT_CODECMAX-1);
+ strncpy(info->acodec_name, acodec_ctx->codec->long_name, KIT_CODECNAMEMAX-1);
+ memcpy(&info->audio, &player->aformat, sizeof(Kit_AudioFormat));
+ }
+ if(vcodec_ctx != NULL) {
+ strncpy(info->vcodec, vcodec_ctx->codec->name, KIT_CODECMAX-1);
+ strncpy(info->vcodec_name, vcodec_ctx->codec->long_name, KIT_CODECNAMEMAX-1);
+ memcpy(&info->video, &player->vformat, sizeof(Kit_VideoFormat));
+ }
+ if(scodec_ctx != NULL) {
+ strncpy(info->scodec, scodec_ctx->codec->name, KIT_CODECMAX-1);
+ strncpy(info->scodec_name, scodec_ctx->codec->long_name, KIT_CODECNAMEMAX-1);
+ memcpy(&info->subtitle, &player->sformat, sizeof(Kit_SubtitleFormat));
+ }
+}
+
+Kit_PlayerState Kit_GetPlayerState(const Kit_Player *player) {
+ assert(player != NULL);
+
+ return player->state;
+}
+
+void Kit_PlayerPlay(Kit_Player *player) {
+ assert(player != NULL);
+
+ if(player->state == KIT_PLAYING) {
+ return;
+ }
+ if(player->state == KIT_STOPPED) {
+ player->clock_sync = _GetSystemTime();
+ }
+ if(player->state == KIT_PAUSED) {
+ player->clock_sync += _GetSystemTime() - player->pause_start;
+ }
+ player->state = KIT_PLAYING;
+}
+
+void Kit_PlayerStop(Kit_Player *player) {
+ assert(player != NULL);
+
+ if(player->state == KIT_STOPPED) {
+ return;
+ }
+ player->state = KIT_STOPPED;
+}
+
+void Kit_PlayerPause(Kit_Player *player) {
+ assert(player != NULL);
+
+ if(player->state != KIT_PLAYING) {
+ return;
+ }
+ player->pause_start = _GetSystemTime();
+ player->state = KIT_PAUSED;
+}
+
+int Kit_PlayerSeek(Kit_Player *player, double m_time) {
+ assert(player != NULL);
+
+ // Send packets to control stream
+ if(SDL_LockMutex(player->cmutex) == 0) {
+ // Flush audio and video buffers, then set seek, then unlock control queue mutex.
+ Kit_WriteBuffer((Kit_Buffer*)player->cbuffer, _CreateControlPacket(KIT_CONTROL_FLUSH, 0));
+ Kit_WriteBuffer((Kit_Buffer*)player->cbuffer, _CreateControlPacket(KIT_CONTROL_SEEK, m_time));
+ SDL_UnlockMutex(player->cmutex);
+ } else {
+ Kit_SetError("Unable to lock control queue mutex");
+ return 1;
+ }
+
+ return 0;
+}
+
+double Kit_GetPlayerDuration(const Kit_Player *player) {
+ assert(player != NULL);
+
+ AVFormatContext *fmt_ctx = (AVFormatContext *)player->src->format_ctx;
+ return (fmt_ctx->duration / AV_TIME_BASE);
+}
+
+double Kit_GetPlayerPosition(const Kit_Player *player) {
+ assert(player != NULL);
+
+ return player->vclock_pos;
+}
diff --git a/src/kitringbuffer.c b/src/kitringbuffer.c
new file mode 100644
index 0000000..1711d52
--- /dev/null
+++ b/src/kitringbuffer.c
@@ -0,0 +1,172 @@
+/*
+ * Ringbuffer
+ *
+ * Copyright (c) 2016, Tuomas Virtanen
+ * license: MIT; see LICENSE for details.
+*/
+
+#include "kitchensink/internal/kitringbuffer.h"
+
+#include <stdlib.h>
+#include <string.h>
+#include <stdio.h>
+#include <assert.h>
+
+/**
+ * Creates a new ringbuffer with the given size.
+ * @param size Size for the new ringbuffer
+ * @return Ringbuffer handle
+ */
+Kit_RingBuffer* Kit_CreateRingBuffer(unsigned int size) {
+ Kit_RingBuffer *rb = calloc(1, sizeof(Kit_RingBuffer));
+ if(rb == NULL) return NULL;
+ rb->size = size;
+ rb->data = malloc(size);
+ if(rb->data == NULL) {
+ free(rb);
+ return NULL;
+ }
+ return rb;
+}
+
+/**
+ * Deletes the given ringbuffer.
+ * @param rb Ringbuffer to be deleted.
+ */
+void Kit_DestroyRingBuffer(Kit_RingBuffer* rb) {
+ if(rb == NULL) return;
+ free(rb->data);
+ free(rb);
+}
+
+/**
+ * Writes to the given ringbuffer. If given length is larger than the amount
+ * the ringbuffer can fit, only the data that fits will be written.
+ * @param rb Ringbuffer to write to.
+ * @param data Data to write
+ * @param len Data length
+ * @return Amount of data that was actually written.
+ */
+int Kit_WriteRingBuffer(Kit_RingBuffer *rb, const char* data, int len) {
+ int k;
+ len = (len > (rb->size - rb->len)) ? (rb->size - rb->len) : len;
+ if(rb->len < rb->size) {
+ if(len + rb->wpos > rb->size) {
+ k = (len + rb->wpos) % rb->size;
+ memcpy((rb->data + rb->wpos), data, len - k);
+ memcpy(rb->data, data+(len-k), k);
+ } else {
+ memcpy((rb->data + rb->wpos), data, len);
+ }
+ rb->len += len;
+ rb->wpos += len;
+ if(rb->wpos >= rb->size) {
+ rb->wpos = rb->wpos % rb->size;
+ }
+ return len;
+ }
+ return 0;
+}
+
+/**
+ * Reads data from ringbuffer. If ringbuffer has less data than was requested,
+ * only the available data will be read.
+ * @param rb Ringbuffer to read from.
+ * @param data Buffer to read into.
+ * @param len How much data do we want
+ * @return Amount of data that was actually read.
+ */
+int Kit_ReadRingBuffer(Kit_RingBuffer *rb, char* data, int len) {
+ int k;
+ len = (len > rb->len) ? rb->len : len;
+ if(rb->len > 0) {
+ if(len + rb->rpos > rb->size) {
+ k = (len + rb->rpos) % rb->size;
+ memcpy(data, (rb->data + rb->rpos), len-k);
+ memcpy(data+(len-k), (rb->data), k);
+ } else {
+ memcpy(data, (rb->data + rb->rpos), len);
+ }
+ rb->len -= len;
+ rb->rpos += len;
+ if(rb->rpos >= rb->size) {
+ rb->rpos = rb->rpos % rb->size;
+ }
+ return len;
+ }
+ return 0;
+}
+
+/**
+ * Peeks into the given ringbuffer. Technically same as rb_read, but does not advance
+ * the internal position pointer. In other words, you may peek as many times as you wish,
+ * and will always get the same data.
+ * @param rb Ringbuffer to peek into.
+ * @param data Buffer to read into
+ * @param len How much data do we need
+ * @return Amount of data actually read
+ */
+int Kit_PeekRingBuffer(const Kit_RingBuffer *rb, char* data, int len) {
+ int k;
+ len = (len > rb->len) ? rb->len : len;
+ if(rb->len > 0) {
+ if(len + rb->rpos > rb->size) {
+ k = (len + rb->rpos) % rb->size;
+ memcpy(data, (rb->data + rb->rpos), len-k);
+ memcpy(data+(len-k), (rb->data), k);
+ } else {
+ memcpy(data, (rb->data + rb->rpos), len);
+ }
+ return len;
+ }
+ return 0;
+}
+
+/**
+ * Advances the internal position counter by given amount. Note that counter can only be
+ * advanced by the amount of unreadable data in ringbuffer.
+ * @param rb Ringbuffer to handle
+ * @param len How much should the position counter be increased
+ * @return How much the position counter was actually increased.
+ */
+int Kit_AdvanceRingBuffer(Kit_RingBuffer *rb, int len) {
+ len = (len > rb->len) ? rb->len : len;
+ if(rb->len > 0) {
+ rb->len -= len;
+ rb->rpos += len;
+ if(rb->rpos >= rb->size) {
+ rb->rpos = rb->rpos % rb->size;
+ }
+ return len;
+ }
+ return 0;
+}
+
+/**
+ * Returns the current length of the Ringbuffer. In other words, how much data
+ * the ringbuffer contains
+ * @param rb Ringbuffer to handle
+ * @return Data in ringbuffer (in bytes).
+ */
+int Kit_GetRingBufferLength(const Kit_RingBuffer *rb) {
+ return rb->len;
+}
+
+/**
+ * Returns the size of the ringbuffer. In other words, the maximum amount of data
+ * the ringbuffer can hold.
+ * @param rb Ringbuffer to handle
+ * @return Size of the ringbuffer
+ */
+int Kit_GetRingBufferSize(const Kit_RingBuffer *rb) {
+ return rb->size;
+}
+
+/**
+ * Returns the free size of the ringbuffer.
+ * @param rb Ringbuffer to handle
+ * @return Free size in the ringbuffer
+ */
+int Kit_GetRingBufferFree(const Kit_RingBuffer *rb) {
+ return rb->size - rb->len;
+}
diff --git a/src/kitsource.c b/src/kitsource.c
new file mode 100644
index 0000000..075bcbd
--- /dev/null
+++ b/src/kitsource.c
@@ -0,0 +1,130 @@
+#include "kitchensink/kitsource.h"
+#include "kitchensink/kiterror.h"
+
+#include <libavcodec/avcodec.h>
+#include <libavformat/avformat.h>
+#include <libavutil/opt.h>
+
+#include <stdlib.h>
+#include <string.h>
+#include <assert.h>
+
+Kit_Source* Kit_CreateSourceFromUrl(const char *url) {
+ assert(url != NULL);
+
+ Kit_Source *src = calloc(1, sizeof(Kit_Source));
+ if(src == NULL) {
+ Kit_SetError("Unable to allocate source");
+ return NULL;
+ }
+
+ // 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;
+ }
+
+ av_opt_set_int(src->format_ctx, "probesize", INT_MAX, 0);
+ av_opt_set_int(src->format_ctx, "analyzeduration", INT_MAX, 0);
+
+ // Fetch stream information. This may potentially take a while.
+ if(avformat_find_stream_info((AVFormatContext *)src->format_ctx, NULL) < 0) {
+ Kit_SetError("Unable to fetch source information");
+ goto exit_1;
+ }
+
+ // Find best streams for defaults
+ src->astream_idx = Kit_GetBestSourceStream(src, KIT_STREAMTYPE_AUDIO);
+ src->vstream_idx = Kit_GetBestSourceStream(src, KIT_STREAMTYPE_VIDEO);
+ src->sstream_idx = Kit_GetBestSourceStream(src, KIT_STREAMTYPE_SUBTITLE);
+ return src;
+
+exit_1:
+ avformat_close_input((AVFormatContext **)&src->format_ctx);
+exit_0:
+ free(src);
+ return NULL;
+}
+
+void Kit_CloseSource(Kit_Source *src) {
+ assert(src != NULL);
+ avformat_close_input((AVFormatContext **)&src->format_ctx);
+ free(src);
+}
+
+int Kit_GetSourceStreamInfo(const Kit_Source *src, Kit_StreamInfo *info, int index) {
+ assert(src != NULL);
+ assert(info != NULL);
+
+ AVFormatContext *format_ctx = (AVFormatContext *)src->format_ctx;
+ if(index < 0 || index >= format_ctx->nb_streams) {
+ Kit_SetError("Invalid stream index");
+ return 1;
+ }
+
+ AVStream *stream = format_ctx->streams[index];
+ switch(stream->codec->codec_type) {
+ case AVMEDIA_TYPE_UNKNOWN: info->type = KIT_STREAMTYPE_UNKNOWN; break;
+ case AVMEDIA_TYPE_DATA: info->type = KIT_STREAMTYPE_DATA; break;
+ case AVMEDIA_TYPE_VIDEO: info->type = KIT_STREAMTYPE_VIDEO; break;
+ case AVMEDIA_TYPE_AUDIO: info->type = KIT_STREAMTYPE_AUDIO; break;
+ case AVMEDIA_TYPE_SUBTITLE: info->type = KIT_STREAMTYPE_SUBTITLE; break;
+ case AVMEDIA_TYPE_ATTACHMENT: info->type = KIT_STREAMTYPE_ATTACHMENT; break;
+ default:
+ Kit_SetError("Unknown native stream type");
+ return 1;
+ }
+
+ info->index = index;
+ return 0;
+}
+
+int Kit_GetBestSourceStream(const Kit_Source *src, const Kit_StreamType type) {
+ assert(src != NULL);
+ int avmedia_type = 0;
+ switch(type) {
+ case KIT_STREAMTYPE_VIDEO: avmedia_type = AVMEDIA_TYPE_VIDEO; break;
+ case KIT_STREAMTYPE_AUDIO: avmedia_type = AVMEDIA_TYPE_AUDIO; break;
+ case KIT_STREAMTYPE_SUBTITLE: avmedia_type = AVMEDIA_TYPE_SUBTITLE; break;
+ default: return -1;
+ }
+ int ret = av_find_best_stream((AVFormatContext *)src->format_ctx, avmedia_type, -1, -1, NULL, 0);
+ if(ret == AVERROR_STREAM_NOT_FOUND) {
+ return -1;
+ }
+ if(ret == AVERROR_DECODER_NOT_FOUND) {
+ Kit_SetError("Unable to find a decoder for the stream");
+ return 1;
+ }
+ return ret;
+}
+
+int Kit_SetSourceStream(Kit_Source *src, const Kit_StreamType type, int index) {
+ assert(src != NULL);
+ switch(type) {
+ case KIT_STREAMTYPE_AUDIO: src->astream_idx = index; break;
+ case KIT_STREAMTYPE_VIDEO: src->vstream_idx = index; break;
+ case KIT_STREAMTYPE_SUBTITLE: src->sstream_idx = index; break;
+ default:
+ Kit_SetError("Invalid stream type");
+ return 1;
+ }
+ return 0;
+}
+
+int Kit_GetSourceStream(const Kit_Source *src, const Kit_StreamType type) {
+ assert(src != NULL);
+ switch(type) {
+ case KIT_STREAMTYPE_AUDIO: return src->astream_idx;
+ case KIT_STREAMTYPE_VIDEO: return src->vstream_idx;
+ case KIT_STREAMTYPE_SUBTITLE: return src->sstream_idx;
+ default:
+ break;
+ }
+ return -1;
+}
+
+int Kit_GetSourceStreamCount(const Kit_Source *src) {
+ assert(src != NULL);
+ return ((AVFormatContext *)src->format_ctx)->nb_streams;
+}
diff --git a/src/kitutils.c b/src/kitutils.c
new file mode 100644
index 0000000..b618c07
--- /dev/null
+++ b/src/kitutils.c
@@ -0,0 +1,73 @@
+#include "kitchensink/kitutils.h"
+#include "kitchensink/kitsource.h"
+
+#include <SDL2/SDL.h>
+
+const char* Kit_GetSDLAudioFormatString(unsigned int type) {
+ switch(type) {
+ case AUDIO_S8: return "AUDIO_S8";
+ case AUDIO_U8: return "AUDIO_U8";
+ case AUDIO_S16: return "AUDIO_S16";
+ case AUDIO_U16: return "AUDIO_U16";
+ case AUDIO_S32: return "AUDIO_S32";
+ case AUDIO_F32: return "AUDIO_F32";
+ default:
+ return NULL;
+ }
+}
+
+const char* Kit_GetSDLPixelFormatString(unsigned int type) {
+ switch(type) {
+ case SDL_PIXELFORMAT_UNKNOWN: return "SDL_PIXELFORMAT_UNKNOWN";
+ case SDL_PIXELFORMAT_INDEX1LSB: return "SDL_PIXELFORMAT_INDEX1LSB";
+ case SDL_PIXELFORMAT_INDEX1MSB: return "SDL_PIXELFORMAT_INDEX1MSB";
+ case SDL_PIXELFORMAT_INDEX4LSB: return "SDL_PIXELFORMAT_INDEX4LSB";
+ case SDL_PIXELFORMAT_INDEX4MSB: return "SDL_PIXELFORMAT_INDEX4MSB";
+ case SDL_PIXELFORMAT_INDEX8: return "SDL_PIXELFORMAT_INDEX8";
+ case SDL_PIXELFORMAT_RGB332: return "SDL_PIXELFORMAT_RGB332";
+ case SDL_PIXELFORMAT_RGB444: return "SDL_PIXELFORMAT_RGB444";
+ case SDL_PIXELFORMAT_RGB555: return "SDL_PIXELFORMAT_RGB555";
+ case SDL_PIXELFORMAT_BGR555: return "SDL_PIXELFORMAT_BGR555";
+ case SDL_PIXELFORMAT_ARGB4444: return "SDL_PIXELFORMAT_ARGB4444";
+ case SDL_PIXELFORMAT_RGBA4444: return "SDL_PIXELFORMAT_RGBA4444";
+ case SDL_PIXELFORMAT_ABGR4444: return "SDL_PIXELFORMAT_ABGR4444";
+ case SDL_PIXELFORMAT_BGRA4444: return "SDL_PIXELFORMAT_BGRA4444";
+ case SDL_PIXELFORMAT_ARGB1555: return "SDL_PIXELFORMAT_ARGB1555";
+ case SDL_PIXELFORMAT_RGBA5551: return "SDL_PIXELFORMAT_RGBA5551";
+ case SDL_PIXELFORMAT_ABGR1555: return "SDL_PIXELFORMAT_ABGR1555";
+ case SDL_PIXELFORMAT_BGRA5551: return "SDL_PIXELFORMAT_BGRA5551";
+ case SDL_PIXELFORMAT_RGB565: return "SDL_PIXELFORMAT_RGB565";
+ case SDL_PIXELFORMAT_BGR565: return "SDL_PIXELFORMAT_BGR565";
+ case SDL_PIXELFORMAT_RGB24: return "SDL_PIXELFORMAT_RGB24";
+ case SDL_PIXELFORMAT_BGR24: return "SDL_PIXELFORMAT_BGR24";
+ case SDL_PIXELFORMAT_RGB888: return "SDL_PIXELFORMAT_RGB888";
+ case SDL_PIXELFORMAT_RGBX8888: return "SDL_PIXELFORMAT_RGBX8888";
+ case SDL_PIXELFORMAT_BGR888: return "SDL_PIXELFORMAT_BGR888";
+ case SDL_PIXELFORMAT_BGRX8888: return "SDL_PIXELFORMAT_BGRX8888";
+ case SDL_PIXELFORMAT_ARGB8888: return "SDL_PIXELFORMAT_ARGB8888";
+ case SDL_PIXELFORMAT_RGBA8888: return "SDL_PIXELFORMAT_RGBA8888";
+ case SDL_PIXELFORMAT_ABGR8888: return "SDL_PIXELFORMAT_ABGR8888";
+ case SDL_PIXELFORMAT_BGRA8888: return "SDL_PIXELFORMAT_BGRA8888";
+ case SDL_PIXELFORMAT_ARGB2101010: return "SDL_PIXELFORMAT_ARGB2101010";
+ case SDL_PIXELFORMAT_YV12: return "SDL_PIXELFORMAT_YV12";
+ case SDL_PIXELFORMAT_IYUV: return "SDL_PIXELFORMAT_IYUV";
+ case SDL_PIXELFORMAT_YUY2: return "SDL_PIXELFORMAT_YUY2";
+ case SDL_PIXELFORMAT_UYVY: return "SDL_PIXELFORMAT_UYVY";
+ case SDL_PIXELFORMAT_YVYU: return "SDL_PIXELFORMAT_YVYU";
+ default:
+ return NULL;
+ }
+}
+
+const char* Kit_GetKitStreamTypeString(unsigned int type) {
+ switch(type) {
+ case KIT_STREAMTYPE_UNKNOWN: return "KIT_STREAMTYPE_UNKNOWN";
+ case KIT_STREAMTYPE_VIDEO: return "KIT_STREAMTYPE_VIDEO";
+ case KIT_STREAMTYPE_AUDIO: return "KIT_STREAMTYPE_AUDIO";
+ case KIT_STREAMTYPE_DATA: return "KIT_STREAMTYPE_DATA";
+ case KIT_STREAMTYPE_SUBTITLE: return "KIT_STREAMTYPE_SUBTITLE";
+ case KIT_STREAMTYPE_ATTACHMENT: return "KIT_STREAMTYPE_ATTACHMENT";
+ default:
+ return NULL;
+ }
+}
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
new file mode 100644
index 0000000..ddfe4f9
--- /dev/null
+++ b/tests/CMakeLists.txt
@@ -0,0 +1,18 @@
+find_package(CUnit)
+
+add_executable(test_lib
+ test_lib.c
+ test_source.c
+)
+
+include_directories(${CUNIT_INCLUDE_DIR} . ../include/)
+if(MINGW)
+ target_link_libraries(test_lib mingw32)
+endif()
+target_link_libraries(test_lib
+ SDL_kitchensink_static
+ ${CUNIT_LIBRARIES}
+ ${SDL2_LIBRARIES}
+ ${FFMPEG_LIBRARIES}
+)
+add_custom_target(unittest test_lib)
diff --git a/tests/data/CEP140_512kb.mp4 b/tests/data/CEP140_512kb.mp4
new file mode 100644
index 0000000..4341032
--- /dev/null
+++ b/tests/data/CEP140_512kb.mp4
Binary files differ
diff --git a/tests/test_lib.c b/tests/test_lib.c
new file mode 100644
index 0000000..92eb058
--- /dev/null
+++ b/tests/test_lib.c
@@ -0,0 +1,28 @@
+#include <CUnit/CUnit.h>
+#include <CUnit/Basic.h>
+#include "kitchensink/kitchensink.h"
+
+void source_test_suite(CU_pSuite suite);
+
+int main(int argc, char **argv) {
+ CU_pSuite suite = NULL;
+
+ Kit_Init(KIT_INIT_NETWORK|KIT_INIT_FORMATS);
+
+ if(CU_initialize_registry() != CUE_SUCCESS) {
+ return CU_get_error();
+ }
+
+ suite = CU_add_suite("Source functions", NULL, NULL);
+ if(suite == NULL) goto end;
+ source_test_suite(suite);
+
+ // Run tests
+ CU_basic_set_mode(CU_BRM_VERBOSE);
+ CU_basic_run_tests();
+
+end:
+ CU_cleanup_registry();
+ Kit_Quit();
+ return CU_get_error();
+}
diff --git a/tests/test_source.c b/tests/test_source.c
new file mode 100644
index 0000000..0f70635
--- /dev/null
+++ b/tests/test_source.c
@@ -0,0 +1,48 @@
+#include <CUnit/CUnit.h>
+#include <CUnit/Basic.h>
+#include <kitchensink/kitchensink.h>
+
+Kit_Source *src = NULL;
+
+void test_Kit_CreateSourceFromUrl(void) {
+ CU_ASSERT_PTR_NULL(Kit_CreateSourceFromUrl("nonexistent"));
+ src = Kit_CreateSourceFromUrl("../../tests/data/CEP140_512kb.mp4");
+ CU_ASSERT_PTR_NOT_NULL(src);
+}
+
+void test_Kit_GetBestSourceStream(void) {
+ CU_ASSERT(Kit_GetBestSourceStream(src, KIT_STREAMTYPE_VIDEO) == 0);
+ CU_ASSERT(Kit_GetBestSourceStream(src, KIT_STREAMTYPE_AUDIO) == 1);
+ CU_ASSERT(Kit_GetBestSourceStream(src, KIT_STREAMTYPE_UNKNOWN) == -1);
+ CU_ASSERT(Kit_GetBestSourceStream(src, KIT_STREAMTYPE_DATA) == -1);
+ CU_ASSERT(Kit_GetBestSourceStream(src, KIT_STREAMTYPE_ATTACHMENT) == -1);
+ CU_ASSERT(Kit_GetBestSourceStream(src, KIT_STREAMTYPE_SUBTITLE) == -1);
+}
+
+void test_Kit_GetSourceStreamCount(void) {
+ CU_ASSERT(Kit_GetSourceStreamCount(src) == 2);
+}
+
+void test_Kit_SetSourceStream(void) {
+ CU_ASSERT(Kit_SetSourceStream(src, KIT_STREAMTYPE_VIDEO, 0) == 0);
+ CU_ASSERT(Kit_SetSourceStream(src, KIT_STREAMTYPE_UNKNOWN, 0) == 1);
+}
+
+void test_Kit_GetSourceStream(void) {
+ CU_ASSERT(Kit_GetSourceStream(src, KIT_STREAMTYPE_VIDEO) == 0);
+ CU_ASSERT(Kit_GetSourceStream(src, KIT_STREAMTYPE_AUDIO) == 1);
+ CU_ASSERT(Kit_GetSourceStream(src, KIT_STREAMTYPE_UNKNOWN) == -1);
+}
+
+void test_Kit_CloseSource(void) {
+ Kit_CloseSource(src);
+}
+
+void source_test_suite(CU_pSuite suite) {
+ if(CU_add_test(suite, "Kit_CreateSourceFromUrl", test_Kit_CreateSourceFromUrl) == NULL) { return; }
+ if(CU_add_test(suite, "Kit_GetBestSourceStream", test_Kit_GetBestSourceStream) == NULL) { return; }
+ if(CU_add_test(suite, "Kit_GetSourceStreamCount", test_Kit_GetSourceStreamCount) == NULL) { return; }
+ if(CU_add_test(suite, "Kit_SetSourceStream", test_Kit_SetSourceStream) == NULL) { return; }
+ if(CU_add_test(suite, "Kit_GetSourceStream", test_Kit_GetSourceStream) == NULL) { return; }
+ if(CU_add_test(suite, "Kit_CloseSource", test_Kit_CloseSource) == NULL) { return; }
+}
diff --git a/travis/ffmpeg.sh b/travis/ffmpeg.sh
new file mode 100644
index 0000000..d27c136
--- /dev/null
+++ b/travis/ffmpeg.sh
@@ -0,0 +1,12 @@
+
+if [ ! -e "$HOME/local/lib/libavcodec.so" ]; then
+ wget https://www.ffmpeg.org/releases/ffmpeg-3.0.4.tar.gz -O ~/ffmpeg.tar.gz
+ tar xzf ~/ffmpeg.tar.gz -C ~/
+ cd ~/ffmpeg-3.0.4
+ export CC=gcc-5
+ ./configure --prefix=$HOME/local --disable-static --enable-shared --disable-doc
+ make
+ make install
+else
+ echo 'Using cached FFmpeg build directory.';
+fi
diff --git a/travis/sdl2.sh b/travis/sdl2.sh
new file mode 100644
index 0000000..8b914fb
--- /dev/null
+++ b/travis/sdl2.sh
@@ -0,0 +1,13 @@
+
+if [ ! -e "$HOME/local/lib/libSDL2.so" ]; then
+ wget https://www.libsdl.org/release/SDL2-2.0.4.tar.gz -O ~/SDL2.tar.gz
+ tar -xzvf ~/SDL2.tar.gz -C ~/
+ mkdir ~/sdl-build
+ cd ~/sdl-build
+ export CC=gcc-5
+ ~/SDL2-2.0.4/configure --prefix=$HOME/local
+ make -j2
+ make install
+else
+ echo 'Using cached SDL2 build directory.';
+fi