bool CCamera::Init(int width, int height, int framerate, int num_levels, bool do_argb_conversion) { //init broadcom host - QUESTION: can this be called more than once?? bcm_host_init(); //store basic parameters Width = width; Height = height; FrameRate = framerate; // Set up the camera_parameters to default raspicamcontrol_set_defaults(&CameraParameters); // Change default parameter, i.e .rotate image int rotation = 90; int my_rotation = ((rotation % 360 ) / 90) * 90; CameraParameters.rotation = my_rotation; //ret = mmal_port_parameter_set_int32(camera->output[0], MMAL_PARAMETER_ROTATION, my_rotation); //mmal_port_parameter_set_int32(camera->output[1], MMAL_PARAMETER_ROTATION, my_rotation); //mmal_port_parameter_set_int32(camera->output[2], MMAL_PARAMETER_ROTATION, my_rotation); #ifdef WITH_ENCODER MMAL_COMPONENT_T *encoder = 0; #endif MMAL_COMPONENT_T *camera = 0; MMAL_COMPONENT_T *splitter = 0; MMAL_CONNECTION_T* vid_to_split_connection = 0; MMAL_PORT_T *video_port = NULL; MMAL_STATUS_T status; CCameraOutput* outputs[4]; memset(outputs,0,sizeof(outputs)); //create the camera component camera = CreateCameraComponentAndSetupPorts(); if (!camera) goto error; //get the video port video_port = camera->output[MMAL_CAMERA_VIDEO_PORT]; video_port->buffer_num = 3; //create the splitter component splitter = CreateSplitterComponentAndSetupPorts(video_port); if(!splitter) goto error; //create and enable a connection between the video output and the resizer input status = mmal_connection_create(&vid_to_split_connection, video_port, splitter->input[0], MMAL_CONNECTION_FLAG_TUNNELLING | MMAL_CONNECTION_FLAG_ALLOCATION_ON_INPUT); if (status != MMAL_SUCCESS) { printf("Failed to create connection\n"); goto error; } status = mmal_connection_enable(vid_to_split_connection); if (status != MMAL_SUCCESS) { printf("Failed to enable connection\n"); goto error; } //setup all the outputs for(int i = 0; i < num_levels; i++) { outputs[i] = new CCameraOutput(); if(!outputs[i]->Init(Width >> i,Height >> i,splitter,i,do_argb_conversion)) { printf("Failed to initialize output %d\n",i); goto error; } } #ifdef WITH_ENCODER encoder = CreateEncoderComponentAndSetupPorts(); if (!encoder) goto error; #endif //begin capture if (mmal_port_parameter_set_boolean(video_port, MMAL_PARAMETER_CAPTURE, 1) != MMAL_SUCCESS) { printf("Failed to start capture\n"); goto error; } //store created info CameraComponent = camera; SplitterComponent = splitter; VidToSplitConn = vid_to_split_connection; memcpy(Outputs,outputs,sizeof(outputs)); //return success printf("Camera successfully created\n"); return true; error: if(vid_to_split_connection) mmal_connection_destroy(vid_to_split_connection); if(camera) mmal_component_destroy(camera); if(splitter) mmal_component_destroy(splitter); for(int i = 0; i < 4; i++) { if(outputs[i]) { outputs[i]->Release(); delete outputs[i]; } } #ifdef WITH_ENCODER if(encoder){} #endif return false; }
bool CCamera::Init(int width, int height, int framerate, int num_levels, bool do_argb_conversion) { //init broadcom host - QUESTION: can this be called more than once?? bcm_host_init(); //store basic parameters Width = width; Height = height; FrameRate = framerate; // Set up the camera_parameters to default raspicamcontrol_set_defaults(&CameraParameters); MMAL_COMPONENT_T *camera = 0; MMAL_COMPONENT_T *splitter = 0; MMAL_CONNECTION_T* vid_to_split_connection = 0; MMAL_PORT_T *video_port = NULL; MMAL_STATUS_T status; CCameraOutput* outputs[4]; memset(outputs,0,sizeof(outputs)); //create the camera component camera = CreateCameraComponentAndSetupPorts(); if (!camera) goto error; //get the video port video_port = camera->output[MMAL_CAMERA_VIDEO_PORT]; video_port->buffer_num = 3; //create the splitter component splitter = CreateSplitterComponentAndSetupPorts(video_port); if(!splitter) goto error; //create and enable a connection between the video output and the resizer input status = mmal_connection_create(&vid_to_split_connection, video_port, splitter->input[0], MMAL_CONNECTION_FLAG_TUNNELLING | MMAL_CONNECTION_FLAG_ALLOCATION_ON_INPUT); if (status != MMAL_SUCCESS) { printf("Failed to create connection\n"); goto error; } status = mmal_connection_enable(vid_to_split_connection); if (status != MMAL_SUCCESS) { printf("Failed to enable connection\n"); goto error; } //setup all the outputs for(int i = 0; i < num_levels; i++) { outputs[i] = new CCameraOutput(); if(!outputs[i]->Init(Width >> i,Height >> i,splitter,i,do_argb_conversion)) { printf("Failed to initialize output %d\n",i); goto error; } } //begin capture if (mmal_port_parameter_set_boolean(video_port, MMAL_PARAMETER_CAPTURE, 1) != MMAL_SUCCESS) { printf("Failed to start capture\n"); goto error; } //store created info CameraComponent = camera; SplitterComponent = splitter; VidToSplitConn = vid_to_split_connection; memcpy(Outputs,outputs,sizeof(outputs)); //custom parameters raspicamcontrol_set_saturation(camera, 0); raspicamcontrol_set_contrast(camera, 100); raspicamcontrol_set_brightness(camera, 50); //raspicamcontrol_set_exposure_mode(camera, MMAL_PARAM_EXPOSUREMODE_OFF); //raspicamcontrol_set_awb_mode(camera, MMAL_PARAM_AWBMODE_OFF); raspicamcontrol_set_shutter_speed(camera, 2400); //return success printf("Camera successfully created\n"); return true; error: if(vid_to_split_connection) mmal_connection_destroy(vid_to_split_connection); if(camera) mmal_component_destroy(camera); if(splitter) mmal_component_destroy(splitter); for(int i = 0; i < 4; i++) { if(outputs[i]) { outputs[i]->Release(); delete outputs[i]; } } return false; }