95 lines
2.4 KiB
C++
95 lines
2.4 KiB
C++
/*
|
|
*******************************************************************************
|
|
* INCLUDE
|
|
*******************************************************************************
|
|
*/
|
|
#include "Muxer.h"
|
|
#include "AudioComponent.h"
|
|
#include "VideoComponent.h"
|
|
#include "Logger.h"
|
|
|
|
namespace Video
|
|
{
|
|
namespace Core
|
|
{
|
|
/*
|
|
*******************************************************************************
|
|
* CLASS DEFINE
|
|
*******************************************************************************
|
|
*/
|
|
Muxer::Muxer(const std::string& name, const std::string& url): Component(name), _url(url)
|
|
{
|
|
}
|
|
|
|
Muxer::~Muxer()
|
|
{
|
|
}
|
|
|
|
void Muxer::start()
|
|
{
|
|
_task.run(
|
|
[this](std::atomic<bool>& isCancelled) -> void
|
|
{
|
|
while (!isCancelled)
|
|
{
|
|
try
|
|
{
|
|
connect();
|
|
while (!isCancelled)
|
|
mux();
|
|
}
|
|
catch (Poco::Exception& e)
|
|
{
|
|
logger().error("%s(CONNECT/MUX): %s", name(), e.displayText());
|
|
}
|
|
catch (std::exception& e)
|
|
{
|
|
logger().error("%s(CONNECT/MUX): %s", name(), std::string(e.what()));
|
|
}
|
|
|
|
try
|
|
{
|
|
disconnect();
|
|
}
|
|
catch (Poco::Exception& e)
|
|
{
|
|
logger().error("%s(DISCONNECT): %s", name(), e.displayText());
|
|
}
|
|
catch (std::exception& e)
|
|
{
|
|
logger().error("%s(DISCONNECT): %s", name(), std::string(e.what()));
|
|
}
|
|
|
|
if (!isCancelled)
|
|
Poco::Thread::sleep(1000);
|
|
}
|
|
});
|
|
}
|
|
|
|
void Muxer::stop()
|
|
{
|
|
_task.cancel();
|
|
}
|
|
|
|
void Muxer::onLink(Component::Ptr pPrevious)
|
|
{
|
|
if (dynamic_cast<AudioComponent*>(pPrevious.get()))
|
|
packetQueues().add(pPrevious, name(), MediaType::AUDIO);
|
|
else if (dynamic_cast<VideoComponent*>(pPrevious.get()))
|
|
packetQueues().add(pPrevious, name(), MediaType::VIDEO);
|
|
else
|
|
{
|
|
logger().error("%s: Unsupport class '%s'", name(), std::string(typeid(*pPrevious).name()));
|
|
}
|
|
}
|
|
|
|
void Muxer::onUnlink(Component::Ptr pPrevious)
|
|
{
|
|
packetQueues().remove(pPrevious);
|
|
}
|
|
|
|
void Muxer::onConfigChanged(ParameterNames& names)
|
|
{
|
|
}
|
|
}
|
|
}
|