Skip to content

Commit

Permalink
fix(cache): pass StreamMeta vector pointer
Browse files Browse the repository at this point in the history
  • Loading branch information
I-m-SuperMan committed Apr 8, 2020
1 parent 962e7ac commit 31813cc
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 43 deletions.
2 changes: 1 addition & 1 deletion framework/cacheModule/CacheModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ CacheRet CacheModule::start()

string cacheTmpPath = mCachePath.getCachePath() + TMP_SUFFIX;
mCacheFileRemuxer = new CacheFileRemuxer(cacheTmpPath, mDescription);
mCacheFileRemuxer->setStreamMeta(mStreamMetas);
mCacheFileRemuxer->setStreamMeta(&mStreamMetas);
mCacheFileRemuxer->setErrorCallback([this](int code, string msg) -> void {
if (mErrorCallback != nullptr) {
mErrorCallback(code, msg);
Expand Down
11 changes: 2 additions & 9 deletions framework/cacheModule/cache/CacheFileRemuxer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -270,16 +270,9 @@ void CacheFileRemuxer::setResultCallback(function<void(bool)> callback)
mResultCallback = callback;
}

void CacheFileRemuxer::setStreamMeta(const vector<Stream_meta *> &streamMetas)
void CacheFileRemuxer::setStreamMeta(const vector<Stream_meta *> *streamMetas)
{
mStreamMetas.clear();
if (streamMetas.empty()) {
return;
}

for (auto &item : streamMetas) {
mStreamMetas.push_back(item);
}
mStreamMetas = streamMetas;
}

void CacheFileRemuxer::sendError(const CacheRet &ret)
Expand Down
5 changes: 2 additions & 3 deletions framework/cacheModule/cache/CacheFileRemuxer.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class CacheFileRemuxer {

void setResultCallback(function<void(bool)> callback);

void setStreamMeta(const vector<Stream_meta *> &streamMetas);
void setStreamMeta(const vector<Stream_meta *> *streamMetas);

private :

Expand All @@ -71,7 +71,6 @@ private :
private:
string mDestFilePath;
string mDescription;
function<bool(StreamType, Stream_meta *)> mMetaCallback = nullptr;
deque<std::unique_ptr<FrameInfo>> mFrameInfoQueue;
condition_variable mQueueCondition;

Expand All @@ -92,7 +91,7 @@ private :
function<void(int, string)> mErrorCallback = nullptr;
function<void(bool)> mResultCallback = nullptr;

vector<Stream_meta *> mStreamMetas{};
const vector<Stream_meta*> *mStreamMetas;

};

Expand Down
4 changes: 1 addition & 3 deletions framework/muxer/IMuxer.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,7 @@ class IMuxer {
* add streamMetas
* @param streamMetas
*/
virtual void setStreamMetas(const std::vector<Stream_meta*> &streamMetas) = 0;

virtual void clearStreamMetas() = 0;
virtual void setStreamMetas(const vector<Stream_meta*> *streamMetas) = 0;

//must be set before open(). These will be write to header.
virtual void addSourceMetas(std::map<std::string,std::string> sourceMetas) = 0;
Expand Down
26 changes: 3 additions & 23 deletions framework/muxer/ffmpegMuxer/FfmpegMuxer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ FfmpegMuxer::~FfmpegMuxer()

mSourceMetaMap.clear();
mStreamInfoMap.clear();
clearStreamMetas();
}

int FfmpegMuxer::open()
Expand All @@ -54,7 +53,7 @@ int FfmpegMuxer::open()
return ret;
}

for (Stream_meta *item : mStreamMetas) {
for (Stream_meta *item : *mStreamMetas) {
AVStream *stream = nullptr;

if (item->type == Stream_type::STREAM_TYPE_VIDEO) {
Expand Down Expand Up @@ -366,28 +365,9 @@ int FfmpegMuxer::muxerWriteDataType(uint8_t *buf, int size, enum DataType type,
}
}

void FfmpegMuxer::setStreamMetas(const vector<Stream_meta *> &streamMetas)
void FfmpegMuxer::setStreamMetas(const vector<Stream_meta *> *streamMetas)
{
clearStreamMetas();

if (streamMetas.empty()) {
return;
}

for (const auto &item : streamMetas) {
mStreamMetas.push_back(item);
}
}

void FfmpegMuxer::clearStreamMetas()
{
if (!mStreamMetas.empty()) {
for (auto &item : mStreamMetas) {
releaseMeta(item);
}

mStreamMetas.clear();
}
mStreamMetas = streamMetas;
}

void FfmpegMuxer::addSourceMetas(map<string, string> sourceMetas)
Expand Down
6 changes: 2 additions & 4 deletions framework/muxer/ffmpegMuxer/FfmpegMuxer.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@ class CICADA_CPLUS_EXTERN FfmpegMuxer : public IMuxer, private IMuxerPrototype {

void setCopyPts(bool copyPts) override;

void setStreamMetas(const std::vector<Stream_meta *> &streamMetas) override;

void clearStreamMetas() override;
void setStreamMetas(const vector<Stream_meta*> *streamMetas) override;

//must be set before open(). These will be write to header.
void addSourceMetas(std::map<std::string, std::string> sourceMetas) override;
Expand Down Expand Up @@ -120,7 +118,7 @@ class CICADA_CPLUS_EXTERN FfmpegMuxer : public IMuxer, private IMuxerPrototype {
private:

std::map<std::string, std::string> mSourceMetaMap;
std::vector<Stream_meta *> mStreamMetas;
const vector<Stream_meta*> *mStreamMetas;
std::map<int, StreamInfo> mStreamInfoMap;

uint8_t *mIobuf = nullptr;
Expand Down

0 comments on commit 31813cc

Please sign in to comment.