- Main Page
- Related Pages
- Data Structures
- Files
- Examples

- File List

# /home/v/Kate/WORK_TREES/kate-sorceress-backup/v/src/kate/src/kate_decode_state.c

    00001 /* Copyright (C) 2008, 2009 Vincent Penquerc'h.
    00002    This file is part of the Kate codec library.
    00003    Written by Vincent Penquerc'h.
    00004
    00005    Use, distribution and reproduction of this library is governed
    00006    by a BSD style source license included with this source in the
    00007    file 'COPYING'. Please read these terms before distributing. */
    00008
    00009
    00010 #define KATE_INTERNAL
    00011 #include "kate_internal.h"
    00012
    00013 #ifdef HAVE_STDLIB_H
    00014 #include <stdlib.h>
    00015 #endif
    00016 #include "kate/kate.h"
    00017 #include "kate_decode_state.h"
    00018
    00019 kate_decode_state *kate_decode_state_create()
    00020 {
    00021   kate_decode_state *kds;
    00022
    00023   kds=(kate_decode_state*)kate_malloc(sizeof(kate_decode_state));
    00024   if (!kds) return NULL;
    00025   kds->ki=NULL;
    00026   kds->kc=NULL;
    00027   kds->event=NULL;
    00028   kds->n_active_events=0;
    00029   kds->active_events=NULL;
    00030
    00031   return kds;
    00032 }
    00033
    00034 int kate_decode_state_clear(kate_decode_state *kds,const kate_info *ki,int new)
    00035 {
    00036   if (!kds || !ki) return KATE_E_INVALID_PARAMETER;
    00037
    00038   if (kds->event) {
    00039     kate_event_release(kds->event);
    00040     kds->event=NULL;
    00041   }
    00042
    00043   if (new) {
    00044     kds->event=kate_event_create(ki);
    00045     if (!kds->event) return KATE_E_OUT_OF_MEMORY;
    00046     kate_event_track(kds->event);
    00047   }
    00048
    00049   return 0;
    00050 }
    00051
    00052 int kate_decode_state_flush_events(kate_decode_state *kds,kate_int64_t granule)
    00053 {
    00054   size_t n;
    00055
    00056   if (!kds) return KATE_E_INVALID_PARAMETER;
    00057
    00058   /* -1 will flush everything */
    00059   for (n=0;n<kds->n_active_events;++n) {
    00060     if (granule<kds->active_events[n].start || granule>kds->active_events[n].end) {
    00061       kds->active_events[n--]=kds->active_events[--kds->n_active_events];
    00062     }
    00063   }
    00064
    00065   return 0;
    00066 }
    00067
    00068 int kate_decode_state_find_event(kate_decode_state *kds,kate_int32_t id)
    00069 {
    00070   size_t n;
    00071
    00072   if (!kds) return KATE_E_INVALID_PARAMETER;
    00073   if (id<0) return KATE_E_INVALID_PARAMETER;
    00074
    00075   for (n=0;n<kds->n_active_events;++n) {
    00076     if (kds->active_events[n].id==id) return 0;
    00077   }
    00078
    00079   return KATE_E_NOT_FOUND;
    00080 }
    00081
    00082 int kate_decode_state_add_event(kate_decode_state *kds,const kate_event *ev)
    00083 {
    00084   size_t n;
    00085   kate_active_event *events;
    00086   int ret;
    00087
    00088   if (!kds) return KATE_E_INVALID_PARAMETER;
    00089   if (!ev) return KATE_E_INVALID_PARAMETER;
    00090
    00091   ret=kate_check_add_overflow(kds->n_active_events,1,NULL);
    00092   if (ret<0) return ret;
    00093
    00094   /* check if it is there already */
    00095   for (n=0;n<kds->n_active_events;++n) {
    00096     if (kds->active_events[n].id==ev->id) {
    00097       return 1;
    00098     }
    00099   }
    00100
    00101   /* if it is not there, add it */
    00102   events=(kate_active_event*)kate_checked_realloc(kds->active_events,(kds->n_active_events+1),sizeof(kate_active_event));
    00103   if (!events) return KATE_E_OUT_OF_MEMORY;
    00104
    00105   kds->active_events=events;
    00106   kds->active_events[kds->n_active_events].id=ev->id;
    00107   kds->active_events[kds->n_active_events].start=ev->start;
    00108   kds->active_events[kds->n_active_events].end=ev->start+ev->duration-1;
    00109   ++kds->n_active_events;
    00110
    00111   return 0;
    00112 }
    00113
    00114 int kate_decode_state_destroy(kate_decode_state *kds)
    00115 {
    00116   if (!kds) return KATE_E_INVALID_PARAMETER;
    00117
    00118   kate_event_release(kds->event);
    00119
    00120   if (kds->ki) kate_info_clear(kds->ki);
    00121   if (kds->kc) kate_comment_clear(kds->kc);
    00122
    00123   kate_free(kds->active_events);
    00124
    00125   kate_free(kds);
    00126
    00127   return 0;
    00128 }