GPU-Calc: remove Alloc_Host_Ptr for clmem of NAN vector
[LibreOffice.git] / avmedia / source / vlc / wrapper / Media.cxx
blob0ab140f89da757bb25ca8b1d42df1da6689db30d
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 "Media.hxx"
12 #include "SymbolLoader.hxx"
13 #include "Instance.hxx"
14 #include "Types.hxx"
15 #include "Common.hxx"
17 struct libvlc_instance_t;
19 namespace avmedia
21 namespace vlc
23 namespace wrapper
25 namespace
27 libvlc_media_t* ( *libvlc_media_new_path ) ( libvlc_instance_t *p_instance, const char *path );
28 libvlc_media_t* ( *libvlc_media_new_location ) (libvlc_instance_t *p_instance, const char *psz_mrl);
29 void ( *libvlc_media_release ) ( libvlc_media_t *p_md );
30 void ( *libvlc_media_retain ) ( libvlc_media_t *p_md );
31 libvlc_time_t ( *libvlc_media_get_duration ) ( libvlc_media_t *p_md );
32 void ( *libvlc_media_parse ) ( libvlc_media_t *p_md );
33 int ( *libvlc_media_is_parsed ) ( libvlc_media_t *p_md );
34 char* ( *libvlc_media_get_mrl )(libvlc_media_t *p_md);
37 libvlc_media_t* InitMedia( const rtl::OUString& url, Instance& instance )
39 rtl::OString dest;
40 url.convertToString(&dest, RTL_TEXTENCODING_UTF8, 0);
42 return libvlc_media_new_location(instance, dest.getStr());
46 bool Media::LoadSymbols()
48 ApiMap VLC_MEDIA_API[] =
50 SYM_MAP( libvlc_media_new_path ),
51 SYM_MAP( libvlc_media_release ),
52 SYM_MAP( libvlc_media_retain ),
53 SYM_MAP( libvlc_media_get_duration ),
54 SYM_MAP( libvlc_media_parse ),
55 SYM_MAP( libvlc_media_is_parsed ),
56 SYM_MAP( libvlc_media_get_mrl ),
57 SYM_MAP( libvlc_media_new_location )
60 return InitApiMap( VLC_MEDIA_API );
63 Media::Media( const rtl::OUString& url, Instance& instance )
64 : mMedia( InitMedia( url, instance ) )
66 if (mMedia == NULL)
68 // TODO: Error
72 Media::Media( const Media& other )
74 operator=( other );
77 Media& Media::operator=( const Media& other )
79 libvlc_media_release( mMedia );
80 mMedia = other.mMedia;
82 libvlc_media_retain( mMedia );
83 return *this;
86 int Media::getDuration() const
88 if ( !libvlc_media_is_parsed( mMedia ) )
89 libvlc_media_parse( mMedia );
91 const int duration = libvlc_media_get_duration( mMedia );
92 if (duration == -1)
94 SAL_WARN("avmedia", Common::LastErrorMessage());
95 return 0;
97 else if (duration == 0)
99 // A duration must be greater than 0
100 return 1;
103 return duration;
106 Media::~Media()
108 libvlc_media_release( mMedia );
114 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */