0ffbd76f00e18e479ab32499bf9e38a8edf64536
2 * melted.c -- MLT Video TCP Server
4 * Copyright (C) 2002-2009 Ushodaya Enterprises Limited
6 * Dan Dennedy <dan@dennedy.org>
7 * Charles Yates <charles.yates@pandora.be>
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.
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.
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 Foundation,
21 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 /* System header files */
28 #include <sys/types.h>
33 #include <framework/mlt.h>
34 #include <mvcp/mvcp_notifier.h>
35 #include <mvcp/mvcp_status.h>
37 /* Application header files */
38 #include "melted_server.h"
39 #include "melted_log.h"
40 #include "melted_commands.h"
41 #include "melted_unit.h"
43 /** Our server context.
46 static melted_server server
= NULL
;
48 /** atexit shutdown handler for the server.
51 static void main_cleanup( )
53 melted_server_close( server
);
56 /** Report usage and exit.
59 void usage( char *app
)
61 fprintf( stderr
, "Usage: %s [-test] [-port NNNN]\n", app
);
65 /** The main function.
68 int main( int argc
, char **argv
)
73 struct timespec tm
= { 1, 0 };
74 struct sched_param scp
;
81 // Use realtime scheduling if possible
82 memset( &scp
, '\0', sizeof( scp
) );
83 scp
.sched_priority
= sched_get_priority_max( SCHED_FIFO
) - 1;
85 sched_setscheduler( 0, SCHED_FIFO
, &scp
);
88 mlt_factory_init( NULL
);
90 server
= melted_server_init( argv
[ 0 ] );
92 for ( index
= 1; index
< argc
; index
++ )
94 if ( !strcmp( argv
[ index
], "-port" ) )
95 melted_server_set_port( server
, atoi( argv
[ ++ index
] ) );
96 else if ( !strcmp( argv
[ index
], "-proxy" ) )
97 melted_server_set_proxy( server
, argv
[ ++ index
] );
98 else if ( !strcmp( argv
[ index
], "-test" ) )
104 /* Optionally detatch ourselves from the controlling tty */
111 melted_log_init( log_syslog
, LOG_NOTICE
);
115 melted_log_init( log_stderr
, LOG_DEBUG
);
118 atexit( main_cleanup
);
120 /* Set the config script */
121 melted_server_set_config( server
, "/etc/melted.conf" );
123 /* Execute the server */
124 error
= melted_server_execute( server
);
126 /* Initialize the as-run log tracking */
127 for ( index
= 0; index
< MAX_UNITS
; index
++ )
128 asrun
[ index
].clip_index
= -1;
130 /* We need to wait until we're exited.. */
131 while ( !server
->shutdown
)
133 nanosleep( &tm
, NULL
);
136 for ( index
= 0; !error
&& index
< MAX_UNITS
; index
++ )
138 melted_unit unit
= melted_get_unit( index
);
140 if ( unit
&& melted_unit_get_status( unit
, &status
) == 0 )
142 int length
= status
.length
- 60;
144 /* Reset the logging if needed */
145 if ( status
.clip_index
!= asrun
[ index
].clip_index
|| status
.position
< length
|| status
.status
== unit_not_loaded
)
147 asrun
[ index
].clip_index
= status
.clip_index
;
148 asrun
[ index
].is_logged
= 0;
150 /* Log as-run only once when near the end */
151 if ( ! asrun
[ index
].is_logged
&& status
.length
> 0 && status
.position
> length
)
153 melted_log( LOG_NOTICE
, "AS-RUN U%d \"%s\" len %d pos %d", index
, status
.clip
, status
.length
, status
.position
);
154 asrun
[ index
].is_logged
= 1;