Exemplo n.º 1
0
static void show_usage( void )
{
   vcos_log_info( "Usage: smem [OPTION]..." );
   vcos_log_info( "  -a, --alloc=SIZE             Allocates a block of SIZE" );
   vcos_log_info( "  -p, --pid=PID                Use PID for desired action" );
   vcos_log_info( "  -s, --status=TYPE            Queries status of TYPE [for PID]" );
   vcos_log_info( "                all                    all (for current pid)" );
   vcos_log_info( "                vc                     videocore allocations" );
   vcos_log_info( "                map                    host map status" );
   vcos_log_info( "                map <pid>              host map status for pid" );
   vcos_log_info( "                host <pid>             host allocations for pid" );
   vcos_log_info( "  -h, --help                   Print this information" );
}
Exemplo n.º 2
0
static void update_fps()
{
    static int frame_count = 0;
    static long long time_start = 0;
    long long time_now;
    struct timeval te;
    float fps;

    frame_count++;

    gettimeofday(&te, NULL);
    time_now = te.tv_sec * 1000LL + te.tv_usec / 1000;

    if (time_start == 0)
    {
        time_start = time_now;
    }
    else if (time_now - time_start > 5000)
    {
        fps = (float) frame_count / ((time_now - time_start) / 1000.0);
        frame_count = 0;
        time_start = time_now;
        vcos_log_info("%3.2f FPS", fps);
    }
}
Exemplo n.º 3
0
static void control_c( int signum )
{
    (void)signum;

    vcos_log_info( "Shutting down..." );

    vcos_event_signal( &quit_event );
}
Exemplo n.º 4
0
static int start_monitor( void )
{
   if ( vcos_event_create( &quit_event, "smem" ) != VCOS_SUCCESS )
   {
      vcos_log_info( "Failed to create quit event" );

      return -1;
   }

   // Handle the INT and TERM signals so we can quit
   signal( SIGINT, control_c );
   signal( SIGTERM, control_c );

   return 0;
}
Exemplo n.º 5
0
/** Play video - from URI or camera - on EGL surface. */
static int vidtex_play(VIDTEX_T *vt, const VIDTEX_PARAMS_T *params)
{
   const char *uri;
   SVP_CALLBACKS_T callbacks;
   SVP_T *svp;
   SVP_OPTS_T opts;
   SVP_STATS_T stats;
   int rv = -1;

   uri = (params->uri[0] == '\0') ? NULL : params->uri;
   vt->opts = params->opts;
   callbacks.ctx = vt;
   callbacks.video_frame_cb = vidtex_video_frame_cb;
   callbacks.stop_cb = vidtex_stop_cb;
   opts.duration_ms = params->duration_ms;

   svp = svp_create(uri, &callbacks, &opts);
   if (svp)
   {
      /* Reset stats */
      vt->num_swaps = 0;

      /* Run video player until receive quit notification */
      if (svp_start(svp) == 0)
      {
         while (!vidtex_set_quit(vt, false))
         {
            vcos_semaphore_wait(&vt->sem_decoded);

            if (vt->video_frame)
            {
               vidtex_draw(vt, vt->video_frame);
               vcos_semaphore_post(&vt->sem_drawn);
            }
         }

         vcos_semaphore_post(&vt->sem_drawn);

         /* Dump stats */
         svp_get_stats(svp, &stats);
         vcos_log_info("video frames decoded: %6u", stats.video_frame_count);
         vcos_log_info("EGL buffer swaps:     %6u", vt->num_swaps);

         /* Determine status of operation and log errors */
         if (vt->stop_reason & SVP_STOP_ERROR)
         {
            vcos_log_error("vidtex exiting on error");
         }
         else if (vt->num_swaps == 0)
         {
            vcos_log_error("vidtex completed with no EGL buffer swaps");
         }
         else if (abs((int)vt->num_swaps - (int)stats.video_frame_count) > VT_MAX_FRAME_DISPARITY)
         {
            vcos_log_error("vidtex completed with %u EGL buffer swaps, but %u video frames",
                           vt->num_swaps, (int)stats.video_frame_count);
         }
         else
         {
            rv = 0;
         }
      }

      svp_destroy(svp);
   }

   vidtex_flush_gl(vt);

   return rv;
}
Exemplo n.º 6
0
void vcos_log_register(const char *name, VCOS_LOG_CAT_T *category)
{
   const char *env;
   VCOS_LOG_CAT_T *i;

   category->name  = name;
   if ( category->level == VCOS_LOG_UNINITIALIZED )
   {
      category->level = VCOS_LOG_ERROR;
   }
   category->flags.want_prefix = (category != &dflt_log_category );

   vcos_mutex_lock(&lock);

   /* is it already registered? */
   for (i = vcos_logging_categories; i ; i = i->next )
   {
      if (i == category)
      {
         i->refcount++;
         break;
      }
   }

   if (!i)
   {
      /* not yet registered */
      category->next = vcos_logging_categories;
      vcos_logging_categories = category;
      category->refcount++;

      vcos_log_platform_register(category);
   }

   vcos_mutex_unlock(&lock);

   /* Check to see if this log level has been enabled. Look for
    * (<category:level>,)*
    *
    * VC_LOGLEVEL=ilcs:info,vchiq:warn
    */

   env = _VCOS_LOG_LEVEL();
   if (env)
   {
      do
      {
         char env_name[64];
         VCOS_LOG_LEVEL_T level;
         if (read_tok(env_name, sizeof(env_name), &env, ':') &&
             read_level(&level, &env, ','))
         {
            if (strcmp(env_name, name) == 0)
            {
               category->level = level;
               break;
            }
         }
         else
         {
            if (!warned_loglevel)
            {
                vcos_log("VC_LOGLEVEL format invalid at %s\n", env);
                warned_loglevel = 1;
            }
            return;
         }
      } while (env[0] != '\0');
   }

   vcos_log_info( "Registered log category '%s' with level %s",
                  category->name,
                  vcos_log_level_to_string( category->level ));
}
Exemplo n.º 7
0
/** Preview worker thread.
 * Ensures camera preview is supplied with buffers and sends preview frames to GL.
 * @param arg  Pointer to state.
 * @return NULL always.
 */
