Commit 95598551 authored by Hugo Beauzée-Luyssen's avatar Hugo Beauzée-Luyssen
Browse files

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
parent 56e36380
......@@ -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
///
......@@ -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
///
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment