Merge commit 'svn/origin' into devel
[cinelerra_cv/ct.git] / libmpeg3 / mpeg3private.h
blob935e926544fdd86008aab15c07107d6c79f50e0c
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 7
17 #define MPEG3_RELEASE 0
19 #define RENDERFARM_FS_PREFIX "vfs://"
22 #define MPEG3_FLOAT32 float
24 #define MPEG3_TOC_PREFIX 0x544f4320
25 // This decreases with every new version
26 #define MPEG3_TOC_VERSION 0x000000fa
27 #define MPEG3_ID3_PREFIX 0x494433
28 #define MPEG3_IFO_PREFIX 0x44564456
29 #define MPEG3_IO_SIZE 0x100000 /* Bytes read by mpeg3io at a time */
30 //#define MPEG3_IO_SIZE 0x800 /* Bytes read by mpeg3io at a time */
31 #define MPEG3_RIFF_CODE 0x52494646
32 #define MPEG3_PROC_CPUINFO "/proc/cpuinfo"
33 #define MPEG3_RAW_SIZE 0x100000 /* Largest possible packet */
34 #define MPEG3_BD_PACKET_SIZE 192
35 #define MPEG3_TS_PACKET_SIZE 188
36 #define MPEG3_DVD_PACKET_SIZE 0x800
37 #define MPEG3_SYNC_BYTE 0x47
38 #define MPEG3_PACK_START_CODE 0x000001ba
39 #define MPEG3_SEQUENCE_START_CODE 0x000001b3
40 #define MPEG3_SEQUENCE_END_CODE 0x000001b7
41 #define MPEG3_SYSTEM_START_CODE 0x000001bb
42 #define MPEG3_STRLEN 1024
43 #define MPEG3_PIDMAX 256 /* Maximum number of PIDs in one stream */
44 #define MPEG3_PROGRAM_ASSOCIATION_TABLE 0x00
45 #define MPEG3_CONDITIONAL_ACCESS_TABLE 0x01
46 #define MPEG3_PACKET_START_CODE_PREFIX 0x000001
47 #define MPEG3_PRIVATE_STREAM_2 0xbf
48 #define MPEG3_PADDING_STREAM 0xbe
49 #define MPEG3_GOP_START_CODE 0x000001b8
50 #define MPEG3_PICTURE_START_CODE 0x00000100
51 #define MPEG3_EXT_START_CODE 0x000001b5
52 #define MPEG3_USER_START_CODE 0x000001b2
53 #define MPEG3_SLICE_MIN_START 0x00000101
54 #define MPEG3_SLICE_MAX_START 0x000001af
55 #define MPEG3_AC3_START_CODE 0x0b77
56 #define MPEG3_PCM_START_CODE 0x7f7f807f
57 #define MPEG3_MAX_CPUS 256
58 #define MPEG3_MAX_STREAMS 0x10000
59 #define MPEG3_MAX_PACKSIZE 262144
60 /* Maximum number of complete subtitles to buffer in a subtitle track */
61 /* or number of incomplete subtitles to buffer in demuxer. */
62 #define MPEG3_MAX_SUBTITLES 5
63 /* Positive difference before declaring timecodes discontinuous */
64 #define MPEG3_CONTIGUOUS_THRESHOLD 10
65 /* Minimum number of seconds before interleaving programs */
66 #define MPEG3_PROGRAM_THRESHOLD 5
67 /* Number of frames difference before absolute seeking */
68 #define MPEG3_SEEK_THRESHOLD 16
69 /* Size of chunk of audio in table of contents */
70 #define MPEG3_AUDIO_CHUNKSIZE 0x10000
71 /* Minimum amount of data required to read an audio packet in streaming mode. */
72 #define MPEG3_AUDIO_STREAM_SIZE 0x1000
73 /* Minimum amount of data required to read a video header in streaming mode. */
74 #define MPEG3_VIDEO_STREAM_SIZE 0x1000
75 #define MPEG3_LITTLE_ENDIAN ((*(uint32_t*)"x\0\0\0") & 0x000000ff)
76 /* Number of samples in audio history */
77 #define MPEG3_AUDIO_HISTORY 0x100000
78 /* Range to scan for pts after byte seek */
79 #define MPEG3_PTS_RANGE 0x100000
81 /* Values for audio format */
82 #define AUDIO_UNKNOWN 0
83 #define AUDIO_MPEG 1
84 #define AUDIO_AC3 2
85 #define AUDIO_PCM 3
86 #define AUDIO_AAC 4
87 #define AUDIO_JESUS 5
90 /* Table of contents sections */
91 #define FILE_TYPE_PROGRAM 0x00000000
92 #define FILE_TYPE_TRANSPORT 0x00000001
93 #define FILE_TYPE_AUDIO 0x00000002
94 #define FILE_TYPE_VIDEO 0x00000003
96 #define STREAM_AUDIO 0x00000004
97 #define STREAM_VIDEO 0x00000005
98 #define STREAM_SUBTITLE 0x00000006
100 #define OFFSETS_AUDIO 0x00000007
101 #define OFFSETS_VIDEO 0x00000008
103 #define ATRACK_COUNT 0x9
104 #define VTRACK_COUNT 0xa
105 #define STRACK_COUNT 0xb
107 #define TITLE_PATH 0xc
108 #define IFO_PALETTE 0xd
109 #define FILE_INFO 0xe
111 // Combine the pid and the stream id into one unit
112 #define CUSTOM_ID(pid, stream_id) (((pid << 8) | stream_id) & 0xffff)
113 #define CUSTOM_ID_PID(id) (id >> 8)
114 #define CUSTOM_ID_STREAMID(id) (id & 0xff)
116 #ifndef MAX
117 #define MAX(a, b) ((a) > (b) ? (a) : (b))
118 #endif
120 #ifndef MIN
121 #define MIN(a, b) ((a) < (b) ? (a) : (b))
122 #endif
125 // CSS
133 struct mpeg3_block
135 unsigned char b[5];
138 struct mpeg3_playkey
140 int offset;
141 unsigned char key[5];
144 typedef struct
146 int encrypted;
147 char device_path[MPEG3_STRLEN]; /* Device the file is located on */
148 unsigned char disk_key[MPEG3_DVD_PACKET_SIZE];
149 unsigned char title_key[5];
150 char challenge[10];
151 struct mpeg3_block key1;
152 struct mpeg3_block key2;
153 struct mpeg3_block keycheck;
154 int varient;
155 int fd;
156 char path[MPEG3_STRLEN];
157 } mpeg3_css_t;
168 // I/O
180 /* Filesystem structure */
181 /* We buffer in MPEG3_IO_SIZE buffers. Stream IO would require back */
182 /* buffering a buffer since the stream must be rewound for packet headers, */
183 /* sequence start codes, format parsing, decryption, and mpeg3cat. */
187 typedef struct
189 FILE *fd;
190 mpeg3_css_t *css; /* Encryption object */
191 char path[MPEG3_STRLEN];
192 unsigned char *buffer; /* Readahead buffer */
193 int64_t buffer_offset; /* Current buffer position */
194 int64_t buffer_size; /* Bytes in buffer */
195 int64_t buffer_position; /* Byte in file of start of buffer */
197 /* Hypothetical position of file pointer */
198 int64_t current_byte;
199 int64_t total_bytes;
200 } mpeg3_fs_t;
209 // Table of contents
218 // May get rid of time values and rename to a cell offset table.
219 // May also get rid of end byte.
220 typedef struct
222 /* Starting byte of cell in the title (start_byte) */
223 int64_t title_start;
224 /* Ending byte of cell in the title (end_byte) */
225 int64_t title_end;
226 /* Starting byte of the cell in the program */
227 int64_t program_start;
228 /* Ending byte of the cell in the program */
229 int64_t program_end;
230 /* Program the cell belongs to */
231 int program;
232 } mpeg3_cell_t;
234 typedef struct
236 void *file;
237 mpeg3_fs_t *fs;
238 /* Total bytes in title file. Critical for seeking and length. */
239 int64_t total_bytes;
240 /* Absolute starting byte of the title in the stream */
241 int64_t start_byte;
242 /* Absolute ending byte of the title in the stream + 1 */
243 int64_t end_byte;
244 /* Timecode table */
245 mpeg3_cell_t *cell_table;
246 int cell_table_size; /* Number of entries */
247 int cell_table_allocation; /* Number of available slots */
248 } mpeg3_title_t;
257 /* Subtitle object. */
258 /* Created by the demuxer to store subtitles. */
266 typedef struct
268 /* Raw data of subtitle */
269 unsigned char *data;
270 /* number of bytes of data */
271 int size;
272 /* Number of stream starting at 0x20 */
273 int id;
274 int done;
275 /* Program offset of start of subtitle */
276 int64_t offset;
278 /* image in YUV 4:2:0 */
279 unsigned char *image_y;
280 unsigned char *image_u;
281 unsigned char *image_v;
282 unsigned char *image_a;
283 int x1;
284 int x2;
285 int y1;
286 int y2;
287 int w;
288 int h;
289 /* Force display */
290 int force;
291 /* Time after detection of subtitle to display it in 1/100sec */
292 int start_time;
293 /* Time after detection of subtitle to hide it in 1/100sec */
294 int stop_time;
295 /* Indexes in the main palette */
296 int palette[4];
297 int alpha[4];
298 /* The subtitle is being drawn */
299 int active;
300 } mpeg3_subtitle_t;
309 // Demuxer
320 typedef struct
322 /* mpeg3_t */
323 void* file;
324 /* One unparsed packet. MPEG3_RAW_SIZE allocated since we don't know the packet size */
325 unsigned char *raw_data;
326 /* Offset in raw_data of read pointer */
327 int raw_offset;
328 /* Amount loaded in last raw_data */
329 int raw_size;
332 /* Elementary stream data when only one stream is to be read. */
333 /* Erased in every call to read a packet. */
334 unsigned char *data_buffer;
335 /* Allocation of data_buffer */
336 int data_allocated;
337 /* Position in data_buffer of write pointer */
338 int data_size;
339 /* Position in data_buffer of read pointer */
340 int data_position;
341 /* Start of the next pes packet in the data buffer for reading. */
342 /* Used for decoding PCM. */
343 int data_start;
345 /* Elementary stream data when all streams are to be read. There is no */
346 /* read pointer since data is expected to be copied directly to a track. */
347 /* Some packets contain audio and video. Further division into */
348 /* stream ID may be needed. */
349 unsigned char *audio_buffer;
350 int audio_allocated;
351 int audio_size;
352 int audio_start;
353 unsigned char *video_buffer;
354 int video_allocated;
355 int video_size;
356 int video_start;
359 /* Subtitle objects */
360 mpeg3_subtitle_t **subtitles;
361 int total_subtitles;
367 /* What type of data to read. */
368 int do_audio;
369 int do_video;
370 int read_all;
372 /* Direction of reads */
373 int reverse;
374 /* Set to 1 when eof or attempt to read before beginning */
375 int error_flag;
376 /* Temp variables for returning */
377 unsigned char next_char;
378 /* Info for mpeg3cat */
379 int64_t last_packet_start;
380 int64_t last_packet_end;
381 int64_t last_packet_decryption;
383 /* Titles */
384 mpeg3_title_t *titles[MPEG3_MAX_STREAMS];
385 int total_titles;
386 /* Title currently being used */
387 int current_title;
390 /* Tables of every stream ID encountered */
391 int astream_table[MPEG3_MAX_STREAMS]; /* macro of audio format if audio */
392 int vstream_table[MPEG3_MAX_STREAMS]; /* 1 if video */
394 /* Programs */
395 int total_programs;
396 int current_program;
398 /* Cell in the current title currently used */
399 int title_cell;
401 /* Byte position in current program. */
402 int64_t program_byte;
403 /* Total bytes in all titles */
404 int64_t total_bytes;
405 /* The end of the current stream in the current program */
406 int64_t stream_end;
408 int transport_error_indicator;
409 int payload_unit_start_indicator;
410 /* PID of last packet */
411 int pid;
412 /* Stream ID of last packet */
413 unsigned int stream_id;
414 /* Custom ID of last packet */
415 unsigned int custom_id;
416 int transport_scrambling_control;
417 int adaptation_field_control;
418 int continuity_counter;
419 int is_padding;
420 int pid_table[MPEG3_PIDMAX];
421 int continuity_counters[MPEG3_PIDMAX];
422 int total_pids;
423 int adaptation_fields;
424 double time; /* Time in seconds */
425 int audio_pid;
426 int video_pid;
427 int got_audio;
428 int got_video;
429 /* if subtitle object was created in last packet */
430 int got_subtitle;
431 /* When only one stream is to be read, these store the stream IDs */
432 /* Video stream ID being decoded. -1 = select first ID in stream */
433 int astream;
434 /* Audio stream ID being decoded. -1 = select first ID in stream */
435 int vstream;
436 /* Multiplexed streams have the audio type */
437 /* Format of the audio derived from multiplexing codes */
438 int aformat;
439 int program_association_tables;
440 int table_id;
441 int section_length;
442 int transport_stream_id;
443 int pes_packets;
444 double pes_audio_time; /* Presentation Time stamps */
445 double pes_video_time; /* Presentation Time stamps */
446 /* Cause the stream parameters to be dumped in human readable format */
447 int dump;
448 } mpeg3_demuxer_t;
457 // Bitstream
468 // next bit in forward direction
469 // next bit in reverse direction |
470 // v v
471 // | | | | | | | | | | | | | | | | | | | | | | | | | | |1|1|1|1|1|1| */
472 // ^ ^
473 // | bit_number = 1
474 // bfr_size = 6
476 typedef struct
478 uint32_t bfr; /* bfr = buffer for bits */
479 int bit_number; /* position of pointer in bfr */
480 int bfr_size; /* number of bits in bfr. Should always be a multiple of 8 */
481 void *file; /* Mpeg2 file */
482 mpeg3_demuxer_t *demuxer; /* Mpeg2 demuxer */
483 /* If the input ptr is true, data is read from it instead of the demuxer. */
484 unsigned char *input_ptr;
485 } mpeg3_bits_t;
496 // Audio
504 #define AC3_N 512
506 #define MAXFRAMESIZE 4096
507 #define MAXFRAMESAMPLES 65536
508 #define HDRCMPMASK 0xfffffd00
509 #define SBLIMIT 32
510 #define SSLIMIT 18
511 #define SCALE_BLOCK 12
512 #define MPEG3AUDIO_PADDING 1024
514 /* Values for mode */
515 #define MPG_MD_STEREO 0
516 #define MPG_MD_JOINT_STEREO 1
517 #define MPG_MD_DUAL_CHANNEL 2
518 #define MPG_MD_MONO 3
521 #define MAX_AC3_FRAMESIZE 1920 * 2 + 512
523 extern int mpeg3_ac3_samplerates[3];
525 /* Exponent strategy constants */
526 #define MPEG3_EXP_REUSE (0)
527 #define MPEG3_EXP_D15 (1)
528 #define MPEG3_EXP_D25 (2)
529 #define MPEG3_EXP_D45 (3)
531 /* Delta bit allocation constants */
532 #define DELTA_BIT_REUSE (0)
533 #define DELTA_BIT_NEW (1)
534 #define DELTA_BIT_NONE (2)
535 #define DELTA_BIT_RESERVED (3)
541 // Layered decoder
543 typedef struct
545 mpeg3_bits_t *stream;
548 // Layer 3
549 unsigned char *bsbuf, *bsbufold;
550 unsigned char bsspace[2][MAXFRAMESIZE + 512]; /* MAXFRAMESIZE */
551 int bsnum;
552 long framesize; /* For mp3 current framesize without header. For AC3 current framesize with header. */
553 long prev_framesize;
554 int channels;
555 int samplerate;
556 int single;
557 int sampling_frequency_code;
558 int error_protection;
559 int mode;
560 int mode_ext;
561 int lsf;
562 long ssize;
563 int mpeg35;
564 int padding;
565 int layer;
566 int extension;
567 int copyright;
568 int original;
569 int emphasis;
570 int bitrate;
571 /* Static variable in synthesizer */
572 int bo;
573 /* Ignore first frame after a seek */
574 int first_frame;
576 float synth_stereo_buffs[2][2][0x110];
577 float synth_mono_buff[64];
578 float mp3_block[2][2][SBLIMIT * SSLIMIT];
579 int mp3_blc[2];
583 // Layer 2
584 int bitrate_index;
585 struct al_table *alloc;
586 int jsbound;
587 int II_sblimit;
588 unsigned int layer2_scfsi_buf[64];
589 } mpeg3_layer_t;
595 // AC3 decoder
597 typedef struct
599 mpeg3_bits_t *stream;
600 int samplerate;
601 int bitrate;
602 int flags;
603 int channels;
604 void *state; /* a52_state_t */
605 void *output; /* sample_t */
606 int framesize;
607 } mpeg3_ac3_t;
612 // PCM decoder
614 #define PCM_HEADERSIZE 20
615 typedef struct
617 int samplerate;
618 int bits;
619 int channels;
620 int framesize;
621 } mpeg3_pcm_t;
628 /* IMDCT variables */
629 typedef struct
631 float real;
632 float imag;
633 } mpeg3_complex_t;
635 struct al_table
637 short bits;
638 short d;
642 typedef struct
644 void* file;
645 void* track;
647 mpeg3_ac3_t *ac3_decoder;
648 mpeg3_layer_t *layer_decoder;
649 mpeg3_pcm_t *pcm_decoder;
651 /* In order of importance */
652 long outscale;
653 /* Number of current frame being decoded */
654 int framenum;
656 /* Size of frame including header */
657 int framesize;
658 /* Output from synthesizer in linear floats */
659 float **output;
660 /* Number of pcm samples in the buffer */
661 int output_size;
662 /* Allocated number of samples in output */
663 int output_allocated;
664 /* Sample position in file of start of output buffer */
665 int output_position;
667 /* Perform a seek to the sample */
668 int sample_seek;
669 /* Perform a seek to the absolute byte */
670 int64_t byte_seek;
671 /* +/- number of samples of difference between audio and video */
672 int seek_correction;
673 /* Buffer containing current packet */
674 unsigned char packet_buffer[MAXFRAMESIZE];
675 /* Position in packet buffer of next byte to read */
676 int packet_position;
677 } mpeg3audio_t;
683 typedef struct
685 /* Buffer of frames for index. A frame is a high/low pair. */
686 float **index_data;
687 /* Number of frames allocated in each index channel. */
688 int index_allocated;
689 /* Number of index channels allocated */
690 int index_channels;
691 /* Number of high/low pairs in index channel */
692 int index_size;
693 /* Downsampling of index buffers when constructing index */
694 int index_zoom;
695 } mpeg3_index_t;
699 typedef struct
701 int channels;
702 int sample_rate;
703 mpeg3_demuxer_t *demuxer;
704 mpeg3audio_t *audio;
705 int current_position;
706 int64_t total_samples;
707 int format; /* format of audio */
708 unsigned int pid;
709 /* If we got the header information yet. Used in streaming mode. */
710 int got_header;
714 /* Pointer to master table of contents when the TOC is read. */
715 /* Pointer to private table when the TOC is being created */
716 /* Stores the absolute byte of each audio chunk */
717 int64_t *sample_offsets;
718 int total_sample_offsets;
719 int sample_offsets_allocated;
720 /* If this sample offset table must be deleted by the track */
721 int private_offsets;
722 /* End of stream in table of contents construction */
723 int64_t audio_eof;
728 /* Starting byte of previous packet for making TOC */
729 int64_t prev_offset;
731 } mpeg3_atrack_t;
742 // Video
753 /* zig-zag scan */
754 extern unsigned char mpeg3_zig_zag_scan_nommx[64];
756 /* alternate scan */
757 extern unsigned char mpeg3_alternate_scan_nommx[64];
759 /* default intra quantization matrix */
760 extern unsigned char mpeg3_default_intra_quantizer_matrix[64];
762 /* Frame rate table must agree with the one in the encoder */
763 extern double mpeg3_frame_rate_table[16];
765 /* non-linear quantization coefficient table */
766 extern unsigned char mpeg3_non_linear_mquant_table[32];
768 #define CHROMA420 1 /* chroma_format */
769 #define CHROMA422 2
770 #define CHROMA444 3
772 #define TOP_FIELD 1 /* picture structure */
773 #define BOTTOM_FIELD 2
774 #define FRAME_PICTURE 3
776 #define SEQ_ID 1 /* extension start code IDs */
777 #define DISP_ID 2
778 #define QUANT_ID 3
779 #define SEQSCAL_ID 5
780 #define PANSCAN_ID 7
781 #define CODING_ID 8
782 #define SPATSCAL_ID 9
783 #define TEMPSCAL_ID 10
785 #define SC_NONE 0 /* scalable_mode */
786 #define SC_DP 1
787 #define SC_SPAT 2
788 #define SC_SNR 3
789 #define SC_TEMP 4
791 #define I_TYPE 1 /* picture coding type */
792 #define P_TYPE 2
793 #define B_TYPE 3
794 #define D_TYPE 4
796 #define MB_INTRA 1 /* macroblock type */
797 #define MB_PATTERN 2
798 #define MB_BACKWARD 4
799 #define MB_FORWARD 8
800 #define MB_QUANT 16
801 #define MB_WEIGHT 32
802 #define MB_CLASS4 64
804 #define MC_FIELD 1 /* motion_type */
805 #define MC_FRAME 2
806 #define MC_16X8 2
807 #define MC_DMV 3
809 #define MV_FIELD 0 /* mv_format */
810 #define MV_FRAME 1
822 /* Array of these feeds the slice decoders */
823 typedef struct
825 unsigned char *data; /* Buffer for holding the slice data */
826 int buffer_size; /* Size of buffer */
827 int buffer_allocation; /* Space allocated for buffer */
828 int current_position; /* Position in buffer */
829 uint32_t bits;
830 int bits_size;
831 pthread_mutex_t completion_lock; /* Lock slice until completion */
832 int done; /* Signal for slice decoder to skip */
833 } mpeg3_slice_buffer_t;
835 /* Each slice decoder */
836 typedef struct
838 void *video; /* mpeg3video_t */
839 mpeg3_slice_buffer_t *slice_buffer;
841 int thread_number; /* Number of this thread */
842 int current_buffer; /* Buffer this slice decoder is on */
843 int buffer_step; /* Number of buffers to skip */
844 int last_buffer; /* Last buffer this decoder should process */
845 int fault;
846 int done;
847 int quant_scale;
848 int pri_brk; /* slice/macroblock */
849 short block[12][64];
850 int sparse[12];
851 pthread_t tid; /* ID of thread */
852 pthread_mutex_t input_lock, output_lock, completion_lock;
853 } mpeg3_slice_t;
855 typedef struct
857 int hour;
858 int minute;
859 int second;
860 int frame;
861 } mpeg3_timecode_t;
865 typedef struct
867 unsigned char *y, *u, *v;
868 int y_size;
869 int u_size;
870 int v_size;
871 int64_t frame_number;
872 } mpeg3_cacheframe_t;
874 typedef struct
876 mpeg3_cacheframe_t *frames;
877 int total;
878 int allocation;
879 } mpeg3_cache_t;
882 typedef struct
884 void* file;
885 void* track;
887 /* ================================= Seeking variables ========================= */
888 mpeg3_bits_t *vstream;
889 int decoder_initted;
890 unsigned char **output_rows; /* Output frame buffer supplied by user */
891 int in_x, in_y, in_w, in_h, out_w, out_h; /* Output dimensions */
892 int row_span;
893 int *x_table, *y_table; /* Location of every output pixel in the input */
894 int color_model;
895 int want_yvu; /* Want to return a YUV frame */
896 char *y_output, *u_output, *v_output; /* Output pointers for a YUV frame */
898 mpeg3_slice_t slice_decoders[MPEG3_MAX_CPUS]; /* One slice decoder for every CPU */
899 int total_slice_decoders; /* Total slice decoders in use */
900 mpeg3_slice_buffer_t slice_buffers[MPEG3_MAX_CPUS]; /* Buffers for holding the slice data */
901 int total_slice_buffers; /* Total buffers in the array to be decompressed */
902 int slice_buffers_initialized; /* Total buffers initialized in the array */
903 pthread_mutex_t slice_lock; /* Lock slice array while getting the next buffer */
904 pthread_mutex_t test_lock;
906 int blockreadsize;
907 int maxframe; /* Max value of frame num to read */
908 int64_t byte_seek; /* Perform absolute byte seek before the next frame is read */
909 int frame_seek; /* Perform a frame seek before the next frame is read */
910 int framenum; /* Number of the next frame to be decoded */
911 int last_number; /* Last framenum rendered */
912 int found_seqhdr;
913 int bitrate;
914 mpeg3_timecode_t gop_timecode; /* Timecode for the last GOP header read. */
915 int has_gops; /* Some streams have no GOPs so try sequence start codes instead */
917 /* These are only available from elementary streams. */
918 int frames_per_gop; /* Frames per GOP after the first GOP. */
919 int first_gop_frames; /* Frames in the first GOP. */
920 int first_frame; /* Number of first frame stored in timecode */
921 int last_frame; /* Last frame in file */
923 /* ================================= Compression variables ===================== */
924 /* Malloced frame buffers. 2 refframes are swapped in and out. */
925 /* while only 1 auxframe is used. */
926 unsigned char *yuv_buffer[5]; /* Make YVU buffers contiguous for all frames */
927 unsigned char *oldrefframe[3], *refframe[3], *auxframe[3];
928 unsigned char *llframe0[3], *llframe1[3];
929 unsigned char *mpeg3_zigzag_scan_table;
930 unsigned char *mpeg3_alternate_scan_table;
931 // Source for the next frame presentation
932 unsigned char *output_src[3];
933 /* Pointers to frame buffers. */
934 unsigned char *newframe[3];
935 int horizontal_size, vertical_size, mb_width, mb_height;
936 int coded_picture_width, coded_picture_height;
937 int chroma_format, chrom_width, chrom_height, blk_cnt;
938 int pict_type;
939 int field_sequence;
940 int forw_r_size, back_r_size, full_forw, full_back;
941 int prog_seq, prog_frame;
942 int h_forw_r_size, v_forw_r_size, h_back_r_size, v_back_r_size;
943 int dc_prec, pict_struct, topfirst, frame_pred_dct, conceal_mv;
944 int intravlc;
945 int repeatfirst;
946 /* Number of times to repeat the current frame * 100 since floating point is impossible in MMX */
947 int repeat_count;
948 /* Number of times the current frame has been repeated * 100 */
949 int current_repeat;
950 int secondfield;
951 int skip_bframes;
952 int stwc_table_index, llw, llh, hm, hn, vm, vn;
953 int lltempref, llx0, lly0, llprog_frame, llfieldsel;
954 int matrix_coefficients;
955 int framerate_code;
956 double frame_rate;
957 int *cr_to_r, *cr_to_g, *cb_to_g, *cb_to_b;
958 int *cr_to_r_ptr, *cr_to_g_ptr, *cb_to_g_ptr, *cb_to_b_ptr;
959 int intra_quantizer_matrix[64], non_intra_quantizer_matrix[64];
960 int chroma_intra_quantizer_matrix[64], chroma_non_intra_quantizer_matrix[64];
961 int mpeg2;
962 int qscale_type, altscan; /* picture coding extension */
963 int pict_scal; /* picture spatial scalable extension */
964 int scalable_mode; /* sequence scalable extension */
966 /* Subtitling frame */
967 unsigned char *subtitle_frame[3];
968 } mpeg3video_t;
984 typedef struct
986 int width;
987 int height;
988 double frame_rate;
989 float aspect_ratio;
990 mpeg3_demuxer_t *demuxer;
991 /* Video decoding object */
992 mpeg3video_t *video;
993 /* Table of current subtitles being overlayed */
994 mpeg3_subtitle_t **subtitles;
995 int total_subtitles;
996 int current_position; /* Number of next frame to be played */
997 int total_frames; /* Total frames in the file */
998 unsigned int pid;
1001 /* Pointer to master table of contents when the TOC is read. */
1002 /* Pointer to private table when the TOC is being created */
1003 /* Stores the absolute byte of each frame */
1004 int64_t *frame_offsets;
1005 int total_frame_offsets;
1006 int frame_offsets_allocated;
1007 int64_t *keyframe_numbers;
1008 int total_keyframe_numbers;
1009 int keyframe_numbers_allocated;
1010 /* Starting byte of previous packet for making TOC */
1011 int64_t prev_offset;
1012 /* Starting byte of previous packet when the start code was found. */
1013 /* Used for headers which require multiple packets. */
1014 int64_t prev_frame_offset;
1015 /* End of stream in table of contents construction */
1016 int64_t video_eof;
1019 mpeg3_cache_t *frame_cache;
1023 /* If these tables must be deleted by the track */
1024 int private_offsets;
1025 } mpeg3_vtrack_t;
1033 /* Subtitle track */
1034 /* Stores the program offsets of subtitle images. */
1035 /* Only used for seeking off of table of contents for editing. */
1036 /* Doesn't have its own demuxer but hangs off the video demuxer. */
1038 typedef struct
1040 /* 0x2X */
1041 int id;
1042 /* Offsets in program of subtitle packets */
1043 int64_t *offsets;
1044 int total_offsets;
1045 int allocated_offsets;
1047 /* Last subtitle objects found in stream. */
1048 mpeg3_subtitle_t **subtitles;
1049 int total_subtitles;
1050 int allocated_subtitles;
1051 } mpeg3_strack_t;
1060 // Whole thing
1061 typedef struct
1063 /* Store entry path here */
1064 mpeg3_fs_t *fs;
1065 /* Master title tables copied to all tracks */
1066 mpeg3_demuxer_t *demuxer;
1068 /* Media specific */
1069 int total_astreams;
1070 mpeg3_atrack_t *atrack[MPEG3_MAX_STREAMS];
1071 int total_vstreams;
1072 mpeg3_vtrack_t *vtrack[MPEG3_MAX_STREAMS];
1073 int total_sstreams;
1074 mpeg3_strack_t *strack[MPEG3_MAX_STREAMS];
1076 /* Table of contents storage */
1077 int64_t **frame_offsets;
1078 int64_t **sample_offsets;
1079 int64_t **keyframe_numbers;
1080 int64_t *video_eof;
1081 int64_t *audio_eof;
1082 int *total_frame_offsets;
1083 int *total_sample_offsets;
1084 int64_t *total_samples;
1085 int *total_keyframe_numbers;
1086 /* Handles changes in channel count after the start of a stream */
1087 int *channel_counts;
1088 /* Indexes for audio tracks */
1089 mpeg3_index_t **indexes;
1090 int total_indexes;
1093 /* Number of bytes to devote to the index of a single track in the index */
1094 /* building process. */
1095 int64_t index_bytes;
1097 /* Only one of these is set to 1 to specify what kind of stream we have. */
1098 int is_transport_stream;
1099 int is_program_stream;
1100 int is_ifo_file;
1101 int is_audio_stream; /* Elemental stream */
1102 int is_video_stream; /* Elemental stream */
1103 // Special kind of transport stream
1104 int is_bd;
1105 /* > 0 if known otherwise determine empirically for every packet */
1106 int packet_size;
1107 /* Type and stream for getting current absolute byte */
1108 int last_type_read; /* 1 - audio 2 - video */
1109 int last_stream_read;
1111 /* Subtitle track to composite if >= 0 */
1112 int subtitle_track;
1114 /* Number of program to play */
1115 int program;
1116 int cpus;
1118 /* Filesystem is seekable. Also means the file isn't a stream. */
1119 int seekable;
1121 /* For building TOC, the output file. */
1122 FILE *toc_fd;
1125 * After byte seeking is called, this is set to -1.
1126 * The first operation to seek needs to set it to the pts of the byte seek.
1127 * Then the next operation to seek needs to match its pts to this value.
1129 int64_t byte_pts;
1132 * The first color palette in the IFO file. Used for subtitles.
1133 * Byte order: YUVX * 16
1135 int have_palette;
1136 unsigned char palette[16 * 4];
1138 /* Date of source file index was created from. */
1139 /* Used to compare DVD source file to table of contents source. */
1140 int64_t source_date;
1141 } mpeg3_t;
1146 #endif