static void *preview_worker(void *arg)
{
	RASPITEX_STATE* state = arg;
	MMAL_PORT_T *preview_port = state->preview_port;
	MMAL_BUFFER_HEADER_T *buf;
	MMAL_STATUS_T st;
	int rc;

	vcos_log_trace("%s: port %p", VCOS_FUNCTION, preview_port);

	rc = state->ops.create_native_window(state);

	if (rc != 0)
		goto end;
	else
		vcos_log_info("%s: create_native_window=%d", VCOS_FUNCTION, rc);

	rc = state->ops.gl_init(state);
	
	if (rc != 0)
		goto end;
	else
		vcos_log_info("%s: gl_init=%d", VCOS_FUNCTION, rc);
	
	// -------------------------------------------------------------------------------------
	
	/* Send empty buffers to camera preview port */
	while ((buf = mmal_queue_get(state->preview_pool->queue)) != NULL)
		{
		st = mmal_port_send_buffer(preview_port, buf);
		if (st != MMAL_SUCCESS)
			{
			vcos_log_error("Failed to send buffer to %s", preview_port->name);
			}
		}
	
	// -------------------------------------------------------------------------------------
	
	//S_COPY_FRAME_DATA	rec_frame_data;

	while (state->preview_stop == 0)
		{
		/* Send empty buffers to camera preview port */
		/*while ((buf = mmal_queue_get(state->preview_pool->queue)) != NULL)
			{
			st = mmal_port_send_buffer(preview_port, buf);
			if (st != MMAL_SUCCESS)
				{
				vcos_log_info("Failed to send buffer to %s", preview_port->name);
				}
			}*/
		
		
		
		//int nLen = mmal_queue_length( state->preview_queue );
		//vcos_log_info("SHIT!!! - LEN=%d", nLen );
		
		//while ((buf = mmal_queue_get(state->preview_pool->queue)) != NULL)
		
		
		//if (buf)
		
		int nExistBufferInQueue = 0;
		
		while ((buf = mmal_queue_get(state->preview_queue)) != NULL)
			{
			nExistBufferInQueue = 1;
			
			//vcos_log_info("DATA READ!!!" );
			
			
			rc = raspitex_draw(state, buf);		// block complete chain!!!
			if (rc != 0)
				{
				vcos_log_info("%s: Error drawing frame. Stopping.", VCOS_FUNCTION);
				state->preview_stop = 1;
				}
			
			
			
			st = mmal_port_send_buffer(preview_port, buf);
			if (st != MMAL_SUCCESS)
				{
				vcos_log_info("Failed to send buffer to %s", preview_port->name);
				}
			
			// -------------------------------------------------------------------------------------
			
			//vcos_sleep( 100 );
			
			// now is main chain already free - now can block this thread
			//
			rc = state->ops.safe_redraw(state);
			if (rc != 0)
				{
				vcos_log_info("%s: Error drawing frame. Stopping.", VCOS_FUNCTION);
				state->preview_stop = 1;
				}
			else
				{
				update_fps( );
				}
			
			// -------------------------------------------------------------------------------------
			
			break;
			}
		
		if (!nExistBufferInQueue)	// slow down while cycle otherwise 100% CPU
			{
			vcos_sleep( 10 );
			}
		
		/*if (preview_process_returned_bufs(state) != 0)
			{
			vcos_log_info("SHIT!!!" );
			}
		else
			{
			vcos_log_info("DATA READ!!!" );
			}*/
		
		/*if (begin_read_frame( state->preview_pool->queue, &rec_frame_data ))
			{
			vcos_log_info("DATA READ!!!" );
			
			//if (state->m_nGetData)
				{
				rc = raspitex_draw(state, buf);		// block complete chain!!!
				if (rc != 0)
					{
					vcos_log_info("%s: Error drawing frame. Stopping.", VCOS_FUNCTION);
					state->preview_stop = 1;
					}
				
				
				}
			
			end_read_frame( preview_port, state->preview_pool, &rec_frame_data );
			}
		else
			{
			vcos_log_info("SHIT!!!" );
			}*/
		
		//vcos_sleep( 500 );
		
		/* Process returned buffers */
		/*if (preview_process_returned_bufs(state) != 0)
			{
			vcos_log_error("Preview error. Exiting.");
			state->preview_stop = 1;
			}
		else
			{
			
			}*/
			
		
		}
	
	// -------------------------------------------------------------------------------------

end:
	/* Make sure all buffers are returned on exit */
	while ((buf = mmal_queue_get(state->preview_queue)) != NULL)
		mmal_buffer_header_release(buf);

	/* Tear down GL */
	state->ops.gl_term(state);
	vcos_log_trace("Exiting preview worker");
	
	return NULL;
}
Exemplo n.º 8
0
int main( int argc, char **argv )
{
   int32_t ret;
   char optstring[OPTSTRING_LEN];
   int  opt;
   int  opt_alloc = 0;
   int  opt_status = 0;
   uint32_t alloc_size = 0;
   int  opt_pid = -1;
   VCSM_STATUS_T status_mode = VCSM_STATUS_NONE;

   void *usr_ptr_1;
   unsigned int usr_hdl_1;
#if defined(DOUBLE_ALLOC) || defined(RESIZE_ALLOC)
   void *usr_ptr_2;
   unsigned int usr_hdl_2;
#endif

   // Initialize VCOS
   vcos_init();

   vcos_log_set_level(&smem_log_category, VCOS_LOG_INFO);
   smem_log_category.flags.want_prefix = 0;
   vcos_log_register( "smem", &smem_log_category );

   // Create the option string that we will be using to parse the arguments
   create_optstring( optstring );

   // Parse the command line arguments
   while (( opt = getopt_long_only( argc, argv, optstring, long_opts,
                                    NULL )) != -1 )
   {
      switch ( opt )
      {
         case 0:
         {
            // getopt_long returns 0 for entries where flag is non-NULL
            break;
         }
         case OPT_ALLOC:
         {
            char *end;
            alloc_size = (uint32_t)strtoul( optarg, &end, 10 );
            if (end == optarg)
            {
               vcos_log_info( "Invalid arguments '%s'", optarg );
               goto err_out;
            }

            opt_alloc = 1;
            break;
         }
         case OPT_PID:
         {
            char *end;
            opt_pid = (int)strtol( optarg, &end, 10 );
            if (end == optarg)
            {
               vcos_log_info( "Invalid arguments '%s'", optarg );
               goto err_out;
            }

            break;
         }
         case OPT_STATUS:
         {
            char status_str[32];

            /* coverity[secure_coding] String length specified, so can't overflow */
            if ( sscanf( optarg, "%31s", status_str ) != 1 )
            {
               vcos_log_info( "Invalid arguments '%s'", optarg );
               goto err_out;
            }

            if ( vcos_strcasecmp( status_str, "all" ) == 0 )
            {
               status_mode = VCSM_STATUS_VC_MAP_ALL;
            }
            else if ( vcos_strcasecmp( status_str, "vc" ) == 0 )
            {
               status_mode = VCSM_STATUS_VC_WALK_ALLOC;
            }
            else if ( vcos_strcasecmp( status_str, "map" ) == 0 )
            {
               status_mode = VCSM_STATUS_HOST_WALK_MAP;
            }
            else if ( vcos_strcasecmp( status_str, "host" ) == 0 )
            {
               status_mode = VCSM_STATUS_HOST_WALK_PID_ALLOC;
            }
            else
            {
               goto err_out;
            }

            opt_status = 1;
            break;
         }
         default:
         {
            vcos_log_info( "Unrecognized option '%d'", opt );
            goto err_usage;
         }
         case '?':
         case OPT_HELP:
         {
            goto err_usage;
         }
      } // end switch
   } // end while

   argc -= optind;
   argv += optind;

   if (( optind == 1 ) || ( argc > 0 ))
   {
      if ( argc > 0 )
      {
         vcos_log_info( "Unrecognized argument -- '%s'", *argv );
      }

      goto err_usage;
   }

   // Start the shared memory support.
   if ( vcsm_init() == -1 )
   {
      vcos_log_info( "Cannot initialize smem device" );
      goto err_out;
   }

   if ( opt_alloc == 1 )
   {
      vcos_log_info( "Allocating 2 times %u-bytes in shared memory", alloc_size );

      usr_hdl_1 = vcsm_malloc( alloc_size,
                               "smem-test-alloc" );

      vcos_log_info( "Allocation 1 result: user %x, vc-hdl %x",
                     usr_hdl_1, vcsm_vc_hdl_from_hdl( usr_hdl_1 ) );

#if defined(DOUBLE_ALLOC) || defined(RESIZE_ALLOC)
      usr_hdl_2 = vcsm_malloc( alloc_size,
                               NULL );
      vcos_log_info( "Allocation 2 result: user %x",
                     usr_hdl_2 );

      usr_ptr_2 = vcsm_lock( usr_hdl_2 );
      vcos_log_info( "Allocation 2 : lock %p",
                     usr_ptr_2 );
      vcos_log_info( "Allocation 2 : unlock %d",
                     vcsm_unlock_hdl( usr_hdl_2 ) );
#endif

      // Do a simple write/read test.
      if ( usr_hdl_1 != 0 )
      {
         usr_ptr_1 = vcsm_lock( usr_hdl_1 );
         vcos_log_info( "Allocation 1 : lock %p",
                        usr_ptr_1 );
         if ( usr_ptr_1 )
         {
            memset ( usr_ptr_1,
                     0,
                     alloc_size );
            memcpy ( usr_ptr_1,
                     blah_blah,
                     32 );
            vcos_log_info( "Allocation 1 contains: \"%s\"",
                           (char *)usr_ptr_1 );

            vcos_log_info( "Allocation 1: vc-hdl %x",
                           vcsm_vc_hdl_from_ptr ( usr_ptr_1 ) );
            vcos_log_info( "Allocation 1: usr-hdl %x",
                           vcsm_usr_handle ( usr_ptr_1 ) );
            vcos_log_info( "Allocation 1 : unlock %d",
                           vcsm_unlock_ptr( usr_ptr_1 ) );
         }

         usr_ptr_1 = vcsm_lock( usr_hdl_1 );
         vcos_log_info( "Allocation 1 (relock) : lock %p",
                        usr_ptr_1 );
         if ( usr_ptr_1 )
         {
            vcos_log_info( "Allocation 1 (relock) : unlock %d",
                           vcsm_unlock_hdl( usr_hdl_1 ) );
         }
      }

#if defined(RESIZE_ALLOC)
      ret = vcsm_resize( usr_hdl_1, 2 * alloc_size );
      vcos_log_info( "Allocation 1 : resize %d", ret );
      if ( ret == 0 )
      {
         usr_ptr_1 = vcsm_lock( usr_hdl_1 );
         vcos_log_info( "Allocation 1 (resize) : lock %p",
                        usr_ptr_1 );
         if ( usr_ptr_1 )
         {
            memset ( usr_ptr_1,
                     0,
                     2 * alloc_size );
            memcpy ( usr_ptr_1,
                     blah_blah,
                     32 );
            vcos_log_info( "Allocation 1 (resized) contains: \"%s\"",
                           (char *)usr_ptr_1 );
            vcos_log_info( "Allocation 1 (resized) : unlock %d",
                           vcsm_unlock_ptr( usr_ptr_1 ) );
         }
      }

      // This checks that the memory can be remapped properly
      // because the Block 1 expanded beyond Block 2 boundary.
      //
      usr_ptr_2 = vcsm_lock( usr_hdl_2 );
      vcos_log_info( "Allocation 2 : lock %p",
                     usr_ptr_2 );
      vcos_log_info( "Allocation 2 : unlock %d",
                     vcsm_unlock_hdl( usr_hdl_2 ) );

      // This checks that we can free a memory block even if it
      // is locked, which could be the case if the application 
      // dies.
      //
      usr_ptr_2 = vcsm_lock( usr_hdl_2 );
      vcos_log_info( "Allocation 2 : lock %p",
                     usr_ptr_2 );
      vcsm_free ( usr_hdl_2 );
#endif

#if defined(DOUBLE_ALLOC)
#endif
   }

   if ( opt_status == 1 )
   {
      get_status( status_mode, opt_pid );
   }
   
   // If we allocated something, wait for the signal to exit to give chance for the
   // user to poke around the allocation test.
   //
   if ( opt_alloc == 1 )
   {
      start_monitor();
      
      vcos_event_wait( &quit_event );
      vcos_event_delete( &quit_event );
   }

   // Terminate the shared memory support.
   vcsm_exit ();
   goto err_out;

err_usage:
   show_usage();

err_out:
   exit( 1 );
}
Exemplo n.º 9
0
int
vchiq_platform_init(VCHIQ_STATE_T *state)
{
	VCHIQ_SLOT_ZERO_T *vchiq_slot_zero;
	int frag_mem_size;
	int err;
	int i;

	/* Allocate space for the channels in coherent memory */
	g_slot_mem_size = PAGE_ALIGN(TOTAL_SLOTS * VCHIQ_SLOT_SIZE);
	frag_mem_size = PAGE_ALIGN(sizeof(FRAGMENTS_T) * MAX_FRAGMENTS);

	err = bus_dma_tag_create(
	    NULL,
	    PAGE_SIZE, 0,	       /* alignment, boundary */
	    BUS_SPACE_MAXADDR_32BIT,    /* lowaddr */
	    BUS_SPACE_MAXADDR,	  /* highaddr */
	    NULL, NULL,		 /* filter, filterarg */
	    g_slot_mem_size + frag_mem_size, 1,		/* maxsize, nsegments */
	    g_slot_mem_size + frag_mem_size, 0,		/* maxsegsize, flags */
	    NULL, NULL,		 /* lockfunc, lockarg */
	    &dma_tag);

	err = bus_dmamem_alloc(dma_tag, (void **)&g_slot_mem,
	    0, &dma_map);
	if (err) {
		vcos_log_error("Unable to allocate channel memory");
		err = ENOMEM;
		goto failed_alloc;
	}

	err = bus_dmamap_load(dma_tag, dma_map, g_slot_mem,
	    g_slot_mem_size + frag_mem_size, vchiq_dmamap_cb,
	    &g_slot_phys, 0);

	if (err) {
		vcos_log_error("cannot load DMA map\n");
		goto failed_load;
	}

	pmap_change_attr((vm_offset_t)g_slot_mem, g_slot_mem_size + frag_mem_size,
		BUS_DMA_NOCACHE);

	vcos_assert(((int)g_slot_mem & (PAGE_SIZE - 1)) == 0);

	vchiq_slot_zero = vchiq_init_slots(g_slot_mem, g_slot_mem_size);
	if (!vchiq_slot_zero)
	{
	   err = EINVAL;
	   goto failed_init_slots;
	}

	vchiq_slot_zero->platform_data[VCHIQ_PLATFORM_FRAGMENTS_OFFSET_IDX] = (int)g_slot_phys + g_slot_mem_size;
	vchiq_slot_zero->platform_data[VCHIQ_PLATFORM_FRAGMENTS_COUNT_IDX] = MAX_FRAGMENTS;

	g_fragments_base = (FRAGMENTS_T *)(g_slot_mem + g_slot_mem_size);
	g_slot_mem_size += frag_mem_size;

	g_free_fragments = g_fragments_base;
	for (i = 0; i < (MAX_FRAGMENTS - 1); i++) {
		*(FRAGMENTS_T **) & g_fragments_base[i] =
			&g_fragments_base[i + 1];
	}
	*(FRAGMENTS_T **) & g_fragments_base[i] = NULL;
	sema_init(&g_free_fragments_sema, MAX_FRAGMENTS, "Fragments semaphore");

	if (vchiq_init_state(state, vchiq_slot_zero, 0/*slave*/) !=
		VCHIQ_SUCCESS)
	{
		err = EINVAL;
		goto failed_vchiq_init;
	}

	bcm_mbox_write(BCM2835_MBOX_CHAN_VCHIQ, (unsigned int)g_slot_phys);

	vcos_log_info("vchiq_init - done (slots %x, phys %x)",
		(unsigned int)vchiq_slot_zero, g_slot_phys);

	return 0;

failed_request_irq:
failed_vchiq_init:
failed_init_slots:
failed_load:
	bus_dmamap_unload(dma_tag, dma_map);
failed_alloc:
	bus_dmamap_destroy(dma_tag, dma_map);
	bus_dma_tag_destroy(dma_tag);

	return err;
}