[vlc-commits] [Git][videolan/libvlcpp][master] 4 commits: Don't expose TrackList anymore

Hugo Beauzée-Luyssen gitlab at videolan.org
Wed Jun 17 10:40:31 CEST 2020



Hugo Beauzée-Luyssen pushed to branch master at VideoLAN / libvlcpp


Commits:
7eb7e720 by Hugo Beauzée-Luyssen at 2020-06-16T10:34:49+02:00
Don't expose TrackList anymore

- - - - -
56e36380 by Hugo Beauzée-Luyssen at 2020-06-16T11:46:03+02:00
Always expose MediaTrack::Type instead of libvlc_track_type_t

- - - - -
95598551 by Hugo Beauzée-Luyssen at 2020-06-16T15:43:22+02:00
MediaTrack: Split 3.x and 4.x implementations.

The 4.x version will store a libvlc_media_track_t instead of all its
fields, which is now possible since the track structure is refcounted.
This will also allow us to provide the original tracks back to any
libvlc function that might require it.
The 3.x version will stick to copying each field to the MediaTrack class
since the original libvlc_media_track_t is released as soon as we're
done constructing a MediaTrack vector

- - - - -
eae999f6 by Hugo Beauzée-Luyssen at 2020-06-17T10:35:29+02:00
MediaPlayer: Expose libvlc_media_player_select_tracks

- - - - -


5 changed files:

- test/main.cpp
- vlcpp/EventManager.hpp
- vlcpp/Media.hpp
- vlcpp/MediaPlayer.hpp
- vlcpp/structures.hpp


Changes:

=====================================
test/main.cpp
=====================================
@@ -136,6 +136,13 @@ int main(int ac, char** av)
 
     std::this_thread::sleep_for( std::chrono::milliseconds(500) );
 
+#if LIBVLC_VERSION_INT >= LIBVLC_VERSION(4, 0, 0, 0)
+    auto tracks = mp.tracks( VLC::MediaTrack::Type::Video );
+    std::cout << "Got " << tracks.size() << " tracks" << std::endl;
+    mp.selectTracks( VLC::MediaTrack::Type::Video, tracks );
+    std::this_thread::sleep_for( std::chrono::milliseconds(1000) );
+#endif
+
     // Showing that copying an object shares the associated eventmanager
     auto mp2 = mp;
     expected = true;


=====================================
vlcpp/EventManager.hpp
=====================================
@@ -746,55 +746,54 @@ class MediaPlayerEventManager : public EventManager
 #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
