diff --git a/src/Common/MultiMediaSourceMuxer.cpp b/src/Common/MultiMediaSourceMuxer.cpp index e9db150f..f2ed90c3 100644 --- a/src/Common/MultiMediaSourceMuxer.cpp +++ b/src/Common/MultiMediaSourceMuxer.cpp @@ -369,6 +369,10 @@ bool MultiMediaSourceMuxer::stopSendRtp(MediaSource &sender, const string& ssrc) } void MultiMediaSourceMuxer::addTrack(const Track::Ptr &track) { + if (CodecL16 == track->getCodecId()) { + WarnL << "L16音频格式目前只支持RTSP协议推流拉流!!!"; + return; + } _muxer->addTrack(track); } 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.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; } } diff --git a/src/Extension/Frame.h b/src/Extension/Frame.h index a967392c..039e3395 100644 --- a/src/Extension/Frame.h +++ b/src/Extension/Frame.h @@ -29,6 +29,7 @@ typedef enum { CodecG711A, CodecG711U, CodecOpus, + CodecL16, 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