通过mp4/hls录制测试

This commit is contained in:
xiongziliang 2018-10-28 01:04:18 +08:00
parent 4876e9ff5c
commit cb78764f1d
4 changed files with 15 additions and 11 deletions

View File

@ -29,7 +29,7 @@
namespace mediakit{ namespace mediakit{
void MediaSink::addTrack(const Track::Ptr &track_in) { void MediaSink::addTrack(const Track::Ptr &track_in) {
lock_guard<mutex> lck(_mtx); lock_guard<recursive_mutex> lck(_mtx);
//克隆Track只拷贝其数据不拷贝其数据转发关系 //克隆Track只拷贝其数据不拷贝其数据转发关系
auto track = track_in->clone(); auto track = track_in->clone();
@ -57,7 +57,7 @@ void MediaSink::addTrack(const Track::Ptr &track_in) {
} }
void MediaSink::inputFrame(const Frame::Ptr &frame) { void MediaSink::inputFrame(const Frame::Ptr &frame) {
lock_guard<mutex> lck(_mtx); lock_guard<recursive_mutex> lck(_mtx);
auto codec_id = frame->getCodecId(); auto codec_id = frame->getCodecId();
auto it = _track_map.find(codec_id); auto it = _track_map.find(codec_id);
if (it == _track_map.end()) { if (it == _track_map.end()) {
@ -84,7 +84,7 @@ bool MediaSink::isAllTrackReady() const {
} }
Track::Ptr MediaSink::getTrack(TrackType type) const { Track::Ptr MediaSink::getTrack(TrackType type) const {
lock_guard<mutex> lck(_mtx); lock_guard<recursive_mutex> lck(_mtx);
for (auto &pr : _track_map){ for (auto &pr : _track_map){
if(pr.second->getTrackType() == type){ if(pr.second->getTrackType() == type){
return pr.second; return pr.second;

View File

@ -93,7 +93,7 @@ protected:
*/ */
virtual void onTrackFrame(const Frame::Ptr &frame) {}; virtual void onTrackFrame(const Frame::Ptr &frame) {};
private: private:
mutable mutex _mtx; mutable recursive_mutex _mtx;
map<int,Track::Ptr> _track_map; map<int,Track::Ptr> _track_map;
map<int,function<void()> > _trackReadyCallback; map<int,function<void()> > _trackReadyCallback;
bool _allTrackReady = false; bool _allTrackReady = false;

View File

@ -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) { void Mp4Maker::inputH264_l(void *pData, uint32_t ui32Length, uint32_t ui32Duration) {
GET_CONFIG_AND_REGISTER(uint32_t,recordSec,Record::kFileSecond); 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)){ if(iType == 5 && (_hMp4 == MP4_INVALID_FILE_HANDLE || _ticker.elapsedTime() > recordSec * 1000)){
//在I帧率处新建MP4文件 //在I帧率处新建MP4文件
//如果文件未创建或者文件超过10分钟则创建新文件 //如果文件未创建或者文件超过10分钟则创建新文件

View File

@ -238,28 +238,32 @@ public:
case 5:{ case 5:{
//I //I
if(!_sps.empty()){ if(!_sps.empty()){
if(!_spsFrame){ if(!_spsFrame)
{
H264Frame::Ptr insertFrame = std::make_shared<H264Frame>(); H264Frame::Ptr insertFrame = std::make_shared<H264Frame>();
insertFrame->timeStamp = frame->stamp();
insertFrame->type = 7; 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->buffer.append(_sps);
insertFrame->iPrefixSize = 4; insertFrame->iPrefixSize = 4;
_spsFrame = insertFrame; _spsFrame = insertFrame;
} }
_spsFrame->timeStamp = frame->stamp();
VideoTrack::inputFrame(_spsFrame); VideoTrack::inputFrame(_spsFrame);
} }
if(!_pps.empty()){ if(!_pps.empty()){
if(!_ppsFrame){ if(!_ppsFrame)
{
H264Frame::Ptr insertFrame = std::make_shared<H264Frame>(); H264Frame::Ptr insertFrame = std::make_shared<H264Frame>();
insertFrame->timeStamp = frame->stamp();
insertFrame->type = 8; 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->buffer.append(_pps);
insertFrame->iPrefixSize = 4; insertFrame->iPrefixSize = 4;
_ppsFrame = insertFrame; _ppsFrame = insertFrame;
} }
_ppsFrame->timeStamp = frame->stamp();
VideoTrack::inputFrame(_ppsFrame); VideoTrack::inputFrame(_ppsFrame);
} }
VideoTrack::inputFrame(frame); VideoTrack::inputFrame(frame);