1 /* 2 * 3 * This library is free software; you can redistribute it and/or 4 * modify it under the terms of the GNU Library General Public 5 * License as published by the Free Software Foundation; either 6 * version 2 of the License, or (at your option) any later version. 7 * 8 * This library 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 GNU 11 * Library General Public License for more details. 12 * 13 * You should have received a copy of the GNU Library General Public 14 * License along with this library; if not, write to the 15 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, 16 * Boston, MA 02110-1301, USA. 17 * 18 * The Original Code is Fluendo MPEG Demuxer plugin. 19 * 20 * The Initial Developer of the Original Code is Fluendo, S.L. 21 * Portions created by Fluendo, S.L. are Copyright (C) 2005 22 * Fluendo, S.L. All Rights Reserved. 23 * 24 * Contributor(s): Wim Taymans <wim@fluendo.com> 25 */ 26 27 #ifndef __GST_MPEG_DEFS_H__ 28 #define __GST_MPEG_DEFS_H__ 29 #include <glib/gprintf.h> 30 31 #define SAFE_FOURCC_FORMAT "02x%02x%02x%02x (%c%c%c%c)" 32 #define SAFE_CHAR(a) (g_ascii_isalnum((gchar) (a)) ? ((gchar)(a)) : '.') 33 #define SAFE_FOURCC_ARGS(a) \ 34 ((guint8) ((a)>>24)), \ 35 ((guint8) ((a) >> 16 & 0xff)), \ 36 ((guint8) ((a) >> 8 & 0xff)), \ 37 ((guint8) ((a) & 0xff)), \ 38 SAFE_CHAR((a)>>24), \ 39 SAFE_CHAR((a) >> 16 & 0xff), \ 40 SAFE_CHAR((a) >> 8 & 0xff), \ 41 SAFE_CHAR(a & 0xff) 42 43 /* Stream type assignments */ 44 /* FIXME: Put these in mpegts lib separate stream type enums */ 45 /* Un-official Dirac extension */ 46 #define ST_VIDEO_DIRAC 0xd1 47 48 /* private stream types */ 49 #define ST_PS_AUDIO_AC4 0x06 50 #define ST_PS_VIDEO_MPEG2_DCII 0x80 51 #define ST_PS_AUDIO_AC3 0x81 52 #define ST_PS_AUDIO_EAC3 0x87 53 #define ST_PS_AUDIO_LPCM2 0x83 54 #define ST_PS_AUDIO_DTS 0x8a 55 #define ST_PS_AUDIO_LPCM 0x8b 56 #define ST_PS_DVD_SUBPICTURE 0xff 57 58 /* Blu-ray related (registration: 'HDMV'*/ 59 #define ST_BD_AUDIO_LPCM 0x80 60 #define ST_BD_AUDIO_AC3 0x81 61 #define ST_BD_AUDIO_DTS 0x82 62 #define ST_BD_AUDIO_AC3_TRUE_HD 0x83 63 #define ST_BD_AUDIO_AC3_PLUS 0x84 64 #define ST_BD_AUDIO_DTS_HD 0x85 65 #define ST_BD_AUDIO_DTS_HD_MASTER_AUDIO 0x86 66 #define ST_BD_AUDIO_EAC3 0x87 67 #define ST_BD_PGS_SUBPICTURE 0x90 68 #define ST_BD_IGS 0x91 69 #define ST_BD_SUBTITLE 0x92 70 #define ST_BD_SECONDARY_AC3_PLUS 0xa1 71 #define ST_BD_SECONDARY_DTS_HD 0xa2 72 73 /* defined for VC1 extension in RP227 */ 74 #define ST_PRIVATE_EA 0xea 75 76 /* Following only apply for streams identified as HDV, 77 * According to specification 61834-11 the PMT will use 78 * a registration descriptor with values TSMV or TSHV */ 79 /* HDV AUX stream mapping 80 * 0xA0 ISO/IEC 61834-11 81 * 0xA1 ISO/IEC 61834-11 82 */ 83 #define ST_HDV_AUX_A 0xa0 84 #define ST_HDV_AUX_V 0xa1 85 86 #define CLOCK_BASE 9LL 87 #define CLOCK_FREQ (CLOCK_BASE * 10000) 88 89 /* Numerical values for second/millisecond in PCR units */ 90 #define PCR_SECOND 27000000 91 #define PCR_MSECOND 27000 92 93 /* PCR_TO_GST calculation requires at least 10 extra bits. 94 * Since maximum PCR value is coded with 42 bits, we are 95 * safe to use direct calculation (10+42 < 63)*/ 96 #define PCRTIME_TO_GSTTIME(t) (((t) * (guint64)1000) / 27) 97 98 /* MPEG_TO_GST calculation requires at least 17 extra bits (100000) 99 * Since maximum PTS/DTS value is coded with 33bits, we are 100 * safe to use direct calculation (17+33 < 63) */ 101 #define MPEGTIME_TO_GSTTIME(t) ((t) * (guint64)100000 / 9) 102 103 #define GSTTIME_TO_MPEGTIME(time) (gst_util_uint64_scale ((time), \ 104 CLOCK_BASE, GST_MSECOND/10)) 105 #define GSTTIME_TO_PCRTIME(time) (gst_util_uint64_scale ((time), \ 106 300 * CLOCK_BASE, GST_MSECOND/10)) 107 108 #define MPEG_MUX_RATE_MULT 50 109 110 /* sync:4 == 00xx ! pts:3 ! 1 ! pts:15 ! 1 | pts:15 ! 1 */ 111 #define READ_TS(data, target, lost_sync_label) \ 112 if ((*data & 0x01) != 0x01) goto lost_sync_label; \ 113 target = ((guint64) (*data++ & 0x0E)) << 29; \ 114 target |= ((guint64) (*data++ )) << 22; \ 115 if ((*data & 0x01) != 0x01) goto lost_sync_label; \ 116 target |= ((guint64) (*data++ & 0xFE)) << 14; \ 117 target |= ((guint64) (*data++ )) << 7; \ 118 if ((*data & 0x01) != 0x01) goto lost_sync_label; \ 119 target |= ((guint64) (*data++ & 0xFE)) >> 1; 120 121 #endif /* __GST_MPEG_DEFS_H__ */ 122