r761: Patches by j@v2v.cc
[cinelerra_cv/mob.git] / libmpeg3 / mpeg3private.h
blobcc0a501e23cca3103bb97e497d248dd7508a9ba5
1 #ifndef MPEG3PRIVATE_H
2 #define MPEG3PRIVATE_H
4 #include <pthread.h>
6 #include <stdint.h>
8 #include <stdio.h>
13 /* Constants */
15 #define MPEG3_MAJOR 1
16 #define MPEG3_MINOR 6
17 #define MPEG3_RELEASE 0
19 #define RENDERFARM_FS_PREFIX "vfs://"
22 #define MPEG3_FLOAT32 float
24 #define MPEG3_TOC_PREFIX 0x544f4320
25 #define MPEG3_TOC_VERSION 0xfd
26 #define MPEG3_ID3_PREFIX 0x494433
27 #define MPEG3_IFO_PREFIX 0x44564456
28 #define MPEG3_IO_SIZE 0x100000 /* Bytes read by mpeg3io at a time */
29 //#define MPEG3_IO_SIZE 0x800 /* Bytes read by mpeg3io at a time */
30 #define MPEG3_RIFF_CODE 0x52494646
31 #define MPEG3_PROC_CPUINFO "/proc/cpuinfo"
32 #define MPEG3_RAW_SIZE 0x100000 /* Largest possible packet */
33 #define MPEG3_TS_PACKET_SIZE 188
34 #define MPEG3_DVD_PACKET_SIZE 0x800
35 #define MPEG3_SYNC_BYTE 0x47
36 #define MPEG3_PACK_START_CODE 0x000001ba
37 #define MPEG3_SEQUENCE_START_CODE 0x000001b3
38 #define MPEG3_SEQUENCE_END_CODE 0x000001b7
39 #define MPEG3_SYSTEM_START_CODE 0x000001bb
40 #define MPEG3_STRLEN 1024
41 #define MPEG3_PIDMAX 256 /* Maximum number of PIDs in one stream */
42 #define MPEG3_PROGRAM_ASSOCIATION_TABLE 0x00
43 #define MPEG3_CONDITIONAL_ACCESS_TABLE 0x01
44 #define MPEG3_PACKET_START_CODE_PREFIX 0x000001
45 #define MPEG3_PRIVATE_STREAM_2 0xbf
46 #define MPEG3_PADDING_STREAM 0xbe
47 #define MPEG3_GOP_START_CODE 0x000001b8
48 #define MPEG3_PICTURE_START_CODE 0x00000100
49 #define MPEG3_EXT_START_CODE 0x000001b5
50 #define MPEG3_USER_START_CODE 0x000001b2
51 #define MPEG3_SLICE_MIN_START 0x00000101
52 #define MPEG3_SLICE_MAX_START 0x000001af
53 #define MPEG3_AC3_START_CODE 0x0b77
54 #define MPEG3_PCM_START_CODE 0x7f7f807f
55 #define MPEG3_MAX_CPUS 256
56 #define MPEG3_MAX_STREAMS 0x10000
57 #define MPEG3_MAX_PACKSIZE 262144
58 /* Positive difference before declaring timecodes discontinuous */
59 #define MPEG3_CONTIGUOUS_THRESHOLD 10
60 /* Minimum number of seconds before interleaving programs */
61 #define MPEG3_PROGRAM_THRESHOLD 5
62 /* Number of frames difference before absolute seeking */
63 #define MPEG3_SEEK_THRESHOLD 16
64 /* Size of chunk of audio in table of contents */
65 #define MPEG3_AUDIO_CHUNKSIZE 0x10000
66 /* Minimum amount of data required to read an audio packet in streaming mode. */
67 #define MPEG3_AUDIO_STREAM_SIZE 0x1000
68 /* Minimum amount of data required to read a video header in streaming mode. */
69 #define MPEG3_VIDEO_STREAM_SIZE 0x1000
70 #define MPEG3_LITTLE_ENDIAN ((*(uint32_t*)"x\0\0\0") & 0x000000ff)
71 /* Number of samples in audio history */
72 #define MPEG3_AUDIO_HISTORY 0x100000
73 /* Range to scan for pts after byte seek */
74 #define MPEG3_PTS_RANGE 0x100000
76 /* Values for audio format */
77 #define AUDIO_UNKNOWN 0
78 #define AUDIO_MPEG 1
79 #define AUDIO_AC3 2
80 #define AUDIO_PCM 3
81 #define AUDIO_AAC 4
82 #define AUDIO_JESUS 5
85 /* Table of contents */
86 #define FILE_TYPE_PROGRAM 0x0
87 #define FILE_TYPE_TRANSPORT 0x1
88 #define FILE_TYPE_AUDIO 0x2
89 #define FILE_TYPE_VIDEO 0x3
91 #define STREAM_AUDIO 0x4
92 #define STREAM_VIDEO 0x5
94 #define OFFSETS_AUDIO 0x6
95 #define OFFSETS_VIDEO 0x7
97 #define ATRACK_COUNT 0x8
98 #define VTRACK_COUNT 0x9
100 #define TITLE_PATH 0x2
102 // Combine the pid and the stream id into one unit
103 #define CUSTOM_ID(pid, stream_id) (((pid << 8) | stream_id) & 0xffff)
104 #define CUSTOM_ID_PID(id) (id >> 8)
105 #define CUSTOM_ID_STREAMID(id) (id & 0xff)
107 #ifndef MAX
108 #define MAX(a, b) ((a) > (b) ? (a) : (b))
109 #endif
111 #ifndef MIN
112 #define MIN(a, b) ((a) < (b) ? (a) : (b))
113 #endif
116 // CSS
124 struct mpeg3_block
126 unsigned char b[5];
129 struct mpeg3_playkey
131 int offset;
132 unsigned char key[5];
135 typedef struct
137 int encrypted;
138 char device_path[MPEG3_STRLEN]; /* Device the file is located on */
139 unsigned char disk_key[MPEG3_DVD_PACKET_SIZE];
140 unsigned char title_key[5];
141 char challenge[10];
142 struct mpeg3_block key1;
143 struct mpeg3_block key2;
144 struct mpeg3_block keycheck;
145 int varient;
146 int fd;
147 char path[MPEG3_STRLEN];
148 } mpeg3_css_t;
159 // I/O
171 /* Filesystem structure */
172 /* We buffer in MPEG3_IO_SIZE buffers. Stream IO would require back */
173 /* buffering a buffer since the stream must be rewound for packet headers, */
174 /* sequence start codes, format parsing, decryption, and mpeg3cat. */
178 typedef struct
180 FILE *fd;
181 mpeg3_css_t *css; /* Encryption object */
182 char path[MPEG3_STRLEN];
183 unsigned char *buffer; /* Readahead buffer */
184 int64_t buffer_offset; /* Current buffer position */
185 int64_t buffer_size; /* Bytes in buffer */
186 int64_t buffer_position; /* Byte in file of start of buffer */
188 /* Hypothetical position of file pointer */
189 int64_t current_byte;
190 int64_t total_bytes;
191 } mpeg3_fs_t;
200 // Table of contents
209 // May get rid of time values and rename to a cell offset table.
210 // May also get rid of end byte.
211 typedef struct
213 /* Starting byte of cell in the title (start_byte) */
214 int64_t title_start;
215 /* Ending byte of cell in the title (end_byte) */
216 int64_t title_end;
217 /* Starting byte of the cell in the program */
218 int64_t program_start;
219 /* Ending byte of the cell in the program */
220 int64_t program_end;
221 /* Program the cell belongs to */
222 int program;
223 } mpeg3_cell_t;
225 typedef struct
227 void *file;
228 mpeg3_fs_t *fs;
229 /* Total bytes in title file. Critical for seeking and length. */
230 int64_t total_bytes;
231 /* Absolute starting byte of the title in the stream */
232 int64_t start_byte;
233 /* Absolute ending byte of the title in the stream + 1 */
234 int64_t end_byte;
235 /* Timecode table */
236 mpeg3_cell_t *cell_table;
237 int cell_table_size; /* Number of entries */
238 int cell_table_allocation; /* Number of available slots */
239 } mpeg3_title_t;
251 // Demuxer
262 typedef struct
264 /* mpeg3_t */
265 void* file;
266 /* One unparsed packet. MPEG3_RAW_SIZE allocated since we don't know the packet size */
267 unsigned char *raw_data;
268 /* Offset in raw_data of read pointer */
269 int raw_offset;
270 /* Amount loaded in last raw_data */
271 int raw_size;
274 /* Elementary stream data when only one stream is to be read. */
275 /* Erased in every call to read a packet. */
276 unsigned char *data_buffer;
277 /* Allocation of data_buffer */
278 int data_allocated;
279 /* Position in data_buffer of write pointer */
280 int data_size;
281 /* Position in data_buffer of read pointer */
282 int data_position;
283 /* Start of the next pes packet in the data buffer for reading. */
284 /* Used for decoding PCM. */
285 int data_start;
287 /* Elementary stream data when all streams are to be read. There is no */
288 /* read pointer since data is expected to be copied directly to a track. */
289 /* Some packets contain audio and video. Further division into */
290 /* stream ID may be needed. */
291 unsigned char *audio_buffer;
292 int audio_allocated;
293 int audio_size;
294 int audio_start;
295 unsigned char *video_buffer;
296 int video_allocated;
297 int video_size;
298 int video_start;
301 /* What type of data to read. */
302 int do_audio;
303 int do_video;
304 int read_all;
306 /* Direction of reads */
307 int reverse;
308 /* Set to 1 when eof or attempt to read before beginning */
309 int error_flag;
310 /* Temp variables for returning */
311 unsigned char next_char;
312 /* Info for mpeg3cat */
313 int64_t last_packet_start;
314 int64_t last_packet_end;
315 int64_t last_packet_decryption;
317 /* Titles */
318 mpeg3_title_t *titles[MPEG3_MAX_STREAMS];
319 int total_titles;
320 /* Title currently being used */
321 int current_title;
324 /* Tables of every stream ID encountered */
325 int astream_table[MPEG3_MAX_STREAMS]; /* macro of audio format if audio */
326 int vstream_table[MPEG3_MAX_STREAMS]; /* 1 if video */
328 /* Programs */
329 int total_programs;
330 int current_program;
332 /* Cell in the current title currently used */
333 int title_cell;
335 /* Byte position in current program. */
336 int64_t program_byte;
337 /* Total bytes in all titles */
338 int64_t total_bytes;
339 /* The end of the current stream in the current program */
340 int64_t stream_end;
342 int transport_error_indicator;
343 int payload_unit_start_indicator;
344 /* PID of last packet */
345 int pid;
346 /* Stream ID of last packet */
347 unsigned int stream_id;
348 /* Custom ID of last packet */
349 unsigned int custom_id;
350 int transport_scrambling_control;
351 int adaptation_field_control;
352 int continuity_counter;
353 int is_padding;
354 int pid_table[MPEG3_PIDMAX];
355 int continuity_counters[MPEG3_PIDMAX];
356 int total_pids;
357 int adaptation_fields;
358 double time; /* Time in seconds */
359 int audio_pid;
360 int video_pid;
361 int got_audio;
362 int got_video;
363 /* When only one stream is to be read, these store the stream IDs */
364 /* Video stream ID being decoded. -1 = select first ID in stream */
365 int astream;
366 /* Audio stream ID being decoded. -1 = select first ID in stream */
367 int vstream;
368 /* Multiplexed streams have the audio type */
369 /* Format of the audio derived from multiplexing codes */
370 int aformat;
371 int program_association_tables;
372 int table_id;
373 int section_length;
374 int transport_stream_id;
375 int pes_packets;
376 double pes_audio_time; /* Presentation Time stamps */
377 double pes_video_time; /* Presentation Time stamps */
378 /* Cause the stream parameters to be dumped in human readable format */
379 int dump;
380 } mpeg3_demuxer_t;
389 // Bitstream
400 // next bit in forward direction
401 // next bit in reverse direction |
402 // v v
403 // | | | | | | | | | | | | | | | | | | | | | | | | | | |1|1|1|1|1|1| */
404 // ^ ^
405 // | bit_number = 1
406 // bfr_size = 6
408 typedef struct
410 uint32_t bfr; /* bfr = buffer for bits */
411 int bit_number; /* position of pointer in bfr */
412 int bfr_size; /* number of bits in bfr. Should always be a multiple of 8 */
413 void *file; /* Mpeg2 file */
414 mpeg3_demuxer_t *demuxer; /* Mpeg2 demuxer */
415 /* If the input ptr is true, data is read from it instead of the demuxer. */
416 unsigned char *input_ptr;
417 } mpeg3_bits_t;
428 // Audio
436 #define AC3_N 512
438 #define MAXFRAMESIZE 4096
439 #define MAXFRAMESAMPLES 65536
440 #define HDRCMPMASK 0xfffffd00
441 #define SBLIMIT 32
442 #define SSLIMIT 18
443 #define SCALE_BLOCK 12
444 #define MPEG3AUDIO_PADDING 1024
446 /* Values for mode */
447 #define MPG_MD_STEREO 0
448 #define MPG_MD_JOINT_STEREO 1
449 #define MPG_MD_DUAL_CHANNEL 2
450 #define MPG_MD_MONO 3
453 #define MAX_AC3_FRAMESIZE 1920 * 2 + 512
455 extern int mpeg3_ac3_samplerates[3];
457 /* Exponent strategy constants */
458 #define MPEG3_EXP_REUSE (0)
459 #define MPEG3_EXP_D15 (1)
460 #define MPEG3_EXP_D25 (2)
461 #define MPEG3_EXP_D45 (3)
463 /* Delta bit allocation constants */
464 #define DELTA_BIT_REUSE (0)
465 #define DELTA_BIT_NEW (1)
466 #define DELTA_BIT_NONE (2)
467 #define DELTA_BIT_RESERVED (3)
473 // Layered decoder
475 typedef struct
477 mpeg3_bits_t *stream;
480 // Layer 3
481 unsigned char *bsbuf, *bsbufold;
482 unsigned char bsspace[2][MAXFRAMESIZE + 512]; /* MAXFRAMESIZE */
483 int bsnum;
484 long framesize; /* For mp3 current framesize without header. For AC3 current framesize with header. */
485 long prev_framesize;
486 int channels;
487 int samplerate;
488 int single;
489 int sampling_frequency_code;
490 int error_protection;
491 int mode;
492 int mode_ext;
493 int lsf;
494 long ssize;
495 int mpeg35;
496 int padding;
497 int layer;
498 int extension;
499 int copyright;
500 int original;
501 int emphasis;
502 int bitrate;
503 /* Static variable in synthesizer */
504 int bo;
505 /* Ignore first frame after a seek */
506 int first_frame;
508 float synth_stereo_buffs[2][2][0x110];
509 float synth_mono_buff[64];
510 float mp3_block[2][2][SBLIMIT * SSLIMIT];
511 int mp3_blc[2];
515 // Layer 2
516 int bitrate_index;
517 struct al_table *alloc;
518 int jsbound;
519 int II_sblimit;
520 unsigned int layer2_scfsi_buf[64];
521 } mpeg3_layer_t;
527 // AC3 decoder
529 typedef struct
531 mpeg3_bits_t *stream;
532 int samplerate;
533 int bitrate;
534 int flags;
535 int channels;
536 void *state; /* a52_state_t */
537 void *output; /* sample_t */
538 int framesize;
539 } mpeg3_ac3_t;
544 // PCM decoder
546 #define PCM_HEADERSIZE 20
547 typedef struct
549 int samplerate;
550 int bits;
551 int channels;
552 int framesize;
553 } mpeg3_pcm_t;
560 /* IMDCT variables */
561 typedef struct
563 float real;
564 float imag;
565 } mpeg3_complex_t;
567 struct al_table
569 short bits;
570 short d;
574 typedef struct
576 void* file;
577 void* track;
579 mpeg3_ac3_t *ac3_decoder;
580 mpeg3_layer_t *layer_decoder;
581 mpeg3_pcm_t *pcm_decoder;
583 /* In order of importance */
584 long outscale;
585 /* Number of current frame being decoded */
586 int framenum;
588 /* Size of frame including header */
589 int framesize;
590 /* Output from synthesizer in linear floats */
591 float **output;
592 /* Number of pcm samples in the buffer */
593 int output_size;
594 /* Allocated number of samples in output */
595 int output_allocated;
596 /* Sample position in file of start of output buffer */
597 int output_position;
599 /* Perform a seek to the sample */
600 int sample_seek;
601 /* Perform a seek to the absolute byte */
602 int64_t byte_seek;
603 /* +/- number of samples of difference between audio and video */
604 int seek_correction;
605 /* Buffer containing current packet */
606 unsigned char packet_buffer[MAXFRAMESIZE];
607 /* Position in packet buffer of next byte to read */
608 int packet_position;
609 } mpeg3audio_t;
615 typedef struct
617 /* Buffer of frames for index. A frame is a high/low pair. */
618 float **index_data;
619 /* Number of frames allocated in each index channel. */
620 int index_allocated;
621 /* Number of index channels allocated */
622 int index_channels;
623 /* Number of high/low pairs in index channel */
624 int index_size;
625 /* Downsampling of index buffers when constructing index */
626 int index_zoom;
627 } mpeg3_index_t;
631 typedef struct
633 int channels;
634 int sample_rate;
635 mpeg3_demuxer_t *demuxer;
636 mpeg3audio_t *audio;
637 int current_position;
638 int total_samples;
639 int format; /* format of audio */
640 unsigned int pid;
641 /* If we got the header information yet. Used in streaming mode. */
642 int got_header;
646 /* Pointer to master table of contents when the TOC is read. */
647 /* Pointer to private table when the TOC is being created */
648 /* Stores the absolute byte of each audio chunk */
649 int64_t *sample_offsets;
650 int total_sample_offsets;
651 int sample_offsets_allocated;
652 /* If this sample offset table must be deleted by the track */
653 int private_offsets;
654 /* End of stream in table of contents construction */
655 int64_t audio_eof;
660 /* Starting byte of previous packet for making TOC */
661 int64_t prev_offset;
663 } mpeg3_atrack_t;
674 // Video
685 /* zig-zag scan */
686 extern unsigned char mpeg3_zig_zag_scan_nommx[64];
688 /* alternate scan */
689 extern unsigned char mpeg3_alternate_scan_nommx[64];
691 /* default intra quantization matrix */
692 extern unsigned char mpeg3_default_intra_quantizer_matrix[64];
694 /* Frame rate table must agree with the one in the encoder */
695 extern double mpeg3_frame_rate_table[16];
697 /* non-linear quantization coefficient table */
698 extern unsigned char mpeg3_non_linear_mquant_table[32];
700 #define CHROMA420 1 /* chroma_format */
701 #define CHROMA422 2
702 #define CHROMA444 3
704 #define TOP_FIELD 1 /* picture structure */
705 #define BOTTOM_FIELD 2
706 #define FRAME_PICTURE 3
708 #define SEQ_ID 1 /* extension start code IDs */
709 #define DISP_ID 2
710 #define QUANT_ID 3
711 #define SEQSCAL_ID 5
712 #define PANSCAN_ID 7
713 #define CODING_ID 8
714 #define SPATSCAL_ID 9
715 #define TEMPSCAL_ID 10
717 #define SC_NONE 0 /* scalable_mode */
718 #define SC_DP 1
719 #define SC_SPAT 2
720 #define SC_SNR 3
721 #define SC_TEMP 4
723 #define I_TYPE 1 /* picture coding type */
724 #define P_TYPE 2
725 #define B_TYPE 3
726 #define D_TYPE 4
728 #define MB_INTRA 1 /* macroblock type */
729 #define MB_PATTERN 2
730 #define MB_BACKWARD 4
731 #define MB_FORWARD 8
732 #define MB_QUANT 16
733 #define MB_WEIGHT 32
734 #define MB_CLASS4 64
736 #define MC_FIELD 1 /* motion_type */
737 #define MC_FRAME 2
738 #define MC_16X8 2
739 #define MC_DMV 3
741 #define MV_FIELD 0 /* mv_format */
742 #define MV_FRAME 1
754 /* Array of these feeds the slice decoders */
755 typedef struct
757 unsigned char *data; /* Buffer for holding the slice data */
758 int buffer_size; /* Size of buffer */
759 int buffer_allocation; /* Space allocated for buffer */
760 int current_position; /* Position in buffer */
761 uint32_t bits;
762 int bits_size;
763 pthread_mutex_t completion_lock; /* Lock slice until completion */
764 int done; /* Signal for slice decoder to skip */
765 } mpeg3_slice_buffer_t;
767 /* Each slice decoder */
768 typedef struct
770 void *video; /* mpeg3video_t */
771 mpeg3_slice_buffer_t *slice_buffer;
773 int thread_number; /* Number of this thread */
774 int current_buffer; /* Buffer this slice decoder is on */
775 int buffer_step; /* Number of buffers to skip */
776 int last_buffer; /* Last buffer this decoder should process */
777 int fault;
778 int done;
779 int quant_scale;
780 int pri_brk; /* slice/macroblock */
781 short block[12][64];
782 int sparse[12];
783 pthread_t tid; /* ID of thread */
784 pthread_mutex_t input_lock, output_lock, completion_lock;
785 } mpeg3_slice_t;
787 typedef struct
789 int hour;
790 int minute;
791 int second;
792 int frame;
793 } mpeg3_timecode_t;
796 typedef struct
798 void* file;
799 void* track;
801 /* ================================= Seeking variables ========================= */
802 mpeg3_bits_t *vstream;
803 int decoder_initted;
804 unsigned char **output_rows; /* Output frame buffer supplied by user */
805 int in_x, in_y, in_w, in_h, out_w, out_h; /* Output dimensions */
806 int row_span;
807 int *x_table, *y_table; /* Location of every output pixel in the input */
808 int color_model;
809 int want_yvu; /* Want to return a YUV frame */
810 char *y_output, *u_output, *v_output; /* Output pointers for a YUV frame */
812 mpeg3_slice_t slice_decoders[MPEG3_MAX_CPUS]; /* One slice decoder for every CPU */
813 int total_slice_decoders; /* Total slice decoders in use */
814 mpeg3_slice_buffer_t slice_buffers[MPEG3_MAX_CPUS]; /* Buffers for holding the slice data */
815 int total_slice_buffers; /* Total buffers in the array to be decompressed */
816 int slice_buffers_initialized; /* Total buffers initialized in the array */
817 pthread_mutex_t slice_lock; /* Lock slice array while getting the next buffer */
818 pthread_mutex_t test_lock;
820 int blockreadsize;
821 int maxframe; /* Max value of frame num to read */
822 int64_t byte_seek; /* Perform absolute byte seek before the next frame is read */
823 int frame_seek; /* Perform a frame seek before the next frame is read */
824 int framenum; /* Number of the next frame to be decoded */
825 int last_number; /* Last framenum rendered */
826 int found_seqhdr;
827 int bitrate;
828 mpeg3_timecode_t gop_timecode; /* Timecode for the last GOP header read. */
829 int has_gops; /* Some streams have no GOPs so try sequence start codes instead */
831 /* These are only available from elementary streams. */
832 int frames_per_gop; /* Frames per GOP after the first GOP. */
833 int first_gop_frames; /* Frames in the first GOP. */
834 int first_frame; /* Number of first frame stored in timecode */
835 int last_frame; /* Last frame in file */
837 /* ================================= Compression variables ===================== */
838 /* Malloced frame buffers. 2 refframes are swapped in and out. */
839 /* while only 1 auxframe is used. */
840 unsigned char *yuv_buffer[5]; /* Make YVU buffers contiguous for all frames */
841 unsigned char *oldrefframe[3], *refframe[3], *auxframe[3];
842 unsigned char *llframe0[3], *llframe1[3];
843 unsigned char *mpeg3_zigzag_scan_table;
844 unsigned char *mpeg3_alternate_scan_table;
845 // Source for the next frame presentation
846 unsigned char **output_src;
847 /* Pointers to frame buffers. */
848 unsigned char *newframe[3];
849 int horizontal_size, vertical_size, mb_width, mb_height;
850 int coded_picture_width, coded_picture_height;
851 int chroma_format, chrom_width, chrom_height, blk_cnt;
852 int pict_type;
853 int field_sequence;
854 int forw_r_size, back_r_size, full_forw, full_back;
855 int prog_seq, prog_frame;
856 int h_forw_r_size, v_forw_r_size, h_back_r_size, v_back_r_size;
857 int dc_prec, pict_struct, topfirst, frame_pred_dct, conceal_mv;
858 int intravlc;
859 int repeatfirst;
860 /* Number of times to repeat the current frame * 100 since floating point is impossible in MMX */
861 int repeat_count;
862 /* Number of times the current frame has been repeated * 100 */
863 int current_repeat;
864 int secondfield;
865 int skip_bframes;
866 int stwc_table_index, llw, llh, hm, hn, vm, vn;
867 int lltempref, llx0, lly0, llprog_frame, llfieldsel;
868 int matrix_coefficients;
869 int framerate_code;
870 double frame_rate;
871 int *cr_to_r, *cr_to_g, *cb_to_g, *cb_to_b;
872 int *cr_to_r_ptr, *cr_to_g_ptr, *cb_to_g_ptr, *cb_to_b_ptr;
873 int intra_quantizer_matrix[64], non_intra_quantizer_matrix[64];
874 int chroma_intra_quantizer_matrix[64], chroma_non_intra_quantizer_matrix[64];
875 int mpeg2;
876 int qscale_type, altscan; /* picture coding extension */
877 int pict_scal; /* picture spatial scalable extension */
878 int scalable_mode; /* sequence scalable extension */
879 } mpeg3video_t;
895 typedef struct
897 int width;
898 int height;
899 double frame_rate;
900 float aspect_ratio;
901 mpeg3_demuxer_t *demuxer;
902 mpeg3video_t *video;
903 int current_position; /* Number of next frame to be played */
904 int total_frames; /* Total frames in the file */
905 unsigned int pid;
908 /* Pointer to master table of contents when the TOC is read. */
909 /* Pointer to private table when the TOC is being created */
910 /* Stores the absolute byte of each frame */
911 int64_t *frame_offsets;
912 int total_frame_offsets;
913 int frame_offsets_allocated;
914 int64_t *keyframe_numbers;
915 int total_keyframe_numbers;
916 int keyframe_numbers_allocated;
917 /* Starting byte of previous packet for making TOC */
918 int64_t prev_offset;
919 /* End of stream in table of contents construction */
920 int64_t video_eof;
922 /* If these tables must be deleted by the track */
923 int private_offsets;
924 } mpeg3_vtrack_t;
935 // Whole thing
936 typedef struct
938 /* Store entry path here */
939 mpeg3_fs_t *fs;
940 /* Master title tables copied to all tracks */
941 mpeg3_demuxer_t *demuxer;
943 /* Media specific */
944 int total_astreams;
945 int total_vstreams;
946 mpeg3_atrack_t *atrack[MPEG3_MAX_STREAMS];
947 mpeg3_vtrack_t *vtrack[MPEG3_MAX_STREAMS];
950 /* Table of contents storage */
951 int64_t **frame_offsets;
952 int64_t **sample_offsets;
953 int64_t **keyframe_numbers;
954 int64_t *video_eof;
955 int64_t *audio_eof;
956 int *total_frame_offsets;
957 int *total_sample_offsets;
958 int *total_keyframe_numbers;
959 /* Handles changes in channel count after the start of a stream */
960 int *channel_counts;
961 /* Indexes for audio tracks */
962 mpeg3_index_t **indexes;
963 int total_indexes;
966 /* Number of bytes to devote to the index of a single track in the index */
967 /* building process. */
968 int64_t index_bytes;
970 /* Only one of these is set to 1 to specify what kind of stream we have. */
971 int is_transport_stream;
972 int is_program_stream;
973 int is_ifo_file;
974 int is_audio_stream; /* Elemental stream */
975 int is_video_stream; /* Elemental stream */
976 /* > 0 if known otherwise determine empirically for every packet */
977 int packet_size;
978 /* Type and stream for getting current absolute byte */
979 int last_type_read; /* 1 - audio 2 - video */
980 int last_stream_read;
982 /* Number of program to play */
983 int program;
984 int cpus;
986 /* Filesystem is seekable. Also means the file isn't a stream. */
987 int seekable;
989 /* For building TOC, the output file. */
990 FILE *toc_fd;
993 * After byte seeking is called, this is set to -1.
994 * The first operation to seek needs to set it to the pts of the byte seek.
995 * Then the next operation to seek needs to match its pts to this value.
997 int64_t byte_pts;
998 } mpeg3_t;
1003 #endif