MCPcopy Create free account
hub / github.com/HandBrake/HandBrake / Flush

Function Flush

libhb/encvorbis.c:179–211  ·  view source on GitHub ↗

* Flush *********************************************************************** * **********************************************************************/

Source from the content-addressed store, hash-verified

177 *
178 **********************************************************************/
179static hb_buffer_t * Flush( hb_work_object_t * w )
180{
181 hb_work_private_t * pv = w->private_data;
182 hb_buffer_t * buf;
183 int64_t blocksize = 0;
184
185 if( vorbis_analysis_blockout( &pv->vd, &pv->vb ) == 1 )
186 {
187 ogg_packet op;
188
189 vorbis_analysis( &pv->vb, NULL );
190 vorbis_bitrate_addblock( &pv->vb );
191
192 if( vorbis_bitrate_flushpacket( &pv->vd, &op ) )
193 {
194 buf = hb_buffer_init( op.bytes );
195 memcpy( buf->data, op.packet, op.bytes );
196 blocksize = vorbis_packet_blocksize(&pv->vi, &op);
197
198 buf->s.type = AUDIO_BUF;
199 buf->s.frametype = HB_FRAME_AUDIO;
200
201 buf->s.start = (int64_t)(vorbis_granule_time(&pv->vd, op.granulepos) * 90000);
202 buf->s.stop = (int64_t)(vorbis_granule_time(&pv->vd, (pv->prev_blocksize + blocksize)/4 + op.granulepos) * 90000);
203 buf->s.duration = buf->s.stop - buf->s.start;
204 /* The stop time isn't accurate for the first ~3 packets, as the actual blocksize depends on the previous _and_ current packets. */
205 pv->prev_blocksize = blocksize;
206 return buf;
207 }
208 }
209
210 return NULL;
211}
212
213/***********************************************************************
214 * Encode

Callers 1

EncodeFunction · 0.70

Calls 1

hb_buffer_initFunction · 0.85

Tested by

no test coverage detected