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

« back to all changes in this revision

Viewing changes to src/rmd_initialize_data.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
#include "rmd_initialize_data.h"
 
29
 
 
30
#include "rmd_cache.h"
 
31
#include "rmd_init_encoder.h"
 
32
#include "rmd_jack.h"
 
33
#include "rmd_make_dummy_pointer.h"
 
34
#include "rmd_opendev.h"
 
35
#include "rmd_yuv_utils.h"
 
36
#include "rmd_types.h"
 
37
 
 
38
#include <pthread.h>
 
39
 
 
40
#include <stdlib.h>
 
41
#include <stdio.h>
 
42
#include <string.h>
 
43
 
 
44
#ifdef HAVE_LIBASOUND
 
45
static void FixBufferSize(snd_pcm_uframes_t *buffsize) {
 
46
    snd_pcm_uframes_t buffsize_t=*buffsize,
 
47
#else
 
48
static void FixBufferSize(u_int32_t *buffsize) {
 
49
    u_int32_t buffsize_t=*buffsize,
 
50
#endif
 
51
                          buffsize_ret=1;
 
52
    while(buffsize_t>1){
 
53
        buffsize_t>>=1;
 
54
        buffsize_ret<<=1;
 
55
    }
 
56
    fprintf(stderr,"Buffer size adjusted to %d from %d frames.\n",
 
57
                   (int)buffsize_ret,(int)*buffsize);
 
58
}
 
59
 
 
60
int InitializeData(ProgData *pdata,
 
61
                   EncData *enc_data,
 
62
                   CacheData *cache_data){
 
63
    int i;
 
64
 
 
65
    fprintf(stderr,"Initializing...\n");
 
66
    MakeMatrices();
 
67
    if(pdata->args.have_dummy_cursor){
 
68
        pdata->dummy_pointer = MakeDummyPointer(pdata->dpy,
 
69
                                                &pdata->specs,
 
70
                                                16,
 
71
                                                pdata->args.cursor_color,
 
72
                                                0,
 
73
                                                &pdata->npxl);
 
74
        pdata->dummy_p_size=16;
 
75
    }
 
76
    else
 
77
        pdata->dummy_p_size=0;
 
78
 
 
79
 
 
80
    pdata->rect_root=NULL;
 
81
    pthread_mutex_init(&pdata->sound_buffer_mutex,NULL);
 
82
    pthread_mutex_init(&pdata->snd_buff_ready_mutex,NULL);
 
83
    pthread_mutex_init(&pdata->img_buff_ready_mutex,NULL);
 
84
    pthread_mutex_init(&pdata->theora_lib_mutex,NULL);
 
85
    pthread_mutex_init(&pdata->vorbis_lib_mutex,NULL);
 
86
    pthread_mutex_init(&pdata->libogg_mutex,NULL);
 
87
    pthread_mutex_init(&pdata->yuv_mutex,NULL);
 
88
    pthread_mutex_init(&pdata->pause_mutex, NULL);
 
89
    pthread_mutex_init(&pdata->time_mutex, NULL);
 
90
    pthread_cond_init(&pdata->time_cond,NULL);
 
91
    pthread_cond_init(&pdata->pause_cond,NULL);
 
92
    pthread_cond_init(&pdata->image_buffer_ready,NULL);
 
93
    pthread_cond_init(&pdata->sound_data_read,NULL);
 
94
    pthread_cond_init(&pdata->theora_lib_clean,NULL);
 
95
    pthread_cond_init(&pdata->vorbis_lib_clean,NULL);
 
96
    pdata->th_encoding_clean=pdata->v_encoding_clean=1;
 
97
    pdata->avd=0;
 
98
    pdata->sound_buffer=NULL;
 
99
    pdata->running             = TRUE;
 
100
    pdata->paused              = FALSE;
 
101
    pdata->aborted             = FALSE;
 
102
    pdata->pause_state_changed = FALSE;
 
103
    pdata->frames_total        = 0;
 
104
    pdata->frames_lost         = 0;
 
105
    pdata->encoder_busy        = FALSE;
 
106
    pdata->capture_busy        = FALSE;
 
107
 
 
108
    if(!pdata->args.nosound){
 
109
        if(!pdata->args.use_jack){
 
110
            FixBufferSize(&pdata->args.buffsize);
 
111
#ifdef HAVE_LIBASOUND
 
112
            pdata->sound_handle=OpenDev( pdata->args.device,
 
113
                                        &pdata->args.channels,
 
114
                                        &pdata->args.frequency,
 
115
                                        &pdata->args.buffsize,
 
116
                                        &pdata->periodsize,
 
117
                                        &pdata->periodtime,
 
118
                                        &pdata->hard_pause);
 
119
            pdata->sound_framesize=((snd_pcm_format_width(
 
120
                                     SND_PCM_FORMAT_S16_LE))/8)*
 
121
                                     pdata->args.channels;
 
122
 
 
123
            if(pdata->sound_handle==NULL){
 
124
#else
 
125
            pdata->sound_handle=OpenDev(pdata->args.device,
 
126
                                        pdata->args.channels,
 
127
                                        pdata->args.frequency);
 
128
            pdata->periodtime=(1000000*pdata->args.buffsize)/
 
129
                            ((pdata->args.channels<<1)*pdata->args.frequency);
 
130
            //when using OSS periodsize serves as an alias of buffsize
 
131
            pdata->periodsize=pdata->args.buffsize;
 
132
            pdata->sound_framesize=pdata->args.channels<<1;
 
133
            if(pdata->sound_handle<0){
 
134
#endif
 
135
                fprintf(stderr,"Error while opening/configuring soundcard %s\n"
 
136
                            "Try running with the --no-sound or specify a "
 
137
                            "correct device.\n",
 
138
                            pdata->args.device);
 
139
                return 3;
 
140
            }
 
141
        }
 
142
        else{
 
143
#ifdef HAVE_LIBJACK
 
144
            int jack_error=0;
 
145
            pdata->jdata->port_names=pdata->args.jack_port_names;
 
146
            pdata->jdata->nports=pdata->args.jack_nports;
 
147
            pdata->jdata->ringbuffer_secs=pdata->args.jack_ringbuffer_secs;
 
148
            pdata->jdata->snd_buff_ready_mutex=&pdata->snd_buff_ready_mutex;
 
149
            pdata->jdata->sound_data_read=&pdata->sound_data_read;
 
150
            pdata->jdata->capture_started=0;
 
151
 
 
152
            if((jack_error=StartJackClient(pdata->jdata))!=0)
 
153
                return jack_error;
 
154
 
 
155
            pdata->args.buffsize=pdata->jdata->buffersize;
 
156
            pdata->periodsize=pdata->args.buffsize;
 
157
            pdata->args.frequency=pdata->jdata->frequency;
 
158
            pdata->args.channels=pdata->jdata->nports;
 
159
            pdata->periodtime=(1000000*pdata->args.buffsize)/
 
160
                              pdata->args.frequency;
 
161
            pdata->sound_framesize=sizeof(jack_default_audio_sample_t)*
 
162
                                   pdata->jdata->nports;
 
163
 
 
164
#else
 
165
            fprintf(stderr,"Should not be here!\n");
 
166
            exit(-1);
 
167
#endif
 
168
        }
 
169
    }
 
170
 
 
171
    if(pdata->args.encOnTheFly)
 
172
        InitEncoder(pdata,enc_data,0);
 
173
    else
 
174
        InitCacheData(pdata,enc_data,cache_data);
 
175
 
 
176
    for(i=0;i<(pdata->enc_data->yuv.y_width*pdata->enc_data->yuv.y_height);i++)
 
177
        pdata->enc_data->yuv.y[i]=0;
 
178
    for(i=0;
 
179
        i<(pdata->enc_data->yuv.uv_width*pdata->enc_data->yuv.uv_height);
 
180
        i++){
 
181
        pdata->enc_data->yuv.v[i]=pdata->enc_data->yuv.u[i]=127;
 
182
    }
 
183
 
 
184
    yblocks=malloc(sizeof(u_int32_t)*(pdata->enc_data->yuv.y_width/Y_UNIT_WIDTH)*
 
185
                (pdata->enc_data->yuv.y_height/Y_UNIT_WIDTH));
 
186
    ublocks=malloc(sizeof(u_int32_t)*(pdata->enc_data->yuv.y_width/Y_UNIT_WIDTH)*
 
187
                (pdata->enc_data->yuv.y_height/Y_UNIT_WIDTH));
 
188
    vblocks=malloc(sizeof(u_int32_t)*(pdata->enc_data->yuv.y_width/Y_UNIT_WIDTH)*
 
189
                (pdata->enc_data->yuv.y_height/Y_UNIT_WIDTH));
 
190
 
 
191
    pdata->frametime=(1000000)/pdata->args.fps;
 
192
    return 0;
 
193
 
 
194
}
 
195
 
 
196
void SetupDefaultArgs(ProgArgs *args) {
 
197
    
 
198
    args->delay                = 0;
 
199
    args->windowid             = 0;
 
200
    args->x                    = 0;
 
201
    args->y                    = 0;
 
202
    args->width                = 0;
 
203
    args->height               = 0;
 
204
    args->rescue_path          = NULL;
 
205
    args->nosound              = 0;
 
206
    args->full_shots           = 0;
 
207
    args->follow_mouse         = 0;
 
208
    args->encOnTheFly          = 0;
 
209
    args->nowmcheck            = 0;
 
210
    args->overwrite            = 0;
 
211
    args->use_jack             = 0;
 
212
    args->noshared             = 0;
 
213
    args->no_encode            = 0;
 
214
    args->noframe              = 0;
 
215
    args->jack_nports          = 0;
 
216
    args->jack_ringbuffer_secs = 3.0;
 
217
    args->jack_port_names      = NULL;
 
218
    args->zerocompression      = 1;
 
219
    args->no_quick_subsample   = 1;
 
220
    args->cursor_color         = 1;
 
221
    args->have_dummy_cursor    = 0;
 
222
    args->xfixes_cursor        = 1;
 
223
    args->fps                  = 15;
 
224
    args->channels             = 1;
 
225
    args->frequency            = 22050;
 
226
    args->buffsize             = 4096;
 
227
    args->v_bitrate            = 45000;
 
228
    args->v_quality            = 63;
 
229
    args->s_quality            = 10;
 
230
 
 
231
    if (getenv("DISPLAY") != NULL) {
 
232
        args->display = (char *) malloc(strlen(getenv("DISPLAY")) + 1);
 
233
        strcpy(args->display, getenv("DISPLAY"));
 
234
    }
 
235
    else {
 
236
        args->display = NULL;
 
237
    }
 
238
 
 
239
    args->device = (char *) malloc(strlen(DEFAULT_AUDIO_DEVICE) + 1);
 
240
    strcpy(args->device, DEFAULT_AUDIO_DEVICE);
 
241
 
 
242
    args->workdir = (char *) malloc(5);
 
243
    strcpy(args->workdir, "/tmp");
 
244
 
 
245
    args->pause_shortcut = (char *) malloc(15);
 
246
    strcpy(args->pause_shortcut, "Control+Mod1+p");
 
247
 
 
248
    args->stop_shortcut = (char *) malloc(15);
 
249
    strcpy(args->stop_shortcut, "Control+Mod1+s");
 
250
 
 
251
    args->filename = (char *) malloc(8);
 
252
    strcpy(args->filename, "out.ogv");
 
253
}
 
254
 
 
255
void CleanUp(void){
 
256
 
 
257
    free(yblocks);
 
258
    free(ublocks);
 
259
    free(vblocks);
 
260
 
 
261
}