-
Notifications
You must be signed in to change notification settings - Fork 40
Expand file tree
/
Copy pathMediaPlayer.hpp
More file actions
1983 lines (1831 loc) · 61 KB
/
MediaPlayer.hpp
File metadata and controls
1983 lines (1831 loc) · 61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
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
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
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
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*****************************************************************************
* MediaPlayer.hpp: MediaPlayer API
*****************************************************************************
* Copyright © 2015 libvlcpp authors & VideoLAN
*
* Authors: Alexey Sokolov <alexey+vlc@asokolov.org>
* Hugo Beauzée-Luyssen <hugo@beauzee.fr>
*
* 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
#include <array>
#include <string>
#include <vector>
#include <memory>
#include "common.hpp"
namespace VLC
{
class AudioOutputDeviceDescription;
class Equalizer;
class Instance;
class Media;
class MediaPlayerEventManager;
class TrackDescription;
class TrackList;
///
/// \brief The MediaPlayer class exposes libvlc_media_player_t functionnalities
///
class MediaPlayer : private CallbackOwner<13>, public Internal<libvlc_media_player_t>
{
private:
enum class CallbackIdx : unsigned int
{
AudioPlay,
AudioPause,
AudioResume,
AudioFlush,
AudioDrain,
AudioVolume,
AudioSetup,
AudioCleanup,
VideoLock,
VideoUnlock,
VideoDisplay,
VideoFormat,
VideoCleanup,
};
public:
#if LIBVLC_VERSION_INT >= LIBVLC_VERSION(4, 0, 0, 0)
enum class DeinterlaceState : signed char
{
Auto = -1,
Disabled = 0,
Enabled = 1
};
#endif
/**
* 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
*/
bool operator==(const MediaPlayer& another) const
{
return m_obj == another.m_obj;
}
/**
* Create an empty Media Player object
*
* \param p_libvlc_instance the libvlc instance in which the Media
* Player should be created.
*/
MediaPlayer( const Instance& instance )
: Internal{ libvlc_media_player_new( getInternalPtr<libvlc_instance_t>( instance ) ),
libvlc_media_player_release }
{
}
#if LIBVLC_VERSION_INT >= LIBVLC_VERSION(4, 0, 0, 0)
/**
* Create a Media Player object from a Media
*
* \param p_md the media. Afterwards the p_md can be safely destroyed.
*/
MediaPlayer( const Instance& inst, Media& md )
: Internal{ libvlc_media_player_new_from_media(
getInternalPtr<libvlc_instance_t>( inst ),
getInternalPtr<libvlc_media_t>( md ) ),
libvlc_media_player_release }
{
}
#else
/**
* Create a Media Player object from a Media
*
* \param p_md the media. Afterwards the p_md can be safely destroyed.
*/
MediaPlayer( Media& md )
: Internal{ libvlc_media_player_new_from_media(
getInternalPtr<libvlc_media_t>( md ) ),
libvlc_media_player_release }
{
}
#endif
/**
* Create an empty VLC MediaPlayer instance.
*
* Calling any method on such an instance is undefined.
*/
MediaPlayer() = default;
/**
* 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.
*/
void setMedia(Media& md)
{
libvlc_media_player_set_media( *this, getInternalPtr<libvlc_media_t>( md ) );
}
/**
* Get the media used by the media_player.
*
* \return the media associated with p_mi, or a nullptr shared_ptr if no
* media is associated
*/
MediaPtr media()
{
auto media = libvlc_media_player_get_media(*this);
if ( media == nullptr )
return nullptr;
return std::make_shared<Media>( media, false );
}
/**
* Get the Event Manager from which the media player send event.
*
* \return the event manager associated with p_mi
*/
MediaPlayerEventManager& eventManager()
{
if ( m_eventManager == nullptr )
{
libvlc_event_manager_t* obj = libvlc_media_player_event_manager( *this );
m_eventManager = std::make_shared<MediaPlayerEventManager>( obj, *this );
}
return *m_eventManager;
}
/**
* \return true if the media player is playing, 0 otherwise
*/
bool isPlaying()
{
return libvlc_media_player_is_playing(*this) != 0;
}
/**
* @brief play Start playback
*
* If playback was already started, this method has no effect
*/
bool play()
{
return libvlc_media_player_play(*this) == 0;
}
/**
* Pause or resume (no effect if there is no media)
*
* \param do_pause play/resume if true, pause if false
*
* \version LibVLC 1.1.1 or later
*/
void setPause(bool pause)
{
libvlc_media_player_set_pause(*this, pause);
}
/**
* @brief pause Toggle pause (no effect if there is no media)
*/
void pause()
{
libvlc_media_player_pause(*this);
}
#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
/**
* @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.
*/
void stop()
{
libvlc_media_player_stop(*this);
}
#endif
/**
* 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
* VLCOpenGLVideoViewEmbedding protocol: VLCOpenGLVideoViewEmbedding <NSObject>
*
* 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.
*/
void setNsobject(void* drawable)
{
libvlc_media_player_set_nsobject(*this, drawable);
}
/**
* Get the NSView handler previously set with MediaPlayer::setNsobject()
* .
*
* \return the NSView handler or 0 if none where set
*/
void* nsobject()
{
return libvlc_media_player_get_nsobject(*this);
}
/**
* 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
*/
void setXwindow(uint32_t drawable)
{
libvlc_media_player_set_xwindow(*this, drawable);
}
/**
* 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.
*/
uint32_t xwindow()
{
return libvlc_media_player_get_xwindow(*this);
}
/**
* 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
*/
void setHwnd(void * drawable)
{
libvlc_media_player_set_hwnd(*this, drawable);
}
/**
* 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.
*
* \return a window handle or nullptr if there are none.
*/
void* hwnd()
{
return libvlc_media_player_get_hwnd(*this);
}
/**
* Get the current movie length (in ms).
*
* \return the movie length (in ms), or -1 if there is no media.
*/
libvlc_time_t length()
{
return libvlc_media_player_get_length(*this);
}
/**
* Get the current movie time (in ms).
*
* \return the movie time (in ms), or -1 if there is no media.
*/
libvlc_time_t time()
{
return libvlc_media_player_get_time(*this);
}
/**
* Set the movie time (in ms). This has no effect if no media is being
* played. Not all formats and protocols support this.
*
* \version{2.x}
* \version{3.x}
* \param i_time the movie time (in ms).
* \version{4.x}
* \param b_fast prefer fast seeking or precise seeking
*/
#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
void setTime(libvlc_time_t i_time)
{
libvlc_media_player_set_time(*this, i_time);
}
#endif
/**
* Get movie position as percentage between 0.0 and 1.0.
*
* \return movie position, or -1. in case of error
*/
float position()
{
return libvlc_media_player_get_position(*this);
}
/**
* 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.
*
* \version{2.x}
* \version{3.x}
* \param f_pos the position
* \version{4.x}
* \param b_fast prefer fast seeking or precise seeking
*/
#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
void setPosition(float f_pos)
{
libvlc_media_player_set_position(*this, f_pos);
}
#endif
/**
* Set movie chapter (if applicable).
*
* \param i_chapter chapter number to play
*/
void setChapter(int i_chapter)
{
libvlc_media_player_set_chapter(*this, i_chapter);
}
/**
* Get movie chapter.
*
* \return chapter number currently playing, or -1 if there is no media.
*/
int chapter()
{
return libvlc_media_player_get_chapter(*this);
}
/**
* Get movie chapter count
*
* \return number of chapters in movie, or -1.
*/
int chapterCount()
{
return libvlc_media_player_get_chapter_count(*this);
}
#if LIBVLC_VERSION_INT < LIBVLC_VERSION(4, 0, 0, 0)
/**
* Is the player able to play
*
* \return boolean
*/
bool willPlay()
{
return libvlc_media_player_will_play(*this) != 0;
}
#endif
/**
* Get title chapter count
*
* \param i_title title
*
* \return number of chapters in title, or -1
*/
int chapterCountForTitle(int i_title)
{
return libvlc_media_player_get_chapter_count_for_title(*this, i_title);
}
/**
* Set movie title
*
* \param i_title title number to play
*/
void setTitle(int i_title)
{
libvlc_media_player_set_title(*this, i_title);
}
/**
* Get movie title
*
* \return title number currently playing, or -1
*/
int title()
{
return libvlc_media_player_get_title(*this);
}
/**
* Get movie title count
*
* \return title number count, or -1
*/
int titleCount()
{
return libvlc_media_player_get_title_count(*this);
}
/**
* Set previous chapter (if applicable)
*/
void previousChapter()
{
libvlc_media_player_previous_chapter(*this);
}
/**
* Set next chapter (if applicable)
*/
void nextChapter()
{
libvlc_media_player_next_chapter(*this);
}
/**
* 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
*/
float rate()
{
return libvlc_media_player_get_rate(*this);
}
/**
* 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)
*/
int setRate(float rate)
{
return libvlc_media_player_set_rate(*this, rate);
}
/**
* Get current movie state
*
* \return the current state of the media player (playing, paused, ...)
*
* \see libvlc_state_t
*/
libvlc_state_t state()
{
return libvlc_media_player_get_state(*this);
}
#if LIBVLC_VERSION_INT < LIBVLC_VERSION(3, 0, 0, 0)
/**
* Get movie fps rate
*
* \return frames per second (fps) for this playing movie, or 0 if
* unspecified
*/
float fps()
{
return libvlc_media_player_get_fps(*this);
}
#endif
/**
* Get the amount of video outputs this media player has?
*
* \return the number of video outputs
*/
uint32_t hasVout()
{
return libvlc_media_player_has_vout(*this);
}
/**
* Is this media player seekable?
*
* \return true if the media player can seek
*/
bool isSeekable()
{
return libvlc_media_player_is_seekable(*this) != 0;
}
/**
* Can this media player be paused?
*
* \return true if the media player can pause
*/
bool canPause()
{
return libvlc_media_player_can_pause(*this) != 0;
}
/**
* Check if the current program is scrambled
*
* \return true if the current program is scrambled
*
* \version LibVLC 2.2.0 or later
*/
bool programScrambled()
{
return libvlc_media_player_program_scrambled(*this) != 0;
}
/**
* Display the next frame (if supported)
*/
void nextFrame()
{
libvlc_media_player_next_frame(*this);
}
/**
* Navigate through DVD Menu
*
* \param navigate the Navigation mode
*
* \version libVLC 2.0.0 or later
*/
void navigate(unsigned navigate)
{
libvlc_media_player_navigate(*this, navigate);
}
/**
* 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
*/
void setVideoTitleDisplay(libvlc_position_t position, unsigned int timeout)
{
libvlc_media_player_set_video_title_display(*this, position, timeout);
}
/**
* Toggle fullscreen status on non-embedded video outputs.
*
* \warning The same limitations applies to this function as to
* MediaPlayer::setFullscreen() .
*/
void toggleFullscreen()
{
libvlc_toggle_fullscreen(*this);
}
/**
* 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
*/
void setFullscreen(bool fullscreen)
{
libvlc_set_fullscreen( *this, fullscreen );
}
/**
* Get current fullscreen status.
*
* \return the fullscreen status (boolean)
*/
bool fullscreen()
{
return libvlc_get_fullscreen(*this) != 0;
}
#if LIBVLC_VERSION_INT < LIBVLC_VERSION(3, 0, 0, 0)
/**
* Toggle teletext transparent status on video output.
*/
void toggleTeletext()
{
libvlc_toggle_teletext(*this);
}
#endif
/**
* 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.
*
* \param equalizer The equalizer to be used by this media player
*
* \return true on success, false otherwise
*
* \version LibVLC 2.2.0 or later
*/
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()
{
return libvlc_media_player_set_equalizer( *this, nullptr ) == 0;
}
/**
* Set callbacks and private data for decoded audio. Use
* MediaPlayer::setFormat() or MediaPlayer::setFormatCallbacks() to configure the
* decoded audio format.
*
* \param play callback to play audio samples (must not be nullptr)
* Required prototype is: void(const void *samples, unsigned count, int64_t pts)
*
* \param pause callback to pause playback (or nullptr to ignore)
* Required prototype is void(int64_t pts);
*
* \param resume callback to resume playback (or nullptr to ignore)
* Required prototype is void(int64_t pts);
*
* \param flush callback to flush audio buffers (or nullptr to ignore)
* Required prototype is void(int64_t pts);
*
* \param drain callback to drain audio buffers (or nullptr to ignore)
* * Required prototype is void();
*
* \version LibVLC 2.0.0 or later
*/
template <typename PlayCb, typename PauseCb, typename ResumeCb, typename FlushCb, typename DrainCb>
void setAudioCallbacks(PlayCb&& play, PauseCb&& pause, ResumeCb&& resume, FlushCb&& flush, DrainCb&& drain)
{
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,
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 ) ),
// 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 invalid callback array.
m_callbacks.get() );
}
/**
* Set callbacks and private data for decoded audio. Use
* MediaPlayer::setFormat() or MediaPlayer::setFormatCallbacks() to configure the
* decoded audio format.
*
* \param set_volume callback to apply audio volume, or nullptr to apply
* volume in software
* Expected prototype is void(float volume, bool mute)
*
* \version LibVLC 2.0.0 or later
*/
template <typename VolumeCb>
void setVolumeCallback(VolumeCb&& func)
{
static_assert(signature_match_or_nullptr<VolumeCb, void(float, bool)>::value, "Mismatched set volume callback");
libvlc_audio_set_volume_callback(*this,
CallbackWrapper<(unsigned int)CallbackIdx::AudioVolume, libvlc_audio_set_volume_cb>::wrap( this, std::forward<VolumeCb>( func ) ) );
}
/**
* Set decoded audio format. This only works in combination with
* MediaPlayer::setCallbacks() .
*
* \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
*
* \param cleanup callback to release any allocated resources (or nullptr)
* Expected prototype is void()
*
* \version LibVLC 2.0.0 or later
*/
template <typename SetupCb, typename CleanupCb>
void setAudioFormatCallbacks(SetupCb&& setup, CleanupCb&& cleanup)
{
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,
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 ) ) );
}
/**
* 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
*/
void setAudioFormat(const std::string& format, unsigned rate, unsigned channels)
{
libvlc_audio_set_format(*this, format.c_str(), rate, channels);
}
/**
* 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.
*
* \param name name of audio output, use psz_name of
*
* \see AudioOutputDescription
*
* \return 0 if function succeded, -1 on error
*/
int setAudioOutput(const std::string& name)
{
return libvlc_audio_output_set(*this, name.c_str());
}
/**
* 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.
*/
std::vector<AudioOutputDeviceDescription> outputDeviceEnum()
{
auto devices = libvlc_audio_output_device_enum(*this);
if ( devices == nullptr )
return {};
std::vector<AudioOutputDeviceDescription> res;
std::unique_ptr<libvlc_audio_output_device_t, decltype(&libvlc_audio_output_device_list_release)>
devicesPtr( devices, libvlc_audio_output_device_list_release);
for ( auto* p = devices; p != nullptr; p = p->p_next )
res.emplace_back( p );
return res;
}
/**
* 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).
*/
#if LIBVLC_VERSION_INT >= LIBVLC_VERSION(4, 0, 0, 0)
void outputDeviceSet(const std::string& device_id)
{
libvlc_audio_output_device_set(*this, device_id.c_str());
}
#else
void outputDeviceSet(const std::string& module, const std::string& device_id)
{
libvlc_audio_output_device_set(*this, module.c_str(), device_id.c_str());
}
void outputDeviceSet(const std::string& device_id)
{
libvlc_audio_output_device_set(*this, nullptr, device_id.c_str());
}
#endif
/**
* 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() .
*/
void toggleMute()
{
libvlc_audio_toggle_mute(*this);
}
/**
* Get current mute status.
*/
bool mute()
{
return libvlc_audio_get_mute( *this ) == 1;
}
/**
* 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.
*/
void setMute(bool mute)
{
libvlc_audio_set_mute( *this, (int)mute );
}
/**
* Get current software audio volume.
*
* \return the software volume in percents (0 = mute, 100 = nominal /
* 0dB)
*/
int volume()
{
return libvlc_audio_get_volume(*this);
}
/**
* Set current software audio volume.
*
* \param i_volume the volume in percents (0 = mute, 100 = 0dB)
*/
bool setVolume(int i_volume)
{
return libvlc_audio_set_volume(*this, i_volume) == 0;
}
#if LIBVLC_VERSION_INT < LIBVLC_VERSION(4, 0, 0, 0)
/**
* Get number of available audio tracks.
*
* \return the number of available audio tracks (int), or -1 if
* unavailable
*/
int audioTrackCount()