From a69d7d0f71af197c315e5968d24e9ed14e8ea76b Mon Sep 17 00:00:00 2001 From: xiongziliang <771730766@qq.com> Date: Thu, 25 Oct 2018 23:24:23 +0800 Subject: [PATCH] =?UTF-8?q?=E6=95=B4=E7=90=86rtp=E7=9B=B8=E5=85=B3?= =?UTF-8?q?=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Rtsp/Rtsp.cpp | 25 +++++------------------- src/Rtsp/Rtsp.h | 18 ++--------------- src/RtspMuxer/H264RtpCodec.cpp | 35 ++++++++++++++++++++++++++++++++++ 3 files changed, 42 insertions(+), 36 deletions(-) diff --git a/src/Rtsp/Rtsp.cpp b/src/Rtsp/Rtsp.cpp index b17b7513..168e75a4 100644 --- a/src/Rtsp/Rtsp.cpp +++ b/src/Rtsp/Rtsp.cpp @@ -157,7 +157,11 @@ void SdpAttr::load(const string &sdp) { } } -SdpTrack::Ptr SdpAttr::getTrack(TrackType type) { +bool SdpAttr::available() const { + return getTrack(TrackAudio) || getTrack(TrackVideo); +} + +SdpTrack::Ptr SdpAttr::getTrack(TrackType type) const { for (auto &pr : _track_map){ if(pr.second->_type == type){ return pr.second; @@ -218,24 +222,5 @@ static onceToken s_token([](){ SdpAttr attr(str); track[0].inited=true; }); -bool MakeNalu(uint8_t in, NALU &nal) { - nal.forbidden_zero_bit = in >> 7; - if (nal.forbidden_zero_bit) { - return false; - } - nal.nal_ref_idc = (in & 0x60) >> 5; - nal.type = in & 0x1f; - return true; -} -bool MakeFU(uint8_t in, FU &fu) { - fu.S = in >> 7; - fu.E = (in >> 6) & 0x01; - fu.R = (in >> 5) & 0x01; - fu.type = in & 0x1f; - if (fu.R != 0) { - return false; - } - return true; -} diff --git a/src/Rtsp/Rtsp.h b/src/Rtsp/Rtsp.h index 9120b993..b4266adb 100644 --- a/src/Rtsp/Rtsp.h +++ b/src/Rtsp/Rtsp.h @@ -71,7 +71,8 @@ public: ~SdpAttr(){} void load(const string &sdp); - SdpTrack::Ptr getTrack(TrackType type); + SdpTrack::Ptr getTrack(TrackType type) const; + bool available() const ; private: map _track_map; }; @@ -218,21 +219,6 @@ private: mutable StrCaseMap _mapUrlArgs; }; -typedef struct { - unsigned forbidden_zero_bit :1; - unsigned nal_ref_idc :2; - unsigned type :5; -} NALU; - -typedef struct { - unsigned S :1; - unsigned E :1; - unsigned R :1; - unsigned type :5; -} FU; - -bool MakeNalu(uint8_t in, NALU &nal) ; -bool MakeFU(uint8_t in, FU &fu) ; #endif //RTSP_RTSP_H_ diff --git a/src/RtspMuxer/H264RtpCodec.cpp b/src/RtspMuxer/H264RtpCodec.cpp index ce6c0e47..ebdc4271 100644 --- a/src/RtspMuxer/H264RtpCodec.cpp +++ b/src/RtspMuxer/H264RtpCodec.cpp @@ -28,6 +28,41 @@ namespace mediakit{ + +typedef struct { + unsigned forbidden_zero_bit :1; + unsigned nal_ref_idc :2; + unsigned type :5; +} NALU; + +typedef struct { + unsigned S :1; + unsigned E :1; + unsigned R :1; + unsigned type :5; +} FU; + +bool MakeNalu(uint8_t in, NALU &nal) { + nal.forbidden_zero_bit = in >> 7; + if (nal.forbidden_zero_bit) { + return false; + } + nal.nal_ref_idc = (in & 0x60) >> 5; + nal.type = in & 0x1f; + return true; +} +bool MakeFU(uint8_t in, FU &fu) { + fu.S = in >> 7; + fu.E = (in >> 6) & 0x01; + fu.R = (in >> 5) & 0x01; + fu.type = in & 0x1f; + if (fu.R != 0) { + return false; + } + return true; +} + + H264RtpDecoder::H264RtpDecoder() { _h264frame = obtainFrame(); }