2018-10-25 10:00:17 +08:00
|
|
|
|
/*
|
2020-04-04 20:30:09 +08:00
|
|
|
|
* Copyright (c) 2016 The ZLMediaKit project authors. All Rights Reserved.
|
2018-10-25 10:00:17 +08:00
|
|
|
|
*
|
|
|
|
|
* This file is part of ZLMediaKit(https://github.com/xiongziliang/ZLMediaKit).
|
|
|
|
|
*
|
2020-04-04 20:30:09 +08:00
|
|
|
|
* 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.
|
2018-10-25 10:00:17 +08:00
|
|
|
|
*/
|
2018-10-24 17:17:55 +08:00
|
|
|
|
|
2018-10-25 16:46:00 +08:00
|
|
|
|
#ifndef ZLMEDIAKIT_MULTIMEDIASOURCEMUXER_H
|
|
|
|
|
#define ZLMEDIAKIT_MULTIMEDIASOURCEMUXER_H
|
2019-06-28 17:30:13 +08:00
|
|
|
|
#include "Rtsp/RtspMediaSourceMuxer.h"
|
|
|
|
|
#include "Rtmp/RtmpMediaSourceMuxer.h"
|
2019-12-04 10:45:38 +08:00
|
|
|
|
#include "Record/Recorder.h"
|
2019-12-28 18:50:56 +08:00
|
|
|
|
#include "Record/HlsMediaSource.h"
|
2019-12-29 10:49:04 +08:00
|
|
|
|
#include "Record/HlsRecorder.h"
|
2020-04-05 09:26:29 +08:00
|
|
|
|
namespace mediakit{
|
2018-10-24 17:17:55 +08:00
|
|
|
|
|
2020-04-05 09:26:29 +08:00
|
|
|
|
class MultiMuxerPrivate : public MediaSink , public std::enable_shared_from_this<MultiMuxerPrivate>{
|
2018-10-24 17:17:55 +08:00
|
|
|
|
public:
|
2020-04-05 09:26:29 +08:00
|
|
|
|
friend class MultiMediaSourceMuxer;
|
|
|
|
|
typedef std::shared_ptr<MultiMuxerPrivate> Ptr;
|
2019-12-26 11:53:19 +08:00
|
|
|
|
class Listener{
|
|
|
|
|
public:
|
|
|
|
|
Listener() = default;
|
|
|
|
|
virtual ~Listener() = default;
|
|
|
|
|
virtual void onAllTrackReady() = 0;
|
|
|
|
|
};
|
2020-04-05 09:26:29 +08:00
|
|
|
|
~MultiMuxerPrivate() override ;
|
|
|
|
|
private:
|
|
|
|
|
MultiMuxerPrivate(const string &vhost,
|
|
|
|
|
const string &app,
|
|
|
|
|
const string &stream,
|
|
|
|
|
float dur_sec,
|
|
|
|
|
bool enable_rtsp,
|
|
|
|
|
bool enable_rtmp,
|
|
|
|
|
bool enable_hls,
|
|
|
|
|
bool enable_mp4);
|
|
|
|
|
|
|
|
|
|
void resetTracks() override;
|
|
|
|
|
void setMediaListener(const std::weak_ptr<MediaSourceEvent> &listener);
|
|
|
|
|
int totalReaderCount() const;
|
|
|
|
|
void setTimeStamp(uint32_t stamp);
|
|
|
|
|
void setTrackListener(Listener *listener);
|
|
|
|
|
bool setupRecord(MediaSource &sender, Recorder::type type, bool start, const string &custom_path);
|
|
|
|
|
bool isRecording(MediaSource &sender, Recorder::type type);
|
2020-04-29 11:59:45 +08:00
|
|
|
|
bool isEnabled();
|
2020-04-05 09:26:29 +08:00
|
|
|
|
private:
|
|
|
|
|
void onTrackReady(const Track::Ptr & track) override;
|
|
|
|
|
void onTrackFrame(const Frame::Ptr &frame) override;
|
|
|
|
|
void onAllTrackReady() override;
|
|
|
|
|
MediaSource::Ptr getHlsMediaSource() const;
|
|
|
|
|
private:
|
|
|
|
|
RtmpMediaSourceMuxer::Ptr _rtmp;
|
|
|
|
|
RtspMediaSourceMuxer::Ptr _rtsp;
|
|
|
|
|
MediaSinkInterface::Ptr _hls;
|
|
|
|
|
MediaSinkInterface::Ptr _mp4;
|
|
|
|
|
Listener *_listener = nullptr;
|
|
|
|
|
std::weak_ptr<MediaSourceEvent> _meida_listener;
|
2020-04-29 11:59:45 +08:00
|
|
|
|
bool _enable_rtxp = false;
|
|
|
|
|
bool _enable_record = false;
|
2020-04-05 09:26:29 +08:00
|
|
|
|
};
|
2018-10-26 14:12:16 +08:00
|
|
|
|
|
2020-04-05 09:26:29 +08:00
|
|
|
|
class MultiMediaSourceMuxer : public MediaSourceEvent, public MediaSinkInterface, public TrackSource, public std::enable_shared_from_this<MultiMediaSourceMuxer>{
|
|
|
|
|
public:
|
|
|
|
|
typedef MultiMuxerPrivate::Listener Listener;
|
2019-12-26 11:53:19 +08:00
|
|
|
|
typedef std::shared_ptr<MultiMediaSourceMuxer> Ptr;
|
2018-10-25 16:46:00 +08:00
|
|
|
|
|
2020-04-05 09:26:29 +08:00
|
|
|
|
~MultiMediaSourceMuxer() override;
|
|
|
|
|
MultiMediaSourceMuxer(const string &vhost,
|
|
|
|
|
const string &app,
|
|
|
|
|
const string &stream,
|
|
|
|
|
float dur_sec = 0.0,
|
|
|
|
|
bool enable_rtsp = true,
|
|
|
|
|
bool enable_rtmp = true,
|
|
|
|
|
bool enable_hls = true,
|
|
|
|
|
bool enable_mp4 = false);
|
2019-10-11 16:51:10 +08:00
|
|
|
|
|
2018-10-25 16:49:43 +08:00
|
|
|
|
/**
|
|
|
|
|
* 设置事件监听器
|
|
|
|
|
* @param listener
|
|
|
|
|
*/
|
2020-04-05 09:26:29 +08:00
|
|
|
|
void setMediaListener(const std::weak_ptr<MediaSourceEvent> &listener);
|
2018-10-26 14:12:16 +08:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 返回总的消费者个数
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
2020-04-05 09:26:29 +08:00
|
|
|
|
int totalReaderCount() const;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 设置MediaSource时间戳
|
|
|
|
|
* @param stamp 时间戳
|
|
|
|
|
*/
|
|
|
|
|
void setTimeStamp(uint32_t stamp);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 随着Track就绪事件监听器
|
|
|
|
|
* @param listener 事件监听器
|
|
|
|
|
*/
|
|
|
|
|
void setTrackListener(Listener *listener);
|
|
|
|
|
|
2019-12-03 12:32:57 +08:00
|
|
|
|
/**
|
2020-04-05 09:26:29 +08:00
|
|
|
|
* 获取所有Track
|
|
|
|
|
* @param trackReady 是否筛选过滤未就绪的track
|
|
|
|
|
* @return 所有Track
|
2019-12-03 12:32:57 +08:00
|
|
|
|
*/
|
2020-04-05 09:26:29 +08:00
|
|
|
|
vector<Track::Ptr> getTracks(bool trackReady = true) const override;
|
2019-12-03 12:32:57 +08:00
|
|
|
|
|
|
|
|
|
/**
|
2020-04-05 09:26:29 +08:00
|
|
|
|
* 通知拖动进度条
|
|
|
|
|
* @param sender 事件发送者
|
|
|
|
|
* @param ui32Stamp 目标时间戳
|
|
|
|
|
* @return 是否成功
|
2019-12-03 12:32:57 +08:00
|
|
|
|
*/
|
2020-04-05 09:26:29 +08:00
|
|
|
|
bool seekTo(MediaSource &sender,uint32_t ui32Stamp) override;
|
2019-12-03 12:32:57 +08:00
|
|
|
|
|
|
|
|
|
/**
|
2020-04-05 09:26:29 +08:00
|
|
|
|
* 通知停止流生成
|
|
|
|
|
* @param sender 事件发送者
|
|
|
|
|
* @param force 是否强制关闭
|
|
|
|
|
* @return 成功与否
|
2019-12-03 12:32:57 +08:00
|
|
|
|
*/
|
2020-04-05 09:26:29 +08:00
|
|
|
|
bool close(MediaSource &sender,bool force) override;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 观看总人数
|
|
|
|
|
* @param sender 事件发送者
|
|
|
|
|
* @return 观看总人数
|
|
|
|
|
*/
|
|
|
|
|
int totalReaderCount(MediaSource &sender) override;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 设置录制状态
|
|
|
|
|
* @param type 录制类型
|
|
|
|
|
* @param start 开始或停止
|
|
|
|
|
* @param custom_path 开启录制时,指定自定义路径
|
|
|
|
|
* @return 是否设置成功
|
|
|
|
|
*/
|
|
|
|
|
bool setupRecord(MediaSource &sender, Recorder::type type, bool start, const string &custom_path) override;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取录制状态
|
|
|
|
|
* @param type 录制类型
|
|
|
|
|
* @return 录制状态
|
|
|
|
|
*/
|
|
|
|
|
bool isRecording(MediaSource &sender, Recorder::type type) override;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 添加track,内部会调用Track的clone方法
|
|
|
|
|
* 只会克隆sps pps这些信息 ,而不会克隆Delegate相关关系
|
|
|
|
|
* @param track
|
|
|
|
|
*/
|
|
|
|
|
void addTrack(const Track::Ptr & track) override;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 添加track完毕
|
|
|
|
|
* @param track
|
|
|
|
|
*/
|
|
|
|
|
void addTrackCompleted();
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 重置track
|
|
|
|
|
*/
|
|
|
|
|
void resetTracks() override;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 写入帧数据
|
|
|
|
|
* @param frame 帧
|
|
|
|
|
*/
|
|
|
|
|
void inputFrame(const Frame::Ptr &frame) override;
|
2020-04-29 11:59:45 +08:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 判断是否生效(是否正在转其他协议)
|
|
|
|
|
*/
|
|
|
|
|
bool isEnabled();
|
2018-10-24 17:17:55 +08:00
|
|
|
|
private:
|
2020-04-05 09:26:29 +08:00
|
|
|
|
MultiMuxerPrivate::Ptr _muxer;
|
|
|
|
|
std::weak_ptr<MediaSourceEvent> _listener;
|
2020-05-25 12:07:38 +08:00
|
|
|
|
Stamp _stamp[2];
|
2018-10-24 17:17:55 +08:00
|
|
|
|
};
|
|
|
|
|
|
2020-04-05 09:26:29 +08:00
|
|
|
|
}//namespace mediakit
|
2018-10-25 16:46:00 +08:00
|
|
|
|
#endif //ZLMEDIAKIT_MULTIMEDIASOURCEMUXER_H
|