Skip to content

Commit

Permalink
Release 3 (#8)
Browse files Browse the repository at this point in the history
* fix: close crashes when no audio driver is set
* fix: allow LVP_Quit to be called multiple times without throwing an exception if not initialized
* improve: exception handling when requesting media details for an invalid media file
* fix: sub-scaling relative to video size
* improve: send callback event when disabling subs
* add: thumbnail to meta data
* add: public methods to get media type of a specific file
* improve: stream info parsing of media format context
* fix: some meta data newline characters are not double-escaped
* fix: thumbnail creation sometimes fails because of inaccurate pitch size
* improve: add external subs to meta data
* update: version to 1.3.0 (#3)
* fix: audio filter fails for wma files (#4)
* improve: ignore id3v2_priv (private) meta tags (#5)
* add: public API endpoint to set mute state (#6)
* improve: support for cross-platform build (#7)
  • Loading branch information
adamajammary authored Sep 16, 2023
1 parent 009a93b commit 24b86ad
Show file tree
Hide file tree
Showing 22 changed files with 1,176 additions and 1,329 deletions.
213 changes: 162 additions & 51 deletions CMakeLists.txt

Large diffs are not rendered by default.

214 changes: 171 additions & 43 deletions README.md

Large diffs are not rendered by default.

100 changes: 65 additions & 35 deletions inc/libvoyaplayer.h
Original file line number Diff line number Diff line change
@@ -1,19 +1,29 @@
#ifndef LIBVOYAPLAYER_H
#define LIBVOYAPLAYER_H

#define DLL __stdcall

#ifdef libvoyaplayer_EXPORTS
#define DLLEXPORT __declspec(dllexport)
#if defined _windows
#define DLL __cdecl

#ifdef voyaplayer_EXPORTS
#define DLLEXPORT __declspec(dllexport)
#else
#define DLLEXPORT __declspec(dllimport)
#endif
#else
#define DLLEXPORT __declspec(dllimport)
#define DLL

#if __GNUC__ >= 4
#define DLLEXPORT __attribute__ ((visibility ("default")))
#else
#define DLLEXPORT
#endif
#endif

#include <libvoyaplayer_events.h>

/**
* @brief Tries to initialize the library and other dependencies.
* @throws exception
* @throws runtime_error
*/
DLLEXPORT void DLL LVP_Initialize(const LVP_CallbackContext &callbackContext);

Expand All @@ -24,137 +34,150 @@ DLLEXPORT std::vector<std::string> DLL LVP_GetAudioDevices();

/**
* @returns a list of chapters in the currently loaded media.
* @throws exception
* @throws runtime_error
*/
DLLEXPORT std::vector<LVP_MediaChapter> DLL LVP_GetChapters();

/**
* @returns the current audio track index number.
* @throws exception
* @throws runtime_error
*/
DLLEXPORT int DLL LVP_GetAudioTrack();

/**
* @returns a list of audio tracks in the currently loaded media.
* @throws exception
* @throws runtime_error
*/
DLLEXPORT std::vector<LVP_MediaTrack> DLL LVP_GetAudioTracks();

/**
* @returns the media duration in milliseconds (one thousandth of a second).
* @throws exception
* @throws runtime_error
*/
DLLEXPORT int64_t DLL LVP_GetDuration();

/**
* @returns the current media file path.
* @throws exception
* @throws runtime_error
*/
DLLEXPORT std::string DLL LVP_GetFilePath();

/**
* @returns media details of the currently loaded media.
* @throws exception
* @throws runtime_error
*/
DLLEXPORT LVP_MediaDetails DLL LVP_GetMediaDetails();

/**
* @returns media details of the provided media file.
* @param filePath Full path to the media file.
* @throws exception
* @throws runtime_error
*/
DLLEXPORT LVP_MediaDetails DLL LVP_GetMediaDetails(const std::string& filePath);

/**
* @returns media details of the provided media file.
* @param filePath Full path to the media file.
* @throws exception
* @throws runtime_error
*/
DLLEXPORT LVP_MediaDetails DLL LVP_GetMediaDetails(const std::wstring& filePath);

/**
* @returns the media type of the currently loaded media.
* @throws exception
* @throws runtime_error
*/
DLLEXPORT LVP_MediaType DLL LVP_GetMediaType();

/**
* @returns the media type of the provided media file.
* @param filePath Full path to the media file.
* @throws runtime_error
*/
DLLEXPORT LVP_MediaType DLL LVP_GetMediaType(const std::string& filePath);

/**
* @returns the media type of the provided media file.
* @param filePath Full path to the media file.
* @throws runtime_error
*/
DLLEXPORT LVP_MediaType DLL LVP_GetMediaType(const std::wstring& filePath);

/**
* @returns the current playback speed as a percent between 0.5 and 2.0.
* @throws exception
* @throws runtime_error
*/
DLLEXPORT double DLL LVP_GetPlaybackSpeed();

/**
* @returns the media playback progress in milliseconds (one thousandth of a second).
* @throws exception
* @throws runtime_error
*/
DLLEXPORT int64_t DLL LVP_GetProgress();

/**
* @returns the current subtitle track index number.
* @throws exception
* @throws runtime_error
*/
DLLEXPORT int DLL LVP_GetSubtitleTrack();

/**
* @returns a list of subtitle tracks in the currently loaded media.
* @throws exception
* @throws runtime_error
*/
DLLEXPORT std::vector<LVP_MediaTrack> DLL LVP_GetSubtitleTracks();

/**
* @returns a list of video tracks in the currently loaded media.
* @throws exception
* @throws runtime_error
*/
DLLEXPORT std::vector<LVP_MediaTrack> DLL LVP_GetVideoTracks();

/**
* @returns the current audio volume as a percent between 0 and 1.
* @throws exception
* @throws runtime_error
*/
DLLEXPORT double DLL LVP_GetVolume();

/**
* @returns true if audio volume is muted.
* @throws exception
* @throws runtime_error
*/
DLLEXPORT bool DLL LVP_IsMuted();

/**
* @returns true if playback is paused.
* @throws exception
* @throws runtime_error
*/
DLLEXPORT bool DLL LVP_IsPaused();

/**
* @returns true if playback is playing (not paused and not stopped).
* @throws exception
* @throws runtime_error
*/
DLLEXPORT bool DLL LVP_IsPlaying();

/**
* @returns true if playback is stopped.
* @throws exception
* @throws runtime_error
*/
DLLEXPORT bool DLL LVP_IsStopped();

/**
* @brief Tries to open and play the given media file.
* @param filePath Full path to the media file.
* @throws exception
* @throws runtime_error
*/
DLLEXPORT void DLL LVP_Open(const std::string &filePath);

/**
* @brief Tries to open and play the given media file.
* @param filePath Full path to the media file.
* @throws exception
* @throws runtime_error
*/
DLLEXPORT void DLL LVP_Open(const std::wstring &filePath);

/**
* @brief Cleans up allocated resources.
* @throws exception
*/
DLLEXPORT void DLL LVP_Quit();

Expand All @@ -174,7 +197,7 @@ DLLEXPORT void DLL LVP_Resize();
/**
* @brief Seeks to the given position as a percent between 0 and 1.
* @param percent [0.0-1.0]
* @throws exception
* @throws runtime_error
*/
DLLEXPORT void DLL LVP_SeekTo(double percent);

Expand All @@ -185,42 +208,49 @@ DLLEXPORT void DLL LVP_SeekTo(double percent);
*/
DLLEXPORT bool DLL LVP_SetAudioDevice(const std::string &device);

/**
* @brief Mutes/unmutes the audio volume.
* @param muted true to mute or false to unmute
* @throws runtime_error
*/
DLLEXPORT void DLL LVP_SetMuted(bool muted);

/**
* @brief Sets the given playback speed as a relative percent between 0.5 and 2.0, where 1.0 is normal/default.
* @param speed [0.5-2.0]
* @throws exception
* @throws runtime_error
*/
DLLEXPORT void DLL LVP_SetPlaybackSpeed(double speed);

/**
* @brief Tries to set the given stream as the current stream if valid.
* @param track -1 to disable subtitles or >= 0 for a valid media track.
* @throws exception
* @throws runtime_error
*/
DLLEXPORT void DLL LVP_SetTrack(const LVP_MediaTrack &track);

/**
* @brief Sets the given audio volume as a percent between 0 and 1.
* @param percent [0.0-1.0]
* @throws exception
* @throws runtime_error
*/
DLLEXPORT void DLL LVP_SetVolume(double percent);

/**
* @brief Stops playback of the currently loaded media.
* @throws exception
* @throws runtime_error
*/
DLLEXPORT void DLL LVP_Stop();

/**
* @brief Toggles muting audio volume on/off.
* @throws exception
* @throws runtime_error
*/
DLLEXPORT void DLL LVP_ToggleMute();

/**
* @brief Toggles between pausing and playing.
* @throws exception
* @throws runtime_error
*/
DLLEXPORT void DLL LVP_TogglePause();

Expand Down
5 changes: 5 additions & 0 deletions inc/libvoyaplayer_events.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
#include <functional>
#include <map>
#include <mutex>
#include <stdexcept>
#include <string>
#include <vector>

#ifndef LIB_SDL2_H
#define LIB_SDL2_H
Expand Down Expand Up @@ -132,6 +135,8 @@ struct LVP_MediaDetails
*/
std::map<std::string, std::string> meta;

SDL_Surface* thumbnail = nullptr;

std::vector<LVP_MediaTrack> audioTracks;
std::vector<LVP_MediaTrack> subtitleTracks;
std::vector<LVP_MediaTrack> videoTracks;
Expand Down
4 changes: 2 additions & 2 deletions src/LVP_Color.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ Graphics::LVP_Color::LVP_Color()

bool Graphics::LVP_Color::operator ==(const LVP_Color &color)
{
return ((color.r == this->r) && (color.g == this->g) && (color.b == this->b) && (color.a == this->a));
return ((this->r == color.r) && (this->g == color.g) && (this->b == color.b) && (this->a == color.a));
}

bool Graphics::LVP_Color::operator !=(const LVP_Color &color)
{
return !((LVP_Color)color == *this);
return !(*this == color);
}

Graphics::LVP_Color::operator SDL_Color()
Expand Down
23 changes: 12 additions & 11 deletions src/LVP_FileSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ Strings System::LVP_FileSystem::getDirectoryContent(const std::string &directory
return directoyContent;

#if defined _windows
auto directoryPathUTF16 = (wchar_t*)SDL_iconv_utf8_ucs2(directoryPath.c_str());
auto directoryPathUTF16 = (wchar_t*)LVP_Text::ToUTF16(directoryPath.c_str());
DIR* directory = opendir(directoryPathUTF16);

SDL_free(directoryPathUTF16);
Expand Down Expand Up @@ -176,8 +176,8 @@ size_t System::LVP_FileSystem::GetFileSize(const std::string &filePath)
stat_t fileStruct;

#if defined _windows
auto filePath16 = (wchar_t*)SDL_iconv_utf8_ucs2(filePath.c_str());
int result = fstatw(filePath16, &fileStruct);
auto filePath16 = (wchar_t*)LVP_Text::ToUTF16(filePath.c_str());
int result = fstat(filePath16, &fileStruct);

SDL_free(filePath16);
#else
Expand Down Expand Up @@ -210,7 +210,7 @@ Strings System::LVP_FileSystem::GetSubtitleFilesForVideo(const std::string &vide
continue;
}

subtitleFiles.push_back(std::format("{}{}{}", directory.c_str(), PATH_SEPARATOR, file.c_str()));
subtitleFiles.push_back(LVP_Text::Format("%s%c%s", directory.c_str(), PATH_SEPARATOR, file.c_str()));

if (LVP_FileSystem::GetFileExtension(file, true) == "IDX")
idxFile = LVP_Text::ToUpper(LVP_FileSystem::getFileName(file, true));
Expand All @@ -232,7 +232,7 @@ bool System::LVP_FileSystem::IsBlurayAACS(const std::string &filePath, size_t fi
const size_t SECTOR_SIZE = 6144;
uint8_t buffer[SECTOR_SIZE];

size_t nrSectors = min(1000, fileSize / SECTOR_SIZE);
size_t nrSectors = std::min((size_t)1000, fileSize / SECTOR_SIZE);
auto file = fopen(filePath.c_str(), "rb");
size_t result = SECTOR_SIZE;
size_t sector = 0;
Expand Down Expand Up @@ -272,12 +272,13 @@ bool System::LVP_FileSystem::IsDVDCSS(const std::string &filePath, size_t fileSi
if (filePath.empty() || (fileSize == 0))
return false;

const int SECTOR_SIZE = 2048;
char buffer[SECTOR_SIZE];
size_t nrSectors = min(1000, fileSize / SECTOR_SIZE);
FILE* file = fopen(filePath.c_str(), "rb");
size_t result = SECTOR_SIZE;
size_t sector = 0;
const size_t SECTOR_SIZE = 2048;
char buffer[SECTOR_SIZE];

size_t nrSectors = std::min((size_t)1000, fileSize / SECTOR_SIZE);
auto file = fopen(filePath.c_str(), "rb");
size_t result = SECTOR_SIZE;
size_t sector = 0;

std::rewind(file);

Expand Down
Loading

0 comments on commit 24b86ad

Please sign in to comment.