Commit 56fca374 authored by Georgi Chorbadzhiyski's avatar Georgi Chorbadzhiyski

dvb/si: Add support for descriptor 0x6e (Announcement support descriptor).

parent cdbad569
......@@ -147,6 +147,7 @@ Supported DVB descriptors
* Descriptor 0x6b: Ancillary data descriptor
* Descriptor 0x6c: Cell list descriptor
* Descriptor 0x6d: Cell frequency link descriptor
* Descriptor 0x6e: Announcement support descriptor
* Descriptor 0x7a: Enhanced AC-3 descriptor
* Descriptor 0x7b: DTS descriptor
* Descriptor 0x7c: AAC descriptor
......
......@@ -5,7 +5,6 @@ so if you like something just do it and send a patch.
- Descriptor 0x29 IPMP_descriptor (defined in ISO/IEC 13818-11, MPEG-2 IPMP)
- Add support (parser, generator, example) for these DVB descriptors:
- Descriptor 0x6e: announcement_support_descriptor
- Descriptor 0x6f: application_signalling_descriptor
- Descriptor 0x70: adaptation_field_data_descriptor
- Descriptor 0x71: service_identifier_descriptor
......
/*****************************************************************************
* desc_6e.h: ETSI EN 300 468 Descriptor 0x6e: Announcement support 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 468 V1.11.1 (2010-04) (SI in DVB systems)
*/
#ifndef __BITSTREAM_DVB_DESC_6E_H__
#define __BITSTREAM_DVB_DESC_6E_H__
#include <bitstream/common.h>
#include <bitstream/mpeg/psi/descriptors.h>
#ifdef __cplusplus
extern "C"
{
#endif
/*****************************************************************************
* Descriptor 0x6e: Announcement support descriptor
*****************************************************************************/
#define DESC6E_HEADER_SIZE (DESC_HEADER_SIZE + 2)
#define DESC6E_DATA_SIZE 1
#define DESC6E_EXT_DATA_SIZE 7
static inline void desc6e_init(uint8_t *p_desc)
{
desc_set_tag(p_desc, 0x6e);
desc_set_length(p_desc, DESC6E_HEADER_SIZE - DESC_HEADER_SIZE);
p_desc[2] = 0xff;
}
static inline uint16_t desc6e_get_announcement_support_indicator(const uint8_t *p_desc)
{
return (p_desc[2] << 8) | p_desc[3];
}
static inline void desc6e_set_announcement_support_indicator(uint8_t *p_desc, uint16_t i_announcement_support_indicator)
{
p_desc[2] = (i_announcement_support_indicator >> 8) & 0xff;
p_desc[3] = i_announcement_support_indicator & 0xff;
}
#define __DEFINE_FLAG(FLAGNAME, bit) \
static inline bool desc6e_get_##FLAGNAME##_flag(const uint8_t *p_desc) \
{ \
return (p_desc[3] & bit) == bit; \
} \
\
static inline void desc6e_set_##FLAGNAME##_flag(uint8_t *p_desc, bool b_##FLAGNAME) \
{ \
p_desc[3] = b_##FLAGNAME ? (p_desc[3] | bit) : (p_desc[3] &~ bit); \
}
__DEFINE_FLAG (emergency_alarm , 0x01)
__DEFINE_FLAG (road_traffic_flash , 0x02)
__DEFINE_FLAG (public_transport_flash, 0x04)
__DEFINE_FLAG (warning_message , 0x08)
__DEFINE_FLAG (news_flash , 0x10)
__DEFINE_FLAG (weather_flash , 0x20)
__DEFINE_FLAG (event_announcement , 0x40)
__DEFINE_FLAG (personal_call , 0x80)
#undef __DEFINE_FLAG
static inline uint8_t desc6en_get_announcement_type(const uint8_t *p_desc_n)
{
return (p_desc_n[0] & 0xf0) >> 4;
}
static inline void desc6en_set_announcement_type(uint8_t *p_desc_n, uint8_t i_announcement_type)
{
p_desc_n[0] = ((i_announcement_type & 0x0f) << 4) | 0x08 | (p_desc_n[0] & 0x07);
}
static inline const char *desc6e_get_announcement_type_txt(uint8_t i_announcement_type)
{
return i_announcement_type == 0x00 ? "Emergency alarm" :
i_announcement_type == 0x01 ? "Road Traffic flash" :
i_announcement_type == 0x02 ? "Public Transport flash" :
i_announcement_type == 0x03 ? "Warning message" :
i_announcement_type == 0x04 ? "News flash" :
i_announcement_type == 0x05 ? "Weather flash" :
i_announcement_type == 0x06 ? "Event announcement" :
i_announcement_type == 0x07 ? "Personal call" : "Reserved";
}
static inline uint8_t desc6en_get_reference_type(const uint8_t *p_desc_n)
{
return p_desc_n[0] & 0x07;
}
static inline void desc6en_set_reference_type(uint8_t *p_desc_n, uint8_t i_reference_type)
{
p_desc_n[0] = (p_desc_n[0] & 0xf0) | 0x08 | (i_reference_type & 0x07);
}
static inline uint16_t desc6en_get_onid(const uint8_t *p_desc_n)
{
uint8_t i_ref_type = desc6en_get_reference_type(p_desc_n);
if (!(i_ref_type == 0x01 || i_ref_type == 0x02 || i_ref_type == 0x03))
return 0;
return (p_desc_n[1] << 8) | p_desc_n[2];
}
static inline void desc6en_set_onid(uint8_t *p_desc_n, uint16_t i_onid)
{
uint8_t i_ref_type = desc6en_get_reference_type(p_desc_n);
if (!(i_ref_type == 0x01 || i_ref_type == 0x02 || i_ref_type == 0x03))
return;
p_desc_n[1] = (i_onid >> 8) & 0xff;
p_desc_n[2] = i_onid & 0xff;
}
static inline uint16_t desc6en_get_tsid(const uint8_t *p_desc_n)
{
uint8_t i_ref_type = desc6en_get_reference_type(p_desc_n);
if (!(i_ref_type == 0x01 || i_ref_type == 0x02 || i_ref_type == 0x03))
return 0;
return (p_desc_n[3] << 8) | p_desc_n[4];
}
static inline void desc6en_set_tsid(uint8_t *p_desc_n, uint16_t i_tsid)
{
uint8_t i_ref_type = desc6en_get_reference_type(p_desc_n);
if (!(i_ref_type == 0x01 || i_ref_type == 0x02 || i_ref_type == 0x03))
return;
p_desc_n[3] = (i_tsid >> 8) & 0xff;
p_desc_n[4] = i_tsid & 0xff;
}
static inline uint16_t desc6en_get_service_id(const uint8_t *p_desc_n)
{
uint8_t i_ref_type = desc6en_get_reference_type(p_desc_n);
if (!(i_ref_type == 0x01 || i_ref_type == 0x02 || i_ref_type == 0x03))
return 0;
return (p_desc_n[5] << 8) | p_desc_n[6];
}
static inline void desc6en_set_service_id(uint8_t *p_desc_n, uint16_t i_service_id)
{
uint8_t i_ref_type = desc6en_get_reference_type(p_desc_n);
if (!(i_ref_type == 0x01 || i_ref_type == 0x02 || i_ref_type == 0x03))
return;
p_desc_n[5] = (i_service_id >> 8) & 0xff;
p_desc_n[6] = i_service_id & 0xff;
}
static inline uint8_t desc6en_get_component_tag(const uint8_t *p_desc_n)
{
uint8_t i_ref_type = desc6en_get_reference_type(p_desc_n);
if (!(i_ref_type == 0x01 || i_ref_type == 0x02 || i_ref_type == 0x03))
return 0;
return p_desc_n[7];
}
static inline void desc6en_set_component_tag(uint8_t *p_desc_n, uint8_t i_component_tag)
{
uint8_t i_ref_type = desc6en_get_reference_type(p_desc_n);
if (!(i_ref_type == 0x01 || i_ref_type == 0x02 || i_ref_type == 0x03))
return;
p_desc_n[7] = i_component_tag;
}
static inline uint8_t *desc6e_get_announcement(uint8_t *p_desc, uint8_t n)
{
uint8_t *p_desc_n = p_desc + DESC6E_HEADER_SIZE;
int i_loop_len = desc_get_length(p_desc) - (DESC6E_HEADER_SIZE - DESC_HEADER_SIZE);
if (i_loop_len <= 0)
return NULL;
while (n) {
uint8_t i_desc6e_data_size = DESC6E_DATA_SIZE;
uint8_t i_ref_type = desc6en_get_reference_type(p_desc_n);
if (i_ref_type == 0x01 || i_ref_type == 0x02 || i_ref_type == 0x03)
i_desc6e_data_size += DESC6E_EXT_DATA_SIZE;
p_desc_n += i_desc6e_data_size;
i_loop_len -= i_desc6e_data_size;
if (i_loop_len <= 0)
return NULL;
n--;
}
return p_desc_n;
}
static inline bool desc6e_validate(const uint8_t *p_desc)
{
const uint8_t *p_desc_n = p_desc + DESC6E_HEADER_SIZE;
int i_desc_size = desc_get_length(p_desc);
while (i_desc_size > (DESC6E_HEADER_SIZE - DESC_HEADER_SIZE)) {
uint8_t i_desc6e_data_size = DESC6E_DATA_SIZE;
uint8_t i_ref_type = desc6en_get_reference_type(p_desc_n);
if (i_ref_type == 0x01 || i_ref_type == 0x02 || i_ref_type == 0x03)
i_desc6e_data_size += DESC6E_EXT_DATA_SIZE;
i_desc_size -= i_desc6e_data_size;
p_desc_n += i_desc6e_data_size;
}
return i_desc_size == (DESC6E_HEADER_SIZE - DESC_HEADER_SIZE);
}
static inline void desc6e_print(uint8_t *p_desc, f_print pf_print,
void *opaque, print_type_t i_print_type)
{
uint8_t n = 0;
uint8_t *p_desc_n;
switch (i_print_type) {
case PRINT_XML:
pf_print(opaque,
"<ANNOUNCEMENT_SUPPORT_DESC announcement_support_indicator=\"0x%04x\""
" emergency_alarm_flag=\"%u\""
" road_traffic_flash_flag=\"%u\""
" public_transport_flash_flag=\"%u\""
" warning_message_flag=\"%u\""
" news_flash_flag=\"%u\""
" weather_flash_flag=\"%u\""
" event_announcement_flag=\"%u\""
" personal_call_flag=\"%u\">",
desc6e_get_announcement_support_indicator(p_desc),
desc6e_get_emergency_alarm_flag(p_desc),
desc6e_get_road_traffic_flash_flag(p_desc),
desc6e_get_public_transport_flash_flag(p_desc),
desc6e_get_warning_message_flag(p_desc),
desc6e_get_news_flash_flag(p_desc),
desc6e_get_weather_flash_flag(p_desc),
desc6e_get_event_announcement_flag(p_desc),
desc6e_get_personal_call_flag(p_desc)
);
break;
default:
pf_print(opaque,
" - desc 6e announcement_support announcement_support_indicator=0x%04x"
" emergency_alarm_flag=%u"
" road_traffic_flash_flag=%u"
" public_transport_flash_flag=%u"
" warning_message_flag=%u"
" news_flash_flag=%u"
" weather_flash_flag=%u"
" event_announcement_flag=%u"
" personal_call_flag=%u",
desc6e_get_announcement_support_indicator(p_desc),
desc6e_get_emergency_alarm_flag(p_desc),
desc6e_get_road_traffic_flash_flag(p_desc),
desc6e_get_public_transport_flash_flag(p_desc),
desc6e_get_warning_message_flag(p_desc),
desc6e_get_news_flash_flag(p_desc),
desc6e_get_weather_flash_flag(p_desc),
desc6e_get_event_announcement_flag(p_desc),
desc6e_get_personal_call_flag(p_desc)
);
}
while ((p_desc_n = desc6e_get_announcement(p_desc, n++)) != NULL) {
uint8_t i_announcement_type = desc6en_get_announcement_type(p_desc_n);
uint8_t i_reference_type = desc6en_get_reference_type(p_desc_n);
bool b_extra_data = (i_reference_type == 0x01 || i_reference_type == 0x02 || i_reference_type == 0x03);
switch (i_print_type) {
case PRINT_XML:
if (!b_extra_data)
pf_print(opaque,
"<ANNOUNCEMENT type=\"%u\" type_txt=\"%s\" reference_type=\"%u\"/>",
i_announcement_type,
desc6e_get_announcement_type_txt(i_announcement_type),
i_reference_type
);
else
pf_print(opaque,
"<ANNOUNCEMENT type=\"%u\" type_txt=\"%s\" reference_type=\"%u\""
" onid=\"%u\" tsid=\"%u\" service_id=\"%u\" component_tag=\"%u\"/>",
i_announcement_type,
desc6e_get_announcement_type_txt(i_announcement_type),
i_reference_type,
desc6en_get_onid(p_desc_n),
desc6en_get_tsid(p_desc_n),
desc6en_get_service_id(p_desc_n),
desc6en_get_component_tag(p_desc_n)
);
break;
default:
if (!b_extra_data)
pf_print(opaque,
" - announcement type=%u type_txt=\"%s\" reference_type=%u",
i_announcement_type,
desc6e_get_announcement_type_txt(i_announcement_type),
i_reference_type
);
else
pf_print(opaque,
" - announcement type=%u type_txt=\"%s\" reference_type=%u"
" onid=%u tsid=%u service_id=%u component_tag=%u",
i_announcement_type,
desc6e_get_announcement_type_txt(i_announcement_type),
i_reference_type,
desc6en_get_onid(p_desc_n),
desc6en_get_tsid(p_desc_n),
desc6en_get_service_id(p_desc_n),
desc6en_get_component_tag(p_desc_n)
);
}
}
if (i_print_type == PRINT_XML)
pf_print(opaque, "</ANNOUNCEMENT_SUPPORT_DESC>");
}
#ifdef __cplusplus
}
#endif
#endif
......@@ -80,6 +80,7 @@
#include <bitstream/dvb/si/desc_6b.h>
#include <bitstream/dvb/si/desc_6c.h>
#include <bitstream/dvb/si/desc_6d.h>
#include <bitstream/dvb/si/desc_6e.h>
#include <bitstream/dvb/si/desc_7a.h>
#include <bitstream/dvb/si/desc_7b.h>
#include <bitstream/dvb/si/desc_7c.h>
......
......@@ -1599,7 +1599,69 @@ static void build_desc6d(uint8_t *desc) {
desc_set_length(desc, cell_n - desc - DESC_HEADER_SIZE);
}
/* --- Descriptor 0x6e: announcement_support_descriptor */
/* DVB Descriptor 0x6e: Announcement support descriptor */
static void build_desc6e(uint8_t *desc) {
desc6e_init(desc);
desc6e_set_emergency_alarm_flag (desc, true);
desc6e_set_road_traffic_flash_flag (desc, false);
desc6e_set_public_transport_flash_flag (desc, true);
desc6e_set_warning_message_flag (desc, true);
desc6e_set_news_flash_flag (desc, true);
desc6e_set_weather_flash_flag (desc, true);
desc6e_set_event_announcement_flag (desc, false);
desc6e_set_personal_call_flag (desc, false);
{
uint8_t n = 0;
uint8_t *ann_n;
desc_set_length(desc, 255);
ann_n = desc6e_get_announcement(desc, n++);
desc6en_set_announcement_type(ann_n, 0); // Emergency alarm
desc6en_set_reference_type(ann_n, 0);
ann_n = desc6e_get_announcement(desc, n++);
desc6en_set_announcement_type(ann_n, 3); // Warning alarm
desc6en_set_reference_type(ann_n, 1);
// The following are valid only if
// reference_type == 0x01
// || reference_type == 0x02
// || reference_type == 0x03
//
desc6en_set_onid(ann_n, 0x1122);
desc6en_set_tsid(ann_n, 0x3344);
desc6en_set_service_id(ann_n, 0x5566);
desc6en_set_component_tag(ann_n, 0x77);
ann_n = desc6e_get_announcement(desc, n++);
desc6en_set_announcement_type(ann_n, 5); // Weather flash
desc6en_set_reference_type(ann_n, 0);
ann_n = desc6e_get_announcement(desc, n++);
desc6en_set_announcement_type(ann_n, 2); // Public Transport flash
desc6en_set_reference_type(ann_n, 3);
// The following are valid only if
// reference_type == 0x01
// || reference_type == 0x02
// || reference_type == 0x03
//
desc6en_set_onid(ann_n, 0x6677);
desc6en_set_tsid(ann_n, 0x8899);
desc6en_set_service_id(ann_n, 0x4455);
desc6en_set_component_tag(ann_n, 0x88);
ann_n = desc6e_get_announcement(desc, n++);
desc6en_set_announcement_type(ann_n, 4); // News flash
desc6en_set_reference_type(ann_n, 0);
ann_n = desc6e_get_announcement(desc, n);
desc_set_length(desc, ann_n - desc - DESC_HEADER_SIZE);
}
}
/* --- Descriptor 0x6f: application_signalling_descriptor */
/* --- Descriptor 0x70: adaptation_field_data_descriptor */
/* --- Descriptor 0x71: service_identifier_descriptor */
......@@ -2206,6 +2268,9 @@ static void generate_sdt(void) {
desc = descs_get_desc(desc_loop, desc_counter++);
build_desc5f(desc);
desc = descs_get_desc(desc_loop, desc_counter++);
build_desc6e(desc);
// Finish descriptor generation
desc = descs_get_desc(desc_loop, desc_counter); // Get next descriptor pos
descs_set_length(desc_loop, desc - desc_loop - DESCS_HEADER_SIZE);
......
......@@ -122,6 +122,12 @@ new SDT actual tsid=10000 version=1 onid=40000
- desc 49 country_availability available=0 country=FRA
- desc 49 country_availability available=0 country=BUL
- desc 5f private_data specifier=0xaabbccdd
- desc 6e announcement_support announcement_support_indicator=0xff3d emergency_alarm_flag=1 road_traffic_flash_flag=0 public_transport_flash_flag=1 warning_message_flag=1 news_flash_flag=1 weather_flash_flag=1 event_announcement_flag=0 personal_call_flag=0
- announcement type=0 type_txt="Emergency alarm" reference_type=0
- announcement type=3 type_txt="Warning message" reference_type=1 onid=4386 tsid=13124 service_id=21862 component_tag=119
- announcement type=5 type_txt="Weather flash" reference_type=0
- announcement type=2 type_txt="Public Transport flash" reference_type=3 onid=26231 tsid=34969 service_id=17493 component_tag=136
- announcement type=4 type_txt="News flash" reference_type=0
* service sid=20200 eit_schedule eit_pf running=3
- desc 48 service type=0x1 provider="Test Provider Name" service="Test Service Name"
- desc 4c time_shifted_service reference_sid=21000
......
......@@ -207,6 +207,15 @@
<DESC id="0x5f" length="4" value="aabbccdd">
<PRIVATE_DATA_SPECIFIER_DESC specifier="0xaabbccdd" />
</DESC>
<DESC id="0x6e" length="21" value="ff3d083911223344556677582b6677889944558848">
<ANNOUNCEMENT_SUPPORT_DESC announcement_support_indicator="0xff3d" emergency_alarm_flag="1" road_traffic_flash_flag="0" public_transport_flash_flag="1" warning_message_flag="1" news_flash_flag="1" weather_flash_flag="1" event_announcement_flag="0" personal_call_flag="0">
<ANNOUNCEMENT type="0" type_txt="Emergency alarm" reference_type="0"/>
<ANNOUNCEMENT type="3" type_txt="Warning message" reference_type="1" onid="4386" tsid="13124" service_id="21862" component_tag="119"/>
<ANNOUNCEMENT type="5" type_txt="Weather flash" reference_type="0"/>
<ANNOUNCEMENT type="2" type_txt="Public Transport flash" reference_type="3" onid="26231" tsid="34969" service_id="17493" component_tag="136"/>
<ANNOUNCEMENT type="4" type_txt="News flash" reference_type="0"/>
</ANNOUNCEMENT_SUPPORT_DESC>
</DESC>
</SERVICE>
<SERVICE sid="20200" eit_schedule="1" eit_pf="1" running="3" free_CA="0">
<DESC id="0x48" length="38" value="0112546573742050726f7669646572204e616d6511546573742053657276696365204e616d65">
......
......@@ -179,6 +179,7 @@ static inline void descl_print(uint8_t *p_descl, uint16_t i_length,
CASE_DESC(6b)
CASE_DESC(6c)
CASE_DESC(6d)
CASE_DESC(6e)
CASE_DESC(7a)
CASE_DESC(7b)
CASE_DESC(7c)
......
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