Commit cfc7dc21 by 夏楚 Committed by GitHub

Merge pull request #74 from 3503207480/master

PR: 注释,说明, 除以0错误 
parents 64cf7efa a7953fdb
...@@ -70,7 +70,7 @@ void MediaSink::inputFrame(const Frame::Ptr &frame) { ...@@ -70,7 +70,7 @@ void MediaSink::inputFrame(const Frame::Ptr &frame) {
it->second->inputFrame(frame); it->second->inputFrame(frame);
if(!_allTrackReady && !_trackReadyCallback.empty() && it->second->ready()){ if(!_allTrackReady && !_trackReadyCallback.empty() && it->second->ready()){
//Track由未就绪状态换成就绪状态,我们就触发onTrackReady回调 //Track由未就绪状态换成就绪状态,我们就触发onTrackReady回调
auto it_callback = _trackReadyCallback.find(codec_id); auto it_callback = _trackReadyCallback.find(codec_id);
if(it_callback != _trackReadyCallback.end()){ if(it_callback != _trackReadyCallback.end()){
it_callback->second(); it_callback->second();
......
...@@ -123,6 +123,7 @@ MediaSource::Ptr MediaSource::find( ...@@ -123,6 +123,7 @@ MediaSource::Ptr MediaSource::find(
lock_guard<recursive_mutex> lock(g_mtxMediaSrc); lock_guard<recursive_mutex> lock(g_mtxMediaSrc);
MediaSource::Ptr ret; MediaSource::Ptr ret;
//查找某一媒体源,找到后返回
searchMedia(schema, vhost, app, id, searchMedia(schema, vhost, app, id,
[&](SchemaVhostAppStreamMap::iterator &it0 , [&](SchemaVhostAppStreamMap::iterator &it0 ,
VhostAppStreamMap::iterator &it1, VhostAppStreamMap::iterator &it1,
...@@ -138,7 +139,7 @@ MediaSource::Ptr MediaSource::find( ...@@ -138,7 +139,7 @@ MediaSource::Ptr MediaSource::find(
return true; return true;
}); });
if(!ret && bMake){ if(!ret && bMake){
//查找某一媒体源,找到后返回 //未查找媒体源,则创建一个
ret = MediaReader::onMakeMediaSource(schema, vhost,app,id); ret = MediaReader::onMakeMediaSource(schema, vhost,app,id);
} }
return ret; return ret;
......
...@@ -48,7 +48,7 @@ string makeAdtsConfig(const uint8_t *pcAdts); ...@@ -48,7 +48,7 @@ string makeAdtsConfig(const uint8_t *pcAdts);
void getAACInfo(const AACFrame &adts,int &iSampleRate,int &iChannel); void getAACInfo(const AACFrame &adts,int &iSampleRate,int &iChannel);
/** /**
* aac帧,包含adts头 * aac帧,包含adts头
*/ */
class AACFrame : public Frame { class AACFrame : public Frame {
......
...@@ -36,6 +36,7 @@ using namespace toolkit; ...@@ -36,6 +36,7 @@ using namespace toolkit;
namespace mediakit{ namespace mediakit{
/** /**
* h264 Rtmp解码类 * h264 Rtmp解码类
* 将 h264 over rtmp 解复用出 h264-Frame
*/ */
class H264RtmpDecoder : public RtmpCodec ,public ResourcePoolHelper<H264Frame> { class H264RtmpDecoder : public RtmpCodec ,public ResourcePoolHelper<H264Frame> {
public: public:
......
...@@ -90,7 +90,24 @@ bool H264RtpDecoder::decodeRtp(const RtpPacket::Ptr &rtppack) { ...@@ -90,7 +90,24 @@ bool H264RtpDecoder::decodeRtp(const RtpPacket::Ptr &rtppack) {
* Type==7:SPS frame * Type==7:SPS frame
* Type==8:PPS frame * Type==8:PPS frame
*/ */
/*
RTF3984 5.2节 Common Structure of the RTP Payload Format
Table 1. Summary of NAL unit types and their payload structures
Type Packet Type name Section
---------------------------------------------------------
0 undefined -
1-23 NAL unit Single NAL unit packet per H.264 5.6
24 STAP-A Single-time aggregation packet 5.7.1
25 STAP-B Single-time aggregation packet 5.7.1
26 MTAP16 Multi-time aggregation packet 5.7.2
27 MTAP24 Multi-time aggregation packet 5.7.2
28 FU-A Fragmentation unit 5.8
29 FU-B Fragmentation unit 5.8
30-31 undefined -
*/
const uint8_t *frame = (uint8_t *) rtppack->data() + rtppack->offset; const uint8_t *frame = (uint8_t *) rtppack->data() + rtppack->offset;
int length = rtppack->size() - rtppack->offset; int length = rtppack->size() - rtppack->offset;
NALU nal; NALU nal;
...@@ -145,7 +162,7 @@ bool H264RtpDecoder::decodeRtp(const RtpPacket::Ptr &rtppack) { ...@@ -145,7 +162,7 @@ bool H264RtpDecoder::decodeRtp(const RtpPacket::Ptr &rtppack) {
FU fu; FU fu;
MakeFU(frame[1], fu); MakeFU(frame[1], fu);
if (fu.S) { if (fu.S) {
//该帧的第一个rtp包 //该帧的第一个rtp包 FU-A start
char tmp = (nal.forbidden_zero_bit << 7 | nal.nal_ref_idc << 5 | fu.type); char tmp = (nal.forbidden_zero_bit << 7 | nal.nal_ref_idc << 5 | fu.type);
_h264frame->buffer.assign("\x0\x0\x0\x1", 4); _h264frame->buffer.assign("\x0\x0\x0\x1", 4);
_h264frame->buffer.push_back(tmp); _h264frame->buffer.push_back(tmp);
...@@ -164,14 +181,14 @@ bool H264RtpDecoder::decodeRtp(const RtpPacket::Ptr &rtppack) { ...@@ -164,14 +181,14 @@ bool H264RtpDecoder::decodeRtp(const RtpPacket::Ptr &rtppack) {
} }
if (!fu.E) { if (!fu.E) {
//该帧的中间rtp包 //该帧的中间rtp包 FU-A mid
_h264frame->buffer.append((char *)frame + 2, length - 2); _h264frame->buffer.append((char *)frame + 2, length - 2);
//该函数return时,保存下当前sequence,以便下次对比seq是否连续 //该函数return时,保存下当前sequence,以便下次对比seq是否连续
_lastSeq = rtppack->sequence; _lastSeq = rtppack->sequence;
return false; return false;
} }
//该帧最后一个rtp包 //该帧最后一个rtp包 FU-A end
_h264frame->buffer.append((char *)frame + 2, length - 2); _h264frame->buffer.append((char *)frame + 2, length - 2);
_h264frame->timeStamp = rtppack->timeStamp; _h264frame->timeStamp = rtppack->timeStamp;
auto key = _h264frame->keyFrame(); auto key = _h264frame->keyFrame();
......
...@@ -36,6 +36,8 @@ namespace mediakit{ ...@@ -36,6 +36,8 @@ namespace mediakit{
/** /**
* h264 rtp解码类 * h264 rtp解码类
* 将 h264 over rtsp-rtp 解复用出 h264-Frame
* rfc3984
*/ */
class H264RtpDecoder : public RtpCodec , public ResourcePoolHelper<H264Frame> { class H264RtpDecoder : public RtpCodec , public ResourcePoolHelper<H264Frame> {
public: public:
......
...@@ -37,6 +37,8 @@ namespace mediakit{ ...@@ -37,6 +37,8 @@ namespace mediakit{
/** /**
* h265 rtp解码类 * h265 rtp解码类
* 将 h265 over rtsp-rtp 解复用出 h265-Frame
* 《草案(H265-over-RTP)draft-ietf-payload-rtp-h265-07.pdf》
*/ */
class H265RtpDecoder : public RtpCodec , public ResourcePoolHelper<H265Frame> { class H265RtpDecoder : public RtpCodec , public ResourcePoolHelper<H265Frame> {
public: public:
......
...@@ -490,6 +490,7 @@ inline void HttpSession::Handle_Req_GET(int64_t &content_len) { ...@@ -490,6 +490,7 @@ inline void HttpSession::Handle_Req_GET(int64_t &content_len) {
//再看看是否为http-flv直播请求 //再看看是否为http-flv直播请求
if(checkLiveFlvStream()){ if(checkLiveFlvStream()){
//若是,return!
return; return;
} }
......
...@@ -44,7 +44,7 @@ using namespace toolkit; ...@@ -44,7 +44,7 @@ using namespace toolkit;
using namespace mediakit::Client; using namespace mediakit::Client;
namespace mediakit { namespace mediakit {
//实现了rtmp播放器协议部分的功能,及数据接收功能
class RtmpPlayer:public PlayerBase, public TcpClient, public RtmpProtocol{ class RtmpPlayer:public PlayerBase, public TcpClient, public RtmpProtocol{
public: public:
typedef std::shared_ptr<RtmpPlayer> Ptr; typedef std::shared_ptr<RtmpPlayer> Ptr;
...@@ -63,11 +63,11 @@ protected: ...@@ -63,11 +63,11 @@ protected:
void onMediaData_l(const RtmpPacket::Ptr &chunkData); void onMediaData_l(const RtmpPacket::Ptr &chunkData);
void onPlayResult_l(const SockException &ex); void onPlayResult_l(const SockException &ex);
//for Tcpclient //form Tcpclient
void onRecv(const Buffer::Ptr &pBuf) override; void onRecv(const Buffer::Ptr &pBuf) override;
void onConnect(const SockException &err) override; void onConnect(const SockException &err) override;
void onErr(const SockException &ex) override; void onErr(const SockException &ex) override;
//fro RtmpProtocol //from RtmpProtocol
void onRtmpChunk(RtmpPacket &chunkData) override; void onRtmpChunk(RtmpPacket &chunkData) override;
void onStreamDry(uint32_t ui32StreamId) override; void onStreamDry(uint32_t ui32StreamId) override;
void onSendRawData(const Buffer::Ptr &buffer) override{ void onSendRawData(const Buffer::Ptr &buffer) override{
......
...@@ -39,7 +39,7 @@ RtspMuxer::RtspMuxer(const TitleSdp::Ptr &title){ ...@@ -39,7 +39,7 @@ RtspMuxer::RtspMuxer(const TitleSdp::Ptr &title){
} }
void RtspMuxer::onTrackReady(const Track::Ptr &track) { void RtspMuxer::onTrackReady(const Track::Ptr &track) {
//根据track生sdp //根据track生sdp
Sdp::Ptr sdp = track->getSdp(); Sdp::Ptr sdp = track->getSdp();
if (!sdp) { if (!sdp) {
return; return;
......
...@@ -450,7 +450,7 @@ void RtspPlayer::handleResPAUSE(const Parser& parser, bool bPause) { ...@@ -450,7 +450,7 @@ void RtspPlayer::handleResPAUSE(const Parser& parser, bool bPause) {
auto strRtpTime = FindField(strTrack.data(), "rtptime=", ";"); auto strRtpTime = FindField(strTrack.data(), "rtptime=", ";");
auto idx = getTrackIndexByControlSuffix(strControlSuffix); auto idx = getTrackIndexByControlSuffix(strControlSuffix);
if(idx != -1){ if(idx != -1){
_aiFistStamp[idx] = atoll(strRtpTime.data()) * 1000 / _aTrackInfo[idx]->_samplerate; _aiFistStamp[idx] = _aTrackInfo[idx]->_samplerate>0?atoll(strRtpTime.data()) * 1000 / _aTrackInfo[idx]->_samplerate :1;
_aiNowStamp[idx] = _aiFistStamp[idx]; _aiNowStamp[idx] = _aiFistStamp[idx];
DebugL << "rtptime(ms):" << strControlSuffix <<" " << strRtpTime; DebugL << "rtptime(ms):" << strControlSuffix <<" " << strRtpTime;
} }
......
...@@ -46,7 +46,7 @@ using namespace toolkit; ...@@ -46,7 +46,7 @@ using namespace toolkit;
namespace mediakit { namespace mediakit {
//实现了rtsp播放器协议部分的功能 //实现了rtsp播放器协议部分的功能,及数据接收功能
class RtspPlayer: public PlayerBase,public TcpClient, public RtspSplitter, public RtpReceiver { class RtspPlayer: public PlayerBase,public TcpClient, public RtspSplitter, public RtpReceiver {
public: public:
typedef std::shared_ptr<RtspPlayer> Ptr; typedef std::shared_ptr<RtspPlayer> Ptr;
......
...@@ -361,10 +361,11 @@ void RtspSession::onAuthSuccess() { ...@@ -361,10 +361,11 @@ void RtspSession::onAuthSuccess() {
strongSelf->shutdown(SockException(Err_shutdown,err)); strongSelf->shutdown(SockException(Err_shutdown,err));
return; return;
} }
//找到了应的rtsp流 //找到了应的rtsp流
strongSelf->_aTrackInfo = SdpParser(rtsp_src->getSdp()).getAvailableTrack(); strongSelf->_aTrackInfo = SdpParser(rtsp_src->getSdp()).getAvailableTrack();
if (strongSelf->_aTrackInfo.empty()) { if (strongSelf->_aTrackInfo.empty()) {
//该流无效 //该流无效
DebugL << "无trackInfo,该流无效";
strongSelf->send_StreamNotFound(); strongSelf->send_StreamNotFound();
strongSelf->shutdown(SockException(Err_shutdown,"can not find any availabe track in sdp")); strongSelf->shutdown(SockException(Err_shutdown,"can not find any availabe track in sdp"));
return; return;
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论