]> git.sesse.net Git - vlc/blobdiff - modules/video_filter/time.c
Some cleanup and unification with xine vcd plugin.
[vlc] / modules / video_filter / time.c
index 28f143cc687ab2fc07f0a43c0d76bd72f634a5a9..fe2eef2a4370859e85e5b695a2b0c0e2cf5c28ab 100644 (file)
@@ -2,7 +2,7 @@
  * time.c : time display video plugin for vlc
  *****************************************************************************
  * Copyright (C) 2003-2004 VideoLAN
- * $Id: logo.c 8721 2004-09-17 10:21:00Z gbazin $
+ * $Id$
  *
  * Authors: Sigmund Augdal <sigmunau@idi.ntnu.no>
  *
@@ -47,26 +47,28 @@ static subpicture_t *Filter( filter_t *, mtime_t );
 struct filter_sys_t
 {
     int i_xoff, i_yoff;  /* offsets for the display string in the video window */
-    char *psz_head;  /* text to put before the day/time */
+    char *psz_format;    /* time format string */
 
     time_t last_time;
 };
 
-#define MSG_TEXT N_("Timestamp Prefix")
-#define MSG_LONGTEXT N_("Text (name) to display before the date and time")
-#define POSX_TEXT N_("X coordinate of the timestamp")
-#define POSX_LONGTEXT N_("Positive offset, from the left" )
-#define POSY_TEXT N_("Y coordinate of the timestamp")
-#define POSY_LONGTEXT N_("Positive offset, down from the top" )
-#define TRANS_TEXT N_("Transparency of the timestamp")
+#define MSG_TEXT N_("Time format string (%Y%m%d %H%M%S)")
+#define MSG_LONGTEXT N_("Time format string (%Y = year, %m = month, %d = day, %H = hour, %M = minute, %S = second")
+#define POSX_TEXT N_("X offset, from left")
+#define POSX_LONGTEXT N_("X offset, from the left screen edge" )
+#define POSY_TEXT N_("Y offset, from the top")
+#define POSY_LONGTEXT N_("Y offset, down from the top" )
 
 /*****************************************************************************
  * Module descriptor
  *****************************************************************************/
 vlc_module_begin();
     set_capability( "sub filter", 0 );
+    set_shortname( N_("Time overlay"));
+    set_category( CAT_VIDEO );
+    set_subcategory( SUBCAT_VIDEO_SUBPIC );
     set_callbacks( CreateFilter, DestroyFilter );
-    add_string( "time-text", NULL, NULL, MSG_TEXT, MSG_LONGTEXT, VLC_FALSE );
+    add_string( "time-format", "%Y-%m-%d   %H:%M:%S", NULL, MSG_TEXT, MSG_LONGTEXT, VLC_FALSE );
     add_integer( "time-x", 0, NULL, POSX_TEXT, POSX_LONGTEXT, VLC_FALSE );
     add_integer( "time-y", 0, NULL, POSY_TEXT, POSY_LONGTEXT, VLC_FALSE );
     set_description( _("Time display sub filter") );
@@ -96,7 +98,7 @@ static int CreateFilter( vlc_object_t *p_this )
     var_Create( p_this, "time-y", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
     var_Get( p_filter, "time-y", &val );
     p_sys->i_yoff = val.i_int;
-    p_sys->psz_head = var_CreateGetString( p_this, "time-text" );
+    p_sys->psz_format = var_CreateGetString( p_this, "time-format" );
 
     /* Misc init */
     p_filter->pf_sub_filter = Filter;
@@ -112,19 +114,33 @@ static void DestroyFilter( vlc_object_t *p_this )
     filter_t *p_filter = (filter_t *)p_this;
     filter_sys_t *p_sys = p_filter->p_sys;
 
-    if( p_sys->psz_head ) free( p_sys->psz_head );
+    if( p_sys->psz_format ) free( p_sys->psz_format );
     free( p_sys );
 }
 
-char *myCtime( time_t *t )
+
+static char *FormatTime(char *tformat )
 {
-#ifdef HAVE_CTIME_R
-    char tmp[27];
-    ctime_r( t, tmp );
-    return strdup( tmp );
+  char buffer[255];
+  time_t curtime;
+#if defined(HAVE_LOCALTIME_R)
+  struct tm loctime;
+#else
+  struct tm *loctime;
+#endif
+
+  /* Get the current time.  */
+  curtime = time( NULL );
+
+  /* Convert it to local time representation.  */
+#if defined(HAVE_LOCALTIME_R)
+  localtime_r( &curtime, &loctime );
+  strftime( buffer, 255, tformat, &loctime );
 #else
-    return strdup( ctime(t) );
+  loctime = localtime( &curtime );
+  strftime( buffer, 255, tformat, loctime );
 #endif
+  return strdup( buffer );
 }
 
 /****************************************************************************
@@ -137,8 +153,6 @@ static subpicture_t *Filter( filter_t *p_filter, mtime_t date )
     filter_sys_t *p_sys = p_filter->p_sys;
     subpicture_t *p_spu;
     video_format_t fmt;
-    time_t t;
-    char *psz_time, *psz_string;
 
     if( p_sys->last_time == time( NULL ) ) return NULL;
 
@@ -159,15 +173,11 @@ static subpicture_t *Filter( filter_t *p_filter, mtime_t date )
         return NULL;
     }
 
-    t = p_sys->last_time = time( NULL );
-    psz_time = myCtime( &t );
-    asprintf( &psz_string, "%s%s", p_sys->psz_head, psz_time );
-    free( psz_time );
+    p_sys->last_time = time( NULL );
 
-    p_spu->p_region->psz_text = psz_string;
+    p_spu->p_region->psz_text = FormatTime( p_sys->psz_format );
     p_spu->i_start = date;
-    p_spu->i_stop  = date + 1000000;
+    p_spu->i_stop  = 0;
     p_spu->b_ephemer = VLC_TRUE;
     p_spu->b_absolute = VLC_FALSE;
     p_spu->i_x = p_sys->i_xoff;