Commit e1f1e0df authored by Adrien Béraud's avatar Adrien Béraud

no more dependency to AudioBuffer in codec shared libraries

parent 003c2f7a
......@@ -122,6 +122,13 @@ class AudioBuffer {
*/
std::vector<SFLAudioSample> *getChannel(unsigned chan=0);
/**
* Return a pointer to the raw data in this buffer.
*/
inline std::vector<std::vector<SFLAudioSample> > *getData() {
return &samples_;
}
/**
* Write interleaved multichannel data to the out buffer (fixed-point 16-bits).
* The out buffer must be at least large by capacity()*sizeof(SFLAudioSample) bytes.
......
......@@ -347,7 +347,7 @@ int AudioRtpRecordHandler::processDataEncode()
ScopedLock lock(audioRtpRecord_.audioCodecMutex_);
RETURN_IF_NULL(audioRtpRecord_.getCurrentCodec(), 0, "Audio codec already destroyed");
unsigned char *micDataEncoded = audioRtpRecord_.encodedData_.data();
return audioRtpRecord_.getCurrentCodec()->encode(micDataEncoded, *out, getCodecFrameSize());
return audioRtpRecord_.getCurrentCodec()->encode(micDataEncoded, out->getData(), getCodecFrameSize());
}
}
#undef RETURN_IF_NULL
......@@ -379,7 +379,7 @@ void AudioRtpRecordHandler::processDataDecode(unsigned char *spkrData, size_t si
ScopedLock lock(audioRtpRecord_.audioCodecMutex_);
RETURN_IF_NULL(audioRtpRecord_.getCurrentCodec(), "Audio codecs already destroyed");
// Return the size of data in samples
inSamples = audioRtpRecord_.getCurrentCodec()->decode(audioRtpRecord_.decData_, spkrData, size);
inSamples = audioRtpRecord_.getCurrentCodec()->decode(audioRtpRecord_.decData_.getData(), spkrData, size);
}
#if HAVE_SPEEXDSP
......
......@@ -59,15 +59,17 @@ AudioCodec::AudioCodec(const AudioCodec& c) :
hasDynamicPayload_(c.hasDynamicPayload_)
{}
int AudioCodec::decode(AudioBuffer& dst, unsigned char *buf, size_t buffer_size, size_t dst_offset /* = 0 */)
int AudioCodec::decode(std::vector<std::vector<short> > *dst, unsigned char *buf, size_t buffer_size, size_t dst_offset /* = 0 */)
{
dst.setSampleRate(clockRate_);
return decode(&(*(dst.getChannel()->begin()+dst_offset)), buf, buffer_size);
//dst.setSampleRate(clockRate_);
//return decode(&(*(dst.getChannel()->begin()+dst_offset)), buf, buffer_size);
return decode(&(*((*dst)[0].begin()+dst_offset)), buf, buffer_size);
}
int AudioCodec::encode(unsigned char *dst, AudioBuffer& src, size_t buffer_size)
int AudioCodec::encode(unsigned char *dst, std::vector<std::vector<short> > *src, size_t buffer_size)
{
return encode(dst, src.getChannel()->data(), buffer_size);
//return encode(dst, src.getChannel()->data(), buffer_size);
return encode(dst, (*src)[0].data(), buffer_size);
}
std::string AudioCodec::getMimeSubtype() const
......
......@@ -33,10 +33,12 @@
#define __AUDIO_CODEC_H__
#include <string>
#include <vector>
#include "cc_config.h"
#include <ccrtp/formats.h> // for ost::DynamicPayloadFormat
#include "audio/audiobuffer.h"
//#include "audio/audiobuffer.h"
/* bump when codec binary interface changes */
#define AUDIO_CODEC_ENTRY create_1_2_2
......@@ -81,13 +83,15 @@ class AudioCodec {
* Multichannel version of decode().
* Default implementation decode(short *, unsigned char *, size_t) to the first channel (assume 1 channel).
*/
int decode(AudioBuffer& dst, unsigned char *buf, size_t buffer_size, size_t dst_offset=0);
//int decode(AudioBuffer& dst, unsigned char *buf, size_t buffer_size, size_t dst_offset=0);
int decode(std::vector<std::vector<short> > *dst, unsigned char *buf, size_t buffer_size, size_t dst_offset=0);
/**
* Multichannel version of encode().
* Default implementation calls encode() on the first channel (assume 1 channel).
*/
int encode(unsigned char *dst, AudioBuffer& src, size_t buffer_size);
//int encode(unsigned char *dst, AudioBuffer& src, size_t buffer_size);
int encode(unsigned char *dst, std::vector<std::vector<short> > *src, size_t buffer_size);
uint8 getPayloadType() const;
......
......@@ -56,8 +56,7 @@ AudioCodecFactory::AudioCodecFactory() :
if (codecDynamicList.empty())
ERROR("No codecs available");
else {
for (AudioCodecVector::const_iterator iter = codecDynamicList.begin();
iter != codecDynamicList.end() ; ++iter) {
for (AudioCodecVector::const_iterator iter = codecDynamicList.begin(); iter != codecDynamicList.end() ; ++iter) {
codecsMap_[(int)(*iter)->getPayloadType()] = *iter;
DEBUG("Loaded codec %s" , (*iter)->getMimeSubtype().c_str());
}
......
......@@ -77,7 +77,7 @@ RawFile::RawFile(const std::string& name, sfl::AudioCodec *codec, unsigned int s
while (length >= encFrameSize) {
//bufpos += audioCodec_->decode(bufpos, filepos, encFrameSize);
bufpos += audioCodec_->decode(*buffer, filepos, encFrameSize, bufpos);
bufpos += audioCodec_->decode(buffer->getData(), filepos, encFrameSize, bufpos);
filepos += encFrameSize;
length -= encFrameSize;
}
......
......@@ -214,7 +214,7 @@ IAXVoIPLink::sendAudioFromMic()
in = &decData_;
}
compSize = audioCodec->encode(encodedData_, *in, DEC_BUFFER_SIZE);
compSize = audioCodec->encode(encodedData_, in->getData(), DEC_BUFFER_SIZE);
if (currentCall->session and samples > 0) {
sfl::ScopedLock m(mutexIAX_);
......@@ -650,7 +650,7 @@ void IAXVoIPLink::iaxHandleVoiceEvent(iax_event* event, IAXCall* call)
if (size > max)
size = max;
int samples = audioCodec->decode(decData_, data , size);
int samples = audioCodec->decode(decData_.getData(), data , size);
int outSize = samples * sizeof(SFLAudioSample);
AudioBuffer *out = &decData_;
unsigned int audioRate = audioCodec->getClockRate();
......
......@@ -36,7 +36,7 @@
namespace Logger {
bool consoleLog = false;
bool debugMode = false;
bool debugMode = true;
void log(const int level, const char* format, ...)
{
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment