[vlc-commits] [Git][videolan/libvlcpp][master] 6 commits: EventManager: Expose new track events
Hugo Beauzée-Luyssen
gitlab at videolan.org
Fri Jun 12 12:32:25 CEST 2020
Hugo Beauzée-Luyssen pushed to branch master at VideoLAN / libvlcpp
Commits:
504fdbbd by Hugo Beauzée-Luyssen at 2020-06-12T11:25:15+02:00
EventManager: Expose new track events
- - - - -
f765e5a0 by Hugo Beauzée-Luyssen at 2020-06-12T11:29:40+02:00
structures: Expose new MediaTrack fields
- - - - -
569e9956 by Hugo Beauzée-Luyssen at 2020-06-12T11:31:16+02:00
structures: Use nullptr instead of NULL
- - - - -
7b07a125 by Hugo Beauzée-Luyssen at 2020-06-12T11:52:17+02:00
structures: Expose TrackList
- - - - -
5d3887a9 by Hugo Beauzée-Luyssen at 2020-06-12T11:52:25+02:00
Media: Expose new track listing API
- - - - -
1a68132a by Hugo Beauzée-Luyssen at 2020-06-12T11:55:08+02:00
MediaPlayer: Expose new track listing API
- - - - -
4 changed files:
- vlcpp/EventManager.hpp
- vlcpp/Media.hpp
- vlcpp/MediaPlayer.hpp
- vlcpp/structures.hpp
Changes:
=====================================
vlcpp/EventManager.hpp
=====================================
@@ -743,7 +743,79 @@ class MediaPlayerEventManager : public EventManager
});
}
-#if LIBVLC_VERSION_INT >= LIBVLC_VERSION(3, 0, 0, 0)
+#if LIBVLC_VERSION_INT >= LIBVLC_VERSION(4, 0, 0, 0)
+ /**
+ * \brief onESAdded Registers an event called when an elementary stream get added
+ * \param f A std::function<void(libvlc_track_type_t, int)> (or an equivalent Callable type)
+ * libvlc_track_type_t: The new track type
+ * int: the new track index
+ */
+ template <typename Func>
+ RegisteredEvent onESAdded( Func&& f )
+ {
+ //FIXME: Expose libvlc_track_type_t as an enum class
+ EXPECT_SIGNATURE(void(libvlc_track_type_t, const std::string&));
+ return handle( libvlc_MediaPlayerESAdded, std::forward<Func>( f ), [](const libvlc_event_t* e, void* data)
+ {
+ auto callback = static_cast<DecayPtr<Func>>( data );
+ (*callback)( e->u.media_player_es_changed.i_type,
+ std::string{ e->u.media_player_es_changed.psz_id } );
+ });
+ }
+
+ /**
+ * \brief onESDeleted Registers an event called when an elementary stream get deleted
+ * \param f A std::function<void(libvlc_track_type_t, int)> (or an equivalent Callable type)
+ * libvlc_track_type_t: The track type
+ * int: the track index
+ */
+ template <typename Func>
+ RegisteredEvent onESDeleted( Func&& f )
+ {
+ EXPECT_SIGNATURE(void(libvlc_track_type_t, const std::string&));
+ return handle( libvlc_MediaPlayerESDeleted, std::forward<Func>( f ), [](const libvlc_event_t* e, void* data)
+ {
+ auto callback = static_cast<DecayPtr<Func>>( data );
+ (*callback)( e->u.media_player_es_changed.i_type,
+ std::string{ e->u.media_player_es_changed.psz_id } );
+ });
+ }
+
+ /**
+ * \brief onESSelected Registers an event called when an elementary stream get selected
+ * \param f A std::function<void(libvlc_track_type_t, int)> (or an equivalent Callable type)
+ * libvlc_track_type_t: The track type
+ * int: the track index
+ */
+ template <typename Func>
+ RegisteredEvent onESSelected( Func&& f )
+ {
+ EXPECT_SIGNATURE(void(libvlc_track_type_t, const std::string&, const std::string&));
+ return handle( libvlc_MediaPlayerESSelected, std::forward<Func>( f ), [](const libvlc_event_t* e, void* data)
+ {
+ auto callback = static_cast<DecayPtr<Func>>( data );
+ (*callback)( e->u.media_player_es_changed.i_type,
+ std::string{ e->u.media_player_es_selection_changed.psz_selected_id },
+ std::string{ e->u.media_player_es_selection_changed.psz_unselected_id } );
+ });
+ }
+
+ /**
+ * \brief onAudioDevice Registers an event called when the current audio output device changes
+ * \param f A std::function<void(std::string)> (or an equivalent Callable type)
+ * The provided string is the new current audio device.
+ */
+ template <typename Func>
+ RegisteredEvent onAudioDevice( Func&& f )
+ {
+ EXPECT_SIGNATURE(void(std::string));
+ return handle( libvlc_MediaPlayerAudioDevice, std::forward<Func>( f ), [](const libvlc_event_t* e, void* data)
+ {
+ auto callback = static_cast<DecayPtr<Func>>( data );
+ (*callback)( e->u.media_player_audio_device.device );
+ });
+ }
+#elif LIBVLC_VERSION_INT >= LIBVLC_VERSION(3, 0, 0, 0)
/**
* \brief onESAdded Registers an event called when an elementary stream get added
* \param f A std::function<void(libvlc_track_type_t, int)> (or an equivalent Callable type)
=====================================
vlcpp/Media.hpp
=====================================
@@ -35,6 +35,7 @@ namespace VLC
class MediaEventManager;
class Instance;
class MediaList;
+class TrackList;
class Media : protected CallbackOwner<4>, public Internal<libvlc_media_t>
{
@@ -653,6 +654,15 @@ public:
*
* \return a vector containing all tracks
*/
+#if LIBVLC_VERSION_INT >= LIBVLC_VERSION(4, 0, 0, 0)
+ std::shared_ptr<TrackList> tracks( libvlc_track_type_t type )
+ {
+ auto trackList = libvlc_media_get_tracklist( *this, type );
+ if ( trackList == nullptr )
+ return nullptr;
+ return std::make_shared<TrackList>( trackList );
+ }
+#elif #if LIBVLC_VERSION_INT >= LIBVLC_VERSION(3, 0, 0, 0)
std::vector<MediaTrack> tracks()
{
libvlc_media_track_t** tracks;
@@ -667,6 +677,7 @@ public:
libvlc_media_tracks_release( tracks, nbTracks );
return res;
}
+#endif
std::shared_ptr<MediaList> subitems()
{
=====================================
vlcpp/MediaPlayer.hpp
=====================================
@@ -40,6 +40,7 @@ class Instance;
class Media;
class MediaPlayerEventManager;
class TrackDescription;
+class TrackList;
///
/// \brief The MediaPlayer class exposes libvlc_media_player_t functionnalities
@@ -1840,6 +1841,18 @@ public:
#endif
+#if LIBVLC_VERSION_INT >= LIBVLC_VERSION(3, 0, 0, 0)
+
+ std::shared_ptr<TrackList> tracks( libvlc_track_type_t type )
+ {
+ auto trackList = libvlc_media_player_get_tracklist( *this, type );
+ if ( trackList == nullptr )
+ return nullptr;
+ return std::make_shared<TrackList>( trackList );
+ }
+
+#endif
+
private:
std::vector<TrackDescription> getTracksDescription( libvlc_track_description_t* tracks ) const
{
=====================================
vlcpp/structures.hpp
=====================================
@@ -75,13 +75,13 @@ public:
explicit ModuleDescription( libvlc_module_description_t* c )
{
- if ( c->psz_name != NULL )
+ if ( c->psz_name != nullptr )
m_name = c->psz_name;
- if ( c->psz_shortname != NULL )
+ if ( c->psz_shortname != nullptr )
m_shortname = c->psz_shortname;
- if ( c->psz_longname != NULL )
+ if ( c->psz_longname != nullptr )
m_longname = c->psz_longname;
- if ( c->psz_help != NULL )
+ if ( c->psz_help != nullptr )
m_help = c->psz_help;
}
@@ -341,6 +341,28 @@ public:
}
#endif
+#if LIBVLC_VERSION_INT >= LIBVLC_VERSION(3, 0, 0, 0)
+ const std::string& idStr() const
+ {
+ return m_idStr;
+ }
+
+ bool idStable() const
+ {
+ return m_idStable;
+ }
+
+ const std::string& name() const
+ {
+ return m_name;
+ }
+
+ bool selected() const
+ {
+ return m_selected;
+ }
+#endif
+
////////////////////////////////////////////////////////////////////////////
// Subtitles specific
////////////////////////////////////////////////////////////////////////////
@@ -360,11 +382,19 @@ public:
, m_profile( c->i_profile )
, m_level( c->i_level )
, m_bitrate( c->i_bitrate )
+#if LIBVLC_VERSION_INT >= LIBVLC_VERSION(4, 0, 0, 0)
+ , m_idStable( c->id_stable )
+ , m_selected( c->selected )
+#endif
{
- if ( c->psz_language != NULL )
+ if ( c->psz_language != nullptr )
m_language = c->psz_language;
- if ( c->psz_description != NULL )
+ if ( c->psz_description != nullptr )
m_description = c->psz_description;
+ if ( c->psz_id != nullptr )
+ m_idStr = c->psz_id;
+ if ( c->psz_name )
+ m_name = c->psz_name;
switch ( c->i_type )
{
case libvlc_track_audio:
@@ -387,7 +417,7 @@ public:
break;
case libvlc_track_text:
m_type = Subtitle;
- if ( c->subtitle->psz_encoding != NULL )
+ if ( c->subtitle->psz_encoding != nullptr )
m_encoding = c->subtitle->psz_encoding;
break;
case libvlc_track_unknown:
@@ -420,6 +450,12 @@ private:
#if LIBVLC_VERSION_INT >= LIBVLC_VERSION(3, 0, 0, 0)
Orientation m_orientation;
Projection m_projection;
+#endif
+#if LIBVLC_VERSION_INT >= LIBVLC_VERSION(4, 0, 0, 0)
+ std::string m_idStr;
+ bool m_idStable;
+ std::string m_name;
+ bool m_selected;
#endif
// Subtitles
std::string m_encoding;
@@ -449,9 +485,9 @@ public:
explicit AudioOutputDescription( libvlc_audio_output_t* c )
{
- if ( c->psz_name != NULL )
+ if ( c->psz_name != nullptr )
m_name = c->psz_name;
- if ( c->psz_description != NULL )
+ if ( c->psz_description != nullptr )
m_description = c->psz_description;
}
@@ -481,9 +517,9 @@ class AudioOutputDeviceDescription
explicit AudioOutputDeviceDescription( libvlc_audio_output_device_t* d )
{
- if ( d->psz_device != NULL )
+ if ( d->psz_device != nullptr )
m_device = d->psz_device;
- if ( d->psz_description != NULL )
+ if ( d->psz_description != nullptr )
m_device = d->psz_description;
}
@@ -698,9 +734,9 @@ class RendererDiscovererDescription
public:
explicit RendererDiscovererDescription( const libvlc_rd_description_t* d )
{
- if (d->psz_name != NULL)
+ if (d->psz_name != nullptr)
m_name = d->psz_name;
- if (d->psz_longname != NULL)
+ if (d->psz_longname != nullptr)
m_longName = d->psz_longname;
}
@@ -721,5 +757,28 @@ private:
#endif
+#if LIBVLC_VERSION_INT >= LIBVLC_VERSION(4, 0, 0, 0)
+
+class TrackList : public Internal<libvlc_media_tracklist_t>
+{
+public:
+ explicit TrackList( libvlc_media_tracklist_t *trackList )
+ : Internal{ trackList, libvlc_media_tracklist_delete }
+ {
+ }
+
+ size_t count() const
+ {
+ return libvlc_media_tracklist_count( *this );
+ }
+
+ MediaTrack at( size_t index ) const
+ {
+ return MediaTrack{ libvlc_media_tracklist_at( *this, index ) };
+ }
+};
+
+#endif
+
} // namespace VLC
#endif
View it on GitLab: https://code.videolan.org/videolan/libvlcpp/-/compare/a490f04156224277e28a3a4131125a32b798e84d...1a68132a15dbaf3690ac5855d92b49bbc3e0e348
--
View it on GitLab: https://code.videolan.org/videolan/libvlcpp/-/compare/a490f04156224277e28a3a4131125a32b798e84d...1a68132a15dbaf3690ac5855d92b49bbc3e0e348
You're receiving this email because of your account on code.videolan.org.
More information about the vlc-commits
mailing list