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 [-prio NNNN|max] [-test] [-port NNNN] [-c config-file]\n", app
);
65 /** The main function.
68 int main( int argc
, char **argv
)
73 struct timespec tm
= { 1, 0 };
79 const char *config_file
= "/etc/melted.conf";
82 for ( index
= 1; index
< argc
; index
++ )
84 if ( !strcmp( argv
[ index
], "-prio" ) )
86 struct sched_param scp
;
87 char* prio
= argv
[ ++ index
];
89 memset( &scp
, 0, sizeof( scp
) );
91 if( !strcmp( prio
, "max" ) )
92 scp
.sched_priority
= sched_get_priority_max( SCHED_FIFO
) - 1;
94 scp
.sched_priority
= atoi(prio
);
96 sched_setscheduler( 0, SCHED_FIFO
, &scp
);
101 mlt_factory_init( NULL
);
103 server
= melted_server_init( argv
[ 0 ] );
105 for ( index
= 1; index
< argc
; index
++ )
107 if ( !strcmp( argv
[ index
], "-port" ) )
108 melted_server_set_port( server
, atoi( argv
[ ++ index
] ) );
109 else if ( !strcmp( argv
[ index
], "-proxy" ) )
110 melted_server_set_proxy( server
, argv
[ ++ index
] );
111 else if ( !strcmp( argv
[ index
], "-test" ) )
113 else if ( !strcmp( argv
[ index
], "-c" ) )
114 config_file
= argv
[ ++ index
];
115 else if ( !strcmp( argv
[ index
], "-prio" ) )
121 /* Optionally detatch ourselves from the controlling tty */
128 melted_log_init( log_syslog
, LOG_NOTICE
);
132 mlt_log_set_level( MLT_LOG_VERBOSE
);
133 melted_log_init( log_stderr
, LOG_DEBUG
);
136 atexit( main_cleanup
);
138 /* Set the config script */
139 melted_server_set_config( server
, config_file
);
141 /* Execute the server */
142 error
= melted_server_execute( server
);
144 /* Initialize the as-run log tracking */
145 for ( index
= 0; index
< MAX_UNITS
; index
++ )
146 asrun
[ index
].clip_index
= -1;
148 /* We need to wait until we're exited.. */
149 while ( !server
->shutdown
)
151 nanosleep( &tm
, NULL
);
154 for ( index
= 0; !error
&& index
< MAX_UNITS
; index
++ )
156 melted_unit unit
= melted_get_unit( index
);
158 if ( unit
&& melted_unit_get_status( unit
, &status
) == 0 )
160 int length
= status
.length
- 60;
162 /* Reset the logging if needed */
163 if ( status
.clip_index
!= asrun
[ index
].clip_index
|| status
.position
< length
|| status
.status
== unit_not_loaded
)
165 asrun
[ index
].clip_index
= status
.clip_index
;
166 asrun
[ index
].is_logged
= 0;
168 /* Log as-run only once when near the end */
169 if ( ! asrun
[ index
].is_logged
&& status
.length
> 0 && status
.position
> length
)
171 melted_log( LOG_NOTICE
, "AS-RUN U%d \"%s\" len %d pos %d", index
, status
.clip
, status
.length
, status
.position
);
172 asrun
[ index
].is_logged
= 1;