whitespace/tabs updates
This commit is contained in:
parent
d63df84c98
commit
fcc507b93e
2378
src/zm_event.cpp
2378
src/zm_event.cpp
File diff suppressed because it is too large
Load Diff
290
src/zm_event.h
290
src/zm_event.h
|
@ -41,193 +41,193 @@
|
||||||
class Zone;
|
class Zone;
|
||||||
class Monitor;
|
class Monitor;
|
||||||
|
|
||||||
#define MAX_PRE_ALARM_FRAMES 16 // Maximum number of prealarm frames that can be stored
|
#define MAX_PRE_ALARM_FRAMES 16 // Maximum number of prealarm frames that can be stored
|
||||||
|
|
||||||
//
|
//
|
||||||
// Class describing events, i.e. captured periods of activity.
|
// Class describing events, i.e. captured periods of activity.
|
||||||
//
|
//
|
||||||
class Event
|
class Event
|
||||||
{
|
{
|
||||||
friend class EventStream;
|
friend class EventStream;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
static bool initialised;
|
static bool initialised;
|
||||||
static char capture_file_format[PATH_MAX];
|
static char capture_file_format[PATH_MAX];
|
||||||
static char analyse_file_format[PATH_MAX];
|
static char analyse_file_format[PATH_MAX];
|
||||||
static char general_file_format[PATH_MAX];
|
static char general_file_format[PATH_MAX];
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
static int sd;
|
static int sd;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
typedef std::set<std::string> StringSet;
|
typedef std::set<std::string> StringSet;
|
||||||
typedef std::map<std::string,StringSet> StringSetMap;
|
typedef std::map<std::string,StringSet> StringSetMap;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
typedef enum { NORMAL, BULK, ALARM } FrameType;
|
typedef enum { NORMAL, BULK, ALARM } FrameType;
|
||||||
|
|
||||||
struct PreAlarmData
|
struct PreAlarmData
|
||||||
{
|
{
|
||||||
Image *image;
|
Image *image;
|
||||||
struct timeval timestamp;
|
struct timeval timestamp;
|
||||||
unsigned int score;
|
unsigned int score;
|
||||||
Image *alarm_frame;
|
Image *alarm_frame;
|
||||||
};
|
};
|
||||||
|
|
||||||
static int pre_alarm_count;
|
static int pre_alarm_count;
|
||||||
static PreAlarmData pre_alarm_data[MAX_PRE_ALARM_FRAMES];
|
static PreAlarmData pre_alarm_data[MAX_PRE_ALARM_FRAMES];
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
unsigned int id;
|
unsigned int id;
|
||||||
Monitor *monitor;
|
Monitor *monitor;
|
||||||
struct timeval start_time;
|
struct timeval start_time;
|
||||||
struct timeval end_time;
|
struct timeval end_time;
|
||||||
std::string cause;
|
std::string cause;
|
||||||
StringSetMap noteSetMap;
|
StringSetMap noteSetMap;
|
||||||
int frames;
|
int frames;
|
||||||
int alarm_frames;
|
int alarm_frames;
|
||||||
unsigned int tot_score;
|
unsigned int tot_score;
|
||||||
unsigned int max_score;
|
unsigned int max_score;
|
||||||
char path[PATH_MAX];
|
char path[PATH_MAX];
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
int last_db_frame;
|
int last_db_frame;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
static void Initialise()
|
static void Initialise()
|
||||||
{
|
{
|
||||||
if ( initialised )
|
if ( initialised )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
snprintf( capture_file_format, sizeof(capture_file_format), "%%s/%%0%dd-capture.jpg", config.event_image_digits );
|
snprintf( capture_file_format, sizeof(capture_file_format), "%%s/%%0%dd-capture.jpg", config.event_image_digits );
|
||||||
snprintf( analyse_file_format, sizeof(analyse_file_format), "%%s/%%0%dd-analyse.jpg", config.event_image_digits );
|
snprintf( analyse_file_format, sizeof(analyse_file_format), "%%s/%%0%dd-analyse.jpg", config.event_image_digits );
|
||||||
snprintf( general_file_format, sizeof(general_file_format), "%%s/%%0%dd-%%s", config.event_image_digits );
|
snprintf( general_file_format, sizeof(general_file_format), "%%s/%%0%dd-%%s", config.event_image_digits );
|
||||||
|
|
||||||
initialised = true;
|
initialised = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void createNotes( std::string ¬es );
|
void createNotes( std::string ¬es );
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static bool OpenFrameSocket( int );
|
static bool OpenFrameSocket( int );
|
||||||
static bool ValidateFrameSocket( int );
|
static bool ValidateFrameSocket( int );
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Event( Monitor *p_monitor, struct timeval p_start_time, const std::string &p_cause, const StringSetMap &p_noteSetMap );
|
Event( Monitor *p_monitor, struct timeval p_start_time, const std::string &p_cause, const StringSetMap &p_noteSetMap );
|
||||||
~Event();
|
~Event();
|
||||||
|
|
||||||
int Id() const { return( id ); }
|
int Id() const { return( id ); }
|
||||||
const std::string &Cause() { return( cause ); }
|
const std::string &Cause() { return( cause ); }
|
||||||
int Frames() const { return( frames ); }
|
int Frames() const { return( frames ); }
|
||||||
int AlarmFrames() const { return( alarm_frames ); }
|
int AlarmFrames() const { return( alarm_frames ); }
|
||||||
|
|
||||||
const struct timeval &StartTime() const { return( start_time ); }
|
const struct timeval &StartTime() const { return( start_time ); }
|
||||||
const struct timeval &EndTime() const { return( end_time ); }
|
const struct timeval &EndTime() const { return( end_time ); }
|
||||||
struct timeval &EndTime() { return( end_time ); }
|
struct timeval &EndTime() { return( end_time ); }
|
||||||
|
|
||||||
bool SendFrameImage( const Image *image, bool alarm_frame=false );
|
bool SendFrameImage( const Image *image, bool alarm_frame=false );
|
||||||
bool WriteFrameImage( Image *image, struct timeval timestamp, const char *event_file, bool alarm_frame=false );
|
bool WriteFrameImage( Image *image, struct timeval timestamp, const char *event_file, bool alarm_frame=false );
|
||||||
|
|
||||||
void updateNotes( const StringSetMap &stringSetMap );
|
void updateNotes( const StringSetMap &stringSetMap );
|
||||||
|
|
||||||
void AddFrames( int n_frames, Image **images, struct timeval **timestamps );
|
void AddFrames( int n_frames, Image **images, struct timeval **timestamps );
|
||||||
void AddFrame( Image *image, struct timeval timestamp, int score=0, Image *alarm_frame=NULL );
|
void AddFrame( Image *image, struct timeval timestamp, int score=0, Image *alarm_frame=NULL );
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void AddFramesInternal( int n_frames, int start_frame, Image **images, struct timeval **timestamps );
|
void AddFramesInternal( int n_frames, int start_frame, Image **images, struct timeval **timestamps );
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static const char *getSubPath( struct tm *time )
|
static const char *getSubPath( struct tm *time )
|
||||||
|
{
|
||||||
|
static char subpath[PATH_MAX] = "";
|
||||||
|
snprintf( subpath, sizeof(subpath), "%02d/%02d/%02d/%02d/%02d/%02d", time->tm_year-100, time->tm_mon+1, time->tm_mday, time->tm_hour, time->tm_min, time->tm_sec );
|
||||||
|
return( subpath );
|
||||||
|
}
|
||||||
|
static const char *getSubPath( time_t *time )
|
||||||
|
{
|
||||||
|
return( Event::getSubPath( localtime( time ) ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
public:
|
||||||
|
static int PreAlarmCount()
|
||||||
|
{
|
||||||
|
return( pre_alarm_count );
|
||||||
|
}
|
||||||
|
static void EmptyPreAlarmFrames()
|
||||||
|
{
|
||||||
|
if ( pre_alarm_count > 0 )
|
||||||
{
|
{
|
||||||
static char subpath[PATH_MAX] = "";
|
for ( int i = 0; i < MAX_PRE_ALARM_FRAMES; i++ )
|
||||||
snprintf( subpath, sizeof(subpath), "%02d/%02d/%02d/%02d/%02d/%02d", time->tm_year-100, time->tm_mon+1, time->tm_mday, time->tm_hour, time->tm_min, time->tm_sec );
|
{
|
||||||
return( subpath );
|
delete pre_alarm_data[i].image;
|
||||||
|
delete pre_alarm_data[i].alarm_frame;
|
||||||
|
}
|
||||||
|
memset( pre_alarm_data, 0, sizeof(pre_alarm_data) );
|
||||||
}
|
}
|
||||||
static const char *getSubPath( time_t *time )
|
pre_alarm_count = 0;
|
||||||
|
}
|
||||||
|
static void AddPreAlarmFrame( Image *image, struct timeval timestamp, int score=0, Image *alarm_frame=NULL )
|
||||||
|
{
|
||||||
|
pre_alarm_data[pre_alarm_count].image = new Image( *image );
|
||||||
|
pre_alarm_data[pre_alarm_count].timestamp = timestamp;
|
||||||
|
pre_alarm_data[pre_alarm_count].score = score;
|
||||||
|
if ( alarm_frame )
|
||||||
{
|
{
|
||||||
return( Event::getSubPath( localtime( time ) ) );
|
pre_alarm_data[pre_alarm_count].alarm_frame = new Image( *alarm_frame );
|
||||||
}
|
}
|
||||||
|
pre_alarm_count++;
|
||||||
public:
|
}
|
||||||
static int PreAlarmCount()
|
void SavePreAlarmFrames()
|
||||||
{
|
{
|
||||||
return( pre_alarm_count );
|
for ( int i = 0; i < pre_alarm_count; i++ )
|
||||||
}
|
{
|
||||||
static void EmptyPreAlarmFrames()
|
AddFrame( pre_alarm_data[i].image, pre_alarm_data[i].timestamp, pre_alarm_data[i].score, pre_alarm_data[i].alarm_frame );
|
||||||
{
|
}
|
||||||
if ( pre_alarm_count > 0 )
|
EmptyPreAlarmFrames();
|
||||||
{
|
}
|
||||||
for ( int i = 0; i < MAX_PRE_ALARM_FRAMES; i++ )
|
|
||||||
{
|
|
||||||
delete pre_alarm_data[i].image;
|
|
||||||
delete pre_alarm_data[i].alarm_frame;
|
|
||||||
}
|
|
||||||
memset( pre_alarm_data, 0, sizeof(pre_alarm_data) );
|
|
||||||
}
|
|
||||||
pre_alarm_count = 0;
|
|
||||||
}
|
|
||||||
static void AddPreAlarmFrame( Image *image, struct timeval timestamp, int score=0, Image *alarm_frame=NULL )
|
|
||||||
{
|
|
||||||
pre_alarm_data[pre_alarm_count].image = new Image( *image );
|
|
||||||
pre_alarm_data[pre_alarm_count].timestamp = timestamp;
|
|
||||||
pre_alarm_data[pre_alarm_count].score = score;
|
|
||||||
if ( alarm_frame )
|
|
||||||
{
|
|
||||||
pre_alarm_data[pre_alarm_count].alarm_frame = new Image( *alarm_frame );
|
|
||||||
}
|
|
||||||
pre_alarm_count++;
|
|
||||||
}
|
|
||||||
void SavePreAlarmFrames()
|
|
||||||
{
|
|
||||||
for ( int i = 0; i < pre_alarm_count; i++ )
|
|
||||||
{
|
|
||||||
AddFrame( pre_alarm_data[i].image, pre_alarm_data[i].timestamp, pre_alarm_data[i].score, pre_alarm_data[i].alarm_frame );
|
|
||||||
}
|
|
||||||
EmptyPreAlarmFrames();
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class EventStream : public StreamBase
|
class EventStream : public StreamBase
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
struct FrameData {
|
struct FrameData {
|
||||||
//unsigned long id;
|
//unsigned long id;
|
||||||
time_t timestamp;
|
time_t timestamp;
|
||||||
time_t offset;
|
time_t offset;
|
||||||
double delta;
|
double delta;
|
||||||
bool in_db;
|
bool in_db;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct EventData
|
struct EventData
|
||||||
{
|
{
|
||||||
unsigned long event_id;
|
unsigned long event_id;
|
||||||
unsigned long monitor_id;
|
unsigned long monitor_id;
|
||||||
unsigned long frame_count;
|
unsigned long frame_count;
|
||||||
time_t start_time;
|
time_t start_time;
|
||||||
double duration;
|
double duration;
|
||||||
char path[PATH_MAX];
|
char path[PATH_MAX];
|
||||||
int n_frames;
|
int n_frames;
|
||||||
FrameData *frames;
|
FrameData *frames;
|
||||||
};
|
};
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
static const int STREAM_PAUSE_WAIT = 250000; // Microseconds
|
static const int STREAM_PAUSE_WAIT = 250000; // Microseconds
|
||||||
|
|
||||||
static const StreamMode DEFAULT_MODE = SINGLE;
|
static const StreamMode DEFAULT_MODE = SINGLE;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
StreamMode mode;
|
StreamMode mode;
|
||||||
bool forceEventChange;
|
bool forceEventChange;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
int curr_frame_id;
|
int curr_frame_id;
|
||||||
double curr_stream_time;
|
double curr_stream_time;
|
||||||
|
|
||||||
EventData *event_data;
|
EventData *event_data;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool loadEventData( int event_id );
|
bool loadEventData( int event_id );
|
||||||
bool loadInitialEventData( int init_event_id, int init_frame_id );
|
bool loadInitialEventData( int init_event_id, int init_frame_id );
|
||||||
bool loadInitialEventData( int monitor_id, time_t event_time );
|
bool loadInitialEventData( int monitor_id, time_t event_time );
|
||||||
|
@ -236,31 +236,31 @@ protected:
|
||||||
void processCommand( const CmdMsg *msg );
|
void processCommand( const CmdMsg *msg );
|
||||||
bool sendFrame( int delta_us );
|
bool sendFrame( int delta_us );
|
||||||
|
|
||||||
public:
|
public:
|
||||||
EventStream()
|
EventStream()
|
||||||
{
|
{
|
||||||
mode = DEFAULT_MODE;
|
mode = DEFAULT_MODE;
|
||||||
|
|
||||||
forceEventChange = false;
|
forceEventChange = false;
|
||||||
|
|
||||||
curr_frame_id = 0;
|
curr_frame_id = 0;
|
||||||
curr_stream_time = 0.0;
|
curr_stream_time = 0.0;
|
||||||
|
|
||||||
event_data = 0;
|
event_data = 0;
|
||||||
}
|
}
|
||||||
void setStreamStart( int init_event_id, int init_frame_id=0 )
|
void setStreamStart( int init_event_id, int init_frame_id=0 )
|
||||||
{
|
{
|
||||||
loadInitialEventData( init_event_id, init_frame_id );
|
loadInitialEventData( init_event_id, init_frame_id );
|
||||||
loadMonitor( event_data->monitor_id );
|
loadMonitor( event_data->monitor_id );
|
||||||
}
|
}
|
||||||
void setStreamStart( int monitor_id, time_t event_time )
|
void setStreamStart( int monitor_id, time_t event_time )
|
||||||
{
|
{
|
||||||
loadInitialEventData( monitor_id, event_time );
|
loadInitialEventData( monitor_id, event_time );
|
||||||
loadMonitor( monitor_id );
|
loadMonitor( monitor_id );
|
||||||
}
|
}
|
||||||
void setStreamMode( StreamMode p_mode )
|
void setStreamMode( StreamMode p_mode )
|
||||||
{
|
{
|
||||||
mode = p_mode;
|
mode = p_mode;
|
||||||
}
|
}
|
||||||
void runStream();
|
void runStream();
|
||||||
};
|
};
|
||||||
|
|
7148
src/zm_monitor.cpp
7148
src/zm_monitor.cpp
File diff suppressed because it is too large
Load Diff
|
@ -28,299 +28,299 @@
|
||||||
StreamBase::~StreamBase()
|
StreamBase::~StreamBase()
|
||||||
{
|
{
|
||||||
#if HAVE_LIBAVCODEC
|
#if HAVE_LIBAVCODEC
|
||||||
if ( vid_stream )
|
if ( vid_stream )
|
||||||
{
|
{
|
||||||
delete vid_stream;
|
delete vid_stream;
|
||||||
vid_stream = NULL;
|
vid_stream = NULL;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
closeComms();
|
closeComms();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool StreamBase::loadMonitor( int monitor_id )
|
bool StreamBase::loadMonitor( int monitor_id )
|
||||||
{
|
{
|
||||||
if ( !(monitor = Monitor::Load( monitor_id, false, Monitor::QUERY )) )
|
if ( !(monitor = Monitor::Load( monitor_id, false, Monitor::QUERY )) )
|
||||||
{
|
{
|
||||||
Fatal( "Unable to load monitor id %d for streaming", monitor_id );
|
Fatal( "Unable to load monitor id %d for streaming", monitor_id );
|
||||||
return( false );
|
return( false );
|
||||||
}
|
}
|
||||||
monitor->connect();
|
monitor->connect();
|
||||||
return( true );
|
return( true );
|
||||||
}
|
}
|
||||||
|
|
||||||
bool StreamBase::checkInitialised()
|
bool StreamBase::checkInitialised()
|
||||||
{
|
{
|
||||||
if ( !monitor )
|
if ( !monitor )
|
||||||
{
|
{
|
||||||
Fatal( "Cannot stream, not initialised" );
|
Fatal( "Cannot stream, not initialised" );
|
||||||
return( false );
|
return( false );
|
||||||
}
|
}
|
||||||
return( true );
|
return( true );
|
||||||
}
|
}
|
||||||
|
|
||||||
void StreamBase::updateFrameRate( double fps )
|
void StreamBase::updateFrameRate( double fps )
|
||||||
{
|
{
|
||||||
base_fps = fps;
|
base_fps = fps;
|
||||||
effective_fps = (base_fps*abs(replay_rate))/ZM_RATE_BASE;
|
effective_fps = (base_fps*abs(replay_rate))/ZM_RATE_BASE;
|
||||||
frame_mod = 1;
|
frame_mod = 1;
|
||||||
Debug( 3, "FPS:%.2f, MXFPS:%.2f, BFPS:%.2f, EFPS:%.2f, FM:%d", fps, maxfps, base_fps, effective_fps, frame_mod );
|
Debug( 3, "FPS:%.2f, MXFPS:%.2f, BFPS:%.2f, EFPS:%.2f, FM:%d", fps, maxfps, base_fps, effective_fps, frame_mod );
|
||||||
// Min frame repeat?
|
// Min frame repeat?
|
||||||
while( effective_fps > maxfps )
|
while( effective_fps > maxfps )
|
||||||
{
|
{
|
||||||
effective_fps /= 2.0;
|
effective_fps /= 2.0;
|
||||||
frame_mod *= 2;
|
frame_mod *= 2;
|
||||||
}
|
}
|
||||||
Debug( 3, "aEFPS:%.2f, aFM:%d", effective_fps, frame_mod );
|
Debug( 3, "aEFPS:%.2f, aFM:%d", effective_fps, frame_mod );
|
||||||
}
|
}
|
||||||
|
|
||||||
bool StreamBase::checkCommandQueue()
|
bool StreamBase::checkCommandQueue()
|
||||||
{
|
{
|
||||||
if ( sd >= 0 )
|
if ( sd >= 0 )
|
||||||
|
{
|
||||||
|
CmdMsg msg;
|
||||||
|
memset( &msg, 0, sizeof(msg) );
|
||||||
|
int nbytes = recvfrom( sd, &msg, sizeof(msg), MSG_DONTWAIT, 0, 0 );
|
||||||
|
if ( nbytes < 0 )
|
||||||
{
|
{
|
||||||
CmdMsg msg;
|
if ( errno != EAGAIN )
|
||||||
memset( &msg, 0, sizeof(msg) );
|
{
|
||||||
int nbytes = recvfrom( sd, &msg, sizeof(msg), MSG_DONTWAIT, 0, 0 );
|
Fatal( "recvfrom(), errno = %d, error = %s", errno, strerror(errno) );
|
||||||
if ( nbytes < 0 )
|
}
|
||||||
{
|
|
||||||
if ( errno != EAGAIN )
|
|
||||||
{
|
|
||||||
Fatal( "recvfrom(), errno = %d, error = %s", errno, strerror(errno) );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//else if ( (nbytes != sizeof(msg)) )
|
|
||||||
//{
|
|
||||||
//Error( "Partial message received, expected %d bytes, got %d", sizeof(msg), nbytes );
|
|
||||||
//}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
processCommand( &msg );
|
|
||||||
return( true );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return( false );
|
//else if ( (nbytes != sizeof(msg)) )
|
||||||
|
//{
|
||||||
|
//Error( "Partial message received, expected %d bytes, got %d", sizeof(msg), nbytes );
|
||||||
|
//}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
processCommand( &msg );
|
||||||
|
return( true );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return( false );
|
||||||
}
|
}
|
||||||
|
|
||||||
Image *StreamBase::prepareImage( Image *image )
|
Image *StreamBase::prepareImage( Image *image )
|
||||||
{
|
{
|
||||||
static int last_scale = 0;
|
static int last_scale = 0;
|
||||||
static int last_zoom = 0;
|
static int last_zoom = 0;
|
||||||
static int last_x = 0;
|
static int last_x = 0;
|
||||||
static int last_y = 0;
|
static int last_y = 0;
|
||||||
|
|
||||||
if ( !last_scale )
|
if ( !last_scale )
|
||||||
last_scale = scale;
|
|
||||||
if ( !last_zoom )
|
|
||||||
last_zoom = zoom;
|
|
||||||
|
|
||||||
// Do not bother to scale zoomed in images, just crop them and let the browser scale
|
|
||||||
// Works in FF2 but breaks FF3 which doesn't like image sizes changing in mid stream.
|
|
||||||
bool optimisedScaling = false;
|
|
||||||
|
|
||||||
bool image_copied = false;
|
|
||||||
|
|
||||||
int mag = (scale * zoom) / ZM_SCALE_BASE;
|
|
||||||
int act_mag = optimisedScaling?(mag > ZM_SCALE_BASE?ZM_SCALE_BASE:mag):mag;
|
|
||||||
Debug( 3, "Scaling by %d, zooming by %d = magnifying by %d(%d)", scale, zoom, mag, act_mag );
|
|
||||||
|
|
||||||
int last_mag = (last_scale * last_zoom) / ZM_SCALE_BASE;
|
|
||||||
int last_act_mag = last_mag > ZM_SCALE_BASE?ZM_SCALE_BASE:last_mag;
|
|
||||||
Debug( 3, "Last scaling by %d, zooming by %d = magnifying by %d(%d)", last_scale, last_zoom, last_mag, last_act_mag );
|
|
||||||
|
|
||||||
int base_image_width = image->Width(), base_image_height = image->Height();
|
|
||||||
Debug( 3, "Base image width = %d, height = %d", base_image_width, base_image_height );
|
|
||||||
|
|
||||||
int virt_image_width = (base_image_width * mag) / ZM_SCALE_BASE, virt_image_height = (base_image_height * mag) / ZM_SCALE_BASE;
|
|
||||||
Debug( 3, "Virtual image width = %d, height = %d", virt_image_width, virt_image_height );
|
|
||||||
|
|
||||||
int last_virt_image_width = (base_image_width * last_mag) / ZM_SCALE_BASE, last_virt_image_height = (base_image_height * last_mag) / ZM_SCALE_BASE;
|
|
||||||
Debug( 3, "Last virtual image width = %d, height = %d", last_virt_image_width, last_virt_image_height );
|
|
||||||
|
|
||||||
int act_image_width = (base_image_width * act_mag ) / ZM_SCALE_BASE, act_image_height = (base_image_height * act_mag ) / ZM_SCALE_BASE;
|
|
||||||
Debug( 3, "Actual image width = %d, height = %d", act_image_width, act_image_height );
|
|
||||||
|
|
||||||
int last_act_image_width = (base_image_width * last_act_mag ) / ZM_SCALE_BASE, last_act_image_height = (base_image_height * last_act_mag ) / ZM_SCALE_BASE;
|
|
||||||
Debug( 3, "Last actual image width = %d, height = %d", last_act_image_width, last_act_image_height );
|
|
||||||
|
|
||||||
int disp_image_width = (image->Width() * scale) / ZM_SCALE_BASE, disp_image_height = (image->Height() * scale) / ZM_SCALE_BASE;
|
|
||||||
Debug( 3, "Display image width = %d, height = %d", disp_image_width, disp_image_height );
|
|
||||||
|
|
||||||
int last_disp_image_width = (image->Width() * last_scale) / ZM_SCALE_BASE, last_disp_image_height = (image->Height() * last_scale) / ZM_SCALE_BASE;
|
|
||||||
Debug( 3, "Last display image width = %d, height = %d", last_disp_image_width, last_disp_image_height );
|
|
||||||
|
|
||||||
int send_image_width = (disp_image_width * act_mag ) / mag, send_image_height = (disp_image_height * act_mag ) / mag;
|
|
||||||
Debug( 3, "Send image width = %d, height = %d", send_image_width, send_image_height );
|
|
||||||
|
|
||||||
int last_send_image_width = (last_disp_image_width * last_act_mag ) / last_mag, last_send_image_height = (last_disp_image_height * last_act_mag ) / last_mag;
|
|
||||||
Debug( 3, "Last send image width = %d, height = %d", last_send_image_width, last_send_image_height );
|
|
||||||
|
|
||||||
if ( mag != ZM_SCALE_BASE )
|
|
||||||
{
|
|
||||||
if ( act_mag != ZM_SCALE_BASE )
|
|
||||||
{
|
|
||||||
Debug( 3, "Magnifying by %d", mag );
|
|
||||||
if ( !image_copied )
|
|
||||||
{
|
|
||||||
static Image copy_image;
|
|
||||||
copy_image.Assign( *image );
|
|
||||||
image = ©_image;
|
|
||||||
image_copied = true;
|
|
||||||
}
|
|
||||||
image->Scale( mag );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Debug( 3, "Real image width = %d, height = %d", image->Width(), image->Height() );
|
|
||||||
|
|
||||||
if ( disp_image_width < virt_image_width || disp_image_height < virt_image_height )
|
|
||||||
{
|
|
||||||
static Box last_crop;
|
|
||||||
|
|
||||||
if ( mag != last_mag || x != last_x || y != last_y )
|
|
||||||
{
|
|
||||||
Debug( 3, "Got click at %d,%d x %d", x, y, mag );
|
|
||||||
|
|
||||||
//if ( !last_mag )
|
|
||||||
//last_mag = mag;
|
|
||||||
|
|
||||||
if ( !(last_disp_image_width < last_virt_image_width || last_disp_image_height < last_virt_image_height) )
|
|
||||||
last_crop = Box();
|
|
||||||
|
|
||||||
Debug( 3, "Recalculating crop" );
|
|
||||||
// Recalculate crop parameters, as %ges
|
|
||||||
int click_x = (last_crop.LoX() * 100 ) / last_act_image_width; // Initial crop offset from last image
|
|
||||||
click_x += ( x * 100 ) / last_virt_image_width;
|
|
||||||
int click_y = (last_crop.LoY() * 100 ) / last_act_image_height; // Initial crop offset from last image
|
|
||||||
click_y += ( y * 100 ) / last_virt_image_height;
|
|
||||||
Debug( 3, "Got adjusted click at %d%%,%d%%", click_x, click_y );
|
|
||||||
|
|
||||||
// Convert the click locations to the current image pixels
|
|
||||||
click_x = ( click_x * act_image_width ) / 100;
|
|
||||||
click_y = ( click_y * act_image_height ) / 100;
|
|
||||||
Debug( 3, "Got readjusted click at %d,%d", click_x, click_y );
|
|
||||||
|
|
||||||
int lo_x = click_x - (send_image_width/2);
|
|
||||||
if ( lo_x < 0 )
|
|
||||||
lo_x = 0;
|
|
||||||
int hi_x = lo_x + (send_image_width-1);
|
|
||||||
if ( hi_x >= act_image_width )
|
|
||||||
{
|
|
||||||
hi_x = act_image_width - 1;
|
|
||||||
lo_x = hi_x - (send_image_width - 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
int lo_y = click_y - (send_image_height/2);
|
|
||||||
if ( lo_y < 0 )
|
|
||||||
lo_y = 0;
|
|
||||||
int hi_y = lo_y + (send_image_height-1);
|
|
||||||
if ( hi_y >= act_image_height )
|
|
||||||
{
|
|
||||||
hi_y = act_image_height - 1;
|
|
||||||
lo_y = hi_y - (send_image_height - 1);
|
|
||||||
}
|
|
||||||
last_crop = Box( lo_x, lo_y, hi_x, hi_y );
|
|
||||||
}
|
|
||||||
Debug( 3, "Cropping to %d,%d -> %d,%d", last_crop.LoX(), last_crop.LoY(), last_crop.HiX(), last_crop.HiY() );
|
|
||||||
if ( !image_copied )
|
|
||||||
{
|
|
||||||
static Image copy_image;
|
|
||||||
copy_image.Assign( *image );
|
|
||||||
image = ©_image;
|
|
||||||
image_copied = true;
|
|
||||||
}
|
|
||||||
image->Crop( last_crop );
|
|
||||||
}
|
|
||||||
last_scale = scale;
|
last_scale = scale;
|
||||||
|
if ( !last_zoom )
|
||||||
last_zoom = zoom;
|
last_zoom = zoom;
|
||||||
last_x = x;
|
|
||||||
last_y = y;
|
|
||||||
|
|
||||||
return( image );
|
// Do not bother to scale zoomed in images, just crop them and let the browser scale
|
||||||
|
// Works in FF2 but breaks FF3 which doesn't like image sizes changing in mid stream.
|
||||||
|
bool optimisedScaling = false;
|
||||||
|
|
||||||
|
bool image_copied = false;
|
||||||
|
|
||||||
|
int mag = (scale * zoom) / ZM_SCALE_BASE;
|
||||||
|
int act_mag = optimisedScaling?(mag > ZM_SCALE_BASE?ZM_SCALE_BASE:mag):mag;
|
||||||
|
Debug( 3, "Scaling by %d, zooming by %d = magnifying by %d(%d)", scale, zoom, mag, act_mag );
|
||||||
|
|
||||||
|
int last_mag = (last_scale * last_zoom) / ZM_SCALE_BASE;
|
||||||
|
int last_act_mag = last_mag > ZM_SCALE_BASE?ZM_SCALE_BASE:last_mag;
|
||||||
|
Debug( 3, "Last scaling by %d, zooming by %d = magnifying by %d(%d)", last_scale, last_zoom, last_mag, last_act_mag );
|
||||||
|
|
||||||
|
int base_image_width = image->Width(), base_image_height = image->Height();
|
||||||
|
Debug( 3, "Base image width = %d, height = %d", base_image_width, base_image_height );
|
||||||
|
|
||||||
|
int virt_image_width = (base_image_width * mag) / ZM_SCALE_BASE, virt_image_height = (base_image_height * mag) / ZM_SCALE_BASE;
|
||||||
|
Debug( 3, "Virtual image width = %d, height = %d", virt_image_width, virt_image_height );
|
||||||
|
|
||||||
|
int last_virt_image_width = (base_image_width * last_mag) / ZM_SCALE_BASE, last_virt_image_height = (base_image_height * last_mag) / ZM_SCALE_BASE;
|
||||||
|
Debug( 3, "Last virtual image width = %d, height = %d", last_virt_image_width, last_virt_image_height );
|
||||||
|
|
||||||
|
int act_image_width = (base_image_width * act_mag ) / ZM_SCALE_BASE, act_image_height = (base_image_height * act_mag ) / ZM_SCALE_BASE;
|
||||||
|
Debug( 3, "Actual image width = %d, height = %d", act_image_width, act_image_height );
|
||||||
|
|
||||||
|
int last_act_image_width = (base_image_width * last_act_mag ) / ZM_SCALE_BASE, last_act_image_height = (base_image_height * last_act_mag ) / ZM_SCALE_BASE;
|
||||||
|
Debug( 3, "Last actual image width = %d, height = %d", last_act_image_width, last_act_image_height );
|
||||||
|
|
||||||
|
int disp_image_width = (image->Width() * scale) / ZM_SCALE_BASE, disp_image_height = (image->Height() * scale) / ZM_SCALE_BASE;
|
||||||
|
Debug( 3, "Display image width = %d, height = %d", disp_image_width, disp_image_height );
|
||||||
|
|
||||||
|
int last_disp_image_width = (image->Width() * last_scale) / ZM_SCALE_BASE, last_disp_image_height = (image->Height() * last_scale) / ZM_SCALE_BASE;
|
||||||
|
Debug( 3, "Last display image width = %d, height = %d", last_disp_image_width, last_disp_image_height );
|
||||||
|
|
||||||
|
int send_image_width = (disp_image_width * act_mag ) / mag, send_image_height = (disp_image_height * act_mag ) / mag;
|
||||||
|
Debug( 3, "Send image width = %d, height = %d", send_image_width, send_image_height );
|
||||||
|
|
||||||
|
int last_send_image_width = (last_disp_image_width * last_act_mag ) / last_mag, last_send_image_height = (last_disp_image_height * last_act_mag ) / last_mag;
|
||||||
|
Debug( 3, "Last send image width = %d, height = %d", last_send_image_width, last_send_image_height );
|
||||||
|
|
||||||
|
if ( mag != ZM_SCALE_BASE )
|
||||||
|
{
|
||||||
|
if ( act_mag != ZM_SCALE_BASE )
|
||||||
|
{
|
||||||
|
Debug( 3, "Magnifying by %d", mag );
|
||||||
|
if ( !image_copied )
|
||||||
|
{
|
||||||
|
static Image copy_image;
|
||||||
|
copy_image.Assign( *image );
|
||||||
|
image = ©_image;
|
||||||
|
image_copied = true;
|
||||||
|
}
|
||||||
|
image->Scale( mag );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Debug( 3, "Real image width = %d, height = %d", image->Width(), image->Height() );
|
||||||
|
|
||||||
|
if ( disp_image_width < virt_image_width || disp_image_height < virt_image_height )
|
||||||
|
{
|
||||||
|
static Box last_crop;
|
||||||
|
|
||||||
|
if ( mag != last_mag || x != last_x || y != last_y )
|
||||||
|
{
|
||||||
|
Debug( 3, "Got click at %d,%d x %d", x, y, mag );
|
||||||
|
|
||||||
|
//if ( !last_mag )
|
||||||
|
//last_mag = mag;
|
||||||
|
|
||||||
|
if ( !(last_disp_image_width < last_virt_image_width || last_disp_image_height < last_virt_image_height) )
|
||||||
|
last_crop = Box();
|
||||||
|
|
||||||
|
Debug( 3, "Recalculating crop" );
|
||||||
|
// Recalculate crop parameters, as %ges
|
||||||
|
int click_x = (last_crop.LoX() * 100 ) / last_act_image_width; // Initial crop offset from last image
|
||||||
|
click_x += ( x * 100 ) / last_virt_image_width;
|
||||||
|
int click_y = (last_crop.LoY() * 100 ) / last_act_image_height; // Initial crop offset from last image
|
||||||
|
click_y += ( y * 100 ) / last_virt_image_height;
|
||||||
|
Debug( 3, "Got adjusted click at %d%%,%d%%", click_x, click_y );
|
||||||
|
|
||||||
|
// Convert the click locations to the current image pixels
|
||||||
|
click_x = ( click_x * act_image_width ) / 100;
|
||||||
|
click_y = ( click_y * act_image_height ) / 100;
|
||||||
|
Debug( 3, "Got readjusted click at %d,%d", click_x, click_y );
|
||||||
|
|
||||||
|
int lo_x = click_x - (send_image_width/2);
|
||||||
|
if ( lo_x < 0 )
|
||||||
|
lo_x = 0;
|
||||||
|
int hi_x = lo_x + (send_image_width-1);
|
||||||
|
if ( hi_x >= act_image_width )
|
||||||
|
{
|
||||||
|
hi_x = act_image_width - 1;
|
||||||
|
lo_x = hi_x - (send_image_width - 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
int lo_y = click_y - (send_image_height/2);
|
||||||
|
if ( lo_y < 0 )
|
||||||
|
lo_y = 0;
|
||||||
|
int hi_y = lo_y + (send_image_height-1);
|
||||||
|
if ( hi_y >= act_image_height )
|
||||||
|
{
|
||||||
|
hi_y = act_image_height - 1;
|
||||||
|
lo_y = hi_y - (send_image_height - 1);
|
||||||
|
}
|
||||||
|
last_crop = Box( lo_x, lo_y, hi_x, hi_y );
|
||||||
|
}
|
||||||
|
Debug( 3, "Cropping to %d,%d -> %d,%d", last_crop.LoX(), last_crop.LoY(), last_crop.HiX(), last_crop.HiY() );
|
||||||
|
if ( !image_copied )
|
||||||
|
{
|
||||||
|
static Image copy_image;
|
||||||
|
copy_image.Assign( *image );
|
||||||
|
image = ©_image;
|
||||||
|
image_copied = true;
|
||||||
|
}
|
||||||
|
image->Crop( last_crop );
|
||||||
|
}
|
||||||
|
last_scale = scale;
|
||||||
|
last_zoom = zoom;
|
||||||
|
last_x = x;
|
||||||
|
last_y = y;
|
||||||
|
|
||||||
|
return( image );
|
||||||
}
|
}
|
||||||
|
|
||||||
bool StreamBase::sendTextFrame( const char *frame_text )
|
bool StreamBase::sendTextFrame( const char *frame_text )
|
||||||
{
|
{
|
||||||
Debug( 2, "Sending text frame '%s'", frame_text );
|
Debug( 2, "Sending text frame '%s'", frame_text );
|
||||||
|
|
||||||
Image image( monitor->Width(), monitor->Height(), monitor->Colours(), monitor->SubpixelOrder() );
|
Image image( monitor->Width(), monitor->Height(), monitor->Colours(), monitor->SubpixelOrder() );
|
||||||
image.Annotate( frame_text, image.centreCoord( frame_text ) );
|
image.Annotate( frame_text, image.centreCoord( frame_text ) );
|
||||||
|
|
||||||
if ( scale != 100 )
|
if ( scale != 100 )
|
||||||
{
|
{
|
||||||
image.Scale( scale );
|
image.Scale( scale );
|
||||||
}
|
}
|
||||||
#if HAVE_LIBAVCODEC
|
#if HAVE_LIBAVCODEC
|
||||||
if ( type == MPEG )
|
if ( type == MPEG )
|
||||||
|
{
|
||||||
|
if ( !vid_stream )
|
||||||
{
|
{
|
||||||
if ( !vid_stream )
|
vid_stream = new VideoStream( "pipe:", format, bitrate, effective_fps, image.Colours(), image.SubpixelOrder(), image.Width(), image.Height() );
|
||||||
{
|
fprintf( stdout, "Content-type: %s\r\n\r\n", vid_stream->MimeType() );
|
||||||
vid_stream = new VideoStream( "pipe:", format, bitrate, effective_fps, image.Colours(), image.SubpixelOrder(), image.Width(), image.Height() );
|
vid_stream->OpenStream();
|
||||||
fprintf( stdout, "Content-type: %s\r\n\r\n", vid_stream->MimeType() );
|
|
||||||
vid_stream->OpenStream();
|
|
||||||
}
|
|
||||||
/* double pts = */ vid_stream->EncodeFrame( image.Buffer(), image.Size() );
|
|
||||||
}
|
}
|
||||||
else
|
/* double pts = */ vid_stream->EncodeFrame( image.Buffer(), image.Size() );
|
||||||
|
}
|
||||||
|
else
|
||||||
#endif // HAVE_LIBAVCODEC
|
#endif // HAVE_LIBAVCODEC
|
||||||
|
{
|
||||||
|
static unsigned char buffer[ZM_MAX_IMAGE_SIZE];
|
||||||
|
int n_bytes = 0;
|
||||||
|
|
||||||
|
image.EncodeJpeg( buffer, &n_bytes );
|
||||||
|
|
||||||
|
fprintf( stdout, "--ZoneMinderFrame\r\n" );
|
||||||
|
fprintf( stdout, "Content-Length: %d\r\n", n_bytes );
|
||||||
|
fprintf( stdout, "Content-Type: image/jpeg\r\n\r\n" );
|
||||||
|
if ( fwrite( buffer, n_bytes, 1, stdout ) != 1 )
|
||||||
{
|
{
|
||||||
static unsigned char buffer[ZM_MAX_IMAGE_SIZE];
|
Error( "Unable to send stream text frame: %s", strerror(errno) );
|
||||||
int n_bytes = 0;
|
return( false );
|
||||||
|
|
||||||
image.EncodeJpeg( buffer, &n_bytes );
|
|
||||||
|
|
||||||
fprintf( stdout, "--ZoneMinderFrame\r\n" );
|
|
||||||
fprintf( stdout, "Content-Length: %d\r\n", n_bytes );
|
|
||||||
fprintf( stdout, "Content-Type: image/jpeg\r\n\r\n" );
|
|
||||||
if ( fwrite( buffer, n_bytes, 1, stdout ) != 1 )
|
|
||||||
{
|
|
||||||
Error( "Unable to send stream text frame: %s", strerror(errno) );
|
|
||||||
return( false );
|
|
||||||
}
|
|
||||||
fprintf( stdout, "\r\n\r\n" );
|
|
||||||
fflush( stdout );
|
|
||||||
}
|
}
|
||||||
last_frame_sent = TV_2_FLOAT( now );
|
fprintf( stdout, "\r\n\r\n" );
|
||||||
return( true );
|
fflush( stdout );
|
||||||
|
}
|
||||||
|
last_frame_sent = TV_2_FLOAT( now );
|
||||||
|
return( true );
|
||||||
}
|
}
|
||||||
|
|
||||||
void StreamBase::openComms()
|
void StreamBase::openComms()
|
||||||
{
|
{
|
||||||
if ( connkey > 0 )
|
if ( connkey > 0 )
|
||||||
|
{
|
||||||
|
sd = socket( AF_UNIX, SOCK_DGRAM, 0 );
|
||||||
|
if ( sd < 0 )
|
||||||
{
|
{
|
||||||
sd = socket( AF_UNIX, SOCK_DGRAM, 0 );
|
Fatal( "Can't create socket: %s", strerror(errno) );
|
||||||
if ( sd < 0 )
|
|
||||||
{
|
|
||||||
Fatal( "Can't create socket: %s", strerror(errno) );
|
|
||||||
}
|
|
||||||
|
|
||||||
snprintf( loc_sock_path, sizeof(loc_sock_path), "%s/zms-%06ds.sock", config.path_socks, connkey );
|
|
||||||
unlink( loc_sock_path );
|
|
||||||
|
|
||||||
strncpy( loc_addr.sun_path, loc_sock_path, sizeof(loc_addr.sun_path) );
|
|
||||||
loc_addr.sun_family = AF_UNIX;
|
|
||||||
if ( bind( sd, (struct sockaddr *)&loc_addr, strlen(loc_addr.sun_path)+sizeof(loc_addr.sun_family)) < 0 )
|
|
||||||
{
|
|
||||||
Fatal( "Can't bind: %s", strerror(errno) );
|
|
||||||
}
|
|
||||||
|
|
||||||
snprintf( rem_sock_path, sizeof(rem_sock_path), "%s/zms-%06dw.sock", config.path_socks, connkey );
|
|
||||||
strncpy( rem_addr.sun_path, rem_sock_path, sizeof(rem_addr.sun_path) );
|
|
||||||
rem_addr.sun_family = AF_UNIX;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
snprintf( loc_sock_path, sizeof(loc_sock_path), "%s/zms-%06ds.sock", config.path_socks, connkey );
|
||||||
|
unlink( loc_sock_path );
|
||||||
|
|
||||||
|
strncpy( loc_addr.sun_path, loc_sock_path, sizeof(loc_addr.sun_path) );
|
||||||
|
loc_addr.sun_family = AF_UNIX;
|
||||||
|
if ( bind( sd, (struct sockaddr *)&loc_addr, strlen(loc_addr.sun_path)+sizeof(loc_addr.sun_family)) < 0 )
|
||||||
|
{
|
||||||
|
Fatal( "Can't bind: %s", strerror(errno) );
|
||||||
|
}
|
||||||
|
|
||||||
|
snprintf( rem_sock_path, sizeof(rem_sock_path), "%s/zms-%06dw.sock", config.path_socks, connkey );
|
||||||
|
strncpy( rem_addr.sun_path, rem_sock_path, sizeof(rem_addr.sun_path) );
|
||||||
|
rem_addr.sun_family = AF_UNIX;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void StreamBase::closeComms()
|
void StreamBase::closeComms()
|
||||||
{
|
{
|
||||||
if ( connkey > 0 )
|
if ( connkey > 0 )
|
||||||
|
{
|
||||||
|
if ( sd >= 0 )
|
||||||
{
|
{
|
||||||
if ( sd >= 0 )
|
close( sd );
|
||||||
{
|
sd = -1;
|
||||||
close( sd );
|
|
||||||
sd = -1;
|
|
||||||
}
|
|
||||||
if ( loc_sock_path[0] )
|
|
||||||
{
|
|
||||||
unlink( loc_sock_path );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
if ( loc_sock_path[0] )
|
||||||
|
{
|
||||||
|
unlink( loc_sock_path );
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
110
src/zm_stream.h
110
src/zm_stream.h
|
@ -32,11 +32,11 @@ class Monitor;
|
||||||
|
|
||||||
class StreamBase
|
class StreamBase
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
typedef enum { JPEG, RAW, ZIP, MPEG } StreamType;
|
typedef enum { JPEG, RAW, ZIP, MPEG } StreamType;
|
||||||
typedef enum { SINGLE, STREAM, ALL, ALL_GAPLESS } StreamMode;
|
typedef enum { SINGLE, STREAM, ALL, ALL_GAPLESS } StreamMode;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
static const int MAX_STREAM_DELAY = 5; // Seconds
|
static const int MAX_STREAM_DELAY = 5; // Seconds
|
||||||
|
|
||||||
static const StreamType DEFAULT_TYPE = JPEG;
|
static const StreamType DEFAULT_TYPE = JPEG;
|
||||||
|
@ -46,25 +46,25 @@ protected:
|
||||||
enum { DEFAULT_MAXFPS=10 };
|
enum { DEFAULT_MAXFPS=10 };
|
||||||
enum { DEFAULT_BITRATE=100000 };
|
enum { DEFAULT_BITRATE=100000 };
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int msg_type;
|
int msg_type;
|
||||||
char msg_data[16];
|
char msg_data[16];
|
||||||
} CmdMsg;
|
} CmdMsg;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int msg_type;
|
int msg_type;
|
||||||
char msg_data[256];
|
char msg_data[256];
|
||||||
} DataMsg;
|
} DataMsg;
|
||||||
|
|
||||||
typedef enum { MSG_CMD=1, MSG_DATA_WATCH, MSG_DATA_EVENT } MsgType;
|
typedef enum { MSG_CMD=1, MSG_DATA_WATCH, MSG_DATA_EVENT } MsgType;
|
||||||
typedef enum { CMD_NONE=0, CMD_PAUSE, CMD_PLAY, CMD_STOP, CMD_FASTFWD, CMD_SLOWFWD, CMD_SLOWREV, CMD_FASTREV, CMD_ZOOMIN, CMD_ZOOMOUT, CMD_PAN, CMD_SCALE, CMD_PREV, CMD_NEXT, CMD_SEEK, CMD_VARPLAY, CMD_GET_IMAGE, CMD_QUERY=99 } MsgCommand;
|
typedef enum { CMD_NONE=0, CMD_PAUSE, CMD_PLAY, CMD_STOP, CMD_FASTFWD, CMD_SLOWFWD, CMD_SLOWREV, CMD_FASTREV, CMD_ZOOMIN, CMD_ZOOMOUT, CMD_PAN, CMD_SCALE, CMD_PREV, CMD_NEXT, CMD_SEEK, CMD_VARPLAY, CMD_GET_IMAGE, CMD_QUERY=99 } MsgCommand;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
Monitor *monitor;
|
Monitor *monitor;
|
||||||
|
|
||||||
StreamType type;
|
StreamType type;
|
||||||
StreamMode mode;
|
StreamMode mode;
|
||||||
const char *format; // used to pass to ffmpeg libs
|
const char *format; // used to pass to ffmpeg libs
|
||||||
int replay_rate;
|
int replay_rate;
|
||||||
int scale;
|
int scale;
|
||||||
|
@ -73,15 +73,15 @@ protected:
|
||||||
int bitrate;
|
int bitrate;
|
||||||
unsigned short x, y;
|
unsigned short x, y;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
int connkey;
|
int connkey;
|
||||||
int sd;
|
int sd;
|
||||||
char loc_sock_path[PATH_MAX];
|
char loc_sock_path[PATH_MAX];
|
||||||
struct sockaddr_un loc_addr;
|
struct sockaddr_un loc_addr;
|
||||||
char rem_sock_path[PATH_MAX];
|
char rem_sock_path[PATH_MAX];
|
||||||
struct sockaddr_un rem_addr;
|
struct sockaddr_un rem_addr;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool paused;
|
bool paused;
|
||||||
int step;
|
int step;
|
||||||
|
|
||||||
|
@ -100,7 +100,7 @@ protected:
|
||||||
|
|
||||||
CmdMsg msg;
|
CmdMsg msg;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool loadMonitor( int monitor_id );
|
bool loadMonitor( int monitor_id );
|
||||||
bool checkInitialised();
|
bool checkInitialised();
|
||||||
void updateFrameRate( double fps );
|
void updateFrameRate( double fps );
|
||||||
|
@ -109,73 +109,73 @@ protected:
|
||||||
bool checkCommandQueue();
|
bool checkCommandQueue();
|
||||||
virtual void processCommand( const CmdMsg *msg )=0;
|
virtual void processCommand( const CmdMsg *msg )=0;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
StreamBase()
|
StreamBase()
|
||||||
{
|
{
|
||||||
monitor = 0;
|
monitor = 0;
|
||||||
|
|
||||||
type = DEFAULT_TYPE;
|
type = DEFAULT_TYPE;
|
||||||
mode = STREAM;
|
mode = STREAM;
|
||||||
format = "";
|
format = "";
|
||||||
replay_rate = DEFAULT_RATE;
|
replay_rate = DEFAULT_RATE;
|
||||||
scale = DEFAULT_SCALE;
|
scale = DEFAULT_SCALE;
|
||||||
zoom = DEFAULT_ZOOM;
|
zoom = DEFAULT_ZOOM;
|
||||||
maxfps = DEFAULT_MAXFPS;
|
maxfps = DEFAULT_MAXFPS;
|
||||||
bitrate = DEFAULT_BITRATE;
|
bitrate = DEFAULT_BITRATE;
|
||||||
|
|
||||||
paused = false;
|
paused = false;
|
||||||
step = 0;
|
step = 0;
|
||||||
x = 0;
|
x = 0;
|
||||||
y = 0;
|
y = 0;
|
||||||
|
|
||||||
connkey = 0;
|
connkey = 0;
|
||||||
sd = -1;
|
sd = -1;
|
||||||
memset( &loc_sock_path, 0, sizeof(loc_sock_path) );
|
memset( &loc_sock_path, 0, sizeof(loc_sock_path) );
|
||||||
memset( &loc_addr, 0, sizeof(loc_addr) );
|
memset( &loc_addr, 0, sizeof(loc_addr) );
|
||||||
memset( &rem_sock_path, 0, sizeof(rem_sock_path) );
|
memset( &rem_sock_path, 0, sizeof(rem_sock_path) );
|
||||||
memset( &rem_addr, 0, sizeof(rem_addr) );
|
memset( &rem_addr, 0, sizeof(rem_addr) );
|
||||||
|
|
||||||
base_fps = 0.0;
|
base_fps = 0.0;
|
||||||
effective_fps = 0.0;
|
effective_fps = 0.0;
|
||||||
frame_mod = 1;
|
frame_mod = 1;
|
||||||
|
|
||||||
#if HAVE_LIBAVCODEC
|
#if HAVE_LIBAVCODEC
|
||||||
vid_stream = 0;
|
vid_stream = 0;
|
||||||
#endif // HAVE_LIBAVCODEC
|
#endif // HAVE_LIBAVCODEC
|
||||||
}
|
}
|
||||||
virtual ~StreamBase();
|
virtual ~StreamBase();
|
||||||
|
|
||||||
void setStreamType( StreamType p_type )
|
void setStreamType( StreamType p_type )
|
||||||
{
|
{
|
||||||
type = p_type;
|
type = p_type;
|
||||||
}
|
}
|
||||||
void setStreamMode( StreamMode p_mode )
|
void setStreamMode( StreamMode p_mode )
|
||||||
{
|
{
|
||||||
mode = p_mode;
|
mode = p_mode;
|
||||||
}
|
}
|
||||||
void setStreamFormat( const char *p_format )
|
void setStreamFormat( const char *p_format )
|
||||||
{
|
{
|
||||||
format = p_format;
|
format = p_format;
|
||||||
}
|
}
|
||||||
void setStreamScale( int p_scale )
|
void setStreamScale( int p_scale )
|
||||||
{
|
{
|
||||||
scale = p_scale;
|
scale = p_scale;
|
||||||
}
|
}
|
||||||
void setStreamReplayRate( int p_rate )
|
void setStreamReplayRate( int p_rate )
|
||||||
{
|
{
|
||||||
replay_rate = p_rate;
|
replay_rate = p_rate;
|
||||||
}
|
}
|
||||||
void setStreamMaxFPS( double p_maxfps )
|
void setStreamMaxFPS( double p_maxfps )
|
||||||
{
|
{
|
||||||
maxfps = p_maxfps;
|
maxfps = p_maxfps;
|
||||||
}
|
}
|
||||||
void setStreamBitrate( int p_bitrate )
|
void setStreamBitrate( int p_bitrate )
|
||||||
{
|
{
|
||||||
bitrate = p_bitrate;
|
bitrate = p_bitrate;
|
||||||
}
|
}
|
||||||
void setStreamQueue( int p_connkey )
|
void setStreamQueue( int p_connkey )
|
||||||
{
|
{
|
||||||
connkey = p_connkey;
|
connkey = p_connkey;
|
||||||
}
|
}
|
||||||
virtual void openComms();
|
virtual void openComms();
|
||||||
virtual void closeComms();
|
virtual void closeComms();
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
Subproject commit e22c1563a51d86aac0d5054beee28b4afb60c802
|
Subproject commit c3976f1478c681b0bbc132ec3a3e82c3984eeed5
|
Loading…
Reference in New Issue