diff --git a/dvb/si/eit.h b/dvb/si/eit.h index c4ddeea..b7f4253 100644 --- a/dvb/si/eit.h +++ b/dvb/si/eit.h @@ -4,6 +4,7 @@ * Copyright (C) 2009-2010 VideoLAN * * Authors: Christophe Massiot + * Georgi Chorbadzhiyski * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the @@ -82,11 +83,129 @@ static inline uint16_t eit_get_tsid(const uint8_t *p_eit) return (p_eit[8] << 8) | p_eit[9]; } +static inline void eit_set_onid(uint8_t *p_eit, uint16_t i_onid) +{ + p_eit[10] = i_onid >> 8; + p_eit[11] = i_onid & 0xff; +} + +static inline uint16_t eit_get_onid(const uint8_t *p_eit) +{ + return (p_eit[10] << 8) | p_eit[11]; +} + +static inline void eit_set_segment_last_sec_number(uint8_t *p_eit, uint8_t i_segment_last_sec_number) +{ + p_eit[12] = i_segment_last_sec_number; +} + +static inline uint8_t eit_get_segment_last_sec_number(const uint8_t *p_eit) +{ + return p_eit[12]; +} + +static inline void eit_set_last_table_id(uint8_t *p_eit, uint8_t i_last_table_id) +{ + p_eit[13] = i_last_table_id; +} + +static inline uint8_t eit_get_last_table_id(const uint8_t *p_eit) +{ + return p_eit[13]; +} + +static inline uint16_t eitn_get_event_id(const uint8_t *p_eit_n) +{ + return (p_eit_n[0] << 8) | p_eit_n[1]; +} + +static inline void eitn_set_event_id(uint8_t *p_eit_n, uint16_t i_event_id) +{ + p_eit_n[0] = i_event_id >> 8; + p_eit_n[1] = i_event_id & 0xff; +} + +static inline uint64_t eitn_get_start_time(const uint8_t *p_eit_n) +{ + return (uint64_t)(((uint64_t)p_eit_n[2] << 32) | ((uint64_t)p_eit_n[3] << 24) | + ((uint64_t)p_eit_n[4] << 16) | ((uint64_t)p_eit_n[5] << 8) | p_eit_n[6]); +} + +static inline void eitn_set_start_time(uint8_t *p_eit_n, uint64_t i_start_time) +{ + p_eit_n[2] = (i_start_time >> 32) & 0xff; + p_eit_n[3] = (i_start_time >> 24) & 0xff; + p_eit_n[4] = (i_start_time >> 16) & 0xff; + p_eit_n[5] = (i_start_time >> 8) & 0xff; + p_eit_n[6] = i_start_time & 0xff; +} + +static inline uint32_t eitn_get_duration_bcd(const uint8_t *p_eit_n) +{ + return ((p_eit_n[7] << 16) | (p_eit_n[8] << 8)) | p_eit_n[9]; +} + +static inline void eitn_set_duration_bcd(uint8_t *p_eit_n, uint32_t i_duration_bcd) +{ + p_eit_n[7] = (i_duration_bcd >> 16) & 0xff; + p_eit_n[8] = (i_duration_bcd >> 8) & 0xff; + p_eit_n[9] = i_duration_bcd & 0xff; +} + +static inline uint8_t eitn_get_running_status(const uint8_t *p_eit_n) +{ + return p_eit_n[10] >> 5; +} + +static inline void eitn_set_running_status(uint8_t *p_eit_n, uint8_t i_running_status) +{ + p_eit_n[10] = (p_eit_n[10] & 0x1f) | (i_running_status << 5); +} + +static inline bool eitn_get_free_CA_mode(const uint8_t *p_eit_n) +{ + return (p_eit_n[10] & 0x10) == 0x10; +} + +static inline void eitn_set_free_CA_mode(uint8_t *p_eit_n, bool b_free_CA_mode) +{ + p_eit_n[10] = b_free_CA_mode ? (p_eit_n[10] | 0x10) : (p_eit_n[10] &~ 0x10); +} + static inline uint16_t eitn_get_desclength(const uint8_t *p_eit_n) { return ((p_eit_n[10] & 0xf) << 8) | p_eit_n[11]; } +static inline void eitn_set_desclength(uint8_t *p_eit_n, uint16_t i_length) +{ + p_eit_n[10] &= ~0xf; + p_eit_n[10] |= (i_length >> 8) & 0xf; + p_eit_n[11] = i_length & 0xff; +} + +static inline uint8_t *eitn_get_descs(uint8_t *p_eit_n) +{ + return &p_eit_n[10]; +} + +static inline uint8_t *eit_get_event(uint8_t *p_eit, uint8_t n) +{ + uint16_t i_section_size = psi_get_length(p_eit) + PSI_HEADER_SIZE + - PSI_CRC_SIZE; + uint8_t *p_eit_n = p_eit + EIT_HEADER_SIZE; + if (p_eit_n - p_eit > i_section_size) return NULL; + + while (n) { + if (p_eit_n + EIT_EVENT_SIZE - p_eit > i_section_size) return NULL; + p_eit_n += EIT_EVENT_SIZE + eitn_get_desclength(p_eit_n); + n--; + } + if (p_eit_n - p_eit >= i_section_size) return NULL; + + return p_eit_n; +} + static inline bool eit_validate_event(const uint8_t *p_eit, const uint8_t *p_eit_n, uint16_t i_desclength) @@ -130,8 +249,6 @@ static inline bool eit_validate(const uint8_t *p_eit) return (p_eit_n - p_eit == i_section_size); } -/* TODO: unfinished support */ - #ifdef __cplusplus } #endif diff --git a/dvb/si/eit_print.h b/dvb/si/eit_print.h new file mode 100644 index 0000000..5adedf8 --- /dev/null +++ b/dvb/si/eit_print.h @@ -0,0 +1,151 @@ +/***************************************************************************** + * eit_print.h: ETSI EN 300 468 Event Information Table (EIT) (printing) + ***************************************************************************** + * Copyright (C) 2011 Unix Solutions Ltd. + * + * Authors: Georgi Chorbadzhiyski + * + * 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. + *****************************************************************************/ + +#ifndef __BITSTREAM_DVB_EIT_PRINT_H__ +#define __BITSTREAM_DVB_EIT_PRINT_H__ + +#include +#include +#include +#include +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + +/***************************************************************************** + * Event Information Table + *****************************************************************************/ +static inline void eit_print(uint8_t *p_eit, + f_print pf_print, void *print_opaque, + f_iconv pf_iconv, void *iconv_opaque, + print_type_t i_print_type) +{ + uint8_t *p_event; + uint8_t j = 0; + uint8_t i_tid = psi_get_tableid(p_eit); + char *psz_tid = "unknown"; + + if (i_tid == EIT_TABLE_ID_PF_ACTUAL) + psz_tid = "actual_pf"; + else if (i_tid == EIT_TABLE_ID_PF_OTHER) + psz_tid = "other_pf"; + else if (i_tid >= EIT_TABLE_ID_SCHED_ACTUAL_FIRST && i_tid <= EIT_TABLE_ID_SCHED_ACTUAL_LAST) + psz_tid = "actual_schedule"; + else if (i_tid >= EIT_TABLE_ID_SCHED_OTHER_FIRST && i_tid <= EIT_TABLE_ID_SCHED_OTHER_LAST) + psz_tid = "other_schedule"; + + switch (i_print_type) { + case PRINT_XML: + pf_print(print_opaque, + "", + i_tid, psz_tid, + psi_get_version(p_eit), + !psi_get_current(p_eit) ? 0 : 1, + eit_get_tsid(p_eit), + eit_get_onid(p_eit), + eit_get_segment_last_sec_number(p_eit), + eit_get_last_table_id(p_eit) + ); + break; + default: + pf_print(print_opaque, + "new EIT tableid=0x%02x type=%s version=%u%s tsid=%u" + " onid=%u seg_last_sec_number=%u last_table_id=0x%02x", + i_tid, psz_tid, + psi_get_version(p_eit), + !psi_get_current(p_eit) ? " (next)" : "", + eit_get_tsid(p_eit), + eit_get_onid(p_eit), + eit_get_segment_last_sec_number(p_eit), + eit_get_last_table_id(p_eit) + ); + } + + while ((p_event = eit_get_event(p_eit, j)) != NULL) { + j++; + char start_str[24], duration_str[10]; + int duration, hour, min, sec; + time_t start_ts; + + start_ts = dvb_time_format_UTC(eitn_get_start_time(p_event), NULL, start_str); + + dvb_time_decode_bcd(eitn_get_duration_bcd(p_event), &duration, &hour, &min, &sec); + sprintf(duration_str, "%02d:%02d:%02d", hour, min, sec); + + switch (i_print_type) { + case PRINT_XML: + pf_print(print_opaque, "", + eitn_get_event_id(p_event), + start_ts, start_str, + duration, duration_str, + eitn_get_running_status(p_event), + eitn_get_free_CA_mode(p_event) + ); + break; + default: + pf_print(print_opaque, " * EVENT id=%u start_time=%ld start_time_dec=\"%s\" duration=%u duration_dec=%s running_status=%d free_CA_mode=%d", + eitn_get_event_id(p_event), + start_ts, start_str, + duration, duration_str, + eitn_get_running_status(p_event), + eitn_get_free_CA_mode(p_event) + ); + } + + descs_print(eitn_get_descs(p_event), pf_print, print_opaque, + pf_iconv, iconv_opaque, i_print_type); + + switch (i_print_type) { + case PRINT_XML: + pf_print(print_opaque, ""); + break; + default: + break; + } + } + + switch (i_print_type) { + case PRINT_XML: + pf_print(print_opaque, ""); + break; + default: + pf_print(print_opaque, "end EIT"); + } +} + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/dvb/si_print.h b/dvb/si_print.h index 5ce3493..06a2f53 100644 --- a/dvb/si_print.h +++ b/dvb/si_print.h @@ -31,5 +31,6 @@ #include #include #include +#include #endif diff --git a/examples/dvb_print_si.c b/examples/dvb_print_si.c index c3c11bf..ccaefc8 100644 --- a/examples/dvb_print_si.c +++ b/examples/dvb_print_si.c @@ -542,6 +542,8 @@ static void handle_eit_section(uint16_t i_pid, uint8_t *p_eit) return; } + eit_print(p_eit, print_wrapper, NULL, iconv_wrapper, NULL, i_print_type); + free(p_eit); }