dsputil: Split off H.263 bits into their own H263DSPContext

pull/73/head
Diego Biurrun 11 years ago
parent 86f910806b
commit 0338c39698
  1. 9
      configure
  2. 1
      libavcodec/Makefile
  3. 79
      libavcodec/dsputil.c
  4. 3
      libavcodec/dsputil.h
  5. 32
      libavcodec/h263.c
  6. 5
      libavcodec/h263data.h
  7. 1
      libavcodec/h263dec.c
  8. 108
      libavcodec/h263dsp.c
  9. 34
      libavcodec/h263dsp.h
  10. 3
      libavcodec/mpegvideo.h
  11. 1
      libavcodec/mpegvideo_enc.c
  12. 1
      libavcodec/rv10.c
  13. 4
      libavcodec/x86/Makefile
  14. 8
      libavcodec/x86/dsputil_init.c
  15. 39
      libavcodec/x86/h263dsp_init.c

9
configure vendored

@ -1384,6 +1384,7 @@ CONFIG_EXTRA="
gcrypt
golomb
gplv3
h263dsp
h264chroma
h264dsp
h264pred
@ -1598,8 +1599,8 @@ g2m_decoder_deps="zlib"
g2m_decoder_select="dsputil"
h261_decoder_select="error_resilience mpegvideo"
h261_encoder_select="aandcttables mpegvideoenc"
h263_decoder_select="error_resilience h263_parser mpegvideo"
h263_encoder_select="aandcttables mpegvideoenc"
h263_decoder_select="error_resilience h263_parser h263dsp mpegvideo"
h263_encoder_select="aandcttables h263dsp mpegvideoenc"
h263i_decoder_select="h263_decoder"
h263p_encoder_select="h263_encoder"
h264_decoder_select="golomb h264chroma h264dsp h264pred h264qpel videodsp"
@ -1665,9 +1666,9 @@ qcelp_decoder_select="lsp"
qdm2_decoder_select="mdct rdft mpegaudiodsp"
ra_144_encoder_select="audio_frame_queue lpc"
ralf_decoder_select="golomb"
rv10_decoder_select="error_resilience h263_decoder"
rv10_decoder_select="error_resilience h263_decoder h263dsp"
rv10_encoder_select="h263_encoder"
rv20_decoder_select="error_resilience h263_decoder"
rv20_decoder_select="error_resilience h263_decoder h263dsp"
rv20_encoder_select="h263_encoder"
rv30_decoder_select="error_resilience golomb h264chroma h264pred h264qpel mpegvideo videodsp"
rv40_decoder_select="error_resilience golomb h264chroma h264pred h264qpel mpegvideo videodsp"

@ -41,6 +41,7 @@ FFT-OBJS-$(CONFIG_HARDCODED_TABLES) += cos_tables.o cos_fixed_tables.o
OBJS-$(CONFIG_FFT) += avfft.o fft_fixed.o fft_float.o \
$(FFT-OBJS-yes)
OBJS-$(CONFIG_GOLOMB) += golomb.o
OBJS-$(CONFIG_H263DSP) += h263dsp.o
OBJS-$(CONFIG_H264CHROMA) += h264chroma.o
OBJS-$(CONFIG_H264DSP) += h264dsp.o h264idct.o
OBJS-$(CONFIG_H264PRED) += h264pred.o

