~ubuntu-branches/ubuntu/karmic/recordmydesktop/karmic

« back to all changes in this revision

Viewing changes to src/rmd.c

  • Committer: Bazaar Package Importer
  • Author(s): Alan Pope
  • Date: 2009-04-21 10:57:22 UTC
  • mfrom: (1.1.5 upstream)
  • Revision ID: james.westby@ubuntu.com-20090421105722-w6l4gz958gva15wn
Tags: 0.3.8.1-0ubuntu1
* New upstream release (LP: #364674)
* debian/control: Fixed libjack0.100.0-dev dependancy
* debian/control: Fixed project home page

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/******************************************************************************
 
2
*                            recordMyDesktop                                  *
 
3
*******************************************************************************
 
4
*                                                                             *
 
5
*            Copyright (C) 2006,2007,2008 John Varouhakis                     *
 
6
*                                                                             *
 
7
*                                                                             *
 
8
*   This program is free software; you can redistribute it and/or modify      *
 
9
*   it under the terms of the GNU General Public License as published by      *
 
10
*   the Free Software Foundation; either version 2 of the License, or         *
 
11
*   (at your option) any later version.                                       *
 
12
*                                                                             *
 
13
*   This program is distributed in the hope that it will be useful,           *
 
14
*   but WITHOUT ANY WARRANTY; without even the implied warranty of            *
 
15
*   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the             *
 
16
*   GNU General Public License for more details.                              *
 
17
*                                                                             *
 
18
*   You should have received a copy of the GNU General Public License         *
 
19
*   along with this program; if not, write to the Free Software               *
 
20
*   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA  *
 
21
*                                                                             *
 
22
*                                                                             *
 
23
*                                                                             *
 
24
*   For further information contact me at johnvarouhakis@gmail.com            *
 
25
******************************************************************************/
 
26
 
 
27
#include "config.h"
 
28
 
 
29
#include "rmd_cache.h"
 
30
#include "rmd_encode_cache.h"
 
31
#include "rmd_error.h"
 
32
#include "rmd_initialize_data.h"
 
33
#include "rmd_parseargs.h"
 
34
#include "rmd_queryextensions.h"
 
35
#include "rmd_rescue.h"
 
36
#include "rmd_setbrwindow.h"
 
37
#include "rmd_shortcuts.h"
 
38
#include "rmd_threads.h"
 
39
#include "rmd_wm_is_compositing.h"
 
40
#include "rmd_types.h"
 
41
 
 
42
#include <X11/Xlib.h>
 
43
 
 
44
#include <stdio.h>
 
45
#include <stdlib.h>
 
46
#include <errno.h>
 
47
 
 
48
int main(int argc,char **argv){
 
49
    ProgData pdata;
 
50
    int exit_status = 0;
 
51
    
 
52
    SetupDefaultArgs(&pdata.args);
 
53
 
 
54
    if (!ParseArgs(argc, argv, &pdata.args)) {
 
55
        exit(1);
 
56
    }
 
57
    if (pdata.args.rescue_path != NULL) {
 
58
        exit(rmdRescue(pdata.args.rescue_path));
 
59
    }
 
60
    if(XInitThreads ()==0){
 
61
        fprintf(stderr,"Couldn't initialize thread support!\n");
 
62
        exit(7);
 
63
    }
 
64
    if(pdata.args.display!=NULL){
 
65
        pdata.dpy = XOpenDisplay(pdata.args.display);
 
66
        XSetErrorHandler(rmdErrorHandler);
 
67
    }
 
68
    else{
 
69
        fprintf(stderr,"No display specified for connection!\n");
 
70
        exit(8);
 
71
    }
 
72
    if (pdata.dpy == NULL) {
 
73
        fprintf(stderr, "Cannot connect to X server %s\n",pdata.args.display);
 
74
        exit(9);
 
75
    }
 
76
    else{
 
77
        EncData enc_data;
 
78
        CacheData cache_data;
 
79
#ifdef HAVE_LIBJACK
 
80
        JackData jdata;
 
81
 
 
82
        // Give jack access to program data, mainly for program state
 
83
        jdata.pdata = &pdata;
 
84
        pdata.jdata = &jdata;
 
85
#endif
 
86
 
 
87
        // Query display specs
 
88
        pdata.specs.screen = DefaultScreen(pdata.dpy);
 
89
        pdata.specs.width  = DisplayWidth(pdata.dpy, pdata.specs.screen);
 
90
        pdata.specs.height = DisplayHeight(pdata.dpy, pdata.specs.screen);
 
91
        pdata.specs.root   = RootWindow(pdata.dpy, pdata.specs.screen);
 
92
        pdata.specs.visual = DefaultVisual(pdata.dpy, pdata.specs.screen);
 
93
        pdata.specs.gc     = DefaultGC(pdata.dpy, pdata.specs.screen);
 
94
        pdata.specs.depth  = DefaultDepth(pdata.dpy, pdata.specs.screen);
 
95
 
 
96
        if((pdata.specs.depth!=32)&&
 
97
           (pdata.specs.depth!=24)&&
 
98
           (pdata.specs.depth!=16)){
 
99
            fprintf(stderr,"Only 32bpp,24bpp and 16bpp"
 
100
                           " color depth modes are currently supported.\n");
 
101
            exit(10);
 
102
        }
 
103
        if (!SetBRWindow(pdata.dpy, &pdata.brwin, &pdata.specs, &pdata.args))
 
104
            exit(11);
 
105
 
 
106
        if( !pdata.args.nowmcheck && 
 
107
            rmdWMIsCompositing( pdata.dpy, pdata.specs.screen ) ) {
 
108
 
 
109
            fprintf(stderr,"\nDetected compositing window manager.\n"
 
110
                           "Reverting to full screen capture at every frame.\n"
 
111
                           "To disable this check run with --no-wm-check\n"
 
112
                           "(though that is not advised, since it will "
 
113
                           "probably produce faulty results).\n\n");
 
114
            pdata.args.full_shots=1;
 
115
            pdata.args.noshared=0;
 
116
        
 
117
        }
 
118
 
 
119
        QueryExtensions(pdata.dpy,
 
120
                        &pdata.args,
 
121
                        &pdata.damage_event,
 
122
                        &pdata.damage_error,
 
123
                        &pdata.shm_opcode);
 
124
 
 
125
 
 
126
        if((exit_status=InitializeData(&pdata,&enc_data,&cache_data))==0){
 
127
 
 
128
            if(!strcmp(pdata.args.pause_shortcut,
 
129
                      pdata.args.stop_shortcut)||
 
130
                RegisterShortcut(pdata.dpy,
 
131
                                 pdata.specs.root,
 
132
                                 pdata.args.pause_shortcut,
 
133
                                 &(pdata.pause_key)) ||
 
134
                RegisterShortcut(pdata.dpy,
 
135
                                 pdata.specs.root,
 
136
                                 pdata.args.stop_shortcut,
 
137
                                 &(pdata.stop_key))){
 
138
 
 
139
                fprintf(stderr,"Invalid shortcut,"
 
140
                               " or shortcuts are the same!\n\n"
 
141
                               "Using defaults.\n");
 
142
 
 
143
                RegisterShortcut(pdata.dpy,
 
144
                                 pdata.specs.root,
 
145
                                 "Control+Mod1+p",
 
146
                                 &(pdata.pause_key));
 
147
                RegisterShortcut(pdata.dpy,
 
148
                                 pdata.specs.root,
 
149
                                 "Control+Mod1+s",
 
150
                                 &(pdata.stop_key));
 
151
            }
 
152
 
 
153
            //this is where the capturing happens.
 
154
            rmdThreads(&pdata);
 
155
 
 
156
            XCloseDisplay(pdata.dpy);
 
157
            fprintf(stderr,".\n");
 
158
 
 
159
            //encode and then cleanup cache
 
160
            if(!pdata.args.encOnTheFly && !pdata.args.no_encode){
 
161
                if (!pdata.aborted) {
 
162
                    EncodeCache(&pdata);
 
163
                }
 
164
                fprintf(stderr,"Cleanning up cache...\n");
 
165
                if(PurgeCache(pdata.cache_data,!pdata.args.nosound))
 
166
                    fprintf(stderr,"Some error occured "
 
167
                                "while cleaning up cache!\n");
 
168
                fprintf(stderr,"Done!!!\n");
 
169
            }
 
170
 
 
171
 
 
172
            if (pdata.aborted && pdata.args.encOnTheFly) {
 
173
                if(remove(pdata.args.filename)){
 
174
                    perror("Error while removing file:\n");
 
175
                    return 1;
 
176
                }
 
177
                else{
 
178
                    fprintf(stderr,"SIGABRT received,file %s removed\n",
 
179
                                pdata.args.filename);
 
180
                    return 0;
 
181
                }
 
182
            }
 
183
            else
 
184
                fprintf(stderr,"Goodbye!\n");
 
185
 
 
186
 
 
187
            CleanUp();
 
188
        }
 
189
    }
 
190
 
 
191
    return exit_status;
 
192
}