]> git.sesse.net Git - vlc/blob - modules/video_filter/time.c
modules/video_filter/Modules.am: added time, for those that don't know the
[vlc] / modules / video_filter / time.c
1 /*****************************************************************************
2  * time.c : time display video plugin for vlc
3  *****************************************************************************
4  * Copyright (C) 2003-2004 VideoLAN
5  * $Id: logo.c 8721 2004-09-17 10:21:00Z gbazin $
6  *
7  * Authors: Sigmund Augdal <sigmunau@idi.ntnu.no>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
22  *****************************************************************************/
23
24 /*****************************************************************************
25  * Preamble
26  *****************************************************************************/
27 #include <stdlib.h>                                      /* malloc(), free() */
28 #include <string.h>
29
30 #include <vlc/vlc.h>
31 #include <vlc/vout.h>
32
33 #include "vlc_filter.h"
34 #include "vlc_block.h"
35
36 /*****************************************************************************
37  * Local prototypes
38  *****************************************************************************/
39 static int  CreateFilter ( vlc_object_t * );
40 static void DestroyFilter( vlc_object_t * );
41 static subpicture_t *Filter( filter_t *, mtime_t );
42
43 /*****************************************************************************
44  * filter_sys_t: time filter descriptor
45  *****************************************************************************/
46 struct filter_sys_t
47 {
48 };
49
50
51 /*****************************************************************************
52  * Module descriptor
53  *****************************************************************************/
54 vlc_module_begin();
55     set_capability( "sub filter", 0 );
56     set_callbacks( CreateFilter, DestroyFilter );
57     set_description( _("Time display sub filter") );
58     add_shortcut( "time" );
59 vlc_module_end();
60
61 /*****************************************************************************
62  * CreateFilter: allocates logo video filter
63  *****************************************************************************/
64 static int CreateFilter( vlc_object_t *p_this )
65 {
66     filter_t *p_filter = (filter_t *)p_this;
67     filter_sys_t *p_sys;
68
69     /* Allocate structure */
70     p_sys = p_filter->p_sys = malloc( sizeof( filter_sys_t ) );
71     if( p_sys == NULL )
72     {
73         msg_Err( p_filter, "out of memory" );
74         return VLC_ENOMEM;
75     }
76
77     /* Misc init */
78     p_filter->pf_sub_filter = Filter;
79
80     return VLC_SUCCESS;
81 }
82 /*****************************************************************************
83  * DestroyFilter: destroy logo video filter
84  *****************************************************************************/
85 static void DestroyFilter( vlc_object_t *p_this )
86 {
87     filter_t *p_filter = (filter_t *)p_this;
88     filter_sys_t *p_sys = p_filter->p_sys;
89
90     free( p_sys );
91 }
92
93 char *myCtime( time_t *t )
94 {
95 #ifdef HAVE_CTIME_R
96     char tmp[27];
97     ctime_r( t, tmp );
98     return strdup( tmp );
99 #else
100     return strdup(ctime(t));
101 #endif
102 }
103
104 /****************************************************************************
105  * Filter: the whole thing
106  ****************************************************************************
107  * This function outputs subpictures at regular time intervals.
108  ****************************************************************************/
109 static subpicture_t *Filter( filter_t *p_filter, mtime_t date )
110 {
111     subpicture_t *p_spu;
112     video_format_t fmt;
113     time_t t;
114     p_spu = p_filter->pf_sub_buffer_new( p_filter );
115     if( !p_spu ) return NULL;
116     
117     memset( &fmt, 0, sizeof(video_format_t) );
118     fmt.i_chroma = VLC_FOURCC('T','E','X','T');
119     fmt.i_aspect = 0;
120     fmt.i_width = fmt.i_height = 0;
121     fmt.i_x_offset = fmt.i_y_offset = 0;
122     
123     p_spu->p_region = p_spu->pf_create_region( VLC_OBJECT(p_filter), &fmt );
124     if( !p_spu->p_region )
125     {
126         p_filter->pf_sub_buffer_del( p_filter, p_spu );
127         return NULL;
128     }
129     t = time(NULL);
130     p_spu->p_region->psz_text = myCtime(&t);
131     p_spu->i_start = date;
132     p_spu->i_stop  = date + 1000000;
133     p_spu->b_ephemer = VLC_TRUE;
134     p_spu->b_absolute = VLC_FALSE;
135     p_spu->i_x = 10;
136     p_spu->i_y = 10;
137     p_spu->i_flags = 0;
138     return p_spu;
139 }