1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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/.
10 #include <rtl/ustring.h>
11 #include <wrapper/Media.hxx>
12 #include "SymbolLoader.hxx"
13 #include <wrapper/Instance.hxx>
15 #include <wrapper/Common.hxx>
16 #include <sal/log.hxx>
18 struct libvlc_instance_t
;
20 namespace avmedia::vlc::wrapper
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
)
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)
69 Media::Media( const Media
& other
)
74 Media
& Media::operator=( const Media
& other
)
76 libvlc_media_release( mMedia
);
77 mMedia
= other
.mMedia
;
79 libvlc_media_retain( mMedia
);
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
);
91 SAL_WARN("avmedia", Common::LastErrorMessage());
94 else if (duration
== 0)
96 // A duration must be greater than 0
105 libvlc_media_release( mMedia
);
109 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */