static int config_output(AVFilterLink *outlink) { AVFilterContext *ctx = outlink->src; int ret; if (ctx->nb_inputs) { AVFilterLink *inlink = ctx->inputs[0]; outlink->format = inlink->format; outlink->sample_rate = inlink->sample_rate; if (ctx->nb_inputs == ctx->nb_outputs) { outlink->channel_layout = inlink->channel_layout; outlink->channels = inlink->channels; } ret = 0; } else { LADSPAContext *s = ctx->priv; outlink->sample_rate = s->sample_rate; outlink->time_base = (AVRational){1, s->sample_rate}; ret = connect_ports(ctx, outlink); } return ret; }
void ofxRaspicam::setup() { MMAL_STATUS_T status = MMAL_SUCCESS; bcm_host_init(); create_camera_component(); create_encoder_component(); camera_still_port = photo.camera->output[MMAL_CAMERA_CAPTURE_PORT]; encoder_input_port = photo.encoder_component->input[0]; encoder_output_port = photo.encoder_component->output[0]; VCOS_STATUS_T vcos_status; ofLogVerbose() << "Connecting camera stills port to encoder input port"; // Now connect the camera to the encoder status = connect_ports(camera_still_port, encoder_input_port, &photo.encoder_connection); if (status != MMAL_SUCCESS) { ofLogVerbose() << "connect camera video port to encoder input FAIL"; }else { ofLogVerbose() << "connect camera video port to encoder input PASS"; } // Set up our userdata - this is passed though to the callback where we need the information. // Null until we open our filename callback_data.file_handle = NULL; callback_data.photo = &photo; vcos_status = vcos_semaphore_create(&callback_data.complete_semaphore, "RaspiStill-sem", 0); vcos_assert(vcos_status == VCOS_SUCCESS); encoder_output_port->userdata = (struct MMAL_PORT_USERDATA_T *)&callback_data; ofLogVerbose() << "Enabling encoder output port"; // Enable the encoder output port and tell it its callback function status = mmal_port_enable(encoder_output_port, encoder_buffer_callback); if (status != MMAL_SUCCESS) { ofLogVerbose() << "Setup encoder output FAIL, error: " << status; }else { ofLogVerbose() << "Setup encoder output PASS"; } }
void FlowPortTest::Execute(void) { cout << "Executing FlowPortTest" << endl; Simulator::Init(L"ExteriorLight.ernest"); Simulator::SetDuration(seconds(10)); BinaryTraceRecorder trace_recorder("ExteriorLight.ernest.bt1"); trace_recorder.AddEventMapping("ExteriorLight.ernest#//@structureModel.0/@modules.23/@ports.3", 0); Simulator::SetTraceRecorder(&trace_recorder); // // Building the hardware topology // // Create ECU Ecu ecu1("ECU1"); Ecu ecu2("ECU2"); // Create the bus SimpleBus bus("SimpleBus"); // Adding bus interfaces to ecus SimpleBusInterface *ecu1BusInterface = ecu1.AddHardware<SimpleBusInterface>(); SimpleBusInterface *ecu2BusInterface = ecu2.AddHardware<SimpleBusInterface>(); // Attaching the interfaces to the bus bus.AttachInterface(ecu1BusInterface); bus.AttachInterface(ecu2BusInterface); // // Configuring the software system // // Set scheduler OsekOS *os1 = ecu1.GetService<OsekOS>(); OsekOS *os2 = ecu2.GetService<OsekOS>(); os1->SetScheduler<RoundRobin>(); os2->SetScheduler<RoundRobin>(); // Create one task with two SWF Task* t1 = os1->DeclareTask<SwfA>(0, milliseconds(0), milliseconds(40), new WorstCaseExecutionSpecification(milliseconds(20))); Task* t2 = os2->DeclareTask<SwfB>(0, milliseconds(10), milliseconds(40), new WorstCaseExecutionSpecification(milliseconds(20))); SwfA* swfA = dynamic_cast<SwfA*>(t1->GetSwf()); SwfB* swfB = dynamic_cast<SwfB*>(t2->GetSwf()); connect_ports(swfA->src_counter, swfB->counter); Simulator::Start(); }
void jack_raw_output::start () { check_idle (); jack_activate (_client); auto grd_activate = base::make_guard ([&] { jack_deactivate (_client); }); connect_ports (); grd_activate.dismiss (); set_state (async_state::running); }
static int sim_init_net(char *netconf, FILE * out) { DEBUG("reading %s", netconf); if (read_netconf(netconf, out) < 0) return -1; if (connect_ports() < 0) return -2; if (set_default_port(NULL) < 0) return -3; return 0; }
RaspiCamCvCapture * raspiCamCvCreateCameraCapture(int index) { RaspiCamCvCapture * capture = (RaspiCamCvCapture*)malloc(sizeof(RaspiCamCvCapture)); // Our main data storage vessel.. RASPIVID_STATE * state = (RASPIVID_STATE*)malloc(sizeof(RASPIVID_STATE)); capture->pState = state; MMAL_STATUS_T status = -1; MMAL_PORT_T *camera_video_port = NULL; MMAL_PORT_T *camera_video_port_2 = NULL; //MMAL_PORT_T *camera_still_port = NULL; MMAL_PORT_T *encoder_input_port = NULL; MMAL_PORT_T *encoder_output_port = NULL; bcm_host_init(); // read default status default_status(state); int w = state->width; int h = state->height; state->py = cvCreateImage(cvSize(w,h), IPL_DEPTH_8U, 3); // Y component of YUV I420 frame if (state->graymode==0) { state->pu = cvCreateImage(cvSize(w/2,h/2), IPL_DEPTH_8U, 1); // U component of YUV I420 frame state->pv = cvCreateImage(cvSize(w/2,h/2), IPL_DEPTH_8U, 1); // V component of YUV I420 frame } vcos_semaphore_create(&state->capture_sem, "Capture-Sem", 0); vcos_semaphore_create(&state->capture_done_sem, "Capture-Done-Sem", 0); if (state->graymode==0) { state->pu_big = cvCreateImage(cvSize(w,h), IPL_DEPTH_8U, 1); state->pv_big = cvCreateImage(cvSize(w,h), IPL_DEPTH_8U, 1); state->yuvImage = cvCreateImage(cvSize(w,h), IPL_DEPTH_8U, 3); state->dstImage = cvCreateImage(cvSize(w,h), IPL_DEPTH_8U, 3); // final picture to display } //printf("point2.0\n"); // create camera if (!create_camera_component(state)) { vcos_log_error("%s: Failed to create camera component", __func__); raspiCamCvReleaseCapture(&capture); return NULL; } else if ((status = create_encoder_component(state)) != MMAL_SUCCESS) { vcos_log_error("%s: Failed to create encode component", __func__); destroy_camera_component(state); return NULL; } //printf("point2.1\n"); //create_encoder_component(state); camera_video_port = state->camera_component->output[MMAL_CAMERA_VIDEO_PORT]; camera_video_port_2 = state->camera_component->output[MMAL_CAMERA_VIDEO_PORT_2]; //camera_still_port = state->camera_component->output[MMAL_CAMERA_CAPTURE_PORT]; encoder_input_port = state->encoder_component->input[0]; encoder_output_port = state->encoder_component->output[0]; // assign data to use for callback camera_video_port->userdata = (struct MMAL_PORT_USERDATA_T *)state; // assign data to use for callback camera_video_port_2->userdata = (struct MMAL_PORT_USERDATA_T *)state; // Now connect the camera to the encoder status = connect_ports(camera_video_port_2, encoder_input_port, &state->encoder_connection); if (state->filename) { if (state->filename[0] == '-') { state->callback_data.file_handle = stdout; } else { state->callback_data.file_handle = open_filename(state); } if (!state->callback_data.file_handle) { // Notify user, carry on but discarding encoded output buffers vcos_log_error("%s: Error opening output file: %s\nNo output file will be generated\n", __func__, state->filename); } } // Set up our userdata - this is passed though to the callback where we need the information. state->callback_data.pstate = state; state->callback_data.abort = 0; encoder_output_port->userdata = (struct MMAL_PORT_USERDATA_T *)&state->callback_data; // Enable the encoder output port and tell it its callback function status = mmal_port_enable(encoder_output_port, encoder_buffer_callback); if (status != MMAL_SUCCESS) { state->encoder_connection = NULL; vcos_log_error("%s: Failed to connect camera video port to encoder input", __func__); return NULL; } if (status != MMAL_SUCCESS) { vcos_log_error("Failed to setup encoder output"); return NULL; } //mmal_port_enable(encoder_output_port, encoder_buffer_callback); // Only encode stuff if we have a filename and it opened // Note we use the copy in the callback, as the call back MIGHT change the file handle if (state->callback_data.file_handle) { int running = 1; // Send all the buffers to the encoder output port { int num = mmal_queue_length(state->encoder_pool->queue); int q; for (q=0;q<num;q++) { MMAL_BUFFER_HEADER_T *buffer2 = mmal_queue_get(state->encoder_pool->queue); if (!buffer2) vcos_log_error("Unable to get a required buffer %d from pool queue", q); if (mmal_port_send_buffer(encoder_output_port, buffer2)!= MMAL_SUCCESS) vcos_log_error("Unable to send a buffer to encoder output port (%d)", q); } } } // start capture if (mmal_port_parameter_set_boolean(camera_video_port_2, MMAL_PARAMETER_CAPTURE, 1) != MMAL_SUCCESS) { vcos_log_error("%s: Failed to start capture", __func__); raspiCamCvReleaseCapture(&capture); return NULL; } // Send all the buffers to the video port int num = mmal_queue_length(state->video_pool->queue); int q; for (q = 0; q < num; q++) { MMAL_BUFFER_HEADER_T *buffer = mmal_queue_get(state->video_pool->queue); if (!buffer) vcos_log_error("Unable to get a required buffer %d from pool queue", q); if (mmal_port_send_buffer(camera_video_port, buffer)!= MMAL_SUCCESS) vcos_log_error("Unable to send a buffer to encoder output port (%d)", q); } //mmal_status_to_int(status); // Disable all our ports that are not handled by connections //check_disable_port(camera_still_port); //if (status != 0) // raspicamcontrol_check_configuration(128); vcos_semaphore_wait(&state->capture_done_sem); return capture; }
int main(int argc, char *argv[]) { static const char short_options[] = "hVlp:"; static const struct option long_options[] = { {"help", 0, NULL, 'h'}, {"version", 0, NULL, 'V'}, {"list", 0, NULL, 'l'}, {"port", 1, NULL, 'p'}, { } }; int do_list = 0; struct pollfd *pfds; int npfds; int c, err; init_seq(); while ((c = getopt_long(argc, argv, short_options, long_options, NULL)) != -1) { switch (c) { case 'h': help(argv[0]); return 0; case 'V': version(); return 0; case 'l': do_list = 1; break; case 'p': parse_ports(optarg); break; default: help(argv[0]); return 1; } } if (optind < argc) { help(argv[0]); return 1; } if (do_list) { list_ports(); return 0; } create_port(); connect_ports(); err = snd_seq_nonblock(seq, 1); check_snd("set nonblock mode", err); if (port_count > 0) printf("Waiting for data."); else printf("Waiting for data at port %d:0.", snd_seq_client_id(seq)); printf(" Press Ctrl+C to end.\n"); printf("Source Event Ch Data\n"); signal(SIGINT, sighandler); signal(SIGTERM, sighandler); npfds = snd_seq_poll_descriptors_count(seq, POLLIN); pfds = alloca(sizeof(*pfds) * npfds); for (;;) { snd_seq_poll_descriptors(seq, pfds, npfds, POLLIN); if (poll(pfds, npfds, -1) < 0) break; do { snd_seq_event_t *event; err = snd_seq_event_input(seq, &event); if (err < 0) break; if (event) dump_event(event); } while (err > 0); fflush(stdout); if (stop) break; } snd_seq_close(seq); return 0; }
/** * main */ int main(int argc, const char **argv) { // Our main data storage vessel.. RASPISTILL_STATE state; MMAL_STATUS_T status = -1; MMAL_PORT_T *camera_preview_port = NULL; MMAL_PORT_T *camera_video_port = NULL; MMAL_PORT_T *camera_still_port = NULL; MMAL_PORT_T *preview_input_port = NULL; MMAL_PORT_T *encoder_input_port = NULL; MMAL_PORT_T *encoder_output_port = NULL; bcm_host_init(); signal(SIGINT, signal_handler); default_status(&state); if (!create_camera_component(&state)) { vcos_log_error("%s: Failed to create camera component", __func__); } //else if (!raspipreview_create(&state.preview_parameters)) //{ // vcos_log_error("%s: Failed to create preview component", __func__); // destroy_camera_component(&state); //} else if (!create_encoder_component(&state)) { vcos_log_error("%s: Failed to create encode component", __func__); raspipreview_destroy(&state.preview_parameters); destroy_camera_component(&state); } else { PORT_USERDATA callback_data; // *** PR : we don't want preview camera_preview_port = NULL;//state.camera_component->output[MMAL_CAMERA_PREVIEW_PORT]; camera_video_port = state.camera_component->output[MMAL_CAMERA_VIDEO_PORT]; camera_still_port = state.camera_component->output[MMAL_CAMERA_CAPTURE_PORT]; preview_input_port = state.preview_parameters.preview_component->input[0]; encoder_input_port = state.encoder_component->input[0]; encoder_output_port = state.encoder_component->output[0]; if (state.preview_parameters.wantPreview ) { if (state.verbose) { fprintf(stderr, "Connecting camera preview port to preview input port\n"); fprintf(stderr, "Starting video preview\n"); } // PR : we don't want preview // Connect camera to preview // status = connect_ports(camera_preview_port, preview_input_port, &state.preview_connection); } VCOS_STATUS_T vcos_status; if (state.verbose) fprintf(stderr, "Connecting camera stills port to encoder input port\n"); // Now connect the camera to the encoder status = connect_ports(camera_still_port, encoder_input_port, &state.encoder_connection); if (status != MMAL_SUCCESS) { vcos_log_error("%s: Failed to connect camera video port to encoder input", __func__); goto error; } // Set up our userdata - this is passed though to the callback where we need the information. // Null until we open our filename callback_data.file_handle = NULL; callback_data.pstate = &state; vcos_status = vcos_semaphore_create(&callback_data.complete_semaphore, "RaspiStill-sem", 0); vcos_assert(vcos_status == VCOS_SUCCESS); encoder_output_port->userdata = (struct MMAL_PORT_USERDATA_T *)&callback_data; if (state.verbose) fprintf(stderr, "Enabling encoder output port\n"); // Enable the encoder output port and tell it its callback function status = mmal_port_enable(encoder_output_port, encoder_buffer_callback); if (status != MMAL_SUCCESS) { vcos_log_error("Failed to setup encoder output"); goto error; } { int num_iterations = state.timelapse ? state.timeout / state.timelapse : 1; int frame; for (frame = 1;frame<=num_iterations; frame++) { if (state.timelapse) vcos_sleep(state.timelapse); else vcos_sleep(state.timeout); // Send all the buffers to the encoder output port int num = mmal_queue_length(state.encoder_pool->queue); int q; for (q=0;q<num;q++) { MMAL_BUFFER_HEADER_T *buffer = mmal_queue_get(state.encoder_pool->queue); if (!buffer) vcos_log_error("Unable to get a required buffer %d from pool queue", q); if (mmal_port_send_buffer(encoder_output_port, buffer)!= MMAL_SUCCESS) vcos_log_error("Unable to send a buffer to encoder output port (%d)", q); } if (mmal_port_parameter_set_boolean(camera_still_port, MMAL_PARAMETER_CAPTURE, 1) != MMAL_SUCCESS) { vcos_log_error("%s: Failed to start capture", __func__); } else { // Wait for capture to complete // For some reason using vcos_semaphore_wait_timeout sometimes returns immediately with bad parameter error // even though it appears to be all correct, so reverting to untimed one until figure out why its erratic vcos_semaphore_wait(&callback_data.complete_semaphore); } } // end for (frame) vcos_semaphore_delete(&callback_data.complete_semaphore); } error: mmal_status_to_int(status); // Disable all our ports that are not handled by connections check_disable_port(camera_video_port); check_disable_port(encoder_output_port); // PR : we don't want preview //if (state.preview_parameters.wantPreview ) // mmal_connection_destroy(state.preview_connection); mmal_connection_destroy(state.encoder_connection); /* Disable components */ if (state.encoder_component) mmal_component_disable(state.encoder_component); if (state.preview_parameters.preview_component) mmal_component_disable(state.preview_parameters.preview_component); if (state.camera_component) mmal_component_disable(state.camera_component); destroy_encoder_component(&state); raspipreview_destroy(&state.preview_parameters); destroy_camera_component(&state); if (state.verbose) fprintf(stderr, "Close down completed, all components disconnected, disabled and destroyed\n\n"); } if (status != 0) raspicamcontrol_check_configuration(128); return 0; }
static int config_input(AVFilterLink *inlink) { AVFilterContext *ctx = inlink->dst; return connect_ports(ctx, inlink); }
/** * main */ int main(int argc, const char **argv) { // *** MODIFICATION: OpenCV modifications. // Load previous image. IplImage* prevImage = cvLoadImage("motion1.jpg", CV_LOAD_IMAGE_COLOR); // Create two arrays with the same number of channels than the original one. avg1 = cvCreateMat(prevImage->height,prevImage->width,CV_32FC3); avg2 = cvCreateMat(prevImage->height,prevImage->width,CV_32FC3); // Create image of 32 bits. IplImage* image32 = cvCreateImage(cvSize(prevImage->width,prevImage->height), 32,3); // Convert image to 32 bits. cvConvertScale(prevImage,image32,1/255,0); // Set data from previous image into arrays. cvSetData(avg1,image32->imageData,image32->widthStep); cvSetData(avg2,image32->imageData,image32->widthStep); // *** MODIFICATION end // Our main data storage vessel.. RASPISTILL_STATE state; MMAL_STATUS_T status = MMAL_SUCCESS; MMAL_PORT_T *camera_preview_port = NULL; MMAL_PORT_T *camera_video_port = NULL; MMAL_PORT_T *camera_still_port = NULL; MMAL_PORT_T *preview_input_port = NULL; MMAL_PORT_T *encoder_input_port = NULL; MMAL_PORT_T *encoder_output_port = NULL; bcm_host_init(); // Register our application with the logging system vcos_log_register("fast", VCOS_LOG_CATEGORY); signal(SIGINT, signal_handler); default_status(&state); if (state.verbose) { fprintf(stderr, "\n%s Camera App %s\n\n", basename(argv[0]), VERSION_STRING); } // OK, we have a nice set of parameters. Now set up our components // We have three components. Camera, Preview and encoder. // Camera and encoder are different in stills/video, but preview // is the same so handed off to a separate module if ((status = create_camera_component(&state)) != MMAL_SUCCESS) { vcos_log_error("%s: Failed to create camera component", __func__); } else if ((status = raspipreview_create(&state.preview_parameters)) != MMAL_SUCCESS) { vcos_log_error("%s: Failed to create preview component", __func__); destroy_camera_component(&state); } else if ((status = create_encoder_component(&state)) != MMAL_SUCCESS) { vcos_log_error("%s: Failed to create encode component", __func__); raspipreview_destroy(&state.preview_parameters); destroy_camera_component(&state); } else { PORT_USERDATA callback_data; if (state.verbose) fprintf(stderr, "Starting component connection stage\n"); camera_preview_port = state.camera_component->output[MMAL_CAMERA_PREVIEW_PORT]; camera_video_port = state.camera_component->output[MMAL_CAMERA_VIDEO_PORT]; camera_still_port = state.camera_component->output[MMAL_CAMERA_CAPTURE_PORT]; preview_input_port = state.preview_parameters.preview_component->input[0]; encoder_input_port = state.encoder_component->input[0]; encoder_output_port = state.encoder_component->output[0]; if (state.preview_parameters.wantPreview ) { if (state.verbose) { fprintf(stderr, "Connecting camera preview port to preview input port\n"); fprintf(stderr, "Starting video preview\n"); } // *** USER: remove preview // Connect camera to preview //status = connect_ports(camera_preview_port, preview_input_port, &state.preview_connection); } else { status = MMAL_SUCCESS; } if (status == MMAL_SUCCESS) { VCOS_STATUS_T vcos_status; if (state.verbose) fprintf(stderr, "Connecting camera stills port to encoder input port\n"); // Now connect the camera to the encoder status = connect_ports(camera_still_port, encoder_input_port, &state.encoder_connection); if (status != MMAL_SUCCESS) { vcos_log_error("%s: Failed to connect camera video port to encoder input", __func__); goto error; } // Set up our userdata - this is passed though to the callback where we need the information. // Null until we open our filename callback_data.file_handle = NULL; callback_data.pstate = &state; vcos_status = vcos_semaphore_create(&callback_data.complete_semaphore, "RaspiStill-sem", 0); vcos_assert(vcos_status == VCOS_SUCCESS); if (status != MMAL_SUCCESS) { vcos_log_error("Failed to setup encoder output"); goto error; } FILE *output_file = NULL; int frame = 1; // Enable the encoder output port encoder_output_port->userdata = (struct MMAL_PORT_USERDATA_T *)&callback_data; if (state.verbose) fprintf(stderr, "Enabling encoder output port\n"); // Enable the encoder output port and tell it its callback function status = mmal_port_enable(encoder_output_port, encoder_buffer_callback); // Create an empty matrix with the size of the buffer. CvMat* buf = cvCreateMat(1,60000,CV_8UC1); // Keep buffer that gets frames from queue. MMAL_BUFFER_HEADER_T *buffer; // Image to be displayed. IplImage* image; // Keep number of buffers and index for the loop. int num, q; while(1) { // Send all the buffers to the encoder output port num = mmal_queue_length(state.encoder_pool->queue); for (q=0;q<num;q++) { buffer = mmal_queue_get(state.encoder_pool->queue); if (!buffer) vcos_log_error("Unable to get a required buffer %d from pool queue", q); if (mmal_port_send_buffer(encoder_output_port, buffer)!= MMAL_SUCCESS) vcos_log_error("Unable to send a buffer to encoder output port (%d)", q); } // for if (mmal_port_parameter_set_boolean(camera_still_port, MMAL_PARAMETER_CAPTURE, 1) != MMAL_SUCCESS) vcos_log_error("%s: Failed to start capture", __func__); else { // Wait for capture to complete // For some reason using vcos_semaphore_wait_timeout sometimes returns immediately with bad parameter error // even though it appears to be all correct, so reverting to untimed one until figure out why its erratic vcos_semaphore_wait(&callback_data.complete_semaphore); if (state.verbose) fprintf(stderr, "Finished capture %d\n", frame); } // else // Copy buffer from camera to matrix. buf->data.ptr = buffer->data; // This workaround is needed for the code to work // *** TODO: investigate why. printf("Until here works\n"); // Decode the image and display it. image = cvDecodeImage(buf, CV_LOAD_IMAGE_COLOR); // Destinations CvMat* res1 = cvCreateMat(image->height,image->width,CV_8UC3); CvMat* res2 = cvCreateMat(image->height,image->width,CV_8UC3); // Update running averages and then scale, calculate absolute values // and convert the result 8-bit. // *** USER:change the value of the weight. cvRunningAvg(image,avg2,0.0001, NULL); cvConvertScaleAbs(avg2, res2, 1,0); cvRunningAvg(image,avg1,0.1, NULL); cvConvertScaleAbs(avg1, res1, 1,0); // Show images cvShowImage("img",image); cvShowImage("avg1",res1); cvShowImage("avg2",res2); cvWaitKey(20); // Update previous image. cvSaveImage("motion1.jpg", image, 0); } // end while vcos_semaphore_delete(&callback_data.complete_semaphore); } else { mmal_status_to_int(status); vcos_log_error("%s: Failed to connect camera to preview", __func__); } error: mmal_status_to_int(status); if (state.verbose) fprintf(stderr, "Closing down\n"); // Disable all our ports that are not handled by connections check_disable_port(camera_video_port); check_disable_port(encoder_output_port); if (state.preview_parameters.wantPreview ) mmal_connection_destroy(state.preview_connection); mmal_connection_destroy(state.encoder_connection); /* Disable components */ if (state.encoder_component) mmal_component_disable(state.encoder_component); if (state.preview_parameters.preview_component) mmal_component_disable(state.preview_parameters.preview_component); if (state.camera_component) mmal_component_disable(state.camera_component); destroy_encoder_component(&state); raspipreview_destroy(&state.preview_parameters); destroy_camera_component(&state); if (state.verbose) fprintf(stderr, "Close down completed, all components disconnected, disabled and destroyed\n\n"); } if (status != MMAL_SUCCESS) raspicamcontrol_check_configuration(128); return 0; }
/** * main */ int main(int argc, const char **argv) { // Our main data storage vessel.. RASPISTILL_STATE state; MMAL_STATUS_T status = -1; MMAL_PORT_T *camera_preview_port = NULL; MMAL_PORT_T *camera_video_port = NULL; MMAL_PORT_T *camera_still_port = NULL; MMAL_PORT_T *preview_input_port = NULL; MMAL_PORT_T *encoder_input_port = NULL; MMAL_PORT_T *encoder_output_port = NULL; bcm_host_init(); clock_t elapsedTime; time_t timer_begin,timer_end; double secondsElapsed; time(&timer_begin); /* get current time; same as: timer = time(NULL) */ // create window cvNamedWindow("camcvWin", CV_WINDOW_AUTOSIZE);//CV_WINDOW_NORMAL);//CV_WINDOW_AUTOSIZE); //cvResizeWindow("camcvWin",640,480); signal(SIGINT, signal_handler); default_status(&state); if (!create_camera_component(&state)) { vcos_log_error("%s: Failed to create camera component", __func__); } else if ( (status = raspipreview_create(&state.preview_parameters)) != MMAL_SUCCESS) { vcos_log_error("%s: Failed to create preview component", __func__); destroy_camera_component(&state); } else if (!create_encoder_component(&state)) { vcos_log_error("%s: Failed to create encode component", __func__); raspipreview_destroy(&state.preview_parameters); destroy_camera_component(&state); } else { PORT_USERDATA callback_data; // *** PR : we don't want preview camera_preview_port = NULL;//state.camera_component->output[MMAL_CAMERA_PREVIEW_PORT]; camera_video_port = state.camera_component->output[MMAL_CAMERA_VIDEO_PORT]; camera_still_port = state.camera_component->output[MMAL_CAMERA_CAPTURE_PORT]; preview_input_port = state.preview_parameters.preview_component->input[0]; encoder_input_port = state.encoder_component->input[0]; encoder_output_port = state.encoder_component->output[0]; if (state.preview_parameters.wantPreview ) { // PR : we don't want preview // Connect camera to preview // status = connect_ports(camera_preview_port, preview_input_port, &state.preview_connection); } VCOS_STATUS_T vcos_status; // Now connect the camera to the encoder status = connect_ports(camera_still_port, encoder_input_port, &state.encoder_connection); if (status != MMAL_SUCCESS) { vcos_log_error("%s: Failed to connect camera video port to encoder input", __func__); goto error; } // Set up our userdata - this is passed though to the callback where we need the information. // Null until we open our filename //callback_data.file_handle = NULL; callback_data.pstate = &state; vcos_status = vcos_semaphore_create(&callback_data.complete_semaphore, "RaspiStill-sem", 0); vcos_assert(vcos_status == VCOS_SUCCESS); encoder_output_port->userdata = (struct MMAL_PORT_USERDATA_T *)&callback_data; // Enable the encoder output port and tell it its callback function status = mmal_port_enable(encoder_output_port, encoder_buffer_callback); if (status != MMAL_SUCCESS) { vcos_log_error("Failed to setup encoder output"); goto error; } int num_iterations = 100; int frame,num,q; elapsedTime= clock(); printf("time=%d\n",elapsedTime); for (frame = 1;frame<=num_iterations; frame++) { // Send all the buffers to the encoder output port num = mmal_queue_length(state.encoder_pool->queue); for (q=0;q<num;q++) { MMAL_BUFFER_HEADER_T *buffer = mmal_queue_get(state.encoder_pool->queue); //if (!buffer) // vcos_log_error("Unable to get a required buffer %d from pool queue", q); if (mmal_port_send_buffer(encoder_output_port, buffer)!= MMAL_SUCCESS) vcos_log_error("Unable to send a buffer to encoder output port (%d)", q); } if (mmal_port_parameter_set_boolean(camera_still_port, MMAL_PARAMETER_CAPTURE, 1) != MMAL_SUCCESS) { vcos_log_error("%s: Failed to start capture", __func__); } else { // Wait for capture to complete // For some reason using vcos_semaphore_wait_timeout sometimes returns immediately with bad parameter error // even though it appears to be all correct, so reverting to untimed one until figure out why its erratic vcos_semaphore_wait(&callback_data.complete_semaphore); } } // end for (frame) vcos_semaphore_delete(&callback_data.complete_semaphore); // compute elapsed time since begin of the loop and display error: mmal_status_to_int(status); // Disable all our ports that are not handled by connections check_disable_port(camera_video_port); check_disable_port(encoder_output_port); // PR : we don't want preview //if (state.preview_parameters.wantPreview ) // mmal_connection_destroy(state.preview_connection); mmal_connection_destroy(state.encoder_connection); /* Disable components */ if (state.encoder_component) mmal_component_disable(state.encoder_component); if (state.preview_parameters.preview_component) mmal_component_disable(state.preview_parameters.preview_component); if (state.camera_component) mmal_component_disable(state.camera_component); destroy_encoder_component(&state); raspipreview_destroy(&state.preview_parameters); destroy_camera_component(&state); } if (status != 0) raspicamcontrol_check_configuration(128); // compute FPS time(&timer_end); /* get current time; same as: timer = time(NULL) */ secondsElapsed = difftime(timer_end,timer_begin); printf ("%.f seconds for %d frames : FPS = %f", secondsElapsed,nbFrames,(float)((float)(nbFrames)/secondsElapsed)); printf("time=%d\n",clock()); elapsedTime=clock()-elapsedTime; printf ("(time) %d clicks (%f seconds). nb Frames = %d. FPS = %f\n",elapsedTime,((float)elapsedTime)/CLOCKS_PER_SEC, nbFrames, (float)nbFrames/(((float)elapsedTime)/CLOCKS_PER_SEC)); return 0; }
void MmalStillCamera::initialize(CameraMode cameraMode) { m_resolution = MmalUtil::get()->getClosestResolution(m_name, cameraMode); if (m_imageWidth != -1) { throw Exception("Camera is already initialized"); } m_imageWidth = m_resolution.width; m_imageHeight = m_resolution.height; m_callbackData = new MmalStillCallbackData(m_imageWidth, m_imageHeight, 3); // Handle the sensor properties real sensorWidth, sensorHeight, focalLength; MmalUtil::get()->getSensorProperties(m_name, sensorWidth, sensorHeight, focalLength); setSensorProperties(sensorWidth, sensorHeight, focalLength); createCameraComponent(); InfoLog << "Created camera" << Logger::ENDL; createPreview(); InfoLog << "Created preview" << Logger::ENDL; InfoLog << "Target Image Width: " << VCOS_ALIGN_UP(m_imageWidth, 32) << Logger::ENDL; InfoLog << "Target Image Height: " << VCOS_ALIGN_UP(m_imageHeight, 16) << Logger::ENDL; MMAL_STATUS_T status; m_targetPort = m_stillPort; // Create pool of buffer headers for the output port to consume m_pool = mmal_port_pool_create(m_targetPort, m_targetPort->buffer_num, m_targetPort->buffer_size); if (m_pool == NULL) { throw Exception("Failed to create buffer header pool for encoder output port"); } MMAL_CONNECTION_T *preview_connection = NULL; status = connect_ports(m_previewPort, m_preview->input[0], &preview_connection); if (status != MMAL_SUCCESS) { throw Exception("Error connecting preview port"); } m_targetPort->userdata = (struct MMAL_PORT_USERDATA_T *) m_callbackData; m_callbackData->image = NULL; m_callbackData->pool = m_pool; // Enable the encoder output port and tell it its callback function if (mmal_port_enable(m_targetPort, EncoderBufferCallback) != MMAL_SUCCESS) { ErrorLog << "Error enabling the encoder buffer callback" << Logger::ENDL; } // Send all the buffers to the encoder output port int num = mmal_queue_length(m_pool->queue); for (int q = 0; q < num; q++) { MMAL_BUFFER_HEADER_T *buffer = mmal_queue_get(m_pool->queue); if (buffer == NULL) { ErrorLog << "Unable to get buffer " << q << " from the pool" << Logger::ENDL; } if (mmal_port_send_buffer(m_targetPort, buffer) != MMAL_SUCCESS) { ErrorLog << "Unable to send a buffer " << q << " to encoder output port " << Logger::ENDL; } } // Enable burst mode if (m_burstModeEnabled) { if (mmal_port_parameter_set_boolean(m_camera->control, MMAL_PARAMETER_CAMERA_BURST_CAPTURE, 1) != MMAL_SUCCESS) { ErrorLog << "Error enabling burst mode" << Logger::ENDL; } InfoLog << "Enabled burst mode for still images" << Logger::ENDL; } InfoLog << "Initialized camera" << Logger::ENDL; }
void camera_thread( void ) { static MMAL_STATUS_T status; static RASPIVID_STATE state; static MMAL_PORT_T *camera_preview_port = NULL; static MMAL_PORT_T *camera_video_port = NULL; static MMAL_PORT_T *camera_still_port = NULL; static MMAL_PORT_T *preview_input_port = NULL; static MMAL_PORT_T *encoder_input_port = NULL; static MMAL_PORT_T *encoder_output_port = NULL; static FILE *output_file = NULL; f_nal_queue = sx_queue_create(); bcm_host_init(); default_status(&state); state.verbose = 1; status = create_camera_component(&state); assert(status == MMAL_SUCCESS); status = raspipreview_create(&state.preview_parameters); assert(status == MMAL_SUCCESS); status = create_encoder_component(&state); assert(status == MMAL_SUCCESS); PORT_USERDATA callback_data; camera_preview_port = state.camera_component->output[MMAL_CAMERA_PREVIEW_PORT]; camera_video_port = state.camera_component->output[MMAL_CAMERA_VIDEO_PORT]; camera_still_port = state.camera_component->output[MMAL_CAMERA_CAPTURE_PORT]; preview_input_port = state.preview_parameters.preview_component->input[0]; encoder_input_port = state.encoder_component->input[0]; encoder_output_port = state.encoder_component->output[0]; // Now connect the camera to the encoder status = connect_ports(camera_video_port, encoder_input_port, &state.encoder_connection); assert(status == MMAL_SUCCESS); char *filename = "output.h264"; state.filename = filename; output_file = fopen(state.filename, "wb"); // Set up our userdata - this is passed though to the callback where we need the information. callback_data.file_handle = output_file; callback_data.pstate = &state; callback_data.abort = 0; encoder_output_port->userdata = (struct MMAL_PORT_USERDATA_T *) &callback_data; // Enable the encoder output port and tell it its callback function status = mmal_port_enable(encoder_output_port, encoder_buffer_callback); assert(status == MMAL_SUCCESS); // Only encode stuff if we have a filename and it opened if (output_file) { int wait; if (state.verbose) fprintf(stderr, "Starting video capture\n"); status = mmal_port_parameter_set_boolean(camera_video_port, MMAL_PARAMETER_CAPTURE, 1); assert(status == MMAL_SUCCESS); // Send all the buffers to the encoder output port { int num = mmal_queue_length(state.encoder_pool->queue); int q; fprintf(stderr, "mmal_queue_len = %d\n", num); for (q=0;q<num;q++) { printf("start current time = %d\n", get_time_ns()); MMAL_BUFFER_HEADER_T *buffer = mmal_queue_get(state.encoder_pool->queue); assert(buffer != NULL); status = mmal_port_send_buffer(encoder_output_port, buffer); assert(status == MMAL_SUCCESS); } } // Now wait until we need to stop. Whilst waiting we do need to check to see if we have aborted (for example // out of storage space) // Going to check every ABORT_INTERVAL milliseconds #if 1 while(1) { // sleep forever. vcos_sleep(ABORT_INTERVAL); } #endif #if 0 for (wait = 0; state.timeout == 0 || wait < state.timeout; wait+= ABORT_INTERVAL) { vcos_sleep(ABORT_INTERVAL); if (callback_data.abort) { fprintf(stderr, "333\n"); break; } fprintf(stderr, "222\n"); } fprintf(stderr, "wait = %u\n", wait); if (state.verbose) fprintf(stderr, "Finished capture\n"); #endif } }
/** * main */ int main(int argc, const char **argv) { // Our main data storage vessel.. RASPISTILLYUV_STATE state; MMAL_STATUS_T status; MMAL_PORT_T *camera_preview_port = NULL; MMAL_PORT_T *camera_video_port = NULL; MMAL_PORT_T *camera_still_port = NULL; MMAL_PORT_T *preview_input_port = NULL; FILE *output_file = NULL; // Register our application with the logging system vcos_log_register("RaspiStill", VCOS_LOG_CATEGORY); printf("\nRaspiStillYUV Camera App\n"); printf( "========================\n\n"); signal(SIGINT, signal_handler); // Do we have any parameters if (argc == 1) { display_valid_parameters(); exit(0); } default_status(&state); // Parse the command line and put options in to our status structure if (parse_cmdline(argc, argv, &state)) { status = -1; exit(0); } if (state.verbose) dump_status(&state); // OK, we have a nice set of parameters. Now set up our components // We have two components. Camera and Preview // Camera is different in stills/video, but preview // is the same so handed off to a separate module if (!create_camera_component(&state)) { vcos_log_error("%s: Failed to create camera component", __func__); } else if ( !raspipreview_create(&state.preview_parameters)) { vcos_log_error("%s: Failed to create preview component", __func__); destroy_camera_component(&state); } else { PORT_USERDATA callback_data; if (state.verbose) printf("Starting component connection stage\n"); camera_preview_port = state.camera_component->output[MMAL_CAMERA_PREVIEW_PORT]; camera_video_port = state.camera_component->output[MMAL_CAMERA_VIDEO_PORT]; camera_still_port = state.camera_component->output[MMAL_CAMERA_CAPTURE_PORT]; preview_input_port = state.preview_parameters.preview_component->input[0]; if (state.preview_parameters.wantPreview ) { if (state.verbose) { printf("Connecting camera preview port to preview input port\n"); printf("Starting video preview\n"); } // Connect camera to preview status = connect_ports(camera_preview_port, preview_input_port, &state.preview_connection); } if (status == MMAL_SUCCESS) { VCOS_STATUS_T vcos_status; if (state.filename) { if (state.verbose) printf("Opening output file %s\n", state.filename); output_file = fopen(state.filename, "wb"); if (!output_file) { // Notify user, carry on but discarding encoded output buffers vcos_log_error("%s: Error opening output file: %s\nNo output file will be generated\n", __func__, state.filename); } } // Set up our userdata - this is passed though to the callback where we need the information. callback_data.file_handle = output_file; callback_data.pstate = &state; vcos_status = vcos_semaphore_create(&callback_data.complete_semaphore, "RaspiStill-sem", 0); vcos_assert(vcos_status == VCOS_SUCCESS); camera_still_port->userdata = (struct MMAL_PORT_USERDATA_T *)&callback_data; if (state.verbose) printf("Enabling camera still output port\n"); // Enable the camera still output port and tell it its callback function status = mmal_port_enable(camera_still_port, camera_buffer_callback); if (status != MMAL_SUCCESS) { vcos_log_error("Failed to setup camera output"); goto error; } if (state.verbose) printf("Starting video preview\n"); // Send all the buffers to the encoder output port { int num = mmal_queue_length(state.camera_pool->queue); int q; for (q=0;q<num;q++) { MMAL_BUFFER_HEADER_T *buffer = mmal_queue_get(state.camera_pool->queue); if (!buffer) vcos_log_error("Unable to get a required buffer %d from pool queue", q); if (mmal_port_send_buffer(camera_still_port, buffer)!= MMAL_SUCCESS) vcos_log_error("Unable to send a buffer to encoder output port (%d)", q); } } // Now wait until we need to do the capture vcos_sleep(state.timeout); // And only do the capture if we have specified a filename and its opened OK if (output_file) { if (state.verbose) printf("Starting capture\n"); // Fire the capture if (mmal_port_parameter_set_boolean(camera_still_port, MMAL_PARAMETER_CAPTURE, 1) != MMAL_SUCCESS) { vcos_log_error("%s: Failed to start capture", __func__); } else { // Wait for capture to complete // For some reason using vcos_semaphore_wait_timeout sometimes returns immediately with bad parameter error // even though it appears to be all correct, so reverting to untimed one until figure out why its erratic vcos_semaphore_wait(&callback_data.complete_semaphore); if (state.verbose) printf("Finished capture\n"); } } vcos_semaphore_delete(&callback_data.complete_semaphore); } else { mmal_status_to_int(status); vcos_log_error("%s: Failed to connect camera to preview", __func__); } error: mmal_status_to_int(status); if (state.verbose) printf("Closing down\n"); if (output_file) fclose(output_file); // Disable all our ports that are not handled by connections check_disable_port(camera_video_port); if (state.preview_parameters.wantPreview ) mmal_connection_destroy(state.preview_connection); /* Disable components */ if (state.preview_parameters.preview_component) mmal_component_disable(state.preview_parameters.preview_component); if (state.camera_component) mmal_component_disable(state.camera_component); raspipreview_destroy(&state.preview_parameters); destroy_camera_component(&state); if (state.verbose) printf("Close down completed, all components disconnected, disabled and destroyed\n\n"); } return 0; }
bool JackToShmdata::start() { buf_.resize(num_channels_ * jack_client_.get_buffer_size()); std::string data_type( "audio/x-raw, " "format=(string)F32LE, " "layout=(string)interleaved, " "rate=" + std::to_string(jack_client_.get_sample_rate()) + ", " "channels=" + std::to_string(num_channels_) + ", channel-mask=(bitmask)"); // This channel mask is used by most encoders. // Here is the reference for the values according to the number of channels: https://goo.gl/M4b7Di std::string channel_mask; switch (num_channels_) { case 1: channel_mask = "0x1"; break; case 2: channel_mask = "0x3"; break; case 3: channel_mask = "0x7"; break; case 4: channel_mask = "0x107"; break; case 5: channel_mask = "0x37"; break; case 6: channel_mask = "0x3f"; break; default: channel_mask = "0x0"; break; } data_type += channel_mask; std::string shmpath = make_shmpath("audio"); shm_ = std::make_unique<ShmdataWriter>( this, shmpath, buf_.size() * sizeof(jack_sample_t), data_type); if (!shm_.get()) { warning("JackToShmdata failed to start"); shm_.reset(nullptr); return false; } pmanage<MPtr(&PContainer::disable)>(auto_connect_id_, disabledWhenStartedMsg); pmanage<MPtr(&PContainer::disable)>(num_channels_id_, disabledWhenStartedMsg); pmanage<MPtr(&PContainer::disable)>(client_name_id_, disabledWhenStartedMsg); pmanage<MPtr(&PContainer::disable)>(connect_to_id_, disabledWhenStartedMsg); pmanage<MPtr(&PContainer::disable)>(index_id_, disabledWhenStartedMsg); { std::lock_guard<std::mutex> lock(input_ports_mutex_); input_ports_.clear(); for (unsigned int i = 0; i < num_channels_; ++i) input_ports_.emplace_back(jack_client_, i + 1, false); connect_ports(); } return true; }
/** * main */ int main(int argc, const char **argv) { // Our main data storage vessel.. RASPIVID_STATE state; MMAL_STATUS_T status; MMAL_PORT_T *camera_preview_port = NULL; MMAL_PORT_T *camera_video_port = NULL; MMAL_PORT_T *camera_still_port = NULL; MMAL_PORT_T *preview_input_port = NULL; MMAL_PORT_T *encoder_input_port = NULL; MMAL_PORT_T *encoder_output_port = NULL; FILE *output_file = NULL; // Register our application with the logging system vcos_log_register("RaspiVid", VCOS_LOG_CATEGORY); printf("\nRaspiVid Camera App\n"); printf("===================\n\n"); signal(SIGINT, signal_handler); default_status(&state); // Do we have any parameters if (argc == 1) { display_valid_parameters(); exit(0); } // Parse the command line and put options in to our status structure if (parse_cmdline(argc, argv, &state)) { status = -1; exit(0); } if (state.verbose) dump_status(&state); // OK, we have a nice set of parameters. Now set up our components // We have three components. Camera, Preview and encoder. if (!create_camera_component(&state)) { vcos_log_error("%s: Failed to create camera component", __func__); } else if (!raspipreview_create(&state.preview_parameters)) { vcos_log_error("%s: Failed to create preview component", __func__); destroy_camera_component(&state); } else if (!create_encoder_component(&state)) { vcos_log_error("%s: Failed to create encode component", __func__); raspipreview_destroy(&state.preview_parameters); destroy_camera_component(&state); } else { PORT_USERDATA callback_data; if (state.verbose) printf("Starting component connection stage\n"); camera_preview_port = state.camera_component->output[MMAL_CAMERA_PREVIEW_PORT]; camera_video_port = state.camera_component->output[MMAL_CAMERA_VIDEO_PORT]; camera_still_port = state.camera_component->output[MMAL_CAMERA_CAPTURE_PORT]; preview_input_port = state.preview_parameters.preview_component->input[0]; encoder_input_port = state.encoder_component->input[0]; encoder_output_port = state.encoder_component->output[0]; if (state.preview_parameters.wantPreview ) { if (state.verbose) { printf("Connecting camera preview port to preview input port\n"); printf("Starting video preview\n"); } // Connect camera to preview status = connect_ports(camera_preview_port, preview_input_port, &state.preview_connection); } if (status == MMAL_SUCCESS) { VCOS_STATUS_T vcos_status; if (state.verbose) printf("Connecting camera stills port to encoder input port\n"); // Now connect the camera to the encoder status = connect_ports(camera_video_port, encoder_input_port, &state.encoder_connection); if (status != MMAL_SUCCESS) { vcos_log_error("%s: Failed to connect camera video port to encoder input", __func__); goto error; } if (state.filename) { if (state.verbose) printf("Opening output file %s\n", state.filename); output_file = fopen(state.filename, "wb"); if (!output_file) { // Notify user, carry on but discarding encoded output buffers vcos_log_error("%s: Error opening output file: %s\nNo output file will be generated\n", __func__, state.filename); } } // Set up our userdata - this is passed though to the callback where we need the information. callback_data.file_handle = output_file; callback_data.pstate = &state; vcos_status = vcos_semaphore_create(&callback_data.complete_semaphore, "RaspiStill-sem", 0); vcos_assert(vcos_status == VCOS_SUCCESS); encoder_output_port->userdata = (struct MMAL_PORT_USERDATA_T *)&callback_data; if (state.verbose) printf("Enabling encoder output port\n"); // Enable the encoder output port and tell it its callback function status = mmal_port_enable(encoder_output_port, encoder_buffer_callback); if (status != MMAL_SUCCESS) { vcos_log_error("Failed to setup encoder output"); goto error; } if (state.demoMode) { // Run for the user specific time.. int num_iterations = state.timeout / state.demoInterval; int i; printf("Running in demo mode\n"); for (i=0;i<num_iterations;i++) { raspicamcontrol_cycle_test(state.camera_component); vcos_sleep(state.demoInterval); } } else { // Only encode stuff if we have a filename and it opened if (output_file) { if (state.verbose) printf("Starting video capture\n"); if (mmal_port_parameter_set_boolean(camera_video_port, MMAL_PARAMETER_CAPTURE, 1) != MMAL_SUCCESS) { goto error; } // Send all the buffers to the encoder output port { int num = mmal_queue_length(state.encoder_pool->queue); int q; for (q=0;q<num;q++) { MMAL_BUFFER_HEADER_T *buffer = mmal_queue_get(state.encoder_pool->queue); if (!buffer) vcos_log_error("Unable to get a required buffer %d from pool queue", q); if (mmal_port_send_buffer(encoder_output_port, buffer)!= MMAL_SUCCESS) vcos_log_error("Unable to send a buffer to encoder output port (%d)", q); } } // Now wait until we need to stop vcos_sleep(state.timeout); printf("Finished capture\n"); } else vcos_sleep(state.timeout); } } else { mmal_status_to_int(status); vcos_log_error("%s: Failed to connect camera to preview", __func__); } error: mmal_status_to_int(status); if (state.verbose) printf("Closing down\n"); // Disable all our ports that are not handled by connections check_disable_port(camera_still_port); check_disable_port(encoder_output_port); if (state.preview_parameters.wantPreview ) mmal_connection_destroy(state.preview_connection); mmal_connection_destroy(state.encoder_connection); // Can now close our file. Note disabling ports may flush buffers which causes // problems if we have already closed the file! if (output_file) fclose(output_file); /* Disable components */ if (state.encoder_component) mmal_component_disable(state.encoder_component); if (state.preview_parameters.preview_component) mmal_component_disable(state.preview_parameters.preview_component); if (state.camera_component) mmal_component_disable(state.camera_component); destroy_encoder_component(&state); raspipreview_destroy(&state.preview_parameters); destroy_camera_component(&state); if (state.verbose) printf("Close down completed, all components disconnected, disabled and destroyed\n\n"); } return 0; }
uint8_t *internelPhotoWithDetails(int width, int height, int quality,MMAL_FOURCC_T encoding, PicamParams *parms, long *sizeread) { RASPISTILL_STATE state; MMAL_STATUS_T status = MMAL_SUCCESS; MMAL_PORT_T *preview_input_port = NULL; MMAL_PORT_T *camera_preview_port = NULL; MMAL_PORT_T *camera_still_port = NULL; MMAL_PORT_T *encoder_input_port = NULL; MMAL_PORT_T *encoder_output_port = NULL; if (width > 2592) { width = 2592; } else if (width < 20) { width = 20; } if (height > 1944) { height = 1944; } else if (height < 20) { height = 20; } if (quality > 100) { quality = 100; } else if (quality < 0) { quality = 85; } bcm_host_init(); default_status(&state); state.width = width; state.height = height; state.quality = quality; state.encoding = encoding; state.videoEncode = 0; state.camera_parameters.exposureMode = parms->exposure; state.camera_parameters.exposureMeterMode = parms->meterMode; state.camera_parameters.awbMode = parms->awbMode; state.camera_parameters.imageEffect = parms->imageFX; state.camera_parameters.ISO = parms->ISO; state.camera_parameters.sharpness = parms->sharpness; state.camera_parameters.contrast = parms->contrast; state.camera_parameters.brightness= parms->brightness; state.camera_parameters.saturation = parms->saturation; state.camera_parameters.videoStabilisation = parms->videoStabilisation; /// 0 or 1 (false or true) state.camera_parameters.exposureCompensation = parms->exposureCompensation; state.camera_parameters.rotation = parms->rotation; state.camera_parameters.hflip = parms->hflip; state.camera_parameters.vflip = parms->vflip; MMAL_COMPONENT_T *preview = 0; if ((status = create_video_camera_component(&state)) != MMAL_SUCCESS) { vcos_log_error("%s: Failed to create camera component", __func__); } else if ((status = mmal_component_create("vc.null_sink", &preview)) != MMAL_SUCCESS) { vcos_log_error("%s: Failed to create preview component", __func__); destroy_camera_component(&state); } else if ((status = create_encoder_component(&state)) != MMAL_SUCCESS) { vcos_log_error("%s: Failed to create encode component", __func__); destroy_camera_component(&state); } else { status = mmal_component_enable(preview); state.preview_component = preview; PORT_USERDATA callback_data; camera_preview_port = state.camera_component->output[MMAL_CAMERA_PREVIEW_PORT]; camera_still_port = state.camera_component->output[MMAL_CAMERA_CAPTURE_PORT]; encoder_input_port = state.encoder_component->input[0]; encoder_output_port = state.encoder_component->output[0]; preview_input_port = state.preview_component->input[0]; status = connect_ports(camera_preview_port, preview_input_port, &state.preview_connection); VCOS_STATUS_T vcos_status; // Now connect the camera to the encoder status = connect_ports(camera_still_port, encoder_input_port, &state.encoder_connection); if (status != MMAL_SUCCESS) { vcos_log_error("%s: Failed to connect camera video port to encoder input", __func__); goto error; } // Set up our userdata - this is passed though to the callback where we need the information. // Null until we open our filename callback_data.pstate = &state; vcos_status = vcos_semaphore_create(&callback_data.complete_semaphore, "picam-sem", 0); vcos_assert(vcos_status == VCOS_SUCCESS); if (status != MMAL_SUCCESS) { vcos_log_error("Failed to setup encoder output"); goto error; } int num, q; // Enable the encoder output port encoder_output_port->userdata = (struct MMAL_PORT_USERDATA_T *)&callback_data; // Enable the encoder output port and tell it its callback function status = mmal_port_enable(encoder_output_port, encoder_buffer_callback); // Send all the buffers to the encoder output port num = mmal_queue_length(state.encoder_pool->queue); for (q=0;q<num;q++) { MMAL_BUFFER_HEADER_T *buffer = mmal_queue_get(state.encoder_pool->queue); if (!buffer) vcos_log_error("Unable to get a required buffer %d from pool queue", q); if (mmal_port_send_buffer(encoder_output_port, buffer)!= MMAL_SUCCESS) vcos_log_error("Unable to send a buffer to encoder output port (%d)", q); } if (mmal_port_parameter_set_boolean(camera_still_port, MMAL_PARAMETER_CAPTURE, 1) != MMAL_SUCCESS) { vcos_log_error("%s: Failed to start capture", __func__); } else { // Wait for capture to complete // For some reason using vcos_semaphore_wait_timeout sometimes returns immediately with bad parameter error // even though it appears to be all correct, so reverting to untimed one until figure out why its erratic vcos_semaphore_wait(&callback_data.complete_semaphore); } // Disable encoder output port status = mmal_port_disable(encoder_output_port); *sizeread = state.bytesStored; vcos_semaphore_delete(&callback_data.complete_semaphore); } error: mmal_status_to_int(status); // Disable all our ports that are not handled by connections check_disable_port(encoder_output_port); mmal_connection_destroy(state.encoder_connection); if (state.encoder_component) mmal_component_disable(state.encoder_component); if (state.preview_component) { mmal_component_disable(state.preview_component); mmal_component_destroy(state.preview_component); state.preview_component = NULL; } if (state.camera_component) mmal_component_disable(state.camera_component); destroy_encoder_component(&state); destroy_camera_component(&state); if (status != MMAL_SUCCESS) raspicamcontrol_check_configuration(128); return state.filedata; }
/** * main */ int main(int argc, const char **argv) { // Our main data storage vessel.. RASPIVID_STATE state; MMAL_STATUS_T status = MMAL_SUCCESS; MMAL_PORT_T *camera_preview_port = NULL; MMAL_PORT_T *camera_video_port = NULL; MMAL_PORT_T *camera_still_port = NULL; MMAL_PORT_T *preview_input_port = NULL; MMAL_PORT_T *encoder_input_port = NULL; MMAL_PORT_T *encoder_output_port = NULL; FILE *output_file = NULL; bcm_host_init(); // Register our application with the logging system vcos_log_register("RaspiVid", VCOS_LOG_CATEGORY); signal(SIGINT, signal_handler); default_status(&state); // Do we have any parameters if (argc == 1) { fprintf(stderr, "\n%s Camera App %s\n\n", basename(argv[0]), VERSION_STRING); display_valid_parameters(basename(argv[0])); exit(0); } // Parse the command line and put options in to our status structure if (parse_cmdline(argc, argv, &state)) { status = -1; exit(0); } if (state.verbose) { fprintf(stderr, "\n%s Camera App %s\n\n", basename(argv[0]), VERSION_STRING); dump_status(&state); } // OK, we have a nice set of parameters. Now set up our components // We have three components. Camera, Preview and encoder. if ((status = create_camera_component(&state)) != MMAL_SUCCESS) { vcos_log_error("%s: Failed to create camera component", __func__); } else if ((status = raspipreview_create(&state.preview_parameters)) != MMAL_SUCCESS) { vcos_log_error("%s: Failed to create preview component", __func__); destroy_camera_component(&state); } else if ((status = create_encoder_component(&state)) != MMAL_SUCCESS) { vcos_log_error("%s: Failed to create encode component", __func__); raspipreview_destroy(&state.preview_parameters); destroy_camera_component(&state); } else { PORT_USERDATA callback_data; if (state.verbose) fprintf(stderr, "Starting component connection stage\n"); camera_preview_port = state.camera_component->output[MMAL_CAMERA_PREVIEW_PORT]; camera_video_port = state.camera_component->output[MMAL_CAMERA_VIDEO_PORT]; camera_still_port = state.camera_component->output[MMAL_CAMERA_CAPTURE_PORT]; preview_input_port = state.preview_parameters.preview_component->input[0]; encoder_input_port = state.encoder_component->input[0]; encoder_output_port = state.encoder_component->output[0]; if (state.preview_parameters.wantPreview ) { if (state.verbose) { fprintf(stderr, "Connecting camera preview port to preview input port\n"); fprintf(stderr, "Starting video preview\n"); } // Connect camera to preview status = connect_ports(camera_preview_port, preview_input_port, &state.preview_connection); } else { status = MMAL_SUCCESS; } if (status == MMAL_SUCCESS) { if (state.verbose) fprintf(stderr, "Connecting camera stills port to encoder input port\n"); // Now connect the camera to the encoder status = connect_ports(camera_video_port, encoder_input_port, &state.encoder_connection); if (status != MMAL_SUCCESS) { vcos_log_error("%s: Failed to connect camera video port to encoder input", __func__); goto error; } if (state.filename) { if (state.filename[0] == '-') { output_file = stdout; // Ensure we don't upset the output stream with diagnostics/info state.verbose = 0; } else { if (state.verbose) fprintf(stderr, "Opening output file \"%s\"\n", state.filename); output_file = fopen(state.filename, "wb"); } if (!output_file) { // Notify user, carry on but discarding encoded output buffers vcos_log_error("%s: Error opening output file: %s\nNo output file will be generated\n", __func__, state.filename); } } // Set up our userdata - this is passed though to the callback where we need the information. callback_data.file_handle = output_file; callback_data.image = Mat(Size(state.width, state.height), CV_8UC1); callback_data.pstate = &state; callback_data.abort = 0; encoder_output_port->userdata = (struct MMAL_PORT_USERDATA_T *)&callback_data; if (state.verbose) fprintf(stderr, "Enabling encoder output port\n"); // Enable the encoder output port and tell it its callback function status = mmal_port_enable(encoder_output_port, encoder_buffer_callback); if (status != MMAL_SUCCESS) { vcos_log_error("Failed to setup encoder output"); goto error; } if (state.demoMode) { // Run for the user specific time.. int num_iterations = state.timeout / state.demoInterval; int i; if (state.verbose) fprintf(stderr, "Running in demo mode\n"); for (i=0;state.timeout == 0 || i<num_iterations;i++) { raspicamcontrol_cycle_test(state.camera_component); vcos_sleep(state.demoInterval); } } else { // Only encode stuff if we have a filename and it opened if (output_file) { int wait; if (state.verbose) fprintf(stderr, "Starting video capture\n"); if (mmal_port_parameter_set_boolean(camera_video_port, MMAL_PARAMETER_CAPTURE, 1) != MMAL_SUCCESS) { goto error; } // Send all the buffers to the encoder output port { int num = mmal_queue_length(state.encoder_pool->queue); int q; for (q=0;q<num;q++) { MMAL_BUFFER_HEADER_T *buffer = mmal_queue_get(state.encoder_pool->queue); if (!buffer) vcos_log_error("Unable to get a required buffer %d from pool queue", q); if (mmal_port_send_buffer(encoder_output_port, buffer)!= MMAL_SUCCESS) vcos_log_error("Unable to send a buffer to encoder output port (%d)", q); } } // Now wait until we need to stop. Whilst waiting we do need to check to see if we have aborted (for example // out of storage space) // Going to check every ABORT_INTERVAL milliseconds for (wait = 0; state.timeout == 0 || wait < state.timeout; wait+= ABORT_INTERVAL) { vcos_sleep(ABORT_INTERVAL); if (callback_data.abort) break; } if (state.verbose) fprintf(stderr, "Finished capture\n"); } else { if (state.timeout) vcos_sleep(state.timeout); else for (;;) vcos_sleep(ABORT_INTERVAL); } } } else { mmal_status_to_int(status); vcos_log_error("%s: Failed to connect camera to preview", __func__); } error: mmal_status_to_int(status); if (state.verbose) fprintf(stderr, "Closing down\n"); // Disable all our ports that are not handled by connections check_disable_port(camera_still_port); check_disable_port(encoder_output_port); if (state.preview_parameters.wantPreview ) mmal_connection_destroy(state.preview_connection); mmal_connection_destroy(state.encoder_connection); // Can now close our file. Note disabling ports may flush buffers which causes // problems if we have already closed the file! if (output_file && output_file != stdout) fclose(output_file); /* Disable components */ if (state.encoder_component) mmal_component_disable(state.encoder_component); if (state.preview_parameters.preview_component) mmal_component_disable(state.preview_parameters.preview_component); if (state.camera_component) mmal_component_disable(state.camera_component); destroy_encoder_component(&state); raspipreview_destroy(&state.preview_parameters); destroy_camera_component(&state); if (state.verbose) fprintf(stderr, "Close down completed, all components disconnected, disabled and destroyed\n\n"); } if (status != MMAL_SUCCESS) raspicamcontrol_check_configuration(128); return 0; }
int init_cam() { bcm_host_init(); // Register our application with the logging system vcos_log_register("RaspiStill", VCOS_LOG_CATEGORY); signal(SIGINT, signal_handler); default_status(&gState); if ((gStatus = create_camera_component(&gState)) != MMAL_SUCCESS) { vcos_log_error("%s: Failed to create camera component", __func__); gStatus = ! MMAL_SUCCESS; } else if ((gStatus = nullsink_preview(&gState.preview_parameters)) != MMAL_SUCCESS) { vcos_log_error("%s: Failed to create preview component", __func__); destroy_camera_component(&gState); gStatus = ! MMAL_SUCCESS; } else { gCamera_preview_port = gState.camera_component->output[MMAL_CAMERA_PREVIEW_PORT]; gCamera_video_port = gState.camera_component->output[MMAL_CAMERA_VIDEO_PORT]; gCamera_still_port = gState.camera_component->output[MMAL_CAMERA_CAPTURE_PORT]; // Note we are lucky that the preview and null sink components use the same input port // so we can simple do this without conditionals gPreview_input_port = gState.preview_parameters.preview_component->input[0]; // Connect camera to preview (which might be a null_sink if no preview required) gStatus = connect_ports(gCamera_preview_port, gPreview_input_port, &gState.preview_connection); if (gStatus == MMAL_SUCCESS) { VCOS_STATUS_T vcos_status; // Set up our userdata - this is passed though to the callback where we need the information. gCallback_data.pstate = &gState; vcos_status = vcos_semaphore_create(&gCallback_data.complete_semaphore, "RaspiStill-sem", 0); vcos_assert(vcos_status == VCOS_SUCCESS); gCamera_still_port->userdata = (struct MMAL_PORT_USERDATA_T *)&gCallback_data; // Enable the camera still output port and tell it its callback function gStatus = mmal_port_enable(gCamera_still_port, camera_buffer_callback); if (gStatus != MMAL_SUCCESS) { vcos_log_error("Failed to setup camera output"); error_cam(); } } else { mmal_status_to_int(gStatus); vcos_log_error("%s: Failed to connect camera to preview", __func__); } } if (gStatus != MMAL_SUCCESS) raspicamcontrol_check_configuration(128); return gStatus != MMAL_SUCCESS; }
MmalStillCamera::MmalStillCamera(int imageWidth, int imageHeight, bool enableBurstMode) : m_imageWidth(imageWidth), m_imageHeight(imageHeight), m_callbackData(NULL), m_cs(), m_camera(NULL), m_preview(NULL), m_encoder(NULL), m_pool(NULL), m_previewPort(NULL), m_videoPort(NULL), m_stillPort(NULL), m_targetPort(NULL) { m_callbackData = new MmalStillCallbackData(m_imageWidth, m_imageHeight, 3); createCameraComponent(); std::cout << "Created camera" << std::endl; createPreview(); std::cout << "Created preview" << std::endl; std::cout << "Target Image Width: " << VCOS_ALIGN_UP(m_imageWidth, 32) << std::endl; std::cout << "Target Image Height: " << VCOS_ALIGN_UP(m_imageHeight, 16) << std::endl; MMAL_STATUS_T status; m_targetPort = m_stillPort; // Create pool of buffer headers for the output port to consume m_pool = mmal_port_pool_create(m_targetPort, m_targetPort->buffer_num, m_targetPort->buffer_size); if (m_pool == NULL) { throw Exception("Failed to create buffer header pool for encoder output port"); } MMAL_CONNECTION_T *preview_connection = NULL; status = connect_ports(m_previewPort, m_preview->input[0], &preview_connection); if (status != MMAL_SUCCESS) { throw Exception("Error connecting preview port"); } m_targetPort->userdata = (struct MMAL_PORT_USERDATA_T *) m_callbackData; m_callbackData->image = NULL; m_callbackData->pool = m_pool; // Enable the encoder output port and tell it its callback function if (mmal_port_enable(m_targetPort, EncoderBufferCallback) != MMAL_SUCCESS) { std::cerr << "Error enabling the encoder buffer callback" << std::endl; } // Send all the buffers to the encoder output port int num = mmal_queue_length(m_pool->queue); for (int q = 0; q < num; q++) { MMAL_BUFFER_HEADER_T *buffer = mmal_queue_get(m_pool->queue); if (buffer == NULL) { std::cerr << "Unable to get buffer " << q << " from the pool" << std::endl; } if (mmal_port_send_buffer(m_targetPort, buffer)!= MMAL_SUCCESS) { std::cerr << "Unable to send a buffer " << q << " to encoder output port " << std::endl; } } // Enable burst mode if (enableBurstMode) { if (mmal_port_parameter_set_boolean(m_camera->control, MMAL_PARAMETER_CAMERA_BURST_CAPTURE, 1) != MMAL_SUCCESS) { std::cerr << "Error enabling burst mode" << std::endl; } std::cout << "Enabled burst mode for still images" << std::endl; } std::cout << "Initialized camera" << std::endl; }
void internelVideoWithDetails(char *filename, int width, int height, int duration) { RASPISTILL_STATE state; MMAL_STATUS_T status = MMAL_SUCCESS; MMAL_PORT_T *camera_video_port = NULL; MMAL_PORT_T *encoder_input_port = NULL; MMAL_PORT_T *encoder_output_port = NULL; FILE *output_file = NULL; if (width > 1920) { width = 1920; } else if (width < 20) { width = 20; } if (height > 1080) { height = 1080; } else if (height < 20) { height = 20; } bcm_host_init(); default_status(&state); state.width = width; state.height = height; state.quality = 0; state.videoEncode = 1; state.filename = filename; if ((status = create_video_camera_component(&state)) != MMAL_SUCCESS) { vcos_log_error("%s: Failed to create camera component", __func__); } else if ((status = create_video_encoder_component(&state)) != MMAL_SUCCESS) { vcos_log_error("%s: Failed to create encode component", __func__); destroy_camera_component(&state); } else { PORT_USERDATA callback_data; camera_video_port = state.camera_component->output[MMAL_CAMERA_VIDEO_PORT]; encoder_input_port = state.encoder_component->input[0]; encoder_output_port = state.encoder_component->output[0]; // Now connect the camera to the encoder status = connect_ports(camera_video_port, encoder_input_port, &state.encoder_connection); if (status != MMAL_SUCCESS) { vcos_log_error("%s: Failed to connect camera video port to encoder input", __func__); goto error; } // Set up our userdata - this is passed though to the callback where we need the information. // Null until we open our filename callback_data.pstate = &state; if (status != MMAL_SUCCESS) { vcos_log_error("Failed to setup encoder output"); goto error; } if (state.filename) { output_file = fopen(state.filename, "wb"); callback_data.file_handle = output_file; callback_data.pstate = &state; callback_data.abort = 0; } encoder_output_port->userdata = (struct MMAL_PORT_USERDATA_T *)&callback_data; int wait; // Enable the encoder output port and tell it its callback function status = mmal_port_enable(encoder_output_port, encoder_buffer_callback); if (mmal_port_parameter_set_boolean(camera_video_port, MMAL_PARAMETER_CAPTURE, 1) != MMAL_SUCCESS) { goto error; } // Send all the buffers to the encoder output port { int num = mmal_queue_length(state.encoder_pool->queue); int q; for (q=0;q<num;q++) { MMAL_BUFFER_HEADER_T *buffer = mmal_queue_get(state.encoder_pool->queue); if (!buffer) vcos_log_error("Unable to get a required buffer %d from pool queue", q); if (mmal_port_send_buffer(encoder_output_port, buffer)!= MMAL_SUCCESS) vcos_log_error("Unable to send a buffer to encoder output port (%d)", q); } } for (wait = 0; wait < duration; wait+= ABORT_INTERVAL) { vcos_sleep(ABORT_INTERVAL); if (callback_data.abort) break; } // Disable encoder output port status = mmal_port_disable(encoder_output_port); vcos_semaphore_delete(&callback_data.complete_semaphore); } error: mmal_status_to_int(status); // Disable all our ports that are not handled by connections check_disable_port(encoder_output_port); if (output_file && output_file != stdout) fclose(output_file); mmal_connection_destroy(state.encoder_connection); if (state.encoder_component) mmal_component_disable(state.encoder_component); if (state.camera_component) mmal_component_disable(state.camera_component); destroy_encoder_component(&state); destroy_camera_component(&state); if (status != MMAL_SUCCESS) raspicamcontrol_check_configuration(128); }
/** * main */ int main(int argc, const char **argv) { // Our main data storage vessel.. RASPISTILLYUV_STATE state; int exit_code = EX_OK; MMAL_STATUS_T status = MMAL_SUCCESS; MMAL_PORT_T *camera_preview_port = NULL; MMAL_PORT_T *camera_video_port = NULL; MMAL_PORT_T *camera_still_port = NULL; MMAL_PORT_T *preview_input_port = NULL; FILE *output_file = NULL; bcm_host_init(); // Register our application with the logging system vcos_log_register("RaspiStill", VCOS_LOG_CATEGORY); signal(SIGINT, signal_handler); // Disable USR1 for the moment - may be reenabled if go in to signal capture mode signal(SIGUSR1, SIG_IGN); default_status(&state); // Do we have any parameters if (argc == 1) { fprintf(stdout, "\n%s Camera App %s\n\n", basename(argv[0]), VERSION_STRING); display_valid_parameters(basename(argv[0])); exit(EX_USAGE); } default_status(&state); // Parse the command line and put options in to our status structure if (parse_cmdline(argc, argv, &state)) { status = -1; exit(EX_USAGE); } if (state.verbose) { fprintf(stderr, "\n%s Camera App %s\n\n", basename(argv[0]), VERSION_STRING); dump_status(&state); } // OK, we have a nice set of parameters. Now set up our components // We have two components. Camera and Preview // Camera is different in stills/video, but preview // is the same so handed off to a separate module if ((status = create_camera_component(&state)) != MMAL_SUCCESS) { vcos_log_error("%s: Failed to create camera component", __func__); exit_code = EX_SOFTWARE; } else if ((status = raspipreview_create(&state.preview_parameters)) != MMAL_SUCCESS) { vcos_log_error("%s: Failed to create preview component", __func__); destroy_camera_component(&state); exit_code = EX_SOFTWARE; } else { PORT_USERDATA callback_data; if (state.verbose) fprintf(stderr, "Starting component connection stage\n"); camera_preview_port = state.camera_component->output[MMAL_CAMERA_PREVIEW_PORT]; camera_video_port = state.camera_component->output[MMAL_CAMERA_VIDEO_PORT]; camera_still_port = state.camera_component->output[MMAL_CAMERA_CAPTURE_PORT]; // Note we are lucky that the preview and null sink components use the same input port // so we can simple do this without conditionals preview_input_port = state.preview_parameters.preview_component->input[0]; // Connect camera to preview (which might be a null_sink if no preview required) status = connect_ports(camera_preview_port, preview_input_port, &state.preview_connection); if (status == MMAL_SUCCESS) { VCOS_STATUS_T vcos_status; // Set up our userdata - this is passed though to the callback where we need the information. // Null until we open our filename callback_data.file_handle = NULL; callback_data.pstate = &state; vcos_status = vcos_semaphore_create(&callback_data.complete_semaphore, "RaspiStill-sem", 0); vcos_assert(vcos_status == VCOS_SUCCESS); camera_still_port->userdata = (struct MMAL_PORT_USERDATA_T *)&callback_data; if (state.verbose) fprintf(stderr, "Enabling camera still output port\n"); // Enable the camera still output port and tell it its callback function status = mmal_port_enable(camera_still_port, camera_buffer_callback); if (status != MMAL_SUCCESS) { vcos_log_error("Failed to setup camera output"); goto error; } if (state.verbose) fprintf(stderr, "Starting video preview\n"); int frame, keep_looping = 1; FILE *output_file = NULL; char *use_filename = NULL; // Temporary filename while image being written char *final_filename = NULL; // Name that file gets once writing complete frame = 0; while (keep_looping) { keep_looping = wait_for_next_frame(&state, &frame); // Open the file if (state.filename) { if (state.filename[0] == '-') { output_file = stdout; // Ensure we don't upset the output stream with diagnostics/info state.verbose = 0; } else { vcos_assert(use_filename == NULL && final_filename == NULL); status = create_filenames(&final_filename, &use_filename, state.filename, frame); if (status != MMAL_SUCCESS) { vcos_log_error("Unable to create filenames"); goto error; } if (state.verbose) fprintf(stderr, "Opening output file %s\n", final_filename); // Technically it is opening the temp~ filename which will be ranamed to the final filename output_file = fopen(use_filename, "wb"); if (!output_file) { // Notify user, carry on but discarding encoded output buffers vcos_log_error("%s: Error opening output file: %s\nNo output file will be generated\n", __func__, use_filename); } } callback_data.file_handle = output_file; } if (output_file) { int num, q; // There is a possibility that shutter needs to be set each loop. if (mmal_status_to_int(mmal_port_parameter_set_uint32(state.camera_component->control, MMAL_PARAMETER_SHUTTER_SPEED, state.camera_parameters.shutter_speed) != MMAL_SUCCESS)) vcos_log_error("Unable to set shutter speed"); // Send all the buffers to the camera output port num = mmal_queue_length(state.camera_pool->queue); for (q=0;q<num;q++) { MMAL_BUFFER_HEADER_T *buffer = mmal_queue_get(state.camera_pool->queue); if (!buffer) vcos_log_error("Unable to get a required buffer %d from pool queue", q); if (mmal_port_send_buffer(camera_still_port, buffer)!= MMAL_SUCCESS) vcos_log_error("Unable to send a buffer to camera output port (%d)", q); } if (state.burstCaptureMode && frame==1) { mmal_port_parameter_set_boolean(state.camera_component->control, MMAL_PARAMETER_CAMERA_BURST_CAPTURE, 1); } if (state.verbose) fprintf(stderr, "Starting capture %d\n", frame); if (mmal_port_parameter_set_boolean(camera_still_port, MMAL_PARAMETER_CAPTURE, 1) != MMAL_SUCCESS) { vcos_log_error("%s: Failed to start capture", __func__); } else { // Wait for capture to complete // For some reason using vcos_semaphore_wait_timeout sometimes returns immediately with bad parameter error // even though it appears to be all correct, so reverting to untimed one until figure out why its erratic vcos_semaphore_wait(&callback_data.complete_semaphore); if (state.verbose) fprintf(stderr, "Finished capture %d\n", frame); } // Ensure we don't die if get callback with no open file callback_data.file_handle = NULL; if (output_file != stdout) { rename_file(&state, output_file, final_filename, use_filename, frame); } } if (use_filename) { free(use_filename); use_filename = NULL; } if (final_filename) { free(final_filename); final_filename = NULL; } } // end for (frame) vcos_semaphore_delete(&callback_data.complete_semaphore); } else { mmal_status_to_int(status); vcos_log_error("%s: Failed to connect camera to preview", __func__); } error: mmal_status_to_int(status); if (state.verbose) fprintf(stderr, "Closing down\n"); if (output_file) fclose(output_file); // Disable all our ports that are not handled by connections check_disable_port(camera_video_port); if (state.preview_connection) mmal_connection_destroy(state.preview_connection); /* Disable components */ if (state.preview_parameters.preview_component) mmal_component_disable(state.preview_parameters.preview_component); if (state.camera_component) mmal_component_disable(state.camera_component); raspipreview_destroy(&state.preview_parameters); destroy_camera_component(&state); if (state.verbose) fprintf(stderr, "Close down completed, all components disconnected, disabled and destroyed\n\n"); } if (status != MMAL_SUCCESS) raspicamcontrol_check_configuration(128); return exit_code; }
int lp_ladspa_audio_ports::run_interlaced_buffer(float *buffer, int tot_len) { if(pv_routing == MONO_NORMAL){ // Copy interlaced to plugin input pv_in_data[0].set_data_copy(buffer, tot_len); if(connect_ports() < 0){ std::cerr << "lp_ladspa_audio_ports::" << __FUNCTION__ << ": connect_ports failed\n"; return -1; } pv_instances[0].run(tot_len); pv_out_data[0].get_data_copy(buffer, tot_len); }else if(pv_routing == MONO_HALF_USED){ // Only use One I/O port, the others must simply benn allocated to run pv_in_data[0].set_data_copy(buffer, tot_len); if(connect_ports() < 0){ std::cerr << "lp_ladspa_audio_ports::" << __FUNCTION__ << ": connect_ports failed\n"; return -1; } pv_instances[0].run(tot_len); pv_out_data[0].get_data_copy(buffer, tot_len); }else if(pv_routing == MONO_1H_MERGE_OUTPUT){ // Copy interlaced to plugin input pv_in_data[0].set_data_copy(buffer, tot_len); if(connect_ports() < 0){ std::cerr << "lp_ladspa_audio_ports::" << __FUNCTION__ << ": connect_ports failed\n"; return -1; } pv_instances[0].run(tot_len); // Mix the two outputs result to the passed buffer back mix_data(buffer, pv_out_data[0].data_ptr(), pv_out_data[1].data_ptr(), tot_len); }else if(pv_routing == MONO_1H_SPLIT_INPUT){ // Copy interlaced to plugin input (same data to each) pv_in_data[0].set_data_copy(buffer, tot_len); pv_in_data[1].set_data_copy(buffer, tot_len); if(connect_ports() < 0){ std::cerr << "lp_ladspa_audio_ports::" << __FUNCTION__ << ": connect_ports failed\n"; return -1; } pv_instances[0].run(tot_len); pv_out_data[0].get_data_copy(buffer, tot_len); }else if(pv_routing == MONO_1H_NO_INPUT){ // No input.. if(connect_ports() < 0){ std::cerr << "lp_ladspa_audio_ports::" << __FUNCTION__ << ": connect_ports failed\n"; return -1; } pv_instances[0].run(tot_len); pv_out_data[0].get_data_copy(buffer, tot_len); }else if(pv_routing == MONO_1H_NO_INPUT_MERGE_OUTPUT){ // No input.. if(connect_ports() < 0){ std::cerr << "lp_ladspa_audio_ports::" << __FUNCTION__ << ": connect_ports failed\n"; return -1; } pv_instances[0].run(tot_len); mix_data(buffer, pv_out_data[0].data_ptr(), pv_out_data[1].data_ptr(), tot_len); }else if(pv_routing == STEREO_NORMAL){ // Copy interlaced to plugin inputs pv_in_data[0].set_data_left_copy(buffer, tot_len); pv_in_data[1].set_data_right_copy(buffer, tot_len); if(connect_ports() < 0){ std::cerr << "lp_ladspa_audio_ports::" << __FUNCTION__ << ": connect_ports failed\n"; return -1; } pv_instances[0].run(tot_len/2); pv_out_data[0].get_data_left_copy(buffer, tot_len); pv_out_data[1].get_data_right_copy(buffer, tot_len); }else if(pv_routing == STEREO_2H){ // Copy interlaced to plugin inputs pv_in_data[0].set_data_left_copy(buffer, tot_len); pv_in_data[0].set_data_right_copy(buffer, tot_len); if(connect_ports() < 0){ std::cerr << "lp_ladspa_audio_ports::" << __FUNCTION__ << ": connect_ports failed\n"; return -1; } pv_instances[0].run(tot_len/2); pv_instances[1].run(tot_len/2); pv_out_data[0].get_data_left_copy(buffer, tot_len); pv_out_data[0].get_data_right_copy(buffer, tot_len); }else if(pv_routing == STEREO_2H_MERGE_OUTPUT){ // Copy interlaced to plugin inputs pv_in_data[0].set_data_left_copy(buffer, tot_len); pv_in_data[0].set_data_right_copy(buffer, tot_len); if(connect_ports() < 0){ std::cerr << "lp_ladspa_audio_ports::" << __FUNCTION__ << ": connect_ports failed\n"; return -1; } pv_instances[0].run(tot_len/2); pv_instances[1].run(tot_len/2); // Mix data 0 and 2, and store it temporary to passed buffer (half len) mix_data(buffer, pv_out_data[0].data_ptr(), pv_out_data[2].data_ptr(), tot_len/2); // Store buffer content to tmp 0 pv_tmp_data[0].set_data_copy(buffer, tot_len/2); // The same with 1 and 3 mix_data(buffer, pv_out_data[1].data_ptr(), pv_out_data[3].data_ptr(), tot_len/2); pv_tmp_data[1].set_data_copy(buffer, tot_len/2); // Copy tmp 1 and 2 to passed buffer - Ouf ! pv_tmp_data[0].get_data_left_copy(buffer, tot_len); pv_tmp_data[0].get_data_right_copy(buffer, tot_len); }else{ return -1; } return tot_len; }