bump product version to 6.3.0.0.beta1
[LibreOffice.git] / avmedia / source / vlc / wrapper / Player.cxx
blob2f8e0d8903a0a013f9b09c9818d5804486adacd4
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 "Types.hxx"
12 #include <wrapper/Player.hxx>
13 #include <wrapper/Media.hxx>
14 #include "SymbolLoader.hxx"
15 #include <wrapper/Common.hxx>
17 struct libvlc_media_t;
19 namespace { extern "C" {
20 void ( *libvlc_media_player_retain ) ( libvlc_media_player_t *p_mi );
21 libvlc_media_player_t * ( *libvlc_media_player_new_from_media ) ( libvlc_media_t *p_md );
22 void ( *libvlc_media_player_release ) ( libvlc_media_player_t *p_mi );
23 int ( *libvlc_media_player_play ) ( libvlc_media_player_t *p_mi );
24 void ( *libvlc_media_player_pause ) ( libvlc_media_player_t *p_mi );
25 int ( *libvlc_media_player_is_playing ) ( libvlc_media_player_t *p_mi );
26 void ( *libvlc_media_player_stop ) ( libvlc_media_player_t *p_mi );
27 void ( *libvlc_media_player_set_time ) ( libvlc_media_player_t *p_mi, libvlc_time_t i_time );
28 libvlc_time_t ( *libvlc_media_player_get_time ) ( libvlc_media_player_t *p_mi );
29 float ( *libvlc_media_player_get_rate )( libvlc_media_player_t *p_mi );
30 int ( *libvlc_audio_set_volume ) ( libvlc_media_player_t *p_mi, int i_volume );
31 int ( *libvlc_audio_get_volume ) ( libvlc_media_player_t *p_mi );
32 int ( *libvlc_audio_get_mute ) ( libvlc_media_player_t *p_mi );
33 void ( *libvlc_audio_set_mute ) ( libvlc_media_player_t *p_mi, int status );
34 int ( *libvlc_video_take_snapshot ) ( libvlc_media_player_t *p_mi,
35 unsigned num,
36 const char *psz_filepath,
37 unsigned int i_width,
38 unsigned int i_height );
39 #if defined UNX
40 void ( *libvlc_media_player_set_xwindow ) ( libvlc_media_player_t *p_mi, uint32_t drawable );
41 #elif defined MACOSX
42 void ( *libvlc_media_player_set_nsobject ) ( libvlc_media_player_t *p_mi, void *drawable );
43 #elif defined WNT
44 void ( *libvlc_media_player_set_hwnd ) ( libvlc_media_player_t *p_mi, void *drawable );
45 #else
46 #error unknown OS
47 #endif
48 unsigned ( *libvlc_media_player_has_vout ) ( libvlc_media_player_t *p_mi );
49 void ( *libvlc_video_set_mouse_input ) ( libvlc_media_player_t *p_mi, unsigned on );
50 void ( *libvlc_video_set_scale ) ( libvlc_media_player_t *p_mi, float f_factor );
51 int ( *libvlc_video_get_size ) ( libvlc_media_player_t *p_mi, unsigned num,
52 unsigned *px, unsigned *py );
53 int ( *libvlc_video_get_track_count ) ( libvlc_media_player_t *p_mi );
54 int ( *libvlc_video_set_track ) ( libvlc_media_player_t *p_mi, int i_track );
55 libvlc_track_description_t* ( *libvlc_video_get_track_description ) ( libvlc_media_player_t *p_mi );
57 int ( *libvlc_audio_get_track ) ( libvlc_media_player_t *p_mi );
58 libvlc_track_description_t * ( *libvlc_audio_get_track_description ) (libvlc_media_player_t *p_mi );
59 int ( *libvlc_audio_set_track ) (libvlc_media_player_t *p_mi, int i_track);
60 } }
62 namespace avmedia
64 namespace vlc
66 namespace wrapper
68 bool Player::LoadSymbols()
70 static ApiMap const VLC_PLAYER_API[] =
72 SYM_MAP( libvlc_media_player_new_from_media ),
73 SYM_MAP( libvlc_media_player_release ),
74 SYM_MAP( libvlc_media_player_play ),
75 SYM_MAP( libvlc_media_player_pause ),
76 SYM_MAP( libvlc_media_player_is_playing ),
77 SYM_MAP( libvlc_media_player_stop ),
78 SYM_MAP( libvlc_media_player_set_time ),
79 SYM_MAP( libvlc_media_player_get_time ),
80 SYM_MAP( libvlc_media_player_get_rate ),
81 SYM_MAP( libvlc_audio_set_volume ),
82 SYM_MAP( libvlc_audio_get_volume ),
83 SYM_MAP( libvlc_audio_set_mute ),
84 SYM_MAP( libvlc_audio_get_mute ),
85 SYM_MAP( libvlc_video_take_snapshot ),
86 #if defined UNX
87 SYM_MAP( libvlc_media_player_set_xwindow ),
88 #elif defined MACOSX
89 SYM_MAP( libvlc_media_player_set_nsobject ),
90 #elif defined WNT
91 SYM_MAP( libvlc_media_player_set_hwnd ),
92 #endif
93 SYM_MAP( libvlc_media_player_has_vout ),
94 SYM_MAP( libvlc_video_set_mouse_input ),
95 SYM_MAP( libvlc_media_player_retain ),
96 SYM_MAP( libvlc_video_set_scale ),
97 SYM_MAP( libvlc_video_get_size ),
98 SYM_MAP( libvlc_video_get_track_count ),
99 SYM_MAP( libvlc_video_set_track ),
100 SYM_MAP( libvlc_video_get_track_description ),
101 SYM_MAP( libvlc_audio_get_track ),
102 SYM_MAP( libvlc_audio_get_track_description ),
103 SYM_MAP( libvlc_audio_set_track )
106 return InitApiMap( VLC_PLAYER_API );
109 Player::Player( Media& media )
110 : mPlayer( libvlc_media_player_new_from_media( media ) )
114 Player::Player( const Player& other )
116 operator=( other );
119 Player& Player::operator=( const Player& other )
121 libvlc_media_player_release( mPlayer );
122 mPlayer = other.mPlayer;
123 libvlc_media_player_retain( mPlayer );
124 return *this;
127 Player::~Player()
129 libvlc_media_player_release( mPlayer );
132 bool Player::play()
134 const bool status = ( libvlc_media_player_play( mPlayer ) == 0 );
135 if ( libvlc_video_get_track_count( mPlayer ) > 0 )
137 const libvlc_track_description_t *description = libvlc_video_get_track_description( mPlayer );
139 for ( ; description->p_next != nullptr; description = description->p_next );
141 libvlc_video_set_track( mPlayer, description->i_id );
144 if ( libvlc_audio_get_track( mPlayer ) > 0 )
146 const libvlc_track_description_t *description = libvlc_audio_get_track_description( mPlayer );
148 for ( ; description->p_next != nullptr; description = description->p_next );
150 libvlc_audio_set_track( mPlayer, description->i_id );
153 return status;
156 void Player::pause()
158 libvlc_media_player_pause( mPlayer );
161 void Player::stop()
163 libvlc_media_player_stop( mPlayer );
166 void Player::setTime( int time )
168 libvlc_media_player_set_time( mPlayer, time );
171 int Player::getTime() const
173 const int time = libvlc_media_player_get_time( mPlayer );
175 return ( time == -1 ? 0 : time );
178 void Player::setScale( float factor )
180 libvlc_video_set_scale( mPlayer, factor );
183 void Player::setMouseHandling(bool flag)
185 libvlc_video_set_mouse_input( mPlayer, flag );
188 bool Player::isPlaying() const
190 return libvlc_media_player_is_playing( mPlayer ) == 1;
193 void Player::setVolume( int volume )
195 libvlc_audio_set_volume( mPlayer, volume );
198 int Player::getVolume() const
200 return libvlc_audio_get_volume( mPlayer );
203 void Player::setMute( bool mute)
205 libvlc_audio_set_mute( mPlayer, mute );
208 bool Player::getMute() const
210 return libvlc_audio_get_mute( mPlayer );
213 void Player::setVideoSize( unsigned width, unsigned )
215 unsigned currentWidth, currentHeight;
216 libvlc_video_get_size( mPlayer, 0, &currentWidth, &currentHeight );
217 if ( currentWidth != 0 )
218 setScale( static_cast<float>( width ) / currentWidth );
221 void Player::setWindow( intptr_t id )
223 #if defined UNX
224 libvlc_media_player_set_xwindow( mPlayer, static_cast<uint32_t>(id) );
225 #elif defined MACOSX
226 libvlc_media_player_set_nsobject( mPlayer, reinterpret_cast<void*>( id ) );
227 #elif defined WNT
228 libvlc_media_player_set_hwnd( mPlayer, reinterpret_cast<void*>( id ) );
229 #endif
232 void Player::takeSnapshot( const OUString& file )
234 OString dest;
235 file.convertToString( &dest, RTL_TEXTENCODING_UTF8, 0 );
236 libvlc_video_take_snapshot( mPlayer, 0, dest.getStr(), 480, 360 );
239 bool Player::hasVout() const
241 return libvlc_media_player_has_vout( mPlayer );
247 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */