1 /*
2 * Copyright (c) 2013 - Mauro Carvalho Chehab <mchehab@kernel.org>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation version 2.1 of the License.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16 * Or, point your browser to http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
17 *
18 * Described on ARIB STD-B10 as TS information descriptor
19 */
20
21 #include <libdvbv5/desc_ts_info.h>
22 #include <libdvbv5/dvb-fe.h>
23 #include <parse_string.h>
24
25 #if __GNUC__ >= 9
26 #pragma GCC diagnostic ignored "-Waddress-of-packed-member"
27 #endif
28
dvb_desc_ts_info_init(struct dvb_v5_fe_parms * parms,const uint8_t * buf,struct dvb_desc * desc)29 int dvb_desc_ts_info_init(struct dvb_v5_fe_parms *parms,
30 const uint8_t *buf, struct dvb_desc *desc)
31 {
32 struct dvb_desc_ts_info *d = (void *)desc;
33 unsigned char *p = (unsigned char *)buf;
34 struct dvb_desc_ts_info_transmission_type *t;
35 size_t len;
36 int i;
37
38 len = sizeof(*d) - offsetof(struct dvb_desc_ts_info, bitfield);
39 memcpy(&d->bitfield, p, len);
40 p += len;
41
42 bswap16(d->bitfield);
43
44 len = d->length_of_ts_name;
45 d->ts_name = NULL;
46 d->ts_name_emph = NULL;
47 dvb_parse_string(parms, &d->ts_name, &d->ts_name_emph, p, len);
48 p += len;
49
50 memcpy(&d->transmission_type, p, sizeof(d->transmission_type));
51 p += sizeof(d->transmission_type);
52
53 t = &d->transmission_type;
54
55 d->service_id = malloc(sizeof(*d->service_id) * t->num_of_service);
56 if (!d->service_id) {
57 dvb_logerr("%s: out of memory", __func__);
58 return -1;
59 }
60
61 memcpy(d->service_id, p, sizeof(*d->service_id) * t->num_of_service);
62
63 for (i = 0; i < t->num_of_service; i++)
64 bswap16(d->service_id[i]);
65
66 p += sizeof(*d->service_id) * t->num_of_service;
67 return 0;
68 }
69
dvb_desc_ts_info_print(struct dvb_v5_fe_parms * parms,const struct dvb_desc * desc)70 void dvb_desc_ts_info_print(struct dvb_v5_fe_parms *parms, const struct dvb_desc *desc)
71 {
72 const struct dvb_desc_ts_info *d = (const void *) desc;
73 const struct dvb_desc_ts_info_transmission_type *t;
74 int i;
75
76 t = &d->transmission_type;
77
78 dvb_loginfo("| remote key ID %d", d->remote_control_key_id);
79 dvb_loginfo("| name %s", d->ts_name);
80 dvb_loginfo("| emphasis name %s", d->ts_name_emph);
81 dvb_loginfo("| transmission type %s", d->ts_name_emph);
82
83 for (i = 0; i < t->num_of_service; i++)
84 dvb_loginfo("| service ID[%d] %d", i, d->service_id[i]);
85 }
86
dvb_desc_ts_info_free(struct dvb_desc * desc)87 void dvb_desc_ts_info_free(struct dvb_desc *desc)
88 {
89 const struct dvb_desc_ts_info *d = (const void *) desc;
90
91 if (d->ts_name)
92 free(d->ts_name);
93 if (d->ts_name_emph)
94 free(d->ts_name_emph);
95
96 free(d->service_id);
97 }
98