mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2026-07-04 01:37:33 +08:00
整理文件 规范命名
This commit is contained in:
@@ -1,129 +0,0 @@
|
||||
/*
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2016 xiongziliang <771730766@qq.com>
|
||||
*
|
||||
* This file is part of ZLMediaKit(https://github.com/xiongziliang/ZLMediaKit).
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <cctype>
|
||||
#include <algorithm>
|
||||
#include "RtpParser.h"
|
||||
#include "Util/base64.h"
|
||||
#include "H264/SPSParser.h"
|
||||
#include "Common/Factory.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
namespace mediakit {
|
||||
|
||||
static int getTimeInSDP(const string &sdp) {
|
||||
auto strRange = FindField(sdp.data(), "a=range:npt=", "\r\n");
|
||||
strRange.append(" ");
|
||||
auto iPos = strRange.find('-');
|
||||
if (iPos == string::npos) {
|
||||
return 0;
|
||||
}
|
||||
auto strStart = strRange.substr(0, iPos);
|
||||
auto strEnd = strRange.substr(iPos + 1);
|
||||
strEnd.pop_back();
|
||||
if (strStart == "now") {
|
||||
strStart = "0";
|
||||
}
|
||||
return atof(strEnd.data()) - atof(strStart.data());
|
||||
}
|
||||
RtpParser::RtpParser(const string& sdp) {
|
||||
RtspTrack tmp[2];
|
||||
int cnt = parserSDP(sdp, tmp);
|
||||
for (int i = 0; i < cnt; i++) {
|
||||
switch (tmp[i].type) {
|
||||
case TrackVideo: {
|
||||
onGetVideoTrack(tmp[i]);
|
||||
}
|
||||
break;
|
||||
case TrackAudio: {
|
||||
onGetAudioTrack(tmp[i]);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
_fDuration = getTimeInSDP(sdp);
|
||||
}
|
||||
|
||||
bool RtpParser::inputRtp(const RtpPacket::Ptr & rtp) {
|
||||
switch (rtp->getTrackType()) {
|
||||
case TrackVideo:{
|
||||
if(_videoRtpDecoder){
|
||||
return _videoRtpDecoder->inputRtp(rtp, true);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
case TrackAudio:{
|
||||
_audioRtpDecoder->inputRtp(rtp, false);
|
||||
return false;
|
||||
}
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
inline void RtpParser::onGetAudioTrack(const RtspTrack& audio) {
|
||||
//生成Track对象
|
||||
_audioTrack = dynamic_pointer_cast<AudioTrack>(Factory::getTrackBySdp(audio.trackSdp));
|
||||
if(_audioTrack){
|
||||
//生成RtpCodec对象以便解码rtp
|
||||
_audioRtpDecoder = Factory::getRtpDecoderById(_audioTrack->getCodecId(),_audioTrack->getAudioSampleRate());
|
||||
if(_audioRtpDecoder){
|
||||
//设置rtp解码器代理,生成的frame写入该Track
|
||||
_audioRtpDecoder->setDelegate(_audioTrack);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
inline void RtpParser::onGetVideoTrack(const RtspTrack& video) {
|
||||
//生成Track对象
|
||||
_videoTrack = dynamic_pointer_cast<VideoTrack>(Factory::getTrackBySdp(video.trackSdp));
|
||||
if(_videoTrack){
|
||||
//生成RtpCodec对象以便解码rtp
|
||||
_videoRtpDecoder = Factory::getRtpDecoderById(_videoTrack->getCodecId(),90000);
|
||||
if(_videoRtpDecoder){
|
||||
//设置rtp解码器代理,生成的frame写入该Track
|
||||
_videoRtpDecoder->setDelegate(_videoTrack);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
vector<Track::Ptr> RtpParser::getTracks() const {
|
||||
vector<Track::Ptr> ret;
|
||||
if(_videoTrack){
|
||||
ret.emplace_back(_videoTrack);
|
||||
}
|
||||
if(_audioTrack){
|
||||
ret.emplace_back(_audioTrack);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
} /* namespace mediakit */
|
||||
@@ -1,86 +0,0 @@
|
||||
/*
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2016 xiongziliang <771730766@qq.com>
|
||||
*
|
||||
* This file is part of ZLMediaKit(https://github.com/xiongziliang/ZLMediaKit).
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef SRC_RTP_RTPPARSER_H_
|
||||
#define SRC_RTP_RTPPARSER_H_
|
||||
|
||||
#include <unordered_map>
|
||||
#include "Rtsp/Rtsp.h"
|
||||
#include "Player/Player.h"
|
||||
#include "Player/PlayerBase.h"
|
||||
#include "Util/TimeTicker.h"
|
||||
#include "RtpCodec/RtpCodec.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace toolkit;
|
||||
|
||||
namespace mediakit {
|
||||
|
||||
class RtpParser : public PlayerBase{
|
||||
public:
|
||||
typedef std::shared_ptr<RtpParser> Ptr;
|
||||
RtpParser(const string &sdp);
|
||||
virtual ~RtpParser(){};
|
||||
|
||||
//返回值:true 代表是i帧第一个rtp包
|
||||
bool inputRtp(const RtpPacket::Ptr &rtp);
|
||||
|
||||
float getDuration() const override {
|
||||
return _fDuration;
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回是否完成初始化完毕
|
||||
* 由于有些rtsp的sdp不包含sps pps信息
|
||||
* 所以要等待接收到到sps的rtp包后才能完成
|
||||
* @return
|
||||
*/
|
||||
bool isInited() const override{
|
||||
bool ret = true;
|
||||
if(ret && _audioTrack){
|
||||
ret = _audioTrack->getTrackType() != TrackInvalid;
|
||||
}
|
||||
if(ret && _videoTrack){
|
||||
ret = _videoTrack->getTrackType() != TrackInvalid;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
vector<Track::Ptr> getTracks() const override;
|
||||
private:
|
||||
inline void onGetAudioTrack(const RtspTrack &audio);
|
||||
inline void onGetVideoTrack(const RtspTrack &video);
|
||||
private:
|
||||
float _fDuration = 0;
|
||||
AudioTrack::Ptr _audioTrack;
|
||||
VideoTrack::Ptr _videoTrack;
|
||||
RtpCodec::Ptr _audioRtpDecoder;
|
||||
RtpCodec::Ptr _videoRtpDecoder;
|
||||
};
|
||||
|
||||
} /* namespace mediakit */
|
||||
|
||||
#endif /* SRC_RTP_RTPPARSER_H_ */
|
||||
@@ -1,21 +0,0 @@
|
||||
//
|
||||
// Created by xzl on 2018/10/24.
|
||||
//
|
||||
|
||||
#include "RtspMaker.h"
|
||||
#include "Common/Factory.h"
|
||||
|
||||
namespace mediakit {
|
||||
|
||||
void RtspMaker::addTrack(const Track::Ptr &track, uint32_t ssrc, int mtu) {
|
||||
if (track->getCodecId() == CodecInvalid) {
|
||||
addTrack(std::make_shared<TitleSdp>(), ssrc, mtu);
|
||||
} else {
|
||||
Sdp::Ptr sdp = Factory::getSdpByTrack(track);
|
||||
if (sdp) {
|
||||
addTrack(sdp, ssrc, mtu);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} /* namespace mediakit */
|
||||
@@ -1,135 +0,0 @@
|
||||
//
|
||||
// Created by xzl on 2018/10/24.
|
||||
//
|
||||
|
||||
#ifndef ZLMEDIAKIT_RTSPMAKER_H
|
||||
#define ZLMEDIAKIT_RTSPMAKER_H
|
||||
|
||||
#include "RtspSdp.h"
|
||||
|
||||
namespace mediakit{
|
||||
/**
|
||||
* rtsp生成器
|
||||
*/
|
||||
class RtspMaker : public FrameRingInterface , public RtpRingInterface{
|
||||
public:
|
||||
/**
|
||||
* 构成函数
|
||||
*/
|
||||
RtspMaker(){
|
||||
_rtpRing = std::make_shared<RtpRingInterface::RingType>();
|
||||
_frameRing = std::make_shared<FrameRingInterface::RingType>();
|
||||
}
|
||||
virtual ~RtspMaker(){}
|
||||
|
||||
/**
|
||||
* 添加音视频或title 媒体
|
||||
* @param sdp 媒体描述对象
|
||||
* @param ssrc 媒体rtp ssrc
|
||||
* @param mtu 媒体rtp mtu
|
||||
*/
|
||||
void addTrack(const Sdp::Ptr & sdp,uint32_t ssrc = 0,int mtu = 1400){
|
||||
if(ssrc == 0){
|
||||
ssrc = ((uint64_t) sdp.get()) & 0xFFFFFFFF;
|
||||
}
|
||||
sdp->createRtpEncoder(ssrc, mtu);
|
||||
sdp->setFrameRing(_frameRing);
|
||||
sdp->setRtpRing(_rtpRing);
|
||||
_sdp_map[sdp->getTrackType()] = sdp;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 添加音视频或title 媒体
|
||||
* @param track 媒体描述
|
||||
* @param ssrc 媒体rtp ssrc
|
||||
* @param mtu 媒体rtp mtu
|
||||
*/
|
||||
void addTrack(const Track::Ptr & track,uint32_t ssrc = 0,int mtu = 1400) ;
|
||||
|
||||
/**
|
||||
* 获取完整的SDP字符串
|
||||
* @return SDP字符串
|
||||
*/
|
||||
string getSdp() {
|
||||
_StrPrinter printer;
|
||||
for(auto &pr : _sdp_map){
|
||||
printer << pr.second->getSdp() ;
|
||||
}
|
||||
return printer;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 写入帧数据然后打包rtp
|
||||
* @param frame 帧数据
|
||||
*/
|
||||
void inputFrame(const Frame::Ptr &frame) override {
|
||||
auto it = _sdp_map.find(frame->getTrackType());
|
||||
if(it == _sdp_map.end()){
|
||||
return ;
|
||||
}
|
||||
it->second->inputFrame(frame);
|
||||
}
|
||||
|
||||
/**
|
||||
* 也可以在外部打包好rtp然后再写入
|
||||
* @param rtp rtp包
|
||||
* @param key_pos 是否为关键帧的第一个rtp包
|
||||
*/
|
||||
bool inputRtp(const RtpPacket::Ptr &rtp, bool key_pos = true) override {
|
||||
auto it = _sdp_map.find(rtp->getTrackType());
|
||||
if(it == _sdp_map.end()){
|
||||
return false;
|
||||
}
|
||||
return it->second->inputRtp(rtp,key_pos);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取rtp环形缓存
|
||||
* @return
|
||||
*/
|
||||
RtpRingInterface::RingType::Ptr getRtpRing() const override{
|
||||
return _rtpRing;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取帧环形缓存
|
||||
* @return
|
||||
*/
|
||||
FrameRingInterface::RingType::Ptr getFrameRing() const override{
|
||||
return _frameRing;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置帧环形缓存
|
||||
* @param ring
|
||||
*/
|
||||
void setFrameRing(const FrameRingInterface::RingType::Ptr &ring) override{
|
||||
_frameRing = ring;
|
||||
for(auto &pr : _sdp_map){
|
||||
pr.second->setFrameRing(ring);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 设置rtp环形缓存
|
||||
* @param ring
|
||||
*/
|
||||
void setRtpRing(const RtpRingInterface::RingType::Ptr &ring) override{
|
||||
_rtpRing = ring;
|
||||
for(auto &pr : _sdp_map){
|
||||
pr.second->setRtpRing(ring);
|
||||
}
|
||||
}
|
||||
private:
|
||||
map<int,Sdp::Ptr> _sdp_map;
|
||||
RtpRingInterface::RingType::Ptr _rtpRing;
|
||||
FrameRingInterface::RingType::Ptr _frameRing;
|
||||
};
|
||||
|
||||
|
||||
} /* namespace mediakit */
|
||||
|
||||
#endif //ZLMEDIAKIT_RTSPMAKER_H
|
||||
@@ -35,7 +35,7 @@
|
||||
#include "Rtsp.h"
|
||||
#include "Common/config.h"
|
||||
#include "Common/MediaSource.h"
|
||||
#include "RtpCodec/RtpCodec.h"
|
||||
#include "RtspMuxer/RtpCodec.h"
|
||||
|
||||
#include "Util/logger.h"
|
||||
#include "Util/RingBuffer.h"
|
||||
|
||||
@@ -31,8 +31,8 @@
|
||||
#include <algorithm>
|
||||
#include <functional>
|
||||
#include "Common/config.h"
|
||||
#include "RtpParser.h"
|
||||
#include "RtspPlayer.h"
|
||||
#include "RtspMuxer/RtspDemuxer.h"
|
||||
#include "Poller/Timer.h"
|
||||
#include "Util/TimeTicker.h"
|
||||
|
||||
@@ -41,7 +41,7 @@ using namespace toolkit;
|
||||
|
||||
namespace mediakit {
|
||||
|
||||
class RtspPlayerImp: public PlayerImp<RtspPlayer,RtpParser> {
|
||||
class RtspPlayerImp: public PlayerImp<RtspPlayer,RtspDemuxer> {
|
||||
public:
|
||||
typedef std::shared_ptr<RtspPlayerImp> Ptr;
|
||||
RtspPlayerImp(){};
|
||||
@@ -68,7 +68,7 @@ private:
|
||||
_pRtspMediaSrc->onGetSDP(sdp);
|
||||
}
|
||||
try {
|
||||
_parser.reset(new RtpParser(sdp));
|
||||
_parser.reset(new RtspDemuxer(sdp));
|
||||
//todo(xzl) 修复此处
|
||||
// _parser->setOnVideoCB(_onGetVideoCB);
|
||||
// _parser->setOnAudioCB(_onGetAudioCB);
|
||||
|
||||
@@ -1,17 +0,0 @@
|
||||
#include "RtspSdp.h"
|
||||
#include "Common/Factory.h"
|
||||
|
||||
namespace mediakit{
|
||||
|
||||
void Sdp::createRtpEncoder(uint32_t ssrc, int mtu) {
|
||||
_encoder = Factory::getRtpEncoderById(getCodecId(),
|
||||
ssrc,
|
||||
mtu,
|
||||
_sample_rate,
|
||||
_playload_type,
|
||||
getTrackType() * 2);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -1,265 +0,0 @@
|
||||
//
|
||||
// Created by xzl on 2018/9/18.
|
||||
//
|
||||
|
||||
#ifndef ZLMEDIAKIT_RTSPSDP_H
|
||||
#define ZLMEDIAKIT_RTSPSDP_H
|
||||
|
||||
#include "RtpCodec/H264RtpCodec.h"
|
||||
#include "RtpCodec/AACRtpCodec.h"
|
||||
#include "Util/base64.h"
|
||||
#include "Player/Track.h"
|
||||
|
||||
namespace mediakit {
|
||||
|
||||
/**
|
||||
* sdp基类
|
||||
*/
|
||||
class Sdp : public FrameRingInterface , public RtpRingInterface , public CodecInfo{
|
||||
public:
|
||||
typedef std::shared_ptr<Sdp> Ptr;
|
||||
|
||||
/**
|
||||
* 构造sdp
|
||||
* @param sample_rate 采样率
|
||||
* @param playload_type pt类型
|
||||
*/
|
||||
Sdp(uint32_t sample_rate, uint8_t playload_type){
|
||||
_sample_rate = sample_rate;
|
||||
_playload_type = playload_type;
|
||||
}
|
||||
|
||||
virtual ~Sdp(){}
|
||||
|
||||
/**
|
||||
* 获取sdp字符串
|
||||
* @return
|
||||
*/
|
||||
virtual string getSdp() const = 0;
|
||||
|
||||
/**
|
||||
* 返回音频或视频类型
|
||||
* @return
|
||||
*/
|
||||
TrackType getTrackType() const override {
|
||||
return TrackInvalid;
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回编码器id
|
||||
* @return
|
||||
*/
|
||||
CodecId getCodecId() const override{
|
||||
return CodecInvalid;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取帧环形缓存
|
||||
* @return
|
||||
*/
|
||||
FrameRingInterface::RingType::Ptr getFrameRing() const override {
|
||||
return _encoder->getFrameRing();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取rtp环形缓存
|
||||
* @return
|
||||
*/
|
||||
RtpRingInterface::RingType::Ptr getRtpRing() const override{
|
||||
return _encoder->getRtpRing();
|
||||
}
|
||||
|
||||
/**
|
||||
* 输入帧数据,驱动rtp打包
|
||||
* @param frame 帧数据
|
||||
*/
|
||||
void inputFrame(const Frame::Ptr &frame) override{
|
||||
_encoder->inputFrame(frame);
|
||||
}
|
||||
|
||||
/**
|
||||
* 也可以在外部打包rtp后直接输入rtp
|
||||
* @param rtp rtp数据包
|
||||
* @param key_pos 是否为关键帧第一个rtp包
|
||||
*/
|
||||
bool inputRtp(const RtpPacket::Ptr &rtp, bool key_pos) override{
|
||||
return _encoder->inputRtp(rtp,key_pos);
|
||||
}
|
||||
|
||||
/**
|
||||
* 替换帧环形缓存,目的是多个rtp打包器共用一个环形缓存
|
||||
* @param ring
|
||||
*/
|
||||
void setFrameRing(const FrameRingInterface::RingType::Ptr &ring) override{
|
||||
_encoder->setFrameRing(ring);
|
||||
}
|
||||
|
||||
/**
|
||||
* 替换帧环形缓存,目的是多个rtp打包器共用一个环形缓存
|
||||
* @param ring
|
||||
*/
|
||||
void setRtpRing(const RtpRingInterface::RingType::Ptr &ring) override{
|
||||
_encoder->setRtpRing(ring);
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建Rtp打包器
|
||||
* @param ssrc 打包器ssrc,可以为0
|
||||
* @param mtu mtu大小,一般小于1500字节,推荐1400
|
||||
*/
|
||||
virtual void createRtpEncoder(uint32_t ssrc, int mtu);
|
||||
private:
|
||||
RtpCodec::Ptr _encoder;
|
||||
uint8_t _playload_type;
|
||||
uint32_t _sample_rate;
|
||||
};
|
||||
|
||||
/**
|
||||
* sdp中除音视频外的其他描述部分
|
||||
*/
|
||||
class TitleSdp : public Sdp{
|
||||
public:
|
||||
|
||||
/**
|
||||
* 构造title类型sdp
|
||||
* @param dur_sec rtsp点播时长,0代表直播,单位秒
|
||||
* @param header 自定义sdp描述
|
||||
* @param version sdp版本
|
||||
*/
|
||||
TitleSdp(float dur_sec = 0,
|
||||
const map<string,string> &header = map<string,string>(),
|
||||
int version = 0) : Sdp(0,0){
|
||||
_printer << "v=" << version << "\r\n";
|
||||
|
||||
if(!header.empty()){
|
||||
for (auto &pr : header){
|
||||
_printer << pr.first << "=" << pr.second << "\r\n";
|
||||
}
|
||||
} else {
|
||||
_printer << "o=- 1383190487994921 1 IN IP4 0.0.0.0\r\n";
|
||||
_printer << "s=RTSP Session, streamed by the ZLMediaKit\r\n";
|
||||
_printer << "i=ZLMediaKit Live Stream\r\n";
|
||||
_printer << "c=IN IP4 0.0.0.0\r\n";
|
||||
_printer << "t=0 0\r\n";
|
||||
}
|
||||
|
||||
if(dur_sec <= 0){
|
||||
_printer << "a=range:npt=0-\r\n";
|
||||
}else{
|
||||
_printer << "a=range:npt=0-" << dur_sec << "\r\n";
|
||||
}
|
||||
_printer << "a=control:*\r\n";
|
||||
}
|
||||
string getSdp() const override {
|
||||
return _printer;
|
||||
}
|
||||
private:
|
||||
_StrPrinter _printer;
|
||||
};
|
||||
|
||||
/**
|
||||
* h264类型sdp
|
||||
*/
|
||||
class H264Sdp : public Sdp {
|
||||
public:
|
||||
|
||||
/**
|
||||
*
|
||||
* @param sps 264 sps,不带0x00000001头
|
||||
* @param pps 264 pps,不带0x00000001头
|
||||
* @param playload_type rtp playload type 默认96
|
||||
* @param bitrate 比特率
|
||||
*/
|
||||
H264Sdp(const string &strSPS,
|
||||
const string &strPPS,
|
||||
int playload_type = 96,
|
||||
int bitrate = 4000) : Sdp(90000,playload_type) {
|
||||
//视频通道
|
||||
_printer << "m=video 0 RTP/AVP " << playload_type << "\r\n";
|
||||
_printer << "b=AS:" << bitrate << "\r\n";
|
||||
_printer << "a=rtpmap:" << playload_type << " H264/" << 90000 << "\r\n";
|
||||
_printer << "a=fmtp:" << playload_type << " packetization-mode=1;profile-level-id=";
|
||||
|
||||
char strTemp[100];
|
||||
int profile_level_id = 0;
|
||||
if (strSPS.length() >= 4) { // sanity check
|
||||
profile_level_id = (strSPS[1] << 16) | (strSPS[2] << 8) | strSPS[3]; // profile_idc|constraint_setN_flag|level_idc
|
||||
}
|
||||
memset(strTemp, 0, 100);
|
||||
sprintf(strTemp, "%06X", profile_level_id);
|
||||
_printer << strTemp;
|
||||
_printer << ";sprop-parameter-sets=";
|
||||
memset(strTemp, 0, 100);
|
||||
av_base64_encode(strTemp, 100, (uint8_t *) strSPS.data(), strSPS.size());
|
||||
_printer << strTemp << ",";
|
||||
memset(strTemp, 0, 100);
|
||||
av_base64_encode(strTemp, 100, (uint8_t *) strPPS.data(), strPPS.size());
|
||||
_printer << strTemp << "\r\n";
|
||||
_printer << "a=control:trackID=" << getTrackType() << "\r\n";
|
||||
}
|
||||
|
||||
string getSdp() const override {
|
||||
return _printer;
|
||||
}
|
||||
|
||||
TrackType getTrackType() const override {
|
||||
return TrackVideo;
|
||||
}
|
||||
|
||||
CodecId getCodecId() const override {
|
||||
return CodecH264;
|
||||
}
|
||||
private:
|
||||
_StrPrinter _printer;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* aac类型SDP
|
||||
*/
|
||||
class AACSdp : public Sdp {
|
||||
public:
|
||||
|
||||
/**
|
||||
*
|
||||
* @param aac_cfg aac两个字节的配置描述
|
||||
* @param sample_rate 音频采样率
|
||||
* @param playload_type rtp playload type 默认98
|
||||
* @param bitrate 比特率
|
||||
*/
|
||||
AACSdp(const string &aac_cfg,
|
||||
int sample_rate,
|
||||
int playload_type = 98,
|
||||
int bitrate = 128) : Sdp(sample_rate,playload_type){
|
||||
_printer << "m=audio 0 RTP/AVP " << playload_type << "\r\n";
|
||||
_printer << "b=AS:" << bitrate << "\r\n";
|
||||
_printer << "a=rtpmap:" << playload_type << " MPEG4-GENERIC/" << sample_rate << "\r\n";
|
||||
|
||||
char configStr[32] = {0};
|
||||
snprintf(configStr, sizeof(configStr), "%02X%02x", aac_cfg[0], aac_cfg[1]);
|
||||
_printer << "a=fmtp:" << playload_type << " streamtype=5;profile-level-id=1;mode=AAC-hbr;"
|
||||
<< "sizelength=13;indexlength=3;indexdeltalength=3;config="
|
||||
<< configStr << "\r\n";
|
||||
_printer << "a=control:trackID=" << getTrackType() << "\r\n";
|
||||
}
|
||||
|
||||
string getSdp() const override {
|
||||
return _printer;
|
||||
}
|
||||
|
||||
TrackType getTrackType() const override {
|
||||
return TrackAudio;
|
||||
};
|
||||
CodecId getCodecId() const override {
|
||||
return CodecAAC;
|
||||
}
|
||||
private:
|
||||
_StrPrinter _printer;
|
||||
};
|
||||
|
||||
|
||||
} /* namespace mediakit */
|
||||
|
||||
|
||||
|
||||
#endif //ZLMEDIAKIT_RTSPSDP_H
|
||||
@@ -27,10 +27,10 @@
|
||||
#ifndef SRC_RTSP_RTSPTORTMPMEDIASOURCE_H_
|
||||
#define SRC_RTSP_RTSPTORTMPMEDIASOURCE_H_
|
||||
|
||||
#include "RtpParser.h"
|
||||
#include "RtspMediaSource.h"
|
||||
#include "Rtmp/amf.h"
|
||||
#include "Rtmp/RtmpMediaSource.h"
|
||||
#include "RtspMuxer/RtspDemuxer.h"
|
||||
#include "MediaFile/MediaRecorder.h"
|
||||
using namespace toolkit;
|
||||
|
||||
@@ -50,7 +50,7 @@ public:
|
||||
|
||||
virtual void onGetSDP(const string& strSdp) override{
|
||||
try {
|
||||
_pParser.reset(new RtpParser(strSdp));
|
||||
_pParser.reset(new RtspDemuxer(strSdp));
|
||||
_pRecorder.reset(new MediaRecorder(getVhost(),getApp(),getId(),_pParser,_bEnableHls,_bEnableMp4));
|
||||
//todo(xzl) 修复此处
|
||||
// _pParser->setOnAudioCB( std::bind(&RtspToRtmpMediaSource::onGetAAC, this, placeholders::_1));
|
||||
@@ -98,7 +98,7 @@ private:
|
||||
void makeAudioConfigPkt();
|
||||
void makeMetaData();
|
||||
private:
|
||||
RtpParser::Ptr _pParser;
|
||||
RtspDemuxer::Ptr _pParser;
|
||||
RtmpMediaSource::Ptr _pRtmpSrc;
|
||||
uint8_t _ui8AudioFlags = 0;
|
||||
MediaRecorder::Ptr _pRecorder;
|
||||
|
||||
Reference in New Issue
Block a user