You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

157 lines
5.8KB

  1. /*
  2. * Constants for DV codec
  3. * Copyright (c) 2002 Fabrice Bellard
  4. *
  5. * This file is part of Libav.
  6. *
  7. * Libav is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Lesser General Public
  9. * License as published by the Free Software Foundation; either
  10. * version 2.1 of the License, or (at your option) any later version.
  11. *
  12. * Libav is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with Libav; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  20. */
  21. /**
  22. * @file
  23. * Constants for DV codec.
  24. */
  25. #ifndef AVCODEC_DVDATA_H
  26. #define AVCODEC_DVDATA_H
  27. #include "libavutil/rational.h"
  28. #include "avcodec.h"
  29. typedef struct DVwork_chunk {
  30. uint16_t buf_offset;
  31. uint16_t mb_coordinates[5];
  32. } DVwork_chunk;
  33. /*
  34. * DVprofile is used to express the differences between various
  35. * DV flavors. For now it's primarily used for differentiating
  36. * 525/60 and 625/50, but the plans are to use it for various
  37. * DV specs as well (e.g. SMPTE314M vs. IEC 61834).
  38. */
  39. typedef struct DVprofile {
  40. int dsf; /* value of the dsf in the DV header */
  41. int video_stype; /* stype for VAUX source pack */
  42. int frame_size; /* total size of one frame in bytes */
  43. int difseg_size; /* number of DIF segments per DIF channel */
  44. int n_difchan; /* number of DIF channels per frame */
  45. AVRational time_base; /* 1/framerate */
  46. int ltc_divisor; /* FPS from the LTS standpoint */
  47. int height; /* picture height in pixels */
  48. int width; /* picture width in pixels */
  49. AVRational sar[2]; /* sample aspect ratios for 4:3 and 16:9 */
  50. DVwork_chunk *work_chunks; /* each thread gets its own chunk of frame to work on */
  51. uint32_t *idct_factor; /* set of iDCT factor tables */
  52. enum PixelFormat pix_fmt; /* picture pixel format */
  53. int bpm; /* blocks per macroblock */
  54. const uint8_t *block_sizes; /* AC block sizes, in bits */
  55. int audio_stride; /* size of audio_shuffle table */
  56. int audio_min_samples[3]; /* min amount of audio samples */
  57. /* for 48kHz, 44.1kHz and 32kHz */
  58. int audio_samples_dist[5]; /* how many samples are supposed to be */
  59. /* in each frame in a 5 frames window */
  60. const uint8_t (*audio_shuffle)[9]; /* PCM shuffling table */
  61. } DVprofile;
  62. static const uint8_t dv_audio_shuffle525[10][9] = {
  63. { 0, 30, 60, 20, 50, 80, 10, 40, 70 }, /* 1st channel */
  64. { 6, 36, 66, 26, 56, 86, 16, 46, 76 },
  65. { 12, 42, 72, 2, 32, 62, 22, 52, 82 },
  66. { 18, 48, 78, 8, 38, 68, 28, 58, 88 },
  67. { 24, 54, 84, 14, 44, 74, 4, 34, 64 },
  68. { 1, 31, 61, 21, 51, 81, 11, 41, 71 }, /* 2nd channel */
  69. { 7, 37, 67, 27, 57, 87, 17, 47, 77 },
  70. { 13, 43, 73, 3, 33, 63, 23, 53, 83 },
  71. { 19, 49, 79, 9, 39, 69, 29, 59, 89 },
  72. { 25, 55, 85, 15, 45, 75, 5, 35, 65 },
  73. };
  74. static const uint8_t dv_audio_shuffle625[12][9] = {
  75. { 0, 36, 72, 26, 62, 98, 16, 52, 88}, /* 1st channel */
  76. { 6, 42, 78, 32, 68, 104, 22, 58, 94},
  77. { 12, 48, 84, 2, 38, 74, 28, 64, 100},
  78. { 18, 54, 90, 8, 44, 80, 34, 70, 106},
  79. { 24, 60, 96, 14, 50, 86, 4, 40, 76},
  80. { 30, 66, 102, 20, 56, 92, 10, 46, 82},
  81. { 1, 37, 73, 27, 63, 99, 17, 53, 89}, /* 2nd channel */
  82. { 7, 43, 79, 33, 69, 105, 23, 59, 95},
  83. { 13, 49, 85, 3, 39, 75, 29, 65, 101},
  84. { 19, 55, 91, 9, 45, 81, 35, 71, 107},
  85. { 25, 61, 97, 15, 51, 87, 5, 41, 77},
  86. { 31, 67, 103, 21, 57, 93, 11, 47, 83},
  87. };
  88. static const av_unused int dv_audio_frequency[3] = {
  89. 48000, 44100, 32000,
  90. };
  91. /* macroblock bit budgets */
  92. static const uint8_t block_sizes_dv2550[8] = {
  93. 112, 112, 112, 112, 80, 80, 0, 0,
  94. };
  95. static const uint8_t block_sizes_dv100[8] = {
  96. 80, 80, 80, 80, 80, 80, 64, 64,
  97. };
  98. enum dv_section_type {
  99. dv_sect_header = 0x1f,
  100. dv_sect_subcode = 0x3f,
  101. dv_sect_vaux = 0x56,
  102. dv_sect_audio = 0x76,
  103. dv_sect_video = 0x96,
  104. };
  105. enum dv_pack_type {
  106. dv_header525 = 0x3f, /* see dv_write_pack for important details on */
  107. dv_header625 = 0xbf, /* these two packs */
  108. dv_timecode = 0x13,
  109. dv_audio_source = 0x50,
  110. dv_audio_control = 0x51,
  111. dv_audio_recdate = 0x52,
  112. dv_audio_rectime = 0x53,
  113. dv_video_source = 0x60,
  114. dv_video_control = 0x61,
  115. dv_video_recdate = 0x62,
  116. dv_video_rectime = 0x63,
  117. dv_unknown_pack = 0xff,
  118. };
  119. #define DV_PROFILE_IS_HD(p) ((p)->video_stype & 0x10)
  120. #define DV_PROFILE_IS_1080i50(p) (((p)->video_stype == 0x14) && ((p)->dsf == 1))
  121. #define DV_PROFILE_IS_720p50(p) (((p)->video_stype == 0x18) && ((p)->dsf == 1))
  122. /* minimum number of bytes to read from a DV stream in order to
  123. determine the profile */
  124. #define DV_PROFILE_BYTES (6*80) /* 6 DIF blocks */
  125. /**
  126. * largest possible DV frame, in bytes (1080i50)
  127. */
  128. #define DV_MAX_FRAME_SIZE 576000
  129. /**
  130. * maximum number of blocks per macroblock in any DV format
  131. */
  132. #define DV_MAX_BPM 8
  133. const DVprofile* avpriv_dv_frame_profile(const DVprofile *sys,
  134. const uint8_t* frame, unsigned buf_size);
  135. const DVprofile* avpriv_dv_codec_profile(AVCodecContext* codec);
  136. #endif /* AVCODEC_DVDATA_H */