Esempio n. 1
0
/**
 * Assign a default set of parameters to the state passed in
 *
 * @param state Pointer to state structure to assign defaults to
 */
static void default_status(RASPIVID_STATE *state)
{
   if (!state)
   {
      vcos_assert(0);
      return;
   }

   // Default everything to zero
   memset(state, 0, sizeof(RASPIVID_STATE));

   // Now set anything non-zero
   state->timeout = 5000;     // 5s delay before take image
   state->width = 1920;       // Default to 1080p
   state->height = 1080;
   state->bitrate = 17000000; // This is a decent default bitrate for 1080p
   state->framerate = VIDEO_FRAME_RATE_NUM;
   state->intraperiod = 0;    // Not set
   state->demoMode = 0;
   state->demoInterval = 250; // ms
   state->immutableInput = 1;

   // Setup preview window defaults
   raspipreview_set_defaults(&state->preview_parameters);

   // Set up the camera_parameters to default
   raspicamcontrol_set_defaults(&state->camera_parameters);
}
Esempio n. 2
0
/**
 * Assign a default set of parameters to the state passed in
 *
 * @param state Pointer to state structure to assign defaults to
 */
static void default_status(RASPISTILLYUV_STATE *state)
{
   if (!state)
   {
      vcos_assert(0);
      return;
   }

   // Default everything to zero
   memset(state, 0, sizeof(RASPISTILLYUV_STATE));

   // Now set anything non-zero
   state->timeout = 5000; // 5s delay before take image
   state->width = 2592;
   state->height = 1944;
   state->timelapse = 0;
   state->filename = NULL;
   state->linkname = NULL;
   state->verbose = 0;
   state->fullResPreview = 0;
   state->frameNextMethod = FRAME_NEXT_SINGLE;
   state->settings = 0;
   state->burstCaptureMode=0;

   // Setup preview window defaults
   raspipreview_set_defaults(&state->preview_parameters);

   // Set up the camera_parameters to default
   raspicamcontrol_set_defaults(&state->camera_parameters);
   
   // Set default camera
   state->cameraNum = 0;
}
Esempio n. 3
0
// default status
static void default_status(RASPIVID_STATE *state)
{
    if (!state)
    {
        vcos_assert(0);
        return;
    }

    // Default everything to zero
    memset(state, 0, sizeof(RASPIVID_STATE));

    // Now set anything non-zero
    state->timeout 			= 10000;     // 5s delay before take image
    state->width 			= 640;      // use a multiple of 320 (640, 1280)
    state->height 			= 480;		// use a multiple of 240 (480, 960)
    state->bitrate 			= 17000000; // This is a decent default bitrate for 1080p
    state->framerate 		= VIDEO_FRAME_RATE_NUM;
    state->immutableInput 	= 1;
    state->graymode 			= 1;		//gray by default, much faster than color (0)

    // Setup preview window defaults
    raspipreview_set_defaults(&state->preview_parameters);

    // Set up the camera_parameters to default
    raspicamcontrol_set_defaults(&state->camera_parameters);
}
Esempio n. 4
0
/**
 * Assign a default set of parameters to the state passed in
 *
 * @param state Pointer to state structure to assign defaults to
 */
static void default_status(RASPISTILL_STATE *state)
{
   if (!state) {
      vcos_assert(0);
      return;
   }   
   state->width = 2592;
   state->height = 1944;
   state->quality = 85;   
   state->bytesStored = 0l;
   /*Video*/
                    
   //state->bitrate = 17000000;
   state->bitrate = 5000000;
   state->framerate = VIDEO_FRAME_RATE_NUM;
   state->immutableInput = 0;
   state->intraperiod = 0;    // Not set
    
   state->camera_component = NULL;
   state->encoder_component = NULL;   
   state->encoder_connection = NULL;
   state->encoder_pool = NULL;
   state->encoding = MMAL_ENCODING_JPEG; //MMAL_ENCODING_BMP  
   raspicamcontrol_set_defaults(&state->camera_parameters);
   //state->camera_parameters.exposureMode = MMAL_PARAM_EXPOSUREMODE_NIGHT;
   //state->camera_parameters.exposureMeterMode = MMAL_PARAM_EXPOSUREMETERINGMODE_AVERAGE;
}
Esempio n. 5
0
/**
 * Assign a default set of parameters to the state passed in
 *
 * @param state Pointer to state structure to assign defaults to
 */
static void default_status(RASPISTILL_STATE *state)
{
   if (!state)
   {
      vcos_assert(0);
      return;
   }
	
	// *** PR : modif for demo purpose : smaller image
   state->timeout = 0;
   state->width = 320;
   state->height = 200;
   state->quality = 85;
   state->wantRAW = 0;
   state->filename = NULL;
   state->verbose = 0;
   state->thumbnailConfig.enable = 0;
   state->thumbnailConfig.width = 64;
   state->thumbnailConfig.height = 48;
   state->thumbnailConfig.quality = 35;
   state->demoMode = 0;
   state->demoInterval = 250; // ms
   state->camera_component = NULL;
   state->encoder_component = NULL;
   state->preview_connection = NULL;
   state->encoder_connection = NULL;
   state->encoder_pool = NULL;
   state->encoding = MMAL_ENCODING_JPEG;
   state->numExifTags = 0;
   state->timelapse = 0;

   // Setup preview window defaults
   raspipreview_set_defaults(&state->preview_parameters);

   // Set up the camera_parameters to default
   raspicamcontrol_set_defaults(&state->camera_parameters);
   
   //pr
   //state->camera_parameters.awbMode=MMAL_PARAM_AWBMODE_AUTO;
   
}
Esempio n. 6
0
/**
 * Assign a default set of parameters to the state passed in
 *
 * @param state Pointer to state structure to assign defaults to
 */
static void default_status(RASPISTILLYUV_STATE *state)
{
   if (!state)
   {
      vcos_assert(0);
      return;
   }

   // Default everything to zero
   memset(state, 0, sizeof(RASPISTILLYUV_STATE));

   // Now set anything non-zero
   state->timeout = 5000; // 5s delay before take image
   state->width = 2592;
   state->height = 1944;
   // Setup preview window defaults
   raspipreview_set_defaults(&state->preview_parameters);

   // Set up the camera_parameters to default
   raspicamcontrol_set_defaults(&state->camera_parameters);
}
Esempio n. 7
0
/**
 * Assign a default set of parameters to the state passed in
 *
 * @param state Pointer to state structure to assign defaults to
 */
static void default_status(RASPISTILL_STATE *state)
{
   if (!state)
   {
      vcos_assert(0);
      return;
   }

   state->timeout = 5000; // 5s delay before take image
   state->width = 2592;
   state->height = 1944;
   state->quality = 85;
   state->wantRAW = 0;
   state->filename = NULL;
   state->linkname = NULL;
   state->verbose = 0;
   state->thumbnailConfig.enable = 1;
   state->thumbnailConfig.width = 64;
   state->thumbnailConfig.height = 48;
   state->thumbnailConfig.quality = 35;
   state->demoMode = 0;
   state->demoInterval = 250; // ms
   state->camera_component = NULL;
   state->encoder_component = NULL;
   state->preview_connection = NULL;
   state->encoder_connection = NULL;
   state->encoder_pool = NULL;
   state->encoding = MMAL_ENCODING_JPEG;
   state->numExifTags = 0;
   state->timelapse = 0;
   state->fullResPreview = 0;

   // Setup preview window defaults
   raspipreview_set_defaults(&state->preview_parameters);

   // Set up the camera_parameters to default
   raspicamcontrol_set_defaults(&state->camera_parameters);
}
Esempio n. 8
0
// default status
static void default_status(RASPIVID_STATE *state)
{
	if (!state)
	{
		vcos_assert(0);
		return;
	}

	// Default everything to zero
	memset(state, 0, sizeof(RASPIVID_STATE));

	// Now set anything non-zero
	state->finished = 0;
	state->width = 320;		// use a multiple of 320 (640, 1280)
	state->height = 240;		// use a multiple of 240 (480, 960)
	//	state->width = 1280;		// use a multiple of 320 (640, 1280)
	//	state->height = 960;		// use a multiple of 240 (480, 960)
	state->bitrate = 2000000; // This is a decent default bitrate for 1080p
	state->framerate = VIDEO_FRAME_RATE_NUM;
	state->intraperiod = 0;	 // Not set
	state->quantisationParameter = 0;
	state->immutableInput = 1;
	state->graymode = 1;		// Gray (1) much faster than color (0)
	state->profile = MMAL_VIDEO_PROFILE_H264_HIGH;
	state->bInlineHeaders = 0;
	state->inlineMotionVectors = 0;

	state->segmentSize = 0;  // 0 = not segmenting the file.
	state->segmentNumber = 1;
	state->segmentWrap = 0; // Point at which to wrap segment number back to 1. 0 = no wrap
	state->splitNow = 0;
	state->splitWait = 0;

	state->filename = "test.h264";

	// Set up the camera_parameters to default
	raspicamcontrol_set_defaults(&state->camera_parameters);
}
/**
 * Assign a default set of parameters to the state passed in
 *
 * @param state Pointer to state structure to assign defaults to
 */
static void default_status(RASPISTILL_STATE *state)
{
   if (!state)
   {
      vcos_assert(0);
      return;
   }
   	
   state->timeout = 1000;// 1s delay before take image   
   // MODIFICATION: modified for demo purpose -> smaller image
   state->width = 324;
   state->height = 243;
   state->quality = 25;
   state->wantRAW = 0;
   // *** USER: change the name of the file.
   state->filename = "cam_image.jpg";
   state->verbose = 0;
   state->thumbnailConfig.enable = 1;
   state->thumbnailConfig.width = 64;
   state->thumbnailConfig.height = 48;
   state->thumbnailConfig.quality = 35;
   state->demoMode = 0;
   state->demoInterval = 250; // ms
   state->camera_component = NULL;
   state->encoder_component = NULL;
   state->preview_connection = NULL;
   state->encoder_connection = NULL;
   state->encoder_pool = NULL;
   state->encoding = MMAL_ENCODING_JPEG;
   state->numExifTags = 0;
   state->timelapse = 0;

   // Setup preview window defaults
   raspipreview_set_defaults(&state->preview_parameters);

   // Set up the camera_parameters to default
   raspicamcontrol_set_defaults(&state->camera_parameters);
}
// default status
static void default_status(RASPIVID_STATE *state)
{
   if (!state)
   {
      vcos_assert(0);
      return;
   }

   // Default everything to zero
   memset(state, 0, sizeof(RASPIVID_STATE));

   // Now set anything non-zero
   state->finished          = 0;
   state->width 			= 320;      // use a multiple of 320 (640, 1280)
   state->height 			= 240;		// use a multiple of 240 (480, 960)
   state->bitrate 			= 17000000; // This is a decent default bitrate for 1080p
   state->framerate 		= VIDEO_FRAME_RATE_NUM;
   state->immutableInput 	= 1;
   state->graymode 			= 0;		// Gray (1) much faster than color (0)
   
   // Set up the camera_parameters to default
   raspicamcontrol_set_defaults(&state->camera_parameters);
}
Esempio n. 11
0
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;
}
/**
 * Assign a default set of parameters to the state passed in
 *
 * @param state Pointer to state structure to assign defaults to
 */
