* Many thanks to Dan Dennedy <dan@dennedy.org> for providing wealth
* of DV technical info.
*
- * This library is free software; you can redistribute it and/or
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
+ * version 2.1 of the License, or (at your option) any later version.
*
- * This library is distributed in the hope that it will be useful,
+ * FFmpeg is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#define ALT_BITSTREAM_READER
#include "avcodec.h"
#include "dsputil.h"
-#include "mpegvideo.h"
+#include "bitstream.h"
#include "simple_idct.h"
#include "dvdata.h"
#endif
/* XXX: also include quantization */
-static RL_VLC_ELEM *dv_rl_vlc;
+static RL_VLC_ELEM dv_rl_vlc[1184];
/* VLC encoding lookup table */
static struct dv_vlc_pair {
uint32_t vlc;
uint8_t size;
-} (*dv_vlc_map)[DV_VLC_MAP_LEV_SIZE] = NULL;
+} dv_vlc_map[DV_VLC_MAP_RUN_SIZE][DV_VLC_MAP_LEV_SIZE];
static void dv_build_unquantize_tables(DVVideoContext *s, uint8_t* perm)
{
}
}
-static int dvvideo_init(AVCodecContext *avctx)
+static av_cold int dvvideo_init(AVCodecContext *avctx)
{
DVVideoContext *s = avctx->priv_data;
DSPContext dsp;
done = 1;
- dv_vlc_map = av_mallocz_static(DV_VLC_MAP_LEV_SIZE*DV_VLC_MAP_RUN_SIZE*sizeof(struct dv_vlc_pair));
- if (!dv_vlc_map)
- return -ENOMEM;
-
/* dv_anchor lets each thread know its Id */
for (i=0; i<DV_ANCHOR_SIZE; i++)
dv_anchor[i] = (void*)(size_t)i;
to accelerate the parsing of partial codes */
init_vlc(&dv_vlc, TEX_VLC_BITS, j,
new_dv_vlc_len, 1, 1, new_dv_vlc_bits, 2, 2, 0);
-
- dv_rl_vlc = av_mallocz_static(dv_vlc.table_size * sizeof(RL_VLC_ELEM));
- if (!dv_rl_vlc)
- return -ENOMEM;
+ assert(dv_vlc.table_size == 1184);
for(i = 0; i < dv_vlc.table_size; i++){
int code= dv_vlc.table[i][0];
/* 248DCT setup */
s->fdct[1] = dsp.fdct248;
- s->idct_put[1] = simple_idct248_put; // FIXME: need to add it to DSP
+ s->idct_put[1] = ff_simple_idct248_put; // FIXME: need to add it to DSP
if(avctx->lowres){
for (i=0; i<64; i++){
int j= ff_zigzag248_direct[i];
return s->size_in_bits - get_bits_count(s);
}
-static inline int get_bits_size(GetBitContext *s)
-{
- return s->size_in_bits;
-}
-
static inline int put_bits_left(PutBitContext* s)
{
return (s->buf_end - s->buf) * 8 - put_bits_count(s);
/* decode ac coefs */
static void dv_decode_ac(GetBitContext *gb, BlockInfo *mb, DCTELEM *block)
{
- int last_index = get_bits_size(gb);
+ int last_index = gb->size_in_bits;
const uint8_t *scan_table = mb->scan_table;
const uint8_t *shift_table = mb->shift_table;
const int *iweight_table = mb->iweight_table;
/* mb_x and mb_y are in units of 8 pixels */
static inline void dv_decode_video_segment(DVVideoContext *s,
- uint8_t *buf_ptr1,
+ const uint8_t *buf_ptr1,
const uint16_t *mb_pos_ptr)
{
int quant, dc, dct_mode, class1, j;
int c_offset;
uint8_t *y_ptr;
void (*idct_put)(uint8_t *dest, int line_size, DCTELEM *block);
- uint8_t *buf_ptr;
+ const uint8_t *buf_ptr;
PutBitContext pb, vs_pb;
GetBitContext gb;
BlockInfo mb_data[5 * 6], *mb, *mb1;
- DECLARE_ALIGNED_8(DCTELEM, sblock[5*6][64]);
+ DECLARE_ALIGNED_16(DCTELEM, sblock[5*6][64]);
DECLARE_ALIGNED_8(uint8_t, mb_bit_buffer[80 + 4]); /* allow some slack */
DECLARE_ALIGNED_8(uint8_t, vs_bit_buffer[5 * 80 + 4]); /* allow some slack */
const int log2_blocksize= 3-s->avctx->lowres;
#ifdef DV_CODEC_TINY_TARGET
/* Converts run and level (where level != 0) pair into vlc, returning bit size */
-static always_inline int dv_rl2vlc(int run, int level, int sign, uint32_t* vlc)
+static av_always_inline int dv_rl2vlc(int run, int level, int sign, uint32_t* vlc)
{
int size;
if (run < DV_VLC_MAP_RUN_SIZE && level < DV_VLC_MAP_LEV_SIZE) {
return size;
}
-static always_inline int dv_rl2vlc_size(int run, int level)
+static av_always_inline int dv_rl2vlc_size(int run, int level)
{
int size;
return size;
}
#else
-static always_inline int dv_rl2vlc(int run, int l, int sign, uint32_t* vlc)
+static av_always_inline int dv_rl2vlc(int run, int l, int sign, uint32_t* vlc)
{
*vlc = dv_vlc_map[run][l].vlc | sign;
return dv_vlc_map[run][l].size;
}
-static always_inline int dv_rl2vlc_size(int run, int l)
+static av_always_inline int dv_rl2vlc_size(int run, int l)
{
return dv_vlc_map[run][l].size;
}
uint32_t partial_bit_buffer; /* we can't use uint16_t here */
} EncBlockInfo;
-static always_inline PutBitContext* dv_encode_ac(EncBlockInfo* bi, PutBitContext* pb_pool,
+static av_always_inline PutBitContext* dv_encode_ac(EncBlockInfo* bi, PutBitContext* pb_pool,
PutBitContext* pb_end)
{
int prev;
return pb;
}
-static always_inline void dv_set_class_number(DCTELEM* blk, EncBlockInfo* bi,
+static av_always_inline void dv_set_class_number(DCTELEM* blk, EncBlockInfo* bi,
const uint8_t* zigzag_scan, const int *weight, int bias)
{
int i, area;
/* weigh it and and shift down into range, adding for rounding */
/* the extra division by a factor of 2^4 reverses the 8x expansion of the DCT
AND the 2x doubling of the weights */
- level = (ABS(level) * weight[i] + (1<<(dv_weight_bits+3))) >> (dv_weight_bits+4);
+ level = (FFABS(level) * weight[i] + (1<<(dv_weight_bits+3))) >> (dv_weight_bits+4);
bi->mb[i] = level;
if(level>max) max= level;
bi->bit_size[area] += dv_rl2vlc_size(i - prev - 1, level);
//FIXME replace this by dsputil
#define SC(x, y) ((s[x] - s[y]) ^ ((s[x] - s[y]) >> 7))
-static always_inline int dv_guess_dct_mode(DCTELEM *blk) {
+static av_always_inline int dv_guess_dct_mode(DCTELEM *blk) {
DCTELEM *s;
int score88 = 0;
int score248 = 0;
uint8_t* data;
uint8_t* ptr;
int do_edge_wrap;
- DECLARE_ALIGNED_8(DCTELEM, block[64]);
+ DECLARE_ALIGNED_16(DCTELEM, block[64]);
EncBlockInfo enc_blks[5*6];
PutBitContext pbs[5*6];
PutBitContext* pb;
int vs_bit_size = 0;
int qnos[5];
- assert((((int)block) & 7) == 0);
+ assert((((int)block) & 15) == 0);
enc_blk = &enc_blks[0];
pb = &pbs[0];
return 0;
}
+#ifdef CONFIG_ENCODERS
static int dv_encode_mt(AVCodecContext *avctx, void* sl)
{
DVVideoContext *s = avctx->priv_data;
&s->sys->video_place[slice*5]);
return 0;
}
+#endif
+#ifdef CONFIG_DECODERS
/* NOTE: exactly one frame must be given (120000 bytes for NTSC,
144000 bytes for PAL - or twice those for 50Mbps) */
static int dvvideo_decode_frame(AVCodecContext *avctx,
void *data, int *data_size,
- uint8_t *buf, int buf_size)
+ const uint8_t *buf, int buf_size)
{
DVVideoContext *s = avctx->priv_data;
s->picture.key_frame = 1;
s->picture.pict_type = FF_I_TYPE;
avctx->pix_fmt = s->sys->pix_fmt;
+ avctx->time_base = (AVRational){s->sys->frame_rate_base, s->sys->frame_rate};
avcodec_set_dimensions(avctx, s->sys->width, s->sys->height);
if(avctx->get_buffer(avctx, &s->picture) < 0) {
av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
return s->sys->frame_size;
}
+#endif
static inline int dv_write_pack(enum dv_pack_type pack_id, DVVideoContext *c, uint8_t* buf)
}
-
+#ifdef CONFIG_ENCODERS
static int dvvideo_encode_frame(AVCodecContext *c, uint8_t *buf, int buf_size,
void *data)
{
return s->sys->frame_size;
}
+#endif
static int dvvideo_close(AVCodecContext *c)
{
+ DVVideoContext *s = c->priv_data;
+
+ if(s->picture.data[0])
+ c->release_buffer(c, &s->picture);
return 0;
}
sizeof(DVVideoContext),
dvvideo_init,
dvvideo_encode_frame,
- dvvideo_close,
- NULL,
- CODEC_CAP_DR1,
- NULL
+ .pix_fmts = (enum PixelFormat[]) {PIX_FMT_YUV411P, PIX_FMT_YUV422P, PIX_FMT_YUV420P, PIX_FMT_NONE},
+ .long_name = NULL_IF_CONFIG_SMALL("DV (Digital Video)"),
};
#endif // CONFIG_DVVIDEO_ENCODER
+#ifdef CONFIG_DVVIDEO_DECODER
AVCodec dvvideo_decoder = {
"dvvideo",
CODEC_TYPE_VIDEO,
dvvideo_close,
dvvideo_decode_frame,
CODEC_CAP_DR1,
- NULL
+ NULL,
+ .long_name = NULL_IF_CONFIG_SMALL("DV (Digital Video)"),
};
+#endif