Home | History | Annotate | Download | only in include
      1 /* ------------------------------------------------------------------
      2  * Copyright (C) 1998-2009 PacketVideo
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
     13  * express or implied.
     14  * See the License for the specific language governing permissions
     15  * and limitations under the License.
     16  * -------------------------------------------------------------------
     17  */
     18 /* //////////////////////////////////////////////////////////////// */
     19 /*  File    : avi_write.h                                           */
     20 /* ---------------------------------------------------------------- */
     21 /*  Create AVI file from a YUV or RGB output of MPEG4 decoder.      */
     22 /* //////////////////////////////////////////////////////////////// */
     23 
     24 #ifndef AVI_WRITE_H_INCLUDED
     25 #define AVI_WRITE_H_INCLUDED
     26 
     27 #include "oscl_string.h"
     28 #include "oscl_file_io.h"
     29 
     30 #ifndef mmioFOURCC
     31 #define mmioFOURCC( ch0, ch1, ch2, ch3 ) \
     32     ( (int)(unsigned char)(ch0) | ( (int)(unsigned char)(ch1) << 8 ) | \
     33     ( (int)(unsigned char)(ch2) << 16 ) | ( (int)(unsigned char)(ch3) << 24 ) )
     34 #endif
     35 
     36 #ifndef max
     37 #define max(a,b)            (((a) > (b)) ? (a) : (b))
     38 #endif
     39 
     40 #ifndef min
     41 #define min(a,b)            (((a) < (b)) ? (a) : (b))
     42 #endif
     43 
     44 #ifndef BI_RGB
     45 #define BI_RGB        0L
     46 #endif
     47 
     48 #define streamtypeVIDEO     mmioFOURCC('v', 'i', 'd', 's')
     49 #define formtypeAVI         mmioFOURCC('A', 'V', 'I', ' ')
     50 #define FOURCC_LIST         mmioFOURCC('L', 'I', 'S', 'T')
     51 #define FOURCC_RIFF         mmioFOURCC('R', 'I', 'F', 'F')
     52 #define FOURCC_WAVE         mmioFOURCC('W', 'A', 'V', 'E')
     53 #define FOURCC_fmt          mmioFOURCC('f', 'm', 't', ' ')
     54 #define FOURCC_data         mmioFOURCC('d', 'a', 't', 'a')
     55 #define listtypeAVIHEADER       mmioFOURCC('h', 'd', 'r', 'l')
     56 #define listtypeSTREAMHEADER    mmioFOURCC('s', 't', 'r', 'l')
     57 #define ckidSTREAMHEADER        mmioFOURCC('s', 't', 'r', 'h')
     58 #define ckidSTREAMFORMAT        mmioFOURCC('s', 't', 'r', 'f')
     59 #define ckidAVIMAINHDR          mmioFOURCC('a', 'v', 'i', 'h')
     60 #define ckidAVIPADDING      mmioFOURCC('J', 'U', 'N', 'K')
     61 #define listtypeAVIMOVIE    mmioFOURCC('m', 'o', 'v', 'i')
     62 #define videoChunkID        mmioFOURCC('0', '0', 'd', 'b')
     63 #define ckidAVINEWINDEX     mmioFOURCC('i', 'd', 'x', '1')
     64 
     65 #define AVIF_HASINDEX_FILE_OUT      0x00000010  // Index at end of file?
     66 #define AVIF_TRUSTCKTYPE_FILE_OUT   0x00000800  // Use CKType to find key frames?
     67 
     68 
     69 #define DEFAULT_COUNT 20000 /* default number of frames */
     70 
     71 typedef struct
     72 {
     73     int16   left;
     74     int16   top;
     75     int16   right;
     76     int16   bottom;
     77 } rect;
     78 
     79 
     80 typedef struct
     81 {
     82     uint32  dwMicroSecPerFrame; // frame display rate (or 0L)
     83     uint32  dwMaxBytesPerSec;   // max. transfer rate
     84     uint32  dwPaddingGranularity;   // pad to multiples of this
     85     // size; normally 2K.
     86     uint32  dwFlags;        // the ever-present flags
     87     uint32  dwTotalFrames;      // # frames in file
     88     uint32  dwInitialFrames;
     89     uint32  dwStreams;
     90     uint32  dwSuggestedBufferSize;
     91 
     92     uint32  dwWidth;
     93     uint32  dwHeight;
     94 
     95     uint32  dwScale;
     96     uint32  dwRate;
     97     uint32  dwStart;
     98     uint32  dwLength;
     99 } AVIMainHeader;
    100 
    101 /*
    102  * Stream header
    103  */
    104 
    105 //#define AVISF_DISABLED            0x00000001
    106 //#define AVISF_VIDEO_PALCHANGES        0x00010000
    107 
    108 typedef struct
    109 {
    110     uint32  fccType;
    111     uint32  fccHandler;
    112     uint32  dwFlags;    /* Contains AVISF_* flags */
    113     uint16  wPriority;  /* dwPriority - splited for audio */
    114     uint16  wLanguage;
    115     uint32  dwInitialFrames;
    116     uint32  dwScale;
    117     uint32  dwRate;     /* dwRate / dwScale == samples/second */
    118     uint32  dwStart;
    119     uint32  dwLength;   /* In units above... */
    120     uint32  dwSuggestedBufferSize;
    121     int32   dwQuality;
    122     uint32  dwSampleSize;
    123     rect    rcFrame;
    124 } AVIStreamHeader;
    125 
    126 typedef struct
    127 {
    128     uint32  chunkID;
    129     uint32  flags;
    130     uint32  offset;
    131     uint32  length;
    132 } AVIIndex;
    133 
    134 typedef struct
    135 {
    136     uint32  length;
    137     uint8   indexBuffer[20000 * 16 + 2];
    138 } IndexBuffer;
    139 
    140 
    141 typedef struct
    142 {
    143     uint32      biSize;
    144     int32       biWidth;
    145     int32       biHeight;
    146     uint16       biPlanes;
    147     uint16       biBitCount;
    148     uint32      biCompression;
    149     uint32      biSizeImage;
    150     int32       biXPelsPerMeter;
    151     int32       biYPelsPerMeter;
    152     uint32      biClrUsed;
    153     uint32      biClrImportant;
    154 } BitMapInfoHeader;
    155 
    156 void InitializeAVI(OSCL_TCHAR *filename, int width, int height, int cc);
    157 
    158 void WriteSampleAVI(unsigned char *src, long timestamp);
    159 
    160 void CleanUpAVI(long lasttime);
    161 
    162 #endif
    163