static void get_status(RASPIVID_STATE *state) {
    int temp;
    std::string str;
    if (!state) {
        vcos_assert(0);
        return;
    }

    // Default everything to zero
    memset(state, 0, sizeof(RASPIVID_STATE));

    if (ros::param::get("~width", temp )) {
        if (temp > 0 && temp <= 1920)
            state->width = temp;
        else
            state->width = 640;
    } else {
        state->width = 640;
        ros::param::set("~width", 640);
    }

    if (ros::param::get("~height", temp )) {
        if (temp > 0 && temp <= 1080)
            state->height = temp;
        else
            state->height = 480;
    } else {
        state->height = 480;
        ros::param::set("~height", 480);
    }

    if (ros::param::get("~quality", temp )) {
        if (temp > 0 && temp <= 100)
            state->quality = temp;
        else
            state->quality = 80;
    } else {
        state->quality = 80;
        ros::param::set("~quality", 80);
    }

    if (ros::param::get("~framerate", temp )) {
        if (temp > 0 && temp <= 90)
            state->framerate = temp;
        else
            state->framerate = 30;
    } else {
        state->framerate = 30;
        ros::param::set("~framerate", 30);
    }

    if (ros::param::get("~tf_prefix",  str)) {
        tf_prefix = str;
    } else {
        tf_prefix = "";
        ros::param::set("~tf_prefix", "");
    }

    ros::param::get("~hflip", temp);
    ROS_INFO("hflip_raw: %d\n", temp);
    if (temp >= 0 && temp <= 1) {
        //state->camera_parameters.hflip = temp;
        //ROS_INFO("set hflip to: %d\n", state->camera_parameters.hflip);
        hflip = temp;
    } else {
        //state->camera_parameters.hflip = 0;
        ros::param::set("~hflip", 0);
    }

    ros::param::get("~vflip", temp);
    ROS_INFO("vflip_raw: %d\n", temp);
    if (temp >= 0 && temp <= 1) {
        //state->camera_parameters.vflip = temp;
        //ROS_INFO("set vflip to: %d\n", state->camera_parameters.vflip);
        vflip = temp;
    } else {
        //state->camera_parameters.vflip = 0;
        ros::param::set("~vflip", 0);
    }

    ros::param::get("~start", temp);
    ROS_INFO("auto_start_raw: %d\n", temp);
    if (temp >= 0 && temp <= 1) {
        auto_start = temp;
    } else {
        ros::param::set("~start", 0);
    }

    state->isInit = 0;

    // Setup preview window defaults
    //raspipreview_set_defaults(&state->preview_parameters);

    // Set up the camera_parameters to default
    raspicamcontrol_set_defaults(&state->camera_parameters);
}
/**
 * Assign a default set of parameters to the state passed in
 *
 * @param state Pointer to state structure to assign defaults to
 */
