private.h
上传用户:sun1608
上传日期:2007-02-02
资源大小:6116k
文件大小:12k
源码类别:

流媒体/Mpeg4/MP4

开发平台:

Visual C++

  1. #ifndef PRIVATE_H
  2. #define PRIVATE_H
  3. /* ================================= structures */
  4. #define HEADER_LENGTH 8
  5. #define MAXTRACKS 1024
  6. #include "sizes.h"
  7. typedef struct
  8. {
  9. float values[9];
  10. } quicktime_matrix_t;
  11. typedef struct
  12. {
  13. int version;
  14. long flags;
  15. unsigned long creation_time;
  16. unsigned long modification_time;
  17. int track_id;
  18. long reserved1;
  19. long duration;
  20. char reserved2[8];
  21. int layer;
  22. int alternate_group;
  23. float volume;
  24. long reserved3;
  25. quicktime_matrix_t matrix;
  26. float track_width;
  27. float track_height;
  28. int is_video;
  29. int is_audio;
  30. int is_hint;
  31. } quicktime_tkhd_t;
  32. typedef struct
  33. {
  34. long seed;
  35. long flags;
  36. long size;
  37. short int *alpha;
  38. short int *red;
  39. short int *green;
  40. short int *blue;
  41. } quicktime_ctab_t;
  42. /* ===================== sample table ======================== // */
  43. /* sample description */
  44. typedef struct
  45. {
  46. int motion_jpeg_quantization_table;
  47. } quicktime_mjqt_t;
  48. typedef struct
  49. {
  50. int motion_jpeg_huffman_table;
  51. } quicktime_mjht_t;
  52. typedef struct
  53. {
  54. int timeScale;
  55. } quicktime_tims_t;
  56. typedef struct
  57. {
  58. int version;
  59. long flags;
  60. int decoderConfigLen;
  61. u_char* decoderConfig;
  62. } quicktime_esds_t;
  63. typedef struct
  64. {
  65. char format[4];
  66. char reserved[6];
  67. int data_reference;
  68. /* common to audio and video */
  69. int version;
  70. int revision;
  71. char vendor[4];
  72. /* video description */
  73. long temporal_quality;
  74. long spatial_quality;
  75. int width;
  76. int height;
  77. float dpi_horizontal;
  78. float dpi_vertical;
  79. long data_size;
  80. int frames_per_sample;
  81. char compressor_name[32];
  82. int depth;
  83. int ctab_id;
  84. quicktime_ctab_t ctab;
  85. float gamma;
  86. int fields;    /* 0, 1, or 2 */
  87. int field_dominance;   /* 0 - unknown     1 - top first     2 - bottom first */
  88. quicktime_mjqt_t mjqt;
  89. quicktime_mjht_t mjht;
  90. /* audio description */
  91. int channels;
  92. int sample_size;
  93. int compression_id;
  94. int packet_size;
  95. float sample_rate;
  96. /* hint description */
  97. int maxPktSize;
  98. quicktime_tims_t tims;
  99. /* MP4 elementary stream descriptor */
  100. quicktime_esds_t esds;
  101. } quicktime_stsd_table_t;
  102. typedef struct
  103. {
  104. int version;
  105. long flags;
  106. long total_entries;
  107. quicktime_stsd_table_t *table;
  108. } quicktime_stsd_t;
  109. /* time to sample */
  110. typedef struct
  111. {
  112. long sample_count;
  113. long sample_duration;
  114. } quicktime_stts_table_t;
  115. typedef struct
  116. {
  117. int version;
  118. long flags;
  119. long total_entries;
  120. long entries_allocated;
  121. quicktime_stts_table_t *table;
  122. } quicktime_stts_t;
  123. /* sync sample */
  124. typedef struct
  125. {
  126. long sample;
  127. } quicktime_stss_table_t;
  128. typedef struct
  129. {
  130. int version;
  131. long flags;
  132. long total_entries;
  133. long entries_allocated;
  134. quicktime_stss_table_t *table;
  135. } quicktime_stss_t;
  136. /* sample to chunk */
  137. typedef struct
  138. {
  139. long chunk;
  140. long samples;
  141. long id;
  142. } quicktime_stsc_table_t;
  143. typedef struct
  144. {
  145. int version;
  146. long flags;
  147. long total_entries;
  148. long entries_allocated;
  149. quicktime_stsc_table_t *table;
  150. } quicktime_stsc_t;
  151. /* sample size */
  152. typedef struct
  153. {
  154. long size;
  155. } quicktime_stsz_table_t;
  156. typedef struct
  157. {
  158. int version;
  159. long flags;
  160. long sample_size;
  161. long total_entries;
  162. long entries_allocated;    /* used by the library for allocating a table */
  163. quicktime_stsz_table_t *table;
  164. } quicktime_stsz_t;
  165. /* chunk offset */
  166. typedef struct
  167. {
  168. long offset;
  169. } quicktime_stco_table_t;
  170. typedef struct
  171. {
  172. int version;
  173. long flags;
  174. long total_entries;
  175. long entries_allocated;    /* used by the library for allocating a table */
  176. quicktime_stco_table_t *table;
  177. } quicktime_stco_t;
  178. /* composition time to sample */
  179. typedef struct
  180. {
  181. long sample_count;
  182. long sample_offset;
  183. } quicktime_ctts_table_t;
  184. typedef struct
  185. {
  186. int version;
  187. long flags;
  188. long total_entries;
  189. long entries_allocated;
  190. quicktime_ctts_table_t *table;
  191. } quicktime_ctts_t;
  192. /* sample table */
  193. typedef struct
  194. {
  195. int version;
  196. long flags;
  197. quicktime_stsd_t stsd;
  198. quicktime_stts_t stts;
  199. quicktime_stss_t stss;
  200. quicktime_stsc_t stsc;
  201. quicktime_stsz_t stsz;
  202. quicktime_stco_t stco;
  203. quicktime_ctts_t ctts;
  204. } quicktime_stbl_t;
  205. /* data reference */
  206. typedef struct
  207. {
  208. long size;
  209. char type[4];
  210. int version;
  211. long flags;
  212. char *data_reference;
  213. } quicktime_dref_table_t;
  214. typedef struct
  215. {
  216. int version;
  217. long flags;
  218. long total_entries;
  219. quicktime_dref_table_t *table;
  220. } quicktime_dref_t;
  221. /* data information */
  222. typedef struct
  223. {
  224. quicktime_dref_t dref;
  225. } quicktime_dinf_t;
  226. /* video media header */
  227. typedef struct
  228. {
  229. int version;
  230. long flags;
  231. int graphics_mode;
  232. int opcolor[3];
  233. } quicktime_vmhd_t;
  234. /* sound media header */
  235. typedef struct
  236. {
  237. int version;
  238. long flags;
  239. int balance;
  240. int reserved;
  241. } quicktime_smhd_t;
  242. /* generic media handler */
  243. typedef struct
  244. {
  245. int version;
  246. long flags;
  247. int graphics_mode;
  248. int opcolor[3];
  249. int balance;
  250. int reserved;
  251. } quicktime_gmin_t;
  252. typedef struct
  253. {
  254. quicktime_gmin_t gmin;
  255. } quicktime_gmhd_t;
  256. /* hint media handler */
  257. typedef struct
  258. {
  259. int version;
  260. long flags;
  261. int maxPDUsize;
  262. int avgPDUsize;
  263. long maxbitrate;
  264. long avgbitrate;
  265. long slidingavgbitrate;
  266. } quicktime_hmhd_t;
  267. /* handler reference */
  268. typedef struct
  269. {
  270. int version;
  271. long flags;
  272. char component_type[4];
  273. char component_subtype[4];
  274. long component_manufacturer;
  275. long component_flags;
  276. long component_flag_mask;
  277. char component_name[256];
  278. } quicktime_hdlr_t;
  279. /* media information */
  280. typedef struct
  281. {
  282. int is_video;
  283. int is_audio;
  284. int is_hint;
  285. quicktime_vmhd_t vmhd;
  286. quicktime_smhd_t smhd;
  287. quicktime_gmhd_t gmhd;
  288. quicktime_hmhd_t hmhd;
  289. quicktime_stbl_t stbl;
  290. quicktime_hdlr_t hdlr;
  291. quicktime_dinf_t dinf;
  292. } quicktime_minf_t;
  293. /* media header */
  294. typedef struct
  295. {
  296. int version;
  297. long flags;
  298. unsigned long creation_time;
  299. unsigned long modification_time;
  300. long time_scale;
  301. long duration;
  302. int language;
  303. int quality;
  304. } quicktime_mdhd_t;
  305. /* media */
  306. typedef struct
  307. {
  308. quicktime_mdhd_t mdhd;
  309. quicktime_minf_t minf;
  310. quicktime_hdlr_t hdlr;
  311. } quicktime_mdia_t;
  312. /* hint */
  313. typedef struct
  314. {
  315. int numTracks;
  316. long trackIds[MAXTRACKS];
  317. void* traks[MAXTRACKS];
  318. } quicktime_hint_t;
  319. /* tref */
  320. typedef struct
  321. {
  322. quicktime_hint_t hint;
  323. } quicktime_tref_t;
  324. /* edit list */
  325. typedef struct
  326. {
  327. long duration;
  328. long time;
  329. float rate;
  330. } quicktime_elst_table_t;
  331. typedef struct
  332. {
  333. int version;
  334. long flags;
  335. long total_entries;
  336. quicktime_elst_table_t *table;
  337. } quicktime_elst_t;
  338. typedef struct
  339. {
  340. quicktime_elst_t elst;
  341. } quicktime_edts_t;
  342. typedef struct {
  343. u_int64_t numBytes; /* bytes sent including 12 byte RTP hdrs */
  344. } quicktime_trpy_t;
  345. typedef struct {
  346. u_int64_t numPackets; /* packets sent */
  347. } quicktime_nump_t;
  348. typedef struct {
  349. u_int64_t numBytes; /* bytes sent of just payload data */
  350. } quicktime_tpyl_t;
  351. typedef struct {
  352. u_int32_t granularity;
  353. u_int32_t maxBitRate;
  354. } quicktime_maxr_t;
  355. typedef struct {
  356. u_int64_t numBytes; /* bytes sent from media data */
  357. } quicktime_dmed_t;
  358. typedef struct {
  359. u_int64_t numBytes; /* bytes of immediate data */
  360. } quicktime_dimm_t;
  361. typedef struct {
  362. u_int64_t numBytes; /* bytes of repeated data */
  363. } quicktime_drep_t;
  364. typedef struct {
  365. int32_t milliSecs; /* min relative xmit time */
  366. } quicktime_tmin_t;
  367. typedef struct {
  368. int32_t milliSecs; /* max relative xmit time */
  369. } quicktime_tmax_t;
  370. typedef struct {
  371. u_int32_t numBytes; /* largest packet size */
  372. } quicktime_pmax_t;
  373. typedef struct {
  374. u_int32_t milliSecs; /* longest packet duration */
  375. } quicktime_dmax_t;
  376. typedef struct {
  377. u_int32_t payloadNumber; /* RTP payload number */
  378. char rtpMapString[256]; /* TBD make this dynamically sized */
  379. } quicktime_payt_t;
  380. typedef struct {
  381. quicktime_trpy_t trpy;
  382. quicktime_nump_t nump;
  383. quicktime_tpyl_t tpyl;
  384. quicktime_maxr_t maxr; /* TBD there can be multiple such atoms */
  385. quicktime_dmed_t dmed;
  386. quicktime_dimm_t dimm;
  387. quicktime_drep_t drep;
  388. quicktime_tmin_t tmin;
  389. quicktime_tmax_t tmax;
  390. quicktime_pmax_t pmax;
  391. quicktime_dmax_t dmax;
  392. quicktime_payt_t payt;
  393. } quicktime_hinf_t;
  394. typedef struct {
  395. char* string;
  396. } quicktime_sdp_t;
  397. typedef struct {
  398. char* string;
  399. } quicktime_rtp_t;
  400. typedef struct {
  401. quicktime_sdp_t sdp;
  402. } quicktime_hint_hnti_t;
  403. typedef struct {
  404. quicktime_rtp_t rtp;
  405. } quicktime_hnti_t;
  406. typedef struct {
  407. /* TBD name */
  408. quicktime_hinf_t hinf;
  409. quicktime_hint_hnti_t hnti;
  410. } quicktime_hint_udta_t;
  411. typedef struct
  412. {
  413. quicktime_tkhd_t tkhd;
  414. quicktime_mdia_t mdia;
  415. quicktime_edts_t edts;
  416. quicktime_tref_t tref;
  417. quicktime_hint_udta_t hint_udta;
  418. } quicktime_trak_t;
  419. typedef struct
  420. {
  421. int version;
  422. long flags;
  423. int audioProfileId;
  424. int videoProfileId;
  425. } quicktime_iods_t;
  426. typedef struct
  427. {
  428. int version;
  429. long flags;
  430. unsigned long creation_time;
  431. unsigned long modification_time;
  432. long time_scale;
  433. long duration;
  434. float preferred_rate;
  435. float preferred_volume;
  436. char reserved[10];
  437. quicktime_matrix_t matrix;
  438. long preview_time;
  439. long preview_duration;
  440. long poster_time;
  441. long selection_time;
  442. long selection_duration;
  443. long current_time;
  444. long next_track_id;
  445. } quicktime_mvhd_t;
  446. typedef struct
  447. {
  448. char *copyright;
  449. int copyright_len;
  450. char *name;
  451. int name_len;
  452. char *info;
  453. int info_len;
  454. quicktime_hnti_t hnti;
  455. } quicktime_udta_t;
  456. typedef struct
  457. {
  458. int total_tracks;
  459. quicktime_mvhd_t mvhd;
  460. quicktime_iods_t iods;
  461. quicktime_trak_t *trak[MAXTRACKS];
  462. quicktime_udta_t udta;
  463. quicktime_ctab_t ctab;
  464. } quicktime_moov_t;
  465. typedef struct
  466. {
  467. long start;
  468. long size;
  469. } quicktime_mdat_t;
  470. typedef struct
  471. {
  472. long start;      /* byte start in file */
  473. long end;        /* byte endpoint in file */
  474. long size;       /* byte size for writing */
  475. char type[4];
  476. } quicktime_atom_t;
  477. /* table of pointers to every track */
  478. typedef struct
  479. {
  480. quicktime_trak_t *track; /* real quicktime track corresponding to this table */
  481. int channels;            /* number of audio channels in the track */
  482. long current_position;   /* current sample in output file */
  483. long current_chunk;      /* current chunk in output file */
  484. void *codec;
  485. /* Array of hint tracks for this audio track */
  486. int totalHintTracks;
  487. quicktime_trak_t *hintTracks[MAXTRACKS];
  488. long hintPositions[MAXTRACKS];
  489. } quicktime_audio_map_t;
  490. typedef struct
  491. {
  492. quicktime_trak_t *track;
  493. long current_position;
  494. long current_chunk;
  495. /* Array of pointers to frames of raw data when caching frames. */
  496. unsigned char **frame_cache;
  497. long frames_cached;
  498. void *codec;
  499. /* Array of hint tracks for this video track */
  500. int totalHintTracks;
  501. quicktime_trak_t *hintTracks[MAXTRACKS];
  502. long hintPositions[MAXTRACKS];
  503. } quicktime_video_map_t;
  504. /* file descriptor passed to all routines */
  505. typedef struct
  506. {
  507. FILE *stream;
  508. long total_length;
  509. quicktime_mdat_t mdat;
  510. quicktime_moov_t moov;
  511. int rd;
  512. int wr;
  513. int use_avi;
  514. int use_mp4;
  515. /* mapping of audio channels to movie tracks */
  516. /* one audio map entry exists for each channel */
  517. int total_atracks;
  518. quicktime_audio_map_t *atracks;
  519. /* mapping of video tracks to movie tracks */
  520. int total_vtracks;
  521. quicktime_video_map_t *vtracks;
  522. int total_hint_tracks;
  523. /* for begining and ending frame writes where the user wants to write the  */
  524. /* file descriptor directly */
  525. long offset;
  526. /* Number of processors at our disposal */
  527. int cpus;
  528. /* I/O */
  529. long file_position;      /* Current position of file descriptor */
  530. /* Read ahead buffer */
  531. long preload_size;      /* Enables preload when nonzero. */
  532. char *preload_buffer;
  533. long preload_start;     /* Start of preload_buffer in file */
  534. long preload_end;       /* End of preload buffer in file */
  535. long preload_ptr;       /* Offset of preload_start in preload_buffer */
  536. /* Parameters for frame currently being decoded */
  537. int do_scaling;
  538. int in_x, in_y, in_w, in_h, out_w, out_h;
  539. int color_model;
  540. /* Cached value for quicktime_video_frame */
  541. long last_frame;
  542. long last_start;
  543. int last_stts_index;
  544. } quicktime_t;
  545. #endif