structures.hpp 15.6 KB
Newer Older
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
1
/*****************************************************************************
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
 *
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 "Picture.hpp"
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 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140

    ///
    /// \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
    };

141
#if !defined(_MSC_VER) || _MSC_VER >= 1900
142 143 144 145
    constexpr static Type Unknown = Type::Unknown;
    constexpr static Type Audio = Type::Audio;
    constexpr static Type Video = Type::Video;
    constexpr static Type Subtitle = Type::Subtitle;
146 147 148 149 150 151
#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
152

Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
153 154 155 156 157 158 159
    ///
    /// \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()
    ///
160 161 162 163 164
    uint32_t codec() const
    {
        return m_codec;
    }

Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
165 166 167 168 169 170 171
    ///
    /// \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
    ///
172 173 174 175 176
    uint32_t originalFourCC() const
    {
        return m_originalFourcc;
    }

Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
177 178 179 180 181
    ///
    /// \brief id The track internal ID.
    ///
    /// This can't be assume to grow one by one monotonically.
    ///
182 183 184 185 186
    int32_t id() const
    {
        return m_id;
    }

Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
187 188 189 190 191
    ///
    /// \brief type The track type
    ///
    /// \see MediaTrack::Type
    ///
192 193 194 195 196
    Type type() const
    {
        return m_type;
    }

Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
197 198 199 200 201
    ///
    /// \brief profile This track profile
    ///
    /// This might or might not be set, depending on the codec.
    ///
202 203 204 205 206
    int32_t profile() const
    {
        return m_profile;
    }

Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
207 208 209 210 211
    ///
    /// \brief level This track level
    ///
    /// This might or might not be set, depending on the codec
    ///
212 213 214 215 216
    int32_t level() const
    {
        return m_level;
    }

Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
217 218 219 220
    ///
    /// \brief bitrate This track bitrate, in bytes per second
    /// \return
    ///
221 222 223 224 225
    uint32_t bitrate() const
    {
        return m_bitrate;
    }

Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
226 227 228
    ///
    /// \brief language This track language, if available.
    ///
229 230 231 232 233
    const std::string& language() const
    {
        return m_language;
    }

Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
234 235 236
    ///
    /// \brief description This track description
    ///
237 238 239 240 241
    const std::string& description() const
    {
        return m_description;
    }

Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
242 243 244 245 246 247 248
    ////////////////////////////////////////////////////////////////////////////
    /// Audio specific
    ////////////////////////////////////////////////////////////////////////////

    ///
    /// \brief channels This track number of channels
    ///
249 250 251 252 253
    uint32_t channels() const
    {
        return m_channels;
    }

Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
254 255 256
    ///
    /// \brief rate This track samplerate, in hertz (Hz)
    ///
257 258 259 260 261
    uint32_t rate() const
    {
        return m_rate;
    }

Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
262
    ////////////////////////////////////////////////////////////////////////////
263
    // Video specific
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
264 265 266 267 268
    ////////////////////////////////////////////////////////////////////////////

    ///
    /// \brief height This track video height
    ///
269 270 271 272 273
    uint32_t height() const
    {
        return m_height;
    }

Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
274 275 276
    ///
    /// \brief width This track video width
    ///
277 278 279 280 281
    uint32_t width() const
    {
        return m_width;
    }

Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
282 283 284 285 286
    ///
    /// \brief sarNum This track aspect ratio numerator
    ///
    /// \see sarDen
    ///
287 288 289 290 291
    uint32_t sarNum() const
    {
        return m_sarNum;
    }

Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
292 293 294 295 296
    ///
    /// \brief sarDen This track aspect ratio denominator
    ///
    /// \see sarNum
    ///
297 298 299 300 301
    uint32_t sarDen() const
    {
        return m_sarDen;
    }

Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
302 303 304 305 306
    ///
    /// \brief fpsNum This track frame per second numerator
    ///
    /// \see fpsDen
    ///
307 308 309 310 311
    uint32_t fpsNum() const
    {
        return m_fpsNum;
    }

Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
312 313 314 315 316
    ///
    /// \brief fpsDen This track frame per second denominator
    ///
    /// \see fpsNum
    ///
317 318 319 320 321
    uint32_t fpsDen() const
    {
        return m_fpsDen;
    }

322
#if LIBVLC_VERSION_INT >= LIBVLC_VERSION(3, 0, 0, 0)
323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341
    ///
    /// \brief Orientation
    ///
    /// \see orientation
    ///
    Orientation orientation() const
    {
        return m_orientation;
    }

    ///
    /// \brief Projection
    ///
    /// \see projection
    ///
    Projection projection() const
    {
        return m_projection;
    }
342
#endif
343

Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
344
    ////////////////////////////////////////////////////////////////////////////
345
    // Subtitles specific
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
346 347 348 349 350
    ////////////////////////////////////////////////////////////////////////////

    ///
    /// \brief encoding Subtitles text encoding
    ///
351 352 353 354
    const std::string& encoding() const
    {
        return m_encoding;
    }
355

356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382
    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;
383
#if LIBVLC_VERSION_INT >= LIBVLC_VERSION(3, 0, 0, 0)
384 385
                m_orientation = static_cast<Orientation>( c->video->i_orientation );
                m_projection = static_cast<Projection>( c->video->i_projection );
386
#endif
387 388 389 390 391 392 393 394 395 396 397 398
                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;
        }
    }
399

400
private:
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
401
    uint32_t m_codec;
402 403 404 405 406
    uint32_t m_originalFourcc;
    uint32_t m_id;
    Type m_type;
    int32_t m_profile;
    int32_t m_level;
407 408 409
    uint32_t m_bitrate;
    std::string m_language;
    std::string m_description;
410 411 412 413 414 415 416 417 418 419
    // 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;
420
#if LIBVLC_VERSION_INT >= LIBVLC_VERSION(3, 0, 0, 0)
421 422
    Orientation m_orientation;
    Projection m_projection;
423
#endif
424 425
    // Subtitles
    std::string m_encoding;
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
426 427
};

Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
428 429 430
///
/// \brief The AudioOutputDescription class describes an audio output module
///
431
class AudioOutputDescription
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
432 433
{
public:
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
434 435 436
    ///
    /// \brief name The module name
    ///
437 438 439 440 441
    const std::string& name() const
    {
        return m_name;
    }

Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
442 443 444
    ///
    /// \brief description The module description
    ///
445 446 447 448
    const std::string& description() const
    {
        return m_description;
    }
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
449

450
    explicit AudioOutputDescription( libvlc_audio_output_t* c )
451 452 453 454 455 456 457
    {
        if ( c->psz_name != NULL )
            m_name = c->psz_name;
        if ( c->psz_description != NULL )
            m_description = c->psz_description;
    }

458
private:
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
459 460 461 462
    std::string m_name;
    std::string m_description;
};

Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
463 464 465 466
///
/// \brief The AudioOutputDeviceDescription class describes an audio device, as seen
///         by an audio output module
///
467
class AudioOutputDeviceDescription
468 469 470
{
    public:
        /**< Device identifier string */
471 472 473 474 475
        const std::string& device() const
        {
            return m_device;
        }

476
        /**< User-friendly device description */
477 478 479 480
        const std::string& description() const
        {
            return m_description;
        }
481

482 483 484 485 486 487 488
        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;
        }
489

490
    private:
491 492 493
        std::string m_device;
        std::string m_description;
};
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
494

Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
495 496 497
///
/// \brief The TrackDescription class describes a track
///
498
class TrackDescription
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
499 500
{
public:
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
501 502 503
    ///
    /// \brief id The track id
    ///
504 505 506 507 508
    int id() const
    {
        return m_id;
    }

Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
509 510 511
    ///
    /// \brief name The track name
    ///
512 513 514 515
    const std::string& name() const
    {
        return m_name;
    }
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
516

517 518 519 520 521 522
    explicit TrackDescription( libvlc_track_description_t* c )
        : m_id( c->i_id )
    {
        if ( c->psz_name != nullptr )
            m_name = c->psz_name;
    }
523 524

private:
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
525 526 527 528
    int m_id;
    std::string m_name;
};

529
#if LIBVLC_VERSION_INT >= LIBVLC_VERSION(3, 0, 0, 0)
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
///
/// \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
    {
557
        return ( m_flags & libvlc_title_menu ) != 0;
558 559
    }

560 561 562 563
    bool isInteractive() const
    {
        return ( m_flags & libvlc_title_interactive ) != 0;
    }
564 565

    explicit TitleDescription( libvlc_title_description_t* c )
566
        : m_duration( c->i_duration ), m_flags( c->i_flags )
567 568 569 570 571 572 573 574
    {
        if ( c->psz_name != nullptr )
            m_name = c->psz_name;
    }

private:
    int64_t m_duration;
    std::string m_name;
575
    int m_flags;
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 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618
///
/// \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;
};
619
#endif
620

621
#if LIBVLC_VERSION_INT >= LIBVLC_VERSION(3, 0, 0, 0)
622 623 624 625 626 627 628 629 630
///
/// \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.
    ///
631
    enum class Type
632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657
    {
        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;
    }
};
Martin Finkel's avatar
Martin Finkel committed
658 659 660


///
661
/// \brief C++ Type wrapper for libvlc_video_viewpoint_t
Martin Finkel's avatar
Martin Finkel committed
662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695
///
class VideoViewpoint : public libvlc_video_viewpoint_t
{
public:
    VideoViewpoint( float yaw, float pitch, float roll, float fieldOfView )
    {
        f_yaw = yaw;
        f_pitch = pitch;
        f_roll = roll;
        f_field_of_view = fieldOfView;
    }

public:
    float yaw() const
    {
        return f_yaw;
    }

    float pitch() const
    {
        return f_pitch;
    }

    float roll() const
    {
        return f_roll;
    }

    float field_of_view() const
    {
        return f_field_of_view;
    }
};

696
class RendererDiscovererDescription
697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720
{
public:
    explicit RendererDiscovererDescription( const libvlc_rd_description_t* d )
    {
        if (d->psz_name != NULL)
            m_name = d->psz_name;
        if (d->psz_longname != NULL)
            m_longName = d->psz_longname;
    }

    const std::string& name() const
    {
        return m_name;
    }

    const std::string& longName() const
    {
        return m_longName;
    }

private:
    std::string m_name;
    std::string m_longName;
};
Martin Finkel's avatar
Martin Finkel committed
721

722
#endif
723

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