Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
137 changes: 0 additions & 137 deletions .clang-format

This file was deleted.

1 change: 1 addition & 0 deletions base/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -628,6 +628,7 @@ SET(UT_FILES
test/overlaymodule_tests.cpp
test/testSignalGeneratorSrc_tests.cpp
test/audioToTextXform_tests.cpp
test/framefactory_memory_tests.cpp
${ARM64_UT_FILES}
${CUDA_UT_FILES}
)
Expand Down
38 changes: 37 additions & 1 deletion base/include/Command.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ class Command {
SendMMQTimestamps,
SendLastGTKGLRenderTS,
DecoderPlaybackSpeed,
Mp4FileClose
Mp4FileClose,
Mp4ReaderPlaybackSpeed
};

Command() { type = CommandType::None; }
Expand Down Expand Up @@ -324,4 +325,39 @@ class DecoderPlaybackSpeed : public Command
ar& playbackFps;
ar& playbackSpeed;
}
};

class Mp4ReaderPlaybackSpeedCommand : public Command
{
public:
Mp4ReaderPlaybackSpeedCommand() : Command(CommandType::Mp4ReaderPlaybackSpeed)
{
playbackSpeed = 1.0f;
direction = true;
}

Mp4ReaderPlaybackSpeedCommand(float _playbackSpeed, bool _direction = true)
: Command(CommandType::Mp4ReaderPlaybackSpeed)
{
playbackSpeed = _playbackSpeed;
direction = _direction;
}

size_t getSerializeSize()
{
return Command::getSerializeSize() + sizeof(playbackSpeed) + sizeof(direction);
}

float playbackSpeed;
bool direction; // fwd = true, bwd = false

private:
friend class boost::serialization::access;
template<class Archive>
void serialize(Archive& ar, const unsigned int /* file_version */)
{
ar& boost::serialization::base_object<Command>(*this);
ar& playbackSpeed;
ar& direction;
}
};
17 changes: 15 additions & 2 deletions base/include/Mp4ReaderSource.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class Mp4ReaderSourceProps : public ModuleProps

}

Mp4ReaderSourceProps(std::string _videoPath, bool _parseFS, uint16_t _reInitInterval, bool _direction, bool _readLoop, bool _giveLiveTS, int _parseFSTimeoutDuration = 15, bool _bFramesEnabled = false) : ModuleProps()
Mp4ReaderSourceProps(std::string _videoPath, bool _parseFS, uint16_t _reInitInterval, bool _direction, bool _readLoop, bool _giveLiveTS, int _parseFSTimeoutDuration = 15, bool _bFramesEnabled = false, float _playbackSpeed = 1.0f) : ModuleProps()
{
/* About props:
- videoPath - Path of a video from where the reading will start.
Expand All @@ -23,6 +23,7 @@ class Mp4ReaderSourceProps : public ModuleProps
- parseFS - Read the NVR format till infinity, if true. Else we read only one file.
- readLoop - Read a single video in loop. It can not be used in conjuction with live mode (reInitInterval > 0) or NVR mode (parseFS = true) mode.
- giveLiveTS - If enabled, gives live timestamps instead of recorded timestamps in the video files.
- playbackSpeed - Initial playback speed (0.25x to 32x). Can be changed dynamically via changePlaybackSpeed().
*/

if (reInitInterval < 0)
Expand All @@ -37,12 +38,21 @@ class Mp4ReaderSourceProps : public ModuleProps
"> reInitInterval <" + std::to_string(reInitInterval) + "> parseFS <" + std::to_string(_parseFS) + ">";
throw AIPException(AIP_FATAL, errMsg);
}

// Validate playback speed
if (_playbackSpeed <= 0.0f)
{
auto errMsg = "playbackSpeed must be greater than 0. Provided: <" + std::to_string(_playbackSpeed) + ">";
throw AIPException(AIP_FATAL, errMsg);
}

