Commit 9bcb806d authored by Georgi Chorbadzhiyski's avatar Georgi Chorbadzhiyski

mpeg/psi: Add support for descriptor 0x24 (Content labeling descriptor).

parent 627b462b
......@@ -88,6 +88,7 @@ Supported MPEG descriptors
* Descriptor 0x21: MuxCode descriptor
* Descriptor 0x22: FmxBufferSize descriptor
* Descriptor 0x23: MultiplexBuffer descriptor
* Descriptor 0x24: Content labeling descriptor
* Descriptor 0x27: Metadata STD descriptor
* Descriptor 0x28: AVC video descriptor
* Descriptor 0x2a: AVC timing and HRD descriptor
......
......@@ -2,7 +2,6 @@ TODO items for biTStream. The items are not ordered by importance
so if you like something just do it and send a patch.
- Add support (parser, generator, example) for these MPEG descriptors:
- Descriptor 0x24 content_labeling_descriptor
- Descriptor 0x25 metadata_pointer_descriptor
- Descriptor 0x26 metadata_descriptor
- Descriptor 0x29 IPMP_descriptor (defined in ISO/IEC 13818-11, MPEG-2 IPMP)
......
......@@ -397,6 +397,55 @@ static void build_desc23(uint8_t *desc) {
desc23_set_tb_leak_rate(desc, 445566);
}
/* MPEG Descriptor 0x24: Content labeling descriptor */
static void build_desc24_1(uint8_t *desc) {
desc24_init(desc);
desc24_set_metadata_application_format(desc, 0xabcd);
desc24_set_content_reference_id_record_flag(desc, false);
desc24_set_content_time_base_indicator(desc, 0);
desc24_set_length(desc);
}
static void build_desc24_2(uint8_t *desc) {
desc24_init(desc);
desc24_set_metadata_application_format(desc, 0xfff0);
desc24_set_content_reference_id_record_flag(desc, false);
desc24_set_content_time_base_indicator(desc, 3);
desc24_set_time_base_association(desc, 3, (uint8_t *)"ABC");
desc24_set_length(desc);
}
static void build_desc24_3(uint8_t *desc) {
desc24_init(desc);
desc24_set_metadata_application_format(desc, 0xffff);
// Needs desc24_set_metadata_application_format(desc, 0xffff);
desc24_set_metadata_application_format_identifier(desc, 0xaabbccdd);
desc24_set_content_reference_id_record_flag(desc, true);
// Needs desc24_set_content_reference_id_record_flag(desc, true);
desc24_set_content_reference_id_record(desc, 3, (uint8_t *)"abc");
desc24_set_content_time_base_indicator(desc, 2);
// Needs desc24_set_content_time_base_indicator(desc, 1..2);
desc24_set_content_time_base_value (desc, 0x1F0F0F0F0); // 8337289456
desc24_set_metadata_time_base_value(desc, 0x1F1F1F1F1); // 8354132465
// Needs desc24_set_content_time_base_indicator(desc, 2);
desc24_set_content_id(desc, 100);
// Needs desc24_set_content_time_base_indicator(desc, 3..7);
desc24_set_time_base_association(desc, 3, (uint8_t *)"ABC");
desc24_set_length(desc);
}
/* MPEG Descriptor 0x27: Metadata STD descriptor */
static void build_desc27(uint8_t *desc) {
desc27_init(desc);
......@@ -2567,6 +2616,15 @@ static void generate_pmt(void) {
desc_loop = pmtn_get_descs(pmt_n);
descs_set_length(desc_loop, DESCS_MAX_SIZE); // This is needed so descs_get_desc(x, n) works
desc = descs_get_desc(desc_loop, desc_counter++);
build_desc24_1(desc);
desc = descs_get_desc(desc_loop, desc_counter++);
build_desc24_2(desc);
desc = descs_get_desc(desc_loop, desc_counter++);
build_desc24_3(desc);
desc = descs_get_desc(desc_loop, desc_counter++);
build_desc28(desc);
......
......@@ -299,6 +299,9 @@ new PMT program=20000 version=1 pcrpid=110
- desc 27 metadata_std input_leak_rate=12345 buffer_size=23456 output_leak_rate=34567
- desc 2c flexmux_timing fcr_es_id=0x1234 fcr_resolution=123456789 fcr_length=55 fmx_rate_length=66
* ES pid=126 streamtype=0x1b streamtype_txt="H.264/14496-10 video (MPEG-4/AVC)"
- desc 24 content_labeling metadata_application_format=0xabcd metadata_application_format_identifier=0x00000000 content_reference_id_record_flag=0 content_reference_id_record_length=0 content_reference_id_record="" content_time_base_indicator=0 content_time_base_value="0" metadata_time_base_value="0" content_id=0 time_base_association_data_length=0 time_base_association_data=""
- desc 24 content_labeling metadata_application_format=0xfff0 metadata_application_format_identifier=0x00000000 content_reference_id_record_flag=0 content_reference_id_record_length=0 content_reference_id_record="" content_time_base_indicator=3 content_time_base_value="0" metadata_time_base_value="0" content_id=0 time_base_association_data_length=3 time_base_association_data="414243"
- desc 24 content_labeling metadata_application_format=0xffff metadata_application_format_identifier=0xaabbccdd content_reference_id_record_flag=1 content_reference_id_record_length=3 content_reference_id_record="616263" content_time_base_indicator=2 content_time_base_value="8337289456" metadata_time_base_value="8354132465" content_id=100 time_base_association_data_length=0 time_base_association_data=""
- desc 28 avc_video profile_idc=0x12 constraint_set0_flag=1 constraint_set1_flag=1 constraint_set2_flag=0 AVC_compatible_flags=0x0a level_idc=0x34 AVC_still_present=0 AVC_24_hour_picture_flag=0
- desc 2a avc_timing_and_hrd hrd_management_valid_flag=0 picture_and_timing_info_present=1 flag_90khz=0 N=12345678 K=34567890 num_units_in_tick=456789 fixed_frame_rate_flag=1 temporal_poc_flag=0 picture_to_display_conversion_flag=1
* ES pid=127 streamtype=0x0f streamtype_txt="13818-7 Audio with ADTS transport syntax"
......
......@@ -535,6 +535,15 @@
</DESC>
</ES>
<ES pid="126" streamtype="0x1b" streamtype_txt="H.264/14496-10 video (MPEG-4/AVC)">
<DESC id="0x24" length="3" value="abcd07">
<CONTENT_LABELING_DESC metadata_application_format="0xabcd" metadata_application_format_identifier="0x00000000" content_reference_id_record_flag="0" content_reference_id_record_length="0" content_reference_id_record="" content_time_base_indicator="0" content_time_base_value="0" metadata_time_base_value="0" content_id="0" time_base_association_data_length="0" time_base_association_data=""/>
</DESC>
<DESC id="0x24" length="7" value="fff01f03414243">
<CONTENT_LABELING_DESC metadata_application_format="0xfff0" metadata_application_format_identifier="0x00000000" content_reference_id_record_flag="0" content_reference_id_record_length="0" content_reference_id_record="" content_time_base_indicator="3" content_time_base_value="0" metadata_time_base_value="0" content_id="0" time_base_association_data_length="3" time_base_association_data="414243"/>
</DESC>
<DESC id="0x24" length="22" value="ffffaabbccdd9703616263fff0f0f0f0fff1f1f1f1e4">
<CONTENT_LABELING_DESC metadata_application_format="0xffff" metadata_application_format_identifier="0xaabbccdd" content_reference_id_record_flag="1" content_reference_id_record_length="3" content_reference_id_record="616263" content_time_base_indicator="2" content_time_base_value="8337289456" metadata_time_base_value="8354132465" content_id="100" time_base_association_data_length="0" time_base_association_data=""/>
</DESC>
<DESC id="0x28" length="4" value="12ca343f">
<AVC_VIDEO_DESC profile_idc="0x12" constraint_set0_flag="1" constraint_set1_flag="1" constraint_set2_flag="0" AVC_compatible_flags="0x0a" level_idc="0x34" AVC_still_present="0" AVC_24_hour_picture_flag="0"/>
</DESC>
......
/*****************************************************************************
* desc_24.h: ISO/IEC 13818-1 Descriptor 0x24 (Content labeling 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:
* - ISO/IEC 13818-1:2007(E) (MPEG-2 Systems)
*/
#ifndef __BITSTREAM_MPEG_DESC_24_H__
#define __BITSTREAM_MPEG_DESC_24_H__
#include <inttypes.h> /* PRIu64 */
#include <bitstream/common.h>
#include <bitstream/mpeg/psi/descriptors.h>
#ifdef __cplusplus
extern "C"
{
#endif
/*****************************************************************************
* Descriptor 0x24 (Content labeling descriptor)
*****************************************************************************/
#define DESC24_HEADER_SIZE (DESC_HEADER_SIZE + 3)
static inline void desc24_init(uint8_t *p_desc)
{
desc_set_tag(p_desc, 0x24);
}
static inline uint16_t desc24_get_metadata_application_format(const uint8_t *p_desc)
{
return (p_desc[2] << 8) | p_desc[3];
}
static inline void desc24_set_metadata_application_format(uint8_t *p_desc, uint16_t i_format)
{
p_desc[2] = (i_format >> 8) & 0xff;
p_desc[3] = i_format & 0xff;
}
static inline uint32_t desc24_get_metadata_application_format_identifier(const uint8_t *p_desc)
{
if (desc24_get_metadata_application_format(p_desc) == 0xffff)
return (p_desc[4] << 24) | (p_desc[5] << 16) | (p_desc[6] << 8) | p_desc[7];
else
return 0;
}
static inline void desc24_set_metadata_application_format_identifier(uint8_t *p_desc, uint32_t i_identifier)
{
if (desc24_get_metadata_application_format(p_desc) != 0xffff)
return;
p_desc[4] = (i_identifier >> 24) & 0xff;
p_desc[5] = (i_identifier >> 16) & 0xff;
p_desc[6] = (i_identifier >> 8) & 0xff;
p_desc[7] = i_identifier & 0xff;
}
#define __ofs1 \
(4 + (desc24_get_metadata_application_format(p_desc) == 0xffff ? 4 : 0))
static inline bool desc24_get_content_reference_id_record_flag(const uint8_t *p_desc)
{
return (p_desc[__ofs1] & 0x80) == 0x80;
}
static inline void desc24_set_content_reference_id_record_flag(uint8_t *p_desc, bool b_flag)
{
uint8_t ofs = __ofs1;
p_desc[ofs] = (b_flag ? (p_desc[ofs] | 0x80) : (p_desc[ofs] &~ 0x80)) | 0x07;
}
static inline uint8_t desc24_get_content_time_base_indicator(const uint8_t *p_desc)
{
return (p_desc[__ofs1] >> 3) & 0x0f;
}
static inline void desc24_set_content_time_base_indicator(uint8_t *p_desc, uint8_t i_indicator)
{
uint8_t ofs = __ofs1;
p_desc[ofs] = (p_desc[ofs] & 0x80) | ((i_indicator & 0x0f) << 3) | 0x07;
}
static inline uint8_t desc24_get_content_reference_id_length(const uint8_t *p_desc)
{
return desc24_get_content_reference_id_record_flag(p_desc) ? p_desc[__ofs1 + 1] : 0;
}
static inline const uint8_t *desc24_get_content_reference_id_data(const uint8_t *p_desc)
{
return desc24_get_content_reference_id_record_flag(p_desc) ? p_desc + __ofs1 + 2 : NULL;
}
static inline const uint8_t *desc24_get_content_reference_id(const uint8_t *p_desc, uint8_t *i_length)
{
*i_length = desc24_get_content_reference_id_length(p_desc);
return desc24_get_content_reference_id_data(p_desc);
}
static inline void desc24_set_content_reference_id_record(uint8_t *p_desc, uint8_t i_length, uint8_t *p_data)
{
if (desc24_get_content_reference_id_record_flag(p_desc)) {
uint8_t ofs = __ofs1;
p_desc[ofs + 1] = i_length;
memcpy(p_desc + ofs + 2, p_data, i_length);
}
}
#define __ofs2 \
(__ofs1 + 1 + \
(desc24_get_content_reference_id_record_flag(p_desc) \
? 1 + desc24_get_content_reference_id_length(p_desc) \
: 0 \
) \
)
static inline uint64_t desc24_get_content_time_base_value(const uint8_t *p_desc)
{
uint8_t i_indicator = desc24_get_content_time_base_indicator(p_desc);
if (i_indicator == 1 || i_indicator == 2) {
uint8_t ofs = __ofs2;
return (uint64_t)(
(((uint64_t)p_desc[ofs] & 0x01ull) << 32) |
((uint64_t)p_desc[ofs + 1] << 24) |
((uint64_t)p_desc[ofs + 2] << 16) |
((uint64_t)p_desc[ofs + 3] << 8) |
(uint64_t)p_desc[ofs + 4]
);
} else {
return 0;
}
}
static inline void desc24_set_content_time_base_value(uint8_t *p_desc, uint64_t i_value)
{
uint8_t i_indicator = desc24_get_content_time_base_indicator(p_desc);
if (i_indicator == 1 || i_indicator == 2) {
uint8_t ofs = __ofs2;
p_desc[ofs + 0] = 0xfe | ((i_value >> 32) & 0x01);
p_desc[ofs + 1] = (i_value >> 24) & 0xff;
p_desc[ofs + 2] = (i_value >> 16) & 0xff;
p_desc[ofs + 3] = (i_value >> 8) & 0xff;
p_desc[ofs + 4] = i_value & 0xff;
}
}
static inline uint64_t desc24_get_metadata_time_base_value(const uint8_t *p_desc)
{
uint8_t i_indicator = desc24_get_content_time_base_indicator(p_desc);
if (i_indicator == 1 || i_indicator == 2) {
uint8_t ofs = __ofs2 + 5;
return (uint64_t)(
(((uint64_t)p_desc[ofs] & 0x01ull) << 32) |
((uint64_t)p_desc[ofs + 1] << 24) |
((uint64_t)p_desc[ofs + 2] << 16) |
((uint64_t)p_desc[ofs + 3] << 8) |
(uint64_t)p_desc[ofs + 4]
);
} else {
return 0;
}
}
static inline void desc24_set_metadata_time_base_value(uint8_t *p_desc, uint64_t i_value)
{
uint8_t i_indicator = desc24_get_content_time_base_indicator(p_desc);
if (i_indicator == 1 || i_indicator == 2) {
uint8_t ofs = __ofs2 + 5;
p_desc[ofs + 0] = 0xfe | ((i_value >> 32) & 0x01);
p_desc[ofs + 1] = (i_value >> 24) & 0xff;
p_desc[ofs + 2] = (i_value >> 16) & 0xff;
p_desc[ofs + 3] = (i_value >> 8) & 0xff;
p_desc[ofs + 4] = i_value & 0xff;
}
}
static inline uint8_t desc24_get_content_id(const uint8_t *p_desc)
{
uint8_t i_indicator = desc24_get_content_time_base_indicator(p_desc);
if (i_indicator == 2) {
uint8_t ofs = __ofs2 + 10;
return p_desc[ofs] & 0x7f;
} else {
return 0;
}
}
static inline void desc24_set_content_id(uint8_t *p_desc, uint8_t i_content_id)
{
uint8_t i_indicator = desc24_get_content_time_base_indicator(p_desc);
if (i_indicator == 2) {
uint8_t ofs = __ofs2 + 10;
p_desc[ofs + 0] = 0x80 | i_content_id;
}
}
static inline uint8_t desc24_get_time_base_association_data_length(const uint8_t *p_desc)
{
uint8_t i_indicator = desc24_get_content_time_base_indicator(p_desc);
return (i_indicator >= 3 && i_indicator <= 7) ? p_desc[__ofs2] : 0;
}
static inline const uint8_t *desc24_get_time_base_association_data(const uint8_t *p_desc)
{
uint8_t i_indicator = desc24_get_content_time_base_indicator(p_desc);
return (i_indicator >= 3 && i_indicator <= 7) ? p_desc + 1 + __ofs2 : NULL;
}
static inline const uint8_t *desc24_get_time_base_association(const uint8_t *p_desc, uint8_t *i_length)
{
*i_length = desc24_get_time_base_association_data_length(p_desc);
return desc24_get_time_base_association_data(p_desc);
}
static inline void desc24_set_time_base_association(uint8_t *p_desc, uint8_t i_length, uint8_t *p_data)
{
uint8_t i_indicator = desc24_get_content_time_base_indicator(p_desc);
if (i_indicator >= 3 && i_indicator <= 7) {
uint8_t ofs = __ofs2;
p_desc[ofs] = i_length;
memcpy(p_desc + ofs + 1, p_data, i_length);
}
}
#undef __ofs1
#undef __ofs2
static inline int desc24_calc_length(const uint8_t *p_desc)
{
int i_length = DESC24_HEADER_SIZE - DESC_HEADER_SIZE;
uint8_t i_indicator = desc24_get_content_time_base_indicator(p_desc);
if (desc24_get_metadata_application_format(p_desc) == 0xffff)
i_length += 4;
if (desc24_get_content_reference_id_record_flag(p_desc))
i_length += 1 + desc24_get_content_reference_id_length(p_desc);
if (i_indicator == 1 || i_indicator == 2)
i_length += 10;
if (i_indicator == 2)
i_length += 1;
if (i_indicator >= 3 && i_indicator <= 7)
i_length += 1 + desc24_get_time_base_association_data_length(p_desc);
return i_length;
}
static inline bool desc24_validate(const uint8_t *p_desc)
{
return desc24_calc_length(p_desc) <= desc_get_length(p_desc);
}
static inline void desc24_set_length(uint8_t *p_desc)
{
desc_set_length(p_desc, desc24_calc_length(p_desc));
}
static inline void desc24_print(const uint8_t *p_desc, f_print pf_print,
void *opaque, print_type_t i_print_type)
{
uint8_t i;
uint8_t i_content_reference_id_length;
uint8_t i_time_base_association_data_length;
const uint8_t *p_content_reference_id = desc24_get_content_reference_id(p_desc, &i_content_reference_id_length);
const uint8_t *p_time_base_association_data = desc24_get_time_base_association(p_desc, &i_time_base_association_data_length);
char psz_content[2 * 255 + 1];
char psz_time_base[2 * 255 + 1];
for (i = 0; i < i_content_reference_id_length; i++)
sprintf(psz_content + 2 * i, "%02x", p_content_reference_id[i]);
psz_content[2 * i] = '\0';
for (i = 0; i < i_time_base_association_data_length; i++)
sprintf(psz_time_base + 2 * i, "%02x", p_time_base_association_data[i]);
psz_time_base[2 * i] = '\0';
switch (i_print_type) {
case PRINT_XML:
pf_print(opaque,
"<CONTENT_LABELING_DESC metadata_application_format=\"0x%04x\""
" metadata_application_format_identifier=\"0x%08x\""
" content_reference_id_record_flag=\"%u\""
" content_reference_id_record_length=\"%u\""
" content_reference_id_record=\"%s\""
" content_time_base_indicator=\"%u\""
" content_time_base_value=\"%"PRIu64"\""
" metadata_time_base_value=\"%"PRIu64"\""
" content_id=\"%u\""
" time_base_association_data_length=\"%u\""
" time_base_association_data=\"%s\"/>",
desc24_get_metadata_application_format(p_desc),
desc24_get_metadata_application_format_identifier(p_desc),
desc24_get_content_reference_id_record_flag(p_desc),
desc24_get_content_reference_id_length(p_desc),
psz_content, // desc24_get_content_reference_id_data(p_desc)
desc24_get_content_time_base_indicator(p_desc),
desc24_get_content_time_base_value(p_desc),
desc24_get_metadata_time_base_value(p_desc),
desc24_get_content_id(p_desc),
desc24_get_time_base_association_data_length(p_desc),
psz_time_base // desc24_get_time_base_association_data(p_desc)
);
break;
default:
pf_print(opaque,
" - desc 24 content_labeling metadata_application_format=0x%04x"
" metadata_application_format_identifier=0x%08x"
" content_reference_id_record_flag=%u"
" content_reference_id_record_length=%u"
" content_reference_id_record=\"%s\""
" content_time_base_indicator=%u"
" content_time_base_value=\"%"PRIu64"\""
" metadata_time_base_value=\"%"PRIu64"\""
" content_id=%u"
" time_base_association_data_length=%u"
" time_base_association_data=\"%s\"",
desc24_get_metadata_application_format(p_desc),
desc24_get_metadata_application_format_identifier(p_desc),
desc24_get_content_reference_id_record_flag(p_desc),
desc24_get_content_reference_id_length(p_desc),
psz_content, // desc24_get_content_reference_id_data(p_desc)
desc24_get_content_time_base_indicator(p_desc),
desc24_get_content_time_base_value(p_desc),
desc24_get_metadata_time_base_value(p_desc),
desc24_get_content_id(p_desc),
desc24_get_time_base_association_data_length(p_desc),
psz_time_base // desc24_get_time_base_association_data(p_desc)
);
}
}
#ifdef __cplusplus
}
#endif
#endif
......@@ -60,6 +60,7 @@
#include <bitstream/mpeg/psi/desc_21.h>
#include <bitstream/mpeg/psi/desc_22.h>
#include <bitstream/mpeg/psi/desc_23.h>
#include <bitstream/mpeg/psi/desc_24.h>
#include <bitstream/mpeg/psi/desc_27.h>
#include <bitstream/mpeg/psi/desc_28.h>
#include <bitstream/mpeg/psi/desc_2a.h>
......
......@@ -126,6 +126,7 @@ static inline void descl_print(uint8_t *p_descl, uint16_t i_length,
CASE_DESC(21)
CASE_DESC(22)
CASE_DESC(23)
CASE_DESC(24)
CASE_DESC(27)
CASE_DESC(28)
CASE_DESC(2a)
......
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