Web lists-archives.com

Re: [MPlayer-dev-eng] gui: subtitle menu is not populated when playing from mpg file




I wrote on Tue, 12 Aug 2014 21:04:21 +0200:

> Reimar Döffinger wrote Tue, 12 Aug 2014 20:15:05 +0200:

>> I was just more wondering why it doesn't happen automatically once we
>> got a new subtitle stream, instead of on every read of that variable.

> On getting a new subtitle stream we only have access to the demuxer
> (variable), the global sub stuff is stored whithin the mpctx.
> I could try moving the global sub information to the demuxer, [...]

Although mpctx's global_sub_size is globally accessible, it's basically local
to command.c, i.e. it's being updated only there (in update_global_sub_size()).
Moreover, since it counts all subtitles we won't achieve much (but new
problems) on relocating it to the demuxer just in order to be able to count
the demuxer subtitles. There are file and vob subtitles as well.

The following patch for the global_sub_size issue is bigger and seems more
complicated than the last one, but it is better.

The two mpctx_get_global_sub_*() functions (currently only used by the GUI)
merge into one. The pos is retrieved by a mp_property_do("sub") command which
performs the necessary update of the global_sub-* variables. As a result,
update_global_sub_size() can remain static.

Ingo
Index: access_mpcontext.h
===================================================================
--- access_mpcontext.h	(revision 37251)
+++ access_mpcontext.h	(working copy)
@@ -25,8 +25,7 @@
 void *mpctx_get_demuxer(struct MPContext *mpctx);
 void *mpctx_get_playtree_iter(struct MPContext *mpctx);
 void *mpctx_get_mixer(struct MPContext *mpctx);
-int mpctx_get_global_sub_size(struct MPContext *mpctx);
-int mpctx_get_global_sub_pos(struct MPContext *mpctx);
+void mpctx_get_global_sub_info(struct MPContext *mpctx, int *size, int *pos);
 int mpctx_get_osd_function(struct MPContext *mpctx);
 void *mpctx_get_stream(struct MPContext *mpctx);
 void *mpctx_get_afilter(struct MPContext *mpctx);
Index: mplayer.c
===================================================================
--- mplayer.c	(revision 37251)
+++ mplayer.c	(working copy)
@@ -360,14 +360,13 @@
     return &mpctx->mixer;
 }
 
-int mpctx_get_global_sub_size(MPContext *mpctx)
+void mpctx_get_global_sub_info(MPContext *mpctx, int *size, int *pos)
 {
-    return mpctx->global_sub_size;
-}
+    mp_property_do("sub", M_PROPERTY_GET, pos, mpctx);
 
-int mpctx_get_global_sub_pos(MPContext *mpctx)
-{
-    return mpctx->global_sub_pos;
+    if (size) *size = mpctx->global_sub_size;
+
+    return;
 }
 
 int mpctx_get_osd_function(MPContext *mpctx)
Index: gui/dialog/menu.c
===================================================================
--- gui/dialog/menu.c	(revision 37251)
+++ gui/dialog/menu.c	(working copy)
@@ -462,7 +462,7 @@
  GtkWidget * H, * N, * D, * F;
  demuxer_t *demuxer = mpctx_get_demuxer(guiInfo.mpcontext);
  mixer_t *mixer = mpctx_get_mixer(guiInfo.mpcontext);
- int global_sub_size = mpctx_get_global_sub_size(guiInfo.mpcontext);
+ int subs = 0, sub_pos;
 
  Menu=gtk_menu_new();
  gtk_widget_realize (Menu);
@@ -733,13 +733,15 @@
    }
 
   /* cheap subtitle switching for non-DVD streams */
-  if ( global_sub_size && guiInfo.StreamType != STREAMTYPE_DVD )
+
+  mpctx_get_global_sub_info(guiInfo.mpcontext, &subs, &sub_pos);
+
+  if ( subs && guiInfo.StreamType != STREAMTYPE_DVD )
    {
-    int pos, i, j, subs0 = guiInfo.mpcontext->sub_counts[SUB_SOURCE_SUBS], subs1 = guiInfo.mpcontext->sub_counts[SUB_SOURCE_VOBSUB];
-    pos = mpctx_get_global_sub_pos(guiInfo.mpcontext);
+    int i, j, subs0 = guiInfo.mpcontext->sub_counts[SUB_SOURCE_SUBS], subs1 = guiInfo.mpcontext->sub_counts[SUB_SOURCE_VOBSUB];
     SubMenu=AddSubMenu( window1, (const char*)subtitle_xpm, Menu, MSGTR_GUI_Subtitles );
-    AddMenuCheckItem( window1, (const char*)empty1px_xpm, SubMenu, MSGTR_GUI__none_, pos == -1, (-1 << 16) + ivSetSubtitle );
-    for ( i=0;i < global_sub_size;i++ )
+    AddMenuCheckItem( window1, (const char*)empty1px_xpm, SubMenu, MSGTR_GUI__none_, sub_pos == -1, (-1 << 16) + ivSetSubtitle );
+    for ( i=0;i < subs;i++ )
      {
       int ret = -1;
       char lng[32], tmp[64], *lang = NULL;
@@ -782,7 +784,7 @@
        }
       if ( ret == 0 ) snprintf( tmp, sizeof(tmp), MSGTR_GUI_TrackN" - %s", i, GetLanguage( lng, GET_LANG_CHR ) );
       else snprintf( tmp, sizeof(tmp), MSGTR_GUI_TrackN, i );
-      AddMenuCheckItem( window1,(const char*)empty1px_xpm,SubMenu,tmp,pos == i,( i << 16 ) + ivSetSubtitle );
+      AddMenuCheckItem( window1,(const char*)empty1px_xpm,SubMenu,tmp,sub_pos == i,( i << 16 ) + ivSetSubtitle );
      }
    }
 
_______________________________________________
MPlayer-dev-eng mailing list
MPlayer-dev-eng@xxxxxxxxxxxx
https://lists.mplayerhq.hu/mailman/listinfo/mplayer-dev-eng