info.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599
  1. /********************************************************************
  2. * *
  3. * THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC SOURCE CODE. *
  4. * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS *
  5. * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
  6. * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. *
  7. * *
  8. * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2001 *
  9. * by the XIPHOPHORUS Company http://www.xiph.org/ *
  10. ********************************************************************
  11. function: maintain the info structure, info <-> header packets
  12. last mod: $Id: info.c,v 1.49.2.1 2001/12/17 05:39:24 xiphmont Exp $
  13. ********************************************************************/
  14. /* general handling of the header and the vorbis_info structure (and
  15. substructures) */
  16. #include <stdlib.h>
  17. #include <string.h>
  18. #include <ctype.h>
  19. #include <ogg/ogg.h>
  20. #include "vorbis/codec.h"
  21. #include "codec_internal.h"
  22. #include "codebook.h"
  23. #include "registry.h"
  24. #include "window.h"
  25. #include "psy.h"
  26. #include "misc.h"
  27. #include "os.h"
  28. /* helpers */
  29. static int ilog2(unsigned int v){
  30. int ret=0;
  31. while(v>1){
  32. ret++;
  33. v>>=1;
  34. }
  35. return(ret);
  36. }
  37. static void _v_writestring(oggpack_buffer *o,char *s, int bytes){
  38. while(bytes--){
  39. oggpack_write(o,*s++,8);
  40. }
  41. }
  42. static void _v_readstring(oggpack_buffer *o,char *buf,int bytes){
  43. while(bytes--){
  44. *buf++=oggpack_read(o,8);
  45. }
  46. }
  47. void vorbis_comment_init(vorbis_comment *vc){
  48. memset(vc,0,sizeof(*vc));
  49. }
  50. void vorbis_comment_add(vorbis_comment *vc,char *comment){
  51. vc->user_comments=_ogg_realloc(vc->user_comments,
  52. (vc->comments+2)*sizeof(*vc->user_comments));
  53. vc->comment_lengths=_ogg_realloc(vc->comment_lengths,
  54. (vc->comments+2)*sizeof(*vc->comment_lengths));
  55. vc->comment_lengths[vc->comments]=strlen(comment);
  56. vc->user_comments[vc->comments]=_ogg_malloc(vc->comment_lengths[vc->comments]+1);
  57. strcpy(vc->user_comments[vc->comments], comment);
  58. vc->comments++;
  59. vc->user_comments[vc->comments]=NULL;
  60. }
  61. void vorbis_comment_add_tag(vorbis_comment *vc, char *tag, char *contents){
  62. char *comment=alloca(strlen(tag)+strlen(contents)+2); /* +2 for = and \0 */
  63. strcpy(comment, tag);
  64. strcat(comment, "=");
  65. strcat(comment, contents);
  66. vorbis_comment_add(vc, comment);
  67. }
  68. /* This is more or less the same as strncasecmp - but that doesn't exist
  69. * everywhere, and this is a fairly trivial function, so we include it */
  70. static int tagcompare(const char *s1, const char *s2, int n){
  71. int c=0;
  72. while(c < n){
  73. if(toupper(s1[c]) != toupper(s2[c]))
  74. return !0;
  75. c++;
  76. }
  77. return 0;
  78. }
  79. char *vorbis_comment_query(vorbis_comment *vc, char *tag, int count){
  80. long i;
  81. int found = 0;
  82. int taglen = strlen(tag)+1; /* +1 for the = we append */
  83. char *fulltag = alloca(taglen+ 1);
  84. strcpy(fulltag, tag);
  85. strcat(fulltag, "=");
  86. for(i=0;i<vc->comments;i++){
  87. if(!tagcompare(vc->user_comments[i], fulltag, taglen)){
  88. if(count == found)
  89. /* We return a pointer to the data, not a copy */
  90. return vc->user_comments[i] + taglen;
  91. else
  92. found++;
  93. }
  94. }
  95. return NULL; /* didn't find anything */
  96. }
  97. int vorbis_comment_query_count(vorbis_comment *vc, char *tag){
  98. int i,count=0;
  99. int taglen = strlen(tag)+1; /* +1 for the = we append */
  100. char *fulltag = alloca(taglen+1);
  101. strcpy(fulltag,tag);
  102. strcat(fulltag, "=");
  103. for(i=0;i<vc->comments;i++){
  104. if(!tagcompare(vc->user_comments[i], fulltag, taglen))
  105. count++;
  106. }
  107. return count;
  108. }
  109. void vorbis_comment_clear(vorbis_comment *vc){
  110. if(vc){
  111. long i;
  112. for(i=0;i<vc->comments;i++)
  113. if(vc->user_comments[i])_ogg_free(vc->user_comments[i]);
  114. if(vc->user_comments)_ogg_free(vc->user_comments);
  115. if(vc->comment_lengths)_ogg_free(vc->comment_lengths);
  116. if(vc->vendor)_ogg_free(vc->vendor);
  117. }
  118. memset(vc,0,sizeof(*vc));
  119. }
  120. /* blocksize 0 is guaranteed to be short, 1 is guarantted to be long.
  121. They may be equal, but short will never ge greater than long */
  122. int vorbis_info_blocksize(vorbis_info *vi,int zo){
  123. codec_setup_info *ci = vi->codec_setup;
  124. return ci ? ci->blocksizes[zo] : -1;
  125. }
  126. /* used by synthesis, which has a full, alloced vi */
  127. void vorbis_info_init(vorbis_info *vi){
  128. memset(vi,0,sizeof(*vi));
  129. vi->codec_setup=_ogg_calloc(1,sizeof(codec_setup_info));
  130. }
  131. void vorbis_info_clear(vorbis_info *vi){
  132. codec_setup_info *ci=vi->codec_setup;
  133. int i;
  134. if(ci){
  135. for(i=0;i<ci->modes;i++)
  136. if(ci->mode_param[i])_ogg_free(ci->mode_param[i]);
  137. for(i=0;i<ci->maps;i++) /* unpack does the range checking */
  138. _mapping_P[ci->map_type[i]]->free_info(ci->map_param[i]);
  139. for(i=0;i<ci->times;i++) /* unpack does the range checking */
  140. _time_P[ci->time_type[i]]->free_info(ci->time_param[i]);
  141. for(i=0;i<ci->floors;i++) /* unpack does the range checking */
  142. _floor_P[ci->floor_type[i]]->free_info(ci->floor_param[i]);
  143. for(i=0;i<ci->residues;i++) /* unpack does the range checking */
  144. _residue_P[ci->residue_type[i]]->free_info(ci->residue_param[i]);
  145. for(i=0;i<ci->books;i++){
  146. if(ci->book_param[i]){
  147. /* knows if the book was not alloced */
  148. vorbis_staticbook_destroy(ci->book_param[i]);
  149. }
  150. }
  151. for(i=0;i<ci->psys;i++)
  152. _vi_psy_free(ci->psy_param[i]);
  153. _ogg_free(ci);
  154. }
  155. memset(vi,0,sizeof(*vi));
  156. }
  157. /* Header packing/unpacking ********************************************/
  158. static int _vorbis_unpack_info(vorbis_info *vi,oggpack_buffer *opb){
  159. codec_setup_info *ci=vi->codec_setup;
  160. if(!ci)return(OV_EFAULT);
  161. vi->version=oggpack_read(opb,32);
  162. if(vi->version!=0)return(OV_EVERSION);
  163. vi->channels=oggpack_read(opb,8);
  164. vi->rate=oggpack_read(opb,32);
  165. vi->bitrate_upper=oggpack_read(opb,32);
  166. vi->bitrate_nominal=oggpack_read(opb,32);
  167. vi->bitrate_lower=oggpack_read(opb,32);
  168. ci->blocksizes[0]=1<<oggpack_read(opb,4);
  169. ci->blocksizes[1]=1<<oggpack_read(opb,4);
  170. if(vi->rate<1)goto err_out;
  171. if(vi->channels<1)goto err_out;
  172. if(ci->blocksizes[0]<8)goto err_out;
  173. if(ci->blocksizes[1]<ci->blocksizes[0])goto err_out;
  174. if(oggpack_read(opb,1)!=1)goto err_out; /* EOP check */
  175. return(0);
  176. err_out:
  177. vorbis_info_clear(vi);
  178. return(OV_EBADHEADER);
  179. }
  180. static int _vorbis_unpack_comment(vorbis_comment *vc,oggpack_buffer *opb){
  181. int i;
  182. int vendorlen=oggpack_read(opb,32);
  183. if(vendorlen<0)goto err_out;
  184. vc->vendor=_ogg_calloc(vendorlen+1,1);
  185. _v_readstring(opb,vc->vendor,vendorlen);
  186. vc->comments=oggpack_read(opb,32);
  187. if(vc->comments<0)goto err_out;
  188. vc->user_comments=_ogg_calloc(vc->comments+1,sizeof(*vc->user_comments));
  189. vc->comment_lengths=_ogg_calloc(vc->comments+1, sizeof(*vc->comment_lengths));
  190. for(i=0;i<vc->comments;i++){
  191. int len=oggpack_read(opb,32);
  192. if(len<0)goto err_out;
  193. vc->comment_lengths[i]=len;
  194. vc->user_comments[i]=_ogg_calloc(len+1,1);
  195. _v_readstring(opb,vc->user_comments[i],len);
  196. }
  197. if(oggpack_read(opb,1)!=1)goto err_out; /* EOP check */
  198. return(0);
  199. err_out:
  200. vorbis_comment_clear(vc);
  201. return(OV_EBADHEADER);
  202. }
  203. /* all of the real encoding details are here. The modes, books,
  204. everything */
  205. static int _vorbis_unpack_books(vorbis_info *vi,oggpack_buffer *opb){
  206. codec_setup_info *ci=vi->codec_setup;
  207. int i;
  208. if(!ci)return(OV_EFAULT);
  209. /* codebooks */
  210. ci->books=oggpack_read(opb,8)+1;
  211. /*ci->book_param=_ogg_calloc(ci->books,sizeof(*ci->book_param));*/
  212. for(i=0;i<ci->books;i++){
  213. ci->book_param[i]=_ogg_calloc(1,sizeof(*ci->book_param[i]));
  214. if(vorbis_staticbook_unpack(opb,ci->book_param[i]))goto err_out;
  215. }
  216. /* time backend settings */
  217. ci->times=oggpack_read(opb,6)+1;
  218. /*ci->time_type=_ogg_malloc(ci->times*sizeof(*ci->time_type));*/
  219. /*ci->time_param=_ogg_calloc(ci->times,sizeof(void *));*/
  220. for(i=0;i<ci->times;i++){
  221. ci->time_type[i]=oggpack_read(opb,16);
  222. if(ci->time_type[i]<0 || ci->time_type[i]>=VI_TIMEB)goto err_out;
  223. ci->time_param[i]=_time_P[ci->time_type[i]]->unpack(vi,opb);
  224. if(!ci->time_param[i])goto err_out;
  225. }
  226. /* floor backend settings */
  227. ci->floors=oggpack_read(opb,6)+1;
  228. /*ci->floor_type=_ogg_malloc(ci->floors*sizeof(*ci->floor_type));*/
  229. /*ci->floor_param=_ogg_calloc(ci->floors,sizeof(void *));*/
  230. for(i=0;i<ci->floors;i++){
  231. ci->floor_type[i]=oggpack_read(opb,16);
  232. if(ci->floor_type[i]<0 || ci->floor_type[i]>=VI_FLOORB)goto err_out;
  233. ci->floor_param[i]=_floor_P[ci->floor_type[i]]->unpack(vi,opb);
  234. if(!ci->floor_param[i])goto err_out;
  235. }
  236. /* residue backend settings */
  237. ci->residues=oggpack_read(opb,6)+1;
  238. /*ci->residue_type=_ogg_malloc(ci->residues*sizeof(*ci->residue_type));*/
  239. /*ci->residue_param=_ogg_calloc(ci->residues,sizeof(void *));*/
  240. for(i=0;i<ci->residues;i++){
  241. ci->residue_type[i]=oggpack_read(opb,16);
  242. if(ci->residue_type[i]<0 || ci->residue_type[i]>=VI_RESB)goto err_out;
  243. ci->residue_param[i]=_residue_P[ci->residue_type[i]]->unpack(vi,opb);
  244. if(!ci->residue_param[i])goto err_out;
  245. }
  246. /* map backend settings */
  247. ci->maps=oggpack_read(opb,6)+1;
  248. /*ci->map_type=_ogg_malloc(ci->maps*sizeof(*ci->map_type));*/
  249. /*ci->map_param=_ogg_calloc(ci->maps,sizeof(void *));*/
  250. for(i=0;i<ci->maps;i++){
  251. ci->map_type[i]=oggpack_read(opb,16);
  252. if(ci->map_type[i]<0 || ci->map_type[i]>=VI_MAPB)goto err_out;
  253. ci->map_param[i]=_mapping_P[ci->map_type[i]]->unpack(vi,opb);
  254. if(!ci->map_param[i])goto err_out;
  255. }
  256. /* mode settings */
  257. ci->modes=oggpack_read(opb,6)+1;
  258. /*vi->mode_param=_ogg_calloc(vi->modes,sizeof(void *));*/
  259. for(i=0;i<ci->modes;i++){
  260. ci->mode_param[i]=_ogg_calloc(1,sizeof(*ci->mode_param[i]));
  261. ci->mode_param[i]->blockflag=oggpack_read(opb,1);
  262. ci->mode_param[i]->windowtype=oggpack_read(opb,16);
  263. ci->mode_param[i]->transformtype=oggpack_read(opb,16);
  264. ci->mode_param[i]->mapping=oggpack_read(opb,8);
  265. if(ci->mode_param[i]->windowtype>=VI_WINDOWB)goto err_out;
  266. if(ci->mode_param[i]->transformtype>=VI_WINDOWB)goto err_out;
  267. if(ci->mode_param[i]->mapping>=ci->maps)goto err_out;
  268. }
  269. if(oggpack_read(opb,1)!=1)goto err_out; /* top level EOP check */
  270. return(0);
  271. err_out:
  272. vorbis_info_clear(vi);
  273. return(OV_EBADHEADER);
  274. }
  275. /* The Vorbis header is in three packets; the initial small packet in
  276. the first page that identifies basic parameters, a second packet
  277. with bitstream comments and a third packet that holds the
  278. codebook. */
  279. int vorbis_synthesis_headerin(vorbis_info *vi,vorbis_comment *vc,ogg_packet *op){
  280. oggpack_buffer opb;
  281. if(op){
  282. oggpack_readinit(&opb,op->packet,op->bytes);
  283. /* Which of the three types of header is this? */
  284. /* Also verify header-ness, vorbis */
  285. {
  286. char buffer[6];
  287. int packtype=oggpack_read(&opb,8);
  288. memset(buffer,0,6);
  289. _v_readstring(&opb,buffer,6);
  290. if(memcmp(buffer,"vorbis",6)){
  291. /* not a vorbis header */
  292. return(OV_ENOTVORBIS);
  293. }
  294. switch(packtype){
  295. case 0x01: /* least significant *bit* is read first */
  296. if(!op->b_o_s){
  297. /* Not the initial packet */
  298. return(OV_EBADHEADER);
  299. }
  300. if(vi->rate!=0){
  301. /* previously initialized info header */
  302. return(OV_EBADHEADER);
  303. }
  304. return(_vorbis_unpack_info(vi,&opb));
  305. case 0x03: /* least significant *bit* is read first */
  306. if(vi->rate==0){
  307. /* um... we didn't get the initial header */
  308. return(OV_EBADHEADER);
  309. }
  310. return(_vorbis_unpack_comment(vc,&opb));
  311. case 0x05: /* least significant *bit* is read first */
  312. if(vi->rate==0 || vc->vendor==NULL){
  313. /* um... we didn;t get the initial header or comments yet */
  314. return(OV_EBADHEADER);
  315. }
  316. return(_vorbis_unpack_books(vi,&opb));
  317. default:
  318. /* Not a valid vorbis header type */
  319. return(OV_EBADHEADER);
  320. break;
  321. }
  322. }
  323. }
  324. return(OV_EBADHEADER);
  325. }
  326. /* pack side **********************************************************/
  327. static int _vorbis_pack_info(oggpack_buffer *opb,vorbis_info *vi){
  328. codec_setup_info *ci=vi->codec_setup;
  329. if(!ci)return(OV_EFAULT);
  330. /* preamble */
  331. oggpack_write(opb,0x01,8);
  332. _v_writestring(opb,"vorbis", 6);
  333. /* basic information about the stream */
  334. oggpack_write(opb,0x00,32);
  335. oggpack_write(opb,vi->channels,8);
  336. oggpack_write(opb,vi->rate,32);
  337. oggpack_write(opb,vi->bitrate_upper,32);
  338. oggpack_write(opb,vi->bitrate_nominal,32);
  339. oggpack_write(opb,vi->bitrate_lower,32);
  340. oggpack_write(opb,ilog2(ci->blocksizes[0]),4);
  341. oggpack_write(opb,ilog2(ci->blocksizes[1]),4);
  342. oggpack_write(opb,1,1);
  343. return(0);
  344. }
  345. static int _vorbis_pack_comment(oggpack_buffer *opb,vorbis_comment *vc){
  346. char temp[]="Xiphophorus libVorbis I 20011217";
  347. int bytes = strlen(temp);
  348. /* preamble */
  349. oggpack_write(opb,0x03,8);
  350. _v_writestring(opb,"vorbis", 6);
  351. /* vendor */
  352. oggpack_write(opb,bytes,32);
  353. _v_writestring(opb,temp, bytes);
  354. /* comments */
  355. oggpack_write(opb,vc->comments,32);
  356. if(vc->comments){
  357. int i;
  358. for(i=0;i<vc->comments;i++){
  359. if(vc->user_comments[i]){
  360. oggpack_write(opb,vc->comment_lengths[i],32);
  361. _v_writestring(opb,vc->user_comments[i], vc->comment_lengths[i]);
  362. }else{
  363. oggpack_write(opb,0,32);
  364. }
  365. }
  366. }
  367. oggpack_write(opb,1,1);
  368. return(0);
  369. }
  370. static int _vorbis_pack_books(oggpack_buffer *opb,vorbis_info *vi){
  371. codec_setup_info *ci=vi->codec_setup;
  372. int i;
  373. if(!ci)return(OV_EFAULT);
  374. oggpack_write(opb,0x05,8);
  375. _v_writestring(opb,"vorbis", 6);
  376. /* books */
  377. oggpack_write(opb,ci->books-1,8);
  378. for(i=0;i<ci->books;i++)
  379. if(vorbis_staticbook_pack(ci->book_param[i],opb))goto err_out;
  380. /* times */
  381. oggpack_write(opb,ci->times-1,6);
  382. for(i=0;i<ci->times;i++){
  383. oggpack_write(opb,ci->time_type[i],16);
  384. _time_P[ci->time_type[i]]->pack(ci->time_param[i],opb);
  385. }
  386. /* floors */
  387. oggpack_write(opb,ci->floors-1,6);
  388. for(i=0;i<ci->floors;i++){
  389. oggpack_write(opb,ci->floor_type[i],16);
  390. _floor_P[ci->floor_type[i]]->pack(ci->floor_param[i],opb);
  391. }
  392. /* residues */
  393. oggpack_write(opb,ci->residues-1,6);
  394. for(i=0;i<ci->residues;i++){
  395. oggpack_write(opb,ci->residue_type[i],16);
  396. _residue_P[ci->residue_type[i]]->pack(ci->residue_param[i],opb);
  397. }
  398. /* maps */
  399. oggpack_write(opb,ci->maps-1,6);
  400. for(i=0;i<ci->maps;i++){
  401. oggpack_write(opb,ci->map_type[i],16);
  402. _mapping_P[ci->map_type[i]]->pack(vi,ci->map_param[i],opb);
  403. }
  404. /* modes */
  405. oggpack_write(opb,ci->modes-1,6);
  406. for(i=0;i<ci->modes;i++){
  407. oggpack_write(opb,ci->mode_param[i]->blockflag,1);
  408. oggpack_write(opb,ci->mode_param[i]->windowtype,16);
  409. oggpack_write(opb,ci->mode_param[i]->transformtype,16);
  410. oggpack_write(opb,ci->mode_param[i]->mapping,8);
  411. }
  412. oggpack_write(opb,1,1);
  413. return(0);
  414. err_out:
  415. return(-1);
  416. }
  417. int vorbis_commentheader_out(vorbis_comment *vc,
  418. ogg_packet *op){
  419. oggpack_buffer opb;
  420. oggpack_writeinit(&opb);
  421. if(_vorbis_pack_comment(&opb,vc)) return OV_EIMPL;
  422. op->packet = _ogg_malloc(oggpack_bytes(&opb));
  423. memcpy(op->packet, opb.buffer, oggpack_bytes(&opb));
  424. op->bytes=oggpack_bytes(&opb);
  425. op->b_o_s=0;
  426. op->e_o_s=0;
  427. op->granulepos=0;
  428. return 0;
  429. }
  430. int vorbis_analysis_headerout(vorbis_dsp_state *v,
  431. vorbis_comment *vc,
  432. ogg_packet *op,
  433. ogg_packet *op_comm,
  434. ogg_packet *op_code){
  435. int ret=OV_EIMPL;
  436. vorbis_info *vi=v->vi;
  437. oggpack_buffer opb;
  438. backend_lookup_state *b=v->backend_state;
  439. if(!b){
  440. ret=OV_EFAULT;
  441. goto err_out;
  442. }
  443. /* first header packet **********************************************/
  444. oggpack_writeinit(&opb);
  445. if(_vorbis_pack_info(&opb,vi))goto err_out;
  446. /* build the packet */
  447. if(b->header)_ogg_free(b->header);
  448. b->header=_ogg_malloc(oggpack_bytes(&opb));
  449. memcpy(b->header,opb.buffer,oggpack_bytes(&opb));
  450. op->packet=b->header;
  451. op->bytes=oggpack_bytes(&opb);
  452. op->b_o_s=1;
  453. op->e_o_s=0;
  454. op->granulepos=0;
  455. /* second header packet (comments) **********************************/
  456. oggpack_reset(&opb);
  457. if(_vorbis_pack_comment(&opb,vc))goto err_out;
  458. if(b->header1)_ogg_free(b->header1);
  459. b->header1=_ogg_malloc(oggpack_bytes(&opb));
  460. memcpy(b->header1,opb.buffer,oggpack_bytes(&opb));
  461. op_comm->packet=b->header1;
  462. op_comm->bytes=oggpack_bytes(&opb);
  463. op_comm->b_o_s=0;
  464. op_comm->e_o_s=0;
  465. op_comm->granulepos=0;
  466. /* third header packet (modes/codebooks) ****************************/
  467. oggpack_reset(&opb);
  468. if(_vorbis_pack_books(&opb,vi))goto err_out;
  469. if(b->header2)_ogg_free(b->header2);
  470. b->header2=_ogg_malloc(oggpack_bytes(&opb));
  471. memcpy(b->header2,opb.buffer,oggpack_bytes(&opb));
  472. op_code->packet=b->header2;
  473. op_code->bytes=oggpack_bytes(&opb);
  474. op_code->b_o_s=0;
  475. op_code->e_o_s=0;
  476. op_code->granulepos=0;
  477. oggpack_writeclear(&opb);
  478. return(0);
  479. err_out:
  480. oggpack_writeclear(&opb);
  481. memset(op,0,sizeof(*op));
  482. memset(op_comm,0,sizeof(*op_comm));
  483. memset(op_code,0,sizeof(*op_code));
  484. if(b->header)_ogg_free(b->header);
  485. if(b->header1)_ogg_free(b->header1);
  486. if(b->header2)_ogg_free(b->header2);
  487. b->header=NULL;
  488. b->header1=NULL;
  489. b->header2=NULL;
  490. return(ret);
  491. }