1 #include "mpeg3private.h"
8 // This is basically qtcache.c with quicktime_ replaced by mpeg3_
11 mpeg3_cache_t
* mpeg3_new_cache()
13 mpeg3_cache_t
*result
= calloc(1, sizeof(mpeg3_cache_t
));
17 void mpeg3_delete_cache(mpeg3_cache_t
*ptr
)
22 for(i
= 0; i
< ptr
->allocation
; i
++)
24 mpeg3_cacheframe_t
*frame
= &ptr
->frames
[i
];
25 if(frame
->y
) free(frame
->y
);
26 if(frame
->u
) free(frame
->u
);
27 if(frame
->v
) free(frame
->v
);
34 void mpeg3_reset_cache(mpeg3_cache_t
*ptr
)
39 void mpeg3_cache_put_frame(mpeg3_cache_t
*ptr
,
48 mpeg3_cacheframe_t
*frame
= 0;
51 //printf("mpeg3_put_frame 1\n");
53 for(i
= 0; i
< ptr
->total
; i
++)
55 if(ptr
->frames
[i
].frame_number
== frame_number
)
57 frame
= &ptr
->frames
[i
];
65 if(ptr
->total
>= ptr
->allocation
)
67 int new_allocation
= ptr
->allocation
* 2;
68 //printf("mpeg3_put_frame 10 %d\n", new_allocation);
69 if(!new_allocation
) new_allocation
= 32;
70 ptr
->frames
= realloc(ptr
->frames
,
71 sizeof(mpeg3_cacheframe_t
) * new_allocation
);
72 bzero(ptr
->frames
+ ptr
->total
,
73 sizeof(mpeg3_cacheframe_t
) * (new_allocation
- ptr
->allocation
));
74 //printf("mpeg3_put_frame 20 %d %d %d\n", new_allocation, ptr->allocation, ptr->total);
75 ptr
->allocation
= new_allocation
;
78 frame
= &ptr
->frames
[ptr
->total
];
79 //printf("mpeg3_put_frame 30 %d %p %p %p\n", ptr->total, frame->y, frame->u, frame->v);
82 // Memcpy is a lot slower than just dropping the seeking frames.
85 frame
->y
= realloc(frame
->y
, y_size
);
86 frame
->y_size
= y_size
;
87 memcpy(frame
->y
, y
, y_size
);
92 frame
->u
= realloc(frame
->u
, u_size
);
93 frame
->u_size
= u_size
;
94 memcpy(frame
->u
, u
, u_size
);
99 frame
->v
= realloc(frame
->v
, v_size
);
100 frame
->v_size
= v_size
;
101 memcpy(frame
->v
, v
, v_size
);
103 frame
->frame_number
= frame_number
;
105 //printf("mpeg3_put_frame 100\n");
108 int mpeg3_cache_get_frame(mpeg3_cache_t
*ptr
,
109 int64_t frame_number
,
116 for(i
= 0; i
< ptr
->total
; i
++)
118 mpeg3_cacheframe_t
*frame
= &ptr
->frames
[i
];
119 if(frame
->frame_number
== frame_number
)
134 int mpeg3_cache_has_frame(mpeg3_cache_t
*ptr
,
135 int64_t frame_number
)
139 for(i
= 0; i
< ptr
->total
; i
++)
141 mpeg3_cacheframe_t
*frame
= &ptr
->frames
[i
];
142 if(frame
->frame_number
== frame_number
)
149 int64_t mpeg3_cache_usage(mpeg3_cache_t
*ptr
)
153 for(i
= 0; i
< ptr
->allocation
; i
++)
155 mpeg3_cacheframe_t
*frame
= &ptr
->frames
[i
];
156 result
+= frame
->y_size
+ frame
->u_size
+ frame
->v_size
;