• Main Page
  • Related Pages
  • Modules
  • Data Structures
  • Files
  • File List
  • Globals

libavcodec/dvdata.h

Go to the documentation of this file.
00001 /*
00002  * Constants for DV codec
00003  * Copyright (c) 2002 Fabrice Bellard
00004  *
00005  * This file is part of FFmpeg.
00006  *
00007  * FFmpeg is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU Lesser General Public
00009  * License as published by the Free Software Foundation; either
00010  * version 2.1 of the License, or (at your option) any later version.
00011  *
00012  * FFmpeg is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015  * Lesser General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU Lesser General Public
00018  * License along with FFmpeg; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
00020  */
00021 
00027 #ifndef AVCODEC_DVDATA_H
00028 #define AVCODEC_DVDATA_H
00029 
00030 #include "libavutil/rational.h"
00031 #include "avcodec.h"
00032 
00033 typedef struct DVwork_chunk {
00034     uint16_t  buf_offset;
00035     uint16_t  mb_coordinates[5];
00036 } DVwork_chunk;
00037 
00038 /*
00039  * DVprofile is used to express the differences between various
00040  * DV flavors. For now it's primarily used for differentiating
00041  * 525/60 and 625/50, but the plans are to use it for various
00042  * DV specs as well (e.g. SMPTE314M vs. IEC 61834).
00043  */
00044 typedef struct DVprofile {
00045     int              dsf;                   /* value of the dsf in the DV header */
00046     int              video_stype;           /* stype for VAUX source pack */
00047     int              frame_size;            /* total size of one frame in bytes */
00048     int              difseg_size;           /* number of DIF segments per DIF channel */
00049     int              n_difchan;             /* number of DIF channels per frame */
00050     AVRational       time_base;             /* 1/framerate */
00051     int              ltc_divisor;           /* FPS from the LTS standpoint */
00052     int              height;                /* picture height in pixels */
00053     int              width;                 /* picture width in pixels */
00054     AVRational       sar[2];                /* sample aspect ratios for 4:3 and 16:9 */
00055     DVwork_chunk    *work_chunks;           /* each thread gets its own chunk of frame to work on */
00056     uint32_t        *idct_factor;           /* set of iDCT factor tables */
00057     enum PixelFormat pix_fmt;               /* picture pixel format */
00058     int              bpm;                   /* blocks per macroblock */
00059     const uint8_t   *block_sizes;           /* AC block sizes, in bits */
00060     int              audio_stride;          /* size of audio_shuffle table */
00061     int              audio_min_samples[3];  /* min amount of audio samples */
00062                                             /* for 48kHz, 44.1kHz and 32kHz */
00063     int              audio_samples_dist[5]; /* how many samples are supposed to be */
00064                                             /* in each frame in a 5 frames window */
00065     const uint8_t  (*audio_shuffle)[9];     /* PCM shuffling table */
00066 } DVprofile;
00067 
00068 #define NB_DV_VLC 409
00069 
00070 /*
00071  * There's a catch about the following three tables: the mapping they establish
00072  * between (run, level) and vlc is not 1-1. So you have to watch out for that
00073  * when building misc. tables. E.g. (1, 0) can be either 0x7cf or 0x1f82.
00074  */
00075 static const uint16_t dv_vlc_bits[409] = {
00076  0x0000, 0x0002, 0x0007, 0x0008, 0x0009, 0x0014, 0x0015, 0x0016,
00077  0x0017, 0x0030, 0x0031, 0x0032, 0x0033, 0x0068, 0x0069, 0x006a,
00078  0x006b, 0x006c, 0x006d, 0x006e, 0x006f, 0x00e0, 0x00e1, 0x00e2,
00079  0x00e3, 0x00e4, 0x00e5, 0x00e6, 0x00e7, 0x00e8, 0x00e9, 0x00ea,
00080  0x00eb, 0x00ec, 0x00ed, 0x00ee, 0x00ef, 0x01e0, 0x01e1, 0x01e2,
00081  0x01e3, 0x01e4, 0x01e5, 0x01e6, 0x01e7, 0x01e8, 0x01e9, 0x01ea,
00082  0x01eb, 0x01ec, 0x01ed, 0x01ee, 0x01ef, 0x03e0, 0x03e1, 0x03e2,
00083  0x03e3, 0x03e4, 0x03e5, 0x03e6, 0x07ce, 0x07cf, 0x07d0, 0x07d1,
00084  0x07d2, 0x07d3, 0x07d4, 0x07d5, 0x0fac, 0x0fad, 0x0fae, 0x0faf,
00085  0x0fb0, 0x0fb1, 0x0fb2, 0x0fb3, 0x0fb4, 0x0fb5, 0x0fb6, 0x0fb7,
00086  0x0fb8, 0x0fb9, 0x0fba, 0x0fbb, 0x0fbc, 0x0fbd, 0x0fbe, 0x0fbf,
00087  0x1f80, 0x1f81, 0x1f82, 0x1f83, 0x1f84, 0x1f85, 0x1f86, 0x1f87,
00088  0x1f88, 0x1f89, 0x1f8a, 0x1f8b, 0x1f8c, 0x1f8d, 0x1f8e, 0x1f8f,
00089  0x1f90, 0x1f91, 0x1f92, 0x1f93, 0x1f94, 0x1f95, 0x1f96, 0x1f97,
00090  0x1f98, 0x1f99, 0x1f9a, 0x1f9b, 0x1f9c, 0x1f9d, 0x1f9e, 0x1f9f,
00091  0x1fa0, 0x1fa1, 0x1fa2, 0x1fa3, 0x1fa4, 0x1fa5, 0x1fa6, 0x1fa7,
00092  0x1fa8, 0x1fa9, 0x1faa, 0x1fab, 0x1fac, 0x1fad, 0x1fae, 0x1faf,
00093  0x1fb0, 0x1fb1, 0x1fb2, 0x1fb3, 0x1fb4, 0x1fb5, 0x1fb6, 0x1fb7,
00094  0x1fb8, 0x1fb9, 0x1fba, 0x1fbb, 0x1fbc, 0x1fbd, 0x1fbe, 0x1fbf,
00095  0x7f00, 0x7f01, 0x7f02, 0x7f03, 0x7f04, 0x7f05, 0x7f06, 0x7f07,
00096  0x7f08, 0x7f09, 0x7f0a, 0x7f0b, 0x7f0c, 0x7f0d, 0x7f0e, 0x7f0f,
00097  0x7f10, 0x7f11, 0x7f12, 0x7f13, 0x7f14, 0x7f15, 0x7f16, 0x7f17,
00098  0x7f18, 0x7f19, 0x7f1a, 0x7f1b, 0x7f1c, 0x7f1d, 0x7f1e, 0x7f1f,
00099  0x7f20, 0x7f21, 0x7f22, 0x7f23, 0x7f24, 0x7f25, 0x7f26, 0x7f27,
00100  0x7f28, 0x7f29, 0x7f2a, 0x7f2b, 0x7f2c, 0x7f2d, 0x7f2e, 0x7f2f,
00101  0x7f30, 0x7f31, 0x7f32, 0x7f33, 0x7f34, 0x7f35, 0x7f36, 0x7f37,
00102  0x7f38, 0x7f39, 0x7f3a, 0x7f3b, 0x7f3c, 0x7f3d, 0x7f3e, 0x7f3f,
00103  0x7f40, 0x7f41, 0x7f42, 0x7f43, 0x7f44, 0x7f45, 0x7f46, 0x7f47,
00104  0x7f48, 0x7f49, 0x7f4a, 0x7f4b, 0x7f4c, 0x7f4d, 0x7f4e, 0x7f4f,
00105  0x7f50, 0x7f51, 0x7f52, 0x7f53, 0x7f54, 0x7f55, 0x7f56, 0x7f57,
00106  0x7f58, 0x7f59, 0x7f5a, 0x7f5b, 0x7f5c, 0x7f5d, 0x7f5e, 0x7f5f,
00107  0x7f60, 0x7f61, 0x7f62, 0x7f63, 0x7f64, 0x7f65, 0x7f66, 0x7f67,
00108  0x7f68, 0x7f69, 0x7f6a, 0x7f6b, 0x7f6c, 0x7f6d, 0x7f6e, 0x7f6f,
00109  0x7f70, 0x7f71, 0x7f72, 0x7f73, 0x7f74, 0x7f75, 0x7f76, 0x7f77,
00110  0x7f78, 0x7f79, 0x7f7a, 0x7f7b, 0x7f7c, 0x7f7d, 0x7f7e, 0x7f7f,
00111  0x7f80, 0x7f81, 0x7f82, 0x7f83, 0x7f84, 0x7f85, 0x7f86, 0x7f87,
00112  0x7f88, 0x7f89, 0x7f8a, 0x7f8b, 0x7f8c, 0x7f8d, 0x7f8e, 0x7f8f,
00113  0x7f90, 0x7f91, 0x7f92, 0x7f93, 0x7f94, 0x7f95, 0x7f96, 0x7f97,
00114  0x7f98, 0x7f99, 0x7f9a, 0x7f9b, 0x7f9c, 0x7f9d, 0x7f9e, 0x7f9f,
00115  0x7fa0, 0x7fa1, 0x7fa2, 0x7fa3, 0x7fa4, 0x7fa5, 0x7fa6, 0x7fa7,
00116  0x7fa8, 0x7fa9, 0x7faa, 0x7fab, 0x7fac, 0x7fad, 0x7fae, 0x7faf,
00117  0x7fb0, 0x7fb1, 0x7fb2, 0x7fb3, 0x7fb4, 0x7fb5, 0x7fb6, 0x7fb7,
00118  0x7fb8, 0x7fb9, 0x7fba, 0x7fbb, 0x7fbc, 0x7fbd, 0x7fbe, 0x7fbf,
00119  0x7fc0, 0x7fc1, 0x7fc2, 0x7fc3, 0x7fc4, 0x7fc5, 0x7fc6, 0x7fc7,
00120  0x7fc8, 0x7fc9, 0x7fca, 0x7fcb, 0x7fcc, 0x7fcd, 0x7fce, 0x7fcf,
00121  0x7fd0, 0x7fd1, 0x7fd2, 0x7fd3, 0x7fd4, 0x7fd5, 0x7fd6, 0x7fd7,
00122  0x7fd8, 0x7fd9, 0x7fda, 0x7fdb, 0x7fdc, 0x7fdd, 0x7fde, 0x7fdf,
00123  0x7fe0, 0x7fe1, 0x7fe2, 0x7fe3, 0x7fe4, 0x7fe5, 0x7fe6, 0x7fe7,
00124  0x7fe8, 0x7fe9, 0x7fea, 0x7feb, 0x7fec, 0x7fed, 0x7fee, 0x7fef,
00125  0x7ff0, 0x7ff1, 0x7ff2, 0x7ff3, 0x7ff4, 0x7ff5, 0x7ff6, 0x7ff7,
00126  0x7ff8, 0x7ff9, 0x7ffa, 0x7ffb, 0x7ffc, 0x7ffd, 0x7ffe, 0x7fff,
00127  0x0006,
00128 };
00129 
00130 static const uint8_t dv_vlc_len[409] = {
00131   2,  3,  4,  4,  4,  5,  5,  5,
00132   5,  6,  6,  6,  6,  7,  7,  7,
00133   7,  7,  7,  7,  7,  8,  8,  8,
00134   8,  8,  8,  8,  8,  8,  8,  8,
00135   8,  8,  8,  8,  8,  9,  9,  9,
00136   9,  9,  9,  9,  9,  9,  9,  9,
00137   9,  9,  9,  9,  9, 10, 10, 10,
00138  10, 10, 10, 10, 11, 11, 11, 11,
00139  11, 11, 11, 11, 12, 12, 12, 12,
00140  12, 12, 12, 12, 12, 12, 12, 12,
00141  12, 12, 12, 12, 12, 12, 12, 12,
00142  13, 13, 13, 13, 13, 13, 13, 13,
00143  13, 13, 13, 13, 13, 13, 13, 13,
00144  13, 13, 13, 13, 13, 13, 13, 13,
00145  13, 13, 13, 13, 13, 13, 13, 13,
00146  13, 13, 13, 13, 13, 13, 13, 13,
00147  13, 13, 13, 13, 13, 13, 13, 13,
00148  13, 13, 13, 13, 13, 13, 13, 13,
00149  13, 13, 13, 13, 13, 13, 13, 13,
00150  15, 15, 15, 15, 15, 15, 15, 15,
00151  15, 15, 15, 15, 15, 15, 15, 15,
00152  15, 15, 15, 15, 15, 15, 15, 15,
00153  15, 15, 15, 15, 15, 15, 15, 15,
00154  15, 15, 15, 15, 15, 15, 15, 15,
00155  15, 15, 15, 15, 15, 15, 15, 15,
00156  15, 15, 15, 15, 15, 15, 15, 15,
00157  15, 15, 15, 15, 15, 15, 15, 15,
00158  15, 15, 15, 15, 15, 15, 15, 15,
00159  15, 15, 15, 15, 15, 15, 15, 15,
00160  15, 15, 15, 15, 15, 15, 15, 15,
00161  15, 15, 15, 15, 15, 15, 15, 15,
00162  15, 15, 15, 15, 15, 15, 15, 15,
00163  15, 15, 15, 15, 15, 15, 15, 15,
00164  15, 15, 15, 15, 15, 15, 15, 15,
00165  15, 15, 15, 15, 15, 15, 15, 15,
00166  15, 15, 15, 15, 15, 15, 15, 15,
00167  15, 15, 15, 15, 15, 15, 15, 15,
00168  15, 15, 15, 15, 15, 15, 15, 15,
00169  15, 15, 15, 15, 15, 15, 15, 15,
00170  15, 15, 15, 15, 15, 15, 15, 15,
00171  15, 15, 15, 15, 15, 15, 15, 15,
00172  15, 15, 15, 15, 15, 15, 15, 15,
00173  15, 15, 15, 15, 15, 15, 15, 15,
00174  15, 15, 15, 15, 15, 15, 15, 15,
00175  15, 15, 15, 15, 15, 15, 15, 15,
00176  15, 15, 15, 15, 15, 15, 15, 15,
00177  15, 15, 15, 15, 15, 15, 15, 15,
00178  15, 15, 15, 15, 15, 15, 15, 15,
00179  15, 15, 15, 15, 15, 15, 15, 15,
00180  15, 15, 15, 15, 15, 15, 15, 15,
00181  15, 15, 15, 15, 15, 15, 15, 15,
00182   4,
00183 };
00184 
00185 static const uint8_t dv_vlc_run[409] = {
00186   0,  0,  1,  0,  0,  2,  1,  0,
00187   0,  3,  4,  0,  0,  5,  6,  2,
00188   1,  1,  0,  0,  0,  7,  8,  9,
00189  10,  3,  4,  2,  1,  1,  1,  0,
00190   0,  0,  0,  0,  0, 11, 12, 13,
00191  14,  5,  6,  3,  4,  2,  2,  1,
00192   0,  0,  0,  0,  0,  5,  3,  3,
00193   2,  1,  1,  1,  0,  1,  6,  4,
00194   3,  1,  1,  1,  2,  3,  4,  5,
00195   7,  8,  9, 10,  7,  8,  4,  3,
00196   2,  2,  2,  2,  2,  1,  1,  1,
00197   0,  1,  2,  3,  4,  5,  6,  7,
00198   8,  9, 10, 11, 12, 13, 14, 15,
00199  16, 17, 18, 19, 20, 21, 22, 23,
00200  24, 25, 26, 27, 28, 29, 30, 31,
00201  32, 33, 34, 35, 36, 37, 38, 39,
00202  40, 41, 42, 43, 44, 45, 46, 47,
00203  48, 49, 50, 51, 52, 53, 54, 55,
00204  56, 57, 58, 59, 60, 61, 62, 63,
00205   0,  0,  0,  0,  0,  0,  0,  0,
00206   0,  0,  0,  0,  0,  0,  0,  0,
00207   0,  0,  0,  0,  0,  0,  0,  0,
00208   0,  0,  0,  0,  0,  0,  0,  0,
00209   0,  0,  0,  0,  0,  0,  0,  0,
00210   0,  0,  0,  0,  0,  0,  0,  0,
00211   0,  0,  0,  0,  0,  0,  0,  0,
00212   0,  0,  0,  0,  0,  0,  0,  0,
00213   0,  0,  0,  0,  0,  0,  0,  0,
00214   0,  0,  0,  0,  0,  0,  0,  0,
00215   0,  0,  0,  0,  0,  0,  0,  0,
00216   0,  0,  0,  0,  0,  0,  0,  0,
00217   0,  0,  0,  0,  0,  0,  0,  0,
00218   0,  0,  0,  0,  0,  0,  0,  0,
00219   0,  0,  0,  0,  0,  0,  0,  0,
00220   0,  0,  0,  0,  0,  0,  0,  0,
00221   0,  0,  0,  0,  0,  0,  0,  0,
00222   0,  0,  0,  0,  0,  0,  0,  0,
00223   0,  0,  0,  0,  0,  0,  0,  0,
00224   0,  0,  0,  0,  0,  0,  0,  0,
00225   0,  0,  0,  0,  0,  0,  0,  0,
00226   0,  0,  0,  0,  0,  0,  0,  0,
00227   0,  0,  0,  0,  0,  0,  0,  0,
00228   0,  0,  0,  0,  0,  0,  0,  0,
00229   0,  0,  0,  0,  0,  0,  0,  0,
00230   0,  0,  0,  0,  0,  0,  0,  0,
00231   0,  0,  0,  0,  0,  0,  0,  0,
00232   0,  0,  0,  0,  0,  0,  0,  0,
00233   0,  0,  0,  0,  0,  0,  0,  0,
00234   0,  0,  0,  0,  0,  0,  0,  0,
00235   0,  0,  0,  0,  0,  0,  0,  0,
00236   0,  0,  0,  0,  0,  0,  0,  0,
00237 127,
00238 };
00239 
00240 static const uint8_t dv_vlc_level[409] = {
00241    1,   2,   1,   3,   4,   1,   2,   5,
00242    6,   1,   1,   7,   8,   1,   1,   2,
00243    3,   4,   9,  10,  11,   1,   1,   1,
00244    1,   2,   2,   3,   5,   6,   7,  12,
00245   13,  14,  15,  16,  17,   1,   1,   1,
00246    1,   2,   2,   3,   3,   4,   5,   8,
00247   18,  19,  20,  21,  22,   3,   4,   5,
00248    6,   9,  10,  11,   0,   0,   3,   4,
00249    6,  12,  13,  14,   0,   0,   0,   0,
00250    2,   2,   2,   2,   3,   3,   5,   7,
00251    7,   8,   9,  10,  11,  15,  16,  17,
00252    0,   0,   0,   0,   0,   0,   0,   0,
00253    0,   0,   0,   0,   0,   0,   0,   0,
00254    0,   0,   0,   0,   0,   0,   0,   0,
00255    0,   0,   0,   0,   0,   0,   0,   0,
00256    0,   0,   0,   0,   0,   0,   0,   0,
00257    0,   0,   0,   0,   0,   0,   0,   0,
00258    0,   0,   0,   0,   0,   0,   0,   0,
00259    0,   0,   0,   0,   0,   0,   0,   0,
00260    0,   1,   2,   3,   4,   5,   6,   7,
00261    8,   9,  10,  11,  12,  13,  14,  15,
00262   16,  17,  18,  19,  20,  21,  22,  23,
00263   24,  25,  26,  27,  28,  29,  30,  31,
00264   32,  33,  34,  35,  36,  37,  38,  39,
00265   40,  41,  42,  43,  44,  45,  46,  47,
00266   48,  49,  50,  51,  52,  53,  54,  55,
00267   56,  57,  58,  59,  60,  61,  62,  63,
00268   64,  65,  66,  67,  68,  69,  70,  71,
00269   72,  73,  74,  75,  76,  77,  78,  79,
00270   80,  81,  82,  83,  84,  85,  86,  87,
00271   88,  89,  90,  91,  92,  93,  94,  95,
00272   96,  97,  98,  99, 100, 101, 102, 103,
00273  104, 105, 106, 107, 108, 109, 110, 111,
00274  112, 113, 114, 115, 116, 117, 118, 119,
00275  120, 121, 122, 123, 124, 125, 126, 127,
00276  128, 129, 130, 131, 132, 133, 134, 135,
00277  136, 137, 138, 139, 140, 141, 142, 143,
00278  144, 145, 146, 147, 148, 149, 150, 151,
00279  152, 153, 154, 155, 156, 157, 158, 159,
00280  160, 161, 162, 163, 164, 165, 166, 167,
00281  168, 169, 170, 171, 172, 173, 174, 175,
00282  176, 177, 178, 179, 180, 181, 182, 183,
00283  184, 185, 186, 187, 188, 189, 190, 191,
00284  192, 193, 194, 195, 196, 197, 198, 199,
00285  200, 201, 202, 203, 204, 205, 206, 207,
00286  208, 209, 210, 211, 212, 213, 214, 215,
00287  216, 217, 218, 219, 220, 221, 222, 223,
00288  224, 225, 226, 227, 228, 229, 230, 231,
00289  232, 233, 234, 235, 236, 237, 238, 239,
00290  240, 241, 242, 243, 244, 245, 246, 247,
00291  248, 249, 250, 251, 252, 253, 254, 255,
00292    0,
00293 };
00294 
00295 /* unquant tables (not used directly) */
00296 static const uint8_t dv_quant_shifts[22][4] = {
00297   { 3,3,4,4 },
00298   { 3,3,4,4 },
00299   { 2,3,3,4 },
00300   { 2,3,3,4 },
00301   { 2,2,3,3 },
00302   { 2,2,3,3 },
00303   { 1,2,2,3 },
00304   { 1,2,2,3 },
00305   { 1,1,2,2 },
00306   { 1,1,2,2 },
00307   { 0,1,1,2 },
00308   { 0,1,1,2 },
00309   { 0,0,1,1 },
00310   { 0,0,1,1 },
00311   { 0,0,0,1 },
00312   { 0,0,0,0 },
00313   { 0,0,0,0 },
00314   { 0,0,0,0 },
00315   { 0,0,0,0 },
00316   { 0,0,0,0 },
00317   { 0,0,0,0 },
00318   { 0,0,0,0 },
00319 };
00320 
00321 static const uint8_t dv_quant_offset[4] = { 6,  3,  0,  1 };
00322 static const uint8_t dv_quant_areas[4]  = { 6, 21, 43, 64 };
00323 
00324 /* quantization quanta by QNO for DV100 */
00325 static const uint8_t dv100_qstep[16] = {
00326     1, /* QNO = 0 and 1 both have no quantization */
00327     1,
00328     2, 3, 4, 5, 6, 7, 8, 16, 18, 20, 22, 24, 28, 52
00329 };
00330 
00331 /* DV25/50 DCT coefficient weights and inverse weights */
00332 /* created by dvtables.py */
00333 static const int dv_weight_bits = 18;
00334 static const int dv_weight_88[64] = {
00335  131072, 257107, 257107, 242189, 252167, 242189, 235923, 237536,
00336  237536, 235923, 229376, 231390, 223754, 231390, 229376, 222935,
00337  224969, 217965, 217965, 224969, 222935, 200636, 218652, 211916,
00338  212325, 211916, 218652, 200636, 188995, 196781, 205965, 206433,
00339  206433, 205965, 196781, 188995, 185364, 185364, 200636, 200704,
00340  200636, 185364, 185364, 174609, 180568, 195068, 195068, 180568,
00341  174609, 170091, 175557, 189591, 175557, 170091, 165371, 170627,
00342  170627, 165371, 160727, 153560, 160727, 144651, 144651, 136258,
00343 };
00344 static const int dv_weight_248[64] = {
00345  131072, 242189, 257107, 237536, 229376, 200636, 242189, 223754,
00346  224969, 196781, 262144, 242189, 229376, 200636, 257107, 237536,
00347  211916, 185364, 235923, 217965, 229376, 211916, 206433, 180568,
00348  242189, 223754, 224969, 196781, 211916, 185364, 235923, 217965,
00349  200704, 175557, 222935, 205965, 200636, 185364, 195068, 170627,
00350  229376, 211916, 206433, 180568, 200704, 175557, 222935, 205965,
00351  175557, 153560, 188995, 174609, 165371, 144651, 200636, 185364,
00352  195068, 170627, 175557, 153560, 188995, 174609, 165371, 144651,
00353 };
00354 static const int dv_iweight_bits = 14;
00355 static const int dv_iweight_88[64] = {
00356  32768, 16710, 16710, 17735, 17015, 17735, 18197, 18079,
00357  18079, 18197, 18725, 18559, 19196, 18559, 18725, 19284,
00358  19108, 19692, 19692, 19108, 19284, 21400, 19645, 20262,
00359  20214, 20262, 19645, 21400, 22733, 21845, 20867, 20815,
00360  20815, 20867, 21845, 22733, 23173, 23173, 21400, 21400,
00361  21400, 23173, 23173, 24600, 23764, 22017, 22017, 23764,
00362  24600, 25267, 24457, 22672, 24457, 25267, 25971, 25191,
00363  25191, 25971, 26715, 27962, 26715, 29642, 29642, 31536,
00364 };
00365 static const int dv_iweight_248[64] = {
00366  32768, 17735, 16710, 18079, 18725, 21400, 17735, 19196,
00367  19108, 21845, 16384, 17735, 18725, 21400, 16710, 18079,
00368  20262, 23173, 18197, 19692, 18725, 20262, 20815, 23764,
00369  17735, 19196, 19108, 21845, 20262, 23173, 18197, 19692,
00370  21400, 24457, 19284, 20867, 21400, 23173, 22017, 25191,
00371  18725, 20262, 20815, 23764, 21400, 24457, 19284, 20867,
00372  24457, 27962, 22733, 24600, 25971, 29642, 21400, 23173,
00373  22017, 25191, 24457, 27962, 22733, 24600, 25971, 29642,
00374 };
00375 
00379 static const int dv_iweight_1080_y[64] = {
00380     128,  16,  16,  17,  17,  17,  18,  18,
00381      18,  18,  18,  18,  19,  18,  18,  19,
00382      19,  19,  19,  19,  19,  42,  38,  40,
00383      40,  40,  38,  42,  44,  43,  41,  41,
00384      41,  41,  43,  44,  45,  45,  42,  42,
00385      42,  45,  45,  48,  46,  43,  43,  46,
00386      48,  49,  48,  44,  48,  49, 101,  98,
00387      98, 101, 104, 109, 104, 116, 116, 123,
00388 };
00389 static const int dv_iweight_1080_c[64] = {
00390     128,  16,  16,  17,  17,  17,  25,  25,
00391      25,  25,  26,  25,  26,  25,  26,  26,
00392      26,  27,  27,  26,  26,  42,  38,  40,
00393      40,  40,  38,  42,  44,  43,  41,  41,
00394      41,  41,  43,  44,  91,  91,  84,  84,
00395      84,  91,  91,  96,  93,  86,  86,  93,
00396      96, 197, 191, 177, 191, 197, 203, 197,
00397     197, 203, 209, 219, 209, 232, 232, 246,
00398 };
00399 static const int dv_iweight_720_y[64] = {
00400     128,  16,  16,  17,  17,  17,  18,  18,
00401      18,  18,  18,  18,  19,  18,  18,  19,
00402      19,  19,  19,  19,  19,  42,  38,  40,
00403      40,  40,  38,  42,  44,  43,  41,  41,
00404      41,  41,  43,  44,  68,  68,  63,  63,
00405      63,  68,  68,  96,  92,  86,  86,  92,
00406      96,  98,  96,  88,  96,  98, 202, 196,
00407     196, 202, 208, 218, 208, 232, 232, 246,
00408 };
00409 static const int dv_iweight_720_c[64] = {
00410     128,  24,  24,  26,  26,  26,  36,  36,
00411      36,  36,  36,  36,  38,  36,  36,  38,
00412      38,  38,  38,  38,  38,  84,  76,  80,
00413      80,  80,  76,  84,  88,  86,  82,  82,
00414      82,  82,  86,  88, 182, 182, 168, 168,
00415     168, 182, 182, 192, 186, 192, 172, 186,
00416     192, 394, 382, 354, 382, 394, 406, 394,
00417     394, 406, 418, 438, 418, 464, 464, 492,
00418 };
00419 
00420 static const uint8_t dv_audio_shuffle525[10][9] = {
00421   {  0, 30, 60, 20, 50, 80, 10, 40, 70 }, /* 1st channel */
00422   {  6, 36, 66, 26, 56, 86, 16, 46, 76 },
00423   { 12, 42, 72,  2, 32, 62, 22, 52, 82 },
00424   { 18, 48, 78,  8, 38, 68, 28, 58, 88 },
00425   { 24, 54, 84, 14, 44, 74,  4, 34, 64 },
00426 
00427   {  1, 31, 61, 21, 51, 81, 11, 41, 71 }, /* 2nd channel */
00428   {  7, 37, 67, 27, 57, 87, 17, 47, 77 },
00429   { 13, 43, 73,  3, 33, 63, 23, 53, 83 },
00430   { 19, 49, 79,  9, 39, 69, 29, 59, 89 },
00431   { 25, 55, 85, 15, 45, 75,  5, 35, 65 },
00432 };
00433 
00434 static const uint8_t dv_audio_shuffle625[12][9] = {
00435   {   0,  36,  72,  26,  62,  98,  16,  52,  88}, /* 1st channel */
00436   {   6,  42,  78,  32,  68, 104,  22,  58,  94},
00437   {  12,  48,  84,   2,  38,  74,  28,  64, 100},
00438   {  18,  54,  90,   8,  44,  80,  34,  70, 106},
00439   {  24,  60,  96,  14,  50,  86,   4,  40,  76},
00440   {  30,  66, 102,  20,  56,  92,  10,  46,  82},
00441 
00442   {   1,  37,  73,  27,  63,  99,  17,  53,  89}, /* 2nd channel */
00443   {   7,  43,  79,  33,  69, 105,  23,  59,  95},
00444   {  13,  49,  85,   3,  39,  75,  29,  65, 101},
00445   {  19,  55,  91,   9,  45,  81,  35,  71, 107},
00446   {  25,  61,  97,  15,  51,  87,   5,  41,  77},
00447   {  31,  67, 103,  21,  57,  93,  11,  47,  83},
00448 };
00449 
00450 static const av_unused int dv_audio_frequency[3] = {
00451     48000, 44100, 32000,
00452 };
00453 
00454 /* macroblock bit budgets */
00455 static const uint8_t block_sizes_dv2550[8] = {
00456     112, 112, 112, 112, 80, 80, 0, 0,
00457 };
00458 
00459 static const uint8_t block_sizes_dv100[8] = {
00460     80, 80, 80, 80, 80, 80, 64, 64,
00461 };
00462 
00463 static DVwork_chunk work_chunks_dv25pal   [1*12*27];
00464 static DVwork_chunk work_chunks_dv25pal411[1*12*27];
00465 static DVwork_chunk work_chunks_dv25ntsc  [1*10*27];
00466 static DVwork_chunk work_chunks_dv50pal   [2*12*27];
00467 static DVwork_chunk work_chunks_dv50ntsc  [2*10*27];
00468 static DVwork_chunk work_chunks_dv100palp [2*12*27];
00469 static DVwork_chunk work_chunks_dv100ntscp[2*10*27];
00470 static DVwork_chunk work_chunks_dv100pali [4*12*27];
00471 static DVwork_chunk work_chunks_dv100ntsci[4*10*27];
00472 
00473 static uint32_t dv_idct_factor_sd    [2*2*22*64];
00474 static uint32_t dv_idct_factor_hd1080[2*4*16*64];
00475 static uint32_t dv_idct_factor_hd720 [2*4*16*64];
00476 
00477 static const DVprofile dv_profiles[] = {
00478     { .dsf = 0,
00479       .video_stype = 0x0,
00480       .frame_size = 120000,        /* IEC 61834, SMPTE-314M - 525/60 (NTSC) */
00481       .difseg_size = 10,
00482       .n_difchan = 1,
00483       .time_base = { 1001, 30000 },
00484       .ltc_divisor = 30,
00485       .height = 480,
00486       .width = 720,
00487       .sar = {{10, 11}, {40, 33}},
00488       .work_chunks = &work_chunks_dv25ntsc[0],
00489       .idct_factor = &dv_idct_factor_sd[0],
00490       .pix_fmt = PIX_FMT_YUV411P,
00491       .bpm = 6,
00492       .block_sizes = block_sizes_dv2550,
00493       .audio_stride = 90,
00494       .audio_min_samples  = { 1580, 1452, 1053 }, /* for 48, 44.1 and 32kHz */
00495       .audio_samples_dist = { 1600, 1602, 1602, 1602, 1602 }, /* per SMPTE-314M */
00496       .audio_shuffle = dv_audio_shuffle525,
00497     },
00498     { .dsf = 1,
00499       .video_stype = 0x0,
00500       .frame_size = 144000,        /* IEC 61834 - 625/50 (PAL) */
00501       .difseg_size = 12,
00502       .n_difchan = 1,
00503       .time_base = { 1, 25 },
00504       .ltc_divisor = 25,
00505       .height = 576,
00506       .width = 720,
00507       .sar = {{59, 54}, {118, 81}},
00508       .work_chunks = &work_chunks_dv25pal[0],
00509       .idct_factor = &dv_idct_factor_sd[0],
00510       .pix_fmt = PIX_FMT_YUV420P,
00511       .bpm = 6,
00512       .block_sizes = block_sizes_dv2550,
00513       .audio_stride = 108,
00514       .audio_min_samples  = { 1896, 1742, 1264 }, /* for 48, 44.1 and 32kHz */
00515       .audio_samples_dist = { 1920, 1920, 1920, 1920, 1920 },
00516       .audio_shuffle = dv_audio_shuffle625,
00517     },
00518     { .dsf = 1,
00519       .video_stype = 0x0,
00520       .frame_size = 144000,        /* SMPTE-314M - 625/50 (PAL) */
00521       .difseg_size = 12,
00522       .n_difchan = 1,
00523       .time_base = { 1, 25 },
00524       .ltc_divisor = 25,
00525       .height = 576,
00526       .width = 720,
00527       .sar = {{59, 54}, {118, 81}},
00528       .work_chunks = &work_chunks_dv25pal411[0],
00529       .idct_factor = &dv_idct_factor_sd[0],
00530       .pix_fmt = PIX_FMT_YUV411P,
00531       .bpm = 6,
00532       .block_sizes = block_sizes_dv2550,
00533       .audio_stride = 108,
00534       .audio_min_samples  = { 1896, 1742, 1264 }, /* for 48, 44.1 and 32kHz */
00535       .audio_samples_dist = { 1920, 1920, 1920, 1920, 1920 },
00536       .audio_shuffle = dv_audio_shuffle625,
00537     },
00538     { .dsf = 0,
00539       .video_stype = 0x4,
00540       .frame_size = 240000,        /* SMPTE-314M - 525/60 (NTSC) 50 Mbps */
00541       .difseg_size = 10,           /* also known as "DVCPRO50" */
00542       .n_difchan = 2,
00543       .time_base = { 1001, 30000 },
00544       .ltc_divisor = 30,
00545       .height = 480,
00546       .width = 720,
00547       .sar = {{10, 11}, {40, 33}},
00548       .work_chunks = &work_chunks_dv50ntsc[0],
00549       .idct_factor = &dv_idct_factor_sd[0],
00550       .pix_fmt = PIX_FMT_YUV422P,
00551       .bpm = 6,
00552       .block_sizes = block_sizes_dv2550,
00553       .audio_stride = 90,
00554       .audio_min_samples  = { 1580, 1452, 1053 }, /* for 48, 44.1 and 32kHz */
00555       .audio_samples_dist = { 1600, 1602, 1602, 1602, 1602 }, /* per SMPTE-314M */
00556       .audio_shuffle = dv_audio_shuffle525,
00557     },
00558     { .dsf = 1,
00559       .video_stype = 0x4,
00560       .frame_size = 288000,        /* SMPTE-314M - 625/50 (PAL) 50 Mbps */
00561       .difseg_size = 12,           /* also known as "DVCPRO50" */
00562       .n_difchan = 2,
00563       .time_base = { 1, 25 },
00564       .ltc_divisor = 25,
00565       .height = 576,
00566       .width = 720,
00567       .sar = {{59, 54}, {118, 81}},
00568       .work_chunks = &work_chunks_dv50pal[0],
00569       .idct_factor = &dv_idct_factor_sd[0],
00570       .pix_fmt = PIX_FMT_YUV422P,
00571       .bpm = 6,
00572       .block_sizes = block_sizes_dv2550,
00573       .audio_stride = 108,
00574       .audio_min_samples  = { 1896, 1742, 1264 }, /* for 48, 44.1 and 32kHz */
00575       .audio_samples_dist = { 1920, 1920, 1920, 1920, 1920 },
00576       .audio_shuffle = dv_audio_shuffle625,
00577     },
00578     { .dsf = 0,
00579       .video_stype = 0x14,
00580       .frame_size = 480000,        /* SMPTE-370M - 1080i60 100 Mbps */
00581       .difseg_size = 10,           /* also known as "DVCPRO HD" */
00582       .n_difchan = 4,
00583       .time_base = { 1001, 30000 },
00584       .ltc_divisor = 30,
00585       .height = 1080,
00586       .width = 1280,
00587       .sar = {{1, 1}, {1, 1}},
00588       .work_chunks = &work_chunks_dv100ntsci[0],
00589       .idct_factor = &dv_idct_factor_hd1080[0],
00590       .pix_fmt = PIX_FMT_YUV422P,
00591       .bpm = 8,
00592       .block_sizes = block_sizes_dv100,
00593       .audio_stride = 90,
00594       .audio_min_samples  = { 1580, 1452, 1053 }, /* for 48, 44.1 and 32kHz */
00595       .audio_samples_dist = { 1600, 1602, 1602, 1602, 1602 }, /* per SMPTE-314M */
00596       .audio_shuffle = dv_audio_shuffle525,
00597     },
00598     { .dsf = 1,
00599       .video_stype = 0x14,
00600       .frame_size = 576000,        /* SMPTE-370M - 1080i50 100 Mbps */
00601       .difseg_size = 12,           /* also known as "DVCPRO HD" */
00602       .n_difchan = 4,
00603       .time_base = { 1, 25 },
00604       .ltc_divisor = 25,
00605       .height = 1080,
00606       .width = 1440,
00607       .sar = {{1, 1}, {1, 1}},
00608       .work_chunks = &work_chunks_dv100pali[0],
00609       .idct_factor = &dv_idct_factor_hd1080[0],
00610       .pix_fmt = PIX_FMT_YUV422P,
00611       .bpm = 8,
00612       .block_sizes = block_sizes_dv100,
00613       .audio_stride = 108,
00614       .audio_min_samples  = { 1896, 1742, 1264 }, /* for 48, 44.1 and 32kHz */
00615       .audio_samples_dist = { 1920, 1920, 1920, 1920, 1920 },
00616       .audio_shuffle = dv_audio_shuffle625,
00617     },
00618     { .dsf = 0,
00619       .video_stype = 0x18,
00620       .frame_size = 240000,        /* SMPTE-370M - 720p60 100 Mbps */
00621       .difseg_size = 10,           /* also known as "DVCPRO HD" */
00622       .n_difchan = 2,
00623       .time_base = { 1001, 60000 },
00624       .ltc_divisor = 60,
00625       .height = 720,
00626       .width = 960,
00627       .sar = {{1, 1}, {1, 1}},
00628       .work_chunks = &work_chunks_dv100ntscp[0],
00629       .idct_factor = &dv_idct_factor_hd720[0],
00630       .pix_fmt = PIX_FMT_YUV422P,
00631       .bpm = 8,
00632       .block_sizes = block_sizes_dv100,
00633       .audio_stride = 90,
00634       .audio_min_samples  = { 1580, 1452, 1053 }, /* for 48, 44.1 and 32kHz */
00635       .audio_samples_dist = { 1600, 1602, 1602, 1602, 1602 }, /* per SMPTE-314M */
00636       .audio_shuffle = dv_audio_shuffle525,
00637     },
00638     { .dsf = 1,
00639       .video_stype = 0x18,
00640       .frame_size = 288000,        /* SMPTE-370M - 720p50 100 Mbps */
00641       .difseg_size = 12,           /* also known as "DVCPRO HD" */
00642       .n_difchan = 2,
00643       .time_base = { 1, 50 },
00644       .ltc_divisor = 50,
00645       .height = 720,
00646       .width = 960,
00647       .sar = {{1, 1}, {1, 1}},
00648       .work_chunks = &work_chunks_dv100palp[0],
00649       .idct_factor = &dv_idct_factor_hd720[0],
00650       .pix_fmt = PIX_FMT_YUV422P,
00651       .bpm = 8,
00652       .block_sizes = block_sizes_dv100,
00653       .audio_stride = 90,
00654       .audio_min_samples  = { 1896, 1742, 1264 }, /* for 48, 44.1 and 32kHz */
00655       .audio_samples_dist = { 1920, 1920, 1920, 1920, 1920 },
00656       .audio_shuffle = dv_audio_shuffle625,
00657     }
00658 };
00659 
00660 enum dv_section_type {
00661      dv_sect_header  = 0x1f,
00662      dv_sect_subcode = 0x3f,
00663      dv_sect_vaux    = 0x56,
00664      dv_sect_audio   = 0x76,
00665      dv_sect_video   = 0x96,
00666 };
00667 
00668 enum dv_pack_type {
00669      dv_header525     = 0x3f, /* see dv_write_pack for important details on */
00670      dv_header625     = 0xbf, /* these two packs */
00671      dv_timecode      = 0x13,
00672      dv_audio_source  = 0x50,
00673      dv_audio_control = 0x51,
00674      dv_audio_recdate = 0x52,
00675      dv_audio_rectime = 0x53,
00676      dv_video_source  = 0x60,
00677      dv_video_control = 0x61,
00678      dv_video_recdate = 0x62,
00679      dv_video_rectime = 0x63,
00680      dv_unknown_pack  = 0xff,
00681 };
00682 
00683 #define DV_PROFILE_IS_HD(p) ((p)->video_stype & 0x10)
00684 #define DV_PROFILE_IS_1080i50(p) (((p)->video_stype == 0x14) && ((p)->dsf == 1))
00685 #define DV_PROFILE_IS_720p50(p)  (((p)->video_stype == 0x18) && ((p)->dsf == 1))
00686 
00687 /* minimum number of bytes to read from a DV stream in order to
00688    determine the profile */
00689 #define DV_PROFILE_BYTES (6*80) /* 6 DIF blocks */
00690 
00694 #define DV_MAX_FRAME_SIZE 576000
00695 
00699 #define DV_MAX_BPM 8
00700 
00701 static inline
00702 const DVprofile* dv_frame_profile(const DVprofile *sys,
00703                                   const uint8_t* frame, unsigned buf_size)
00704 {
00705    int i;
00706 
00707    int dsf = (frame[3] & 0x80) >> 7;
00708 
00709    int stype = frame[80*5 + 48 + 3] & 0x1f;
00710 
00711    /* 576i50 25Mbps 4:1:1 is a special case */
00712    if (dsf == 1 && stype == 0 && frame[5] & 0x07) {
00713        return &dv_profiles[2];
00714    }
00715 
00716    for (i=0; i<FF_ARRAY_ELEMS(dv_profiles); i++)
00717        if (dsf == dv_profiles[i].dsf && stype == dv_profiles[i].video_stype)
00718            return &dv_profiles[i];
00719 
00720    /* check if old sys matches and assumes corrupted input */
00721    if (sys && buf_size == sys->frame_size)
00722        return sys;
00723 
00724    return NULL;
00725 }
00726 
00727 static const DVprofile* dv_codec_profile(AVCodecContext* codec)
00728 {
00729     int i;
00730 
00731     for (i=0; i<FF_ARRAY_ELEMS(dv_profiles); i++)
00732        if (codec->height  == dv_profiles[i].height  &&
00733            codec->pix_fmt == dv_profiles[i].pix_fmt &&
00734            codec->width   == dv_profiles[i].width)
00735                return &dv_profiles[i];
00736 
00737     return NULL;
00738 }
00739 
00740 static inline int dv_write_dif_id(enum dv_section_type t, uint8_t chan_num,
00741                                   uint8_t seq_num, uint8_t dif_num,
00742                                   uint8_t* buf)
00743 {
00744     buf[0] = (uint8_t)t;       /* Section type */
00745     buf[1] = (seq_num  << 4) | /* DIF seq number 0-9 for 525/60; 0-11 for 625/50 */
00746              (chan_num << 3) | /* FSC: for 50Mb/s 0 - first channel; 1 - second */
00747              7;                /* reserved -- always 1 */
00748     buf[2] = dif_num;          /* DIF block number Video: 0-134, Audio: 0-8 */
00749     return 3;
00750 }
00751 
00752 
00753 static inline int dv_write_ssyb_id(uint8_t syb_num, uint8_t fr, uint8_t* buf)
00754 {
00755     if (syb_num == 0 || syb_num == 6) {
00756         buf[0] = (fr << 7) | /* FR ID 1 - first half of each channel; 0 - second */
00757                  (0  << 4) | /* AP3 (Subcode application ID) */
00758                  0x0f;       /* reserved -- always 1 */
00759     }
00760     else if (syb_num == 11) {
00761         buf[0] = (fr << 7) | /* FR ID 1 - first half of each channel; 0 - second */
00762                  0x7f;       /* reserved -- always 1 */
00763     }
00764     else {
00765         buf[0] = (fr << 7) | /* FR ID 1 - first half of each channel; 0 - second */
00766                  (0  << 4) | /* APT (Track application ID) */
00767                  0x0f;       /* reserved -- always 1 */
00768     }
00769     buf[1] = 0xf0 |            /* reserved -- always 1 */
00770              (syb_num & 0x0f); /* SSYB number 0 - 11   */
00771     buf[2] = 0xff;             /* reserved -- always 1 */
00772     return 3;
00773 }
00774 
00775 #endif /* AVCODEC_DVDATA_H */

Generated on Sat Feb 16 2013 09:23:12 for ffmpeg by  doxygen 1.7.1