[MPlayer-cvslog] r22155 - in trunk: libmpdemux/demux_mkv.c libmpdemux/demuxer.h mplayer.c

reimar subversion at mplayerhq.hu
Mon Feb 5 19:25:30 CET 2007


Author: reimar
Date: Mon Feb  5 19:25:28 2007
New Revision: 22155

Modified:
   trunk/libmpdemux/demux_mkv.c
   trunk/libmpdemux/demuxer.h
   trunk/mplayer.c

Log:
Another round of subtitle code cleanup


Modified: trunk/libmpdemux/demux_mkv.c
==============================================================================
--- trunk/libmpdemux/demux_mkv.c	(original)
+++ trunk/libmpdemux/demux_mkv.c	Mon Feb  5 19:25:28 2007
@@ -166,8 +166,6 @@
   uint64_t tc_scale, cluster_tc, first_tc;
   int has_first_tc;
 
-  subtitle subs;
-
   uint64_t cluster_size;
   uint64_t blockgroup_size;
 
@@ -523,7 +521,6 @@
     return 0;
   memcpy(buf, t->private_data, t->private_size);
   buf[t->private_size] = 0;
-  t->sh_sub.type = 'v';
   t->sh_sub.has_palette = 0;
 
   pos = buf;
@@ -2376,8 +2373,6 @@
           track->subtitle_type == MATROSKA_SUBTYPE_VOBSUB)
         continue;
 
-      track->sh_sub.type = 'a';
-
       if (track->subtitle_type == MATROSKA_SUBTYPE_SSA)
         {
           track->sh_sub.ass_track = ass_new_track(ass_library);
@@ -2391,10 +2386,6 @@
             }
           ass_process_codec_private(track->sh_sub.ass_track, track->private_data, track->private_size);
         }
-      else
-        {
-          track->sh_sub.ass_track = ass_default_track(ass_library);
-        }
     }
 }
 #endif
@@ -2405,15 +2396,13 @@
   if (track->subtitle_type != MATROSKA_SUBTYPE_UNKNOWN)
     {
       sh_sub_t *sh = new_sh_sub_sid(demuxer, track->tnum, sid);
-      if ((track->subtitle_type == MATROSKA_SUBTYPE_VOBSUB) ||
-          (track->subtitle_type == MATROSKA_SUBTYPE_SSA))
-        {
-          if (track->private_data != NULL)
-            {
+      track->sh_sub.type = 't';
+      if (track->subtitle_type == MATROSKA_SUBTYPE_VOBSUB)
+        track->sh_sub.type = 'v';
+      if (track->subtitle_type == MATROSKA_SUBTYPE_SSA)
+        track->sh_sub.type = 'a';
               if (sh)
                 memcpy(sh, &track->sh_sub, sizeof(sh_sub_t));
-            }
-        }
     }
   else
     {
@@ -2718,9 +2707,6 @@
 }
 
 static void
-clear_subtitles(demuxer_t *demuxer, uint64_t timecode, int clear_all);
-
-static void
 demux_close_mkv (demuxer_t *demuxer)
 {
   mkv_demuxer_t *mkv_d = (mkv_demuxer_t *) demuxer->priv;
@@ -2731,7 +2717,6 @@
 #ifdef USE_ICONV
       subcp_close();
 #endif
-      clear_subtitles(demuxer, 0, 1);
       free_cached_dps (demuxer);
       if (mkv_d->tracks)
         {
@@ -2853,6 +2838,7 @@
                  int64_t size, uint64_t block_duration, uint64_t timecode)
 {
   mkv_demuxer_t *mkv_d = (mkv_demuxer_t *) demuxer->priv;
+  demux_packet_t *dp;
   char *ptr1;
   int i;
 
@@ -2868,9 +2854,6 @@
     ass_process_chunk(track->sh_sub.ass_track, block, size, (long long)timecode, (long long)block_duration);
     return;
   }
-  // Use code below only to parse this single sub, old subs timed in libass
-  if (ass_enabled)
-      clear_subtitles(demuxer, timecode, 1);
 #endif
 
   ptr1 = block;
@@ -2885,27 +2868,12 @@
     }
 
   sub_utf8 = 1;
-  sub_add_text(&mkv_d->subs, ptr1, size - (ptr1 - block),
-                 (timecode + block_duration) / 1000.0f);
-#ifdef USE_ASS
-  if (ass_enabled) {
-    mkv_d->subs.start = timecode / 10;
-    mkv_d->subs.end = (timecode + block_duration) / 10;
-    ass_process_subtitle(track->sh_sub.ass_track, &mkv_d->subs);
-    return;
-  }
-#endif
-  vo_sub = &mkv_d->subs;
-  vo_osd_changed (OSDTYPE_SUBTITLE);
-}
-
-static void
-clear_subtitles(demuxer_t *demuxer, uint64_t timecode, int clear_all)
-{
-  mkv_demuxer_t *mkv_d = (mkv_demuxer_t *) demuxer->priv;
-  double pts = clear_all ? MP_NOPTS_VALUE : (timecode / 1000.0f);
-  if (sub_clear_text(&mkv_d->subs, pts))
-    vo_osd_changed(OSDTYPE_SUBTITLE);
+  size -= ptr1 - block;
+  dp = new_demux_packet(size);
+  memcpy(dp->buffer, ptr1, size);
+  dp->pts = timecode / 1000.0f;
+  dp->endpts = (timecode + block_duration) / 1000.0f;
+  ds_add_packet(demuxer->sub, dp);
 }
 
 // Taken from demux_real.c. Thanks to the original developpers :)
@@ -3241,8 +3209,6 @@
   }
   current_pts = tc / 1000.0;
 
-  clear_subtitles(demuxer, tc, 0);
-
   for (i=0; i<mkv_d->num_tracks; i++)
     if (mkv_d->tracks[i]->tnum == num) {
       track = mkv_d->tracks[i];
@@ -3628,10 +3594,6 @@
         mkv_d->skip_to_timecode = target_timecode;
       mkv_d->a_skip_to_keyframe = 1;
 
-      /* Clear subtitles. */
-      if (target_timecode <= mkv_d->last_pts * 1000)
-        clear_subtitles(demuxer, 0, 1);
-
       demux_mkv_fill_buffer(demuxer, NULL);
     }
   else if ((demuxer->movi_end <= 0) || !(flags & 1))
@@ -3670,10 +3632,6 @@
       mkv_d->skip_to_timecode = index->timecode;
       mkv_d->a_skip_to_keyframe = 1;
 
-      /* Clear subtitles. */
-      if (index->timecode <= mkv_d->last_pts * 1000)
-        clear_subtitles(demuxer, 0, 1);
-
       demux_mkv_fill_buffer(demuxer, NULL);
     }
 }

Modified: trunk/libmpdemux/demuxer.h
==============================================================================
--- trunk/libmpdemux/demuxer.h	(original)
+++ trunk/libmpdemux/demuxer.h	Mon Feb  5 19:25:28 2007
@@ -85,6 +85,7 @@
 typedef struct demux_packet_st {
   int len;
   double pts;
+  double endpts;
   double stream_pts;
   off_t pos;  // position in index (AVI) or file (MPG)
   unsigned char* buffer;
@@ -212,6 +213,7 @@
   // still using 0 by default in case there is some code that uses 0 for both
   // unknown and a valid pts value
   dp->pts=correct_pts ? MP_NOPTS_VALUE : 0;
+  dp->endpts=MP_NOPTS_VALUE;
   dp->stream_pts = MP_NOPTS_VALUE;
   dp->pos=0;
   dp->flags=0;

Modified: trunk/mplayer.c
==============================================================================
--- trunk/mplayer.c	(original)
+++ trunk/mplayer.c	Mon Feb  5 19:25:28 2007
@@ -2899,6 +2899,11 @@
     unsigned char *packet=NULL;
     int len;
     char type = d_dvdsub->sh ? ((sh_sub_t *)d_dvdsub->sh)->type : 'v';
+    if (type == 'a')
+#ifdef USE_ASS
+      if (!ass_enabled)
+#endif
+      type = 't';
     // find sub
     if (subdata) {
 	double pts = sh_video->pts;
@@ -2959,21 +2964,43 @@
 	if (spudec_changed(vo_spudec))
 	    vo_osd_changed(OSDTYPE_SPU);
     } else if (dvdsub_id >= 0 && type == 't') {
+      static subtitle subs;
+      double curpts = sh_video->pts + sub_delay;
       double pts = MP_NOPTS_VALUE;
+      double endpts;
+      vo_sub = &subs;
       while (d_dvdsub->first) {
         double nextpts = ds_get_next_pts(d_dvdsub);
-        if (nextpts == MP_NOPTS_VALUE || nextpts - sub_delay > sh_video->pts)
+        if (nextpts == MP_NOPTS_VALUE || nextpts > curpts)
           break;
+        endpts = d_dvdsub->first->endpts;
         len = ds_get_packet_sub(d_dvdsub, &packet);
-        pts = nextpts - sub_delay;
+        pts = nextpts;
       }
+#ifdef USE_ASS
+      if (ass_enabled) {
+        static global_ass_track = NULL;
+        sh_sub_t *sh = (sh_sub_t *)d_dvdsub->sh;
+        if (!global_ass_track) global_ass_track = ass_default_track(ass_library);
+        ass_track = global_ass_track;
+        vo_sub = NULL;
+        if (pts != MP_NOPTS_VALUE) {
+          if (endpts == MP_NOPTS_VALUE) endpts = pts + 3;
+          sub_clear_text(&subs, MP_NOPTS_VALUE);
+          sub_add_text(&subs, packet, len, endpts);
+          subs.start = pts * 100;
+          subs.end = endpts * 100;
+          ass_process_subtitle(ass_track, &subs);
+        }
+      } else
+#endif
       if (pts != MP_NOPTS_VALUE) {
-        static subtitle subs;
+        if (endpts == MP_NOPTS_VALUE)
         sub_clear_text(&subs, MP_NOPTS_VALUE);
-        sub_add_text(&subs, packet, len, MP_NOPTS_VALUE);
-        vo_sub = &subs;
+        sub_add_text(&subs, packet, len, endpts);
+        vo_osd_changed(OSDTYPE_SUBTITLE);
+      } else if (sub_clear_text(&subs, curpts))
         vo_osd_changed(OSDTYPE_SUBTITLE);
-      }
     }
     current_module=NULL;
 }



More information about the MPlayer-cvslog mailing list