合并代码,去除冗余代码

This commit is contained in:
ziyue
2021-04-02 16:23:40 +08:00
8 changed files with 45 additions and 51 deletions

View File

@@ -22,7 +22,7 @@ namespace mediakit{
class G711Track : public AudioTrackImp{
public:
using Ptr = std::shared_ptr<G711Track>;
G711Track(CodecId codecId,int sample_rate, int channels, int sample_bit) : AudioTrackImp(codecId,sample_rate,channels,sample_bit){}
G711Track(CodecId codecId, int sample_rate, int channels, int sample_bit) : AudioTrackImp(codecId, 8000, 1, 16) {}
private:
Sdp::Ptr getSdp() override;

View File

@@ -415,17 +415,11 @@ void RtmpSession::onCmd_pause(AMFDecoder &dec) {
}
void RtmpSession::setMetaData(AMFDecoder &dec) {
if (!_publisher_src) {
throw std::runtime_error("not a publisher");
}
std::string type = dec.load<std::string>();
if (type != "onMetaData") {
throw std::runtime_error("can only set metadata");
}
auto metadata = dec.load<AMFValue>();
// dumpMetadata(metadata);
_publisher_src->setMetaData(metadata);
_set_meta_data = true;
_publisher_metadata = dec.load<AMFValue>();
}
void RtmpSession::onProcessCmd(AMFDecoder &dec) {
@@ -478,7 +472,8 @@ void RtmpSession::onRtmpChunk(RtmpPacket::Ptr packet) {
case MSG_AUDIO:
case MSG_VIDEO: {
if (!_publisher_src) {
throw std::runtime_error("Not a rtmp publisher!");
WarnL << "Not a rtmp publisher!";
return;
}
GET_CONFIG(bool, rtmp_modify_stamp, Rtmp::kModifyStamp);
if (rtmp_modify_stamp) {
@@ -487,9 +482,9 @@ void RtmpSession::onRtmpChunk(RtmpPacket::Ptr packet) {
chunk_data.time_stamp = (uint32_t)dts_out;
}
if (!_set_meta_data && !chunk_data.isCfgFrame()) {
if (!_set_meta_data) {
_set_meta_data = true;
_publisher_src->setMetaData(TitleMeta().getMetadata());
_publisher_src->setMetaData(_publisher_metadata ? _publisher_metadata : TitleMeta().getMetadata());
}
_publisher_src->onWrite(std::move(packet));
break;

View File

@@ -98,8 +98,8 @@ private:
//数据接收超时计时器
Ticker _ticker;
MediaInfo _media_info;
std::weak_ptr<RtmpMediaSource> _player_src;
AMFValue _publisher_metadata;
std::shared_ptr<RtmpMediaSourceImp> _publisher_src;
RtmpMediaSource::RingType::RingReader::Ptr _ring_reader;
};

View File

@@ -145,6 +145,9 @@ bool RtpProcess::alive() {
void RtpProcess::setStopCheckRtp(bool is_check){
_stop_rtp_check = is_check;
if (!is_check) {
_last_frame_time.resetTime();
}
}
void RtpProcess::onDetach() {