|
@@ -4,10 +4,84 @@
|
|
|
|
|
|
#include <json/reader.h>
|
|
|
#include <json/writer.h>
|
|
|
+#include <sys/stat.h>
|
|
|
#include "video_similarity.h"
|
|
|
|
|
|
|
|
|
+const int MAX_STACK_FRAMES = 128;
|
|
|
+
|
|
|
+void sig_crash(int sig) {
|
|
|
+ FILE *fd;
|
|
|
+ struct stat buf;
|
|
|
+ stat("./crash.log", &buf);
|
|
|
+ if (buf.st_size > 10 * 1000 * 1000) { // 超过10兆则清空内容
|
|
|
+ fd = fopen("/datalog/crash.log", "w");
|
|
|
+ } else {
|
|
|
+ fd = fopen("/datalog/crash.log", "at");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (NULL == fd) {
|
|
|
+ exit(0);
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ char szLine[512] = {0,};
|
|
|
+ time_t t = time(NULL);
|
|
|
+ tm *now = localtime(&t);
|
|
|
+ int nLen1 = sprintf(szLine,
|
|
|
+ "#########################################################\n[%04d-%02d-%02d %02d:%02d:%02d][crash signal number:%d]\n",
|
|
|
+ now->tm_year + 1900,
|
|
|
+ now->tm_mon + 1,
|
|
|
+ now->tm_mday,
|
|
|
+ now->tm_hour,
|
|
|
+ now->tm_min,
|
|
|
+ now->tm_sec,
|
|
|
+ sig);
|
|
|
+ fwrite(szLine, 1, strlen(szLine), fd);
|
|
|
+#ifdef __linux
|
|
|
+ void* array[MAX_STACK_FRAMES];
|
|
|
+ size_t size = 0;
|
|
|
+ char** strings = NULL;
|
|
|
+ size_t i, j;
|
|
|
+ signal(sig, SIG_DFL);
|
|
|
+ size = backtrace(array, MAX_STACK_FRAMES);
|
|
|
+ strings = (char**)backtrace_symbols(array, size);
|
|
|
+ //fprintf(stderr, "oncrash;\n");
|
|
|
+ for (i = 0; i < size; ++i)
|
|
|
+ {
|
|
|
+ char szLine[512] = {0, };
|
|
|
+ sprintf(szLine, "%d %s\n", i, strings[i]);
|
|
|
+ fwrite(szLine, 1, strlen(szLine), fd);
|
|
|
+
|
|
|
+ std::string symbol(strings[i]);
|
|
|
+ size_t pos1 = symbol.find_first_of("[");
|
|
|
+ size_t pos2 = symbol.find_last_of("]");
|
|
|
+ std::string address = symbol.substr(pos1 + 1, pos2 - pos1 -1);
|
|
|
+ char cmd[128] = {0, };
|
|
|
+ sprintf(cmd, "addr2line -e test %s", address.c_str()); // test为应用程序名称,需要改为用户自己的应用程序名
|
|
|
+ FILE *fPipe = popen(cmd, "r");
|
|
|
+ if(fPipe != NULL){
|
|
|
+ char buff[1024];
|
|
|
+ memset(buff, 0, sizeof(buff));
|
|
|
+ char* ret = fgets(buff, sizeof(buff), fPipe);
|
|
|
+ pclose(fPipe);
|
|
|
+ fwrite(ret, 1, strlen(ret), fd);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ free(strings);
|
|
|
+#endif // __linux
|
|
|
+ }catch (...) {
|
|
|
+ //
|
|
|
+ }
|
|
|
+ signal(sig, SIG_DFL);
|
|
|
+ fflush(fd);
|
|
|
+ fclose(fd);
|
|
|
+ fd = NULL;
|
|
|
+ exit(0);
|
|
|
+}
|
|
|
+
|
|
|
long video_similarity_detection_init(const char *url) {
|
|
|
+ signal(SIGABRT, sig_crash);
|
|
|
+ signal(SIGSEGV, sig_crash);
|
|
|
auto *ctx = (VideoSimilarityContext *) malloc(sizeof(VideoSimilarityContext));
|
|
|
if (!ctx)return -1;
|
|
|
memset(ctx, 0, sizeof(VideoSimilarityContext));
|
|
@@ -205,16 +279,18 @@ const char *get_video_similarity_list(const char *inputjson) {
|
|
|
const char *name = GetFileName(((VideoSimilarityContext *) id)->video_path, n); //把字符串及其长度传给函数
|
|
|
printf("%s\n", name); //name就是那个名称,可以输出
|
|
|
char args[512];
|
|
|
-// sprintf(args, "/Users/devyk/Data/Project/sample/github_code/OpenCVSample/temp/%s.log",name);
|
|
|
- sprintf(args, "/datalog/ffmpeg_opencv/%s.log", name);
|
|
|
+ sprintf(args, "/Users/devyk/Data/Project/sample/github_code/OpenCVSample/temp/%s.log", name);
|
|
|
+// sprintf(args, "/datalog/ffmpeg_opencv/%s.log", name);
|
|
|
((VideoSimilarityContext *) id)->log = fopen(args, "wb+");
|
|
|
printf("args===%s \n", args);
|
|
|
if (((VideoSimilarityContext *) id)->log)fprintf(((VideoSimilarityContext *) id)->log, inputjson);
|
|
|
}
|
|
|
- if (((VideoSimilarityContext *) id)->log)fprintf(((VideoSimilarityContext *) id)->log, "video_similarity_detection_start \n");
|
|
|
+ if (((VideoSimilarityContext *) id)->log)
|
|
|
+ fprintf(((VideoSimilarityContext *) id)->log, "video_similarity_detection_start \n");
|
|
|
video_similarity_detection_start(id, 0, AUDIO,
|
|
|
&vs->clips);
|
|
|
- if (((VideoSimilarityContext *) id)->log)fprintf(((VideoSimilarityContext *) id)->log, "video_similarity_detection_start exit \n");
|
|
|
+ if (((VideoSimilarityContext *) id)->log)
|
|
|
+ fprintf(((VideoSimilarityContext *) id)->log, "video_similarity_detection_start exit \n");
|
|
|
video_similarity_detection_close(id);
|
|
|
ret_json = videoSimilarity2json(vs);
|
|
|
delete vs;
|