FFmpeg  2.1.1
mpegvideo_bfin.c
Go to the documentation of this file.
1 /*
2  * BlackFin MPEGVIDEO OPTIMIZATIONS
3  *
4  * Copyright (C) 2007 Marc Hoffman <mmh@pleasantst.com>
5  *
6  * This file is part of FFmpeg.
7  *
8  * FFmpeg is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2.1 of the License, or (at your option) any later version.
12  *
13  * FFmpeg is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with FFmpeg; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21  */
22 
23 #include "libavutil/attributes.h"
24 #include "libavcodec/avcodec.h"
25 #include "libavcodec/mpegvideo.h"
26 #include "dsputil_bfin.h"
27 
29  int16_t *block, int n,
30  int qscale, int *overflow)
31 {
32  int last_non_zero, q, start_i;
33  const short *qmat;
34  short *bias;
35  const uint8_t *scantable= s->intra_scantable.scantable;
36  short dc;
37  int max=0;
38 
39  PROF("fdct",0);
40  s->dsp.fdct(block);
41  EPROF();
42 
43  PROF("denoise",1);
44  if(s->dct_error_sum)
45  s->denoise_dct(s, block);
46  EPROF();
47 
48  PROF("quant-init",2);
49  if (s->mb_intra) {
50  if (!s->h263_aic) {
51  if (n < 4)
52  q = s->y_dc_scale;
53  else
54  q = s->c_dc_scale;
55  q = q << 3;
56  } else
57  /* For AIC we skip quant/dequant of INTRADC */
58  q = 1 << 3;
59 
60  /* note: block[0] is assumed to be positive */
61  dc = block[0] = (block[0] + (q >> 1)) / q;
62  start_i = 1;
63  last_non_zero = 0;
64  if(n<4){
65  bias = s->q_intra_matrix16[qscale][1];
66  qmat = s->q_intra_matrix16[qscale][0];
67  }else{
68  bias = s->q_chroma_intra_matrix16[qscale][1];
69  qmat = s->q_chroma_intra_matrix16[qscale][0];
70  }
71 
72  } else {
73  start_i = 0;
74  last_non_zero = -1;
75  bias = s->q_inter_matrix16[qscale][1];
76  qmat = s->q_inter_matrix16[qscale][0];
77 
78  }
79  EPROF();
80 
81  PROF("quantize",4);
82 
83  /* for(i=start_i; i<64; i++) { */
84  /* sign = (block[i]>>15)|1; */
85  /* level = ((abs(block[i])+bias[0])*qmat[i])>>16; */
86  /* if (level < 0) level = 0; */
87  /* max |= level; */
88  /* level = level * sign; */
89  /* block[i] = level; */
90  /* } */
91 
92  __asm__ volatile
93  ("i2=%1;\n\t"
94  "r1=[%1++]; \n\t"
95  "r0=r1>>>15 (v); \n\t"
96  "lsetup (0f,1f) lc0=%3; \n\t"
97  "0: r0=r0|%4; \n\t"
98  " r1=abs r1 (v) || r2=[%2++];\n\t"
99  " r1=r1+|+%5; \n\t"
100  " r1=max(r1,%6) (v); \n\t"
101  " r1.h=(a1 =r1.h*r2.h), r1.l=(a0 =r1.l*r2.l) (tfu); \n\t"
102  " %0=%0|r1; \n\t"
103  " r0.h=(a1 =r1.h*r0.h), r0.l=(a0 =r1.l*r0.l) (is) || r1=[%1++];\n\t"
104  "1: r0=r1>>>15 (v) || [i2++]=r0;\n\t"
105  "r1=%0>>16; \n\t"
106  "%0=%0|r1; \n\t"
107  "%0.h=0; \n\t"
108  : "=&d" (max)
109  : "b" (block), "b" (qmat), "a" (32), "d" (0x00010001), "d" (bias[0]*0x10001), "d" (0)
110  : "R0","R1","R2", "I2");
111  if (start_i == 1) block[0] = dc;
112 
113  EPROF();
114 
115 
116  PROF("zzscan",5);
117 
118  __asm__ volatile
119  ("r0=b[%1--] (x); \n\t"
120  "lsetup (0f,1f) lc0=%3; \n\t" /* for(i=63; i>=start_i; i--) { */
121  "0: p0=r0; \n\t" /* j = scantable[i]; */
122  " p0=%2+(p0<<1); \n\t" /* if (block[j]) { */
123  " r0=w[p0]; \n\t" /* last_non_zero = i; */
124  " cc=r0==0; \n\t" /* break; */
125  " if !cc jump 2f; \n\t" /* } */
126  "1: r0=b[%1--] (x); \n\t" /* } */
127  " %0=%4; \n\t"
128  " jump 3f; \n\t"
129  "2: %0=lc0; \n\t"
130  "3:\n\t"
131 
132  : "=d" (last_non_zero)
133  : "a" (scantable+63), "a" (block), "a" (63), "d" (last_non_zero)
134  : "P0","R0");
135 
136  EPROF();
137 
138  *overflow= s->max_qcoeff < max; //overflow might have happened
139 
140  bfprof();
141 
142  /* we need this permutation so that we correct the IDCT, we only permute the !=0 elements */
144  ff_block_permute(block, s->dsp.idct_permutation, scantable, last_non_zero);
145 
146  return last_non_zero;
147 }
148 
150 {
151 /* s->dct_quantize= dct_quantize_bfin; */
152 }
const char * s
Definition: avisynth_c.h:668
uint16_t(* q_chroma_intra_matrix16)[2][64]
Definition: mpegvideo.h:501
void ff_block_permute(int16_t *block, uint8_t *permutation, const uint8_t *scantable, int last)
Permute an 8x8 block.
Definition: mpegvideo.c:3058
mpegvideo header.
#define av_cold
Definition: avcodec.h:653
int h263_aic
Advanded INTRA Coding (AIC)
Definition: mpegvideo.h:296
#define EPROF()
Definition: dsputil_bfin.h:91
uint8_t
void(* denoise_dct)(struct MpegEncContext *s, int16_t *block)
Definition: mpegvideo.h:735
uint8_t idct_permutation[64]
idct input permutation.
Definition: dsputil.h:246
const uint8_t * scantable
Definition: dsputil.h:112
int max_qcoeff
maximum encodable coefficient
Definition: mpegvideo.h:484
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(constint16_t *) pi >>8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(constint32_t *) pi >>24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(constfloat *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(constfloat *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(constfloat *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(constdouble *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(constdouble *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(constdouble *) pi *(1U<< 31))))#defineSET_CONV_FUNC_GROUP(ofmt, ifmt) staticvoidset_generic_function(AudioConvert *ac){}voidff_audio_convert_free(AudioConvert **ac){return;ff_dither_free(&(*ac) ->dc);av_freep(ac);}AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enumAVSampleFormatout_fmt, enumAVSampleFormatin_fmt, intchannels, intsample_rate, intapply_map){AudioConvert *ac;intin_planar, out_planar;ac=av_mallocz(sizeof(*ac));returnNULL;ac->avr=avr;ac->out_fmt=out_fmt;ac->in_fmt=in_fmt;ac->channels=channels;ac->apply_map=apply_map;if(avr->dither_method!=AV_RESAMPLE_DITHER_NONE &&av_get_packed_sample_fmt(out_fmt)==AV_SAMPLE_FMT_S16 &&av_get_bytes_per_sample(in_fmt)>2){ac->dc=ff_dither_alloc(avr, out_fmt, in_fmt, channels, sample_rate, apply_map);if(!ac->dc){av_free(ac);returnNULL;}returnac;}in_planar=av_sample_fmt_is_planar(in_fmt);out_planar=av_sample_fmt_is_planar(out_fmt);if(in_planar==out_planar){ac->func_type=CONV_FUNC_TYPE_FLAT;ac->planes=in_planar?ac->channels:1;}elseif(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;elseac->func_type=CONV_FUNC_TYPE_DEINTERLEAVE;set_generic_function(ac);ff_audio_convert_init_arm(ac);ff_audio_convert_init_x86(ac);returnac;}intff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in){intuse_generic=1;intlen=in->nb_samples;intp;if(ac->dc){av_dlog(ac->avr,"%dsamples-audio_convert:%sto%s(dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));returnff_convert_dither(ac-> dc
uint16_t(* q_inter_matrix16)[2][64]
Definition: mpegvideo.h:502
#define bfprof()
Definition: dsputil_bfin.h:92
#define PROF(a, b)
Definition: dsputil_bfin.h:90
uint16_t(* q_intra_matrix16)[2][64]
identical to the above but for MMX &amp; these are not permutated, second 64 entries are bias ...
Definition: mpegvideo.h:500
#define FF_NO_IDCT_PERM
Definition: dsputil.h:248
int n
Definition: avisynth_c.h:588
int idct_permutation_type
Definition: dsputil.h:247
ScanTable intra_scantable
Definition: mpegvideo.h:300
DSPContext dsp
pointers for accelerated dsp functions
Definition: mpegvideo.h:395
static int dct_quantize_bfin(MpegEncContext *s, int16_t *block, int n, int qscale, int *overflow)
MpegEncContext.
Definition: mpegvideo.h:245
av_cold void ff_MPV_common_init_bfin(MpegEncContext *s)
int(* dct_error_sum)[64]
Definition: mpegvideo.h:505
void(* fdct)(int16_t *block)
Definition: dsputil.h:215
static int16_t block[64]
Definition: dct-test.c:198