コード例 #1
0
ファイル: RaspiTex.c プロジェクト: JimmyC543/userland
/**
 * Draws the next preview frame. If a new preview buffer is available then the
 * preview texture is updated first.
 *
 * @param state RASPITEX STATE
 * @param video_frame MMAL buffer header containing the opaque buffer handle.
 * @return Zero if successful.
 */
static int raspitex_draw(RASPITEX_STATE *state, MMAL_BUFFER_HEADER_T *buf)
{
    int rc = 0;

    /* If buf is non-NULL then there is a new viewfinder frame available
     * from the camera so the texture should be updated.
     *
     * Although it's possible to have multiple textures mapped to different
     * viewfinder frames this can consume a lot of GPU memory for high-resolution
     * viewfinders.
     */
    if (buf)
    {
        /* Update the texture to the new viewfinder image which should */
        if (state->ops.update_texture)
        {
            rc = state->ops.update_texture(state, (EGLClientBuffer) buf->data);
            if (rc != 0)
            {
                vcos_log_error("%s: Failed to update RGBX texture %d",
                               VCOS_FUNCTION, rc);
                goto end;
            }
        }

        if (state->ops.update_y_texture)
        {
            rc = state->ops.update_y_texture(state, (EGLClientBuffer) buf->data);
            if (rc != 0)
            {
                vcos_log_error("%s: Failed to update Y' plane texture %d", VCOS_FUNCTION, rc);
                goto end;
            }
        }

        if (state->ops.update_u_texture)
        {
            rc = state->ops.update_u_texture(state, (EGLClientBuffer) buf->data);
            if (rc != 0)
            {
                vcos_log_error("%s: Failed to update U plane texture %d", VCOS_FUNCTION, rc);
                goto end;
            }
        }

        if (state->ops.update_v_texture)
        {
            rc = state->ops.update_v_texture(state, (EGLClientBuffer) buf->data);
            if (rc != 0)
            {
                vcos_log_error("%s: Failed to update V texture %d", VCOS_FUNCTION, rc);
                goto end;
            }
        }

        /* Now return the PREVIOUS MMAL buffer header back to the camera preview. */
        if (state->preview_buf)
            mmal_buffer_header_release(state->preview_buf);

        state->preview_buf = buf;
    }

    /*  Do the drawing */
    if (check_egl_image(state) == 0)
    {
        rc = state->ops.update_model(state);
        if (rc != 0)
            goto end;

        rc = state->ops.redraw(state);
        if (rc != 0)
            goto end;

        raspitex_do_capture(state);

        eglSwapBuffers(state->display, state->surface);
        update_fps();
    }
    else
    {
        // vcos_log_trace("%s: No preview image", VCOS_FUNCTION);
    }

end:
    return rc;
}
コード例 #2
0
/**
 * Draws the next preview frame. If a new preview buffer is available then the
 * preview texture is updated first.
 *
 * @param state RASPITEX STATE
 * @param video_frame MMAL buffer header containing the opaque buffer handle.
 * @return Zero if successful.
 */
static int raspitex_draw(RASPITEX_STATE *state, MMAL_BUFFER_HEADER_T *buf)
{
   int rc = 0;

   /* If buf is non-NULL then there is a new viewfinder frame available
    * from the camera so the texture should be updated.
    *
    * Although it's possible to have multiple textures mapped to different
    * viewfinder frames this can consume a lot of GPU memory for high-resolution
    * viewfinders.
    */

	if (buf)
		{
		/* Update the texture to the new viewfinder image which should */
		
   
		if (state->ops.update_texture)
		{
		//unsigned dwTick = GetTickCount( );
		
		if (state->m_nSaveImageRequest == 1)		// tweak for save images, but don't too often -> can have high load on CPU
			{
			//fprintf(stderr, "update_texture\n" );
			rc = state->ops.update_texture(state, (EGLClientBuffer) buf->data);
			if (rc != 0)
				{
				vcos_log_error("%s: Failed to update RGBX texture %d",
				VCOS_FUNCTION, rc);
				goto end;
				}
			
			if (state->m_nSaveImageRequest == 1)
				{
				state->m_nSaveImageRequest = 2;		// say that I Have one image
				}
			else
				{
				state->m_nSaveImageRequest = 4;		// say that I Have image for H264
				}
			}
		}

      if (state->ops.update_y_texture)
      {
	  //fprintf(stderr, "update_y_texture\n" );
         rc = state->ops.update_y_texture(state, (EGLClientBuffer) buf->data);
         if (rc != 0)
         {
            vcos_log_error("%s: Failed to update Y' plane texture %d", VCOS_FUNCTION, rc);
            goto end;
         }
      }

      if (state->ops.update_u_texture)
      {
	  //fprintf(stderr, "update_u_texture\n" );
	  
         rc = state->ops.update_u_texture(state, (EGLClientBuffer) buf->data);
         if (rc != 0)
         {
            vcos_log_error("%s: Failed to update U plane texture %d", VCOS_FUNCTION, rc);
            goto end;
         }
      }

      if (state->ops.update_v_texture)
      {
	  //fprintf(stderr, "update_v_texture\n" );
	  
         rc = state->ops.update_v_texture(state, (EGLClientBuffer) buf->data);
         if (rc != 0)
         {
            vcos_log_error("%s: Failed to update V texture %d", VCOS_FUNCTION, rc);
            goto end;
         }
      }



      /* Now return the PREVIOUS MMAL buffer header back to the camera preview. */
      /*if (state->preview_buf)
         mmal_buffer_header_release(state->preview_buf);

      state->preview_buf = buf;*/
   }

	//vcos_sleep( 10 );

   /*  Do the drawing */
   if (check_egl_image(state) == 0)
   {
      rc = state->ops.update_model(state);
      if (rc != 0)
         goto end;

      rc = state->ops.redraw(state);
      if (rc != 0)
         goto end;

      //raspitex_do_capture(state);

      //eglSwapBuffers(state->display, state->surface);
      //update_fps();
   }
   else
   {
      // vcos_log_trace("%s: No preview image", VCOS_FUNCTION);
   }

end:
   return rc;
}