Skip to content

Commit

Permalink
1. getSetProps - working all the tests passong.
Browse files Browse the repository at this point in the history
1. Added tests for mp4_getLiveVideoTs, mp4_dts_strategy, mp4_simul_read_write
  • Loading branch information
mohammedzakikochargi committed Jul 26, 2023
1 parent d7988db commit 10aae1d
Show file tree
Hide file tree
Showing 197 changed files with 1,678 additions and 306 deletions.
3 changes: 3 additions & 0 deletions base/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,9 @@ SET(UT_FILES
test/mp4_reverse_play_tests.cpp
test/ordered_cache_of_files_tests.cpp
test/mp4_seek_tests.cpp
test/mp4_simul_read_write_tests.cpp
test/mp4_getlivevideots_tests.cpp
test/mp4_dts_strategy_tests.cpp
test/overlaymodule_tests.cpp
${ARM64_UT_FILES}
${CUDA_UT_FILES}
Expand Down
16 changes: 1 addition & 15 deletions base/include/Command.h
Original file line number Diff line number Diff line change
Expand Up @@ -280,18 +280,6 @@ class Mp4SeekCommand : public Command

}

Mp4SeekCommand(uint64_t _seekStartTS,uint64_t _seekEndTS) : Command(CommandType::Seek)
{
seekStartTS = _seekStartTS;
seekEndTS = _seekEndTS;
}


Mp4SeekCommand(uint64_t _seekStartTS) : Command(CommandType::Seek)
{
seekStartTS = _seekStartTS;
}

Mp4SeekCommand(uint64_t _skipTS, bool _forceReopen = false) : Command(CommandType::Seek)
{
seekStartTS = _skipTS;
Expand All @@ -300,11 +288,10 @@ class Mp4SeekCommand : public Command

size_t getSerializeSize()
{
return 128 + sizeof(Mp4SeekCommand) + sizeof(seekStartTS) + sizeof(seekEndTS) + +sizeof(forceReopen) + Command::getSerializeSize();
return 128 + sizeof(Mp4SeekCommand) + sizeof(seekStartTS) +sizeof(forceReopen) + Command::getSerializeSize();
}

uint64_t seekStartTS = 0;
uint64_t seekEndTS = 9999999999999;
bool forceReopen = false;
private:

Expand All @@ -314,7 +301,6 @@ class Mp4SeekCommand : public Command
{
ar& boost::serialization::base_object<Command>(*this);
ar& seekStartTS;
ar& seekEndTS;
ar& forceReopen;
}
};
Expand Down
2 changes: 1 addition & 1 deletion base/include/Mp4ReaderSource.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ class Mp4ReaderSource : public Module
std::string addOutPutPin(framemetadata_sp& metadata);
bool changePlayback(float speed, bool direction);
bool getVideoRangeFromCache(std::string videoPath, uint64_t& start_ts, uint64_t& end_ts);
bool randomSeek(uint64_t skipTS, bool forceReopen);
bool randomSeek(uint64_t skipTS, bool forceReopen = false);
bool refreshCache();
std::map<std::string, std::pair<uint64_t, uint64_t>> getCacheSnapShot(); // to be used for debugging only
double getOpenVideoFPS();
Expand Down
3 changes: 3 additions & 0 deletions base/include/OrderedCacheOfFiles.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ class OrderedCacheOfFiles
std::string getFileAt(uint64_t timestamp, bool direction);
bool isTimeStampInFile(std::string& filename, uint64_t timestamp);
std::string getNextFileAfter(std::string& currentFile, bool direction);
std::vector<boost::filesystem::path> parseAndSortDateDir(std::string rootDir);
std::vector<boost::filesystem::path> parseAndSortHourDir(std::string rootDir);
std::vector<boost::filesystem::path> parseAndSortMp4Files(std::string rootDir);
bool parseFiles(uint64_t start_ts, bool direction, bool includeFloorFile = false, bool disableBatchSizeCheck = false, uint64_t skipTS = 0);
bool getRandomSeekFile(uint64_t ts, bool direction, uint64_t& skipMsecs, std::string& fileName);
bool getFileFromCache(uint64_t timestamp, bool direction, std::string& fileName);
Expand Down
2 changes: 1 addition & 1 deletion base/src/Module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ class Module::Profiler
double mPipelineFps;
};

