mirror of
				https://gitlab.freedesktop.org/pipewire/pipewire.git
				synced 2025-11-03 09:01:54 -05:00 
			
		
		
		
	inspect: improve output
Keep state variable to enumerate things. This allows us to remove the expectation that the same index will give the same item. Use a new rectangle type for video size. When enumerating sizes, this allows us to specify relations between width and height more easily. Remove the struct and bytes type, they are like pointer. Add filter to enum_formats to speed up enumerations.
This commit is contained in:
		
							parent
							
								
									77bc2a1793
								
							
						
					
					
						commit
						b9320c67c2
					
				
					 27 changed files with 414 additions and 287 deletions
				
			
		| 
						 | 
				
			
			@ -29,7 +29,7 @@
 | 
			
		|||
 | 
			
		||||
typedef struct _SpaV4l2Source SpaV4l2Source;
 | 
			
		||||
 | 
			
		||||
static const char default_device[] = "/dev/video0";
 | 
			
		||||
static const char default_device[] = "/dev/video1";
 | 
			
		||||
 | 
			
		||||
typedef struct {
 | 
			
		||||
  SpaProps props;
 | 
			
		||||
| 
						 | 
				
			
			@ -312,32 +312,22 @@ spa_v4l2_source_node_remove_port (SpaHandle      *handle,
 | 
			
		|||
static SpaResult
 | 
			
		||||
spa_v4l2_source_node_port_enum_formats (SpaHandle       *handle,
 | 
			
		||||
                                        uint32_t         port_id,
 | 
			
		||||
                                        unsigned int     index,
 | 
			
		||||
                                        SpaFormat      **format)
 | 
			
		||||
                                        SpaFormat      **format,
 | 
			
		||||
                                        const SpaFormat *filter,
 | 
			
		||||
                                        void           **state)
 | 
			
		||||
{
 | 
			
		||||
  SpaV4l2Source *this = (SpaV4l2Source *) handle;
 | 
			
		||||
  SpaV4l2State *state;
 | 
			
		||||
  SpaResult res;
 | 
			
		||||
 | 
			
		||||
  if (handle == NULL || format == NULL)
 | 
			
		||||
  if (handle == NULL || format == NULL || state == NULL)
 | 
			
		||||
    return SPA_RESULT_INVALID_ARGUMENTS;
 | 
			
		||||
 | 
			
		||||
  if (port_id != 0)
 | 
			
		||||
    return SPA_RESULT_INVALID_PORT;
 | 
			
		||||
 | 
			
		||||
  state = &this->state[port_id];
 | 
			
		||||
  res = spa_v4l2_enum_format (this, format, state);
 | 
			
		||||
 | 
			
		||||
  /*
 | 
			
		||||
  switch (index) {
 | 
			
		||||
    case 0:
 | 
			
		||||
      spa_video_raw_format_init (&state->raw_format[0]);
 | 
			
		||||
      break;
 | 
			
		||||
    default:
 | 
			
		||||
      break;
 | 
			
		||||
  }
 | 
			
		||||
  *format = &state->raw_format[0].format;
 | 
			
		||||
  */
 | 
			
		||||
 | 
			
		||||
  return spa_v4l2_enum_format (this, format, &state->cookie);
 | 
			
		||||
  return res;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static SpaResult
 | 
			
		||||
| 
						 | 
				
			
			@ -616,7 +606,7 @@ v4l2_source_init (const SpaHandleFactory  *factory,
 | 
			
		|||
  this->state[0].info.flags = SPA_PORT_INFO_FLAG_NONE;
 | 
			
		||||
  this->state[0].status.flags = SPA_PORT_STATUS_FLAG_NONE;
 | 
			
		||||
 | 
			
		||||
  this->state[0].export_buf = true;
 | 
			
		||||
  this->state[0].export_buf = false;
 | 
			
		||||
 | 
			
		||||
  return SPA_RESULT_OK;
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -631,14 +621,24 @@ static const SpaInterfaceInfo v4l2_source_interfaces[] =
 | 
			
		|||
 | 
			
		||||
static SpaResult
 | 
			
		||||
v4l2_source_enum_interface_info (const SpaHandleFactory  *factory,
 | 
			
		||||
                               unsigned int             index,
 | 
			
		||||
                               const SpaInterfaceInfo **info)
 | 
			
		||||
                                 const SpaInterfaceInfo **info,
 | 
			
		||||
                                 void                   **state)
 | 
			
		||||
{
 | 
			
		||||
  if (index >= 1)
 | 
			
		||||
    return SPA_RESULT_ENUM_END;
 | 
			
		||||
  int index;
 | 
			
		||||
 | 
			
		||||
  *info = &v4l2_source_interfaces[index];
 | 
			
		||||
  if (factory == NULL || info == NULL || state == NULL)
 | 
			
		||||
    return SPA_RESULT_INVALID_ARGUMENTS;
 | 
			
		||||
 | 
			
		||||
  index = (*state == NULL ? 0 : *(int*)state);
 | 
			
		||||
 | 
			
		||||
  switch (index) {
 | 
			
		||||
    case 0:
 | 
			
		||||
      *info = &v4l2_source_interfaces[index];
 | 
			
		||||
      break;
 | 
			
		||||
    default:
 | 
			
		||||
      return SPA_RESULT_ENUM_END;
 | 
			
		||||
  }
 | 
			
		||||
  *(int*)state = ++index;
 | 
			
		||||
  return SPA_RESULT_OK;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -66,7 +66,6 @@ spa_v4l2_open (SpaV4l2Source *this)
 | 
			
		|||
  return 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#if 0
 | 
			
		||||
static SpaVideoFormat
 | 
			
		||||
fourcc_to_video_format (uint32_t fourcc)
 | 
			
		||||
{
 | 
			
		||||
| 
						 | 
				
			
			@ -169,7 +168,6 @@ fourcc_to_video_format (uint32_t fourcc)
 | 
			
		|||
  }
 | 
			
		||||
  return format;
 | 
			
		||||
}
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
static uint32_t
 | 
			
		||||
video_format_to_fourcc (SpaVideoFormat format)
 | 
			
		||||
| 
						 | 
				
			
			@ -329,37 +327,17 @@ again:
 | 
			
		|||
    }
 | 
			
		||||
    state->frmival.index++;
 | 
			
		||||
  }
 | 
			
		||||
  fprintf (stderr, "format %c%c%c%c\n", FOURCC_ARGS (state->fmtdesc.pixelformat));
 | 
			
		||||
  if (state->frmsize.type == V4L2_FRMSIZE_TYPE_DISCRETE) {
 | 
			
		||||
    fprintf (stderr, "size %dx%d\n", state->frmsize.discrete.width, state->frmsize.discrete.height);
 | 
			
		||||
  } else if (state->frmsize.type == V4L2_FRMSIZE_TYPE_STEPWISE) {
 | 
			
		||||
    fprintf (stderr, "size %dx%d - %dx%d with step %d/%d\n",
 | 
			
		||||
	state->frmsize.stepwise.min_width,
 | 
			
		||||
	state->frmsize.stepwise.min_height,
 | 
			
		||||
	state->frmsize.stepwise.max_width,
 | 
			
		||||
	state->frmsize.stepwise.max_height,
 | 
			
		||||
	state->frmsize.stepwise.step_width,
 | 
			
		||||
	state->frmsize.stepwise.step_height);
 | 
			
		||||
  }
 | 
			
		||||
  if (state->frmival.type == V4L2_FRMIVAL_TYPE_DISCRETE) {
 | 
			
		||||
    fprintf (stderr, "framerate %u/%u\n",
 | 
			
		||||
                state->frmival.discrete.numerator,
 | 
			
		||||
                state->frmival.discrete.denominator);
 | 
			
		||||
  } else if (state->frmival.type == V4L2_FRMIVAL_TYPE_CONTINUOUS) {
 | 
			
		||||
    fprintf (stderr, "framerate %u/%u - %u/%u\n",
 | 
			
		||||
                state->frmival.stepwise.min.numerator,
 | 
			
		||||
                state->frmival.stepwise.min.denominator,
 | 
			
		||||
                state->frmival.stepwise.max.numerator,
 | 
			
		||||
                state->frmival.stepwise.max.denominator);
 | 
			
		||||
  } else if (state->frmival.type == V4L2_FRMIVAL_TYPE_STEPWISE) {
 | 
			
		||||
    fprintf (stderr, "framerate %u/%u - %u/%u step %u/%u\n",
 | 
			
		||||
                state->frmival.stepwise.min.numerator,
 | 
			
		||||
                state->frmival.stepwise.min.denominator,
 | 
			
		||||
                state->frmival.stepwise.max.numerator,
 | 
			
		||||
                state->frmival.stepwise.max.denominator,
 | 
			
		||||
                state->frmival.stepwise.step.numerator,
 | 
			
		||||
                state->frmival.stepwise.step.denominator);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  spa_video_raw_format_init (&state->raw_format[0]);
 | 
			
		||||
  state->raw_format[0].info.format = fourcc_to_video_format (state->fmtdesc.pixelformat);
 | 
			
		||||
  state->raw_format[0].info.size.width = state->frmsize.discrete.width;
 | 
			
		||||
  state->raw_format[0].info.size.height = state->frmsize.discrete.height;
 | 
			
		||||
  state->raw_format[0].info.framerate.num = state->frmival.discrete.numerator;
 | 
			
		||||
  state->raw_format[0].info.framerate.denom = state->frmival.discrete.denominator;
 | 
			
		||||
  state->raw_format[0].unset_mask &= ~((1<<0)|(1<<1)|(1<<2));
 | 
			
		||||
 | 
			
		||||
  *format = &state->raw_format[0].format;
 | 
			
		||||
 | 
			
		||||
  return SPA_RESULT_OK;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -381,8 +359,8 @@ spa_v4l2_set_format (SpaV4l2Source *this, SpaFormat *format, bool try_only)
 | 
			
		|||
      SpaVideoRawFormat *f = (SpaVideoRawFormat *) format;
 | 
			
		||||
 | 
			
		||||
      fmt.fmt.pix.pixelformat = video_format_to_fourcc (f->info.format);
 | 
			
		||||
      fmt.fmt.pix.width = f->info.width;
 | 
			
		||||
      fmt.fmt.pix.height = f->info.height;
 | 
			
		||||
      fmt.fmt.pix.width = f->info.size.width;
 | 
			
		||||
      fmt.fmt.pix.height = f->info.size.height;
 | 
			
		||||
      fmt.fmt.pix.field = V4L2_FIELD_ANY;
 | 
			
		||||
      streamparm.parm.capture.timeperframe.numerator = f->info.framerate.denom;
 | 
			
		||||
      streamparm.parm.capture.timeperframe.denominator = f->info.framerate.num;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -23,12 +23,16 @@
 | 
			
		|||
extern const SpaHandleFactory spa_v4l2_source_factory;
 | 
			
		||||
 | 
			
		||||
SpaResult
 | 
			
		||||
spa_enum_handle_factory (unsigned int             index,
 | 
			
		||||
                         const SpaHandleFactory **factory)
 | 
			
		||||
spa_enum_handle_factory (const SpaHandleFactory **factory,
 | 
			
		||||
                         void                   **state)
 | 
			
		||||
{
 | 
			
		||||
  if (factory == NULL)
 | 
			
		||||
  int index;
 | 
			
		||||
 | 
			
		||||
  if (factory == NULL || state == NULL)
 | 
			
		||||
    return SPA_RESULT_INVALID_ARGUMENTS;
 | 
			
		||||
 | 
			
		||||
  index = (*state == NULL ? 0 : *(int*)state);
 | 
			
		||||
 | 
			
		||||
  switch (index) {
 | 
			
		||||
    case 0:
 | 
			
		||||
      *factory = &spa_v4l2_source_factory;
 | 
			
		||||
| 
						 | 
				
			
			@ -36,5 +40,7 @@ spa_enum_handle_factory (unsigned int             index,
 | 
			
		|||
    default:
 | 
			
		||||
      return SPA_RESULT_ENUM_END;
 | 
			
		||||
  }
 | 
			
		||||
  *(int*)state = ++index;
 | 
			
		||||
 | 
			
		||||
  return SPA_RESULT_OK;
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue