"Fossies" - the Fresh Open Source Software Archive

Member "quicktime4linux-2.3/qtprivate.h" (5 Aug 2008, 16474 Bytes) of package /linux/privat/old/quicktime4linux-2.3-src.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 #ifndef PRIVATE_H
    2 #define PRIVATE_H
    3 
    4 /* ================================= structures */
    5 
    6 /* Version used internally.  You need to query it with the C functions */
    7 #define QUICKTIME_MAJOR 2
    8 #define QUICKTIME_MINOR 3
    9 #define QUICKTIME_RELEASE 0
   10 
   11 
   12 #define HEADER_LENGTH 8
   13 #define MAXTRACKS 1024
   14 
   15 /* Crazy Mich R. Soft constants */
   16 #define AVI_HASINDEX       0x00000010  // Index at end of file?
   17 #define AVI_MUSTUSEINDEX   0x00000020
   18 #define AVI_ISINTERLEAVED  0x00000100
   19 #define AVI_TRUSTCKTYPE    0x00000800  // Use CKType to find key frames?
   20 #define AVI_WASCAPTUREFILE 0x00010000
   21 #define AVI_COPYRIGHTED    0x00020000
   22 #define AVIF_WASCAPTUREFILE     0x00010000
   23 #define AVI_KEYFRAME       0x10
   24 #define AVI_INDEX_OF_CHUNKS 0x01
   25 #define AVI_INDEX_OF_INDEXES 0x00
   26 
   27 #define AVI_FRAME_RATE_BASE 10000
   28 #define MAX_RIFFS  0x100
   29 
   30 #define QT_TRACE printf("%s: %d\n", __FILE__, __LINE__);
   31 
   32 #include <stdio.h>
   33 #include <stdint.h>
   34 #include <stdlib.h>
   35 
   36 
   37 
   38 
   39 #define FTELL ftello64
   40 #define FSEEK fseeko64
   41 
   42 
   43 // ffmpeg requires global variable initialization
   44 // These are defined in mpeg4.c
   45 extern int ffmpeg_initialized;
   46 extern pthread_mutex_t ffmpeg_lock;
   47 
   48 
   49 
   50 // Utility functions for vbr audio.  This is accessed through quicktime_audio_map_t.
   51 typedef struct
   52 {
   53 // End of the output buffer in the file in samples
   54     int64_t buffer_end;
   55 // Number of samples in output buffer before end
   56     int buffer_size;
   57 // Position in output buffer of buffer_end
   58     int buffer_ptr;
   59 // Output buffer, linear for each channel.
   60     double **output_buffer;
   61 // Copy of channel count for deletion
   62     int channels;
   63 // Input buffer for temporary compressed data
   64     int input_size;
   65     int input_allocation;
   66     unsigned char *input_buffer;
   67 // Entry in sample size table of next frame of audio to read
   68     int sample_size_entry;
   69 // Next sample/frame to read
   70     int64_t sample;
   71 } quicktime_vbr_t;
   72 
   73 
   74 
   75 
   76 
   77 
   78 
   79 
   80 
   81 typedef struct
   82 {
   83 /* for AVI it's the end of the 8 byte header in the file */
   84 /* for Quicktime it's the start of the 8 byte header in the file */
   85     int64_t start;      
   86     int64_t end;        /* byte endpoint in file */
   87     int64_t size;       /* byte size for writing */
   88     int use_64;         /* Use 64 bit header */
   89     unsigned char type[5];
   90 } quicktime_atom_t;
   91 
   92 typedef struct
   93 {
   94     float values[9];
   95 } quicktime_matrix_t;
   96 
   97 
   98 typedef struct
   99 {
  100     int version;
  101     long flags;
  102     unsigned long creation_time;
  103     unsigned long modification_time;
  104     int track_id;
  105     long reserved1;
  106     long duration;
  107     char reserved2[8];
  108     int layer;
  109     int alternate_group;
  110     float volume;
  111     long reserved3;
  112     quicktime_matrix_t matrix;
  113     float track_width;
  114     float track_height;
  115 } quicktime_tkhd_t;
  116 
  117 
  118 typedef struct
  119 {
  120     long seed;
  121     long flags;
  122     long size;
  123     short int *alpha;
  124     short int *red;
  125     short int *green;
  126     short int *blue;
  127 } quicktime_ctab_t;
  128 
  129 
  130 
  131 /* ===================== sample table ======================== // */
  132 
  133 
  134 
  135 /* sample description */
  136 
  137 typedef struct
  138 {
  139     int motion_jpeg_quantization_table;
  140 } quicktime_mjqt_t;
  141 
  142 
  143 typedef struct
  144 {
  145     int motion_jpeg_huffman_table;
  146 } quicktime_mjht_t;
  147 
  148 
  149 typedef struct
  150 {
  151     char *mpeg4_header;
  152     int mpeg4_header_size;
  153 } quicktime_esds_t;
  154 
  155 typedef struct
  156 {
  157     char *data;
  158     int data_size;
  159 } quicktime_avcc_t;
  160 
  161 typedef struct
  162 {
  163     char *data;
  164     int data_size;
  165 } quicktime_frma_t;
  166 
  167 typedef struct
  168 {
  169     char format[4];
  170     char reserved[6];
  171     int data_reference;
  172 
  173 /* common to audio and video */
  174     int version;
  175     int revision;
  176     char vendor[4];
  177 
  178 /* video description */
  179     long temporal_quality;
  180     long spatial_quality;
  181     int width;
  182     int height;
  183     float dpi_horizontal;
  184     float dpi_vertical;
  185     int64_t data_size;
  186     int frames_per_sample;
  187     char compressor_name[32];
  188     int depth;
  189     int ctab_id;
  190     quicktime_ctab_t ctab;
  191     float gamma;
  192 /* 0, 1, or 2 */
  193     int fields;
  194 /* 0 - unknown     1 - top first     2 - bottom first */
  195     int field_dominance;
  196     quicktime_mjqt_t mjqt;
  197     quicktime_mjht_t mjht;
  198 
  199 /* audio description */
  200     int channels;
  201     int sample_size;
  202     int compression_id;
  203     int packet_size;
  204     float sample_rate;
  205 
  206 /* Version 1 of audio description */
  207     int samples_per_packet;
  208     int bytes_per_packet;
  209     int bytes_per_frame;
  210     int bytes_per_sample;
  211 
  212     quicktime_esds_t esds;
  213     quicktime_avcc_t avcc;
  214     quicktime_frma_t frma;
  215 } quicktime_stsd_table_t;
  216 
  217 
  218 typedef struct
  219 {
  220     int version;
  221     long flags;
  222     long total_entries;
  223     quicktime_stsd_table_t *table;
  224 } quicktime_stsd_t;
  225 
  226 
  227 /* time to sample */
  228 typedef struct
  229 {
  230     long sample_count;
  231     long sample_duration;
  232 } quicktime_stts_table_t;
  233 
  234 typedef struct
  235 {
  236     int version;
  237     long flags;
  238     long total_entries;
  239     int is_vbr;
  240     quicktime_stts_table_t *table;
  241 } quicktime_stts_t;
  242 
  243 
  244 /* sync sample */
  245 typedef struct
  246 {
  247     int64_t sample;
  248 } quicktime_stss_table_t;
  249 
  250 typedef struct
  251 {
  252     int version;
  253     long flags;
  254     long total_entries;
  255     long entries_allocated;
  256     quicktime_stss_table_t *table;
  257 } quicktime_stss_t;
  258 
  259 
  260 /* sample to chunk */
  261 typedef struct
  262 {
  263     long chunk;
  264     long samples;
  265     long id;
  266 } quicktime_stsc_table_t;
  267 
  268 typedef struct
  269 {
  270     int version;
  271     long flags;
  272     long total_entries;
  273     
  274     long entries_allocated;
  275     quicktime_stsc_table_t *table;
  276 } quicktime_stsc_t;
  277 
  278 
  279 /* sample size */
  280 typedef struct
  281 {
  282     int64_t size;
  283 } quicktime_stsz_table_t;
  284 
  285 typedef struct
  286 {
  287     int version;
  288     long flags;
  289     int64_t sample_size;
  290     long total_entries;
  291 
  292     long entries_allocated;    /* used by the library for allocating a table */
  293     quicktime_stsz_table_t *table;
  294 } quicktime_stsz_t;
  295 
  296 
  297 /* chunk offset */
  298 typedef struct
  299 {
  300     int64_t offset;
  301 } quicktime_stco_table_t;
  302 
  303 typedef struct
  304 {
  305     int version;
  306     long flags;
  307     long total_entries;
  308     
  309     long entries_allocated;    /* used by the library for allocating a table */
  310     quicktime_stco_table_t *table;
  311 } quicktime_stco_t;
  312 
  313 
  314 /* sample table */
  315 typedef struct
  316 {
  317     int version;
  318     long flags;
  319     quicktime_stsd_t stsd;
  320     quicktime_stts_t stts;
  321     quicktime_stss_t stss;
  322     quicktime_stsc_t stsc;
  323     quicktime_stsz_t stsz;
  324     quicktime_stco_t stco;
  325 } quicktime_stbl_t;
  326 
  327 /* data reference */
  328 
  329 typedef struct
  330 {
  331     int64_t size;
  332     char type[4];
  333     int version;
  334     long flags;
  335     char *data_reference;
  336 } quicktime_dref_table_t;
  337 
  338 typedef struct
  339 {
  340     int version;
  341     long flags;
  342     long total_entries;
  343     quicktime_dref_table_t *table;
  344 } quicktime_dref_t;
  345 
  346 /* data information */
  347 
  348 typedef struct
  349 {
  350     quicktime_dref_t dref;
  351 } quicktime_dinf_t;
  352 
  353 /* video media header */
  354 
  355 typedef struct
  356 {
  357     int version;
  358     long flags;
  359     int graphics_mode;
  360     int opcolor[3];
  361 } quicktime_vmhd_t;
  362 
  363 
  364 /* sound media header */
  365 
  366 typedef struct
  367 {
  368     int version;
  369     long flags;
  370     int balance;
  371     int reserved;
  372 } quicktime_smhd_t;
  373 
  374 /* handler reference */
  375 
  376 typedef struct
  377 {
  378     int version;
  379     long flags;
  380     char component_type[4];
  381     char component_subtype[4];
  382     long component_manufacturer;
  383     long component_flags;
  384     long component_flag_mask;
  385     char component_name[256];
  386 } quicktime_hdlr_t;
  387 
  388 /* media information */
  389 
  390 typedef struct
  391 {
  392     int is_video;
  393     int is_audio;
  394     quicktime_vmhd_t vmhd;
  395     quicktime_smhd_t smhd;
  396     quicktime_stbl_t stbl;
  397     quicktime_hdlr_t hdlr;
  398     quicktime_dinf_t dinf;
  399 } quicktime_minf_t;
  400 
  401 
  402 /* media header */
  403 
  404 typedef struct
  405 {
  406     int version;
  407     long flags;
  408     unsigned long creation_time;
  409     unsigned long modification_time;
  410     long time_scale;
  411     long duration;
  412     int language;
  413     int quality;
  414 } quicktime_mdhd_t;
  415 
  416 
  417 /* media */
  418 
  419 typedef struct
  420 {
  421     quicktime_mdhd_t mdhd;
  422     quicktime_minf_t minf;
  423     quicktime_hdlr_t hdlr;
  424 } quicktime_mdia_t;
  425 
  426 /* edit list */
  427 typedef struct
  428 {
  429     long duration;
  430     long time;
  431     float rate;
  432 } quicktime_elst_table_t;
  433 
  434 typedef struct
  435 {
  436     int version;
  437     long flags;
  438     long total_entries;
  439 
  440     quicktime_elst_table_t *table;
  441 } quicktime_elst_t;
  442 
  443 typedef struct
  444 {
  445     quicktime_elst_t elst;
  446 } quicktime_edts_t;
  447 
  448 
  449 
  450 
  451 typedef struct
  452 {
  453     quicktime_tkhd_t tkhd;
  454     quicktime_mdia_t mdia;
  455     quicktime_edts_t edts;
  456 } quicktime_trak_t;
  457 
  458 
  459 typedef struct
  460 {
  461     int version;
  462     long flags;
  463     unsigned long creation_time;
  464     unsigned long modification_time;
  465     long time_scale;
  466     long duration;
  467     float preferred_rate;
  468     float preferred_volume;
  469     char reserved[10];
  470     quicktime_matrix_t matrix;
  471     long preview_time;
  472     long preview_duration;
  473     long poster_time;
  474     long selection_time;
  475     long selection_duration;
  476     long current_time;
  477     long next_track_id;
  478 } quicktime_mvhd_t;
  479 
  480 typedef struct
  481 {
  482     char *copyright;
  483     int copyright_len;
  484     char *name;
  485     int name_len;
  486     char *info;
  487     int info_len;
  488     char *require;
  489     int require_len;
  490     char *encoder;
  491     int encoder_len;
  492 } quicktime_udta_t;
  493 
  494 
  495 typedef struct
  496 {
  497     int total_tracks;
  498 
  499     quicktime_mvhd_t mvhd;
  500     quicktime_trak_t *trak[MAXTRACKS];
  501     quicktime_udta_t udta;
  502     quicktime_ctab_t ctab;
  503 } quicktime_moov_t;
  504 
  505 typedef struct
  506 {
  507     quicktime_atom_t atom;
  508 } quicktime_mdat_t;
  509 
  510 typedef struct
  511 {
  512 /* Offset of end of 8 byte chunk header relative to ix->base_offset */
  513     int relative_offset;
  514 /* size of data without 8 byte header */
  515     int size;
  516 } quicktime_ixtable_t;
  517 
  518 typedef struct
  519 {
  520     quicktime_atom_t atom;
  521     quicktime_ixtable_t *table;
  522     int table_size;
  523     int table_allocation;
  524     int longs_per_entry;
  525     int index_type;
  526 /* ixtable relative_offset is relative to this */
  527     int64_t base_offset;
  528 /* ix atom title */
  529     char tag[5];
  530 /* corresponding chunk id */
  531     char chunk_id[5];
  532 } quicktime_ix_t;
  533 
  534 
  535 typedef struct
  536 {
  537     quicktime_atom_t atom;
  538 
  539 /* Partial index */
  540 /* For writing only, there are multiple movi objects with multiple ix tables. */
  541 /* This is not used for reading.  Instead an ix_t object in indx_t is used. */
  542     quicktime_ix_t *ix[MAXTRACKS];
  543 } quicktime_movi_t;
  544 
  545 typedef struct
  546 {
  547 /* Start of start of corresponding ix## header */
  548     int64_t index_offset;
  549 /* Size not including 8 byte header */
  550     int index_size;
  551 /* duration in "ticks" */
  552     int duration;
  553 
  554 /* Partial index for reading only. */
  555     quicktime_ix_t *ix;
  556 } quicktime_indxtable_t;
  557 
  558 typedef struct
  559 {
  560     quicktime_atom_t atom;
  561     int longs_per_entry;
  562     int index_subtype;
  563     int index_type;
  564 /* corresponding chunk id: 00wb, 00dc */
  565     char chunk_id[5];
  566 
  567 /* Number of partial indexes here */
  568     int table_size;
  569     int table_allocation;
  570     quicktime_indxtable_t *table;
  571 } quicktime_indx_t;
  572 
  573 /* AVI equivalent for each trak.  Use file->moov.total_tracks */
  574 /* Need it for super indexes during reading. */
  575 typedef struct
  576 {
  577     quicktime_atom_t atom;
  578 /* Super index for reading */
  579     quicktime_indx_t indx;
  580 /* AVI needs header placeholders before anything else is written */
  581     int64_t length_offset;
  582 /* Sample count read directly from auds */
  583     int64_t samples;
  584 /* Bytes per second read directly from auds */
  585     int bytes_per_second;
  586 /* Bytes totalled up from idx1 */
  587     int64_t total_bytes;
  588     int64_t samples_per_chunk_offset;
  589     int64_t sample_size_offset;
  590 /* Start of indx header for later writing */
  591     int64_t indx_offset;
  592 /* Size of JUNK without 8 byte header which is to be replaced by indx */
  593     int64_t padding_size;
  594 /* Tag for writer with NULL termination: 00wb, 00dc   Not available in reader.*/
  595     char tag[5];
  596 /* Flags for reader.  Not available in writer. */
  597     int is_audio;
  598     int is_video;
  599 /* Notify reader the super indexes are valid */
  600     int have_indx;
  601 } quicktime_strl_t;
  602 
  603 typedef struct
  604 {
  605     quicktime_atom_t atom;
  606     int64_t frames_offset;
  607     int64_t bitrate_offset;
  608 /* Offsets to be written during file closure */
  609     int64_t total_frames_offset;
  610 
  611 /* AVI equivalent for each trak.  Use file->moov.total_tracks */
  612 /* Need it for super indexes during reading. */
  613     quicktime_strl_t *strl[MAXTRACKS];
  614 } quicktime_hdrl_t;
  615 
  616 typedef struct
  617 {
  618     char tag[5];
  619     uint32_t flags;
  620 /* Start of 8 byte chunk header relative to start of the 'movi' string */
  621     int32_t offset;
  622 /* Size of chunk less the 8 byte header */
  623     int32_t size;
  624 } quicktime_idx1table_t;
  625 
  626 typedef struct
  627 {
  628     quicktime_atom_t atom;
  629     quicktime_idx1table_t *table;
  630     int table_size;
  631     int table_allocation;
  632 } quicktime_idx1_t;
  633 
  634 typedef struct
  635 {
  636     quicktime_atom_t atom;
  637     quicktime_movi_t movi;
  638     quicktime_hdrl_t hdrl;
  639 
  640 /* Full index */
  641     quicktime_idx1_t idx1;
  642 /* Notify reader the idx1 table is valid */
  643     int have_idx1;
  644     int have_hdrl;
  645 } quicktime_riff_t;
  646 
  647 typedef struct
  648 {
  649     unsigned char *y, *u, *v;
  650     int y_size;
  651     int u_size;
  652     int v_size;
  653     int64_t frame_number;
  654 } quicktime_cacheframe_t;
  655 
  656 typedef struct
  657 {
  658     quicktime_cacheframe_t *frames;
  659     int total;
  660     int allocation;
  661 } quicktime_cache_t;
  662 
  663 /* table of pointers to every track */
  664 typedef struct
  665 {
  666     quicktime_trak_t *track; /* real quicktime track corresponding to this table */
  667     int channels;            /* number of audio channels in the track */
  668     int64_t current_position;   /* current sample in output file */
  669     int64_t current_chunk;      /* current chunk in output file */
  670     quicktime_vbr_t vbr;     /* Stores for vbr codecs */
  671 
  672     void *codec;
  673 } quicktime_audio_map_t;
  674 
  675 typedef struct
  676 {
  677     quicktime_trak_t *track;
  678     int64_t current_position;   /* current frame in output file */
  679     int64_t current_chunk;      /* current chunk in output file */
  680 // Cache for the current GOP after a seek.
  681     quicktime_cache_t *frame_cache;
  682 
  683     void *codec;
  684 } quicktime_video_map_t;
  685 
  686 /* file descriptor passed to all routines */
  687 typedef struct
  688 {
  689     FILE *stream;
  690     int64_t total_length;
  691     quicktime_mdat_t mdat;
  692     quicktime_moov_t moov;
  693     int rd;
  694     int wr;
  695 
  696 /* If the moov atom is compressed */
  697     int compressed_moov;
  698     unsigned char *moov_data;
  699 /*
  700  * Temporary storage of compressed sizes.  If the file length is shorter than the
  701  * uncompressed sizes, it won't work.
  702  */
  703     int64_t moov_end;
  704     int64_t moov_size;
  705     int64_t old_preload_size;
  706     char *old_preload_buffer;
  707     int64_t old_preload_start;
  708     int64_t old_preload_end;
  709     int64_t old_preload_ptr;
  710 
  711 
  712 
  713 
  714 
  715 /* ASF/WMV section */
  716     int use_asf;
  717     void *asf;
  718 
  719 
  720 
  721 
  722 /* AVI section */
  723     int use_avi;
  724 /* AVI tree */
  725     quicktime_riff_t *riff[MAX_RIFFS];
  726     int total_riffs;
  727 /* is odml version of AVI */
  728     int is_odml;
  729 
  730 
  731 
  732 
  733 
  734 
  735 
  736 
  737 /* for begining and ending frame writes where the user wants to write the  */
  738 /* file descriptor directly */
  739     int64_t offset;
  740 
  741 /* I/O */
  742 /* Current position of virtual file descriptor */
  743     int64_t file_position;      
  744 
  745 /* Work around a bug in glibc where ftello returns only 32 bits by maintaining */
  746 /* our own position */
  747     int64_t ftell_position;
  748 
  749 /* Read ahead buffer */
  750     int64_t preload_size;      /* Enables preload when nonzero. */
  751     char *preload_buffer;
  752     int64_t preload_start;     /* Start of preload_buffer in file */
  753     int64_t preload_end;       /* End of preload buffer in file */
  754     int64_t preload_ptr;       /* Offset of preload_start in preload_buffer */
  755 
  756 /* Write ahead buffer */
  757 /* Amount of data in presave buffer */
  758     int64_t presave_size;
  759 /* Next presave byte's position in file */
  760     int64_t presave_position;
  761     char *presave_buffer;
  762 /* Presave doesn't matter a whole lot, so its size is fixed */
  763 #define QUICKTIME_PRESAVE 0x100000
  764     int use_presave;
  765 
  766 /* mapping of audio channels to movie tracks */
  767 /* one audio map entry exists for each channel */
  768     int total_atracks;
  769     quicktime_audio_map_t *atracks;
  770 
  771 /* mapping of video tracks to movie tracks */
  772     int total_vtracks;
  773     quicktime_video_map_t *vtracks;
  774 
  775 /* Number of processors at our disposal */
  776     int cpus;
  777 
  778 /* Parameters for frame currently being decoded */
  779     int do_scaling;
  780     int in_x, in_y, in_w, in_h, out_w, out_h;
  781     int color_model, row_span;
  782 
  783 } quicktime_t;
  784 
  785 
  786 /* Structure created in track_map to describe the codec */
  787 typedef struct
  788 {
  789     int (*delete_vcodec)(quicktime_video_map_t *vtrack);
  790     int (*delete_acodec)(quicktime_audio_map_t *atrack);
  791 /* Decode a single frame */
  792     int (*decode_video)(quicktime_t *file, 
  793                 unsigned char **row_pointers, 
  794                 int track);
  795 /* Encode a single frame */
  796     int (*encode_video)(quicktime_t *file, 
  797                 unsigned char **row_pointers, 
  798                 int track);
  799 /* Decode a certain number of samples */
  800     int (*decode_audio)(quicktime_t *file, 
  801                 int16_t *output_i, 
  802                 float *output_f, 
  803                 long samples, 
  804                 int track,
  805                 int channel);
  806 /* Encode a chunk of audio */
  807     int (*encode_audio)(quicktime_t *file, 
  808                 int16_t **input_i, 
  809                 float **input_f, 
  810                 int track, 
  811                 long samples);
  812     int (*reads_colormodel)(quicktime_t *file, 
  813         int colormodel, 
  814         int track);
  815     int (*writes_colormodel)(quicktime_t *file, 
  816         int colormodel, 
  817         int track);
  818 
  819     int (*set_parameter)(quicktime_t *file, 
  820         int track, 
  821         char *key, 
  822         void *value);
  823     void (*flush)(quicktime_t *file, 
  824         int track);
  825 
  826 /* AVI codec ID for audio.  AVI codec ID's are based on WAV files, by the way. */
  827     int wav_id;
  828 
  829 /* Pointer to static character code for identifying the codec. */
  830     char *fourcc;
  831 
  832 /* English title of codec.  Optional. */
  833     char *title;
  834 
  835 /* English description of codec.  Optional. */
  836     char *desc;
  837 
  838 /* Frame cache for seeking only. */
  839     
  840 
  841 /* Proprietary data for the codec to allocate and delete. */
  842     void *priv;
  843 } quicktime_codec_t;
  844 
  845 
  846 
  847 /* Structure tabulated in plugin.c to search the codecs */
  848 typedef struct
  849 {
  850     void (*init_vcodec)(quicktime_video_map_t *);
  851     void (*init_acodec)(quicktime_audio_map_t *);
  852 } quicktime_codectable_t;
  853 
  854 
  855 
  856 
  857 #endif