-
Notifications
You must be signed in to change notification settings - Fork 13
/
main.cc
153 lines (132 loc) · 3.04 KB
/
main.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
/*
* main.cc -- A DV/1394 capture utility
* Copyright (C) 2000-2002 Arne Schirmacher <[email protected]>
* Copyright (C) 2003-2008 Dan Dennedy <[email protected]>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
/** the dvgrab main program
contains the main logic
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
// C++ includes
#include <string>
#include <iostream>
using std::cout;
using std::endl;
// C includes
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <fcntl.h>
#include <pthread.h>
#include <sched.h>
#include <string.h>
#include <sys/time.h>
#include <sys/resource.h>
#include <sys/mman.h>
// local includes
#include "io.h"
#include "dvgrab.h"
#include "error.h"
bool g_done = false;
void signal_handler( int sig )
{
g_done = true;
}
int rt_raisepri (int pri)
{
#ifdef _SC_PRIORITY_SCHEDULING
struct sched_param scp;
/*
* Verify that scheduling is available
*/
if ( sysconf( _SC_PRIORITY_SCHEDULING ) == -1)
{
// sendEvent( "Warning: RR-scheduler not available, disabling." );
return -1;
}
else
{
memset( &scp, '\0', sizeof( scp ) );
scp.sched_priority = sched_get_priority_max( SCHED_RR ) - pri;
if ( sched_setscheduler( 0, SCHED_RR, &scp ) < 0 )
{
// sendEvent( "Warning: Cannot set RR-scheduler" );
return -1;
}
}
return 0;
#else
return -1;
#endif
}
int main( int argc, char *argv[] )
{
int ret = 0;
fcntl( fileno( stderr ), F_SETFL, O_NONBLOCK );
try
{
char c;
DVgrab dvgrab( argc, argv );
signal( SIGINT, signal_handler );
signal( SIGTERM, signal_handler );
signal( SIGHUP, signal_handler );
signal( SIGPIPE, signal_handler );
if ( rt_raisepri( 1 ) != 0 )
setpriority( PRIO_PROCESS, 0, -20 );
#if _POSIX_MEMLOCK > 0
mlockall( MCL_CURRENT | MCL_FUTURE );
#endif
if ( dvgrab.isInteractive() )
{
term_init();
fprintf( stderr, "Going interactive. Press '?' for help.\n" );
while ( !g_done )
{
dvgrab.status( );
if ( ( c = term_read() ) != -1 )
if ( !dvgrab.execute( c ) )
break;
}
term_exit();
}
else
{
dvgrab.startCapture();
while ( !g_done )
if ( dvgrab.done() )
break;
dvgrab.stopCapture();
}
}
catch ( std::string s )
{
fprintf( stderr, "Error: %s\n", s.c_str() );
fflush( stderr );
ret = 1;
}
catch ( ... )
{
fprintf( stderr, "Error: unknown\n" );
fflush( stderr );
ret = 1;
}
fprintf( stderr, "\n" );
return ret;
}