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

« back to all changes in this revision

Viewing changes to src/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
 
 
28
 
#include <recordmydesktop.h>
29
 
 
30
 
#ifdef HAVE_LIBASOUND
31
 
void FixBufferSize(snd_pcm_uframes_t *buffsize){
32
 
    snd_pcm_uframes_t buffsize_t=*buffsize,
33
 
#else
34
 
void FixBufferSize(u_int32_t *buffsize){
35
 
    u_int32_t buffsize_t=*buffsize,
36
 
#endif
37
 
                          buffsize_ret=1;
38
 
    while(buffsize_t>1){
39
 
        buffsize_t>>=1;
40
 
        buffsize_ret<<=1;
41
 
    }
42
 
    fprintf(stderr,"Buffer size adjusted to %d from %d frames.\n",
43
 
                   (int)buffsize_ret,(int)*buffsize);
44
 
}
45
 
 
46
 
int InitializeData(ProgData *pdata,
47
 
                   EncData *enc_data,
48
 
                   CacheData *cache_data){
49
 
    int i;
50
 
    //these are globals, look for them at the header
51
 
    frames_total=frames_lost=encoder_busy=capture_busy=0;
52
 
 
53
 
    fprintf(stderr,"Initializing...\n");
54
 
    MakeMatrices();
55
 
    if(pdata->args.have_dummy_cursor){
56
 
        pdata->dummy_pointer=MakeDummyPointer(&pdata->specs,16,
57
 
                                              pdata->args.cursor_color,0,
58
 
                                              &pdata->npxl);
59
 
        pdata->dummy_p_size=16;
60
 
    }
61
 
    else
62
 
        pdata->dummy_p_size=0;
63
 
 
64
 
 
65
 
    pdata->rect_root=NULL;
66
 
    pthread_mutex_init(&pdata->sound_buffer_mutex,NULL);
67
 
    pthread_mutex_init(&pdata->snd_buff_ready_mutex,NULL);
68
 
    pthread_mutex_init(&pdata->img_buff_ready_mutex,NULL);
69
 
    pthread_mutex_init(&pdata->theora_lib_mutex,NULL);
70
 
    pthread_mutex_init(&pdata->vorbis_lib_mutex,NULL);
71
 
    pthread_mutex_init(&pdata->libogg_mutex,NULL);
72
 
    pthread_mutex_init(&pdata->yuv_mutex,NULL);
73
 
    pthread_mutex_init(&pause_mutex,NULL);
74
 
    pthread_mutex_init(&time_mutex,NULL);
75
 
    pthread_cond_init(&pdata->time_cond,NULL);
76
 
    pthread_cond_init(&pdata->pause_cond,NULL);
77
 
    pthread_cond_init(&pdata->image_buffer_ready,NULL);
78
 
    pthread_cond_init(&pdata->sound_buffer_ready,NULL);
79
 
    pthread_cond_init(&pdata->sound_data_read,NULL);
80
 
    pthread_cond_init(&pdata->theora_lib_clean,NULL);
81
 
    pthread_cond_init(&pdata->vorbis_lib_clean,NULL);
82
 
    pdata->th_encoding_clean=pdata->v_encoding_clean=1;
83
 
    Paused=Aborted=pdata->avd=0;
84
 
    pdata->sound_buffer=NULL;
85
 
    pdata->running=1;
86
 
    time_cond=&pdata->time_cond;
87
 
    pause_cond=&pdata->pause_cond;
88
 
    Running=&pdata->running;
89
 
    PauseStateChanged=0;
90
 
 
91
 
    if(!pdata->args.nosound){
92
 
        if(!pdata->args.use_jack){
93
 
            FixBufferSize(&pdata->args.buffsize);
94
 
#ifdef HAVE_LIBASOUND
95
 
            pdata->sound_handle=OpenDev( pdata->args.device,
96
 
                                        &pdata->args.channels,
97
 
                                        &pdata->args.frequency,
98
 
                                        &pdata->args.buffsize,
99
 
                                        &pdata->periodsize,
100
 
                                        &pdata->periodtime,
101
 
                                        &pdata->hard_pause);
102
 
            pdata->sound_framesize=((snd_pcm_format_width(
103
 
                                     SND_PCM_FORMAT_S16_LE))/8)*
104
 
                                     pdata->args.channels;
105
 
 
106
 
            if(pdata->sound_handle==NULL){
107
 
#else
108
 
            pdata->sound_handle=OpenDev(pdata->args.device,
109
 
                                        pdata->args.channels,
110
 
                                        pdata->args.frequency);
111
 
            pdata->periodtime=(1000000*pdata->args.buffsize)/
112
 
                            ((pdata->args.channels<<1)*pdata->args.frequency);
113
 
            //when using OSS periodsize serves as an alias of buffsize
114
 
            pdata->periodsize=pdata->args.buffsize;
115
 
            pdata->sound_framesize=pdata->args.channels<<1;
116
 
            if(pdata->sound_handle<0){
117
 
#endif
118
 
                fprintf(stderr,"Error while opening/configuring soundcard %s\n"
119
 
                            "Try running with the --no-sound or specify a "
120
 
                            "correct device.\n",
121
 
                            pdata->args.device);
122
 
                return 3;
123
 
            }
124
 
        }
125
 
        else{
126
 
#ifdef HAVE_JACK_H
127
 
            int jack_error=0;
128
 
            pdata->jdata->port_names=pdata->args.jack_port_names;
129
 
            pdata->jdata->nports=pdata->args.jack_nports;
130
 
            pdata->jdata->ringbuffer_secs=pdata->args.jack_ringbuffer_secs;
131
 
            pdata->jdata->snd_buff_ready_mutex=&pdata->snd_buff_ready_mutex;
132
 
            pdata->jdata->sound_data_read=&pdata->sound_data_read;
133
 
            pdata->jdata->capture_started=0;
134
 
 
135
 
            if((jack_error=StartJackClient(pdata->jdata))!=0)
136
 
                return jack_error;
137
 
 
138
 
            pdata->args.buffsize=pdata->jdata->buffersize;
139
 
            pdata->periodsize=pdata->args.buffsize;
140
 
            pdata->args.frequency=pdata->jdata->frequency;
141
 
            pdata->args.channels=pdata->jdata->nports;
142
 
            pdata->periodtime=(1000000*pdata->args.buffsize)/
143
 
                              pdata->args.frequency;
144
 
            pdata->sound_framesize=sizeof(jack_default_audio_sample_t)*
145
 
                                   pdata->jdata->nports;
146
 
 
147
 
#else
148
 
            fprintf(stderr,"Should not be here!\n");
149
 
            exit(-1);
150
 
#endif
151
 
        }
152
 
    }
153
 
 
154
 
    if(pdata->args.encOnTheFly)
155
 
        InitEncoder(pdata,enc_data,0);
156
 
    else
157
 
        InitCacheData(pdata,enc_data,cache_data);
158
 
 
159
 
    for(i=0;i<(pdata->enc_data->yuv.y_width*pdata->enc_data->yuv.y_height);i++)
160
 
        pdata->enc_data->yuv.y[i]=0;
161
 
    for(i=0;
162
 
        i<(pdata->enc_data->yuv.uv_width*pdata->enc_data->yuv.uv_height);
163
 
        i++){
164
 
        pdata->enc_data->yuv.v[i]=pdata->enc_data->yuv.u[i]=127;
165
 
    }
166
 
 
167
 
    yblocks=malloc(sizeof(u_int32_t)*(pdata->enc_data->yuv.y_width/Y_UNIT_WIDTH)*
168
 
                (pdata->enc_data->yuv.y_height/Y_UNIT_WIDTH));
169
 
    ublocks=malloc(sizeof(u_int32_t)*(pdata->enc_data->yuv.y_width/Y_UNIT_WIDTH)*
170
 
                (pdata->enc_data->yuv.y_height/Y_UNIT_WIDTH));
171
 
    vblocks=malloc(sizeof(u_int32_t)*(pdata->enc_data->yuv.y_width/Y_UNIT_WIDTH)*
172
 
                (pdata->enc_data->yuv.y_height/Y_UNIT_WIDTH));
173
 
 
174
 
    pdata->frametime=(1000000)/pdata->args.fps;
175
 
    return 0;
176
 
 
177
 
}