提交 b59d87d9 authored 作者: blu's avatar blu

evcamera: video quality adjustment and fix video glich

上级 a2ff0344
...@@ -195,10 +195,10 @@ REQUEST_VIDEOS_T ...@@ -195,10 +195,10 @@ REQUEST_VIDEOS_T
{ {
"time": 1567669674, "time": 1567669674,
"cmd": "upload_video", "cmd": "upload_video",
"rid": "<random_str>", "rid": "001231554A20",
"data": { "data": {
"start": 1567669674, "start": 1592985060,
"end": 1567668000, "end": 1592985180,
"type": 6 "type": 6
} }
} }
......
...@@ -53,11 +53,10 @@ sequenceDiagram ...@@ -53,11 +53,10 @@ sequenceDiagram
EVCamera ->> Broker: power_on: pub online EVCamera ->> Broker: power_on: pub online
EVCamera ->> Broker: sub: /evcamera/v1.0/request/<SN> EVCamera ->> Broker: sub: /evcamera/v1.0/request/<SN>
CloudSvc ->> Broker: pub: cmd = config|status|upload_video|ptz|get_config|qr CloudSvc ->> Broker: pub: config|status|upload_video|<br/>ptz|get_config|qr
Broker ->> EVCamera: notify: request {"rid":"<RID>", "cmd": "<x>", ...} Broker ->> EVCamera: notify: request {"rid":"<RID>", "cmd": "<x>"...}
EVCamera ->> EVCamera: [Handle cmd] EVCamera ->> EVCamera: [Handle cmd]
EVCamera ->> Broker: pub /evcamera/v1.0/response/<RID> EVCamera ->> Broker: pub: /evcamera/v1.0/response/<RID> or<br/>/evcamera/v1.0/report
EVCamera ->> Broker: pub /evcamera/v1.0/report
``` ```
#### MQTT Broker topics #### MQTT Broker topics
......
#include "base_features.h"
#include <stdlib.h>
int ev_stop_record(ev_record_cfg_t **handle)
{
assert(handle != nullptr);
if(*handle != nullptr) {
free(*handle);
handle = nullptr;
}
}
int ev_start_record(const json &config, ev_record_cfg_t **handle)
{
assert(handle != nullptr);
*handle = (ev_record_cfg_t*)malloc(sizeof(ev_record_cfg_t));
//
}
\ No newline at end of file
#ifndef __BASE_FEATURES_H__
#define __BASE_FEATURES_H__
#include <jsoncons/json.hpp>
using namespace jsoncons;
typedef struct ev_record_status_t {
/// TODO:
} ev_record_status_t;
typedef struct ev_mdstatus_t {
/// TODO:
} ev_mdstatus_t;
typedef struct ev_ai_status_t {
/// TODO:
} ev_ai_status_t;
typedef struct ev_record_cfg {
} ev_record_cfg;
typedef struct ev_record_cfg_t {
} ev_record_cfg_t;
typedef struct ev_md_cfg_t {
} ev_md_cfg_t;
typedef struct ev_ai_cfg_t {
} ev_ai_cfg_t;
/// record
int ev_start_record(const json &config, ev_record_cfg_t **handle);
int ev_stop_record(ev_record_cfg_t **handle);
ev_record_status_t ev_get_record_status(ev_record_cfg_t **handle);
/// motion detect
int ev_start_md(const json &config, ev_md_cfg_t **handle);
int ev_stop_md(ev_md_cfg_t *handle);
ev_mdstatus_t ev_get_md_status(ev_md_cfg_t **handle);
/// ai detect
int ev_start_ai(const json &config, ev_ai_cfg_t **handle);
int ev_stop_ai(ev_ai_cfg_t **handle);
ev_ai_status_t ev_get_ai_status(ev_ai_cfg_t **handle);
#endif
\ No newline at end of file
#ifndef _RTSP_COMMON_H
#define _RTSP_COMMON_H
#include <stdlib.h>
#include <stdio.h>
/******************************************************************************
* DEFINITIONS
******************************************************************************/
/* this is necessary to get rid of 'useless keyword or type ..' shit */
#define __DEBUG
#define TYPES
#define likely(x) __builtin_expect((x), 1)
#define unlikely(x) __builtin_expect((x), 0)
#ifdef __DEBUG
/* -------------------------------------------------------------------------- */
#define DBG( fmt, args...) do {\
fprintf(stderr, "--- DEBUG:%s:%s:%d ---: ", __FILE__, __FUNCTION__, __LINE__);\
fprintf(stderr, fmt, ## args);} while(0)
#define ERR(fmt, args...) do {\
fprintf(stderr, "XXX ERROR:%s:%s:%d XXX: ",__FILE__,__FUNCTION__,__LINE__);\
fprintf(stderr, fmt, ## args);} while (0)
#define CHECK do {\
DBG("(*^-^)\n");} while (0)
/* debug assert (completely removed in release version) */
#define DASSERT(b,action) do {if(unlikely(!(b))){ ERR("debug assertion failure (%s)\n", #b);action;} } while (0)
/* must success (check omitted in release version) */
#define MUST(b,action) do {if(unlikely(!(b))){ ERR("assertion failure (%s)\n", #b);action;} } while (0)
/* assertion */
#define ASSERT(b,action) do {if(unlikely(!(b))){ ERR("assertion failure (%s)\n", #b);action;} } while (0)
/* sanity check wrapper (same in release and debug version) */
#define TEST(b,action) do {if(unlikely(!(b))){ ERR("unexpected (%s)\n", #b);action;} } while (0)
/* -------------------------------------------------------------------------- */
#else
/* -------------------------------------------------------------------------- */
#define DBG( fmt, args...)
#define ERR(fmt, args...) do {\
fprintf(stderr, "XXX ERROR:%s:%s:%d XXX: ",__FILE__,__FUNCTION__,__LINE__);\
fprintf(stderr, fmt, ## args);} while (0)
#define CHECK
/* debug assert (completely removed in release version) */
//#define DASSERT(b,action)
/* must success (check omitted in release version) */
//#define MUST(b,action) do {if ((b)){}} while (0)
/* debug assert (completely removed in release version) */
#define DASSERT(b,action) do {if(unlikely(!(b))){ ERR("debug assertion failure (%s)\n", #b);action;} } while (0)
/* must success (check omitted in release version) */
#define MUST(b,action) do {if(unlikely(!(b))){ ERR("assertion failure (%s)\n", #b);action;} } while (0)
/* assertion */
#define ASSERT(b,action) do {if(unlikely(!(b))){ ERR("assertion failure (%s)\n", #b);action;} } while (0)
/* sanity check wrapper (same in release and debug version) */
#define TEST(b,action) do {if(unlikely(!(b))){ ERR("unexpected (%s)\n", #b);action;} } while (0)
/* -------------------------------------------------------------------------- */
#endif
#define SUCCESS 0
#define FAILURE -1
#define ERR_RTSP_SHOULD_FIN -10
/* Defining infinite time */
#define FOREVER -1
#define CLEAR(x) memset (&(x), 0, sizeof (x))
#define CLOSE(x) do{if((x)>0){close(x);(x) = 0;}}while(0)
#define FCLOSE(x) do{if((x)!=NULL){fclose(x);(x) = NULL;}}while(0)
#define ALLOC(t) (t = (typeof(t))calloc(1,sizeof(typeof(*(t)))))
#define NEW(t) ((t *)calloc(1,sizeof(t)))
#define COPY(x,y) memcpy ((x),(y),sizeof (*(y)))
//#define FREE(h) do { if(h){printf("freeing 0x%08x\n",(unsigned int)h);free(h);h=NULL;}else{DBG("freeing NULL pointer\n");}} while (0);
#define FREE(h) do { if(h){free(h);h=NULL;}} while (0);
/* common object creation macro: calloc given pointer. when failed, perform 'action' */
#define TALLOC(h,action) do {h=NULL;if(!(ALLOC(h))){ERR("No memory!\n");action;}} while (0)
#ifndef max
#define max(a,b) ((a)>(b)?(a):(b))
#endif
#ifndef min
#define min(a,b) ((a)>(b)?(b):(a))
#endif
#define TRUE 1
#define FALSE 0
/* Type magic */
enum type_magic_e {
MAGIC_NAL_QUEUE_ITEM = 0xdead0000,
MAGIC_PACKET_QUEUE_ITEM,
MAGIC_BUFPOOL_ELEM
};
#define CHECK_MAGIC(magic,ptr) (*(ptr) && (((unsigned int*)(*(ptr)))[0] == (magic)))
#ifndef container_of
#define container_of(type,ptr,member) ({ const typeof( ((type *)0)->member) *__mptr=(ptr); (type *) ( (char *)__mptr - offsetof(type,member));})
#endif
#endif
#ifndef _RTSP_COMMON_H
#define _RTSP_COMMON_H
#include <stdio.h>
#include <pthread.h>
#include <stddef.h>
#include <string.h>
#include <stdlib.h>
/******************************************************************************
* DEFINITIONS
******************************************************************************/
/* this is necessary to get rid of 'useless keyword or type ..' shit */
#define typeof(x) __typeof__(x)
#define __DEBUG
#define TYPES
#define likely(x) __builtin_expect((x), 1)
#define unlikely(x) __builtin_expect((x), 0)
#ifdef __DEBUG
/* -------------------------------------------------------------------------- */
#define DBG( fmt, args...) do {\
fprintf(stderr, "--- DEBUG:%s:%s:%d ---: ", __FILE__, __FUNCTION__, __LINE__);\
fprintf(stderr, fmt, ## args);} while(0)
#define ERR(fmt, args...) do {\
fprintf(stderr, "XXX ERROR:%s:%s:%d XXX: ",__FILE__,__FUNCTION__,__LINE__);\
fprintf(stderr, fmt, ## args);} while (0)
#define CHECK do {\
DBG("(*^-^)\n");} while (0)
/* debug assert (completely removed in release version) */
#define DASSERT(b,action) do {if(unlikely(!(b))){ ERR("debug assertion failure (%s)\n", #b);action;} } while (0)
/* must success (check omitted in release version) */
#define MUST(b,action) do {if(unlikely(!(b))){ ERR("assertion failure (%s)\n", #b);action;} } while (0)
/* assertion */
#define ASSERT(b,action) do {if(unlikely(!(b))){ ERR("assertion failure (%s)\n", #b);action;} } while (0)
/* sanity check wrapper (same in release and debug version) */
#define TEST(b,action) do {if(unlikely(!(b))){ ERR("unexpected (%s)\n", #b);action;} } while (0)
/* -------------------------------------------------------------------------- */
#else
/* -------------------------------------------------------------------------- */
#define DBG( fmt, args...)
#define ERR(fmt, args...) do {\
fprintf(stderr, "XXX ERROR:%s:%s:%d XXX: ",__FILE__,__FUNCTION__,__LINE__);\
fprintf(stderr, fmt, ## args);} while (0)
#define CHECK
/* debug assert (completely removed in release version) */
//#define DASSERT(b,action)
/* must success (check omitted in release version) */
//#define MUST(b,action) do {if ((b)){}} while (0)
/* debug assert (completely removed in release version) */
#define DASSERT(b,action) do {if(unlikely(!(b))){ ERR("debug assertion failure (%s)\n", #b);action;} } while (0)
/* must success (check omitted in release version) */
#define MUST(b,action) do {if(unlikely(!(b))){ ERR("assertion failure (%s)\n", #b);action;} } while (0)
/* assertion */
#define ASSERT(b,action) do {if(unlikely(!(b))){ ERR("assertion failure (%s)\n", #b);action;} } while (0)
/* sanity check wrapper (same in release and debug version) */
#define TEST(b,action) do {if(unlikely(!(b))){ ERR("unexpected (%s)\n", #b);action;} } while (0)
/* -------------------------------------------------------------------------- */
#endif
#define SUCCESS 0
#define FAILURE -1
#define ERR_RTSP_SHOULD_FIN -10
/* Defining infinite time */
#define FOREVER -1
#define CLEAR(x) memset (&(x), 0, sizeof (x))
#define CLOSE(x) do{if((x)>0){close(x);(x) = 0;}}while(0)
#define FCLOSE(x) do{if((x)!=NULL){fclose(x);(x) = NULL;}}while(0)
#define ALLOC(t) (t = (typeof(t))calloc(1,sizeof(typeof(*(t)))))
#define NEW(t) ((t *)calloc(1,sizeof(t)))
#define COPY(x,y) memcpy ((x),(y),sizeof (*(y)))
//#define FREE(h) do { if(h){printf("freeing 0x%08x\n",(unsigned int)h);free(h);h=NULL;}else{DBG("freeing NULL pointer\n");}} while (0);
#define FREE(h) do { if(h){free(h);h=NULL;}} while (0);
/* common object creation macro: calloc given pointer. when failed, perform 'action' */
#define TALLOC(h,action) do {h=NULL;if(!(ALLOC(h))){ERR("No memory!\n");action;}} while (0)
#ifndef max
#define max(a,b) ((a)>(b)?(a):(b))
#endif
#ifndef min
#define min(a,b) ((a)>(b)?(b):(a))
#endif
#define TRUE 1
#define FALSE 0
/* Type magic */
enum type_magic_e {
MAGIC_NAL_QUEUE_ITEM = 0xdead0000,
MAGIC_PACKET_QUEUE_ITEM,
MAGIC_BUFPOOL_ELEM
};
#define CHECK_MAGIC(magic,ptr) (*(ptr) && (((unsigned int*)(*(ptr)))[0] == (magic)))
#ifndef container_of
#define container_of(type,ptr,member) ({ const typeof( ((type *)0)->member) *__mptr=(ptr); (type *) ( (char *)__mptr - offsetof(type,member));})
#endif
/******************************************************************************
* DATA STRUCTURES
******************************************************************************/
struct global_state_t {
unsigned long long frames; /* Video frame counter */
pthread_mutex_t mutex; /* Mutex to protect the global data */
int quit;
};
/******************************************************************************
* INLINE FUNCTIONS
******************************************************************************/
static inline struct global_state_t *gbl_create()
{
struct global_state_t *nh;
TALLOC(nh,return NULL);
pthread_mutex_init(&nh->mutex,NULL);
return nh;
}
static inline void gbl_delete(struct global_state_t *h)
{
if(h) {
pthread_mutex_destroy(&h->mutex);
FREE(h);
}
}
static inline int
gbl_get_quit(struct global_state_t *gbl)
{
int quit;
pthread_mutex_lock(&gbl->mutex);
quit = gbl->quit;
pthread_mutex_unlock(&gbl->mutex);
return quit;
}
static inline void
gbl_set_quit(struct global_state_t *gbl)
{
pthread_mutex_lock(&gbl->mutex);
gbl->quit = TRUE;
pthread_mutex_unlock(&gbl->mutex);
}
#endif
...@@ -81,7 +81,7 @@ const string consts::pub_topic_eventdata = "/evcamera/v1.0/eventdata/"; ...@@ -81,7 +81,7 @@ const string consts::pub_topic_eventdata = "/evcamera/v1.0/eventdata/";
const string consts::pub_topic_lastwill = "/evcamera/v1.0/lastwill/"; const string consts::pub_topic_lastwill = "/evcamera/v1.0/lastwill/";
const string consts::pub_topic_report = "/evcamera/v1.0/report"; const string consts::pub_topic_report = "/evcamera/v1.0/report";
const string consts::mqtt_url = "tcp://admin:vJ3zHqWrHbrqxVMT@evcloudsvc.ilabservice.cloud:11883"; const string consts::mqtt_url = "tcp://admin:vJ3zHqWrHbrqxVMT@evcloudsvc.ilabservice.cloud:11883";
const string consts::vgw_addr = "tcp://evcloudsvc.ilabservice.cloud:7123"; const string consts::vgw_addr = "tcp://vgw.ilabservice.cloud:7123";
const string consts::upload_addr = "tcp://evcloudsvc.ilabservice.cloud:10009"; const string consts::upload_addr = "tcp://evcloudsvc.ilabservice.cloud:10009";
const string consts::strPubUrl = "inproc://frame"; const string consts::strPubUrl = "inproc://frame";
...@@ -111,11 +111,12 @@ json make_default_cloud_config() ...@@ -111,11 +111,12 @@ json make_default_cloud_config()
{ {
return R"( return R"(
{ {
"vgw":"evcloudsvc.ilabservice.cloud:7123", "vgw":"vgw.ilabservice.cloud:7123",
"mqtt":"admin:vJ3zHqWrHbrqxVMT@evcloudsvc.ilabservice.cloud:11883", "mqtt":"admin:vJ3zHqWrHbrqxVMT@evcloudsvc.ilabservice.cloud:11883",
"upload":"evcloudsvc.ilabservice.cloud:10010", "upload":"vup.ilabservice.cloud:10010",
"features":{ "features":{
"push":0, "push":0,
"fps":20,
"motion":{ "motion":{
"enabled":1, "enabled":1,
"region":{ "region":{
...@@ -128,7 +129,7 @@ json make_default_cloud_config() ...@@ -128,7 +129,7 @@ json make_default_cloud_config()
}, },
"recordLen":120, "recordLen":120,
"ai":{ "ai":{
"enabled":1, "enabled":0,
"faceThresh":0.75, "faceThresh":0.75,
"humanThresh":0.63, "humanThresh":0.63,
"region":{ "region":{
...@@ -237,7 +238,7 @@ bool get_sdcard_megabytes(uint64_t &total, uint64_t &free, char* path ) ...@@ -237,7 +238,7 @@ bool get_sdcard_megabytes(uint64_t &total, uint64_t &free, char* path )
} }
/// returns negtive for failure, otherwise success /// returns negtive for failure, otherwise success
int setupDealer(void **ctx, void **s, string ident, string addr, int sndQS, int timeoutMs) int setupDealer(void **ctx, void **s, string ident, string addr, int timeoutMs, int sndQS)
{ {
int ret = 0; int ret = 0;
*ctx = zmq_ctx_new(); *ctx = zmq_ctx_new();
...@@ -250,20 +251,15 @@ int setupDealer(void **ctx, void **s, string ident, string addr, int sndQS, int ...@@ -250,20 +251,15 @@ int setupDealer(void **ctx, void **s, string ident, string addr, int sndQS, int
ret = 2; ret = 2;
zmq_setsockopt(*s, ZMQ_TCP_KEEPALIVE_CNT, &ret, sizeof (ret)); zmq_setsockopt(*s, ZMQ_TCP_KEEPALIVE_CNT, &ret, sizeof (ret));
if(sndQS!=0) { if(sndQS!=0) {
zmq_setsockopt(*s, ZMQ_SNDHWM, &sndQS, sizeof (sndQS)); ret = zmq_setsockopt(*s, ZMQ_SNDHWM, &sndQS, sizeof (sndQS));
} if(ret < 0) {
if(timeoutMs != 0) { spdlog::error("failed to setup ZMQ_SNDHWM for Dealer {}@{}: {}", ident, addr, zmq_strerror(zmq_errno()));
if(timeoutMs == -1) {
timeoutMs = 5 *1000;
} }
zmq_setsockopt(*s, ZMQ_RCVTIMEO, &timeoutMs, sizeof(timeoutMs));
} }
if(timeoutMs > 0) {
zmq_setsockopt(*s, ZMQ_RCVTIMEO, &timeoutMs, sizeof (timeoutMs));
// uint64_t hwm = 12; zmq_setsockopt(*s, ZMQ_SNDTIMEO, &timeoutMs, sizeof (timeoutMs));
// zmq_setsockopt(*s, ZMQ_SNDHWM, &hwm, sizeof(hwm)); }
// int onlyOne = 1;
// zmq_setsockopt(*s, ZMQ_CONFLATE, &onlyOne, sizeof(onlyOne));
ret = zmq_setsockopt(*s, ZMQ_IDENTITY, ident.c_str(), ident.size()); ret = zmq_setsockopt(*s, ZMQ_IDENTITY, ident.c_str(), ident.size());
if(ret < 0) { if(ret < 0) {
...@@ -271,7 +267,7 @@ int setupDealer(void **ctx, void **s, string ident, string addr, int sndQS, int ...@@ -271,7 +267,7 @@ int setupDealer(void **ctx, void **s, string ident, string addr, int sndQS, int
zmq_ctx_destroy(*ctx); zmq_ctx_destroy(*ctx);
*s = nullptr; *s = nullptr;
*ctx = nullptr; *ctx = nullptr;
spdlog::debug("{} failed setsockopts ZMQ_ROUTING_ID to {}: {}", ident, addr, zmq_strerror(zmq_errno())); spdlog::debug("{} failed setsockopts ZMQ_IDENTITY to {}: {}", ident, addr, zmq_strerror(zmq_errno()));
} }
else { else {
ret = zmq_connect(*s, addr.c_str()); ret = zmq_connect(*s, addr.c_str());
......
...@@ -104,7 +104,7 @@ extern json make_online_msg(string sn); ...@@ -104,7 +104,7 @@ extern json make_online_msg(string sn);
extern json make_lastwill_msg(string sn); extern json make_lastwill_msg(string sn);
extern void get_mac_addr(char *buf, char *intf = nullptr); extern void get_mac_addr(char *buf, char *intf = nullptr);
extern bool get_sdcard_megabytes(uint64_t &total, uint64_t &free, char* path = nullptr); extern bool get_sdcard_megabytes(uint64_t &total, uint64_t &free, char* path = nullptr);
extern int setupDealer(void **ctx, void **s, string ident, string addr, int sndQS=0, int timeoutMs = -1); extern int setupDealer(void **ctx, void **s, string ident, string addr, int timeoutMs = 0, int sndQS = 0);
extern int setupRouter(void **ctx, void **s, string addr, int rcvQS=0); extern int setupRouter(void **ctx, void **s, string addr, int rcvQS=0);
extern int z_recv_multiple(void *s, vector<uint8_t> &buf, int &frames); extern int z_recv_multiple(void *s, vector<uint8_t> &buf, int &frames);
extern vector<string> split(const string &s, char delim); extern vector<string> split(const string &s, char delim);
...@@ -129,7 +129,7 @@ public: ...@@ -129,7 +129,7 @@ public:
void insert(TN elem, cb_remove_elem<TN> fn=nullptr) void insert(TN elem, cb_remove_elem<TN> fn=nullptr)
{ {
// list_.insert(lower_bound(list_.begin(), list_.end(), elem), elem); // list_.insert(lower_bound(list_.begin(), list_.end(), elem), elem);
if(cntInsert % 10 == 0) { if(cntInsert % 100 == 0) {
oldestTs = chrono::duration_cast<chrono::milliseconds>(chrono::system_clock::now().time_since_epoch()).count() - 60*2*1000*maxSize; oldestTs = chrono::duration_cast<chrono::milliseconds>(chrono::system_clock::now().time_since_epoch()).count() - 60*2*1000*maxSize;
spdlog::info("record: maxSlices {}, oldestTs {}", maxSize, oldestTs); spdlog::info("record: maxSlices {}, oldestTs {}", maxSize, oldestTs);
uint64_t mt, mf; uint64_t mt, mf;
......
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
#include "common.h"
#include "mime.h"
/******************************************************************************
* PRIVATE DEFINITIONS
******************************************************************************/
#define __MIME_BASE64_TEST_SOURCE "ABCDEFGnzmk.ghijdtyo9ryfyhszldfho;asrupq8w49ryaishv;zxvj;oalsurp89w4qytzjhv;sadzaas;fdh;qwoe45yp9gha;ovhajvas;fguasd;f2139457398579 "
#define __MIME_BASE64_TEST_RESULT "QUJDREVGR256bWsuZ2hpamR0eW85cnlmeWhzemxkZmhvO2FzcnVwcTh3NDlyeWFpc2h2O3p4dmo7b2Fsc3VycDg5dzRxeXR6amh2O3NhZHphYXM7ZmRoO3F3b2U0NXlwOWdoYTtvdmhhanZhcztmZ3Vhc2Q7ZjIxMzk0NTczOTg1Nzk="
/******************************************************************************
* PRIVATE DATA
******************************************************************************/
#ifdef I_THOUGHT_THIS_IS_NECESSARY_BUT_NOT_SO_KEEP_IT_FOR_GOODNESS
static unsigned char __byte_adjust_table[256] =
{0,128,64,192,32,160,96,224,16,144,80,208,48,176,112,240,8,136,72,200,40,168,104,232,24,152,88,216,56,184,120,248,4,132,68,196,36,164,100,228,20,148,84,212,52,180,116,244,12,140,76,204,44,172,108,236,28,156,92,220,60,188,124,252,2,130,66,194,34,162,98,226,18,146,82,210,50,178,114,242,10,138,74,202,42,170,106,234,26,154,90,218,58,186,122,250,6,134,70,198,38,166,102,230,22,150,86,214,54,182,118,246,14,142,78,206,46,174,110,238,30,158,94,222,62,190,126,254,1,129,65,193,33,161,97,225,17,145,81,209,49,177,113,241,9,137,73,201,41,169,105,233,25,153,89,217,57,185,121,249,5,133,69,197,37,165,101,229,21,149,85,213,53,181,117,245,13,141,77,205,45,173,109,237,29,157,93,221,61,189,125,253,3,131,67,195,35,163,99,227,19,147,83,211,51,179,115,243,11,139,75,203,43,171,107,235,27,155,91,219,59,187,123,251,7,135,71,199,39,167,103,231,23,151,87,215,55,183,119,247,15,143,79,207,47,175,111,239,31,159,95,223,63,191,127,255};
static inline char __byte_adjust(unsigned char x)
{
char ret = x;
#ifndef __RTSP_BIG_ENDIAN
ret = __byte_adjust_table[x];
#endif
return ret;
}
#endif
static char __base64_charmap[64] =
{'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','0','1','2','3','4','5','6','7','8','9','+','/'};
static char __base16_charmap[16] =
{'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
/******************************************************************************
* PRIATE FUNCTIONS
******************************************************************************/
/******************************************************************************
* PUBLIC FUNCTIONS
******************************************************************************/
mime_encoded_handle mime_base16_create(char *src, size_t len)
{
mime_encoded_handle nh = NULL;
int i;
char *result = NULL;
char *p;
DASSERT(src, return NULL);
DASSERT(len > 0, return NULL);
TALLOC(nh, return NULL);
ASSERT(result = calloc(len * 2 + 1, sizeof(char)), goto error);
p = result;
for (i = 0; i < len; i++) {
*(p++) = __base16_charmap[(src[i] & 0xF0) >> 4];
*(p++) = __base16_charmap[(src[i] & 0x0F)];
}
*p = 0;
nh->result = result;
nh->len_result = len * 2 + 1;
nh->len_src = len;
nh->base = 16;
DASSERT(strlen(nh->result) + 1 == nh->len_result, goto error);
return nh;
error:
mime_encoded_delete(nh);
return NULL;
}
mime_encoded_handle mime_base64_create(char *src, size_t len)
{
mime_encoded_handle nh = NULL;
int i;
char *result = NULL;
char *p;
DASSERT(src, return NULL);
DASSERT(len > 0, return NULL);
TALLOC(nh, return NULL);
ASSERT(result = calloc(len * 2 + 1, sizeof(char)), goto error);
p = result;
for(i = 0; i <= len - 3; i+=3) {
*(p++) = __base64_charmap[(src[i] & 0xFC) >> 2];
*(p++) = __base64_charmap[((src[i] & 0x03) << 4) | ((src[i+1] & 0xF0) >> 4)];
*(p++) = __base64_charmap[((src[i+1] & 0x0F) << 2) | ((src[i+2] & 0xC0) >> 6)];
*(p++) = __base64_charmap[src[i+2] & 0x3F];
}
switch(len - i) {
/* 111111 _ 11 | 1111 _ 1111 | 00 _ '=' */
case 2:
*(p++) = __base64_charmap[(src[i] & 0xFC) >> 2];
*(p++) = __base64_charmap[((src[i] & 0x03) << 4) | ((src[i+1] & 0xF0) >> 4)];
*(p++) = __base64_charmap[(src[i+1] & 0x0F) << 2];
*(p++) = '=';
break;
/* 111111 _ 11 | 0000 _ '=' _ '=' */
case 1:
*(p++) = __base64_charmap[(src[i] & 0xFC) >> 2];
*(p++) = __base64_charmap[(src[i] & 0x3) << 4];
*(p++) = '=';
*(p++) = '=';
break;
case 0:
break;
default:
ERR("BUG in base64 encoding\n");
goto error;
}
*p = 0;
nh->result = result;
nh->len_result= 1 + p - result;
nh->len_src = len;
nh->base = 64;
DASSERT(strlen(nh->result) + 1 == nh->len_result, goto error);
return nh;
error:
mime_encoded_delete(nh);
return NULL;
}
#ifndef _RTSP_MIME_H
#define _RTSP_MIME_H
#if defined (__cplusplus)
extern "C" {
#endif
/******************************************************************************
* DEFINITIONS
******************************************************************************/
/******************************************************************************
* DATA STRUCTURES
******************************************************************************/
struct __mime_encoded_obj_t {
char *result;
size_t len_result;
size_t len_src;
unsigned int base; /* 16 or 32 or 64 */
};
typedef struct __mime_encoded_obj_t *mime_encoded_handle;
/******************************************************************************
* DECLARATIONS
******************************************************************************/
mime_encoded_handle mime_base64_create(char *src, size_t len);
mime_encoded_handle mime_base16_create(char *src, size_t len);
static inline void mime_encoded_delete(mime_encoded_handle h)
{
if(h) {
free(h->result);
free(h);
}
}
#if defined (__cplusplus)
}
#endif
#endif
...@@ -36,26 +36,27 @@ typedef struct { ...@@ -36,26 +36,27 @@ typedef struct {
} MdBdMgr_s; } MdBdMgr_s;
std::atomic<uint64_t> gMotionCounter(0); std::atomic<uint64_t> gMotionCounter(0);
extern shared_ptr<spdlog::logger> rlogger;
static XM_S32 cb_motion_detect(XM_VOID *pUserArg, MaQueMdAlarm_s *pstMdAlarm) static XM_S32 cb_motion_detect(XM_VOID *pUserArg, MaQueMdAlarm_s *pstMdAlarm)
{ {
ev_module_config_t * pArgs = (ev_module_config_t *)pUserArg; //ev_module_config_t * pArgs = (ev_module_config_t *)pUserArg;
gMotionCounter++; gMotionCounter++;
//spdlog::info("MD eAlarmType: {}, alarmState: {}", pstMdAlarm->eAlarmType, pstMdAlarm->alarmState); //rlogger->info("MD eAlarmType: {}, alarmState: {}", pstMdAlarm->eAlarmType, pstMdAlarm->alarmState);
return 0; return 0;
} }
static XM_S32 cb_blind_detect(XM_VOID *pUserArg, MaQueBdResult_s *pstBdRes) static XM_S32 cb_blind_detect(XM_VOID *pUserArg, MaQueBdResult_s *pstBdRes)
{ {
ev_module_config_t * pArgs = (ev_module_config_t *)pUserArg; // ev_module_config_t * pArgs = (ev_module_config_t *)pUserArg;
static int prevState = 0; static int prevState = 0;
if(pstBdRes->state != prevState) { if(pstBdRes->state != prevState) {
if(pstBdRes->state == 1) { if(pstBdRes->state == 1) {
spdlog::info("The Camera is blind"); rlogger->info("The Camera is blind");
} }
else { else {
spdlog::info("The Camera is blind recovered"); rlogger->info("The Camera is blind recovered");
} }
} }
prevState = pstBdRes->state; prevState = pstBdRes->state;
...@@ -65,10 +66,10 @@ static XM_S32 cb_blind_detect(XM_VOID *pUserArg, MaQueBdResult_s *pstBdRes) ...@@ -65,10 +66,10 @@ static XM_S32 cb_blind_detect(XM_VOID *pUserArg, MaQueBdResult_s *pstBdRes)
void start_md_bd(ev_module_config_t *pArgs) void start_md_bd(ev_module_config_t *pArgs)
{ {
if(!pArgs->module.motion.enabled) { if(!pArgs->module.motion.enabled) {
spdlog::warn("motion detect is disabled"); rlogger->warn("motion detect is disabled");
} }
spdlog::info("starting motion detect module"); rlogger->info("starting motion detect module");
MdModParam_s mdParam = { 0 }; MdModParam_s mdParam = { 0 };
BdModParam_s bdParam = { 0 }; BdModParam_s bdParam = { 0 };
...@@ -79,7 +80,9 @@ void start_md_bd(ev_module_config_t *pArgs) ...@@ -79,7 +80,9 @@ void start_md_bd(ev_module_config_t *pArgs)
mdParam.stMdParam.w = (pArgs->module.motion.region.maxx - pArgs->module.motion.region.minx) * 352; mdParam.stMdParam.w = (pArgs->module.motion.region.maxx - pArgs->module.motion.region.minx) * 352;
mdParam.stMdParam.h = (pArgs->module.motion.region.maxy - pArgs->module.motion.region.miny) * 288; mdParam.stMdParam.h = (pArgs->module.motion.region.maxy - pArgs->module.motion.region.miny) * 288;
mdParam.stMdParam.eMdAlarmlevel = (MaQueMdAlarmLevel_e)pArgs->module.motion.level; // [1, 6] mdParam.stMdParam.eMdAlarmlevel = (MaQueMdAlarmLevel_e)pArgs->module.motion.level; // [1, 6]
bdParam.stBdParam.bEnabled = 1;
/// Blind detection
bdParam.stBdParam.bEnabled = 0;
bdParam.stBdParam.eBdAlarmLevel = (MaQueBdAlarmLevel_e)pArgs->module.motion.level; bdParam.stBdParam.eBdAlarmLevel = (MaQueBdAlarmLevel_e)pArgs->module.motion.level;
if (mdParam.stMdParam.bEnabled) { if (mdParam.stMdParam.bEnabled) {
...@@ -88,11 +91,11 @@ void start_md_bd(ev_module_config_t *pArgs) ...@@ -88,11 +91,11 @@ void start_md_bd(ev_module_config_t *pArgs)
LibXmMaQue_MDAlarm_register(0, cb_motion_detect, pArgs); LibXmMaQue_MDAlarm_register(0, cb_motion_detect, pArgs);
} }
if (bdParam.stBdParam.bEnabled) { // if (bdParam.stBdParam.bEnabled) {
LibXmMaQue_BD_create(0); // LibXmMaQue_BD_create(0);
LibXmMaQue_BD_setParam(0, &bdParam.stBdParam); // LibXmMaQue_BD_setParam(0, &bdParam.stBdParam);
LibXmMaQue_BD_register(0, cb_blind_detect, pArgs); // LibXmMaQue_BD_register(0, cb_blind_detect, pArgs);
} // }
} }
void stop_md_bd() void stop_md_bd()
......
差异被折叠。
...@@ -30,6 +30,8 @@ ...@@ -30,6 +30,8 @@
#define VN(packet) (uint8_t) ((packet.li_vn_mode & 0x38) >> 3) // (vn & 00 111 000) >> 3 #define VN(packet) (uint8_t) ((packet.li_vn_mode & 0x38) >> 3) // (vn & 00 111 000) >> 3
#define MODE(packet) (uint8_t) ((packet.li_vn_mode & 0x07) >> 0) // (mode & 00 000 111) >> 0 #define MODE(packet) (uint8_t) ((packet.li_vn_mode & 0x07) >> 0) // (mode & 00 000 111) >> 0
extern std::shared_ptr<spdlog::logger> rlogger;
int getNtpTime(time_t * txTm) int getNtpTime(time_t * txTm)
{ {
int socket_ = 0, n = 0, rv = 0; // Socket file descriptor and the n return result from writing/reading from the socket. int socket_ = 0, n = 0, rv = 0; // Socket file descriptor and the n return result from writing/reading from the socket.
...@@ -82,11 +84,11 @@ int getNtpTime(time_t * txTm) ...@@ -82,11 +84,11 @@ int getNtpTime(time_t * txTm)
hints.ai_protocol = 0; hints.ai_protocol = 0;
int last_errno = 0; int last_errno = 0;
spdlog::info("get ntp host info"); rlogger->info("get ntp host info");
addrinfo *addrinfo_result = nullptr; addrinfo *addrinfo_result = nullptr;
rv = ::getaddrinfo(host_name, std::to_string(123).c_str(), &hints, &addrinfo_result); rv = ::getaddrinfo(host_name, std::to_string(123).c_str(), &hints, &addrinfo_result);
if (rv != 0) { if (rv != 0) {
spdlog::error("::getaddrinfo failed: {}", gai_strerror(rv)); rlogger->error("::getaddrinfo failed: {}", gai_strerror(rv));
goto end; goto end;
} }
...@@ -101,14 +103,14 @@ int getNtpTime(time_t * txTm) ...@@ -101,14 +103,14 @@ int getNtpTime(time_t * txTm)
timeout.tv_usec = 0; timeout.tv_usec = 0;
if (setsockopt (socket_, SOL_SOCKET, SO_RCVTIMEO, (char *)&timeout, sizeof(timeout)) < 0) { if (setsockopt (socket_, SOL_SOCKET, SO_RCVTIMEO, (char *)&timeout, sizeof(timeout)) < 0) {
spdlog::error("setsockopt SO_RCVTIMEO failed"); rlogger->error("setsockopt SO_RCVTIMEO failed");
goto end; goto end;
} }
timeout.tv_sec = 2; timeout.tv_sec = 2;
if (setsockopt (socket_, SOL_SOCKET, SO_SNDTIMEO, (char *)&timeout, sizeof(timeout)) < 0) { if (setsockopt (socket_, SOL_SOCKET, SO_SNDTIMEO, (char *)&timeout, sizeof(timeout)) < 0) {
spdlog::error("setsockopt SO_SNDTIMEO failed"); rlogger->error("setsockopt SO_SNDTIMEO failed");
goto end; goto end;
} }
...@@ -116,10 +118,10 @@ int getNtpTime(time_t * txTm) ...@@ -116,10 +118,10 @@ int getNtpTime(time_t * txTm)
if (rv == 0) { if (rv == 0) {
auto addr = (struct sockaddr_in *)rp->ai_addr; auto addr = (struct sockaddr_in *)rp->ai_addr;
auto hostIp = inet_ntoa((struct in_addr)addr->sin_addr); auto hostIp = inet_ntoa((struct in_addr)addr->sin_addr);
spdlog::info("ntp host {} has ip {}", host_name, hostIp); rlogger->info("ntp host {} has ip {}", host_name, hostIp);
// rv = fcntl(*socket_, F_SETFL, fcntl(*socket_, F_GETFL, 0) | O_NONBLOCK); // rv = fcntl(*socket_, F_SETFL, fcntl(*socket_, F_GETFL, 0) | O_NONBLOCK);
// if (rv == -1){ // if (rv == -1){
// spdlog::error("error calling fcntl"); // rlogger->error("error calling fcntl");
// } // }
break; break;
} }
...@@ -145,7 +147,7 @@ end: ...@@ -145,7 +147,7 @@ end:
n = write( socket_, ( char* ) &packet, sizeof( ntp_packet ) ); n = write( socket_, ( char* ) &packet, sizeof( ntp_packet ) );
if ( n < 0 ) { if ( n < 0 ) {
spdlog::error("ERROR writing to socket" ); rlogger->error("ERROR writing to socket" );
return -1; return -1;
} }
...@@ -155,7 +157,7 @@ end: ...@@ -155,7 +157,7 @@ end:
n = read( socket_, ( char* ) &packet, sizeof( ntp_packet ) ); n = read( socket_, ( char* ) &packet, sizeof( ntp_packet ) );
if ( n < 0 ) { if ( n < 0 ) {
spdlog::error("ERROR reading from socket" ); rlogger->error("ERROR reading from socket" );
return -1; return -1;
} }
...@@ -178,7 +180,7 @@ end: ...@@ -178,7 +180,7 @@ end:
::close(socket_); ::close(socket_);
spdlog::info( "Time: {}", (int)ctime( ( const time_t* ) &txTm ) ); rlogger->info( "Time: {}", (int)ctime( ( const time_t* ) &txTm ) );
return 0; return 0;
} }
\ No newline at end of file
...@@ -22,6 +22,8 @@ using namespace std; ...@@ -22,6 +22,8 @@ using namespace std;
using namespace evutils; using namespace evutils;
using namespace jsoncons; using namespace jsoncons;
extern shared_ptr<spdlog::logger> rlogger;
recursive_mutex gMut; recursive_mutex gMut;
map<string, int> mapDirection = { map<string, int> mapDirection = {
{"left", MOTOR_MOVE_LEFT}, {"left", MOTOR_MOVE_LEFT},
...@@ -44,7 +46,7 @@ void ptz_waitfor_idle() ...@@ -44,7 +46,7 @@ void ptz_waitfor_idle()
usleep(100*1000); usleep(100*1000);
int cnt = 5 * 60; // wait for max 60s int cnt = 5 * 60; // wait for max 60s
while (cnt-- > 0) { while (cnt-- > 0) {
spdlog::info("ptz waiting"); rlogger->info("ptz waiting");
if (0 == LibXmMaQue_Motor_getPostion(&action,&x,&y)) { if (0 == LibXmMaQue_Motor_getPostion(&action,&x,&y)) {
if (MOTOR_IDLE == action) { if (MOTOR_IDLE == action) {
break; break;
...@@ -54,18 +56,18 @@ void ptz_waitfor_idle() ...@@ -54,18 +56,18 @@ void ptz_waitfor_idle()
} }
} }
else { else {
spdlog::error("ptz failed get position when waiting for idle"); rlogger->error("ptz failed get position when waiting for idle");
break; break;
} }
} }
spdlog::info("ptz end wait"); rlogger->info("ptz end wait");
} }
string ptz_service_start() string ptz_service_start()
{ {
string rc; string rc;
spdlog::info("start ptz service: calibration/re-locating"); rlogger->info("start ptz service: calibration/re-locating");
if (LibXmMaQue_Motor_create() < 0) { if (LibXmMaQue_Motor_create() < 0) {
rc = "ptz failed start service"; rc = "ptz failed start service";
return rc; return rc;
...@@ -75,7 +77,7 @@ string ptz_service_start() ...@@ -75,7 +77,7 @@ string ptz_service_start()
return rc; return rc;
} }
spdlog::info("ptz start service finished."); rlogger->info("ptz start service finished.");
return rc; return rc;
} }
...@@ -109,7 +111,7 @@ string ptz_get_params(ptz_param_position & param) ...@@ -109,7 +111,7 @@ string ptz_get_params(ptz_param_position & param)
param.step_y = y/EV_PTZ_Y_DEGREE; param.step_y = y/EV_PTZ_Y_DEGREE;
param.current_y_deg = cy / param.step_y; param.current_y_deg = cy / param.step_y;
param.current_y_steps = cy; param.current_y_steps = cy;
spdlog::info("ptz_get_params: max_x: {}, max_y: {}, current_x: {}, current_y: {}, step_x: {}, step_y: {}", param.max_x, param.max_y, param.current_x_steps, param.current_y_steps, param.step_x, param.step_y); rlogger->info("ptz_get_params: max_x: {}, max_y: {}, current_x: {}, current_y: {}, step_x: {}, step_y: {}", param.max_x, param.max_y, param.current_x_steps, param.current_y_steps, param.step_x, param.step_y);
return rc; return rc;
} }
...@@ -129,12 +131,12 @@ string ptz_save() ...@@ -129,12 +131,12 @@ string ptz_save()
js["ptz"] = json(); js["ptz"] = json();
js["ptz"]["x"] = pos.current_x_steps; js["ptz"]["x"] = pos.current_x_steps;
js["ptz"]["y"] = pos.current_y_steps; js["ptz"]["y"] = pos.current_y_steps;
spdlog::info("ptz_save current: {}", js.to_string()); rlogger->info("ptz_save current: {}", js.to_string());
rc = save_json(js, extraSysConfigFile, true, evutils::make_default_sys_extra_config); rc = save_json(js, extraSysConfigFile, true, evutils::make_default_sys_extra_config);
if(!rc.empty()) { if(!rc.empty()) {
spdlog::error(rc); rlogger->error(rc);
} }
spdlog::info("ptz_save current end: {}", js.to_string()); rlogger->info("ptz_save current end: {}", js.to_string());
return rc; return rc;
} }
...@@ -148,18 +150,18 @@ string ptz_load() ...@@ -148,18 +150,18 @@ string ptz_load()
} }
rc = save_json(js, extraSysConfigFile, false, evutils::make_default_sys_extra_config); rc = save_json(js, extraSysConfigFile, false, evutils::make_default_sys_extra_config);
if(!rc.empty()) { if(!rc.empty()) {
spdlog::error(rc); rlogger->error(rc);
return rc; return rc;
} }
auto x = js["ptz"]["x"].as<uint32_t>(); auto x = js["ptz"]["x"].as<uint32_t>();
auto y = js["ptz"]["y"].as<uint32_t>(); auto y = js["ptz"]["y"].as<uint32_t>();
rc = ptz_relocate(x, y); rc = ptz_relocate(x, y);
if(!rc.empty()) { if(!rc.empty()) {
spdlog::error(rc); rlogger->error(rc);
return rc; return rc;
} }
spdlog::info("ptz loaded"); rlogger->info("ptz loaded");
return rc; return rc;
} }
...@@ -192,9 +194,9 @@ string ptz_move(string dire, float degree) ...@@ -192,9 +194,9 @@ string ptz_move(string dire, float degree)
else { else {
curr_pos.current_y_steps = 0; curr_pos.current_y_steps = 0;
} }
spdlog::info("ptz executing: {}, {}", dire, degree); rlogger->info("ptz executing: {}, {}", dire, degree);
spdlog::info("motor moving steps: {}, {}", curr_pos.current_x_steps, curr_pos.current_y_steps ); rlogger->info("motor moving steps: {}, {}", curr_pos.current_x_steps, curr_pos.current_y_steps );
if(LibXmMaQue_Motor_move(mapDirection[dire], 6, 6, curr_pos.current_x_steps, curr_pos.current_y_steps) < 0) { if(LibXmMaQue_Motor_move(mapDirection[dire], 6, 6, curr_pos.current_x_steps, curr_pos.current_y_steps) < 0) {
rc = fmt::format("ptz failed to move {} {}: current({},{}), max({},{})", dire, degree, curr_pos.current_x_deg, curr_pos.current_y_deg, 355, 0); rc = fmt::format("ptz failed to move {} {}: current({},{}), max({},{})", dire, degree, curr_pos.current_x_deg, curr_pos.current_y_deg, 355, 0);
...@@ -235,9 +237,9 @@ string ptz_relocate(int x, int y) ...@@ -235,9 +237,9 @@ string ptz_relocate(int x, int y)
// move to origin(0,0) // move to origin(0,0)
LibXmMaQue_Motor_setZero(); LibXmMaQue_Motor_setZero();
spdlog::info("ptz set zero"); rlogger->info("ptz set zero");
ptz_waitfor_idle(); ptz_waitfor_idle();
spdlog::info("ptz set to zero"); rlogger->info("ptz set to zero");
// move to target (x,y) // move to target (x,y)
auto i = LibXmMaQue_Motor_move(mapDirection["upright"], 6, 6, targetx, targety); auto i = LibXmMaQue_Motor_move(mapDirection["upright"], 6, 6, targetx, targety);
...@@ -246,9 +248,9 @@ string ptz_relocate(int x, int y) ...@@ -246,9 +248,9 @@ string ptz_relocate(int x, int y)
return rc; return rc;
} }
spdlog::info("ptz move to center"); rlogger->info("ptz move to center");
ptz_waitfor_idle(); ptz_waitfor_idle();
spdlog::info("ptz end center"); rlogger->info("ptz end center");
return rc; return rc;
} }
\ No newline at end of file
...@@ -26,6 +26,7 @@ using namespace std; ...@@ -26,6 +26,7 @@ using namespace std;
using namespace zxing; using namespace zxing;
using namespace zxing::multi; using namespace zxing::multi;
using namespace zxing::qrcode; using namespace zxing::qrcode;
extern shared_ptr<spdlog::logger> rlogger;
/// TODO: refinment of extern /// TODO: refinment of extern
extern "C" { extern "C" {
......
...@@ -21,6 +21,8 @@ ...@@ -21,6 +21,8 @@
using namespace std; using namespace std;
extern shared_ptr<spdlog::logger> rlogger;
int _raw_connect(std::string host, std::string port, int *socket_, int recv_timeout, int send_timeout) int _raw_connect(std::string host, std::string port, int *socket_, int recv_timeout, int send_timeout)
{ {
int rv = -1; int rv = -1;
...@@ -31,12 +33,12 @@ int _raw_connect(std::string host, std::string port, int *socket_, int recv_time ...@@ -31,12 +33,12 @@ int _raw_connect(std::string host, std::string port, int *socket_, int recv_time
hints.ai_flags = AI_NUMERICSERV; // port passed as as numeric value hints.ai_flags = AI_NUMERICSERV; // port passed as as numeric value
hints.ai_protocol = 0; hints.ai_protocol = 0;
spdlog::info("raw connect: {}:{}", host, port); rlogger->info("raw connect: {}:{}", host, port);
addrinfo *addrinfo_result; addrinfo *addrinfo_result;
rv = ::getaddrinfo(host.c_str(), port.c_str(), &hints, &addrinfo_result); rv = ::getaddrinfo(host.c_str(), port.c_str(), &hints, &addrinfo_result);
if (rv != 0) { if (rv != 0) {
spdlog::error("raw_connect ::getaddrinfo failed: {}", gai_strerror(rv)); rlogger->error("raw_connect ::getaddrinfo failed: {}", gai_strerror(rv));
return rv; return rv;
} }
...@@ -53,7 +55,7 @@ int _raw_connect(std::string host, std::string port, int *socket_, int recv_time ...@@ -53,7 +55,7 @@ int _raw_connect(std::string host, std::string port, int *socket_, int recv_time
timeout.tv_sec = recv_timeout; timeout.tv_sec = recv_timeout;
timeout.tv_usec = 0; timeout.tv_usec = 0;
if (setsockopt (*socket_, SOL_SOCKET, SO_RCVTIMEO, (char *)&timeout, sizeof(timeout)) < 0) { if (setsockopt (*socket_, SOL_SOCKET, SO_RCVTIMEO, (char *)&timeout, sizeof(timeout)) < 0) {
spdlog::warn("raw_connect setsockopt SO_RCVTIMEO failed"); rlogger->warn("raw_connect setsockopt SO_RCVTIMEO failed");
continue; continue;
} }
} }
...@@ -61,7 +63,7 @@ int _raw_connect(std::string host, std::string port, int *socket_, int recv_time ...@@ -61,7 +63,7 @@ int _raw_connect(std::string host, std::string port, int *socket_, int recv_time
if(send_timeout != 0) { if(send_timeout != 0) {
timeout.tv_sec = send_timeout; timeout.tv_sec = send_timeout;
if (setsockopt (*socket_, SOL_SOCKET, SO_SNDTIMEO, (char *)&timeout, sizeof(timeout)) < 0) { if (setsockopt (*socket_, SOL_SOCKET, SO_SNDTIMEO, (char *)&timeout, sizeof(timeout)) < 0) {
spdlog::warn("raw_connect setsockopt SO_SNDTIMEO failed"); rlogger->warn("raw_connect setsockopt SO_SNDTIMEO failed");
continue; continue;
} }
} }
...@@ -74,9 +76,9 @@ int _raw_connect(std::string host, std::string port, int *socket_, int recv_time ...@@ -74,9 +76,9 @@ int _raw_connect(std::string host, std::string port, int *socket_, int recv_time
// //auto hostIp = string(inet_ntoa((struct in_addr)addr->sin_addr)); // //auto hostIp = string(inet_ntoa((struct in_addr)addr->sin_addr));
// rv = fcntl(*socket_, F_SETFL, fcntl(*socket_, F_GETFL, 0) | O_NONBLOCK); // rv = fcntl(*socket_, F_SETFL, fcntl(*socket_, F_GETFL, 0) | O_NONBLOCK);
// if (rv == -1){ // if (rv == -1){
// spdlog::error("error calling fcntl"); // rlogger->error("error calling fcntl");
// } // }
spdlog::info("raw_connect success to {}:{}", host, port); rlogger->info("raw_connect success to {}:{}", host, port);
break; break;
} }
else { else {
...@@ -84,7 +86,7 @@ int _raw_connect(std::string host, std::string port, int *socket_, int recv_time ...@@ -84,7 +86,7 @@ int _raw_connect(std::string host, std::string port, int *socket_, int recv_time
::close(*socket_); ::close(*socket_);
*socket_ = -1; *socket_ = -1;
rv = -1; rv = -1;
spdlog::warn("raw_connect failed to {}:{}", host, port); rlogger->warn("raw_connect failed to {}:{}", host, port);
} }
} }
......
差异被折叠。
...@@ -22,8 +22,6 @@ typedef struct { ...@@ -22,8 +22,6 @@ typedef struct {
static pthread_mutex_t g_mutexMem; static pthread_mutex_t g_mutexMem;
static pthread_mutexattr_t Attr; static pthread_mutexattr_t Attr;
// = PTHREAD_MUTEX_INITIALIZER;
void MaQue_Demo_Mem_Init(){ void MaQue_Demo_Mem_Init(){
pthread_mutexattr_init(&Attr); pthread_mutexattr_init(&Attr);
pthread_mutexattr_settype(&Attr, PTHREAD_MUTEX_RECURSIVE); pthread_mutexattr_settype(&Attr, PTHREAD_MUTEX_RECURSIVE);
...@@ -58,13 +56,8 @@ XM_S32 MaQue_Demo_Mem_alloc(XM_HANDLE *pHandle, MaQueMemAllocParam_s *pstAllocPa ...@@ -58,13 +56,8 @@ XM_S32 MaQue_Demo_Mem_alloc(XM_HANDLE *pHandle, MaQueMemAllocParam_s *pstAllocPa
case MAQUE_MEM_TYPE_YUV_GET: case MAQUE_MEM_TYPE_YUV_GET:
{ {
/// NOTE by Bruce: ATTENTION! we place the extr evpacket_t ahead for saving memory ops later /// NOTE by Bruce: ATTENTION! we place the extr evpacket_t ahead for saving memory ops later
#ifdef RAW_FORMAT
XM_U8 * raw = (XM_U8 *)malloc(pstAllocParam->nBufSize); XM_U8 * raw = (XM_U8 *)malloc(pstAllocParam->nBufSize);
pstMem->pBuffer = raw; pstMem->pBuffer = raw;
#else
XM_U8 * raw = (XM_U8 *)malloc(pstAllocParam->nBufSize + sizeof(evpacket_t));
pstMem->pBuffer = raw + sizeof(evpacket_t);
#endif
//printf("malloc. raw: %08X, shifted: %08X\n", (uint32_t)raw, (uint32_t)pstMem->pBuffer); //printf("malloc. raw: %08X, shifted: %08X\n", (uint32_t)raw, (uint32_t)pstMem->pBuffer);
if (raw) { if (raw) {
pstMem->index = 0xff; pstMem->index = 0xff;
...@@ -107,7 +100,6 @@ XM_S32 MaQue_Demo_Mem_release(XM_HANDLE handle) ...@@ -107,7 +100,6 @@ XM_S32 MaQue_Demo_Mem_release(XM_HANDLE handle)
return 0; return 0;
} }
#ifdef RAW_FORMAT
if(pstMem == nullptr || pstMem->pBuffer == nullptr ){ if(pstMem == nullptr || pstMem->pBuffer == nullptr ){
pthread_mutex_unlock(&g_mutexMem); pthread_mutex_unlock(&g_mutexMem);
return 0; return 0;
...@@ -128,32 +120,6 @@ XM_S32 MaQue_Demo_Mem_release(XM_HANDLE handle) ...@@ -128,32 +120,6 @@ XM_S32 MaQue_Demo_Mem_release(XM_HANDLE handle)
else{ else{
spdlog::error("shouldn't be here"); spdlog::error("shouldn't be here");
} }
#else
if(pstMem == nullptr || pstMem->pBuffer == nullptr || pstMem->pBuffer - sizeof(evpacket_t) == nullptr || pstMem->nRefCount == 0){
//printf("invalid free: %08X, %08X, %uref\n", (int)pstMem, (int)pstMem->pBuffer, pstMem->nRefCount);
pthread_mutex_unlock(&g_mutexMem);
return 0;
}
XM_U8* shifted = pstMem->pBuffer;
XM_U8* raw = shifted - sizeof(evpacket_t);
//printf("release. h:%08X, raw: %08X, shifted: %08X, %uref\n", (int)handle, (int)raw, (int)shifted, pstMem->nRefCount);
if (pstMem->nRefCount > 1) {
pstMem->nRefCount--;
}
else if (shifted && raw) {
/// NOTE by Bruce: ATTENTION!
free(raw);
free(pstMem);
}else if(pstMem->nRefCount < 0){
spdlog::error("shouldn't be here. refcnt:{}", pstMem->nRefCount);
}
else if(raw == nullptr || shifted == nullptr){
printf("BOOM! r: %08X, s: %08X\n", (int)raw, (int)shifted);
}else{
spdlog::error("shouldn't be here");
}
#endif
pthread_mutex_unlock(&g_mutexMem); pthread_mutex_unlock(&g_mutexMem);
return 0; return 0;
......
#ifndef __REF_MEMORY_H__
#define __REF_MEMORY_H__
#include <maque_type.h>
#include <maque_mem.h>
#include <pthread.h>
#include <spdlog/spdlog.h>
#include <evpacket.h>
#ifdef __cplusplus
extern "C" {
#endif
typedef struct {
XM_U8 *pBuffer;
XM_U32 nBufSize;
XM_U32 nUsedBytes;
XM_U32 nRefCount;
XM_S32 index;
} DemoMemory_s;
static pthread_mutex_t g_mutexMem;
static pthread_mutexattr_t Attr;
// = PTHREAD_MUTEX_INITIALIZER;
void MaQue_Demo_Mem_Init(){
pthread_mutexattr_init(&Attr);
pthread_mutexattr_settype(&Attr, PTHREAD_MUTEX_RECURSIVE);
pthread_mutex_init(&g_mutexMem, &Attr);
}
XM_S32 MaQue_Demo_Mem_setLength(XM_HANDLE handle, XM_U32 len)
{
pthread_mutex_lock(&g_mutexMem);
DemoMemory_s *pstMem = (DemoMemory_s *)handle;
pstMem->nUsedBytes = len;
pthread_mutex_unlock(&g_mutexMem);
return 0;
}
XM_S32 MaQue_Demo_Mem_alloc(XM_HANDLE *pHandle, MaQueMemAllocParam_s *pstAllocParam)
{
pthread_mutex_lock(&g_mutexMem);
DemoMemory_s *pstMem = NULL;
pstMem = (DemoMemory_s *)malloc(sizeof(DemoMemory_s));
memset(pstMem, 0, sizeof(*pstMem));
if (!pstMem) {
spdlog::error("malloc failed!");
pthread_mutex_unlock(&g_mutexMem);
return -1;
}
switch(pstAllocParam->eMemType) {
case MAQUE_MEM_TYPE_VIDEO_ENC:
case MAQUE_MEM_TYPE_JPEG_ENC:
case MAQUE_MEM_TYPE_YUV_GET:
{
pstMem->pBuffer = (XM_U8 *)malloc(pstAllocParam->nBufSize);
if (pstMem->pBuffer) {
pstMem->index = 0xff;
pstMem->nBufSize = pstAllocParam->nBufSize;
pstMem->nRefCount = 1;
}else {
spdlog::error("memory allocate failure");
free(pstMem);
pstMem = NULL;
}
}
break;
default:
spdlog::error("Invalid eMemType: {}", pstAllocParam->eMemType);
break;
}
if (!pstMem) {
spdlog::error("alloc failed");
pthread_mutex_unlock(&g_mutexMem);
return -1;
}
*pHandle = (XM_HANDLE)pstMem;
pstAllocParam->pBuffer = pstMem->pBuffer;
pthread_mutex_unlock(&g_mutexMem);
return 0;
}
XM_S32 MaQue_Demo_Mem_release(XM_HANDLE handle)
{
if(handle == 0){
return 0;
}
pthread_mutex_lock(&g_mutexMem);
DemoMemory_s *pstMem = (DemoMemory_s *)handle;
if (!handle) {
pthread_mutex_unlock(&g_mutexMem);
return 0;
}
if(pstMem == nullptr || pstMem->pBuffer == nullptr ||pstMem->nRefCount == 0){
//printf("invalid free: %08X, %08X, %uref\n", (int)pstMem, (int)pstMem->pBuffer, pstMem->nRefCount);
pthread_mutex_unlock(&g_mutexMem);
return 0;
}
if (pstMem->nRefCount > 1) {
pstMem->nRefCount--;
}
else if (pstMem->pBuffer) {
/// NOTE by Bruce: ATTENTION!
free(pstMem->pBuffer);
free(pstMem);
}else if(pstMem->nRefCount < 0){
spdlog::error("shouldn't be here. refcnt:{}", pstMem->nRefCount);
}
else if(pstMem->pBuffer == nullptr){
printf("BOOM! r: %08X\n", (int)pstMem->pBuffer);
}else{
spdlog::error("shouldn't be here");
}
pthread_mutex_unlock(&g_mutexMem);
return 0;
}
XM_S32 MaQue_Demo_Mem_addRef(XM_HANDLE handle)
{
pthread_mutex_lock(&g_mutexMem);
DemoMemory_s *pstMem = (DemoMemory_s *)handle;
// memory already released
if(!handle) {
pthread_mutex_unlock(&g_mutexMem);
spdlog::error("BOOM! ar");
return -1;
}
pstMem->nRefCount += 1;
pthread_mutex_unlock(&g_mutexMem);
return 0;
}
#ifdef __cplusplus
}
#endif
#endif
\ No newline at end of file
#ifndef _RTSP_RTP_H
#define _RTSP_RTP_H
#endif
差异被折叠。
差异被折叠。
do
{
ret = send(sock, pmsg, len, 0);
if (ret == -1)
{
err = getLastSocketError();
if (
(err == EWOULDBLOCK) || (err == EAGAIN)
)
{
fd_set wfd;
FD_ZERO(&wfd);
FD_SET(sock, &wfd);
timeval timeout;
timeout.tv_sec = ...;
timeout.tv_usec = ...;
ret = select(
sock+1
, NULL, &wfd, NULL, &timeout);
if (ret > 0)
continue;
if (ret == 0)
{
printf("*J* Send Timeout\n");
// handle timeout as needed ...
return;
}
err = getLastSocketError();
}
{
printf("*J* Send Failed: %d\n", err);
// handle fatal error as needed ...
return;
}
}
else
{
pmsg += ret;
len -= ret;
}
}
while (len > 0);
\ No newline at end of file
差异被折叠。
差异被折叠。
...@@ -19,6 +19,9 @@ link_directories(${COMMON_LIB_DIR}) ...@@ -19,6 +19,9 @@ link_directories(${COMMON_LIB_DIR})
add_executable(vgw videogateway.cc) add_executable(vgw videogateway.cc)
target_link_libraries(vgw PUBLIC ${VGW_LIBS} ${COMM_LIBS}) target_link_libraries(vgw PUBLIC ${VGW_LIBS} ${COMM_LIBS})
add_executable(test_proxy test_proxy.cc)
target_link_libraries(test_proxy PUBLIC ${COMM_LIBS})
# add_executable(test_mqtt test_mqtt_rd.cc) # add_executable(test_mqtt test_mqtt_rd.cc)
# target_link_libraries(test_mqtt PUBLIC ${COMM_LIBS}) # target_link_libraries(test_mqtt PUBLIC ${COMM_LIBS})
......
差异被折叠。
差异被折叠。
File mode changed from 100755 to 100644
libzmq @ a84ffa12
Subproject commit a84ffa12b2eb3569ced199660bac5ad128bff1f0
# libzmq.la - a libtool library file # libzmq.la - a libtool library file
# Generated by libtool (GNU libtool) 2.4.6 Debian-2.4.6-2 # Generated by libtool (GNU libtool) 2.4.2 Debian-2.4.2-1.7ubuntu1
# #
# Please DO NOT delete this file! # Please DO NOT delete this file!
# It is necessary for linking the library. # It is necessary for linking the library.
...@@ -13,7 +13,7 @@ library_names='libzmq.so.5.2.2 libzmq.so.5 libzmq.so' ...@@ -13,7 +13,7 @@ library_names='libzmq.so.5.2.2 libzmq.so.5 libzmq.so'
# The name of the static archive. # The name of the static archive.
old_library='libzmq.a' old_library='libzmq.a'
# Linker flags that cannot go in dependency_libs. # Linker flags that can not go in dependency_libs.
inherited_linker_flags='' inherited_linker_flags=''
# Libraries that this one depends upon. # Libraries that this one depends upon.
...@@ -38,4 +38,4 @@ dlopen='' ...@@ -38,4 +38,4 @@ dlopen=''
dlpreopen='' dlpreopen=''
# Directory that this library needs to be installed in: # Directory that this library needs to be installed in:
libdir='/mnt/shared/evcamera/vendor/libzmq../x64/lib' libdir='/mnt/shared/evcamera/vendor/x64/lib'
prefix=/mnt/shared/evcamera/vendor/libzmq../x64 prefix=/mnt/shared/evcamera/vendor/x64
exec_prefix=${prefix} exec_prefix=${prefix}
libdir=${exec_prefix}/lib libdir=${exec_prefix}/lib
includedir=${prefix}/include includedir=${prefix}/include
...@@ -9,4 +9,4 @@ Version: 4.3.2 ...@@ -9,4 +9,4 @@ Version: 4.3.2
Libs: -L${libdir} -lzmq Libs: -L${libdir} -lzmq
Libs.private: -lstdc++ -lpthread -lrt Libs.private: -lstdc++ -lpthread -lrt
Requires.private: Requires.private:
Cflags: -I${includedir} -DZMQ_BUILD_DRAFT_API=1 Cflags: -I${includedir}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论