]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/dvdata.h
use dc tables from msmpeg4 instead of duplicating them patch by anonymous
[ffmpeg] / libavcodec / dvdata.h
index bab69133e7430ffd9fd710590735fa25b7f3824a..acda751d6bf99e4ec794634b89aae9c057d13ecb 100644 (file)
  * @file dvdata.h
  * Constants for DV codec.
  */
+
+/* 
+ * DVprofile is used to express the differences between various 
+ * DV flavors. For now it's primarily used for differentiating
+ * 525/60 and 625/50, but the plans are to use it for various
+ * DV specs as well (e.g. SMPTE314M vs. IEC 61834).
+ */
+typedef struct DVprofile {
+    int              dsf;                 /* value of the dsf in the DV header */
+    int              frame_size;          /* total size of one frame in bytes */
+    int              difseg_size;         /* number of DIF segments */
+    int              frame_rate;      
+    int              frame_rate_base;
+    int              ltc_divisor;         /* FPS from the LTS standpoint */
+    int              height;              /* picture height in pixels */
+    int              width;               /* picture width in pixels */
+    AVRational       sar[2];              /* sample aspect ratios for 4:3 and 16:9 */
+    const uint16_t  *video_place;         /* positions of all DV macro blocks */
+    enum PixelFormat pix_fmt;             /* picture pixel format */
+    
+    int              audio_stride;        /* size of audio_shuffle table */
+    int              audio_min_samples[3];/* min ammount of audio samples */
+                                          /* for 48Khz, 44.1Khz and 32Khz */
+    int              audio_samples_dist[5];/* how many samples are supposed to be */
+                                         /* in each frame in a 5 frames window */
+    const uint16_t (*audio_shuffle)[9];  /* PCM shuffling table */
+} DVprofile;
+
 #define NB_DV_VLC 409
-#define AAUX_AS_OFFSET  (80*6 + 80*16*3 + 3)
-#define AAUX_ASC_OFFSET (80*6 + 80*16*4 + 3)
-#define VAUX_TC61_OFFSET (80*5 + 48 + 5)
 
