Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
savoirfairelinux
jami-daemon
Commits
cce5909c
Commit
cce5909c
authored
Oct 11, 2011
by
Tristan Matthews
Browse files
* #7097: more cleanup in audio backend
parent
16e6a3c1
Changes
4
Hide whitespace changes
Inline
Side-by-side
daemon/src/audio/audiolayer.h
View file @
cce5909c
...
...
@@ -31,8 +31,8 @@
* as that of the covered work.
*/
#ifndef _AUDIO_LAYER_H
#define _AUDIO_LAYER_H
#ifndef
_
_AUDIO_LAYER_H
__
#define
_
_AUDIO_LAYER_H
__
#include
<cc++/thread.h>
// for ost::Mutex
#include
<sys/time.h>
...
...
@@ -59,7 +59,7 @@ class AudioLayer {
AudioLayer
(
const
AudioLayer
&
rh
);
// assignment operator
AudioLayer
&
operator
=
(
const
AudioLayer
&
rh
);
const
AudioLayer
&
operator
=
(
const
AudioLayer
&
rh
);
public:
/**
...
...
@@ -70,23 +70,23 @@ class AudioLayer {
/**
* Destructor
*/
virtual
~
AudioLayer
(
void
);
virtual
~
AudioLayer
();
/**
* Start the capture stream and prepare the playback stream.
* The playback starts accordingly to its threshold
* ALSA Library API
*/
virtual
void
startStream
(
void
)
=
0
;
virtual
void
startStream
()
=
0
;
/**
* Stop the playback and capture streams.
* Drops the pending frames and put the capture and playback handles to PREPARED state
* ALSA Library API
*/
virtual
void
stopStream
(
void
)
=
0
;
virtual
void
stopStream
()
=
0
;
bool
isStarted
(
void
)
const
{
bool
isStarted
()
const
{
return
isStarted_
;
}
...
...
@@ -98,9 +98,9 @@ class AudioLayer {
*/
void
putUrgent
(
void
*
buffer
,
int
toCopy
);
void
flushMain
(
void
);
void
flushMain
();
void
flushUrgent
(
void
);
void
flushUrgent
();
/**
...
...
@@ -115,11 +115,11 @@ class AudioLayer {
/**
* Get the mutex lock for the entire audio layer
*/
ost
::
Mutex
*
getMutexLock
(
void
)
{
ost
::
Mutex
*
getMutexLock
()
{
return
&
mutex_
;
}
void
notifyincomingCall
(
void
);
void
notifyincomingCall
();
protected:
...
...
daemon/src/audio/audioloop.h
View file @
cce5909c
...
...
@@ -90,7 +90,7 @@ class AudioLoop {
AudioLoop
(
const
AudioLoop
&
rh
);
// Assignment Operator
AudioLoop
&
operator
=
(
const
AudioLoop
&
rh
);
const
AudioLoop
&
operator
=
(
const
AudioLoop
&
rh
);
};
#endif // __AUDIOLOOP_H__
...
...
daemon/src/audio/audiorecord.cpp
View file @
cce5909c
...
...
@@ -51,7 +51,7 @@ struct wavhdr {
};
AudioRecord
::
AudioRecord
()
:
f
p
(
NULL
)
AudioRecord
::
AudioRecord
()
:
f
ileHandle_
(
NULL
)
,
channels_
(
1
)
,
byteCounter_
(
0
)
,
sndSmplRate_
(
8000
)
...
...
@@ -59,15 +59,10 @@ AudioRecord::AudioRecord() : fp(NULL)
,
nbSamplesSpk_
(
0
)
,
nbSamplesMax_
(
3000
)
,
recordingEnabled_
(
false
)
,
mixBuffer_
(
NULL
)
,
micBuffer_
(
NULL
)
,
spkBuffer_
(
NULL
)
,
mixBuffer_
(
new
SFLDataFormat
[
nbSamplesMax_
]
)
,
micBuffer_
(
new
SFLDataFormat
[
nbSamplesMax_
]
)
,
spkBuffer_
(
new
SFLDataFormat
[
nbSamplesMax_
]
)
{
mixBuffer_
=
new
SFLDataFormat
[
nbSamplesMax_
];
micBuffer_
=
new
SFLDataFormat
[
nbSamplesMax_
];
spkBuffer_
=
new
SFLDataFormat
[
nbSamplesMax_
];
createFilename
();
}
...
...
@@ -100,11 +95,8 @@ void AudioRecord::setRecordingOption(FILE_TYPE type, int sndSmplRate, const std:
void
AudioRecord
::
initFileName
(
std
::
string
peerNumber
)
{
std
::
string
fName
;
fName
=
fileName_
;
fName
.
append
(
"-"
+
peerNumber
);
std
::
string
fName
=
fileName_
;
fName
.
append
(
"-"
+
peerNumber
);
if
(
fileType_
==
FILE_RAW
)
{
if
(
strstr
(
fileName_
,
".raw"
)
==
NULL
)
{
...
...
@@ -128,28 +120,24 @@ std::string AudioRecord::getFileName()
bool
AudioRecord
::
openFile
()
{
bool
result
=
false
;
_debug
(
"AudioRecord: Open file()"
);
if
(
isF
ileExist
())
{
if
(
not
f
ileExist
s
())
{
_debug
(
"AudioRecord: Filename does not exist, creating one"
);
byteCounter_
=
0
;
if
(
fileType_
==
FILE_RAW
)
{
if
(
fileType_
==
FILE_RAW
)
result
=
setRawFile
();
}
else
if
(
fileType_
==
FILE_WAV
)
{
else
if
(
fileType_
==
FILE_WAV
)
result
=
setWavFile
();
}
}
else
{
_debug
(
"AudioRecord: Filename already exist opening it"
);
if
(
fileType_
==
FILE_RAW
)
{
_debug
(
"AudioRecord: Filename already exists, opening it"
);
if
(
fileType_
==
FILE_RAW
)
result
=
openExistingRawFile
();
}
else
if
(
fileType_
==
FILE_WAV
)
{
else
if
(
fileType_
==
FILE_WAV
)
result
=
openExistingWavFile
();
}
}
return
result
;
...
...
@@ -158,65 +146,45 @@ bool AudioRecord::openFile()
void
AudioRecord
::
closeFile
()
{
if
(
fp
==
0
)
return
;
if
(
fileHandle_
==
0
)
return
;
if
(
fileType_
==
FILE_RAW
)
fclose
(
f
p
);
fclose
(
f
ileHandle_
);
else
if
(
fileType_
==
FILE_WAV
)
this
->
closeWavFile
();
}
bool
AudioRecord
::
isOpenFile
()
{
if
(
fp
)
{
return
true
;
}
else
{
return
false
;
}
return
fileHandle_
!=
0
;
}
bool
AudioRecord
::
isF
ileExist
()
bool
AudioRecord
::
f
ileExist
s
()
{
_info
(
"AudioRecord: Try to open name : %s "
,
fileName_
);
if
(
fopen
(
fileName_
,
"rb"
)
==
0
)
{
return
true
;
}
return
false
;
_info
(
"AudioRecord: Trying to open %s "
,
fileName_
);
return
fopen
(
fileName_
,
"rb"
)
!=
0
;
}
bool
AudioRecord
::
isRecording
()
bool
AudioRecord
::
isRecording
()
const
{
if
(
recordingEnabled_
)
return
true
;
else
return
false
;
return
recordingEnabled_
;
}
bool
AudioRecord
::
setRecording
()
{
if
(
isOpenFile
())
{
if
(
!
recordingEnabled_
)
{
_info
(
"AudioRecording: Start recording"
);
recordingEnabled_
=
true
;
}
else
{
recordingEnabled_
=
false
;
_info
(
"AudioRecording: Stop recording"
);
recordingEnabled_
=
false
;
}
}
else
{
openFile
();
recordingEnabled_
=
true
;
// once opend file, start recording
}
...
...
@@ -228,15 +196,12 @@ bool AudioRecord::setRecording()
void
AudioRecord
::
stopRecording
()
{
_info
(
"AudioRecording: Stop recording"
);
if
(
recordingEnabled_
)
recordingEnabled_
=
false
;
recordingEnabled_
=
false
;
}
void
AudioRecord
::
createFilename
()
{
time_t
rawtime
;
struct
tm
*
timeinfo
;
...
...
@@ -289,10 +254,9 @@ void AudioRecord::createFilename()
bool
AudioRecord
::
setRawFile
()
{
fileHandle_
=
fopen
(
savePath_
.
c_str
(),
"wb"
);
fp
=
fopen
(
savePath_
.
c_str
(),
"wb"
);
if
(
!
fp
)
{
if
(
!
fileHandle_
)
{
_warn
(
"AudioRecord: Could not create RAW file!"
);
return
false
;
}
...
...
@@ -307,9 +271,9 @@ bool AudioRecord::setWavFile()
{
_debug
(
"AudioRecord: Create new wave file %s, sampling rate: %d"
,
savePath_
.
c_str
(),
sndSmplRate_
);
f
p
=
fopen
(
savePath_
.
c_str
(),
"wb"
);
f
ileHandle_
=
fopen
(
savePath_
.
c_str
(),
"wb"
);
if
(
!
f
p
)
{
if
(
!
f
ileHandle_
)
{
_warn
(
"AudioRecord: Error: could not create WAV file."
);
return
false
;
}
...
...
@@ -335,7 +299,7 @@ bool AudioRecord::setWavFile()
hdr
.
bytes_per_sec
=
(
SINT32
)(
hdr
.
sample_rate
*
hdr
.
bytes_per_samp
);
if
(
fwrite
(
&
hdr
,
4
,
11
,
f
p
)
!=
11
)
{
if
(
fwrite
(
&
hdr
,
4
,
11
,
f
ileHandle_
)
!=
11
)
{
_warn
(
"AudioRecord: Error: could not write WAV header for file. "
);
return
false
;
}
...
...
@@ -348,9 +312,9 @@ bool AudioRecord::setWavFile()
bool
AudioRecord
::
openExistingRawFile
()
{
f
p
=
fopen
(
fileName_
,
"ab+"
);
f
ileHandle_
=
fopen
(
fileName_
,
"ab+"
);
if
(
!
f
p
)
{
if
(
!
f
ileHandle_
)
{
_warn
(
"AudioRecord: could not create RAW file!"
);
return
false
;
}
...
...
@@ -363,146 +327,123 @@ bool AudioRecord::openExistingWavFile()
{
_info
(
"%s(%s)
\n
"
,
__PRETTY_FUNCTION__
,
fileName_
);
f
p
=
fopen
(
fileName_
,
"rb+"
);
f
ileHandle_
=
fopen
(
fileName_
,
"rb+"
);
if
(
!
f
p
)
{
if
(
!
f
ileHandle_
)
{
_warn
(
"AudioRecord: Error: could not open WAV file!"
);
return
false
;
}
if
(
fseek
(
f
p
,
40
,
SEEK_SET
)
!=
0
)
// jump to data length
if
(
fseek
(
f
ileHandle_
,
40
,
SEEK_SET
)
!=
0
)
// jump to data length
_warn
(
"AudioRecord: Error: Couldn't seek offset 40 in the file "
);
if
(
fread
(
&
byteCounter_
,
4
,
1
,
f
p
))
if
(
fread
(
&
byteCounter_
,
4
,
1
,
f
ileHandle_
))
_warn
(
"AudioRecord: Error: bytecounter Read successfully "
);
if
(
fseek
(
f
p
,
0
,
SEEK_END
)
!=
0
)
if
(
fseek
(
f
ileHandle_
,
0
,
SEEK_END
)
!=
0
)
_warn
(
"AudioRecord: Error: Couldn't seek at the en of the file "
);
if
(
fclose
(
f
p
)
!=
0
)
if
(
fclose
(
f
ileHandle_
)
!=
0
)
_warn
(
"AudioRecord: Error: Can't close file r+ "
);
fileHandle_
=
fopen
(
fileName_
,
"ab+"
);
fp
=
fopen
(
fileName_
,
"ab+"
);
if
(
!
fp
)
{
if
(
!
fileHandle_
)
{
_warn
(
"AudioRecord: Error: Could not createopen WAV file ab+!"
);
return
false
;
}
if
(
fseek
(
f
p
,
4
,
SEEK_END
)
!=
0
)
if
(
fseek
(
f
ileHandle_
,
4
,
SEEK_END
)
!=
0
)
_warn
(
"AudioRecord: Error: Couldn't seek at the en of the file "
);
return
true
;
}
void
AudioRecord
::
closeWavFile
()
{
if
(
f
p
==
0
)
{
if
(
f
ileHandle_
==
0
)
{
_debug
(
"AudioRecord: Can't closeWavFile, a file has not yet been opened!"
);
return
;
}
_debug
(
"AudioRecord: Close wave file"
);
SINT32
bytes
=
byteCounter_
*
channels_
;
fseek
(
f
p
,
40
,
SEEK_SET
);
// jump to data length
fseek
(
f
ileHandle_
,
40
,
SEEK_SET
);
// jump to data length
if
(
ferror
(
f
p
))
if
(
ferror
(
f
ileHandle_
))
_warn
(
"AudioRecord: Error: can't reach offset 40 while closing"
);
fwrite
(
&
bytes
,
sizeof
(
SINT32
),
1
,
f
p
);
fwrite
(
&
bytes
,
sizeof
(
SINT32
),
1
,
f
ileHandle_
);
if
(
ferror
(
f
p
))
if
(
ferror
(
f
ileHandle_
))
_warn
(
"AudioRecord: Error: can't write bytes for data length "
);
bytes
=
byteCounter_
*
channels_
+
44
;
// + 44 for the wave header
fseek
(
f
p
,
4
,
SEEK_SET
);
// jump to file size
fseek
(
f
ileHandle_
,
4
,
SEEK_SET
);
// jump to file size
if
(
ferror
(
f
p
))
if
(
ferror
(
f
ileHandle_
))
_warn
(
"AudioRecord: Error: can't reach offset 4"
);
fwrite
(
&
bytes
,
4
,
1
,
f
p
);
fwrite
(
&
bytes
,
4
,
1
,
f
ileHandle_
);
if
(
ferror
(
f
p
))
if
(
ferror
(
f
ileHandle_
))
_warn
(
"AudioRecord: Error: can't reach offset 4"
);
if
(
fclose
(
fp
)
!=
0
)
if
(
fclose
(
fileHandle_
)
!=
0
)
_warn
(
"AudioRecord: Error: can't close file"
);
}
void
AudioRecord
::
recSpkrData
(
SFLDataFormat
*
buffer
,
int
nSamples
)
{
if
(
recordingEnabled_
)
{
nbSamplesMic_
=
nSamples
;
for
(
int
i
=
0
;
i
<
nbSamplesMic_
;
i
++
)
micBuffer_
[
i
]
=
buffer
[
i
];
}
return
;
}
void
AudioRecord
::
recMicData
(
SFLDataFormat
*
buffer
,
int
nSamples
)
{
if
(
recordingEnabled_
)
{
nbSamplesSpk_
=
nSamples
;
for
(
int
i
=
0
;
i
<
nbSamplesSpk_
;
i
++
)
spkBuffer_
[
i
]
=
buffer
[
i
];
}
return
;
}
void
AudioRecord
::
recData
(
SFLDataFormat
*
buffer
,
int
nSamples
)
{
if
(
recordingEnabled_
)
{
if
(
fp
==
0
)
{
if
(
fileHandle_
==
0
)
{
_debug
(
"AudioRecord: Can't record data, a file has not yet been opened!"
);
return
;
}
if
(
fwrite
(
buffer
,
sizeof
(
SFLDataFormat
),
nSamples
,
f
p
)
!=
(
unsigned
int
)
nSamples
)
if
(
fwrite
(
buffer
,
sizeof
(
SFLDataFormat
),
nSamples
,
f
ileHandle_
)
!=
(
unsigned
int
)
nSamples
)
_warn
(
"AudioRecord: Could not record data! "
);
else
{
fflush
(
f
p
);
fflush
(
f
ileHandle_
);
byteCounter_
+=
(
unsigned
long
)(
nSamples
*
sizeof
(
SFLDataFormat
));
}
}
return
;
}
void
AudioRecord
::
recData
(
SFLDataFormat
*
buffer_1
,
SFLDataFormat
*
buffer_2
,
int
nSamples_1
,
int
nSamples_2
UNUSED
)
void
AudioRecord
::
recData
(
SFLDataFormat
*
buffer_1
,
SFLDataFormat
*
buffer_2
,
int
nSamples_1
,
int
/*nSamples_2*/
)
{
if
(
recordingEnabled_
)
{
_debug
(
"Recording enabled"
);
if
(
fp
==
0
)
{
if
(
fileHandle_
==
0
)
{
_debug
(
"AudioRecord: Can't record data, a file has not yet been opened!"
);
return
;
}
...
...
@@ -510,15 +451,13 @@ void AudioRecord::recData(SFLDataFormat* buffer_1, SFLDataFormat* buffer_2, int
for
(
int
k
=
0
;
k
<
nSamples_1
;
k
++
)
{
mixBuffer_
[
k
]
=
(
buffer_1
[
k
]
+
buffer_2
[
k
]);
if
(
fwrite
(
&
mixBuffer_
[
k
],
2
,
1
,
f
p
)
!=
1
)
if
(
fwrite
(
&
mixBuffer_
[
k
],
2
,
1
,
f
ileHandle_
)
!=
1
)
_warn
(
"AudioRecord: Could not record data!"
);
else
fflush
(
f
p
);
fflush
(
f
ileHandle_
);
}
byteCounter_
+=
(
unsigned
long
)(
nSamples_1
*
sizeof
(
SFLDataFormat
));
}
return
;
}
daemon/src/audio/audiorecord.h
View file @
cce5909c
...
...
@@ -49,7 +49,7 @@ class AudioRecord {
/**
* Get the recrding sampling rate
*/
int
getSndSamplingRate
(
void
)
const
;
int
getSndSamplingRate
()
const
;
void
setRecordingOption
(
FILE_TYPE
type
,
int
sndSmplRate
,
const
std
::
string
&
path
);
...
...
@@ -61,7 +61,7 @@ class AudioRecord {
/**
* Return the filepath of the recording
*/
std
::
string
getFileName
(
void
);
std
::
string
getFileName
();
/**
* Check if no otehr file is opened, then create a new one
...
...
@@ -83,14 +83,14 @@ class AudioRecord {
bool
isOpenFile
();
/**
* Check if a file already exist
* Check if a file already exist
s
*/
bool
isF
ileExist
();
bool
f
ileExist
s
();
/**
* Check recording state
*/
bool
isRecording
();
bool
isRecording
()
const
;
/**
* Set recording flag
...
...
@@ -170,7 +170,7 @@ class AudioRecord {
/**
* Pointer to the recorded file
*/
FILE
*
f
p
;
//file pointer
FILE
*
f
ileHandle_
;
/**
* File format (RAW / WAVE)
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment