2003-05-10 01:16:14 +03:00
|
|
|
/*
|
2009-01-19 17:46:40 +02:00
|
|
|
* Copyright (c) 2003 The FFmpeg Project
|
2003-05-10 01:16:14 +03:00
|
|
|
*
|
2006-10-07 18:30:46 +03:00
|
|
|
* This file is part of FFmpeg.
|
|
|
|
*
|
|
|
|
* FFmpeg is free software; you can redistribute it and/or
|
2003-05-10 01:16:14 +03:00
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
2006-10-07 18:30:46 +03:00
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
2003-05-10 01:16:14 +03:00
|
|
|
*
|
2006-10-07 18:30:46 +03:00
|
|
|
* FFmpeg is distributed in the hope that it will be useful,
|
2003-05-10 01:16:14 +03:00
|
|
|
* 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
|
2006-10-07 18:30:46 +03:00
|
|
|
* License along with FFmpeg; if not, write to the Free Software
|
2006-01-13 00:43:26 +02:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
2007-07-05 13:40:25 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2003-05-10 01:16:14 +03:00
|
|
|
* How to use this decoder:
|
|
|
|
* SVQ3 data is transported within Apple Quicktime files. Quicktime files
|
2003-05-10 07:30:29 +03:00
|
|
|
* have stsd atoms to describe media trak properties. A stsd atom for a
|
|
|
|
* video trak contains 1 or more ImageDescription atoms. These atoms begin
|
|
|
|
* with the 4-byte length of the atom followed by the codec fourcc. Some
|
|
|
|
* decoders need information in this atom to operate correctly. Such
|
|
|
|
* is the case with SVQ3. In order to get the best use out of this decoder,
|
|
|
|
* the calling app must make the SVQ3 ImageDescription atom available
|
2003-05-10 01:16:14 +03:00
|
|
|
* via the AVCodecContext's extradata[_size] field:
|
|
|
|
*
|
2005-12-17 20:14:38 +02:00
|
|
|
* AVCodecContext.extradata = pointer to ImageDescription, first characters
|
2003-05-10 07:30:29 +03:00
|
|
|
* are expected to be 'S', 'V', 'Q', and '3', NOT the 4-byte atom length
|
2005-12-17 20:14:38 +02:00
|
|
|
* AVCodecContext.extradata_size = size of ImageDescription atom memory
|
|
|
|
* buffer (which will be the same as the ImageDescription atom size field
|
2003-05-10 07:30:29 +03:00
|
|
|
* from the QT file, minus 4 bytes since the length is missing)
|
|
|
|
*
|
|
|
|
* You will know you have these parameters passed correctly when the decoder
|
|
|
|
* correctly decodes this file:
|
2008-12-25 17:49:02 +02:00
|
|
|
* http://samples.mplayerhq.hu/V-codecs/SVQ3/Vertical400kbit.sorenson3.mov
|
2003-05-10 01:16:14 +03:00
|
|
|
*/
|
2013-05-02 11:20:12 +03:00
|
|
|
|
2014-03-13 14:13:33 +03:00
|
|
|
#include <inttypes.h>
|
|
|
|
|
2013-05-02 11:20:12 +03:00
|
|
|
#include "libavutil/attributes.h"
|
2010-01-12 07:30:31 +02:00
|
|
|
#include "internal.h"
|
|
|
|
#include "avcodec.h"
|
2014-02-28 15:40:54 +03:00
|
|
|
#include "mpegutils.h"
|
2016-05-18 09:02:39 +02:00
|
|
|
#include "h264dec.h"
|
2013-08-19 15:24:45 +03:00
|
|
|
#include "h264data.h"
|
2010-01-12 07:30:31 +02:00
|
|
|
#include "golomb.h"
|
2013-03-11 00:12:58 +03:00
|
|
|
#include "hpeldsp.h"
|
2016-03-24 12:16:53 +02:00
|
|
|
#include "mathops.h"
|
2010-01-12 07:30:31 +02:00
|
|
|
#include "rectangle.h"
|
2013-12-21 18:03:59 +03:00
|
|
|
#include "tpeldsp.h"
|
2010-01-12 07:30:31 +02:00
|
|
|
|
2009-01-14 01:44:16 +02:00
|
|
|
#if CONFIG_ZLIB
|
2008-10-27 01:41:00 +02:00
|
|
|
#include <zlib.h>
|
|
|
|
#endif
|
|
|
|
|
2008-10-29 01:11:59 +02:00
|
|
|
#include "svq1.h"
|
|
|
|
|
2003-05-10 01:16:14 +03:00
|
|
|
/**
|
2010-04-20 17:45:34 +03:00
|
|
|
* @file
|
2003-05-10 01:16:14 +03:00
|
|
|
* svq3 decoder.
|
|
|
|
*/
|
|
|
|
|
2016-05-18 09:34:05 +02:00
|
|
|
typedef struct SVQ3Frame {
|
|
|
|
AVFrame *f;
|
|
|
|
|
|
|
|
AVBufferRef *motion_val_buf[2];
|
|
|
|
int16_t (*motion_val[2])[2];
|
|
|
|
|
|
|
|
AVBufferRef *mb_type_buf;
|
|
|
|
uint32_t *mb_type;
|
|
|
|
|
|
|
|
|
|
|
|
AVBufferRef *ref_index_buf[2];
|
|
|
|
int8_t *ref_index[2];
|
|
|
|
} SVQ3Frame;
|
|
|
|
|
2014-09-22 12:01:31 +03:00
|
|
|
typedef struct SVQ3Context {
|
2016-03-23 14:23:55 +02:00
|
|
|
AVCodecContext *avctx;
|
2016-03-22 16:32:57 +02:00
|
|
|
|
|
|
|
H264DSPContext h264dsp;
|
|
|
|
H264PredContext hpc;
|
2013-03-11 00:12:58 +03:00
|
|
|
HpelDSPContext hdsp;
|
2013-12-21 18:03:59 +03:00
|
|
|
TpelDSPContext tdsp;
|
2016-03-22 16:32:57 +02:00
|
|
|
VideoDSPContext vdsp;
|
|
|
|
|
2016-05-18 09:34:05 +02:00
|
|
|
SVQ3Frame *cur_pic;
|
|
|
|
SVQ3Frame *next_pic;
|
|
|
|
SVQ3Frame *last_pic;
|
2016-03-12 18:46:36 +02:00
|
|
|
GetBitContext gb;
|
2016-03-23 14:16:32 +02:00
|
|
|
GetBitContext gb_slice;
|
2016-03-12 18:46:36 +02:00
|
|
|
uint8_t *slice_buf;
|
|
|
|
int slice_size;
|
2011-05-05 15:18:33 +03:00
|
|
|
int halfpel_flag;
|
|
|
|
int thirdpel_flag;
|
2015-05-02 03:02:30 +02:00
|
|
|
int has_watermark;
|
2011-05-05 15:18:33 +03:00
|
|
|
uint32_t watermark_key;
|
2011-05-05 16:17:51 +03:00
|
|
|
uint8_t *buf;
|
|
|
|
int buf_size;
|
2013-02-03 13:10:05 +03:00
|
|
|
int adaptive_quant;
|
|
|
|
int next_p_frame_damaged;
|
|
|
|
int h_edge_pos;
|
|
|
|
int v_edge_pos;
|
|
|
|
int last_frame_output;
|
2016-03-23 11:43:41 +02:00
|
|
|
int slice_num;
|
|
|
|
int qscale;
|
|
|
|
int cbp;
|
2016-03-23 12:04:59 +02:00
|
|
|
int frame_num;
|
|
|
|
int frame_num_offset;
|
|
|
|
int prev_frame_num_offset;
|
|
|
|
int prev_frame_num;
|
2016-03-22 16:54:20 +02:00
|
|
|
|
2016-03-23 11:33:48 +02:00
|
|
|
enum AVPictureType pict_type;
|
2016-09-08 21:15:55 +02:00
|
|
|
enum AVPictureType slice_type;
|
2016-03-23 14:23:55 +02:00
|
|
|
int low_delay;
|
2016-03-23 11:33:48 +02:00
|
|
|
|
2016-03-22 16:54:20 +02:00
|
|
|
int mb_x, mb_y;
|
|
|
|
int mb_xy;
|
2016-03-23 11:33:48 +02:00
|
|
|
int mb_width, mb_height;
|
|
|
|
int mb_stride, mb_num;
|
|
|
|
int b_stride;
|
2016-03-23 10:49:20 +02:00
|
|
|
|
2016-03-23 11:03:50 +02:00
|
|
|
uint32_t *mb2br_xy;
|
|
|
|
|
2016-03-23 10:49:20 +02:00
|
|
|
int chroma_pred_mode;
|
|
|
|
int intra16x16_pred_mode;
|
|
|
|
|
|
|
|
int8_t intra4x4_pred_mode_cache[5 * 8];
|
|
|
|
int8_t (*intra4x4_pred_mode);
|
|
|
|
|
|
|
|
unsigned int top_samples_available;
|
|
|
|
unsigned int topright_samples_available;
|
|
|
|
unsigned int left_samples_available;
|
2016-03-23 10:54:43 +02:00
|
|
|
|
|
|
|
uint8_t *edge_emu_buffer;
|
2016-03-23 11:03:50 +02:00
|
|
|
|
|
|
|
DECLARE_ALIGNED(16, int16_t, mv_cache)[2][5 * 8][2];
|
|
|
|
DECLARE_ALIGNED(8, int8_t, ref_cache)[2][5 * 8];
|
2016-03-23 11:43:41 +02:00
|
|
|
DECLARE_ALIGNED(16, int16_t, mb)[16 * 48 * 2];
|
|
|
|
DECLARE_ALIGNED(16, int16_t, mb_luma_dc)[3][16 * 2];
|
|
|
|
DECLARE_ALIGNED(8, uint8_t, non_zero_count_cache)[15 * 8];
|
2016-03-23 11:26:54 +02:00
|
|
|
uint32_t dequant4_coeff[QP_MAX_NUM + 1][16];
|
2016-03-23 14:17:44 +02:00
|
|
|
int block_offset[2 * (16 * 3)];
|
2011-05-05 15:18:33 +03:00
|
|
|
} SVQ3Context;
|
|
|
|
|
2005-12-17 20:14:38 +02:00
|
|
|
#define FULLPEL_MODE 1
|
|
|
|
#define HALFPEL_MODE 2
|
2003-05-15 03:43:43 +03:00
|
|
|
#define THIRDPEL_MODE 3
|
2003-06-27 18:05:29 +03:00
|
|
|
#define PREDICT_MODE 4
|
2005-12-17 20:14:38 +02:00
|
|
|
|
2016-04-27 19:45:23 +02:00
|
|
|
/* dual scan (from some older H.264 draft)
|
2012-10-19 19:03:10 +03:00
|
|
|
* o-->o-->o o
|
|
|
|
* | /|
|
|
|
|
* o o o / o
|
|
|
|
* | / | |/ |
|
|
|
|
* o o o o
|
|
|
|
* /
|
|
|
|
* o-->o-->o-->o
|
|
|
|
*/
|
2008-11-22 18:36:50 +02:00
|
|
|
static const uint8_t svq3_scan[16] = {
|
2012-10-19 19:03:10 +03:00
|
|
|
0 + 0 * 4, 1 + 0 * 4, 2 + 0 * 4, 2 + 1 * 4,
|
|
|
|
2 + 2 * 4, 3 + 0 * 4, 3 + 1 * 4, 3 + 2 * 4,
|
|
|
|
0 + 1 * 4, 0 + 2 * 4, 1 + 1 * 4, 1 + 2 * 4,
|
|
|
|
0 + 3 * 4, 1 + 3 * 4, 2 + 3 * 4, 3 + 3 * 4,
|
2003-05-10 01:16:14 +03:00
|
|
|
};
|
|
|
|
|
2013-08-19 13:44:58 +03:00
|
|
|
static const uint8_t luma_dc_zigzag_scan[16] = {
|
|
|
|
0 * 16 + 0 * 64, 1 * 16 + 0 * 64, 2 * 16 + 0 * 64, 0 * 16 + 2 * 64,
|
|
|
|
3 * 16 + 0 * 64, 0 * 16 + 1 * 64, 1 * 16 + 1 * 64, 2 * 16 + 1 * 64,
|
|
|
|
1 * 16 + 2 * 64, 2 * 16 + 2 * 64, 3 * 16 + 2 * 64, 0 * 16 + 3 * 64,
|
|
|
|
3 * 16 + 1 * 64, 1 * 16 + 3 * 64, 2 * 16 + 3 * 64, 3 * 16 + 3 * 64,
|
|
|
|
};
|
|
|
|
|
2003-05-10 01:16:14 +03:00
|
|
|
static const uint8_t svq3_pred_0[25][2] = {
|
2008-11-22 18:36:50 +02:00
|
|
|
{ 0, 0 },
|
|
|
|
{ 1, 0 }, { 0, 1 },
|
|
|
|
{ 0, 2 }, { 1, 1 }, { 2, 0 },
|
|
|
|
{ 3, 0 }, { 2, 1 }, { 1, 2 }, { 0, 3 },
|
|
|
|
{ 0, 4 }, { 1, 3 }, { 2, 2 }, { 3, 1 }, { 4, 0 },
|
|
|
|
{ 4, 1 }, { 3, 2 }, { 2, 3 }, { 1, 4 },
|
|
|
|
{ 2, 4 }, { 3, 3 }, { 4, 2 },
|
|
|
|
{ 4, 3 }, { 3, 4 },
|
|
|
|
{ 4, 4 }
|
2003-05-10 01:16:14 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
static const int8_t svq3_pred_1[6][6][5] = {
|
2012-10-19 19:03:10 +03:00
|
|
|
{ { 2, -1, -1, -1, -1 }, { 2, 1, -1, -1, -1 }, { 1, 2, -1, -1, -1 },
|
|
|
|
{ 2, 1, -1, -1, -1 }, { 1, 2, -1, -1, -1 }, { 1, 2, -1, -1, -1 } },
|
|
|
|
{ { 0, 2, -1, -1, -1 }, { 0, 2, 1, 4, 3 }, { 0, 1, 2, 4, 3 },
|
|
|
|
{ 0, 2, 1, 4, 3 }, { 2, 0, 1, 3, 4 }, { 0, 4, 2, 1, 3 } },
|
|
|
|
{ { 2, 0, -1, -1, -1 }, { 2, 1, 0, 4, 3 }, { 1, 2, 4, 0, 3 },
|
|
|
|
{ 2, 1, 0, 4, 3 }, { 2, 1, 4, 3, 0 }, { 1, 2, 4, 0, 3 } },
|
|
|
|
{ { 2, 0, -1, -1, -1 }, { 2, 0, 1, 4, 3 }, { 1, 2, 0, 4, 3 },
|
|
|
|
{ 2, 1, 0, 4, 3 }, { 2, 1, 3, 4, 0 }, { 2, 4, 1, 0, 3 } },
|
|
|
|
{ { 0, 2, -1, -1, -1 }, { 0, 2, 1, 3, 4 }, { 1, 2, 3, 0, 4 },
|
|
|
|
{ 2, 0, 1, 3, 4 }, { 2, 1, 3, 0, 4 }, { 2, 0, 4, 3, 1 } },
|
|
|
|
{ { 0, 2, -1, -1, -1 }, { 0, 2, 4, 1, 3 }, { 1, 4, 2, 0, 3 },
|
|
|
|
{ 4, 2, 0, 1, 3 }, { 2, 0, 1, 4, 3 }, { 4, 2, 1, 0, 3 } },
|
2003-05-10 01:16:14 +03:00
|
|
|
};
|
|
|
|
|
2012-10-19 19:03:10 +03:00
|
|
|
static const struct {
|
|
|
|
uint8_t run;
|
|
|
|
uint8_t level;
|
|
|
|
} svq3_dct_tables[2][16] = {
|
2008-11-22 18:36:50 +02:00
|
|
|
{ { 0, 0 }, { 0, 1 }, { 1, 1 }, { 2, 1 }, { 0, 2 }, { 3, 1 }, { 4, 1 }, { 5, 1 },
|
|
|
|
{ 0, 3 }, { 1, 2 }, { 2, 2 }, { 6, 1 }, { 7, 1 }, { 8, 1 }, { 9, 1 }, { 0, 4 } },
|
|
|
|
{ { 0, 0 }, { 0, 1 }, { 1, 1 }, { 0, 2 }, { 2, 1 }, { 0, 3 }, { 0, 4 }, { 0, 5 },
|
|
|
|
{ 3, 1 }, { 4, 1 }, { 1, 2 }, { 1, 3 }, { 0, 6 }, { 0, 7 }, { 0, 8 }, { 0, 9 } }
|
2003-05-10 01:16:14 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
static const uint32_t svq3_dequant_coeff[32] = {
|
2012-10-19 19:03:10 +03:00
|
|
|
3881, 4351, 4890, 5481, 6154, 6914, 7761, 8718,
|
|
|
|
9781, 10987, 12339, 13828, 15523, 17435, 19561, 21873,
|
|
|
|
24552, 27656, 30847, 34870, 38807, 43747, 49103, 54683,
|
|
|
|
61694, 68745, 77615, 89113, 100253, 109366, 126635, 141533
|
2003-05-10 01:16:14 +03:00
|
|
|
};
|
|
|
|
|
2013-12-15 02:36:29 +03:00
|
|
|
static int svq3_decode_end(AVCodecContext *avctx);
|
|
|
|
|
2016-03-22 16:26:39 +02:00
|
|
|
static void svq3_luma_dc_dequant_idct_c(int16_t *output, int16_t *input, int qp)
|
2012-10-19 19:03:10 +03:00
|
|
|
{
|
2017-05-07 03:16:53 +02:00
|
|
|
const unsigned qmul = svq3_dequant_coeff[qp];
|
2003-05-10 01:16:14 +03:00
|
|
|
#define stride 16
|
|
|
|
int i;
|
|
|
|
int temp[16];
|
2012-10-19 19:03:10 +03:00
|
|
|
static const uint8_t x_offset[4] = { 0, 1 * stride, 4 * stride, 5 * stride };
|
|
|
|
|
|
|
|
for (i = 0; i < 4; i++) {
|
|
|
|
const int z0 = 13 * (input[4 * i + 0] + input[4 * i + 2]);
|
|
|
|
const int z1 = 13 * (input[4 * i + 0] - input[4 * i + 2]);
|
|
|
|
const int z2 = 7 * input[4 * i + 1] - 17 * input[4 * i + 3];
|
|
|
|
const int z3 = 17 * input[4 * i + 1] + 7 * input[4 * i + 3];
|
|
|
|
|
|
|
|
temp[4 * i + 0] = z0 + z3;
|
|
|
|
temp[4 * i + 1] = z1 + z2;
|
|
|
|
temp[4 * i + 2] = z1 - z2;
|
|
|
|
temp[4 * i + 3] = z0 - z3;
|
2003-05-10 01:16:14 +03:00
|
|
|
}
|
|
|
|
|
2012-10-19 19:03:10 +03:00
|
|
|
for (i = 0; i < 4; i++) {
|
|
|
|
const int offset = x_offset[i];
|
|
|
|
const int z0 = 13 * (temp[4 * 0 + i] + temp[4 * 2 + i]);
|
|
|
|
const int z1 = 13 * (temp[4 * 0 + i] - temp[4 * 2 + i]);
|
|
|
|
const int z2 = 7 * temp[4 * 1 + i] - 17 * temp[4 * 3 + i];
|
|
|
|
const int z3 = 17 * temp[4 * 1 + i] + 7 * temp[4 * 3 + i];
|
|
|
|
|
2017-05-07 03:16:53 +02:00
|
|
|
output[stride * 0 + offset] = (int)((z0 + z3) * qmul + 0x80000) >> 20;
|
|
|
|
output[stride * 2 + offset] = (int)((z1 + z2) * qmul + 0x80000) >> 20;
|
|
|
|
output[stride * 8 + offset] = (int)((z1 - z2) * qmul + 0x80000) >> 20;
|
|
|
|
output[stride * 10 + offset] = (int)((z0 - z3) * qmul + 0x80000) >> 20;
|
2003-05-10 01:16:14 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#undef stride
|
|
|
|
|
2016-03-22 16:26:39 +02:00
|
|
|
static void svq3_add_idct_c(uint8_t *dst, int16_t *block,
|
|
|
|
int stride, int qp, int dc)
|
2008-11-22 18:03:20 +02:00
|
|
|
{
|
2008-11-22 18:36:50 +02:00
|
|
|
const int qmul = svq3_dequant_coeff[qp];
|
2003-05-10 01:16:14 +03:00
|
|
|
int i;
|
|
|
|
|
|
|
|
if (dc) {
|
2017-05-13 23:16:44 +02:00
|
|
|
dc = 13 * 13 * (dc == 1 ? 1538U* block[0]
|
2012-10-19 19:26:54 +03:00
|
|
|
: qmul * (block[0] >> 3) / 2);
|
2003-05-10 01:16:14 +03:00
|
|
|
block[0] = 0;
|
|
|
|
}
|
|
|
|
|
2008-11-22 18:36:50 +02:00
|
|
|
for (i = 0; i < 4; i++) {
|
2012-10-19 19:03:10 +03:00
|
|
|
const int z0 = 13 * (block[0 + 4 * i] + block[2 + 4 * i]);
|
|
|
|
const int z1 = 13 * (block[0 + 4 * i] - block[2 + 4 * i]);
|
|
|
|
const int z2 = 7 * block[1 + 4 * i] - 17 * block[3 + 4 * i];
|
|
|
|
const int z3 = 17 * block[1 + 4 * i] + 7 * block[3 + 4 * i];
|
|
|
|
|
|
|
|
block[0 + 4 * i] = z0 + z3;
|
|
|
|
block[1 + 4 * i] = z1 + z2;
|
|
|
|
block[2 + 4 * i] = z1 - z2;
|
|
|
|
block[3 + 4 * i] = z0 - z3;
|
2003-05-10 01:16:14 +03:00
|
|
|
}
|
|
|
|
|
2008-11-22 18:36:50 +02:00
|
|
|
for (i = 0; i < 4; i++) {
|
2017-05-10 01:26:39 +02:00
|
|
|
const unsigned z0 = 13 * (block[i + 4 * 0] + block[i + 4 * 2]);
|
|
|
|
const unsigned z1 = 13 * (block[i + 4 * 0] - block[i + 4 * 2]);
|
|
|
|
const unsigned z2 = 7 * block[i + 4 * 1] - 17 * block[i + 4 * 3];
|
|
|
|
const unsigned z3 = 17 * block[i + 4 * 1] + 7 * block[i + 4 * 3];
|
2017-09-18 17:03:55 +02:00
|
|
|
const int rr = (dc + 0x80000u);
|
2008-11-22 18:36:50 +02:00
|
|
|
|
2017-05-10 01:26:39 +02:00
|
|
|
dst[i + stride * 0] = av_clip_uint8(dst[i + stride * 0] + ((int)((z0 + z3) * qmul + rr) >> 20));
|
|
|
|
dst[i + stride * 1] = av_clip_uint8(dst[i + stride * 1] + ((int)((z1 + z2) * qmul + rr) >> 20));
|
|
|
|
dst[i + stride * 2] = av_clip_uint8(dst[i + stride * 2] + ((int)((z1 - z2) * qmul + rr) >> 20));
|
|
|
|
dst[i + stride * 3] = av_clip_uint8(dst[i + stride * 3] + ((int)((z0 - z3) * qmul + rr) >> 20));
|
2003-05-10 01:16:14 +03:00
|
|
|
}
|
2013-02-19 08:03:02 +03:00
|
|
|
|
|
|
|
memset(block, 0, 16 * sizeof(int16_t));
|
2003-05-10 01:16:14 +03:00
|
|
|
}
|
|
|
|
|
2013-01-20 03:02:29 +03:00
|
|
|
static inline int svq3_decode_block(GetBitContext *gb, int16_t *block,
|
2008-11-22 18:03:20 +02:00
|
|
|
int index, const int type)
|
|
|
|
{
|
2016-03-24 12:16:53 +02:00
|
|
|
static const uint8_t *const scan_patterns[4] = {
|
2013-08-19 15:24:45 +03:00
|
|
|
luma_dc_zigzag_scan, ff_zigzag_scan, svq3_scan, ff_h264_chroma_dc_scan
|
2016-03-24 12:16:53 +02:00
|
|
|
};
|
2003-05-10 01:16:14 +03:00
|
|
|
|
2012-12-08 18:36:47 +03:00
|
|
|
int run, level, sign, limit;
|
2012-11-30 17:00:47 +03:00
|
|
|
unsigned vlc;
|
2012-10-19 19:26:54 +03:00
|
|
|
const int intra = 3 * type >> 2;
|
2008-11-22 18:36:50 +02:00
|
|
|
const uint8_t *const scan = scan_patterns[type];
|
2003-05-10 01:16:14 +03:00
|
|
|
|
2008-11-22 18:36:50 +02:00
|
|
|
for (limit = (16 >> intra); index < 16; index = limit, limit += 8) {
|
2016-05-24 01:20:34 +02:00
|
|
|
for (; (vlc = get_interleaved_ue_golomb(gb)) != 0; index++) {
|
2012-12-11 12:22:01 +03:00
|
|
|
if ((int32_t)vlc < 0)
|
2012-10-19 19:03:10 +03:00
|
|
|
return -1;
|
2003-05-10 01:16:14 +03:00
|
|
|
|
2012-12-08 18:36:47 +03:00
|
|
|
sign = (vlc & 1) ? 0 : -1;
|
2012-11-30 17:00:47 +03:00
|
|
|
vlc = vlc + 1 >> 1;
|
2012-10-19 19:03:10 +03:00
|
|
|
|
|
|
|
if (type == 3) {
|
|
|
|
if (vlc < 3) {
|
|
|
|
run = 0;
|
|
|
|
level = vlc;
|
|
|
|
} else if (vlc < 4) {
|
|
|
|
run = 1;
|
|
|
|
level = 1;
|
|
|
|
} else {
|
2012-10-19 19:26:54 +03:00
|
|
|
run = vlc & 0x3;
|
|
|
|
level = (vlc + 9 >> 2) - run;
|
2012-10-19 19:03:10 +03:00
|
|
|
}
|
|
|
|
} else {
|
2012-10-21 17:32:41 +03:00
|
|
|
if (vlc < 16U) {
|
2012-10-19 19:03:10 +03:00
|
|
|
run = svq3_dct_tables[intra][vlc].run;
|
|
|
|
level = svq3_dct_tables[intra][vlc].level;
|
|
|
|
} else if (intra) {
|
2012-10-19 19:26:54 +03:00
|
|
|
run = vlc & 0x7;
|
2012-10-21 17:32:41 +03:00
|
|
|
level = (vlc >> 3) + ((run == 0) ? 8 : ((run < 2) ? 2 : ((run < 5) ? 0 : -1)));
|
2012-10-19 19:03:10 +03:00
|
|
|
} else {
|
2012-10-19 19:26:54 +03:00
|
|
|
run = vlc & 0xF;
|
2012-10-21 17:32:41 +03:00
|
|
|
level = (vlc >> 4) + ((run == 0) ? 4 : ((run < 3) ? 2 : ((run < 10) ? 1 : 0)));
|
2012-10-19 19:03:10 +03:00
|
|
|
}
|
|
|
|
}
|
2003-05-10 01:16:14 +03:00
|
|
|
|
2012-10-21 17:32:41 +03:00
|
|
|
|
2012-10-19 19:03:10 +03:00
|
|
|
if ((index += run) >= limit)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
block[scan[index]] = (level ^ sign) - sign;
|
2008-11-22 18:36:50 +02:00
|
|
|
}
|
2003-05-10 01:16:14 +03:00
|
|
|
|
2008-11-22 18:36:50 +02:00
|
|
|
if (type != 2) {
|
|
|
|
break;
|
|
|
|
}
|
2003-05-10 01:16:14 +03:00
|
|
|
}
|
|
|
|
|
2008-11-22 18:36:50 +02:00
|
|
|
return 0;
|
2003-05-10 01:16:14 +03:00
|
|
|
}
|
|
|
|
|
2016-03-23 10:59:57 +02:00
|
|
|
static av_always_inline int
|
2016-03-23 11:03:50 +02:00
|
|
|
svq3_fetch_diagonal_mv(const SVQ3Context *s, const int16_t **C,
|
2016-03-23 10:59:57 +02:00
|
|
|
int i, int list, int part_width)
|
|
|
|
{
|
2016-03-23 11:03:50 +02:00
|
|
|
const int topright_ref = s->ref_cache[list][i - 8 + part_width];
|
2016-03-23 10:59:57 +02:00
|
|
|
|
|
|
|
if (topright_ref != PART_NOT_AVAILABLE) {
|
2016-03-23 11:03:50 +02:00
|
|
|
*C = s->mv_cache[list][i - 8 + part_width];
|
2016-03-23 10:59:57 +02:00
|
|
|
return topright_ref;
|
|
|
|
} else {
|
2016-03-23 11:03:50 +02:00
|
|
|
*C = s->mv_cache[list][i - 8 - 1];
|
|
|
|
return s->ref_cache[list][i - 8 - 1];
|
2016-03-23 10:59:57 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the predicted MV.
|
|
|
|
* @param n the block index
|
|
|
|
* @param part_width the width of the partition (4, 8,16) -> (1, 2, 4)
|
|
|
|
* @param mx the x component of the predicted motion vector
|
|
|
|
* @param my the y component of the predicted motion vector
|
|
|
|
*/
|
2016-03-23 11:03:50 +02:00
|
|
|
static av_always_inline void svq3_pred_motion(const SVQ3Context *s, int n,
|
2016-03-23 10:59:57 +02:00
|
|
|
int part_width, int list,
|
|
|
|
int ref, int *const mx, int *const my)
|
|
|
|
{
|
|
|
|
const int index8 = scan8[n];
|
2016-03-23 11:03:50 +02:00
|
|
|
const int top_ref = s->ref_cache[list][index8 - 8];
|
|
|
|
const int left_ref = s->ref_cache[list][index8 - 1];
|
|
|
|
const int16_t *const A = s->mv_cache[list][index8 - 1];
|
|
|
|
const int16_t *const B = s->mv_cache[list][index8 - 8];
|
2016-03-23 10:59:57 +02:00
|
|
|
const int16_t *C;
|
|
|
|
int diagonal_ref, match_count;
|
|
|
|
|
|
|
|
/* mv_cache
|
|
|
|
* B . . A T T T T
|
|
|
|
* U . . L . . , .
|
|
|
|
* U . . L . . . .
|
|
|
|
* U . . L . . , .
|
|
|
|
* . . . L . . . .
|
|
|
|
*/
|
|
|
|
|
2016-03-23 11:03:50 +02:00
|
|
|
diagonal_ref = svq3_fetch_diagonal_mv(s, &C, index8, list, part_width);
|
2016-03-23 10:59:57 +02:00
|
|
|
match_count = (diagonal_ref == ref) + (top_ref == ref) + (left_ref == ref);
|
|
|
|
if (match_count > 1) { //most common
|
|
|
|
*mx = mid_pred(A[0], B[0], C[0]);
|
|
|
|
*my = mid_pred(A[1], B[1], C[1]);
|
|
|
|
} else if (match_count == 1) {
|
|
|
|
if (left_ref == ref) {
|
|
|
|
*mx = A[0];
|
|
|
|
*my = A[1];
|
|
|
|
} else if (top_ref == ref) {
|
|
|
|
*mx = B[0];
|
|
|
|
*my = B[1];
|
|
|
|
} else {
|
|
|
|
*mx = C[0];
|
|
|
|
*my = C[1];
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (top_ref == PART_NOT_AVAILABLE &&
|
|
|
|
diagonal_ref == PART_NOT_AVAILABLE &&
|
|
|
|
left_ref != PART_NOT_AVAILABLE) {
|
|
|
|
*mx = A[0];
|
|
|
|
*my = A[1];
|
|
|
|
} else {
|
|
|
|
*mx = mid_pred(A[0], B[0], C[0]);
|
|
|
|
*my = mid_pred(A[1], B[1], C[1]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-03 13:10:05 +03:00
|
|
|
static inline void svq3_mc_dir_part(SVQ3Context *s,
|
2008-11-22 18:03:20 +02:00
|
|
|
int x, int y, int width, int height,
|
|
|
|
int mx, int my, int dxy,
|
|
|
|
int thirdpel, int dir, int avg)
|
|
|
|
{
|
2016-05-18 09:34:05 +02:00
|
|
|
const SVQ3Frame *pic = (dir == 0) ? s->last_pic : s->next_pic;
|
2008-11-22 18:36:50 +02:00
|
|
|
uint8_t *src, *dest;
|
|
|
|
int i, emu = 0;
|
2012-10-19 19:03:10 +03:00
|
|
|
int blocksize = 2 - (width >> 3); // 16->0, 8->1, 4->2
|
2016-03-23 11:43:41 +02:00
|
|
|
int linesize = s->cur_pic->f->linesize[0];
|
|
|
|
int uvlinesize = s->cur_pic->f->linesize[1];
|
2008-11-22 18:36:50 +02:00
|
|
|
|
|
|
|
mx += x;
|
|
|
|
my += y;
|
2003-05-10 01:16:14 +03:00
|
|
|
|
2012-10-19 19:26:54 +03:00
|
|
|
if (mx < 0 || mx >= s->h_edge_pos - width - 1 ||
|
|
|
|
my < 0 || my >= s->v_edge_pos - height - 1) {
|
2013-02-18 04:01:26 +03:00
|
|
|
emu = 1;
|
2012-10-19 19:26:54 +03:00
|
|
|
mx = av_clip(mx, -16, s->h_edge_pos - width + 15);
|
|
|
|
my = av_clip(my, -16, s->v_edge_pos - height + 15);
|
2003-05-10 01:16:14 +03:00
|
|
|
}
|
|
|
|
|
2008-11-22 18:36:50 +02:00
|
|
|
/* form component predictions */
|
2016-03-23 12:02:19 +02:00
|
|
|
dest = s->cur_pic->f->data[0] + x + y * linesize;
|
2016-03-23 11:43:41 +02:00
|
|
|
src = pic->f->data[0] + mx + my * linesize;
|
2008-11-22 18:36:50 +02:00
|
|
|
|
|
|
|
if (emu) {
|
2016-03-23 10:54:43 +02:00
|
|
|
s->vdsp.emulated_edge_mc(s->edge_emu_buffer, src,
|
2016-03-23 11:43:41 +02:00
|
|
|
linesize, linesize,
|
2012-12-15 20:46:02 +03:00
|
|
|
width + 1, height + 1,
|
|
|
|
mx, my, s->h_edge_pos, s->v_edge_pos);
|
2016-03-23 10:54:43 +02:00
|
|
|
src = s->edge_emu_buffer;
|
2003-05-10 01:16:14 +03:00
|
|
|
}
|
2008-11-22 18:36:50 +02:00
|
|
|
if (thirdpel)
|
2013-12-21 18:03:59 +03:00
|
|
|
(avg ? s->tdsp.avg_tpel_pixels_tab
|
2016-03-23 11:43:41 +02:00
|
|
|
: s->tdsp.put_tpel_pixels_tab)[dxy](dest, src, linesize,
|
2013-12-21 18:03:59 +03:00
|
|
|
width, height);
|
2008-11-22 18:36:50 +02:00
|
|
|
else
|
2013-03-11 00:12:58 +03:00
|
|
|
(avg ? s->hdsp.avg_pixels_tab
|
2016-03-23 11:43:41 +02:00
|
|
|
: s->hdsp.put_pixels_tab)[blocksize][dxy](dest, src, linesize,
|
2013-03-11 00:12:58 +03:00
|
|
|
height);
|
2008-11-22 18:36:50 +02:00
|
|
|
|
2016-03-23 14:23:55 +02:00
|
|
|
if (!(s->avctx->flags & AV_CODEC_FLAG_GRAY)) {
|
2012-10-19 19:26:54 +03:00
|
|
|
mx = mx + (mx < (int) x) >> 1;
|
|
|
|
my = my + (my < (int) y) >> 1;
|
|
|
|
width = width >> 1;
|
|
|
|
height = height >> 1;
|
2008-11-22 18:36:50 +02:00
|
|
|
blocksize++;
|
|
|
|
|
|
|
|
for (i = 1; i < 3; i++) {
|
2016-03-23 12:02:19 +02:00
|
|
|
dest = s->cur_pic->f->data[i] + (x >> 1) + (y >> 1) * uvlinesize;
|
2016-03-23 11:43:41 +02:00
|
|
|
src = pic->f->data[i] + mx + my * uvlinesize;
|
2008-11-22 18:36:50 +02:00
|
|
|
|
|
|
|
if (emu) {
|
2016-03-23 10:54:43 +02:00
|
|
|
s->vdsp.emulated_edge_mc(s->edge_emu_buffer, src,
|
2016-03-23 11:43:41 +02:00
|
|
|
uvlinesize, uvlinesize,
|
2012-12-15 20:46:02 +03:00
|
|
|
width + 1, height + 1,
|
|
|
|
mx, my, (s->h_edge_pos >> 1),
|
|
|
|
s->v_edge_pos >> 1);
|
2016-03-23 10:54:43 +02:00
|
|
|
src = s->edge_emu_buffer;
|
2008-11-22 18:36:50 +02:00
|
|
|
}
|
|
|
|
if (thirdpel)
|
2013-12-21 18:03:59 +03:00
|
|
|
(avg ? s->tdsp.avg_tpel_pixels_tab
|
|
|
|
: s->tdsp.put_tpel_pixels_tab)[dxy](dest, src,
|
2016-03-23 11:43:41 +02:00
|
|
|
uvlinesize,
|
2013-12-21 18:03:59 +03:00
|
|
|
width, height);
|
2008-11-22 18:36:50 +02:00
|
|
|
else
|
2013-03-11 00:12:58 +03:00
|
|
|
(avg ? s->hdsp.avg_pixels_tab
|
|
|
|
: s->hdsp.put_pixels_tab)[blocksize][dxy](dest, src,
|
2016-03-23 11:43:41 +02:00
|
|
|
uvlinesize,
|
2013-03-11 00:12:58 +03:00
|
|
|
height);
|
2008-11-22 18:36:50 +02:00
|
|
|
}
|
|
|
|
}
|
2003-05-10 01:16:14 +03:00
|
|
|
}
|
|
|
|
|
2013-02-03 13:10:05 +03:00
|
|
|
static inline int svq3_mc_dir(SVQ3Context *s, int size, int mode,
|
2012-10-19 19:03:10 +03:00
|
|
|
int dir, int avg)
|
2008-11-22 18:03:20 +02:00
|
|
|
{
|
2008-11-22 18:36:50 +02:00
|
|
|
int i, j, k, mx, my, dx, dy, x, y;
|
2012-10-19 19:03:10 +03:00
|
|
|
const int part_width = ((size & 5) == 4) ? 4 : 16 >> (size & 1);
|
|
|
|
const int part_height = 16 >> ((unsigned)(size + 1) / 3);
|
|
|
|
const int extra_width = (mode == PREDICT_MODE) ? -16 * 6 : 0;
|
|
|
|
const int h_edge_pos = 6 * (s->h_edge_pos - part_width) - extra_width;
|
|
|
|
const int v_edge_pos = 6 * (s->v_edge_pos - part_height) - extra_width;
|
|
|
|
|
|
|
|
for (i = 0; i < 16; i += part_height)
|
2008-11-22 18:36:50 +02:00
|
|
|
for (j = 0; j < 16; j += part_width) {
|
2016-03-22 16:54:20 +02:00
|
|
|
const int b_xy = (4 * s->mb_x + (j >> 2)) +
|
2016-03-23 11:33:48 +02:00
|
|
|
(4 * s->mb_y + (i >> 2)) * s->b_stride;
|
2008-11-22 18:36:50 +02:00
|
|
|
int dxy;
|
2016-03-22 16:54:20 +02:00
|
|
|
x = 16 * s->mb_x + j;
|
|
|
|
y = 16 * s->mb_y + i;
|
2012-10-19 19:26:54 +03:00
|
|
|
k = (j >> 2 & 1) + (i >> 1 & 2) +
|
|
|
|
(j >> 1 & 4) + (i & 8);
|
2008-11-22 18:36:50 +02:00
|
|
|
|
|
|
|
if (mode != PREDICT_MODE) {
|
2016-03-23 11:03:50 +02:00
|
|
|
svq3_pred_motion(s, k, part_width >> 2, dir, 1, &mx, &my);
|
2008-11-22 18:36:50 +02:00
|
|
|
} else {
|
2017-05-15 21:21:20 +02:00
|
|
|
mx = s->next_pic->motion_val[0][b_xy][0] * 2;
|
|
|
|
my = s->next_pic->motion_val[0][b_xy][1] * 2;
|
2008-11-22 18:36:50 +02:00
|
|
|
|
|
|
|
if (dir == 0) {
|
2016-03-23 12:04:59 +02:00
|
|
|
mx = mx * s->frame_num_offset /
|
|
|
|
s->prev_frame_num_offset + 1 >> 1;
|
|
|
|
my = my * s->frame_num_offset /
|
|
|
|
s->prev_frame_num_offset + 1 >> 1;
|
2008-11-22 18:36:50 +02:00
|
|
|
} else {
|
2016-03-23 12:04:59 +02:00
|
|
|
mx = mx * (s->frame_num_offset - s->prev_frame_num_offset) /
|
|
|
|
s->prev_frame_num_offset + 1 >> 1;
|
|
|
|
my = my * (s->frame_num_offset - s->prev_frame_num_offset) /
|
|
|
|
s->prev_frame_num_offset + 1 >> 1;
|
2008-11-22 18:36:50 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* clip motion vector prediction to frame border */
|
2012-10-19 19:03:10 +03:00
|
|
|
mx = av_clip(mx, extra_width - 6 * x, h_edge_pos - 6 * x);
|
|
|
|
my = av_clip(my, extra_width - 6 * y, v_edge_pos - 6 * y);
|
2008-11-22 18:36:50 +02:00
|
|
|
|
|
|
|
/* get (optional) motion vector differential */
|
|
|
|
if (mode == PREDICT_MODE) {
|
|
|
|
dx = dy = 0;
|
|
|
|
} else {
|
2016-05-24 01:20:34 +02:00
|
|
|
dy = get_interleaved_se_golomb(&s->gb_slice);
|
|
|
|
dx = get_interleaved_se_golomb(&s->gb_slice);
|
2008-11-22 18:36:50 +02:00
|
|
|
|
2017-04-27 15:10:26 +02:00
|
|
|
if (dx != (int16_t)dx || dy != (int16_t)dy) {
|
2016-03-23 14:23:55 +02:00
|
|
|
av_log(s->avctx, AV_LOG_ERROR, "invalid MV vlc\n");
|
2008-11-22 18:36:50 +02:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* compute motion vector */
|
|
|
|
if (mode == THIRDPEL_MODE) {
|
|
|
|
int fx, fy;
|
2012-10-19 19:26:54 +03:00
|
|
|
mx = (mx + 1 >> 1) + dx;
|
|
|
|
my = (my + 1 >> 1) + dy;
|
2017-04-27 15:10:25 +02:00
|
|
|
fx = (unsigned)(mx + 0x30000) / 3 - 0x10000;
|
|
|
|
fy = (unsigned)(my + 0x30000) / 3 - 0x10000;
|
2012-10-19 19:03:10 +03:00
|
|
|
dxy = (mx - 3 * fx) + 4 * (my - 3 * fy);
|
|
|
|
|
|
|
|
svq3_mc_dir_part(s, x, y, part_width, part_height,
|
|
|
|
fx, fy, dxy, 1, dir, avg);
|
2008-11-22 18:36:50 +02:00
|
|
|
mx += mx;
|
|
|
|
my += my;
|
|
|
|
} else if (mode == HALFPEL_MODE || mode == PREDICT_MODE) {
|
2017-04-27 15:10:25 +02:00
|
|
|
mx = (unsigned)(mx + 1 + 0x30000) / 3 + dx - 0x10000;
|
|
|
|
my = (unsigned)(my + 1 + 0x30000) / 3 + dy - 0x10000;
|
2012-10-19 19:03:10 +03:00
|
|
|
dxy = (mx & 1) + 2 * (my & 1);
|
2008-11-22 18:36:50 +02:00
|
|
|
|
2012-10-19 19:03:10 +03:00
|
|
|
svq3_mc_dir_part(s, x, y, part_width, part_height,
|
|
|
|
mx >> 1, my >> 1, dxy, 0, dir, avg);
|
2008-11-22 18:36:50 +02:00
|
|
|
mx *= 3;
|
|
|
|
my *= 3;
|
|
|
|
} else {
|
2017-04-27 15:10:25 +02:00
|
|
|
mx = (unsigned)(mx + 3 + 0x60000) / 6 + dx - 0x10000;
|
|
|
|
my = (unsigned)(my + 3 + 0x60000) / 6 + dy - 0x10000;
|
2008-11-22 18:36:50 +02:00
|
|
|
|
2012-10-19 19:03:10 +03:00
|
|
|
svq3_mc_dir_part(s, x, y, part_width, part_height,
|
|
|
|
mx, my, 0, 0, dir, avg);
|
2008-11-22 18:36:50 +02:00
|
|
|
mx *= 6;
|
|
|
|
my *= 6;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* update mv_cache */
|
|
|
|
if (mode != PREDICT_MODE) {
|
2012-10-19 19:03:10 +03:00
|
|
|
int32_t mv = pack16to32(mx, my);
|
2008-11-22 18:36:50 +02:00
|
|
|
|
|
|
|
if (part_height == 8 && i < 8) {
|
2016-03-23 11:03:50 +02:00
|
|
|
AV_WN32A(s->mv_cache[dir][scan8[k] + 1 * 8], mv);
|
2008-11-22 18:36:50 +02:00
|
|
|
|
2012-10-19 19:03:10 +03:00
|
|
|
if (part_width == 8 && j < 8)
|
2016-03-23 11:03:50 +02:00
|
|
|
AV_WN32A(s->mv_cache[dir][scan8[k] + 1 + 1 * 8], mv);
|
2008-11-22 18:36:50 +02:00
|
|
|
}
|
2012-10-19 19:03:10 +03:00
|
|
|
if (part_width == 8 && j < 8)
|
2016-03-23 11:03:50 +02:00
|
|
|
AV_WN32A(s->mv_cache[dir][scan8[k] + 1], mv);
|
2012-10-19 19:03:10 +03:00
|
|
|
if (part_width == 4 || part_height == 4)
|
2016-03-23 11:03:50 +02:00
|
|
|
AV_WN32A(s->mv_cache[dir][scan8[k]], mv);
|
2008-11-22 18:36:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* write back motion vectors */
|
2016-03-23 12:02:19 +02:00
|
|
|
fill_rectangle(s->cur_pic->motion_val[dir][b_xy],
|
2016-03-23 11:33:48 +02:00
|
|
|
part_width >> 2, part_height >> 2, s->b_stride,
|
2011-07-06 21:08:30 +03:00
|
|
|
pack16to32(mx, my), 4);
|
2005-12-22 03:10:11 +02:00
|
|
|
}
|
2003-06-27 18:05:29 +03:00
|
|
|
|
2008-11-22 18:36:50 +02:00
|
|
|
return 0;
|
2003-06-27 18:05:29 +03:00
|
|
|
}
|
|
|
|
|
2016-03-23 11:43:41 +02:00
|
|
|
static av_always_inline void hl_decode_mb_idct_luma(SVQ3Context *s,
|
2016-03-22 15:56:59 +02:00
|
|
|
int mb_type, const int *block_offset,
|
|
|
|
int linesize, uint8_t *dest_y)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
if (!IS_INTRA4x4(mb_type)) {
|
|
|
|
for (i = 0; i < 16; i++)
|
2016-03-23 11:43:41 +02:00
|
|
|
if (s->non_zero_count_cache[scan8[i]] || s->mb[i * 16]) {
|
2016-03-22 15:56:59 +02:00
|
|
|
uint8_t *const ptr = dest_y + block_offset[i];
|
2016-03-23 11:43:41 +02:00
|
|
|
svq3_add_idct_c(ptr, s->mb + i * 16, linesize,
|
|
|
|
s->qscale, IS_INTRA(mb_type) ? 1 : 0);
|
2016-03-22 15:56:59 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-22 16:32:57 +02:00
|
|
|
static av_always_inline void hl_decode_mb_predict_luma(SVQ3Context *s,
|
2016-03-22 15:56:59 +02:00
|
|
|
int mb_type,
|
|
|
|
const int *block_offset,
|
|
|
|
int linesize,
|
|
|
|
uint8_t *dest_y)
|
|
|
|
{
|
|
|
|
int i;
|
2016-03-23 11:43:41 +02:00
|
|
|
int qscale = s->qscale;
|
2016-03-22 15:56:59 +02:00
|
|
|
|
|
|
|
if (IS_INTRA4x4(mb_type)) {
|
|
|
|
for (i = 0; i < 16; i++) {
|
|
|
|
uint8_t *const ptr = dest_y + block_offset[i];
|
2016-03-23 10:49:20 +02:00
|
|
|
const int dir = s->intra4x4_pred_mode_cache[scan8[i]];
|
2016-03-22 15:56:59 +02:00
|
|
|
|
|
|
|
uint8_t *topright;
|
|
|
|
int nnz, tr;
|
|
|
|
if (dir == DIAG_DOWN_LEFT_PRED || dir == VERT_LEFT_PRED) {
|
2016-03-23 10:49:20 +02:00
|
|
|
const int topright_avail = (s->topright_samples_available << i) & 0x8000;
|
2016-04-27 17:07:35 +02:00
|
|
|
av_assert2(s->mb_y || linesize <= block_offset[i]);
|
2016-03-22 15:56:59 +02:00
|
|
|
if (!topright_avail) {
|
|
|
|
tr = ptr[3 - linesize] * 0x01010101u;
|
|
|
|
topright = (uint8_t *)&tr;
|
|
|
|
} else
|
|
|
|
topright = ptr + 4 - linesize;
|
|
|
|
} else
|
|
|
|
topright = NULL;
|
|
|
|
|
2016-03-22 16:32:57 +02:00
|
|
|
s->hpc.pred4x4[dir](ptr, topright, linesize);
|
2016-03-23 11:43:41 +02:00
|
|
|
nnz = s->non_zero_count_cache[scan8[i]];
|
2016-03-22 15:56:59 +02:00
|
|
|
if (nnz) {
|
2016-03-23 11:43:41 +02:00
|
|
|
svq3_add_idct_c(ptr, s->mb + i * 16, linesize, qscale, 0);
|
2016-03-22 15:56:59 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2016-03-23 10:49:20 +02:00
|
|
|
s->hpc.pred16x16[s->intra16x16_pred_mode](dest_y, linesize);
|
2016-03-23 11:43:41 +02:00
|
|
|
svq3_luma_dc_dequant_idct_c(s->mb, s->mb_luma_dc[0], qscale);
|
2016-03-22 15:56:59 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-23 14:23:55 +02:00
|
|
|
static void hl_decode_mb(SVQ3Context *s)
|
2016-03-22 15:56:59 +02:00
|
|
|
{
|
2016-03-22 16:54:20 +02:00
|
|
|
const int mb_x = s->mb_x;
|
|
|
|
const int mb_y = s->mb_y;
|
|
|
|
const int mb_xy = s->mb_xy;
|
2016-03-23 12:02:19 +02:00
|
|
|
const int mb_type = s->cur_pic->mb_type[mb_xy];
|
2016-03-22 15:56:59 +02:00
|
|
|
uint8_t *dest_y, *dest_cb, *dest_cr;
|
|
|
|
int linesize, uvlinesize;
|
|
|
|
int i, j;
|
2016-03-23 14:17:44 +02:00
|
|
|
const int *block_offset = &s->block_offset[0];
|
2016-03-23 14:23:55 +02:00
|
|
|
const int block_h = 16 >> 1;
|
2016-03-22 15:56:59 +02:00
|
|
|
|
2016-03-23 11:43:41 +02:00
|
|
|
linesize = s->cur_pic->f->linesize[0];
|
|
|
|
uvlinesize = s->cur_pic->f->linesize[1];
|
2016-03-22 15:56:59 +02:00
|
|
|
|
2016-03-23 12:02:19 +02:00
|
|
|
dest_y = s->cur_pic->f->data[0] + (mb_x + mb_y * linesize) * 16;
|
|
|
|
dest_cb = s->cur_pic->f->data[1] + mb_x * 8 + mb_y * uvlinesize * block_h;
|
|
|
|
dest_cr = s->cur_pic->f->data[2] + mb_x * 8 + mb_y * uvlinesize * block_h;
|
2016-03-22 15:56:59 +02:00
|
|
|
|
2016-03-23 11:43:41 +02:00
|
|
|
s->vdsp.prefetch(dest_y + (s->mb_x & 3) * 4 * linesize + 64, linesize, 4);
|
|
|
|
s->vdsp.prefetch(dest_cb + (s->mb_x & 7) * uvlinesize + 64, dest_cr - dest_cb, 2);
|
2016-03-22 15:56:59 +02:00
|
|
|
|
|
|
|
if (IS_INTRA(mb_type)) {
|
2016-03-23 10:49:20 +02:00
|
|
|
s->hpc.pred8x8[s->chroma_pred_mode](dest_cb, uvlinesize);
|
|
|
|
s->hpc.pred8x8[s->chroma_pred_mode](dest_cr, uvlinesize);
|
2016-03-22 15:56:59 +02:00
|
|
|
|
2016-03-23 14:23:55 +02:00
|
|
|
hl_decode_mb_predict_luma(s, mb_type, block_offset, linesize, dest_y);
|
2016-03-22 15:56:59 +02:00
|
|
|
}
|
|
|
|
|
2016-03-23 11:43:41 +02:00
|
|
|
hl_decode_mb_idct_luma(s, mb_type, block_offset, linesize, dest_y);
|
2016-03-22 15:56:59 +02:00
|
|
|
|
2016-03-23 11:43:41 +02:00
|
|
|
if (s->cbp & 0x30) {
|
2016-03-22 15:56:59 +02:00
|
|
|
uint8_t *dest[2] = { dest_cb, dest_cr };
|
2016-03-23 11:43:41 +02:00
|
|
|
s->h264dsp.h264_chroma_dc_dequant_idct(s->mb + 16 * 16 * 1,
|
|
|
|
s->dequant4_coeff[4][0]);
|
|
|
|
s->h264dsp.h264_chroma_dc_dequant_idct(s->mb + 16 * 16 * 2,
|
|
|
|
s->dequant4_coeff[4][0]);
|
2016-03-22 15:56:59 +02:00
|
|
|
for (j = 1; j < 3; j++) {
|
|
|
|
for (i = j * 16; i < j * 16 + 4; i++)
|
2016-03-23 11:43:41 +02:00
|
|
|
if (s->non_zero_count_cache[scan8[i]] || s->mb[i * 16]) {
|
2016-03-22 15:56:59 +02:00
|
|
|
uint8_t *const ptr = dest[j - 1] + block_offset[i];
|
2016-03-23 11:43:41 +02:00
|
|
|
svq3_add_idct_c(ptr, s->mb + i * 16,
|
|
|
|
uvlinesize, ff_h264_chroma_qp[0][s->qscale + 12] - 12, 2);
|
2016-03-22 15:56:59 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-03 13:10:05 +03:00
|
|
|
static int svq3_decode_mb(SVQ3Context *s, unsigned int mb_type)
|
2008-11-22 18:03:20 +02:00
|
|
|
{
|
2008-11-22 18:36:50 +02:00
|
|
|
int i, j, k, m, dir, mode;
|
|
|
|
int cbp = 0;
|
|
|
|
uint32_t vlc;
|
|
|
|
int8_t *top, *left;
|
2016-03-22 16:54:20 +02:00
|
|
|
const int mb_xy = s->mb_xy;
|
2016-03-23 11:33:48 +02:00
|
|
|
const int b_xy = 4 * s->mb_x + 4 * s->mb_y * s->b_stride;
|
2008-11-22 18:36:50 +02:00
|
|
|
|
2016-03-23 10:49:20 +02:00
|
|
|
s->top_samples_available = (s->mb_y == 0) ? 0x33FF : 0xFFFF;
|
|
|
|
s->left_samples_available = (s->mb_x == 0) ? 0x5F5F : 0xFFFF;
|
|
|
|
s->topright_samples_available = 0xFFFF;
|
2008-11-22 18:36:50 +02:00
|
|
|
|
|
|
|
if (mb_type == 0) { /* SKIP */
|
2016-03-23 11:33:48 +02:00
|
|
|
if (s->pict_type == AV_PICTURE_TYPE_P ||
|
2012-11-21 23:34:46 +03:00
|
|
|
s->next_pic->mb_type[mb_xy] == -1) {
|
2016-03-22 16:54:20 +02:00
|
|
|
svq3_mc_dir_part(s, 16 * s->mb_x, 16 * s->mb_y, 16, 16,
|
2012-10-19 19:03:10 +03:00
|
|
|
0, 0, 0, 0, 0, 0);
|
2008-11-22 18:36:50 +02:00
|
|
|
|
2016-03-23 11:33:48 +02:00
|
|
|
if (s->pict_type == AV_PICTURE_TYPE_B)
|
2016-03-22 16:54:20 +02:00
|
|
|
svq3_mc_dir_part(s, 16 * s->mb_x, 16 * s->mb_y, 16, 16,
|
2012-10-19 19:03:10 +03:00
|
|
|
0, 0, 0, 0, 1, 1);
|
2008-11-22 18:36:50 +02:00
|
|
|
|
|
|
|
mb_type = MB_TYPE_SKIP;
|
|
|
|
} else {
|
2012-11-21 23:34:46 +03:00
|
|
|
mb_type = FFMIN(s->next_pic->mb_type[mb_xy], 6);
|
2013-02-03 13:10:05 +03:00
|
|
|
if (svq3_mc_dir(s, mb_type, PREDICT_MODE, 0, 0) < 0)
|
2008-11-22 18:36:50 +02:00
|
|
|
return -1;
|
2013-02-03 13:10:05 +03:00
|
|
|
if (svq3_mc_dir(s, mb_type, PREDICT_MODE, 1, 1) < 0)
|
2008-11-22 18:36:50 +02:00
|
|
|
return -1;
|
2003-05-10 01:16:14 +03:00
|
|
|
|
2008-11-22 18:36:50 +02:00
|
|
|
mb_type = MB_TYPE_16x16;
|
2005-12-22 03:10:11 +02:00
|
|
|
}
|
2008-11-22 18:36:50 +02:00
|
|
|
} else if (mb_type < 8) { /* INTER */
|
2016-03-23 14:16:32 +02:00
|
|
|
if (s->thirdpel_flag && s->halfpel_flag == !get_bits1(&s->gb_slice))
|
2008-11-22 18:36:50 +02:00
|
|
|
mode = THIRDPEL_MODE;
|
2013-02-03 13:10:05 +03:00
|
|
|
else if (s->halfpel_flag &&
|
2016-03-23 14:16:32 +02:00
|
|
|
s->thirdpel_flag == !get_bits1(&s->gb_slice))
|
2008-11-22 18:36:50 +02:00
|
|
|
mode = HALFPEL_MODE;
|
2012-10-19 19:03:10 +03:00
|
|
|
else
|
2008-11-22 18:36:50 +02:00
|
|
|
mode = FULLPEL_MODE;
|
2003-05-10 01:16:14 +03:00
|
|
|
|
2008-11-22 18:36:50 +02:00
|
|
|
/* fill caches */
|
|
|
|
/* note ref_cache should contain here:
|
2012-10-19 19:03:10 +03:00
|
|
|
* ????????
|
|
|
|
* ???11111
|
|
|
|
* N??11111
|
|
|
|
* N??11111
|
|
|
|
* N??11111
|
|
|
|
*/
|
2008-11-22 18:36:50 +02:00
|
|
|
|
|
|
|
for (m = 0; m < 2; m++) {
|
2016-03-23 11:03:50 +02:00
|
|
|
if (s->mb_x > 0 && s->intra4x4_pred_mode[s->mb2br_xy[mb_xy - 1] + 6] != -1) {
|
2012-10-19 19:03:10 +03:00
|
|
|
for (i = 0; i < 4; i++)
|
2016-03-23 11:03:50 +02:00
|
|
|
AV_COPY32(s->mv_cache[m][scan8[0] - 1 + i * 8],
|
2016-03-23 12:02:19 +02:00
|
|
|
s->cur_pic->motion_val[m][b_xy - 1 + i * s->b_stride]);
|
2008-11-22 18:36:50 +02:00
|
|
|
} else {
|
2012-10-19 19:03:10 +03:00
|
|
|
for (i = 0; i < 4; i++)
|
2016-03-23 11:03:50 +02:00
|
|
|
AV_ZERO32(s->mv_cache[m][scan8[0] - 1 + i * 8]);
|
2008-11-22 18:36:50 +02:00
|
|
|
}
|
2016-03-22 16:54:20 +02:00
|
|
|
if (s->mb_y > 0) {
|
2016-03-23 11:03:50 +02:00
|
|
|
memcpy(s->mv_cache[m][scan8[0] - 1 * 8],
|
2016-03-23 12:02:19 +02:00
|
|
|
s->cur_pic->motion_val[m][b_xy - s->b_stride],
|
2012-10-19 19:03:10 +03:00
|
|
|
4 * 2 * sizeof(int16_t));
|
2016-03-23 11:03:50 +02:00
|
|
|
memset(&s->ref_cache[m][scan8[0] - 1 * 8],
|
2016-03-23 11:33:48 +02:00
|
|
|
(s->intra4x4_pred_mode[s->mb2br_xy[mb_xy - s->mb_stride]] == -1) ? PART_NOT_AVAILABLE : 1, 4);
|
2008-11-22 18:36:50 +02:00
|
|
|
|
2016-03-23 11:33:48 +02:00
|
|
|
if (s->mb_x < s->mb_width - 1) {
|
2016-03-23 11:03:50 +02:00
|
|
|
AV_COPY32(s->mv_cache[m][scan8[0] + 4 - 1 * 8],
|
2016-03-23 12:02:19 +02:00
|
|
|
s->cur_pic->motion_val[m][b_xy - s->b_stride + 4]);
|
2016-03-23 11:03:50 +02:00
|
|
|
s->ref_cache[m][scan8[0] + 4 - 1 * 8] =
|
2016-03-23 11:33:48 +02:00
|
|
|
(s->intra4x4_pred_mode[s->mb2br_xy[mb_xy - s->mb_stride + 1] + 6] == -1 ||
|
|
|
|
s->intra4x4_pred_mode[s->mb2br_xy[mb_xy - s->mb_stride]] == -1) ? PART_NOT_AVAILABLE : 1;
|
2012-10-19 19:03:10 +03:00
|
|
|
} else
|
2016-03-23 11:03:50 +02:00
|
|
|
s->ref_cache[m][scan8[0] + 4 - 1 * 8] = PART_NOT_AVAILABLE;
|
2016-03-22 16:54:20 +02:00
|
|
|
if (s->mb_x > 0) {
|
2016-03-23 11:03:50 +02:00
|
|
|
AV_COPY32(s->mv_cache[m][scan8[0] - 1 - 1 * 8],
|
2016-03-23 12:02:19 +02:00
|
|
|
s->cur_pic->motion_val[m][b_xy - s->b_stride - 1]);
|
2016-03-23 11:03:50 +02:00
|
|
|
s->ref_cache[m][scan8[0] - 1 - 1 * 8] =
|
2016-03-23 11:33:48 +02:00
|
|
|
(s->intra4x4_pred_mode[s->mb2br_xy[mb_xy - s->mb_stride - 1] + 3] == -1) ? PART_NOT_AVAILABLE : 1;
|
2012-10-19 19:03:10 +03:00
|
|
|
} else
|
2016-03-23 11:03:50 +02:00
|
|
|
s->ref_cache[m][scan8[0] - 1 - 1 * 8] = PART_NOT_AVAILABLE;
|
2012-10-19 19:03:10 +03:00
|
|
|
} else
|
2016-03-23 11:03:50 +02:00
|
|
|
memset(&s->ref_cache[m][scan8[0] - 1 * 8 - 1],
|
2012-10-19 19:03:10 +03:00
|
|
|
PART_NOT_AVAILABLE, 8);
|
2008-11-22 18:36:50 +02:00
|
|
|
|
2016-03-23 11:33:48 +02:00
|
|
|
if (s->pict_type != AV_PICTURE_TYPE_B)
|
2008-11-22 18:36:50 +02:00
|
|
|
break;
|
2005-12-22 03:10:11 +02:00
|
|
|
}
|
2003-05-10 01:16:14 +03:00
|
|
|
|
2008-11-22 18:36:50 +02:00
|
|
|
/* decode motion vector(s) and form prediction(s) */
|
2016-03-23 11:33:48 +02:00
|
|
|
if (s->pict_type == AV_PICTURE_TYPE_P) {
|
2013-02-03 13:10:05 +03:00
|
|
|
if (svq3_mc_dir(s, mb_type - 1, mode, 0, 0) < 0)
|
2008-11-22 18:36:50 +02:00
|
|
|
return -1;
|
2011-04-28 02:40:44 +03:00
|
|
|
} else { /* AV_PICTURE_TYPE_B */
|
2008-11-22 18:36:50 +02:00
|
|
|
if (mb_type != 2) {
|
2013-02-03 13:10:05 +03:00
|
|
|
if (svq3_mc_dir(s, 0, mode, 0, 0) < 0)
|
2008-11-22 18:36:50 +02:00
|
|
|
return -1;
|
|
|
|
} else {
|
2012-10-19 19:03:10 +03:00
|
|
|
for (i = 0; i < 4; i++)
|
2016-03-23 12:02:19 +02:00
|
|
|
memset(s->cur_pic->motion_val[0][b_xy + i * s->b_stride],
|
2012-10-19 19:03:10 +03:00
|
|
|
0, 4 * 2 * sizeof(int16_t));
|
2008-11-22 18:36:50 +02:00
|
|
|
}
|
|
|
|
if (mb_type != 1) {
|
2013-02-03 13:10:05 +03:00
|
|
|
if (svq3_mc_dir(s, 0, mode, 1, mb_type == 3) < 0)
|
2008-11-22 18:36:50 +02:00
|
|
|
return -1;
|
|
|
|
} else {
|
2012-10-19 19:03:10 +03:00
|
|
|
for (i = 0; i < 4; i++)
|
2016-03-23 12:02:19 +02:00
|
|
|
memset(s->cur_pic->motion_val[1][b_xy + i * s->b_stride],
|
2012-10-19 19:03:10 +03:00
|
|
|
0, 4 * 2 * sizeof(int16_t));
|
2008-11-22 18:36:50 +02:00
|
|
|
}
|
2005-12-22 03:10:11 +02:00
|
|
|
}
|
2003-05-10 01:16:14 +03:00
|
|
|
|
2008-11-22 18:36:50 +02:00
|
|
|
mb_type = MB_TYPE_16x16;
|
|
|
|
} else if (mb_type == 8 || mb_type == 33) { /* INTRA4x4 */
|
2016-03-23 11:03:50 +02:00
|
|
|
int8_t *i4x4 = s->intra4x4_pred_mode + s->mb2br_xy[s->mb_xy];
|
2016-03-23 10:49:20 +02:00
|
|
|
int8_t *i4x4_cache = s->intra4x4_pred_mode_cache;
|
2016-03-22 16:52:45 +02:00
|
|
|
|
2016-03-23 10:49:20 +02:00
|
|
|
memset(s->intra4x4_pred_mode_cache, -1, 8 * 5 * sizeof(int8_t));
|
2008-11-22 18:36:50 +02:00
|
|
|
|
|
|
|
if (mb_type == 8) {
|
2016-03-22 16:54:20 +02:00
|
|
|
if (s->mb_x > 0) {
|
2012-10-19 19:03:10 +03:00
|
|
|
for (i = 0; i < 4; i++)
|
2016-03-23 11:03:50 +02:00
|
|
|
s->intra4x4_pred_mode_cache[scan8[0] - 1 + i * 8] = s->intra4x4_pred_mode[s->mb2br_xy[mb_xy - 1] + 6 - i];
|
2016-03-23 10:49:20 +02:00
|
|
|
if (s->intra4x4_pred_mode_cache[scan8[0] - 1] == -1)
|
|
|
|
s->left_samples_available = 0x5F5F;
|
2008-11-22 18:36:50 +02:00
|
|
|
}
|
2016-03-22 16:54:20 +02:00
|
|
|
if (s->mb_y > 0) {
|
2016-03-23 11:33:48 +02:00
|
|
|
s->intra4x4_pred_mode_cache[4 + 8 * 0] = s->intra4x4_pred_mode[s->mb2br_xy[mb_xy - s->mb_stride] + 0];
|
|
|
|
s->intra4x4_pred_mode_cache[5 + 8 * 0] = s->intra4x4_pred_mode[s->mb2br_xy[mb_xy - s->mb_stride] + 1];
|
|
|
|
s->intra4x4_pred_mode_cache[6 + 8 * 0] = s->intra4x4_pred_mode[s->mb2br_xy[mb_xy - s->mb_stride] + 2];
|
|
|
|
s->intra4x4_pred_mode_cache[7 + 8 * 0] = s->intra4x4_pred_mode[s->mb2br_xy[mb_xy - s->mb_stride] + 3];
|
2008-11-22 18:36:50 +02:00
|
|
|
|
2016-03-23 10:49:20 +02:00
|
|
|
if (s->intra4x4_pred_mode_cache[4 + 8 * 0] == -1)
|
|
|
|
s->top_samples_available = 0x33FF;
|
2008-11-22 18:36:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* decode prediction codes for luma blocks */
|
2012-10-19 19:03:10 +03:00
|
|
|
for (i = 0; i < 16; i += 2) {
|
2016-05-24 01:20:34 +02:00
|
|
|
vlc = get_interleaved_ue_golomb(&s->gb_slice);
|
2008-11-22 18:36:50 +02:00
|
|
|
|
2012-10-21 17:32:41 +03:00
|
|
|
if (vlc >= 25U) {
|
2016-03-23 14:23:55 +02:00
|
|
|
av_log(s->avctx, AV_LOG_ERROR,
|
2014-03-13 14:13:33 +03:00
|
|
|
"luma prediction:%"PRIu32"\n", vlc);
|
2008-11-22 18:36:50 +02:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2016-03-23 10:49:20 +02:00
|
|
|
left = &s->intra4x4_pred_mode_cache[scan8[i] - 1];
|
|
|
|
top = &s->intra4x4_pred_mode_cache[scan8[i] - 8];
|
2008-11-22 18:36:50 +02:00
|
|
|
|
|
|
|
left[1] = svq3_pred_1[top[0] + 1][left[0] + 1][svq3_pred_0[vlc][0]];
|
|
|
|
left[2] = svq3_pred_1[top[1] + 1][left[1] + 1][svq3_pred_0[vlc][1]];
|
|
|
|
|
2012-10-19 19:03:10 +03:00
|
|
|
if (left[1] == -1 || left[2] == -1) {
|
2016-03-23 14:23:55 +02:00
|
|
|
av_log(s->avctx, AV_LOG_ERROR, "weird prediction\n");
|
2008-11-22 18:36:50 +02:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else { /* mb_type == 33, DC_128_PRED block type */
|
2012-10-19 19:03:10 +03:00
|
|
|
for (i = 0; i < 4; i++)
|
2016-03-23 10:49:20 +02:00
|
|
|
memset(&s->intra4x4_pred_mode_cache[scan8[0] + 8 * i], DC_PRED, 4);
|
2005-01-23 19:59:01 +02:00
|
|
|
}
|
2003-05-10 01:16:14 +03:00
|
|
|
|
2016-03-22 16:52:45 +02:00
|
|
|
AV_COPY32(i4x4, i4x4_cache + 4 + 8 * 4);
|
|
|
|
i4x4[4] = i4x4_cache[7 + 8 * 3];
|
|
|
|
i4x4[5] = i4x4_cache[7 + 8 * 2];
|
|
|
|
i4x4[6] = i4x4_cache[7 + 8 * 1];
|
2003-05-10 01:16:14 +03:00
|
|
|
|
2008-11-22 18:36:50 +02:00
|
|
|
if (mb_type == 8) {
|
2016-03-23 10:49:20 +02:00
|
|
|
ff_h264_check_intra4x4_pred_mode(s->intra4x4_pred_mode_cache,
|
2016-03-23 14:23:55 +02:00
|
|
|
s->avctx, s->top_samples_available,
|
2016-03-23 10:49:20 +02:00
|
|
|
s->left_samples_available);
|
2003-06-19 04:44:44 +03:00
|
|
|
|
2016-03-23 10:49:20 +02:00
|
|
|
s->top_samples_available = (s->mb_y == 0) ? 0x33FF : 0xFFFF;
|
|
|
|
s->left_samples_available = (s->mb_x == 0) ? 0x5F5F : 0xFFFF;
|
2008-11-22 18:36:50 +02:00
|
|
|
} else {
|
2012-10-19 19:03:10 +03:00
|
|
|
for (i = 0; i < 4; i++)
|
2016-03-23 10:49:20 +02:00
|
|
|
memset(&s->intra4x4_pred_mode_cache[scan8[0] + 8 * i], DC_128_PRED, 4);
|
2003-06-19 04:44:44 +03:00
|
|
|
|
2016-03-23 10:49:20 +02:00
|
|
|
s->top_samples_available = 0x33FF;
|
|
|
|
s->left_samples_available = 0x5F5F;
|
2008-11-22 18:36:50 +02:00
|
|
|
}
|
2003-06-19 04:44:44 +03:00
|
|
|
|
2008-11-22 18:36:50 +02:00
|
|
|
mb_type = MB_TYPE_INTRA4x4;
|
|
|
|
} else { /* INTRA16x16 */
|
2013-08-19 15:24:45 +03:00
|
|
|
dir = ff_h264_i_mb_type_info[mb_type - 8].pred_mode;
|
2012-10-19 19:03:10 +03:00
|
|
|
dir = (dir >> 1) ^ 3 * (dir & 1) ^ 1;
|
2003-05-10 01:16:14 +03:00
|
|
|
|
2016-03-23 14:23:55 +02:00
|
|
|
if ((s->intra16x16_pred_mode = ff_h264_check_intra_pred_mode(s->avctx, s->top_samples_available,
|
2016-03-23 10:49:20 +02:00
|
|
|
s->left_samples_available, dir, 0)) < 0) {
|
2016-03-23 14:23:55 +02:00
|
|
|
av_log(s->avctx, AV_LOG_ERROR, "ff_h264_check_intra_pred_mode < 0\n");
|
2016-03-23 10:49:20 +02:00
|
|
|
return s->intra16x16_pred_mode;
|
2008-11-22 18:36:50 +02:00
|
|
|
}
|
2003-05-10 01:16:14 +03:00
|
|
|
|
2013-08-19 15:24:45 +03:00
|
|
|
cbp = ff_h264_i_mb_type_info[mb_type - 8].cbp;
|
2008-11-22 18:36:50 +02:00
|
|
|
mb_type = MB_TYPE_INTRA16x16;
|
2005-01-23 19:59:01 +02:00
|
|
|
}
|
2003-05-10 01:16:14 +03:00
|
|
|
|
2016-03-23 11:33:48 +02:00
|
|
|
if (!IS_INTER(mb_type) && s->pict_type != AV_PICTURE_TYPE_I) {
|
2012-10-19 19:03:10 +03:00
|
|
|
for (i = 0; i < 4; i++)
|
2016-03-23 12:02:19 +02:00
|
|
|
memset(s->cur_pic->motion_val[0][b_xy + i * s->b_stride],
|
2012-10-19 19:03:10 +03:00
|
|
|
0, 4 * 2 * sizeof(int16_t));
|
2016-03-23 11:33:48 +02:00
|
|
|
if (s->pict_type == AV_PICTURE_TYPE_B) {
|
2012-10-19 19:03:10 +03:00
|
|
|
for (i = 0; i < 4; i++)
|
2016-03-23 12:02:19 +02:00
|
|
|
memset(s->cur_pic->motion_val[1][b_xy + i * s->b_stride],
|
2012-10-19 19:03:10 +03:00
|
|
|
0, 4 * 2 * sizeof(int16_t));
|
2008-11-22 18:36:50 +02:00
|
|
|
}
|
2003-05-10 01:16:14 +03:00
|
|
|
}
|
2008-11-22 18:36:50 +02:00
|
|
|
if (!IS_INTRA4x4(mb_type)) {
|
2016-03-23 11:03:50 +02:00
|
|
|
memset(s->intra4x4_pred_mode + s->mb2br_xy[mb_xy], DC_PRED, 8);
|
2003-06-19 04:44:44 +03:00
|
|
|
}
|
2016-03-23 11:33:48 +02:00
|
|
|
if (!IS_SKIP(mb_type) || s->pict_type == AV_PICTURE_TYPE_B) {
|
2016-03-23 11:43:41 +02:00
|
|
|
memset(s->non_zero_count_cache + 8, 0, 14 * 8 * sizeof(uint8_t));
|
2005-01-23 19:59:01 +02:00
|
|
|
}
|
2003-06-27 18:05:29 +03:00
|
|
|
|
2012-10-19 19:03:10 +03:00
|
|
|
if (!IS_INTRA16x16(mb_type) &&
|
2016-03-23 11:33:48 +02:00
|
|
|
(!IS_SKIP(mb_type) || s->pict_type == AV_PICTURE_TYPE_B)) {
|
2016-06-26 15:12:48 +02:00
|
|
|
if ((vlc = get_interleaved_ue_golomb(&s->gb_slice)) >= 48U){
|
2016-03-23 14:23:55 +02:00
|
|
|
av_log(s->avctx, AV_LOG_ERROR, "cbp_vlc=%"PRIu32"\n", vlc);
|
2008-11-22 18:36:50 +02:00
|
|
|
return -1;
|
|
|
|
}
|
2003-05-10 01:16:14 +03:00
|
|
|
|
2013-08-19 15:24:45 +03:00
|
|
|
cbp = IS_INTRA(mb_type) ? ff_h264_golomb_to_intra4x4_cbp[vlc]
|
|
|
|
: ff_h264_golomb_to_inter_cbp[vlc];
|
2005-01-23 19:59:01 +02:00
|
|
|
}
|
2012-10-19 19:03:10 +03:00
|
|
|
if (IS_INTRA16x16(mb_type) ||
|
2016-03-23 11:33:48 +02:00
|
|
|
(s->pict_type != AV_PICTURE_TYPE_I && s->adaptive_quant && cbp)) {
|
2016-05-24 01:20:34 +02:00
|
|
|
s->qscale += get_interleaved_se_golomb(&s->gb_slice);
|
2003-05-10 01:16:14 +03:00
|
|
|
|
2016-03-23 11:43:41 +02:00
|
|
|
if (s->qscale > 31u) {
|
2016-03-23 14:23:55 +02:00
|
|
|
av_log(s->avctx, AV_LOG_ERROR, "qscale:%d\n", s->qscale);
|
2005-12-22 03:10:11 +02:00
|
|
|
return -1;
|
|
|
|
}
|
2003-05-10 01:16:14 +03:00
|
|
|
}
|
2008-11-22 18:36:50 +02:00
|
|
|
if (IS_INTRA16x16(mb_type)) {
|
2016-03-23 11:43:41 +02:00
|
|
|
AV_ZERO128(s->mb_luma_dc[0] + 0);
|
|
|
|
AV_ZERO128(s->mb_luma_dc[0] + 8);
|
2016-03-23 14:16:32 +02:00
|
|
|
if (svq3_decode_block(&s->gb_slice, s->mb_luma_dc[0], 0, 1)) {
|
2016-03-23 14:23:55 +02:00
|
|
|
av_log(s->avctx, AV_LOG_ERROR,
|
2012-10-19 19:03:10 +03:00
|
|
|
"error while decoding intra luma dc\n");
|
2008-11-22 18:36:50 +02:00
|
|
|
return -1;
|
2005-01-23 19:59:01 +02:00
|
|
|
}
|
2008-11-22 18:36:50 +02:00
|
|
|
}
|
2003-05-10 01:16:14 +03:00
|
|
|
|
2008-11-22 18:36:50 +02:00
|
|
|
if (cbp) {
|
|
|
|
const int index = IS_INTRA16x16(mb_type) ? 1 : 0;
|
2016-03-23 11:43:41 +02:00
|
|
|
const int type = ((s->qscale < 24 && IS_INTRA4x4(mb_type)) ? 2 : 1);
|
2008-11-22 18:36:50 +02:00
|
|
|
|
2012-10-19 19:03:10 +03:00
|
|
|
for (i = 0; i < 4; i++)
|
2008-11-22 18:36:50 +02:00
|
|
|
if ((cbp & (1 << i))) {
|
|
|
|
for (j = 0; j < 4; j++) {
|
2012-10-19 19:03:10 +03:00
|
|
|
k = index ? (1 * (j & 1) + 2 * (i & 1) +
|
|
|
|
2 * (j & 2) + 4 * (i & 2))
|
|
|
|
: (4 * i + j);
|
2016-03-23 11:43:41 +02:00
|
|
|
s->non_zero_count_cache[scan8[k]] = 1;
|
2012-10-19 19:03:10 +03:00
|
|
|
|
2016-03-23 14:16:32 +02:00
|
|
|
if (svq3_decode_block(&s->gb_slice, &s->mb[16 * k], index, type)) {
|
2016-03-23 14:23:55 +02:00
|
|
|
av_log(s->avctx, AV_LOG_ERROR,
|
2012-10-19 19:03:10 +03:00
|
|
|
"error while decoding block\n");
|
2008-11-22 18:36:50 +02:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2003-05-10 01:16:14 +03:00
|
|
|
|
2008-11-22 18:36:50 +02:00
|
|
|
if ((cbp & 0x30)) {
|
2012-10-19 19:03:10 +03:00
|
|
|
for (i = 1; i < 3; ++i)
|
2016-03-23 14:16:32 +02:00
|
|
|
if (svq3_decode_block(&s->gb_slice, &s->mb[16 * 16 * i], 0, 3)) {
|
2016-03-23 14:23:55 +02:00
|
|
|
av_log(s->avctx, AV_LOG_ERROR,
|
2012-10-19 19:03:10 +03:00
|
|
|
"error while decoding chroma dc block\n");
|
|
|
|
return -1;
|
|
|
|
}
|
2008-11-22 18:36:50 +02:00
|
|
|
|
|
|
|
if ((cbp & 0x20)) {
|
2011-06-13 20:21:46 +03:00
|
|
|
for (i = 1; i < 3; i++) {
|
|
|
|
for (j = 0; j < 4; j++) {
|
2012-10-19 19:03:10 +03:00
|
|
|
k = 16 * i + j;
|
2016-03-23 11:43:41 +02:00
|
|
|
s->non_zero_count_cache[scan8[k]] = 1;
|
2011-06-13 20:21:46 +03:00
|
|
|
|
2016-03-23 14:16:32 +02:00
|
|
|
if (svq3_decode_block(&s->gb_slice, &s->mb[16 * k], 1, 1)) {
|
2016-03-23 14:23:55 +02:00
|
|
|
av_log(s->avctx, AV_LOG_ERROR,
|
2012-10-19 19:03:10 +03:00
|
|
|
"error while decoding chroma ac block\n");
|
2011-06-13 20:21:46 +03:00
|
|
|
return -1;
|
|
|
|
}
|
2008-11-22 18:36:50 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2005-12-22 03:10:11 +02:00
|
|
|
}
|
2003-05-10 01:16:14 +03:00
|
|
|
}
|
|
|
|
|
2016-03-23 12:02:19 +02:00
|
|
|
s->cbp = cbp;
|
|
|
|
s->cur_pic->mb_type[mb_xy] = mb_type;
|
2003-05-10 01:16:14 +03:00
|
|
|
|
2012-10-19 19:03:10 +03:00
|
|
|
if (IS_INTRA(mb_type))
|
2016-03-23 14:23:55 +02:00
|
|
|
s->chroma_pred_mode = ff_h264_check_intra_pred_mode(s->avctx, s->top_samples_available,
|
2016-03-23 10:49:20 +02:00
|
|
|
s->left_samples_available, DC_PRED8x8, 1);
|
2003-05-10 01:16:14 +03:00
|
|
|
|
2008-11-22 18:36:50 +02:00
|
|
|
return 0;
|
2003-05-10 01:16:14 +03:00
|
|
|
}
|
|
|
|
|
2011-05-05 15:18:33 +03:00
|
|
|
static int svq3_decode_slice_header(AVCodecContext *avctx)
|
2008-11-22 18:03:20 +02:00
|
|
|
{
|
2013-02-03 13:10:05 +03:00
|
|
|
SVQ3Context *s = avctx->priv_data;
|
2016-03-22 16:54:20 +02:00
|
|
|
const int mb_xy = s->mb_xy;
|
2008-11-22 18:36:50 +02:00
|
|
|
int i, header;
|
2012-12-08 15:36:28 +03:00
|
|
|
unsigned slice_id;
|
2003-06-19 04:44:44 +03:00
|
|
|
|
2016-03-12 18:46:36 +02:00
|
|
|
header = get_bits(&s->gb, 8);
|
2003-06-19 04:44:44 +03:00
|
|
|
|
2008-11-22 18:36:50 +02:00
|
|
|
if (((header & 0x9F) != 1 && (header & 0x9F) != 2) || (header & 0x60) == 0) {
|
|
|
|
/* TODO: what? */
|
2011-05-05 15:18:33 +03:00
|
|
|
av_log(avctx, AV_LOG_ERROR, "unsupported slice header (%02X)\n", header);
|
2008-11-22 18:36:50 +02:00
|
|
|
return -1;
|
|
|
|
} else {
|
2016-03-12 18:46:36 +02:00
|
|
|
int slice_bits, slice_bytes, slice_length;
|
2012-10-19 19:26:54 +03:00
|
|
|
int length = header >> 5 & 3;
|
2003-06-19 04:44:44 +03:00
|
|
|
|
2016-03-12 18:46:36 +02:00
|
|
|
slice_length = show_bits(&s->gb, 8 * length);
|
|
|
|
slice_bits = slice_length * 8;
|
|
|
|
slice_bytes = slice_length + length - 1;
|
2003-06-19 04:44:44 +03:00
|
|
|
|
2016-03-12 18:46:36 +02:00
|
|
|
skip_bits(&s->gb, 8);
|
|
|
|
|
|
|
|
av_fast_malloc(&s->slice_buf, &s->slice_size, slice_bytes + AV_INPUT_BUFFER_PADDING_SIZE);
|
|
|
|
if (!s->slice_buf)
|
|
|
|
return AVERROR(ENOMEM);
|
|
|
|
|
2017-10-04 01:28:51 +02:00
|
|
|
if (slice_bytes * 8LL > get_bits_left(&s->gb)) {
|
2017-02-01 12:50:38 +02:00
|
|
|
av_log(avctx, AV_LOG_ERROR, "slice after bitstream end\n");
|
|
|
|
return AVERROR_INVALIDDATA;
|
|
|
|
}
|
2016-03-12 18:46:36 +02:00
|
|
|
memcpy(s->slice_buf, s->gb.buffer + s->gb.index / 8, slice_bytes);
|
|
|
|
|
2013-02-03 13:10:05 +03:00
|
|
|
if (s->watermark_key) {
|
2018-01-19 00:31:48 +02:00
|
|
|
uint32_t header = AV_RL32(&s->slice_buf[1]);
|
|
|
|
AV_WL32(&s->slice_buf[1], header ^ s->watermark_key);
|
2008-11-22 18:36:50 +02:00
|
|
|
}
|
2018-01-19 00:31:48 +02:00
|
|
|
init_get_bits(&s->gb_slice, s->slice_buf, slice_bits);
|
|
|
|
|
2008-11-22 18:36:50 +02:00
|
|
|
if (length > 0) {
|
2016-04-14 14:25:17 +02:00
|
|
|
memmove(s->slice_buf, &s->slice_buf[slice_length], length - 1);
|
2008-11-22 18:36:50 +02:00
|
|
|
}
|
2016-03-12 18:46:36 +02:00
|
|
|
skip_bits_long(&s->gb, slice_bytes * 8);
|
2003-06-19 04:44:44 +03:00
|
|
|
}
|
|
|
|
|
2016-05-24 01:20:34 +02:00
|
|
|
if ((slice_id = get_interleaved_ue_golomb(&s->gb_slice)) >= 3) {
|
2016-03-23 14:23:55 +02:00
|
|
|
av_log(s->avctx, AV_LOG_ERROR, "illegal slice type %u \n", slice_id);
|
2008-11-22 18:36:50 +02:00
|
|
|
return -1;
|
|
|
|
}
|
2003-06-19 04:44:44 +03:00
|
|
|
|
2016-09-08 21:15:55 +02:00
|
|
|
s->slice_type = ff_h264_golomb_to_pict_type[slice_id];
|
2003-06-19 04:44:44 +03:00
|
|
|
|
2008-11-22 18:36:50 +02:00
|
|
|
if ((header & 0x9F) == 2) {
|
2018-07-31 02:22:02 +02:00
|
|
|
i = (s->mb_num < 64) ? 6 : (1 + av_log2(s->mb_num - 1));
|
2016-03-23 14:16:32 +02:00
|
|
|
get_bits(&s->gb_slice, i);
|
2018-07-31 02:22:02 +02:00
|
|
|
} else if (get_bits1(&s->gb_slice)) {
|
|
|
|
avpriv_report_missing_feature(s->avctx, "Media key encryption");
|
|
|
|
return AVERROR_PATCHWELCOME;
|
2008-11-22 18:36:50 +02:00
|
|
|
}
|
2003-06-19 04:44:44 +03:00
|
|
|
|
2016-03-23 14:16:32 +02:00
|
|
|
s->slice_num = get_bits(&s->gb_slice, 8);
|
|
|
|
s->qscale = get_bits(&s->gb_slice, 5);
|
|
|
|
s->adaptive_quant = get_bits1(&s->gb_slice);
|
2003-06-19 04:44:44 +03:00
|
|
|
|
2008-11-22 18:36:50 +02:00
|
|
|
/* unknown fields */
|
2016-03-23 14:16:32 +02:00
|
|
|
skip_bits1(&s->gb_slice);
|
2003-06-19 04:44:44 +03:00
|
|
|
|
2015-05-02 03:02:30 +02:00
|
|
|
if (s->has_watermark)
|
2016-03-23 14:16:32 +02:00
|
|
|
skip_bits1(&s->gb_slice);
|
2003-06-19 04:44:44 +03:00
|
|
|
|
2016-03-23 14:16:32 +02:00
|
|
|
skip_bits1(&s->gb_slice);
|
|
|
|
skip_bits(&s->gb_slice, 2);
|
2003-06-19 04:44:44 +03:00
|
|
|
|
2016-05-03 11:26:13 +02:00
|
|
|
if (skip_1stop_8data_bits(&s->gb_slice) < 0)
|
2013-10-30 20:28:00 +03:00
|
|
|
return AVERROR_INVALIDDATA;
|
2003-06-19 04:44:44 +03:00
|
|
|
|
2008-11-22 18:36:50 +02:00
|
|
|
/* reset intra predictors and invalidate motion vector references */
|
2016-03-22 16:54:20 +02:00
|
|
|
if (s->mb_x > 0) {
|
2016-03-23 11:03:50 +02:00
|
|
|
memset(s->intra4x4_pred_mode + s->mb2br_xy[mb_xy - 1] + 3,
|
2012-10-19 19:03:10 +03:00
|
|
|
-1, 4 * sizeof(int8_t));
|
2016-03-23 11:03:50 +02:00
|
|
|
memset(s->intra4x4_pred_mode + s->mb2br_xy[mb_xy - s->mb_x],
|
2016-03-22 16:54:20 +02:00
|
|
|
-1, 8 * sizeof(int8_t) * s->mb_x);
|
2008-11-22 18:36:50 +02:00
|
|
|
}
|
2016-03-22 16:54:20 +02:00
|
|
|
if (s->mb_y > 0) {
|
2016-03-23 11:33:48 +02:00
|
|
|
memset(s->intra4x4_pred_mode + s->mb2br_xy[mb_xy - s->mb_stride],
|
|
|
|
-1, 8 * sizeof(int8_t) * (s->mb_width - s->mb_x));
|
2008-11-22 18:36:50 +02:00
|
|
|
|
2016-03-22 16:54:20 +02:00
|
|
|
if (s->mb_x > 0)
|
2016-03-23 11:33:48 +02:00
|
|
|
s->intra4x4_pred_mode[s->mb2br_xy[mb_xy - s->mb_stride - 1] + 3] = -1;
|
2003-06-19 04:44:44 +03:00
|
|
|
}
|
|
|
|
|
2008-11-22 18:36:50 +02:00
|
|
|
return 0;
|
2003-06-19 04:44:44 +03:00
|
|
|
}
|
|
|
|
|
2016-03-23 11:26:54 +02:00
|
|
|
static void init_dequant4_coeff_table(SVQ3Context *s)
|
|
|
|
{
|
|
|
|
int q, x;
|
|
|
|
const int max_qp = 51;
|
|
|
|
|
|
|
|
for (q = 0; q < max_qp + 1; q++) {
|
|
|
|
int shift = ff_h264_quant_div6[q] + 2;
|
|
|
|
int idx = ff_h264_quant_rem6[q];
|
|
|
|
for (x = 0; x < 16; x++)
|
|
|
|
s->dequant4_coeff[q][(x >> 2) | ((x << 2) & 0xF)] =
|
|
|
|
((uint32_t)ff_h264_dequant4_coeff_init[idx][(x & 1) + ((x >> 2) & 1)] * 16) << shift;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-02-22 15:48:55 +02:00
|
|
|
static av_cold int svq3_decode_init(AVCodecContext *avctx)
|
2008-11-22 18:03:20 +02:00
|
|
|
{
|
2013-02-03 13:10:05 +03:00
|
|
|
SVQ3Context *s = avctx->priv_data;
|
2016-03-23 11:03:50 +02:00
|
|
|
int m, x, y;
|
2008-11-22 18:36:50 +02:00
|
|
|
unsigned char *extradata;
|
2012-02-10 07:21:47 +03:00
|
|
|
unsigned char *extradata_end;
|
2008-11-22 18:36:50 +02:00
|
|
|
unsigned int size;
|
2012-02-10 07:21:47 +03:00
|
|
|
int marker_found = 0;
|
2013-12-15 02:36:29 +03:00
|
|
|
int ret;
|
2008-11-22 18:36:50 +02:00
|
|
|
|
2013-02-03 13:10:05 +03:00
|
|
|
s->cur_pic = av_mallocz(sizeof(*s->cur_pic));
|
|
|
|
s->last_pic = av_mallocz(sizeof(*s->last_pic));
|
|
|
|
s->next_pic = av_mallocz(sizeof(*s->next_pic));
|
|
|
|
if (!s->next_pic || !s->last_pic || !s->cur_pic) {
|
2013-12-15 02:36:29 +03:00
|
|
|
ret = AVERROR(ENOMEM);
|
|
|
|
goto fail;
|
2013-02-03 13:10:05 +03:00
|
|
|
}
|
|
|
|
|
2015-04-17 12:09:50 +02:00
|
|
|
s->cur_pic->f = av_frame_alloc();
|
|
|
|
s->last_pic->f = av_frame_alloc();
|
|
|
|
s->next_pic->f = av_frame_alloc();
|
|
|
|
if (!s->cur_pic->f || !s->last_pic->f || !s->next_pic->f)
|
|
|
|
return AVERROR(ENOMEM);
|
|
|
|
|
2016-03-22 16:32:57 +02:00
|
|
|
ff_h264dsp_init(&s->h264dsp, 8, 1);
|
|
|
|
ff_h264_pred_init(&s->hpc, AV_CODEC_ID_SVQ3, 8, 1);
|
|
|
|
ff_videodsp_init(&s->vdsp, 8);
|
2015-04-05 21:02:56 +02:00
|
|
|
|
2015-04-05 21:36:07 +02:00
|
|
|
|
2015-04-06 01:37:34 +02:00
|
|
|
avctx->bits_per_raw_sample = 8;
|
2015-04-05 21:02:56 +02:00
|
|
|
|
2013-03-11 00:12:58 +03:00
|
|
|
ff_hpeldsp_init(&s->hdsp, avctx->flags);
|
2013-12-21 18:03:59 +03:00
|
|
|
ff_tpeldsp_init(&s->tdsp);
|
|
|
|
|
2014-03-17 20:53:14 +03:00
|
|
|
avctx->pix_fmt = AV_PIX_FMT_YUVJ420P;
|
|
|
|
avctx->color_range = AVCOL_RANGE_JPEG;
|
2008-11-22 18:36:50 +02:00
|
|
|
|
2016-03-23 14:23:55 +02:00
|
|
|
s->avctx = avctx;
|
2013-02-03 13:10:05 +03:00
|
|
|
s->halfpel_flag = 1;
|
|
|
|
s->thirdpel_flag = 1;
|
2015-05-02 03:02:30 +02:00
|
|
|
s->has_watermark = 0;
|
2013-02-04 13:21:10 +03:00
|
|
|
|
|
|
|
/* prowl for the "SEQH" marker in the extradata */
|
|
|
|
extradata = (unsigned char *)avctx->extradata;
|
|
|
|
extradata_end = avctx->extradata + avctx->extradata_size;
|
|
|
|
if (extradata) {
|
|
|
|
for (m = 0; m + 8 < avctx->extradata_size; m++) {
|
|
|
|
if (!memcmp(extradata, "SEQH", 4)) {
|
|
|
|
marker_found = 1;
|
|
|
|
break;
|
2012-02-10 07:21:47 +03:00
|
|
|
}
|
2013-02-04 13:21:10 +03:00
|
|
|
extradata++;
|
2008-11-22 18:36:50 +02:00
|
|
|
}
|
2013-02-04 13:21:10 +03:00
|
|
|
}
|
2003-05-10 01:16:14 +03:00
|
|
|
|
2013-02-04 13:21:10 +03:00
|
|
|
/* if a match was found, parse the extra data */
|
|
|
|
if (marker_found) {
|
|
|
|
GetBitContext gb;
|
|
|
|
int frame_size_code;
|
2015-05-02 02:58:00 +02:00
|
|
|
int unk0, unk1, unk2, unk3, unk4;
|
2019-06-25 23:42:43 +02:00
|
|
|
int w,h;
|
2013-02-04 13:21:10 +03:00
|
|
|
|
|
|
|
size = AV_RB32(&extradata[4]);
|
2013-12-15 02:36:29 +03:00
|
|
|
if (size > extradata_end - extradata - 8) {
|
|
|
|
ret = AVERROR_INVALIDDATA;
|
|
|
|
goto fail;
|
|
|
|
}
|
2013-02-04 13:21:10 +03:00
|
|
|
init_get_bits(&gb, extradata + 8, size * 8);
|
|
|
|
|
|
|
|
/* 'frame size code' and optional 'width, height' */
|
|
|
|
frame_size_code = get_bits(&gb, 3);
|
|
|
|
switch (frame_size_code) {
|
|
|
|
case 0:
|
2019-06-25 23:42:43 +02:00
|
|
|
w = 160;
|
|
|
|
h = 120;
|
2013-02-04 13:21:10 +03:00
|
|
|
break;
|
|
|
|
case 1:
|
2019-06-25 23:42:43 +02:00
|
|
|
w = 128;
|
|
|
|
h = 96;
|
2013-02-04 13:21:10 +03:00
|
|
|
break;
|
|
|
|
case 2:
|
2019-06-25 23:42:43 +02:00
|
|
|
w = 176;
|
|
|
|
h = 144;
|
2013-02-04 13:21:10 +03:00
|
|
|
break;
|
|
|
|
case 3:
|
2019-06-25 23:42:43 +02:00
|
|
|
w = 352;
|
|
|
|
h = 288;
|
2013-02-04 13:21:10 +03:00
|
|
|
break;
|
|
|
|
case 4:
|
2019-06-25 23:42:43 +02:00
|
|
|
w = 704;
|
|
|
|
h = 576;
|
2013-02-04 13:21:10 +03:00
|
|
|
break;
|
|
|
|
case 5:
|
2019-06-25 23:42:43 +02:00
|
|
|
w = 240;
|
|
|
|
h = 180;
|
2013-02-04 13:21:10 +03:00
|
|
|
break;
|
|
|
|
case 6:
|
2019-06-25 23:42:43 +02:00
|
|
|
w = 320;
|
|
|
|
h = 240;
|
2013-02-04 13:21:10 +03:00
|
|
|
break;
|
|
|
|
case 7:
|
2019-06-25 23:42:43 +02:00
|
|
|
w = get_bits(&gb, 12);
|
|
|
|
h = get_bits(&gb, 12);
|
2013-02-04 13:21:10 +03:00
|
|
|
break;
|
|
|
|
}
|
2019-06-25 23:42:43 +02:00
|
|
|
ret = ff_set_dimensions(avctx, w, h);
|
|
|
|
if (ret < 0)
|
|
|
|
goto fail;
|
2003-05-10 01:16:14 +03:00
|
|
|
|
2013-02-03 13:10:05 +03:00
|
|
|
s->halfpel_flag = get_bits1(&gb);
|
|
|
|
s->thirdpel_flag = get_bits1(&gb);
|
2003-05-10 01:16:14 +03:00
|
|
|
|
2013-02-04 13:21:10 +03:00
|
|
|
/* unknown fields */
|
2015-05-02 02:58:00 +02:00
|
|
|
unk0 = get_bits1(&gb);
|
|
|
|
unk1 = get_bits1(&gb);
|
|
|
|
unk2 = get_bits1(&gb);
|
|
|
|
unk3 = get_bits1(&gb);
|
2003-05-10 01:16:14 +03:00
|
|
|
|
2016-03-23 14:23:55 +02:00
|
|
|
s->low_delay = get_bits1(&gb);
|
2008-10-27 01:34:44 +02:00
|
|
|
|
2013-02-04 13:21:10 +03:00
|
|
|
/* unknown field */
|
2015-05-02 02:58:00 +02:00
|
|
|
unk4 = get_bits1(&gb);
|
|
|
|
|
|
|
|
av_log(avctx, AV_LOG_DEBUG, "Unknown fields %d %d %d %d %d\n",
|
|
|
|
unk0, unk1, unk2, unk3, unk4);
|
2008-11-22 18:36:50 +02:00
|
|
|
|
2013-12-15 02:36:29 +03:00
|
|
|
if (skip_1stop_8data_bits(&gb) < 0) {
|
|
|
|
ret = AVERROR_INVALIDDATA;
|
|
|
|
goto fail;
|
|
|
|
}
|
2008-11-22 18:36:50 +02:00
|
|
|
|
2015-05-02 03:02:30 +02:00
|
|
|
s->has_watermark = get_bits1(&gb);
|
2016-03-23 14:23:55 +02:00
|
|
|
avctx->has_b_frames = !s->low_delay;
|
2015-05-02 03:02:30 +02:00
|
|
|
if (s->has_watermark) {
|
2009-01-14 01:44:16 +02:00
|
|
|
#if CONFIG_ZLIB
|
2016-05-24 01:20:34 +02:00
|
|
|
unsigned watermark_width = get_interleaved_ue_golomb(&gb);
|
|
|
|
unsigned watermark_height = get_interleaved_ue_golomb(&gb);
|
|
|
|
int u1 = get_interleaved_ue_golomb(&gb);
|
2013-02-04 13:21:10 +03:00
|
|
|
int u2 = get_bits(&gb, 8);
|
|
|
|
int u3 = get_bits(&gb, 2);
|
2016-05-24 01:20:34 +02:00
|
|
|
int u4 = get_interleaved_ue_golomb(&gb);
|
2013-02-04 13:21:10 +03:00
|
|
|
unsigned long buf_len = watermark_width *
|
|
|
|
watermark_height * 4;
|
|
|
|
int offset = get_bits_count(&gb) + 7 >> 3;
|
|
|
|
uint8_t *buf;
|
|
|
|
|
2013-09-20 14:29:39 +03:00
|
|
|
if (watermark_height <= 0 ||
|
2013-12-15 02:36:29 +03:00
|
|
|
(uint64_t)watermark_width * 4 > UINT_MAX / watermark_height) {
|
|
|
|
ret = -1;
|
|
|
|
goto fail;
|
|
|
|
}
|
2008-11-22 18:36:50 +02:00
|
|
|
|
2013-02-04 13:21:10 +03:00
|
|
|
buf = av_malloc(buf_len);
|
2015-01-14 14:23:20 +02:00
|
|
|
if (!buf) {
|
|
|
|
ret = AVERROR(ENOMEM);
|
|
|
|
goto fail;
|
|
|
|
}
|
2014-03-13 14:13:33 +03:00
|
|
|
av_log(avctx, AV_LOG_DEBUG, "watermark size: %ux%u\n",
|
2013-02-04 13:21:10 +03:00
|
|
|
watermark_width, watermark_height);
|
|
|
|
av_log(avctx, AV_LOG_DEBUG,
|
|
|
|
"u1: %x u2: %x u3: %x compressed data size: %d offset: %d\n",
|
|
|
|
u1, u2, u3, u4, offset);
|
|
|
|
if (uncompress(buf, &buf_len, extradata + 8 + offset,
|
|
|
|
size - offset) != Z_OK) {
|
2012-10-19 19:03:10 +03:00
|
|
|
av_log(avctx, AV_LOG_ERROR,
|
2013-02-04 13:21:10 +03:00
|
|
|
"could not uncompress watermark logo\n");
|
|
|
|
av_free(buf);
|
2013-12-15 02:36:29 +03:00
|
|
|
ret = -1;
|
|
|
|
goto fail;
|
2008-11-22 18:36:50 +02:00
|
|
|
}
|
2013-02-03 13:10:05 +03:00
|
|
|
s->watermark_key = ff_svq1_packet_checksum(buf, buf_len, 0);
|
|
|
|
s->watermark_key = s->watermark_key << 16 | s->watermark_key;
|
2013-02-04 13:21:10 +03:00
|
|
|
av_log(avctx, AV_LOG_DEBUG,
|
2014-03-13 14:13:33 +03:00
|
|
|
"watermark key %#"PRIx32"\n", s->watermark_key);
|
2013-02-04 13:21:10 +03:00
|
|
|
av_free(buf);
|
|
|
|
#else
|
|
|
|
av_log(avctx, AV_LOG_ERROR,
|
|
|
|
"this svq3 file contains watermark which need zlib support compiled in\n");
|
2013-12-15 02:36:29 +03:00
|
|
|
ret = -1;
|
|
|
|
goto fail;
|
2013-02-04 13:21:10 +03:00
|
|
|
#endif
|
2008-11-22 18:36:50 +02:00
|
|
|
}
|
2013-02-04 13:21:10 +03:00
|
|
|
}
|
2011-05-13 10:24:31 +03:00
|
|
|
|
2016-03-23 11:33:48 +02:00
|
|
|
s->mb_width = (avctx->width + 15) / 16;
|
|
|
|
s->mb_height = (avctx->height + 15) / 16;
|
|
|
|
s->mb_stride = s->mb_width + 1;
|
|
|
|
s->mb_num = s->mb_width * s->mb_height;
|
|
|
|
s->b_stride = 4 * s->mb_width;
|
|
|
|
s->h_edge_pos = s->mb_width * 16;
|
|
|
|
s->v_edge_pos = s->mb_height * 16;
|
|
|
|
|
|
|
|
s->intra4x4_pred_mode = av_mallocz(s->mb_stride * 2 * 8);
|
2016-03-23 10:49:20 +02:00
|
|
|
if (!s->intra4x4_pred_mode)
|
|
|
|
return AVERROR(ENOMEM);
|
|
|
|
|
2016-03-23 11:33:48 +02:00
|
|
|
s->mb2br_xy = av_mallocz(s->mb_stride * (s->mb_height + 1) *
|
2016-03-23 11:03:50 +02:00
|
|
|
sizeof(*s->mb2br_xy));
|
|
|
|
if (!s->mb2br_xy)
|
|
|
|
return AVERROR(ENOMEM);
|
|
|
|
|
2016-03-23 11:33:48 +02:00
|
|
|
for (y = 0; y < s->mb_height; y++)
|
|
|
|
for (x = 0; x < s->mb_width; x++) {
|
|
|
|
const int mb_xy = x + y * s->mb_stride;
|
2016-03-23 11:03:50 +02:00
|
|
|
|
2016-03-23 11:33:48 +02:00
|
|
|
s->mb2br_xy[mb_xy] = 8 * (mb_xy % (2 * s->mb_stride));
|
2016-03-23 11:03:50 +02:00
|
|
|
}
|
|
|
|
|
2016-03-23 11:26:54 +02:00
|
|
|
init_dequant4_coeff_table(s);
|
2008-11-22 18:36:50 +02:00
|
|
|
|
2008-11-24 20:49:50 +02:00
|
|
|
return 0;
|
2013-12-15 02:36:29 +03:00
|
|
|
fail:
|
|
|
|
svq3_decode_end(avctx);
|
|
|
|
return ret;
|
2008-11-24 20:49:50 +02:00
|
|
|
}
|
|
|
|
|
2016-05-18 09:34:05 +02:00
|
|
|
static void free_picture(AVCodecContext *avctx, SVQ3Frame *pic)
|
2012-11-21 23:34:46 +03:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
for (i = 0; i < 2; i++) {
|
|
|
|
av_buffer_unref(&pic->motion_val_buf[i]);
|
|
|
|
av_buffer_unref(&pic->ref_index_buf[i]);
|
|
|
|
}
|
|
|
|
av_buffer_unref(&pic->mb_type_buf);
|
|
|
|
|
2015-04-17 12:09:50 +02:00
|
|
|
av_frame_unref(pic->f);
|
2012-11-21 23:34:46 +03:00
|
|
|
}
|
|
|
|
|
2016-05-18 09:34:05 +02:00
|
|
|
static int get_buffer(AVCodecContext *avctx, SVQ3Frame *pic)
|
2013-02-03 13:10:05 +03:00
|
|
|
{
|
|
|
|
SVQ3Context *s = avctx->priv_data;
|
2016-03-23 11:33:48 +02:00
|
|
|
const int big_mb_num = s->mb_stride * (s->mb_height + 1) + 1;
|
|
|
|
const int mb_array_size = s->mb_stride * s->mb_height;
|
|
|
|
const int b4_stride = s->mb_width * 4 + 1;
|
|
|
|
const int b4_array_size = b4_stride * s->mb_height * 4;
|
2013-02-03 13:10:05 +03:00
|
|
|
int ret;
|
|
|
|
|
2012-11-21 23:34:46 +03:00
|
|
|
if (!pic->motion_val_buf[0]) {
|
2013-02-03 13:10:05 +03:00
|
|
|
int i;
|
|
|
|
|
2016-03-23 11:33:48 +02:00
|
|
|
pic->mb_type_buf = av_buffer_allocz((big_mb_num + s->mb_stride) * sizeof(uint32_t));
|
2012-11-21 23:34:46 +03:00
|
|
|
if (!pic->mb_type_buf)
|
2013-02-03 13:10:05 +03:00
|
|
|
return AVERROR(ENOMEM);
|
2016-03-23 11:33:48 +02:00
|
|
|
pic->mb_type = (uint32_t*)pic->mb_type_buf->data + 2 * s->mb_stride + 1;
|
2013-02-03 13:10:05 +03:00
|
|
|
|
|
|
|
for (i = 0; i < 2; i++) {
|
2012-11-21 23:34:46 +03:00
|
|
|
pic->motion_val_buf[i] = av_buffer_allocz(2 * (b4_array_size + 4) * sizeof(int16_t));
|
|
|
|
pic->ref_index_buf[i] = av_buffer_allocz(4 * mb_array_size);
|
|
|
|
if (!pic->motion_val_buf[i] || !pic->ref_index_buf[i]) {
|
|
|
|
ret = AVERROR(ENOMEM);
|
|
|
|
goto fail;
|
|
|
|
}
|
2013-02-03 13:10:05 +03:00
|
|
|
|
2012-11-21 23:34:46 +03:00
|
|
|
pic->motion_val[i] = (int16_t (*)[2])pic->motion_val_buf[i]->data + 4;
|
|
|
|
pic->ref_index[i] = pic->ref_index_buf[i]->data;
|
2013-02-03 13:10:05 +03:00
|
|
|
}
|
|
|
|
}
|
2012-11-21 23:34:46 +03:00
|
|
|
|
2015-04-17 12:09:50 +02:00
|
|
|
ret = ff_get_buffer(avctx, pic->f,
|
2016-05-18 09:34:05 +02:00
|
|
|
(s->pict_type != AV_PICTURE_TYPE_B) ?
|
|
|
|
AV_GET_BUFFER_FLAG_REF : 0);
|
2012-11-21 23:34:46 +03:00
|
|
|
if (ret < 0)
|
|
|
|
goto fail;
|
2013-02-03 13:10:05 +03:00
|
|
|
|
2016-03-23 10:54:43 +02:00
|
|
|
if (!s->edge_emu_buffer) {
|
2016-04-27 17:47:52 +02:00
|
|
|
s->edge_emu_buffer = av_mallocz_array(pic->f->linesize[0], 17);
|
2016-03-23 10:54:43 +02:00
|
|
|
if (!s->edge_emu_buffer)
|
2013-02-18 04:01:26 +03:00
|
|
|
return AVERROR(ENOMEM);
|
|
|
|
}
|
2013-02-03 13:10:05 +03:00
|
|
|
|
2012-11-21 23:34:46 +03:00
|
|
|
return 0;
|
|
|
|
fail:
|
|
|
|
free_picture(avctx, pic);
|
2013-02-03 13:10:05 +03:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2012-10-19 19:03:10 +03:00
|
|
|
static int svq3_decode_frame(AVCodecContext *avctx, void *data,
|
2012-11-13 21:35:22 +03:00
|
|
|
int *got_frame, AVPacket *avpkt)
|
2008-11-24 20:49:50 +02:00
|
|
|
{
|
2013-02-03 13:10:05 +03:00
|
|
|
SVQ3Context *s = avctx->priv_data;
|
2012-10-19 19:03:10 +03:00
|
|
|
int buf_size = avpkt->size;
|
2013-02-16 23:14:00 +03:00
|
|
|
int left;
|
2011-05-05 16:17:51 +03:00
|
|
|
uint8_t *buf;
|
2013-02-03 13:10:05 +03:00
|
|
|
int ret, m, i;
|
2008-11-24 20:49:50 +02:00
|
|
|
|
2008-11-22 18:36:50 +02:00
|
|
|
/* special case for last picture */
|
|
|
|
if (buf_size == 0) {
|
2016-03-23 14:23:55 +02:00
|
|
|
if (s->next_pic->f->data[0] && !s->low_delay && !s->last_frame_output) {
|
2015-04-17 12:09:50 +02:00
|
|
|
ret = av_frame_ref(data, s->next_pic->f);
|
2012-11-21 23:34:46 +03:00
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
2013-02-03 13:10:05 +03:00
|
|
|
s->last_frame_output = 1;
|
2012-11-13 21:35:22 +03:00
|
|
|
*got_frame = 1;
|
2008-11-22 18:36:50 +02:00
|
|
|
}
|
|
|
|
return 0;
|
2003-06-19 04:44:44 +03:00
|
|
|
}
|
2003-05-10 01:16:14 +03:00
|
|
|
|
2016-05-03 11:23:23 +02:00
|
|
|
s->mb_x = s->mb_y = s->mb_xy = 0;
|
2003-05-10 01:16:14 +03:00
|
|
|
|
2013-02-16 23:14:00 +03:00
|
|
|
if (s->watermark_key) {
|
2013-10-30 12:17:26 +03:00
|
|
|
av_fast_padded_malloc(&s->buf, &s->buf_size, buf_size);
|
2013-02-16 23:14:00 +03:00
|
|
|
if (!s->buf)
|
2011-05-05 16:17:51 +03:00
|
|
|
return AVERROR(ENOMEM);
|
2013-02-16 23:14:00 +03:00
|
|
|
memcpy(s->buf, avpkt->data, buf_size);
|
|
|
|
buf = s->buf;
|
2011-05-05 16:17:51 +03:00
|
|
|
} else {
|
|
|
|
buf = avpkt->data;
|
|
|
|
}
|
|
|
|
|
2016-03-12 18:46:36 +02:00
|
|
|
ret = init_get_bits(&s->gb, buf, 8 * buf_size);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
2011-05-05 16:17:51 +03:00
|
|
|
|
2011-05-05 15:18:33 +03:00
|
|
|
if (svq3_decode_slice_header(avctx))
|
2008-11-22 18:36:50 +02:00
|
|
|
return -1;
|
2003-05-10 01:16:14 +03:00
|
|
|
|
2016-09-08 21:15:55 +02:00
|
|
|
s->pict_type = s->slice_type;
|
|
|
|
|
2016-03-23 11:33:48 +02:00
|
|
|
if (s->pict_type != AV_PICTURE_TYPE_B)
|
2016-05-18 09:34:05 +02:00
|
|
|
FFSWAP(SVQ3Frame*, s->next_pic, s->last_pic);
|
2013-02-03 13:10:05 +03:00
|
|
|
|
2015-04-17 12:09:50 +02:00
|
|
|
av_frame_unref(s->cur_pic->f);
|
2003-05-10 01:16:14 +03:00
|
|
|
|
2011-04-02 12:56:21 +03:00
|
|
|
/* for skipping the frame */
|
2016-03-23 11:33:48 +02:00
|
|
|
s->cur_pic->f->pict_type = s->pict_type;
|
|
|
|
s->cur_pic->f->key_frame = (s->pict_type == AV_PICTURE_TYPE_I);
|
2008-11-22 18:36:50 +02:00
|
|
|
|
2013-02-03 13:10:05 +03:00
|
|
|
ret = get_buffer(avctx, s->cur_pic);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
for (i = 0; i < 16; i++) {
|
2016-03-23 14:17:44 +02:00
|
|
|
s->block_offset[i] = (4 * ((scan8[i] - scan8[0]) & 7)) + 4 * s->cur_pic->f->linesize[0] * ((scan8[i] - scan8[0]) >> 3);
|
|
|
|
s->block_offset[48 + i] = (4 * ((scan8[i] - scan8[0]) & 7)) + 8 * s->cur_pic->f->linesize[0] * ((scan8[i] - scan8[0]) >> 3);
|
2013-02-03 13:10:05 +03:00
|
|
|
}
|
|
|
|
for (i = 0; i < 16; i++) {
|
2016-03-23 14:17:44 +02:00
|
|
|
s->block_offset[16 + i] =
|
|
|
|
s->block_offset[32 + i] = (4 * ((scan8[i] - scan8[0]) & 7)) + 4 * s->cur_pic->f->linesize[1] * ((scan8[i] - scan8[0]) >> 3);
|
|
|
|
s->block_offset[48 + 16 + i] =
|
|
|
|
s->block_offset[48 + 32 + i] = (4 * ((scan8[i] - scan8[0]) & 7)) + 8 * s->cur_pic->f->linesize[1] * ((scan8[i] - scan8[0]) >> 3);
|
2013-02-03 13:10:05 +03:00
|
|
|
}
|
|
|
|
|
2016-03-23 11:33:48 +02:00
|
|
|
if (s->pict_type != AV_PICTURE_TYPE_I) {
|
2015-04-17 12:09:50 +02:00
|
|
|
if (!s->last_pic->f->data[0]) {
|
2013-02-03 13:10:05 +03:00
|
|
|
av_log(avctx, AV_LOG_ERROR, "Missing reference frame.\n");
|
2015-04-29 15:44:21 +02:00
|
|
|
av_frame_unref(s->last_pic->f);
|
2013-02-03 13:10:05 +03:00
|
|
|
ret = get_buffer(avctx, s->last_pic);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
2015-04-17 12:09:50 +02:00
|
|
|
memset(s->last_pic->f->data[0], 0, avctx->height * s->last_pic->f->linesize[0]);
|
|
|
|
memset(s->last_pic->f->data[1], 0x80, (avctx->height / 2) *
|
|
|
|
s->last_pic->f->linesize[1]);
|
|
|
|
memset(s->last_pic->f->data[2], 0x80, (avctx->height / 2) *
|
|
|
|
s->last_pic->f->linesize[2]);
|
2013-02-03 13:10:05 +03:00
|
|
|
}
|
|
|
|
|
2016-03-23 11:33:48 +02:00
|
|
|
if (s->pict_type == AV_PICTURE_TYPE_B && !s->next_pic->f->data[0]) {
|
2013-02-03 13:10:05 +03:00
|
|
|
av_log(avctx, AV_LOG_ERROR, "Missing reference frame.\n");
|
2015-04-29 15:44:21 +02:00
|
|
|
av_frame_unref(s->next_pic->f);
|
2013-02-03 13:10:05 +03:00
|
|
|
ret = get_buffer(avctx, s->next_pic);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
2015-04-17 12:09:50 +02:00
|
|
|
memset(s->next_pic->f->data[0], 0, avctx->height * s->next_pic->f->linesize[0]);
|
|
|
|
memset(s->next_pic->f->data[1], 0x80, (avctx->height / 2) *
|
|
|
|
s->next_pic->f->linesize[1]);
|
|
|
|
memset(s->next_pic->f->data[2], 0x80, (avctx->height / 2) *
|
|
|
|
s->next_pic->f->linesize[2]);
|
2013-02-03 13:10:05 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (avctx->debug & FF_DEBUG_PICT_INFO)
|
2016-03-23 14:23:55 +02:00
|
|
|
av_log(s->avctx, AV_LOG_DEBUG,
|
2013-02-03 13:10:05 +03:00
|
|
|
"%c hpel:%d, tpel:%d aqp:%d qp:%d, slice_num:%02X\n",
|
2016-03-23 11:33:48 +02:00
|
|
|
av_get_picture_type_char(s->pict_type),
|
2013-02-03 13:10:05 +03:00
|
|
|
s->halfpel_flag, s->thirdpel_flag,
|
2016-03-23 11:43:41 +02:00
|
|
|
s->adaptive_quant, s->qscale, s->slice_num);
|
2013-02-03 13:10:05 +03:00
|
|
|
|
2016-03-23 11:33:48 +02:00
|
|
|
if (avctx->skip_frame >= AVDISCARD_NONREF && s->pict_type == AV_PICTURE_TYPE_B ||
|
|
|
|
avctx->skip_frame >= AVDISCARD_NONKEY && s->pict_type != AV_PICTURE_TYPE_I ||
|
2012-10-19 19:26:54 +03:00
|
|
|
avctx->skip_frame >= AVDISCARD_ALL)
|
2008-11-22 18:36:50 +02:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (s->next_p_frame_damaged) {
|
2016-03-23 11:33:48 +02:00
|
|
|
if (s->pict_type == AV_PICTURE_TYPE_B)
|
2008-11-22 18:36:50 +02:00
|
|
|
return 0;
|
|
|
|
else
|
|
|
|
s->next_p_frame_damaged = 0;
|
|
|
|
}
|
2003-06-19 04:44:44 +03:00
|
|
|
|
2016-03-23 11:33:48 +02:00
|
|
|
if (s->pict_type == AV_PICTURE_TYPE_B) {
|
2016-03-23 12:04:59 +02:00
|
|
|
s->frame_num_offset = s->slice_num - s->prev_frame_num;
|
2003-05-10 01:16:14 +03:00
|
|
|
|
2016-03-23 12:04:59 +02:00
|
|
|
if (s->frame_num_offset < 0)
|
|
|
|
s->frame_num_offset += 256;
|
|
|
|
if (s->frame_num_offset == 0 ||
|
|
|
|
s->frame_num_offset >= s->prev_frame_num_offset) {
|
2016-03-23 14:23:55 +02:00
|
|
|
av_log(s->avctx, AV_LOG_ERROR, "error in B-frame picture id\n");
|
2008-11-22 18:36:50 +02:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
} else {
|
2016-03-23 12:04:59 +02:00
|
|
|
s->prev_frame_num = s->frame_num;
|
|
|
|
s->frame_num = s->slice_num;
|
|
|
|
s->prev_frame_num_offset = s->frame_num - s->prev_frame_num;
|
2003-06-19 04:44:44 +03:00
|
|
|
|
2016-03-23 12:04:59 +02:00
|
|
|
if (s->prev_frame_num_offset < 0)
|
|
|
|
s->prev_frame_num_offset += 256;
|
2003-06-19 04:44:44 +03:00
|
|
|
}
|
|
|
|
|
2012-10-19 19:03:10 +03:00
|
|
|
for (m = 0; m < 2; m++) {
|
2008-11-22 18:36:50 +02:00
|
|
|
int i;
|
2012-10-19 19:03:10 +03:00
|
|
|
for (i = 0; i < 4; i++) {
|
2008-11-22 18:36:50 +02:00
|
|
|
int j;
|
|
|
|
for (j = -1; j < 4; j++)
|
2016-03-23 11:03:50 +02:00
|
|
|
s->ref_cache[m][scan8[0] + 8 * i + j] = 1;
|
2008-11-22 18:36:50 +02:00
|
|
|
if (i < 3)
|
2016-03-23 11:03:50 +02:00
|
|
|
s->ref_cache[m][scan8[0] + 8 * i + j] = PART_NOT_AVAILABLE;
|
2008-11-22 18:36:50 +02:00
|
|
|
}
|
2003-06-19 04:44:44 +03:00
|
|
|
}
|
|
|
|
|
2016-03-23 11:33:48 +02:00
|
|
|
for (s->mb_y = 0; s->mb_y < s->mb_height; s->mb_y++) {
|
|
|
|
for (s->mb_x = 0; s->mb_x < s->mb_width; s->mb_x++) {
|
2012-11-30 17:00:47 +03:00
|
|
|
unsigned mb_type;
|
2016-03-23 11:33:48 +02:00
|
|
|
s->mb_xy = s->mb_x + s->mb_y * s->mb_stride;
|
2003-06-19 04:44:44 +03:00
|
|
|
|
2016-03-23 14:16:32 +02:00
|
|
|
if ((get_bits_left(&s->gb_slice)) <= 7) {
|
|
|
|
if (((get_bits_count(&s->gb_slice) & 7) == 0 ||
|
|
|
|
show_bits(&s->gb_slice, get_bits_left(&s->gb_slice) & 7) == 0)) {
|
2003-06-19 04:44:44 +03:00
|
|
|
|
2016-03-12 18:46:36 +02:00
|
|
|
if (svq3_decode_slice_header(avctx))
|
|
|
|
return -1;
|
|
|
|
}
|
2016-09-08 21:15:55 +02:00
|
|
|
if (s->slice_type != s->pict_type) {
|
2016-12-03 16:40:26 +02:00
|
|
|
avpriv_request_sample(avctx, "non constant slice type");
|
2016-09-08 21:15:55 +02:00
|
|
|
}
|
2008-11-22 18:36:50 +02:00
|
|
|
/* TODO: support s->mb_skip_run */
|
|
|
|
}
|
2003-06-19 04:44:44 +03:00
|
|
|
|
2016-05-24 01:20:34 +02:00
|
|
|
mb_type = get_interleaved_ue_golomb(&s->gb_slice);
|
2003-06-19 04:44:44 +03:00
|
|
|
|
2016-03-23 11:33:48 +02:00
|
|
|
if (s->pict_type == AV_PICTURE_TYPE_I)
|
2008-11-22 18:36:50 +02:00
|
|
|
mb_type += 8;
|
2016-03-23 11:33:48 +02:00
|
|
|
else if (s->pict_type == AV_PICTURE_TYPE_B && mb_type >= 4)
|
2008-11-22 18:36:50 +02:00
|
|
|
mb_type += 4;
|
2013-02-03 13:10:05 +03:00
|
|
|
if (mb_type > 33 || svq3_decode_mb(s, mb_type)) {
|
2016-03-23 14:23:55 +02:00
|
|
|
av_log(s->avctx, AV_LOG_ERROR,
|
2016-03-22 16:54:20 +02:00
|
|
|
"error while decoding MB %d %d\n", s->mb_x, s->mb_y);
|
2008-11-22 18:36:50 +02:00
|
|
|
return -1;
|
|
|
|
}
|
2003-05-10 01:16:14 +03:00
|
|
|
|
2016-05-03 11:23:23 +02:00
|
|
|
if (mb_type != 0 || s->cbp)
|
2016-03-23 14:23:55 +02:00
|
|
|
hl_decode_mb(s);
|
2003-05-10 01:16:14 +03:00
|
|
|
|
2016-03-23 14:23:55 +02:00
|
|
|
if (s->pict_type != AV_PICTURE_TYPE_B && !s->low_delay)
|
2016-03-23 12:02:19 +02:00
|
|
|
s->cur_pic->mb_type[s->mb_x + s->mb_y * s->mb_stride] =
|
2016-03-23 11:33:48 +02:00
|
|
|
(s->pict_type == AV_PICTURE_TYPE_P && mb_type < 8) ? (mb_type - 1) : -1;
|
2008-11-22 18:36:50 +02:00
|
|
|
}
|
2003-06-27 18:05:29 +03:00
|
|
|
|
2015-04-17 12:09:50 +02:00
|
|
|
ff_draw_horiz_band(avctx, s->cur_pic->f,
|
|
|
|
s->last_pic->f->data[0] ? s->last_pic->f : NULL,
|
2016-03-23 14:23:55 +02:00
|
|
|
16 * s->mb_y, 16, PICT_FRAME, 0,
|
|
|
|
s->low_delay);
|
2003-05-10 01:16:14 +03:00
|
|
|
}
|
2003-05-16 13:14:25 +03:00
|
|
|
|
2016-05-03 11:26:13 +02:00
|
|
|
left = buf_size*8 - get_bits_count(&s->gb_slice);
|
2011-05-05 15:40:26 +03:00
|
|
|
|
2016-05-03 11:52:04 +02:00
|
|
|
if (s->mb_y != s->mb_height || s->mb_x != s->mb_width) {
|
2016-05-03 11:23:23 +02:00
|
|
|
av_log(avctx, AV_LOG_INFO, "frame num %d incomplete pic x %d y %d left %d\n", avctx->frame_number, s->mb_y, s->mb_x, left);
|
2011-05-05 15:40:26 +03:00
|
|
|
//av_hex_dump(stderr, buf+buf_size-8, 8);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (left < 0) {
|
|
|
|
av_log(avctx, AV_LOG_ERROR, "frame num %d left %d\n", avctx->frame_number, left);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2016-03-23 14:23:55 +02:00
|
|
|
if (s->pict_type == AV_PICTURE_TYPE_B || s->low_delay)
|
2015-04-17 12:09:50 +02:00
|
|
|
ret = av_frame_ref(data, s->cur_pic->f);
|
|
|
|
else if (s->last_pic->f->data[0])
|
|
|
|
ret = av_frame_ref(data, s->last_pic->f);
|
2012-11-21 23:34:46 +03:00
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
2003-06-19 04:44:44 +03:00
|
|
|
|
2008-11-22 18:36:50 +02:00
|
|
|
/* Do not output the last pic after seeking. */
|
2016-03-23 14:23:55 +02:00
|
|
|
if (s->last_pic->f->data[0] || s->low_delay)
|
2012-11-13 21:35:22 +03:00
|
|
|
*got_frame = 1;
|
2003-06-19 04:44:44 +03:00
|
|
|
|
2016-03-23 11:33:48 +02:00
|
|
|
if (s->pict_type != AV_PICTURE_TYPE_B) {
|
2016-05-18 09:34:05 +02:00
|
|
|
FFSWAP(SVQ3Frame*, s->cur_pic, s->next_pic);
|
2012-11-21 23:34:46 +03:00
|
|
|
} else {
|
2015-04-17 12:09:50 +02:00
|
|
|
av_frame_unref(s->cur_pic->f);
|
2013-02-03 13:10:05 +03:00
|
|
|
}
|
|
|
|
|
2008-11-22 18:36:50 +02:00
|
|
|
return buf_size;
|
2003-05-10 01:16:14 +03:00
|
|
|
}
|
|
|
|
|
2013-05-02 11:20:12 +03:00
|
|
|
static av_cold int svq3_decode_end(AVCodecContext *avctx)
|
2011-05-05 15:18:33 +03:00
|
|
|
{
|
2013-02-03 13:10:05 +03:00
|
|
|
SVQ3Context *s = avctx->priv_data;
|
2011-05-05 15:18:33 +03:00
|
|
|
|
2013-02-03 13:10:05 +03:00
|
|
|
free_picture(avctx, s->cur_pic);
|
|
|
|
free_picture(avctx, s->next_pic);
|
|
|
|
free_picture(avctx, s->last_pic);
|
2015-04-17 12:09:50 +02:00
|
|
|
av_frame_free(&s->cur_pic->f);
|
|
|
|
av_frame_free(&s->next_pic->f);
|
|
|
|
av_frame_free(&s->last_pic->f);
|
2012-11-21 23:34:46 +03:00
|
|
|
av_freep(&s->cur_pic);
|
|
|
|
av_freep(&s->next_pic);
|
|
|
|
av_freep(&s->last_pic);
|
2016-03-12 18:46:36 +02:00
|
|
|
av_freep(&s->slice_buf);
|
2016-03-23 10:49:20 +02:00
|
|
|
av_freep(&s->intra4x4_pred_mode);
|
2016-03-23 10:54:43 +02:00
|
|
|
av_freep(&s->edge_emu_buffer);
|
2016-03-23 11:03:50 +02:00
|
|
|
av_freep(&s->mb2br_xy);
|
2012-11-21 23:34:46 +03:00
|
|
|
|
2011-05-05 15:18:33 +03:00
|
|
|
|
2013-02-16 23:14:00 +03:00
|
|
|
av_freep(&s->buf);
|
|
|
|
s->buf_size = 0;
|
2011-05-05 16:17:51 +03:00
|
|
|
|
2011-05-05 15:18:33 +03:00
|
|
|
return 0;
|
|
|
|
}
|
2003-05-10 01:16:14 +03:00
|
|
|
|
2011-01-25 23:40:11 +02:00
|
|
|
AVCodec ff_svq3_decoder = {
|
2011-07-17 13:54:31 +03:00
|
|
|
.name = "svq3",
|
2013-10-03 23:57:53 +03:00
|
|
|
.long_name = NULL_IF_CONFIG_SMALL("Sorenson Vector Quantizer 3 / Sorenson Video 3 / SVQ3"),
|
2011-07-17 13:54:31 +03:00
|
|
|
.type = AVMEDIA_TYPE_VIDEO,
|
2012-08-05 12:11:04 +03:00
|
|
|
.id = AV_CODEC_ID_SVQ3,
|
2011-07-17 13:54:31 +03:00
|
|
|
.priv_data_size = sizeof(SVQ3Context),
|
|
|
|
.init = svq3_decode_init,
|
|
|
|
.close = svq3_decode_end,
|
|
|
|
.decode = svq3_decode_frame,
|
2015-07-07 02:41:27 +02:00
|
|
|
.capabilities = AV_CODEC_CAP_DRAW_HORIZ_BAND |
|
|
|
|
AV_CODEC_CAP_DR1 |
|
|
|
|
AV_CODEC_CAP_DELAY,
|
2012-10-19 19:03:10 +03:00
|
|
|
.pix_fmts = (const enum AVPixelFormat[]) { AV_PIX_FMT_YUVJ420P,
|
|
|
|
AV_PIX_FMT_NONE},
|
2003-05-10 01:16:14 +03:00
|
|
|
};
|