oss4: don't iterate the formats table twice for each entry

When iterating the formats table, we can just pass the whole
entry to our helper function, which avoids iterating the table
again to find the entry structure from the passed format id.
This commit is contained in:
Tim-Philipp Müller 2010-04-08 10:40:02 +01:00
parent 59120a0222
commit 4d658c188c

View file

@ -45,7 +45,7 @@ GST_DEBUG_CATEGORY (oss4_debug);
#define GST_CAT_DEFAULT oss4_debug #define GST_CAT_DEFAULT oss4_debug
static const struct typedef struct
{ {
const GstBufferFormat gst_fmt; const GstBufferFormat gst_fmt;
const gint oss_fmt; const gint oss_fmt;
@ -54,7 +54,10 @@ static const struct
const gint width; const gint width;
const gint endianness; const gint endianness;
const gboolean signedness; const gboolean signedness;
} fmt_map[] = { } GstOss4AudioFormat;
/* *INDENT-OFF* */
static const GstOss4AudioFormat fmt_map[] = {
/* note: keep sorted by preference, prefered formats first */ /* note: keep sorted by preference, prefered formats first */
{ {
GST_MU_LAW, AFMT_MU_LAW, "audio/x-mulaw", 0, 0, 0, FALSE}, { GST_MU_LAW, AFMT_MU_LAW, "audio/x-mulaw", 0, 0, 0, FALSE}, {
@ -72,6 +75,7 @@ static const struct
GST_S8, AFMT_S8, "audio/x-raw-int", 8, 8, 0, TRUE}, { GST_S8, AFMT_S8, "audio/x-raw-int", 8, 8, 0, TRUE}, {
GST_U8, AFMT_U8, "audio/x-raw-int", 8, 8, 0, FALSE} GST_U8, AFMT_U8, "audio/x-raw-int", 8, 8, 0, FALSE}
}; };
/* *INDENT-ON* */
/* formats we assume the OSS4 layer can always handle and convert internally */ /* formats we assume the OSS4 layer can always handle and convert internally */
#define CONVERTIBLE_FORMATS ( \ #define CONVERTIBLE_FORMATS ( \
@ -83,27 +87,18 @@ static const struct
AFMT_U16_LE | AFMT_U16_BE | \ AFMT_U16_LE | AFMT_U16_BE | \
AFMT_S8 | AFMT_U8 ) AFMT_S8 | AFMT_U8 )
static gboolean static void
gst_oss4_append_format_to_caps (gint fmt, GstCaps * caps) gst_oss4_append_format_to_caps (const GstOss4AudioFormat * fmt, GstCaps * caps)
{ {
gint i; GstStructure *s;
for (i = 0; i < G_N_ELEMENTS (fmt_map); ++i) { s = gst_structure_empty_new (fmt->name);
if (fmt_map[i].oss_fmt == fmt) { if (fmt->width != 0 && fmt->depth != 0) {
GstStructure *s; gst_structure_set (s, "width", G_TYPE_INT, fmt->width,
"depth", G_TYPE_INT, fmt->depth, "endianness", G_TYPE_INT,
s = gst_structure_empty_new (fmt_map[i].name); fmt->endianness, "signed", G_TYPE_BOOLEAN, fmt->signedness, NULL);
if (fmt_map[i].width != 0 && fmt_map[i].depth != 0) {
gst_structure_set (s, "width", G_TYPE_INT, fmt_map[i].width,
"depth", G_TYPE_INT, fmt_map[i].depth, "endianness", G_TYPE_INT,
fmt_map[i].endianness, "signed", G_TYPE_BOOLEAN,
fmt_map[i].signedness, NULL);
}
gst_caps_append_structure (caps, s);
return TRUE;
}
} }
return FALSE; gst_caps_append_structure (caps, s);
} }
static gint static gint
@ -441,7 +436,7 @@ gst_oss4_audio_probe_caps (GstObject * obj, int fd)
/* first list all the formats natively supported */ /* first list all the formats natively supported */
for (i = 0; i < G_N_ELEMENTS (fmt_map); ++i) { for (i = 0; i < G_N_ELEMENTS (fmt_map); ++i) {
if ((formats & fmt_map[i].oss_fmt)) { if ((formats & fmt_map[i].oss_fmt)) {
gst_oss4_append_format_to_caps (fmt_map[i].oss_fmt, caps); gst_oss4_append_format_to_caps (&fmt_map[i], caps);
} else if ((fmt_map[i].oss_fmt & CONVERTIBLE_FORMATS)) { } else if ((fmt_map[i].oss_fmt & CONVERTIBLE_FORMATS)) {
nonnative_formats |= fmt_map[i].oss_fmt; nonnative_formats |= fmt_map[i].oss_fmt;
} }
@ -453,7 +448,7 @@ gst_oss4_audio_probe_caps (GstObject * obj, int fd)
/* now append non-native formats for which conversion would be needed */ /* now append non-native formats for which conversion would be needed */
for (i = 0; i < G_N_ELEMENTS (fmt_map); ++i) { for (i = 0; i < G_N_ELEMENTS (fmt_map); ++i) {
if ((nonnative_formats & fmt_map[i].oss_fmt)) { if ((nonnative_formats & fmt_map[i].oss_fmt)) {
gst_oss4_append_format_to_caps (fmt_map[i].oss_fmt, caps); gst_oss4_append_format_to_caps (&fmt_map[i], caps);
} }
} }
@ -501,7 +496,7 @@ gst_oss4_audio_get_template_caps (void)
caps = gst_caps_new_empty (); caps = gst_caps_new_empty ();
for (i = 0; i < G_N_ELEMENTS (fmt_map); ++i) { for (i = 0; i < G_N_ELEMENTS (fmt_map); ++i) {
gst_oss4_append_format_to_caps (fmt_map[i].oss_fmt, caps); gst_oss4_append_format_to_caps (&fmt_map[i], caps);
} }
gst_caps_do_simplify (caps); gst_caps_do_simplify (caps);