整理代码
This commit is contained in:
commit
c7b4e178ec
364 changed files with 59691 additions and 0 deletions
87
video/core/VideoEncoder.cpp
Normal file
87
video/core/VideoEncoder.cpp
Normal file
|
|
@ -0,0 +1,87 @@
|
|||
/*
|
||||
*******************************************************************************
|
||||
* 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue