- out_size = sizeof(buffer);
- uncompressed_len = avcodec_decode_audio2( pv->context, buffer,
- &out_size,
- parser_output_buffer,
- parser_output_buffer_len );
- }
- if( out_size )
- {
- short * s16;
- float * fl32;
-
- buf = hb_buffer_init( 2 * out_size );
-
- int sample_size_in_bytes = 2; // Default to 2 bytes
- switch (pv->context->sample_fmt)
- {
- case SAMPLE_FMT_S16:
- sample_size_in_bytes = 2;
- break;
- /* We should handle other formats here - but that needs additional format conversion work below */
- /* For now we'll just report the error and try to carry on */
- default:
- hb_log("decavcodecWork - Unknown Sample Format from avcodec_decode_audio (%d) !", pv->context->sample_fmt);
- break;
- }
-
- buf->start = cur;
- buf->stop = cur + 90000 * ( out_size / (sample_size_in_bytes * pv->context->channels) ) /
- pv->context->sample_rate;
- cur = buf->stop;
-
- s16 = buffer;
- fl32 = (float *) buf->data;
- for( i = 0; i < out_size / 2; i++ )
- {
- fl32[i] = s16[i];
- }
-
- if( last )
- {
- last = last->next = buf;
- }
- else
+ // set the duration on every frame since the stream format can
+ // change (it shouldn't but there's no way to guarantee it).
+ // duration is a scaling factor to go from #bytes in the decoded
+ // frame to frame time (in 90KHz mpeg ticks). 'channels' converts
+ // total samples to per-channel samples. 'sample_rate' converts
+ // per-channel samples to seconds per sample and the 90000
+ // is mpeg ticks per second.
+ if ( pv->context->sample_rate && pv->context->channels )