changeset 25654:0190aa38aae2

Init and destroy ass_tracks in demuxer.c based on sh_sub->type value.
author eugeni
date Fri, 11 Jan 2008 21:45:15 +0000
parents ec6e8ea85a87
children e98ceb0190c1
files libmpdemux/demux_mkv.c libmpdemux/demuxer.c
diffstat 2 files changed, 19 insertions(+), 40 deletions(-) [+]
line wrap: on
line diff
--- a/libmpdemux/demux_mkv.c	Fri Jan 11 21:45:13 2008 +0000
+++ b/libmpdemux/demux_mkv.c	Fri Jan 11 21:45:15 2008 +0000
@@ -956,10 +956,6 @@
     free (track->audio_buf);
   if (track->audio_timestamp)
     free (track->audio_timestamp);
-#ifdef USE_ASS
-  if (track->sh_sub && track->sh_sub->ass_track)
-    ass_free_track (track->sh_sub->ass_track);
-#endif
   demux_mkv_free_encodings(track->encodings, track->num_encodings);
   free(track);
 }
@@ -2254,38 +2250,6 @@
     }
 }
 
-/** \brief Parse the private data for SSA/ASS subtitle tracks.
-
-  This function tries to parse the private data for all SSA/ASS tracks.
-  The private data contains the normal text from the original script,
-  from the start to the beginning of 'Events' section, including '[Events]' line.
-
-  \param demuxer The generic demuxer.
-*/
-#ifdef USE_ASS
-static void
-demux_mkv_parse_ass_data (demuxer_t *demuxer)
-{
-  mkv_demuxer_t *mkv_d = (mkv_demuxer_t *) demuxer->priv;
-  mkv_track_t *track;
-  int i;
-
-  for (i = 0; i < mkv_d->num_tracks; i++)
-    {
-      track = mkv_d->tracks[i];
-      if (track->type != MATROSKA_TRACK_SUBTITLE ||
-          track->subtitle_type == MATROSKA_SUBTYPE_VOBSUB)
-        continue;
-
-      if (track->subtitle_type == MATROSKA_SUBTYPE_SSA)
-        {
-          track->sh_sub->ass_track = ass_new_track(ass_library);
-          ass_process_codec_private(track->sh_sub->ass_track, track->private_data, track->private_size);
-        }
-    }
-}
-#endif
-
 static int
 demux_mkv_open_sub (demuxer_t *demuxer, mkv_track_t *track, int sid)
 {
@@ -2549,10 +2513,7 @@
     }
 
   demux_mkv_parse_vobsub_data (demuxer);
-#ifdef USE_ASS
-  if (ass_enabled)
-    demux_mkv_parse_ass_data (demuxer);
-#endif
+
   /* DO NOT automatically select a subtitle track and behave like DVD */
   /* playback: only show subtitles if the user explicitely wants them. */
   track = NULL;
--- a/libmpdemux/demuxer.c	Fri Jan 11 21:45:13 2008 +0000
+++ b/libmpdemux/demuxer.c	Fri Jan 11 21:45:15 2008 +0000
@@ -22,6 +22,11 @@
 
 #include "libaf/af_format.h"
 
+#ifdef USE_ASS
+#include "libass/ass.h"
+#include "libass/ass_mp.h"
+#endif
+
 extern void resync_video_stream(sh_video_t *sh_video);
 extern void resync_audio_stream(sh_audio_t *sh_audio);
 
@@ -239,6 +244,7 @@
 void free_sh_sub(sh_sub_t *sh) {
     mp_msg(MSGT_DEMUXER, MSGL_DBG2, "DEMUXER: freeing sh_sub at %p\n", sh);
     if (sh->extradata) free(sh->extradata);
+    if (sh->ass_track) ass_free_track(sh->ass_track);
     free(sh);
 }
 
@@ -813,6 +819,18 @@
     sh_video->i_bps*0.008f,
     sh_video->i_bps/1024.0f );
 }
+#ifdef USE_ASS
+ if (ass_enabled && ass_library) {
+   for (i = 0; i < MAX_S_STREAMS; ++i) {
+     sh_sub_t* sh = demuxer->s_streams[i];
+     if (sh && sh->type == 'a') {
+       sh->ass_track = ass_new_track(ass_library);
+       if (sh->ass_track && sh->extradata)
+         ass_process_codec_private(sh->ass_track, sh->extradata, sh->extradata_len);
+     }
+   }
+ }
+#endif
 return demuxer;
 }