]> git.sesse.net Git - ffmpeg/blob - libavcodec/dvdata.h
8b4811ac69db4fb8ea85852681d084a4aefb850e
[ffmpeg] / libavcodec / dvdata.h
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 /**
23  * @file
24  * Constants for DV codec.
25  */
26
27 #ifndef AVCODEC_DVDATA_H
28 #define AVCODEC_DVDATA_H
29
30 #include "libavutil/rational.h"
31 #include "avcodec.h"
32 #include "dsputil.h"
33 #include "get_bits.h"
34
35 typedef struct DVwork_chunk {
36     uint16_t  buf_offset;
37     uint16_t  mb_coordinates[5];
38 } DVwork_chunk;
39
40 /*
41  * DVprofile is used to express the differences between various
42  * DV flavors. For now it's primarily used for differentiating
43  * 525/60 and 625/50, but the plans are to use it for various
44  * DV specs as well (e.g. SMPTE314M vs. IEC 61834).
45  */
46 typedef struct DVprofile {
47     int              dsf;                   /* value of the dsf in the DV header */
48     int              video_stype;           /* stype for VAUX source pack */
49     int              frame_size;            /* total size of one frame in bytes */
50     int              difseg_size;           /* number of DIF segments per DIF channel */
51     int              n_difchan;             /* number of DIF channels per frame */
52     AVRational       time_base;             /* 1/framerate */
53     int              ltc_divisor;           /* FPS from the LTS standpoint */
54     int              height;                /* picture height in pixels */
55     int              width;                 /* picture width in pixels */
56     AVRational       sar[2];                /* sample aspect ratios for 4:3 and 16:9 */
57     DVwork_chunk    *work_chunks;           /* each thread gets its own chunk of frame to work on */
58     uint32_t        *idct_factor;           /* set of iDCT factor tables */
59     enum PixelFormat pix_fmt;               /* picture pixel format */
60     int              bpm;                   /* blocks per macroblock */
61     const uint8_t   *block_sizes;           /* AC block sizes, in bits */
62     int              audio_stride;          /* size of audio_shuffle table */
63     int              audio_min_samples[3];  /* min amount of audio samples */
64                                             /* for 48kHz, 44.1kHz and 32kHz */
65     int              audio_samples_dist[5]; /* how many samples are supposed to be */
66                                             /* in each frame in a 5 frames window */
67     const uint8_t  (*audio_shuffle)[9];     /* PCM shuffling table */
68 } DVprofile;
69
70 typedef struct DVVideoContext {
71     const DVprofile *sys;
72     AVFrame          picture;
73     AVCodecContext  *avctx;
74     uint8_t         *buf;
75
76     uint8_t  dv_zigzag[2][64];
77
78     void (*get_pixels)(DCTELEM *block, const uint8_t *pixels, int line_size);
79     void (*fdct[2])(DCTELEM *block);
80     void (*idct_put[2])(uint8_t *dest, int line_size, DCTELEM *block);
81     me_cmp_func ildct_cmp;
82 } DVVideoContext;
83
84 enum dv_section_type {
85      dv_sect_header  = 0x1f,
86      dv_sect_subcode = 0x3f,
87      dv_sect_vaux    = 0x56,
88      dv_sect_audio   = 0x76,
89      dv_sect_video   = 0x96,
90 };
91
92 enum dv_pack_type {
93      dv_header525     = 0x3f, /* see dv_write_pack for important details on */
94      dv_header625     = 0xbf, /* these two packs */
95      dv_timecode      = 0x13,
96      dv_audio_source  = 0x50,
97      dv_audio_control = 0x51,
98      dv_audio_recdate = 0x52,
99      dv_audio_rectime = 0x53,
100      dv_video_source  = 0x60,
101      dv_video_control = 0x61,
102      dv_video_recdate = 0x62,
103      dv_video_rectime = 0x63,
104      dv_unknown_pack  = 0xff,
105 };
106
107 #define DV_PROFILE_IS_HD(p) ((p)->video_stype & 0x10)
108 #define DV_PROFILE_IS_1080i50(p) (((p)->video_stype == 0x14) && ((p)->dsf == 1))
109 #define DV_PROFILE_IS_720p50(p)  (((p)->video_stype == 0x18) && ((p)->dsf == 1))
110
111 /* minimum number of bytes to read from a DV stream in order to
112    determine the profile */
113 #define DV_PROFILE_BYTES (6*80) /* 6 DIF blocks */
114
115 /**
116  * largest possible DV frame, in bytes (1080i50)
117  */
118 #define DV_MAX_FRAME_SIZE 576000
119
120 /**
121  * maximum number of blocks per macroblock in any DV format
122  */
123 #define DV_MAX_BPM 8
124
125 #define TEX_VLC_BITS 9
126
127 extern RL_VLC_ELEM ff_dv_rl_vlc[1184];
128
129 const DVprofile* avpriv_dv_frame_profile(const DVprofile *sys,
130                                          const uint8_t* frame, unsigned buf_size);
131 const DVprofile* avpriv_dv_codec_profile(AVCodecContext* codec);
132
133 int ff_dv_init_dynamic_tables(const DVprofile *d);
134 int ff_dvvideo_init(AVCodecContext *avctx);
135
136 static inline int dv_work_pool_size(const DVprofile *d)
137 {
138     int size = d->n_difchan*d->difseg_size*27;
139     if (DV_PROFILE_IS_1080i50(d))
140         size -= 3*27;
141     if (DV_PROFILE_IS_720p50(d))
142         size -= 4*27;
143     return size;
144 }
145
146 static inline void dv_calculate_mb_xy(DVVideoContext *s, DVwork_chunk *work_chunk, int m, int *mb_x, int *mb_y)
147 {
148      *mb_x = work_chunk->mb_coordinates[m] & 0xff;
149      *mb_y = work_chunk->mb_coordinates[m] >> 8;
150
151      /* We work with 720p frames split in half. The odd half-frame (chan==2,3) is displaced :-( */
152      if (s->sys->height == 720 && !(s->buf[1]&0x0C)) {
153          *mb_y -= (*mb_y>17)?18:-72; /* shifting the Y coordinate down by 72/2 macro blocks */
154      }
155 }
156
157 /**
158  *  Print all allowed DV profiles into logctx at specified logging level.
159  */
160 void ff_dv_print_profiles(void *logctx, int loglevel);
161
162 #endif /* AVCODEC_DVDATA_H */