Header refactor (#2115)

* 优化MultiMediaSourceMuxer头文件包含

* 将MediaSinkDelegate和Demux移到MediaSink中

* MediaSource头文件重构, 独立出PacketCache.h
精简Frame和Track的头文件

* Rtmp头文件重构

* Rtsp头文件重构

* webrtc头文件重构

* 规范.h头文件包含,并将其移到.cpp中:
- 尽量不包含Common\config.h
- Util\File.h
- Rtsp/RtspPlayer.h
- Rtmp/RtmpPlayer.h

* 删除多余的Stamp.h和Base64包含
This commit is contained in:
mtdxc
2022-11-29 11:07:13 +08:00
committed by GitHub
parent 59ecdd13e5
commit 754073918a
127 changed files with 1043 additions and 917 deletions

View File

@@ -9,6 +9,7 @@
*/
#include "HlsMaker.h"
#include "Common/config.h"
using namespace std;

View File

@@ -11,13 +11,9 @@
#ifndef HLSMAKER_H
#define HLSMAKER_H
#include <string>
#include <deque>
#include <tuple>
#include "Common/config.h"
#include "Util/TimeTicker.h"
#include "Util/File.h"
#include "Util/util.h"
#include "Util/logger.h"
namespace mediakit {

View File

@@ -13,6 +13,8 @@
#include "HlsMakerImp.h"
#include "Util/util.h"
#include "Util/uv_errno.h"
#include "Util/File.h"
#include "Common/config.h"
using namespace std;
using namespace toolkit;

View File

@@ -9,6 +9,7 @@
*/
#include "HlsMediaSource.h"
#include "Common/config.h"
using namespace toolkit;
@@ -64,4 +65,40 @@ HlsMediaSource::Ptr HlsCookieData::getMediaSource() const {
return _src.lock();
}
void HlsMediaSource::setIndexFile(std::string index_file)
{
if (!_ring) {
std::weak_ptr<HlsMediaSource> weakSelf = std::dynamic_pointer_cast<HlsMediaSource>(shared_from_this());
auto lam = [weakSelf](int size) {
auto strongSelf = weakSelf.lock();
if (!strongSelf) {
return;
}
strongSelf->onReaderChanged(size);
};
_ring = std::make_shared<RingType>(0, std::move(lam));
regist();
}
//赋值m3u8索引文件内容
std::lock_guard<std::mutex> lck(_mtx_index);
_index_file = std::move(index_file);
if (!_index_file.empty()) {
_list_cb.for_each([&](const std::function<void(const std::string& str)>& cb) { cb(_index_file); });
_list_cb.clear();
}
}
void HlsMediaSource::getIndexFile(std::function<void(const std::string& str)> cb)
{
std::lock_guard<std::mutex> lck(_mtx_index);
if (!_index_file.empty()) {
cb(_index_file);
return;
}
//等待生成m3u8文件
_list_cb.emplace_back(std::move(cb));
}
} // namespace mediakit

View File

@@ -13,6 +13,7 @@
#include "Common/MediaSource.h"
#include "Util/TimeTicker.h"
#include "Util/RingBuffer.h"
#include <atomic>
namespace mediakit {
@@ -41,42 +42,12 @@ public:
/**
* 设置或清空m3u8索引文件内容
*/
void setIndexFile(std::string index_file) {
if (!_ring) {
std::weak_ptr<HlsMediaSource> weakSelf = std::dynamic_pointer_cast<HlsMediaSource>(shared_from_this());
auto lam = [weakSelf](int size) {
auto strongSelf = weakSelf.lock();
if (!strongSelf) {
return;
}
strongSelf->onReaderChanged(size);
};
_ring = std::make_shared<RingType>(0, std::move(lam));
regist();
}
//赋值m3u8索引文件内容
std::lock_guard<std::mutex> lck(_mtx_index);
_index_file = std::move(index_file);
if (!_index_file.empty()) {
_list_cb.for_each([&](const std::function<void(const std::string &str)> &cb) { cb(_index_file); });
_list_cb.clear();
}
}
void setIndexFile(std::string index_file);
/**
* 异步获取m3u8文件
*/
void getIndexFile(std::function<void(const std::string &str)> cb) {
std::lock_guard<std::mutex> lck(_mtx_index);
if (!_index_file.empty()) {
cb(_index_file);
return;
}
//等待生成m3u8文件
_list_cb.emplace_back(std::move(cb));
}
void getIndexFile(std::function<void(const std::string &str)> cb);
/**
* 同步获取m3u8文件

View File

@@ -13,6 +13,7 @@
#include "HlsMakerImp.h"
#include "MPEG.h"
#include "Common/config.h"
namespace mediakit {

View File

@@ -11,8 +11,11 @@
#ifdef ENABLE_MP4
#include "MP4Muxer.h"
#include "Util/File.h"
#include "Extension/AAC.h"
#include "Extension/G711.h"
#include "Extension/H264.h"
#include "Extension/H265.h"
#include "Common/config.h"
using namespace std;
using namespace toolkit;

View File

@@ -14,10 +14,6 @@
#ifdef ENABLE_MP4
#include "Common/MediaSink.h"
#include "Extension/AAC.h"
#include "Extension/G711.h"
#include "Extension/H264.h"
#include "Extension/H265.h"
#include "Common/Stamp.h"
#include "MP4.h"

View File

@@ -13,6 +13,7 @@
#include "MP4Reader.h"
#include "Common/config.h"
#include "Thread/WorkThreadPool.h"
#include "Util/File.h"
using namespace std;
using namespace toolkit;

View File

@@ -15,6 +15,7 @@
#include "Common/config.h"
#include "MP4Recorder.h"
#include "Thread/WorkThreadPool.h"
#include "MP4Muxer.h"
using namespace std;
using namespace toolkit;

View File

@@ -13,17 +13,14 @@
#include <mutex>
#include <memory>
#include "Player/PlayerBase.h"
#include "Util/util.h"
#include "Util/logger.h"
#include "Util/TimeTicker.h"
#include "Util/TimeTicker.h"
#include "Common/MediaSink.h"
#include "MP4Muxer.h"
#include "Record/Recorder.h"
namespace mediakit {
#ifdef ENABLE_MP4
class MP4Muxer;
class MP4Recorder final : public MediaSinkInterface {
public:
using Ptr = std::shared_ptr<MP4Recorder>;
@@ -63,7 +60,7 @@ private:
std::string _full_path;
std::string _full_path_tmp;
RecordInfo _info;
MP4Muxer::Ptr _muxer;
std::shared_ptr<MP4Muxer> _muxer;
std::list<Track::Ptr> _tracks;
uint64_t _last_dts = 0;
};

View File

@@ -18,10 +18,8 @@
#include <unordered_map>
#include "Extension/Frame.h"
#include "Extension/Track.h"
#include "Util/File.h"
#include "Common/MediaSink.h"
#include "Common/Stamp.h"
#include "Util/ResourcePool.h"
namespace mediakit {
//该类用于产生MPEG-TS/MPEG-PS

View File

@@ -10,9 +10,11 @@
#include "Recorder.h"
#include "Common/config.h"
#include "Util/File.h"
#include "Common/MediaSource.h"
#include "MP4Recorder.h"
#include "HlsRecorder.h"
#include "Util/File.h"
using namespace std;
using namespace toolkit;