zoneminder/src/zm_rtsp_server_server_media...

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

109 lines
3.2 KiB
C++
Raw Normal View History

/* ---------------------------------------------------------------------------
**
** ServerMediaSubsession.cpp
**
** -------------------------------------------------------------------------*/
#include "zm_rtsp_server_server_media_subsession.h"
#include "zm_config.h"
2021-01-23 09:22:50 +08:00
#include "zm_rtsp_server_adts_source.h"
2021-02-28 01:26:19 +08:00
#include "zm_rtsp_server_adts_fifo_source.h"
#include <sstream>
2021-01-23 09:22:50 +08:00
#if HAVE_RTSP_SERVER
// ---------------------------------
// BaseServerMediaSubsession
// ---------------------------------
FramedSource* BaseServerMediaSubsession::createSource(
2021-02-28 01:26:19 +08:00
UsageEnvironment& env,
FramedSource* inputSource,
const std::string& format)
{
FramedSource* source = nullptr;
2021-02-28 01:26:19 +08:00
if (format == "video/MP2T") {
2021-01-23 09:22:50 +08:00
source = MPEG2TransportStreamFramer::createNew(env, inputSource);
2021-02-28 01:26:19 +08:00
} else if (format == "video/H264") {
source = H264VideoStreamDiscreteFramer::createNew(env, inputSource
/*Boolean includeStartCodeInOutput, Boolean insertAccessUnitDelimiters*/
);
}
#if LIVEMEDIA_LIBRARY_VERSION_INT > 1414454400
2021-02-28 01:26:19 +08:00
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;
2021-02-28 01:26:19 +08:00
if (format == "video/MP2T") {
2021-01-23 09:22:50 +08:00
sink = SimpleRTPSink::createNew(env, rtpGroupsock, rtpPayloadTypeIfDynamic, 90000, "video", "MP2T", 1, true, false);
2021-02-28 01:26:19 +08:00
} else if (format == "video/H264") {
2021-01-23 09:22:50 +08:00
sink = H264VideoRTPSink::createNew(env, rtpGroupsock, rtpPayloadTypeIfDynamic);
2021-02-28 01:26:19 +08:00
} 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
2021-02-28 01:26:19 +08:00
else if (format == "video/VP9") {
2021-01-23 09:22:50 +08:00
sink = VP9VideoRTPSink::createNew(env, rtpGroupsock, rtpPayloadTypeIfDynamic);
2021-02-28 01:26:19 +08:00
} else if (format == "video/H265") {
2021-01-23 09:22:50 +08:00
sink = H265VideoRTPSink::createNew(env, rtpGroupsock, rtpPayloadTypeIfDynamic);
#endif
2021-02-28 01:26:19 +08:00
} else if (format == "audio/AAC") {
ADTS_ZoneMinderFifoSource *adts_source = (ADTS_ZoneMinderFifoSource *)(m_replicator->inputSource());
2021-01-23 09:22:50 +08:00
sink = MPEG4GenericRTPSink::createNew(env, rtpGroupsock,
rtpPayloadTypeIfDynamic,
adts_source->getFrequency(),
2021-01-23 09:22:50 +08:00
"audio", "AAC-hbr",
adts_source->configStr(),
adts_source->getChannels()
2021-01-23 09:22:50 +08:00
);
} 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(
2021-02-28 01:26:19 +08:00
ZoneMinderFifoSource* source,
unsigned char rtpPayloadType
) {
const char* auxLine = nullptr;
2021-02-28 01:26:19 +08:00
if (source) {
std::ostringstream os;
2021-01-23 09:22:50 +08:00
os << "a=fmtp:" << int(rtpPayloadType) << " ";
os << source->getAuxLine();
//os << "\r\n";
auxLine = strdup(os.str().c_str());
Debug(1, "BaseServerMediaSubsession::auxLine: %s", auxLine);
} else {
2021-02-28 01:26:19 +08:00
Error("No source auxLine:");
return "";
2021-01-23 09:22:50 +08:00
}
return auxLine;
}
#endif // HAVE_RTSP_SERVER