| 1 |
|
| 2 |
#include "v4lwindow.h" |
| 3 |
#include "vidconf.h" |
| 4 |
|
| 5 |
#include <aviplay.h> |
| 6 |
#include "v4lxif.h" |
| 7 |
#include <avm_except.h> |
| 8 |
#include <avm_cpuinfo.h> |
| 9 |
#include <videoencoder.h> |
| 10 |
#include <VideoDPMS.h> |
| 11 |
#include <version.h> |
| 12 |
#define DECLARE_REGISTRY_SHORTCUT |
| 13 |
#include <configfile.h> |
| 14 |
#undef DECLARE_REGISTRY_SHORTCUT |
| 15 |
|
| 16 |
#include <qapplication.h> |
| 17 |
#include <qtextcodec.h> |
| 18 |
|
| 19 |
#ifdef HAVE_SYSINFO |
| 20 |
#include <sys/sysinfo.h> // is this standard for all linux boxes ? |
| 21 |
#endif |
| 22 |
#include <sys/resource.h> |
| 23 |
#include <sys/types.h> |
| 24 |
#include <sys/time.h> |
| 25 |
#include <unistd.h> |
| 26 |
#include <errno.h> |
| 27 |
#include <stdlib.h> |
| 28 |
#include <stdio.h> |
| 29 |
|
| 30 |
|
| 31 |
unsigned int m_iMemory; |
| 32 |
const char* g_pcProgramName = "AviCap"; |
| 33 |
|
| 34 |
static v4lxif* createDevice() |
| 35 |
{ |
| 36 |
v4lxif* v4l = new v4l1if(0, RS("CaptureDevice", "/dev/video")); |
| 37 |
if (v4l->init() == 0) |
| 38 |
return v4l; |
| 39 |
delete v4l; |
| 40 |
return 0; |
| 41 |
} |
| 42 |
|
| 43 |
#if 0 |
| 44 |
// We do not need this ugly CPU hungry busy loop hack anymore |
| 45 |
// [email protected] |
| 46 |
class QMyApp: public QApplication |
| 47 |
{ |
| 48 |
V4LWindow* m_pWin; |
| 49 |
public: |
| 50 |
QMyApp(int argc, char** argv): QApplication(argc, argv), m_pWin(0){} |
| 51 |
void setWindow(V4LWindow* pWin) { m_pWin=pWin; } |
| 52 |
virtual bool x11EventFilter( XEvent * e ) |
| 53 |
{ |
| 54 |
if(m_pWin) |
| 55 |
m_pWin->get_clips(); |
| 56 |
return QApplication::x11EventFilter(e); |
| 57 |
} |
| 58 |
}; |
| 59 |
#endif |
| 60 |
|
| 61 |
static const QString trans_path[] = { ".", I18N_PATH, "" }; |
| 62 |
|
| 63 |
int main(int argc, char** argv) |
| 64 |
{ |
| 65 |
if (GetAvifileVersion() != AVIFILE_VERSION) |
| 66 |
{ |
| 67 |
printf("This binary was compiled for Avifile ver. %x, " |
| 68 |
"but the library is ver. %x. Aborting.\n", |
| 69 |
AVIFILE_VERSION, GetAvifileVersion()); |
| 70 |
return 0; |
| 71 |
} |
| 72 |
|
| 73 |
// Registry::ReadString("QtVidcap", "CapDev", "/dev/video"); |
| 74 |
QApplication a(argc,argv); |
| 75 |
|
| 76 |
#if 0 |
| 77 |
QTranslator qtrans( 0 ); |
| 78 |
qtrans.load( QString( "qt_" ) + QTextCodec::locale(), "." ); |
| 79 |
a.installTranslator( &qtrans ); |
| 80 |
#endif |
| 81 |
|
| 82 |
// translation file for application strings |
| 83 |
QTranslator mytrans( 0 ); |
| 84 |
int i=0; |
| 85 |
bool res=false; |
| 86 |
do{ |
| 87 |
res=mytrans.load( QString( "avicap_" ) + QTextCodec::locale(), trans_path[i] ); |
| 88 |
if(res){ |
| 89 |
printf("translation loaded from %s\n",trans_path[i].latin1()); |
| 90 |
} |
| 91 |
i++; |
| 92 |
}while(!(res || trans_path[i]=="")); |
| 93 |
|
| 94 |
a.installTranslator( &mytrans ); |
| 95 |
|
| 96 |
bool bNow=false; |
| 97 |
bool bTimer=false; |
| 98 |
if(argc==2){ |
| 99 |
if(!strcmp(argv[1], "-now")){ |
| 100 |
bNow=true; |
| 101 |
} |
| 102 |
else if(!strcmp(argv[1], "-timer")){ |
| 103 |
bTimer=true; |
| 104 |
} |
| 105 |
} |
| 106 |
avm::string cmd = avm::string("kv4lsetup -t=2 -l ") + RS("CaptureDevice", "/dev/video"); |
| 107 |
|
| 108 |
if ((cmd.find(':')!=avm::string::npos) |
| 109 |
|| (cmd.find('|')!=avm::string::npos) |
| 110 |
|| (cmd.find(';')!=avm::string::npos)) { |
| 111 |
system("kv4lsetup -t=2"); |
| 112 |
// printf("Retval: %d errno: %d\n", val, errno); |
| 113 |
} else { |
| 114 |
system(cmd.c_str()); |
| 115 |
// printf("str: %s\n", cmd.c_str()); |
| 116 |
// printf("Retval: %d errno: %d\n", val, errno); |
| 117 |
} |
| 118 |
|
| 119 |
#ifdef HAVE_SYSINFO |
| 120 |
struct sysinfo s_info; |
| 121 |
sysinfo(&s_info); |
| 122 |
m_iMemory=s_info.totalram; |
| 123 |
if (m_iMemory < 2*1048576) |
| 124 |
m_iMemory=1048576; |
| 125 |
else |
| 126 |
m_iMemory/=2; |
| 127 |
printf("Using %dMb of memory for frame caching\n", m_iMemory/1048576); |
| 128 |
#else |
| 129 |
m_iMemory = 16 * 1024 * 1024; |
| 130 |
#endif |
| 131 |
|
| 132 |
int p = getpriority(PRIO_PROCESS, 0); |
| 133 |
//attention: only root is allowed to lower priority |
| 134 |
setpriority(PRIO_PROCESS, 0, (p + 3 < 20) ? p + 3 : 20); |
| 135 |
|
| 136 |
for (;;) { |
| 137 |
v4lxif* pV4L = createDevice(); |
| 138 |
if (pV4L) { |
| 139 |
V4LWindow m(pV4L); |
| 140 |
avm::VideoDPMS dp(m.x11Display()); |
| 141 |
if (bNow) |
| 142 |
m.setAutoRecord(); |
| 143 |
m.show(); |
| 144 |
m.setupDevice(); |
| 145 |
//a.setWindow(&m); |
| 146 |
if (bTimer) |
| 147 |
m.startTimer(); |
| 148 |
a.setMainWidget(&m); |
| 149 |
a.exec(); |
| 150 |
break; |
| 151 |
} |
| 152 |
else |
| 153 |
{ |
| 154 |
VidConfig conf(0, pV4L, 0); |
| 155 |
if (conf.exec()==QDialog::Rejected) |
| 156 |
return -1; |
| 157 |
} |
| 158 |
} |
| 159 |
return 0; |
| 160 |
} |