mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2024-10-30 16:27:36 +08:00
rtp解包采用自有代码
This commit is contained in:
parent
9fa2221a79
commit
74d6689a65
@ -151,15 +151,7 @@ endif()
|
||||
#添加rtp库用于rtp转ps/ts
|
||||
if(ENABLE_RTPPROXY AND ENABLE_HLS)
|
||||
message(STATUS "ENABLE_RTPPROXY defined")
|
||||
include_directories(${MediaServer_Root}/librtp/include)
|
||||
|
||||
aux_source_directory(${MediaServer_Root}/librtp/include src_rtp)
|
||||
aux_source_directory(${MediaServer_Root}/librtp/source src_rtp)
|
||||
aux_source_directory(${MediaServer_Root}/librtp/payload src_rtp)
|
||||
add_library(rtp STATIC ${src_rtp})
|
||||
add_definitions(-DENABLE_RTPPROXY)
|
||||
list(APPEND LINK_LIB_LIST rtp)
|
||||
list(APPEND CXX_API_TARGETS rtp)
|
||||
endif()
|
||||
|
||||
#收集源代码
|
||||
|
@ -1,62 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#if defined(ENABLE_RTPPROXY)
|
||||
#include "Util/logger.h"
|
||||
#include "RtpDecoder.h"
|
||||
#include "rtp-payload.h"
|
||||
using namespace toolkit;
|
||||
|
||||
namespace mediakit{
|
||||
|
||||
RtpDecoder::RtpDecoder(const char *codec) {
|
||||
_buffer = std::make_shared<BufferRaw>();
|
||||
_codec = codec;
|
||||
}
|
||||
|
||||
RtpDecoder::~RtpDecoder() {
|
||||
if(_rtp_decoder){
|
||||
rtp_payload_decode_destroy(_rtp_decoder);
|
||||
_rtp_decoder = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
void RtpDecoder::decodeRtp(const void *data, int bytes) {
|
||||
if(!_rtp_decoder){
|
||||
static rtp_payload_t s_func= {
|
||||
[](void* param, int bytes){
|
||||
RtpDecoder *obj = (RtpDecoder *)param;
|
||||
obj->_buffer->setCapacity(bytes);
|
||||
return (void *)obj->_buffer->data();
|
||||
},
|
||||
[](void* param, void* packet){
|
||||
//do nothing
|
||||
},
|
||||
[](void* param, const void *packet, int bytes, uint32_t timestamp, int flags){
|
||||
RtpDecoder *obj = (RtpDecoder *)param;
|
||||
obj->onRtpDecode((uint8_t *)packet, bytes, timestamp, flags);
|
||||
}
|
||||
};
|
||||
|
||||
uint8_t rtp_type = 0x7F & ((uint8_t *) data)[1];
|
||||
InfoL << "rtp type:" << (int) rtp_type;
|
||||
_rtp_decoder = rtp_payload_decode_create(rtp_type, _codec.data(), &s_func, this);
|
||||
if (!_rtp_decoder) {
|
||||
WarnL << "unsupported rtp type:" << (int) rtp_type << ",size:" << bytes << ",hexdump" << hexdump(data, bytes > 16 ? 16 : bytes);
|
||||
}
|
||||
}
|
||||
|
||||
if(_rtp_decoder){
|
||||
rtp_payload_decode_input(_rtp_decoder,data,bytes);
|
||||
}
|
||||
}
|
||||
|
||||
}//namespace mediakit
|
||||
#endif//defined(ENABLE_RTPPROXY)
|
@ -1,35 +0,0 @@
|
||||
/*
|
||||
* 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_RTPDECODER_H
|
||||
#define ZLMEDIAKIT_RTPDECODER_H
|
||||
|
||||
#if defined(ENABLE_RTPPROXY)
|
||||
#include "Network/Buffer.h"
|
||||
using namespace toolkit;
|
||||
|
||||
namespace mediakit{
|
||||
|
||||
class RtpDecoder {
|
||||
public:
|
||||
RtpDecoder(const char *codec = "MP2P");
|
||||
virtual ~RtpDecoder();
|
||||
void decodeRtp(const void *data, int bytes);
|
||||
protected:
|
||||
virtual void onRtpDecode(const uint8_t *packet, int bytes, uint32_t timestamp, int flags) = 0;
|
||||
private:
|
||||
void *_rtp_decoder = nullptr;
|
||||
BufferRaw::Ptr _buffer;
|
||||
string _codec;
|
||||
};
|
||||
|
||||
}//namespace mediakit
|
||||
#endif//defined(ENABLE_RTPPROXY)
|
||||
#endif //ZLMEDIAKIT_RTPDECODER_H
|
@ -53,6 +53,10 @@ RtpProcess::RtpProcess(const string &stream_id) {
|
||||
});
|
||||
}
|
||||
}
|
||||
_rtp_decoder = std::make_shared<CommonRtpDecoder>(CodecInvalid, 256 * 1024);
|
||||
_rtp_decoder->addDelegate(std::make_shared<FrameWriterInterfaceHelper>([this](const Frame::Ptr &frame){
|
||||
onRtpDecode((uint8_t *) frame->data(), frame->size(), frame->dts());
|
||||
}));
|
||||
}
|
||||
|
||||
RtpProcess::~RtpProcess() {
|
||||
@ -121,7 +125,7 @@ void RtpProcess::onRtpSorted(const RtpPacket::Ptr &rtp, int) {
|
||||
fwrite((uint8_t *) &size, 2, 1, _save_file_rtp.get());
|
||||
fwrite((uint8_t *) rtp->data() + 4, rtp->size() - 4, 1, _save_file_rtp.get());
|
||||
}
|
||||
decodeRtp(rtp->data() + 4 ,rtp->size() - 4);
|
||||
_rtp_decoder->inputRtp(rtp);
|
||||
}
|
||||
|
||||
const char *RtpProcess::onSearchPacketTail(const char *packet,int bytes){
|
||||
@ -139,7 +143,7 @@ const char *RtpProcess::onSearchPacketTail(const char *packet,int bytes){
|
||||
}
|
||||
}
|
||||
|
||||
void RtpProcess::onRtpDecode(const uint8_t *packet, int bytes, uint32_t timestamp, int flags) {
|
||||
void RtpProcess::onRtpDecode(const uint8_t *packet, int bytes, uint32_t timestamp) {
|
||||
if(_save_file_ps){
|
||||
fwrite((uint8_t *)packet,bytes, 1, _save_file_ps.get());
|
||||
}
|
||||
|
@ -14,16 +14,16 @@
|
||||
#if defined(ENABLE_RTPPROXY)
|
||||
|
||||
#include "Rtsp/RtpReceiver.h"
|
||||
#include "RtpDecoder.h"
|
||||
#include "Decoder.h"
|
||||
#include "Common/Device.h"
|
||||
#include "Common/Stamp.h"
|
||||
#include "Http/HttpRequestSplitter.h"
|
||||
#include "Extension/CommonRtp.h"
|
||||
using namespace mediakit;
|
||||
|
||||
namespace mediakit{
|
||||
|
||||
class RtpProcess : public HttpRequestSplitter, public RtpReceiver , public RtpDecoder, public SockInfo, public MediaSinkInterface, public std::enable_shared_from_this<RtpProcess>{
|
||||
class RtpProcess : public HttpRequestSplitter, public RtpReceiver, public SockInfo, public MediaSinkInterface, public std::enable_shared_from_this<RtpProcess>{
|
||||
public:
|
||||
typedef std::shared_ptr<RtpProcess> Ptr;
|
||||
RtpProcess(const string &stream_id);
|
||||
@ -67,7 +67,6 @@ public:
|
||||
|
||||
protected:
|
||||
void onRtpSorted(const RtpPacket::Ptr &rtp, int track_index) override ;
|
||||
void onRtpDecode(const uint8_t *packet, int bytes, uint32_t timestamp, int flags) override;
|
||||
void inputFrame(const Frame::Ptr &frame) override;
|
||||
void addTrack(const Track::Ptr & track) override;
|
||||
void resetTracks() override {};
|
||||
@ -77,8 +76,10 @@ protected:
|
||||
|
||||
private:
|
||||
void emitOnPublish();
|
||||
void onRtpDecode(const uint8_t *packet, int bytes, uint32_t timestamp);
|
||||
|
||||
private:
|
||||
std::shared_ptr<CommonRtpDecoder> _rtp_decoder;
|
||||
std::shared_ptr<FILE> _save_file_rtp;
|
||||
std::shared_ptr<FILE> _save_file_ps;
|
||||
std::shared_ptr<FILE> _save_file_video;
|
||||
|
Loading…
Reference in New Issue
Block a user