From 1f8901981861b210d611b2d55708cad736e8cd80 Mon Sep 17 00:00:00 2001 From: xiongziliang <771730766@qq.com> Date: Thu, 1 Aug 2019 22:13:26 +0800 Subject: [PATCH] =?UTF-8?q?=E5=86=99mp4=E6=96=87=E4=BB=B6=E7=BC=93?= =?UTF-8?q?=E5=AD=98=E5=8F=AF=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Common/config.cpp | 4 ++++ src/Common/config.h | 2 ++ src/MediaFile/MP4Muxer.cpp | 9 +++++---- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/Common/config.cpp b/src/Common/config.cpp index 42aedb2d..1b4bf795 100644 --- a/src/Common/config.cpp +++ b/src/Common/config.cpp @@ -260,11 +260,15 @@ const string kFileSecond = RECORD_FIELD"fileSecond"; #define RECORD_FILE_PATH HTTP_ROOT_PATH const string kFilePath = RECORD_FIELD"filePath"; +//mp4文件写缓存大小 +const string kFileBufSize = RECORD_FIELD"fileBufSize"; + onceToken token([](){ mINI::Instance()[kAppName] = RECORD_APP_NAME; mINI::Instance()[kSampleMS] = RECORD_SAMPLE_MS; mINI::Instance()[kFileSecond] = RECORD_FILE_SECOND; mINI::Instance()[kFilePath] = RECORD_FILE_PATH; + mINI::Instance()[kFileBufSize] = 64 * 1024; },nullptr); } //namespace Record diff --git a/src/Common/config.h b/src/Common/config.h index 8807d175..6817e02e 100644 --- a/src/Common/config.h +++ b/src/Common/config.h @@ -255,6 +255,8 @@ extern const string kSampleMS; extern const string kFileSecond; //录制文件路径 extern const string kFilePath; +//mp4文件写缓存大小 +extern const string kFileBufSize; } //namespace Record ////////////HLS相关配置/////////// diff --git a/src/MediaFile/MP4Muxer.cpp b/src/MediaFile/MP4Muxer.cpp index eb5a9b56..afa78762 100644 --- a/src/MediaFile/MP4Muxer.cpp +++ b/src/MediaFile/MP4Muxer.cpp @@ -28,6 +28,7 @@ #include "MP4Muxer.h" #include "Util/File.h" +#include "Common/config.h" namespace mediakit{ @@ -213,8 +214,6 @@ void MP4Muxer::onTrackReady(const Track::Ptr &track) { } } -#define FILE_BUF_SIZE (64 * 1024) - MP4MuxerFile::MP4MuxerFile(const char *file) { //创建文件 auto fp = File::createfile_file(file,"wb+"); @@ -222,8 +221,10 @@ MP4MuxerFile::MP4MuxerFile(const char *file) { throw std::runtime_error(string("打开文件失败:") + file); } + GET_CONFIG(uint32_t,mp4BufSize,Record::kFileBufSize); + //新建文件io缓存 - std::shared_ptr file_buf(new char[FILE_BUF_SIZE],[](char *ptr){ + std::shared_ptr file_buf(new char[mp4BufSize],[](char *ptr){ if(ptr){ delete [] ptr; } @@ -231,7 +232,7 @@ MP4MuxerFile::MP4MuxerFile(const char *file) { if(file_buf){ //设置文件io缓存 - setvbuf(fp, file_buf.get(), _IOFBF, FILE_BUF_SIZE); + setvbuf(fp, file_buf.get(), _IOFBF, mp4BufSize); } //创建智能指针