diff options
Diffstat (limited to 'modules')
-rw-r--r-- | modules/mda/mda.c | 40 | ||||
-rw-r--r-- | modules/mda/mda.h | 17 | ||||
-rw-r--r-- | modules/mda/player.cpp | 176 | ||||
-rw-r--r-- | modules/mda/recorder.cpp | 170 | ||||
-rw-r--r-- | modules/mda/util.cpp | 39 |
5 files changed, 0 insertions, 442 deletions
diff --git a/modules/mda/mda.c b/modules/mda/mda.c deleted file mode 100644 index 208facc..0000000 --- a/modules/mda/mda.c +++ /dev/null @@ -1,40 +0,0 @@ -/** - * @file mda.c Symbian MDA audio driver - * - * Copyright (C) 2010 Creytiv.com - */ -#include <re.h> -#include <baresip.h> -#include "mda.h" - - -static struct auplay *auplay; -static struct ausrc *ausrc; - - -static int module_init(void) -{ - int err; - - err = auplay_register(&auplay, "mda", mda_player_alloc); - err |= ausrc_register(&ausrc, "mda", mda_recorder_alloc); - - return err; -} - - -static int module_close(void) -{ - auplay = mem_deref(auplay); - ausrc = mem_deref(ausrc); - - return 0; -} - - -EXPORT_SYM const struct mod_export DECL_EXPORTS(mda) = { - "mda", - "audio", - module_init, - module_close, -}; diff --git a/modules/mda/mda.h b/modules/mda/mda.h deleted file mode 100644 index eee41d9..0000000 --- a/modules/mda/mda.h +++ /dev/null @@ -1,17 +0,0 @@ -/** - * @file mda.h Symbian MDA audio driver -- Internal interface - * - * Copyright (C) 2010 Creytiv.com - */ - - -int mda_player_alloc(struct auplay_st **stp, struct auplay *ap, - struct auplay_prm *prm, const char *device, - auplay_write_h *wh, void *arg); -int mda_recorder_alloc(struct ausrc_st **stp, struct ausrc *as, - struct media_ctx **ctx, - struct ausrc_prm *prm, const char *device, - ausrc_read_h *rh, ausrc_error_h *errh, void *arg); - -int convert_srate(uint32_t srate); -int convert_channels(uint8_t ch); diff --git a/modules/mda/player.cpp b/modules/mda/player.cpp deleted file mode 100644 index 4cfa18c..0000000 --- a/modules/mda/player.cpp +++ /dev/null @@ -1,176 +0,0 @@ -/** - * @file player.cpp Symbian MDA audio driver -- player - * - * Copyright (C) 2010 Creytiv.com - */ -#include <e32def.h> -#include <e32std.h> -#include <mdaaudiooutputstream.h> -#include <mda/common/audio.h> - -extern "C" { -#include <re.h> -#include <baresip.h> -#include "mda.h" - -#define DEBUG_MODULE "player" -#define DEBUG_LEVEL 5 -#include <re_dbg.h> -} - - -enum {VOLUME = 100}; - -class mda_player; -struct auplay_st { - struct auplay *ap; /* inheritance */ - mda_player *mda; - auplay_write_h *wh; - void *arg; -}; - - -class mda_player : public MMdaAudioOutputStreamCallback, public CBase -{ -public: - mda_player(struct auplay_st *st, struct auplay_prm *prm); - ~mda_player(); - void play(); - - /* from MMdaAudioOutputStreamCallback */ - virtual void MaoscOpenComplete(TInt aError); - virtual void MaoscBufferCopied(TInt aError, const TDesC8& aBuffer); - virtual void MaoscPlayComplete(TInt aError); - -private: - CMdaAudioOutputStream *iOutput; - TMdaAudioDataSettings iSettings; - TBool iIsReady; - TBuf8<320> iBuf; - struct auplay_st *state; -}; - - -mda_player::mda_player(struct auplay_st *st, struct auplay_prm *prm) - :iIsReady(EFalse) -{ - state = st; - - iBuf.FillZ(320); - - iSettings.iSampleRate = convert_srate(prm->srate); - iSettings.iChannels = convert_channels(prm->ch); - iSettings.iVolume = VOLUME; - - iOutput = CMdaAudioOutputStream::NewL(*this); - iOutput->Open(&iSettings); -} - - -mda_player::~mda_player() -{ - if (iOutput) { - iOutput->Stop(); - delete iOutput; - } -} - - -void mda_player::play() -{ - /* call write handler here */ - state->wh((uint8_t *)&iBuf[0], iBuf.Length(), state->arg); - - TRAPD(ret, iOutput->WriteL(iBuf)); - if (KErrNone != ret) { - DEBUG_WARNING("WriteL left with %d\n", ret); - } -} - - -void mda_player::MaoscOpenComplete(TInt aError) -{ - if (KErrNone != aError) { - iIsReady = EFalse; - DEBUG_WARNING("mda player error: %d\n", aError); - return; - } - - iOutput->SetAudioPropertiesL(iSettings.iSampleRate, - iSettings.iChannels); - iOutput->SetPriority(EMdaPriorityNormal, - EMdaPriorityPreferenceTime); - - iIsReady = ETrue; - - play(); -} - - -/* - * Note: In reality, this function is called approx. 1 millisecond after the - * last block was played, hence we have to generate buffer N+1 while buffer N - * is playing. - */ -void mda_player::MaoscBufferCopied(TInt aError, const TDesC8& aBuffer) -{ - (void)aBuffer; - - if (KErrNone != aError && KErrCancel != aError) { - DEBUG_WARNING("MaoscBufferCopied [aError=%d]\n", aError); - } - if (aError == KErrAbort) { - DEBUG_NOTICE("player aborted\n"); - return; - } - - play(); -} - - -void mda_player::MaoscPlayComplete(TInt aError) -{ - if (KErrNone != aError) { - DEBUG_WARNING("MaoscPlayComplete [aError=%d]\n", aError); - } -} - - -static void auplay_destructor(void *arg) -{ - struct auplay_st *st = (struct auplay_st *)arg; - - delete st->mda; - - mem_deref(st->ap); -} - - -int mda_player_alloc(struct auplay_st **stp, struct auplay *ap, - struct auplay_prm *prm, const char *device, - auplay_write_h *wh, void *arg) -{ - struct auplay_st *st; - int err = 0; - - (void)device; - - st = (struct auplay_st *)mem_zalloc(sizeof(*st), auplay_destructor); - if (!st) - return ENOMEM; - - st->ap = (struct auplay *)mem_ref(ap); - st->wh = wh; - st->arg = arg; - - st->mda = new mda_player(st, prm); - if (!st->mda) - err = ENOMEM; - - if (err) - mem_deref(st); - else - *stp = st; - - return err; -} diff --git a/modules/mda/recorder.cpp b/modules/mda/recorder.cpp deleted file mode 100644 index 6c358dc..0000000 --- a/modules/mda/recorder.cpp +++ /dev/null @@ -1,170 +0,0 @@ -/** - * @file recorder.cpp Symbian MDA audio driver -- recorder - * - * Copyright (C) 2010 Creytiv.com - */ -#include <e32def.h> -#include <e32std.h> -#include <mdaaudioinputstream.h> -#include <mda/common/audio.h> - -extern "C" { -#include <re.h> -#include <baresip.h> -#include "mda.h" - -#define DEBUG_MODULE "recorder" -#define DEBUG_LEVEL 5 -#include <re_dbg.h> -} - - -enum {VOLUME = 100}; - -class mda_recorder; -struct ausrc_st { - struct ausrc *as; /* inheritance */ - mda_recorder *mda; - ausrc_read_h *rh; - void *arg; -}; - - -class mda_recorder : public MMdaAudioInputStreamCallback, public CBase -{ -public: - mda_recorder(struct ausrc_st *st, struct ausrc_prm *prm); - ~mda_recorder(); - - /* from MMdaAudioInputStreamCallback */ - virtual void MaiscOpenComplete(TInt aError); - virtual void MaiscBufferCopied(TInt aError, const TDesC8& aBuffer); - virtual void MaiscRecordComplete(TInt aError); - -private: - CMdaAudioInputStream *iInput; - TMdaAudioDataSettings iSettings; - TBool iIsReady; - TBuf8<320> iBuf; - struct ausrc_st *state; -}; - - -mda_recorder::mda_recorder(struct ausrc_st *st, struct ausrc_prm *prm) - :iIsReady(EFalse) -{ - state = st; - - iInput = CMdaAudioInputStream::NewL(*this); - - iSettings.iSampleRate = convert_srate(prm->srate); - iSettings.iChannels = convert_channels(prm->ch); - iSettings.iVolume = VOLUME; - - iInput->Open(&iSettings); -} - - -mda_recorder::~mda_recorder() -{ - if (iInput) { - iInput->Stop(); - delete iInput; - } -} - - -void mda_recorder::MaiscOpenComplete(TInt aError) -{ - if (KErrNone != aError) { - DEBUG_WARNING("MaiscOpenComplete %d\n", aError); - return; - } - - iInput->SetGain(iInput->MaxGain()); - iInput->SetAudioPropertiesL(iSettings.iSampleRate, - iSettings.iChannels); - iInput->SetPriority(EMdaPriorityNormal, - EMdaPriorityPreferenceTime); - - TRAPD(ret, iInput->ReadL(iBuf)); - if (KErrNone != ret) { - DEBUG_WARNING("ReadL left with %d\n", ret); - } -} - - -void mda_recorder::MaiscBufferCopied(TInt aError, const TDesC8& aBuffer) -{ - if (KErrNone != aError) { - DEBUG_WARNING("MaiscBufferCopied: error=%d %d bytes\n", - aError, aBuffer.Length()); - return; - } - - state->rh(aBuffer.Ptr(), aBuffer.Length(), state->arg); - - iBuf.Zero(); - TRAPD(ret, iInput->ReadL(iBuf)); - if (KErrNone != ret) { - DEBUG_WARNING("ReadL left with %d\n", ret); - } -} - - -void mda_recorder::MaiscRecordComplete(TInt aError) -{ - DEBUG_NOTICE("MaiscRecordComplete: error=%d\n", aError); - -#if 0 - if (KErrOverflow == aError) { - - /* re-open input stream */ - iInput->Stop(); - iInput->Open(&iSettings); - } -#endif -} - - -static void ausrc_destructor(void *arg) -{ - struct ausrc_st *st = (struct ausrc_st *)arg; - - delete st->mda; - - mem_deref(st->as); -} - - -int mda_recorder_alloc(struct ausrc_st **stp, struct ausrc *as, - struct media_ctx **ctx, - struct ausrc_prm *prm, const char *device, - ausrc_read_h *rh, ausrc_error_h *errh, void *arg) -{ - struct ausrc_st *st; - int err = 0; - - (void)ctx; - (void)device; - (void)errh; - - st = (struct ausrc_st *)mem_zalloc(sizeof(*st), ausrc_destructor); - if (!st) - return ENOMEM; - - st->as = (struct ausrc *)mem_ref(as); - st->rh = rh; - st->arg = arg; - - st->mda = new mda_recorder(st, prm); - if (!st->mda) - err = ENOMEM; - - if (err) - mem_deref(st); - else - *stp = st; - - return err; -} diff --git a/modules/mda/util.cpp b/modules/mda/util.cpp deleted file mode 100644 index b879c7f..0000000 --- a/modules/mda/util.cpp +++ /dev/null @@ -1,39 +0,0 @@ -/** - * @file util.cpp Symbian MDA audio driver -- utilities - * - * Copyright (C) 2010 Creytiv.com - */ -#include <e32def.h> -#include <e32std.h> -#include <mda/common/audio.h> - -extern "C" { -#include <re.h> -#include <baresip.h> -#include "mda.h" -} - - -int convert_srate(uint32_t srate) -{ - switch (srate) { - - case 8000: return TMdaAudioDataSettings::ESampleRate8000Hz; - case 12000: return TMdaAudioDataSettings::ESampleRate12000Hz; - case 16000: return TMdaAudioDataSettings::ESampleRate16000Hz; - case 24000: return TMdaAudioDataSettings::ESampleRate24000Hz; - case 32000: return TMdaAudioDataSettings::ESampleRate32000Hz; - default: return -1; - } -} - - -int convert_channels(uint8_t ch) -{ - switch (ch) { - - case 1: return TMdaAudioDataSettings::EChannelsMono; - case 2: return TMdaAudioDataSettings::EChannelsStereo; - default: return -1; - } -} |