structures.hpp 13.3 KB
Newer Older
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
1
/*****************************************************************************
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
2
 * structures.hpp: LibVLC++ structures
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
3
 *****************************************************************************
4
 * Copyright © 2015 libvlcpp authors & VideoLAN
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
5
 *
Alexey Sokolov's avatar
Alexey Sokolov committed
6
 * Authors: Alexey Sokolov <alexey+vlc@asokolov.org>
7
 *          Hugo Beauzée-Luyssen <hugo@beauzee.fr>
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
 *
 * 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_STRUCTURES_H
#define LIBVLC_CXX_STRUCTURES_H
26

27 28
#include <string>

29
#include "common.hpp"
30
#include <vlc/libvlc_version.h>
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
31

32 33 34
//FIXME:
//Should we make the constructors private again and implement our own vector allocator?

35 36
namespace VLC
{
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
37

Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
38 39 40
///
/// \brief The ModuleDescription class describes a module
///
41
class ModuleDescription
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
42 43
{
public:
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
44 45 46
    ///
    /// \brief name Returns the module name
    ///
47 48 49 50 51
    const std::string& name() const
    {
        return m_name;
    }

Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
52 53 54
    ///
    /// \brief shortname Returns the module short name
    ///
55 56 57 58 59
    const std::string& shortname() const
    {
        return m_shortname;
    }

Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
60 61 62
    ///
    /// \brief longname returns the module long name
    ///
63 64 65 66 67
    const std::string& longname() const
    {
        return m_longname;
    }

Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
68 69 70
    ///
    /// \brief help Returns a basic help string for this module
    ///
71 72 73 74
    const std::string& help() const
    {
        return m_help;
    }
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
75

76 77 78 79 80 81 82 83 84 85 86 87
    explicit ModuleDescription( libvlc_module_description_t* c )
    {
        if ( c->psz_name != NULL )
            m_name = c->psz_name;
        if ( c->psz_shortname != NULL )
            m_shortname = c->psz_shortname;
        if ( c->psz_longname != NULL )
            m_longname = c->psz_longname;
        if ( c->psz_help != NULL )
            m_help = c->psz_help;
    }

88
private:
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
89 90 91 92 93 94
    std::string m_name;
    std::string m_shortname;
    std::string m_longname;
    std::string m_help;
};

Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
95 96 97
///
/// \brief The MediaTrack class describes a track
///
98
class MediaTrack
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
99 100
{
public:
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
101 102 103
    ///
    /// \brief The Type enum indicates the type of a track
    ///
104
    enum class Type
105 106
    {
        Unknown = -1,
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
107
        /// Audio track
108
        Audio,
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
109
        /// Video track
110
        Video,
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
111
        /// Subtitle track (also called SPU sometimes)
112
        Subtitle
113
    };
114
#if !defined(_MSC_VER) || _MSC_VER >= 1900
115 116 117 118
    constexpr static Type Unknown = Type::Unknown;
    constexpr static Type Audio = Type::Audio;
    constexpr static Type Video = Type::Video;
    constexpr static Type Subtitle = Type::Subtitle;
119 120 121 122 123 124
#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
125

Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
126 127 128 129 130 131 132
    ///
    /// \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()
    ///
133 134 135 136 137
    uint32_t codec() const
    {
        return m_codec;
    }

Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
138 139 140 141 142 143 144
    ///
    /// \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
    ///
145 146 147 148 149
    uint32_t originalFourCC() const
    {
        return m_originalFourcc;
    }

Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
150 151 152 153 154
    ///
    /// \brief id The track internal ID.
    ///
    /// This can't be assume to grow one by one monotonically.
    ///
155 156 157 158 159
    int32_t id() const
    {
        return m_id;
    }

Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
160 161 162 163 164
    ///
    /// \brief type The track type
    ///
    /// \see MediaTrack::Type
    ///
165 166 167 168 169
    Type type() const
    {
        return m_type;
    }

Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
170 171 172 173 174
    ///
    /// \brief profile This track profile
    ///
    /// This might or might not be set, depending on the codec.
    ///
175 176 177 178 179
    int32_t profile() const
    {
        return m_profile;
    }

Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
180 181 182 183 184
    ///
    /// \brief level This track level
    ///
    /// This might or might not be set, depending on the codec
    ///
185 186 187 188 189
    int32_t level() const
    {
        return m_level;
    }

Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
190 191 192 193
    ///
    /// \brief bitrate This track bitrate, in bytes per second
    /// \return
    ///
194 195 196 197 198
    uint32_t bitrate() const
    {
        return m_bitrate;
    }

Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
199 200 201
    ///
    /// \brief language This track language, if available.
    ///
202 203 204 205 206
    const std::string& language() const
    {
        return m_language;
    }

Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
207 208 209
    ///
    /// \brief description This track description
    ///
210 211 212 213 214
    const std::string& description() const
    {
        return m_description;
    }

Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
215 216 217 218 219 220 221
    ////////////////////////////////////////////////////////////////////////////
    /// Audio specific
    ////////////////////////////////////////////////////////////////////////////

    ///
    /// \brief channels This track number of channels
    ///
222 223 224 225 226
    uint32_t channels() const
    {
        return m_channels;
    }

Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
227 228 229
    ///
    /// \brief rate This track samplerate, in hertz (Hz)
    ///
230 231 232 233 234
    uint32_t rate() const
    {
        return m_rate;
    }

Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
235
    ////////////////////////////////////////////////////////////////////////////
236
    // Video specific
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
237 238 239 240 241
    ////////////////////////////////////////////////////////////////////////////

    ///
    /// \brief height This track video height
    ///
242 243 244 245 246
    uint32_t height() const
    {
        return m_height;
    }

Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
247 248 249
    ///
    /// \brief width This track video width
    ///
250 251 252 253 254
    uint32_t width() const
    {
        return m_width;
    }

Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
255 256 257 258 259
    ///
    /// \brief sarNum This track aspect ratio numerator
    ///
    /// \see sarDen
    ///
260 261 262 263 264
    uint32_t sarNum() const
    {
        return m_sarNum;
    }

Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
265 266 267 268 269
    ///
    /// \brief sarDen This track aspect ratio denominator
    ///
    /// \see sarNum
    ///
270 271 272 273 274
    uint32_t sarDen() const
    {
        return m_sarDen;
    }

Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
275 276 277 278 279
    ///
    /// \brief fpsNum This track frame per second numerator
    ///
    /// \see fpsDen
    ///
280 281 282 283 284
    uint32_t fpsNum() const
    {
        return m_fpsNum;
    }

Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
285 286 287 288 289
    ///
    /// \brief fpsDen This track frame per second denominator
    ///
    /// \see fpsNum
    ///
290 291 292 293 294
    uint32_t fpsDen() const
    {
        return m_fpsDen;
    }

Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
295
    ////////////////////////////////////////////////////////////////////////////
296
    // Subtitles specific
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
297 298 299 300 301
    ////////////////////////////////////////////////////////////////////////////

    ///
    /// \brief encoding Subtitles text encoding
    ///
302 303 304 305
    const std::string& encoding() const
    {
        return m_encoding;
    }
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
    explicit MediaTrack(libvlc_media_track_t* c)
        : m_codec( c->i_codec )
        , m_originalFourcc( c->i_original_fourcc )
        , m_id( c->i_id )
        , m_profile( c->i_profile )
        , m_level( c->i_level )
        , m_bitrate( c->i_bitrate )
    {
        if ( c->psz_language != NULL )
            m_language = c->psz_language;
        if ( c->psz_description != NULL )
            m_description = c->psz_description;
        switch ( c->i_type )
        {
            case libvlc_track_audio:
                m_type = Audio;
                m_channels = c->audio->i_channels;
                m_rate = c->audio->i_rate;
                break;
            case libvlc_track_video:
                m_type = Video;
                m_height = c->video->i_height;
                m_width = c->video->i_width;
                m_sarNum = c->video->i_sar_num;
                m_sarDen = c->video->i_sar_den;
                m_fpsNum = c->video->i_frame_rate_num;
                m_fpsDen = c->video->i_frame_rate_den;
                break;
            case libvlc_track_text:
                m_type = Subtitle;
                if ( c->subtitle->psz_encoding != NULL )
                    m_encoding = c->subtitle->psz_encoding;
                break;
            case libvlc_track_unknown:
            default:
                m_type = Unknown;
                break;
        }
    }
346

347
private:
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
348
    uint32_t m_codec;
349 350 351 352 353
    uint32_t m_originalFourcc;
    uint32_t m_id;
    Type m_type;
    int32_t m_profile;
    int32_t m_level;
354 355 356
    uint32_t m_bitrate;
    std::string m_language;
    std::string m_description;
357 358 359 360 361 362 363 364 365 366 367 368
    // Audio
    uint32_t m_channels;
    uint32_t m_rate;
    // Video
    uint32_t m_height;
    uint32_t m_width;
    uint32_t m_sarNum;
    uint32_t m_sarDen;
    uint32_t m_fpsNum;
    uint32_t m_fpsDen;
    // Subtitles
    std::string m_encoding;
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
369 370
};

Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
371 372 373
///
/// \brief The AudioOutputDescription class describes an audio output module
///
374
class AudioOutputDescription
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
375 376
{
public:
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
377 378 379
    ///
    /// \brief name The module name
    ///
380 381 382 383 384
    const std::string& name() const
    {
        return m_name;
    }

Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
385 386 387
    ///
    /// \brief description The module description
    ///
388 389 390 391
    const std::string& description() const
    {
        return m_description;
    }
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
392

393
    explicit AudioOutputDescription( libvlc_audio_output_t* c )
394 395 396 397 398 399 400
    {
        if ( c->psz_name != NULL )
            m_name = c->psz_name;
        if ( c->psz_description != NULL )
            m_description = c->psz_description;
    }

401
private:
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
402 403 404 405
    std::string m_name;
    std::string m_description;
};

Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
406 407 408 409
///
/// \brief The AudioOutputDeviceDescription class describes an audio device, as seen
///         by an audio output module
///
410
class AudioOutputDeviceDescription
411 412 413
{
    public:
        /**< Device identifier string */