Module::Module(Kind nature, string name, ModuleProps _props) : mRunning(false), mPlay(true), mForceStepCount(0), mStopCount(0), mForwardPins(0), myNature(nature), myName(name), mSkipIndex(0)
Module::Module(Kind nature, string name, ModuleProps _props) : mRunning(false), mPlay(true), mDirection(true), mForceStepCount(0), mStopCount(0), mForwardPins(0), myNature(nature), myName(name), mSkipIndex(0)
{
static int moduleCounter = 0;
moduleCounter += 1;
Expand Down
68 changes: 33 additions & 35 deletions base/src/Mp4ReaderSource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,29 +89,34 @@ class Mp4ReaderDetailAbs
}
catch (...)
{
LOG_ERROR << "Incorrect video path ";
auto msg = "Video File name not in proper format.Check the filename sent as props. \
If you want to read a file with custom name instead, please disable parseFS flag.";
LOG_ERROR << msg;
return;
}
// clear the cache if parseFS is changed
if (props.parseFS != mProps.parseFS && cof)

// If the video path is a custom file - don't parse just open the video, cof check says that not to open video if setProps if called from module init().
if (!props.parseFS && cof)
{
cof->clearCache();
updateMstate(props, tempVideoPath);
initNewVideo();
return;
}

// check if the video file path has changed & its dynamic change of props
if (mState.mVideoPath != props.videoPath && mState.mVideoPath != "")
auto tempSkipDir = boost::filesystem::path(tempVideoPath).parent_path().parent_path().parent_path().string();
if (props.parseFS && mProps.skipDir == tempSkipDir && mState.mVideoPath != "")
{
if (mProps.videoPath == props.videoPath)
mProps = props;
LOG_ERROR << "The root dir is same and only file path has changed, Please use SEEK functionality instead for this use case!, cannot change props";
return;
}

if (props.parseFS && mProps.skipDir != tempSkipDir && mState.mVideoPath != "")
{
sentEOSSignal = false;

if (!props.parseFS)
{
// If the video path is a custom file - don't parse just open the video
updateMstate(props, tempVideoPath);
initNewVideo();
return;
}

// parseFS enabled
auto boostVideoTS = boost::filesystem::path(tempVideoPath).stem().string();
uint64_t start_parsing_ts = 0;
try
Expand All @@ -125,25 +130,16 @@ class Mp4ReaderDetailAbs
LOG_ERROR << msg;
throw AIPException(AIP_FATAL, msg);
}
auto tempSkipDir = boost::filesystem::path(tempVideoPath).parent_path().parent_path().parent_path().string();

//check if root has changed
if (mProps.skipDir != tempSkipDir)
{
cof = boost::shared_ptr<OrderedCacheOfFiles>(new OrderedCacheOfFiles(tempSkipDir));
cof->clearCache();
cof->parseFiles(start_parsing_ts, props.direction, true, false);
//parse successful - update mState and skipDir with current root dir
updateMstate(props, tempVideoPath);
mProps.skipDir = tempSkipDir;
initNewVideo(true);
return;
}

// The root dir is same only file path has changed
LOG_ERROR << "Please use SEEK functionality instead for this use case!";
cof = boost::shared_ptr<OrderedCacheOfFiles>(new OrderedCacheOfFiles(tempSkipDir));
cof->clearCache();
cof->parseFiles(start_parsing_ts, props.direction, true, false);
//parse successful - update mState and skipDir with current root dir
updateMstate(props, tempVideoPath);
mState.end = cof->parseFiles(start_parsing_ts, mState.direction, true, false);
initNewVideo();
mProps.skipDir = tempSkipDir;
initNewVideo(true);