@ -1409,80 +1409,6 @@ static void put_mspel8_mc22_c(uint8_t *dst, uint8_t *src, ptrdiff_t stride)
wmv2_mspel8_v_lowpass(dst, halfH+8, stride, 8, 8);
}
static void h263_v_loop_filter_c(uint8_t *src, int stride, int qscale){
if(CONFIG_H263_DECODER || CONFIG_H263_ENCODER) {
int x;
const int strength= ff_h263_loop_filter_strength[qscale];
for(x=0; x<8; x++){
int d1, d2, ad1;
int p0= src[x-2*stride];
int p1= src[x-1*stride];
int p2= src[x+0*stride];
int p3= src[x+1*stride];
int d = (p0 - p3 + 4*(p2 - p1)) / 8;
if (d<-2*strength) d1= 0;
else if(d<- strength) d1=-2*strength - d;
else if(d< strength) d1= d;
else if(d< 2*strength) d1= 2*strength - d;
else d1= 0;
p1 += d1;
p2 -= d1;
if(p1&256) p1= ~(p1>>31);
if(p2&256) p2= ~(p2>>31);
src[x-1*stride] = p1;
src[x+0*stride] = p2;
ad1= FFABS(d1)>>1;
d2= av_clip((p0-p3)/4, -ad1, ad1);
src[x-2*stride] = p0 - d2;
src[x+ stride] = p3 + d2;
}
}
}
static void h263_h_loop_filter_c(uint8_t *src, int stride, int qscale){
if(CONFIG_H263_DECODER || CONFIG_H263_ENCODER) {
int y;
const int strength= ff_h263_loop_filter_strength[qscale];
for(y=0; y<8; y++){
int d1, d2, ad1;
int p0= src[y*stride-2];
int p1= src[y*stride-1];
int p2= src[y*stride+0];
int p3= src[y*stride+1];
int d = (p0 - p3 + 4*(p2 - p1)) / 8;
if (d<-2*strength) d1= 0;
else if(d<- strength) d1=-2*strength - d;
else if(d< strength) d1= d;
else if(d< 2*strength) d1= 2*strength - d;
else d1= 0;
p1 += d1;
p2 -= d1;
if(p1&256) p1= ~(p1>>31);
if(p2&256) p2= ~(p2>>31);
src[y*stride-1] = p1;
src[y*stride+0] = p2;
ad1= FFABS(d1)>>1;
d2= av_clip((p0-p3)/4, -ad1, ad1);
src[y*stride-2] = p0 - d2;
src[y*stride+1] = p3 + d2;
}
}
}
static inline int pix_abs16_c(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h)
{
int s, i;
@ -2701,11 +2627,6 @@ av_cold void ff_dsputil_init(DSPContext* c, AVCodecContext *avctx)
c->bswap_buf= bswap_buf;
c->bswap16_buf = bswap16_buf;
if (CONFIG_H263_DECODER || CONFIG_H263_ENCODER) {
c->h263_h_loop_filter= h263_h_loop_filter_c;
c->h263_v_loop_filter= h263_v_loop_filter_c;
}
c->try_8x8basis= try_8x8basis_c;
c->add_8x8basis= add_8x8basis_c;

@ -202,9 +202,6 @@ typedef struct DSPContext {
void (*bswap_buf)(uint32_t *dst, const uint32_t *src, int w);
void (*bswap16_buf)(uint16_t *dst, const uint16_t *src, int len);
void (*h263_v_loop_filter)(uint8_t *src, int stride, int qscale);
void (*h263_h_loop_filter)(uint8_t *src, int stride, int qscale);
/* assume len is a multiple of 8, and arrays are 16-byte aligned */
void (*vector_clipf)(float *dst /* align 16 */, const float *src /* align 16 */, float min, float max, int len /* align 16 */);

@ -152,8 +152,8 @@ void ff_h263_loop_filter(MpegEncContext * s){
*/
if (!IS_SKIP(s->current_picture.mb_type[xy])) {
qp_c= s->qscale;
s->dsp.h263_v_loop_filter(dest_y+8*linesize , linesize, qp_c);
s->dsp.h263_v_loop_filter(dest_y+8*linesize+8, linesize, qp_c);
s->h263dsp.h263_v_loop_filter(dest_y + 8 * linesize, linesize, qp_c);
s->h263dsp.h263_v_loop_filter(dest_y + 8 * linesize + 8, linesize, qp_c);
}else
qp_c= 0;
@ -172,15 +172,15 @@ void ff_h263_loop_filter(MpegEncContext * s){
if(qp_tc){
const int chroma_qp= s->chroma_qscale_table[qp_tc];
s->dsp.h263_v_loop_filter(dest_y , linesize, qp_tc);
s->dsp.h263_v_loop_filter(dest_y+8, linesize, qp_tc);
s->h263dsp.h263_v_loop_filter(dest_y, linesize, qp_tc);
s->h263dsp.h263_v_loop_filter(dest_y + 8, linesize, qp_tc);
s->dsp.h263_v_loop_filter(dest_cb , uvlinesize, chroma_qp);
s->dsp.h263_v_loop_filter(dest_cr , uvlinesize, chroma_qp);
s->h263dsp.h263_v_loop_filter(dest_cb, uvlinesize, chroma_qp);
s->h263dsp.h263_v_loop_filter(dest_cr, uvlinesize, chroma_qp);
}
if(qp_tt)
s->dsp.h263_h_loop_filter(dest_y-8*linesize+8 , linesize, qp_tt);
s->h263dsp.h263_h_loop_filter(dest_y - 8 * linesize + 8, linesize, qp_tt);
if(s->mb_x){
if (qp_tt || IS_SKIP(s->current_picture.mb_type[xy - 1 - s->mb_stride]))
@ -190,17 +190,17 @@ void ff_h263_loop_filter(MpegEncContext * s){
if(qp_dt){
const int chroma_qp= s->chroma_qscale_table[qp_dt];
s->dsp.h263_h_loop_filter(dest_y -8*linesize , linesize, qp_dt);
s->dsp.h263_h_loop_filter(dest_cb-8*uvlinesize, uvlinesize, chroma_qp);
s->dsp.h263_h_loop_filter(dest_cr-8*uvlinesize, uvlinesize, chroma_qp);
s->h263dsp.h263_h_loop_filter(dest_y - 8 * linesize, linesize, qp_dt);
s->h263dsp.h263_h_loop_filter(dest_cb - 8 * uvlinesize, uvlinesize, chroma_qp);
s->h263dsp.h263_h_loop_filter(dest_cr - 8 * uvlinesize, uvlinesize, chroma_qp);
}
}
}
if(qp_c){
s->dsp.h263_h_loop_filter(dest_y +8, linesize, qp_c);
s->h263dsp.h263_h_loop_filter(dest_y + 8, linesize, qp_c);
if(s->mb_y + 1 == s->mb_height)
s->dsp.h263_h_loop_filter(dest_y+8*linesize+8, linesize, qp_c);
s->h263dsp.h263_h_loop_filter(dest_y + 8 * linesize + 8, linesize, qp_c);
}
if(s->mb_x){
@ -211,12 +211,12 @@ void ff_h263_loop_filter(MpegEncContext * s){
qp_lc = s->current_picture.qscale_table[xy - 1];
if(qp_lc){
s->dsp.h263_h_loop_filter(dest_y, linesize, qp_lc);
s->h263dsp.h263_h_loop_filter(dest_y, linesize, qp_lc);
if(s->mb_y + 1 == s->mb_height){
const int chroma_qp= s->chroma_qscale_table[qp_lc];
s->dsp.h263_h_loop_filter(dest_y +8* linesize, linesize, qp_lc);
s->dsp.h263_h_loop_filter(dest_cb , uvlinesize, chroma_qp);
s->dsp.h263_h_loop_filter(dest_cr , uvlinesize, chroma_qp);
s->h263dsp.h263_h_loop_filter(dest_y + 8 * linesize, linesize, qp_lc);
s->h263dsp.h263_h_loop_filter(dest_cb, uvlinesize, chroma_qp);
s->h263dsp.h263_h_loop_filter(dest_cr, uvlinesize, chroma_qp);
}
}
}

@ -272,11 +272,6 @@ uint8_t ff_mba_length[7]={
6, 7, 9, 11, 13, 14, 14
};
const uint8_t ff_h263_loop_filter_strength[32]={
// 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
0, 1, 1, 2, 2, 3, 3, 4, 4, 4, 5, 5, 6, 6, 7, 7, 7, 8, 8, 8, 9, 9, 9,10,10,10,11,11,11,12,12,12
};
const AVRational ff_h263_pixel_aspect[16]={
{0, 1},
{1, 1},

@ -116,6 +116,7 @@ av_cold int ff_h263_decode_init(AVCodecContext *avctx)
if ((ret = ff_MPV_common_init(s)) < 0)
return ret;
ff_h263dsp_init(&s->h263dsp);
ff_h263_decode_init_vlc();
return 0;

@ -0,0 +1,108 @@
/*
* This file is part of Libav.
*
* Libav 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.1 of the License, or (at your option) any later version.
*
* Libav 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 Libav; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <stdint.h>
#include "libavutil/attributes.h"
#include "libavutil/common.h"
#include "config.h"
#include "h263dsp.h"
const uint8_t ff_h263_loop_filter_strength[32]={
// 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
0, 1, 1, 2, 2, 3, 3, 4, 4, 4, 5, 5, 6, 6, 7, 7, 7, 8, 8, 8, 9, 9, 9,10,10,10,11,11,11,12,12,12
};
static void h263_h_loop_filter_c(uint8_t *src, int stride, int qscale){
int y;
const int strength= ff_h263_loop_filter_strength[qscale];
for(y=0; y<8; y++){
int d1, d2, ad1;
int p0= src[y*stride-2];
int p1= src[y*stride-1];
int p2= src[y*stride+0];
int p3= src[y*stride+1];
int d = (p0 - p3 + 4*(p2 - p1)) / 8;
if (d<-2*strength) d1= 0;
else if(d<- strength) d1=-2*strength - d;
else if(d< strength) d1= d;
else if(d< 2*strength) d1= 2*strength - d;
else d1= 0;
p1 += d1;
p2 -= d1;
if(p1&256) p1= ~(p1>>31);
if(p2&256) p2= ~(p2>>31);
src[y*stride-1] = p1;
src[y*stride+0] = p2;
ad1= FFABS(d1)>>1;
d2= av_clip((p0-p3)/4, -ad1, ad1);
src[y*stride-2] = p0 - d2;
src[y*stride+1] = p3 + d2;
}
}
static void h263_v_loop_filter_c(uint8_t *src, int stride, int qscale){
int x;
const int strength= ff_h263_loop_filter_strength[qscale];
for(x=0; x<8; x++){
int d1, d2, ad1;
int p0= src[x-2*stride];
int p1= src[x-1*stride];
int p2= src[x+0*stride];
int p3= src[x+1*stride];
int d = (p0 - p3 + 4*(p2 - p1)) / 8;
if (d<-2*strength) d1= 0;
else if(d<- strength) d1=-2*strength - d;
else if(d< strength) d1= d;
else if(d< 2*strength) d1= 2*strength - d;
else d1= 0;
p1 += d1;
p2 -= d1;
if(p1&256) p1= ~(p1>>31);
if(p2&256) p2= ~(p2>>31);
src[x-1*stride] = p1;
src[x+0*stride] = p2;
ad1= FFABS(d1)>>1;
d2= av_clip((p0-p3)/4, -ad1, ad1);
src[x-2*stride] = p0 - d2;
src[x+ stride] = p3 + d2;
}
}
av_cold void ff_h263dsp_init(H263DSPContext *ctx)
{
ctx->h263_h_loop_filter = h263_h_loop_filter_c;
ctx->h263_v_loop_filter = h263_v_loop_filter_c;
if (ARCH_X86)
ff_h263dsp_init_x86(ctx);
}

@ -0,0 +1,34 @@
/*
* This file is part of Libav.
*
* Libav 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.1 of the License, or (at your option) any later version.
*
* Libav 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 Libav; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef AVCODEC_H263DSP_H
#define AVCODEC_H263DSP_H
#include <stdint.h>
extern const uint8_t ff_h263_loop_filter_strength[32];
typedef struct H263DSPContext {
void (*h263_h_loop_filter)(uint8_t *src, int stride, int qscale);
void (*h263_v_loop_filter)(uint8_t *src, int stride, int qscale);
} H263DSPContext;
void ff_h263dsp_init(H263DSPContext *ctx);
void ff_h263dsp_init_x86(H263DSPContext *ctx);
#endif /* AVCODEC_H263DSP_H */

@ -32,6 +32,7 @@
#include "dsputil.h"
#include "error_resilience.h"
#include "get_bits.h"
#include "h263dsp.h"
#include "hpeldsp.h"
#include "put_bits.h"
#include "ratecontrol.h"
@ -384,6 +385,7 @@ typedef struct MpegEncContext {
DSPContext dsp; ///< pointers for accelerated dsp functions
HpelDSPContext hdsp;
VideoDSPContext vdsp;
H263DSPContext h263dsp;
int f_code; ///< forward MV resolution
int b_code; ///< backward MV resolution for B Frames (mpeg4)
int16_t (*p_mv_table_base)[2];
@ -896,7 +898,6 @@ void ff_mpeg1_encode_slice_header(MpegEncContext *s);
extern const uint8_t ff_aic_dc_scale_table[32];
extern const uint8_t ff_h263_chroma_qscale_table[32];
extern const uint8_t ff_h263_loop_filter_strength[32];
/* rv10.c */
void ff_rv10_encode_picture_header(MpegEncContext *s, int picture_number);

@ -707,6 +707,7 @@ av_cold int ff_MPV_encode_init(AVCodecContext *avctx)
if (ARCH_X86)
ff_MPV_encode_init_x86(s);
ff_h263dsp_init(&s->h263dsp);
if (!s->dct_quantize)
s->dct_quantize = ff_dct_quantize_c;
if (!s->denoise_dct)

@ -484,6 +484,7 @@ static av_cold int rv10_decode_init(AVCodecContext *avctx)
if ((ret = ff_MPV_common_init(s)) < 0)
return ret;
ff_h263dsp_init(&s->h263dsp);
ff_h263_decode_init_vlc();
/* init rv vlc */

@ -12,6 +12,7 @@ OBJS-$(CONFIG_ENCODERS) += x86/dsputilenc_mmx.o \
x86/fdct.o \
x86/motion_est.o
OBJS-$(CONFIG_FFT) += x86/fft_init.o
OBJS-$(CONFIG_H263DSP) += x86/h263dsp_init.o
OBJS-$(CONFIG_H264CHROMA) += x86/h264chroma_init.o
OBJS-$(CONFIG_H264DSP) += x86/h264dsp_init.o
OBJS-$(CONFIG_H264PRED) += x86/h264_intrapred_init.o
@ -59,8 +60,7 @@ YASM-OBJS-$(CONFIG_DSPUTIL) += x86/dsputil.o \
x86/qpel.o
YASM-OBJS-$(CONFIG_ENCODERS) += x86/dsputilenc.o
YASM-OBJS-$(CONFIG_FFT) += x86/fft.o
YASM-OBJS-$(CONFIG_H263_DECODER) += x86/h263_loopfilter.o
YASM-OBJS-$(CONFIG_H263_ENCODER) += x86/h263_loopfilter.o
YASM-OBJS-$(CONFIG_H263DSP) += x86/h263_loopfilter.o
YASM-OBJS-$(CONFIG_H264CHROMA) += x86/h264_chromamc.o \
x86/h264_chromamc_10bit.o
YASM-OBJS-$(CONFIG_H264DSP) += x86/h264_deblock.o \

@ -68,9 +68,6 @@ void ff_put_no_rnd_mpeg4_qpel8_v_lowpass_mmxext(uint8_t *dst, uint8_t *src,
#define ff_put_no_rnd_pixels16_mmxext ff_put_pixels16_mmxext
#define ff_put_no_rnd_pixels8_mmxext ff_put_pixels8_mmxext
void ff_h263_v_loop_filter_mmx(uint8_t *src, int stride, int qscale);
void ff_h263_h_loop_filter_mmx(uint8_t *src, int stride, int qscale);
int32_t ff_scalarproduct_int16_mmxext(const int16_t *v1, const int16_t *v2,
int order);
int32_t ff_scalarproduct_int16_sse2(const int16_t *v1, const int16_t *v2,
@ -566,11 +563,6 @@ static av_cold void dsputil_init_mmx(DSPContext *c, AVCodecContext *avctx,
#endif /* HAVE_MMX_INLINE */
#if HAVE_MMX_EXTERNAL
if (CONFIG_H263_DECODER || CONFIG_H263_ENCODER) {
c->h263_v_loop_filter = ff_h263_v_loop_filter_mmx;
c->h263_h_loop_filter = ff_h263_h_loop_filter_mmx;
}
c->vector_clip_int32 = ff_vector_clip_int32_mmx;
#endif /* HAVE_MMX_EXTERNAL */
}

@ -0,0 +1,39 @@
/*
* Copyright (c) 2013 Diego Biurrun <diego@biurrun.de>
*
* This file is part of Libav.
*
* Libav 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.1 of the License, or (at your option) any later version.
*
* Libav 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 Libav; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <stdint.h>
#include "libavutil/attributes.h"
#include "libavutil/cpu.h"
#include "libavutil/x86/cpu.h"
#include "libavcodec/h263dsp.h"
void ff_h263_h_loop_filter_mmx(uint8_t *src, int stride, int qscale);
void ff_h263_v_loop_filter_mmx(uint8_t *src, int stride, int qscale);
av_cold void ff_h263dsp_init_x86(H263DSPContext *c)
{
int cpu_flags = av_get_cpu_flags();
if (EXTERNAL_MMX(cpu_flags)) {
c->h263_h_loop_filter = ff_h263_h_loop_filter_mmx;
c->h263_v_loop_filter = ff_h263_v_loop_filter_mmx;
}
}
Loading…
Cancel
Save