display: don't use GstCaps for decode or encode profiles list.

Replace gst_vaapi_display_get_{decode,encode}_caps() APIs with more
more convenient APIs that return an array of GstVaapiProfile instead
of GstCaps: gst_vaapi_display_get_{decode,encode}_profiles().
This commit is contained in:
Gwenole Beauchesne 2013-12-20 15:31:14 +01:00
parent c4ca08a8d6
commit c5581298fb
4 changed files with 102 additions and 82 deletions

View file

@ -347,28 +347,39 @@ append_h263_config (GArray * configs)
} }
} }
/* Sort profiles. Group per codec */
static gint
compare_profiles (gconstpointer a, gconstpointer b)
{
const GstVaapiConfig *const config1 = (GstVaapiConfig *) a;
const GstVaapiConfig *const config2 = (GstVaapiConfig *) b;
if (config1->profile == config2->profile)
return config1->entrypoint - config2->entrypoint;
return config1->profile - config2->profile;
}
/* Convert configs array to profiles as GstCaps */ /* Convert configs array to profiles as GstCaps */
static GstCaps * static GArray *
get_profile_caps (GArray * configs) get_profiles (GArray * configs)
{ {
GstVaapiConfig *config; GstVaapiConfig *config;
GstCaps *out_caps, *caps; GArray *out_profiles;
guint i; guint i;
if (!configs) if (!configs)
return NULL; return NULL;
out_caps = gst_caps_new_empty (); out_profiles = g_array_new (FALSE, FALSE, sizeof (GstVaapiProfile));
if (!out_caps) if (!out_profiles)
return NULL; return NULL;
for (i = 0; i < configs->len; i++) { for (i = 0; i < configs->len; i++) {
config = &g_array_index (configs, GstVaapiConfig, i); config = &g_array_index (configs, GstVaapiConfig, i);
caps = gst_vaapi_profile_get_caps (config->profile); g_array_append_val (out_profiles, config->profile);
if (caps)
out_caps = gst_caps_merge (out_caps, caps);
} }
return out_caps; return out_profiles;
} }
/* Find format info */ /* Find format info */
@ -554,6 +565,9 @@ ensure_profiles (GstVaapiDisplay * display)
} }
append_h263_config (priv->decoders); append_h263_config (priv->decoders);
g_array_sort (priv->decoders, compare_profiles);
g_array_sort (priv->encoders, compare_profiles);
/* Video processing API */ /* Video processing API */
#if USE_VA_VPP #if USE_VA_VPP
status = vaQueryConfigEntrypoints (priv->display, VAProfileNone, status = vaQueryConfigEntrypoints (priv->display, VAProfileNone,
@ -1364,21 +1378,24 @@ gst_vaapi_display_has_video_processing (GstVaapiDisplay * display)
} }
/** /**
* gst_vaapi_display_get_decode_caps: * gst_vaapi_display_get_decode_profiles:
* @display: a #GstVaapiDisplay * @display: a #GstVaapiDisplay
* *
* Gets the supported profiles for decoding as #GstCaps capabilities. * Gets the supported profiles for decoding. The caller owns an extra
* reference to the resulting array of #GstVaapiProfile elements, so
* it shall be released with g_array_unref() after usage.
* *
* Return value: a newly allocated #GstCaps object, possibly empty * Return value: a newly allocated #GArray, or %NULL or error or if
* decoding is not supported at all
*/ */
GstCaps * GArray *
gst_vaapi_display_get_decode_caps (GstVaapiDisplay * display) gst_vaapi_display_get_decode_profiles (GstVaapiDisplay * display)
{ {
g_return_val_if_fail (display != NULL, NULL); g_return_val_if_fail (display != NULL, NULL);
if (!ensure_profiles (display)) if (!ensure_profiles (display))
return NULL; return NULL;
return get_profile_caps (GST_VAAPI_DISPLAY_GET_PRIVATE (display)->decoders); return get_profiles (GST_VAAPI_DISPLAY_GET_PRIVATE (display)->decoders);
} }
/** /**
@ -1405,21 +1422,24 @@ gst_vaapi_display_has_decoder (GstVaapiDisplay * display,
} }
/** /**
* gst_vaapi_display_get_encode_caps: * gst_vaapi_display_get_encode_profiles:
* @display: a #GstVaapiDisplay * @display: a #GstVaapiDisplay
* *
* Gets the supported profiles for decoding as #GstCaps capabilities. * Gets the supported profiles for encoding. The caller owns an extra
* reference to the resulting array of #GstVaapiProfile elements, so
* it shall be released with g_array_unref() after usage.
* *
* Return value: a newly allocated #GstCaps object, possibly empty * Return value: a newly allocated #GArray, or %NULL or error or if
* encoding is not supported at all
*/ */
GstCaps * GArray *
gst_vaapi_display_get_encode_caps (GstVaapiDisplay * display) gst_vaapi_display_get_encode_profiles (GstVaapiDisplay * display)
{ {
g_return_val_if_fail (display != NULL, NULL); g_return_val_if_fail (display != NULL, NULL);
if (!ensure_profiles (display)) if (!ensure_profiles (display))
return NULL; return NULL;
return get_profile_caps (GST_VAAPI_DISPLAY_GET_PRIVATE (display)->encoders); return get_profiles (GST_VAAPI_DISPLAY_GET_PRIVATE (display)->encoders);
} }
/** /**

View file

@ -144,15 +144,15 @@ gst_vaapi_display_get_pixel_aspect_ratio (GstVaapiDisplay * display,
gboolean gboolean
gst_vaapi_display_has_video_processing (GstVaapiDisplay * display); gst_vaapi_display_has_video_processing (GstVaapiDisplay * display);
GstCaps * GArray *
gst_vaapi_display_get_decode_caps (GstVaapiDisplay * display); gst_vaapi_display_get_decode_profiles (GstVaapiDisplay * display);
gboolean gboolean
gst_vaapi_display_has_decoder (GstVaapiDisplay * display, gst_vaapi_display_has_decoder (GstVaapiDisplay * display,
GstVaapiProfile profile, GstVaapiEntrypoint entrypoint); GstVaapiProfile profile, GstVaapiEntrypoint entrypoint);
GstCaps * GArray *
gst_vaapi_display_get_encode_caps (GstVaapiDisplay * display); gst_vaapi_display_get_encode_profiles (GstVaapiDisplay * display);
gboolean gboolean
gst_vaapi_display_has_encoder (GstVaapiDisplay * display, gst_vaapi_display_has_encoder (GstVaapiDisplay * display,

View file

@ -815,8 +815,9 @@ gst_vaapidecode_class_init(GstVaapiDecodeClass *klass)
static gboolean static gboolean
gst_vaapidecode_ensure_allowed_caps(GstVaapiDecode *decode) gst_vaapidecode_ensure_allowed_caps(GstVaapiDecode *decode)
{ {
GstCaps *decode_caps; GstCaps *caps, *allowed_caps;
guint i, n_decode_caps; GArray *profiles;
guint i;
if (decode->allowed_caps) if (decode->allowed_caps)
return TRUE; return TRUE;
@ -824,30 +825,32 @@ gst_vaapidecode_ensure_allowed_caps(GstVaapiDecode *decode)
if (!gst_vaapidecode_ensure_display(decode)) if (!gst_vaapidecode_ensure_display(decode))
goto error_no_display; goto error_no_display;
decode_caps = gst_vaapi_display_get_decode_caps( profiles = gst_vaapi_display_get_decode_profiles(
GST_VAAPI_PLUGIN_BASE_DISPLAY(decode)); GST_VAAPI_PLUGIN_BASE_DISPLAY(decode));
if (!decode_caps) if (!profiles)
goto error_no_decode_caps; goto error_no_profiles;
n_decode_caps = gst_caps_get_size(decode_caps);
decode->allowed_caps = gst_caps_new_empty(); allowed_caps = gst_caps_new_empty();
if (!decode->allowed_caps) if (!allowed_caps)
goto error_no_memory; goto error_no_memory;
for (i = 0; i < n_decode_caps; i++) { for (i = 0; i < profiles->len; i++) {
GstStructure *structure; const GstVaapiProfile profile =
structure = gst_caps_get_structure(decode_caps, i); g_array_index(profiles, GstVaapiProfile, i);
if (!structure) const gchar *media_type_name;
continue;
structure = gst_structure_copy(structure);
if (!structure)
continue;
gst_structure_remove_field(structure, "profile");
decode->allowed_caps =
gst_caps_merge_structure(decode->allowed_caps, structure);
}
gst_caps_unref(decode_caps); media_type_name = gst_vaapi_profile_get_media_type_name(profile);
if (!media_type_name)
continue;
caps = gst_caps_from_string(media_type_name);
if (!caps)
continue;
allowed_caps = gst_caps_merge(allowed_caps, caps);
}
decode->allowed_caps = allowed_caps;
g_array_unref(profiles);
return TRUE; return TRUE;
/* ERRORS */ /* ERRORS */
@ -856,15 +859,15 @@ error_no_display:
GST_ERROR("failed to retrieve VA display"); GST_ERROR("failed to retrieve VA display");
return FALSE; return FALSE;
} }
error_no_decode_caps: error_no_profiles:
{ {
GST_ERROR("failed to retrieve VA decode caps"); GST_ERROR("failed to retrieve VA decode profiles");
return FALSE; return FALSE;
} }
error_no_memory: error_no_memory:
{ {
GST_ERROR("failed to allocate allowed-caps set"); GST_ERROR("failed to allocate allowed-caps set");
gst_caps_unref(decode_caps); g_array_unref(profiles);
return FALSE; return FALSE;
} }
} }

View file

@ -63,33 +63,31 @@ print_value(const GValue *value, const gchar *name)
} }
static void static void
print_profile_caps(GstCaps *caps, const gchar *name) print_profiles(GArray *profiles, const gchar *name)
{ {
guint i, n_caps = gst_caps_get_size(caps); GstVaapiCodec codec;
gint version; const gchar *codec_name, *profile_name;
const gchar *profile; guint i;
gboolean has_version;
g_print("%u %s caps\n", n_caps, name); g_print("%u %s caps\n", profiles->len, name);
for (i = 0; i < gst_caps_get_size(caps); i++) { for (i = 0; i < profiles->len; i++) {
GstStructure * const structure = gst_caps_get_structure(caps, i); const GstVaapiProfile profile =
if (!structure) g_array_index(profiles, GstVaapiProfile, i);
g_error("could not get caps structure %d", i);
has_version = ( codec = gst_vaapi_profile_get_codec(profile);
gst_structure_get_int(structure, "version", &version) || if (!codec)
gst_structure_get_int(structure, "mpegversion", &version) continue;
);
g_print(" %s", gst_structure_get_name(structure)); codec_name = gst_vaapi_codec_get_name(codec);
if (has_version) if (!codec_name)
g_print("%d", version); continue;
profile = gst_structure_get_string(structure, "profile"); profile_name = gst_vaapi_profile_get_name(profile);
if (!profile) if (!profile_name)
g_error("could not get structure profile"); continue;
g_print(": %s profile\n", profile);
g_print(" %s: %s profile\n", codec_name, profile_name);
} }
} }
@ -232,22 +230,21 @@ end:
static void static void
dump_info(GstVaapiDisplay *display) dump_info(GstVaapiDisplay *display)
{ {
GArray *formats; GArray *profiles, *formats;
GstCaps *caps;
caps = gst_vaapi_display_get_decode_caps(display); profiles = gst_vaapi_display_get_decode_profiles(display);
if (!caps) if (!profiles)
g_error("could not get VA decode caps"); g_error("could not get VA decode profiles");
print_profile_caps(caps, "decoders"); print_profiles(profiles, "decoders");
gst_caps_unref(caps); g_array_unref(profiles);
caps = gst_vaapi_display_get_encode_caps(display); profiles = gst_vaapi_display_get_encode_profiles(display);
if (!caps) if (!profiles)
g_error("could not get VA encode caps"); g_error("could not get VA encode profiles");
print_profile_caps(caps, "encoders"); print_profiles(profiles, "encoders");
gst_caps_unref(caps); g_array_unref(profiles);
formats = gst_vaapi_display_get_image_formats(display); formats = gst_vaapi_display_get_image_formats(display);
if (!formats) if (!formats)