1 #include "funcprotos.h"
6 quicktime_cache_t
* quicktime_new_cache()
8 quicktime_cache_t
*result
= calloc(1, sizeof(quicktime_cache_t
));
12 void quicktime_delete_cache(quicktime_cache_t
*ptr
)
17 //printf("quicktime_delete_cache 1\n");
18 for(i
= 0; i
< ptr
->allocation
; i
++)
20 quicktime_cacheframe_t
*frame
= &ptr
->frames
[i
];
21 if(frame
->y
) free(frame
->y
);
22 if(frame
->u
) free(frame
->u
);
23 if(frame
->v
) free(frame
->v
);
30 void quicktime_reset_cache(quicktime_cache_t
*ptr
)
35 void quicktime_put_frame(quicktime_cache_t
*ptr
,
44 quicktime_cacheframe_t
*frame
= 0;
47 //printf("quicktime_put_frame 1\n");
49 for(i
= 0; i
< ptr
->total
; i
++)
51 if(ptr
->frames
[i
].frame_number
== frame_number
)
53 frame
= &ptr
->frames
[i
];
61 if(ptr
->total
>= ptr
->allocation
)
63 int new_allocation
= ptr
->allocation
* 2;
64 //printf("quicktime_put_frame 10 %d\n", new_allocation);
65 if(!new_allocation
) new_allocation
= 32;
66 ptr
->frames
= realloc(ptr
->frames
,
67 sizeof(quicktime_cacheframe_t
) * new_allocation
);
68 bzero(ptr
->frames
+ ptr
->total
,
69 sizeof(quicktime_cacheframe_t
) * (new_allocation
- ptr
->allocation
));
70 ptr
->allocation
= new_allocation
;
71 //printf("quicktime_put_frame 20 %p %d %d\n", ptr, ptr->allocation, ptr->total);
74 frame
= &ptr
->frames
[ptr
->total
];
75 //printf("quicktime_put_frame 30 %d %p %p %p\n", ptr->total, frame->y, frame->u, frame->v);
78 // Memcpy is a lot slower than just dropping the seeking frames.
81 frame
->y
= realloc(frame
->y
, y_size
);
82 frame
->y_size
= y_size
;
83 memcpy(frame
->y
, y
, y_size
);
88 frame
->u
= realloc(frame
->u
, u_size
);
89 frame
->u_size
= u_size
;
90 memcpy(frame
->u
, u
, u_size
);
95 frame
->v
= realloc(frame
->v
, v_size
);
96 frame
->v_size
= v_size
;
97 memcpy(frame
->v
, v
, v_size
);
99 frame
->frame_number
= frame_number
;
101 //printf("quicktime_put_frame 100\n");
104 int quicktime_get_frame(quicktime_cache_t
*ptr
,
105 int64_t frame_number
,
112 for(i
= 0; i
< ptr
->total
; i
++)
114 quicktime_cacheframe_t
*frame
= &ptr
->frames
[i
];
115 if(frame
->frame_number
== frame_number
)
129 int quicktime_has_frame(quicktime_cache_t
*ptr
,
130 int64_t frame_number
)
134 for(i
= 0; i
< ptr
->total
; i
++)
136 quicktime_cacheframe_t
*frame
= &ptr
->frames
[i
];
137 if(frame
->frame_number
== frame_number
)
147 int64_t quicktime_cache_usage(quicktime_cache_t
*ptr
)
151 //printf("quicktime_cache_usage %p %d %lld\n", ptr, ptr->allocation, result);
152 for(i
= 0; i
< ptr
->allocation
; i
++)
154 quicktime_cacheframe_t
*frame
= &ptr
->frames
[i
];
155 result
+= frame
->y_size
+ frame
->u_size
+ frame
->v_size
;