• Main Page
  • Related Pages
  • Modules
  • Data Structures
  • Files

hvirtual/libmpeg3/mpeg3private.h

Go to the documentation of this file.
00001 #ifndef MPEG3PRIVATE_H
00002 #define MPEG3PRIVATE_H
00003 
00004 #include <pthread.h>
00005 
00006 #include <stdint.h>
00007 
00008 #include <stdio.h>
00009 
00010 
00011 
00012 
00013 /* Constants */
00014 
00015 #define MPEG3_MAJOR   1
00016 #define MPEG3_MINOR   7
00017 #define MPEG3_RELEASE 0
00018 
00019 #define RENDERFARM_FS_PREFIX "vfs://"
00020 
00021 
00022 #define MPEG3_FLOAT32 float
00023 
00024 #define MPEG3_TOC_PREFIX                 0x544f4320
00025 // This decreases with every new version
00026 #define MPEG3_TOC_VERSION                0x000000fa
00027 #define MPEG3_ID3_PREFIX                 0x494433
00028 #define MPEG3_IFO_PREFIX                 0x44564456
00029 #define MPEG3_IO_SIZE                    0x100000     /* Bytes read by mpeg3io at a time */
00030 //#define MPEG3_IO_SIZE                    0x800          /* Bytes read by mpeg3io at a time */
00031 #define MPEG3_RIFF_CODE                  0x52494646
00032 #define MPEG3_PROC_CPUINFO               "/proc/cpuinfo"
00033 #define MPEG3_RAW_SIZE                   0x100000     /* Largest possible packet */
00034 #define MPEG3_BD_PACKET_SIZE             192
00035 #define MPEG3_TS_PACKET_SIZE             188
00036 #define MPEG3_DVD_PACKET_SIZE            0x800
00037 #define MPEG3_SYNC_BYTE                  0x47
00038 #define MPEG3_PACK_START_CODE            0x000001ba
00039 #define MPEG3_SEQUENCE_START_CODE        0x000001b3
00040 #define MPEG3_SEQUENCE_END_CODE          0x000001b7
00041 #define MPEG3_SYSTEM_START_CODE          0x000001bb
00042 #define MPEG3_STRLEN                     1024
00043 #define MPEG3_PIDMAX                     256             /* Maximum number of PIDs in one stream */
00044 #define MPEG3_PROGRAM_ASSOCIATION_TABLE  0x00
00045 #define MPEG3_CONDITIONAL_ACCESS_TABLE   0x01
00046 #define MPEG3_PACKET_START_CODE_PREFIX   0x000001
00047 #define MPEG3_PRIVATE_STREAM_2           0xbf
00048 #define MPEG3_PADDING_STREAM             0xbe
00049 #define MPEG3_GOP_START_CODE             0x000001b8
00050 #define MPEG3_PICTURE_START_CODE         0x00000100
00051 #define MPEG3_EXT_START_CODE             0x000001b5
00052 #define MPEG3_USER_START_CODE            0x000001b2
00053 #define MPEG3_SLICE_MIN_START            0x00000101
00054 #define MPEG3_SLICE_MAX_START            0x000001af
00055 #define MPEG3_AC3_START_CODE             0x0b77
00056 #define MPEG3_PCM_START_CODE             0x7f7f807f
00057 #define MPEG3_MAX_CPUS                   256
00058 #define MPEG3_MAX_STREAMS                0x10000
00059 #define MPEG3_MAX_PACKSIZE               262144
00060 /* Maximum number of complete subtitles to buffer in a subtitle track */
00061 /* or number of incomplete subtitles to buffer in demuxer. */
00062 #define MPEG3_MAX_SUBTITLES              5
00063 /* Positive difference before declaring timecodes discontinuous */
00064 #define MPEG3_CONTIGUOUS_THRESHOLD       10  
00065 /* Minimum number of seconds before interleaving programs */
00066 #define MPEG3_PROGRAM_THRESHOLD          5   
00067 /* Number of frames difference before absolute seeking */
00068 #define MPEG3_SEEK_THRESHOLD             16  
00069 /* Size of chunk of audio in table of contents */
00070 #define MPEG3_AUDIO_CHUNKSIZE            0x10000 
00071 /* Minimum amount of data required to read an audio packet in streaming mode. */
00072 #define MPEG3_AUDIO_STREAM_SIZE          0x1000 
00073 /* Minimum amount of data required to read a video header in streaming mode. */
00074 #define MPEG3_VIDEO_STREAM_SIZE          0x1000 
00075 #define MPEG3_LITTLE_ENDIAN              ((*(uint32_t*)"x\0\0\0") & 0x000000ff)
00076 /* Number of samples in audio history */
00077 #define MPEG3_AUDIO_HISTORY              0x100000 
00078 /* Range to scan for pts after byte seek */
00079 #define MPEG3_PTS_RANGE                  0x100000 
00080 
00081 /* Values for audio format */
00082 #define AUDIO_UNKNOWN 0
00083 #define AUDIO_MPEG 1
00084 #define AUDIO_AC3  2
00085 #define AUDIO_PCM  3
00086 #define AUDIO_AAC  4
00087 #define AUDIO_JESUS  5
00088 
00089 
00090 /* Table of contents sections */
00091 #define FILE_TYPE_PROGRAM 0x00000000
00092 #define FILE_TYPE_TRANSPORT 0x00000001
00093 #define FILE_TYPE_AUDIO 0x00000002
00094 #define FILE_TYPE_VIDEO 0x00000003
00095 
00096 #define STREAM_AUDIO 0x00000004
00097 #define STREAM_VIDEO 0x00000005
00098 #define STREAM_SUBTITLE 0x00000006
00099 
00100 #define OFFSETS_AUDIO 0x00000007
00101 #define OFFSETS_VIDEO 0x00000008
00102 
00103 #define ATRACK_COUNT 0x9
00104 #define VTRACK_COUNT 0xa
00105 #define STRACK_COUNT 0xb
00106 
00107 #define TITLE_PATH 0xc
00108 #define IFO_PALETTE 0xd
00109 #define FILE_INFO 0xe
00110 
00111 // Combine the pid and the stream id into one unit
00112 #define CUSTOM_ID(pid, stream_id) (((pid << 8) | stream_id) & 0xffff)
00113 #define CUSTOM_ID_PID(id) (id >> 8)
00114 #define CUSTOM_ID_STREAMID(id) (id & 0xff)
00115 
00116 #ifndef MAX
00117 #define MAX(a, b) ((a) > (b) ? (a) : (b))
00118 #endif
00119 
00120 #ifndef MIN
00121 #define MIN(a, b) ((a) < (b) ? (a) : (b))
00122 #endif
00123 
00124 
00125 // CSS
00126 
00127 
00128 
00129 
00130 
00131 
00132 
00133 struct mpeg3_block 
00134 {
00135         unsigned char b[5];
00136 };
00137 
00138 struct mpeg3_playkey 
00139 {
00140         int offset;
00141         unsigned char key[5];
00142 };
00143 
00144 typedef struct
00145 {
00146         int encrypted;
00147         char device_path[MPEG3_STRLEN];    /* Device the file is located on */
00148         unsigned char disk_key[MPEG3_DVD_PACKET_SIZE];
00149         unsigned char title_key[5];
00150         char challenge[10];
00151         struct mpeg3_block key1;
00152         struct mpeg3_block key2;
00153         struct mpeg3_block keycheck;
00154         int varient;
00155         int fd;
00156         char path[MPEG3_STRLEN];
00157 } mpeg3_css_t;
00158 
00159 
00160 
00161 
00162 
00163 
00164 
00165 
00166 
00167 
00168 // I/O
00169 
00170 
00171 
00172 
00173 
00174 
00175 
00176 
00177 
00178 
00179 
00180 /* Filesystem structure */
00181 /* We buffer in MPEG3_IO_SIZE buffers.  Stream IO would require back */
00182 /* buffering a buffer since the stream must be rewound for packet headers, */
00183 /* sequence start codes, format parsing, decryption, and mpeg3cat. */
00184 
00185 
00186 
00187 typedef struct
00188 {
00189         FILE *fd;
00190         mpeg3_css_t *css;          /* Encryption object */
00191         char path[MPEG3_STRLEN];
00192         unsigned char *buffer;   /* Readahead buffer */
00193         int64_t buffer_offset;      /* Current buffer position */
00194         int64_t buffer_size;        /* Bytes in buffer */
00195         int64_t buffer_position;    /* Byte in file of start of buffer */
00196 
00197 /* Hypothetical position of file pointer */
00198         int64_t current_byte;
00199         int64_t total_bytes;
00200 } mpeg3_fs_t;
00201 
00202 
00203 
00204 
00205 
00206 
00207 
00208 
00209 // Table of contents
00210 
00211 
00212 
00213 
00214 
00215 
00216 
00217 
00218 // May get rid of time values and rename to a cell offset table.
00219 // May also get rid of end byte.
00220 typedef struct
00221 {
00222 /* Starting byte of cell in the title (start_byte) */
00223         int64_t title_start;
00224 /* Ending byte of cell in the title (end_byte) */
00225         int64_t title_end;
00226 /* Starting byte of the cell in the program */
00227         int64_t program_start;
00228 /* Ending byte of the cell in the program */
00229         int64_t program_end;
00230 /* Program the cell belongs to */
00231         int program;
00232 } mpeg3_cell_t;
00233 
00234 typedef struct
00235 {
00236         void *file;
00237         mpeg3_fs_t *fs;
00238 /* Total bytes in title file.  Critical for seeking and length. */
00239         int64_t total_bytes;
00240 /* Absolute starting byte of the title in the stream */
00241         int64_t start_byte;
00242 /* Absolute ending byte of the title in the stream + 1 */
00243         int64_t end_byte;
00244 /* Timecode table */
00245         mpeg3_cell_t *cell_table;
00246         int cell_table_size;    /* Number of entries */
00247         int cell_table_allocation;    /* Number of available slots */
00248 } mpeg3_title_t;
00249 
00250 
00251 
00252 
00253 
00254 
00255 
00256 
00257 /* Subtitle object. */
00258 /* Created by the demuxer to store subtitles. */
00259 
00260 
00261 
00262 
00263 
00264 
00265 
00266 typedef struct
00267 {
00268 /* Raw data of subtitle */
00269         unsigned char *data;
00270 /* number of bytes of data */
00271         int size;
00272 /* Number of stream starting at 0x20 */
00273         int id;
00274         int done;
00275 /* Program offset of start of subtitle */
00276         int64_t offset;
00277 
00278 /* image in YUV 4:2:0 */
00279         unsigned char *image_y;
00280         unsigned char *image_u;
00281         unsigned char *image_v;
00282         unsigned char *image_a;
00283         int x1;
00284         int x2;
00285         int y1;
00286         int y2;
00287         int w;
00288         int h;
00289 /* Force display */
00290         int force;
00291 /* Time after detection of subtitle to display it in 1/100sec */
00292         int start_time;
00293 /* Time after detection of subtitle to hide it in 1/100sec */
00294         int stop_time;
00295 /* Indexes in the main palette */
00296         int palette[4];
00297         int alpha[4];
00298 /* The subtitle is being drawn */
00299         int active;
00300 } mpeg3_subtitle_t;
00301 
00302 
00303 
00304 
00305 
00306 
00307 
00308 
00309 // Demuxer
00310 
00311 
00312 
00313 
00314 
00315 
00316 
00317 
00318 
00319 
00320 typedef struct
00321 {
00322 /* mpeg3_t */
00323         void* file;
00324 /* One unparsed packet.  MPEG3_RAW_SIZE allocated since we don't know the packet size */
00325         unsigned char *raw_data;
00326 /* Offset in raw_data of read pointer */
00327         int raw_offset;
00328 /* Amount loaded in last raw_data */
00329         int raw_size;
00330 
00331 
00332 /* Elementary stream data when only one stream is to be read. */
00333 /* Erased in every call to read a packet. */
00334         unsigned char *data_buffer;
00335 /* Allocation of data_buffer */
00336         int data_allocated;
00337 /* Position in data_buffer of write pointer */
00338         int data_size;
00339 /* Position in data_buffer of read pointer */
00340         int data_position;
00341 /* Start of the next pes packet in the data buffer for reading.  */
00342 /* Used for decoding PCM. */
00343         int data_start;
00344 
00345 /* Elementary stream data when all streams are to be read.  There is no */
00346 /* read pointer since data is expected to be copied directly to a track. */
00347 /* Some packets contain audio and video.  Further division into */
00348 /* stream ID may be needed. */
00349         unsigned char *audio_buffer;
00350         int audio_allocated;
00351         int audio_size;
00352         int audio_start;
00353         unsigned char *video_buffer;
00354         int video_allocated;
00355         int video_size;
00356         int video_start;
00357 
00358 
00359 /* Subtitle objects */
00360         mpeg3_subtitle_t **subtitles;
00361         int total_subtitles;
00362 
00363 
00364 
00365 
00366 
00367 /* What type of data to read. */
00368         int do_audio;
00369         int do_video;
00370         int read_all;
00371 
00372 /* Direction of reads */
00373         int reverse;
00374 /* Set to 1 when eof or attempt to read before beginning */
00375         int error_flag;
00376 /* Temp variables for returning */
00377         unsigned char next_char;
00378 /* Info for mpeg3cat */
00379         int64_t last_packet_start;
00380         int64_t last_packet_end;
00381         int64_t last_packet_decryption;
00382 
00383 /* Titles */
00384         mpeg3_title_t *titles[MPEG3_MAX_STREAMS];
00385         int total_titles;
00386 /* Title currently being used */
00387         int current_title;
00388         
00389 
00390 /* Tables of every stream ID encountered */
00391         int astream_table[MPEG3_MAX_STREAMS];  /* macro of audio format if audio  */
00392         int vstream_table[MPEG3_MAX_STREAMS];  /* 1 if video */
00393 
00394 /* Programs */
00395         int total_programs;
00396         int current_program;
00397 
00398 /* Cell in the current title currently used */
00399         int title_cell;
00400 
00401 /* Byte position in current program. */
00402         int64_t program_byte;
00403 /* Total bytes in all titles */
00404         int64_t total_bytes;
00405 /* The end of the current stream in the current program */
00406         int64_t stream_end;
00407 
00408         int transport_error_indicator;
00409         int payload_unit_start_indicator;
00410 /* PID of last packet */
00411         int pid;
00412 /* Stream ID of last packet */
00413         unsigned int stream_id;
00414 /* Custom ID of last packet */
00415         unsigned int custom_id;
00416         int transport_scrambling_control;
00417         int adaptation_field_control;
00418         int continuity_counter;
00419         int is_padding;
00420         int pid_table[MPEG3_PIDMAX];
00421         int continuity_counters[MPEG3_PIDMAX];
00422         int total_pids;
00423         int adaptation_fields;
00424         double time;           /* Time in seconds */
00425         int audio_pid;
00426         int video_pid;
00427         int got_audio;
00428         int got_video;
00429 /* if subtitle object was created in last packet */
00430         int got_subtitle;
00431 /* When only one stream is to be read, these store the stream IDs */
00432 /* Video stream ID being decoded.  -1 = select first ID in stream */
00433         int astream;     
00434 /* Audio stream ID being decoded.  -1 = select first ID in stream */
00435         int vstream;
00436 /* Multiplexed streams have the audio type */
00437 /* Format of the audio derived from multiplexing codes */
00438         int aformat;      
00439         int program_association_tables;
00440         int table_id;
00441         int section_length;
00442         int transport_stream_id;
00443         int pes_packets;
00444         double pes_audio_time;  /* Presentation Time stamps */
00445         double pes_video_time;  /* Presentation Time stamps */
00446 /* Cause the stream parameters to be dumped in human readable format */
00447         int dump;
00448 } mpeg3_demuxer_t;
00449 
00450 
00451 
00452 
00453 
00454 
00455 
00456 
00457 // Bitstream
00458 
00459 
00460 
00461 
00462 
00463 
00464 
00465 
00466 
00467 
00468 //                                    next bit in forward direction
00469 //                                  next bit in reverse direction |
00470 //                                                              v v
00471 // | | | | | | | | | | | | | | | | | | | | | | | | | | |1|1|1|1|1|1| */
00472 //                                                     ^         ^
00473 //                                                     |         bit_number = 1
00474 //                                                     bfr_size = 6
00475 
00476 typedef struct
00477 {
00478         uint32_t bfr;  /* bfr = buffer for bits */
00479         int bit_number;   /* position of pointer in bfr */
00480         int bfr_size;    /* number of bits in bfr.  Should always be a multiple of 8 */
00481         void *file;    /* Mpeg2 file */
00482         mpeg3_demuxer_t *demuxer;   /* Mpeg2 demuxer */
00483 /* If the input ptr is true, data is read from it instead of the demuxer. */
00484         unsigned char *input_ptr;
00485 } mpeg3_bits_t;
00486 
00487 
00488 
00489 
00490 
00491 
00492 
00493 
00494 
00495 
00496 // Audio
00497 
00498 
00499 
00500 
00501 
00502 
00503 
00504 #define AC3_N 512
00505 
00506 #define MAXFRAMESIZE 4096
00507 #define MAXFRAMESAMPLES 65536
00508 #define HDRCMPMASK 0xfffffd00
00509 #define SBLIMIT 32
00510 #define SSLIMIT 18
00511 #define SCALE_BLOCK 12
00512 #define MPEG3AUDIO_PADDING 1024
00513 
00514 /* Values for mode */
00515 #define MPG_MD_STEREO                   0
00516 #define MPG_MD_JOINT_STEREO     1
00517 #define MPG_MD_DUAL_CHANNEL     2
00518 #define MPG_MD_MONO                     3
00519 
00520 
00521 #define MAX_AC3_FRAMESIZE 1920 * 2 + 512
00522 
00523 extern int mpeg3_ac3_samplerates[3];
00524 
00525 /* Exponent strategy constants */
00526 #define MPEG3_EXP_REUSE (0)
00527 #define MPEG3_EXP_D15   (1)
00528 #define MPEG3_EXP_D25   (2)
00529 #define MPEG3_EXP_D45   (3)
00530 
00531 /* Delta bit allocation constants */
00532 #define DELTA_BIT_REUSE (0)
00533 #define DELTA_BIT_NEW (1)
00534 #define DELTA_BIT_NONE (2)
00535 #define DELTA_BIT_RESERVED (3)
00536 
00537 
00538 
00539 
00540 
00541 // Layered decoder
00542 
00543 typedef struct
00544 {
00545         mpeg3_bits_t *stream;
00546 
00547 
00548 // Layer 3
00549         unsigned char *bsbuf, *bsbufold;
00550         unsigned char bsspace[2][MAXFRAMESIZE + 512]; /* MAXFRAMESIZE */
00551         int bsnum;
00552         long framesize;           /* For mp3 current framesize without header.  For AC3 current framesize with header. */
00553         long prev_framesize;
00554         int channels;
00555         int samplerate;
00556         int single;
00557         int sampling_frequency_code;
00558         int error_protection;
00559         int mode;
00560         int mode_ext;
00561         int lsf;
00562         long ssize;
00563         int mpeg35;
00564         int padding;
00565         int layer;
00566         int extension;
00567         int copyright;
00568         int original;
00569         int emphasis;
00570         int bitrate;
00571 /* Static variable in synthesizer */
00572         int bo;                      
00573 /* Ignore first frame after a seek */
00574         int first_frame;
00575 
00576         float synth_stereo_buffs[2][2][0x110];
00577         float synth_mono_buff[64];
00578         float mp3_block[2][2][SBLIMIT * SSLIMIT];
00579         int mp3_blc[2];
00580 
00581 
00582 
00583 // Layer 2
00584         int bitrate_index;
00585     struct al_table *alloc;
00586     int jsbound;
00587     int II_sblimit;
00588         unsigned int layer2_scfsi_buf[64];
00589 } mpeg3_layer_t;
00590 
00591 
00592 
00593 
00594 
00595 // AC3 decoder
00596 
00597 typedef struct
00598 {
00599         mpeg3_bits_t *stream;
00600         int samplerate;
00601         int bitrate;
00602         int flags;
00603         int channels;
00604         void *state;  /* a52_state_t */
00605         void *output; /* sample_t */
00606         int framesize;
00607 } mpeg3_ac3_t;
00608 
00609 
00610 
00611 
00612 // PCM decoder
00613 
00614 #define PCM_HEADERSIZE 20
00615 typedef struct
00616 {
00617         int samplerate;
00618         int bits;
00619         int channels;
00620         int framesize;
00621 } mpeg3_pcm_t;
00622 
00623 
00624 
00625 
00626 
00627 
00628 /* IMDCT variables */
00629 typedef struct
00630 {
00631         float real;
00632         float imag;
00633 } mpeg3_complex_t;
00634 
00635 struct al_table 
00636 {
00637         short bits;
00638         short d;
00639 };
00640 
00641 
00642 typedef struct
00643 {
00644         void* file;
00645         void* track;
00646 
00647         mpeg3_ac3_t *ac3_decoder;
00648         mpeg3_layer_t *layer_decoder;
00649         mpeg3_pcm_t *pcm_decoder;
00650 
00651 /* In order of importance */
00652         long outscale;
00653 /* Number of current frame being decoded */
00654         int framenum;
00655         
00656 /* Size of frame including header */
00657         int framesize;
00658 /* Output from synthesizer in linear floats */
00659         float **output;           
00660 /* Number of pcm samples in the buffer */
00661         int output_size;         
00662 /* Allocated number of samples in output */
00663         int output_allocated;    
00664 /* Sample position in file of start of output buffer */
00665         int output_position;     
00666 
00667 /* Perform a seek to the sample */
00668         int sample_seek;
00669 /* Perform a seek to the absolute byte */
00670         int64_t byte_seek;
00671 /* +/- number of samples of difference between audio and video */
00672         int seek_correction;
00673 /* Buffer containing current packet */
00674         unsigned char packet_buffer[MAXFRAMESIZE];
00675 /* Position in packet buffer of next byte to read */
00676         int packet_position;
00677 } mpeg3audio_t;
00678 
00679 
00680 
00681 
00682 
00683 typedef struct
00684 {
00685 /* Buffer of frames for index.  A frame is a high/low pair. */
00686         float **index_data;
00687 /* Number of frames allocated in each index channel. */
00688         int index_allocated;
00689 /* Number of index channels allocated */
00690         int index_channels;
00691 /* Number of high/low pairs in index channel */
00692         int index_size;
00693 /* Downsampling of index buffers when constructing index */
00694         int index_zoom;
00695 } mpeg3_index_t;
00696 
00697 
00698 
00699 typedef struct
00700 {
00701         int channels;
00702         int sample_rate;
00703         mpeg3_demuxer_t *demuxer;
00704         mpeg3audio_t *audio;
00705         int current_position;
00706         int64_t total_samples;
00707         int format;               /* format of audio */
00708         unsigned int pid;
00709 /* If we got the header information yet.  Used in streaming mode. */
00710         int got_header;
00711 
00712 
00713 
00714 /* Pointer to master table of contents when the TOC is read. */
00715 /* Pointer to private table when the TOC is being created */
00716 /* Stores the absolute byte of each audio chunk */
00717         int64_t *sample_offsets;
00718         int total_sample_offsets;
00719         int sample_offsets_allocated;
00720 /* If this sample offset table must be deleted by the track */
00721         int private_offsets;
00722 /* End of stream in table of contents construction */
00723         int64_t audio_eof;
00724 
00725 
00726 
00727 
00728 /* Starting byte of previous packet for making TOC */
00729         int64_t prev_offset;
00730 
00731 } mpeg3_atrack_t;
00732 
00733 
00734 
00735 
00736 
00737 
00738 
00739 
00740 
00741 
00742 // Video
00743 
00744 
00745 
00746 
00747 
00748 
00749 
00750 
00751 
00752 
00753 /* zig-zag scan */
00754 extern unsigned char mpeg3_zig_zag_scan_nommx[64];
00755 
00756 /* alternate scan */
00757 extern unsigned char mpeg3_alternate_scan_nommx[64];
00758 
00759 /* default intra quantization matrix */
00760 extern unsigned char mpeg3_default_intra_quantizer_matrix[64];
00761 
00762 /* Frame rate table must agree with the one in the encoder */
00763 extern double mpeg3_frame_rate_table[16];
00764 
00765 /* non-linear quantization coefficient table */
00766 extern unsigned char mpeg3_non_linear_mquant_table[32];
00767 
00768 #define CHROMA420     1     /* chroma_format */
00769 #define CHROMA422     2
00770 #define CHROMA444     3
00771 
00772 #define TOP_FIELD     1     /* picture structure */
00773 #define BOTTOM_FIELD  2
00774 #define FRAME_PICTURE 3
00775 
00776 #define SEQ_ID        1     /* extension start code IDs */
00777 #define DISP_ID       2
00778 #define QUANT_ID      3
00779 #define SEQSCAL_ID    5
00780 #define PANSCAN_ID    7
00781 #define CODING_ID     8
00782 #define SPATSCAL_ID   9
00783 #define TEMPSCAL_ID  10
00784 
00785 #define SC_NONE       0   /* scalable_mode */
00786 #define SC_DP         1
00787 #define SC_SPAT       2
00788 #define SC_SNR        3
00789 #define SC_TEMP       4
00790 
00791 #define I_TYPE        1     /* picture coding type */
00792 #define P_TYPE        2
00793 #define B_TYPE        3
00794 #define D_TYPE        4
00795 
00796 #define MB_INTRA      1         /* macroblock type */
00797 #define MB_PATTERN    2
00798 #define MB_BACKWARD   4
00799 #define MB_FORWARD    8
00800 #define MB_QUANT      16
00801 #define MB_WEIGHT     32
00802 #define MB_CLASS4     64
00803 
00804 #define MC_FIELD      1     /* motion_type */
00805 #define MC_FRAME      2
00806 #define MC_16X8       2
00807 #define MC_DMV        3
00808 
00809 #define MV_FIELD      0     /* mv_format */
00810 #define MV_FRAME      1
00811 
00812 
00813 
00814 
00815 
00816 
00817 
00818 
00819 
00820 
00821 
00822 /* Array of these feeds the slice decoders */
00823 typedef struct
00824 {
00825         unsigned char *data;   /* Buffer for holding the slice data */
00826         int buffer_size;         /* Size of buffer */
00827         int buffer_allocation;   /* Space allocated for buffer  */
00828         int current_position;    /* Position in buffer */
00829         uint32_t bits;
00830         int bits_size;
00831         pthread_mutex_t completion_lock; /* Lock slice until completion */
00832         int done;           /* Signal for slice decoder to skip */
00833 } mpeg3_slice_buffer_t;
00834 
00835 /* Each slice decoder */
00836 typedef struct
00837 {
00838         void *video;     /* mpeg3video_t */
00839         mpeg3_slice_buffer_t *slice_buffer;
00840 
00841         int thread_number;      /* Number of this thread */
00842         int current_buffer;     /* Buffer this slice decoder is on */
00843         int buffer_step;        /* Number of buffers to skip */
00844         int last_buffer;        /* Last buffer this decoder should process */
00845         int fault;
00846         int done;
00847         int quant_scale;
00848         int pri_brk;                  /* slice/macroblock */
00849         short block[12][64];
00850         int sparse[12];
00851         pthread_t tid;   /* ID of thread */
00852         pthread_mutex_t input_lock, output_lock, completion_lock;
00853 } mpeg3_slice_t;
00854 
00855 typedef struct 
00856 {
00857         int hour;
00858         int minute;
00859         int second;
00860         int frame;
00861 } mpeg3_timecode_t;
00862 
00863 
00864 
00865 typedef struct
00866 {
00867         unsigned char *y, *u, *v;
00868         int y_size;
00869         int u_size;
00870         int v_size;
00871         int64_t frame_number;
00872 } mpeg3_cacheframe_t;
00873 
00874 typedef struct
00875 {
00876         mpeg3_cacheframe_t *frames;
00877         int total;
00878         int allocation;
00879 } mpeg3_cache_t;
00880 
00881 
00882 typedef struct
00883 {
00884         void* file;
00885         void* track;
00886 
00887 /* ================================= Seeking variables ========================= */
00888         mpeg3_bits_t *vstream;
00889         int decoder_initted;
00890         unsigned char **output_rows;     /* Output frame buffer supplied by user */
00891         int in_x, in_y, in_w, in_h, out_w, out_h; /* Output dimensions */
00892         int row_span;
00893         int *x_table, *y_table;          /* Location of every output pixel in the input */
00894         int color_model;
00895         int want_yvu;                    /* Want to return a YUV frame */
00896         char *y_output, *u_output, *v_output; /* Output pointers for a YUV frame */
00897 
00898         mpeg3_slice_t slice_decoders[MPEG3_MAX_CPUS];  /* One slice decoder for every CPU */
00899         int total_slice_decoders;                       /* Total slice decoders in use */
00900         mpeg3_slice_buffer_t slice_buffers[MPEG3_MAX_CPUS];   /* Buffers for holding the slice data */
00901         int total_slice_buffers;         /* Total buffers in the array to be decompressed */
00902         int slice_buffers_initialized;     /* Total buffers initialized in the array */
00903         pthread_mutex_t slice_lock;      /* Lock slice array while getting the next buffer */
00904         pthread_mutex_t test_lock;
00905 
00906         int blockreadsize;
00907         int maxframe;         /* Max value of frame num to read */
00908         int64_t byte_seek;   /* Perform absolute byte seek before the next frame is read */
00909         int frame_seek;        /* Perform a frame seek before the next frame is read */
00910         int framenum;         /* Number of the next frame to be decoded */
00911         int last_number;       /* Last framenum rendered */
00912         int found_seqhdr;
00913         int bitrate;
00914         mpeg3_timecode_t gop_timecode;     /* Timecode for the last GOP header read. */
00915         int has_gops; /* Some streams have no GOPs so try sequence start codes instead */
00916 
00917 /* These are only available from elementary streams. */
00918         int frames_per_gop;       /* Frames per GOP after the first GOP. */
00919         int first_gop_frames;     /* Frames in the first GOP. */
00920         int first_frame;     /* Number of first frame stored in timecode */
00921         int last_frame;      /* Last frame in file */
00922 
00923 /* ================================= Compression variables ===================== */
00924 /* Malloced frame buffers.  2 refframes are swapped in and out. */
00925 /* while only 1 auxframe is used. */
00926         unsigned char *yuv_buffer[5];  /* Make YVU buffers contiguous for all frames */
00927         unsigned char *oldrefframe[3], *refframe[3], *auxframe[3];
00928         unsigned char *llframe0[3], *llframe1[3];
00929         unsigned char *mpeg3_zigzag_scan_table;
00930         unsigned char *mpeg3_alternate_scan_table;
00931 // Source for the next frame presentation
00932         unsigned char *output_src[3];
00933 /* Pointers to frame buffers. */
00934         unsigned char *newframe[3];
00935         int horizontal_size, vertical_size, mb_width, mb_height;
00936         int coded_picture_width,  coded_picture_height;
00937         int chroma_format, chrom_width, chrom_height, blk_cnt;
00938         int pict_type;
00939         int field_sequence;
00940         int forw_r_size, back_r_size, full_forw, full_back;
00941         int prog_seq, prog_frame;
00942         int h_forw_r_size, v_forw_r_size, h_back_r_size, v_back_r_size;
00943         int dc_prec, pict_struct, topfirst, frame_pred_dct, conceal_mv;
00944         int intravlc;
00945         int repeatfirst;
00946 /* Number of times to repeat the current frame * 100 since floating point is impossible in MMX */
00947         int repeat_count;
00948 /* Number of times the current frame has been repeated * 100 */
00949         int current_repeat;
00950         int secondfield;
00951         int skip_bframes;
00952         int stwc_table_index, llw, llh, hm, hn, vm, vn;
00953         int lltempref, llx0, lly0, llprog_frame, llfieldsel;
00954         int matrix_coefficients;
00955         int framerate_code;
00956         double frame_rate;
00957         int *cr_to_r, *cr_to_g, *cb_to_g, *cb_to_b;
00958         int *cr_to_r_ptr, *cr_to_g_ptr, *cb_to_g_ptr, *cb_to_b_ptr;
00959         int intra_quantizer_matrix[64], non_intra_quantizer_matrix[64];
00960         int chroma_intra_quantizer_matrix[64], chroma_non_intra_quantizer_matrix[64];
00961         int mpeg2;
00962         int qscale_type, altscan;      /* picture coding extension */
00963         int pict_scal;                /* picture spatial scalable extension */
00964         int scalable_mode;            /* sequence scalable extension */
00965 
00966 /* Subtitling frame */
00967         unsigned char *subtitle_frame[3];
00968 } mpeg3video_t;
00969 
00970 
00971 
00972 
00973 
00974 
00975 
00976 
00977 
00978 
00979 
00980 
00981 
00982 
00983 
00984 typedef struct
00985 {
00986         int width;
00987         int height;
00988         double frame_rate;
00989         float aspect_ratio;
00990         mpeg3_demuxer_t *demuxer;
00991 /* Video decoding object */
00992         mpeg3video_t *video;
00993 /* Table of current subtitles being overlayed */
00994         mpeg3_subtitle_t **subtitles;
00995         int total_subtitles;
00996         int current_position;  /* Number of next frame to be played */
00997         int total_frames;     /* Total frames in the file */
00998         unsigned int pid;
00999 
01000 
01001 /* Pointer to master table of contents when the TOC is read. */
01002 /* Pointer to private table when the TOC is being created */
01003 /* Stores the absolute byte of each frame */
01004         int64_t *frame_offsets;
01005         int total_frame_of