summaryrefslogtreecommitdiffstats
path: root/mencoder.c
diff options
context:
space:
mode:
authorods15 <ods15@b3059339-0415-0410-9bf9-f77b7e298cf2>2005-07-17 19:27:27 +0000
committerods15 <ods15@b3059339-0415-0410-9bf9-f77b7e298cf2>2005-07-17 19:27:27 +0000
commit78600ea9bc1bf62ee4484a8c05ef3b2372373fa7 (patch)
tree87aaa778746bb027468e6a90d5ea284a02a2e463 /mencoder.c
parent275beee96ffef08db9062c3e1b0066723deee31b (diff)
downloadmpv-78600ea9bc1bf62ee4484a8c05ef3b2372373fa7.tar.bz2
mpv-78600ea9bc1bf62ee4484a8c05ef3b2372373fa7.tar.xz
-delay for MEncoder, step 4.
git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@15996 b3059339-0415-0410-9bf9-f77b7e298cf2
Diffstat (limited to 'mencoder.c')
-rw-r--r--mencoder.c56
1 files changed, 33 insertions, 23 deletions
diff --git a/mencoder.c b/mencoder.c
index dc79c37dd8..0d49c8c49f 100644
--- a/mencoder.c
+++ b/mencoder.c
@@ -242,6 +242,10 @@ typedef struct {
/// Returns a_pts
static float calc_a_pts(demux_stream_t *d_audio);
+/** \brief Seeks audio forward to pts by dumping audio packets
+ \return The current audio pts.
+*/
+static float forward_audio(float pts, demux_stream_t *d_audio, muxer_stream_t* mux_a);
#ifdef USE_EDL
#include "edl.h"
@@ -1618,13 +1622,39 @@ static float calc_a_pts(demux_stream_t *d_audio) {
return a_pts;
}
+static float forward_audio(float pts, demux_stream_t *d_audio, muxer_stream_t* mux_a) {
+ sh_audio_t * sh_audio = d_audio ? d_audio->sh : NULL;
+ int samplesize, avg;
+ float a_pts = calc_a_pts(d_audio);
+
+ if (!sh_audio) return a_pts;
+
+ if (sh_audio->audio.dwScale) samplesize = sh_audio->audio.dwSampleSize;
+ else samplesize = (sh_audio->wf ? sh_audio->wf->nBlockAlign : 1);
+ avg = (sh_audio->wf ? sh_audio->wf->nAvgBytesPerSec : sh_audio->i_bps);
+
+ while (pts > a_pts) {
+ int len;
+ if (samplesize) {
+ len = avg * (pts - a_pts > 0.5 ? 0.5 : pts - a_pts);
+ len/= samplesize; if(len<1) len=1;
+ len*= samplesize;
+ len = demux_read_data(sh_audio->ds,mux_a->buffer,len);
+ } else {
+ unsigned char * crap;
+ len = ds_get_packet(sh_audio->ds, &crap);
+ }
+ if (len <= 0) break; // EOF of audio.
+ a_pts = calc_a_pts(d_audio);
+ }
+ return a_pts;
+}
+
#ifdef USE_EDL
static int edl_seek(edl_record_ptr next_edl_record, demuxer_t* demuxer, demux_stream_t *d_audio, muxer_stream_t* mux_a, s_frame_data * frame_data, int framecopy) {
- sh_audio_t * sh_audio = d_audio->sh;
sh_video_t * sh_video = demuxer->video ? demuxer->video->sh : NULL;
vf_instance_t * vfilter = sh_video ? sh_video->vfilter : NULL;
int done = 0;
- int samplesize, avg;
if (!sh_video) return 0;
if (sh_video->pts >= next_edl_record->stop_sec) return 1; // nothing to do...
@@ -1643,10 +1673,6 @@ static int edl_seek(edl_record_ptr next_edl_record, demuxer_t* demuxer, demux_st
// slow seek, read every frame.
- if (sh_audio->audio.dwScale) samplesize = sh_audio->audio.dwSampleSize;
- else samplesize = (sh_audio->wf ? sh_audio->wf->nBlockAlign : 1);
- avg = (sh_audio->wf ? sh_audio->wf->nAvgBytesPerSec : sh_audio->i_bps);
-
while (!interrupted) {
float a_pts = 0.;
@@ -1654,23 +1680,7 @@ static int edl_seek(edl_record_ptr next_edl_record, demuxer_t* demuxer, demux_st
if(frame_data->in_size<0) return 2;
sh_video->timer += frame_data->frame_time;
- if (sh_audio) {
- a_pts = calc_a_pts(d_audio);
- while (sh_video->pts - frame_data->frame_time > a_pts) {
- int len;
- if (samplesize) {
- len = avg * (sh_video->pts - frame_data->frame_time - a_pts);
- len/= samplesize; if(len<1) len=1;
- len*= samplesize;
- len = demux_read_data(sh_audio->ds,mux_a->buffer,len);
- } else {
- unsigned char * crap;
- len = ds_get_packet(sh_audio->ds, &crap);
- }
- if (len <= 0) break; // EOF of audio.
- a_pts = calc_a_pts(d_audio);
- }
- }
+ a_pts = forward_audio(sh_video->pts - frame_data->frame_time, d_audio, mux_a);
if (done) {
frame_data->already_read = 1;