mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2024-10-30 16:27:36 +08:00
通过mp4/hls录制测试
This commit is contained in:
parent
4876e9ff5c
commit
cb78764f1d
@ -29,7 +29,7 @@
|
||||
namespace mediakit{
|
||||
|
||||
void MediaSink::addTrack(const Track::Ptr &track_in) {
|
||||
lock_guard<mutex> lck(_mtx);
|
||||
lock_guard<recursive_mutex> lck(_mtx);
|
||||
//克隆Track,只拷贝其数据,不拷贝其数据转发关系
|
||||
auto track = track_in->clone();
|
||||
|
||||
@ -57,7 +57,7 @@ void MediaSink::addTrack(const Track::Ptr &track_in) {
|
||||
}
|
||||
|
||||
void MediaSink::inputFrame(const Frame::Ptr &frame) {
|
||||
lock_guard<mutex> lck(_mtx);
|
||||
lock_guard<recursive_mutex> lck(_mtx);
|
||||
auto codec_id = frame->getCodecId();
|
||||
auto it = _track_map.find(codec_id);
|
||||
if (it == _track_map.end()) {
|
||||
@ -84,7 +84,7 @@ bool MediaSink::isAllTrackReady() const {
|
||||
}
|
||||
|
||||
Track::Ptr MediaSink::getTrack(TrackType type) const {
|
||||
lock_guard<mutex> lck(_mtx);
|
||||
lock_guard<recursive_mutex> lck(_mtx);
|
||||
for (auto &pr : _track_map){
|
||||
if(pr.second->getTrackType() == type){
|
||||
return pr.second;
|
||||
|
@ -93,7 +93,7 @@ protected:
|
||||
*/
|
||||
virtual void onTrackFrame(const Frame::Ptr &frame) {};
|
||||
private:
|
||||
mutable mutex _mtx;
|
||||
mutable recursive_mutex _mtx;
|
||||
map<int,Track::Ptr> _track_map;
|
||||
map<int,function<void()> > _trackReadyCallback;
|
||||
bool _allTrackReady = false;
|
||||
|
@ -113,7 +113,7 @@ void Mp4Maker::inputAAC(void *pData, uint32_t ui32Length, uint32_t ui32TimeStamp
|
||||
void Mp4Maker::inputH264_l(void *pData, uint32_t ui32Length, uint32_t ui32Duration) {
|
||||
GET_CONFIG_AND_REGISTER(uint32_t,recordSec,Record::kFileSecond);
|
||||
|
||||
auto iType = ((uint8_t*)pData)[0] & 0x1F;
|
||||
auto iType = ((uint8_t*)pData)[4] & 0x1F;
|
||||
if(iType == 5 && (_hMp4 == MP4_INVALID_FILE_HANDLE || _ticker.elapsedTime() > recordSec * 1000)){
|
||||
//在I帧率处新建MP4文件
|
||||
//如果文件未创建或者文件超过10分钟则创建新文件
|
||||
|
@ -238,28 +238,32 @@ public:
|
||||
case 5:{
|
||||
//I
|
||||
if(!_sps.empty()){
|
||||
if(!_spsFrame){
|
||||
if(!_spsFrame)
|
||||
{
|
||||
H264Frame::Ptr insertFrame = std::make_shared<H264Frame>();
|
||||
insertFrame->timeStamp = frame->stamp();
|
||||
insertFrame->type = 7;
|
||||
insertFrame->buffer.assign("\x0\x0\x0\x1");
|
||||
insertFrame->timeStamp = frame->stamp();
|
||||
insertFrame->buffer.assign("\x0\x0\x0\x1",4);
|
||||
insertFrame->buffer.append(_sps);
|
||||
insertFrame->iPrefixSize = 4;
|
||||
_spsFrame = insertFrame;
|
||||
}
|
||||
_spsFrame->timeStamp = frame->stamp();
|
||||
VideoTrack::inputFrame(_spsFrame);
|
||||
}
|
||||
|
||||
if(!_pps.empty()){
|
||||
if(!_ppsFrame){
|
||||
if(!_ppsFrame)
|
||||
{
|
||||
H264Frame::Ptr insertFrame = std::make_shared<H264Frame>();
|
||||
insertFrame->timeStamp = frame->stamp();
|
||||
insertFrame->type = 8;
|
||||
insertFrame->buffer.assign("\x0\x0\x0\x1");
|
||||
insertFrame->timeStamp = frame->stamp();
|
||||
insertFrame->buffer.assign("\x0\x0\x0\x1",4);
|
||||
insertFrame->buffer.append(_pps);
|
||||
insertFrame->iPrefixSize = 4;
|
||||
_ppsFrame = insertFrame;
|
||||
}
|
||||
_ppsFrame->timeStamp = frame->stamp();
|
||||
VideoTrack::inputFrame(_ppsFrame);
|
||||
}
|
||||
VideoTrack::inputFrame(frame);
|
||||
|
Loading…
Reference in New Issue
Block a user