Commit c354e176 authored by Michael Krufky's avatar Michael Krufky Committed by Jean-Paul Saman

add support for parsing ac-3 audio descriptor 0x81

Signed-off-by: default avatarMichael Krufky <mkrufky@linuxtv.org>
parent 0d969f66
......@@ -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 \
......
/*
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;
}
/*
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
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment