int main(int argc, char** argv) { PORT_USERDATA userdata; MMAL_STATUS_T status; cairo_surface_t *surface,*surface2; cairo_t *context,*context2; int i; int duration = 1; int valid = 1; char text[256]; strcpy (text,"Camera 1"); for (i = 1; i < argc && valid; i++) { if (strcmp(argv[i], "-s")==0) { strcpy(text, argv[i + 1]); i++; } if (strcmp(argv[i], "-t")==0) { sscanf(argv[i + 1], "%u", &duration); i++; } if (strcmp(argv[i], "-d")==0) { } } //fprintf(stderr, "CAPTION : %s\n", text); duration = 3; memset(&userdata, 0, sizeof (PORT_USERDATA)); userdata.width = VIDEO_WIDTH; userdata.height = VIDEO_HEIGHT; userdata.fps = 0.0; //fprintf(stderr, "VIDEO_WIDTH : %i\n", userdata.width ); //fprintf(stderr, "VIDEO_HEIGHT: %i\n", userdata.height ); //fprintf(stderr, "VIDEO_FPS : %i\n", VIDEO_FPS); //fprintf(stderr, "Running...\n"); bcm_host_init(); surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 600, 100); context = cairo_create(surface); cairo_rectangle(context, 0.0, 0.0, 600, 100); cairo_set_source_rgba(context, 0.0, 0.0, 0.0, 1.0); cairo_fill(context); userdata.overlay_buffer = cairo_image_surface_get_data(surface); userdata.overlay = 1; surface2 = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 600, 100); context2 = cairo_create(surface2); cairo_rectangle(context2, 0.0, 0.0, 600, 100); cairo_set_source_rgba(context2, 0.0, 0.0, 0.0, 1.0); cairo_fill(context2); userdata.overlay_buffer2 = cairo_image_surface_get_data(surface2); if (1 && setup_camera(&userdata) != 0) { fprintf(stderr, "Error: setup camera %x\n", status); return -1; } if (1 && setup_encoder(&userdata) != 0) { fprintf(stderr, "Error: setup encoder %x\n", status); return -1; } if (1 && setup_preview(&userdata) != 0) { fprintf(stderr, "Error: setup preview %x\n", status); return -1; } while (duration >0) { //Update Draw to unused buffer that way there is no flickering of the overlay text if the overlay update rate //and video FPS are not the same if (userdata.overlay == 1) { cairo_rectangle(context, 0.0, 0.0, 600, 100); cairo_set_source_rgba(context, 0.0, 0.0, 0.0, 1.0); cairo_fill(context); cairo_move_to(context, 0.0, 0.0); cairo_set_source_rgba(context, 1.0, 1.0, 1.0, 1.0); cairo_move_to(context, 0.0, 30.0); cairo_set_font_size(context, 20.0); //sprintf(text, "%.2fFPS GPS: %.3f, %.3f Speed %.1fkm/h b0", userdata.fps,lat,lon,speed); cairo_show_text(context, text); userdata.overlay = 0; } else { cairo_rectangle(context2, 0.0, 0.0, 600, 100); cairo_set_source_rgba(context2, 0.0, 0.0, 0.0, 1.0); cairo_fill(context2); cairo_move_to(context2, 0.0, 0.0); cairo_set_source_rgba(context2, 1.0, 1.0, 1.0, 1.0); cairo_move_to(context2, 0.0, 30.0); cairo_set_font_size(context2, 20.0); //sprintf(text, "%.2fFPS GPS: %.3f, %.3f Speed %.1fkm/h b1", userdata.fps,lat,lon,speed); //sprintf(text, "%.2fFPS GPS: 0.00000, 0.00000 Speed 0km/h b1", userdata.fps); cairo_show_text(context2, text); userdata.overlay = 1; } duration--; usleep(30000); } return 0; }
int main(int argc, char** argv) { PORT_USERDATA userdata; MMAL_STATUS_T status; cairo_surface_t *surface,*surface2; cairo_t *context,*context2; memset(&userdata, 0, sizeof (PORT_USERDATA)); userdata.width = VIDEO_WIDTH; userdata.height = VIDEO_HEIGHT; userdata.fps = 0.0; fprintf(stderr, "VIDEO_WIDTH : %i\n", userdata.width ); fprintf(stderr, "VIDEO_HEIGHT: %i\n", userdata.height ); fprintf(stderr, "VIDEO_FPS : %i\n", VIDEO_FPS); fprintf(stderr, "Running...\n"); bcm_host_init(); surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 600, 100); context = cairo_create(surface); cairo_rectangle(context, 0.0, 0.0, 600, 100); cairo_set_source_rgba(context, 0.0, 0.0, 0.0, 1.0); cairo_fill(context); userdata.overlay_buffer = cairo_image_surface_get_data(surface); userdata.overlay = 1; surface2 = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 600, 100); context2 = cairo_create(surface2); cairo_rectangle(context2, 0.0, 0.0, 600, 100); cairo_set_source_rgba(context2, 0.0, 0.0, 0.0, 1.0); cairo_fill(context2); userdata.overlay_buffer2 = cairo_image_surface_get_data(surface2); if (1 && setup_camera(&userdata) != 0) { fprintf(stderr, "Error: setup camera %x\n", status); return -1; } if (1 && setup_encoder(&userdata) != 0) { fprintf(stderr, "Error: setup encoder %x\n", status); return -1; } if (1 && setup_preview(&userdata) != 0) { fprintf(stderr, "Error: setup preview %x\n", status); return -1; } char text[256]; //fake Speed and GPS data float lat = 47.4912; float lon = 8.906; float speed = 20.0; while (1) { //Update Draw to unused buffer that way there is no flickering of the overlay text if the overlay update rate //and video FPS are not the same if (userdata.overlay == 1) { cairo_rectangle(context, 0.0, 0.0, 600, 100); cairo_set_source_rgba(context, 0.0, 0.0, 0.0, 1.0); cairo_fill(context); cairo_move_to(context, 0.0, 0.0); cairo_set_source_rgba(context, 1.0, 1.0, 1.0, 1.0); cairo_move_to(context, 0.0, 30.0); cairo_set_font_size(context, 20.0); sprintf(text, "%.2fFPS GPS: %.3f, %.3f Speed %.1fkm/h b0", userdata.fps,lat,lon,speed); cairo_show_text(context, text); userdata.overlay = 0; } else { cairo_rectangle(context2, 0.0, 0.0, 600, 100); cairo_set_source_rgba(context2, 0.0, 0.0, 0.0, 1.0); cairo_fill(context2); cairo_move_to(context2, 0.0, 0.0); cairo_set_source_rgba(context2, 1.0, 1.0, 1.0, 1.0); cairo_move_to(context2, 0.0, 30.0); cairo_set_font_size(context2, 20.0); sprintf(text, "%.2fFPS GPS: %.3f, %.3f Speed %.1fkm/h b1", userdata.fps,lat,lon,speed); //sprintf(text, "%.2fFPS GPS: 0.00000, 0.00000 Speed 0km/h b1", userdata.fps); cairo_show_text(context2, text); userdata.overlay = 1; } lat += 0.01; lon += 0.01; speed += 0.1; usleep(30000); } return 0; }