auto canonicalVideoPath = boost::filesystem::canonical(_videoPath);
videoPath = canonicalVideoPath.string();
parseFS = _parseFS;
bFramesEnabled = _bFramesEnabled;
direction = _direction;
giveLiveTS = _giveLiveTS;
playbackSpeed = _playbackSpeed;
if (_reInitInterval < 0)
{
throw AIPException(AIP_FATAL, "reInitInterval must be 0 or more seconds");
Expand Down Expand Up @@ -70,7 +80,7 @@ class Mp4ReaderSourceProps : public ModuleProps

size_t getSerializeSize()
{
return ModuleProps::getSerializeSize() + sizeof(videoPath) + sizeof(parseFS) + sizeof(skipDir) + sizeof(direction) + sizeof(parseFSTimeoutDuration) + sizeof(biggerFrameSize) + sizeof(biggerMetadataFrameSize) + sizeof(bFramesEnabled) + sizeof(forceFPS);
return ModuleProps::getSerializeSize() + sizeof(videoPath) + sizeof(parseFS) + sizeof(skipDir) + sizeof(direction) + sizeof(parseFSTimeoutDuration) + sizeof(biggerFrameSize) + sizeof(biggerMetadataFrameSize) + sizeof(bFramesEnabled) + sizeof(forceFPS) + sizeof(playbackSpeed);
}

std::string skipDir = "./data/Mp4_videos";
Expand All @@ -85,6 +95,7 @@ class Mp4ReaderSourceProps : public ModuleProps
bool readLoop = false;
bool giveLiveTS = false;
bool forceFPS = false;
float playbackSpeed = 1.0f;
private:
friend class boost::serialization::access;

Expand All @@ -103,6 +114,7 @@ class Mp4ReaderSourceProps : public ModuleProps
ar& readLoop;
ar& giveLiveTS;
ar& forceFPS;
ar& playbackSpeed;
}
};

Expand All @@ -119,6 +131,7 @@ class Mp4ReaderSource : public Module
void setImageMetadata(std::string& pinId, framemetadata_sp& metadata);
std::string addOutPutPin(framemetadata_sp& metadata);
bool changePlayback(float speed, bool direction);
bool changePlaybackSpeed(float speed, bool direction = true);
bool getVideoRangeFromCache(std::string videoPath, uint64_t& start_ts, uint64_t& end_ts);
bool randomSeek(uint64_t skipTS, bool forceReopen = false);
bool refreshCache();
Expand Down
22 changes: 21 additions & 1 deletion base/src/FrameFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,29 @@ void FrameFactory::destroy(Frame *pointer)
boost::mutex::scoped_lock lock(m_mutex);
counter.fetch_sub(1, memory_order_seq_cst);

// Calculate the actual allocation size
// If the pointer has been offset (by skipBytes), we need to reconstruct
// the original allocation size to free the correct number of chunks
size_t actualSize = pointer->size();
bool isOriginal = (pointer->myOrig == pointer->data());

if (!isOriginal) {
// The pointer has been moved forward by skipBytes
ptrdiff_t offset = static_cast<uint8_t*>(pointer->data()) - static_cast<uint8_t*>(pointer->myOrig);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we need a check for myOrig not being NULL before this. Ideally at the start of the function. There is currently as pathway possible that myOrig is NULL. That check is present at end of this function but the pgm will crash here itself.

// The original allocation was for (current size + offset) bytes
actualSize = pointer->size() + offset;
LOG_TRACE << "destroy frame with offset: current size=" << pointer->size()
<< " offset=" << offset
<< " original allocation size=" << actualSize
<< " pointer=" << pointer->myOrig;
}

// Calculate chunks based on the original allocation size
size_t n = getNumberOfChunks(actualSize);

// Free the memory chunks from the original pointer
if (pointer->myOrig != NULL)
{
size_t n = getNumberOfChunks(pointer->size());
numberOfChunks.fetch_sub(n, memory_order_seq_cst);
memory_allocator->freeChunks(pointer->myOrig, n);
}
Expand Down
6 changes: 4 additions & 2 deletions base/src/Logger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@ Logger* Logger::getLogger()
{
return instance.get();
}

initLogger(LoggerProps());
LoggerProps props;
std::cout << "Logger initializing with default props. => console logs "<< (props.enableConsoleLog ? "enabled" : "disabled")
<< ", file logs " << (props.enableFileLog ? "enabled" : "disabled") << std::endl;
initLogger(props);
return instance.get();
}

Expand Down
Loading