return;
}

Expand Down Expand Up @@ -246,6 +242,7 @@ class Mp4ReaderDetailAbs
if (mState.demux)
{
mp4_demux_close(mState.demux);
mState.demux = nullptr;
}
}
catch (...)
Expand Down Expand Up @@ -664,6 +661,7 @@ class Mp4ReaderDetailAbs
try
{
mp4_demux_close(mState.demux);
mState.demux = nullptr;
}
catch (...)
{
Expand Down Expand Up @@ -992,7 +990,7 @@ class Mp4ReaderDetailJpeg : public Mp4ReaderDetailAbs
Mp4ReaderDetailJpeg(Mp4ReaderSourceProps& props, std::function<frame_sp(size_t size, std::string& pinId)> _makeFrame,
std::function<frame_sp(frame_sp& bigFrame, size_t& size, string& pinId)> _makeFrameTrim, std::function<void(frame_sp frame)> _sendEOS, std::function<void(std::string& pinId, framemetadata_sp& metadata)> _setMetadata, std::function<void(frame_sp& frame)> _sendMp4ErrorFrame) : Mp4ReaderDetailAbs(props, _makeFrame, _makeFrameTrim, _sendEOS, _setMetadata, _sendMp4ErrorFrame)
{}
~Mp4ReaderDetailJpeg() { mp4_demux_close(mState.demux); }
~Mp4ReaderDetailJpeg() {}
void setMetadata();
bool produceFrames(frame_container& frames);
void sendEndOfStream() {}
Expand All @@ -1005,7 +1003,7 @@ class Mp4ReaderDetailH264 : public Mp4ReaderDetailAbs
Mp4ReaderDetailH264(Mp4ReaderSourceProps& props, std::function<frame_sp(size_t size, string& pinId)> _makeFrame,
std::function<frame_sp(frame_sp& bigFrame, size_t& size, string& pinId)> _makeFrameTrim, std::function<void(frame_sp frame)> _sendEOS, std::function<void(std::string& pinId, framemetadata_sp& metadata)> _setMetadata, std::function<void(frame_sp& frame)> _sendMp4ErrorFrame) : Mp4ReaderDetailAbs(props, _makeFrame, _makeFrameTrim, _sendEOS, _setMetadata, _sendMp4ErrorFrame)
{}
~Mp4ReaderDetailH264() { mp4_demux_close(mState.demux); }
~Mp4ReaderDetailH264() {}
void setMetadata();
void readSPSPPS();
bool produceFrames(frame_container& frames);
Expand Down Expand Up @@ -1385,7 +1383,7 @@ bool Mp4ReaderSource::getVideoRangeFromCache(std::string videoFile, uint64_t& st
bool Mp4ReaderSource::term()
{
auto moduleRet = Module::term();

mDetail->attemptFileClose();
return moduleRet;
}

Expand Down Expand Up @@ -1453,7 +1451,7 @@ Mp4ReaderSourceProps Mp4ReaderSource::getProps()
bool Mp4ReaderSource::handlePropsChange(frame_sp& frame)
{
bool direction = getPlayDirection();
Mp4ReaderSourceProps props(mDetail->mProps.videoPath, mDetail->mProps.reInitInterval, direction, mDetail->mProps.readLoop, mDetail->mProps.giveLiveTS, mDetail->mProps.parseFSTimeoutDuration, mDetail->mProps.bFramesEnabled);
Mp4ReaderSourceProps props(mDetail->mProps.videoPath, mDetail->mProps.parseFS, mDetail->mProps.reInitInterval, direction, mDetail->mProps.readLoop, mDetail->mProps.giveLiveTS, mDetail->mProps.parseFSTimeoutDuration, mDetail->mProps.bFramesEnabled);
bool ret = Module::handlePropsChange(frame, props);
mDetail->setProps(props);
return ret;
Expand Down
Loading

0 comments on commit 10aae1d

Please sign in to comment.