summaryrefslogtreecommitdiffstats
path: root/avmedia/source/vlc/wrapper/Media.cxx
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-27 16:51:28 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-27 16:51:28 +0000
commit940b4d1848e8c70ab7642901a68594e8016caffc (patch)
treeeb72f344ee6c3d9b80a7ecc079ea79e9fba8676d /avmedia/source/vlc/wrapper/Media.cxx
parentInitial commit. (diff)
downloadlibreoffice-940b4d1848e8c70ab7642901a68594e8016caffc.tar.xz
libreoffice-940b4d1848e8c70ab7642901a68594e8016caffc.zip
Adding upstream version 1:7.0.4.upstream/1%7.0.4upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'avmedia/source/vlc/wrapper/Media.cxx')
-rw-r--r--avmedia/source/vlc/wrapper/Media.cxx109
1 files changed, 109 insertions, 0 deletions
diff --git a/avmedia/source/vlc/wrapper/Media.cxx b/avmedia/source/vlc/wrapper/Media.cxx
new file mode 100644
index 000000000..f09aecd76
--- /dev/null
+++ b/avmedia/source/vlc/wrapper/Media.cxx
@@ -0,0 +1,109 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include <rtl/ustring.h>
+#include <wrapper/Media.hxx>
+#include "SymbolLoader.hxx"
+#include <wrapper/Instance.hxx>
+#include "Types.hxx"
+#include <wrapper/Common.hxx>
+#include <sal/log.hxx>
+
+struct libvlc_instance_t;
+
+namespace avmedia::vlc::wrapper
+{
+namespace
+{
+ libvlc_media_t* ( *libvlc_media_new_path ) ( libvlc_instance_t *p_instance, const char *path );
+ libvlc_media_t* ( *libvlc_media_new_location ) (libvlc_instance_t *p_instance, const char *psz_mrl);
+ void ( *libvlc_media_release ) ( libvlc_media_t *p_md );
+ void ( *libvlc_media_retain ) ( libvlc_media_t *p_md );
+ libvlc_time_t ( *libvlc_media_get_duration ) ( libvlc_media_t *p_md );
+ void ( *libvlc_media_parse ) ( libvlc_media_t *p_md );
+ int ( *libvlc_media_is_parsed ) ( libvlc_media_t *p_md );
+ char* ( *libvlc_media_get_mrl )(libvlc_media_t *p_md);
+
+
+ libvlc_media_t* InitMedia( const OUString& url, Instance& instance )
+ {
+ OString dest;
+ url.convertToString(&dest, RTL_TEXTENCODING_UTF8, 0);
+
+ return libvlc_media_new_location(instance, dest.getStr());
+ }
+}
+
+bool Media::LoadSymbols()
+{
+ static ApiMap const VLC_MEDIA_API[] =
+ {
+ SYM_MAP( libvlc_media_new_path ),
+ SYM_MAP( libvlc_media_release ),
+ SYM_MAP( libvlc_media_retain ),
+ SYM_MAP( libvlc_media_get_duration ),
+ SYM_MAP( libvlc_media_parse ),
+ SYM_MAP( libvlc_media_is_parsed ),
+ SYM_MAP( libvlc_media_get_mrl ),
+ SYM_MAP( libvlc_media_new_location )
+ };
+
+ return InitApiMap( VLC_MEDIA_API );
+}
+
+Media::Media( const OUString& url, Instance& instance )
+ : mMedia( InitMedia( url, instance ) )
+{
+ if (mMedia == nullptr)
+ {
+ // TODO: Error
+ }
+}
+
+Media::Media( const Media& other )
+{
+ operator=( other );
+}
+
+Media& Media::operator=( const Media& other )
+{
+ libvlc_media_release( mMedia );
+ mMedia = other.mMedia;
+
+ libvlc_media_retain( mMedia );
+ return *this;
+}
+
+int Media::getDuration() const
+{
+ if ( !libvlc_media_is_parsed( mMedia ) )
+ libvlc_media_parse( mMedia );
+
+ const int duration = libvlc_media_get_duration( mMedia );
+ if (duration == -1)
+ {
+ SAL_WARN("avmedia", Common::LastErrorMessage());
+ return 0;
+ }
+ else if (duration == 0)
+ {
+ // A duration must be greater than 0
+ return 1;
+ }
+
+ return duration;
+}
+
+Media::~Media()
+{
+ libvlc_media_release( mMedia );
+}
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */