Skip to content
Extraits de code Groupes Projets
Sélectionner une révision Git
  • 7ee4bd7abc51ca9c6ab47500f4449b5d13e568f3
  • master par défaut
  • script
  • new-devel
  • devel
  • timingView-edit
  • fix-mpv
7 résultats

Audio.hh

Blame
  • Audio.hh 4,84 Kio
    #pragma once
    
    #ifndef __cplusplus
    #error "This is a C++ header"
    #endif
    
    extern "C" {
    #include <libavutil/opt.h>
    #include <libavcodec/avcodec.h>
    #include <libavformat/avformat.h>
    #include <libswresample/swresample.h>
    #include <libavcodec/avfft.h>
    #include <memory.h>
    }
    
    #include "Utils.hh"
    #include <QtGlobal>
    #include <QMap>
    #include <QVector>
    #include <QString>
    
    namespace Vivy
    {
    class AudioContext;
    
    // The memory representation of an audio file. It is created inplace and should
    // not be moved around. It should be used to get the properties of an audio
    // file and its streams. The user can use a stream from the file and get data
    // from it.
    class AudioContext final {
        VIVY_UNMOVABLE_OBJECT(AudioContext)
    
    public:
        // Hold all the data for a stream in an audio file. Should only be owned by
        // the AudioContext class.
        class Stream final {
            VIVY_UNMOVABLE_OBJECT(Stream)
    
            static inline Utils::DeleterFunctionType<double> dataDeleter =
                std::bind_front(Utils::freePtrIfNotNull<double>, av_free);
    
            static inline Utils::DeleterFunctionType<AVCodecContext> codecContexteleter =
                std::bind_front(Utils::freePPtrIfNotNull<AVCodecContext>, avcodec_free_context);
    
            static inline Utils::DeleterFunctionType<AVFrame> avFrameDeleter =
                std::bind_front(Utils::freePPtrIfNotNull<AVFrame>, av_frame_free);
    
            static inline Utils::DeleterFunctionType<SwrContext> swrContenxtDeleter =
                std::bind_front(Utils::freePPtrIfNotNull<SwrContext>, swr_free);
    
            // All the used types
            using AVCodecContextPtr = std::unique_ptr<AVCodecContext, decltype(codecContexteleter)>;
            using DataPtr           = std::shared_ptr<double[]>;
            using AVFramePtr        = std::unique_ptr<AVFrame, decltype(avFrameDeleter)>;
            using SwrContextPtr     = std::unique_ptr<SwrContext, decltype(swrContenxtDeleter)>;
    
        public:
            Stream(AVCodec *, AVFormatContext *, AVStream *, int index);
            ~Stream() noexcept;
    
            // The non-owning view of the stream's data
            using DataWeakPtr = std::weak_ptr<double[]>;
    
            // Decode the stream
            void decodeData();
            void cleanUpData() noexcept;
            bool isDecoded() const noexcept;
            int getDataSampleRate() const noexcept;
            size_t getDecodedDataSize() const noexcept;
            size_t getDecodedChunkSize() const noexcept;