blob: 4ed0a85f2ca6adb087c45fd818f59ef485f0def3 [file] [log] [blame]
Tristan Matthews0a329cc2013-07-17 13:20:14 -04001/* $Id$ */
2/*
3 * Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */
19#ifndef __PJMEDIA_AVI_H__
20#define __PJMEDIA_AVI_H__
21
22
23/**
24 * @file avi.h
25 * @brief AVI file manipulation.
26 */
27
28/**
29 * @defgroup PJMEDIA_FILE_FORMAT File Formats
30 * @brief Supported file formats
31 */
32
33
34/**
35 * @defgroup PJMEDIA_AVI AVI Header
36 * @ingroup PJMEDIA_FILE_FORMAT
37 * @brief Representation of RIFF/AVI file format
38 * @{
39 *
40 * This the the low level representation of RIFF/AVI file format. For
41 * higher abstraction, please see \ref PJMEDIA_FILE_PLAY and
42 * \ref PJMEDIA_FILE_REC.
43 */
44
45
46PJ_BEGIN_DECL
47
48#define PJMEDIA_AVI_MAX_NUM_STREAMS 4
49
50static const char avi_tags[][4] = {
51 { 'R', 'I', 'F', 'F' }, { 'A', 'V', 'I', ' ' },
52 { 'h', 'd', 'r', 'l' }, { 'a', 'v', 'i', 'h' },
53 { 's', 't', 'r', 'l' }, { 's', 't', 'r', 'h' },
54 { 'a', 'u', 'd', 's' }, { 'v', 'i', 'd', 's' },
55 { 's', 't', 'r', 'f' }, { 'm', 'o', 'v', 'i' },
56 { 'L', 'I', 'S', 'T' }, { 'J', 'U', 'N', 'K' },
57};
58
59typedef enum {
60 PJMEDIA_AVI_RIFF_TAG = 0,
61 PJMEDIA_AVI_AVI_TAG,
62 PJMEDIA_AVI_HDRL_TAG,
63 PJMEDIA_AVI_AVIH_TAG,
64 PJMEDIA_AVI_STRL_TAG,
65 PJMEDIA_AVI_STRH_TAG,
66 PJMEDIA_AVI_AUDS_TAG,
67 PJMEDIA_AVI_VIDS_TAG,
68 PJMEDIA_AVI_STRF_TAG,
69 PJMEDIA_AVI_MOVI_TAG,
70 PJMEDIA_AVI_LIST_TAG,
71 PJMEDIA_AVI_JUNK_TAG,
72} pjmedia_avi_tag;
73
74
75/**
76 * These types describe the simpler/canonical version of an AVI file.
77 * They do not support the full AVI RIFF format specification.
78 */
79#pragma pack(2)
80
81/** This structure describes RIFF AVI file header */
82typedef struct riff_hdr_t {
83 pj_uint32_t riff; /**< "RIFF" ASCII tag. */
84 pj_uint32_t file_len; /**< File length minus 8 bytes */
85 pj_uint32_t avi; /**< "AVI" ASCII tag. */
86} riff_hdr_t;
87
88/** This structure describes avih header */
89typedef struct avih_hdr_t {
90 pj_uint32_t list_tag;
91 pj_uint32_t list_sz;
92 pj_uint32_t hdrl_tag;
93 pj_uint32_t avih;
94 pj_uint32_t size;
95 pj_uint32_t usec_per_frame; /**< microsecs between frames */
96 pj_uint32_t max_Bps;
97 pj_uint32_t pad;
98 pj_uint32_t flags;
99 pj_uint32_t tot_frames;
100 pj_uint32_t init_frames;
101 pj_uint32_t num_streams;
102 pj_uint32_t buf_size;
103 pj_uint32_t width;
104 pj_uint32_t height;
105 pj_uint32_t reserved[4];
106} avih_hdr_t;
107
108/** This structure describes strl header */
109typedef struct strl_hdr_t {
110 pj_uint32_t list_tag;
111 pj_uint32_t list_sz;
112 pj_uint32_t strl_tag;
113
114 pj_uint32_t strh;
115 pj_uint32_t strh_size;
116 pj_uint32_t data_type;
117 pj_uint32_t codec;
118 pj_uint32_t flags;
119 pj_uint32_t bogus_priority_language; /**< Do not access this data */
120 pj_uint32_t init_frames;
121 pj_uint32_t scale;
122 pj_uint32_t rate;
123 pj_uint32_t start;
124 pj_uint32_t length;
125 pj_uint32_t buf_size;
126 pj_uint32_t quality;
127 pj_uint32_t sample_size;
128 pj_uint32_t bogus_frame[2]; /**< Do not access this data */
129} strl_hdr_t;
130
131typedef struct {
132 pj_uint32_t strf;
133 pj_uint32_t strf_size;
134 pj_uint16_t fmt_tag; /**< 1 for PCM */
135 pj_uint16_t nchannels; /**< Number of channels. */
136 pj_uint32_t sample_rate; /**< Sampling rate. */
137 pj_uint32_t bytes_per_sec; /**< Average bytes per second. */
138 pj_uint16_t block_align; /**< nchannels * bits / 8 */
139 pj_uint16_t bits_per_sample; /**< Bits per sample. */
140 pj_uint16_t extra_size;
141} strf_audio_hdr_t;
142
143/**
144 * Sizes of strf_audio_hdr_t struct, started by the size (in bytes) of
145 * 32-bits struct members, alternated with the size of 16-bits members.
146 */
147static const pj_uint8_t strf_audio_hdr_sizes [] = {8, 4, 8, 6};
148
149typedef struct {
150 pj_uint32_t strf;
151 pj_uint32_t strf_size;
152 pj_uint32_t biSize;
153 pj_int32_t biWidth;
154 pj_int32_t biHeight;
155 pj_uint16_t biPlanes;
156 pj_uint16_t biBitCount;
157 pj_uint32_t biCompression;
158 pj_uint32_t biSizeImage;
159 pj_int32_t biXPelsPerMeter;
160 pj_int32_t biYPelsPerMeter;
161 pj_uint32_t biClrUsed;
162 pj_uint32_t biClrImportant;
163} strf_video_hdr_t;
164
165static const pj_uint8_t strf_video_hdr_sizes [] = {20, 4, 24};
166
167struct pjmedia_avi_hdr
168{
169 riff_hdr_t riff_hdr;
170 avih_hdr_t avih_hdr;
171 strl_hdr_t strl_hdr[PJMEDIA_AVI_MAX_NUM_STREAMS];
172 union {
173 strf_audio_hdr_t strf_audio_hdr;
174 strf_video_hdr_t strf_video_hdr;
175 } strf_hdr[PJMEDIA_AVI_MAX_NUM_STREAMS];
176};
177
178#pragma pack()
179
180/**
181 * @see pjmedia_avi_hdr
182 */
183typedef struct pjmedia_avi_hdr pjmedia_avi_hdr;
184
185/**
186 * This structure describes generic RIFF subchunk header.
187 */
188typedef struct pjmedia_avi_subchunk
189{
190 pj_uint32_t id; /**< Subchunk ASCII tag. */
191 pj_uint32_t len; /**< Length following this field */
192} pjmedia_avi_subchunk;
193
194
195PJ_END_DECL
196
197/**
198 * @}
199 */
200
201
202#endif /* __PJMEDIA_AVI_H__ */