<div dir="ltr"><div dir="ltr">On Wed, Aug 19, 2020 at 10:45 AM Steve Lhomme <<a href="mailto:robux4@ycbcr.xyz">robux4@ycbcr.xyz</a>> wrote:<br></div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Hello,<br>
<br>
On 2020-08-18 22:37, Kartik Ohri wrote:<br>
> The purpose of this module is to serve as a Proof Of Concept<br>
<br>
In general you should use [RFC] in the subject of your email, suggesting <br>
it's not meant to be merged as such.<br>
<br></blockquote><div>I will keep this in mind.</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
> and an example on how Rust code can be integrated inside VLC.<br>
> ---<br>
> <a href="http://configure.ac" rel="noreferrer" target="_blank">configure.ac</a> | 12 ++<br>
> modules/demux/Makefile.am | 25 +++<br>
> modules/demux/playlist/cuesheet.c | 155 ++++++++++++++++++<br>
> modules/demux/playlist/cuesheet/.gitignore | 2 +<br>
> modules/demux/playlist/cuesheet/Cargo.toml | 10 ++<br>
> modules/demux/playlist/cuesheet/cbindgen.toml | 16 ++<br>
> modules/demux/playlist/cuesheet/cuesheet.h | 44 +++++<br>
> modules/demux/playlist/cuesheet/src/<a href="http://capi.rs" rel="noreferrer" target="_blank">capi.rs</a> | 115 +++++++++++++<br>
> modules/demux/playlist/cuesheet/src/<a href="http://config.rs" rel="noreferrer" target="_blank">config.rs</a> | 108 ++++++++++++<br>
> modules/demux/playlist/cuesheet/src/<a href="http://lib.rs" rel="noreferrer" target="_blank">lib.rs</a> | 18 ++<br>
> modules/demux/playlist/cuesheet/src/<a href="http://parse.rs" rel="noreferrer" target="_blank">parse.rs</a> | 69 ++++++++<br>
> modules/demux/playlist/playlist.c | 4 +<br>
> modules/demux/playlist/playlist.h | 2 +<br>
> 13 files changed, 580 insertions(+)<br>
> create mode 100644 modules/demux/playlist/cuesheet.c<br>
> create mode 100644 modules/demux/playlist/cuesheet/.gitignore<br>
> create mode 100644 modules/demux/playlist/cuesheet/Cargo.toml<br>
> create mode 100644 modules/demux/playlist/cuesheet/cbindgen.toml<br>
> create mode 100644 modules/demux/playlist/cuesheet/cuesheet.h<br>
> create mode 100644 modules/demux/playlist/cuesheet/src/<a href="http://capi.rs" rel="noreferrer" target="_blank">capi.rs</a><br>
> create mode 100644 modules/demux/playlist/cuesheet/src/<a href="http://config.rs" rel="noreferrer" target="_blank">config.rs</a><br>
> create mode 100644 modules/demux/playlist/cuesheet/src/<a href="http://lib.rs" rel="noreferrer" target="_blank">lib.rs</a><br>
> create mode 100644 modules/demux/playlist/cuesheet/src/<a href="http://parse.rs" rel="noreferrer" target="_blank">parse.rs</a><br>
> <br>
> diff --git a/<a href="http://configure.ac" rel="noreferrer" target="_blank">configure.ac</a> b/<a href="http://configure.ac" rel="noreferrer" target="_blank">configure.ac</a><br>
> index a30e86bf37..93a45d57d6 100644<br>
> --- a/<a href="http://configure.ac" rel="noreferrer" target="_blank">configure.ac</a><br>
> +++ b/<a href="http://configure.ac" rel="noreferrer" target="_blank">configure.ac</a><br>
> @@ -1886,6 +1886,18 @@ AS_IF([test "${enable_sout}" != "no"], [<br>
> ])<br>
> AM_CONDITIONAL([ENABLE_SOUT], [test "${enable_sout}" != "no"])<br>
> <br>
> +dnl Rust Modules<br>
> +AC_ARG_ENABLE([rust],<br>
> + AS_HELP_STRING([--enable-rust], [disable building Rust modules (default disabled)]))<br>
> +AS_IF([test "${enable_rust}" = "yes"],<br>
> + [AC_DEFINE(ENABLE_RUST, 1, [Define to 1 for building rust modules.])])<br>
> +AM_CONDITIONAL([BUILD_RUST], [test "${enable_rust}" = "yes"])<br>
> +if test "${enable_rust}" = "yes"<br>
> +then<br>
> + AC_CHECK_PROG(CARGO, [cargo], [yes], [no])<br>
> + AS_IF(test "x$CARGO" = "xno", [cargo not found. cargo is required to build rust modules])<br>
> +fi<br>
<br>
You probably don't want to enable building Rust if cargo is not found. <br>
So BUILD_RUST should also depend on this test.<br>
<br></blockquote><div>Yes, right. Will fix it.</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
> +<br>
> dnl Lua modules<br>
> AC_ARG_ENABLE([lua],<br>
> AS_HELP_STRING([--disable-lua],<br>
> diff --git a/modules/demux/Makefile.am b/modules/demux/Makefile.am<br>
> index 67ec086af9..a2c3018f71 100644<br>
> --- a/modules/demux/Makefile.am<br>
> +++ b/modules/demux/Makefile.am<br>
> @@ -1,3 +1,4 @@<br>
> +<br>
> demuxdir = $(pluginsdir)/demux<br>
> demux_LTLIBRARIES =<br>
> <br>
> @@ -254,6 +255,30 @@ libplaylist_plugin_la_SOURCES = \<br>
> demux/playlist/wpl.c \<br>
> demux/playlist/xspf.c \<br>
> demux/playlist/playlist.c demux/playlist/playlist.h<br>
> +<br>
> +if BUILD_RUST<br>
> +CARGO_C = cargo capi install --release<br>
> +RUST_RUNTIME_LIBS = -ldl -lrt -lpthread -lgcc_s -lc -lm -lrt -lpthread -lutil<br>
<br>
This should not be hardcoded. Some may come from the Rust+C linking, <br>
some from the library you are using. This should be settled via <br>
variables in <a href="http://configure.ac" rel="noreferrer" target="_blank">configure.ac</a>.<br>
<br></blockquote><div>Understood.</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
> +<br>
> +libcuesheet_rust_plugin_la_SOURCES = \<br>
> + demux/playlist/cuesheet/src/<a href="http://capi.rs" rel="noreferrer" target="_blank">capi.rs</a> \<br>
> + demux/playlist/cuesheet/src/<a href="http://config.rs" rel="noreferrer" target="_blank">config.rs</a> \<br>
> + demux/playlist/cuesheet/src/<a href="http://lib.rs" rel="noreferrer" target="_blank">lib.rs</a> \<br>
> + demux/playlist/cuesheet/src/<a href="http://parse.rs" rel="noreferrer" target="_blank">parse.rs</a><br>
> +<br>
> +abs_src_dir = $(shell readlink -f $(srcdir))<br>
> +<br>
> +@abs_top_builddir@/modules/demux/playlist/cuesheet/libcuesheet.a: $(libcuesheet_rust_plugin_la_SOURCES)<br>
> + mkdir -p demux/playlist/cuesheet && cd demux/playlist/cuesheet && \<br>
> + $(CARGO_C) --library-type=staticlib --destdir=. --includedir=.. --libdir=. \<br>
> + --manifest-path=$(abs_src_dir)/demux/playlist/cuesheet/Cargo.toml<br>
> +<br>
> +CUESHEET_LIBS = @abs_top_builddir@/modules/demux/playlist/cuesheet/libcuesheet.a<br>
> +CUESHEET_LIBS += $(RUST_RUNTIME_LIBS)<br>
> +libplaylist_plugin_la_SOURCES += demux/playlist/cuesheet.c demux/playlist/cuesheet/cuesheet.h<br>
> +libplaylist_plugin_la_LIBADD = $(CUESHEET_LIBS)<br>
> +endif<br>
> +<br>
> demux_LTLIBRARIES += <a href="http://libplaylist_plugin.la" rel="noreferrer" target="_blank">libplaylist_plugin.la</a><br>
> <br>
> libts_plugin_la_SOURCES = demux/mpeg/ts.c demux/mpeg/ts.h \<br>
> diff --git a/modules/demux/playlist/cuesheet.c b/modules/demux/playlist/cuesheet.c<br>
> new file mode 100644<br>
> index 0000000000..9330b01079<br>
> --- /dev/null<br>
> +++ b/modules/demux/playlist/cuesheet.c<br>
> @@ -0,0 +1,155 @@<br>
> +/*****************************************************************************<br>
> + * cuesheet.c : cue sheet playlist import format<br>
> + *****************************************************************************<br>
> + * Copyright (C) 2020 VLC authors and VideoLAN<br>
> + *<br>
> + * Authors: Kartik Ohri <<a href="mailto:kartikohri13@gmail.com" target="_blank">kartikohri13@gmail.com</a>><br>
> + *<br>
> + * This program is free software; you can redistribute it and/or modify it<br>
> + * under the terms of the GNU Lesser General Public License as published by<br>
> + * the Free Software Foundation; either version 2.1 of the License, or<br>
> + * (at your option) any later version.<br>
> + *<br>
> + * This program is distributed in the hope that it will be useful,<br>
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of<br>
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the<br>
> + * GNU Lesser General Public License for more details.<br>
> + *<br>
> + * You should have received a copy of the GNU Lesser General Public License<br>
> + * along with this program; if not, write to the Free Software Foundation,<br>
> + * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.<br>
> + *****************************************************************************/<br>
> +<br>
> +#ifdef HAVE_CONFIG_H<br>
> +# include "config.h"<br>
> +#endif<br>
> +<br>
> +#include <string.h><br>
> +<br>
> +#include <vlc_common.h><br>
> +#include <vlc_access.h><br>
> +#include <vlc_url.h><br>
> +<br>
> +#include "cuesheet/cuesheet.h"<br>
> +#include "playlist.h"<br>
> +<br>
> +typedef struct {<br>
> + struct CCuesheet *cuesheet;<br>
> +} cuesheet_sys_t;<br>
> +<br>
> +static int ReadDir(stream_t *, input_item_node_t *);<br>
> +static char* get_string_property(CCuesheet *, const char*, int);<br>
> +<br>
> +int Import_Cue_Sheet( vlc_object_t *p_this )<br>
> +{<br>
> + stream_t *p_demux = (stream_t *) p_this;<br>
> + CHECK_FILE ( p_demux );<br>
> +<br>
> + if ( !stream_IsMimeType ( p_demux->s, "application/x-cue" )<br>
> + && !stream_HasExtension( p_demux->s, ".cue" ))<br>
> + return VLC_EGENERIC;<br>
> +<br>
> + cuesheet_sys_t *sys = (cuesheet_sys_t *) malloc(sizeof(*sys));<br>
> + sys->cuesheet = cuesheet_default();<br>
> + p_demux->p_sys = sys;<br>
> +<br>
> + p_demux->pf_control = access_vaDirectoryControlHelper;<br>
> + p_demux->pf_readdir = ReadDir;<br>
> + return VLC_SUCCESS;<br>
> +}<br>
> +<br>
> +/**<br>
> + * free should not be called on strings allocated by rust compiler. There is no<br>
> + * way to ensure this without duplicating the string before passing it to<br>
> + * input_item_t. To avoid redundancy and duplication, use this method instead<br>
> + * of directly using cuesheet_get_property or cuesheet_get_track_property.<br>
> + * For getting the property using cuesheet_get_property pass a negative number as<br>
> + * track_num. For using cuesheet_get_track_property, pass the track number for<br>
> + * which you the property as track_num.<br>
> + */<br>
> +static char* get_string_property(CCuesheet *cuesheet, const char* property, int track_num) {<br>
> + const char* psz_val;<br>
> + if(track_num < 0)<br>
> + psz_val = cuesheet_get_property(cuesheet, property);<br>
> + else<br>
> + psz_val = cuesheet_get_track_property(cuesheet, track_num, property);<br>
> + if(!psz_val)<br>
> + return NULL;<br>
> + char *psz_c_val = strdup(psz_val);<br>
<br>
It seems you use the return value to call other setter functions. You <br>
can probably just return the const char * and use it directly.<br>
<br></blockquote><div>I did this because the Rust documentation (<a href="https://doc.rust-lang.org/std/ffi/struct.CString.html#method.into_raw">https://doc.rust-lang.org/std/ffi/struct.CString.html#method.into_raw</a>) mentions that free() should not be called on a string allocated by rust. If it is guaranteed that this will not happen for the current usage, it is safe to remove this block of code.</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
> + unref_cuesheet_string(psz_val);<br>
> + return psz_c_val;<br>
> +}<br>
> +<br>
> +static int ReadDir(stream_t* p_demux, input_item_node_t* p_subitems)<br>
> +{<br>
> + cuesheet_sys_t *sys = p_demux->p_sys;<br>
> + char *psz_line;<br>
> + while ((psz_line = vlc_stream_ReadLine(p_demux->s)) != NULL)<br>
> + {<br>
> + msg_Dbg(p_demux, "%s", psz_line);<br>
<br>
Should probably be commented out in the end.<br>
<br></blockquote><div>Will fix this.</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
> + cuesheet_process_line(sys->cuesheet, psz_line);<br>
> + free(psz_line);<br>
> + }<br>
> + int tracks = cuesheet_get_tracks_number(sys->cuesheet);<br>
> + int idx = 0;<br>
> + const char *p_val = NULL;<br>
> + char *ppsz_option[2];<br>
> +<br>
> + char *psz_audio_file = get_string_property(sys->cuesheet, "FILE_NAME", -1);<br>
> + if (!psz_audio_file)<br>
> + goto error;<br>
> +<br>
> + char *psz_audio_file_uri = vlc_uri_encode(psz_audio_file);<br>
> + char *psz_url = vlc_uri_resolve(p_demux->psz_url, psz_audio_file_uri);<br>
> + free(psz_audio_file);<br>
> + free(psz_audio_file_uri);<br>
> +<br>
> + while ( idx < tracks )<br>
> + {<br>
> + int i_options = 0;<br>
> + input_item_t *p_item;<br>
> +<br>
> + p_val = get_string_property(sys->cuesheet, "TITLE", idx);<br>
> + if (p_val)<br>
> + {<br>
> + p_item = input_item_New(psz_url, p_val);<br>
> + p_item->i_type = ITEM_TYPE_FILE;<br>
> + }<br>
> + else<br>
> + goto error;<br>
> +<br>
> + p_val = get_string_property(sys->cuesheet, "TITLE", -1);<br>
> + if (p_val)<br>
> + input_item_SetAlbum(p_item, p_val);<br>
> +<br>
> + p_val = get_string_property(sys->cuesheet, "PERFORMER", -1);<br>
> + if (p_val)<br>
> + input_item_SetAlbumArtist(p_item, p_val);<br>
> +<br>
> + p_val = get_string_property(sys->cuesheet, "PERFORMER", idx);<br>
> + if (p_val)<br>
> + input_item_SetArtist(p_item, p_val);<br>
> +<br>
> + int i_time = cuesheet_get_track_start(sys->cuesheet, idx);<br>
> + if (asprintf(ppsz_option, ":start-time=%d", i_time))<br>
> + i_options++;<br>
> +<br>
> + if (idx < tracks - 1)<br>
> + {<br>
> + i_time = cuesheet_get_track_start(sys->cuesheet, idx + 1);<br>
> + if (asprintf(ppsz_option + i_options, ":stop-time=%d", i_time))<br>
> + i_options++;<br>
> + }<br>
> +<br>
> + input_item_AddOptions(p_item, i_options, (const char **)ppsz_option, VLC_INPUT_OPTION_TRUSTED);<br>
> + input_item_node_AppendItem(p_subitems, p_item);<br>
> + input_item_Release(p_item);<br>
> + idx++;<br>
> + }<br>
> + return VLC_SUCCESS;<br>
> +error:<br>
> + return VLC_EGENERIC;<br>
> +}<br>
> +<br>
> +<br>
> +<br>
> diff --git a/modules/demux/playlist/cuesheet/.gitignore b/modules/demux/playlist/cuesheet/.gitignore<br>
<br>
This should not be merged here. Either a general rule in the topmost <br>
.gitignore or not at all.<br>
<br></blockquote><div>Understood. Will fix it.</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
> new file mode 100644<br>
> index 0000000000..96ef6c0b94<br>
> --- /dev/null<br>
> +++ b/modules/demux/playlist/cuesheet/.gitignore<br>
<br>
Same here.<br>
<br>
> @@ -0,0 +1,2 @@<br>
> +/target<br>
> +Cargo.lock<br>
> diff --git a/modules/demux/playlist/cuesheet/Cargo.toml b/modules/demux/playlist/cuesheet/Cargo.toml<br>
> new file mode 100644<br>
> index 0000000000..3ce20f6480<br>
> --- /dev/null<br>
> +++ b/modules/demux/playlist/cuesheet/Cargo.toml<br>
> @@ -0,0 +1,10 @@<br>
> +[package]<br>
> +name = "cuesheet"<br>
> +version = "0.1.0"<br>
> +authors = ["Kartik Ohri <<a href="mailto:kartikohri13@gmail.com" target="_blank">kartikohri13@gmail.com</a>>"]<br>
> +edition = "2018"<br>
> +<br>
> +[dependencies]<br>
> +<br>
> +[lib]<br>
> +name = "cuesheet"<br>
> \ No newline at end of file<br>
> diff --git a/modules/demux/playlist/cuesheet/cbindgen.toml b/modules/demux/playlist/cuesheet/cbindgen.toml<br>
> new file mode 100644<br>
> index 0000000000..bc8fd14ae8<br>
> --- /dev/null<br>
> +++ b/modules/demux/playlist/cuesheet/cbindgen.toml<br>
> @@ -0,0 +1,16 @@<br>
> +header = "// SPDX-License-Identifier: LGPL-3.0-or-later"<br>
> +sys_includes = ["stddef.h", "stdint.h", "stdlib.h"]<br>
> +no_includes = true<br>
> +include_guard = "CUESHEET_H"<br>
> +tab_width = 4<br>
<br>
Is this file used for text editors or also for building ?<br>
<br></blockquote><div>Yes, the file is required for building. This file is used to generate the C headers for the rust module in this case (cuesheet.h). I'd like to know the opinion on whether to commit the cuesheet.h file or not because it is auto-generated during the build time. If a cuesheet.h file (from a previous build or say from the git repository) already exists, it will be overridden.</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
> +language = "C"<br>
> +documentation_style = "C"<br>
> +style = "type"<br>
> +cpp_compat = true<br>
> +<br>
> +[export]<br>
> +item_types = ["enums", "structs", "unions", "typedefs", "opaque", "functions"]<br>
> +<br>
> +[enum]<br>
> +rename_variants = "ScreamingSnakeCase"<br>
> +prefix_with_name = true<br>
> \ No newline at end of file<br>
> diff --git a/modules/demux/playlist/cuesheet/cuesheet.h b/modules/demux/playlist/cuesheet/cuesheet.h<br>
> new file mode 100644<br>
> index 0000000000..cb7dd970f3<br>
> --- /dev/null<br>
> +++ b/modules/demux/playlist/cuesheet/cuesheet.h<br>
> @@ -0,0 +1,44 @@<br>
> +// SPDX-License-Identifier: LGPL-3.0-or-later<br>
> +<br>
> +#ifndef CUESHEET_H<br>
> +#define CUESHEET_H<br>
> +<br>
> +<br>
> +#define CUESHEET_MAJOR 0<br>
> +#define CUESHEET_MINOR 1<br>
> +#define CUESHEET_PATCH 0<br>
> +<br>
> +<br>
> +#include <stddef.h><br>
> +#include <stdint.h><br>
> +#include <stdlib.h><br>
> +<br>
> +typedef struct CCuesheet CCuesheet;<br>
> +<br>
> +#ifdef __cplusplus<br>
> +extern "C" {<br>
> +#endif // __cplusplus<br>
> +<br>
> +CCuesheet *cuesheet_default(void);<br>
> +<br>
> +const char *cuesheet_get_comment_value(CCuesheet *c_cuesheet, const char *line);<br>
> +<br>
> +const char *cuesheet_get_property(CCuesheet *c_cuesheet, const char *line);<br>
> +<br>
> +const char *cuesheet_get_track_property(CCuesheet *c_cuesheet, int index, const char *line);<br>
> +<br>
> +int cuesheet_get_track_start(CCuesheet *c_cuesheet, int index);<br>
> +<br>
> +int cuesheet_get_tracks_number(CCuesheet *c_cuesheet);<br>
> +<br>
> +void cuesheet_process_line(CCuesheet *c_cuesheet, const char *line);<br>
> +<br>
> +void unref_cuesheet(CCuesheet *cuesheet);<br>
> +<br>
> +void unref_cuesheet_string(char *text);<br>
> +<br>
> +#ifdef __cplusplus<br>
> +} // extern "C"<br>
> +#endif // __cplusplus<br>
> +<br>
> +#endif /* CUESHEET_H */<br>
> diff --git a/modules/demux/playlist/cuesheet/src/<a href="http://capi.rs" rel="noreferrer" target="_blank">capi.rs</a> b/modules/demux/playlist/cuesheet/src/<a href="http://capi.rs" rel="noreferrer" target="_blank">capi.rs</a><br>
> new file mode 100644<br>
> index 0000000000..b5af473fe7<br>
> --- /dev/null<br>
> +++ b/modules/demux/playlist/cuesheet/src/<a href="http://capi.rs" rel="noreferrer" target="_blank">capi.rs</a><br>
> @@ -0,0 +1,115 @@<br>
> +use crate::config::Cuesheet;<br>
> +use crate::parse::process_line;<br>
> +use std::os::raw::{c_char, c_int};<br>
> +use std::ffi::{CStr, CString};<br>
> +use std::convert::TryFrom;<br>
> +<br>
> +pub struct CCuesheet {<br>
> + cuesheet : Cuesheet<br>
> +}<br>
> +<br>
> +#[no_mangle]<br>
> +pub unsafe extern fn cuesheet_default() -> *mut CCuesheet {<br>
> + let cuesheet = Cuesheet::default();<br>
> + let c_cuesheet = Box::new(CCuesheet {cuesheet});<br>
> + Box::into_raw(c_cuesheet)<br>
> +}<br>
> +<br>
> +#[no_mangle]<br>
> +pub unsafe extern fn cuesheet_process_line(c_cuesheet : *mut CCuesheet, line : *const c_char) {<br>
> + let rust_line = CStr::from_ptr(line).to_str().to_owned().unwrap();<br>
> + process_line(&mut (*c_cuesheet).cuesheet, rust_line);<br>
> +}<br>
> +<br>
> +#[no_mangle]<br>
> +pub unsafe extern fn cuesheet_get_property(c_cuesheet : *mut CCuesheet, line : *const c_char)<br>
> + -> *const c_char {<br>
> + let rust_line = match CStr::from_ptr(line).to_str() {<br>
> + Ok(value) => value,<br>
> + Err(_) => return std::ptr::null()<br>
> + };<br>
> +<br>
> + let cuesheet = & (*c_cuesheet).cuesheet;<br>
> +<br>
> + let property_value = cuesheet.get_property(rust_line);<br>
> + if property_value.is_empty() {<br>
> + return std::ptr::null()<br>
> + }<br>
> + convert_string_to_ptr(property_value.to_string())<br>
> +}<br>
> +<br>
> +#[no_mangle]<br>
> +pub unsafe extern fn cuesheet_get_comment_value(c_cuesheet : *mut CCuesheet,<br>
> + line : *const c_char) -> *const c_char {<br>
> + let rust_line = match CStr::from_ptr(line).to_str() {<br>
> + Ok(value) => value,<br>
> + Err(_) => return std::ptr::null()<br>
> + };<br>
> +<br>
> + let cuesheet = & (*c_cuesheet).cuesheet;<br>
> +<br>
> + match cuesheet.comments.get(rust_line) {<br>
> + Some(value) => convert_string_to_ptr(value.to_string()),<br>
> + _ => std::ptr::null()<br>
> + }<br>
> +}<br>
> +<br>
> +#[no_mangle]<br>
> +pub unsafe extern fn cuesheet_get_tracks_number(c_cuesheet : *mut CCuesheet) -> c_int {<br>
> + (*c_cuesheet).cuesheet.tracks.len() as i32<br>
> +}<br>
> +<br>
> +#[no_mangle]<br>
> +pub unsafe extern fn cuesheet_get_track_property(c_cuesheet : *mut CCuesheet, index : c_int,<br>
> + line : *const c_char) -> *const c_char {<br>
> + let rust_line = match CStr::from_ptr(line).to_str() {<br>
> + Ok(value) => value,<br>
> + Err(_) => return std::ptr::null()<br>
> + };<br>
> +<br>
> + let cuesheet = & (*c_cuesheet).cuesheet;<br>
> + let u_index = match usize::try_from(index) {<br>
> + Ok(value) => value,<br>
> + Err(_) => return std::ptr::null()<br>
> + };<br>
> +<br>
> + let track = match cuesheet.get_track_at_index(u_index) {<br>
> + Ok(value) => value,<br>
> + Err(_) => return std::ptr::null()<br>
> + };<br>
> +<br>
> + let val = track.get_property(rust_line);<br>
> + if val.is_empty() {<br>
> + return std::ptr::null();<br>
> + }<br>
> + convert_string_to_ptr(val.to_string())<br>
> +}<br>
> +<br>
> +unsafe fn convert_string_to_ptr(string: String) -> *mut c_char {<br>
> + CString::new(string).unwrap().into_raw()<br>
> +}<br>
> +<br>
> +#[no_mangle]<br>
> +pub unsafe extern fn cuesheet_get_track_start(c_cuesheet: *mut CCuesheet, index : c_int) -> c_int {<br>
> + let cuesheet = &(*c_cuesheet).cuesheet;<br>
> +<br>
> + let u_index = match usize::try_from(index){<br>
> + Ok(value) => value,<br>
> + Err(_e) => return -1<br>
> + };<br>
> +<br>
> + match cuesheet.get_track_at_index(u_index) {<br>
> + Ok(t) => t.begin_time_in_seconds(),<br>
> + Err(_) => return -1<br>
> + }<br>
> +}<br>
> +<br>
> +#[no_mangle]<br>
> +pub unsafe extern fn unref_cuesheet_string(text : *mut c_char) {<br>
> + let _temp = CString::from_raw(text);<br>
> +}<br>
> +<br>
> +#[no_mangle]<br>
> +pub unsafe extern fn unref_cuesheet(cuesheet : *mut CCuesheet) {<br>
> + let _temp = Box::from_raw(cuesheet);<br>
> +}<br>
> diff --git a/modules/demux/playlist/cuesheet/src/<a href="http://config.rs" rel="noreferrer" target="_blank">config.rs</a> b/modules/demux/playlist/cuesheet/src/<a href="http://config.rs" rel="noreferrer" target="_blank">config.rs</a><br>
> new file mode 100644<br>
> index 0000000000..45292a3e3b<br>
> --- /dev/null<br>
> +++ b/modules/demux/playlist/cuesheet/src/<a href="http://config.rs" rel="noreferrer" target="_blank">config.rs</a><br>
> @@ -0,0 +1,108 @@<br>
> +use std::collections::HashMap;<br>
> +use std::borrow::Borrow;<br>
> +<br>
> +#[derive(Clone, Debug)]<br>
> +pub struct CuesheetTrack {<br>
> + pub item_type : String,<br>
> + pub item_position : u8,<br>
> + pub item_performer : String,<br>
> + pub item_title : String,<br>
> + pub item_begin_duration : String<br>
> +}<br>
> +<br>
> +impl Default for CuesheetTrack {<br>
> + fn default() -> Self {<br>
> + CuesheetTrack {<br>
> + item_type: "".to_owned(),<br>
> + item_position: 0,<br>
> + item_performer: "".to_string(),<br>
> + item_title: "".to_string(),<br>
> + item_begin_duration: "".to_string()<br>
> + }<br>
> + }<br>
> +}<br>
> +<br>
> +impl CuesheetTrack {<br>
> + pub fn begin_time_in_seconds(&self) -> i32 {<br>
> + let start: &str = &self.item_begin_duration;<br>
> + let mut duration_parts: Vec<&str> = start.split(":").collect();<br>
> +<br>
> + let frame_rate = 75;<br>
> + let convert_min_to_s = 60;<br>
> + let mut start_time;<br>
> + let mut part;<br>
> +<br>
> + part = match duration_parts.pop() {<br>
> + Some(t) => t.parse::<u32>().unwrap(),<br>
> + None => return -1<br>
> + };<br>
> + start_time = (part / frame_rate) as i32;<br>
> +<br>
> + part = match duration_parts.pop() {<br>
> + Some(t) => t.parse::<u32>().unwrap(),<br>
> + None => return -1<br>
> + };<br>
> + start_time += part as i32;<br>
> +<br>
> + part = match duration_parts.pop() {<br>
> + Some(t) => t.parse::<u32>().unwrap(),<br>
> + None => return -1<br>
> + };<br>
> + start_time += (part * convert_min_to_s) as i32;<br>
> + start_time<br>
> + }<br>
> +<br>
> + pub fn get_property(&self, key : &str) -> &str {<br>
> + match key.to_ascii_lowercase().as_str() {<br>
> + "type" => self.item_type.as_str(),<br>
> + "begin_duration" => self.item_begin_duration.as_str(),<br>
> + "performer" => self.item_performer.as_str(),<br>
> + "title" => self.item_title.as_str(),<br>
> + _ => ""<br>
> + }<br>
> + }<br>
> +}<br>
> +<br>
> +#[derive(Clone, Debug)]<br>
> +pub struct Cuesheet {<br>
> + pub file_name : String,<br>
> + pub file_type : String,<br>
> + pub tracks : Vec<CuesheetTrack>,<br>
> + pub performer : String,<br>
> + pub title : String,<br>
> + pub comments : HashMap<String, String>,<br>
> + pub is_processing_tracks : bool<br>
> +}<br>
> +<br>
> +impl Default for Cuesheet {<br>
> + fn default() -> Self {<br>
> + Cuesheet {<br>
> + file_name: "".to_string(),<br>
> + file_type: "".to_string(),<br>
> + tracks: Vec::new(),<br>
> + performer: "".to_string(),<br>
> + title: "".to_string(),<br>
> + comments: HashMap::new(),<br>
> + is_processing_tracks: false<br>
> + }<br>
> + }<br>
> +}<br>
> +<br>
> +impl Cuesheet {<br>
> + pub fn get_track_at_index(&self, index : usize) -> Result<&CuesheetTrack, &'static str> {<br>
> + if index >= self.tracks.len() {<br>
> + return Err("Index Out of Bounds");<br>
> + }<br>
> + Ok(self.tracks[index].borrow())<br>
> + }<br>
> +<br>
> + pub fn get_property(&self, key : &str) -> &str {<br>
> + match key.to_ascii_lowercase().as_str() {<br>
> + "file_name" => self.file_name.as_str(),<br>
> + "file_type" => self.file_type.as_str(),<br>
> + "performer" => self.performer.as_str(),<br>
> + "title" => self.title.as_str(),<br>
> + _ => ""<br>
> + }<br>
> + }<br>
> +}<br>
> \ No newline at end of file<br>
> diff --git a/modules/demux/playlist/cuesheet/src/<a href="http://lib.rs" rel="noreferrer" target="_blank">lib.rs</a> b/modules/demux/playlist/cuesheet/src/<a href="http://lib.rs" rel="noreferrer" target="_blank">lib.rs</a><br>
> new file mode 100644<br>
> index 0000000000..c768d23825<br>
> --- /dev/null<br>
> +++ b/modules/demux/playlist/cuesheet/src/<a href="http://lib.rs" rel="noreferrer" target="_blank">lib.rs</a><br>
> @@ -0,0 +1,18 @@<br>
> +mod parse;<br>
> +mod config;<br>
> +<br>
> +#[cfg(test)]<br>
> +mod tests {<br>
> + use crate::parse::parse_line_alt;<br>
> + #[test]<br>
> + fn test_parse_line_alt() {<br>
> + let parts = parse_line_alt("FILE \"Live in Berlin\" MP3");<br>
> + assert_eq!(3, parts.len());<br>
> + assert_eq!("FILE", parts[0]);<br>
> + assert_eq!("Live in Berlin", parts[1]);<br>
> + assert_eq!("MP3", parts[2]);<br>
> + }<br>
> +}<br>
> +<br>
> +#[cfg(cargo_c)]<br>
> +mod capi;<br>
> \ No newline at end of file<br>
> diff --git a/modules/demux/playlist/cuesheet/src/<a href="http://parse.rs" rel="noreferrer" target="_blank">parse.rs</a> b/modules/demux/playlist/cuesheet/src/<a href="http://parse.rs" rel="noreferrer" target="_blank">parse.rs</a><br>
> new file mode 100644<br>
> index 0000000000..c1e6e35a2a<br>
> --- /dev/null<br>
> +++ b/modules/demux/playlist/cuesheet/src/<a href="http://parse.rs" rel="noreferrer" target="_blank">parse.rs</a><br>
> @@ -0,0 +1,69 @@<br>
> +use crate::config::*;<br>
> +<br>
> +pub(crate) fn parse_line_alt(line: &str) -> Vec<String> {<br>
> + let characters = line.trim().chars();<br>
> + let mut parts: Vec<String> = Vec::new();<br>
> + let mut inside_quotes: bool = false;<br>
> + let mut temp_str: String = String::new();<br>
> + for char in characters {<br>
> + if char == '"' {<br>
> + inside_quotes = !inside_quotes;<br>
> + } else if inside_quotes {<br>
> + temp_str.push(char);<br>
> + } else if char.is_whitespace() {<br>
> + parts.push(temp_str.clone());<br>
> + temp_str.clear();<br>
> + } else {<br>
> + temp_str.push(char);<br>
> + }<br>
> + }<br>
> + parts.push(temp_str.clone());<br>
> + parts<br>
> +}<br>
> +<br>
> +pub fn process_line(cuesheet: &mut Cuesheet, line : &str) {<br>
> + let parts = parse_line_alt(line);<br>
> + let keyword = parts[0].as_str();<br>
> + if !cuesheet.is_processing_tracks {<br>
> + match keyword {<br>
> + "FILE" => {<br>
> + cuesheet.file_name = parts[1].to_owned();<br>
> + cuesheet.file_type = parts[2].to_owned();<br>
> + },<br>
> + "TITLE" => cuesheet.title = parts[1].to_owned(),<br>
> + "PERFORMER" => cuesheet.performer = parts[1].to_owned(),<br>
> + "REM" => {<br>
> + cuesheet.comments.insert(<br>
> + parts[1].to_owned().to_lowercase(), parts[2].to_owned());<br>
> + },<br>
> + "TRACK" => cuesheet.is_processing_tracks = true,<br>
> + _ => {}<br>
> + };<br>
> + }<br>
> + if cuesheet.is_processing_tracks {<br>
> + if keyword == "TRACK" {<br>
> + let mut track = CuesheetTrack::default();<br>
> + track.item_position = parts[1].to_owned().parse::<u8>().unwrap();<br>
> + track.item_type = parts[2].to_owned();<br>
> + cuesheet.tracks.push(track);<br>
> + } else {<br>
> + process_track(cuesheet.tracks.last_mut().unwrap(), line);<br>
> + }<br>
> + }<br>
> +}<br>
> +<br>
> +fn process_track(track: &mut CuesheetTrack, line : &str) {<br>
> + let parts = parse_line_alt(line);<br>
> + let keyword = parts[0].as_str();<br>
> + match keyword {<br>
> + "TITLE" => track.item_title = parts[1].to_owned(),<br>
> + "PERFORMER" => track.item_performer = parts[1].to_owned(),<br>
> + "INDEX" => {<br>
> + let index_position = parts[1].to_owned().parse::<u8>().unwrap();<br>
> + if index_position == 1 {<br>
> + track.item_begin_duration = parts[2].to_owned();<br>
> + }<br>
> + },<br>
> + _ => {}<br>
> + };<br>
> +}<br>
> \ No newline at end of file<br>
> diff --git a/modules/demux/playlist/playlist.c b/modules/demux/playlist/playlist.c<br>
> index d3cca7a502..d5142b7930 100644<br>
> --- a/modules/demux/playlist/playlist.c<br>
> +++ b/modules/demux/playlist/playlist.c<br>
> @@ -130,6 +130,10 @@ vlc_module_begin ()<br>
> add_shortcut( "wpl" )<br>
> set_capability( "stream_filter", 310 )<br>
> set_callbacks( Import_WPL, Close_WPL )<br>
> + add_submodule ()<br>
> + set_description ( N_("Cue Sheet importer") )<br>
> + set_capability ( "stream_filter", 320 )<br>
> + set_callback ( Import_Cue_Sheet )<br>
<br>
I suppose this module requires some (large) Rust runtime to be linked <br>
with it. I think it would be better in a separate module to avoid this <br>
dependency on the regular module.<br>
<br></blockquote><div>I understand the rationale but I did not completely understand what should be done. </div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
> vlc_module_end ()<br>
> <br>
> /**<br>
> diff --git a/modules/demux/playlist/playlist.h b/modules/demux/playlist/playlist.h<br>
> index 10a9135bbf..6daf77aebb 100644<br>
> --- a/modules/demux/playlist/playlist.h<br>
> +++ b/modules/demux/playlist/playlist.h<br>
> @@ -61,6 +61,8 @@ int Import_WMS(vlc_object_t *);<br>
> int Import_WPL ( vlc_object_t * );<br>
> void Close_WPL ( vlc_object_t * );<br>
> <br>
> +int Import_Cue_Sheet ( vlc_object_t * );<br>
> +<br>
> #define GetCurrentItem(obj) ((obj)->p_input_item)<br>
> #define GetSource(obj) ((obj)->s)<br>
> <br>
> --<br>
> 2.25.1<br>
> <br>
> _______________________________________________<br>
> vlc-devel mailing list<br>
> To unsubscribe or modify your subscription options:<br>
> <a href="https://mailman.videolan.org/listinfo/vlc-devel" rel="noreferrer" target="_blank">https://mailman.videolan.org/listinfo/vlc-devel</a><br>
> <br>
_______________________________________________<br>
vlc-devel mailing list<br>
To unsubscribe or modify your subscription options:<br>
<a href="https://mailman.videolan.org/listinfo/vlc-devel" rel="noreferrer" target="_blank">https://mailman.videolan.org/listinfo/vlc-devel</a></blockquote></div></div>