[vlc-commits] [Git][videolan/libvlcpp][master] 4 commits: Media: Adapt to recent API changes
Hugo Beauzée-Luyssen (@chouquette)
gitlab at videolan.org
Mon Jun 20 08:26:30 UTC 2022
Hugo Beauzée-Luyssen pushed to branch master at VideoLAN / libvlcpp
Commits:
41a07fcd by Hugo Beauzée-Luyssen at 2022-06-20T10:08:03+02:00
Media: Adapt to recent API changes
The media isn't constructed with an instance anymore, but takes the
instance as a parameter later on when needed
- - - - -
a14c7cc6 by Hugo Beauzée-Luyssen at 2022-06-20T10:08:03+02:00
MediaPlayer: Adapt to recent API changes
- - - - -
64dbe443 by Hugo Beauzée-Luyssen at 2022-06-20T10:08:03+02:00
examples: Adapt to recent API changes
- - - - -
0c7d3968 by Hugo Beauzée-Luyssen at 2022-06-20T10:24:45+02:00
CI: Bump 4.0 image
- - - - -
6 changed files:
- .gitlab-ci.yml
- examples/helloworld/main.cpp
- examples/imem/imem.cpp
- test/main.cpp
- vlcpp/Media.hpp
- vlcpp/MediaPlayer.hpp
Changes:
=====================================
.gitlab-ci.yml
=====================================
@@ -1,6 +1,6 @@
variables:
VLC30_IMAGE: registry.videolan.org/medialibrary:20201009131431
- VLC40_IMAGE: registry.videolan.org/libvlcpp-unstable:20220502070249
+ VLC40_IMAGE: registry.videolan.org/libvlcpp-unstable:20220620081936
.common_build:
rules:
=====================================
examples/helloworld/main.cpp
=====================================
@@ -10,8 +10,13 @@ int main(int ac, char** av)
return 1;
}
auto instance = VLC::Instance(0, nullptr);
+#if LIBVLC_VERSION_INT >= LIBVLC_VERSION(4, 0, 0, 0)
+ auto media = VLC::Media(av[1], VLC::Media::FromPath);
+ auto mp = VLC::MediaPlayer(instance, media);
+#else
auto media = VLC::Media(instance, av[1], VLC::Media::FromPath);
auto mp = VLC::MediaPlayer(media);
+#endif
mp.play();
std::this_thread::sleep_for( std::chrono::seconds( 10 ) );
#if LIBVLC_VERSION_INT >= LIBVLC_VERSION(4, 0, 0, 0)
=====================================
examples/imem/imem.cpp
=====================================
@@ -21,7 +21,11 @@ int main(int ac, char**av)
auto instance = VLC::Instance(0, nullptr);
auto dummyOpaque = new ImemOpaque{};
dummyOpaque->path = av[1];
+#if LIBVLC_VERSION_INT >= LIBVLC_VERSION(4, 0, 0, 0)
+ auto imemMedia = VLC::Media(
+#else
auto imemMedia = VLC::Media( instance,
+#endif
// Open
[dummyOpaque]( void*, void** opaque, uint64_t* p_size ) -> int {
dummyOpaque->file = fopen( dummyOpaque->path.c_str(), "rb" );
@@ -55,7 +59,11 @@ int main(int ac, char**av)
// Do not use a user defined opaque
// This is mostly meant to test that our nullptr overload are functionnal
+#if LIBVLC_VERSION_INT >= LIBVLC_VERSION(4, 0, 0, 0)
+ auto imemMedia2 = VLC::Media(
+#else
auto imemMedia2 = VLC::Media( instance,
+#endif
nullptr,
[opaque2]( void* opaque, unsigned char* buf, size_t size ) -> ssize_t {
assert( opaque == nullptr );
@@ -70,11 +78,19 @@ int main(int ac, char**av)
return 0;
}, nullptr );
+#if LIBVLC_VERSION_INT >= LIBVLC_VERSION(4, 0, 0, 0)
+ auto mp = VLC::MediaPlayer( instance, imemMedia );
+ mp.play();
+
+ auto mp2 = VLC::MediaPlayer( instance, imemMedia2 );
+ mp2.play();
+#else
auto mp = VLC::MediaPlayer( imemMedia );
mp.play();
auto mp2 = VLC::MediaPlayer( imemMedia2 );
mp2.play();
+#endif
std::this_thread::sleep_for( std::chrono::seconds( 10 ) );
=====================================
test/main.cpp
=====================================
@@ -53,8 +53,13 @@ int main(int ac, char** av)
std::cout << "Hooked VLC log: " << lvl << ' ' << message << std::endl;
});
+#if LIBVLC_VERSION_INT >= LIBVLC_VERSION(4, 0, 0, 0)
+ auto media = VLC::Media(av[1], VLC::Media::FromPath);
+ auto mp = VLC::MediaPlayer(instance, media);
+#else
auto media = VLC::Media(instance, av[1], VLC::Media::FromPath);
auto mp = VLC::MediaPlayer(media);
+#endif
auto eventManager = mp.eventManager();
eventManager.onPlaying([&media]() {
std::cout << media.mrl() << " is playing" << std::endl;
=====================================
vlcpp/Media.hpp
=====================================
@@ -136,6 +136,61 @@ public:
};
#endif
+#if LIBVLC_VERSION_INT >= LIBVLC_VERSION(4, 0, 0, 0)
+ /**
+ * @brief Media Constructs a libvlc Media instance
+ * @param instance A libvlc instance
+ * @param mrl A path, location, or node name, depending on the 3rd parameter
+ * @param type The type of the 2nd argument. \sa{FromType}
+ */
+ Media(const std::string& mrl, FromType type)
+ : Internal{ libvlc_media_release }
+ {
+ InternalPtr ptr = nullptr;
+ switch (type)
+ {
+ case FromLocation:
+ ptr = libvlc_media_new_location( mrl.c_str() );
+ break;
+ case FromPath:
+ ptr = libvlc_media_new_path( mrl.c_str() );
+ break;
+ case AsNode:
+ ptr = libvlc_media_new_as_node( mrl.c_str() );
+ break;
+ default:
+ break;
+ }
+ if ( ptr == nullptr )
+ throw std::runtime_error("Failed to construct a media");
+ m_obj.reset( ptr, libvlc_media_release );
+ }
+
+ /**
+ * Create a media for an already open file descriptor.
+ * The file descriptor shall be open for reading (or reading and writing).
+ *
+ * Regular file descriptors, pipe read descriptors and character device
+ * descriptors (including TTYs) are supported on all platforms.
+ * Block device descriptors are supported where available.
+ * Directory descriptors are supported on systems that provide fdopendir().
+ * Sockets are supported on all platforms where they are file descriptors,
+ * i.e. all except Windows.
+ *
+ * \note This library will <b>not</b> automatically close the file descriptor
+ * under any circumstance. Nevertheless, a file descriptor can usually only be
+ * rendered once in a media player. To render it a second time, the file
+ * descriptor should probably be rewound to the beginning with lseek().
+ *
+ * \param fd open file descriptor
+ * \return the newly created media
+ */
+ Media( int fd)
+ : Internal { libvlc_media_new_fd( fd ),
+ libvlc_media_release }
+ {
+ }
+#else
/**
* @brief Media Constructs a libvlc Media instance
* @param instance A libvlc instance
@@ -190,6 +245,7 @@ public:
libvlc_media_release }
{
}
+#endif
/**
* Get media instance from this media list instance. This action will increase
@@ -291,7 +347,35 @@ public:
*
* \version LibVLC 3.0.0 and later.
*/
+#if LIBVLC_VERSION_INT >= LIBVLC_VERSION(4, 0, 0, 0)
+ template <typename OpenCb, typename ReadCb, typename SeekCb, typename CloseCb>
+ Media( OpenCb&& openCb, ReadCb&& readCb, SeekCb&& seekCb, CloseCb&& closeCb )
+ {
+ static_assert( signature_match_or_nullptr<OpenCb, ExpectedMediaOpenCb>::value, "Mismatched Open callback prototype" );
+ static_assert( signature_match_or_nullptr<SeekCb, ExpectedMediaSeekCb>::value, "Mismatched Seek callback prototype" );
+ static_assert( signature_match_or_nullptr<CloseCb, ExpectedMediaCloseCb>::value, "Mismatched Close callback prototype" );
+ static_assert( signature_match<ReadCb, ExpectedMediaReadCb>::value, "Mismatched Read callback prototype" );
+ auto ptr = libvlc_media_new_callbacks(
+ imem::CallbackWrapper<(unsigned int)CallbackIdx::Open, libvlc_media_open_cb>::
+ wrap<imem::GuessBoxingStrategy<OpenCb, imem::BoxingStrategy::Setup>::Strategy>(
+ *m_callbacks, std::forward<OpenCb>( openCb ) ),
+ imem::CallbackWrapper<(unsigned int)CallbackIdx::Read, libvlc_media_read_cb>::
+ wrap<imem::GuessBoxingStrategy<OpenCb, imem::BoxingStrategy::Unbox>::Strategy>(
+ *m_callbacks, std::forward<ReadCb>( readCb ) ),
+ imem::CallbackWrapper<(unsigned int)CallbackIdx::Seek, libvlc_media_seek_cb>::
+ wrap<imem::GuessBoxingStrategy<OpenCb, imem::BoxingStrategy::Unbox>::Strategy>(
+ *m_callbacks, std::forward<SeekCb>( seekCb ) ),
+ imem::CallbackWrapper<(unsigned int)CallbackIdx::Close, libvlc_media_close_cb>::
+ wrap<imem::GuessBoxingStrategy<OpenCb, imem::BoxingStrategy::Cleanup>::Strategy>(
+ *m_callbacks, std::forward<CloseCb>( closeCb ) ),
+ m_callbacks.get()
+ );
+ if ( ptr == nullptr )
+ throw std::runtime_error( "Failed to create media" );
+ m_obj.reset( ptr, libvlc_media_release );
+ }
+#else
template <typename OpenCb, typename ReadCb, typename SeekCb, typename CloseCb>
Media( const Instance& instance, OpenCb&& openCb, ReadCb&& readCb, SeekCb&& seekCb, CloseCb&& closeCb )
{
@@ -319,7 +403,7 @@ public:
throw std::runtime_error( "Failed to create media" );
m_obj.reset( ptr, libvlc_media_release );
}
-
+#endif
#endif
explicit Media( Internal::InternalPtr ptr, bool incrementRefCount)
@@ -459,7 +543,17 @@ public:
libvlc_media_set_meta(*this, e_meta, psz_value.c_str());
}
-
+#if LIBVLC_VERSION_INT >= LIBVLC_VERSION(4, 0, 0, 0)
+ /**
+ * Save the meta previously set
+ *
+ * \return true if the write operation was successful
+ */
+ bool saveMeta(const Instance& instance)
+ {
+ return libvlc_media_save_meta(getInternalPtr<libvlc_instance_t>(instance), *this) != 0;
+ }
+#else
/**
* Save the meta previously set
*
@@ -469,6 +563,7 @@ public:
{
return libvlc_media_save_meta(*this) != 0;
}
+#endif
#if LIBVLC_VERSION_INT < LIBVLC_VERSION(4, 0, 0, 0)
/**
@@ -578,7 +673,7 @@ public:
{
return libvlc_media_is_parsed(*this) != 0;
}
-#else
+#elif LIBVLC_VERSION_INT < LIBVLC_VERSION(4, 0, 0, 0)
/**
* Parse the media asynchronously with options.
*
@@ -620,6 +715,51 @@ public:
{
libvlc_media_parse_stop( *this );
}
+#else
+ /**
+ * Parse the media asynchronously with options.
+ *
+ * This fetches (local or network) art, meta data and/or tracks information.
+ * This method is the extended version of libvlc_media_parse_async()..
+ *
+ * To track when this is over you can listen to libvlc_MediaParsedStatus
+ * event. However if this functions returns an error, you will not receive any
+ * events.
+ *
+ * It uses a flag to specify parse options (see libvlc_media_parse_flag_t). All
+ * these flags can be combined. By default, media is parsed if it's a local
+ * file.
+ *
+ * \see ParsedStatus
+ * \see meta()
+ * \see tracks()
+ * \see parsedStatus
+ * \see ParseFlag
+ *
+ * \return true on success, false otherwise
+ * \param flags parse options
+ * \param timeout maximum time allowed to preparse the media. If -1, the
+ * default "preparse-timeout" option will be used as a timeout. If 0, it will
+ * wait indefinitely. If > 0, the timeout will be used (in milliseconds).
+ * \version LibVLC 3.0.0 or later
+ */
+ bool parseRequest( const Instance& instance, ParseFlags flags, int timeout )
+ {
+ return libvlc_media_parse_request( getInternalPtr<libvlc_instance_t>( instance ),
+ *this, static_cast<libvlc_media_parse_flag_t>( flags ), timeout ) == 0;
+ }
+
+ ParsedStatus parsedStatus( const Instance& instance )
+ {
+ return static_cast<ParsedStatus>( getInternalPtr<libvlc_instance_t>( instance ),
+ libvlc_media_get_parsed_status( *this ) );
+ }
+
+ void parseStop( const Instance& instance )
+ {
+ libvlc_media_parse_stop( getInternalPtr<libvlc_instance_t>( instance ),
+ *this );
+ }
#endif
/**
@@ -772,20 +912,22 @@ public:
Fast = libvlc_media_thumbnail_seek_fast,
};
- ThumbnailRequest* thumbnailRequestByTime( libvlc_time_t time, ThumbnailSeekSpeed speed,
+ ThumbnailRequest* thumbnailRequestByTime( const Instance& inst, libvlc_time_t time, ThumbnailSeekSpeed speed,
uint32_t width, uint32_t height, bool crop,
Picture::Type type, libvlc_time_t timeout )
{
- return libvlc_media_thumbnail_request_by_time( *this, time,
+ return libvlc_media_thumbnail_request_by_time(
+ getInternalPtr<libvlc_instance_t>( inst ), *this, time,
static_cast<libvlc_thumbnailer_seek_speed_t>( speed ), width,
height, crop, static_cast<libvlc_picture_type_t>( type ), timeout );
}
- ThumbnailRequest* thumbnailRequestByPos( float pos, ThumbnailSeekSpeed speed,
+ ThumbnailRequest* thumbnailRequestByPos( const Instance& inst, float pos, ThumbnailSeekSpeed speed,
uint32_t width, uint32_t height, bool crop,
Picture::Type type, libvlc_time_t timeout )
{
- return libvlc_media_thumbnail_request_by_pos( *this, pos,
+ return libvlc_media_thumbnail_request_by_pos(
+ getInternalPtr<libvlc_instance_t>( inst ), *this, pos,
static_cast<libvlc_thumbnailer_seek_speed_t>( speed ), width,
height, crop, static_cast<libvlc_picture_type_t>( type ), timeout );
}
=====================================
vlcpp/MediaPlayer.hpp
=====================================
@@ -92,10 +92,25 @@ public:
* Player should be created.
*/
MediaPlayer( const Instance& instance )
- : Internal{ libvlc_media_player_new( instance ), libvlc_media_player_release }
+ : 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( 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
*
@@ -107,7 +122,7 @@ public:
libvlc_media_player_release }
{
}
-
+#endif
/**
* Create an empty VLC MediaPlayer instance.
*
View it on GitLab: https://code.videolan.org/videolan/libvlcpp/-/compare/42b58a17ab8aa0e1d30ec358d03d5ba6ca32efb7...0c7d3968010f1b27b36e78c11e07e4d7f6fe756b
--
View it on GitLab: https://code.videolan.org/videolan/libvlcpp/-/compare/42b58a17ab8aa0e1d30ec358d03d5ba6ca32efb7...0c7d3968010f1b27b36e78c11e07e4d7f6fe756b
You're receiving this email because of your account on code.videolan.org.
VideoLAN code repository instance
More information about the vlc-commits
mailing list