// get next frame void CameraMJPG::update() { int res = 0; // remove previous frame remove_frame(); // get image while(!frame){ if( (res = read_data(buf_read.data, buf_read.real_size))>0 ) get_image(buf_read.data, res); else break; } if (!frame) { printf("[!][CameraMJPG][update] Error: cant get frame!\n"); reconnect(); // переподключение return; } if(show_capture) { cvShowImage(window_name, frame); } }
static void add_frameFromTupleInt (const Tuple * tuple, int field, int id3_field, GHashTable * dict) { if (tuple_get_value_type (tuple, field) != TUPLE_INT) { remove_frame (id3_field, dict); return; } char scratch[16]; str_itoa (tuple_get_int (tuple, field), scratch, sizeof scratch); add_text_frame (id3_field, scratch, dict); }
static void add_frameFromTupleInt (const Tuple * tuple, gint field, gint id3_field, mowgli_dictionary_t * dict) { if (tuple_get_value_type (tuple, field, NULL) != TUPLE_INT) { remove_frame (id3_field, dict); return; } gchar scratch[16]; snprintf (scratch, sizeof scratch, "%d", tuple_get_int (tuple, field, NULL)); add_text_frame (id3_field, scratch, dict); }
static void add_text_frame (int id, const char * text, GHashTable * dict) { if (text == NULL) { remove_frame (id, dict); return; } TAGDBG ("Adding text frame %s = %s.\n", id3_frames[id], text); int length = strlen (text); GenericFrame * frame = add_generic_frame (id, length + 1, dict); frame->data[0] = 3; /* UTF-8 encoding */ memcpy (frame->data + 1, text, length); }
static void add_comment_frame (const char * text, GHashTable * dict) { if (text == NULL) { remove_frame (ID3_COMMENT, dict); return; } TAGDBG ("Adding comment frame = %s.\n", text); int length = strlen (text); GenericFrame * frame = add_generic_frame (ID3_COMMENT, length + 5, dict); frame->data[0] = 3; /* UTF-8 encoding */ strcpy ((char *) frame->data + 1, "eng"); /* well, it *might* be English */ memcpy (frame->data + 5, text, length); }
static char* send_frame(Frame *f, int sym, Bool swap) { Frame *fp; SET(fp); switch(sym) { case LUP: fp = f->aprev; if(!fp) return Ebadvalue; fp = fp->aprev; break; case LDOWN: fp = f->anext; if(!fp) return Ebadvalue; break; default: assert(!"can't get here"); } if(swap) { if(!fp) return Ebadvalue; swap_frames(f, fp); }else { remove_frame(f); insert_frame(fp, f); } arrange_view(f->view); flushevents(EnterWindowMask, False); focus_frame(f, True); update_views(); return nil; }
// find image in buffer int CameraMJPG::cut_image(char* buffer, int length) { if(!buffer || length<=0) return 1; // find MIME header if( find_data_in_buffer(buffer, length, CAMERA_MJPG_MIME_CONTENT_TYPE_JPEG, CAMERA_MJPG_MIME_CONTENT_TYPE_JPEG_SIZE) != 0 ) { //printf("[i][CameraMJPG][cut_image] Image header!\n"); // get message with image size const char* pdest1 = find_data_in_buffer(buffer, length, CAMERA_MJPG_MIME_CONTENT_LENGTH, CAMERA_MJPG_MIME_CONTENT_LENGTH_SIZE); pdest1 += CAMERA_MJPG_MIME_CONTENT_LENGTH_SIZE; const char* pdest2 = strstr(pdest1, "\r\n\r\n"); int str_len = pdest2 - pdest1; if (str_len > 128){ printf("[!][CameraMJPG][cut_image] Error: image size error!\n"); str_len = 128; } char str_size[128]; memcpy(str_size, pdest1, str_len); str_size[str_len] = 0; int size = atoi(str_size); // printf("[i][CameraMJPG][cut_image] image size: %d \n", size); if(size > buf_video.real_size) printf("[!][CameraMJPG][cut_image] Warning: too big image: %d !\n", size); // get data length int recv_len = length - (pdest2 - buffer + 4); // pointer to image data const char* pimage = pdest2 + 4; // not all image in buffer if (recv_len < size){ return 2; } // // got image! // image_counter++; #if CAMERA_MJPG_SAVE_JPEG_IMAGE // // save JPEG into file // char file[128]; snprintf(file, 128, "image%02d.jpg", imageCounter); writeBufferToFile(file, pimage, size); #endif //#if VIDEOSERVER_SAVE_JPEG_IMAGE remove_frame(); #if defined(USE_OPENCV) // // unpack JPEG-image // frame = decompress_image(pimage, size); #else frame = new char[size]; if(frame){ memcpy(frame, pimage, size); frame_size = size; } else{ printf("[!][cut_image][cut_image] Error: cant allocate memory!\n"); } #endif // #if defined(USE_OPENCV) #if 0 // reset buffer buf_video.zero(); #else int i, j; for(j=0, i=(pimage-buffer)+size; i<length; i++, j++){ buf_video.data[j] = buf_video.data[i]; } buf_video.size = j; #endif return 0; } return 3; }
int main(int argc, char *argv[]) { const char *term = getenv("TERM"); const char *home = getenv("HOME"); const char *tag = NULL; const char *rc = NULL; const char *command = NULL; char *command_history_filename; char *search_history_filename; char *editor_dir; bool read_rc = true; int i; if (!home) home = ""; home_dir = xstrdup(home); for (i = 1; i < argc; i++) { const char *opt = argv[i]; if (opt[0] != '-' || !opt[1]) break; if (!opt[2]) { switch (opt[1]) { case 'R': read_rc = false; continue; case 't': tag = opt_arg(opt, argv[++i]); continue; case 'r': rc = opt_arg(opt, argv[++i]); continue; case 'c': command = opt_arg(opt, argv[++i]); continue; case 'V': printf("%s %s\nWritten by Timo Hirvonen\n", program, version); return 0; } if (opt[1] == '-') { i++; break; } } printf("Usage: %s [-R] [-V] [-c command] [-t tag] [-r rcfile] [file]...\n", argv[0]); return 1; } if (!isatty(1)) { fprintf(stderr, "stdout doesn't refer to a terminal\n"); return 1; } if (term == NULL || term[0] == 0) { fprintf(stderr, "TERM not set\n"); return 1; } switch (term_init(term)) { case -1: fprintf(stderr, "terminal is hardcopy\n"); return 1; case -2: fprintf(stderr, "terminal could not be found\n"); return 1; case -3: fprintf(stderr, "terminfo database could not be found\n"); return 1; } // create this early. needed if lock-files is true editor_dir = editor_file(""); mkdir(editor_dir, 0755); free(editor_dir); setlocale(LC_CTYPE, ""); charset = nl_langinfo(CODESET); if (streq(charset, "UTF-8")) term_utf8 = true; exec_builtin_rc(builtin_rc); fill_builtin_colors(); // NOTE: syntax_changed() uses window. should possibly create window after reading rc window = new_window(); root_frame = new_root_frame(window); if (read_rc) { if (rc) { read_config(commands, rc, true); } else { char *filename = editor_file("rc"); if (read_config(commands, filename, false)) { free(filename); filename = xsprintf("%s/rc", pkgdatadir); read_config(commands, filename, true); } free(filename); } } update_all_syntax_colors(); sort_aliases(); /* Terminal does not generate signals for control keys. */ set_signal_handler(SIGINT, SIG_IGN); set_signal_handler(SIGQUIT, SIG_IGN); set_signal_handler(SIGPIPE, SIG_IGN); /* Terminal does not generate signal for ^Z but someone can send * us SIGTSTP nevertheless. SIGSTOP can't be caught. */ set_signal_handler(SIGTSTP, handle_sigtstp); set_signal_handler(SIGCONT, handle_sigcont); set_signal_handler(SIGWINCH, handle_sigwinch); load_file_history(); command_history_filename = editor_file("command-history"); search_history_filename = editor_file("search-history"); history_load(&command_history, command_history_filename, command_history_size); history_load(&search_history, search_history_filename, search_history_size); if (search_history.count) search_set_regexp(search_history.ptrs[search_history.count - 1]); /* Initialize terminal but don't update screen yet. Also display * "Press any key to continue" prompt if there were any errors * during reading configuration files. */ term_raw(); if (nr_errors) { any_key(); clear_error(); } editor_status = EDITOR_RUNNING; for (; i < argc; i++) window_open_buffer(window, argv[i], false, NULL); if (window->views.count == 0) window_open_empty_buffer(window); set_view(window->views.ptrs[0]); if (command || tag) resize(); if (command) handle_command(commands, command); if (tag) { PTR_ARRAY(array); ptr_array_add(&array, xstrdup("tag")); ptr_array_add(&array, xstrdup(tag)); ptr_array_add(&array, NULL); run_commands(commands, &array); ptr_array_free(&array); } resize(); main_loop(); ui_end(); // unlock files and add files to file history remove_frame(root_frame); history_save(&command_history, command_history_filename); history_save(&search_history, search_history_filename); free(command_history_filename); free(search_history_filename); save_file_history(); return 0; }