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 <recordmydesktop.h>
31
void FixBufferSize(snd_pcm_uframes_t *buffsize){
32
snd_pcm_uframes_t buffsize_t=*buffsize,
34
void FixBufferSize(u_int32_t *buffsize){
35
u_int32_t buffsize_t=*buffsize,
42
fprintf(stderr,"Buffer size adjusted to %d from %d frames.\n",
43
(int)buffsize_ret,(int)*buffsize);
46
int InitializeData(ProgData *pdata,
48
CacheData *cache_data){
50
//these are globals, look for them at the header
51
frames_total=frames_lost=encoder_busy=capture_busy=0;
53
fprintf(stderr,"Initializing...\n");
55
if(pdata->args.have_dummy_cursor){
56
pdata->dummy_pointer=MakeDummyPointer(&pdata->specs,16,
57
pdata->args.cursor_color,0,
59
pdata->dummy_p_size=16;
62
pdata->dummy_p_size=0;
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;
86
time_cond=&pdata->time_cond;
87
pause_cond=&pdata->pause_cond;
88
Running=&pdata->running;
91
if(!pdata->args.nosound){
92
if(!pdata->args.use_jack){
93
FixBufferSize(&pdata->args.buffsize);
95
pdata->sound_handle=OpenDev( pdata->args.device,
96
&pdata->args.channels,
97
&pdata->args.frequency,
98
&pdata->args.buffsize,
102
pdata->sound_framesize=((snd_pcm_format_width(
103
SND_PCM_FORMAT_S16_LE))/8)*
104
pdata->args.channels;
106
if(pdata->sound_handle==NULL){
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){
118
fprintf(stderr,"Error while opening/configuring soundcard %s\n"
119
"Try running with the --no-sound or specify a "
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;
135
if((jack_error=StartJackClient(pdata->jdata))!=0)
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;
148
fprintf(stderr,"Should not be here!\n");
154
if(pdata->args.encOnTheFly)
155
InitEncoder(pdata,enc_data,0);
157
InitCacheData(pdata,enc_data,cache_data);
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;
162
i<(pdata->enc_data->yuv.uv_width*pdata->enc_data->yuv.uv_height);
164
pdata->enc_data->yuv.v[i]=pdata->enc_data->yuv.u[i]=127;
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));
174
pdata->frametime=(1000000)/pdata->args.fps;