整理代码

This commit is contained in:
蒲爽 2026-09-28 21:33:04 +08:00
commit c7b4e178ec
364 changed files with 59691 additions and 0 deletions

View file

@ -0,0 +1,85 @@
/*
*******************************************************************************
* INCLUDE
*******************************************************************************
*/
#include "AudioEncoder.h"
#include "Logger.h"
#include <cstdint>
namespace Video
{
namespace Core
{
/*
*******************************************************************************
* CLASS DEFINE
*******************************************************************************
*/
AudioEncoder::AudioEncoder(const std::string& name, CodecID codecID): AudioAdaptablePipe(name)
{
setCodecID(codecID);
setBitrate(128000);
}
AudioEncoder::~AudioEncoder()
{
}
void AudioEncoder::start()
{
_task.run(
[this](std::atomic<bool>& isCancelled) -> void
{
Packet::Ptr pPacket;
while (!isCancelled)
{
try
{
pPacket = encode();
if (!pPacket)
continue;
postToNextComponents(sharedFromThis(), pPacket, MediaType::AUDIO);
}
catch (Poco::Exception& e)
{
logger().error("%s: %s", name(), e.displayText());
Poco::Thread::sleep(1000);
}
catch (std::exception& e)
{
logger().error("%s: %s", name(), std::string(e.what()));
Poco::Thread::sleep(1000);
}
}
});
}
void AudioEncoder::stop()
{
_task.cancel();
}
Frame::Ptr AudioEncoder::readFrame(uint32_t timeout)
{
Frame::Ptr pFrame = AudioAdaptablePipe::readFrame(timeout);
const int64_t off = _ptsOffsetUs.load(std::memory_order_relaxed);
if (off != 0)
{
const int64_t ts = (int64_t)pFrame->timestamp + off;
pFrame->timestamp = (ts > 0) ? (uint64_t)ts : 0ULL;
}
return pFrame;
}
void AudioEncoder::onConfigChanged(ParameterNames& names)
{
if (names.exists(_PTSOffset))
_ptsOffsetUs.store(getPTSOffset(), std::memory_order_relaxed);
}
}
}