summaryrefslogtreecommitdiffstats
path: root/src/sources/libfaadloader.h
blob: a0822559e465036c0ff84ffe04da66ae83b3f41e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
#pragma once

#include <QLibrary>
#include <QtDebug>

#include "util/memory.h"

namespace faad2 {

// object types for AAC
constexpr unsigned char MAIN = 1;
constexpr unsigned char LC = 2;
constexpr unsigned char SSR = 3;
constexpr unsigned char LTP = 4;
constexpr unsigned char HE_AAC = 5;
constexpr unsigned char ER_LC = 17;
constexpr unsigned char ER_LTP = 19;
constexpr unsigned char LD = 23;
constexpr unsigned char DRM_ER_LC = 27; // special object type for DRM

// library output formats
constexpr unsigned char FMT_16BIT = 1;
constexpr unsigned char FMT_24BIT = 2;
constexpr unsigned char FMT_32BIT = 3;
constexpr unsigned char FMT_FLOAT = 4;
constexpr unsigned char FMT_FIXED = FMT_FLOAT;
constexpr unsigned char FMT_DOUBLE = 5;

enum class FrameError : unsigned char {
    InvalidNumberOfChannels = 12,
    InvalidChannelConfiguration = 21,
};

typedef void* DecoderHandle;

extern "C" {

typedef struct
{
    unsigned char defObjectType;
    unsigned long defSampleRate;
    unsigned char outputFormat;
    unsigned char downMatrix;
    unsigned char useOldADTSFormat;
    unsigned char dontUpSampleImplicitSBR;
} Configuration;

typedef struct
{
    unsigned long bytesconsumed;
    unsigned long samples;
    unsigned char channels;
    unsigned char error;
    unsigned long samplerate;

    // SBR: 0: off, 1: on; upsample, 2: on; downsampled, 3: off; upsampled
    unsigned char sbr;

    // MPEG-4 ObjectType
    unsigned char object_type;

    // AAC header type; MP4 will be signalled as RAW also
    unsigned char header_type;

    // multichannel configuration
    unsigned char num_front_channels;
    unsigned char num_side_channels;
    unsigned char num_back_channels;
    unsigned char num_lfe_channels;
    unsigned char channel_position[64];

    // PS: 0: off, 1: on
    unsigned char ps;
} FrameInfo;

} // extern "C"

class LibLoader {
  public:
    static LibLoader* Instance();

    bool isLoaded() const;

    DecoderHandle Open() const;

    Configuration* GetCurrentConfiguration(
            DecoderHandle hDecoder) const;

    unsigned char SetConfiguration(
            DecoderHandle hDecoder, Configuration* config) const;

    // Init the decoder using the AAC stream (ADTS/ADIF)
    long Init(
            DecoderHandle hDecoder,
            unsigned char* pBuffer,
            unsigned long sizeofBuffer,
            unsigned long* pSampleRate,
            unsigned char* pChannels) const;

    // Init the decoder using a DecoderSpecificInfo
    char Init2(
            DecoderHandle hDecoder,
            unsigned char* pBuffer,
            unsigned long sizeofBuffer,
            unsigned long* pSampleRate,
            unsigned char* pChannels) const;

    void Close(DecoderHandle hDecoder) const;

    void PostSeekReset(DecoderHandle hDecoder, long frame) const;

    void* Decode2(
            DecoderHandle hDecoder,
            FrameInfo* pInfo,
            unsigned char* pBuffer,
            unsigned long bufferSize,
            void** ppSampleBuffer,
            unsigned long sampleBufferSize) const;

    char* GetErrorMessage(unsigned char errcode) const;

    int GetVersion(
            char** faad2_id_string,
            char** faad2_copyright_string) const;

  private:
    LibLoader();

    LibLoader(const LibLoader&) = delete;
    LibLoader& operator=(const LibLoader&) = delete;

    // QLibrary is not copy-able
    std::unique_ptr<QLibrary> m_pLibrary;

    typedef DecoderHandle (*NeAACDecOpen_t)();
    NeAACDecOpen_t m_neAACDecOpen;

    typedef Configuration* (*NeAACDecGetCurrentConfiguration_t)(DecoderHandle);
    NeAACDecGetCurrentConfiguration_t m_neAACDecGetCurrentConfiguration;

    typedef unsigned char (*NeAACDecSetConfiguration_t)(
            DecoderHandle, Configuration*);
    NeAACDecSetConfiguration_t m_neAACDecSetConfiguration;

    typedef long (*NeAACDecInit_t)(
            DecoderHandle, unsigned char*, unsigned long, unsigned long*, unsigned char*);
    NeAACDecInit_t m_neAACDecInit;

    typedef char (*NeAACDecInit2_t)(
            DecoderHandle, unsigned char*, unsigned long, unsigned long*, unsigned char*);
    NeAACDecInit2_t m_neAACDecInit2;

    typedef void (*NeAACDecClose_t)(DecoderHandle);
    NeAACDecClose_t m_neAACDecClose;

    typedef void (*NeAACDecPostSeekReset_t)(DecoderHandle, long);
    NeAACDecPostSeekReset_t m_neAACDecPostSeekReset;

    typedef void* (*NeAACDecDecode2_t)(
            DecoderHandle, FrameInfo*, unsigned char*, unsigned long, void**, unsigned long);
    NeAACDecDecode2_t m_neAACDecDecode2;

    typedef char* (*NeAACDecGetErrorMessage_t)(unsigned char);
    NeAACDecGetErrorMessage_t m_neAACDecGetErrorMessage;

    typedef int (*NeAACDecGetVersion_t)(
            char** faad2_id_string,
            char** faad2_copyright_string);
    NeAACDecGetVersion_t m_neAACDecGetVersion;
};

} // namespace faad2

QDebug operator<<(
        QDebug dbg,
        const faad2::Configuration& cfg);