summaryrefslogtreecommitdiffstats
path: root/libhb
diff options
context:
space:
mode:
authorjstebbins <[email protected]>2013-01-21 22:11:14 +0000
committerjstebbins <[email protected]>2013-01-21 22:11:14 +0000
commit35c85b5d02ba6e334192d2977c789d1b7e23e35b (patch)
tree8445c9395397ffb61c7b94dda5aabdf4836075e7 /libhb
parenta5691e14fd8176f640119c9b1134e4850997abd0 (diff)
libhb: Fix issue with silence insertion when using FLAC encoder
When we insert silence to maintain sync, we typically need to insert about 70ms. But the default flac frame duration is very large (>=96ms). This is causing us to overshoot the target and we immediately drop a frame. Dropping a frame undershoots and we insert a frame... ad infinitum. This patch changes the behavior of silence insertion for non-passthru audio. Instead of inserting full frames of silence, the last "frame" inserted may be a partial. This lets us insert a finer grained silence duration and eliminates the problem with large flac frames. git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@5188 b64f7644-9d1e-0410-96f1-a4d463321fa5
Diffstat (limited to 'libhb')
-rw-r--r--libhb/sync.c25
1 files changed, 20 insertions, 5 deletions
diff --git a/libhb/sync.c b/libhb/sync.c
index 5ad5bfedb..444f2f98b 100644
--- a/libhb/sync.c
+++ b/libhb/sync.c
@@ -1162,7 +1162,7 @@ static void InsertSilence( hb_work_object_t * w, int64_t duration )
hb_sync_audio_t *sync = &pv->type.audio;
hb_buffer_t *buf;
hb_fifo_t *fifo;
- int frame_dur, frame_count;
+ int frame_dur;
// to keep pass-thru and regular audio in sync we generate silence in
// frame-sized units. If the silence duration isn't an integer multiple
@@ -1178,9 +1178,8 @@ static void InsertSilence( hb_work_object_t * w, int64_t duration )
frame_dur = ( 90000 * w->audio->config.out.samples_per_frame ) /
w->audio->config.in.samplerate;
}
- frame_count = ( duration + (frame_dur >> 1) ) / frame_dur;
- while ( --frame_count >= 0 )
+ while (duration >= frame_dur >> 2)
{
if( w->audio->config.out.codec & HB_ACODEC_PASS_FLAG )
{
@@ -1189,15 +1188,31 @@ static void InsertSilence( hb_work_object_t * w, int64_t duration )
buf->s.stop = buf->s.start + frame_dur;
memcpy( buf->data, sync->silence_buf, buf->size );
fifo = w->audio->priv.fifo_out;
+ duration -= frame_dur;
}
else
{
- buf = hb_buffer_init( sizeof( float ) * w->audio->config.out.samples_per_frame *
- hb_mixdown_get_discrete_channel_count( w->audio->config.out.mixdown ) );
+ int channel_count = hb_mixdown_get_discrete_channel_count( w->audio->config.out.mixdown );
+ int size = sizeof( float ) *
+ w->audio->config.out.samples_per_frame *
+ channel_count;
+ if (frame_dur > duration)
+ {
+ int samples = duration * w->audio->config.in.samplerate / 90000;
+ if (samples == 0)
+ {
+ break;
+ }
+ size = sizeof(float) * samples * channel_count;
+ frame_dur = (90000 * samples) / w->audio->config.in.samplerate;
+ }
+ buf = hb_buffer_init(size);
buf->s.start = sync->next_start;
+ buf->s.duration = frame_dur;
buf->s.stop = buf->s.start + frame_dur;
memset( buf->data, 0, buf->size );
fifo = w->audio->priv.fifo_sync;
+ duration -= frame_dur;
}
buf = OutputAudioFrame( w->audio, buf, sync );
hb_fifo_push( fifo, buf );