2021-01-07 00:26:08 +08:00
|
|
|
/* ---------------------------------------------------------------------------
|
|
|
|
**
|
|
|
|
** ServerMediaSubsession.cpp
|
|
|
|
**
|
|
|
|
** -------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
#include "zm_rtsp_server_server_media_subsession.h"
|
2021-02-04 11:47:28 +08:00
|
|
|
|
|
|
|
#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"
|
2021-02-04 11:47:28 +08:00
|
|
|
#include <sstream>
|
2021-01-23 09:22:50 +08:00
|
|
|
|
2021-02-04 11:47:28 +08:00
|
|
|
#if HAVE_RTSP_SERVER
|
2021-01-07 00:26:08 +08:00
|
|
|
// ---------------------------------
|
|
|
|
// BaseServerMediaSubsession
|
|
|
|
// ---------------------------------
|
|
|
|
FramedSource* BaseServerMediaSubsession::createSource(
|
2021-02-28 01:26:19 +08:00
|
|
|
UsageEnvironment& env,
|
|
|
|
FramedSource* inputSource,
|
|
|
|
const std::string& format)
|
2021-01-07 00:26:08 +08:00
|
|
|
{
|
|
|
|
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") {
|
2021-03-02 03:01:22 +08:00
|
|
|
source = H264VideoStreamDiscreteFramer::createNew(env, inputSource
|
|
|
|
/*Boolean includeStartCodeInOutput, Boolean insertAccessUnitDelimiters*/
|
|
|
|
);
|
2021-01-07 00:26:08 +08:00
|
|
|
}
|
|
|
|
#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);
|
2021-01-07 00:26:08 +08:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#if 0
|
|
|
|
else if (format == "video/JPEG") {
|
2021-01-23 09:22:50 +08:00
|
|
|
source = MJPEGVideoSource::createNew(env, inputSource);
|
2021-01-07 00:26:08 +08:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
else {
|
2021-01-23 09:22:50 +08:00
|
|
|
source = inputSource;
|
2021-01-07 00:26:08 +08:00
|
|
|
}
|
|
|
|
return source;
|
|
|
|
}
|
|
|
|
|
2021-01-23 09:22:50 +08:00
|
|
|
/* source is generally a replica */
|
2021-01-07 00:26:08 +08:00
|
|
|
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-07 00:26:08 +08:00
|
|
|
) {
|
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);
|
2021-01-07 00:26:08 +08:00
|
|
|
}
|
|
|
|
#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);
|
2021-01-07 00:26:08 +08:00
|
|
|
#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,
|
2021-03-02 05:46:02 +08:00
|
|
|
adts_source->getFrequency(),
|
2021-01-23 09:22:50 +08:00
|
|
|
"audio", "AAC-hbr",
|
|
|
|
adts_source->configStr(),
|
2021-03-02 05:46:02 +08:00
|
|
|
adts_source->getChannels()
|
2021-01-23 09:22:50 +08:00
|
|
|
);
|
2021-01-07 00:26:08 +08:00
|
|
|
} else {
|
2021-01-23 09:22:50 +08:00
|
|
|
Error("unknown format");
|
2021-01-07 00:26:08 +08:00
|
|
|
}
|
|
|
|
#if 0
|
|
|
|
else if (format == "video/JPEG") {
|
2021-01-23 09:22:50 +08:00
|
|
|
sink = JPEGVideoRTPSink::createNew (env, rtpGroupsock);
|
2021-01-07 00:26:08 +08:00
|
|
|
}
|
|
|
|
#endif
|
2021-01-23 09:22:50 +08:00
|
|
|
return sink;
|
2021-01-07 00:26:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
char const* BaseServerMediaSubsession::getAuxLine(
|
2021-02-28 01:26:19 +08:00
|
|
|
ZoneMinderFifoSource* source,
|
2021-01-07 00:26:08 +08:00
|
|
|
unsigned char rtpPayloadType
|
|
|
|
) {
|
|
|
|
const char* auxLine = nullptr;
|
2021-02-28 01:26:19 +08:00
|
|
|
if (source) {
|
2021-01-07 00:26:08 +08:00
|
|
|
std::ostringstream os;
|
2021-01-23 09:22:50 +08:00
|
|
|
os << "a=fmtp:" << int(rtpPayloadType) << " ";
|
|
|
|
os << source->getAuxLine();
|
2021-03-02 03:01:22 +08:00
|
|
|
//os << "\r\n";
|
2021-01-07 00:26:08 +08:00
|
|
|
auxLine = strdup(os.str().c_str());
|
2021-03-02 03:01:22 +08:00
|
|
|
Debug(1, "BaseServerMediaSubsession::auxLine: %s", auxLine);
|
2021-01-07 00:26:08 +08:00
|
|
|
} else {
|
2021-02-28 01:26:19 +08:00
|
|
|
Error("No source auxLine:");
|
|
|
|
return "";
|
2021-01-23 09:22:50 +08:00
|
|
|
}
|
2021-01-07 00:26:08 +08:00
|
|
|
return auxLine;
|
|
|
|
}
|
2021-02-04 11:59:03 +08:00
|
|
|
#endif // HAVE_RTSP_SERVER
|