+         * \param f A std::function<void(MediaTrack::Type, int)> (or an equivalent Callable type)
+         *          MediaTrack::Type: 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&));
+            EXPECT_SIGNATURE(void(MediaTrack::Type, 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,
+                (*callback)( static_cast<MediaTrack::Type>( 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
+         * \param f A std::function<void(MediaTrack::Type, int)> (or an equivalent Callable type)
+         *          MediaTrack::Type: The track type
          *          int: the track index
          */
         template <typename Func>
         RegisteredEvent onESDeleted( Func&& f )
         {
-            EXPECT_SIGNATURE(void(libvlc_track_type_t, const std::string&));
+            EXPECT_SIGNATURE(void(MediaTrack::Type, 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,
+                (*callback)( static_cast<MediaTrack::Type>( 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
+         * \param f A std::function<void(MediaTrack::Type, int)> (or an equivalent Callable type)
+         *          MediaTrack::Type: 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&));
+            EXPECT_SIGNATURE(void(MediaTrack::Type, 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,
+                (*callback)( static_cast<MediaTrack::Type>( 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 } );
             });
@@ -818,53 +817,55 @@ class MediaPlayerEventManager : public EventManager
 #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)
-         *          libvlc_track_type_t: The new track type
+         * \param f A std::function<void(MediaTrack::Type, int)> (or an equivalent Callable type)
+         *          MediaTrack::Type: 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, int));
+            EXPECT_SIGNATURE(void(MediaTrack::Type, int));
             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, e->u.media_player_es_changed.i_id );
+                (*callback)( static_cast<MediaTrack::Type>( e->u.media_player_es_changed.i_type ),
+                             e->u.media_player_es_changed.i_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
+         * \param f A std::function<void(MediaTrack::Type, int)> (or an equivalent Callable type)
+         *          MediaTrack::Type: The track type
          *          int: the track index
          */
         template <typename Func>
         RegisteredEvent onESDeleted( Func&& f )
         {
-            EXPECT_SIGNATURE(void(libvlc_track_type_t, int));
+            EXPECT_SIGNATURE(void(MediaTrack::Type, int));
             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, e->u.media_player_es_changed.i_id );
+                (*callback)( static_cast<MediaTrack::Type>( e->u.media_player_es_changed.i_type ),
+                             e->u.media_player_es_changed.i_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
+         * \param f A std::function<void(MediaTrack::Type, int)> (or an equivalent Callable type)
+         *          MediaTrack::Type: The track type
          *          int: the track index
          */
         template <typename Func>
         RegisteredEvent onESSelected( Func&& f )
         {
-            EXPECT_SIGNATURE(void(libvlc_track_type_t, int));
+            EXPECT_SIGNATURE(void(MediaTrack::Type, int));
             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, e->u.media_player_es_changed.i_id );
+                (*callback)( static_cast<MediaTrack::Type>( e->u.media_player_es_changed.i_type ),
+                             e->u.media_player_es_changed.i_id );
             });
         }
 


=====================================
vlcpp/Media.hpp
=====================================
@@ -655,12 +655,20 @@ 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 )
+    std::vector<MediaTrack> tracks( MediaTrack::Type type )
     {
-        auto trackList = libvlc_media_get_tracklist( *this, type );
+        using TrackListPtr = std::unique_ptr<libvlc_media_tracklist_t,
+                                decltype(&libvlc_media_tracklist_delete)>;
+        TrackListPtr trackList{ libvlc_media_get_tracklist( *this,
+                                    static_cast<libvlc_track_type_t>( type ) ),
+                                &libvlc_media_tracklist_delete };
         if ( trackList == nullptr )
-            return nullptr;
-        return std::make_shared<TrackList>( trackList );
+            return {};
+        auto count = libvlc_media_tracklist_count( trackList.get() );
+        std::vector<MediaTrack> res{};
+        for ( auto i = 0u; i < count; ++i )
+            res.emplace_back( libvlc_media_tracklist_at( trackList.get(), i ) );
+        return res;
     }
 #elif LIBVLC_VERSION_INT >= LIBVLC_VERSION(3, 0, 0, 0)
     std::vector<MediaTrack> tracks()


=====================================
vlcpp/MediaPlayer.hpp
=====================================
@@ -1843,14 +1843,33 @@ public:
 
 #if LIBVLC_VERSION_INT >= LIBVLC_VERSION(4, 0, 0, 0)
 
-    std::shared_ptr<TrackList> tracks( libvlc_track_type_t type )
+    std::vector<MediaTrack> tracks( MediaTrack::Type type )
     {
-        auto trackList = libvlc_media_player_get_tracklist( *this, type );
+        using TrackListPtr = std::unique_ptr<libvlc_media_tracklist_t,
+                                decltype(&libvlc_media_tracklist_delete)>;
+        TrackListPtr trackList{ libvlc_media_player_get_tracklist( *this,
+                                    static_cast<libvlc_track_type_t>( type ) ),
+                                &libvlc_media_tracklist_delete };
         if ( trackList == nullptr )
-            return nullptr;
-        return std::make_shared<TrackList>( trackList );
+            return {};
+        auto count = libvlc_media_tracklist_count( trackList.get() );
+        std::vector<MediaTrack> res{};
+        for ( auto i = 0u; i < count; ++i )
+            res.emplace_back( libvlc_media_tracklist_at( trackList.get(), i ) );
+        return res;
     }
 
+    void selectTracks( MediaTrack::Type type, const std::vector<MediaTrack>& tracks )
+    {
+        std::vector<const libvlc_media_track_t*> ctracks{};
+        ctracks.reserve( tracks.size() );
+        for ( const auto& mt : tracks )
+            ctracks.push_back( mt.get() );
+        libvlc_media_player_select_tracks( *this,
+                                           static_cast<libvlc_track_type_t>( type ),
+                                           ctracks.data(),
+                                           ctracks.size() );
+    }
 #endif
 
 private:


=====================================
vlcpp/structures.hpp
=====================================
@@ -92,6 +92,312 @@ private:
     std::string m_help;
 };
 
+#if LIBVLC_VERSION_INT >= LIBVLC_VERSION(4, 0, 0, 0)
+
+///
+/// \brief The MediaTrack class describes a track
+///
+class MediaTrack : public Internal<libvlc_media_track_t>
+{
+public:
+    ///
+    /// \brief The Type enum indicates the type of a track
+    ///
+    enum class Type
+    {
+        Unknown = libvlc_track_unknown,
+        /// Audio track
+        Audio = libvlc_track_audio,
+        /// Video track
+        Video = libvlc_track_video,
+        /// Subtitle track (also called SPU sometimes)
+        Subtitle = libvlc_track_text,
+    };
+
+    ///
+    /// \brief The Orientation enum indicates the orientation of a video
+    ///
+    enum class Orientation
+    {
+        TopLeft,
+        TopRight,
+        BottomLeft,
+        BottomRight,
+        LeftTop,
+        LeftBottom,
+        RightTop,
+        RightBottom
+    };
+
+    ///
+    /// \brief The Projection enum indicates the projection of a video
+    ///
+    enum class Projection
+    {
+        Rectangular,
+        /// 360 spherical
+        Equirectangular,
+        CubemapLayoutStandard = 0x100
+    };
+
+#if !defined(_MSC_VER) || _MSC_VER >= 1900
+    constexpr static Type Unknown = Type::Unknown;
+    constexpr static Type Audio = Type::Audio;
+    constexpr static Type Video = Type::Video;
+    constexpr static Type Subtitle = Type::Subtitle;
+#else
+    const static Type Unknown = Type::Unknown;
+    const static Type Audio = Type::Audio;
+    const static Type Video = Type::Video;
+    const static Type Subtitle = Type::Subtitle;
+#endif
+
+    ///
+    /// \brief codec Returns the codec as a fourcc
+    ///
+    /// This is the fourcc will use to select a codec, but it might be an
+    /// interpretation of the original fourcc.
+    /// \see originalFourCC()
+    ///
+    uint32_t codec() const
+    {
+        return m_obj->i_codec;
+    }
+
+    ///
+    /// \brief originalFourCC Returns the fourcc as found in the file.
+    ///
+    /// VLC might chose to use a different fourcc internally.
+    /// For instance, AVC1 & H264 fourcc are (almost?) identical. VLC would
+    /// use H264 as the codec/fourcc, and store AVC1/H264 as the original fourcc
+    ///
+    uint32_t originalFourCC() const
+    {
+        return m_obj->i_original_fourcc;
+    }
+
+    ///
+    /// \brief id The track internal ID.
+    ///
+    /// This can't be assume to grow one by one monotonically.
+    ///
+    int32_t id() const
+    {
+        return m_obj->i_id;
+    }
+
+    ///
+    /// \brief type The track type
+    ///
+    /// \see MediaTrack::Type
+    ///
+    Type type() const
+    {
+        return static_cast<Type>( m_obj->i_type );
+    }
+
+    ///
+    /// \brief profile This track profile
+    ///
+    /// This might or might not be set, depending on the codec.
+    ///
+    int32_t profile() const
+    {
+        return m_obj->i_profile;
+    }
+
+    ///
+    /// \brief level This track level
+    ///
+    /// This might or might not be set, depending on the codec
+    ///
+    int32_t level() const
+    {
+        return m_obj->i_level;
+    }
+
+    ///
+    /// \brief bitrate This track bitrate, in bytes per second
+    /// \return
+    ///
+    uint32_t bitrate() const
+    {
+        return m_obj->i_bitrate;
+    }
+
+    ///
+    /// \brief language This track language, if available.
+    ///
+    std::string language() const
+    {
+        return m_obj->psz_language ? m_obj->psz_language : "";
+    }
+
+    ///
+    /// \brief description This track description
+    ///
+    std::string description() const
+    {
+        return m_obj->psz_description ? m_obj->psz_description : "";
+    }
+
+    ////////////////////////////////////////////////////////////////////////////
+    /// Audio specific
+    ////////////////////////////////////////////////////////////////////////////
+
+    ///
+    /// \brief channels This track number of channels
+    ///
+    uint32_t channels() const
+    {
+        assert( m_obj->i_type == libvlc_track_audio );
+        return m_obj->audio->i_channels;
+    }
+
+    ///
+    /// \brief rate This track samplerate, in hertz (Hz)
+    ///
+    uint32_t rate() const
+    {
+        assert( m_obj->i_type == libvlc_track_audio );
+        return m_obj->audio->i_rate;
+    }
+
+    ////////////////////////////////////////////////////////////////////////////
+    // Video specific
+    ////////////////////////////////////////////////////////////////////////////
+
+    ///
+    /// \brief height This track video height
+    ///
+    uint32_t height() const
+    {
+        assert( m_obj->i_type == libvlc_track_video );
+        return m_obj->video->i_height;
+    }
+
+    ///
+    /// \brief width This track video width
+    ///
+    uint32_t width() const
+    {
+        assert( m_obj->i_type == libvlc_track_video );
+        return m_obj->video->i_width;
+    }
+
+    ///
+    /// \brief sarNum This track aspect ratio numerator
+    ///
+    /// \see sarDen
+    ///
+    uint32_t sarNum() const
+    {
+        assert( m_obj->i_type == libvlc_track_video );
+        return m_obj->video->i_sar_num;
+    }
+
+    ///
+    /// \brief sarDen This track aspect ratio denominator
+    ///
+    /// \see sarNum
+    ///
+    uint32_t sarDen() const
+    {
+        assert( m_obj->i_type == libvlc_track_video );
+        return m_obj->video->i_sar_den;
+    }
+
+    ///
+    /// \brief fpsNum This track frame per second numerator
+    ///
+    /// \see fpsDen
+    ///
+    uint32_t fpsNum() const
+    {
+        assert( m_obj->i_type == libvlc_track_video );
+        return m_obj->video->i_frame_rate_num;
+    }
+
+    ///
+    /// \brief fpsDen This track frame per second denominator
+    ///
+    /// \see fpsNum
+    ///
+    uint32_t fpsDen() const
+    {
+        assert( m_obj->i_type == libvlc_track_video );
+        return m_obj->video->i_frame_rate_den;
+    }
+
+    ///
+    /// \brief Orientation
+    ///
+    /// \see orientation
+    ///
+    Orientation orientation() const
+    {
+        assert( m_obj->i_type == libvlc_track_video );
+        return static_cast<Orientation>( m_obj->video->i_orientation );
+    }
+
+    ///
+    /// \brief Projection
+    ///
+    /// \see projection
+    ///
+    Projection projection() const
+    {
+        assert( m_obj->i_type == libvlc_track_video );
+        return static_cast<Projection>( m_obj->video->i_projection );
+    }
+
+    std::string idStr() const
+    {
+        return m_obj->psz_id ? m_obj->psz_id : "";
+    }
+
+    bool idStable() const
+    {
+        return m_obj->id_stable;
+    }
+
+    std::string name() const
+    {
+        return m_obj->psz_name ? m_obj->psz_name : "";
+    }
+
+    bool selected() const
+    {
+        return m_obj->selected;
+    }
+
+    ////////////////////////////////////////////////////////////////////////////
+    // Subtitles specific
+    ////////////////////////////////////////////////////////////////////////////
+
+    ///
+    /// \brief encoding Subtitles text encoding
+    ///
+    std::string encoding() const
+    {
+        assert( m_obj->i_type == libvlc_track_text );
+        return m_obj->subtitle->psz_encoding ? m_obj->subtitle->psz_encoding : "";
+    }
+
+    ///
+    /// \brief MediaTrack Construct a libvlc_media_track_t representation
+    /// \param c A valid media track
+    ///
+    /// \note The track will he held and released automatically.
+    ///
+    explicit MediaTrack(libvlc_media_track_t* c)
+        : Internal{ libvlc_media_track_hold( c ), libvlc_media_track_release }
+    {
+    }
+};
+
+#else
+
 ///
 /// \brief The MediaTrack class describes a track
 ///
@@ -103,13 +409,13 @@ public:
     ///
     enum class Type
     {
-        Unknown = -1,
+        Unknown = libvlc_track_unknown,
         /// Audio track
-        Audio,
+        Audio = libvlc_track_audio,
         /// Video track
-        Video,
+        Video = libvlc_track_video,
         /// Subtitle track (also called SPU sometimes)
-        Subtitle
+        Subtitle = libvlc_track_text,
     };
 
     ///
@@ -341,28 +647,6 @@ public:
     }
 #endif
 
