Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/Apra-Labs/ApraPipes into mo…
Browse files Browse the repository at this point in the history
…duleTestSignalGenerator
  • Loading branch information
mohammedzakikochargi committed Jul 28, 2023
2 parents 2a74b17 + c2f230e commit 987e3be
Show file tree
Hide file tree
Showing 220 changed files with 6,828 additions and 1,254 deletions.
11 changes: 9 additions & 2 deletions base/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -156,15 +156,16 @@ SET(CORE_FILES
src/Mp4WriterSinkUtils.cpp
src/MultimediaQueueXform.cpp
src/Mp4ReaderSource.cpp
src/Mp4ReaderSourceUtils.cpp
src/RTSPClientSrc.cpp
src/RTSPClientSrc.cpp
src/MotionVectorExtractor.cpp
src/OverlayModule.cpp
src/OrderedCacheOfFiles.cpp
)

SET(CORE_FILES_H
include/BufferMaker.h
include/Mp4ErrorFrame.h
include/FramesMuxer.h
include/FrameMetadata.h
include/FrameMetadataFactory.h
Expand Down Expand Up @@ -215,11 +216,11 @@ SET(CORE_FILES_H
include/RTSPClientSrc.h
include/H264Metadata.h
include/Mp4ReaderSource.h
include/Mp4ReaderSourceUtils.h
include/RTSPClientSrc.h
include/H264Metadata.h
include/MotionVectorExtractor.h
include/OverlayModule.h
include/OrderedCacheOfFiles.h
include/TestSignalGeneratorSrc.h
)

Expand Down Expand Up @@ -546,6 +547,12 @@ SET(UT_FILES
test/rtsp_client_tests.cpp
test/rtsp_client_tests.cpp
test/motionvector_extractor_and_overlay_tests.cpp
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
test/testSignalGeneratorSrc_tests.cpp
${ARM64_UT_FILES}
Expand Down
40 changes: 40 additions & 0 deletions base/include/AIPExceptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,25 @@
#define AIP_NOTIMPLEMENTED 7723
#define AIP_NOTSET 7725
#define AIP_NOTEXEPCTED 7726
#define MP4_OCOF_END 7726

// Fatal errors
#define AIP_FATAL 7811
#define MP4_NAME_PARSE_FAILED 7812
#define MP4_FILE_CLOSE_FAILED 7813
#define MP4_RELOAD_RESUME_FAILED 7814
#define MP4_OPEN_FILE_FAILED 7815
#define MP4_MISSING_VIDEOTRACK 7816
#define MP4_MISSING_START_TS 7817
#define MP4_TIME_RANGE_FETCH_FAILED 7818
#define MP4_SET_POINTER_END_FAILED 7819
#define MP4_SEEK_INSIDE_FILE_FAILED 7820
#define MP4_BUFFER_TOO_SMALL 7821
#define MP4_OCOF_EMPTY 7721
#define MP4_OCOF_MISSING_FILE 7822
#define MP4_OCOF_INVALID_DUR 7823
#define MP4_UNEXPECTED_STATE 7824


#define AIPException_LOG_SEV(severity,type) for(std::ostringstream stream; Logger::getLogger()->push(severity, stream);) Logger::getLogger()->aipexceptionPre(stream, severity,type)

Expand Down Expand Up @@ -67,4 +83,28 @@ class AIP_Exception : public std::runtime_error
std::string message;
};

class Mp4_Exception : public AIP_Exception
{
public:
explicit Mp4_Exception(int type, const std::string file, int line, const std::string logMessage) :
AIP_Exception(type, file, line, logMessage)
{
}

explicit Mp4_Exception(int type, const std::string file, int line, int _openFileErrorCode, const std::string logMessage) :
AIP_Exception(type, file, line, logMessage)
{
openFileErrorCode = _openFileErrorCode;
}

int getOpenFileErrorCode()
{
return openFileErrorCode;
}

private:
int openFileErrorCode = 0;
};

#define AIPException(_type,_message) AIP_Exception(_type,__FILE__,__LINE__,_message)
#define Mp4Exception(_type,_message) Mp4_Exception(_type,__FILE__,__LINE__,_message)
54 changes: 47 additions & 7 deletions base/include/Command.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ class Command
MultimediaQueueXform,
Seek,
DeleteWindow,
CreateWindow
CreateWindow,
PlayPause
};

Command()
Expand Down Expand Up @@ -279,19 +280,19 @@ class Mp4SeekCommand : public Command

}

Mp4SeekCommand(uint64_t _seekStartTS,uint64_t _seekEndTS) : Command(CommandType::Seek)
Mp4SeekCommand(uint64_t _skipTS, bool _forceReopen = false) : Command(CommandType::Seek)
{
seekStartTS = _seekStartTS;
seekEndTS = _seekEndTS;
seekStartTS = _skipTS;
forceReopen = _forceReopen;
}

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

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

friend class boost::serialization::access;
Expand All @@ -300,6 +301,45 @@ class Mp4SeekCommand : public Command
{
ar& boost::serialization::base_object<Command>(*this);
ar& seekStartTS;
ar& seekEndTS;
ar& forceReopen;
}
};

