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>
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
,
36 const char *psz_filepath
,
38 unsigned int i_height
);
40 void ( *libvlc_media_player_set_nsobject
) ( libvlc_media_player_t
*p_mi
, void *drawable
);
42 void ( *libvlc_media_player_set_xwindow
) ( libvlc_media_player_t
*p_mi
, uint32_t drawable
);
44 void ( *libvlc_media_player_set_hwnd
) ( libvlc_media_player_t
*p_mi
, void *drawable
);
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
);
62 namespace avmedia::vlc::wrapper
64 bool Player::LoadSymbols()
66 static ApiMap
const VLC_PLAYER_API
[] =
68 SYM_MAP( libvlc_media_player_new_from_media
),
69 SYM_MAP( libvlc_media_player_release
),
70 SYM_MAP( libvlc_media_player_play
),
71 SYM_MAP( libvlc_media_player_pause
),
72 SYM_MAP( libvlc_media_player_is_playing
),
73 SYM_MAP( libvlc_media_player_stop
),
74 SYM_MAP( libvlc_media_player_set_time
),
75 SYM_MAP( libvlc_media_player_get_time
),
76 SYM_MAP( libvlc_media_player_get_rate
),
77 SYM_MAP( libvlc_audio_set_volume
),
78 SYM_MAP( libvlc_audio_get_volume
),
79 SYM_MAP( libvlc_audio_set_mute
),
80 SYM_MAP( libvlc_audio_get_mute
),
81 SYM_MAP( libvlc_video_take_snapshot
),
83 SYM_MAP( libvlc_media_player_set_nsobject
),
85 SYM_MAP( libvlc_media_player_set_xwindow
),
87 SYM_MAP( libvlc_media_player_set_hwnd
),
89 SYM_MAP( libvlc_media_player_has_vout
),
90 SYM_MAP( libvlc_video_set_mouse_input
),
91 SYM_MAP( libvlc_media_player_retain
),
92 SYM_MAP( libvlc_video_set_scale
),
93 SYM_MAP( libvlc_video_get_size
),
94 SYM_MAP( libvlc_video_get_track_count
),
95 SYM_MAP( libvlc_video_set_track
),
96 SYM_MAP( libvlc_video_get_track_description
),
97 SYM_MAP( libvlc_audio_get_track
),
98 SYM_MAP( libvlc_audio_get_track_description
),
99 SYM_MAP( libvlc_audio_set_track
)
102 return InitApiMap( VLC_PLAYER_API
);
105 Player::Player( Media
& media
)
106 : mPlayer( libvlc_media_player_new_from_media( media
) )
110 Player::Player( const Player
& other
)
115 Player
& Player::operator=( const Player
& other
)
117 libvlc_media_player_release( mPlayer
);
118 mPlayer
= other
.mPlayer
;
119 libvlc_media_player_retain( mPlayer
);
125 libvlc_media_player_release( mPlayer
);
130 const bool status
= ( libvlc_media_player_play( mPlayer
) == 0 );
131 if ( libvlc_video_get_track_count( mPlayer
) > 0 )
133 const libvlc_track_description_t
*description
= libvlc_video_get_track_description( mPlayer
);
135 for ( ; description
->p_next
!= nullptr; description
= description
->p_next
);
137 libvlc_video_set_track( mPlayer
, description
->i_id
);
140 if ( libvlc_audio_get_track( mPlayer
) > 0 )
142 const libvlc_track_description_t
*description
= libvlc_audio_get_track_description( mPlayer
);
144 for ( ; description
->p_next
!= nullptr; description
= description
->p_next
);
146 libvlc_audio_set_track( mPlayer
, description
->i_id
);
154 libvlc_media_player_pause( mPlayer
);
159 libvlc_media_player_stop( mPlayer
);
162 void Player::setTime( int time
)
164 libvlc_media_player_set_time( mPlayer
, time
);
167 int Player::getTime() const
169 const int time
= libvlc_media_player_get_time( mPlayer
);
171 return ( time
== -1 ? 0 : time
);
174 void Player::setScale( float factor
)
176 libvlc_video_set_scale( mPlayer
, factor
);
179 void Player::setMouseHandling(bool flag
)
181 libvlc_video_set_mouse_input( mPlayer
, flag
);
184 bool Player::isPlaying() const
186 return libvlc_media_player_is_playing( mPlayer
) == 1;
189 void Player::setVolume( int volume
)
191 libvlc_audio_set_volume( mPlayer
, volume
);
194 int Player::getVolume() const
196 return libvlc_audio_get_volume( mPlayer
);
199 void Player::setMute( bool mute
)
201 libvlc_audio_set_mute( mPlayer
, mute
);
204 bool Player::getMute() const
206 return libvlc_audio_get_mute( mPlayer
);
209 void Player::setVideoSize( unsigned width
, unsigned )
211 unsigned currentWidth
, currentHeight
;
212 libvlc_video_get_size( mPlayer
, 0, ¤tWidth
, ¤tHeight
);
213 if ( currentWidth
!= 0 )
214 setScale( static_cast<float>( width
) / currentWidth
);
217 void Player::setWindow( intptr_t id
)
220 libvlc_media_player_set_nsobject( mPlayer
, reinterpret_cast<void*>( id
) );
222 libvlc_media_player_set_xwindow( mPlayer
, static_cast<uint32_t>(id
) );
224 libvlc_media_player_set_hwnd( mPlayer
, reinterpret_cast<void*>( id
) );
228 void Player::takeSnapshot( const OUString
& file
)
231 file
.convertToString( &dest
, RTL_TEXTENCODING_UTF8
, 0 );
232 libvlc_video_take_snapshot( mPlayer
, 0, dest
.getStr(), 480, 360 );
235 bool Player::hasVout() const
237 return libvlc_media_player_has_vout( mPlayer
);
241 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */