summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDidier Raboud <odyx@debian.org>2020-05-05 19:19:24 +0200
committerDidier Raboud <odyx@debian.org>2020-05-05 19:19:24 +0200
commit19fe87e593d9772e8116281c2f0cb63cf59efb53 (patch)
tree8ee5b0970c1b488d4555b8ba4b3be175adfdf4f4
parent22915829711618e24c3c3b711bde4d0b50a1385d (diff)
parent4b1a7cce5512cbb80a48fd498da89e6fd38a53e6 (diff)
Update to upstream 1.0.8
[git-debrebase anchor: new upstream 1.0.8, merge]
-rw-r--r--.github/ISSUE_TEMPLATE/bug_report.md29
-rw-r--r--.travis.yml138
-rw-r--r--CMakeLists.txt107
-rw-r--r--README.md4
-rw-r--r--cmake/FindSDL2.cmake388
-rw-r--r--examples/example_complex.c2
-rw-r--r--examples/example_custom.c2
-rw-r--r--examples/example_rwops.c2
-rw-r--r--examples/example_simple.c2
-rw-r--r--include/kitchensink/internal/audio/kitaudio.h2
-rw-r--r--include/kitchensink/internal/kitdecoder.h40
-rw-r--r--include/kitchensink/internal/subtitle/kitatlas.h2
-rw-r--r--include/kitchensink/internal/subtitle/kitsubtitle.h6
-rw-r--r--include/kitchensink/internal/utils/kithelpers.h2
-rw-r--r--include/kitchensink/internal/video/kitvideo.h2
-rw-r--r--src/internal/audio/kitaudio.c26
-rw-r--r--src/internal/kitdecoder.c72
-rw-r--r--src/internal/subtitle/kitatlas.c21
-rw-r--r--src/internal/subtitle/kitsubtitle.c30
-rw-r--r--src/internal/subtitle/renderers/kitsubass.c37
-rw-r--r--src/internal/subtitle/renderers/kitsubimage.c15
-rw-r--r--src/internal/utils/kithelpers.c4
-rw-r--r--src/internal/video/kitvideo.c26
-rw-r--r--src/kiterror.c2
-rw-r--r--src/kitlib.c10
-rw-r--r--src/kitplayer.c115
-rw-r--r--src/kitsource.c32
27 files changed, 836 insertions, 282 deletions
diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md
new file mode 100644
index 0000000..737033e
--- /dev/null
+++ b/.github/ISSUE_TEMPLATE/bug_report.md
@@ -0,0 +1,29 @@
+---
+name: Bug report
+about: Create a report to help us improve
+title: ''
+labels: bug
+assignees: katajakasa
+
+---
+
+**Describe the bug**
+A clear and concise description of what the bug is.
+
+**Expected behavior**
+A clear and concise description of what you expected to happen.
+
+**Observed behaviour**
+A clear and concise description of what actually happened.
+
+**Screenshots**
+If applicable, add screenshots to help explain your problem.
+
+**Platform (please fill out as much as possible):**
+ - OS: [e.g. Ubuntu linux 18.04 LTS]
+ - SDL version
+ - FFMPEG version
+ - SDL_Kitchensink version or commit id
+
+**Additional context**
+Add any other context about the problem here.
diff --git a/.travis.yml b/.travis.yml
index 2dc6271..4944acd 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,38 +1,116 @@
language: c
-sudo: required
-dist: trusty
+dist: xenial
-compiler:
- - gcc
+matrix:
+ include:
+ - os: linux
+ addons:
+ sonarcloud:
+ organization: "katajakasa-github"
+ apt:
+ sources:
+ - ubuntu-toolchain-r-test
+ - sourceline: 'deb https://apt.kitware.com/ubuntu/ xenial main'
+ key_url: 'https://apt.kitware.com/keys/kitware-archive-latest.asc'
+ - sourceline: 'ppa:jonathonf/ffmpeg-4'
+ - sourceline: 'ppa:litenstein/sdl2-xenial'
+ packages:
+ - gcc-8
+ - cmake
+ - cmake-data
+ - libass-dev
+ - libavcodec-dev
+ - libavformat-dev
+ - libswresample-dev
+ - libswscale-dev
+ - libavutil-dev
+ - libsdl2-dev
+ cache:
+ directories:
+ - '$HOME/.sonar/cache'
+ after_script:
+ - build-wrapper-linux-x86-64 --out-dir bw-output make
+ - sonar-scanner
+ env:
+ - MATRIX_EVAL="CC=gcc-8"
+ - os: linux
+ addons:
+ apt:
+ sources:
+ - ubuntu-toolchain-r-test
+ - sourceline: 'deb https://apt.kitware.com/ubuntu/ xenial main'
+ key_url: 'https://apt.kitware.com/keys/kitware-archive-latest.asc'
+ - sourceline: 'ppa:jonathonf/ffmpeg-4'
+ - sourceline: 'ppa:litenstein/sdl2-xenial'
+ packages:
+ - gcc-9
+ - cmake
+ - cmake-data
+ - libass-dev
+ - libavcodec-dev
+ - libavformat-dev
+ - libswresample-dev
+ - libswscale-dev
+ - libavutil-dev
+ - libsdl2-dev
+ env:
+ - MATRIX_EVAL="CC=gcc-9"
+ - os: linux
+ addons:
+ apt:
+ sources:
+ - ubuntu-toolchain-r-test
+ - llvm-toolchain-xenial-7
+ - sourceline: 'deb https://apt.kitware.com/ubuntu/ xenial main'
+ key_url: 'https://apt.kitware.com/keys/kitware-archive-latest.asc'
+ - sourceline: 'ppa:jonathonf/ffmpeg-4'
+ - sourceline: 'ppa:litenstein/sdl2-xenial'
+ packages:
+ - clang-7
+ - cmake
+ - cmake-data
+ - libass-dev
+ - libavcodec-dev
+ - libavformat-dev
+ - libswresample-dev
+ - libswscale-dev
+ - libavutil-dev
+ - libsdl2-dev
+ env:
+ - MATRIX_EVAL="CC=clang-7"
+ - os: linux
+ addons:
+ apt:
+ sources:
+ - ubuntu-toolchain-r-test
+ - llvm-toolchain-xenial-8
+ - sourceline: 'deb https://apt.kitware.com/ubuntu/ xenial main'
+ key_url: 'https://apt.kitware.com/keys/kitware-archive-latest.asc'
+ - sourceline: 'ppa:jonathonf/ffmpeg-4'
+ - sourceline: 'ppa:litenstein/sdl2-xenial'
+ packages:
+ - clang-8
+ - cmake
+ - cmake-data
+ - libass-dev
+ - libavcodec-dev
+ - libavformat-dev
+ - libswresample-dev
+ - libswscale-dev
+ - libavutil-dev
+ - libsdl2-dev
+ env:
+ - MATRIX_EVAL="CC=clang-8"
+
+before_install:
+ - eval "${MATRIX_EVAL}"
script:
- - wget https://www.libsdl.org/release/SDL2-2.0.8.tar.gz -O - | tar -xz
- - cd SDL2-2.0.8 && CC=gcc-7 ./configure --prefix=/usr && make -j2 && sudo make install && cd ..
- - cmake -DCMAKE_BUILD_TYPE=Debug -DBUILD_EXAMPLES=On -DUSE_DYNAMIC_LIBASS=On -DCMAKE_C_COMPILER=/usr/bin/gcc-7 .
- - build-wrapper-linux-x86-64 --out-dir bw-output make && sonar-scanner
+ - cd $TRAVIS_BUILD_DIR
+ - cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_EXAMPLES=On .
+ - make
+ - make clean
notifications:
email: false
-
-addons:
- sonarcloud:
- organization: "katajakasa-github"
- apt:
- sources:
- - sourceline: 'ppa:ubuntu-toolchain-r/test'
- - sourceline: 'ppa:george-edison55/cmake-3.x'
- - sourceline: 'ppa:jonathonf/ffmpeg-3'
- packages:
- - cmake
- - gcc-7
- - libass-dev
- - libavcodec-dev
- - libavformat-dev
- - libswresample-dev
- - libswscale-dev
- - libavutil-dev
-
-cache:
- directories:
- - '$HOME/.sonar/cache'
diff --git a/CMakeLists.txt b/CMakeLists.txt
index f048ee9..0f82906 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -5,7 +5,7 @@ set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
set(KIT_VERSION_MAJOR "1")
set(KIT_VERSION_MINOR "0")
-set(KIT_VERSION_PATCH "7")
+set(KIT_VERSION_PATCH "8")
set(KIT_VERSION ${KIT_VERSION_MAJOR}.${KIT_VERSION_MINOR}.${KIT_VERSION_PATCH})
add_definitions(
-DKIT_VERSION_MAJOR=${KIT_VERSION_MAJOR}
@@ -22,6 +22,28 @@ set(CMAKE_C_FLAGS_MINSIZEREL "${CMAKE_C_FLAGS_MINSIZEREL} -Os -DNDEBUG")
option(BUILD_EXAMPLES "Build examples" OFF)
option(USE_DYNAMIC_LIBASS "Use dynamically loaded libass" OFF)
option(USE_ASAN "Use AddressSanitizer" OFF)
+option(BUILD_SHARED "Build shared library" ON)
+option(BUILD_STATIC "Build static library" ON)
+
+if(NOT BUILD_SHARED AND NOT BUILD_STATIC)
+ message(FATAL_ERROR "Nothing to build, set BUILD_SHARED and/or BUILD_STATIC.")
+endif()
+
+if(BUILD_SHARED)
+ message(STATUS "Building shared libraries")
+else()
+ message(STATUS "NOT building shared libraries")
+endif()
+
+if(BUILD_STATIC)
+ message(STATUS "Building static libraries")
+else()
+ message(STATUS "NOT building static libraries")
+endif()
+
+if(USE_ASAN)
+ message(STATUS "DEVELOPMENT: AddressSanitizer enabled!")
+endif()
find_package(SDL2 REQUIRED)
find_package(ffmpeg COMPONENTS avcodec avformat avutil swscale swresample)
@@ -53,32 +75,46 @@ endif()
FILE(GLOB_RECURSE SOURCES "src/*.c")
FILE(GLOB INSTALL_HEADERS "include/kitchensink/*.h")
-add_library(SDL_kitchensink SHARED ${SOURCES})
-add_library(SDL_kitchensink_static STATIC ${SOURCES})
+include_directories(${INCLUDES})
-set_target_properties(SDL_kitchensink PROPERTIES VERSION ${KIT_VERSION})
-set_target_properties(SDL_kitchensink PROPERTIES SOVERSION ${KIT_VERSION_MAJOR})
+set(INSTALL_TARGETS "")
-set_target_properties(SDL_kitchensink PROPERTIES DEBUG_POSTFIX "d")
-set_target_properties(SDL_kitchensink_static PROPERTIES DEBUG_POSTFIX "d")
+if(BUILD_SHARED)
+ add_library(SDL_kitchensink SHARED ${SOURCES})
-target_compile_definitions(SDL_kitchensink PRIVATE "KIT_DLL;KIT_DLL_EXPORTS")
-target_compile_options(SDL_kitchensink PRIVATE "-fvisibility=hidden")
+ if(USE_ASAN)
+ target_compile_options(SDL_kitchensink PRIVATE "-fsanitize=address")
+ target_link_libraries(SDL_kitchensink asan)
+ endif()
-set_property(TARGET SDL_kitchensink PROPERTY C_STANDARD 99)
-set_property(TARGET SDL_kitchensink_static PROPERTY C_STANDARD 99)
+ target_link_libraries(SDL_kitchensink ${LIBRARIES})
-if(USE_ASAN)
- set(LIBRARIES asan ${LIBRARIES})
- target_compile_options(SDL_kitchensink PRIVATE "-fsanitize=address")
- message(STATUS "DEVELOPMENT: AddressSanitizer enabled!")
+ 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")
+
+ target_compile_definitions(SDL_kitchensink PRIVATE "KIT_DLL;KIT_DLL_EXPORTS")
+ target_compile_options(SDL_kitchensink PRIVATE "-fvisibility=hidden")
+
+ set_property(TARGET SDL_kitchensink PROPERTY C_STANDARD 99)
+
+ set(INSTALL_TARGETS SDL_kitchensink ${INSTALL_TARGETS})
endif()
-include_directories(${INCLUDES})
-target_link_libraries(SDL_kitchensink ${LIBRARIES})
+if(BUILD_STATIC)
+ add_library(SDL_kitchensink_static STATIC ${SOURCES})
-set(PKG_CONFIG_FILE "${CMAKE_CURRENT_BINARY_DIR}/SDL_kitchensink.pc")
+ if(USE_ASAN)
+ target_compile_options(SDL_kitchensink_static PRIVATE "-fsanitize=address")
+ endif()
+ set_target_properties(SDL_kitchensink_static PROPERTIES DEBUG_POSTFIX "d")
+ set_property(TARGET SDL_kitchensink_static PROPERTY C_STANDARD 99)
+
+ set(INSTALL_TARGETS SDL_kitchensink_static ${INSTALL_TARGETS})
+endif()
+
+set(PKG_CONFIG_FILE "${CMAKE_CURRENT_BINARY_DIR}/SDL_kitchensink.pc")
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/pkg-config.pc.in"
${PKG_CONFIG_FILE}
@@ -106,20 +142,39 @@ if(BUILD_EXAMPLES)
set_property(TARGET custom PROPERTY C_STANDARD 99)
set_property(TARGET rwops PROPERTY C_STANDARD 99)
- target_link_libraries(audio SDL_kitchensink_static ${LIBRARIES})
- target_link_libraries(complex SDL_kitchensink_static ${LIBRARIES})
- target_link_libraries(simple SDL_kitchensink_static ${LIBRARIES})
- target_link_libraries(custom SDL_kitchensink_static ${LIBRARIES})
- target_link_libraries(rwops SDL_kitchensink_static ${LIBRARIES})
+ # If we are building static, just link all libraries (ffmpeg, sdl, etc.)
+ # If building shared, link shared kitchensink + SDL2 (ffmpeg gets pulled by kitchensink)
+ if(BUILD_STATIC)
+ set(EXAMPLE_LIBRARIES SDL_kitchensink_static ${LIBRARIES})
+ else()
+ set(EXAMPLE_LIBRARIES SDL_kitchensink ${SDL2_LIBRARIES})
+ endif()
+ if(USE_ASAN)
+ set(EXAMPLE_LIBRARIES asan ${EXAMPLE_LIBRARIES})
+ endif()
+
+ target_link_libraries(audio ${EXAMPLE_LIBRARIES})
+ target_link_libraries(complex ${EXAMPLE_LIBRARIES})
+ target_link_libraries(simple ${EXAMPLE_LIBRARIES})
+ target_link_libraries(custom ${EXAMPLE_LIBRARIES})
+ target_link_libraries(rwops ${EXAMPLE_LIBRARIES})
+
+ if(USE_ASAN)
+ target_compile_options(audio PRIVATE "-fsanitize=address")
+ target_compile_options(complex PRIVATE "-fsanitize=address")
+ target_compile_options(simple PRIVATE "-fsanitize=address")
+ target_compile_options(custom PRIVATE "-fsanitize=address")
+ target_compile_options(rwops PRIVATE "-fsanitize=address")
+ endif()
endif()
# documentation target
add_custom_target(docs COMMAND doxygen WORKING_DIRECTORY ${PROJECT_SOURCE_DIR})
# Installation
-install(FILES ${PKG_CONFIG_FILE} DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
-install(FILES ${INSTALL_HEADERS} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/kitchensink)
-INSTALL(TARGETS SDL_kitchensink SDL_kitchensink_static
+INSTALL(FILES ${PKG_CONFIG_FILE} DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
+INSTALL(FILES ${INSTALL_HEADERS} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/kitchensink)
+INSTALL(TARGETS ${INSTALL_TARGETS}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
diff --git a/README.md b/README.md
index d2745ce..744bad7 100644
--- a/README.md
+++ b/README.md
@@ -52,6 +52,8 @@ 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.
+* Set BUILD_STATIC off if you don't want to build static library
+* Set BUILD_SHARED off if you don't want to build shared library
* 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'.
@@ -88,7 +90,7 @@ supported on all OSes (eg. windows).
After building, you can run with the following (make sure to set correct llvm-symbolizer path):
```
-ASAN_OPTIONS=symbolize=1 ASAN_SYMBOLIZER_PATH=/usr/bin/llvm-symbolizer ./examplevideo <my videofile>
+ASAN_OPTIONS=symbolize=1 ASAN_SYMBOLIZER_PATH=/usr/bin/llvm-symbolizer ./complex <my videofile>
```
## 3. Why the name SDL_kitchensink
diff --git a/cmake/FindSDL2.cmake b/cmake/FindSDL2.cmake
new file mode 100644
index 0000000..a3673a7
--- /dev/null
+++ b/cmake/FindSDL2.cmake
@@ -0,0 +1,388 @@
+# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
+# file Copyright.txt or https://cmake.org/licensing for details.
+
+# Copyright 2019 Amine Ben Hassouna <amine.benhassouna@gmail.com>
+# Copyright 2000-2019 Kitware, Inc. and Contributors
+# All rights reserved.
+
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+
+# * Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+
+# * Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+
+# * Neither the name of Kitware, Inc. nor the names of Contributors
+# may be used to endorse or promote products derived from this
+# software without specific prior written permission.
+
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#[=======================================================================[.rst:
+FindSDL2
+--------
+
+Locate SDL2 library
+
+This module defines the following 'IMPORTED' targets:
+
+::
+
+ SDL2::Core
+ The SDL2 library, if found.
+ Libraries should link to SDL2::Core
+
+ SDL2::Main
+ The SDL2main library, if found.
+ Applications should link to SDL2::Main instead of SDL2::Core
+
+
+
+This module will set the following variables in your project:
+
+::
+
+ SDL2_LIBRARIES, the name of the library to link against
+ SDL2_INCLUDE_DIRS, where to find SDL.h
+ SDL2_FOUND, if false, do not try to link to SDL2
+ SDL2MAIN_FOUND, if false, do not try to link to SDL2main
+ SDL2_VERSION_STRING, human-readable string containing the version of SDL2
+
+
+
+This module responds to the following cache variables:
+
+::
+
+ SDL2_PATH
+ Set a custom SDL2 Library path (default: empty)
+
+ SDL2_NO_DEFAULT_PATH
+ Disable search SDL2 Library in default path.
+ If SDL2_PATH (default: ON)
+ Else (default: OFF)
+
+ SDL2_INCLUDE_DIR
+ SDL2 headers path.
+
+ SDL2_LIBRARY
+ SDL2 Library (.dll, .so, .a, etc) path.
+
+ SDL2MAIN_LIBRAY
+ SDL2main Library (.a) path.
+
+ SDL2_BUILDING_LIBRARY
+ This flag is useful only when linking to SDL2_LIBRARIES insead of
+ SDL2::Main. It is required only when building a library that links to
+ SDL2_LIBRARIES, because only applications need main() (No need to also
+ link to SDL2main).
+ If this flag is defined, then no SDL2main will be added to SDL2_LIBRARIES
+ and no SDL2::Main target will be created.
+
+
+Don't forget to include SDLmain.h and SDLmain.m in your project for the
+OS X framework based version. (Other versions link to -lSDL2main which
+this module will try to find on your behalf.) Also for OS X, this
+module will automatically add the -framework Cocoa on your behalf.
+
+
+Additional Note: If you see an empty SDL2_LIBRARY in your project
+configuration, it means CMake did not find your SDL2 library
+(SDL2.dll, libsdl2.so, SDL2.framework, etc). Set SDL2_LIBRARY to point
+to your SDL2 library, and configure again. Similarly, if you see an
+empty SDL2MAIN_LIBRARY, you should set this value as appropriate. These
+values are used to generate the final SDL2_LIBRARIES variable and the
+SDL2::Core and SDL2::Main targets, but when these values are unset,
+SDL2_LIBRARIES, SDL2::Core and SDL2::Main does not get created.
+
+
+$SDL2DIR is an environment variable that would correspond to the
+./configure --prefix=$SDL2DIR used in building SDL2. l.e.galup 9-20-02
+
+
+
+Created by Amine Ben Hassouna:
+ Adapt FindSDL.cmake to SDL2 (FindSDL2.cmake).
+ Add cache variables for more flexibility:
+ SDL2_PATH, SDL2_NO_DEFAULT_PATH (for details, see doc above).
+ Mark 'Threads' as a required dependency for non-OSX systems.
+ Modernize the FindSDL2.cmake module by creating specific targets:
+ SDL2::Core and SDL2::Main (for details, see doc above).
+
+
+Original FindSDL.cmake module:
+ Modified by Eric Wing. Added code to assist with automated building
+ by using environmental variables and providing a more
+ controlled/consistent search behavior. Added new modifications to
+ recognize OS X frameworks and additional Unix paths (FreeBSD, etc).
+ Also corrected the header search path to follow "proper" SDL
+ guidelines. Added a search for SDLmain which is needed by some
+ platforms. Added a search for threads which is needed by some
+ platforms. Added needed compile switches for MinGW.
+
+On OSX, this will prefer the Framework version (if found) over others.
+People will have to manually change the cache value of SDL2_LIBRARY to
+override this selection or set the SDL2_PATH variable or the CMake
+environment CMAKE_INCLUDE_PATH to modify the search paths.
+
+Note that the header path has changed from SDL/SDL.h to just SDL.h
+This needed to change because "proper" SDL convention is #include
+"SDL.h", not <SDL/SDL.h>. This is done for portability reasons
+because not all systems place things in SDL/ (see FreeBSD).
+#]=======================================================================]
+
+# Define options for searching SDL2 Library in a custom path
+
+set(SDL2_PATH "" CACHE STRING "Custom SDL2 Library path")
+
+set(_SDL2_NO_DEFAULT_PATH OFF)
+if(SDL2_PATH)
+ set(_SDL2_NO_DEFAULT_PATH ON)
+endif()
+
+set(SDL2_NO_DEFAULT_PATH ${_SDL2_NO_DEFAULT_PATH}
+ CACHE BOOL "Disable search SDL2 Library in default path")
+unset(_SDL2_NO_DEFAULT_PATH)
+
+set(SDL2_NO_DEFAULT_PATH_CMD)
+if(SDL2_NO_DEFAULT_PATH)
+ set(SDL2_NO_DEFAULT_PATH_CMD NO_DEFAULT_PATH)
+endif()
+
+# Search for the SDL2 include directory
+find_path(SDL2_INCLUDE_DIR SDL.h
+ HINTS
+ ENV SDL2DIR
+ ${SDL2_NO_DEFAULT_PATH_CMD}
+ PATH_SUFFIXES SDL2
+ # path suffixes to search inside ENV{SDL2DIR}
+ include/SDL2 include
+ PATHS ${SDL2_PATH}
+ DOC "Where the SDL2 headers can be found"
+)
+
+set(SDL2_INCLUDE_DIRS "${SDL2_INCLUDE_DIR}")
+
+if(CMAKE_SIZEOF_VOID_P EQUAL 8)
+ set(VC_LIB_PATH_SUFFIX lib/x64)
+else()
+ set(VC_LIB_PATH_SUFFIX lib/x86)
+endif()
+
+# SDL-2.0 is the name used by FreeBSD ports...
+# don't confuse it for the version number.
+find_library(SDL2_LIBRARY
+ NAMES SDL2 SDL-2.0
+ HINTS
+ ENV SDL2DIR
+ ${SDL2_NO_DEFAULT_PATH_CMD}
+ PATH_SUFFIXES lib ${VC_LIB_PATH_SUFFIX}
+ PATHS ${SDL2_PATH}
+ DOC "Where the SDL2 Library can be found"
+)
+
+set(SDL2_LIBRARIES "${SDL2_LIBRARY}")
+
+if(NOT SDL2_BUILDING_LIBRARY)
+ if(NOT SDL2_INCLUDE_DIR MATCHES ".framework")
+ # Non-OS X framework versions expect you to also dynamically link to
+ # SDL2main. This is mainly for Windows and OS X. Other (Unix) platforms
+ # seem to provide SDL2main for compatibility even though they don't
+ # necessarily need it.
+
+ if(SDL2_PATH)
+ set(SDL2MAIN_LIBRARY_PATHS "${SDL2_PATH}")
+ endif()
+
+ if(NOT SDL2_NO_DEFAULT_PATH)
+ set(SDL2MAIN_LIBRARY_PATHS
+ /sw
+ /opt/local
+ /opt/csw
+ /opt
+ "${SDL2MAIN_LIBRARY_PATHS}"
+ )
+ endif()
+
+ find_library(SDL2MAIN_LIBRARY
+ NAMES SDL2main
+ HINTS
+ ENV SDL2DIR
+ ${SDL2_NO_DEFAULT_PATH_CMD}
+ PATH_SUFFIXES lib ${VC_LIB_PATH_SUFFIX}
+ PATHS ${SDL2MAIN_LIBRARY_PATHS}
+ DOC "Where the SDL2main library can be found"
+ )
+ unset(SDL2MAIN_LIBRARY_PATHS)
+ endif()
+endif()
+
+# SDL2 may require threads on your system.
+# The Apple build may not need an explicit flag because one of the
+# frameworks may already provide it.
+# But for non-OSX systems, I will use the CMake Threads package.
+if(NOT APPLE)
+ find_package(Threads QUIET)
+ if(NOT Threads_FOUND)
+ set(SDL2_THREADS_NOT_FOUND "Could NOT find Threads (Threads is required by SDL2).")
+ if(SDL2_FIND_REQUIRED)
+ message(FATAL_ERROR ${SDL2_THREADS_NOT_FOUND})
+ else()
+ if(NOT SDL2_FIND_QUIETLY)
+ message(STATUS ${SDL2_THREADS_NOT_FOUND})
+ endif()
+ return()
+ endif()
+ unset(SDL2_THREADS_NOT_FOUND)
+ endif()
+endif()
+
+# MinGW needs an additional link flag, -mwindows
+# It's total link flags should look like -lmingw32 -lSDL2main -lSDL2 -mwindows
+if(MINGW)
+ set(MINGW32_LIBRARY mingw32 "-mwindows" CACHE STRING "link flags for MinGW")
+endif()
+
+if(SDL2_LIBRARY)
+ # For SDL2main
+ if(SDL2MAIN_LIBRARY AND NOT SDL2_BUILDING_LIBRARY)
+ list(FIND SDL2_LIBRARIES "${SDL2MAIN_LIBRARY}" _SDL2_MAIN_INDEX)
+ if(_SDL2_MAIN_INDEX EQUAL -1)
+ set(SDL2_LIBRARIES "${SDL2MAIN_LIBRARY}" ${SDL2_LIBRARIES})
+ endif()
+ unset(_SDL2_MAIN_INDEX)
+ endif()
+
+ # For OS X, SDL2 uses Cocoa as a backend so it must link to Cocoa.
+ # CMake doesn't display the -framework Cocoa string in the UI even
+ # though it actually is there if I modify a pre-used variable.
+ # I think it has something to do with the CACHE STRING.
+ # So I use a temporary variable until the end so I can set the
+ # "real" variable in one-shot.
+ if(APPLE)
+ set(SDL2_LIBRARIES ${SDL2_LIBRARIES} -framework Cocoa)
+ endif()
+
+ # For threads, as mentioned Apple doesn't need this.
+ # In fact, there seems to be a problem if I used the Threads package
+ # and try using this line, so I'm just skipping it entirely for OS X.
+ if(NOT APPLE)
+ set(SDL2_LIBRARIES ${SDL2_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT})
+ endif()
+
+ # For MinGW library
+ if(MINGW)
+ set(SDL2_LIBRARIES ${MINGW32_LIBRARY} ${SDL2_LIBRARIES})
+ endif()
+
+endif()
+
+# Read SDL2 version
+if(SDL2_INCLUDE_DIR AND EXISTS "${SDL2_INCLUDE_DIR}/SDL_version.h")
+ file(STRINGS "${SDL2_INCLUDE_DIR}/SDL_version.h" SDL2_VERSION_MAJOR_LINE REGEX "^#define[ \t]+SDL_MAJOR_VERSION[ \t]+[0-9]+$")
+ file(STRINGS "${SDL2_INCLUDE_DIR}/SDL_version.h" SDL2_VERSION_MINOR_LINE REGEX "^#define[ \t]+SDL_MINOR_VERSION[ \t]+[0-9]+$")
+ file(STRINGS "${SDL2_INCLUDE_DIR}/SDL_version.h" SDL2_VERSION_PATCH_LINE REGEX "^#define[ \t]+SDL_PATCHLEVEL[ \t]+[0-9]+$")
+ string(REGEX REPLACE "^#define[ \t]+SDL_MAJOR_VERSION[ \t]+([0-9]+)$" "\\1" SDL2_VERSION_MAJOR "${SDL2_VERSION_MAJOR_LINE}")
+ string(REGEX REPLACE "^#define[ \t]+SDL_MINOR_VERSION[ \t]+([0-9]+)$" "\\1" SDL2_VERSION_MINOR "${SDL2_VERSION_MINOR_LINE}")
+ string(REGEX REPLACE "^#define[ \t]+SDL_PATCHLEVEL[ \t]+([0-9]+)$" "\\1" SDL2_VERSION_PATCH "${SDL2_VERSION_PATCH_LINE}")
+ set(SDL2_VERSION_STRING ${SDL2_VERSION_MAJOR}.${SDL2_VERSION_MINOR}.${SDL2_VERSION_PATCH})
+ unset(SDL2_VERSION_MAJOR_LINE)
+ unset(SDL2_VERSION_MINOR_LINE)
+ unset(SDL2_VERSION_PATCH_LINE)
+ unset(SDL2_VERSION_MAJOR)
+ unset(SDL2_VERSION_MINOR)
+ unset(SDL2_VERSION_PATCH)
+endif()
+
+include(FindPackageHandleStandardArgs)
+
+FIND_PACKAGE_HANDLE_STANDARD_ARGS(SDL2
+ REQUIRED_VARS SDL2_LIBRARY SDL2_INCLUDE_DIR
+ VERSION_VAR SDL2_VERSION_STRING)
+
+if(SDL2MAIN_LIBRARY)
+ FIND_PACKAGE_HANDLE_STANDARD_ARGS(SDL2main
+ REQUIRED_VARS SDL2MAIN_LIBRARY SDL2_INCLUDE_DIR
+ VERSION_VAR SDL2_VERSION_STRING)
+endif()
+
+
+mark_as_advanced(SDL2_PATH
+ SDL2_NO_DEFAULT_PATH
+ SDL2_LIBRARY
+ SDL2MAIN_LIBRARY
+ SDL2_INCLUDE_DIR
+ SDL2_BUILDING_LIBRARY)
+
+
+# SDL2:: targets (SDL2::Core and SDL2::Main)
+if(SDL2_FOUND)
+
+ # SDL2::Core target
+ if(SDL2_LIBRARY AND NOT TARGET SDL2::Core)
+ add_library(SDL2::Core UNKNOWN IMPORTED)
+ set_target_properties(SDL2::Core PROPERTIES
+ IMPORTED_LOCATION "${SDL2_LIBRARY}"
+ INTERFACE_INCLUDE_DIRECTORIES "${SDL2_INCLUDE_DIR}")
+
+ if(APPLE)
+ # For OS X, SDL2 uses Cocoa as a backend so it must link to Cocoa.
+ # For more details, please see above.
+ set_property(TARGET SDL2::Core APPEND PROPERTY
+ INTERFACE_LINK_OPTIONS -framework Cocoa)
+ else()
+ # For threads, as mentioned Apple doesn't need this.
+ # For more details, please see above.
+ set_property(TARGET SDL2::Core APPEND PROPERTY
+ INTERFACE_LINK_LIBRARIES Threads::Threads)
+ endif()
+ endif()
+
+ # SDL2::Main target
+ # Applications should link to SDL2::Main instead of SDL2::Core
+ # For more details, please see above.
+ if(NOT SDL2_BUILDING_LIBRARY AND NOT TARGET SDL2::Main)
+
+ if(SDL2_INCLUDE_DIR MATCHES ".framework" OR NOT SDL2MAIN_LIBRARY)
+ add_library(SDL2::Main INTERFACE IMPORTED)
+ set_property(TARGET SDL2::Main PROPERTY
+ INTERFACE_LINK_LIBRARIES SDL2::Core)
+ elseif(SDL2MAIN_LIBRARY)
+ # MinGW requires that the mingw32 library is specified before the
+ # libSDL2main.a static library when linking.
+ # The SDL2::MainInternal target is used internally to make sure that
+ # CMake respects this condition.
+ add_library(SDL2::MainInternal UNKNOWN IMPORTED)
+ set_property(TARGET SDL2::MainInternal PROPERTY
+ IMPORTED_LOCATION "${SDL2MAIN_LIBRARY}")
+ set_property(TARGET SDL2::MainInternal PROPERTY
+ INTERFACE_LINK_LIBRARIES SDL2::Core)
+
+ add_library(SDL2::Main INTERFACE IMPORTED)
+
+ if(MINGW)
+ # MinGW needs an additional link flag '-mwindows' and link to mingw32
+ set_property(TARGET SDL2::Main PROPERTY
+ INTERFACE_LINK_LIBRARIES "mingw32" "-mwindows")
+ endif()
+
+ set_property(TARGET SDL2::Main APPEND PROPERTY
+ INTERFACE_LINK_LIBRARIES SDL2::MainInternal)
+ endif()
+
+ endif()
+endif()
diff --git a/examples/example_complex.c b/examples/example_complex.c
index 779c879..8af8c3a 100644
--- a/examples/example_complex.c
+++ b/examples/example_complex.c
@@ -96,7 +96,7 @@ int main(int argc, char *argv[]) {
// 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) {
+ if(renderer == NULL) {
fprintf(stderr, "Unable to create a renderer!\n");
return 1;
}
diff --git a/examples/example_custom.c b/examples/example_custom.c
index 8844b79..c02f7dc 100644
--- a/examples/example_custom.c
+++ b/examples/example_custom.c
@@ -56,7 +56,7 @@ int main(int argc, char *argv[]) {
// 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) {
+ if(renderer == NULL) {
fprintf(stderr, "Unable to create a renderer!\n");
return 1;
}
diff --git a/examples/example_rwops.c b/examples/example_rwops.c
index 96a3655..9aa6d96 100644
--- a/examples/example_rwops.c
+++ b/examples/example_rwops.c
@@ -48,7 +48,7 @@ int main(int argc, char *argv[]) {
// 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) {
+ if(renderer == NULL) {
fprintf(stderr, "Unable to create a renderer!\n");
return 1;
}
diff --git a/examples/example_simple.c b/examples/example_simple.c
index 234a83d..bce0751 100644
--- a/examples/example_simple.c
+++ b/examples/example_simple.c
@@ -47,7 +47,7 @@ int main(int argc, char *argv[]) {
// 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) {
+ if(renderer == NULL) {
fprintf(stderr, "Unable to create a renderer!\n");
return 1;
}
diff --git a/include/kitchensink/internal/audio/kitaudio.h b/include/kitchensink/internal/audio/kitaudio.h
index c3db420..0558343 100644
--- a/include/kitchensink/internal/audio/kitaudio.h
+++ b/include/kitchensink/internal/audio/kitaudio.h
@@ -7,6 +7,6 @@
KIT_LOCAL Kit_Decoder* Kit_CreateAudioDecoder(const Kit_Source *src, int stream_index);
KIT_LOCAL int Kit_GetAudioDecoderData(Kit_Decoder *dec, unsigned char *buf, int len);
-KIT_LOCAL double Kit_GetAudioDecoderPTS(Kit_Decoder *dec);
+KIT_LOCAL double Kit_GetAudioDecoderPTS(const Kit_Decoder *dec);
#endif // KITAUDIO_H
diff --git a/include/kitchensink/internal/kitdecoder.h b/include/kitchensink/internal/kitdecoder.h
index 17e1e4b..e12c5fe 100644
--- a/include/kitchensink/internal/kitdecoder.h
+++ b/include/kitchensink/internal/kitdecoder.h
@@ -55,25 +55,25 @@ KIT_LOCAL void Kit_SetDecoderClockSync(Kit_Decoder *dec, double sync);
KIT_LOCAL void Kit_ChangeDecoderClockSync(Kit_Decoder *dec, double sync);
KIT_LOCAL int Kit_RunDecoder(Kit_Decoder *dec);
-KIT_LOCAL void Kit_ClearDecoderBuffers(Kit_Decoder *dec);
-
-KIT_LOCAL bool Kit_CanWriteDecoderInput(Kit_Decoder *dec);
-KIT_LOCAL int Kit_WriteDecoderInput(Kit_Decoder *dec, AVPacket *packet);
-KIT_LOCAL AVPacket* Kit_ReadDecoderInput(Kit_Decoder *dec);
-KIT_LOCAL void Kit_ClearDecoderInput(Kit_Decoder *dec);
-KIT_LOCAL AVPacket* Kit_PeekDecoderInput(Kit_Decoder *dec);
-KIT_LOCAL void Kit_AdvanceDecoderInput(Kit_Decoder *dec);
-
-KIT_LOCAL int Kit_WriteDecoderOutput(Kit_Decoder *dec, void *packet);
-KIT_LOCAL bool Kit_CanWriteDecoderOutput(Kit_Decoder *dec);
-KIT_LOCAL void* Kit_PeekDecoderOutput(Kit_Decoder *dec);
-KIT_LOCAL void* Kit_ReadDecoderOutput(Kit_Decoder *dec);
-KIT_LOCAL void Kit_AdvanceDecoderOutput(Kit_Decoder *dec);
-KIT_LOCAL void Kit_ForEachDecoderOutput(Kit_Decoder *dec, Kit_ForEachItemCallback foreach_cb, void *userdata);
-KIT_LOCAL int Kit_LockDecoderOutput(Kit_Decoder *dec);
-KIT_LOCAL void Kit_UnlockDecoderOutput(Kit_Decoder *dec);
-KIT_LOCAL void Kit_ClearDecoderOutput(Kit_Decoder *dec);
-KIT_LOCAL unsigned int Kit_GetDecoderOutputLength(Kit_Decoder *dec);
-
+KIT_LOCAL void Kit_ClearDecoderBuffers(const Kit_Decoder *dec);
+
+KIT_LOCAL bool Kit_CanWriteDecoderInput(const Kit_Decoder *dec);
+KIT_LOCAL int Kit_WriteDecoderInput(const Kit_Decoder *dec, AVPacket *packet);
+KIT_LOCAL AVPacket* Kit_ReadDecoderInput(const Kit_Decoder *dec);
+KIT_LOCAL void Kit_ClearDecoderInput(const Kit_Decoder *dec);
+KIT_LOCAL AVPacket* Kit_PeekDecoderInput(const Kit_Decoder *dec);
+KIT_LOCAL void Kit_AdvanceDecoderInput(const Kit_Decoder *dec);
+
+KIT_LOCAL int Kit_WriteDecoderOutput(const Kit_Decoder *dec, void *packet);
+KIT_LOCAL bool Kit_CanWriteDecoderOutput(const Kit_Decoder *dec);
+KIT_LOCAL void* Kit_PeekDecoderOutput(const Kit_Decoder *dec);
+KIT_LOCAL void* Kit_ReadDecoderOutput(const Kit_Decoder *dec);
+KIT_LOCAL void Kit_ClearDecoderOutput(const Kit_Decoder *dec);
+KIT_LOCAL void Kit_AdvanceDecoderOutput(const Kit_Decoder *dec);
+KIT_LOCAL void Kit_ForEachDecoderOutput(const Kit_Decoder *dec, Kit_ForEachItemCallback foreach_cb, void *userdata);
+KIT_LOCAL unsigned int Kit_GetDecoderOutputLength(const Kit_Decoder *dec);
+
+KIT_LOCAL int Kit_LockDecoderOutput(const Kit_Decoder *dec);
+KIT_LOCAL void Kit_UnlockDecoderOutput(const Kit_Decoder *dec);
#endif // KITDECODER_H
diff --git a/include/kitchensink/internal/subtitle/kitatlas.h b/include/kitchensink/internal/subtitle/kitatlas.h
index d9207c1..a408b2d 100644
--- a/include/kitchensink/internal/subtitle/kitatlas.h
+++ b/include/kitchensink/internal/subtitle/kitatlas.h
@@ -35,6 +35,6 @@ KIT_LOCAL void Kit_FreeAtlas(Kit_TextureAtlas *atlas);
KIT_LOCAL void Kit_ClearAtlasContent(Kit_TextureAtlas *atlas);
KIT_LOCAL void Kit_CheckAtlasTextureSize(Kit_TextureAtlas *atlas, SDL_Texture *texture);
KIT_LOCAL int Kit_GetAtlasItems(const Kit_TextureAtlas *atlas, SDL_Rect *sources, SDL_Rect *targets, int limit);
-KIT_LOCAL int Kit_AddAtlasItem(Kit_TextureAtlas *atlas, SDL_Texture *texture, SDL_Surface *surface, const SDL_Rect *target);
+KIT_LOCAL int Kit_AddAtlasItem(Kit_TextureAtlas *atlas, SDL_Texture *texture, const SDL_Surface *surface, const SDL_Rect *target);
#endif // KITATLAS_H
diff --git a/include/kitchensink/internal/subtitle/kitsubtitle.h b/include/kitchensink/internal/subtitle/kitsubtitle.h
index 09aabec..09ce8ad 100644
--- a/include/kitchensink/internal/subtitle/kitsubtitle.h
+++ b/include/kitchensink/internal/subtitle/kitsubtitle.h
@@ -9,9 +9,9 @@
KIT_LOCAL Kit_Decoder* Kit_CreateSubtitleDecoder(
const Kit_Source *src, int stream_index, int video_w, int video_h, int screen_w, int screen_h);
-KIT_LOCAL void Kit_GetSubtitleDecoderTexture(Kit_Decoder *dec, SDL_Texture *texture, double sync_ts);
-KIT_LOCAL void Kit_SetSubtitleDecoderSize(Kit_Decoder *dec, int w, int h);
+KIT_LOCAL void Kit_GetSubtitleDecoderTexture(const Kit_Decoder *dec, SDL_Texture *texture, double sync_ts);
+KIT_LOCAL void Kit_SetSubtitleDecoderSize(const Kit_Decoder *dec, int w, int h);
KIT_LOCAL int Kit_GetSubtitleDecoderInfo(
- Kit_Decoder *dec, SDL_Texture *texture, SDL_Rect *sources, SDL_Rect *targets, int limit);
+ const Kit_Decoder *dec, const SDL_Texture *texture, SDL_Rect *sources, SDL_Rect *targets, int limit);
#endif // KITSUBTITLE_H
diff --git a/include/kitchensink/internal/utils/kithelpers.h b/include/kitchensink/internal/utils/kithelpers.h
index 5b94a7a..e4c163c 100644
--- a/include/kitchensink/internal/utils/kithelpers.h
+++ b/include/kitchensink/internal/utils/kithelpers.h
@@ -6,6 +6,6 @@
#include "kitchensink/kitconfig.h"
KIT_LOCAL double _GetSystemTime();
-KIT_LOCAL bool attachment_is_font(AVStream *stream);
+KIT_LOCAL bool attachment_is_font(const AVStream *stream);
#endif // KITHELPERS_H
diff --git a/include/kitchensink/internal/video/kitvideo.h b/include/kitchensink/internal/video/kitvideo.h
index b393347..405c258 100644
--- a/include/kitchensink/internal/video/kitvideo.h
+++ b/include/kitchensink/internal/video/kitvideo.h
@@ -9,6 +9,6 @@
KIT_LOCAL Kit_Decoder* Kit_CreateVideoDecoder(const Kit_Source *src, int stream_index);
KIT_LOCAL int Kit_GetVideoDecoderData(Kit_Decoder *dec, SDL_Texture *texture);
-KIT_LOCAL double Kit_GetVideoDecoderPTS(Kit_Decoder *dec);
+KIT_LOCAL double Kit_GetVideoDecoderPTS(const Kit_Decoder *dec);
#endif // KITVIDEO_H
diff --git a/src/internal/audio/kitaudio.c b/src/internal/audio/kitaudio.c
index b2f41fc..b950fd9 100644
--- a/src/internal/audio/kitaudio.c
+++ b/src/internal/audio/kitaudio.c
@@ -182,8 +182,8 @@ static int dec_decode_audio_cb(Kit_Decoder *dec, AVPacket *in_packet) {
return 0;
}
#else
-static void dec_read_audio(Kit_Decoder *dec) {
- Kit_AudioDecoder *audio_dec = dec->userdata;
+static void dec_read_audio(const Kit_Decoder *dec) {
+ const Kit_AudioDecoder *audio_dec = dec->userdata;
int len;
int dst_linesize;
int dst_nb_samples;
@@ -278,7 +278,7 @@ Kit_Decoder* Kit_CreateAudioDecoder(const Kit_Source *src, int stream_index) {
return NULL;
}
- Kit_LibraryState *state = Kit_GetLibraryState();
+ const Kit_LibraryState *state = Kit_GetLibraryState();
// First the generic decoder component ...
Kit_Decoder *dec = Kit_CreateDecoder(
@@ -288,20 +288,20 @@ Kit_Decoder* Kit_CreateAudioDecoder(const Kit_Source *src, int stream_index) {
free_out_audio_packet_cb,
state->thread_count);
if(dec == NULL) {
- goto exit_0;
+ goto EXIT_0;
}
// ... then allocate the audio decoder
Kit_AudioDecoder *audio_dec = calloc(1, sizeof(Kit_AudioDecoder));
if(audio_dec == NULL) {
- goto exit_1;
+ goto EXIT_1;
}
// Create temporary audio frame
audio_dec->scratch_frame = av_frame_alloc();
if(audio_dec->scratch_frame == NULL) {
Kit_SetError("Unable to initialize temporary audio frame");
- goto exit_2;
+ goto EXIT_2;
}
// Set format configs
@@ -326,7 +326,7 @@ Kit_Decoder* Kit_CreateAudioDecoder(const Kit_Source *src, int stream_index) {
if(swr_init(audio_dec->swr) != 0) {
Kit_SetError("Unable to initialize audio resampler context");
- goto exit_3;
+ goto EXIT_3;
}
// Set callbacks and userdata, and we're go
@@ -336,18 +336,18 @@ Kit_Decoder* Kit_CreateAudioDecoder(const Kit_Source *src, int stream_index) {
dec->output = output;
return dec;
-exit_3:
+EXIT_3:
av_frame_free(&audio_dec->scratch_frame);
-exit_2:
+EXIT_2:
free(audio_dec);
-exit_1:
+EXIT_1:
Kit_CloseDecoder(dec);
-exit_0:
+EXIT_0:
return NULL;
}
-double Kit_GetAudioDecoderPTS(Kit_Decoder *dec) {
- Kit_AudioPacket *packet = Kit_PeekDecoderOutput(dec);
+double Kit_GetAudioDecoderPTS(const Kit_Decoder *dec) {
+ const Kit_AudioPacket *packet = Kit_PeekDecoderOutput(dec);
if(packet == NULL) {
return -1.0;
}
diff --git a/src/internal/kitdecoder.c b/src/internal/kitdecoder.c
index 9b925c7..c5b5589 100644
--- a/src/internal/kitdecoder.c
+++ b/src/internal/kitdecoder.c
@@ -21,7 +21,7 @@ Kit_Decoder* Kit_CreateDecoder(const Kit_Source *src, int stream_index,
AVCodecContext *codec_ctx = NULL;
AVDictionary *codec_opts = NULL;
- AVCodec *codec = NULL;
+ const AVCodec *codec = NULL;
AVFormatContext *format_ctx = src->format_ctx;
int bsizes[2] = {BUFFER_IN_SIZE, out_b_size};
dec_free_packet_cb free_hooks[2] = {free_in_video_packet_cb, free_out_cb};
@@ -29,14 +29,14 @@ Kit_Decoder* Kit_CreateDecoder(const Kit_Source *src, int stream_index,
// Make sure index seems correct
if(stream_index >= (int)format_ctx->nb_streams || stream_index < 0) {
Kit_SetError("Invalid stream %d", stream_index);
- goto exit_0;
+ goto EXIT_0;
}
// Allocate decoder and make sure allocation was a success
Kit_Decoder *dec = calloc(1, sizeof(Kit_Decoder));
if(dec == NULL) {
Kit_SetError("Unable to allocate kit decoder for stream %d", stream_index);
- goto exit_0;
+ goto EXIT_0;
}
// Find audio decoder
@@ -47,14 +47,14 @@ Kit_Decoder* Kit_CreateDecoder(const Kit_Source *src, int stream_index,
#endif
if(codec == NULL) {
Kit_SetError("No suitable decoder found for stream %d", stream_index);
- goto exit_1;
+ goto EXIT_1;
}
// Allocate a context for the codec
codec_ctx = avcodec_alloc_context3(codec);
if(codec_ctx == NULL) {
Kit_SetError("Unable to allocate codec context for stream %d", stream_index);
- goto exit_1;
+ goto EXIT_1;
}
// Copy params
@@ -65,7 +65,7 @@ Kit_Decoder* Kit_CreateDecoder(const Kit_Source *src, int stream_index,
#endif
{
Kit_SetError("Unable to copy codec context for stream %d", stream_index);
- goto exit_2;
+ goto EXIT_2;
}
// Required by ffmpeg for now when using the new API.
@@ -85,7 +85,7 @@ Kit_Decoder* Kit_CreateDecoder(const Kit_Source *src, int stream_index,
// Open the stream
if(avcodec_open2(codec_ctx, codec, &codec_opts) < 0) {
Kit_SetError("Unable to open codec for stream %d", stream_index);
- goto exit_2;
+ goto EXIT_2;
}
// Set index and codec
@@ -98,7 +98,7 @@ Kit_Decoder* Kit_CreateDecoder(const Kit_Source *src, int stream_index,
dec->buffer[i] = Kit_CreateBuffer(bsizes[i], free_hooks[i]);
if(dec->buffer[i] == NULL) {
Kit_SetError("Unable to allocate buffer for stream %d: %s", stream_index, SDL_GetError());
- goto exit_3;
+ goto EXIT_3;
}
}
@@ -106,23 +106,23 @@ Kit_Decoder* Kit_CreateDecoder(const Kit_Source *src, int stream_index,
dec->output_lock = SDL_CreateMutex();
if(dec->output_lock == NULL) {
Kit_SetError("Unable to allocate mutex for stream %d: %s", stream_index, SDL_GetError());
- goto exit_3;
+ goto EXIT_3;
}
// That's that
return dec;
-exit_3:
+EXIT_3:
for(int i = 0; i < KIT_DEC_BUF_COUNT; i++) {
Kit_DestroyBuffer(dec->buffer[i]);
}
avcodec_close(codec_ctx);
-exit_2:
+EXIT_2:
av_dict_free(&codec_opts);
avcodec_free_context(&codec_ctx);
-exit_1:
+EXIT_1:
free(dec);
-exit_0:
+EXIT_0:
return NULL;
}
@@ -170,6 +170,13 @@ int Kit_RunDecoder(Kit_Decoder *dec) {
return 0;
}
+void Kit_ClearDecoderBuffers(const Kit_Decoder *dec) {
+ if(dec == NULL) return;
+ Kit_ClearDecoderInput(dec);
+ Kit_ClearDecoderOutput(dec);
+ avcodec_flush_buffers(dec->codec_ctx);
+}
+
// ---- Information API ----
int Kit_GetDecoderCodecInfo(const Kit_Decoder *dec, Kit_Codec *codec) {
@@ -214,38 +221,38 @@ void Kit_ChangeDecoderClockSync(Kit_Decoder *dec, double sync) {
// ---- Input buffer handling ----
-int Kit_WriteDecoderInput(Kit_Decoder *dec, AVPacket *packet) {
+int Kit_WriteDecoderInput(const Kit_Decoder *dec, AVPacket *packet) {
assert(dec != NULL);
return Kit_WriteBuffer(dec->buffer[KIT_DEC_BUF_IN], packet);
}
-bool Kit_CanWriteDecoderInput(Kit_Decoder *dec) {
+bool Kit_CanWriteDecoderInput(const Kit_Decoder *dec) {
assert(dec != NULL);
return !Kit_IsBufferFull(dec->buffer[KIT_DEC_BUF_IN]);
}
-AVPacket* Kit_ReadDecoderInput(Kit_Decoder *dec) {
+AVPacket* Kit_ReadDecoderInput(const Kit_Decoder *dec) {
assert(dec != NULL);
return Kit_ReadBuffer(dec->buffer[KIT_DEC_BUF_IN]);
}
-AVPacket* Kit_PeekDecoderInput(Kit_Decoder *dec) {
+AVPacket* Kit_PeekDecoderInput(const Kit_Decoder *dec) {
assert(dec != NULL);
return Kit_PeekBuffer(dec->buffer[KIT_DEC_BUF_IN]);
}
-void Kit_AdvanceDecoderInput(Kit_Decoder *dec) {
+void Kit_AdvanceDecoderInput(const Kit_Decoder *dec) {
assert(dec != NULL);
Kit_AdvanceBuffer(dec->buffer[KIT_DEC_BUF_IN]);
}
-void Kit_ClearDecoderInput(Kit_Decoder *dec) {
+void Kit_ClearDecoderInput(const Kit_Decoder *dec) {
Kit_ClearBuffer(dec->buffer[KIT_DEC_BUF_IN]);
}
// ---- Output buffer handling ----
-int Kit_WriteDecoderOutput(Kit_Decoder *dec, void *packet) {
+int Kit_WriteDecoderOutput(const Kit_Decoder *dec, void *packet) {
assert(dec != NULL);
int ret = 1;
if(SDL_LockMutex(dec->output_lock) == 0) {
@@ -255,14 +262,14 @@ int Kit_WriteDecoderOutput(Kit_Decoder *dec, void *packet) {
return ret;
}
-void Kit_ClearDecoderOutput(Kit_Decoder *dec) {
+void Kit_ClearDecoderOutput(const Kit_Decoder *dec) {
if(SDL_LockMutex(dec->output_lock) == 0) {
Kit_ClearBuffer(dec->buffer[KIT_DEC_BUF_OUT]);
SDL_UnlockMutex(dec->output_lock);
}
}
-void* Kit_PeekDecoderOutput(Kit_Decoder *dec) {
+void* Kit_PeekDecoderOutput(const Kit_Decoder *dec) {
assert(dec != NULL);
void *ret = NULL;
if(SDL_LockMutex(dec->output_lock) == 0) {
@@ -272,7 +279,7 @@ void* Kit_PeekDecoderOutput(Kit_Decoder *dec) {
return ret;
}
-void* Kit_ReadDecoderOutput(Kit_Decoder *dec) {
+void* Kit_ReadDecoderOutput(const Kit_Decoder *dec) {
assert(dec != NULL);
void *ret = NULL;
if(SDL_LockMutex(dec->output_lock) == 0) {
@@ -282,7 +289,7 @@ void* Kit_ReadDecoderOutput(Kit_Decoder *dec) {
return ret;
}
-bool Kit_CanWriteDecoderOutput(Kit_Decoder *dec) {
+bool Kit_CanWriteDecoderOutput(const Kit_Decoder *dec) {
assert(dec != NULL);
bool ret = false;
if(SDL_LockMutex(dec->output_lock) == 0) {
@@ -292,7 +299,7 @@ bool Kit_CanWriteDecoderOutput(Kit_Decoder *dec) {
return ret;
}
-void Kit_ForEachDecoderOutput(Kit_Decoder *dec, Kit_ForEachItemCallback cb, void *userdata) {
+void Kit_ForEachDecoderOutput(const Kit_Decoder *dec, Kit_ForEachItemCallback cb, void *userdata) {
assert(dec != NULL);
if(SDL_LockMutex(dec->output_lock) == 0) {
Kit_ForEachItemInBuffer(dec->buffer[KIT_DEC_BUF_OUT], cb, userdata);
@@ -300,7 +307,7 @@ void Kit_ForEachDecoderOutput(Kit_Decoder *dec, Kit_ForEachItemCallback cb, void
}
}
-void Kit_AdvanceDecoderOutput(Kit_Decoder *dec) {
+void Kit_AdvanceDecoderOutput(const Kit_Decoder *dec) {
assert(dec != NULL);
if(SDL_LockMutex(dec->output_lock) == 0) {
Kit_AdvanceBuffer(dec->buffer[KIT_DEC_BUF_OUT]);
@@ -308,7 +315,7 @@ void Kit_AdvanceDecoderOutput(Kit_Decoder *dec) {
}
}
-unsigned int Kit_GetDecoderOutputLength(Kit_Decoder *dec) {
+unsigned int Kit_GetDecoderOutputLength(const Kit_Decoder *dec) {
assert(dec != NULL);
unsigned int len = 0;
if(SDL_LockMutex(dec->output_lock) == 0) {
@@ -318,17 +325,10 @@ unsigned int Kit_GetDecoderOutputLength(Kit_Decoder *dec) {
return len;
}
-void Kit_ClearDecoderBuffers(Kit_Decoder *dec) {
- if(dec == NULL) return;
- Kit_ClearDecoderInput(dec);
- Kit_ClearDecoderOutput(dec);
- avcodec_flush_buffers(dec->codec_ctx);
-}
-
-int Kit_LockDecoderOutput(Kit_Decoder *dec) {
+int Kit_LockDecoderOutput(const Kit_Decoder *dec) {
return SDL_LockMutex(dec->output_lock);
}
-void Kit_UnlockDecoderOutput(Kit_Decoder *dec) {
+void Kit_UnlockDecoderOutput(const Kit_Decoder *dec) {
SDL_UnlockMutex(dec->output_lock);
}
diff --git a/src/internal/subtitle/kitatlas.c b/src/internal/subtitle/kitatlas.c
index e7bb654..d75bdda 100644
--- a/src/internal/subtitle/kitatlas.c
+++ b/src/internal/subtitle/kitatlas.c
@@ -13,7 +13,7 @@ static int min(int a, int b) {
Kit_TextureAtlas* Kit_CreateAtlas() {
Kit_TextureAtlas *atlas = calloc(1, sizeof(Kit_TextureAtlas));
if(atlas == NULL) {
- goto exit_0;
+ goto EXIT_0;
}
atlas->cur_items = 0;
atlas->max_items = 1024;
@@ -24,22 +24,22 @@ Kit_TextureAtlas* Kit_CreateAtlas() {
// Allocate items. These hold the surfaces that should be in atlas
atlas->items = calloc(atlas->max_items, sizeof(Kit_TextureAtlasItem));
if(atlas->items == NULL) {
- goto exit_1;
+ goto EXIT_1;
}
// Allocate shelves. These describe the used space of the atlas
atlas->shelves = calloc(atlas->max_shelves, sizeof(Kit_Shelf));
if(atlas->shelves == NULL) {
- goto exit_2;
+ goto EXIT_2;
}
return atlas;
-exit_2:
+EXIT_2:
free(atlas->items);
-exit_1:
+EXIT_1:
free(atlas);
-exit_0:
+EXIT_0:
return NULL;
}
@@ -56,7 +56,7 @@ void Kit_FreeAtlas(Kit_TextureAtlas *atlas) {
free(atlas);
}
-void Kit_SetItemAllocation(Kit_TextureAtlasItem *item, SDL_Surface *surface, int shelf, int slot, int x, int y) {
+void Kit_SetItemAllocation(Kit_TextureAtlasItem *item, const SDL_Surface *surface, int shelf, int slot, int x, int y) {
assert(item != NULL);
item->cur_shelf = shelf;
@@ -67,7 +67,7 @@ void Kit_SetItemAllocation(Kit_TextureAtlasItem *item, SDL_Surface *surface, int
item->source.h = surface->h;
}
-int Kit_FindFreeAtlasSlot(Kit_TextureAtlas *atlas, SDL_Surface *surface, Kit_TextureAtlasItem *item) {
+int Kit_FindFreeAtlasSlot(const Kit_TextureAtlas *atlas, const SDL_Surface *surface, Kit_TextureAtlasItem *item) {
assert(atlas != NULL);
assert(item != NULL);
@@ -145,10 +145,11 @@ void Kit_CheckAtlasTextureSize(Kit_TextureAtlas *atlas, SDL_Texture *texture) {
int Kit_GetAtlasItems(const Kit_TextureAtlas *atlas, SDL_Rect *sources, SDL_Rect *targets, int limit) {
assert(atlas != NULL);
assert(limit >= 0);
+ const Kit_TextureAtlasItem *item = NULL;
int max_count = min(atlas->cur_items, limit);
for(int i = 0; i < max_count; i++) {
- Kit_TextureAtlasItem *item = &atlas->items[i];
+ item = &atlas->items[i];
if(sources != NULL)
memcpy(&sources[i], &item->source, sizeof(SDL_Rect));
if(targets != NULL)
@@ -157,7 +158,7 @@ int Kit_GetAtlasItems(const Kit_TextureAtlas *atlas, SDL_Rect *sources, SDL_Rect
return max_count;
}
-int Kit_AddAtlasItem(Kit_TextureAtlas *atlas, SDL_Texture *texture, SDL_Surface *surface, const SDL_Rect *target) {
+int Kit_AddAtlasItem(Kit_TextureAtlas *atlas, SDL_Texture *texture, const SDL_Surface *surface, const SDL_Rect *target) {
assert(atlas != NULL);
assert(surface != NULL);
assert(target != NULL);
diff --git a/src/internal/subtitle/kitsubtitle.c b/src/internal/subtitle/kitsubtitle.c
index 024179e..32c8a9b 100644
--- a/src/internal/subtitle/kitsubtitle.c
+++ b/src/internal/subtitle/kitsubtitle.c
@@ -95,7 +95,7 @@ Kit_Decoder* Kit_CreateSubtitleDecoder(const Kit_Source *src, int stream_index,
return NULL;
}
- Kit_LibraryState *state = Kit_GetLibraryState();
+ const Kit_LibraryState *state = Kit_GetLibraryState();
// First the generic decoder component
Kit_Decoder *dec = Kit_CreateDecoder(
@@ -106,14 +106,14 @@ Kit_Decoder* Kit_CreateSubtitleDecoder(const Kit_Source *src, int stream_index,
state->thread_count);
if(dec == NULL) {
Kit_SetError("Unable to allocate subtitle decoder");
- goto exit_0;
+ goto EXIT_0;
}
// ... then allocate the subtitle decoder
Kit_SubtitleDecoder *subtitle_dec = calloc(1, sizeof(Kit_SubtitleDecoder));
if(subtitle_dec == NULL) {
Kit_SetError("Unable to allocate subtitle decoder");
- goto exit_1;
+ goto EXIT_1;
}
// Set format. Note that is_enabled may be changed below ...
@@ -144,14 +144,14 @@ Kit_Decoder* Kit_CreateSubtitleDecoder(const Kit_Source *src, int stream_index,
break;
}
if(subtitle_dec->renderer == NULL) {
- goto exit_2;
+ goto EXIT_2;
}
// Allocate texture atlas for subtitle rectangles
subtitle_dec->atlas = Kit_CreateAtlas();
if(subtitle_dec->atlas == NULL) {
Kit_SetError("Unable to allocate subtitle texture atlas");
- goto exit_3;
+ goto EXIT_3;
}
// Set callbacks and userdata, and we're go
@@ -161,31 +161,31 @@ Kit_Decoder* Kit_CreateSubtitleDecoder(const Kit_Source *src, int stream_index,
dec->output = output;
return dec;
-exit_3:
+EXIT_3:
Kit_CloseSubtitleRenderer(subtitle_dec->renderer);
-exit_2:
+EXIT_2:
free(subtitle_dec);
-exit_1:
+EXIT_1:
Kit_CloseDecoder(dec);
-exit_0:
+EXIT_0:
return NULL;
}
-void Kit_SetSubtitleDecoderSize(Kit_Decoder *dec, int screen_w, int screen_h) {
+void Kit_SetSubtitleDecoderSize(const Kit_Decoder *dec, int screen_w, int screen_h) {
assert(dec != NULL);
- Kit_SubtitleDecoder *subtitle_dec = dec->userdata;
+ const Kit_SubtitleDecoder *subtitle_dec = dec->userdata;
Kit_SetSubtitleRendererSize(subtitle_dec->renderer, screen_w, screen_h);
}
-void Kit_GetSubtitleDecoderTexture(Kit_Decoder *dec, SDL_Texture *texture, double sync_ts) {
+void Kit_GetSubtitleDecoderTexture(const Kit_Decoder *dec, SDL_Texture *texture, double sync_ts) {
assert(dec != NULL);
assert(texture != NULL);
- Kit_SubtitleDecoder *subtitle_dec = dec->userdata;
+ const Kit_SubtitleDecoder *subtitle_dec = dec->userdata;
Kit_GetSubtitleRendererData(subtitle_dec->renderer, subtitle_dec->atlas, texture, sync_ts);
}
-int Kit_GetSubtitleDecoderInfo(Kit_Decoder *dec, SDL_Texture *texture, SDL_Rect *sources, SDL_Rect *targets, int limit) {
- Kit_SubtitleDecoder *subtitle_dec = dec->userdata;
+int Kit_GetSubtitleDecoderInfo(const Kit_Decoder *dec, const SDL_Texture *texture, SDL_Rect *sources, SDL_Rect *targets, int limit) {
+ const Kit_SubtitleDecoder *subtitle_dec = dec->userdata;
return Kit_GetAtlasItems(subtitle_dec->atlas, sources, targets, limit);
}
diff --git a/src/internal/subtitle/renderers/kitsubass.c b/src/internal/subtitle/renderers/kitsubass.c
index 7dfb31b..49ac13f 100644
--- a/src/internal/subtitle/renderers/kitsubass.c
+++ b/src/internal/subtitle/renderers/kitsubass.c
@@ -17,12 +17,12 @@ typedef struct Kit_ASSSubtitleRenderer {
ASS_Track *track;
} Kit_ASSSubtitleRenderer;
-static void Kit_ProcessAssImage(SDL_Surface *surface, const ASS_Image *img) {
+static void Kit_ProcessAssImage(const SDL_Surface *surface, const ASS_Image *img) {
unsigned char r = ((img->color) >> 24) & 0xFF;
unsigned char g = ((img->color) >> 16) & 0xFF;
unsigned char b = ((img->color) >> 8) & 0xFF;
unsigned char a = 0xFF - ((img->color) & 0xFF);
- unsigned char *src = img->bitmap;
+ const unsigned char *src = img->bitmap;
unsigned char *dst = surface->pixels;
unsigned int x;
unsigned int y;
@@ -45,8 +45,8 @@ static void ren_render_ass_cb(Kit_SubtitleRenderer *ren, void *src, double pts,
assert(ren != NULL);
assert(src != NULL);
- Kit_ASSSubtitleRenderer *ass_ren = ren->userdata;
- AVSubtitle *sub = src;
+ const Kit_ASSSubtitleRenderer *ass_ren = ren->userdata;
+ const AVSubtitle *sub = src;
// Read incoming subtitle packets to libASS
long long start_ms = (start + pts) * 1000;
@@ -84,9 +84,9 @@ static void ren_close_ass_cb(Kit_SubtitleRenderer *ren) {
}
static int ren_get_ass_data_cb(Kit_SubtitleRenderer *ren, Kit_TextureAtlas *atlas, SDL_Texture *texture, double current_pts) {
- Kit_ASSSubtitleRenderer *ass_ren = ren->userdata;
+ const Kit_ASSSubtitleRenderer *ass_ren = ren->userdata;
SDL_Surface *dst = NULL;
- ASS_Image *src = NULL;
+ const ASS_Image *src = NULL;
int change = 0;
long long now = current_pts * 1000;
@@ -125,7 +125,7 @@ static int ren_get_ass_data_cb(Kit_SubtitleRenderer *ren, Kit_TextureAtlas *atla
}
static void ren_set_ass_size_cb(Kit_SubtitleRenderer *ren, int w, int h) {
- Kit_ASSSubtitleRenderer *ass_ren = ren->userdata;
+ const Kit_ASSSubtitleRenderer *ass_ren = ren->userdata;
ass_set_frame_size(ass_ren->renderer, w, h);
}
@@ -137,7 +137,7 @@ Kit_SubtitleRenderer* Kit_CreateASSSubtitleRenderer(Kit_Decoder *dec, int video_
assert(screen_h >= 0);
// Make sure that libass library has been initialized + get handle
- Kit_LibraryState *state = Kit_GetLibraryState();
+ const Kit_LibraryState *state = Kit_GetLibraryState();
if(state->libass_handle == NULL) {
Kit_SetError("Libass library has not been initialized");
return NULL;
@@ -146,30 +146,31 @@ Kit_SubtitleRenderer* Kit_CreateASSSubtitleRenderer(Kit_Decoder *dec, int video_
// First allocate the generic decoder component
Kit_SubtitleRenderer *ren = Kit_CreateSubtitleRenderer(dec);
if(ren == NULL) {
- goto exit_0;
+ goto EXIT_0;
}
// Next, allocate ASS subtitle renderer context.
Kit_ASSSubtitleRenderer *ass_ren = calloc(1, sizeof(Kit_ASSSubtitleRenderer));
if(ass_ren == NULL) {
Kit_SetError("Unable to allocate ass subtitle renderer");
- goto exit_1;
+ goto EXIT_1;
}
// Initialize libass renderer
ASS_Renderer *ass_renderer = ass_renderer_init(state->libass_handle);
if(ass_renderer == NULL) {
Kit_SetError("Unable to initialize libass renderer");
- goto exit_2;
+ goto EXIT_2;
}
// Read fonts from attachment streams and give them to libass
+ const AVStream *st = NULL;
for(int j = 0; j < dec->format_ctx->nb_streams; j++) {
- AVStream *st = dec->format_ctx->streams[j];
+ st = dec->format_ctx->streams[j];
#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(57, 48, 101)
AVCodecContext *codec = st->codec;
#else
- AVCodecParameters *codec = st->codecpar;
+ const AVCodecParameters *codec = st->codecpar;
#endif
if(codec->codec_type == AVMEDIA_TYPE_ATTACHMENT && attachment_is_font(st)) {
const AVDictionaryEntry *tag = av_dict_get(
@@ -201,7 +202,7 @@ Kit_SubtitleRenderer* Kit_CreateASSSubtitleRenderer(Kit_Decoder *dec, int video_
ASS_Track *ass_track = ass_new_track(state->libass_handle);
if(ass_track == NULL) {
Kit_SetError("Unable to initialize libass track");
- goto exit_3;
+ goto EXIT_3;
}
// Set up libass track headers (ffmpeg provides these)
@@ -222,12 +223,12 @@ Kit_SubtitleRenderer* Kit_CreateASSSubtitleRenderer(Kit_Decoder *dec, int video_
ren->userdata = ass_ren;
return ren;
-exit_3:
+EXIT_3:
ass_renderer_done(ass_renderer);
-exit_2:
+EXIT_2:
free(ass_ren);
-exit_1:
+EXIT_1:
Kit_CloseSubtitleRenderer(ren);
-exit_0:
+EXIT_0:
return NULL;
}
diff --git a/src/internal/subtitle/renderers/kitsubimage.c b/src/internal/subtitle/renderers/kitsubimage.c
index b9a8e48..25da545 100644
--- a/src/internal/subtitle/renderers/kitsubimage.c
+++ b/src/internal/subtitle/renderers/kitsubimage.c
@@ -21,7 +21,7 @@ static void ren_render_image_cb(Kit_SubtitleRenderer *ren, void *sub_src, double
assert(ren != NULL);
assert(sub_src != NULL);
- AVSubtitle *sub = sub_src;
+ const AVSubtitle *sub = sub_src;
SDL_Surface *dst = NULL;
SDL_Surface *src = NULL;
double start_pts = pts + start;
@@ -35,8 +35,9 @@ static void ren_render_image_cb(Kit_SubtitleRenderer *ren, void *sub_src, double
}
// Convert subtitle images from paletted to RGBA8888
+ const AVSubtitleRect *r = NULL;
for(int n = 0; n < sub->num_rects; n++) {
- AVSubtitleRect *r = sub->rects[n];
+ r = sub->rects[n];
if(r->type != SUBTITLE_BITMAP)
continue;
@@ -60,7 +61,7 @@ static void ren_render_image_cb(Kit_SubtitleRenderer *ren, void *sub_src, double
}
static int ren_get_img_data_cb(Kit_SubtitleRenderer *ren, Kit_TextureAtlas *atlas, SDL_Texture *texture, double current_pts) {
- Kit_ImageSubtitleRenderer *img_ren = ren->userdata;
+ const Kit_ImageSubtitleRenderer *img_ren = ren->userdata;
Kit_SubtitlePacket *packet = NULL;
Kit_CheckAtlasTextureSize(atlas, texture);
@@ -117,14 +118,14 @@ Kit_SubtitleRenderer* Kit_CreateImageSubtitleRenderer(Kit_Decoder *dec, int vide
// Allocate a new renderer
Kit_SubtitleRenderer *ren = Kit_CreateSubtitleRenderer(dec);
if(ren == NULL) {
- goto exit_0;
+ goto EXIT_0;
}
// Allocate image renderer internal context
Kit_ImageSubtitleRenderer *img_ren = calloc(1, sizeof(Kit_ImageSubtitleRenderer));
if(img_ren == NULL) {
Kit_SetError("Unable to allocate image subtitle renderer");
- goto exit_1;
+ goto EXIT_1;
}
// Only renderer required, no other data.
@@ -139,8 +140,8 @@ Kit_SubtitleRenderer* Kit_CreateImageSubtitleRenderer(Kit_Decoder *dec, int vide
ren->userdata = img_ren;
return ren;
-exit_1:
+EXIT_1:
Kit_CloseSubtitleRenderer(ren);
-exit_0:
+EXIT_0:
return NULL;
}
diff --git a/src/internal/utils/kithelpers.c b/src/internal/utils/kithelpers.c
index c68f1c7..0108f1b 100644
--- a/src/internal/utils/kithelpers.c
+++ b/src/internal/utils/kithelpers.c
@@ -17,8 +17,8 @@ double _GetSystemTime() {
return (double)av_gettime() / 1000000.0;
}
-bool attachment_is_font(AVStream *stream) {
- AVDictionaryEntry *tag = av_dict_get(stream->metadata, "mimetype", NULL, AV_DICT_MATCH_CASE);
+bool attachment_is_font(const AVStream *stream) {
+ const 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) {
diff --git a/src/internal/video/kitvideo.c b/src/internal/video/kitvideo.c
index 1f2bed9..7cf6688 100644
--- a/src/internal/video/kitvideo.c
+++ b/src/internal/video/kitvideo.c
@@ -154,8 +154,8 @@ static int dec_decode_video_cb(Kit_Decoder *dec, AVPacket *in_packet) {
return 0;
}
#else
-static void dec_read_video(Kit_Decoder *dec) {
- Kit_VideoDecoder *video_dec = dec->userdata;
+static void dec_read_video(const Kit_Decoder *dec) {
+ const Kit_VideoDecoder *video_dec = dec->userdata;
AVFrame *out_frame = NULL;
Kit_VideoPacket *out_packet = NULL;
double pts;
@@ -232,7 +232,7 @@ Kit_Decoder* Kit_CreateVideoDecoder(const Kit_Source *src, int stream_index) {
return NULL;
}
- Kit_LibraryState *state = Kit_GetLibraryState();
+ const Kit_LibraryState *state = Kit_GetLibraryState();
// First the generic decoder component ...
Kit_Decoder *dec = Kit_CreateDecoder(
@@ -242,20 +242,20 @@ Kit_Decoder* Kit_CreateVideoDecoder(const Kit_Source *src, int stream_index) {
free_out_video_packet_cb,
state->thread_count);
if(dec == NULL) {
- goto exit_0;
+ goto EXIT_0;
}
// ... then allocate the video decoder
Kit_VideoDecoder *video_dec = calloc(1, sizeof(Kit_VideoDecoder));
if(video_dec == NULL) {
- goto exit_1;
+ goto EXIT_1;
}
// Create temporary video frame
video_dec->scratch_frame = av_frame_alloc();
if(video_dec->scratch_frame == NULL) {
Kit_SetError("Unable to initialize temporary video frame");
- goto exit_2;
+ goto EXIT_2;
}
// Find best output format for us
@@ -281,7 +281,7 @@ Kit_Decoder* Kit_CreateVideoDecoder(const Kit_Source *src, int stream_index) {
NULL, NULL, NULL);
if(video_dec->sws == NULL) {
Kit_SetError("Unable to initialize video converter context");
- goto exit_3;
+ goto EXIT_3;
}
// Set callbacks and userdata, and we're go
@@ -291,18 +291,18 @@ Kit_Decoder* Kit_CreateVideoDecoder(const Kit_Source *src, int stream_index) {
dec->output = output;
return dec;
-exit_3:
+EXIT_3:
av_frame_free(&video_dec->scratch_frame);
-exit_2:
+EXIT_2:
free(video_dec);
-exit_1:
+EXIT_1:
Kit_CloseDecoder(dec);
-exit_0:
+EXIT_0:
return NULL;
}
-double Kit_GetVideoDecoderPTS(Kit_Decoder *dec) {
- Kit_VideoPacket *packet = Kit_PeekDecoderOutput(dec);
+double Kit_GetVideoDecoderPTS(const Kit_Decoder *dec) {
+ const Kit_VideoPacket *packet = Kit_PeekDecoderOutput(dec);
if(packet == NULL) {
return -1.0;
}
diff --git a/src/kiterror.c b/src/kiterror.c
index 9ed0081..7c4522e 100644
--- a/src/kiterror.c
+++ b/src/kiterror.c
@@ -23,7 +23,7 @@ void Kit_SetError(const char* fmt, ...) {
assert(fmt != NULL);
va_list args;
va_start(args, fmt);
- vsnprintf(_error_message, KIT_ERRBUFSIZE, (char*)fmt, args);
+ vsnprintf(_error_message, KIT_ERRBUFSIZE, fmt, args);
va_end(args);
_error_available = true;
}
diff --git a/src/kitlib.c b/src/kitlib.c
index e823c52..c3f98e4 100644
--- a/src/kitlib.c
+++ b/src/kitlib.c
@@ -45,7 +45,7 @@ int Kit_Init(unsigned int flags) {
if(state->init_flags != 0) {
Kit_SetError("SDL_kitchensink is already initialized");
- goto exit_0;
+ goto EXIT_0;
}
#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(58, 9, 100)
@@ -58,17 +58,17 @@ int Kit_Init(unsigned int flags) {
if(flags & KIT_INIT_ASS) {
if(Kit_InitASS(state) != 0) {
Kit_SetError("Failed to initialize libass");
- goto exit_1;
+ goto EXIT_1;
}
}
state->init_flags = flags;
return 0;
-exit_1:
+EXIT_1:
avformat_network_deinit();
-exit_0:
+EXIT_0:
return 1;
}
@@ -106,7 +106,7 @@ void Kit_SetHint(Kit_HintType type, int value) {
}
int Kit_GetHint(Kit_HintType type) {
- Kit_LibraryState *state = Kit_GetLibraryState();
+ const Kit_LibraryState *state = Kit_GetLibraryState();
switch(type) {
case KIT_HINT_THREAD_COUNT:
return state->thread_count;
diff --git a/src/kitplayer.c b/src/kitplayer.c
index 2135a65..3cf0881 100644
--- a/src/kitplayer.c
+++ b/src/kitplayer.c
@@ -24,12 +24,13 @@ enum DecoderIndex {
static int _DemuxStream(const Kit_Player *player) {
assert(player != NULL);
AVFormatContext *format_ctx = player->src->format_ctx;
+ const Kit_Decoder *dec = NULL;
// If any buffer is full, just stop here for now.
// Since we don't know what kind of data is going to come out of av_read_frame, we really
// want to make sure we are prepared for everything :)
for(int i = 0; i < KIT_DEC_COUNT; i++) {
- Kit_Decoder *dec = player->decoders[i];
+ dec = player->decoders[i];
if(dec == NULL)
continue;
if(!Kit_CanWriteDecoderInput(dec))
@@ -45,7 +46,7 @@ static int _DemuxStream(const Kit_Player *player) {
// Check if this is a packet we need to handle and pass it on
for(int i = 0; i < KIT_DEC_COUNT; i++) {
- Kit_Decoder *dec = player->decoders[i];
+ dec = player->decoders[i];
if(dec == NULL)
continue;
if(dec->stream_index == packet->stream_index) {
@@ -61,8 +62,9 @@ static int _DemuxStream(const Kit_Player *player) {
}
static bool _IsOutputEmpty(const Kit_Player *player) {
+ const Kit_Decoder *dec = NULL;
for(int i = 0; i < KIT_DEC_COUNT; i++) {
- Kit_Decoder *dec = player->decoders[i];
+ dec = player->decoders[i];
if(dec == NULL)
continue;
if(Kit_PeekDecoderOutput(dec))
@@ -71,9 +73,10 @@ static bool _IsOutputEmpty(const Kit_Player *player) {
return true;
}
-static int _RunDecoder(Kit_Player *player) {
+static int _RunDecoder(const Kit_Player *player) {
int got;
bool has_room = true;
+ const Kit_Decoder *dec = NULL;
do {
while((got = _DemuxStream(player)) == -1);
@@ -88,7 +91,7 @@ static int _RunDecoder(Kit_Player *player) {
// If there is no room in any decoder input, just stop here since it likely means that
// at least some decoder output is full.
for(int i = 0; i < KIT_DEC_COUNT; i++) {
- Kit_Decoder *dec = player->decoders[i];
+ dec = player->decoders[i];
if(dec == NULL)
continue;
if(!Kit_CanWriteDecoderInput(dec) || got == 1) {
@@ -101,42 +104,38 @@ static int _RunDecoder(Kit_Player *player) {
return 0;
}
+static void _TryWork(Kit_Player *player) {
+ /**
+ * \brief Run the decoders and demuxer as long as there is work. Returns when playback stops.
+ */
+ while(player->state == KIT_PLAYING || player->state == KIT_PAUSED) {
+ // Grab the decoder lock, and run demuxer & decoders for a bit.
+ if(SDL_LockMutex(player->dec_lock) == 0) {
+ if(_RunDecoder(player) == 1) {
+ player->state = KIT_STOPPED;
+ }
+ SDL_UnlockMutex(player->dec_lock);
+ }
+
+ // Delay to make sure this thread does not hog all cpu
+ SDL_Delay(2);
+ }
+}
+
static int _DecoderThread(void *ptr) {
+ /**
+ * \brief Decoder thread main, which runs as long as the player exists.
+ */
Kit_Player *player = ptr;
- bool is_running = true;
- bool is_playing = true;
- while(is_running) {
+ while(true) {
if(player->state == KIT_CLOSED) {
- is_running = false;
- continue;
- }
- if(player->state == KIT_PLAYING) {
- is_playing = true;
- }
- while(is_running && is_playing) {
- // Grab the decoder lock, and run demuxer & decoders for a bit.
- if(SDL_LockMutex(player->dec_lock) == 0) {
- if(player->state == KIT_CLOSED) {
- is_running = false;
- goto end_block;
- }
- if(player->state == KIT_STOPPED) {
- is_playing = false;
- goto end_block;
- }
- if(_RunDecoder(player) == 1) {
- player->state = KIT_STOPPED;
- goto end_block;
- }
-
-end_block:
- SDL_UnlockMutex(player->dec_lock);
- }
-
- // Delay to make sure this thread does not hog all cpu
- SDL_Delay(2);
+ break;
}
+
+ // This will block as long as there is something to demux/decode
+ // Returns when playback stops.
+ _TryWork(player);
// Just idle while waiting for work.
SDL_Delay(25);
@@ -157,25 +156,25 @@ Kit_Player* Kit_CreatePlayer(const Kit_Source *src,
if(video_stream_index < 0 && subtitle_stream_index >= 0) {
Kit_SetError("Subtitle stream selected without video stream");
- goto exit_0;
+ goto EXIT_0;
}
Kit_Player *player = calloc(1, sizeof(Kit_Player));
if(player == NULL) {
Kit_SetError("Unable to allocate player");
- goto exit_0;
+ goto EXIT_0;
}
// Initialize audio decoder
player->decoders[KIT_AUDIO_DEC] = Kit_CreateAudioDecoder(src, audio_stream_index);
if(player->decoders[KIT_AUDIO_DEC] == NULL && audio_stream_index >= 0) {
- goto exit_1;
+ goto EXIT_1;
}
// Initialize video decoder
player->decoders[KIT_VIDEO_DEC] = Kit_CreateVideoDecoder(src, video_stream_index);
if(player->decoders[KIT_VIDEO_DEC] == NULL && video_stream_index >= 0) {
- goto exit_2;
+ goto EXIT_2;
}
// Initialize subtitle decoder.
@@ -184,35 +183,35 @@ Kit_Player* Kit_CreatePlayer(const Kit_Source *src,
player->decoders[KIT_SUBTITLE_DEC] = Kit_CreateSubtitleDecoder(
src, subtitle_stream_index, output.width, output.height, screen_w, screen_h);
if(player->decoders[KIT_SUBTITLE_DEC] == NULL && subtitle_stream_index >= 0) {
- goto exit_2;
+ goto EXIT_2;
}
// Decoder thread lock
player->dec_lock = SDL_CreateMutex();
if(player->dec_lock == NULL) {
Kit_SetError("Unable to create a decoder thread lock mutex: %s", SDL_GetError());
- goto exit_2;
+ goto EXIT_2;
}
// Decoder thread
player->dec_thread = SDL_CreateThread(_DecoderThread, "Kit Decoder Thread", player);
if(player->dec_thread == NULL) {
Kit_SetError("Unable to create a decoder thread: %s", SDL_GetError());
- goto exit_3;
+ goto EXIT_3;
}
player->src = src;
return player;
-exit_3:
+EXIT_3:
SDL_DestroyMutex(player->dec_lock);
-exit_2:
+EXIT_2:
for(int i = 0; i < KIT_DEC_COUNT; i++) {
Kit_CloseDecoder(player->decoders[i]);
}
-exit_1:
+EXIT_1:
free(player);
-exit_0:
+EXIT_0:
return NULL;
}
@@ -238,7 +237,7 @@ void Kit_ClosePlayer(Kit_Player *player) {
void Kit_SetPlayerScreenSize(Kit_Player *player, int w, int h) {
assert(player != NULL);
- Kit_Decoder *dec = player->decoders[KIT_SUBTITLE_DEC];
+ const Kit_Decoder *dec = player->decoders[KIT_SUBTITLE_DEC];
if(dec == NULL)
return;
Kit_SetSubtitleDecoderSize(dec, w, h);
@@ -310,8 +309,8 @@ int Kit_GetPlayerSubtitleData(Kit_Player *player, SDL_Texture *texture, SDL_Rect
assert(targets != NULL);
assert(limit >= 0);
- Kit_Decoder *sub_dec = player->decoders[KIT_SUBTITLE_DEC];
- Kit_Decoder *video_dec = player->decoders[KIT_VIDEO_DEC];
+ const Kit_Decoder *sub_dec = player->decoders[KIT_SUBTITLE_DEC];
+ const Kit_Decoder *video_dec = player->decoders[KIT_VIDEO_DEC];
if(sub_dec == NULL || video_dec == NULL) {
return 0;
}
@@ -334,24 +333,24 @@ int Kit_GetPlayerSubtitleData(Kit_Player *player, SDL_Texture *texture, SDL_Rect
void Kit_GetPlayerInfo(const Kit_Player *player, Kit_PlayerInfo *info) {
assert(player != NULL);
assert(info != NULL);
+ const Kit_Decoder *dec = NULL;
+ Kit_PlayerStreamInfo *streams[] = {&info->video, &info->audio, &info->subtitle};
- void *streams[] = {&info->video, &info->audio, &info->subtitle};
for(int i = 0; i < KIT_DEC_COUNT; i++) {
- Kit_Decoder *dec = player->decoders[i];
- Kit_PlayerStreamInfo *stream = streams[i];
- Kit_GetDecoderCodecInfo(dec, &stream->codec);
- Kit_GetDecoderOutputFormat(dec, &stream->output);
+ dec = player->decoders[i];
+ Kit_GetDecoderCodecInfo(dec, &streams[i]->codec);
+ Kit_GetDecoderOutputFormat(dec, &streams[i]->output);
}
}
-static void _SetClockSync(Kit_Player *player) {
+static void _SetClockSync(const Kit_Player *player) {
double sync = _GetSystemTime();
for(int i = 0; i < KIT_DEC_COUNT; i++) {
Kit_SetDecoderClockSync(player->decoders[i], sync);
}
}
-static void _ChangeClockSync(Kit_Player *player, double delta) {
+static void _ChangeClockSync(const Kit_Player *player, double delta) {
for(int i = 0; i < KIT_DEC_COUNT; i++) {
Kit_ChangeDecoderClockSync(player->decoders[i], delta);
}
@@ -476,7 +475,7 @@ int Kit_PlayerSeek(Kit_Player *player, double seek_set) {
double Kit_GetPlayerDuration(const Kit_Player *player) {
assert(player != NULL);
- AVFormatContext *fmt_ctx = player->src->format_ctx;
+ const AVFormatContext *fmt_ctx = player->src->format_ctx;
return (fmt_ctx->duration / AV_TIME_BASE);
}
diff --git a/src/kitsource.c b/src/kitsource.c
index 1a3bb00..4c01466 100644
--- a/src/kitsource.c
+++ b/src/kitsource.c
@@ -34,19 +34,19 @@ Kit_Source* Kit_CreateSourceFromUrl(const char *url) {
// Attempt to open source
if(avformat_open_input((AVFormatContext **)&src->format_ctx, url, NULL, NULL) < 0) {
Kit_SetError("Unable to open source Url");
- goto exit_0;
+ goto EXIT_0;
}
// Scan source information (may seek forwards)
if(_ScanSource(src->format_ctx)) {
- goto exit_1;
+ goto EXIT_1;
}
return src;
-exit_1:
+EXIT_1:
avformat_close_input((AVFormatContext **)&src->format_ctx);
-exit_0:
+EXIT_0:
free(src);
return NULL;
}
@@ -63,20 +63,20 @@ Kit_Source* Kit_CreateSourceFromCustom(Kit_ReadCallback read_cb, Kit_SeekCallbac
uint8_t *avio_buf = av_malloc(AVIO_BUF_SIZE);
if(avio_buf == NULL) {
Kit_SetError("Unable to allocate avio buffer");
- goto exit_0;
+ goto EXIT_0;
}
AVFormatContext *format_ctx = avformat_alloc_context();
if(format_ctx == NULL) {
Kit_SetError("Unable to allocate format context");
- goto exit_1;
+ goto EXIT_1;
}
AVIOContext *avio_ctx = avio_alloc_context(
avio_buf, AVIO_BUF_SIZE, 0, userdata, read_cb, 0, seek_cb);
if(avio_ctx == NULL) {
Kit_SetError("Unable to allocate avio context");
- goto exit_2;
+ goto EXIT_2;
}
// Set the format as AVIO format
@@ -85,12 +85,12 @@ Kit_Source* Kit_CreateSourceFromCustom(Kit_ReadCallback read_cb, Kit_SeekCallbac
// Attempt to open source
if(avformat_open_input(&format_ctx, "", NULL, NULL) < 0) {
Kit_SetError("Unable to open custom source");
- goto exit_3;
+ goto EXIT_3;
}
// Scan source information (may seek forwards)
if(_ScanSource(format_ctx)) {
- goto exit_4;
+ goto EXIT_4;
}
// Set internals
@@ -98,15 +98,15 @@ Kit_Source* Kit_CreateSourceFromCustom(Kit_ReadCallback read_cb, Kit_SeekCallbac
src->avio_ctx = avio_ctx;
return src;
-exit_4:
+EXIT_4:
avformat_close_input(&format_ctx);
-exit_3:
+EXIT_3:
av_freep(&avio_ctx);
-exit_2:
+EXIT_2:
avformat_free_context(format_ctx);
-exit_1:
+EXIT_1:
av_freep(&avio_buf);
-exit_0:
+EXIT_0:
free(src);
return NULL;
}
@@ -170,13 +170,13 @@ int Kit_GetSourceStreamInfo(const Kit_Source *src, Kit_SourceStreamInfo *info, i
assert(src != NULL);
assert(info != NULL);
- AVFormatContext *format_ctx = (AVFormatContext *)src->format_ctx;
+ const 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];
+ const AVStream *stream = format_ctx->streams[index];
enum AVMediaType codec_type;
#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(57, 48, 101)
codec_type = stream->codec->codec_type;