summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjstebbins <[email protected]>2012-05-01 10:05:53 +0000
committerjstebbins <[email protected]>2012-05-01 10:05:53 +0000
commit2e8be70b9910c62d8d8cb693f8c58485efbf4e97 (patch)
treeb1bccf23e518790e29948fcf11503b6cf79fc0ae
parent4dcf3fcfd9aaeca7fe7ec06ff8c0c6b2d5d3c198 (diff)
libhb: fix problem with incorrect addition of audio silence
sync needs the precise duration of a frame of audio and has no way to compute it for passthru audio. So add a duration member to hb_buffer_t and set it in the audio decoders. This should eventually supersede hb_buffer_t member "stop" since it provides redundant information. git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@4618 b64f7644-9d1e-0410-96f1-a4d463321fa5
-rw-r--r--libhb/deca52.c2
-rw-r--r--libhb/decavcodec.c5
-rw-r--r--libhb/decdca.c5
-rw-r--r--libhb/declpcm.c1
-rw-r--r--libhb/internal.h1
-rw-r--r--libhb/sync.c10
6 files changed, 21 insertions, 3 deletions
diff --git a/libhb/deca52.c b/libhb/deca52.c
index 1f05cc829..09eb88101 100644
--- a/libhb/deca52.c
+++ b/libhb/deca52.c
@@ -265,6 +265,7 @@ static hb_buffer_t * Decode( hb_work_object_t * w )
buf = hb_buffer_init( size );
memcpy( buf->data, pv->frame, size );
buf->s.start = pts;
+ buf->s.duration = frame_dur;
pts += frame_dur;
buf->s.stop = pts;
pv->next_expected_pts = pts;
@@ -289,6 +290,7 @@ static hb_buffer_t * Decode( hb_work_object_t * w )
/* 6 blocks per frame, 256 samples per block, channelsused channels */
buf = hb_buffer_init( 6 * 256 * pv->out_discrete_channels * sizeof( float ) );
buf->s.start = pts;
+ buf->s.duration = frame_dur;
pts += frame_dur;
buf->s.stop = pts;
pv->next_expected_pts = pts;
diff --git a/libhb/decavcodec.c b/libhb/decavcodec.c
index bb7c4c3c3..45239a29c 100644
--- a/libhb/decavcodec.c
+++ b/libhb/decavcodec.c
@@ -1523,7 +1523,8 @@ static void decodeAudio( hb_audio_t * audio, hb_work_private_t *pv, uint8_t *dat
{
int isamp = av_get_bytes_per_sample( context->sample_fmt );
nsamples = out_size / isamp;
- double pts_next = pv->pts_next + nsamples * pv->duration;
+ double duration = nsamples * pv->duration;
+ double pts_next = pv->pts_next + duration;
// DTS-HD can be passed through to mkv
if( audio->config.out.codec & HB_ACODEC_PASS_FLAG )
@@ -1536,6 +1537,7 @@ static void decodeAudio( hb_audio_t * audio, hb_work_private_t *pv, uint8_t *dat
buf = hb_buffer_init( avp.size );
memcpy( buf->data, avp.data, avp.size );
buf->s.start = pv->pts_next;
+ buf->s.duration = duration;
buf->s.stop = pts_next;
hb_list_add( pv->list, buf );
pv->pts_next = pts_next;
@@ -1576,6 +1578,7 @@ static void decodeAudio( hb_audio_t * audio, hb_work_private_t *pv, uint8_t *dat
hb_buffer_t * buf;
buf = downmixAudio( audio, pv, buffer, context->channels, nsamples );
buf->s.start = pv->pts_next;
+ buf->s.duration = duration;
buf->s.stop = pts_next;
hb_list_add( pv->list, buf );
diff --git a/libhb/decdca.c b/libhb/decdca.c
index 5bc118007..49fb3ecae 100644
--- a/libhb/decdca.c
+++ b/libhb/decdca.c
@@ -235,6 +235,7 @@ static hb_buffer_t * Decode( hb_work_object_t * w )
buf = hb_buffer_init( pv->size );
memcpy( buf->data, pv->frame, pv->size );
buf->s.start = pts;
+ buf->s.duration = frame_dur;
pv->next_pts = pts + frame_dur;
buf->s.stop = pv->next_pts;
pv->sync = 0;
@@ -249,10 +250,12 @@ static hb_buffer_t * Decode( hb_work_object_t * w )
/* num_blocks blocks per frame, 256 samples per block, channelsused channels */
int nsamp = num_blocks * 256;
+ frame_dur = (double)nsamp / (double)pv->rate * 90000.;
buf = hb_buffer_init( nsamp * pv->out_discrete_channels * sizeof( float ) );
buf->s.start = pts;
- pv->next_pts = pts + (double)nsamp / (double)pv->rate * 90000.;
+ buf->s.duration = frame_dur;
+ pv->next_pts = pts + frame_dur;
buf->s.stop = pv->next_pts;
for( i = 0; i < num_blocks; i++ )
diff --git a/libhb/declpcm.c b/libhb/declpcm.c
index 6a7cbe56c..98ecc7fc7 100644
--- a/libhb/declpcm.c
+++ b/libhb/declpcm.c
@@ -219,6 +219,7 @@ static hb_buffer_t *Decode( hb_work_object_t *w )
out = hb_buffer_init( pv->samples * sizeof( float ) );
out->s.start = pv->next_pts;
+ out->s.duration = pv->duration;
pv->next_pts += pv->duration;
out->s.stop = pv->next_pts;
diff --git a/libhb/internal.h b/libhb/internal.h
index 0d6ee2776..4c2c6e2a9 100644
--- a/libhb/internal.h
+++ b/libhb/internal.h
@@ -73,6 +73,7 @@ struct hb_buffer_s
int id; // ID of the track that the packet comes from
int64_t start; // start time of frame
+ double duration; // Actual duration, may be fractional ticks
int64_t stop; // stop time of frame
int64_t renderOffset; // DTS used by b-frame offsets in muxmp4
int64_t pcr;
diff --git a/libhb/sync.c b/libhb/sync.c
index c76cc45d2..1a10e5e5e 100644
--- a/libhb/sync.c
+++ b/libhb/sync.c
@@ -1050,7 +1050,15 @@ static hb_buffer_t * OutputAudioFrame( hb_audio_t *audio, hb_buffer_t *buf,
hb_sync_audio_t *sync )
{
int64_t start = (int64_t)sync->next_start;
- double duration = buf->s.stop - buf->s.start;
+
+ // Can't count of buf->s.stop - buf->s.start for accurate duration
+ // due to integer rounding, so use buf->s.duration when it is set
+ // (which should be always if I didn't miss anything)
+ double duration;
+ if ( buf->s.duration > 0 )
+ duration = buf->s.duration;
+ else
+ duration = buf->s.stop - buf->s.start;
if ( !( audio->config.out.codec & HB_ACODEC_PASS_FLAG ) )
{