• Main Page
  • Related Pages
  • Modules
  • Data Structures
  • Files
  • File List
  • Globals

libavcodec/bfin/mpegvideo_bfin.c

Go to the documentation of this file.
00001 /*
00002  * BlackFin MPEGVIDEO OPTIMIZATIONS
00003  *
00004  * Copyright (C) 2007 Marc Hoffman <mmh@pleasantst.com>
00005  *
00006  * This file is part of FFmpeg.
00007  *
00008  * FFmpeg is free software; you can redistribute it and/or
00009  * modify it under the terms of the GNU Lesser General Public
00010  * License as published by the Free Software Foundation; either
00011  * version 2.1 of the License, or (at your option) any later version.
00012  *
00013  * FFmpeg is distributed in the hope that it will be useful,
00014  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00016  * Lesser General Public License for more details.
00017  *
00018  * You should have received a copy of the GNU Lesser General Public
00019  * License along with FFmpeg; if not, write to the Free Software
00020  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
00021  */
00022 
00023 #include "libavcodec/avcodec.h"
00024 #include "libavcodec/dsputil.h"
00025 #include "libavcodec/mpegvideo.h"
00026 #include "dsputil_bfin.h"
00027 
00028 
00029 void ff_bfin_fdct (DCTELEM *block) attribute_l1_text;
00030 
00031 
00032 static int dct_quantize_bfin (MpegEncContext *s,
00033                               DCTELEM *block, int n,
00034                               int qscale, int *overflow)
00035 {
00036     int last_non_zero, q, start_i;
00037     const short *qmat;
00038     short *bias;
00039     const uint8_t *scantable= s->intra_scantable.scantable;
00040     short dc;
00041     int   max=0;
00042 
00043     PROF("fdct",0);
00044     ff_bfin_fdct (block);
00045     EPROF();
00046 
00047     PROF("denoise",1);
00048     if(s->dct_error_sum)
00049         s->denoise_dct(s, block);
00050     EPROF();
00051 
00052     PROF("quant-init",2);
00053     if (s->mb_intra) {
00054         if (!s->h263_aic) {
00055             if (n < 4)
00056                 q = s->y_dc_scale;
00057             else
00058                 q = s->c_dc_scale;
00059             q = q << 3;
00060         } else
00061             /* For AIC we skip quant/dequant of INTRADC */
00062             q = 1 << 3;
00063 
00064         /* note: block[0] is assumed to be positive */
00065         dc = block[0] = (block[0] + (q >> 1)) / q;
00066         start_i = 1;
00067         last_non_zero = 0;
00068         bias = s->q_intra_matrix16[qscale][1];
00069         qmat = s->q_intra_matrix16[qscale][0];
00070 
00071     } else {
00072         start_i = 0;
00073         last_non_zero = -1;
00074         bias = s->q_inter_matrix16[qscale][1];
00075         qmat = s->q_inter_matrix16[qscale][0];
00076 
00077     }
00078     EPROF();
00079 
00080     PROF("quantize",4);
00081 
00082     /*  for(i=start_i; i<64; i++) {                           */
00083     /*      sign     = (block[i]>>15)|1;                      */
00084     /*      level    = ((abs(block[i])+bias[0])*qmat[i])>>16; */
00085     /*      if (level < 0) level = 0;                         */
00086     /*      max     |= level;                                 */
00087     /*      level    = level * sign;                          */
00088     /*      block[i] = level;                                 */
00089     /*  } */
00090 
00091     __asm__ volatile
00092         ("i2=%1;\n\t"
00093          "r1=[%1++];                                                         \n\t"
00094          "r0=r1>>>15 (v);                                                    \n\t"
00095          "lsetup (0f,1f) lc0=%3;                                             \n\t"
00096          "0:   r0=r0|%4;                                                     \n\t"
00097          "     r1=abs r1 (v)                                    || r2=[%2++];\n\t"
00098          "     r1=r1+|+%5;                                                   \n\t"
00099          "     r1=max(r1,%6) (v);                                            \n\t"
00100          "     r1.h=(a1 =r1.h*r2.h), r1.l=(a0 =r1.l*r2.l) (tfu);             \n\t"
00101          "     %0=%0|r1;                                                     \n\t"
00102          "     r0.h=(a1 =r1.h*r0.h), r0.l=(a0 =r1.l*r0.l) (is)  || r1=[%1++];\n\t"
00103          "1:   r0=r1>>>15 (v)                                   || [i2++]=r0;\n\t"
00104          "r1=%0>>16;                                                         \n\t"
00105          "%0=%0|r1;                                                          \n\t"
00106          "%0.h=0;                                                            \n\t"
00107          : "=&d" (max)
00108          : "b" (block), "b" (qmat), "a" (32), "d" (0x00010001), "d" (bias[0]*0x10001), "d" (0)
00109          : "R0","R1","R2", "I2");
00110     if (start_i == 1) block[0] = dc;
00111 
00112     EPROF();
00113 
00114 
00115     PROF("zzscan",5);
00116 
00117     __asm__ volatile
00118         ("r0=b[%1--] (x);         \n\t"
00119          "lsetup (0f,1f) lc0=%3;  \n\t"     /*    for(i=63; i>=start_i; i--) { */
00120          "0: p0=r0;               \n\t"     /*        j = scantable[i];        */
00121          "   p0=%2+(p0<<1);       \n\t"     /*        if (block[j]) {          */
00122          "   r0=w[p0];            \n\t"     /*           last_non_zero = i;    */
00123          "   cc=r0==0;            \n\t"     /*           break;                */
00124          "   if !cc jump 2f;      \n\t"     /*        }                        */
00125          "1: r0=b[%1--] (x);      \n\t"     /*    }                            */
00126          "   %0=%4;               \n\t"
00127          "   jump 3f;             \n\t"
00128          "2: %0=lc0;              \n\t"
00129          "3:\n\t"
00130 
00131          : "=d" (last_non_zero)
00132          : "a" (scantable+63), "a" (block), "a" (63), "d" (last_non_zero)
00133          : "P0","R0");
00134 
00135     EPROF();
00136 
00137     *overflow= s->max_qcoeff < max; //overflow might have happened
00138 
00139     bfprof();
00140 
00141     /* we need this permutation so that we correct the IDCT, we only permute the !=0 elements */
00142     if (s->dsp.idct_permutation_type != FF_NO_IDCT_PERM)
00143         ff_block_permute(block, s->dsp.idct_permutation, scantable, last_non_zero);
00144 
00145     return last_non_zero;
00146 }
00147 
00148 void MPV_common_init_bfin (MpegEncContext *s)
00149 {
00150     s->dct_quantize= dct_quantize_bfin;
00151 }
00152 

Generated on Tue Nov 4 2014 12:59:21 for ffmpeg by  doxygen 1.7.1