Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit baeb6ddd authored by Andreas Huber's avatar Andreas Huber Committed by Android Git Automerger
Browse files

am 781ac162: Merge change I8768f2cc into eclair-mr2

Merge commit '781ac16283574ec07cd7b13d67b54b7b4c2c15cb' into eclair-mr2-plus-aosp

* commit '781ac16283574ec07cd7b13d67b54b7b4c2c15cb':
  A small sample tool to encode pcm audio data to amr, decode it again and play it. Some changes to OMXCodec to properly configure the AMR decoder(s).
parents ab762493 c297fccf
Loading
Loading
Loading
Loading
+22 −0
Original line number Diff line number Diff line
@@ -43,4 +43,26 @@ LOCAL_MODULE:= record

include $(BUILD_EXECUTABLE)

################################################################################

include $(CLEAR_VARS)

LOCAL_SRC_FILES:=         \
        SineSource.cpp    \
        audioloop.cpp

LOCAL_SHARED_LIBRARIES := \
	libstagefright

LOCAL_C_INCLUDES:= \
	$(JNI_H_INCLUDE) \
	frameworks/base/media/libstagefright \
	$(TOP)/external/opencore/extern_libs_v2/khronos/openmax/include

LOCAL_CFLAGS += -Wno-multichar

LOCAL_MODULE:= audioloop

include $(BUILD_EXECUTABLE)

endif
+1 −0
Original line number Diff line number Diff line
@@ -52,6 +52,7 @@ sp<MetaData> SineSource::getFormat() {
    meta->setCString(kKeyMIMEType, MEDIA_MIMETYPE_AUDIO_RAW);
    meta->setInt32(kKeyChannelCount, mNumChannels);
    meta->setInt32(kKeySampleRate, mSampleRate);
    meta->setInt32(kKeyMaxInputSize, kBufferSize);

    return meta;
}
+81 −0
Original line number Diff line number Diff line
#include "SineSource.h"

#include <binder/ProcessState.h>
#include <media/stagefright/AudioPlayer.h>
#include <media/stagefright/MediaDebug.h>
#include <media/stagefright/MediaDefs.h>
#include <media/stagefright/MetaData.h>
#include <media/stagefright/OMXClient.h>
#include <media/stagefright/OMXCodec.h>

using namespace android;

int main() {
    // We only have an AMR-WB encoder on sholes...
    static bool outputWBAMR = false;
    static const int32_t kSampleRate = outputWBAMR ? 16000 : 8000;
    static const int32_t kNumChannels = 1;

    android::ProcessState::self()->startThreadPool();

    OMXClient client;
    CHECK_EQ(client.connect(), OK);

    sp<MediaSource> source = new SineSource(kSampleRate, kNumChannels);

    sp<MetaData> meta = new MetaData;

    meta->setCString(
            kKeyMIMEType,
            outputWBAMR ? MEDIA_MIMETYPE_AUDIO_AMR_WB
                        : MEDIA_MIMETYPE_AUDIO_AMR_NB);

    meta->setInt32(kKeyChannelCount, kNumChannels);
    meta->setInt32(kKeySampleRate, kSampleRate);

    int32_t maxInputSize;
    if (source->getFormat()->findInt32(kKeyMaxInputSize, &maxInputSize)) {
        meta->setInt32(kKeyMaxInputSize, maxInputSize);
    }

    sp<OMXCodec> encoder = OMXCodec::Create(
            client.interface(),
            meta, true /* createEncoder */,
            source);

    sp<OMXCodec> decoder = OMXCodec::Create(
            client.interface(),
            meta, false /* createEncoder */,
            encoder);

#if 1
    AudioPlayer *player = new AudioPlayer(NULL);
    player->setSource(decoder);

    player->start();

    sleep(10);

    player->stop();

    delete player;
    player = NULL;
#else
    CHECK_EQ(decoder->start(), OK);

    MediaBuffer *buffer;
    while (decoder->read(&buffer) == OK) {
        // do something with buffer

        putchar('.');
        fflush(stdout);

        buffer->release();
        buffer = NULL;
    }

    CHECK_EQ(decoder->stop(), OK);
#endif

    return 0;
}
+1 −2
Original line number Diff line number Diff line
@@ -146,8 +146,7 @@ private:

    void setComponentRole();

    void setAMRFormat();
    void setAMRWBFormat();
    void setAMRFormat(bool isWAMR);
    void setAACFormat(int32_t numChannels, int32_t sampleRate);

    status_t setVideoPortFormatType(
+15 −45
Original line number Diff line number Diff line
@@ -416,10 +416,10 @@ sp<OMXCodec> OMXCodec::Create(
    }

    if (!strcasecmp(MEDIA_MIMETYPE_AUDIO_AMR_NB, mime)) {
        codec->setAMRFormat();
        codec->setAMRFormat(false /* isWAMR */);
    }
    if (!strcasecmp(MEDIA_MIMETYPE_AUDIO_AMR_WB, mime)) {
        codec->setAMRWBFormat();
        codec->setAMRFormat(true /* isWAMR */);
    }
    if (!strcasecmp(MEDIA_MIMETYPE_AUDIO_AAC, mime)) {
        int32_t numChannels, sampleRate;
@@ -1900,42 +1900,12 @@ void OMXCodec::setRawAudioFormat(
    CHECK_EQ(err, OK);
}

void OMXCodec::setAMRFormat() {
    if (!mIsEncoder) {
        OMX_AUDIO_PARAM_AMRTYPE def;
        InitOMXParams(&def);
        def.nPortIndex = kPortIndexInput;

        status_t err =
            mOMX->getParameter(mNode, OMX_IndexParamAudioAmr, &def, sizeof(def));

        CHECK_EQ(err, OK);

        def.eAMRFrameFormat = OMX_AUDIO_AMRFrameFormatFSF;
        def.eAMRBandMode = OMX_AUDIO_AMRBandModeNB0;

        err = mOMX->setParameter(mNode, OMX_IndexParamAudioAmr, &def, sizeof(def));
        CHECK_EQ(err, OK);
    }

    ////////////////////////

    if (mIsEncoder) {
        sp<MetaData> format = mSource->getFormat();
        int32_t sampleRate;
        int32_t numChannels;
        CHECK(format->findInt32(kKeySampleRate, &sampleRate));
        CHECK(format->findInt32(kKeyChannelCount, &numChannels));
void OMXCodec::setAMRFormat(bool isWAMR) {
    OMX_U32 portIndex = mIsEncoder ? kPortIndexOutput : kPortIndexInput;

        setRawAudioFormat(kPortIndexInput, sampleRate, numChannels);
    }
}

void OMXCodec::setAMRWBFormat() {
    if (!mIsEncoder) {
    OMX_AUDIO_PARAM_AMRTYPE def;
    InitOMXParams(&def);
        def.nPortIndex = kPortIndexInput;
    def.nPortIndex = portIndex;

    status_t err =
        mOMX->getParameter(mNode, OMX_IndexParamAudioAmr, &def, sizeof(def));
@@ -1943,11 +1913,11 @@ void OMXCodec::setAMRWBFormat() {
    CHECK_EQ(err, OK);

    def.eAMRFrameFormat = OMX_AUDIO_AMRFrameFormatFSF;
        def.eAMRBandMode = OMX_AUDIO_AMRBandModeWB0;
    def.eAMRBandMode =
        isWAMR ? OMX_AUDIO_AMRBandModeWB0 : OMX_AUDIO_AMRBandModeNB0;

    err = mOMX->setParameter(mNode, OMX_IndexParamAudioAmr, &def, sizeof(def));
    CHECK_EQ(err, OK);
    }

    ////////////////////////