1 /*
2  * mpegts.h -
3  * Copyright (C) 2013 Edward Hervey
4  *
5  * Authors:
6  *   Edward Hervey <edward@collabora.com>
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Library General Public
10  * License as published by the Free Software Foundation; either
11  * version 2 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * Library General Public License for more details.
17  *
18  * You should have received a copy of the GNU Library General Public
19  * License along with this library; if not, write to the
20  * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
21  * Boston, MA 02110-1301, USA.
22  */
23 
24 #ifndef _GST_MPEGTS_PRIVATE_H_
25 #define _GST_MPEGTS_PRIVATE_H_
26 
27 G_BEGIN_DECLS
28 
29 GST_DEBUG_CATEGORY_EXTERN (mpegts_debug);
30 #define GST_CAT_DEFAULT mpegts_debug
31 
32 G_GNUC_INTERNAL void __initialize_descriptors (void);
33 G_GNUC_INTERNAL guint32 _calc_crc32 (const guint8 *data, guint datalen);
34 G_GNUC_INTERNAL gchar *get_encoding_and_convert (const gchar *text, guint length);
35 G_GNUC_INTERNAL gchar *convert_lang_code (guint8 * data);
36 G_GNUC_INTERNAL guint8 *dvb_text_from_utf8 (const gchar * text, gsize *out_size);
37 G_GNUC_INTERNAL GstMpegtsDescriptor *_new_descriptor (guint8 tag, guint8 length);
38 G_GNUC_INTERNAL GstMpegtsDescriptor *_new_descriptor_with_extension (guint8 tag,
39     guint8 tag_extension, guint8 length);
40 G_GNUC_INTERNAL void _packetize_descriptor_array (GPtrArray * array,
41     guint8 ** out_data);
42 G_GNUC_INTERNAL GstMpegtsSection *_gst_mpegts_section_init (guint16 pid, guint8 table_id);
43 G_GNUC_INTERNAL void _packetize_common_section (GstMpegtsSection * section, gsize length);
44 
45 typedef gpointer (*GstMpegtsParseFunc) (GstMpegtsSection *section);
46 G_GNUC_INTERNAL gpointer __common_section_checks (GstMpegtsSection *section,
47 						  guint minsize,
48 						  GstMpegtsParseFunc parsefunc,
49 						  GDestroyNotify destroynotify);
50 
51 #define __common_desc_check_base(desc, tagtype, retval)			\
52   if (G_UNLIKELY ((desc)->data == NULL)) {				\
53     GST_WARNING ("Descriptor is empty (data field == NULL)");		\
54     return retval;							\
55   }									\
56   if (G_UNLIKELY ((desc)->tag != (tagtype))) {				\
57     GST_WARNING ("Wrong descriptor type (Got 0x%02x, expected 0x%02x)",	\
58 		 (desc)->tag, tagtype);					\
59     return retval;							\
60   }									\
61 
62 #define __common_desc_checks(desc, tagtype, minlen, retval)		\
63   __common_desc_check_base(desc, tagtype, retval);			\
64   if (G_UNLIKELY ((desc)->length < (minlen))) {				\
65     GST_WARNING ("Descriptor too small (Got %d, expected at least %d)",	\
66 		 (desc)->length, minlen);				\
67     return retval;							\
68   }
69 #define __common_desc_checks_exact(desc, tagtype, len, retval)		\
70   __common_desc_check_base(desc, tagtype, retval);			\
71   if (G_UNLIKELY ((desc)->length != (len))) {				\
72     GST_WARNING ("Wrong descriptor size (Got %d, expected %d)",		\
73 		 (desc)->length, len);					\
74     return retval;							\
75   }
76 
77 #define __common_desc_ext_check_base(desc, tagexttype, retval)          \
78   if (G_UNLIKELY ((desc)->data == NULL)) {                              \
79     GST_WARNING ("Descriptor is empty (data field == NULL)");           \
80     return retval;                                                      \
81   }                                                                     \
82   if (G_UNLIKELY ((desc)->tag != 0x7f) ||                               \
83     ((desc)->tag_extension != (tagexttype))) {                          \
84     GST_WARNING ("Wrong descriptor type (Got 0x%02x, expected 0x%02x)", \
85                  (desc)->tag_extension, tagexttype);                    \
86     return retval;                                                      \
87   }
88 #define __common_desc_ext_checks(desc, tagexttype, minlen, retval)      \
89   __common_desc_ext_check_base(desc, tagexttype, retval);                    \
90   if (G_UNLIKELY ((desc)->length < (minlen))) {                         \
91     GST_WARNING ("Descriptor too small (Got %d, expected at least %d)", \
92                  (desc)->length, minlen);                               \
93     return retval;                                                      \
94   }
95 #define __common_desc_ext_checks_exact(desc, tagexttype, len, retval)   \
96   __common_desc_ext_check_base(desc, tagexttype, retval);               \
97   if (G_UNLIKELY ((desc)->length != (len))) {                           \
98      GST_WARNING ("Wrong descriptor size (Got %d, expected %d)",        \
99                   (desc)->length, len);                                 \
100      return retval;                                                     \
101   }
102 
103 G_END_DECLS
104 
105 #endif	/* _GST_MPEGTS_PRIVATE_H_ */
106