void default_status(RASPIVID_STATE *state)
{
    if (!state)
    {
        vcos_assert(0);
        return;
    }

    // Default everything to zero
    memset(state, 0, sizeof(RASPIVID_STATE));

#ifdef __WEBRTC_DEFAULT__
    state->width = RASPI_CAM_FIXED_WIDTH;	// default width for FOV
    state->height = RASPI_CAM_FIXED_HEIGHT;	// default width for FOV
    state->encoding = MMAL_ENCODING_H264;
    // state->bitrate = 17000000; 			// This is a decent default bitrate for 1080p
    state->bitrate = 0; 			// For variable bitrate setttings
    state->framerate = VIDEO_FRAME_RATE_NUM;
    state->intra_refresh_type = MMAL_VIDEO_INTRA_REFRESH_BOTH;		// cyclic intra rehash type
    state->intraperiod = VIDEO_FRAME_RATE_NUM * 3;	// every 3 second
    state->bInlineHeaders = MMAL_TRUE;	    // enabling Inline Header
    state->profile = MMAL_VIDEO_PROFILE_H264_CONSTRAINED_BASELINE;  
    // state->profile = MMAL_VIDEO_PROFILE_H264_MAIN;  
    state->verbose = MMAL_TRUE;

#define __RATECONTROL_DISABLE__

#ifdef __RATECONTROL_DISABLE__
    state->videoRateControl = MMAL_FALSE;
    state->quantisationParameter = MMAL_TRUE;
    state->quantisationInitialParameter = 26;   // Initial quantization parameter
    state->quantisationMaxParameter	= 35;       /// Maximum quantization parameter
    state->quantisationMinParameter  = 24;       /// Minimum quantization parameter
#else
    state->videoRateControl = MMAL_TRUE;
    state->quantisationParameter = MMAL_FALSE;   // disable quatization, Not working
    state->quantisationInitialParameter = 26;   // Initial quantization parameter
    state->quantisationMaxParameter	= 35;       /// Maximum quantization parameter
    state->quantisationMinParameter  = 22;       /// Minimum quantization parameter
#endif // __RATECONTROL_DISABLE__

    // state->settings = MMAL_TRUE;				// camera setting
    state->settings = MMAL_FALSE;

#else	/* RaspiVid defaults */
    state->width = 1920;       // Default to 1080p
    state->height = 1080;
    state->encoding = MMAL_ENCODING_H264;
    state->bitrate = 17000000; // This is a decent default bitrate for 1080p
    state->framerate = VIDEO_FRAME_RATE_NUM;
    state->intraperiod = -1;    // Not set
    state->intra_refresh_type = -1;
    state->bInlineHeaders = 0;
    state->quantisationParameter = MMAL_FALSE;
    state->profile = MMAL_VIDEO_PROFILE_H264_HIGH;
    state->verbose = MMAL_TRUE;
    state->videoRateControl = 0;
    state->settings = 0;
#endif

    state->immutableInput = 1;
    state->bCapturing = 0;

    state->cameraNum = 0;
    state->sensor_mode = 0;


    // Setup preview window defaults
    raspipreview_set_defaults(&state->preview_parameters);

    // Set up the camera_parameters to default
    raspicamcontrol_set_defaults(&state->camera_parameters);
}
Esempio n. 14
0
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;
}
Esempio n. 15
0
void create_camera_component(int Width, int Height, int FrameRate){
	MMAL_COMPONENT_T *camera = 0;
	MMAL_ES_FORMAT_T *format;
	
	MMAL_STATUS_T status;
	
	/* Create the component */
	status = mmal_component_create(MMAL_COMPONENT_DEFAULT_CAMERA, &camera);

	if (status != MMAL_SUCCESS)	{
		printf("Failed to create camera component : error %d\n", status);
		exit(1);
	}

	if (!camera->output_num)	{
		status = MMAL_ENOSYS;
		printf("Camera doesn't have output ports\n");
		exit(1);
	}

	preview_port = camera->output[MMAL_CAMERA_PREVIEW_PORT];
	video_port = camera->output[MMAL_CAMERA_VIDEO_PORT];
	still_port = camera->output[MMAL_CAMERA_CAPTURE_PORT];
	
	// Enable the camera, and tell it its control callback function
	status = mmal_port_enable(camera->control, camera_control_callback);
	if (status != MMAL_SUCCESS)	{
		printf("Unable to enable control port : error %d\n", status);
		mmal_component_destroy(camera);
		exit(1);
	}
	
	//set camera parameters.
	MMAL_PARAMETER_CAMERA_CONFIG_T cam_config;
	cam_config.hdr = MMAL_PARAMETER_CAMERA_CONFIG;
	cam_config.hdr.size = sizeof(cam_config);
	cam_config.max_stills_w = Width;
	cam_config.max_stills_h = Height;
	cam_config.stills_yuv422 = 0;
	cam_config.one_shot_stills = 0;
	cam_config.max_preview_video_w = Width;
	cam_config.max_preview_video_h = Height;
	cam_config.num_preview_video_frames = 3;
	cam_config.stills_capture_circular_buffer_height = 0;
	cam_config.fast_preview_resume = 0;
	cam_config.use_stc_timestamp = MMAL_PARAM_TIMESTAMP_MODE_RESET_STC;
	status = mmal_port_parameter_set(camera->control, &cam_config.hdr);

	if (status != MMAL_SUCCESS)	{
		printf("Unable to set camera parameters : error %d\n", status);
		mmal_component_destroy(camera);
		exit(1);
	}
	
	// setup preview port format - QUESTION: Needed if we aren't using preview?
	format = preview_port->format;
	format->encoding = MMAL_ENCODING_OPAQUE;
	format->encoding_variant = MMAL_ENCODING_I420;
	format->es->video.width = Width;
	format->es->video.height = Height;
	format->es->video.crop.x = 0;
	format->es->video.crop.y = 0;
	format->es->video.crop.width = Width;
	format->es->video.crop.height = Height;
	format->es->video.frame_rate.num = FrameRate;
	format->es->video.frame_rate.den = 1;
	status = mmal_port_format_commit(preview_port);
	if (status != MMAL_SUCCESS)
	{
		printf("Couldn't set preview port format : error %d\n", status);
		mmal_component_destroy(camera);
		exit(1);
	}

	//setup video port format
	format = video_port->format;
	format->encoding = MMAL_ENCODING_I420;
	format->encoding_variant = MMAL_ENCODING_I420;
	format->es->video.width = Width;
	format->es->video.height = Height;
	format->es->video.crop.x = 0;
	format->es->video.crop.y = 0;
	format->es->video.crop.width = Width;
	format->es->video.crop.height = Height;
	format->es->video.frame_rate.num = FrameRate;
	format->es->video.frame_rate.den = 1;
	status = mmal_port_format_commit(video_port);
	if (status != MMAL_SUCCESS)
	{
		printf("Couldn't set video port format : error %d\n", status);
		mmal_component_destroy(camera);
		exit(1);
	}
	
	//setup still port format
	format = still_port->format;
	format->encoding = MMAL_ENCODING_OPAQUE;
	format->encoding_variant = MMAL_ENCODING_I420;
	format->es->video.width = Width;
	format->es->video.height = Height;
	format->es->video.crop.x = 0;
	format->es->video.crop.y = 0;
	format->es->video.crop.width = Width;
	format->es->video.crop.height = Height;
	format->es->video.frame_rate.num = 1;
	format->es->video.frame_rate.den = 1;
	status = mmal_port_format_commit(still_port);
	if (status != MMAL_SUCCESS)
	{
		printf("Couldn't set still port format : error %d\n", status);
		mmal_component_destroy(camera);
		exit(1);
	}
	
	status = mmal_port_parameter_set_boolean(preview_port,
	MMAL_PARAMETER_ZERO_COPY, MMAL_TRUE);
	if (status != MMAL_SUCCESS)
	{
		printf("Failed to enable zero copy on camera video port\n");
		exit(1);
	}
	
	status = mmal_port_format_commit(preview_port);
	if (status != MMAL_SUCCESS)
	{
		printf("camera format couldn't be set\n");
		exit(1);
	}
	
	/* For GL a pool of opaque buffer handles must be allocated in the client.
	* These buffers are used to create the EGL images.
	*/
	preview_port->buffer_num = 3;
	preview_port->buffer_size = preview_port->buffer_size_recommended;

	/* Pool + queue to hold preview frames */
	video_pool = mmal_port_pool_create(preview_port,preview_port->buffer_num,preview_port->buffer_size);
	if (!video_pool)
	{
		printf("Error allocating camera video pool. Buffer num: %d Buffer size: %d\n", preview_port->buffer_num, preview_port->buffer_size);
		status = MMAL_ENOMEM;
		exit(1);
	}
	printf("Allocated %d MMAL buffers of size %d.\n", preview_port->buffer_num, preview_port->buffer_size);

	/* Place filled buffers from the preview port in a queue to render */
	video_queue = mmal_queue_create();
	if (!video_queue)
	{
		printf("Error allocating video buffer queue\n");
		status = MMAL_ENOMEM;
		exit(1);
	}

	/* Enable video port callback */
	//port->userdata = (struct MMAL_PORT_USERDATA_T *)this;
	status = mmal_port_enable(preview_port, video_output_callback);
	if (status != MMAL_SUCCESS)
	{
		printf("Failed to enable video port\n");
		exit(1);
	}
	
	// Set up the camera_parameters to default
	raspicamcontrol_set_defaults(&cameraParameters);
	//apply all camera parameters
	raspicamcontrol_set_all_parameters(camera, &cameraParameters);

	//enable the camera
	status = mmal_component_enable(camera);
	if (status != MMAL_SUCCESS)
	{
		printf("Couldn't enable camera\n\n");
		mmal_component_destroy(camera);
		exit(1);
	}
	
	//send all the buffers in our pool to the video port ready for use
	{
		int num = mmal_queue_length(video_pool->queue);
		int q;
		for (q=0;q<num;q++)
		{
			MMAL_BUFFER_HEADER_T *buffer = mmal_queue_get(video_pool->queue);
			if (!buffer)
			{
				printf("Unable to get a required buffer %d from pool queue\n\n", q);
				exit(1);
			}
			else if (mmal_port_send_buffer(preview_port, buffer)!= MMAL_SUCCESS)
			{
				printf("Unable to send a buffer to port (%d)\n\n", q);
				exit(1);
			}
		}
	}
	
	/*
	//begin capture
	if (mmal_port_parameter_set_boolean(preview_port, MMAL_PARAMETER_CAPTURE, 1) != MMAL_SUCCESS)
	{
		printf("Failed to start capture\n\n");
		exit(1);
	}
	*/
	
	printf("Camera initialized.\n");
	
	
	
	//Setup the camera's textures and EGL images.
	glGenTextures(1, &cam_ytex);
	glGenTextures(1, &cam_utex);
	glGenTextures(1, &cam_vtex);
	
	return;
}