From e5cff5a3ef373a5090f45cd1dfb0b85d9c851d5d Mon Sep 17 00:00:00 2001 From: FuJuntang <strongtiger_001@163.com> Date: 星期三, 06 七月 2022 10:04:09 +0800 Subject: [PATCH] Add video recorder and playback support. --- comm/proto_comm.c | 146 ++++++++++++++++++++++++++++++++---------------- 1 files changed, 97 insertions(+), 49 deletions(-) diff --git a/comm/proto_comm.c b/comm/proto_comm.c index df226ca..21c3c26 100644 --- a/comm/proto_comm.c +++ b/comm/proto_comm.c @@ -1,73 +1,131 @@ - #include <stdio.h> #include <stdlib.h> #include <assert.h> +#include <time.h> +#include <signal.h> + #include "proto_comm.h" #include "proto_dbg.h" +int timer_init(timer_t *timer_index, void (*timer_handler)(union sigval para)) { + struct sigevent event; + timer_t timer; + int ret; + + memset(&event, 0x00, sizeof(event)); + event.sigev_value.sival_int = ENABLE; + event.sigev_value.sival_ptr = NULL; + event.sigev_notify = SIGEV_THREAD; + event.sigev_notify_function = timer_handler; + + ret = timer_create(CLOCK_REALTIME, &event, &timer); + if (ret) { + return -1; + } + + if (timer_index != NULL) { + *timer_index = timer; + } + + return 0; +} + +int timer_start(timer_t timer_index, int sec) { + int ret; + struct itimerspec ts; + + ts.it_interval.tv_sec = 0; + ts.it_interval.tv_nsec = 0; + ts.it_value.tv_sec = sec; + ts.it_value.tv_nsec = 0; + ret = timer_settime(timer_index, 0, &ts, NULL); + if (ret) { + return -1; + } + + return ret; +} + +int timer_stop(timer_t timer_index) { + + int ret = timer_start(timer_index, 0); + + return ret; +} + +int timer_destroy(timer_t timer_index) { + int ret; + + ret = timer_delete(timer_index); + + return ret; +} + void soap_perror(struct soap *soap, const char *str) { - if (NULL == str) { - SOAP_DBGERR("[soap] error: %d, %s, %s\n", soap->error, *soap_faultcode(soap), *soap_faultstring(soap)); - } else { - SOAP_DBGERR("[soap] %s error: %d, %s, %s\n", str, soap->error, *soap_faultcode(soap), *soap_faultstring(soap)); - } - return; + if (NULL == str) { + SOAP_DBGERR("[soap] error: %d, %s, %s\n", soap->error, *soap_faultcode(soap), *soap_faultstring(soap)); + } else { + SOAP_DBGERR("[soap] %s error: %d, %s, %s\n", str, soap->error, *soap_faultcode(soap), *soap_faultstring(soap)); + } + + return; } void* proto_soap_malloc(struct soap *soap, unsigned int n) { - void *p = NULL; + void *p = NULL; - if (n > 0) { - p = soap_malloc(soap, n); - SOAP_ASSERT(NULL != p); - memset(p, 0x00 ,n); - } - return p; + if (n > 0) { + p = soap_malloc(soap, n); + SOAP_ASSERT(NULL != p); + memset(p, 0x00 ,n); + } + + return p; } struct soap *proto_soap_new(int timeout) { - struct soap *soap = NULL; // soap环境变量 + struct soap *soap = NULL; - SOAP_ASSERT(NULL != (soap = soap_new())); + SOAP_ASSERT(NULL != (soap = soap_new())); - soap_set_namespaces(soap, namespaces); // 设置soap的namespaces - soap->recv_timeout = timeout; - soap->send_timeout = timeout; - soap->connect_timeout = timeout; + soap_set_namespaces(soap, namespaces); + soap->recv_timeout = timeout; + soap->send_timeout = timeout; + soap->connect_timeout = timeout; #if defined(__linux__) || defined(__linux) - soap->socket_flags = MSG_NOSIGNAL; + soap->socket_flags = MSG_NOSIGNAL; #endif - soap_set_mode(soap, SOAP_C_UTFSTRING); + soap_set_mode(soap, SOAP_C_UTFSTRING); - return soap; + return soap; } void proto_soap_delete(struct soap *soap) { - soap_destroy(soap); // remove deserialized class instances (C++ only) - soap_end(soap); // Clean up deserialized data (except class instances) and temporary data - soap_done(soap); // Reset, close communications, and remove callbacks - soap_free(soap); // Reset and deallocate the context created with soap_new or soap_copy + soap_destroy(soap); // remove deserialized class instances (C++ only) + soap_end(soap); // Clean up deserialized data (except class instances) and temporary data + soap_done(soap); // Reset, close communications, and remove callbacks + soap_free(soap); // Reset and deallocate the context created with soap_new or soap_copy } int proto_SetAuthInfo(struct soap *soap, const char *username, const char *password) { - int result = 0; + int result = 0; - SOAP_ASSERT(NULL != username); - SOAP_ASSERT(NULL != password); + SOAP_ASSERT(NULL != username); + SOAP_ASSERT(NULL != password); - result = soap_wsse_add_UsernameTokenDigest(soap, NULL, username, password); - SOAP_CHECK_ERROR(result, soap, "add_UsernameTokenDigest"); + result = soap_wsse_add_UsernameTokenDigest(soap, NULL, username, password); + SOAP_CHECK_ERROR(result, soap, "add_UsernameTokenDigest"); EXIT: - return result; + return result; } float para_check(float data) @@ -85,11 +143,6 @@ return ret; } -/************************************************************************ - *初始化soap描述消息头 - - *在本函数内部通过proto_soap_malloc分配的内存,将在proto_soap_delete中被释放 -************************************************************************/ void proto_init_header(struct soap *soap) { struct SOAP_ENV__Header *header = NULL; @@ -109,27 +162,22 @@ return; } -/************************************************************************ - *初始化探测设备的范围和类型 - - *在本函数内部通过proto_soap_malloc分配的内存,将在proto_soap_delete中被释放 -************************************************************************/ void proto_init_ProbeType(struct soap *soap, struct wsdd__ProbeType *probe) { - struct wsdd__ScopesType *scope = NULL; // 用于描述查找哪类的Web服务 + struct wsdd__ScopesType *scope = NULL; SOAP_ASSERT(NULL != soap); SOAP_ASSERT(NULL != probe); scope = (struct wsdd__ScopesType *)proto_soap_malloc(soap, sizeof(struct wsdd__ScopesType)); - soap_default_wsdd__ScopesType(soap, scope); // 设置寻找设备的范围 + soap_default_wsdd__ScopesType(soap, scope); scope->__item = (char*)proto_soap_malloc(soap, strlen(SOAP_ITEM) + 1); strcpy(scope->__item, SOAP_ITEM); memset(probe, 0x00, sizeof(struct wsdd__ProbeType)); soap_default_wsdd__ProbeType(soap, probe); probe->Scopes = scope; - probe->Types = (char*)proto_soap_malloc(soap, strlen(SOAP_TYPES) + 1); // 设置寻找设备的类型 + probe->Types = (char*)proto_soap_malloc(soap, strlen(SOAP_TYPES) + 1); strcpy(probe->Types, SOAP_TYPES); return; @@ -139,7 +187,7 @@ *rtsp://100.100.100.140:554/av0_0 *rtsp://username:password@100.100.100.140:554/av0_0 ************************************************************************/ -int make_uri_withauth(char *src_uri, char *username, char *password, char *dest_uri, unsigned int size_dest_uri) +int bridge_uri(char *src_uri, const char *username, const char *password, char *dest_uri, unsigned int size_dest_uri) { int result = 0; unsigned int needBufSize = 0; @@ -150,14 +198,14 @@ SOAP_ASSERT(NULL != dest_uri); memset(dest_uri, 0x00, size_dest_uri); - needBufSize = strlen(src_uri) + strlen(username) + strlen(password) + 3; // 检查缓存是否足够,包括‘:’和‘@’和字符串结束符 + needBufSize = strlen(src_uri) + strlen(username) + strlen(password) + 3; //check buf size with character ‘:’ and ‘@' if (size_dest_uri < needBufSize) { SOAP_DBGERR("dest uri buf size is not enough.\n"); result = -1; goto EXIT; } - if (0 == strlen(username) && 0 == strlen(password)) { // 生成新的uri地址 + if (0 == strlen(username) && 0 == strlen(password)) { strcpy(dest_uri, src_uri); } else { char *p = strstr(src_uri, "//"); -- Gitblit v1.8.0