"Fossies" - the Fresh Open Source Software Archive

Member "quicktime4linux-2.3/qtcache.c" (9 Jan 2007, 3188 Bytes) of package /linux/privat/old/quicktime4linux-2.3-src.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 #include "funcprotos.h"
    2 #include "qtprivate.h"
    3 #include <string.h>
    4 
    5 
    6 quicktime_cache_t* quicktime_new_cache()
    7 {
    8     quicktime_cache_t *result = calloc(1, sizeof(quicktime_cache_t));
    9     return result;
   10 }
   11 
   12 void quicktime_delete_cache(quicktime_cache_t *ptr)
   13 {
   14     if(ptr->frames) 
   15     {
   16         int i;
   17 //printf("quicktime_delete_cache 1\n");
   18         for(i = 0; i < ptr->allocation; i++)
   19         {
   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);
   24         }
   25         free(ptr->frames);
   26         free(ptr);
   27     }
   28 }
   29 
   30 void quicktime_reset_cache(quicktime_cache_t *ptr)
   31 {
   32     ptr->total = 0;
   33 }
   34 
   35 void quicktime_put_frame(quicktime_cache_t *ptr,
   36     int64_t frame_number,
   37     unsigned char *y,
   38     unsigned char *u,
   39     unsigned char *v,
   40     int y_size,
   41     int u_size,
   42     int v_size)
   43 {
   44     quicktime_cacheframe_t *frame = 0;
   45     int i;
   46 
   47 //printf("quicktime_put_frame 1\n");
   48 // Get existing frame
   49     for(i = 0; i < ptr->total; i++)
   50     {
   51         if(ptr->frames[i].frame_number == frame_number)
   52         {
   53             frame = &ptr->frames[i];
   54             break;
   55         }
   56     }
   57 
   58 
   59     if(!frame)
   60     {
   61         if(ptr->total >= ptr->allocation)
   62         {
   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);
   72         }
   73 
   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);
   76         ptr->total++;
   77 
   78 // Memcpy is a lot slower than just dropping the seeking frames.
   79         if(y) 
   80         {
   81             frame->y = realloc(frame->y, y_size);
   82             frame->y_size = y_size;
   83             memcpy(frame->y, y, y_size);
   84         }
   85 
   86         if(u)
   87         {
   88             frame->u = realloc(frame->u, u_size);
   89             frame->u_size = u_size;
   90             memcpy(frame->u, u, u_size);
   91         }
   92 
   93         if(v)
   94         {
   95             frame->v = realloc(frame->v, v_size);
   96             frame->v_size = v_size;
   97             memcpy(frame->v, v, v_size);
   98         }
   99         frame->frame_number = frame_number;
  100     }
  101 //printf("quicktime_put_frame 100\n");
  102 }
  103 
  104 int quicktime_get_frame(quicktime_cache_t *ptr,
  105     int64_t frame_number,
  106     unsigned char **y,
  107     unsigned char **u,
  108     unsigned char **v)
  109 {
  110     int i;
  111 
  112     for(i = 0; i < ptr->total; i++)
  113     {
  114         quicktime_cacheframe_t *frame = &ptr->frames[i];
  115         if(frame->frame_number == frame_number)
  116         {
  117             
  118             *y = frame->y;
  119             *u = frame->u;
  120             *v = frame->v;
  121             return 1;
  122             break;
  123         }
  124     }
  125 
  126     return 0;
  127 }
  128 
  129 int quicktime_has_frame(quicktime_cache_t *ptr,
  130     int64_t frame_number)
  131 {
  132     int i;
  133 
  134     for(i = 0; i < ptr->total; i++)
  135     {
  136         quicktime_cacheframe_t *frame = &ptr->frames[i];
  137         if(frame->frame_number == frame_number)
  138         {
  139             return 1;
  140             break;
  141         }
  142     }
  143 
  144     return 0;
  145 }
  146 
  147 int64_t quicktime_cache_usage(quicktime_cache_t *ptr)
  148 {
  149     int64_t result = 0;
  150     int i;
  151 //printf("quicktime_cache_usage %p %d %lld\n", ptr,  ptr->allocation, result);
  152     for(i = 0; i < ptr->allocation; i++)
  153     {
  154         quicktime_cacheframe_t *frame = &ptr->frames[i];
  155         result += frame->y_size + frame->u_size + frame->v_size;
  156     }
  157     return result;
  158 }
  159 
  160 
  161