Tue, 06 Jan 2015 21:39:09 +0100
Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.
michael@0 | 1 | /******************************************************************** |
michael@0 | 2 | * * |
michael@0 | 3 | * THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC SOURCE CODE. * |
michael@0 | 4 | * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS * |
michael@0 | 5 | * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE * |
michael@0 | 6 | * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. * |
michael@0 | 7 | * * |
michael@0 | 8 | * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2009 * |
michael@0 | 9 | * by the Xiph.Org Foundation http://www.xiph.org/ * |
michael@0 | 10 | * * |
michael@0 | 11 | ******************************************************************** |
michael@0 | 12 | |
michael@0 | 13 | function: single-block PCM synthesis |
michael@0 | 14 | last mod: $Id: synthesis.c 17474 2010-09-30 03:41:41Z gmaxwell $ |
michael@0 | 15 | |
michael@0 | 16 | ********************************************************************/ |
michael@0 | 17 | |
michael@0 | 18 | #include <stdio.h> |
michael@0 | 19 | #include <ogg/ogg.h> |
michael@0 | 20 | #include "vorbis/codec.h" |
michael@0 | 21 | #include "codec_internal.h" |
michael@0 | 22 | #include "registry.h" |
michael@0 | 23 | #include "misc.h" |
michael@0 | 24 | #include "os.h" |
michael@0 | 25 | |
michael@0 | 26 | int vorbis_synthesis(vorbis_block *vb,ogg_packet *op){ |
michael@0 | 27 | vorbis_dsp_state *vd= vb ? vb->vd : 0; |
michael@0 | 28 | private_state *b= vd ? vd->backend_state : 0; |
michael@0 | 29 | vorbis_info *vi= vd ? vd->vi : 0; |
michael@0 | 30 | codec_setup_info *ci= vi ? vi->codec_setup : 0; |
michael@0 | 31 | oggpack_buffer *opb=vb ? &vb->opb : 0; |
michael@0 | 32 | int type,mode,i; |
michael@0 | 33 | |
michael@0 | 34 | if (!vd || !b || !vi || !ci || !opb) { |
michael@0 | 35 | return OV_EBADPACKET; |
michael@0 | 36 | } |
michael@0 | 37 | |
michael@0 | 38 | /* first things first. Make sure decode is ready */ |
michael@0 | 39 | _vorbis_block_ripcord(vb); |
michael@0 | 40 | oggpack_readinit(opb,op->packet,op->bytes); |
michael@0 | 41 | |
michael@0 | 42 | /* Check the packet type */ |
michael@0 | 43 | if(oggpack_read(opb,1)!=0){ |
michael@0 | 44 | /* Oops. This is not an audio data packet */ |
michael@0 | 45 | return(OV_ENOTAUDIO); |
michael@0 | 46 | } |
michael@0 | 47 | |
michael@0 | 48 | /* read our mode and pre/post windowsize */ |
michael@0 | 49 | mode=oggpack_read(opb,b->modebits); |
michael@0 | 50 | if(mode==-1){ |
michael@0 | 51 | return(OV_EBADPACKET); |
michael@0 | 52 | } |
michael@0 | 53 | |
michael@0 | 54 | vb->mode=mode; |
michael@0 | 55 | if(!ci->mode_param[mode]){ |
michael@0 | 56 | return(OV_EBADPACKET); |
michael@0 | 57 | } |
michael@0 | 58 | |
michael@0 | 59 | vb->W=ci->mode_param[mode]->blockflag; |
michael@0 | 60 | if(vb->W){ |
michael@0 | 61 | |
michael@0 | 62 | /* this doesn;t get mapped through mode selection as it's used |
michael@0 | 63 | only for window selection */ |
michael@0 | 64 | vb->lW=oggpack_read(opb,1); |
michael@0 | 65 | vb->nW=oggpack_read(opb,1); |
michael@0 | 66 | if(vb->nW==-1){ |
michael@0 | 67 | return(OV_EBADPACKET); |
michael@0 | 68 | } |
michael@0 | 69 | }else{ |
michael@0 | 70 | vb->lW=0; |
michael@0 | 71 | vb->nW=0; |
michael@0 | 72 | } |
michael@0 | 73 | |
michael@0 | 74 | /* more setup */ |
michael@0 | 75 | vb->granulepos=op->granulepos; |
michael@0 | 76 | vb->sequence=op->packetno; |
michael@0 | 77 | vb->eofflag=op->e_o_s; |
michael@0 | 78 | |
michael@0 | 79 | /* alloc pcm passback storage */ |
michael@0 | 80 | vb->pcmend=ci->blocksizes[vb->W]; |
michael@0 | 81 | vb->pcm=_vorbis_block_alloc(vb,sizeof(*vb->pcm)*vi->channels); |
michael@0 | 82 | for(i=0;i<vi->channels;i++) |
michael@0 | 83 | vb->pcm[i]=_vorbis_block_alloc(vb,vb->pcmend*sizeof(*vb->pcm[i])); |
michael@0 | 84 | |
michael@0 | 85 | /* unpack_header enforces range checking */ |
michael@0 | 86 | type=ci->map_type[ci->mode_param[mode]->mapping]; |
michael@0 | 87 | |
michael@0 | 88 | return(_mapping_P[type]->inverse(vb,ci->map_param[ci->mode_param[mode]-> |
michael@0 | 89 | mapping])); |
michael@0 | 90 | } |
michael@0 | 91 | |
michael@0 | 92 | /* used to track pcm position without actually performing decode. |
michael@0 | 93 | Useful for sequential 'fast forward' */ |
michael@0 | 94 | int vorbis_synthesis_trackonly(vorbis_block *vb,ogg_packet *op){ |
michael@0 | 95 | vorbis_dsp_state *vd=vb->vd; |
michael@0 | 96 | private_state *b=vd->backend_state; |
michael@0 | 97 | vorbis_info *vi=vd->vi; |
michael@0 | 98 | codec_setup_info *ci=vi->codec_setup; |
michael@0 | 99 | oggpack_buffer *opb=&vb->opb; |
michael@0 | 100 | int mode; |
michael@0 | 101 | |
michael@0 | 102 | /* first things first. Make sure decode is ready */ |
michael@0 | 103 | _vorbis_block_ripcord(vb); |
michael@0 | 104 | oggpack_readinit(opb,op->packet,op->bytes); |
michael@0 | 105 | |
michael@0 | 106 | /* Check the packet type */ |
michael@0 | 107 | if(oggpack_read(opb,1)!=0){ |
michael@0 | 108 | /* Oops. This is not an audio data packet */ |
michael@0 | 109 | return(OV_ENOTAUDIO); |
michael@0 | 110 | } |
michael@0 | 111 | |
michael@0 | 112 | /* read our mode and pre/post windowsize */ |
michael@0 | 113 | mode=oggpack_read(opb,b->modebits); |
michael@0 | 114 | if(mode==-1)return(OV_EBADPACKET); |
michael@0 | 115 | |
michael@0 | 116 | vb->mode=mode; |
michael@0 | 117 | if(!ci->mode_param[mode]){ |
michael@0 | 118 | return(OV_EBADPACKET); |
michael@0 | 119 | } |
michael@0 | 120 | |
michael@0 | 121 | vb->W=ci->mode_param[mode]->blockflag; |
michael@0 | 122 | if(vb->W){ |
michael@0 | 123 | vb->lW=oggpack_read(opb,1); |
michael@0 | 124 | vb->nW=oggpack_read(opb,1); |
michael@0 | 125 | if(vb->nW==-1) return(OV_EBADPACKET); |
michael@0 | 126 | }else{ |
michael@0 | 127 | vb->lW=0; |
michael@0 | 128 | vb->nW=0; |
michael@0 | 129 | } |
michael@0 | 130 | |
michael@0 | 131 | /* more setup */ |
michael@0 | 132 | vb->granulepos=op->granulepos; |
michael@0 | 133 | vb->sequence=op->packetno; |
michael@0 | 134 | vb->eofflag=op->e_o_s; |
michael@0 | 135 | |
michael@0 | 136 | /* no pcm */ |
michael@0 | 137 | vb->pcmend=0; |
michael@0 | 138 | vb->pcm=NULL; |
michael@0 | 139 | |
michael@0 | 140 | return(0); |
michael@0 | 141 | } |
michael@0 | 142 | |
michael@0 | 143 | long vorbis_packet_blocksize(vorbis_info *vi,ogg_packet *op){ |
michael@0 | 144 | codec_setup_info *ci=vi->codec_setup; |
michael@0 | 145 | oggpack_buffer opb; |
michael@0 | 146 | int mode; |
michael@0 | 147 | |
michael@0 | 148 | oggpack_readinit(&opb,op->packet,op->bytes); |
michael@0 | 149 | |
michael@0 | 150 | /* Check the packet type */ |
michael@0 | 151 | if(oggpack_read(&opb,1)!=0){ |
michael@0 | 152 | /* Oops. This is not an audio data packet */ |
michael@0 | 153 | return(OV_ENOTAUDIO); |
michael@0 | 154 | } |
michael@0 | 155 | |
michael@0 | 156 | { |
michael@0 | 157 | int modebits=0; |
michael@0 | 158 | int v=ci->modes; |
michael@0 | 159 | while(v>1){ |
michael@0 | 160 | modebits++; |
michael@0 | 161 | v>>=1; |
michael@0 | 162 | } |
michael@0 | 163 | |
michael@0 | 164 | /* read our mode and pre/post windowsize */ |
michael@0 | 165 | mode=oggpack_read(&opb,modebits); |
michael@0 | 166 | } |
michael@0 | 167 | if(mode==-1)return(OV_EBADPACKET); |
michael@0 | 168 | return(ci->blocksizes[ci->mode_param[mode]->blockflag]); |
michael@0 | 169 | } |
michael@0 | 170 | |
michael@0 | 171 | int vorbis_synthesis_halfrate(vorbis_info *vi,int flag){ |
michael@0 | 172 | /* set / clear half-sample-rate mode */ |
michael@0 | 173 | codec_setup_info *ci=vi->codec_setup; |
michael@0 | 174 | |
michael@0 | 175 | /* right now, our MDCT can't handle < 64 sample windows. */ |
michael@0 | 176 | if(ci->blocksizes[0]<=64 && flag)return -1; |
michael@0 | 177 | ci->halfrate_flag=(flag?1:0); |
michael@0 | 178 | return 0; |
michael@0 | 179 | } |
michael@0 | 180 | |
michael@0 | 181 | int vorbis_synthesis_halfrate_p(vorbis_info *vi){ |
michael@0 | 182 | codec_setup_info *ci=vi->codec_setup; |
michael@0 | 183 | return ci->halfrate_flag; |
michael@0 | 184 | } |