diff options
Diffstat (limited to 'gst-libs/gst/mpegts/gstmpegtsdescriptor.c')
-rw-r--r-- | gst-libs/gst/mpegts/gstmpegtsdescriptor.c | 150 |
1 files changed, 100 insertions, 50 deletions
diff --git a/gst-libs/gst/mpegts/gstmpegtsdescriptor.c b/gst-libs/gst/mpegts/gstmpegtsdescriptor.c index 9a89627a..6490b73a 100644 --- a/gst-libs/gst/mpegts/gstmpegtsdescriptor.c +++ b/gst-libs/gst/mpegts/gstmpegtsdescriptor.c @@ -282,7 +282,7 @@ _encode_control_codes (gchar * text, gsize length, gboolean is_multibyte) * @out_size: (out): the byte length of the new text * * Converts UTF-8 strings to text characters compliant with EN 300 468. - * The converted text can be used directly in DVB #GstMpegTsDescriptor + * The converted text can be used directly in DVB #GstMpegtsDescriptor * * The function will try different character maps until the string is * completely converted. @@ -622,12 +622,23 @@ failed: } } +gchar * +convert_lang_code (guint8 * data) +{ + gchar *code; + /* the iso language code and country code is always 3 byte long */ + code = g_malloc0 (4); + memcpy (code, data, 3); + + return code; +} + void _packetize_descriptor_array (GPtrArray * array, guint8 ** out_data) { guint i; guint8 header_size; - GstMpegTsDescriptor *descriptor; + GstMpegtsDescriptor *descriptor; g_return_if_fail (out_data != NULL); g_return_if_fail (*out_data != NULL); @@ -648,13 +659,13 @@ _packetize_descriptor_array (GPtrArray * array, guint8 ** out_data) } } -GstMpegTsDescriptor * +GstMpegtsDescriptor * _new_descriptor (guint8 tag, guint8 length) { - GstMpegTsDescriptor *descriptor; + GstMpegtsDescriptor *descriptor; guint8 *data; - descriptor = g_slice_new (GstMpegTsDescriptor); + descriptor = g_slice_new (GstMpegtsDescriptor); descriptor->tag = tag; descriptor->tag_extension = 0; @@ -670,13 +681,13 @@ _new_descriptor (guint8 tag, guint8 length) return descriptor; } -GstMpegTsDescriptor * +GstMpegtsDescriptor * _new_descriptor_with_extension (guint8 tag, guint8 tag_extension, guint8 length) { - GstMpegTsDescriptor *descriptor; + GstMpegtsDescriptor *descriptor; guint8 *data; - descriptor = g_slice_new (GstMpegTsDescriptor); + descriptor = g_slice_new (GstMpegtsDescriptor); descriptor->tag = tag; descriptor->tag_extension = tag_extension; @@ -693,25 +704,25 @@ _new_descriptor_with_extension (guint8 tag, guint8 tag_extension, guint8 length) return descriptor; } -static GstMpegTsDescriptor * -_copy_descriptor (GstMpegTsDescriptor * desc) +static GstMpegtsDescriptor * +_copy_descriptor (GstMpegtsDescriptor * desc) { - GstMpegTsDescriptor *copy; + GstMpegtsDescriptor *copy; - copy = g_slice_dup (GstMpegTsDescriptor, desc); + copy = g_slice_dup (GstMpegtsDescriptor, desc); copy->data = g_memdup (desc->data, desc->length + 2); return copy; } void -_free_descriptor (GstMpegTsDescriptor * desc) +_free_descriptor (GstMpegtsDescriptor * desc) { g_free ((gpointer) desc->data); - g_slice_free (GstMpegTsDescriptor, desc); + g_slice_free (GstMpegtsDescriptor, desc); } -G_DEFINE_BOXED_TYPE (GstMpegTsDescriptor, gst_mpegts_descriptor, +G_DEFINE_BOXED_TYPE (GstMpegtsDescriptor, gst_mpegts_descriptor, (GBoxedCopyFunc) _copy_descriptor, (GBoxedFreeFunc) _free_descriptor); /** @@ -724,7 +735,7 @@ G_DEFINE_BOXED_TYPE (GstMpegTsDescriptor, gst_mpegts_descriptor, * * Note: The data provided in @buffer will not be copied. * - * Returns: (transfer full) (element-type GstMpegTsDescriptor): an + * Returns: (transfer full) (element-type GstMpegtsDescriptor): an * array of the parsed descriptors or %NULL if there was an error. * Release with #g_array_unref when done with it. */ @@ -772,7 +783,7 @@ gst_mpegts_parse_descriptors (guint8 * buffer, gsize buf_len) data = buffer; for (i = 0; i < nb_desc; i++) { - GstMpegTsDescriptor *desc = g_slice_new0 (GstMpegTsDescriptor); + GstMpegtsDescriptor *desc = g_slice_new0 (GstMpegtsDescriptor); desc->data = data; desc->tag = *data++; @@ -798,8 +809,8 @@ gst_mpegts_parse_descriptors (guint8 * buffer, gsize buf_len) /** * gst_mpegts_find_descriptor: - * @descriptors: (element-type GstMpegTsDescriptor) (transfer none): an array - * of #GstMpegTsDescriptor + * @descriptors: (element-type GstMpegtsDescriptor) (transfer none): an array + * of #GstMpegtsDescriptor * @tag: the tag to look for * * Finds the first descriptor of type @tag in the array. @@ -809,7 +820,7 @@ gst_mpegts_parse_descriptors (guint8 * buffer, gsize buf_len) * * Returns: (transfer none): the first descriptor matchin @tag, else %NULL. */ -const GstMpegTsDescriptor * +const GstMpegtsDescriptor * gst_mpegts_find_descriptor (GPtrArray * descriptors, guint8 tag) { guint i, nb_desc; @@ -818,9 +829,9 @@ gst_mpegts_find_descriptor (GPtrArray * descriptors, guint8 tag) nb_desc = descriptors->len; for (i = 0; i < nb_desc; i++) { - GstMpegTsDescriptor *desc = g_ptr_array_index (descriptors, i); + GstMpegtsDescriptor *desc = g_ptr_array_index (descriptors, i); if (desc->tag == tag) - return (const GstMpegTsDescriptor *) desc; + return (const GstMpegtsDescriptor *) desc; } return NULL; } @@ -832,15 +843,15 @@ gst_mpegts_find_descriptor (GPtrArray * descriptors, guint8 tag) * @additional_info: (transfer none) (allow-none): pointer to optional additional info * @additional_info_length: length of the optional @additional_info * - * Creates a %GST_MTS_DESC_REGISTRATION #GstMpegTsDescriptor + * Creates a %GST_MTS_DESC_REGISTRATION #GstMpegtsDescriptor * - * Return: #GstMpegTsDescriptor, %NULL on failure + * Return: #GstMpegtsDescriptor, %NULL on failure */ -GstMpegTsDescriptor * +GstMpegtsDescriptor * gst_mpegts_descriptor_from_registration (const gchar * format_identifier, guint8 * additional_info, gsize additional_info_length) { - GstMpegTsDescriptor *descriptor; + GstMpegtsDescriptor *descriptor; g_return_val_if_fail (format_identifier != NULL, NULL); @@ -855,10 +866,43 @@ gst_mpegts_descriptor_from_registration (const gchar * format_identifier, } /* GST_MTS_DESC_ISO_639_LANGUAGE (0x0A) */ +static GstMpegtsISO639LanguageDescriptor * +_gst_mpegts_iso_639_language_descriptor_copy (GstMpegtsISO639LanguageDescriptor + * source) +{ + GstMpegtsISO639LanguageDescriptor *copy; + guint i; + + copy = g_slice_dup (GstMpegtsISO639LanguageDescriptor, source); + + for (i = 0; i < source->nb_language; i++) { + copy->language[i] = g_strdup (source->language[i]); + } + + return copy; +} + +void +gst_mpegts_iso_639_language_descriptor_free (GstMpegtsISO639LanguageDescriptor + * desc) +{ + guint i; + + for (i = 0; i < desc->nb_language; i++) { + g_free (desc->language[i]); + } + g_slice_free (GstMpegtsISO639LanguageDescriptor, desc); +} + +G_DEFINE_BOXED_TYPE (GstMpegtsISO639LanguageDescriptor, + gst_mpegts_iso_639_language, + (GBoxedCopyFunc) _gst_mpegts_iso_639_language_descriptor_copy, + (GFreeFunc) gst_mpegts_iso_639_language_descriptor_free); + /** * gst_mpegts_descriptor_parse_iso_639_language: - * @descriptor: a %GST_MTS_DESC_ISO_639_LANGUAGE #GstMpegTsDescriptor - * @res: (out) (transfer none): the #GstMpegTsISO639LanguageDescriptor to fill + * @descriptor: a %GST_MTS_DESC_ISO_639_LANGUAGE #GstMpegtsDescriptor + * @res: (out) (transfer full): the #GstMpegtsISO639LanguageDescriptor to fill * * Extracts the iso 639-2 language information from @descriptor. * @@ -868,34 +912,41 @@ gst_mpegts_descriptor_from_registration (const gchar * format_identifier, * Returns: %TRUE if parsing succeeded, else %FALSE. */ gboolean -gst_mpegts_descriptor_parse_iso_639_language (const GstMpegTsDescriptor * - descriptor, GstMpegTsISO639LanguageDescriptor * res) +gst_mpegts_descriptor_parse_iso_639_language (const GstMpegtsDescriptor * + descriptor, GstMpegtsISO639LanguageDescriptor ** desc) { guint i; guint8 *data; + GstMpegtsISO639LanguageDescriptor *res; - g_return_val_if_fail (descriptor != NULL && res != NULL, FALSE); + g_return_val_if_fail (descriptor != NULL && desc != NULL, FALSE); /* This descriptor can be empty, no size check needed */ __common_desc_checks (descriptor, GST_MTS_DESC_ISO_639_LANGUAGE, 0, FALSE); data = (guint8 *) descriptor->data + 2; + + res = g_slice_new0 (GstMpegtsISO639LanguageDescriptor); + /* Each language is 3 + 1 bytes */ res->nb_language = descriptor->length / 4; for (i = 0; i < res->nb_language; i++) { - memcpy (res->language[i], data, 3); + res->language[i] = convert_lang_code (data); res->audio_type[i] = data[3]; data += 4; } + + *desc = res; + return TRUE; } /** * gst_mpegts_descriptor_parse_iso_639_language_idx: - * @descriptor: a %GST_MTS_DESC_ISO_639_LANGUAGE #GstMpegTsDescriptor + * @descriptor: a %GST_MTS_DESC_ISO_639_LANGUAGE #GstMpegtsDescriptor * @idx: Table id of the language to parse - * @lang: (out) (transfer none): 4-byte gchar array to hold the language code - * @audio_type: (out) (transfer none) (allow-none): the #GstMpegTsIso639AudioType to set + * @lang: (out) (transfer full): 4-byte gchar array to hold the language code + * @audio_type: (out) (transfer none) (allow-none): the #GstMpegtsIso639AudioType to set * * Extracts the iso 639-2 language information from specific table id in @descriptor. * @@ -905,9 +956,8 @@ gst_mpegts_descriptor_parse_iso_639_language (const GstMpegTsDescriptor * * Returns: %TRUE if parsing succeeded, else %FALSE. */ gboolean -gst_mpegts_descriptor_parse_iso_639_language_idx (const GstMpegTsDescriptor * - descriptor, guint idx, gchar (*lang)[4], - GstMpegTsIso639AudioType * audio_type) +gst_mpegts_descriptor_parse_iso_639_language_idx (const GstMpegtsDescriptor * + descriptor, guint idx, gchar ** lang, GstMpegtsIso639AudioType * audio_type) { guint8 *data; @@ -920,8 +970,7 @@ gst_mpegts_descriptor_parse_iso_639_language_idx (const GstMpegTsDescriptor * data = (guint8 *) descriptor->data + 2 + idx * 4; - memcpy (lang, data, 3); - (*lang)[3] = 0; + *lang = convert_lang_code (data); data += 3; @@ -933,12 +982,12 @@ gst_mpegts_descriptor_parse_iso_639_language_idx (const GstMpegTsDescriptor * /** * gst_mpegts_descriptor_parse_iso_639_language_nb: - * @descriptor: a %GST_MTS_DESC_ISO_639_LANGUAGE #GstMpegTsDescriptor + * @descriptor: a %GST_MTS_DESC_ISO_639_LANGUAGE #GstMpegtsDescriptor * * Returns: The number of languages in @descriptor */ guint -gst_mpegts_descriptor_parse_iso_639_language_nb (const GstMpegTsDescriptor * +gst_mpegts_descriptor_parse_iso_639_language_nb (const GstMpegtsDescriptor * descriptor) { g_return_val_if_fail (descriptor != NULL, 0); @@ -950,16 +999,16 @@ gst_mpegts_descriptor_parse_iso_639_language_nb (const GstMpegTsDescriptor * /** * gst_mpegts_descriptor_parse_logical_channel: - * @descriptor: a %GST_MTS_DESC_DTG_LOGICAL_CHANNEL #GstMpegTsDescriptor - * @res: (out) (transfer none): the #GstMpegTsLogicalChannelDescriptor to fill + * @descriptor: a %GST_MTS_DESC_DTG_LOGICAL_CHANNEL #GstMpegtsDescriptor + * @res: (out) (transfer none): the #GstMpegtsLogicalChannelDescriptor to fill * * Extracts the logical channels from @descriptor. * * Returns: %TRUE if parsing succeeded, else %FALSE. */ gboolean -gst_mpegts_descriptor_parse_logical_channel (const GstMpegTsDescriptor * - descriptor, GstMpegTsLogicalChannelDescriptor * res) +gst_mpegts_descriptor_parse_logical_channel (const GstMpegtsDescriptor * + descriptor, GstMpegtsLogicalChannelDescriptor * res) { guint i; guint8 *data; @@ -969,6 +1018,7 @@ gst_mpegts_descriptor_parse_logical_channel (const GstMpegTsDescriptor * __common_desc_checks (descriptor, GST_MTS_DESC_DTG_LOGICAL_CHANNEL, 0, FALSE); data = (guint8 *) descriptor->data + 2; + res->nb_channels = descriptor->length / 4; for (i = 0; i < res->nb_channels; i++) { @@ -989,15 +1039,15 @@ gst_mpegts_descriptor_parse_logical_channel (const GstMpegTsDescriptor * * @data: (transfer none): descriptor data (after tag and length field) * @length: length of @data * - * Creates a #GstMpegTsDescriptor with custom @tag and @data + * Creates a #GstMpegtsDescriptor with custom @tag and @data * - * Returns: #GstMpegTsDescriptor + * Returns: #GstMpegtsDescriptor */ -GstMpegTsDescriptor * +GstMpegtsDescriptor * gst_mpegts_descriptor_from_custom (guint8 tag, const guint8 * data, gsize length) { - GstMpegTsDescriptor *descriptor; + GstMpegtsDescriptor *descriptor; descriptor = _new_descriptor (tag, length); |