414 415 416 417 418
        const std::string& device() const
        {
            return m_device;
        }

419
        /**< User-friendly device description */
420 421 422 423
        const std::string& description() const
        {
            return m_description;
        }
424

425 426 427 428 429 430 431
        explicit AudioOutputDeviceDescription( libvlc_audio_output_device_t* d )
        {
            if ( d->psz_device != NULL )
                m_device = d->psz_device;
            if ( d->psz_description != NULL )
                m_device = d->psz_description;
        }
432

433
    private:
434 435 436
        std::string m_device;
        std::string m_description;
};
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
437

Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
438 439 440
///
/// \brief The TrackDescription class describes a track
///
441
class TrackDescription
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
442 443
{
public:
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
444 445 446
    ///
    /// \brief id The track id
    ///
447 448 449 450 451
    int id() const
    {
        return m_id;
    }

Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
452 453 454
    ///
    /// \brief name The track name
    ///
455 456 457 458
    const std::string& name() const
    {
        return m_name;
    }
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
459

460 461 462 463 464 465
    explicit TrackDescription( libvlc_track_description_t* c )
        : m_id( c->i_id )
    {
        if ( c->psz_name != nullptr )
            m_name = c->psz_name;
    }
466 467

private:
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
468 469 470 471
    int m_id;
    std::string m_name;
};

472
#if LIBVLC_VERSION_INT >= LIBVLC_VERSION(3, 0, 0, 0)
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
///
/// \brief The TitleDescription class describes a title
///
class TitleDescription
{
public:
    ///
    /// \brief duration The title duration in (ms)
    ///
    int64_t duration() const
    {
        return m_duration;
    }

    ///
    /// \brief name The title name
    ///
    const std::string& name() const
    {
        return m_name;
    }

    ///
    /// \brief name Is the title a menu?
    ///
    bool isMenu() const
    {
500
        return ( m_flags & libvlc_title_menu ) != 0;
501 502
    }

503 504 505 506
    bool isInteractive() const
    {
        return ( m_flags & libvlc_title_interactive ) != 0;
    }
507 508

    explicit TitleDescription( libvlc_title_description_t* c )
509
        : m_duration( c->i_duration ), m_flags( c->i_flags )
510 511 512 513 514 515 516 517
    {
        if ( c->psz_name != nullptr )
            m_name = c->psz_name;
    }

private:
    int64_t m_duration;
    std::string m_name;
518
    int m_flags;
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
///
/// \brief The ChapterDescription class describes a chapter
///
class ChapterDescription
{
public:
    ///
    /// \brief timeoffset The chapter start time in (ms)
    ///
    int64_t starttime() const
    {
        return m_starttime;
    }

    ///
    /// \brief duration The chapter duration in (ms)
    ///
    int64_t duration() const
    {
        return m_duration;
    }

    ///
    /// \brief name The chapter name
    ///
    const std::string& name() const
    {
        return m_name;
    }

    explicit ChapterDescription( libvlc_chapter_description_t* c )
        : m_duration( c->i_duration ), m_starttime( c->i_time_offset )
    {
        if ( c->psz_name != nullptr )
            m_name = c->psz_name;
    }

private:
    int64_t m_duration, m_starttime;
    std::string m_name;
};
562
#endif
563

564
#if LIBVLC_VERSION_INT >= LIBVLC_VERSION(3, 0, 0, 0)
565 566 567 568 569 570 571 572 573
///
/// \brief C++ Type wrapper for libvlc_media_slave_t
///
class MediaSlave : private libvlc_media_slave_t
{
public:
    ///
    /// Type of a media slave: subtitle or audio.
    ///
574
    enum class Type
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
    {
        Subtitle = libvlc_media_slave_type_subtitle,
        Audio = libvlc_media_slave_type_audio
    };

    MediaSlave(libvlc_media_slave_t *other) :
        libvlc_media_slave_t(*other)
    {
    }

public:
    Type type() const
    {
        return (Type)i_type;
    }

    unsigned priority() const
    {
        return i_priority;
    }

    std::string uri() const
    {
        return psz_uri;
    }
};
601
#endif
602

Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
603 604
} // namespace VLC
#endif