From 66a3b7a9ca44c616e7ca5e7f7f645fc3df235fed Mon Sep 17 00:00:00 2001 From: Liu Jiang Date: Sat, 26 Dec 2020 15:08:01 +0800 Subject: [PATCH] =?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