Commit a2228e5a authored by Olivier FAURE's avatar Olivier FAURE
Browse files

Add libvlc methods to vlc.js API.

parent 4c2d3527
......@@ -32,7 +32,8 @@ emcc --bind -s USE_PTHREADS=1 -s TOTAL_MEMORY=1GB -s PTHREAD_POOL_SIZE=15 \
-s OFFSCREEN_FRAMEBUFFER=1 -s USE_WEBGL2=1 --profiling-funcs \
-s MODULARIZE=1 -s EXPORT_NAME="VlcModule" \
-s EXTRA_EXPORTED_RUNTIME_METHODS="allocateUTF8" \
-I $PATH_VLC/include/ -I $PROJECT_DIR/wasm32-unknown-emscripten/include/ main.c \
-I $PATH_VLC/include/ -I $PROJECT_DIR/wasm32-unknown-emscripten/include/ \
exports_media_player.c main.c \
$PROJECT_DIR/build-emscripten/lib/.libs/libvlc.a \
$PROJECT_DIR/build-emscripten/vlc-modules.bc \
$PROJECT_DIR/build-emscripten/modules/.libs/*.a \
......
#include <vlc/vlc.h>
#include <vlc_common.h>
#include <emscripten.h>
#include <emscripten/html5.h>
extern libvlc_instance_t *libvlc;
// TODO - explain why we have to redefine everything
libvlc_media_player_t* EMSCRIPTEN_KEEPALIVE wasm_media_player_new() {
return libvlc_media_player_new(libvlc);
}
libvlc_media_player_t* EMSCRIPTEN_KEEPALIVE wasm_media_player_new_from_media(libvlc_media_t* media) {
return libvlc_media_player_new_from_media(media);
}
void EMSCRIPTEN_KEEPALIVE wasm_media_player_release(libvlc_media_player_t *media_player) {
libvlc_media_player_release(media_player);
}
void EMSCRIPTEN_KEEPALIVE wasmc_media_player_retain(libvlc_media_player_t *media_player) {
libvlc_media_player_retain(media_player);
}
void EMSCRIPTEN_KEEPALIVE wasm_media_player_set_media(libvlc_media_player_t *media_player, libvlc_media_t *media) {
libvlc_media_player_set_media(media_player, media);
}
libvlc_media_t* EMSCRIPTEN_KEEPALIVE wasm_media_player_get_media(libvlc_media_player_t *media_player) {
return libvlc_media_player_get_media(media_player);
}
// TODO
// LIBVLC_API libvlc_event_manager_t * libvlc_media_player_event_manager (libvlc_media_player_t *p_mi );
EM_BOOL EMSCRIPTEN_KEEPALIVE wasm_media_player_is_playing(libvlc_media_player_t *media_player) {
return libvlc_media_player_is_playing(media_player);
}
int EMSCRIPTEN_KEEPALIVE wasm_media_player_play(libvlc_media_player_t *media_player) {
return libvlc_media_player_play(media_player);
}
void EMSCRIPTEN_KEEPALIVE wasm_media_player_set_pause(libvlc_media_player_t *media_player, int do_pause) {
libvlc_media_player_set_pause(media_player, do_pause);
}
void EMSCRIPTEN_KEEPALIVE wasm_media_player_pause(libvlc_media_player_t *media_player) {
libvlc_media_player_pause(media_player);
}
// TODO
// LIBVLC_API int libvlc_media_player_stop_async ( libvlc_media_player_t *p_mi );
libvlc_time_t EMSCRIPTEN_KEEPALIVE wasm_media_player_get_length(libvlc_media_player_t *media_player) {
return libvlc_media_player_get_length(media_player);
}
libvlc_time_t EMSCRIPTEN_KEEPALIVE wasm_media_player_get_time(libvlc_media_player_t *media_player) {
return libvlc_media_player_get_time(media_player);
}
int EMSCRIPTEN_KEEPALIVE wasm_media_player_set_time(libvlc_media_player_t *media_player, libvlc_time_t time, bool fast) {
return libvlc_media_player_set_time(media_player, time, fast);
}
float EMSCRIPTEN_KEEPALIVE wasm_media_player_get_position(libvlc_media_player_t *media_player) {
return libvlc_media_player_get_position(media_player);
}
int EMSCRIPTEN_KEEPALIVE wasm_media_player_set_position(libvlc_media_player_t *media_player, float position, EM_BOOL fast) {
return libvlc_media_player_set_position(media_player, position, fast);
}
void EMSCRIPTEN_KEEPALIVE wasm_media_player_set_chapter(libvlc_media_player_t *media_player, int chapter) {
libvlc_media_player_set_chapter(media_player, chapter);
}
float EMSCRIPTEN_KEEPALIVE wasm_media_player_get_chapter(libvlc_media_player_t *media_player) {
return libvlc_media_player_get_chapter(media_player);
}
float EMSCRIPTEN_KEEPALIVE wasm_media_player_get_chapter_count(libvlc_media_player_t *media_player) {
return libvlc_media_player_get_chapter_count(media_player);
}
int EMSCRIPTEN_KEEPALIVE wasm_media_player_get_chapter_count_for_title(libvlc_media_player_t *media_player, int title) {
return libvlc_media_player_get_chapter_count_for_title(media_player, title);
}
void EMSCRIPTEN_KEEPALIVE wasm_media_player_set_title(libvlc_media_player_t *media_player, int title) {
libvlc_media_player_set_title(media_player, title);
}
float EMSCRIPTEN_KEEPALIVE wasm_media_player_get_title(libvlc_media_player_t *media_player) {
return libvlc_media_player_get_title(media_player);
}
int EMSCRIPTEN_KEEPALIVE wasm_media_player_get_title_count( libvlc_media_player_t *media_player ) {
return libvlc_media_player_get_title_count(media_player);
}
void EMSCRIPTEN_KEEPALIVE wasm_media_player_previous_chapter( libvlc_media_player_t *media_player ) {
libvlc_media_player_previous_chapter(media_player);
}
void EMSCRIPTEN_KEEPALIVE wasm_media_player_next_chapter( libvlc_media_player_t *media_player ) {
libvlc_media_player_next_chapter(media_player);
}
float EMSCRIPTEN_KEEPALIVE wasm_media_player_get_rate( libvlc_media_player_t *media_player ) {
return libvlc_media_player_get_rate(media_player);
}
int EMSCRIPTEN_KEEPALIVE wasm_media_player_set_rate( libvlc_media_player_t *media_player, float rate ) {
return libvlc_media_player_set_rate(media_player, rate);
}
unsigned EMSCRIPTEN_KEEPALIVE wasm_media_player_has_vout( libvlc_media_player_t *media_player ) {
return libvlc_media_player_has_vout(media_player);
}
EM_BOOL EMSCRIPTEN_KEEPALIVE wasm_media_player_is_seekable( libvlc_media_player_t *media_player ) {
return libvlc_media_player_is_seekable(media_player);
}
EM_BOOL EMSCRIPTEN_KEEPALIVE wasm_media_player_can_pause( libvlc_media_player_t *media_player ) {
return libvlc_media_player_can_pause(media_player);
}
EM_BOOL EMSCRIPTEN_KEEPALIVE wasm_media_player_program_scrambled( libvlc_media_player_t *media_player ) {
return libvlc_media_player_program_scrambled(media_player);
}
void EMSCRIPTEN_KEEPALIVE wasm_media_player_next_frame( libvlc_media_player_t *media_player ) {
libvlc_media_player_next_frame(media_player);
}
int EMSCRIPTEN_KEEPALIVE wasm_video_get_size_x(libvlc_media_player_t *media_player, unsigned num) {
unsigned x = 0;
unsigned y = 0;
int res = libvlc_video_get_size(media_player, num, &x, &y);
if (res == -1)
return -1;
else
return x;
}
int EMSCRIPTEN_KEEPALIVE wasm_video_get_size_y(libvlc_media_player_t *media_player, unsigned num) {
unsigned x = 0;
unsigned y = 0;
int res = libvlc_video_get_size(media_player, num, &x, &y);
if (res == -1)
return -1;
else
return y;
}
int EMSCRIPTEN_KEEPALIVE wasm_video_get_cursor_x(libvlc_media_player_t *media_player, unsigned num) {
int x = 0;
int y = 0;
int res = libvlc_video_get_cursor(media_player, num, &x, &y);
if (res == -1)
return -1;
else
return x;
}
int EMSCRIPTEN_KEEPALIVE wasm_video_get_cursor_y(libvlc_media_player_t *media_player, unsigned num) {
int x = 0;
int y = 0;
int res = libvlc_video_get_cursor(media_player, num, &x, &y);
if (res == -1)
return -1;
else
return y;
}
void EMSCRIPTEN_KEEPALIVE wasm_audio_toggle_mute(libvlc_media_player_t *media_player) {
libvlc_audio_toggle_mute(media_player);
}
EM_BOOL EMSCRIPTEN_KEEPALIVE wasm_audio_get_mute(libvlc_media_player_t *media_player) {
return libvlc_audio_get_mute(media_player);
}
void EMSCRIPTEN_KEEPALIVE wasm_audio_set_mute(libvlc_media_player_t *media_player, int status) {
libvlc_audio_set_mute(media_player, status);
}
int EMSCRIPTEN_KEEPALIVE wasm_audio_get_volume(libvlc_media_player_t *media_player) {
return libvlc_audio_get_volume(media_player);
}
int EMSCRIPTEN_KEEPALIVE wasm_audio_set_volume(libvlc_media_player_t *media_player, int volume) {
return libvlc_audio_set_volume(media_player, volume);
}
int EMSCRIPTEN_KEEPALIVE wasm_audio_get_channel(libvlc_media_player_t *media_player) {
return libvlc_audio_get_channel(media_player);
}
int EMSCRIPTEN_KEEPALIVE wasm_audio_set_channel(libvlc_media_player_t *media_player, int channel) {
return libvlc_audio_set_channel(media_player, channel);
}
int EMSCRIPTEN_KEEPALIVE wasm_audio_get_delay(libvlc_media_player_t *media_player) {
return libvlc_audio_get_delay(media_player);
}
int EMSCRIPTEN_KEEPALIVE wasm_audio_set_delay(libvlc_media_player_t *media_player, int delay) {
return libvlc_audio_set_delay(media_player, delay);
}
// TODO - Export libvlc_media_player_role constants
int EMSCRIPTEN_KEEPALIVE wasm_media_player_get_role(libvlc_media_player_t *media_player) {
return libvlc_media_player_get_role(media_player);
}
int EMSCRIPTEN_KEEPALIVE wasm_media_player_set_role(libvlc_media_player_t *media_player, unsigned role) {
return libvlc_media_player_set_role(media_player, role);
}
export class MediaPlayer {
constructor(module, path) {
this.module = module;
this.media_player_ptr = module._wasm_media_player_new();
module._attach_update_events(this.media_player_ptr);
if (path != null) {
let media = new Media(module, path);
this.set_media(media);
media.release();
}
}
release() {
this.module._wasm_media_player_release(this.media_player_ptr);
this.media_player_ptr = 0;
}
let path_ptr = module.allocateUTF8(path)
this.media_player_ptr = module._get_media_player(path_ptr);
module._free(path_ptr);
set_media(media) {
// TODO - assert typeof
this.module._wasm_media_player_set_media(this.media_player_ptr, media.media_ptr);
}
get_media() {
let media_ptr = this.module._wasm_media_player_get_media(this.media_player_ptr);
this.module._wasm_media_retain(media_ptr);
// Build from raw ptr
return new Media(this.module, null, media_ptr);
}
toggle_play() {
......@@ -17,45 +37,208 @@ export class MediaPlayer {
}
}
is_playing() {
return this.module._wasm_media_player_is_playing(this.media_player_ptr);
}
play() {
return this.module._play(this.media_player_ptr);
return this.module._wasm_media_player_play(this.media_player_ptr);
}
set_pause(do_pause) {
return this.module._wasm_media_player_set_pause(this.media_player_ptr, do_pause);
}
pause() {
return this.module._pause_video(this.media_player_ptr);
return this.module._wasm_media_player_pause(this.media_player_ptr);
}
is_playing() {
return this.module._is_playing(this.media_player_ptr);
get_length() {
return this.module._wasm_media_player_get_length(this.media_player_ptr);
}
get_time() {
return this.module._wasm_media_player_get_time(this.media_player_ptr);
}
set_time(time, fast = false) {
// TODO - what does "fast" argument do?
return this.module._wasm_media_player_set_time(this.media_player_ptr, time, fast);
}
get_position() {
return this.module._get_position(this.media_player_ptr);
return this.module._wasm_media_player_get_position(this.media_player_ptr);
}
set_position(position, fast = 0) {
set_position(position, fast = false) {
// TODO - what does "fast" argument do?
return this.module._set_position(this.media_player_ptr, position, fast);
return this.module._wasm_media_player_set_position(this.media_player_ptr, position, fast);
}
get_volume() {
return this.module._get_volume(this.media_player_ptr);
set_chapter(chapter) {
this.module._wasm_media_player_set_chapter(this.media_player_ptr, chapter);
}
set_volume(volume) {
return this.module._set_volume(this.media_player_ptr, volume);
get_chapter() {
return this.module._wasm_media_player_get_chapter(this.media_player_ptr);
}
get_chapter_count() {
return this.module._wasm_media_player_get_chapter_count(this.media_player_ptr);
}
get_chapter_count_for_title(title) {
return this.module._wasm_media_player_get_chapter_count_for_title(this.media_player_ptr, title);
}
set_title(title) {
this.module._wasm_media_player_set_title(this.media_player_ptr, title);
}
get_title() {
return this.module._wasm_media_player_get_title(this.media_player_ptr);
}
get_title_count() {
return this.module._wasm_media_player_get_title_count(this.media_player_ptr);
}
previous_chapter() {
return this.module._wasm_media_player_previous_chapter(this.media_player_ptr);
}
next_chapter() {
return this.module._wasm_media_player_next_chapter(this.media_player_ptr);
}
get_rate() {
return this.module._wasm_media_player_get_rate(this.media_player_ptr);
}
set_rate(rate) {
return this.module._wasm_media_player_set_rate(this.media_player_ptr, rate);
}
has_vout() {
return this.module._wasm_media_player_has_vout(this.media_player_ptr);
}
is_seekable() {
return this.module._wasm_media_player_is_seekable(this.media_player_ptr);
}
can_pause() {
return this.module._wasm_media_player_can_pause(this.media_player_ptr);
}
program_scrambled() {
return this.module._wasm_media_player_program_scrambled(this.media_player_ptr);
}
next_frame() {
return this.module._wasm_media_player_next_frame(this.media_player_ptr);
}
get_size() {
let x = this.module._wasm_video_get_size_x(this.media_player_ptr);
let y = this.module._wasm_video_get_size_y(this.media_player_ptr);
if (x == -1 || y == -1) {
// TODO - give more context
throw new Error("Cannot get video size");
}
return { x, y };
}
get_cursor() {
let x = this.module._wasm_video_get_cursor_x(this.media_player_ptr);
let y = this.module._wasm_video_get_cursor_y(this.media_player_ptr);
if (x == -1 || y == -1) {
// TODO - give more context
throw new Error("Cannot get video cursor");
}
return { x, y };
}
toggle_mute() {
return this.module._toggle_mute(this.media_player_ptr);
this.module._wasm_audio_toggle_mute(this.media_player_ptr);
}
get_mute() {
return this.module._get_mute(this.media_player_ptr);
return this.module._wasm_audio_get_mute(this.media_player_ptr);
}
set_mute(mute) {
return this.module._set_mute(this.media_player_ptr, mute);
this.module._wasm_audio_set_mute(this.media_player_ptr, mute);
}
get_volume() {
return this.module._wasm_audio_get_volume(this.media_player_ptr);
}
set_volume(volume) {
return this.module._wasm_audio_set_volume(this.media_player_ptr, volume);
}
get_channel() {
return this.module._wasm_audio_get_channel(this.media_player_ptr);
}
set_channel(rate) {
return this.module._wasm_audio_set_channel(this.media_player_ptr, rate);
}
get_delay() {
return this.module._wasm_audio_get_delay(this.media_player_ptr);
}
set_delay(rate) {
return this.module._wasm_audio_set_delay(this.media_player_ptr, rate);
}
get_role() {
return this.module._wasm_media_player_get_role(this.media_player_ptr);
}
set_role(role) {
return this.module._wasm_media_player_set_role(this.media_player_ptr, role);
}
}
export class Media {
constructor(module, path, raw_ptr) {
if (raw_ptr != null) {
this.module = module;
this.media_ptr = raw_ptr;
return;
}
if (typeof path != 'string') {
throw new Error("Tried to create Media with invalid value");
}
this.module = module;
let path_ptr = module.allocateUTF8(path)
this.media_ptr = module._wasm_media_new_path(path_ptr);
module._free(path_ptr);
if (this.media_ptr == 0) {
// TODO - give more context
throw new Error(`Could not create media from path {path}`);
}
}
release() {
this.module._wasm_media_release(this.media_ptr);
this.media_ptr = 0;
}
}
......@@ -13,6 +13,8 @@ libvlc_time_t t = -1;
static void iter()
{
if (!mp)
return;
if (libvlc_media_player_get_time(mp) == t) {
// when enable, the js does not respond.
//libvlc_media_player_release( mp );
......@@ -22,6 +24,10 @@ static void iter()
t = libvlc_media_player_get_time(mp);
}
void EMSCRIPTEN_KEEPALIVE set_global_media_player(libvlc_media_player_t *media_player) {
mp = media_player;
}
extern void update_overlay();
extern void on_position_changed(const libvlc_event_t *p_event, void *p_data);
......@@ -52,27 +58,7 @@ int main() {
return 0;
}
void* EMSCRIPTEN_KEEPALIVE get_media_player(const char* path) {
libvlc_media_player_t *media_player;
libvlc_media_t *m;
m = libvlc_media_new_path( libvlc, path );
if (m == NULL)
{
fprintf(stderr, "unable to create media");
return NULL;
}
media_player = libvlc_media_player_new_from_media( m );
if (media_player == NULL)
{
fprintf(stderr, "unable to create media player");
return NULL;
}
libvlc_media_release( m );
m = libvlc_media_player_get_media(media_player);
void EMSCRIPTEN_KEEPALIVE attach_update_events(libvlc_media_player_t *media_player) {
libvlc_event_manager_t* event_manager = libvlc_media_player_event_manager(media_player);
int res;
res = libvlc_event_attach(
......@@ -89,50 +75,18 @@ void* EMSCRIPTEN_KEEPALIVE get_media_player(const char* path) {
NULL
);
assert(res == 0);
assert(media_player != NULL);
mp = media_player;
return media_player;
}
// ---
int EMSCRIPTEN_KEEPALIVE play(libvlc_media_player_t *media_player) {
return libvlc_media_player_play(media_player);
}
void EMSCRIPTEN_KEEPALIVE pause_video(libvlc_media_player_t *media_player) {
libvlc_media_player_pause(media_player);
}
EM_BOOL EMSCRIPTEN_KEEPALIVE is_playing(libvlc_media_player_t *media_player) {
return libvlc_media_player_is_playing(media_player);
}
float EMSCRIPTEN_KEEPALIVE get_position(libvlc_media_player_t *media_player) {
return libvlc_media_player_get_position(media_player);
}
int EMSCRIPTEN_KEEPALIVE set_position(libvlc_media_player_t *media_player, float position, EM_BOOL fast) {
return libvlc_media_player_set_position(media_player, position, fast);
}
int EMSCRIPTEN_KEEPALIVE get_volume(libvlc_media_player_t *media_player) {
return libvlc_audio_get_volume(media_player);
}
int EMSCRIPTEN_KEEPALIVE set_volume(libvlc_media_player_t *media_player, int i_volume) {
return libvlc_audio_set_volume(media_player, i_volume);
}
void EMSCRIPTEN_KEEPALIVE toggle_mute(libvlc_media_player_t *media_player) {
libvlc_audio_toggle_mute(media_player);
libvlc_media_t* EMSCRIPTEN_KEEPALIVE wasm_media_new_path(const char *path) {
return libvlc_media_new_path(libvlc, path);
}
EM_BOOL EMSCRIPTEN_KEEPALIVE get_mute(libvlc_media_player_t *media_player) {
return libvlc_audio_get_mute(media_player);
void EMSCRIPTEN_KEEPALIVE wasm_media_retain( libvlc_media_t *media) {
libvlc_media_retain(media);
}
void EMSCRIPTEN_KEEPALIVE set_mute(libvlc_media_player_t *media_player, int i_status) {
libvlc_audio_set_mute(media_player, i_status);
void EMSCRIPTEN_KEEPALIVE wasm_media_release( libvlc_media_t *media) {
libvlc_media_release(media);
}
......@@ -119,6 +119,9 @@
const overlay = document.getElementById("overlay");
const media_player = new MediaPlayer(Module, "./samples/BigBuckBunny.mp4");
// FIXME
Module._set_global_media_player(media_player.media_player_ptr);
window.media_player = media_player;
window.on_overlay_click = on_overlay_click;
window.update_overlay = update_overlay;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment