libkate: /home/v/Kate/WORK_TREES/kate-sorceress-backup/v/src/kate/src/kate_ogg.c Source File

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

- File List

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

    00001 /* Copyright (C) 2008 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 #ifdef HAVE_STRING_H
    00017 #include <string.h>
    00018 #endif
    00019 #include "kate/oggkate.h"
    00020 #include "kate_encode_state.h"
    00021
    00022 static void kate_packet_wrap_ogg(kate_packet *kp,const ogg_packet *op)
    00023 {
    00024   kate_packet_wrap(kp,op->bytes,op->packet);
    00025 }
    00026
    00027 static int kate_packet_create_ogg(kate_packet *kp,ogg_packet *op,kate_encode_state *kes,int eos)
    00028 {
    00029   op->b_o_s=(kes->packetno==0);
    00030   op->e_o_s=eos;
    00031   op->packetno=kes->packetno;
    00032   op->granulepos=kes->granulepos;
    00033   op->bytes=kp->nbytes;
    00034   op->packet=_ogg_malloc(kp->nbytes);
    00035   if (!op->packet) {
    00036     kate_free(kp->data);
    00037     return KATE_E_OUT_OF_MEMORY;
    00038   }
    00039   memcpy(op->packet,kp->data,kp->nbytes);
    00040   kate_free(kp->data);
    00041   return 0;
    00042 }
    00043
    00054 int kate_ogg_encode_headers(kate_state *k,kate_comment *kc,ogg_packet *op)
    00055 {
    00056   kate_packet kp;
    00057   int ret=kate_encode_headers(k,kc,&kp);
    00058   if (ret<0) return ret;
    00059   if (ret>0) return ret; /* no more headers, no packet created */
    00060   return kate_packet_create_ogg(&kp,op,k->kes,0);
    00061 }
    00062
    00075 int kate_ogg_encode_text(kate_state *k,kate_float start_time,kate_float stop_time,const char *text,size_t sz,ogg_packet *op)
    00076 {
    00077   kate_packet kp;
    00078   int ret=kate_encode_text(k,start_time,stop_time,text,sz,&kp);
    00079   if (ret<0) return ret;
    00080   return kate_packet_create_ogg(&kp,op,k->kes,0);
    00081 }
    00082
    00095 int kate_ogg_encode_text_raw_times(kate_state *k,kate_int64_t start_time,kate_int64_t stop_time,const char *text,size_t sz,ogg_packet *op)
    00096 {
    00097   kate_packet kp;
    00098   int ret=kate_encode_text_raw_times(k,start_time,stop_time,text,sz,&kp);
    00099   if (ret<0) return ret;
    00100   return kate_packet_create_ogg(&kp,op,k->kes,0);
    00101 }
    00102
    00114 int kate_ogg_encode_repeat(kate_state *k,kate_float t,kate_float threshold,ogg_packet *op)
    00115 {
    00116   kate_packet kp;
    00117   int ret=kate_encode_repeat(k,t,threshold,&kp);
    00118   if (ret<0) return ret;
    00119   if (ret>0) {
    00120     int pret=kate_packet_create_ogg(&kp,op,k->kes,0);
    00121     if (pret<0) return pret;
    00122   }
    00123   return ret;
    00124 }
    00125
    00137 int kate_ogg_encode_repeat_raw_times(kate_state *k,kate_int64_t t,kate_int64_t threshold,ogg_packet *op)
    00138 {
    00139   kate_packet kp;
    00140   int ret=kate_encode_repeat_raw_times(k,t,threshold,&kp);
    00141   if (ret<0) return ret;
    00142   if (ret>0) {
    00143     int pret=kate_packet_create_ogg(&kp,op,k->kes,0);
    00144     if (pret<0) return pret;
    00145   }
    00146   return ret;
    00147 }
    00148
    00158 int kate_ogg_encode_keepalive(kate_state *k,kate_float t,ogg_packet *op)
    00159 {
    00160   kate_packet kp;
    00161   int ret=kate_encode_keepalive(k,t,&kp);
    00162   if (ret<0) return ret;
    00163   return kate_packet_create_ogg(&kp,op,k->kes,0);
    00164 }
    00165
    00175 int kate_ogg_encode_keepalive_raw_times(kate_state *k,kate_int64_t t,ogg_packet *op)
    00176 {
    00177   kate_packet kp;
    00178   int ret=kate_encode_keepalive_raw_times(k,t,&kp);
    00179   if (ret<0) return ret;
    00180   return kate_packet_create_ogg(&kp,op,k->kes,0);
    00181 }
    00182
    00193 int kate_ogg_encode_finish(kate_state *k,kate_float t,ogg_packet *op)
    00194 {
    00195   kate_packet kp;
    00196   int ret=kate_encode_finish(k,t,&kp);
    00197   if (ret<0) return ret;
    00198   return kate_packet_create_ogg(&kp,op,k->kes,1);
    00199 }
    00200
    00211 int kate_ogg_encode_finish_raw_times(kate_state *k,kate_int64_t t,ogg_packet *op)
    00212 {
    00213   kate_packet kp;
    00214   int ret=kate_encode_finish_raw_times(k,t,&kp);
    00215   if (ret<0) return ret;
    00216   return kate_packet_create_ogg(&kp,op,k->kes,1);
    00217 }
    00218
    00226 int kate_ogg_decode_is_idheader(const ogg_packet *op)
    00227 {
    00228   kate_packet kp;
    00229   if (!op) return 0;
    00230   if (op->packetno!=0) return 0;
    00231   kate_packet_wrap_ogg(&kp,op);
    00232   return kate_decode_is_idheader(&kp);
    00233 }
    00234
    00244 int kate_ogg_decode_headerin(kate_info *ki,kate_comment *kc,ogg_packet *op)
    00245 {
    00246   kate_packet kp;
    00247   if (!op) return KATE_E_INVALID_PARAMETER;
    00248   kate_packet_wrap_ogg(&kp,op);
    00249   return kate_decode_headerin(ki,kc,&kp);
    00250 }
    00251
    00260 int kate_ogg_decode_packetin(kate_state *k,ogg_packet *op)
    00261 {
    00262   kate_packet kp;
    00263   if (!op) return KATE_E_INVALID_PARAMETER;
    00264   kate_packet_wrap_ogg(&kp,op);
    00265   return kate_decode_packetin(k,&kp);
    00266 }
    00267