整理代码
This commit is contained in:
commit
c7b4e178ec
364 changed files with 59691 additions and 0 deletions
99
video/shine/AudioEncoder.cpp
Normal file
99
video/shine/AudioEncoder.cpp
Normal file
|
|
@ -0,0 +1,99 @@
|
|||
/*
|
||||
*******************************************************************************
|
||||
* INCLUDE
|
||||
*******************************************************************************
|
||||
*/
|
||||
#include "AudioEncoder.h"
|
||||
#include "Logger.h"
|
||||
#include "../core/System.h"
|
||||
|
||||
namespace Video
|
||||
{
|
||||
namespace Shine
|
||||
{
|
||||
/*
|
||||
*******************************************************************************
|
||||
* CLASS DEFINE
|
||||
*******************************************************************************
|
||||
*/
|
||||
AudioEncoder::AudioEncoder(Core::CodecID codecID)
|
||||
: Core::AudioEncoder(Poco::format("Shine::AudioEncoder(%s)", Core::codecIDToString(codecID)), codecID),
|
||||
_pEncoder(nullptr)
|
||||
{
|
||||
shine_set_config_mpeg_defaults(&_config.mpeg);
|
||||
}
|
||||
|
||||
AudioEncoder::~AudioEncoder()
|
||||
{
|
||||
}
|
||||
|
||||
void AudioEncoder::initialize()
|
||||
{
|
||||
setSampleFormat(Core::SampleFormat::S16);
|
||||
|
||||
int channels = Core::channelLayoutChannels(getChannelLayout());
|
||||
|
||||
_config.wave.channels = channels > 1 ? PCM_STEREO : PCM_MONO;
|
||||
_config.wave.samplerate = getSampleRate();
|
||||
_config.mpeg.bitr = (int)(getBitrate() / 1000);
|
||||
|
||||
if (shine_check_config(_config.wave.samplerate, _config.mpeg.bitr) < 0)
|
||||
throw Poco::InvalidAccessException(Poco::format("%s: Config error.", name()), -1);
|
||||
|
||||
_config.mpeg.mode = _config.wave.channels > 1 ? STEREO : MONO;
|
||||
|
||||
_pEncoder = shine_initialise(&_config);
|
||||
dummyConfig(&_config);
|
||||
|
||||
setFrameSize(shine_samples_per_pass(_pEncoder));
|
||||
}
|
||||
|
||||
void AudioEncoder::deinitialize()
|
||||
{
|
||||
if (_pEncoder)
|
||||
{
|
||||
shine_close(_pEncoder);
|
||||
_pEncoder = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
Core::Packet::Ptr AudioEncoder::encode()
|
||||
{
|
||||
if (!_pEncoder)
|
||||
return nullptr;
|
||||
|
||||
auto pIn = readFrame();
|
||||
int len;
|
||||
uint8_t* pData = shine_encode_buffer_interleaved(_pEncoder, (int16_t*)pIn->data[0].get(), &len);
|
||||
if (!pData || len <= 0)
|
||||
{
|
||||
logger().error("%s: Encode FAIL", name());
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
uint8_t* pBuffer = new uint8_t[len];
|
||||
memcpy(pBuffer, pData, len);
|
||||
|
||||
return new Core::Packet(serialCodeManager().code(), 0, pBuffer, len, pIn->timestamp, pIn->timestamp);
|
||||
}
|
||||
|
||||
void AudioEncoder::onConfigChanged(ParameterNames& names)
|
||||
{
|
||||
Core::AudioEncoder::onConfigChanged(names);
|
||||
}
|
||||
|
||||
void AudioEncoder::dummyConfig(shine_config_t* pConfig)
|
||||
{
|
||||
static const char* version_names[4] = {"2.5", "reserved", "II", "I"};
|
||||
static const char* mode_names[4] = {"stereo", "joint-stereo", "dual-channel", "mono"};
|
||||
static const char* demp_names[4] = {"none", "50/15us", "", "CITT"};
|
||||
|
||||
printf("MPEG-%s layer III, %s Psychoacoustic Model: Shine\n",
|
||||
version_names[shine_check_config(pConfig->wave.samplerate, pConfig->mpeg.bitr)],
|
||||
mode_names[pConfig->mpeg.mode]);
|
||||
printf("Bitrate: %d kbps ", pConfig->mpeg.bitr);
|
||||
printf("De-emphasis: %s %s %s\n", demp_names[pConfig->mpeg.emph], ((pConfig->mpeg.original) ? "Original" : ""),
|
||||
((pConfig->mpeg.copyright) ? "(C)" : ""));
|
||||
}
|
||||
}
|
||||
}
|
||||
43
video/shine/AudioEncoder.h
Normal file
43
video/shine/AudioEncoder.h
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
#ifndef FAAFB16A_5BB2_43F7_9F92_991E8328451D
|
||||
#define FAAFB16A_5BB2_43F7_9F92_991E8328451D
|
||||
/*
|
||||
*******************************************************************************
|
||||
* INCLUDE
|
||||
*******************************************************************************
|
||||
*/
|
||||
#include "../core/AudioEncoder.h"
|
||||
extern "C"
|
||||
{
|
||||
#include <shine/layer3.h>
|
||||
}
|
||||
|
||||
namespace Video
|
||||
{
|
||||
namespace Shine
|
||||
{
|
||||
/*
|
||||
*******************************************************************************
|
||||
* CLASS DECLARE
|
||||
*******************************************************************************
|
||||
*/
|
||||
class AudioEncoder: public Core::AudioEncoder
|
||||
{
|
||||
public:
|
||||
AudioEncoder(Core::CodecID codecID);
|
||||
~AudioEncoder();
|
||||
|
||||
protected:
|
||||
void initialize() override;
|
||||
void deinitialize() override;
|
||||
Core::Packet::Ptr encode() override;
|
||||
void onConfigChanged(ParameterNames& names) override;
|
||||
|
||||
void dummyConfig(shine_config_t* pConfig);
|
||||
|
||||
private:
|
||||
shine_t _pEncoder;
|
||||
shine_config_t _config;
|
||||
};
|
||||
}
|
||||
}
|
||||
#endif
|
||||
Loading…
Add table
Add a link
Reference in a new issue