lavc: export DV profile API used by muxer/demuxer as public
[libav.git] / libavcodec / dv.h
CommitLineData
3cbe1126
DB
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_DV_H
28#define AVCODEC_DV_H
29
30#include "avcodec.h"
31#include "dsputil.h"
32#include "get_bits.h"
33#include "dv_profile.h"
34
650dee63
AK
35typedef struct DVwork_chunk {
36 uint16_t buf_offset;
37 uint16_t mb_coordinates[5];
38} DVwork_chunk;
39
3cbe1126 40typedef struct DVVideoContext {
f6ee61fb 41 const AVDVProfile *sys;
d4f1188d 42 AVFrame *frame;
3cbe1126
DB
43 AVCodecContext *avctx;
44 uint8_t *buf;
45
46 uint8_t dv_zigzag[2][64];
47
48 void (*get_pixels)(int16_t *block, const uint8_t *pixels, int line_size);
49 void (*fdct[2])(int16_t *block);
50 void (*idct_put[2])(uint8_t *dest, int line_size, int16_t *block);
51 me_cmp_func ildct_cmp;
650dee63
AK
52 DVwork_chunk work_chunks[4 * 12 * 27];
53 uint32_t idct_factor[2 * 4 * 16 * 64];
3cbe1126
DB
54} DVVideoContext;
55
56enum dv_section_type {
57 dv_sect_header = 0x1f,
58 dv_sect_subcode = 0x3f,
59 dv_sect_vaux = 0x56,
60 dv_sect_audio = 0x76,
61 dv_sect_video = 0x96,
62};
63
64enum dv_pack_type {
65 dv_header525 = 0x3f, /* see dv_write_pack for important details on */
66 dv_header625 = 0xbf, /* these two packs */
67 dv_timecode = 0x13,
68 dv_audio_source = 0x50,
69 dv_audio_control = 0x51,
70 dv_audio_recdate = 0x52,
71 dv_audio_rectime = 0x53,
72 dv_video_source = 0x60,
73 dv_video_control = 0x61,
74 dv_video_recdate = 0x62,
75 dv_video_rectime = 0x63,
76 dv_unknown_pack = 0xff,
77};
78
79#define DV_PROFILE_IS_HD(p) ((p)->video_stype & 0x10)
80#define DV_PROFILE_IS_1080i50(p) (((p)->video_stype == 0x14) && ((p)->dsf == 1))
81#define DV_PROFILE_IS_720p50(p) (((p)->video_stype == 0x18) && ((p)->dsf == 1))
82
83/* minimum number of bytes to read from a DV stream in order to
84 determine the profile */
85#define DV_PROFILE_BYTES (6*80) /* 6 DIF blocks */
86
87/**
88 * largest possible DV frame, in bytes (1080i50)
89 */
90#define DV_MAX_FRAME_SIZE 576000
91
92/**
93 * maximum number of blocks per macroblock in any DV format
94 */
95#define DV_MAX_BPM 8
96
97#define TEX_VLC_BITS 9
98
99extern RL_VLC_ELEM ff_dv_rl_vlc[1184];
100
f6ee61fb 101int ff_dv_init_dynamic_tables(DVVideoContext *s, const AVDVProfile *d);
3cbe1126
DB
102int ff_dvvideo_init(AVCodecContext *avctx);
103
f6ee61fb 104static inline int dv_work_pool_size(const AVDVProfile *d)
3cbe1126
DB
105{
106 int size = d->n_difchan*d->difseg_size*27;
107 if (DV_PROFILE_IS_1080i50(d))
108 size -= 3*27;
109 if (DV_PROFILE_IS_720p50(d))
110 size -= 4*27;
111 return size;
112}
113
114static inline void dv_calculate_mb_xy(DVVideoContext *s, DVwork_chunk *work_chunk, int m, int *mb_x, int *mb_y)
115{
116 *mb_x = work_chunk->mb_coordinates[m] & 0xff;
117 *mb_y = work_chunk->mb_coordinates[m] >> 8;
118
119 /* We work with 720p frames split in half. The odd half-frame (chan==2,3) is displaced :-( */
120 if (s->sys->height == 720 && !(s->buf[1]&0x0C)) {
121 *mb_y -= (*mb_y>17)?18:-72; /* shifting the Y coordinate down by 72/2 macro blocks */
122 }
123}
124
125#endif /* AVCODEC_DV_H */