87 lines
2.1 KiB
C++
87 lines
2.1 KiB
C++
/*
|
|
*******************************************************************************
|
|
* INCLUDE
|
|
*******************************************************************************
|
|
*/
|
|
#include "VideoEncoder.h"
|
|
#include "Logger.h"
|
|
|
|
namespace Video
|
|
{
|
|
namespace Core
|
|
{
|
|
/*
|
|
*******************************************************************************
|
|
* CLASS DEFINE
|
|
*******************************************************************************
|
|
*/
|
|
VideoEncoder::VideoEncoder(const std::string& name, CodecID codecID): VideoComponent(name)
|
|
{
|
|
setCodecID(codecID);
|
|
|
|
setCodecProfile(CodecProfile::H264_MAIN);
|
|
setBitrate(4000000);
|
|
setGOP(30);
|
|
setGOPMode(GOPMode::NORMAL_P);
|
|
setBitrateControl(BitrateControl::VBR);
|
|
setAdaptable(false);
|
|
}
|
|
|
|
VideoEncoder::~VideoEncoder()
|
|
{
|
|
}
|
|
|
|
void VideoEncoder::start()
|
|
{
|
|
_task.run(
|
|
[this](std::atomic<bool>& isCancelled) -> void
|
|
{
|
|
while (!isCancelled)
|
|
{
|
|
try
|
|
{
|
|
postToNextComponents(sharedFromThis(), encode(readFrame()), MediaType::VIDEO);
|
|
}
|
|
catch (Poco::Exception& e)
|
|
{
|
|
logger().error("%s: %s", name(), e.displayText());
|
|
Poco::Thread::sleep(100);
|
|
}
|
|
catch (std::exception& e)
|
|
{
|
|
logger().error("%s: %s", name(), std::string(e.what()));
|
|
Poco::Thread::sleep(100);
|
|
}
|
|
}
|
|
});
|
|
}
|
|
|
|
void VideoEncoder::stop()
|
|
{
|
|
_task.cancel();
|
|
}
|
|
|
|
Packet::Ptr VideoEncoder::encode(Frame::Ptr pFrame)
|
|
{
|
|
return nullptr;
|
|
}
|
|
|
|
Frame::Ptr VideoEncoder::readFrame(uint32_t timeout)
|
|
{
|
|
if (previousComponents().size() == 0)
|
|
throw Poco::NotFoundException("No previous components");
|
|
|
|
return frameQueues().first()->dequeue(timeout);
|
|
}
|
|
|
|
void VideoEncoder::onLink(Core::Component::Ptr pPrevious)
|
|
{
|
|
frameQueues().add(pPrevious, name(), MediaType::VIDEO);
|
|
}
|
|
|
|
void VideoEncoder::onUnlink(Core::Component::Ptr pPrevious)
|
|
{
|
|
frameQueues().remove(pPrevious);
|
|
}
|
|
}
|
|
}
|