mirror of
https://github.com/sle118/squeezelite-esp32.git
synced 2025-12-11 22:17:17 +03:00
move to new cspot
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
#pragma once
|
||||
|
||||
#include "BaseCodec.h"
|
||||
#include "aacdec.h"
|
||||
|
||||
namespace bell {
|
||||
|
||||
class AACDecoder : public BaseCodec {
|
||||
private:
|
||||
HAACDecoder aac;
|
||||
int16_t* pcmData;
|
||||
AACFrameInfo frame = {};
|
||||
|
||||
public:
|
||||
AACDecoder();
|
||||
~AACDecoder();
|
||||
bool setup(uint32_t sampleRate, uint8_t channelCount,
|
||||
uint8_t bitDepth) override;
|
||||
bool setup(AudioContainer* container) override;
|
||||
uint8_t* decode(uint8_t* inData, uint32_t& inLen, uint32_t& outLen) override;
|
||||
};
|
||||
} // namespace bell
|
||||
@@ -0,0 +1,16 @@
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include "BaseCodec.h"
|
||||
#include "AudioContainer.h"
|
||||
|
||||
namespace bell {
|
||||
|
||||
class AudioCodecs {
|
||||
public:
|
||||
static std::shared_ptr<BaseCodec> getCodec(AudioCodec type);
|
||||
static std::shared_ptr<BaseCodec> getCodec(AudioContainer* container);
|
||||
static void addCodec(AudioCodec type,
|
||||
const std::shared_ptr<BaseCodec>& codec);
|
||||
};
|
||||
} // namespace bell
|
||||
@@ -0,0 +1,49 @@
|
||||
#pragma once
|
||||
|
||||
#include "AudioContainer.h"
|
||||
|
||||
namespace bell {
|
||||
|
||||
class BaseCodec {
|
||||
private:
|
||||
uint32_t lastSampleLen, availableBytes;
|
||||
|
||||
public:
|
||||
uint32_t sampleRate = 44100;
|
||||
uint8_t channelCount = 2;
|
||||
uint8_t bitDepth = 16;
|
||||
|
||||
/**
|
||||
* Setup the codec (sample rate, channel count, etc) using the specified container.
|
||||
*/
|
||||
virtual bool setup(AudioContainer* container);
|
||||
/**
|
||||
* Setup the codec manually, using the provided values.
|
||||
*/
|
||||
virtual bool setup(uint32_t sampleRate, uint8_t channelCount,
|
||||
uint8_t bitDepth) = 0;
|
||||
/**
|
||||
* Decode the given sample.
|
||||
*
|
||||
* @param [in] inData encoded data. Should allow nullptr, in which case nullptr should be returned.
|
||||
* @param [in] inLen size of inData, in bytes
|
||||
* @param [out] outLen size of output PCM data, in bytes
|
||||
* @return pointer to decoded raw PCM audio data, allocated inside the codec object; nullptr on failure
|
||||
*/
|
||||
virtual uint8_t* decode(uint8_t* inData, uint32_t& inLen,
|
||||
uint32_t& outLen) = 0;
|
||||
/**
|
||||
* Read a single sample from the container, decode it, and return the result.
|
||||
*
|
||||
* @param [in] container media container to read the sample from (the container's codec must match this instance)
|
||||
* @param [out] outLen size of output PCM data, in bytes
|
||||
* @return pointer to decoded raw PCM audio data, allocated inside the codec object; nullptr on failure
|
||||
*/
|
||||
uint8_t* decode(AudioContainer* container, uint32_t& outLen);
|
||||
/**
|
||||
* Last error that occurred, this is a codec-specific value.
|
||||
* This may be set by a codec upon decoding failure.
|
||||
*/
|
||||
int lastErrno = -1;
|
||||
};
|
||||
} // namespace bell
|
||||
@@ -0,0 +1,13 @@
|
||||
#pragma once
|
||||
|
||||
namespace bell {
|
||||
enum class AudioCodec {
|
||||
UNKNOWN = 0,
|
||||
AAC = 1,
|
||||
MP3 = 2,
|
||||
VORBIS = 3,
|
||||
OPUS = 4,
|
||||
FLAC = 5,
|
||||
};
|
||||
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
#ifndef BELL_DISABLE_CODECS
|
||||
#ifndef DECODER_GLOBALS_H
|
||||
#define DECODER_GLOBALS_H
|
||||
|
||||
#define AAC_READBUF_SIZE (4 * AAC_MAINBUF_SIZE * AAC_MAX_NCHANS)
|
||||
#define MP3_READBUF_SIZE (2 * 1024);
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <memory>
|
||||
#include "aacdec.h"
|
||||
#include "mp3dec.h"
|
||||
|
||||
namespace bell
|
||||
{
|
||||
class DecodersInstance
|
||||
{
|
||||
public:
|
||||
DecodersInstance(){};
|
||||
~DecodersInstance()
|
||||
{
|
||||
MP3FreeDecoder(mp3Decoder);
|
||||
AACFreeDecoder(aacDecoder);
|
||||
};
|
||||
|
||||
HAACDecoder aacDecoder = NULL;
|
||||
HMP3Decoder mp3Decoder = NULL;
|
||||
|
||||
void ensureAAC()
|
||||
{
|
||||
if (aacDecoder == NULL)
|
||||
{
|
||||
aacDecoder = AACInitDecoder();
|
||||
}
|
||||
}
|
||||
|
||||
void ensureMP3()
|
||||
{
|
||||
if (mp3Decoder == NULL)
|
||||
{
|
||||
mp3Decoder = MP3InitDecoder();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
extern bell::DecodersInstance* decodersInstance;
|
||||
|
||||
void createDecoders();
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif
|
||||
@@ -0,0 +1,22 @@
|
||||
#pragma once
|
||||
|
||||
#include "BaseCodec.h"
|
||||
#include "mp3dec.h"
|
||||
|
||||
namespace bell {
|
||||
class MP3Decoder : public BaseCodec {
|
||||
private:
|
||||
HMP3Decoder mp3;
|
||||
int16_t* pcmData;
|
||||
MP3FrameInfo frame = {};
|
||||
|
||||
public:
|
||||
MP3Decoder();
|
||||
~MP3Decoder();
|
||||
bool setup(uint32_t sampleRate, uint8_t channelCount,
|
||||
uint8_t bitDepth) override;
|
||||
|
||||
bool setup(AudioContainer* container) override;
|
||||
uint8_t* decode(uint8_t* inData, uint32_t& inLen, uint32_t& outLen) override;
|
||||
};
|
||||
} // namespace bell
|
||||
@@ -0,0 +1,20 @@
|
||||
#pragma once
|
||||
|
||||
#include "BaseCodec.h"
|
||||
|
||||
struct OpusDecoder;
|
||||
|
||||
namespace bell {
|
||||
class OPUSDecoder : public BaseCodec {
|
||||
private:
|
||||
OpusDecoder* opus;
|
||||
int16_t* pcmData;
|
||||
|
||||
public:
|
||||
OPUSDecoder();
|
||||
~OPUSDecoder();
|
||||
bool setup(uint32_t sampleRate, uint8_t channelCount,
|
||||
uint8_t bitDepth) override;
|
||||
uint8_t* decode(uint8_t* inData, uint32_t& inLen, uint32_t& outLen) override;
|
||||
};
|
||||
} // namespace bell
|
||||
@@ -0,0 +1,26 @@
|
||||
#pragma once
|
||||
|
||||
#include "BaseCodec.h"
|
||||
#include "ivorbiscodec.h"
|
||||
|
||||
namespace bell {
|
||||
class VorbisDecoder : public BaseCodec {
|
||||
private:
|
||||
vorbis_info* vi = nullptr;
|
||||
vorbis_comment* vc = nullptr;
|
||||
vorbis_dsp_state* vd = nullptr;
|
||||
ogg_packet op = {};
|
||||
int16_t* pcmData;
|
||||
|
||||
public:
|
||||
VorbisDecoder();
|
||||
~VorbisDecoder();
|
||||
bool setup(uint32_t sampleRate, uint8_t channelCount,
|
||||
uint8_t bitDepth) override;
|
||||
uint8_t* decode(uint8_t* inData, uint32_t& inLen, uint32_t& outLen) override;
|
||||
bool setup(AudioContainer* container) override;
|
||||
|
||||
private:
|
||||
void setPacket(uint8_t* inData, uint32_t inLen) const;
|
||||
};
|
||||
} // namespace bell
|
||||
Reference in New Issue
Block a user