<div dir="ltr"><div dir="ltr">On Mon, Sep 14, 2020 at 4:27 PM Thomas Guillem <<a href="mailto:thomas@gllm.fr">thomas@gllm.fr</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"><br>
<br>
On Fri, Sep 11, 2020, at 21:33, Kartik Ohri wrote:<br>
> The module is written using Rust API and serves as<br>
> a proof of concept for the same.<br>
> ---<br>
> modules/demux/Makefile.am | 26 +++<br>
> modules/demux/playlist/cuesheet.c | 192 ++++++++++++++++++<br>
> modules/demux/playlist/cuesheet/Cargo.toml | 13 ++<br>
> modules/demux/playlist/cuesheet/cbindgen.toml | 16 ++<br>
> modules/demux/playlist/cuesheet/src/<a href="http://capi.rs" rel="noreferrer" target="_blank">capi.rs</a> | 122 +++++++++++<br>
> modules/demux/playlist/cuesheet/src/<a href="http://config.rs" rel="noreferrer" target="_blank">config.rs</a> | 106 ++++++++++<br>
> modules/demux/playlist/cuesheet/src/<a href="http://lib.rs" rel="noreferrer" target="_blank">lib.rs</a> | 5 +<br>
> modules/demux/playlist/cuesheet/src/<a href="http://parse.rs" rel="noreferrer" target="_blank">parse.rs</a> | 75 +++++++<br>
> 8 files changed, 555 insertions(+)<br>
> create mode 100644 modules/demux/playlist/cuesheet.c<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/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/modules/demux/Makefile.am b/modules/demux/Makefile.am<br>
> index 675b2d10af..31591a768b 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>
> @@ -256,6 +257,31 @@ libplaylist_plugin_la_SOURCES = \<br>
> demux/playlist/playlist.c demux/playlist/playlist.h<br>
> demux_LTLIBRARIES += <a href="http://libplaylist_plugin.la" rel="noreferrer" target="_blank">libplaylist_plugin.la</a><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 <br>
> -lutil<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/cuesheet.h: <br>
> $(libcuesheet_rust_plugin_la_SOURCES)<br>
> + mkdir -p demux/playlist/cuesheet && cd demux/playlist/cuesheet && \<br>
> + $(CARGO_C) --library-type=staticlib --destdir=. --includedir=.. <br>
> --libdir=. \<br>
> + --manifest-path=$(abs_src_dir)/demux/playlist/cuesheet/Cargo.toml<br>
> +<br>
> +BUILT_SOURCES += <br>
> @abs_top_builddir@/modules/demux/playlist/cuesheet/cuesheet.h<br>
> +CUESHEET_LIBS = <br>
> @abs_top_builddir@/modules/demux/playlist/cuesheet/libcuesheet.a<br>
> +CUESHEET_LIBS += $(RUST_RUNTIME_LIBS)<br>
> +libcuesheet_plugin_la_SOURCES = demux/playlist/cuesheet.c <br>
> @abs_top_builddir@/modules/demux/playlist/cuesheet/cuesheet.h<br>
> +libcuesheet_plugin_la_LIBADD = $(CUESHEET_LIBS)<br>
> +<br>
> +demux_LTLIBRARIES += <a href="http://libcuesheet_plugin.la" rel="noreferrer" target="_blank">libcuesheet_plugin.la</a><br>
> +endif<br>
> +<br>
> libts_plugin_la_SOURCES = demux/mpeg/ts.c demux/mpeg/ts.h \<br>
> demux/mpeg/ts_pid.h demux/mpeg/ts_pid_fwd.h <br>
> demux/mpeg/ts_pid.c \<br>
> demux/mpeg/ts_psi.h demux/mpeg/ts_psi.c \<br>
> diff --git a/modules/demux/playlist/cuesheet.c <br>
> b/modules/demux/playlist/cuesheet.c<br>
> new file mode 100644<br>
> index 0000000000..9634396b88<br>
> --- /dev/null<br>
> +++ b/modules/demux/playlist/cuesheet.c<br>
> @@ -0,0 +1,192 @@<br>
> +/*****************************************************************************<br>
> + * cuesheet.c : cue sheet playlist import format<br>
> + <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 <br>
> modify it<br>
> + * under the terms of the GNU Lesser General Public License as <br>
> 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 <br>
> License<br>
> + * along with this program; if not, write to the Free Software <br>
> Foundation,<br>
> + * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.<br>
> + <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_plugin.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>
> +int Import_Cue_Sheet(vlc_object_t *);<br>
> +static int ReadDir(stream_t *, input_item_node_t *);<br>
> +static char* rust_string_to_c_string(char*);<br>
> +static char* get_cuesheet_property(CCuesheet *, const char*);<br>
> +static char* get_cuesheet_comment(CCuesheet *, const char*);<br>
> +static char* get_track_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>
> + 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. <br>
> There is no<br>
> + * way to ensure this without duplicating the string before passing it <br>
> to<br>
> + * input_item_t.<br>
> + */<br>
> +static char* rust_string_to_c_string(char *psz_rust) {<br>
> + if (!psz_rust)<br>
> + return NULL;<br>
> + char *psz_c = strdup(psz_rust);<br>
> + unref_cuesheet_string(psz_rust);<br>
> + return psz_c;<br>
> +}<br>
> +<br>
> +static char* get_cuesheet_property(CCuesheet *cuesheet, const char* <br>
> psz_property) {<br>
> + char* psz_val = cuesheet_get_property(cuesheet, psz_property);<br>
> + return rust_string_to_c_string(psz_val);<br>
> +}<br>
> +<br>
> +static char* get_cuesheet_comment(CCuesheet *cuesheet, const char* <br>
> psz_property) {<br>
> + char* psz_val = cuesheet_get_comment_value(cuesheet, psz_property);<br>
> + return rust_string_to_c_string(psz_val);<br>
> +}<br>
> +<br>
> +static char* get_track_property(CCuesheet *cuesheet, const char* <br>
> psz_property, int track_num) {<br>
> + char* psz_val = cuesheet_get_track_property(cuesheet, track_num, <br>
> psz_property);<br>
> + return rust_string_to_c_string(psz_val);<br>
> +}<br>
> +<br>
> +static int ReadDir(stream_t* p_demux, input_item_node_t* p_subitems)<br>
> +{<br>
> + int i_ret = VLC_EGENERIC;<br>
> + CCuesheet *cuesheet = cuesheet_from_demux(p_demux->s);<br>
> + if(!cuesheet)<br>
> + return i_ret;<br>
> +<br>
> + int tracks = cuesheet_get_tracks_number(cuesheet);<br>
> + int idx = 0;<br>
> + char *psz_val = NULL;<br>
> + char *ppsz_option[2];<br>
> +<br>
> + char *psz_album = get_cuesheet_property(cuesheet, "TITLE");<br>
> + char *psz_album_artist = get_cuesheet_property(cuesheet, <br>
> "PERFORMER");<br>
> + char *psz_description = get_cuesheet_comment(cuesheet, "COMMENT");<br>
> + char *psz_genre = get_cuesheet_comment(cuesheet, "GENRE");<br>
> + char *psz_date = get_cuesheet_comment(cuesheet, "DATE");<br>
> +<br>
> + char *psz_audio_file = get_cuesheet_property(cuesheet, <br>
> "FILE_NAME");<br>
> + if (!psz_audio_file)<br>
> + goto end;<br>
> +<br>
> + char *psz_audio_file_uri = vlc_uri_encode(psz_audio_file);<br>
> + char *psz_url = vlc_uri_resolve(p_demux->psz_url, <br>
> 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>
> + psz_val = get_track_property(cuesheet, "TITLE", idx);<br>
> + if (psz_val)<br>
> + {<br>
> + p_item = input_item_New(psz_url, psz_val);<br>
> + p_item->i_type = ITEM_TYPE_FILE;<br>
> + free(psz_val);<br>
> + }<br>
> + else<br>
> + goto end;<br>
> +<br>
> + if (psz_album)<br>
> + input_item_SetAlbum(p_item, psz_album);<br>
> +<br>
> + if (psz_album_artist)<br>
> + input_item_SetAlbumArtist(p_item, psz_album_artist);<br>
> +<br>
> + if (psz_description)<br>
> + input_item_SetDescription(p_item, psz_description);<br>
> +<br>
> + if (psz_date)<br>
> + input_item_SetDate(p_item, psz_date);<br>
> +<br>
> + if (psz_genre)<br>
> + input_item_SetGenre(p_item, psz_genre);<br>
> +<br>
> + psz_val = get_track_property(cuesheet, "PERFORMER", idx);<br>
> + if (psz_val)<br>
> + {<br>
> + input_item_SetArtist(p_item, psz_val);<br>
> + free(psz_val);<br>
> + }<br>
> +<br>
> + int i_time = cuesheet_get_track_start(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(cuesheet, idx + 1);<br>
> + if (asprintf(ppsz_option + i_options, ":stop-time=%d", <br>
> i_time))<br>
> + i_options++;<br>
> + }<br>
> +<br>
> + input_item_AddOptions(p_item, i_options, (const char <br>
> **)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>
> + <br>
> + i_ret = VLC_SUCCESS;<br>
> + <br>
> + end:<br>
> + free(psz_album);<br>
> + free(psz_album_artist);<br>
> + free(psz_description);<br>
> + free(psz_genre);<br>
> + free(psz_date);<br>
> + unref_cuesheet(cuesheet);<br>
> + return i_ret;<br>
> +}<br>
> +<br>
> +vlc_module_begin()<br>
> + add_shortcut( "playlist" )<br>
> + set_category( CAT_INPUT )<br>
> + set_subcategory( SUBCAT_INPUT_DEMUX )<br>
> + set_description ( N_("Cue Sheet importer") )<br>
> + set_capability ( "stream_filter", 320 )<br>
> + set_callback ( Import_Cue_Sheet )<br>
> +vlc_module_end()<br>
> +<br>
> +<br>
> diff --git a/modules/demux/playlist/cuesheet/Cargo.toml <br>
> b/modules/demux/playlist/cuesheet/Cargo.toml<br>
> new file mode 100644<br>
> index 0000000000..597076aa13<br>
> --- /dev/null<br>
> +++ b/modules/demux/playlist/cuesheet/Cargo.toml<br>
> @@ -0,0 +1,13 @@<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>
> +license = "LGPL-2.1-or-later"<br>
> +<br>
> +[dependencies]<br>
> +vlccore-rs = {path = "../../../../src/vlccore-rs"}<br>
> +vlccore-sys = {path = "../../../../src/vlccore-sys"}<br>
> +<br>
> +[lib]<br>
> +name = "cuesheet"<br>
> \ No newline at end of file<br>
> diff --git a/modules/demux/playlist/cuesheet/cbindgen.toml <br>
> 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>
<br>
Why this license? I don't think such license is acceptable in VLC (impossible to use on iOS for example).<br>
<br></blockquote><div>That was a mistake on my part. I had only seen that other modules use LGPL but forgot to check which version. I checked the version and see that libVLC uses LGPL-2.1. Is changing to that fine or some other license should be used ?</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">
> +sys_includes = ["stddef.h", "stdint.h", "stdlib.h"]<br>
> +no_includes = true<br>
> +include_guard = "CUESHEET_H"<br>
> +tab_width = 4<br>
> +language = "C"<br>
> +documentation_style = "C"<br>
> +style = "type"<br>
> +cpp_compat = true<br>
> +<br>
> +[export]<br>
> +item_types = ["enums", "structs", "unions", "typedefs", "opaque", <br>
> "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/src/<a href="http://capi.rs" rel="noreferrer" target="_blank">capi.rs</a> <br>
> 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..cd8daac2ba<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,122 @@<br>
> +use crate::config::Cuesheet;<br>
> +use std::convert::TryFrom;<br>
> +use std::ffi::{CStr, CString};<br>
> +use std::io::{BufRead, BufReader};<br>
> +use std::mem::ManuallyDrop;<br>
> +use std::os::raw::{c_char, c_int};<br>
> +use std::ptr::null_mut;<br>
> +<br>
> +use vlccore_rs::stream;<br>
> +use vlccore_sys::stream::stream_t;<br>
> +<br>
> +pub struct CCuesheet {<br>
> + cuesheet: Cuesheet,<br>
> +}<br>
> +<br>
> +#[no_mangle]<br>
> +pub extern "C" fn cuesheet_from_demux(s: *mut stream_t) -> *mut <br>
> CCuesheet {<br>
> + let mut stream = s.into();<br>
> + let ptr = rust_cuesheet_from_demux(&mut stream)<br>
> + .map(|cuesheet| Box::new(CCuesheet { cuesheet }))<br>
> + .map(|c_cuesheet| Box::into_raw(c_cuesheet))<br>
> + .unwrap_or(null_mut());<br>
> + let _ = ManuallyDrop::new(stream);<br>
> + ptr<br>
> +}<br>
> +<br>
> +fn rust_cuesheet_from_demux(stream: &mut stream::Stream) -> <br>
> Option<Cuesheet> {<br>
> + let mut cuesheet = Cuesheet::default();<br>
> + let reader = BufReader::new(stream);<br>
> + for line in reader.lines() {<br>
> + match line {<br>
> + Ok(l) => cuesheet.process_line(l.as_str())?,<br>
> + Err(_) => return None,<br>
> + }<br>
> + }<br>
> + Some(cuesheet)<br>
> +}<br>
> +<br>
> +#[no_mangle]<br>
> +pub unsafe extern "C" fn cuesheet_get_property(<br>
> + c_cuesheet: *mut CCuesheet,<br>
> + line: *const c_char,<br>
> +) -> *mut c_char {<br>
> + let cuesheet = &(*c_cuesheet).cuesheet;<br>
> +<br>
> + CStr::from_ptr(line)<br>
> + .to_str()<br>
> + .ok()<br>
> + .and_then(|line| cuesheet.get_property(line))<br>
> + .map(|property| convert_string_to_ptr(property.to_string()))<br>
> + .unwrap_or(null_mut())<br>
> +}<br>
> +<br>
> +#[no_mangle]<br>
> +pub unsafe extern "C" fn cuesheet_get_comment_value(<br>
> + c_cuesheet: *mut CCuesheet,<br>
> + line: *const c_char,<br>
> +) -> *mut c_char {<br>
> + let cuesheet = &(*c_cuesheet).cuesheet;<br>
> +<br>
> + CStr::from_ptr(line)<br>
> + .to_str()<br>
> + .ok()<br>
> + .and_then(|line| cuesheet.comments.get(line))<br>
> + .map(|comment| convert_string_to_ptr(comment.to_string()))<br>
> + .unwrap_or(null_mut())<br>
> +}<br>
> +<br>
> +#[no_mangle]<br>
> +pub unsafe extern "C" fn cuesheet_get_tracks_number(c_cuesheet: *mut <br>
> CCuesheet) -> c_int {<br>
> + (*c_cuesheet).cuesheet.tracks.len() as i32<br>
> +}<br>
> +<br>
> +#[no_mangle]<br>
> +pub unsafe extern "C" fn cuesheet_get_track_property(<br>
> + c_cuesheet: *mut CCuesheet,<br>
> + index: c_int,<br>
> + line: *const c_char,<br>
> +) -> *mut c_char {<br>
> + let cuesheet = &(*c_cuesheet).cuesheet;<br>
> +<br>
> + usize::try_from(index)<br>
> + .ok()<br>
> + .and_then(|index| cuesheet.get_track_at_index(index))<br>
> + .zip(CStr::from_ptr(line).to_str().ok())<br>
> + .and_then(|(track, property)| track.get_property(property))<br>
> + .map(|value| convert_string_to_ptr(value.to_string()))<br>
> + .unwrap_or(null_mut())<br>
> +}<br>
> +<br>
> +#[no_mangle]<br>
> +pub unsafe extern "C" fn cuesheet_get_track_start(<br>
> + c_cuesheet: *mut CCuesheet,<br>
> + index: c_int,<br>
> +) -> c_int {<br>
> + let cuesheet = &(*c_cuesheet).cuesheet;<br>
> +<br>
> + usize::try_from(index)<br>
> + .ok()<br>
> + .and_then(|index| cuesheet.get_track_at_index(index))<br>
> + .map(|track| track.begin_time_in_seconds())<br>
> + .unwrap_or(-1)<br>
> +}<br>
> +<br>
> +unsafe fn convert_string_to_ptr(string: String) -> *mut c_char {<br>
> + if string.is_empty() {<br>
> + return std::ptr::null_mut();<br>
> + }<br>
> + CString::new(string)<br>
> + .map(|ptr| ptr.into_raw())<br>
> + .unwrap_or(null_mut())<br>
> +}<br>
> +<br>
> +#[no_mangle]<br>
> +pub unsafe extern "C" fn unref_cuesheet_string(text: *mut c_char) {<br>
> + let _ = CString::from_raw(text);<br>
> +}<br>
> +<br>
> +#[no_mangle]<br>
> +pub unsafe extern "C" fn unref_cuesheet(cuesheet: *mut CCuesheet) {<br>
> + let _ = 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> <br>
> 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..24ebbbc7a4<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,106 @@<br>
> +use std::borrow::Borrow;<br>
> +use std::collections::HashMap;<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>
> +fn add_to_start_time(<br>
> + start_time: i32,<br>
> + time_to_add: Option<&str>,<br>
> + conversion_factor: i32,<br>
> +) -> Option<i32> {<br>
> + let val = time_to_add?.parse::<u32>().ok()?;<br>
> + Some(start_time + val as i32 * conversion_factor)<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>
> +<br>
> + duration_parts<br>
> + .pop()<br>
> + .and_then(|part| part.parse::<u32>().ok())<br>
> + .map(|part| part / frame_rate)<br>
> + .and_then(|start| add_to_start_time(start as i32, <br>
> duration_parts.pop(), 1))<br>
> + .and_then(|start| {<br>
> + add_to_start_time(start as i32, duration_parts.pop(), <br>
> convert_min_to_s)<br>
> + })<br>
> + .unwrap_or(-1)<br>
> + }<br>
> +<br>
> + pub fn get_property(&self, key: &str) -> Option<&str> {<br>
> + match key.to_ascii_lowercase().as_str() {<br>
> + "type" => Some(self.item_type.as_str()),<br>
> + "begin_duration" => <br>
> Some(self.item_begin_duration.as_str()),<br>
> + "performer" => Some(self.item_performer.as_str()),<br>
> + "title" => Some(self.item_title.as_str()),<br>
> + _ => None,<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) -> <br>
> Option<&CuesheetTrack> {<br>
> + if index >= self.tracks.len() {<br>
> + return None;<br>
> + }<br>
> + Some(self.tracks[index].borrow())<br>
> + }<br>
> +<br>
> + pub fn get_property(&self, key: &str) -> Option<&str> {<br>
> + match key.to_ascii_lowercase().as_str() {<br>
> + "file_name" => Some(self.file_name.as_str()),<br>
> + "file_type" => Some(self.file_type.as_str()),<br>
> + "performer" => Some(self.performer.as_str()),<br>
> + "title" => Some(self.title.as_str()),<br>
> + _ => None,<br>
> + }<br>
> + }<br>
> +}<br>
> diff --git a/modules/demux/playlist/cuesheet/src/<a href="http://lib.rs" rel="noreferrer" target="_blank">lib.rs</a> <br>
> 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..c43541e34f<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,5 @@<br>
> +mod config;<br>
> +mod parse;<br>
> +<br>
> +#[cfg(cargo_c)]<br>
> +mod capi;<br>
> diff --git a/modules/demux/playlist/cuesheet/src/<a href="http://parse.rs" rel="noreferrer" target="_blank">parse.rs</a> <br>
> 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..b570638325<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,75 @@<br>
> +use crate::config::*;<br>
> +<br>
> +pub fn parse_line(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>
> +impl Cuesheet {<br>
> + pub fn process_line(&mut self, line: &str) -> Option<()> {<br>
> + let parts = parse_line(line);<br>
> + let keyword = parts[0].as_str();<br>
> + if !self.is_processing_tracks {<br>
> + match keyword {<br>
> + "FILE" => {<br>
> + self.file_name = parts[1].to_owned();<br>
> + self.file_type = parts[2].to_owned();<br>
> + }<br>
> + "TITLE" => self.title = parts[1].to_owned(),<br>
> + "PERFORMER" => self.performer = parts[1].to_owned(),<br>
> + "REM" => {<br>
> + self.comments<br>
> + .insert(parts[1].to_owned().to_lowercase(), <br>
> parts[2].to_owned());<br>
> + }<br>
> + "TRACK" => self.is_processing_tracks = true,<br>
> + _ => {}<br>
> + };<br>
> + }<br>
> + if self.is_processing_tracks {<br>
> + if keyword == "TRACK" {<br>
> + let mut track = CuesheetTrack::default();<br>
> + track.item_position = <br>
> parts[1].to_owned().parse::<u8>().ok()?;<br>
> + track.item_type = parts[2].to_owned();<br>
> + self.tracks.push(track);<br>
> + } else {<br>
> + self.tracks.last_mut()?.process_track(line);<br>
> + }<br>
> + }<br>
> + Some(())<br>
> + }<br>
> +}<br>
> +<br>
> +impl CuesheetTrack {<br>
> + fn process_track(&mut self, line: &str) -> Option<()> {<br>
> + let parts = parse_line(line);<br>
> + let keyword = parts[0].as_str();<br>
> + match keyword {<br>
> + "TITLE" => self.item_title = parts[1].to_owned(),<br>
> + "PERFORMER" => self.item_performer = parts[1].to_owned(),<br>
> + "INDEX" => {<br>
> + let index_position = <br>
> parts[1].to_owned().parse::<u8>().ok()?;<br>
> + if index_position == 1 {<br>
> + self.item_begin_duration = parts[2].to_owned();<br>
> + }<br>
> + }<br>
> + _ => {}<br>
> + };<br>
> + Some(())<br>
> + }<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>
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>