class PlayPauseCommand : public Command
{
public:
PlayPauseCommand() : Command(CommandType::PlayPause)
{
}

PlayPauseCommand(float _speed, bool _direction) : Command(CommandType::PlayPause)
{

if (_speed != 0 && _speed != 1)
{
LOG_ERROR << "Fractional speed is not yet supported.";
throw AIPException(AIP_FATAL, "Fractional speed is not yet supported.");
}
speed = _speed;
direction = _direction;
}

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

// play speed of the module at any given fps
float speed = 1;
// fwd = 1, bwd = 0
bool direction = 1;
private:
friend class boost::serialization::access;
template<class Archive>
void serialize(Archive& ar, const unsigned int)
{
ar& boost::serialization::base_object<Command>(*this);
ar& speed;
ar& direction;
}
};
12 changes: 12 additions & 0 deletions base/include/Frame.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class Frame :public boost::asio::mutable_buffer {
int m_num, m_den;
virtual bool isEoP() { return false; }
virtual bool isEOS() { return false; }
virtual bool isMp4ErrorFrame() { return false; }
virtual bool isEmpty() { return false; }
virtual bool isPropsChange();
virtual bool isPausePlay();
Expand Down Expand Up @@ -51,9 +52,20 @@ class EoPFrame : public Frame

class EoSFrame : public Frame {
public:
enum EoSFrameType
{
GENERAL = 0,
MP4_PLYB_EOS,
MP4_SEEK_EOS,
};
EoSFrame();
virtual ~EoSFrame() {}
virtual bool isEOS();
EoSFrameType getEoSFrameType();
EoSFrame(EoSFrameType eosType, uint64_t mp4TS);
private:
EoSFrameType type;
uint64_t mp4TS;
};

class EmptyFrame :public Frame {
Expand Down
8 changes: 8 additions & 0 deletions base/include/Module.h
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ class Module {
virtual bool init();
void operator()(); //to support boost::thread
virtual bool run();
bool play(float speed, bool direction = true);
bool play(bool play);
bool queueStep();
virtual bool step();
Expand All @@ -176,6 +177,7 @@ class Module {
boost::shared_ptr<PaceMaker> getPacer() { return pacer; }
static frame_sp getFrameByType(frame_container& frames, int frameType);
virtual void flushQue();
bool getPlayDirection() { return mDirection; }
virtual void flushQueRecursive();
protected:
virtual boost_deque<frame_sp> getFrames(frame_container& frames);
Expand Down Expand Up @@ -240,6 +242,7 @@ class Module {
Utils::deSerialize(cmd, frame->data(), frame->size());
}

bool queuePlayPauseCommand(PlayPauseCommand ppCmd);
frame_sp makeCommandFrame(size_t size, framemetadata_sp& metadata);
frame_sp makeFrame(size_t size, string& pinId);
frame_sp makeFrame(size_t size); // use only if 1 output pin is there
Expand All @@ -252,6 +255,8 @@ class Module {

virtual bool send(frame_container& frames, bool forceBlockingPush=false);
virtual void sendEOS();
virtual void sendEOS(frame_sp& frame);
virtual void sendMp4ErrorFrame(frame_sp& frame);
virtual void sendEoPFrame();

boost::function<void () > onStepFail;
Expand Down Expand Up @@ -318,6 +323,7 @@ class Module {

bool processSourceQue();
bool handlePausePlay(bool play);
virtual bool handlePausePlay(float speed = 1, bool direction = true);
virtual void notifyPlay(bool play) {}

//makes buffers from frameFactory
Expand Down Expand Up @@ -370,6 +376,8 @@ class Module {
bool isFeedbackEnabled(std::string& moduleId); // get pins and call

bool mPlay;
bool mDirection;
float mSpeed;
uint32_t mForceStepCount;
int mSkipIndex;
Kind myNature;
Expand Down
40 changes: 40 additions & 0 deletions base/include/Mp4ErrorFrame.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#pragma once
#include "Frame.h"
#include "Utils.h"

class Mp4ErrorFrame : public Frame {
public:
enum Mp4ErrorFrameType
{
MP4_SEEK,
MP4_STEP
};

Mp4ErrorFrame() {}
Mp4ErrorFrame(int _errorType, int _errorCode, std::string &_errorMsg)
{
errorType = _errorType;
errorCode = _errorCode;
errorMsg = _errorMsg;
}

Mp4ErrorFrame(int _errorType, int _errorCode, std::string &_errorMsg, int _openErrorCode, uint64_t& _errorMp4TS)
{
errorType = _errorType;
errorCode = _errorCode;
errorMsg = _errorMsg;
openErrorCode = _openErrorCode;
errorMp4TS = _errorMp4TS;
}

bool isMp4ErrorFrame()
{
return true;
}

int errorType; // SEEK/STEP
int errorCode; // defined in AIPExceptions.h
uint64_t errorMp4TS = 0; // skipTS in randomSeek, lastFrameTS in step
int openErrorCode = 0; // expose some libmp4 error codes
std::string errorMsg; // keep chars < 500
};
Loading

0 comments on commit 987e3be

Please sign in to comment.