changeset 30379:0140d505dd91

Reset the parser on seek. Should fix some cases of audio "blips" after seeking. AC3 is still broken due to the libavcodec parser being broken.
author reimar
date Sun, 24 Jan 2010 15:19:14 +0000
parents 8339bca8e4b4
children 661f6f2b0235
files libmpcodecs/ad_ffmpeg.c libmpdemux/demuxer.c
diffstat 2 files changed, 24 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/libmpcodecs/ad_ffmpeg.c	Sun Jan 24 15:16:39 2010 +0000
+++ b/libmpcodecs/ad_ffmpeg.c	Sun Jan 24 15:19:14 2010 +0000
@@ -153,6 +153,7 @@
     switch(cmd){
     case ADCTRL_RESYNC_STREAM:
         avcodec_flush_buffers(lavc_context);
+        ds_clear_parser(sh->ds);
     return CONTROL_TRUE;
     }
     return CONTROL_UNKNOWN;
--- a/libmpdemux/demuxer.c	Sun Jan 24 15:16:39 2010 +0000
+++ b/libmpdemux/demuxer.c	Sun Jan 24 15:19:14 2010 +0000
@@ -60,6 +60,7 @@
 // just be removed again.
 #define PARSE_ON_ADD 0
 
+static void clear_parser(sh_common_t *sh);
 void resync_video_stream(sh_video_t *sh_video);
 void resync_audio_stream(sh_audio_t *sh_audio);
 
@@ -286,8 +287,7 @@
 #endif
     free(sh->lang);
 #ifdef CONFIG_LIBAVCODEC
-    av_parser_close(sh->parser);
-    av_freep(&sh->avctx);
+    clear_parser((sh_common_t *)sh);
 #endif
     free(sh);
 }
@@ -327,8 +327,7 @@
     free(sh->codecdata);
     free(sh->lang);
 #ifdef CONFIG_LIBAVCODEC
-    av_parser_close(sh->parser);
-    av_freep(&sh->avctx);
+    clear_parser((sh_common_t *)sh);
 #endif
     free(sh);
 }
@@ -359,8 +358,7 @@
     mp_msg(MSGT_DEMUXER, MSGL_DBG2, "DEMUXER: freeing sh_video at %p\n", sh);
     free(sh->bih);
 #ifdef CONFIG_LIBAVCODEC
-    av_parser_close(sh->parser);
-    av_freep(&sh->avctx);
+    clear_parser((sh_common_t *)sh);
 #endif
     free(sh);
 }
@@ -510,6 +508,20 @@
         return *len;
     return av_parser_parse2(parser, avctx, buffer, len, *buffer, *len, pts, pts, pos);
 }
+
+static void clear_parser(sh_common_t *sh)
+{
+    av_parser_close(sh->parser);
+    sh->parser = NULL;
+    av_freep(&sh->avctx);
+}
+
+void ds_clear_parser(demux_stream_t *ds)
+{
+    if (!ds->sh)
+        return;
+    clear_parser(ds->sh);
+}
 #endif
 
 void ds_add_packet(demux_stream_t *ds, demux_packet_t *dp)
@@ -1200,6 +1212,11 @@
 
 void demux_flush(demuxer_t *demuxer)
 {
+#if PARSE_ON_ADD
+    ds_clear_parser(demuxer->video);
+    ds_clear_parser(demuxer->audio);
+    ds_clear_parser(demuxer->sub);
+#endif
     ds_free_packs(demuxer->video);
     ds_free_packs(demuxer->audio);
     ds_free_packs(demuxer->sub);