1 #include "../libzmpeg3.h"
13 for( int i=0; i<allocation; ++i ) {
14 cacheframe_t *frame = &frames[i];
15 if( frame->y ) delete [] frame->y;
16 if( frame->u ) delete [] frame->u;
17 if( frame->v ) delete [] frame->v;
30 if( total >= MAX_CACHE_FRAMES ) {
32 uint32_t vtim = frames[0].age;
33 while( ++i < total ) {
34 if( frames[i].age < vtim ) {
35 n = i; vtim = frames[i].age;
38 frames[n].age = seq++;
41 if( total >= allocation ) {
42 int new_allocation = ZMAX(allocation*2,8);
43 cacheframe_t *new_frames = new cacheframe_t[new_allocation];
44 for( int i=0; i<total; ++i )
45 new_frames[i] = frames[i];
48 allocation = new_allocation;
49 //zmsgs("%d %d %d\n", new_allocation, allocation, total);
51 frames[total].age = seq++;
56 put_frame(int64_t zframe_number,
57 uint8_t *zy, uint8_t *zu, uint8_t *zv,
58 int zy_size, int zu_size, int zv_size)
60 cacheframe_t *frame = 0;
62 //zmsgs("save %d\n",zframe_number);
64 for( i=0; i<total; ++i ) { /* Get existing frame */
65 if( frames[i].frame_number == zframe_number ) {
72 int i = extend_cache();
74 //zmsgs("30 %d %p %p %p\n", ptr->total, frame->y, frame->u, frame->v);
76 if( zy_size > frame->y_alloc ) {
78 frame->y = new uint8_t[frame->y_alloc=zy_size];
80 memcpy(frame->y, zy, frame->y_size=zy_size);
83 if( zu_size > frame->u_alloc ) {
85 frame->u = new uint8_t[frame->u_alloc=zu_size];
87 memcpy(frame->u, zu, frame->u_size=zu_size);
90 if( zv_size > frame->v_alloc ) {
92 frame->v = new uint8_t[frame->v_alloc=zv_size];
94 memcpy(frame->v, zv, frame->v_size=zv_size);
96 frame->frame_number = zframe_number;
101 get_frame(int64_t zframe_number,
102 uint8_t **zy, uint8_t **zu, uint8_t **zv)
104 for( int i=0; i<total; ++i ) {
105 cacheframe_t *frame = &frames[i];
106 if( frame->frame_number == zframe_number ) {
111 //zmsgs("hit %d\n",zframe_number);
116 //zmsgs("missed %d\n",zframe_number);
121 has_frame(int64_t zframe_number)
123 for( int i=0; i<total; ++i )
124 if( frames[i].frame_number == zframe_number ) return 1;
133 for( int i=0; i<allocation; ++i ) {
134 cacheframe_t *frame = &frames[i];
135 result += frame->y_alloc + frame->u_alloc + frame->v_alloc;