1
/******************************************************************************
3
*******************************************************************************
5
* Copyright (C) 2006,2007,2008 John Varouhakis *
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. *
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. *
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 *
24
* For further information contact me at johnvarouhakis@gmail.com *
25
******************************************************************************/
28
#include "rmd_initialize_data.h"
30
#include "rmd_cache.h"
31
#include "rmd_init_encoder.h"
33
#include "rmd_make_dummy_pointer.h"
34
#include "rmd_opendev.h"
35
#include "rmd_yuv_utils.h"
36
#include "rmd_types.h"
45
static void FixBufferSize(snd_pcm_uframes_t *buffsize) {
46
snd_pcm_uframes_t buffsize_t=*buffsize,
48
static void FixBufferSize(u_int32_t *buffsize) {
49
u_int32_t buffsize_t=*buffsize,
56
fprintf(stderr,"Buffer size adjusted to %d from %d frames.\n",
57
(int)buffsize_ret,(int)*buffsize);
60
int InitializeData(ProgData *pdata,
62
CacheData *cache_data){
65
fprintf(stderr,"Initializing...\n");
67
if(pdata->args.have_dummy_cursor){
68
pdata->dummy_pointer = MakeDummyPointer(pdata->dpy,
71
pdata->args.cursor_color,
74
pdata->dummy_p_size=16;
77
pdata->dummy_p_size=0;
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;
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;
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,
119
pdata->sound_framesize=((snd_pcm_format_width(
120
SND_PCM_FORMAT_S16_LE))/8)*
121
pdata->args.channels;
123
if(pdata->sound_handle==NULL){
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){
135
fprintf(stderr,"Error while opening/configuring soundcard %s\n"
136
"Try running with the --no-sound or specify a "
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;
152
if((jack_error=StartJackClient(pdata->jdata))!=0)
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;
165
fprintf(stderr,"Should not be here!\n");
171
if(pdata->args.encOnTheFly)
172
InitEncoder(pdata,enc_data,0);
174
InitCacheData(pdata,enc_data,cache_data);
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;
179
i<(pdata->enc_data->yuv.uv_width*pdata->enc_data->yuv.uv_height);
181
pdata->enc_data->yuv.v[i]=pdata->enc_data->yuv.u[i]=127;
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));
191
pdata->frametime=(1000000)/pdata->args.fps;
196
void SetupDefaultArgs(ProgArgs *args) {
204
args->rescue_path = NULL;
206
args->full_shots = 0;
207
args->follow_mouse = 0;
208
args->encOnTheFly = 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;
225
args->frequency = 22050;
226
args->buffsize = 4096;
227
args->v_bitrate = 45000;
228
args->v_quality = 63;
229
args->s_quality = 10;
231
if (getenv("DISPLAY") != NULL) {
232
args->display = (char *) malloc(strlen(getenv("DISPLAY")) + 1);
233
strcpy(args->display, getenv("DISPLAY"));
236
args->display = NULL;
239
args->device = (char *) malloc(strlen(DEFAULT_AUDIO_DEVICE) + 1);
240
strcpy(args->device, DEFAULT_AUDIO_DEVICE);
242
args->workdir = (char *) malloc(5);
243
strcpy(args->workdir, "/tmp");
245
args->pause_shortcut = (char *) malloc(15);
246
strcpy(args->pause_shortcut, "Control+Mod1+p");
248
args->stop_shortcut = (char *) malloc(15);
249
strcpy(args->stop_shortcut, "Control+Mod1+s");
251
args->filename = (char *) malloc(8);
252
strcpy(args->filename, "out.ogv");