+/* 
+ * There's a catch about the following three tables: the mapping they establish
+ * between (run, level) and vlc is not 1-1. So you have to watch out for that
+ * when building misc. tables. E.g. (1, 0) can be either 0x7cf or 0x1f82. 
+ */
 static const uint16_t dv_vlc_bits[409] = {
  0x0000, 0x0002, 0x0007, 0x0008, 0x0009, 0x0014, 0x0015, 0x0016,
  0x0017, 0x0030, 0x0031, 0x0032, 0x0033, 0x0068, 0x0069, 0x006a,
@@ -189,7 +218,7 @@ static const uint8_t dv_vlc_run[409] = {
   0,  0,  0,  0,  0,  0,  0,  0,
   0,  0,  0,  0,  0,  0,  0,  0,
   0,  0,  0,  0,  0,  0,  0,  0,
-  0,
+127,
 };
 
 static const uint8_t dv_vlc_level[409] = {
@@ -247,19 +276,6 @@ static const uint8_t dv_vlc_level[409] = {
   0,
 };
 
-/* Specific zigzag scan for 248 idct. NOTE that unlike the
-   specification, we interleave the fields */
-static const uint8_t dv_248_zigzag[64] = {
-  0,  8,  1,  9, 16, 24,  2, 10,
- 17, 25, 32, 40, 48, 56, 33, 41,
- 18, 26,  3, 11,  4, 12, 19, 27,
- 34, 42, 49, 57, 50, 58, 35, 43,
- 20, 28,  5, 13,  6, 14, 21, 29,
- 36, 44, 51, 59, 52, 60, 37, 45,
- 22, 30,  7, 15, 23, 31, 38, 46,
- 53, 61, 54, 62, 39, 47, 55, 63,
-};
-
 /* unquant tables (not used directly) */
 static const uint8_t dv_88_areas[64] = {
     0,0,0,1,1,1,2,2,
@@ -283,7 +299,7 @@ static const uint8_t dv_248_areas[64] = {
     1,2,2,3,3,3,3,3,
 };
 
-static uint8_t dv_quant_shifts[22][4] = {
+static const uint8_t dv_quant_shifts[22][4] = {
   { 3,3,4,4 }, 
   { 3,3,4,4 }, 
   { 2,3,3,4 }, 
@@ -1240,7 +1256,7 @@ static const uint16_t dv_place_411[1350] = {
  0x0834, 0x2320, 0x2f44, 0x3810, 0x1658,
 };
 
-static const uint16_t dv_place_audio60[10][9] = {
+static const uint16_t dv_audio_shuffle525[10][9] = {
   {  0, 30, 60, 20, 50, 80, 10, 40, 70 }, /* 1st channel */
   {  6, 36, 66, 26, 56, 86, 16, 46, 76 },
   { 12, 42, 72,  2, 32, 62, 22, 52, 82 },
@@ -1254,7 +1270,7 @@ static const uint16_t dv_place_audio60[10][9] = {
   { 25, 55, 85, 15, 45, 75,  5, 35, 65 },
 };
 
-static const uint16_t dv_place_audio50[12][9] = {
+static const uint16_t dv_audio_shuffle625[12][9] = {
   {   0,  36,  72,  26,  62,  98,  16,  52,  88}, /* 1st channel */
   {   6,  42,  78,  32,  68, 104,  22,  58,  94},
   {  12,  48,  84,   2,  38,  74,  28,  64, 100},
@@ -1270,11 +1286,81 @@ static const uint16_t dv_place_audio50[12][9] = {
   {  31,  67, 103,  21,  57,  93,  11,  47,  83},
 };
 
-static const int dv_audio_frequency[3] = {
-    48000, 44100, 32000, 
+static const __attribute__((unused)) int dv_audio_frequency[3] = {
+    48000, 44100, 32000,
 };
-
-static const int dv_audio_min_samples[2][3] = {
-    { 1580, 1452, 1053 }, /* 60 fields */
-    { 1896, 1742, 1264 }, /* 50 fileds */
+    
+static const DVprofile dv_profiles[] = {
+    { .dsf = 0,
+      .frame_size = 120000,        /* IEC 61834, SMPTE-314M - 525/60 (NTSC) */
+      .difseg_size = 10,
+      .frame_rate = 30000,
+      .ltc_divisor = 30,
+      .frame_rate_base = 1001,
+      .height = 480,
+      .width = 720,
+      .sar = {{10, 11}, {40, 33}},
+      .video_place = dv_place_411,
+      .pix_fmt = PIX_FMT_YUV411P,
+      .audio_stride = 90,
+      .audio_min_samples = { 1580, 1452, 1053 }, /* for 48, 44.1 and 32Khz */
+      .audio_samples_dist = { 1602, 1601, 1602, 1601, 1602 },
+      .audio_shuffle = dv_audio_shuffle525,
+    }, 
+    { .dsf = 1,
+      .frame_size = 144000,        /* IEC 61834 - 625/50 (PAL) */
+      .difseg_size = 12,
+      .frame_rate = 25,
+      .frame_rate_base = 1,
+      .ltc_divisor = 25,
+      .height = 576,
+      .width = 720,
+      .sar = {{59, 54}, {118, 81}},
+      .video_place = dv_place_420,
+      .pix_fmt = PIX_FMT_YUV420P,
+      .audio_stride = 108,
+      .audio_min_samples = { 1896, 1742, 1264 }, /* for 48, 44.1 and 32Khz */
+      .audio_samples_dist = { 1920, 1920, 1920, 1920, 1920 },
+      .audio_shuffle = dv_audio_shuffle625,
+    },
+    { .dsf = 1,
+      .frame_size = 144000,        /* SMPTE-314M - 625/50 (PAL) */
+      .difseg_size = 12,
+      .frame_rate = 25,
+      .frame_rate_base = 1,
+      .ltc_divisor = 25,
+      .height = 576,
+      .width = 720,
+      .sar = {{59, 54}, {118, 81}},
+      .video_place = dv_place_411P,
+      .pix_fmt = PIX_FMT_YUV411P,
+      .audio_stride = 108,
+      .audio_min_samples = { 1896, 1742, 1264 }, /* for 48, 44.1 and 32Khz */
+      .audio_samples_dist = { 1920, 1920, 1920, 1920, 1920 },
+      .audio_shuffle = dv_audio_shuffle625,
+     }
 };
+
+static inline const DVprofile* dv_frame_profile(uint8_t* frame)
+{
+    if ((frame[3] & 0x80) == 0) {      /* DSF flag */
+        return &dv_profiles[0];
+    }
+    else if ((frame[5] & 0x07) == 0) { /* APT flag */
+        return &dv_profiles[1];
+    }
+    else 
+        return &dv_profiles[2];
+}
+
+static inline const DVprofile* dv_codec_profile(AVCodecContext* codec)
+{
+    if (codec->width != 720) {
+        return NULL;
+    } 
+    else if (codec->height == 480) {
+        return &dv_profiles[0];
+    } 
+    else 
+        return &dv_profiles[1];
+}