int BURGERCALL vorbis_analysis_headerout(vorbis_dsp_state *v, vorbis_comment *vc, ogg_packet *op, ogg_packet *op_comm, ogg_packet *op_code){ int ret=OV_EIMPL; vorbis_info *vi=v->vi; oggpack_buffer opb; backend_lookup_state *b=static_cast<backend_lookup_state *>(v->backend_state); if(!b){ ret=OV_EFAULT; goto err_out; } /* first header packet **********************************************/ oggpack_writeinit(&opb); if(_vorbis_pack_info(&opb,vi))goto err_out; /* build the packet */ if(b->header)DeallocAPointer(b->header); b->header=static_cast<Word8 *>(AllocAPointer(oggpack_bytes(&opb))); FastMemCpy(b->header,opb.buffer,oggpack_bytes(&opb)); op->packet=b->header; op->bytes=oggpack_bytes(&opb); op->b_o_s=1; op->e_o_s=0; op->granulepos=0; /* second header packet (comments) **********************************/ oggpack_reset(&opb); if(_vorbis_pack_comment(&opb,vc))goto err_out; if(b->header1)DeallocAPointer(b->header1); b->header1=static_cast<Word8 *>(AllocAPointer(oggpack_bytes(&opb))); FastMemCpy(b->header1,opb.buffer,oggpack_bytes(&opb)); op_comm->packet=b->header1; op_comm->bytes=oggpack_bytes(&opb); op_comm->b_o_s=0; op_comm->e_o_s=0; op_comm->granulepos=0; /* third header packet (modes/codebooks) ****************************/ oggpack_reset(&opb); if(_vorbis_pack_books(&opb,vi))goto err_out; if(b->header2)DeallocAPointer(b->header2); b->header2=static_cast<Word8 *>(AllocAPointer(oggpack_bytes(&opb))); FastMemCpy(b->header2,opb.buffer,oggpack_bytes(&opb)); op_code->packet=b->header2; op_code->bytes=oggpack_bytes(&opb); op_code->b_o_s=0; op_code->e_o_s=0; op_code->granulepos=0; oggpack_writeclear(&opb); return(0); err_out: oggpack_writeclear(&opb); FastMemSet(op,0,sizeof(*op)); FastMemSet(op_comm,0,sizeof(*op_comm)); FastMemSet(op_code,0,sizeof(*op_code)); if(b->header)DeallocAPointer(b->header); if(b->header1)DeallocAPointer(b->header1); if(b->header2)DeallocAPointer(b->header2); b->header=NULL; b->header1=NULL; b->header2=NULL; return(ret); }
int vorbis_analysis_headerout(vorbis_dsp_state *v, vorbis_comment *vc, ogg_packet *op, ogg_packet *op_comm, ogg_packet *op_code){ int ret=OV_EIMPL; vorbis_info *vi=v->vi; oggpack_buffer opb; private_state *b=v->backend_state; if(!b){ ret=OV_EFAULT; goto err_out; } /* first header packet **********************************************/ oggpack_writeinit(&opb); if(_vorbis_pack_info(&opb,vi))goto err_out; /* build the packet */ if(b->header)_ogg_free(b->header); b->header=_ogg_malloc(oggpack_bytes(&opb)); memcpy(b->header,opb.buffer,oggpack_bytes(&opb)); op->packet=b->header; op->bytes=oggpack_bytes(&opb); op->b_o_s=1; op->e_o_s=0; op->granulepos=0; op->packetno=0; /* second header packet (comments) **********************************/ oggpack_reset(&opb); if(_vorbis_pack_comment(&opb,vc))goto err_out; if(b->header1)_ogg_free(b->header1); b->header1=_ogg_malloc(oggpack_bytes(&opb)); memcpy(b->header1,opb.buffer,oggpack_bytes(&opb)); op_comm->packet=b->header1; op_comm->bytes=oggpack_bytes(&opb); op_comm->b_o_s=0; op_comm->e_o_s=0; op_comm->granulepos=0; op_comm->packetno=1; /* third header packet (modes/codebooks) ****************************/ oggpack_reset(&opb); if(_vorbis_pack_books(&opb,vi))goto err_out; if(b->header2)_ogg_free(b->header2); b->header2=_ogg_malloc(oggpack_bytes(&opb)); memcpy(b->header2,opb.buffer,oggpack_bytes(&opb)); op_code->packet=b->header2; op_code->bytes=oggpack_bytes(&opb); op_code->b_o_s=0; op_code->e_o_s=0; op_code->granulepos=0; op_code->packetno=2; oggpack_writeclear(&opb); return(0); err_out: memset(op,0,sizeof(*op)); memset(op_comm,0,sizeof(*op_comm)); memset(op_code,0,sizeof(*op_code)); if(b){ oggpack_writeclear(&opb); if(b->header)_ogg_free(b->header); if(b->header1)_ogg_free(b->header1); if(b->header2)_ogg_free(b->header2); b->header=NULL; b->header1=NULL; b->header2=NULL; } return(ret); }