Michael Sevakis | a222f27 | 2007-12-29 19:46:35 +0000 | [diff] [blame] | 1 | /*************************************************************************** |
| 2 | * __________ __ ___. |
| 3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ |
| 4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / |
| 5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < |
| 6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ |
| 7 | * \/ \/ \/ \/ \/ |
| 8 | * $Id$ |
| 9 | * |
| 10 | * Stream definitions for MPEG |
| 11 | * |
| 12 | * Copyright (c) 2007 Michael Sevakis |
| 13 | * |
Daniel Stenberg | 2acc0ac | 2008-06-28 18:10:04 +0000 | [diff] [blame^] | 14 | * This program is free software; you can redistribute it and/or |
| 15 | * modify it under the terms of the GNU General Public License |
| 16 | * as published by the Free Software Foundation; either version 2 |
| 17 | * of the License, or (at your option) any later version. |
Michael Sevakis | a222f27 | 2007-12-29 19:46:35 +0000 | [diff] [blame] | 18 | * |
| 19 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY |
| 20 | * KIND, either express or implied. |
| 21 | * |
| 22 | ****************************************************************************/ |
| 23 | #ifndef MPEG_STREAM_H |
| 24 | #define MPEG_STREAM_H |
| 25 | |
| 26 | /* Codes for various header byte sequences - MSB represents lowest memory |
| 27 | address */ |
| 28 | #define PACKET_START_CODE_PREFIX 0x00000100ul |
| 29 | #define END_CODE 0x000001b9ul |
| 30 | #define PACK_START_CODE 0x000001baul |
| 31 | #define SYSTEM_HEADER_START_CODE 0x000001bbul |
| 32 | |
| 33 | /* p = base pointer, b0 - b4 = byte offsets from p */ |
| 34 | /* We only care about the MS 32 bits of the 33 and so the ticks are 45kHz */ |
| 35 | #define TS_FROM_HEADER(p, b0) \ |
| 36 | ((uint32_t)((((p)[(b0)+0] & 0x0e) << 28) | \ |
| 37 | (((p)[(b0)+1] ) << 21) | \ |
| 38 | (((p)[(b0)+2] & 0xfe) << 13) | \ |
| 39 | (((p)[(b0)+3] ) << 6) | \ |
| 40 | (((p)[(b0)+4] ) >> 2))) |
| 41 | |
| 42 | #define TS_CHECK_MARKERS(p, b0) \ |
| 43 | (((((p)[(b0)+0] & 0x01) << 2) | \ |
| 44 | (((p)[(b0)+2] & 0x01) << 1) | \ |
| 45 | (((p)[(b0)+4] & 0x01) )) == 0x07) |
| 46 | |
| 47 | /* Get the SCR in our 45kHz ticks. Ignore the 9-bit extension */ |
| 48 | #define MPEG2_PACK_HEADER_SCR(p, b0) \ |
| 49 | ((uint32_t)((((p)[(b0)+0] & 0x38) << 26) | \ |
| 50 | (((p)[(b0)+0] & 0x03) << 27) | \ |
| 51 | (((p)[(b0)+1] ) << 19) | \ |
| 52 | (((p)[(b0)+2] & 0xf8) << 11) | \ |
| 53 | (((p)[(b0)+2] & 0x03) << 12) | \ |
| 54 | (((p)[(b0)+3] ) << 4) | \ |
| 55 | (((p)[(b0)+4] ) >> 4))) |
| 56 | |
| 57 | #define MPEG2_CHECK_PACK_SCR_MARKERS(ph, b0) \ |
| 58 | (((((ph)[(b0)+0] & 0x04) ) | \ |
| 59 | (((ph)[(b0)+2] & 0x04) >> 1) | \ |
| 60 | (((ph)[(b0)+4] & 0x04) >> 2)) == 0x07) |
| 61 | |
| 62 | #define INVALID_TIMESTAMP (~(uint32_t)0) |
| 63 | #define MAX_TIMESTAMP (INVALID_TIMESTAMP-1) |
| 64 | #define TS_SECOND (45000) /* Timestamp ticks per second */ |
| 65 | #define TC_SECOND (27000000) /* MPEG timecode ticks per second */ |
| 66 | |
| 67 | /* These values immediately follow the start code prefix '00 00 01' */ |
| 68 | |
| 69 | /* Video start codes */ |
| 70 | #define MPEG_START_PICTURE 0x00 |
| 71 | #define MPEG_START_SLICE_FIRST 0x01 |
| 72 | #define MPEG_START_SLICE_LAST 0xaf |
| 73 | #define MPEG_START_RESERVED_1 0xb0 |
| 74 | #define MPEG_START_RESERVED_2 0xb1 |
| 75 | #define MPEG_START_USER_DATA 0xb2 |
| 76 | #define MPEG_START_SEQUENCE_HEADER 0xb3 |
| 77 | #define MPEG_START_SEQUENCE_ERROR 0xb4 |
| 78 | #define MPEG_START_EXTENSION 0xb5 |
| 79 | #define MPEG_START_RESERVED_3 0xb6 |
| 80 | #define MPEG_START_SEQUENCE_END 0xb7 |
| 81 | #define MPEG_START_GOP 0xb8 |
| 82 | |
| 83 | /* Stream IDs */ |
| 84 | #define MPEG_STREAM_PROGRAM_END 0xb9 |
| 85 | #define MPEG_STREAM_PACK_HEADER 0xba |
| 86 | #define MPEG_STREAM_SYSTEM_HEADER 0xbb |
| 87 | #define MPEG_STREAM_PROGRAM_STREAM_MAP 0xbc |
| 88 | #define MPEG_STREAM_PRIVATE_1 0xbd |
| 89 | #define MPEG_STREAM_PADDING 0xbe |
| 90 | #define MPEG_STREAM_PRIVATE_2 0xbf |
| 91 | #define MPEG_STREAM_AUDIO_FIRST 0xc0 |
| 92 | #define MPEG_STREAM_AUDIO_LAST 0xcf |
| 93 | #define MPEG_STREAM_VIDEO_FIRST 0xe0 |
| 94 | #define MPEG_STREAM_VIDEO_LAST 0xef |
| 95 | #define MPEG_STREAM_ECM 0xf0 |
| 96 | #define MPEG_STREAM_EMM 0xf1 |
| 97 | /* ITU-T Rec. H.222.0 | ISO/IEC 13818-1 Annex A or |
| 98 | * ISO/IEC 13818-6_DSMCC_stream */ |
| 99 | #define MPEG_STREAM_MISC_1 0xf2 |
| 100 | /* ISO/IEC_13522_stream */ |
| 101 | #define MPEG_STREAM_MISC_2 0xf3 |
| 102 | /* ITU-T Rec. H.222.1 type A - E */ |
| 103 | #define MPEG_STREAM_MISC_3 0xf4 |
| 104 | #define MPEG_STREAM_MISC_4 0xf5 |
| 105 | #define MPEG_STREAM_MISC_5 0xf6 |
| 106 | #define MPEG_STREAM_MISC_6 0xf7 |
| 107 | #define MPEG_STREAM_MISC_7 0xf8 |
| 108 | #define MPEG_STREAM_ANCILLARY 0xf9 |
| 109 | #define MPEG_STREAM_RESERVED_FIRST 0xfa |
| 110 | #define MPEG_STREAM_RESERVED_LAST 0xfe |
| 111 | /* Program stream directory */ |
| 112 | #define MPEG_STREAM_PROGRAM_DIRECTORY 0xff |
| 113 | |
| 114 | #define STREAM_IS_AUDIO(s) (((s) & 0xf0) == 0xc0) |
| 115 | #define STREAM_IS_VIDEO(s) (((s) & 0xf0) == 0xe0) |
| 116 | |
| 117 | #define MPEG_MAX_PACKET_SIZE (64*1024+16) |
| 118 | |
| 119 | /* Largest MPEG audio frame - MPEG1, Layer II, 384kbps, 32kHz, pad */ |
| 120 | #define MPA_MAX_FRAME_SIZE 1729 |
| 121 | |
| 122 | #endif /* MPEG_STREAM_H */ |