add support for parsing ac-3 audio descriptor 0x81
[email protected] (Michael Krufky)
| Newsgroups | gmane.comp.video.videolan.libdvbpsi.devel |
|---|---|
| Message-ID | <[email protected]> |
libdvbpsi | branch: master | Michael Krufky <[email protected]> | Mon May 20 20:09:08 2013 -0400| [c354e17665d4e1a72c5c7c9036682d92e9c3b319] | committer: Jean-Paul Saman add support for parsing ac-3 audio descriptor 0x81 Signed-off-by: Michael Krufky <[email protected]> > http://git.videolan.org/gitweb.cgi/libdvbpsi.git/?a=commit;h=c354e17665d4e1a72c5c7c9036682d92e9c3b319 --- src/Makefile.am | 2 + src/descriptors/dr_81.c | 127 +++++++++++++++++++++++++++++++++++++++++++++++ src/descriptors/dr_81.h | 90 +++++++++++++++++++++++++++++++++ 3 files changed, 219 insertions(+) diff --git a/src/Makefile.am b/src/Makefile.am index 61ec5ae..5ebab6d 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -66,6 +66,7 @@ pkginclude_HEADERS = dvbpsi.h psi.h descriptor.h demux.h \ descriptors/dr_73.h \ descriptors/dr_76.h \ descriptors/dr_7c.h \ + descriptors/dr_81.h \ descriptors/dr_83.h \ descriptors/dr_86.h \ descriptors/dr_8a.h \ @@ -118,6 +119,7 @@ descriptors_src = descriptors/dr_02.c \ descriptors/dr_73.c \ descriptors/dr_76.c \ descriptors/dr_7c.c \ + descriptors/dr_81.c \ descriptors/dr_83.c \ descriptors/dr_86.c \ descriptors/dr_8a.c \ diff --git a/src/descriptors/dr_81.c b/src/descriptors/dr_81.c new file mode 100644 index 0000000..800e145 --- /dev/null +++ b/src/descriptors/dr_81.c @@ -0,0 +1,127 @@ +/* +Copyright (C) 2013 Michael Krufky + +This library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +This library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with this library; if not, write to the Free Software +Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + +dr_81.c + +Decode AC-3 Audio Descriptor. + +*/ +#include "config.h" + +#include <stdio.h> +#include <stdlib.h> +#include <stdbool.h> +#include <string.h> + +#if defined(HAVE_INTTYPES_H) +#include <inttypes.h> +#elif defined(HAVE_STDINT_H) +#include <stdint.h> +#endif + +#include "../dvbpsi.h" +#include "../dvbpsi_private.h" +#include "../descriptor.h" + +#include "dr_81.h" + +/***************************************************************************** + * dvbpsi_DecodeAc3AudioDr + *****************************************************************************/ +dvbpsi_ac3_audio_dr_t *dvbpsi_DecodeAc3AudioDr(dvbpsi_descriptor_t *p_descriptor) +{ + dvbpsi_ac3_audio_dr_t *p_decoded; + uint8_t * buf = p_descriptor->p_data; + + /* Check the tag */ + if (p_descriptor->i_tag != 0x81) + return NULL; + + /* Don't decode twice */ + if (p_descriptor->p_decoded) + return p_descriptor->p_decoded; + + /* Check length */ + if (p_descriptor->i_length < 3) + return NULL; + + p_decoded = (dvbpsi_ac3_audio_dr_t*)malloc(sizeof(dvbpsi_ac3_audio_dr_t)); + if (!p_decoded) + return NULL; + + p_descriptor->p_decoded = (void*)p_decoded; + + p_decoded->i_sample_rate_code = 0x07 & (buf[0] >> 5); + p_decoded->i_bsid = 0x1f & buf[0]; + p_decoded->i_bit_rate_code = 0x3f & (buf[1] >> 2); + p_decoded->i_surround_mode = 0x03 & buf[1]; + p_decoded->i_bsmod = 0x07 & (buf[2] >> 5); + p_decoded->i_num_channels = 0x0f & (buf[2] >> 1); + p_decoded->b_full_svc = 0x01 & buf[2]; + buf += 3; + if (buf == p_descriptor->p_data + p_descriptor->i_length) + return p_decoded; + + p_decoded->i_lang_code = buf[0]; + buf++; + + if (buf == p_descriptor->p_data + p_descriptor->i_length) + return p_decoded; + + if (!p_decoded->i_num_channels) { + p_decoded->i_lang_code2 = buf[0]; + buf++; + } + + if (buf == p_descriptor->p_data + p_descriptor->i_length) + return p_decoded; + + if (p_decoded->i_bsmod < 2) { + p_decoded->i_mainid = 0x07 & (buf[0] >> 5); + p_decoded->i_priority = 0x03 & (buf[0] >> 3); + } else + p_decoded->i_asvcflags = buf[0]; + buf++; + + if (buf == p_descriptor->p_data + p_descriptor->i_length) + return p_decoded; + + p_decoded->i_textlen = 0x7f & (buf[0] >> 1); + p_decoded->b_text_code = 0X01 & buf[0]; + buf++; + + memset(p_decoded->text, 0, sizeof(p_decoded->text)); + memcpy(p_decoded->text, buf, p_decoded->i_textlen); + buf += p_decoded->i_textlen; + + if (buf == p_descriptor->p_data + p_descriptor->i_length) + return p_decoded; + + p_decoded->b_language_flag = 0x01 & (buf[0] >> 7); + p_decoded->b_language_flag_2 = 0x01 & (buf[0] >> 6); + buf++; + + if (p_decoded->b_language_flag) { + memcpy(p_decoded->language, buf, 3); + buf += 3; + } + if (p_decoded->b_language_flag_2) { + memcpy(p_decoded->language_2, buf, 3); + buf += 3; + } + return p_decoded; +} diff --git a/src/descriptors/dr_81.h b/src/descriptors/dr_81.h new file mode 100644 index 0000000..567eec0 --- /dev/null +++ b/src/descriptors/dr_81.h @@ -0,0 +1,90 @@ +/* +Copyright (C) 2013 Michael Krufky + +This library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +This library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with this library; if not, write to the Free Software +Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + +dr_81.h + +Decode AC-3 Audio Descriptor. + +*/ + +/*! + * \file dr_81.h + * \author Michael Krufky + * \brief Decode AC-3 Audio Descriptor. + */ + +#ifndef _DR_81_H +#define _DR_81_H + +#ifdef __cplusplus +extern "C" { +#endif + +/***************************************************************************** + * dvbpsi_ac3_audio_dr_s + *****************************************************************************/ +/*! + * \struct dvbpsi_ac3_audio_dr_s + * \brief AC-3 Audio Descriptor + * + * This structure is used to store a decoded AC-3 Audio descriptor. + */ +/*! + * \typedef struct dvbpsi_ac3_audio_dr_s dvbpsi_ac3_audio_dr_t + * \brief dvbpsi_ac3_audio_dr_t type definition. + */ +typedef struct dvbpsi_ac3_audio_dr_s +{ + uint8_t i_sample_rate_code; // 3bits + uint8_t i_bsid; // 5bits + uint8_t i_bit_rate_code; // 6bits + uint8_t i_surround_mode; // 2bits + uint8_t i_bsmod; // 3bits + uint8_t i_num_channels; // 4bits + int b_full_svc; + uint8_t i_lang_code; // 8bits + uint8_t i_lang_code2; // 8bits + uint8_t i_mainid; // 3bits + uint8_t i_priority; // 2bits + uint8_t i_asvcflags; // 8bits + uint8_t i_textlen; // 7bits + int b_text_code; + unsigned char text[128]; + int b_language_flag; + int b_language_flag_2; + uint8_t language[3]; + uint8_t language_2[3]; +}dvbpsi_ac3_audio_dr_t; + +/***************************************************************************** + * dvbpsi_DecodeAc3AudioDr + *****************************************************************************/ +/*! + * \fn dvbpsi_ac3_audio_dr_t dvbpsi_DecodeAc3AudioDr(dvbpsi_descriptor_t *p_descriptor) + * \brief Decode a AC-3 Audio descriptor (tag 0x81) + * \param p_descriptor Raw descriptor to decode. + * \return NULL if the descriptor could not be decoded or a pointer to a + * dvbpsi_ac3_audio_dr_t structure. + */ +dvbpsi_ac3_audio_dr_t *dvbpsi_DecodeAc3AudioDr(dvbpsi_descriptor_t *p_descriptor); + +#ifdef __cplusplus +} +#endif + +#endif + _______________________________________________ libdvbpsi-devel mailing list [email protected] https://mailman.videolan.org/listinfo/libdvbpsi-devel