nss: upgrade to release 3.73
[LibreOffice.git] / avmedia / source / vlc / wrapper / Media.cxx
blobf09aecd766fd3401ca61f19d1761b3973fe4dd3c
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 */
10 #include <rtl/ustring.h>
11 #include <wrapper/Media.hxx>
12 #include "SymbolLoader.hxx"
13 #include <wrapper/Instance.hxx>
14 #include "Types.hxx"
15 #include <wrapper/Common.hxx>
16 #include <sal/log.hxx>
18 struct libvlc_instance_t;
20 namespace avmedia::vlc::wrapper
22 namespace
24 libvlc_media_t* ( *libvlc_media_new_path ) ( libvlc_instance_t *p_instance, const char *path );
25 libvlc_media_t* ( *libvlc_media_new_location ) (libvlc_instance_t *p_instance, const char *psz_mrl);
26 void ( *libvlc_media_release ) ( libvlc_media_t *p_md );
27 void ( *libvlc_media_retain ) ( libvlc_media_t *p_md );
28 libvlc_time_t ( *libvlc_media_get_duration ) ( libvlc_media_t *p_md );
29 void ( *libvlc_media_parse ) ( libvlc_media_t *p_md );
30 int ( *libvlc_media_is_parsed ) ( libvlc_media_t *p_md );
31 char* ( *libvlc_media_get_mrl )(libvlc_media_t *p_md);
34 libvlc_media_t* InitMedia( const OUString& url, Instance& instance )
36 OString dest;
37 url.convertToString(&dest, RTL_TEXTENCODING_UTF8, 0);
39 return libvlc_media_new_location(instance, dest.getStr());
43 bool Media::LoadSymbols()
45 static ApiMap const VLC_MEDIA_API[] =
47 SYM_MAP( libvlc_media_new_path ),
48 SYM_MAP( libvlc_media_release ),
49 SYM_MAP( libvlc_media_retain ),
50 SYM_MAP( libvlc_media_get_duration ),
51 SYM_MAP( libvlc_media_parse ),
52 SYM_MAP( libvlc_media_is_parsed ),
53 SYM_MAP( libvlc_media_get_mrl ),
54 SYM_MAP( libvlc_media_new_location )
57 return InitApiMap( VLC_MEDIA_API );
60 Media::Media( const OUString& url, Instance& instance )
61 : mMedia( InitMedia( url, instance ) )
63 if (mMedia == nullptr)
65 // TODO: Error
69 Media::Media( const Media& other )
71 operator=( other );
74 Media& Media::operator=( const Media& other )
76 libvlc_media_release( mMedia );
77 mMedia = other.mMedia;
79 libvlc_media_retain( mMedia );
80 return *this;
83 int Media::getDuration() const
85 if ( !libvlc_media_is_parsed( mMedia ) )
86 libvlc_media_parse( mMedia );
88 const int duration = libvlc_media_get_duration( mMedia );
89 if (duration == -1)
91 SAL_WARN("avmedia", Common::LastErrorMessage());
92 return 0;
94 else if (duration == 0)
96 // A duration must be greater than 0
97 return 1;
100 return duration;
103 Media::~Media()
105 libvlc_media_release( mMedia );
109 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */