[MPlayer-cvslog] r29712 - in trunk: mencoder.c mp_osd.h mpcommon.c mpcommon.h mplayer.c

reimar subversion at mplayerhq.hu
Wed Sep 23 23:48:48 CEST 2009


Author: reimar
Date: Wed Sep 23 23:48:48 2009
New Revision: 29712

Log:
Add support for displaying subtitles on the command-line when playing
audio-only files.

Modified:
   trunk/mencoder.c
   trunk/mp_osd.h
   trunk/mpcommon.c
   trunk/mpcommon.h
   trunk/mplayer.c

Modified: trunk/mencoder.c
==============================================================================
--- trunk/mencoder.c	Wed Sep 23 23:27:36 2009	(r29711)
+++ trunk/mencoder.c	Wed Sep 23 23:48:48 2009	(r29712)
@@ -218,6 +218,12 @@ void mplayer_put_key(int code)
 char *current_module;
 #include "mpcommon.h"
 
+// Needed by mpcommon.c
+void set_osd_subtitle(subtitle *subs) {
+    vo_sub = subs;
+    vo_osd_changed(OSDTYPE_SUBTITLE);
+}
+
 //char *out_audio_codec=NULL; // override audio codec
 //char *out_video_codec=NULL; // override video codec
 

Modified: trunk/mp_osd.h
==============================================================================
--- trunk/mp_osd.h	Wed Sep 23 23:27:36 2009	(r29711)
+++ trunk/mp_osd.h	Wed Sep 23 23:48:48 2009	(r29712)
@@ -11,6 +11,7 @@
 #define OSD_MSG_RADIO_CHANNEL           7
 /// Base id for messages generated from the commmand to property bridge.
 #define OSD_MSG_PROPERTY                0x100
+#define OSD_MSG_SUB_BASE                0x1000
 
 #define MAX_OSD_LEVEL 3
 #define MAX_TERM_OSD_LEVEL 1

Modified: trunk/mpcommon.c
==============================================================================
--- trunk/mpcommon.c	Wed Sep 23 23:27:36 2009	(r29711)
+++ trunk/mpcommon.c	Wed Sep 23 23:48:48 2009	(r29712)
@@ -75,8 +75,7 @@ void update_subtitles(sh_video_t *sh_vid
     if (reset) {
         sub_clear_text(&subs, MP_NOPTS_VALUE);
         if (vo_sub) {
-            vo_sub = NULL;
-            vo_osd_changed(OSDTYPE_SUBTITLE);
+            set_osd_subtitle(NULL);
         }
         if (vo_spudec) {
             spudec_reset(vo_spudec);
@@ -145,7 +144,6 @@ void update_subtitles(sh_video_t *sh_vid
     } else if (dvdsub_id >= 0 && (type == 't' || type == 'm' || type == 'a')) {
         double curpts = refpts + sub_delay;
         double endpts;
-        vo_sub = &subs;
         while (d_dvdsub->first) {
             double subpts = ds_get_next_pts(d_dvdsub);
             if (subpts > curpts)
@@ -167,7 +165,6 @@ void update_subtitles(sh_video_t *sh_vid
                                       (long long)(subpts*1000 + 0.5),
                                       (long long)((endpts-subpts)*1000 + 0.5));
                 } else { // plaintext subs with libass
-                    vo_sub = NULL;
                     if (subpts != MP_NOPTS_VALUE) {
                         if (endpts == MP_NOPTS_VALUE) endpts = subpts + 3;
                         sub_clear_text(&subs, MP_NOPTS_VALUE);
@@ -195,11 +192,11 @@ void update_subtitles(sh_video_t *sh_vid
                     packet = p;
                 }
                 sub_add_text(&subs, packet, len, endpts);
-                vo_osd_changed(OSDTYPE_SUBTITLE);
+                set_osd_subtitle(&subs);
             }
         }
         if (sub_clear_text(&subs, curpts))
-            vo_osd_changed(OSDTYPE_SUBTITLE);
+            set_osd_subtitle(&subs);
     }
     current_module=NULL;
 }

Modified: trunk/mpcommon.h
==============================================================================
--- trunk/mpcommon.h	Wed Sep 23 23:27:36 2009	(r29711)
+++ trunk/mpcommon.h	Wed Sep 23 23:48:48 2009	(r29712)
@@ -13,6 +13,7 @@ void print_version(const char* name);
 void update_subtitles(sh_video_t *sh_video, double refpts, demux_stream_t *d_dvdsub, int reset);
 void update_teletext(sh_video_t *sh_video, demuxer_t *demuxer, int reset);
 int select_audio(demuxer_t* demuxer, int audio_id, char* audio_lang);
+void set_osd_subtitle(subtitle *subs);
 
 extern int disable_system_conf;
 extern int disable_user_conf;

Modified: trunk/mplayer.c
==============================================================================
--- trunk/mplayer.c	Wed Sep 23 23:27:36 2009	(r29711)
+++ trunk/mplayer.c	Wed Sep 23 23:48:48 2009	(r29712)
@@ -1507,6 +1507,26 @@ void set_osd_bar(int type,const char* na
                 name,ROUND(100*(val-min)/(max-min)));
 }
 
+/**
+ * \brief Display text subtitles on the OSD
+ */
+void set_osd_subtitle(subtitle *subs) {
+    int i;
+    vo_sub = subs;
+    vo_osd_changed(OSDTYPE_SUBTITLE);
+    if (!mpctx->sh_video) {
+        // reverse order, since newest set_osd_msg is displayed first
+        for (i = SUB_MAX_TEXT - 1; i >= 0; i--) {
+            if (!subs || i >= subs->lines || !subs->text[i])
+                rm_osd_msg(OSD_MSG_SUB_BASE + i);
+            else {
+                // HACK: currently display time for each sub line except the last is set to 2 seconds.
+                int display_time = i == subs->lines - 1 ? 180000 : 2000;
+                set_osd_msg(OSD_MSG_SUB_BASE + i, 1, display_time, "%s", subs->text[i]);
+            }
+        }
+    }
+}
 
 /**
  * \brief Update the OSD message line.
@@ -2492,6 +2512,8 @@ static int seek(MPContext *mpctx, double
 	mpctx->audio_out->reset(); // stop audio, throwing away buffered data
 	mpctx->sh_audio->a_buffer_len = 0;
 	mpctx->sh_audio->a_out_buffer_len = 0;
+	if (!mpctx->sh_video)
+	    update_subtitles(NULL, mpctx->sh_audio->pts, mpctx->d_sub, 1);
     }
 
     if (vo_vobsub && mpctx->sh_video) {
@@ -3704,6 +3726,7 @@ if(!mpctx->sh_video) {
 
   if(end_at.type == END_AT_TIME && end_at.pos < a_pos)
     mpctx->eof = PT_NEXT_ENTRY;
+  update_subtitles(NULL, mpctx->sh_audio->pts, mpctx->d_sub, 0);
   update_osd_msg();
 
 } else {


More information about the MPlayer-cvslog mailing list