zoneminder/src/zm_rtsp_server_server_media...

110 lines
3.3 KiB
C++
Raw Normal View History

/* ---------------------------------------------------------------------------
**
** ServerMediaSubsession.cpp
**
** -------------------------------------------------------------------------*/
2021-01-27 23:50:07 +08:00
#include "zm.h"
#if HAVE_RTSP_SERVER
#include <sstream>
#include "zm_rtsp_server_server_media_subsession.h"
#include "zm_rtsp_server_device_source.h"
2021-01-23 09:22:50 +08:00
#include "zm_rtsp_server_adts_source.h"
// ---------------------------------
// BaseServerMediaSubsession
// ---------------------------------
FramedSource* BaseServerMediaSubsession::createSource(
2021-01-23 09:22:50 +08:00
UsageEnvironment& env, FramedSource* inputSource, const std::string& format)
{
FramedSource* source = nullptr;
if ( format == "video/MP2T" ) {
2021-01-23 09:22:50 +08:00
source = MPEG2TransportStreamFramer::createNew(env, inputSource);
} else if ( format == "video/H264" ) {
2021-01-23 09:22:50 +08:00
source = H264VideoStreamDiscreteFramer::createNew(env, inputSource);
}
#if LIVEMEDIA_LIBRARY_VERSION_INT > 1414454400
else if ( format == "video/H265" ) {
2021-01-23 09:22:50 +08:00
source = H265VideoStreamDiscreteFramer::createNew(env, inputSource);
}
#endif
#if 0
else if (format == "video/JPEG") {
2021-01-23 09:22:50 +08:00
source = MJPEGVideoSource::createNew(env, inputSource);
}
#endif
else {
2021-01-23 09:22:50 +08:00
source = inputSource;
}
return source;
}
2021-01-23 09:22:50 +08:00
/* source is generally a replica */
RTPSink* BaseServerMediaSubsession::createSink(
UsageEnvironment& env,
Groupsock* rtpGroupsock,
unsigned char rtpPayloadTypeIfDynamic,
2021-01-23 09:22:50 +08:00
const std::string& format,
FramedSource *source
) {
2021-01-23 09:22:50 +08:00
RTPSink* sink = nullptr;
if ( format == "video/MP2T" ) {
2021-01-23 09:22:50 +08:00
sink = SimpleRTPSink::createNew(env, rtpGroupsock, rtpPayloadTypeIfDynamic, 90000, "video", "MP2T", 1, true, false);
} else if ( format == "video/H264" ) {
2021-01-23 09:22:50 +08:00
sink = H264VideoRTPSink::createNew(env, rtpGroupsock, rtpPayloadTypeIfDynamic);
} else if ( format == "video/VP8" ) {
2021-01-23 09:22:50 +08:00
sink = VP8VideoRTPSink::createNew(env, rtpGroupsock, rtpPayloadTypeIfDynamic);
}
#if LIVEMEDIA_LIBRARY_VERSION_INT > 1414454400
else if ( format == "video/VP9" ) {
2021-01-23 09:22:50 +08:00
sink = VP9VideoRTPSink::createNew(env, rtpGroupsock, rtpPayloadTypeIfDynamic);
} else if ( format == "video/H265" ) {
2021-01-23 09:22:50 +08:00
sink = H265VideoRTPSink::createNew(env, rtpGroupsock, rtpPayloadTypeIfDynamic);
#endif
2021-01-23 09:22:50 +08:00
} else if ( format == "audio/AAC" ) {
ADTS_ZoneMinderDeviceSource *adts_source = (ADTS_ZoneMinderDeviceSource *)(m_replicator->inputSource());
sink = MPEG4GenericRTPSink::createNew(env, rtpGroupsock,
rtpPayloadTypeIfDynamic,
adts_source->samplingFrequency(),
"audio", "AAC-hbr",
adts_source->configStr(),
adts_source->numChannels()
);
} else {
2021-01-23 09:22:50 +08:00
Error("unknown format");
}
#if 0
else if (format == "video/JPEG") {
2021-01-23 09:22:50 +08:00
sink = JPEGVideoRTPSink::createNew (env, rtpGroupsock);
}
#endif
2021-01-23 09:22:50 +08:00
return sink;
}
char const* BaseServerMediaSubsession::getAuxLine(
ZoneMinderDeviceSource* source,
unsigned char rtpPayloadType
) {
const char* auxLine = nullptr;
if ( source ) {
std::ostringstream os;
2021-01-23 09:22:50 +08:00
os << "a=fmtp:" << int(rtpPayloadType) << " ";
os << source->getAuxLine();
os << "\r\n";
int width = source->getWidth();
int height = source->getHeight();
if ( (width > 0) && (height>0) ) {
2021-01-23 09:22:50 +08:00
os << "a=x-dimensions:" << width << "," << height << "\r\n";
}
auxLine = strdup(os.str().c_str());
2021-01-23 09:22:50 +08:00
Debug(1, "auxLine: %s", auxLine);
} else {
2021-01-21 23:25:26 +08:00
Error("No source auxLine: ");
2021-01-23 09:22:50 +08:00
}
return auxLine;
}
2021-01-27 07:29:02 +08:00
#endif