1 /*
2 * Copyright (c) 2013 - Andre Roth <neolynx@gmail.com>
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 */
19
20 #include <libdvbv5/mpeg_ts.h>
21 #include <libdvbv5/descriptors.h>
22 #include <libdvbv5/dvb-fe.h>
23
24 #if __GNUC__ >= 9
25 #pragma GCC diagnostic ignored "-Waddress-of-packed-member"
26 #endif
27
dvb_mpeg_ts_init(struct dvb_v5_fe_parms * parms,const uint8_t * buf,ssize_t buflen,uint8_t * table,ssize_t * table_length)28 ssize_t dvb_mpeg_ts_init(struct dvb_v5_fe_parms *parms, const uint8_t *buf, ssize_t buflen, uint8_t *table, ssize_t *table_length)
29 {
30 struct dvb_mpeg_ts *ts = (struct dvb_mpeg_ts *) table;
31 const uint8_t *p = buf;
32
33 if (buf[0] != DVB_MPEG_TS) {
34 dvb_logerr("mpeg ts invalid marker 0x%02x, should be 0x%02x", buf[0], DVB_MPEG_TS);
35 *table_length = 0;
36 return -1;
37 }
38
39 memcpy(table, p, sizeof(struct dvb_mpeg_ts));
40 p += sizeof(struct dvb_mpeg_ts);
41
42 bswap16(ts->bitfield);
43
44 if (ts->adaptation_field) {
45 memcpy(ts->adaption, p, sizeof(struct dvb_mpeg_ts_adaption));
46 p += ts->adaption->length + 1;
47 /* FIXME: copy adaption->lenght bytes */
48 }
49
50 *table_length = p - buf;
51 return p - buf;
52 }
53
dvb_mpeg_ts_free(struct dvb_mpeg_ts * ts)54 void dvb_mpeg_ts_free(struct dvb_mpeg_ts *ts)
55 {
56 free(ts);
57 }
58
dvb_mpeg_ts_print(struct dvb_v5_fe_parms * parms,struct dvb_mpeg_ts * ts)59 void dvb_mpeg_ts_print(struct dvb_v5_fe_parms *parms, struct dvb_mpeg_ts *ts)
60 {
61 dvb_loginfo("MPEG TS");
62 dvb_loginfo(" - sync 0x%02x", ts->sync_byte);
63 dvb_loginfo(" - tei %d", ts->tei);
64 dvb_loginfo(" - payload_start %d", ts->payload_start);
65 dvb_loginfo(" - priority %d", ts->priority);
66 dvb_loginfo(" - pid 0x%04x", ts->pid);
67 dvb_loginfo(" - scrambling %d", ts->scrambling);
68 dvb_loginfo(" - adaptation_field %d", ts->adaptation_field);
69 dvb_loginfo(" - continuity_counter %d", ts->continuity_counter);
70 if (ts->adaptation_field) {
71 dvb_loginfo(" Adaptation Field");
72 dvb_loginfo(" - length %d", ts->adaption->length);
73 dvb_loginfo(" - discontinued %d", ts->adaption->discontinued);
74 dvb_loginfo(" - random_access %d", ts->adaption->random_access);
75 dvb_loginfo(" - priority %d", ts->adaption->priority);
76 dvb_loginfo(" - PCR %d", ts->adaption->PCR);
77 dvb_loginfo(" - OPCR %d", ts->adaption->OPCR);
78 dvb_loginfo(" - splicing_point %d", ts->adaption->splicing_point);
79 dvb_loginfo(" - private_data %d", ts->adaption->private_data);
80 dvb_loginfo(" - extension %d", ts->adaption->extension);
81 }
82 }
83