TheorafileGMS/src/TheorafileGMS.c

117 lines
2.9 KiB
C

/* TheorafileGMS - YUV decoder for Game Maker
*
* Copyright (c) 2021 Evan Hemsley
*
* This software is provided 'as-is', without any express or implied warranty.
* In no event will the authors be held liable for any damages arising from
* the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software in a
* product, an acknowledgment in the product documentation would be
* appreciated but is not required.
*
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
*
* 3. This notice may not be removed or altered from any source distribution.
*
* Evan "cosmonaut" Hemsley <evan@moonside.games>
*
*/
#include "TheorafileGMS.h"
#include "theorafile.h"
#include "SDL.h"
static inline void LogError(char* string)
{
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "%s\n", string);
}
char* TheorafileGMS_Open(char* filename)
{
OggTheora_File* file = SDL_malloc(sizeof(OggTheora_File));
int err = tf_fopen(filename, file);
if (err < 0)
{
if (err == TF_EUNKNOWN)
{
LogError("An unknown error occurred! Something very wrong happened!");
}
else if (err == TF_EUNSUPPORTED)
{
LogError("Unsupported theorafile type! Bailing!");
}
else if (err == TF_ENODATASOURCE)
{
LogError("Unknown data source! Bailing!");
}
else
{
LogError("An even more unknown error occurred!");
}
return NULL;
}
return (char*)file;
}
void TheorafileGMS_Close(char* filePointer)
{
SDL_free(filePointer);
}
double TheorafileGMS_HasVideo(char* filePointer)
{
OggTheora_File* file = (OggTheora_File*)filePointer;
return (double)tf_hasvideo(file);
}
double TheorafileGMS_Width(char* filePointer)
{
OggTheora_File* file = (OggTheora_File*)filePointer;
int width;
tf_videoinfo(file, &width, NULL, NULL, NULL);
return (double)width;
}
double TheorafileGMS_Height(char* filePointer)
{
OggTheora_File* file = (OggTheora_File*)filePointer;
int height;
tf_videoinfo(file, NULL, &height, NULL, NULL);
return (double)height;
}
double TheorafileGMS_FPS(char* filePointer)
{
OggTheora_File* file = (OggTheora_File*)filePointer;
double fps;
tf_videoinfo(file, NULL, NULL, &fps, NULL);
return fps;
}
double TheorafileGMS_EndOfStream(char* filePointer)
{
OggTheora_File* file = (OggTheora_File*)filePointer;
return (double)tf_eos(file);
}
void TheorafileGMS_Reset(char* filePointer)
{
OggTheora_File* file = (OggTheora_File*)filePointer;
tf_reset(file);
}
double TheorafileGMS_ReadVideo(char* filePointer, char* buffer, double numFrames)
{
OggTheora_File* file = (OggTheora_File*)filePointer;
return (double)tf_readvideo(file, buffer, (int)numFrames);
}