Commit 5b5f2a4b authored by Georgi Chorbadzhiyski's avatar Georgi Chorbadzhiyski

dvb/si: Add support for descriptor 0x51 (Mosaic descriptor).

parent 86e286ae
......@@ -114,6 +114,7 @@ Supported DVB descriptors
* Descriptor 0x4e: Extended event descriptor
* Descriptor 0x4f: Time shifted event descriptor
* Descriptor 0x50: Component descriptor
* Descriptor 0x51: Mosaic descriptor
* Descriptor 0x52: Stream identifier descriptor
* Descriptor 0x54: Content descriptor
* Descriptor 0x55: Parental rating descriptor
......
......@@ -14,7 +14,6 @@ so if you like something just do it and send a patch.
- Descriptor 0x6a: AC-3 descriptor
- Add support (parser, generator, example) for these DVB descriptors:
- Descriptor 0x51: mosaic_descriptor
- Descriptor 0x53: CA_identifier_descriptor
- Descriptor 0x57: telephone_descriptor
- Descriptor 0x5b: multilingual_network_name_descriptor
......
/*****************************************************************************
* desc_51.h: ETSI EN 300 518 Descriptor 0x51: Mosaic descriptor
*****************************************************************************
* Copyright (C) 2011 Unix Solutions Ltd.
*
* Authors: Georgi Chorbadzhiyski <georgi@unixsol.org>
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject
* to the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*****************************************************************************/
/*
* Normative references:
* - ETSI EN 300 518 V1.11.1 (2010-04) (SI in DVB systems)
*/
#ifndef __BITSTREAM_DVB_DESC_51_H__
#define __BITSTREAM_DVB_DESC_51_H__
#include <bitstream/common.h>
#include <bitstream/mpeg/psi/descriptors.h>
#ifdef __cplusplus
extern "C"
{
#endif
/*****************************************************************************
* Descriptor 0x51: Mosaic descriptor
*****************************************************************************/
#define DESC51_HEADER_SIZE (DESC_HEADER_SIZE + 1)
#define DESC51_DATA_SIZE 4
static inline void desc51_init(uint8_t *p_desc)
{
desc_set_tag(p_desc, 0x51);
desc_set_length(p_desc, 1);
p_desc[2] = 0x08;
}
static inline bool desc51_get_mosaic_entry_point(const uint8_t *p_desc)
{
return (p_desc[2] & 0x80) == 0x80;
}
static inline void desc51_set_mosaic_entry_point(uint8_t *p_desc, bool b_entry_point)
{
p_desc[2] = b_entry_point ? (p_desc[2] | 0x80) : (p_desc[2] &~ 0x80);
}
static inline uint8_t desc51_get_horizontal_cells(const uint8_t *p_desc)
{
return (p_desc[2] & 0x70) >> 4;
}
static inline void desc51_set_horizontal_cells(uint8_t *p_desc, uint8_t i_hcells)
{
p_desc[2] = (p_desc[2] & 0x8f) | ((i_hcells & 0x07) << 4);
}
static inline uint8_t desc51_get_vertical_cells(const uint8_t *p_desc)
{
return (p_desc[2] & 0x07);
}
static inline void desc51_set_vertical_cells(uint8_t *p_desc, uint8_t i_vcells)
{
p_desc[2] = (p_desc[2] & 0xf8) | (i_vcells & 0x07);
}
static inline uint8_t desc51n_get_logical_cell_id(const uint8_t *p_desc_n)
{
return p_desc_n[0] >> 2;
}
static inline void desc51n_set_logical_cell_id(uint8_t *p_desc_n, uint8_t i_logical_cell_id)
{
p_desc_n[0] = (i_logical_cell_id << 2) | 0x03;
}
static inline uint8_t desc51n_get_logical_cell_presentation_info(const uint8_t *p_desc_n)
{
return p_desc_n[1] & 0x07;
}
static inline void desc51n_set_logical_cell_presentation_info(uint8_t *p_desc_n, uint8_t i_lc_presentation_info)
{
p_desc_n[1] = (i_lc_presentation_info & 0x07) | 0xf8;
}
static inline char *desc51_get_logical_cell_presentation_info_txt(uint8_t i_lcp_info)
{
return i_lcp_info == 0x00 ? "undefined" :
i_lcp_info == 0x01 ? "video" :
i_lcp_info == 0x02 ? "still picture" :
i_lcp_info == 0x03 ? "graphics/text" : "reserved";
}
static inline uint8_t desc51n_get_elementary_cell_field_length(const uint8_t *p_desc_n)
{
return p_desc_n[2];
}
static inline void desc51n_set_elementary_cell_field_length(uint8_t *p_desc_n, uint8_t i_length)
{
p_desc_n[2] = i_length;
}
static inline uint8_t desc51n_get_elementary_cell_id(const uint8_t *p_desc_n, uint8_t idx)
{
return p_desc_n[3 + idx] & 0x3f;
}
static inline void desc51n_set_elementary_cell_id(uint8_t *p_desc_n, uint8_t idx, uint8_t i_elementary_cell_id)
{
p_desc_n[3 + idx] = 0xc0 | (i_elementary_cell_id & 0x3f);
}
static inline uint8_t desc51n_get_cell_linkage_info(const uint8_t *p_desc_n)
{
return p_desc_n[3 + desc51n_get_elementary_cell_field_length(p_desc_n)];
}
static inline void desc51n_set_cell_linkage_info(uint8_t *p_desc_n, uint8_t i_cell_linkage_info)
{
p_desc_n[3 + desc51n_get_elementary_cell_field_length(p_desc_n)] = i_cell_linkage_info;
}
static inline char *desc51_get_cell_linkage_info_txt(uint8_t i_icl_info)
{
return i_icl_info == 0x00 ? "undefined" :
i_icl_info == 0x01 ? "bouquet related" :
i_icl_info == 0x02 ? "service related" :
i_icl_info == 0x03 ? "other mosaic related" :
i_icl_info == 0x04 ? "event related" : "reserved";
}
#define init_link_n(__const) \
__const uint8_t *link_n; \
uint8_t i_cell_linkage_info = desc51n_get_cell_linkage_info(p_desc_n); \
link_n = p_desc_n + 4 + desc51n_get_elementary_cell_field_length(p_desc_n)
static inline uint16_t desc51n_get_bouquet_id(const uint8_t *p_desc_n)
{
init_link_n(const);
if (i_cell_linkage_info != 1) return 0;
return (link_n[0] << 8) | link_n[1];
}
static inline void desc51n_set_bouquet_id(uint8_t *p_desc_n, uint16_t i_bouquet_id)
{
init_link_n();
if (i_cell_linkage_info != 1) return;
link_n[0] = (i_bouquet_id >> 8) & 0xff;
link_n[1] = i_bouquet_id & 0xff;
}
static inline uint16_t desc51n_get_onid(const uint8_t *p_desc_n)
{
init_link_n(const);
if (i_cell_linkage_info < 2 || i_cell_linkage_info > 4) return 0;
return (link_n[0] << 8) | link_n[1];
}
static inline void desc51n_set_onid(uint8_t *p_desc_n, uint16_t i_onid)
{
init_link_n();
if (i_cell_linkage_info < 2 || i_cell_linkage_info > 4) return;
link_n[0] = (i_onid >> 8) & 0xff;
link_n[1] = i_onid & 0xff;
}
static inline uint16_t desc51n_get_tsid(const uint8_t *p_desc_n)
{
init_link_n(const);
if (i_cell_linkage_info < 2 || i_cell_linkage_info > 4) return 0;
return (link_n[2] << 8) | link_n[3];
}
static inline void desc51n_set_tsid(uint8_t *p_desc_n, uint16_t i_tsid)
{
init_link_n();
if (i_cell_linkage_info < 2 || i_cell_linkage_info > 4) return;
link_n[2] = (i_tsid >> 8) & 0xff;
link_n[3] = i_tsid & 0xff;
}
static inline uint16_t desc51n_get_sid(const uint8_t *p_desc_n)
{
init_link_n(const);
if (i_cell_linkage_info < 2 || i_cell_linkage_info > 4) return 0;
return (link_n[4] << 8) | link_n[5];
}
static inline void desc51n_set_sid(uint8_t *p_desc_n, uint16_t i_sid)
{
init_link_n();
if (i_cell_linkage_info < 2 || i_cell_linkage_info > 4) return;
link_n[4] = (i_sid >> 8) & 0xff;
link_n[5] = i_sid & 0xff;
}
static inline uint16_t desc51n_get_event_id(const uint8_t *p_desc_n)
{
init_link_n(const);
if (i_cell_linkage_info != 4) return 0;
return (link_n[6] << 8) | link_n[7];
}
static inline void desc51n_set_event_id(uint8_t *p_desc_n, uint16_t i_event_id)
{
init_link_n();
if (i_cell_linkage_info != 4) return;
link_n[6] = (i_event_id >> 8) & 0xff;
link_n[7] = i_event_id & 0xff;
}
#undef setup_link_
static inline uint8_t *desc51_get_logical_cell(uint8_t *p_desc, uint8_t n)
{
uint8_t *p_desc_n = p_desc + DESC51_HEADER_SIZE;
uint8_t i_desc_size = desc_get_length(p_desc);
while (n) {
uint8_t i_desc51_data_size = DESC51_DATA_SIZE + desc51n_get_elementary_cell_field_length(p_desc_n);
switch (desc51n_get_cell_linkage_info(p_desc_n)) {
case 1: i_desc51_data_size += 2; break;
case 2: i_desc51_data_size += 6; break;
case 3: i_desc51_data_size += 6; break;
case 4: i_desc51_data_size += 8; break;
}
if (p_desc_n + i_desc51_data_size - p_desc > i_desc_size)
return NULL;
p_desc_n += i_desc51_data_size;
n--;
}
if (p_desc_n - p_desc > i_desc_size)
return NULL;
return p_desc_n;
}
static inline bool desc51_validate(const uint8_t *p_desc)
{
const uint8_t *p_desc_n = p_desc + DESC51_HEADER_SIZE;
int i_desc_size = desc_get_length(p_desc);
while (i_desc_size > (DESC51_HEADER_SIZE - DESC_HEADER_SIZE)) {
uint8_t i_desc51_data_size = DESC51_DATA_SIZE + desc51n_get_elementary_cell_field_length(p_desc_n);
switch (desc51n_get_cell_linkage_info(p_desc_n)) {
case 1: i_desc51_data_size += 2; break;
case 2: i_desc51_data_size += 6; break;
case 3: i_desc51_data_size += 6; break;
case 4: i_desc51_data_size += 8; break;
}
i_desc_size -= i_desc51_data_size;
p_desc_n += i_desc51_data_size;
}
return i_desc_size == (DESC51_HEADER_SIZE - DESC_HEADER_SIZE);
}
static inline void desc51_print(uint8_t *p_desc, f_print pf_print,
void *opaque, print_type_t i_print_type)
{
uint8_t j = 0;
uint8_t *p_desc_n;
if (i_print_type == PRINT_XML)
pf_print(opaque,
"<MOSAIC_DESC entry_point=\"%u\" horizontal_elementary_cells=\"%u\" vertical_elementary_cells=\"%u\">",
desc51_get_mosaic_entry_point(p_desc),
desc51_get_horizontal_cells(p_desc),
desc51_get_vertical_cells(p_desc)
);
else
pf_print(opaque,
" - desc 51 mosaic entry_point=%u horizontal_elementary_cells=%u vertical_elementary_cells=%u",
desc51_get_mosaic_entry_point(p_desc),
desc51_get_horizontal_cells(p_desc),
desc51_get_vertical_cells(p_desc)
);
while ((p_desc_n = desc51_get_logical_cell(p_desc, j++)) != NULL) {
uint8_t k;
uint8_t i_present_info = desc51n_get_logical_cell_presentation_info(p_desc_n);
uint8_t i_el_cell_len = desc51n_get_elementary_cell_field_length(p_desc_n);
uint8_t i_cell_linkage = desc51n_get_cell_linkage_info(p_desc_n);
switch (i_print_type) {
case PRINT_XML:
pf_print(opaque,
"<MOSAIC_LOGICAL_CELL cell_id=\"%u\" presentation_info=\"%u\""
" presentation_info_txt=\"%s\" cell_linkage=\"%u\""
" cell_linkage_txt=\"%s\" bouquet_id=\"%u\" onid=\"%u\""
" tsid=\"%u\" sid=\"%u\" event_id=\"%u\">",
desc51n_get_logical_cell_id(p_desc_n),
i_present_info,
desc51_get_logical_cell_presentation_info_txt(i_present_info),
i_cell_linkage,
desc51_get_cell_linkage_info_txt(i_cell_linkage),
desc51n_get_bouquet_id(p_desc_n),
desc51n_get_onid(p_desc_n),
desc51n_get_tsid(p_desc_n),
desc51n_get_sid(p_desc_n),
desc51n_get_event_id(p_desc_n)
);
for (k = 0; k < i_el_cell_len; k++) {
pf_print(opaque,
"<MOSAIC_ELEMENTARY_CELL cell_id=\"%u\"/>",
desc51n_get_elementary_cell_id(p_desc_n, k));
}
pf_print(opaque, "</MOSAIC_LOGICAL_CELL>");
break;
default:
pf_print(opaque,
" - logical_cell cell_id=%u presentation_info=%u"
" presentation_info_txt=\"%s\" cell_linkage=%u"
" cell_linkage_txt=\"%s\" bouquet_id=%u onid=%u"
" tsid=%u sid=%u event_id=%u",
desc51n_get_logical_cell_id(p_desc_n),
i_present_info,
desc51_get_logical_cell_presentation_info_txt(i_present_info),
i_cell_linkage,
desc51_get_cell_linkage_info_txt(i_cell_linkage),
desc51n_get_bouquet_id(p_desc_n),
desc51n_get_onid(p_desc_n),
desc51n_get_tsid(p_desc_n),
desc51n_get_sid(p_desc_n),
desc51n_get_event_id(p_desc_n)
);
for (k = 0; k < i_el_cell_len; k++) {
pf_print(opaque,
" - elementary_cell cell_id=%u",
desc51n_get_elementary_cell_id(p_desc_n, k));
}
}
}
if (i_print_type == PRINT_XML)
pf_print(opaque, "</MOSAIC_DESC>");
}
#ifdef __cplusplus
}
#endif
#endif
......@@ -51,6 +51,7 @@
#include <bitstream/dvb/si/desc_4e.h>
#include <bitstream/dvb/si/desc_4f.h>
#include <bitstream/dvb/si/desc_50.h>
#include <bitstream/dvb/si/desc_51.h>
#include <bitstream/dvb/si/desc_52.h>
#include <bitstream/dvb/si/desc_54.h>
#include <bitstream/dvb/si/desc_55.h>
......
......@@ -643,7 +643,69 @@ static void build_desc50(uint8_t *desc) {
desc50_set_text(desc, (uint8_t *)text, strlen(text)); // Not required
}
/* --- Descriptor 0x51: mosaic_descriptor */
/* DVB Descriptor 0x51: Mosaic descriptor */
static void build_desc51(uint8_t *desc) {
uint8_t k = 0;
uint8_t *cell_n;
desc51_init(desc);
desc51_set_mosaic_entry_point(desc, 1);
desc51_set_horizontal_cells(desc, 2); // +1 == 3
desc51_set_vertical_cells(desc, 2); // +1 == 3 (3x3 == 9 cells)
desc_set_length(desc, 255);
cell_n = desc51_get_logical_cell(desc, k++);
{
desc51n_set_logical_cell_id(cell_n, 0);
desc51n_set_logical_cell_presentation_info(cell_n, 1);
desc51n_set_elementary_cell_field_length(cell_n, 3);
{
desc51n_set_elementary_cell_id(cell_n, 0, 0);
desc51n_set_elementary_cell_id(cell_n, 1, 1);
desc51n_set_elementary_cell_id(cell_n, 2, 2);
}
desc51n_set_cell_linkage_info(cell_n, 1); // bouquet_id
desc51n_set_bouquet_id(cell_n, onid + 100);
}
cell_n = desc51_get_logical_cell(desc, k++);
{
desc51n_set_logical_cell_id(cell_n, 1);
desc51n_set_logical_cell_presentation_info(cell_n, 2);
desc51n_set_elementary_cell_field_length(cell_n, 3);
{
desc51n_set_elementary_cell_id(cell_n, 0, 3);
desc51n_set_elementary_cell_id(cell_n, 1, 4);
desc51n_set_elementary_cell_id(cell_n, 2, 5);
}
desc51n_set_cell_linkage_info(cell_n, 2); // 2 or 3, onid, tsid, sid
desc51n_set_onid(cell_n, onid + 500);
desc51n_set_tsid(cell_n, tsid + 500);
desc51n_set_sid(cell_n, sid + 500);
}
cell_n = desc51_get_logical_cell(desc, k++);
{
desc51n_set_logical_cell_id(cell_n, 2);
desc51n_set_logical_cell_presentation_info(cell_n, 3);
desc51n_set_elementary_cell_field_length(cell_n, 3);
{
desc51n_set_elementary_cell_id(cell_n, 0, 6);
desc51n_set_elementary_cell_id(cell_n, 1, 7);
desc51n_set_elementary_cell_id(cell_n, 2, 8);
}
desc51n_set_cell_linkage_info(cell_n, 4); // onid, tsid, sid, event_id
desc51n_set_onid(cell_n, onid + 1000);
desc51n_set_tsid(cell_n, tsid + 1000);
desc51n_set_sid(cell_n, sid + 1000);
desc51n_set_event_id(cell_n, event_id + 1000);
}
cell_n = desc51_get_logical_cell(desc, k);
desc_set_length(desc, cell_n - desc - DESC_HEADER_SIZE);
}
/* DVB Descriptor 0x52: Stream identifier descriptor */
static void build_desc52(uint8_t *desc) {
desc52_init(desc);
......@@ -1303,6 +1365,9 @@ static void generate_sdt(void) {
desc = descs_get_desc(desc_loop, desc_counter++);
build_desc49(desc, true);
desc = descs_get_desc(desc_loop, desc_counter++);
build_desc51(desc);
desc = descs_get_desc(desc_loop, desc_counter++);
build_desc5f(desc);
......
......@@ -146,6 +146,7 @@ static inline void descl_print(uint8_t *p_descl, uint16_t i_length,
CASE_DESC_ICONV(4e)
CASE_DESC(4f)
CASE_DESC_ICONV(50)
CASE_DESC(51)
CASE_DESC(52)
CASE_DESC(54)
CASE_DESC(55)
......
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