From 66a3b7a9ca44c616e7ca5e7f7f645fc3df235fed Mon Sep 17 00:00:00 2001 From: Liu Jiang Date: Sat, 26 Dec 2020 15:08:01 +0800 Subject: [PATCH 1/4] =?UTF-8?q?RTSP=E6=8E=A8=E6=B5=81=E5=A2=9E=E5=8A=A0L16?= =?UTF-8?q?=E5=8A=A8=E6=80=81payload=20type=E6=94=AF=E6=8C=81(RFC=203551?= =?UTF-8?q?=20Section=204.5.11,=20RFC=202586)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Extension/Factory.cpp | 7 ++++ src/Extension/Frame.h | 1 + src/Extension/L16.cpp | 26 ++++++++++++++ src/Extension/L16.h | 74 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 108 insertions(+) create mode 100644 src/Extension/L16.cpp create mode 100644 src/Extension/L16.h diff --git a/src/Extension/Factory.cpp b/src/Extension/Factory.cpp index fba7109b..fa2248de 100644 --- a/src/Extension/Factory.cpp +++ b/src/Extension/Factory.cpp @@ -20,6 +20,7 @@ #include "CommonRtp.h" #include "Opus.h" #include "G711.h" +#include "L16.h" #include "Common/Parser.h" namespace mediakit{ @@ -56,6 +57,10 @@ Track::Ptr Factory::getTrackBySdp(const SdpTrack::Ptr &track) { return std::make_shared(CodecG711U, track->_samplerate, track->_channel, 16); } + if (strcasecmp(track->_codec.data(), "L16") == 0) { + return std::make_shared(track->_samplerate, track->_channel); + } + if (strcasecmp(track->_codec.data(), "h264") == 0) { //a=fmtp:96 packetization-mode=1;profile-level-id=42C01F;sprop-parameter-sets=Z0LAH9oBQBboQAAAAwBAAAAPI8YMqA==,aM48gA== auto map = Parser::parseArgs(FindField(track->_fmtp.data()," ", nullptr),";","="); @@ -123,6 +128,7 @@ RtpCodec::Ptr Factory::getRtpEncoderBySdp(const Sdp::Ptr &sdp) { case CodecH264 : return std::make_shared(ssrc, mtu, sample_rate, pt, interleaved); case CodecH265 : return std::make_shared(ssrc, mtu, sample_rate, pt, interleaved); case CodecAAC : return std::make_shared(ssrc, mtu, sample_rate, pt, interleaved); + case CodecL16 : case CodecOpus : case CodecG711A : case CodecG711U : return std::make_shared(codec_id, ssrc, mtu, sample_rate, pt, interleaved); @@ -135,6 +141,7 @@ RtpCodec::Ptr Factory::getRtpDecoderByTrack(const Track::Ptr &track) { case CodecH264 : return std::make_shared(); case CodecH265 : return std::make_shared(); case CodecAAC : return std::make_shared(track->clone()); + case CodecL16 : case CodecOpus : case CodecG711A : case CodecG711U : return std::make_shared(track->getCodecId()); diff --git a/src/Extension/Frame.h b/src/Extension/Frame.h index a967392c..2453b4f1 100644 --- a/src/Extension/Frame.h +++ b/src/Extension/Frame.h @@ -28,6 +28,7 @@ typedef enum { CodecAAC, CodecG711A, CodecG711U, + CodecL16, CodecOpus, CodecMax = 0x7FFF } CodecId; diff --git a/src/Extension/L16.cpp b/src/Extension/L16.cpp new file mode 100644 index 00000000..8cc0c977 --- /dev/null +++ b/src/Extension/L16.cpp @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2016 The ZLMediaKit project authors. All Rights Reserved. + * + * This file is part of ZLMediaKit(https://github.com/xiongziliang/ZLMediaKit). + * + * Use of this source code is governed by MIT license that can be found in the + * LICENSE file in the root of the source tree. All contributing project authors + * may be found in the AUTHORS file in the root of the source tree. + */ + +#include "L16.h" + +namespace mediakit{ + +Sdp::Ptr L16Track::getSdp() { + WarnL << "Enter L16Track::getSdp function"; + if(!ready()){ + WarnL << getCodecName() << " Track未准备好"; + return nullptr; + } + return std::make_shared(getCodecId(), getAudioSampleRate(), getAudioChannel(), getBitRate() / 1024); +} + +}//namespace mediakit + + diff --git a/src/Extension/L16.h b/src/Extension/L16.h new file mode 100644 index 00000000..38b3f131 --- /dev/null +++ b/src/Extension/L16.h @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2016 The ZLMediaKit project authors. All Rights Reserved. + * + * This file is part of ZLMediaKit(https://github.com/xiongziliang/ZLMediaKit). + * + * Use of this source code is governed by MIT license that can be found in the + * LICENSE file in the root of the source tree. All contributing project authors + * may be found in the AUTHORS file in the root of the source tree. + */ + +#ifndef ZLMEDIAKIT_L16_H +#define ZLMEDIAKIT_L16_H + +#include "Frame.h" +#include "Track.h" + +namespace mediakit{ + +/** + * L16音频通道 + */ +class L16Track : public AudioTrackImp{ +public: + typedef std::shared_ptr Ptr; + L16Track(int sample_rate, int channels) : AudioTrackImp(CodecL16,sample_rate,channels,16){} + +private: + //克隆该Track + Track::Ptr clone() override { + return std::make_shared::type >(*this); + } + //生成sdp + Sdp::Ptr getSdp() override ; +}; + +/** + * L16类型SDP + */ +class L16Sdp : public Sdp { +public: + /** + * L16采样位数固定为16位 + * @param codecId CodecL16 + * @param sample_rate 音频采样率 + * @param payload_type rtp payload + * @param bitrate 比特率 + */ + L16Sdp(CodecId codecId, + int sample_rate, + int channels, + int bitrate = 128, + int payload_type = 98) : Sdp(sample_rate,payload_type), _codecId(codecId){ + _printer << "m=audio 0 RTP/AVP " << payload_type << "\r\n"; + if (bitrate) { + _printer << "b=AS:" << bitrate << "\r\n"; + } + _printer << "a=rtpmap:" << payload_type << " L16/" << sample_rate << "/" << channels << "\r\n"; + _printer << "a=control:trackID=" << (int)TrackAudio << "\r\n"; + } + + string getSdp() const override { + return _printer; + } + + CodecId getCodecId() const override { + return _codecId; + } +private: + _StrPrinter _printer; + CodecId _codecId; +}; + +}//namespace mediakit +#endif //ZLMEDIAKIT_L16_H \ No newline at end of file From 525949c36252506a4dfa3ca2924986a903520ade Mon Sep 17 00:00:00 2001 From: Liu Jiang Date: Sat, 26 Dec 2020 16:00:35 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=E5=B0=86CodecL16=E6=94=BE=E7=BD=AE?= =?UTF-8?q?=E5=88=B0enum=E6=9C=80=E5=90=8E,=E9=98=B2=E6=AD=A2=E5=85=BC?= =?UTF-8?q?=E5=AE=B9=E6=80=A7=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Extension/Frame.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Extension/Frame.h b/src/Extension/Frame.h index 2453b4f1..039e3395 100644 --- a/src/Extension/Frame.h +++ b/src/Extension/Frame.h @@ -28,8 +28,8 @@ typedef enum { CodecAAC, CodecG711A, CodecG711U, - CodecL16, CodecOpus, + CodecL16, CodecMax = 0x7FFF } CodecId; From d270a780895a50eed495ec493bfd3394b991aab1 Mon Sep 17 00:00:00 2001 From: Liu Jiang Date: Sat, 26 Dec 2020 16:01:08 +0800 Subject: [PATCH 3/4] =?UTF-8?q?getTrackType=E5=92=8CgetCodecName=E5=87=BD?= =?UTF-8?q?=E6=95=B0=E9=80=82=E9=85=8DL16?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Extension/Frame.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Extension/Frame.cpp b/src/Extension/Frame.cpp index ec8a3608..45c2db38 100644 --- a/src/Extension/Frame.cpp +++ b/src/Extension/Frame.cpp @@ -80,6 +80,7 @@ const char *getCodecName(CodecId codecId) { SWITCH_CASE(CodecG711A); SWITCH_CASE(CodecG711U); SWITCH_CASE(CodecOpus); + SWITCH_CASE(CodecL16); default : return "unknown codec"; } } @@ -91,7 +92,8 @@ TrackType getTrackType(CodecId codecId){ case CodecAAC: case CodecG711A: case CodecG711U: - case CodecOpus: return TrackAudio; + case CodecOpus: + case CodecL16: return TrackAudio; default: return TrackInvalid; } } From 923768623a77d77dc1a9935ed08375c1dba789f7 Mon Sep 17 00:00:00 2001 From: Liu Jiang Date: Sat, 26 Dec 2020 16:52:36 +0800 Subject: [PATCH 4/4] =?UTF-8?q?L16=E6=A0=BC=E5=BC=8F=E6=B6=88=E9=99=A4unkn?= =?UTF-8?q?own=20codec=E6=8F=90=E9=86=92,=E6=B7=BB=E5=8A=A0=E5=8F=AA?= =?UTF-8?q?=E6=94=AF=E6=8C=81RTSP=E5=8D=8F=E8=AE=AE=E6=8E=A8=E6=B5=81?= =?UTF-8?q?=E6=8B=89=E6=B5=81=E6=8F=90=E9=86=92?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Common/MultiMediaSourceMuxer.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Common/MultiMediaSourceMuxer.cpp b/src/Common/MultiMediaSourceMuxer.cpp index f3d44352..906af81c 100644 --- a/src/Common/MultiMediaSourceMuxer.cpp +++ b/src/Common/MultiMediaSourceMuxer.cpp @@ -361,6 +361,10 @@ bool MultiMediaSourceMuxer::stopSendRtp(MediaSource &sender){ } void MultiMediaSourceMuxer::addTrack(const Track::Ptr &track) { + if (CodecL16 == track->getCodecId()) { + WarnL << "L16音频格式目前只支持RTSP协议推流拉流!!!"; + return; + } _muxer->addTrack(track); }