-#if LIBVLC_VERSION_INT >= LIBVLC_VERSION(4, 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
     ////////////////////////////////////////////////////////////////////////////
@@ -382,21 +666,11 @@ 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 != nullptr )
             m_language = c->psz_language;
         if ( c->psz_description != nullptr )
             m_description = c->psz_description;
-#if LIBVLC_VERSION_INT >= LIBVLC_VERSION(4, 0, 0, 0)
-        if ( c->psz_id != nullptr )
-            m_idStr = c->psz_id;
-        if ( c->psz_name )
-            m_name = c->psz_name;
-#endif
         switch ( c->i_type )
         {
             case libvlc_track_audio:
@@ -452,17 +726,13 @@ 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;
 };
 
+#endif
+
 ///
 /// \brief The AudioOutputDescription class describes an audio output module
 ///
@@ -759,28 +1029,5 @@ 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/7a026fa6874a2e755a685d5f8794f758ab5ab3be...eae999f652cc3b8cec84882069a3cde26a9d8bd9

-- 
View it on GitLab: https://code.videolan.org/videolan/libvlcpp/-/compare/7a026fa6874a2e755a685d5f8794f758ab5ab3be...eae999f652cc3b8cec84882069a3cde26a9d8bd9
You're receiving this email because of your account on code.videolan.org.




More information about the vlc-commits mailing list