Commit 5cd8e8ae by xiongziliang

添加媒体生成源信息

parent 2cf66594
......@@ -245,6 +245,18 @@ bool FFmpegSource::close(MediaSource &sender, bool force) {
return true;
}
MediaOriginType FFmpegSource::getOriginType(MediaSource &sender) const{
return MediaOriginType::ffmpeg_pull;
}
string FFmpegSource::getOriginUrl(MediaSource &sender) const{
return _src_url;
}
std::shared_ptr<SockInfo> FFmpegSource::getOriginSock(MediaSource &sender) const {
return nullptr;
}
void FFmpegSource::onGetMediaSource(const MediaSource::Ptr &src) {
auto listener = src->getListener();
if (listener.lock().get() != this) {
......
......@@ -58,8 +58,15 @@ private:
void startTimer(int timeout_ms);
void onGetMediaSource(const MediaSource::Ptr &src);
//MediaSourceEvent override
///////MediaSourceEvent override///////
// 关闭
bool close(MediaSource &sender,bool force) override;
// 获取媒体源类型
MediaOriginType getOriginType(MediaSource &sender) const override;
//获取媒体源url或者文件路径
string getOriginUrl(MediaSource &sender) const override;
// 获取媒体源客户端相关信息
std::shared_ptr<SockInfo> getOriginSock(MediaSource &sender) const override;
private:
Process _process;
......
......@@ -397,6 +397,20 @@ void installWebApi() {
item["stream"] = media->getId();
item["readerCount"] = media->readerCount();
item["totalReaderCount"] = media->totalReaderCount();
item["originType"] = (int) media->getOriginType();
item["originTypeStr"] = getOriginTypeString(media->getOriginType());
item["originUrl"] = media->getOriginUrl();
auto originSock = media->getOriginSock();
if (originSock) {
item["originSock"]["local_ip"] = originSock->get_local_ip();
item["originSock"]["local_port"] = originSock->get_local_port();
item["originSock"]["peer_ip"] = originSock->get_peer_ip();
item["originSock"]["peer_port"] = originSock->get_peer_port();
item["originSock"]["identifier"] = originSock->getIdentifier();
} else {
item["originSock"] = Json::nullValue;
}
for(auto &track : media->getTracks()){
Value obj;
auto codec_type = track->getTrackType();
......
......@@ -166,5 +166,9 @@ void DevChannel::initAudio(const AudioInfo &info) {
}
}
MediaOriginType DevChannel::getOriginType(MediaSource &sender) const {
return MediaOriginType::device_chn;
}
} /* namespace mediakit */
......@@ -129,6 +129,9 @@ public:
#endif //ENABLE_FAAC
private:
MediaOriginType getOriginType(MediaSource &sender) const override;
private:
#ifdef ENABLE_X264
std::shared_ptr<H264Encoder> _pH264Enc;
......
......@@ -19,6 +19,20 @@ namespace mediakit {
recursive_mutex s_media_source_mtx;
MediaSource::SchemaVhostAppStreamMap s_media_source_map;
string getOriginTypeString(MediaOriginType type){
#define SWITCH_CASE(type) case type : return #type
switch (type) {
SWITCH_CASE(MediaOriginType::unknown);
SWITCH_CASE(MediaOriginType::rtmp_push);
SWITCH_CASE(MediaOriginType::rtsp_push);
SWITCH_CASE(MediaOriginType::rtp_push);
SWITCH_CASE(MediaOriginType::pull);
SWITCH_CASE(MediaOriginType::ffmpeg_pull);
SWITCH_CASE(MediaOriginType::mp4_vod);
SWITCH_CASE(MediaOriginType::device_chn);
}
}
MediaSource::MediaSource(const string &schema, const string &vhost, const string &app, const string &stream_id){
GET_CONFIG(bool, enableVhost, General::kEnableVhost);
if (!enableVhost) {
......@@ -76,6 +90,30 @@ int MediaSource::totalReaderCount(){
return listener->totalReaderCount(*this);
}
MediaOriginType MediaSource::getOriginType() const {
auto listener = _listener.lock();
if (!listener) {
return MediaOriginType::unknown;
}
return listener->getOriginType(const_cast<MediaSource &>(*this));
}
string MediaSource::getOriginUrl() const {
auto listener = _listener.lock();
if (!listener) {
return "";
}
return listener->getOriginUrl(const_cast<MediaSource &>(*this));
}
std::shared_ptr<SockInfo> MediaSource::getOriginSock() const {
auto listener = _listener.lock();
if (!listener) {
return nullptr;
}
return listener->getOriginSock(const_cast<MediaSource &>(*this));
}
bool MediaSource::seekTo(uint32_t stamp) {
auto listener = _listener.lock();
if(!listener){
......@@ -365,6 +403,7 @@ bool MediaSource::unregist() {
/////////////////////////////////////MediaInfo//////////////////////////////////////
void MediaInfo::parse(const string &url_in){
_full_url = url_in;
string url = url_in;
auto pos = url.find("?");
if (pos != string::npos) {
......@@ -486,6 +525,30 @@ void MediaSourceEvent::onReaderChanged(MediaSource &sender, int size){
}, nullptr);
}
MediaOriginType MediaSourceEventInterceptor::getOriginType(MediaSource &sender) const {
auto listener = _listener.lock();
if (!listener) {
return MediaOriginType::unknown;
}
return listener->getOriginType(sender);
}
string MediaSourceEventInterceptor::getOriginUrl(MediaSource &sender) const {
auto listener = _listener.lock();
if (!listener) {
return "";
}
return listener->getOriginUrl(sender);
}
std::shared_ptr<SockInfo> MediaSourceEventInterceptor::getOriginSock(MediaSource &sender) const {
auto listener = _listener.lock();
if (!listener) {
return nullptr;
}
return listener->getOriginSock(sender);
}
bool MediaSourceEventInterceptor::seekTo(MediaSource &sender, uint32_t stamp) {
auto listener = _listener.lock();
if (!listener) {
......
......@@ -22,6 +22,7 @@
#include "Util/TimeTicker.h"
#include "Util/NoticeCenter.h"
#include "Util/List.h"
#include "Network/Socket.h"
#include "Rtsp/Rtsp.h"
#include "Rtmp/Rtmp.h"
#include "Extension/Track.h"
......@@ -36,6 +37,19 @@ namespace toolkit{
namespace mediakit {
enum class MediaOriginType : uint8_t {
unknown = 0,
rtmp_push ,
rtsp_push,
rtp_push,
pull,
ffmpeg_pull,
mp4_vod,
device_chn
};
string getOriginTypeString(MediaOriginType type);
class MediaSource;
class MediaSourceEvent{
public:
......@@ -43,6 +57,13 @@ public:
MediaSourceEvent(){};
virtual ~MediaSourceEvent(){};
// 获取媒体源类型
virtual MediaOriginType getOriginType(MediaSource &sender) const { return MediaOriginType::unknown; }
// 获取媒体源url或者文件路径
virtual string getOriginUrl(MediaSource &sender) const { return ""; }
// 获取媒体源客户端相关信息
virtual std::shared_ptr<SockInfo> getOriginSock(MediaSource &sender) const { return nullptr; }
// 通知拖动进度条
virtual bool seekTo(MediaSource &sender, uint32_t stamp) { return false; }
// 通知其停止产生流
......@@ -76,6 +97,10 @@ public:
MediaSourceEventInterceptor(){}
~MediaSourceEventInterceptor() override {}
MediaOriginType getOriginType(MediaSource &sender) const override;
string getOriginUrl(MediaSource &sender) const override;
std::shared_ptr<SockInfo> getOriginSock(MediaSource &sender) const override;
bool seekTo(MediaSource &sender, uint32_t stamp) override;
bool close(MediaSource &sender, bool force) override;
int totalReaderCount(MediaSource &sender) override;
......@@ -102,6 +127,7 @@ public:
void parse(const string &url);
public:
string _full_url;
string _schema;
string _host;
string _port;
......@@ -156,6 +182,13 @@ public:
// 观看者个数,包括(hls/rtsp/rtmp)
virtual int totalReaderCount();
// 获取媒体源类型
MediaOriginType getOriginType() const;
// 获取媒体源url或者文件路径
string getOriginUrl() const;
// 获取媒体源客户端相关信息
std::shared_ptr<SockInfo> getOriginSock() const;
// 拖动进度条
bool seekTo(uint32_t stamp);
// 关闭该流
......
......@@ -194,6 +194,11 @@ public:
}
return Parent::getTracks(trackReady);
}
std::shared_ptr<SockInfo> getSockInfo() const{
return dynamic_pointer_cast<SockInfo>(_delegate);
}
protected:
void onShutdown(const SockException &ex) override {
if (_shutdownCB) {
......
......@@ -112,6 +112,7 @@ void PlayerProxy::play(const string &strUrlTmp) {
}
});
MediaPlayer::play(strUrlTmp);
_pull_url = strUrlTmp;
MediaSource::Ptr mediaSource;
if(dynamic_pointer_cast<RtspPlayer>(_delegate)){
......@@ -180,6 +181,18 @@ int PlayerProxy::totalReaderCount(MediaSource &sender) {
return totalReaderCount();
}
MediaOriginType PlayerProxy::getOriginType(MediaSource &sender) const{
return MediaOriginType::pull;
}
string PlayerProxy::getOriginUrl(MediaSource &sender) const{
return _pull_url;
}
std::shared_ptr<SockInfo> PlayerProxy::getOriginSock(MediaSource &sender) const{
return getSockInfo();
}
class MuteAudioMaker : public FrameDispatcher{
public:
typedef std::shared_ptr<MuteAudioMaker> Ptr;
......
......@@ -59,6 +59,10 @@ private:
//MediaSourceEvent override
bool close(MediaSource &sender,bool force) override;
int totalReaderCount(MediaSource &sender) override;
MediaOriginType getOriginType(MediaSource &sender) const override;
string getOriginUrl(MediaSource &sender) const override;
std::shared_ptr<SockInfo> getOriginSock(MediaSource &sender) const override;
void rePlay(const string &strUrl,int iFailedCnt);
void onPlaySuccess();
......@@ -69,6 +73,7 @@ private:
string _vhost;
string _app;
string _stream_id;
string _pull_url;
Timer::Ptr _timer;
function<void()> _on_close;
function<void(const SockException &ex)> _on_play;
......
......@@ -109,6 +109,11 @@ public:
}
_shutdownCB = cb;
}
std::shared_ptr<SockInfo> getSockInfo() const{
return dynamic_pointer_cast<SockInfo>(_delegate);
}
protected:
PusherBase::Event _shutdownCB;
PusherBase::Event _publishCB;
......
......@@ -17,24 +17,24 @@ namespace mediakit {
MP4Reader::MP4Reader(const string &strVhost,const string &strApp, const string &strId,const string &filePath ) {
_poller = WorkThreadPool::Instance().getPoller();
auto strFileName = filePath;
if(strFileName.empty()){
_file_path = filePath;
if(_file_path.empty()){
GET_CONFIG(string,recordPath,Record::kFilePath);
GET_CONFIG(bool,enableVhost,General::kEnableVhost);
if(enableVhost){
strFileName = strVhost + "/" + strApp + "/" + strId;
_file_path = strVhost + "/" + strApp + "/" + strId;
}else{
strFileName = strApp + "/" + strId;
_file_path = strApp + "/" + strId;
}
strFileName = File::absolutePath(strFileName,recordPath);
_file_path = File::absolutePath(_file_path,recordPath);
}
_demuxer = std::make_shared<MP4Demuxer>();
_demuxer->openMP4(strFileName);
_demuxer->openMP4(_file_path);
_mediaMuxer.reset(new MultiMediaSourceMuxer(strVhost, strApp, strId, _demuxer->getDurationMS() / 1000.0, true, true, false, false));
auto tracks = _demuxer->getTracks(false);
if(tracks.empty()){
throw std::runtime_error(StrPrinter << "该mp4文件没有有效的track:" << strFileName);
throw std::runtime_error(StrPrinter << "该mp4文件没有有效的track:" << _file_path);
}
for(auto &track : tracks){
_mediaMuxer->addTrack(track);
......@@ -153,5 +153,13 @@ int MP4Reader::totalReaderCount(MediaSource &sender) {
return _mediaMuxer ? _mediaMuxer->totalReaderCount() : sender.readerCount();
}
MediaOriginType MP4Reader::getOriginType(MediaSource &sender) const {
return MediaOriginType::mp4_vod;
}
string MP4Reader::getOriginUrl(MediaSource &sender) const {
return _file_path;
}
} /* namespace mediakit */
#endif //ENABLE_MP4
\ No newline at end of file
......@@ -41,6 +41,8 @@ private:
bool seekTo(MediaSource &sender,uint32_t ui32Stamp) override;
bool close(MediaSource &sender,bool force) override;
int totalReaderCount(MediaSource &sender) override;
MediaOriginType getOriginType(MediaSource &sender) const override;
string getOriginUrl(MediaSource &sender) const override;
bool readSample();
uint32_t getCurrentStamp();
......@@ -50,6 +52,7 @@ private:
private:
bool _have_video = false;
uint32_t _seek_to;
string _file_path;
recursive_mutex _mtx;
Ticker _seek_ticker;
Timer::Ptr _timer;
......
......@@ -543,6 +543,18 @@ int RtmpSession::totalReaderCount(MediaSource &sender) {
return _publisher_src ? _publisher_src->totalReaderCount() : sender.readerCount();
}
MediaOriginType RtmpSession::getOriginType(MediaSource &sender) const{
return MediaOriginType::rtmp_push;
}
string RtmpSession::getOriginUrl(MediaSource &sender) const {
return _media_info._full_url;
}
std::shared_ptr<SockInfo> RtmpSession::getOriginSock(MediaSource &sender) const {
return const_cast<RtmpSession *>(this)->shared_from_this();
}
void RtmpSession::setSocketFlags(){
GET_CONFIG(int, merge_write_ms, General::kMergeWriteMS);
if (merge_write_ms > 0) {
......
......@@ -69,9 +69,17 @@ private:
sendResponse(MSG_CMD, invoke.data());
}
//MediaSourceEvent override
bool close(MediaSource &sender,bool force) override ;
///////MediaSourceEvent override///////
// 关闭
bool close(MediaSource &sender, bool force) override;
// 播放总人数
int totalReaderCount(MediaSource &sender) override;
// 获取媒体源类型
MediaOriginType getOriginType(MediaSource &sender) const override;
// 获取媒体源url或者文件路径
string getOriginUrl(MediaSource &sender) const override;
// 获取媒体源客户端相关信息
std::shared_ptr<SockInfo> getOriginSock(MediaSource &sender) const override;
void setSocketFlags();
string getStreamId(const string &str);
......
......@@ -26,6 +26,7 @@ namespace mediakit{
class RtpProcess : public HttpRequestSplitter, public RtpReceiver, public SockInfo, public MediaSinkInterface, public std::enable_shared_from_this<RtpProcess>{
public:
typedef std::shared_ptr<RtpProcess> Ptr;
friend class RtpProcessHelper;
RtpProcess(const string &stream_id);
~RtpProcess();
......
......@@ -145,6 +145,18 @@ int RtpProcessHelper::totalReaderCount(MediaSource &sender) {
return _process ? _process->totalReaderCount() : sender.totalReaderCount();
}
MediaOriginType RtpProcessHelper::getOriginType(MediaSource &sender) const{
return MediaOriginType::rtp_push;
}
string RtpProcessHelper::getOriginUrl(MediaSource &sender) const {
return _process ? _process->_media_info._full_url : "";
}
std::shared_ptr<SockInfo> RtpProcessHelper::getOriginSock(MediaSource &sender) const{
return _process;
}
RtpProcess::Ptr &RtpProcessHelper::getProcess() {
return _process;
}
......
......@@ -34,6 +34,12 @@ protected:
bool close(MediaSource &sender,bool force) override;
// 观看总人数
int totalReaderCount(MediaSource &sender) override;
// 获取媒体源类型
MediaOriginType getOriginType(MediaSource &sender) const override;
// 获取媒体源url或者文件路径
string getOriginUrl(MediaSource &sender) const override;
// 获取媒体源客户端相关信息
std::shared_ptr<SockInfo> getOriginSock(MediaSource &sender) const override;
private:
weak_ptr<RtpSelector > _parent;
......
......@@ -1105,6 +1105,18 @@ int RtspSession::totalReaderCount(MediaSource &sender) {
return _push_src ? _push_src->totalReaderCount() : sender.readerCount();
}
MediaOriginType RtspSession::getOriginType(MediaSource &sender) const{
return MediaOriginType::rtsp_push;
}
string RtspSession::getOriginUrl(MediaSource &sender) const {
return _media_info._full_url;
}
std::shared_ptr<SockInfo> RtspSession::getOriginSock(MediaSource &sender) const {
return const_cast<RtspSession *>(this)->shared_from_this();
}
inline void RtspSession::onSendRtpPacket(const RtpPacket::Ptr &pkt){
#if RTSP_SERVER_SEND_RTCP
int track_index = getTrackIndexByTrackType(pkt->type);
......
......@@ -74,11 +74,22 @@ protected:
void onRtpPacket(const char *data, uint64_t len) override;
//从rtsp头中获取Content长度
int64_t getContentLength(Parser &parser) override;
////RtpReceiver override////
void onRtpSorted(const RtpPacket::Ptr &rtp, int track_idx) override;
////MediaSourceEvent override////
bool close(MediaSource &sender, bool force) override ;
///////MediaSourceEvent override///////
// 关闭
bool close(MediaSource &sender, bool force) override;
// 播放总人数
int totalReaderCount(MediaSource &sender) override;
// 获取媒体源类型
MediaOriginType getOriginType(MediaSource &sender) const override;
// 获取媒体源url或者文件路径
string getOriginUrl(MediaSource &sender) const override;
// 获取媒体源客户端相关信息
std::shared_ptr<SockInfo> getOriginSock(MediaSource &sender) const override;
/////TcpSession override////
int send(const Buffer::Ptr &pkt) override;
//收到RTCP包回调
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论