00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
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;
00059 void *ring_lum[RING_SIZE];
00060 void *ring_Cr[RING_SIZE];
00061 void *ring_Cb[RING_SIZE];
00062 int ring_temporal_reference[RING_SIZE];
00063 int ring_quality[RING_SIZE];
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
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;
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
00117
00118
00119
00120
00121
00122
00123
00124
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