Main Page | Class List | File List | Class Members | File Members

vid_main.c File Reference

#include "vid_sim.h"
#include "video_codec.h"

Go to the source code of this file.

Functions

int NextTwoPB (PictImage *next2, PictImage *next1, PictImage *prev, int bskip, int pskip, int seek_dist)
void PrintResult (Bits *bits, int num_units, int num)
void PrintSNR (Results *res, int num)

Variables

video_codecVidSt
FILE * streamfile


Function Documentation

int NextTwoPB PictImage next2,
PictImage next1,
PictImage prev,
int  bskip,
int  pskip,
int  seek_dist
 

Definition at line 75 of file vid_main.c.

References video_codec::advanced, video_codec::lines, video_codec::long_vectors, pict_image::lum, MB_SIZE, MBC, MBR, motionvector::min_error, MotionEstimation(), MotionVector, video_codec::mv_outside_frame, video_codec::pels, PictImage, SAD_MB_Bidir(), VidSt, motionvector::x, and motionvector::y.

Referenced by code_video().

00077 {
00078   int adv_is_on = 0, mof_is_on = 0, lv_is_on = 0;
00079   int psad1, psad2, bsad, psad;
00080   MotionVector *MV[6][MBR+1][MBC+2];
00081   MotionVector *mvp, *mvbf, *mvbb;
00082   int x,y;
00083   int i,j,k,tmp;
00084 
00085   /* Temporarily disable some options to simplify motion estimation */
00086   if ((VidSt->advanced)) {
00087     (VidSt->advanced) = OFF;
00088     adv_is_on = ON;
00089   }
00090   if ((VidSt->mv_outside_frame)) {
00091     (VidSt->mv_outside_frame) = OFF;
00092     mof_is_on = ON;
00093   }
00094   if ((VidSt->long_vectors)) {
00095     (VidSt->long_vectors) = OFF;
00096     lv_is_on = ON;
00097   }
00098 
00099   for (j = 1; j <= ((VidSt->lines)>>4); j++) 
00100     for (i = 1; i <= ((VidSt->pels)>>4); i++) 
00101       for (k = 0; k < 3; k++) {
00102         MV[k][j][i] = (MotionVector *)calloc(1,sizeof(MotionVector));
00103         /* calloc to avoid Checker warnings about reading of
00104            unitizalized memory in the memcpy's below */
00105       }
00106 
00107   mvbf = (MotionVector *)malloc(sizeof(MotionVector));
00108   mvbb = (MotionVector *)malloc(sizeof(MotionVector));
00109 
00110   psad = 0;
00111   psad1 = 0;
00112   psad2 = 0;
00113   bsad = 0;
00114 
00115   /* Integer motion estimation */
00116   for ( j = 1; j < (VidSt->lines)/MB_SIZE - 1; j++) {
00117     for ( i = 1; i < (VidSt->pels)/MB_SIZE - 1 ; i++) {
00118       x = i*MB_SIZE;
00119       y = j*MB_SIZE;
00120 
00121       /* picture order: prev -> next1 -> next2 */
00122       /* next1 and next2 can be coded as PB or PP */
00123       /* prev is the previous encoded picture */
00124 
00125       /* computes vectors (prev <- next2) */
00126       MotionEstimation(next2->lum,prev->lum,x,y,0,0,seek_dist,MV,&tmp);
00127       if (MV[0][j+1][i+1]->x == 0 && MV[0][j+1][i+1]->y == 0)
00128         MV[0][j+1][i+1]->min_error += PREF_NULL_VEC;
00129       /* not necessary to prefer zero vector here */
00130       memcpy(MV[2][j+1][i+1],MV[0][j+1][i+1],sizeof(MotionVector));
00131 
00132       /* computes sad(prev <- next1) */
00133       MotionEstimation(next1->lum,prev->lum,x,y,0,0,seek_dist,MV,&tmp);
00134       if (MV[0][j+1][i+1]->x == 0 && MV[0][j+1][i+1]->y == 0)
00135         MV[0][j+1][i+1]->min_error += PREF_NULL_VEC;
00136       memcpy(MV[1][j+1][i+1],MV[0][j+1][i+1],sizeof(MotionVector));
00137 
00138       /* computes vectors for (next1 <- next2) */
00139       MotionEstimation(next2->lum,next1->lum,x,y,0,0,seek_dist,MV,&tmp);
00140       if (MV[0][j+1][i+1]->x == 0 && MV[0][j+1][i+1]->y == 0)
00141         MV[0][j+1][i+1]->min_error += PREF_NULL_VEC;
00142 
00143       /* scales vectors for (prev <- next2 ) */
00144       mvp = MV[2][j+1][i+1];
00145       mvbf->x =   bskip * mvp->x / (bskip + pskip);
00146       mvbb->x = - pskip * mvp->x / (bskip + pskip);
00147       mvbf->y =   bskip * mvp->y / (bskip + pskip);
00148       mvbb->y = - pskip * mvp->y / (bskip + pskip);
00149 
00150       psad1 += MV[0][j+1][i+1]->min_error;
00151       psad2 += MV[1][j+1][i+1]->min_error;
00152       psad +=  mvp->min_error;
00153 
00154       /* computes sad(prev <- next1 -> next2) */
00155       bsad += SAD_MB_Bidir(next1->lum + x + y*(VidSt->pels),
00156            next2->lum + x + mvbb->x + (y + mvbb->y)*(VidSt->pels),
00157            prev->lum + x + mvbf->x + (y + mvbf->y)*(VidSt->pels),
00158            (VidSt->pels), INT_MAX);
00159     }
00160   }
00161 
00162   for (j = 1; j <= ((VidSt->lines)>>4); j++) 
00163     for (i = 1; i <= ((VidSt->pels)>>4); i++) 
00164       for (k = 0; k < 3; k++) 
00165         free(MV[k][j][i]);
00166   free(mvbf);
00167   free(mvbb);
00168 
00169   /* restore advanced parameters */
00170   (VidSt->advanced) = adv_is_on;
00171   (VidSt->mv_outside_frame) = mof_is_on;
00172   (VidSt->long_vectors) = lv_is_on;
00173 
00174   /* do the decision */
00175   if (bsad < (psad1+psad2)/2)
00176     fprintf(stdout,"Chose PB - bsad %d, psad %d\n", 
00177             bsad, (psad1+psad2)/2);
00178   else
00179     fprintf(stdout,"Chose PP  - bsad %d, psad %d\n", 
00180             bsad, (psad1+psad2)/2);
00181 
00182   if (bsad < (psad1 + psad2)/2)
00183     return 1;
00184   else 
00185     return 0;
00186 }

void PrintResult Bits bits,
int  num_units,
int  num
 

Definition at line 204 of file vid_main.c.

References Bits, bits_counted::C, bits_counted::CBPB, bits_counted::CBPCM, bits_counted::CBPY, bits_counted::COD, bits_counted::DQUANT, bits_counted::header, bits_counted::MODB, bits_counted::no_inter, bits_counted::no_inter4v, bits_counted::no_intra, bits_counted::total, bits_counted::vec, and bits_counted::Y.

Referenced by close_video_codec(), and code_video().

00205 {
00206   fprintf(stdout,"# intra   : %d\n", bits->no_intra/num_units);
00207   fprintf(stdout,"# inter   : %d\n", bits->no_inter/num_units);
00208   fprintf(stdout,"# inter4v : %d\n", bits->no_inter4v/num_units);
00209   fprintf(stdout,"--------------\n");
00210   fprintf(stdout,"Coeff_Y: %d\n", bits->Y/num);
00211   fprintf(stdout,"Coeff_C: %d\n", bits->C/num);
00212   fprintf(stdout,"Vectors: %d\n", bits->vec/num);
00213   fprintf(stdout,"CBPY   : %d\n", bits->CBPY/num);
00214   fprintf(stdout,"MCBPC  : %d\n", bits->CBPCM/num);
00215   fprintf(stdout,"MODB   : %d\n", bits->MODB/num);
00216   fprintf(stdout,"CBPB   : %d\n", bits->CBPB/num);
00217   fprintf(stdout,"COD    : %d\n", bits->COD/num);
00218   fprintf(stdout,"DQUANT : %d\n", bits->DQUANT/num);
00219   fprintf(stdout,"header : %d\n", bits->header/num);
00220   fprintf(stdout,"==============\n");
00221   fprintf(stdout,"Total  : %d\n", bits->total/num);
00222   fprintf(stdout,"\n");
00223   return;
00224 }

void PrintSNR Results res,
int  num
 

Definition at line 226 of file vid_main.c.

References Results, results::SNR_Cb, results::SNR_Cr, and results::SNR_l.

Referenced by close_video_codec(), and code_video().

00227 {
00228   FILE *fp = fopen("snr.dat","a");
00229   assert(fp!=NULL);
00230   fprintf(fp,"%.2f %.2f %.2f\n",res->SNR_l/num,res->SNR_Cb/num,res->SNR_Cr/num);
00231   fclose(fp);
00232   fprintf(stdout,"SNR_Y  : %.2f\n", res->SNR_l/num);
00233   fprintf(stdout,"SNR_Cb : %.2f\n", res->SNR_Cb/num);
00234   fprintf(stdout,"SNR_Cr : %.2f\n", res->SNR_Cr/num);
00235   fprintf(stdout,"--------------\n");
00236 
00237   return;
00238 }


Variable Documentation

FILE* streamfile
 

Definition at line 52 of file vid_main.c.

video_codec* VidSt
 

Definition at line 16 of file vid_wrapper.c.


Generated on Sun Jul 16 16:27:47 2006 by  doxygen 1.3.9.1