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:
Wim Taymans 2016-07-15 18:22:29 +02:00
parent 77bc2a1793
commit b9320c67c2
27 changed files with 414 additions and 287 deletions

View file

@ -246,28 +246,33 @@ spa_ffmpeg_dec_node_remove_port (SpaHandle *handle,
static SpaResult
spa_ffmpeg_dec_node_port_enum_formats (SpaHandle *handle,
uint32_t port_id,
unsigned int index,
SpaFormat **format)
SpaFormat **format,
const SpaFormat *filter,
void **state)
{
SpaFFMpegDec *this = (SpaFFMpegDec *) handle;
SpaFFMpegState *state;
SpaFFMpegState *s;
int index;
if (handle == NULL || format == NULL)
if (handle == NULL || format == NULL || state == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
if (!IS_VALID_PORT (port_id))
return SPA_RESULT_INVALID_PORT;
state = &this->state[port_id];
s = &this->state[port_id];
index = (*state == NULL ? 0 : *(int*)state);
switch (index) {
case 0:
spa_video_raw_format_init (&state->raw_format[0]);
spa_video_raw_format_init (&s->raw_format[0]);
break;
default:
return SPA_RESULT_ENUM_END;
}
*format = &state->raw_format[0].format;
*format = &s->raw_format[0].format;
*(int*)state = ++index;
return SPA_RESULT_OK;
}

View file

@ -246,11 +246,13 @@ spa_ffmpeg_enc_node_remove_port (SpaHandle *handle,
static SpaResult
spa_ffmpeg_enc_node_port_enum_formats (SpaHandle *handle,
uint32_t port_id,
unsigned int index,
SpaFormat **format)
SpaFormat **format,
const SpaFormat *filter,
void **state)
{
SpaFFMpegEnc *this = (SpaFFMpegEnc *) handle;
SpaFFMpegState *state;
SpaFFMpegState *s;
int index;
if (handle == NULL || format == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
@ -258,16 +260,19 @@ spa_ffmpeg_enc_node_port_enum_formats (SpaHandle *handle,
if (!IS_VALID_PORT (port_id))
return SPA_RESULT_INVALID_PORT;
state = &this->state[port_id];
s = &this->state[port_id];
index = (*state == NULL ? 0 : *(int*)state);
switch (index) {
case 0:
spa_video_raw_format_init (&state->raw_format[0]);
spa_video_raw_format_init (&s->raw_format[0]);
break;
default:
return SPA_RESULT_ENUM_END;
}
*format = &state->raw_format[0].format;
*format = &s->raw_format[0].format;
*(int*)state = ++index;
return SPA_RESULT_OK;
}

View file

@ -58,25 +58,36 @@ static const SpaInterfaceInfo ffmpeg_interfaces[] =
static SpaResult
ffmpeg_enum_interface_info (const SpaHandleFactory *factory,
unsigned int index,
const SpaInterfaceInfo **info)
const SpaInterfaceInfo **info,
void **state)
{
int index;
if (factory == NULL || state == NULL || info == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
index = (*state == NULL ? 0 : *(int*)state);
if (index >= 1)
return SPA_RESULT_ENUM_END;
*info = &ffmpeg_interfaces[index];
*(int*)state = ++index;
return SPA_RESULT_OK;
}
SpaResult
spa_enum_handle_factory (unsigned int index,
const SpaHandleFactory **factory)
spa_enum_handle_factory (const SpaHandleFactory **factory,
void **state)
{
static const AVCodec *c = NULL;
static int ci = 0;
static SpaHandleFactory f;
static char name[128];
int index;
index = (*state == NULL ? 0 : *(int*)state);
av_register_all();
@ -91,6 +102,8 @@ spa_enum_handle_factory (unsigned int index,
if (c == NULL)
return SPA_RESULT_ENUM_END;
*(int*)state = ++index;
if (av_codec_is_encoder (c)) {
snprintf (name, 128, "ffenc_%s", c->name);
f.init = ffmpeg_enc_init;