MediaPlayer.hpp 57.4 KB
Newer Older
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
1
/*****************************************************************************
2
 * MediaPlayer.hpp: MediaPlayer API
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
3
 *****************************************************************************
4
 * Copyright © 2015 libvlcpp authors & VideoLAN
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
5
 *
6
 * Authors: Alexey Sokolov <alexey+vlc@asokolov.org>
7
 *          Hugo Beauzée-Luyssen <hugo@beauzee.fr>
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation; either version 2.1 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
 *****************************************************************************/

#ifndef LIBVLC_CXX_MEDIAPLAYER_H
#define LIBVLC_CXX_MEDIAPLAYER_H

27
#include <array>
28 29
#include <string>
#include <vector>
30
#include <memory>
31

32
#include "common.hpp"
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
33

34
namespace VLC
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
35 36
{

37
class AudioOutputDeviceDescription;
38
class Equalizer;
39 40
class Instance;
class Media;
41
class MediaPlayerEventManager;
42
class TrackDescription;
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
43

Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
44 45 46
///
/// \brief The MediaPlayer class exposes libvlc_media_player_t functionnalities
///
47
class MediaPlayer : private CallbackOwner<13>, public Internal<libvlc_media_player_t>
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
48
{
49
private:
50
    enum class CallbackIdx : unsigned int
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
    {
        AudioPlay,
        AudioPause,
        AudioResume,
        AudioFlush,
        AudioDrain,
        AudioVolume,
        AudioSetup,
        AudioCleanup,

        VideoLock,
        VideoUnlock,
        VideoDisplay,
        VideoFormat,
        VideoCleanup,
    };
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
67
public:
68
#if LIBVLC_VERSION_INT >= LIBVLC_VERSION(4, 0, 0, 0)
69
    enum class DeinterlaceState : signed char
70 71 72 73 74 75 76
    {
        Auto     = -1,
        Disabled =  0,
        Enabled  =  1
    };
#endif

Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
77 78 79 80 81
    /**
     * Check if 2 MediaPlayer objects contain the same libvlc_media_player_t.
     * \param another another MediaPlayer
     * \return true if they contain the same libvlc_media_player_t
     */
82 83 84 85
    bool operator==(const MediaPlayer& another) const
    {
        return m_obj == another.m_obj;
    }
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
86 87 88 89 90 91 92

    /**
     * Create an empty Media Player object
     *
     * \param p_libvlc_instance  the libvlc instance in which the Media
     * Player should be created.
     */
93
    MediaPlayer( Instance& instance )
94
        : Internal{ libvlc_media_player_new( instance ), libvlc_media_player_release }
95 96
    {
    }
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
97 98 99 100 101 102

    /**
     * Create a Media Player object from a Media
     *
     * \param p_md  the media. Afterwards the p_md can be safely destroyed.
     */
103
    MediaPlayer( Media& md )
104 105 106 107 108 109
        : Internal{ libvlc_media_player_new_from_media(
                        getInternalPtr<libvlc_media_t>( md ) ),
                    libvlc_media_player_release }
    {
    }

110
    /**
111 112 113 114 115
     * Create an empty VLC MediaPlayer instance.
     *
     * Calling any method on such an instance is undefined.
    */
    MediaPlayer() = default;
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
116 117 118 119 120 121 122

    /**
     * Set the media that will be used by the media_player. If any, previous
     * md will be released.
     *
     * \param p_md  the Media. Afterwards the p_md can be safely destroyed.
     */
123
    void setMedia(Media& md)
124
    {
125
        libvlc_media_player_set_media( *this, getInternalPtr<libvlc_media_t>( md ) );
126
    }
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
127 128 129 130 131 132 133

    /**
     * Get the media used by the media_player.
     *
     * \return the media associated with p_mi, or NULL if no media is
     * associated
     */
134 135
    MediaPtr media()
    {
136 137 138
        auto media = libvlc_media_player_get_media(*this);
        if ( media == nullptr )
            return nullptr;
139
        return std::make_shared<Media>( media, false );
140
    }
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
141 142 143 144 145 146

    /**
     * Get the Event Manager from which the media player send event.
     *
     * \return the event manager associated with p_mi
     */
147
    MediaPlayerEventManager& eventManager()
148
    {
149
        if ( m_eventManager == nullptr )
150
        {
151
            libvlc_event_manager_t* obj = libvlc_media_player_event_manager( *this );
152
            m_eventManager = std::make_shared<MediaPlayerEventManager>( obj, *this );
153
        }
154
        return *m_eventManager;
155
    }
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
156 157

    /**
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
158
     * \return true if the media player is playing, 0 otherwise
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
159
     */
160 161
    bool isPlaying()
    {
162
        return libvlc_media_player_is_playing(*this) != 0;
163
    }
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
164 165

    /**
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
166
     * @brief play Start playback
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
167
     *
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
168
     * If playback was already started, this method has no effect
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
169
     */
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
170
    bool play()
171
    {
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
172
        return libvlc_media_player_play(*this) == 0;
173
    }
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
174 175 176 177

    /**
     * Pause or resume (no effect if there is no media)
     *
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
178
     * \param do_pause  play/resume if true, pause if false
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
179 180 181
     *
     * \version LibVLC 1.1.1 or later
     */
182
    void setPause(bool pause)
183
    {
184
        libvlc_media_player_set_pause(*this, pause);
185
    }
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
186 187

    /**
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
188
     * @brief pause Toggle pause (no effect if there is no media)
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
189
     */
190 191
    void pause()
    {
192
        libvlc_media_player_pause(*this);
193
    }
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
194

195 196 197 198 199 200 201 202 203
#if LIBVLC_VERSION_INT >= LIBVLC_VERSION(4, 0, 0, 0)
    /**
     * @brief stop Stop the playback (no effect if there is no media)
     */
    void stopAsync()
    {
        libvlc_media_player_stop_async(*this);
    }
#else
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
204
    /**
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
205 206 207 208 209
     * @brief stop Stop the playback (no effect if there is no media)
     *
     * \warning This is synchronous, and will block until all VLC threads have
     *          been joined.
     *          Calling this from a VLC callback is a bound to cause a deadlock.
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
210
     */
211 212
    void stop()
    {
213
        libvlc_media_player_stop(*this);
214
    }
215
#endif
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
216 217 218 219 220 221 222 223

    /**
     * Set the NSView handler where the media player should render its video
     * output.
     *
     * Use the vout called "macosx".
     *
     * The drawable is an NSObject that follow the
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
224
     * VLCOpenGLVideoViewEmbedding protocol: VLCOpenGLVideoViewEmbedding <NSObject>
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
225 226 227 228 229 230 231 232 233 234 235 236 237 238
     *
     * Or it can be an NSView object.
     *
     * If you want to use it along with Qt4 see the QMacCocoaViewContainer.
     * Then the following code should work:  { NSView *video = [[NSView
     * alloc] init]; QMacCocoaViewContainer *container = new
     * QMacCocoaViewContainer(video, parent);
     * libvlc_media_player_set_nsobject(mp, video); [video release]; }
     *
     * You can find a live example in VLCVideoView in VLCKit.framework.
     *
     * \param drawable  the drawable that is either an NSView or an object
     * following the VLCOpenGLVideoViewEmbedding protocol.
     */
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
239
    void setNsobject(void* drawable)
240
    {
241
        libvlc_media_player_set_nsobject(*this, drawable);
242
    }
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
243 244 245 246 247 248 249

    /**
     * Get the NSView handler previously set with MediaPlayer::setNsobject()
     * .
     *
     * \return the NSView handler or 0 if none where set
     */
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
250
    void* nsobject()
251
    {
252
        return libvlc_media_player_get_nsobject(*this);
253
    }
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
254 255 256 257 258 259 260 261 262 263 264 265 266 267 268

    /**
     * Set an X Window System drawable where the media player should render
     * its video output. If LibVLC was built without X11 output support, then
     * this has no effects.
     *
     * The specified identifier must correspond to an existing Input/Output
     * class X11 window. Pixmaps are supported. The caller shall ensure that
     * the X11 server is the same as the one the VLC instance has been
     * configured with. This function must be called before video playback is
     * started; otherwise it will only take effect after playback stop and
     * restart.
     *
     * \param drawable  the ID of the X window
     */
269 270
    void setXwindow(uint32_t drawable)
    {
271
        libvlc_media_player_set_xwindow(*this, drawable);
272
    }
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
273 274 275 276 277 278 279 280 281

    /**
     * Get the X Window System window identifier previously set with
     * MediaPlayer::setXwindow() . Note that this will return the identifier
     * even if VLC is not currently using it (for instance if it is playing
     * an audio-only input).
     *
     * \return an X window ID, or 0 if none where set.
     */
282 283
    uint32_t xwindow()
    {
284
        return libvlc_media_player_get_xwindow(*this);
285
    }
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
286 287 288 289 290 291 292 293

    /**
     * Set a Win32/Win64 API window handle (HWND) where the media player
     * should render its video output. If LibVLC was built without
     * Win32/Win64 API output support, then this has no effects.
     *
     * \param drawable  windows handle of the drawable
     */
294 295
    void setHwnd(void * drawable)
    {
296
        libvlc_media_player_set_hwnd(*this, drawable);
297
    }
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
298 299 300 301 302 303

    /**
     * Get the Windows API window handle (HWND) previously set with
     * MediaPlayer::setHwnd() . The handle will be returned even if LibVLC is
     * not currently outputting any video to it.
     *
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
304
     * \return a window handle or nullptr if there are none.
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
305
     */
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
306
    void* hwnd()
307
    {
308
        return libvlc_media_player_get_hwnd(*this);
309
    }
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
310 311 312 313 314 315

    /**
     * Get the current movie length (in ms).
     *
     * \return the movie length (in ms), or -1 if there is no media.
     */
316 317
    libvlc_time_t length()
    {
318
        return libvlc_media_player_get_length(*this);
319
    }
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
320 321 322 323 324 325

    /**
     * Get the current movie time (in ms).
     *
     * \return the movie time (in ms), or -1 if there is no media.
     */
326 327
    libvlc_time_t time()
    {
328
        return  libvlc_media_player_get_time(*this);
329
    }
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
330 331 332 333 334

    /**
     * Set the movie time (in ms). This has no effect if no media is being
     * played. Not all formats and protocols support this.
     *
335 336
     * \version{2.x}
     * \version{3.x}
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
337
     * \param i_time  the movie time (in ms).
338 339
     * \version{4.x}
     * \param b_fast  prefer fast seeking or precise seeking
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
340
     */
341 342 343 344 345 346
#if LIBVLC_VERSION_INT >= LIBVLC_VERSION(4, 0, 0, 0)
    void setTime(libvlc_time_t i_time, bool b_fast)
    {
        libvlc_media_player_set_time(*this, i_time, b_fast);
    }
#else
347 348
    void setTime(libvlc_time_t i_time)
    {
349
        libvlc_media_player_set_time(*this, i_time);
350
    }
351
#endif
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
352 353 354 355 356 357

    /**
     * Get movie position as percentage between 0.0 and 1.0.
     *
     * \return movie position, or -1. in case of error
     */
358 359
    float position()
    {
360
        return libvlc_media_player_get_position(*this);
361
    }
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
362 363 364 365 366 367

    /**
     * Set movie position as percentage between 0.0 and 1.0. This has no
     * effect if playback is not enabled. This might not work depending on
     * the underlying input format and protocol.
     *
368 369
     * \version{2.x}
     * \version{3.x}
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
370
     * \param f_pos  the position
371 372
     * \version{4.x}
     * \param b_fast prefer fast seeking or precise seeking
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
373
     */
374 375 376 377 378 379
#if LIBVLC_VERSION_INT >= LIBVLC_VERSION(4, 0, 0, 0)
    void setPosition(float f_pos, bool b_fast)
    {
        libvlc_media_player_set_position(*this, f_pos, b_fast);
    }
#else
380 381
    void setPosition(float f_pos)
    {
382
        libvlc_media_player_set_position(*this, f_pos);
383
    }
384
#endif
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
385 386 387 388 389 390

    /**
     * Set movie chapter (if applicable).
     *
     * \param i_chapter  chapter number to play
     */
391 392
    void setChapter(int i_chapter)
    {
393
        libvlc_media_player_set_chapter(*this, i_chapter);
394
    }
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
395 396 397 398 399 400

    /**
     * Get movie chapter.
     *
     * \return chapter number currently playing, or -1 if there is no media.
     */
401 402
    int chapter()
    {
403
        return libvlc_media_player_get_chapter(*this);
404
    }
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
405 406 407 408 409 410

    /**
     * Get movie chapter count
     *
     * \return number of chapters in movie, or -1.
     */
411 412
    int chapterCount()
    {
413
        return libvlc_media_player_get_chapter_count(*this);
414
    }
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
415

416
#if LIBVLC_VERSION_INT < LIBVLC_VERSION(4, 0, 0, 0)
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
417 418 419 420 421
    /**
     * Is the player able to play
     *
     * \return boolean
     */
422 423
    bool willPlay()
    {
424
        return libvlc_media_player_will_play(*this) != 0;
425
    }
426
#endif
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
427 428 429 430 431 432 433 434

    /**
     * Get title chapter count
     *
     * \param i_title  title
     *
     * \return number of chapters in title, or -1
     */
435 436
    int chapterCountForTitle(int i_title)
    {
437
        return libvlc_media_player_get_chapter_count_for_title(*this, i_title);
438
    }
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
439 440 441 442 443 444

    /**
     * Set movie title
     *
     * \param i_title  title number to play
     */
445 446
    void setTitle(int i_title)
    {
447
        libvlc_media_player_set_title(*this, i_title);
448
    }
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
449 450 451 452 453 454

    /**
     * Get movie title
     *
     * \return title number currently playing, or -1
     */
455 456
    int title()
    {
457
        return libvlc_media_player_get_title(*this);
458
    }
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
459 460 461 462 463 464

    /**
     * Get movie title count
     *
     * \return title number count, or -1
     */
465 466
    int titleCount()
    {
467
        return libvlc_media_player_get_title_count(*this);
468
    }
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
469 470 471 472

    /**
     * Set previous chapter (if applicable)
     */
473 474
    void previousChapter()
    {
475
        libvlc_media_player_previous_chapter(*this);
476
    }
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
477 478 479 480

    /**
     * Set next chapter (if applicable)
     */
481 482
    void nextChapter()
    {
483
        libvlc_media_player_next_chapter(*this);
484
    }
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
485 486 487 488 489 490 491 492 493

    /**
     * Get the requested movie play rate.
     *
     * \warning Depending on the underlying media, the requested rate may be
     * different from the real playback rate.
     *
     * \return movie play rate
     */
494 495
    float rate()
    {
496
        return libvlc_media_player_get_rate(*this);
497
    }
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
498 499 500 501 502 503 504 505 506

    /**
     * Set movie play rate
     *
     * \param rate  movie play rate to set
     *
     * \return -1 if an error was detected, 0 otherwise (but even then, it
     * might not actually work depending on the underlying media protocol)
     */
507 508
    int setRate(float rate)
    {
509
        return libvlc_media_player_set_rate(*this, rate);
510
    }
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
511 512 513 514 515 516 517 518

    /**
     * Get current movie state
     *
     * \return the current state of the media player (playing, paused, ...)
     *
     * \see libvlc_state_t
     */
519 520
    libvlc_state_t state()
    {
521
        return libvlc_media_player_get_state(*this);
522
    }
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
523

524
#if LIBVLC_VERSION_INT < LIBVLC_VERSION(3, 0, 0, 0)
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
525 526 527 528 529 530
    /**
     * Get movie fps rate
     *
     * \return frames per second (fps) for this playing movie, or 0 if
     * unspecified
     */
531 532
    float fps()
    {
533
        return libvlc_media_player_get_fps(*this);
534
    }
535
#endif
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
536 537

    /**
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
538
     * Get the amount of video outputs this media player has?
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
539 540 541
     *
     * \return the number of video outputs
     */
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
542
    uint32_t hasVout()
543
    {
544
        return libvlc_media_player_has_vout(*this);
545
    }
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
546 547 548 549 550 551

    /**
     * Is this media player seekable?
     *
     * \return true if the media player can seek
     */
552 553
    bool isSeekable()
    {
554
        return libvlc_media_player_is_seekable(*this) != 0;
555
    }
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
556 557 558 559 560 561

    /**
     * Can this media player be paused?
     *
     * \return true if the media player can pause
     */
562 563
    bool canPause()
    {
564
        return libvlc_media_player_can_pause(*this) != 0;
565
    }
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
566 567 568 569 570 571 572 573

    /**
     * Check if the current program is scrambled
     *
     * \return true if the current program is scrambled
     *
     * \version LibVLC 2.2.0 or later
     */
574 575
    bool programScrambled()
    {
576
        return libvlc_media_player_program_scrambled(*this) != 0;
577
    }
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
578 579 580 581

    /**
     * Display the next frame (if supported)
     */
582 583
    void nextFrame()
    {
584
        libvlc_media_player_next_frame(*this);
585
    }
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
586 587 588 589 590 591 592 593

    /**
     * Navigate through DVD Menu
     *
     * \param navigate  the Navigation mode
     *
     * \version libVLC 2.0.0 or later
     */
594 595
    void navigate(unsigned navigate)
    {
596
        libvlc_media_player_navigate(*this, navigate);
597
    }
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
598 599 600 601 602 603 604 605 606 607 608 609

    /**
     * Set if, and how, the video title will be shown when media is played.
     *
     * \param position  position at which to display the title, or
     * libvlc_position_disable to prevent the title from being displayed
     *
     * \param timeout  title display timeout in milliseconds (ignored if
     * libvlc_position_disable)
     *
     * \version libVLC 2.1.0 or later
     */
610 611
    void setVideoTitleDisplay(libvlc_position_t position, unsigned int timeout)
    {
612
        libvlc_media_player_set_video_title_display(*this, position, timeout);
613
    }
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
614 615 616 617 618 619 620

    /**
     * Toggle fullscreen status on non-embedded video outputs.
     *
     * \warning The same limitations applies to this function as to
     * MediaPlayer::setFullscreen() .
     */
621 622
    void toggleFullscreen()
    {
623
        libvlc_toggle_fullscreen(*this);
624
    }
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
625 626 627 628 629 630 631 632 633 634 635 636 637

    /**
     * Enable or disable fullscreen.
     *
     * \warning With most window managers, only a top-level windows can be in
     * full-screen mode. Hence, this function will not operate properly if
     * MediaPlayer::setXwindow() was used to embed the video in a non-top-
     * level window. In that case, the embedding window must be reparented to
     * the root window fullscreen mode is enabled. You will want to reparent
     * it back to its normal parent when disabling fullscreen.
     *
     * \param b_fullscreen  boolean for fullscreen status
     */
638
    void setFullscreen(bool fullscreen)
639
    {
640
        libvlc_set_fullscreen( *this, fullscreen );
641
    }
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
642 643 644 645 646 647

    /**
     * Get current fullscreen status.
     *
     * \return the fullscreen status (boolean)
     */
648 649
    bool fullscreen()
    {
650
        return libvlc_get_fullscreen(*this) != 0;
651
    }
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
652

653
#if LIBVLC_VERSION_INT < LIBVLC_VERSION(3, 0, 0, 0)
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
654 655 656
    /**
     * Toggle teletext transparent status on video output.
     */
657 658
    void toggleTeletext()
    {
659
        libvlc_toggle_teletext(*this);
660
    }
661
#endif
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688

    /**
     * Apply new equalizer settings to a media player.
     *
     * The equalizer is first created by invoking
     * libvlc_audio_equalizer_new() or
     * libvlc_audio_equalizer_new_from_preset() .
     *
     * It is possible to apply new equalizer settings to a media player
     * whether the media player is currently playing media or not.
     *
     * Invoking this method will immediately apply the new equalizer settings
     * to the audio output of the currently playing media if there is any.
     *
     * If there is no currently playing media, the new equalizer settings
     * will be applied later if and when new media is played.
     *
     * Equalizer settings will automatically be applied to subsequently
     * played media.
     *
     * To disable the equalizer for a media player invoke this method passing
     * NULL for the p_equalizer parameter.
     *
     * The media player does not keep a reference to the supplied equalizer
     * so it is safe for an application to release the equalizer reference
     * any time after this method returns.
     *
689
     * \param equalizer  The equalizer to be used by this media player
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
690
     *
691
     * \return true on success, false otherwise
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
692 693 694
     *
     * \version LibVLC 2.2.0 or later
     */
695 696 697 698 699 700 701 702 703 704 705
    bool setEqualizer(Equalizer& equalizer)
    {
        return libvlc_media_player_set_equalizer( *this, equalizer ) == 0;
    }

    ///
    /// \brief unsetEqualizer disable equalizer for this media player
    ///
    /// \return true on success, false otherwise.
    ///
    bool unsetEqualizer()
706
    {
707
        return libvlc_media_player_set_equalizer( *this, nullptr ) == 0;
708
    }
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
709

710 711 712 713 714
    /**
     * Set callbacks and private data for decoded audio. Use
     * MediaPlayer::setFormat() or MediaPlayer::setFormatCallbacks() to configure the
     * decoded audio format.
     *
715 716
     * \param play  callback to play audio samples (must not be nullptr)
     *              Required prototype is: void(const void *samples, unsigned count, int64_t pts)
717
     *
718 719
     * \param pause  callback to pause playback (or nullptr to ignore)
     *               Required prototype is void(int64_t pts);
720
     *
721 722
     * \param resume callback to resume playback (or nullptr to ignore)
     *               Required prototype is void(int64_t pts);
723
     *
724 725
     * \param flush  callback to flush audio buffers (or nullptr to ignore)
     *               Required prototype is void(int64_t pts);
726
     *
727 728
     * \param drain  callback to drain audio buffers (or nullptr to ignore)
     * *             Required prototype is void();
729 730 731
     *
     * \version LibVLC 2.0.0 or later
     */
732 733
    template <typename PlayCb, typename PauseCb, typename ResumeCb, typename FlushCb, typename DrainCb>
    void setAudioCallbacks(PlayCb&& play, PauseCb&& pause, ResumeCb&& resume, FlushCb&& flush, DrainCb&& drain)
734
    {
735 736 737 738 739 740 741
        static_assert(signature_match<PlayCb, void(const void*, unsigned int, int64_t)>::value, "Mismatched play callback prototype");
        static_assert(signature_match_or_nullptr<PauseCb, void(int64_t)>::value, "Mismatched pause callback prototype");
        static_assert(signature_match_or_nullptr<ResumeCb, void(int64_t)>::value, "Mismatched resume callback prototype");
        static_assert(signature_match_or_nullptr<FlushCb, void(int64_t pts)>::value, "Mismatched flush callback prototype");
        static_assert(signature_match_or_nullptr<DrainCb, void()>::value, "Mismatched drain callback prototype");

        libvlc_audio_set_callbacks( *this,
742 743 744 745 746
            CallbackWrapper<(unsigned int)CallbackIdx::AudioPlay,   libvlc_audio_play_cb>::wrap(   *m_callbacks, std::forward<PlayCb>( play ) ),
            CallbackWrapper<(unsigned int)CallbackIdx::AudioPause,  libvlc_audio_pause_cb>::wrap(  *m_callbacks, std::forward<PauseCb>( pause ) ),
            CallbackWrapper<(unsigned int)CallbackIdx::AudioResume, libvlc_audio_resume_cb>::wrap( *m_callbacks, std::forward<ResumeCb>( resume ) ),
            CallbackWrapper<(unsigned int)CallbackIdx::AudioFlush,  libvlc_audio_flush_cb>::wrap(  *m_callbacks, std::forward<FlushCb>( flush ) ),
            CallbackWrapper<(unsigned int)CallbackIdx::AudioDrain,  libvlc_audio_drain_cb>::wrap(  *m_callbacks, std::forward<DrainCb>( drain ) ),
747
            // We will receive the pointer as a void*, we need to offset the value *now*, otherwise we'd get
748
            // a shifted value, resulting in an invalid callback array.
749
            m_callbacks.get() );
750
    }
751 752 753 754 755 756

    /**
     * Set callbacks and private data for decoded audio. Use
     * MediaPlayer::setFormat() or MediaPlayer::setFormatCallbacks() to configure the
     * decoded audio format.
     *
757 758 759
     * \param set_volume  callback to apply audio volume, or nullptr to apply
     *                    volume in software
     *                    Expected prototype is void(float volume, bool mute)
760 761 762
     *
     * \version LibVLC 2.0.0 or later
     */
763 764
    template <typename VolumeCb>
    void setVolumeCallback(VolumeCb&& func)
765
    {
766 767
        static_assert(signature_match_or_nullptr<VolumeCb, void(float, bool)>::value, "Mismatched set volume callback");
        libvlc_audio_set_volume_callback(*this,
768
            CallbackWrapper<(unsigned int)CallbackIdx::AudioVolume, libvlc_audio_set_volume_cb>::wrap( this, std::forward<VolumeCb>( func ) ) );
769
    }
770 771 772 773 774

    /**
     * Set decoded audio format. This only works in combination with
     * MediaPlayer::setCallbacks() .
     *
775 776 777
     * \param setup  callback to select the audio format (cannot be a nullptr)
     *               Expected prototype is int(char *format, unsigned *rate, unsigned *channels)
     *               Where the return value is 0 for success, anything else to skip audio playback
778
     *
779 780
     * \param cleanup  callback to release any allocated resources (or nullptr)
     *                 Expected prototype is void()
781 782 783
     *
     * \version LibVLC 2.0.0 or later
     */
784 785
    template <typename SetupCb, typename CleanupCb>
    void setAudioFormatCallbacks(SetupCb&& setup, CleanupCb&& cleanup)
786
    {
787 788 789 790
        static_assert(signature_match<SetupCb, int(char*, uint32_t*, uint32_t*)>::value, "Mismatched Setup callback");
        static_assert(signature_match_or_nullptr<CleanupCb, void()>::value, "Mismatched cleanup callback");

        libvlc_audio_set_format_callbacks(*this,
791 792
            CallbackWrapper<(unsigned int)CallbackIdx::AudioSetup, libvlc_audio_setup_cb>::wrap( this, std::forward<SetupCb>( setup ) ),
            CallbackWrapper<(unsigned int)CallbackIdx::AudioCleanup, libvlc_audio_cleanup_cb>::wrap( this, std::forward<CleanupCb>( cleanup ) ) );
793
    }
794 795 796 797 798 799 800 801 802 803 804 805 806 807 808

    /**
     * Set decoded audio format. This only works in combination with
     * MediaPlayer::setCallbacks() , and is mutually exclusive with
     * MediaPlayer::setFormatCallbacks() .
     *
     * \param format  a four-characters string identifying the sample format
     * (e.g. "S16N" or "FL32")
     *
     * \param rate  sample rate (expressed in Hz)
     *
     * \param channels  channels count
     *
     * \version LibVLC 2.0.0 or later
     */
809 810
    void setAudioFormat(const std::string& format, unsigned rate, unsigned channels)
    {
811
        libvlc_audio_set_format(*this, format.c_str(), rate, channels);
812
    }
813 814 815 816 817 818 819

    /**
     * Selects an audio output module.
     *
     * \note Any change will take be effect only after playback is stopped
     * and restarted. Audio output cannot be changed while playing.
     *
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
820
     * \param name  name of audio output, use psz_name of
821 822 823 824 825
     *
     * \see AudioOutputDescription
     *
     * \return 0 if function succeded, -1 on error
     */
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
826
    int setAudioOutput(const std::string& name)
827
    {
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
828
        return libvlc_audio_output_set(*this, name.c_str());
829
    }
830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846

    /**
     * Gets a list of potential audio output devices,
     *
     * \see MediaPlayer::outputDeviceSet() .
     *
     * \note Not all audio outputs support enumerating devices. The audio
     * output may be functional even if the list is empty (NULL).
     *
     * \note The list may not be exhaustive.
     *
     * \warning Some audio output devices in the list might not actually work
     * in some circumstances. By default, it is recommended to not specify
     * any explicit audio device.
     *
     * \version LibVLC 2.2.0 or later.
     */
847 848
    std::vector<AudioOutputDeviceDescription> outputDeviceEnum()
    {
849 850 851
        auto devices = libvlc_audio_output_device_enum(*this);
        if ( devices == nullptr )
            return {};
852
        std::vector<AudioOutputDeviceDescription> res;
853 854
        std::unique_ptr<libvlc_audio_output_device_t, decltype(&libvlc_audio_output_device_list_release)>
                devicesPtr( devices, libvlc_audio_output_device_list_release);
855 856
        for ( auto* p = devices; p != NULL; p = p->p_next )
            res.emplace_back( p );
857 858
        return res;
    }
859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897

    /**
     * Configures an explicit audio output device.
     *
     * If the module paramater is NULL, audio output will be moved to the
     * device specified by the device identifier string immediately. This is
     * the recommended usage.
     *
     * A list of adequate potential device strings can be obtained with
     * MediaPlayer::outputDeviceEnum() .
     *
     * However passing NULL is supported in LibVLC version 2.2.0 and later
     * only; in earlier versions, this function would have no effects when
     * the module parameter was NULL.
     *
     * If the module parameter is not NULL, the device parameter of the
     * corresponding audio output, if it exists, will be set to the specified
     * string. Note that some audio output modules do not have such a
     * parameter (notably MMDevice and PulseAudio).
     *
     * A list of adequate potential device strings can be obtained with
     * Instance::audioOutputDeviceList() .
     *
     * \note This function does not select the specified audio output plugin.
     * MediaPlayer::outputSet() is used for that purpose.
     *
     * \warning The syntax for the device parameter depends on the audio
     * output. Some audio output modules require further parameters (e.g. a
     * channels map in the case of ALSA).
     *
     * \param module  If NULL, current audio output module. if non-NULL, name
     * of audio output module (
     *
     * \see AudioOutputDescription )
     *
     * \param device_id  device identifier string
     *
     * \return Nothing. Errors are ignored (this is a design bug).
     */
898 899
    void outputDeviceSet(const std::string& module, const std::string& device_id)
    {
900
        libvlc_audio_output_device_set(*this, module.c_str(), device_id.c_str());
901
    }
902

903 904 905 906 907
    void outputDeviceSet(const std::string& device_id)
    {
        libvlc_audio_output_device_set(*this, nullptr, device_id.c_str());
    }

908 909 910 911 912 913 914 915
    /**
     * Toggle mute status.
     *
     * \warning Toggling mute atomically is not always possible: On some
     * platforms, other processes can mute the VLC audio playback stream
     * asynchronously. Thus, there is a small race condition where toggling
     * will not work. See also the limitations of MediaPlayer::setMute() .
     */
916 917
    void toggleMute()
    {
918
        libvlc_audio_toggle_mute(*this);
919
    }
920 921 922 923

    /**
     * Get current mute status.
     */
924
    bool mute()
925
    {
926
        return libvlc_audio_get_mute( *this ) == 1;
927
    }
928 929 930 931 932 933 934 935 936 937 938 939 940 941 942

    /**
     * Set mute status.
     *
     * \param status  If status is true then mute, otherwise unmute
     *
     * \warning This function does not always work. If there are no active
     * audio playback stream, the mute status might not be available. If
     * digital pass-through (S/PDIF, HDMI...) is in use, muting may be
     * unapplicable. Also some audio output plugins do not support muting at
     * all.
     *
     * \note To force silent playback, disable all audio tracks. This is more
     * efficient and reliable than mute.
     */
943
    void setMute(bool mute)
944
    {
945
        libvlc_audio_set_mute( *this, (int)mute );
946
    }
947 948 949 950 951 952 953

    /**
     * Get current software audio volume.
     *
     * \return the software volume in percents (0 = mute, 100 = nominal /
     * 0dB)
     */
954 955
    int volume()
    {
956
        return libvlc_audio_get_volume(*this);
957
    }
958 959 960 961 962 963

    /**
     * Set current software audio volume.
     *
     * \param i_volume  the volume in percents (0 = mute, 100 = 0dB)
     */
964
    bool setVolume(int i_volume)
965
    {
966
        return libvlc_audio_set_volume(*this, i_volume) == 0;
967
    }
968 969 970 971 972 973 974

    /**
     * Get number of available audio tracks.
     *
     * \return the number of available audio tracks (int), or -1 if
     * unavailable
     */
975 976
    int audioTrackCount()
    {
977
        return libvlc_audio_get_track_count(*this);
978
    }
979 980 981 982

    /**
     * Get the description of available audio tracks.
     *
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
983
     * \return list with description of available audio tracks
984
     */
985 986
    std::vector<TrackDescription> audioTrackDescription()
    {
987
        libvlc_track_description_t* result = libvlc_audio_get_track_description( *this );
988 989
        return getTracksDescription( result );
    }
990 991 992 993 994 995

    /**
     * Get current audio track.
     *
     * \return the audio track ID or -1 if no active input.
     */
996 997
    int audioTrack()
    {
998
        return libvlc_audio_get_track(*this);
999
    }
1000 1001 1002 1003 1004 1005

    /**
     * Set current audio track.
     *
     * \param i_track  the track ID (i_id field from track description)
     */
1006
    bool setAudioTrack(int i_track)
1007
    {
1008
        return libvlc_audio_set_track(*this, i_track) == 0;
1009
    }
1010 1011 1012 1013 1014 1015 1016 1017

    /**
     * Get current audio channel.
     *
     * \return the audio channel
     *
     * \see libvlc_audio_output_channel_t
     */
1018 1019
    int channel()
    {
1020
        return libvlc_audio_get_channel(*this);
1021
    }
1022 1023 1024 1025 1026 1027 1028 1029

    /**
     * Set current audio channel.
     *
     * \param channel  the audio channel,
     *
     * \see libvlc_audio_output_channel_t
     */
1030
    bool setChannel(int channel)
1031
    {
1032
        return libvlc_audio_set_channel(*this, channel) == 0;
1033
    }
1034 1035 1036 1037 1038 1039 1040 1041

    /**
     * Get current audio delay.
     *
     * \return the audio delay (microseconds)
     *
     * \version LibVLC 1.1.1 or later
     */
1042
    int64_t audioDelay()
1043
    {
1044
        return libvlc_audio_get_delay(*this);
1045
    }
1046 1047 1048 1049 1050 1051 1052 1053 1054

    /**
     * Set current audio delay. The audio delay will be reset to zero each
     * time the media changes.
     *
     * \param i_delay  the audio delay (microseconds)
     *
     * \version LibVLC 1.1.1 or later
     */
1055
    bool setAudioDelay(int64_t i_delay)
1056
    {
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
1057
        return libvlc_audio_set_delay(*this, i_delay) == 0;
1058
    }
1059 1060 1061 1062 1063 1064

    /**
     * Set callbacks and private data to render decoded video to a custom
     * area in memory. Use MediaPlayer::setFormat() or MediaPlayer::setFormatCallbacks()
     * to configure the decoded format.
     *
1065 1066 1067 1068
     * \param lock  callback to lock video memory (must not be nullptr)
     *              Expected prototype is void*(void** planes)
     *              planes is a pointer to an array of planes, that must be provided with some allocated buffers
     *              Return value is a picture identifier, to be passed to unlock & display callbacks
1069
     *
1070 1071 1072 1073
     * \param unlock  callback to unlock video memory (or nullptr if not needed)
     *                Expected prototype is void(void* pictureId, void*const* planes);
     *                pictureId is the value returned by the lock callback.
     *                planes is the planes provided by the lock callback
1074
     *
1075 1076 1077
     * \param display callback to display video (or nullptr if not needed)
     *                Expected prototype is void(void* pictureId);
     *                pictureId is the value returned by the lock callback.
1078 1079 1080
     *
     * \version LibVLC 1.1.1 or later
     */
1081 1082
    template <typename LockCb, typename UnlockCb, typename DisplayCb>
    void setVideoCallbacks(LockCb&& lock, UnlockCb&& unlock, DisplayCb&& display)
1083
    {
1084 1085 1086 1087 1088
        static_assert(signature_match<LockCb, void*(void**)>::value, "Mismatched lock callback signature");
        static_assert(signature_match_or_nullptr<UnlockCb, void(void*, void *const *)>::value, "Mismatched unlock callback signature");
        static_assert(signature_match_or_nullptr<DisplayCb, void(void*)>::value, "Mismatched lock callback signature");

        libvlc_video_set_callbacks(*this,
1089 1090 1091
                CallbackWrapper<(unsigned int)CallbackIdx::VideoLock, libvlc_video_lock_cb>::wrap( *m_callbacks, std::forward<LockCb>( lock ) ),
                CallbackWrapper<(unsigned int)CallbackIdx::VideoUnlock, libvlc_video_unlock_cb>::wrap( *m_callbacks, std::forward<UnlockCb>( unlock ) ),
                CallbackWrapper<(unsigned int)CallbackIdx::VideoDisplay, libvlc_video_display_cb>::wrap( *m_callbacks, std::forward<DisplayCb>( display ) ),
1092 1093
                // We will receive the pointer as a void*, we need to offset the value *now*, otherwise we'd get
                // a shifted value, resulting in an empty callback array.
1094
                m_callbacks.get() );
1095
    }
1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112

    /**
     * Set decoded video chroma and dimensions. This only works in
     * combination with MediaPlayer::setCallbacks() , and is mutually exclusive
     * with MediaPlayer::setFormatCallbacks() .
     *
     * \param chroma  a four-characters string identifying the chroma (e.g.
     * "RV32" or "YUYV")
     *
     * \param width  pixel width
     *
     * \param height  pixel height
     *
     * \param pitch  line pitch (in bytes)
     *
     * \version LibVLC 1.1.1 or later
     */
1113 1114
    void setVideoFormat(const std::string& chroma, unsigned width, unsigned height, unsigned pitch)
    {
1115
        libvlc_video_set_format(*this, chroma.c_str(), width, height, pitch);
1116
    }
1117 1118 1119 1120 1121

    /**
     * Set decoded video chroma and dimensions. This only works in
     * combination with MediaPlayer::setCallbacks() .
     *
1122 1123 1124 1125 1126 1127 1128
     * \param setup  callback to lock video memory (must not be nullptr)
     *              Expected prototype is uint32_t(char *chroma,       // Must be filled with the required fourcc
     *                                              unsigned *width,   // Must be filled with the required width
     *                                              unsigned *height,  // Must be filled with the required height
     *                                              unsigned *pitches, // Must be filled with the required pitch for each plane
     *                                              unsigned *lines);  // Must be filled with the required number of lines for each plane
     *              The return value reprensent the amount of pictures to create in a pool. 0 to indicate an error
1129
     *
1130 1131
     * \param cleanup  callback to release any allocated resources (or nullptr)
     *                 Expected prototype is void()
1132 1133 1134
     *
     * \version LibVLC 2.0.0 or later
     */
1135 1136
    template <typename FormatCb, typename CleanupCb>
    void setVideoFormatCallbacks(FormatCb&& setup, CleanupCb&& cleanup)
1137
    {
1138 1139 1140 1141 1142
        static_assert(signature_match<FormatCb, uint32_t(char*, uint32_t*, uint32_t*, uint32_t*, uint32_t*)>::value,
                      "Unmatched prototype for format callback" );
        static_assert(signature_match_or_nullptr<CleanupCb, void()>::value, "Unmatched prototype for cleanup callback");

        libvlc_video_set_format_callbacks(*this,
1143 1144
                CallbackWrapper<(unsigned int)CallbackIdx::VideoFormat, libvlc_video_format_cb>::wrap( *m_callbacks, std::forward<FormatCb>( setup ) ),
                CallbackWrapper<(unsigned int)CallbackIdx::VideoCleanup, libvlc_video_cleanup_cb>::wrap( *m_callbacks, std::forward<CleanupCb>( cleanup ) ) );
1145
    }
1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161

    /**
     * Enable or disable key press events handling, according to the LibVLC
     * hotkeys configuration. By default and for historical reasons, keyboard
     * events are handled by the LibVLC video widget.
     *
     * \note On X11, there can be only one subscriber for key press and mouse
     * click events per window. If your application has subscribed to those
     * events for the X window ID of the video widget, then LibVLC will not
     * be able to handle key presses and mouse clicks in any case.
     *
     * \warning This function is only implemented for X11 and Win32 at the
     * moment.
     *
     * \param on  true to handle key press events, false to ignore them.
     */
1162
    void setKeyInput(bool enable)
1163
    {
1164
        libvlc_video_set_key_input(*this, (int)enable);
1165
    }
1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178

    /**
     * Enable or disable mouse click events handling. By default, those
     * events are handled. This is needed for DVD menus to work, as well as a
     * few video filters such as "puzzle".
     *
     * \see MediaPlayer::setKeyInput() .
     *
     * \warning This function is only implemented for X11 and Win32 at the
     * moment.
     *
     * \param on  true to handle mouse click events, false to ignore them.
     */
1179
    void setMouseInput(bool enable)
1180
    {
1181
        libvlc_video_set_mouse_input(*this, (int)enable);
1182
    }
1183 1184 1185 1186 1187 1188 1189 1190 1191 1192

    /**
     * Get the pixel dimensions of a video.
     *
     * \param num  number of the video (starting from, and most commonly 0)
     *
     * \param px  pointer to get the pixel width [OUT]
     *
     * \param py  pointer to get the pixel height [OUT]
     */
1193
    bool size(unsigned num, unsigned * px, unsigned * py)
1194
    {
1195
        return libvlc_video_get_size( *this, num, px, py ) == 0;
1196
    }
1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221

    /**
     * Get the mouse pointer coordinates over a video. Coordinates are
     * expressed in terms of the decoded video resolution, in terms of pixels
     * on the screen/viewport (to get the latter, you can query your
     * windowing system directly).
     *
     * Either of the coordinates may be negative or larger than the
     * corresponding dimension of the video, if the cursor is outside the
     * rendering area.
     *
     * \warning The coordinates may be out-of-date if the pointer is not
     * located on the video rendering area. LibVLC does not track the pointer
     * if it is outside of the video widget.
     *
     * \note LibVLC does not support multiple pointers (it does of course
     * support multiple input devices sharing the same pointer) at the
     * moment.
     *
     * \param num  number of the video (starting from, and most commonly 0)
     *
     * \param px  pointer to get the abscissa [OUT]
     *
     * \param py  pointer to get the ordinate [OUT]
     */
1222
    bool cursor(unsigned num, int * px, int * py)
1223
    {
1224
        return libvlc_video_get_cursor( *this, num, px, py ) == 0;
1225
    }
1226 1227 1228 1229 1230 1231 1232

    /**
     * Get the current video scaling factor. See also MediaPlayer::setScale() .
     *
     * \return the currently configured zoom factor, or 0. if the video is
     * set to fit to the output window/drawable automatically.
     */
1233 1234
    float scale()
    {
1235
        return libvlc_video_get_scale(*this);
1236
    }
1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247

    /**
     * Set the video scaling factor. That is the ratio of the number of
     * pixels on screen to the number of pixels in the original decoded video
     * in each dimension. Zero is a special value; it will adjust the video
     * to the output window/drawable (in windowed mode) or the entire screen.
     *
     * Note that not all video outputs support scaling.
     *
     * \param f_factor  the scaling factor, or zero
     */
1248 1249
    void setScale(float f_factor)
    {
1250
        libvlc_video_set_scale(*this, f_factor);
1251
    }
1252 1253 1254 1255

    /**
     * Get current video aspect ratio.
     *
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
1256
     * \return the video aspect ratio or an empty string if unspecified.
1257
     */
1258 1259
    std::string aspectRatio()
    {
1260 1261 1262 1263
        auto str = wrapCStr( libvlc_video_get_aspect_ratio(*this) );
        if ( str == nullptr )
            return {};
        return str.get();
1264
    }
1265 1266 1267 1268

    /**
     * Set new video aspect ratio.
     *
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
1269
     * \param psz_aspect  new video aspect-ratio or empty string to reset to default
1270 1271 1272
     *
     * \note Invalid aspect ratios are ignored.
     */
1273
    void setAspectRatio( const std::string& ar )
1274
    {
1275
        libvlc_video_set_aspect_ratio( *this, ar.size() > 0 ? ar.c_str() : nullptr );
1276
    }
1277 1278 1279 1280 1281 1282

    /**
     * Get current video subtitle.
     *
     * \return the video subtitle selected, or -1 if none
     */
1283 1284
    int spu()
    {
1285
        return libvlc_video_get_spu(*this);
1286
    }
1287 1288 1289 1290 1291 1292

    /**
     * Get the number of available video subtitles.
     *
     * \return the number of available video subtitles
     */
1293 1294
    int spuCount()
    {
1295
        return libvlc_video_get_spu_count(*this);
1296
    }
1297 1298 1299 1300 1301 1302

    /**
     * Get the description of available video subtitles.
     *
     * \return list containing description of available video subtitles
     */
1303 1304
    std::vector<TrackDescription> spuDescription()
    {
1305
        libvlc_track_description_t* result = libvlc_video_get_spu_description( *this );
1306 1307
        return getTracksDescription( result );
    }
1308 1309 1310 1311 1312 1313 1314 1315 1316

    /**
     * Set new video subtitle.
     *
     * \param i_spu  video subtitle track to select (i_id from track
     * description)
     *
     * \return 0 on success, -1 if out of range
     */
1317 1318
    int setSpu(int i_spu)
    {
1319
        return libvlc_video_set_spu(*this, i_spu);
1320
    }
1321

1322
#if LIBVLC_VERSION_INT < LIBVLC_VERSION(3, 0, 0, 0)
1323 1324 1325 1326 1327
    /**
     * Set new video subtitle file.
     *
     * \param psz_subtitle  new video subtitle file
     */
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
1328
    bool setSubtitleFile(const std::string& psz_subtitle)
1329
    {
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
1330
        return libvlc_video_set_subtitle_file(*this, psz_subtitle.c_str()) != 0;
1331
    }
1332
#endif
1333 1334 1335 1336 1337 1338 1339 1340 1341 1342

    /**
     * Get the current subtitle delay. Positive values means subtitles are
     * being displayed later, negative values earlier.
     *
     * \return time (in microseconds) the display of subtitles is being
     * delayed
     *
     * \version LibVLC 2.0.0 or later
     */
1343 1344
    int64_t spuDelay()
    {
1345
        return libvlc_video_get_spu_delay(*this);
1346
    }
1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362

    /**
     * Set the subtitle delay. This affects the timing of when the subtitle
     * will be displayed. Positive values result in subtitles being displayed
     * later, while negative values will result in subtitles being displayed
     * earlier.
     *
     * The subtitle delay will be reset to zero each time the media changes.
     *
     * \param i_delay  time (in microseconds) the display of subtitles should
     * be delayed
     *
     * \return 0 on success, -1 on error
     *
     * \version LibVLC 2.0.0 or later
     */
1363 1364
    int setSpuDelay(int64_t i_delay)
    {
1365
        return libvlc_video_set_spu_delay(*this, i_delay);
1366
    }
1367 1368 1369 1370 1371 1372

    /**
     * Get the description of available titles.
     *
     * \return list containing description of available titles
     */
1373
#if LIBVLC_VERSION_INT < LIBVLC_VERSION(3, 0, 0, 0)
1374 1375
    std::vector<TrackDescription> titleDescription()
    {
1376
        libvlc_track_description_t* result = libvlc_video_get_title_description( *this );
1377 1378
        return getTracksDescription( result );
    }
1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392
#else
    std::vector<TitleDescription> titleDescription()
    {
        libvlc_title_description_t **titles;
        int nbTitles = libvlc_media_player_get_full_title_descriptions( *this, &titles);
        auto cleanupCb = [nbTitles]( libvlc_title_description_t** ts) {
            libvlc_title_descriptions_release( ts, nbTitles );
        };

        std::vector<TitleDescription> res;

        if ( nbTitles < 1 )
            return res;

1393 1394
        std::unique_ptr<libvlc_title_description_t*[], decltype(cleanupCb)> ptr( titles, cleanupCb );

1395 1396
        for ( int i = 0; i < nbTitles; ++i )
            res.emplace_back( ptr[i] );
1397
        return res;
1398 1399
    }
#endif
1400 1401 1402 1403 1404 1405

    /**
     * Get the description of available chapters for specific title.
     *
     * \param i_title  selected title
     *
1406
     * \return list containing description of available chapters for title
1407 1408
     * i_title
     */
1409
#if LIBVLC_VERSION_INT < LIBVLC_VERSION(3, 0, 0, 0)
1410 1411
    std::vector<TrackDescription> chapterDescription(int i_title)
    {
1412
        libvlc_track_description_t* result = libvlc_video_get_chapter_description( *this, i_title );
1413 1414
        return getTracksDescription( result );
    }
1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428
#else
    std::vector<ChapterDescription> chapterDescription(int i_title)
    {
        libvlc_chapter_description_t **chapters;
        int nbChapters = libvlc_media_player_get_full_chapter_descriptions( *this, i_title, &chapters );
        auto cleanupCb = [nbChapters](libvlc_chapter_description_t** cs) {
            libvlc_chapter_descriptions_release( cs, nbChapters );
        };

        std::vector<ChapterDescription> res;

        if ( nbChapters < 1 )
            return res;

1429 1430
        std::unique_ptr<libvlc_chapter_description_t*[], decltype(cleanupCb)> ptr( chapters, cleanupCb );

1431 1432
        for ( int i = 0; i < nbChapters; ++i )
            res.emplace_back( ptr[i] );
1433
        return res;
1434 1435
    }
#endif
1436

1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491