Skip to content

Commit

Permalink
Add common library (alexmercerind#110)
Browse files Browse the repository at this point in the history
Build a common library that gets linked into the platform-specific plugin shared library.
  • Loading branch information
jnschulze authored Aug 17, 2021
1 parent ab2503c commit 9a08ad4
Show file tree
Hide file tree
Showing 67 changed files with 1,817 additions and 247 deletions.
29 changes: 14 additions & 15 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
name: Github Actions
on:
pull_request:
branches:
- stable
- master
push:
branches:
- stable
- master
on: [push, pull_request]

defaults:
run:
Expand All @@ -19,9 +11,6 @@ jobs:
runs-on: windows-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-java@v1
with:
java-version: "12.x"
- uses: subosito/flutter-action@v1
with:
channel: "beta"
Expand All @@ -38,9 +27,6 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-java@v1
with:
java-version: "12.x"
- uses: subosito/flutter-action@v1
with:
channel: "beta"
Expand All @@ -49,3 +35,16 @@ jobs:
- run: flutter config --enable-linux-desktop
- run: flutter pub get
- run: flutter build linux --verbose

build_macos:
name: Build macOS
runs-on: macos-latest
steps:
- uses: actions/checkout@v2
- uses: subosito/flutter-action@v1
with:
channel: "beta"
- run: flutter config --enable-macos-desktop
- run: flutter pub get
- run: flutter build macos --verbose

1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,3 @@ build/

.idea

example/*
91 changes: 91 additions & 0 deletions dartvlc/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
cmake_minimum_required(VERSION 3.13)
set(CMAKE_CXX_STANDARD 17)

if(UNIX AND NOT APPLE)
set(LINUX TRUE)
endif()

set(LIBRARY_NAME dart_vlc_core)
project(${LIBRARY_NAME} LANGUAGES C CXX)

set(LIBVLC_VERSION "3.0.9.2")
set(LIBVLC_BINARIES "${CMAKE_CURRENT_SOURCE_DIR}/../bin")

set(LIBVLC_ARCHIVE "${LIBVLC_BINARIES}/vlc-${LIBVLC_VERSION}.7z")
set(LIBVLCPP_ARCHIVE "${LIBVLC_BINARIES}/libvlcpp.zip")

set(LIBVLC_PACKAGE_DIR "${CMAKE_BINARY_DIR}/${LIBRARY_NAME}_packages")
set(LIBVLC_SOURCE "${LIBVLC_PACKAGE_DIR}/vlc-${LIBVLC_VERSION}")
set(LIBVLCPP_SOURCE "${LIBVLC_PACKAGE_DIR}/libvlcpp-master")

add_custom_target(LIBVLC_EXTRACT ALL)

if (NOT EXISTS "${LIBVLC_SOURCE}" OR NOT EXISTS "${LIBVLCPP_SOURCE}")
file(MAKE_DIRECTORY ${LIBVLC_PACKAGE_DIR})
add_custom_command(
TARGET LIBVLC_EXTRACT PRE_BUILD
COMMAND ${CMAKE_COMMAND} -E tar xzf \"${LIBVLC_ARCHIVE}\"
COMMAND ${CMAKE_COMMAND} -E tar xzf \"${LIBVLCPP_ARCHIVE}\"
WORKING_DIRECTORY "${LIBVLC_PACKAGE_DIR}"
DEPENDS "${LIBVLC_ARCHIVE}" "${LIBVLCPP_ARCHIVE}"
)
endif()

add_library(${LIBRARY_NAME} STATIC
main.cc
api/api.cc
)
add_dependencies(${LIBRARY_NAME} LIBVLC_EXTRACT)

set_target_properties(${LIBRARY_NAME} PROPERTIES LINKER_LANGUAGE CXX)

get_directory_property(hasParent PARENT_DIRECTORY)

target_include_directories(${LIBRARY_NAME} PRIVATE
# dart_vlc wrapper headers.
"${CMAKE_CURRENT_SOURCE_DIR}"
# libVLC++ headers.
"${LIBVLCPP_SOURCE}"
# libVLC headers.
"${LIBVLC_SOURCE}/sdk/include"
)

target_include_directories(${LIBRARY_NAME} INTERFACE
# libVLC++ headers.
"${LIBVLCPP_SOURCE}"
# libVLC headers.
"${LIBVLC_SOURCE}/sdk/include"
)

if(WIN32)
set_target_properties(${LIBRARY_NAME} PROPERTIES CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
target_link_libraries(${LIBRARY_NAME} PRIVATE
"${LIBVLC_SOURCE}/sdk/lib/libvlc.lib"
"${LIBVLC_SOURCE}/sdk/lib/libvlccore.lib"
)

# Add generated shared library & libVLC DLLs.
set(DARTVLC_CORE_LIBS
# In case we decide to build this as a shared library
#"$<TARGET_FILE:dart_vlc_core>"

"${LIBVLC_SOURCE}/libvlc.dll"
"${LIBVLC_SOURCE}/libvlccore.dll"
"${LIBVLC_SOURCE}/plugins"
PARENT_SCOPE
)

elseif(LINUX)
set_target_properties(${LIBRARY_NAME} PROPERTIES POSITION_INDEPENDENT_CODE ON)
target_link_libraries(${LIBRARY_NAME} PRIVATE
"vlc"
)
endif()

if (hasParent)
set(DARTVLC_CORE_PATH ${CMAKE_CURRENT_SOURCE_DIR} PARENT_SCOPE)
else()
# only required by our podspec script phase
install(TARGETS ${LIBRARY_NAME})
endif()

22 changes: 8 additions & 14 deletions ffi/native/dart_vlc.cpp → dartvlc/api/api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,20 @@
* GNU Lesser General Public License v2.1
*/

#ifndef DLLEXPORT
#ifdef _WIN32
#define DLLEXPORT __declspec(dllexport)
#else
#define DLLEXPORT
#endif
#endif

#include <memory>

#include "eventmanager.hpp"
#include "api/eventmanager.h"
#include "broadcast.h"
#include "chromecast.h"
#include "device.h"
#include "equalizer.h"
#include "player.h"
#include "record.h"

#ifdef __cplusplus
extern "C" {
#endif

#ifndef DART_VLC_FFI
#define DART_VLC_FFI

static char** g_metas_ptr = nullptr;
static size_t g_metas_size = 0;
static char** g_devices_ptr = nullptr;
Expand Down Expand Up @@ -370,7 +365,6 @@ DLLEXPORT void EqualizerSetPreAmp(int32_t id, float amp) {
g_equalizers->Get(id)->SetPreAmp(amp);
}

#endif
#ifdef __cplusplus
}
#endif
#endif
106 changes: 106 additions & 0 deletions dartvlc/api/api.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
/*
* dart_vlc: A media playback library for Dart & Flutter. Based on libVLC &
* libVLC++.
*
* Hitesh Kumar Saini
* https://github.com/alexmercerind
* [email protected]
*
* GNU Lesser General Public License v2.1
*/

#ifndef API_DART_VLC_H_
#define API_DART_VLC_H_

#include <cstdint>

#include "base.h"

#ifdef __cplusplus
extern "C" {
#endif

DLLEXPORT void PlayerCreate(int32_t id, int32_t video_width,
int32_t video_height,
int32_t commandLineArgumentsCount,
const char** commandLineArguments);
DLLEXPORT void PlayerDispose(int32_t id);

DLLEXPORT void PlayerOpen(int32_t id, bool auto_start, const char** source,
int32_t source_size);

DLLEXPORT void PlayerPlay(int32_t id);

DLLEXPORT void PlayerPause(int32_t id);

DLLEXPORT void PlayerPlayOrPause(int32_t id);

DLLEXPORT void PlayerStop(int32_t id);
DLLEXPORT void PlayerNext(int32_t id);

DLLEXPORT void PlayerBack(int32_t id);

DLLEXPORT void PlayerJump(int32_t id, int32_t index);

DLLEXPORT void PlayerSeek(int32_t id, int32_t position);

DLLEXPORT void PlayerSetVolume(int32_t id, float volume);

DLLEXPORT void PlayerSetRate(int32_t id, float rate);

DLLEXPORT void PlayerSetUserAgent(int32_t id, const char* userAgent);

DLLEXPORT void PlayerSetDevice(int32_t id, const char* device_id,
const char* device_name);

DLLEXPORT void PlayerSetEqualizer(int32_t id, int32_t equalizer_id);

DLLEXPORT void PlayerSetPlaylistMode(int32_t id, const char* mode);

DLLEXPORT void PlayerAdd(int32_t id, const char* type, const char* resource);

DLLEXPORT void PlayerRemove(int32_t id, int32_t index);

DLLEXPORT void PlayerInsert(int32_t id, int32_t index, const char* type,
const char* resource);

DLLEXPORT void Player_move(int32_t id, int32_t initial_index,
int32_t final_index);

DLLEXPORT char** MediaParse(const char* type, const char* resource,
int32_t timeout);

DLLEXPORT void MediaClear();

DLLEXPORT void BroadcastCreate(int32_t id, const char* type,
const char* resource, const char* access,
const char* mux, const char* dst,
const char* vcodec, int32_t vb,
const char* acodec, int32_t ab);

DLLEXPORT void BroadcastStart(int32_t id);

DLLEXPORT void BroadcastDispose(int32_t id);

DLLEXPORT void ChromecastCreate(int32_t id, const char* type,
const char* resource, const char* ip_address);

DLLEXPORT void ChromecastStart(int32_t id);

DLLEXPORT void ChromecastDispose(int32_t id);
DLLEXPORT void RecordCreate(int32_t id, const char* saving_file,
const char* type, const char* resource);
DLLEXPORT void RecordStart(int32_t id);
DLLEXPORT void RecordDispose(int32_t id);
DLLEXPORT char** DevicesAll();
DLLEXPORT void DevicesClear();
DLLEXPORT char** EqualizerCreateEmpty();
DLLEXPORT char** EqualizerCreateMode(int32_t mode);
DLLEXPORT void EqualizerClear();
DLLEXPORT void EqualizerSetBandAmp(int32_t id, float band, float amp);
DLLEXPORT void EqualizerSetPreAmp(int32_t id, float amp);

#endif
#ifdef __cplusplus
}
#endif
19 changes: 8 additions & 11 deletions ffi/native/callbackmanager.hpp → dartvlc/api/callbackmanager.h
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
#ifndef DLLEXPORT
#ifdef _WIN32
#define DLLEXPORT __declspec(dllexport)
#else
#define DLLEXPORT
#endif
#endif
#ifndef API_CALLBACKMANAGER_H_
#define API_CALLBACKMANAGER_H_

#include <cstdint>
#include <iostream>
#include <string>
#include <vector>

#ifndef CALLBACK_MANAGER
#define CALLBACK_MANAGER
#include "base.h"

typedef int64_t Dart_Port;

Expand Down Expand Up @@ -118,7 +115,7 @@ void CallbackStringArray(int32_t length, char** values) {
auto value_objects =
std::unique_ptr<Dart_CObject[]>(new Dart_CObject[length]);
auto value_object_refs =
std::unique_ptr<Dart_CObject* []>(new Dart_CObject*[length]);
std::unique_ptr<Dart_CObject*[]>(new Dart_CObject*[length]);

for (int32_t i = 0; i < length; i++) {
Dart_CObject* value_object = &value_objects[i];
Expand All @@ -138,7 +135,7 @@ void CallbackStringArray(const std::vector<std::string>& values) {
auto value_objects =
std::unique_ptr<Dart_CObject[]>(new Dart_CObject[length]);
auto value_object_refs =
std::unique_ptr<Dart_CObject* []>(new Dart_CObject*[length]);
std::unique_ptr<Dart_CObject*[]>(new Dart_CObject*[length]);

for (int32_t i = 0; i < length; i++) {
Dart_CObject* value_object = &value_objects[i];
Expand Down
12 changes: 9 additions & 3 deletions ffi/native/eventmanager.hpp → dartvlc/api/eventmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@
* GNU Lesser General Public License v2.1
*/

#include "../../dartvlc/main.cpp"
#include "callbackmanager.hpp"
#ifndef API_EVENTMANAGER_H_
#define API_EVENTMANAGER_H_

#include "api/callbackmanager.h"
#include "player.h"

#ifdef __cplusplus
extern "C" {
Expand All @@ -33,7 +36,8 @@ inline void OnPosition(int32_t id, PlayerState* state) {

inline void OnComplete(int32_t id, PlayerState* state) {
std::vector<std::string> event{
std::to_string(id), "completeEvent",
std::to_string(id),
"completeEvent",
std::to_string(state->is_completed()),
};
CallbackStringArray(event);
Expand Down Expand Up @@ -81,3 +85,5 @@ inline void OnVideo(int32_t id, int size, PlayerState* state, uint8_t* frame) {
#ifdef __cplusplus
}
#endif

#endif
12 changes: 12 additions & 0 deletions dartvlc/base.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#ifndef BASE_H_
#define BASE_H_

#ifndef DLLEXPORT
#ifdef _WIN32
#define DLLEXPORT __declspec(dllexport)
#else
#define DLLEXPORT
#endif
#endif

#endif
Loading

0 comments on commit 9a08ad4

Please sign in to comment.