179 lines
5.3 KiB
C++
179 lines
5.3 KiB
C++
/*
|
|
*******************************************************************************
|
|
* INCLUDE
|
|
*******************************************************************************
|
|
*/
|
|
#include "Logger.h"
|
|
#include "VideoSubsystem.h"
|
|
|
|
#include "core/Demuxer.h"
|
|
#include "core/AudioDecoder.h"
|
|
#include "core/AudioMixer.h"
|
|
|
|
#include "v4l2/Input.h"
|
|
#include "alsa/Output.h"
|
|
|
|
#include "libopus/AudioEncoder.h"
|
|
#include "libopus/AudioDecodeHandler.h"
|
|
#include "shine/AudioEncoder.h"
|
|
|
|
#include "hisi/mpp5/System.h"
|
|
#include "hisi/mpp5/VideoInput.h"
|
|
#include "hisi/mpp5/VideoEncoder.h"
|
|
#include "hisi/mpp5/VideoDecoder.h"
|
|
#include "hisi/mpp5/VideoProcessor.h"
|
|
#include "hisi/mpp5/VideoMixer.h"
|
|
#include "hisi/mpp5/VideoOverlay.h"
|
|
#include "hisi/mpp5/AudioEncoder.h"
|
|
#include "hisi/mpp5/HDMIAudioOutput.h"
|
|
#include "hisi/mpp5/HDMIVideoOutput.h"
|
|
|
|
#if defined(USING_FFMPEG)
|
|
#include "ffmpeg/Muxer.h"
|
|
#include "ffmpeg/DemuxHandler.h"
|
|
#include "ffmpeg/AudioEncoder.h"
|
|
#include "ffmpeg/AudioDecodeHandler.h"
|
|
#include "ffmpeg/AudioResample.h"
|
|
extern "C"
|
|
{
|
|
#include <libavutil/log.h>
|
|
}
|
|
#endif
|
|
|
|
#include "mediaserver/RTMPMuxer.h"
|
|
#include "mediaserver/MPEGMuxer.h"
|
|
#include "mediaserver/RTMPDemuxHandler.h"
|
|
#include <sdk/include/sockutil.h>
|
|
|
|
namespace Video
|
|
{
|
|
/*
|
|
*******************************************************************************
|
|
* CLASS DEFINE
|
|
*******************************************************************************
|
|
*/
|
|
VideoSubsystem::VideoSubsystem()
|
|
{
|
|
}
|
|
|
|
VideoSubsystem::~VideoSubsystem()
|
|
{
|
|
}
|
|
|
|
const char* VideoSubsystem::name() const
|
|
{
|
|
return "Video";
|
|
}
|
|
|
|
void VideoSubsystem::initialize(Poco::Util::Application& app)
|
|
{
|
|
socket_init();
|
|
|
|
Core::System::registerClass<MPP5::System>();
|
|
|
|
Core::VideoEncoder::registerClass<MPP5::VideoEncoder>(Core::CodecID::H264);
|
|
Core::VideoEncoder::registerClass<MPP5::VideoEncoder>(Core::CodecID::H265);
|
|
Core::VideoDecoder::registerClass<MPP5::VideoDecoder>(0);
|
|
Core::VideoProcessor::registerClass<MPP5::VideoProcessor>(0);
|
|
Core::VideoMixer::registerClass<MPP5::VideoMixer>(0);
|
|
Core::VideoOverlay::registerClass<MPP5::VideoOverlay>(Core::VideoOverlayType::CANVAS);
|
|
Core::VideoOverlay::registerClass<MPP5::VideoOverlay>(Core::VideoOverlayType::MOSAIC);
|
|
Core::VideoOutput::registerClass<MPP5::HDMIVideoOutput>("HDMI");
|
|
|
|
Core::AudioEncoder::registerClass<MPP5::AudioEncoder>(Core::CodecID::AAC);
|
|
Core::AudioDecoder::registerClass<Core::AudioDecoder>(0);
|
|
Core::AudioMixer::registerClass<Core::AudioMixer>(0);
|
|
Core::AudioOutput::registerClass<ALSA::Output>("ALSA");
|
|
Core::AudioOutput::registerClass<MPP5::HDMIAudioOutput>("HDMI");
|
|
|
|
Core::AudioEncoder::registerClass<LibOPUS::AudioEncoder>(Core::CodecID::OPUS);
|
|
Core::AudioDecodeHandler::registerClass<LibOPUS::AudioDecodeHandler>(Core::CodecID::OPUS);
|
|
Core::AudioEncoder::registerClass<Shine::AudioEncoder>(Core::CodecID::MP3);
|
|
|
|
#if defined(USING_FFMPEG)
|
|
|
|
Core::Muxer::registerClass<FFmpeg::Muxer>("rtsp");
|
|
|
|
Core::DemuxHandler::registerClass<MediaServer::RTMPDemuxHandler>("rtmp");
|
|
Core::DemuxHandler::registerClass<FFmpeg::DemuxHandler>("rtsp");
|
|
Core::DemuxHandler::registerClass<FFmpeg::DemuxHandler>("file");
|
|
|
|
Core::AudioEncoder::registerClass<FFmpeg::AudioEncoder>(Core::CodecID::G711A);
|
|
Core::AudioEncoder::registerClass<FFmpeg::AudioEncoder>(Core::CodecID::G711U);
|
|
|
|
Core::AudioResample::registerClass<FFmpeg::AudioResample>(0);
|
|
|
|
Core::AudioDecodeHandler::registerClass<FFmpeg::AudioDecodeHandler>(Core::CodecID::AAC);
|
|
Core::AudioDecodeHandler::registerClass<FFmpeg::AudioDecodeHandler>(Core::CodecID::G711A);
|
|
Core::AudioDecodeHandler::registerClass<FFmpeg::AudioDecodeHandler>(Core::CodecID::G711U);
|
|
#endif
|
|
|
|
Core::Muxer::registerClass<MediaServer::RTMPMuxer>("rtmp");
|
|
Core::Muxer::registerClass<MediaServer::MPEGMuxer>("udp");
|
|
Core::DemuxHandler::registerClass<MediaServer::RTMPDemuxHandler>("rtmp");
|
|
|
|
MPP5::VideoInput::initModule();
|
|
MPP5::VideoEncoder::initModule();
|
|
MPP5::VideoDecoder::initModule();
|
|
MPP5::AudioEncoder::initModule();
|
|
}
|
|
|
|
void VideoSubsystem::uninitialize()
|
|
{
|
|
stopAll();
|
|
#ifdef USING_ONVIF
|
|
ONVIF::ONVIFService::getIns()->stop();
|
|
#endif
|
|
MPP5::AudioEncoder::deinitModule();
|
|
MPP5::VideoInput::deinitModule();
|
|
MPP5::VideoEncoder::deinitModule();
|
|
|
|
socket_cleanup();
|
|
}
|
|
|
|
#if defined(USING_FFMPEG)
|
|
void VideoSubsystem::ffmpegLogCallback(void* ptr, int level, const char* fmt, va_list args)
|
|
{
|
|
if (level > av_log_get_level())
|
|
return;
|
|
|
|
char str[4096];
|
|
int len = sizeof(str);
|
|
|
|
int n = vsnprintf(str, len, fmt, args);
|
|
if (n >= len)
|
|
n = len - 1;
|
|
|
|
switch (level)
|
|
{
|
|
case AV_LOG_TRACE:
|
|
logger().trace("FFMPEG: " + std::string(str, n));
|
|
break;
|
|
|
|
case AV_LOG_VERBOSE:
|
|
case AV_LOG_DEBUG:
|
|
logger().debug("FFMPEG: " + std::string(str, n));
|
|
break;
|
|
|
|
case AV_LOG_INFO:
|
|
logger().information("FFMPEG: " + std::string(str, n));
|
|
break;
|
|
|
|
case AV_LOG_WARNING:
|
|
logger().warning("FFMPEG: " + std::string(str, n));
|
|
break;
|
|
|
|
case AV_LOG_ERROR:
|
|
logger().error("FFMPEG: " + std::string(str, n));
|
|
break;
|
|
|
|
case AV_LOG_FATAL:
|
|
logger().fatal("FFMPEG: " + std::string(str, n));
|
|
break;
|
|
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
#endif
|
|
}
|