avi.h 5.5 KB

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