Main Page | File List

ring_buf.c

00001 /************************************************************************
00002  *
00003  *  ring_buf.c, Buffer functions used for Reference Picture Section Mode.
00004  *
00005  *  Copyright (C) 1997  University of BC, Canada
00006  *
00007  *  Contacts: 
00008  *  Guy Cote                          <guyc@ee.ubc.ca>
00009  *  Michael Gallant                   <mikeg@ee.ubc.ca>
00010  *  Berna Erol                        <bernae@ee.ubc.ca>
00011  *
00012  *  UBC Image Processing Laboratory   http://www.ee.ubc.ca/image
00013  *  2356 Main Mall                    tel.: +1 604 822 4051
00014  *  Vancouver BC Canada V6T1Z4        fax.: +1 604 822 5949
00015  *
00016  ************************************************************************/
00017 
00018 /*
00019  * Disclaimer of Warranty
00020  *
00021  * These software programs are available to the user without any
00022  * license fee or royalty on an "as is" basis. The University of
00023  * British Columbia disclaims any and all warranties, whether
00024  * express, implied, or statuary, including any implied warranties
00025  * or merchantability or of fitness for a particular purpose.  In no
00026  * event shall the copyright-holder be liable for any incidental,
00027  * punitive, or consequential damages of any kind whatsoever arising
00028  * from the use of these programs.
00029  *
00030  * This disclaimer of warranty extends to the user of these programs
00031  * and user's customers, employees, agents, transferees, successors,
00032  * and assigns.
00033  *
00034  * The University of British Columbia does not represent or warrant
00035  * that the programs furnished hereunder are free of infringement of
00036  * any third-party patents.
00037  *
00038  * Commercial implementations of H.263, including shareware, are
00039  * subject to royalty fees to patent holders.  Many of these patents
00040  * are general enough such that they are unavoidable regardless of
00041  * implementation design.
00042  *
00043 */
00044 
00045 #include <stdlib.h>
00046 #include <string.h>
00047 #include "config.h"
00048 #include "tmndec.h"
00049 #include "global.h"
00050 
00051 #define RING_SIZE 8
00052 
00053 int  get_reference_picture(void);
00054 void store_picture(int quality);
00055 int get_reference_gob(void);
00056 void store_gob(int quality);
00057 
00058 int   ring_pointer;                           /* pointer to last picture        */
00059 void  *ring_lum[RING_SIZE];                   /* Ring buffer                    */
00060 void  *ring_Cr[RING_SIZE];
00061 void  *ring_Cb[RING_SIZE];
00062 int   ring_temporal_reference[RING_SIZE];     /* TR values for the pictures     */
00063 int   ring_quality[RING_SIZE];                /* Picture Quality                */  
00064 
00065 
00066 /**********************************************************************
00067  *
00068  *      Name:         get_reference_picture
00069  *      Description:  gets the requested prediction picture from
00070  *                the ring buffer.
00071  *      
00072  *      Input:        tr, orig, recon
00073  *        
00074  *      Returns:      0
00075  *      Side effects: 
00076  *
00077  *      Date: 980610  Author: Guy Cote <guyc@ece.ubc.ca>
00078  *
00079  ***********************************************************************/
00080 int get_reference_picture(void)
00081 {
00082   int i,diff_tr;
00083   
00084   if (!TRPI) 
00085   {
00086     return 0;
00087   }
00088   for (i = ring_pointer; i != (ring_pointer+1)%RING_SIZE;
00089          i = (i+RING_SIZE-1)%RING_SIZE) 
00090    {
00091      diff_tr =  temporal_reference_for_prediction - ring_temporal_reference[i];
00092      if (diff_tr > 128)  diff_tr -= 256;
00093      if (diff_tr < -128) diff_tr += 256;
00094      if (diff_tr >= 0)  break;
00095    }
00096    if (ring_temporal_reference[ring_pointer] == temp_ref &&
00097      ring_quality[i]+diff_tr >= ring_quality[ring_pointer]) 
00098    {
00099      return -1; /* don't decode this sync frame (redundant) */
00100    }
00101    if (ring_lum[i]) 
00102    {
00103      memcpy(prev_I_P_frame[0],ring_lum[i], coded_picture_height*coded_picture_width);
00104      memcpy(prev_I_P_frame[1],ring_Cr[i], coded_picture_height*coded_picture_width/4);
00105      memcpy(prev_I_P_frame[2],ring_Cb[i], coded_picture_height*coded_picture_width/4);
00106    }
00107    if (diff_tr && !quiet)
00108      fprintf(stderr,"getrefpic: TR=%d, TRP=%d, available %d, q=%d+%d\n",
00109      temp_ref,temporal_reference_for_prediction,
00110      ring_temporal_reference[i],ring_quality[i],diff_tr);
00111    return ring_quality[i]+diff_tr;
00112    
00113 }
00114 /**********************************************************************
00115  *
00116  *      Name:         store_picture
00117  *      Description:  Stores a picture into the ring buffer.                  
00118  *      
00119  *      Input:        tr, orig, recon
00120  *        
00121  *      Returns:      0
00122  *      Side effects: 
00123  *
00124  *      Date: 980610  Author: Guy Cote <guyc@ece.ubc.ca>
00125  *
00126  ***********************************************************************/
00127 
00128 void store_picture(int quality)
00129 {
00130   ring_pointer = (ring_pointer+1)%RING_SIZE;
00131   if (!ring_lum[ring_pointer]) {
00132     ring_lum[ring_pointer] = malloc(coded_picture_height*coded_picture_width);
00133     ring_Cr[ring_pointer]  = malloc(coded_picture_height*coded_picture_width/4);
00134     ring_Cb[ring_pointer]  = malloc(coded_picture_height*coded_picture_width/4);
00135   }
00136   memcpy(ring_lum[ring_pointer],current_frame[0], coded_picture_height*coded_picture_width);
00137   memcpy(ring_Cr[ring_pointer],current_frame[1], coded_picture_height*coded_picture_width/4);
00138   memcpy(ring_Cb[ring_pointer],current_frame[2], coded_picture_height*coded_picture_width/4);
00139   ring_temporal_reference[ring_pointer] = temp_ref;
00140   ring_quality[ring_pointer] = quality;
00141 }
00142 
00143 
00144 
00145 
00146 

Generated on Mon May 8 22:27:08 2006 by  doxygen 1.3.9.1