1 /* 2 * section and descriptor parser 3 * 4 * Copyright (C) 2005 Kenneth Aafloy (kenneth@linuxtv.org) 5 * Copyright (C) 2005 Andrew de Quincey (adq_dvb@lidskialf.net) 6 * 7 * This library is free software; you can redistribute it and/or 8 * modify it under the terms of the GNU Lesser General Public 9 * License as published by the Free Software Foundation; either 10 * version 2.1 of the License, or (at your option) any later version. 11 * 12 * This library is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 * Lesser General Public License for more details. 16 * 17 * You should have received a copy of the GNU Lesser General Public 18 * License along with this library; if not, write to the Free Software 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 20 */ 21 22 #ifndef _UCSI_MPEG_CA_DESCRIPTOR 23 #define _UCSI_MPEG_CA_DESCRIPTOR 1 24 25 #ifdef __cplusplus 26 extern "C" 27 { 28 #endif 29 30 #include <libucsi/descriptor.h> 31 #include <libucsi/endianops.h> 32 33 /** 34 * mpeg_ca_descriptor structure 35 */ 36 struct mpeg_ca_descriptor { 37 struct descriptor d; 38 39 uint16_t ca_system_id; 40 EBIT2(uint16_t reserved : 3; , 41 uint16_t ca_pid : 13; ); 42 /* uint8_t data[] */ 43 } __ucsi_packed; 44 45 /** 46 * Process an mpeg_ca_descriptor. 47 * 48 * @param d Generic descriptor. 49 * @return Pointer to an mpeg_ca_descriptor, or NULL on error. 50 */ 51 static inline struct mpeg_ca_descriptor* mpeg_ca_descriptor_codec(struct descriptor * d)52 mpeg_ca_descriptor_codec(struct descriptor* d) 53 { 54 if (d->len < (sizeof(struct mpeg_ca_descriptor) - 2)) 55 return NULL; 56 57 bswap16((uint8_t*) d + 2); 58 bswap16((uint8_t*) d + 4); 59 60 return (struct mpeg_ca_descriptor*) d; 61 } 62 63 /** 64 * Accessor for pointer to data field of an mpeg_ca_descriptor. 65 * 66 * @param d The mpeg_ca_descriptor structure. 67 * @return Pointer to the field. 68 */ 69 static inline uint8_t * mpeg_ca_descriptor_data(struct mpeg_ca_descriptor * d)70 mpeg_ca_descriptor_data(struct mpeg_ca_descriptor *d) 71 { 72 return (uint8_t *) d + sizeof(struct mpeg_ca_descriptor); 73 } 74 75 /** 76 * Determine length of data field of an mpeg_ca_descriptor. 77 * 78 * @param d The mpeg_ca_descriptor structure. 79 * @return Length of the field in bytes. 80 */ 81 static inline int mpeg_ca_descriptor_data_length(struct mpeg_ca_descriptor * d)82 mpeg_ca_descriptor_data_length(struct mpeg_ca_descriptor *d) 83 { 84 return d->d.len - 4; 85 } 86 87 #ifdef __cplusplus 88 } 89 #endif 90 91 #endif 92