mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2024-11-22 19:00:01 +08:00
!17 【功能请求】 /index/api/getMediaList接口 增加LOSS字段用于统计每个轨道丢包率反馈
* update webrtc/WebRtcPusher.h. * update webrtc/WebRtcPusher.cpp. * update webrtc/WebRtcTransport.h. * update webrtc/WebRtcTransport.cpp. * update src/Common/MediaSource.h. * update src/Common/MediaSource.cpp. * update server/WebApi.cpp.
This commit is contained in:
parent
3a9408bcec
commit
be995f9cd2
@ -1,4 +1,4 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2016 The ZLMediaKit project authors. All Rights Reserved.
|
* Copyright (c) 2016 The ZLMediaKit project authors. All Rights Reserved.
|
||||||
*
|
*
|
||||||
* This file is part of ZLMediaKit(https://github.com/xia-chu/ZLMediaKit).
|
* This file is part of ZLMediaKit(https://github.com/xia-chu/ZLMediaKit).
|
||||||
@ -343,6 +343,7 @@ Value makeMediaSourceJson(MediaSource &media){
|
|||||||
switch(codec_type){
|
switch(codec_type){
|
||||||
case TrackAudio : {
|
case TrackAudio : {
|
||||||
auto audio_track = dynamic_pointer_cast<AudioTrack>(track);
|
auto audio_track = dynamic_pointer_cast<AudioTrack>(track);
|
||||||
|
obj["loss"] = media.getLossRate(TrackAudio);
|
||||||
obj["sample_rate"] = audio_track->getAudioSampleRate();
|
obj["sample_rate"] = audio_track->getAudioSampleRate();
|
||||||
obj["channels"] = audio_track->getAudioChannel();
|
obj["channels"] = audio_track->getAudioChannel();
|
||||||
obj["sample_bit"] = audio_track->getAudioSampleBit();
|
obj["sample_bit"] = audio_track->getAudioSampleBit();
|
||||||
@ -350,6 +351,7 @@ Value makeMediaSourceJson(MediaSource &media){
|
|||||||
}
|
}
|
||||||
case TrackVideo : {
|
case TrackVideo : {
|
||||||
auto video_track = dynamic_pointer_cast<VideoTrack>(track);
|
auto video_track = dynamic_pointer_cast<VideoTrack>(track);
|
||||||
|
obj["loss"] = media.getLossRate(TrackVideo);
|
||||||
obj["width"] = video_track->getVideoWidth();
|
obj["width"] = video_track->getVideoWidth();
|
||||||
obj["height"] = video_track->getVideoHeight();
|
obj["height"] = video_track->getVideoHeight();
|
||||||
obj["fps"] = round(video_track->getVideoFps());
|
obj["fps"] = round(video_track->getVideoFps());
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2016 The ZLMediaKit project authors. All Rights Reserved.
|
* Copyright (c) 2016 The ZLMediaKit project authors. All Rights Reserved.
|
||||||
*
|
*
|
||||||
* This file is part of ZLMediaKit(https://github.com/xia-chu/ZLMediaKit).
|
* This file is part of ZLMediaKit(https://github.com/xia-chu/ZLMediaKit).
|
||||||
@ -213,6 +213,14 @@ bool MediaSource::close(bool force) {
|
|||||||
return listener->close(*this,force);
|
return listener->close(*this,force);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int MediaSource::getLossRate(mediakit::TrackType type) {
|
||||||
|
auto listener = _listener.lock();
|
||||||
|
if (!listener) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
return listener->getLossRate(*this, type);
|
||||||
|
}
|
||||||
|
|
||||||
void MediaSource::onReaderChanged(int size) {
|
void MediaSource::onReaderChanged(int size) {
|
||||||
auto listener = _listener.lock();
|
auto listener = _listener.lock();
|
||||||
if (listener) {
|
if (listener) {
|
||||||
@ -690,6 +698,14 @@ void MediaSourceEventInterceptor::onRegist(MediaSource &sender, bool regist) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int MediaSourceEventInterceptor::getLossRate(MediaSource &sender, TrackType type){
|
||||||
|
auto listener = _listener.lock();
|
||||||
|
if (listener) {
|
||||||
|
return listener->getLossRate(sender, type);
|
||||||
|
}
|
||||||
|
return -1; //异常返回-1
|
||||||
|
}
|
||||||
|
|
||||||
bool MediaSourceEventInterceptor::setupRecord(MediaSource &sender, Recorder::type type, bool start, const string &custom_path, size_t max_second) {
|
bool MediaSourceEventInterceptor::setupRecord(MediaSource &sender, Recorder::type type, bool start, const string &custom_path, size_t max_second) {
|
||||||
auto listener = _listener.lock();
|
auto listener = _listener.lock();
|
||||||
if (!listener) {
|
if (!listener) {
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2016 The ZLMediaKit project authors. All Rights Reserved.
|
* Copyright (c) 2016 The ZLMediaKit project authors. All Rights Reserved.
|
||||||
*
|
*
|
||||||
* This file is part of ZLMediaKit(https://github.com/xia-chu/ZLMediaKit).
|
* This file is part of ZLMediaKit(https://github.com/xia-chu/ZLMediaKit).
|
||||||
@ -78,6 +78,8 @@ public:
|
|||||||
//流注册或注销事件
|
//流注册或注销事件
|
||||||
virtual void onRegist(MediaSource &sender, bool regist) {};
|
virtual void onRegist(MediaSource &sender, bool regist) {};
|
||||||
|
|
||||||
|
virtual int getLossRate(MediaSource &sender, TrackType type) {return -1;};
|
||||||
|
|
||||||
////////////////////////仅供MultiMediaSourceMuxer对象继承////////////////////////
|
////////////////////////仅供MultiMediaSourceMuxer对象继承////////////////////////
|
||||||
// 开启或关闭录制
|
// 开启或关闭录制
|
||||||
virtual bool setupRecord(MediaSource &sender, Recorder::type type, bool start, const std::string &custom_path, size_t max_second) { return false; };
|
virtual bool setupRecord(MediaSource &sender, Recorder::type type, bool start, const std::string &custom_path, size_t max_second) { return false; };
|
||||||
@ -142,7 +144,7 @@ public:
|
|||||||
std::vector<Track::Ptr> getMediaTracks(MediaSource &sender, bool trackReady = true) const override;
|
std::vector<Track::Ptr> getMediaTracks(MediaSource &sender, bool trackReady = true) const override;
|
||||||
void startSendRtp(MediaSource &sender, const SendRtpArgs &args, const std::function<void(uint16_t, const toolkit::SockException &)> cb) override;
|
void startSendRtp(MediaSource &sender, const SendRtpArgs &args, const std::function<void(uint16_t, const toolkit::SockException &)> cb) override;
|
||||||
bool stopSendRtp(MediaSource &sender, const std::string &ssrc) override;
|
bool stopSendRtp(MediaSource &sender, const std::string &ssrc) override;
|
||||||
|
int getLossRate(MediaSource &sender, TrackType type) override;
|
||||||
private:
|
private:
|
||||||
std::weak_ptr<MediaSourceEvent> _listener;
|
std::weak_ptr<MediaSourceEvent> _listener;
|
||||||
};
|
};
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2016 The ZLMediaKit project authors. All Rights Reserved.
|
* Copyright (c) 2016 The ZLMediaKit project authors. All Rights Reserved.
|
||||||
*
|
*
|
||||||
* This file is part of ZLMediaKit(https://github.com/xia-chu/ZLMediaKit).
|
* This file is part of ZLMediaKit(https://github.com/xia-chu/ZLMediaKit).
|
||||||
@ -146,4 +146,8 @@ void WebRtcPusher::onRtcConfigure(RtcConfigure &configure) const {
|
|||||||
WebRtcTransportImp::onRtcConfigure(configure);
|
WebRtcTransportImp::onRtcConfigure(configure);
|
||||||
//这只是推流
|
//这只是推流
|
||||||
configure.audio.direction = configure.video.direction = RtpDirection::recvonly;
|
configure.audio.direction = configure.video.direction = RtpDirection::recvonly;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int WebRtcPusher::getLossRate(MediaSource &sender,mediakit::TrackType type){
|
||||||
|
return WebRtcTransportImp::getLossRate(type);
|
||||||
|
}
|
@ -1,4 +1,4 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2016 The ZLMediaKit project authors. All Rights Reserved.
|
* Copyright (c) 2016 The ZLMediaKit project authors. All Rights Reserved.
|
||||||
*
|
*
|
||||||
* This file is part of ZLMediaKit(https://github.com/xia-chu/ZLMediaKit).
|
* This file is part of ZLMediaKit(https://github.com/xia-chu/ZLMediaKit).
|
||||||
@ -40,6 +40,8 @@ protected:
|
|||||||
// 获取媒体源客户端相关信息
|
// 获取媒体源客户端相关信息
|
||||||
std::shared_ptr<SockInfo> getOriginSock(mediakit::MediaSource &sender) const override;
|
std::shared_ptr<SockInfo> getOriginSock(mediakit::MediaSource &sender) const override;
|
||||||
|
|
||||||
|
int getLossRate(mediakit::MediaSource &sender,mediakit::TrackType type) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
WebRtcPusher(const EventPoller::Ptr &poller, const mediakit::RtspMediaSourceImp::Ptr &src,
|
WebRtcPusher(const EventPoller::Ptr &poller, const mediakit::RtspMediaSourceImp::Ptr &src,
|
||||||
const std::shared_ptr<void> &ownership, const mediakit::MediaInfo &info, const mediakit::ProtocolOption &option);
|
const std::shared_ptr<void> &ownership, const mediakit::MediaInfo &info, const mediakit::ProtocolOption &option);
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2016 The ZLMediaKit project authors. All Rights Reserved.
|
* Copyright (c) 2016 The ZLMediaKit project authors. All Rights Reserved.
|
||||||
*
|
*
|
||||||
* This file is part of ZLMediaKit(https://github.com/xia-chu/ZLMediaKit).
|
* This file is part of ZLMediaKit(https://github.com/xia-chu/ZLMediaKit).
|
||||||
@ -612,6 +612,10 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
int getLossRate() {
|
int getLossRate() {
|
||||||
|
if (!_rtcp_context.getExpectedPacketsInterval()) //_rtcp_context.getExpectedPacketsInterval()取值总为零?
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
return _rtcp_context.geLostInterval() * 100 / _rtcp_context.getExpectedPacketsInterval();
|
return _rtcp_context.geLostInterval() * 100 / _rtcp_context.getExpectedPacketsInterval();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -655,6 +659,21 @@ std::shared_ptr<RtpChannel> MediaTrack::getRtpChannel(uint32_t ssrc) const{
|
|||||||
return it_chn->second;
|
return it_chn->second;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int WebRtcTransportImp::getLossRate(mediakit::TrackType type){
|
||||||
|
for(auto it : _ssrc_to_track){
|
||||||
|
auto ssrc = it.first;
|
||||||
|
auto track = it.second;
|
||||||
|
auto rtp_chn = track->getRtpChannel(ssrc);
|
||||||
|
if(rtp_chn){
|
||||||
|
InfoL << "-----------接收丢包率,ssrc------------- :" << ssrc << ",loss rate(%):" << rtp_chn->getLossRate() ;
|
||||||
|
if (track->media && type==track->media->type){
|
||||||
|
return rtp_chn->getLossRate();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
void WebRtcTransportImp::onRtcp(const char *buf, size_t len) {
|
void WebRtcTransportImp::onRtcp(const char *buf, size_t len) {
|
||||||
_bytes_usage += len;
|
_bytes_usage += len;
|
||||||
auto rtcps = RtcpHeader::loadFromBytes((char *) buf, len);
|
auto rtcps = RtcpHeader::loadFromBytes((char *) buf, len);
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2016 The ZLMediaKit project authors. All Rights Reserved.
|
* Copyright (c) 2016 The ZLMediaKit project authors. All Rights Reserved.
|
||||||
*
|
*
|
||||||
* This file is part of ZLMediaKit(https://github.com/xia-chu/ZLMediaKit).
|
* This file is part of ZLMediaKit(https://github.com/xia-chu/ZLMediaKit).
|
||||||
@ -262,6 +262,7 @@ protected:
|
|||||||
void onShutdown(const SockException &ex) override;
|
void onShutdown(const SockException &ex) override;
|
||||||
virtual void onRecvRtp(MediaTrack &track, const std::string &rid, mediakit::RtpPacket::Ptr rtp) = 0;
|
virtual void onRecvRtp(MediaTrack &track, const std::string &rid, mediakit::RtpPacket::Ptr rtp) = 0;
|
||||||
void updateTicker();
|
void updateTicker();
|
||||||
|
int getLossRate(mediakit::TrackType type);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void onSortedRtp(MediaTrack &track, const std::string &rid, mediakit::RtpPacket::Ptr rtp);
|
void onSortedRtp(MediaTrack &track, const std::string &rid, mediakit::RtpPacket::Ptr rtp);
|
||||||
|
Loading…
Reference in New Issue
Block a user