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

Commit 4ae65f93 authored by Arne Coucheron's avatar Arne Coucheron
Browse files

Revert "FM Radio: Add support for FM Radio in Android"

This reverts commit 3142d888.

Change-Id: Id6a8f16f27529d734d36da89bc9041f693af5b75
parent 6c081235
Loading
Loading
Loading
Loading
+0 −64
Original line number Diff line number Diff line
/*
 * Copyright (C) ST-Ericsson SA 2012
 * Copyright (C) 2012 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * Author: Stefan Ekenberg (stefan.ekenberg@stericsson.com) for ST-Ericsson
 */

#ifndef FMRADIO_SOURCE_H_

#define FMRADIO_SOURCE_H_

#include <media/AudioRecord.h>
#include <media/stagefright/DataSource.h>
#include <media/stagefright/foundation/ABase.h>
#include <system/audio.h>

namespace android {

class FMRadioSource : public DataSource {
public:
    FMRadioSource();

    virtual status_t initCheck() const;
    virtual ssize_t readAt(off64_t offset, void *data, size_t size);
    virtual status_t getSize(off64_t *size);

protected:
    virtual ~FMRadioSource();

private:
    struct Buffer {
        size_t  frameCount;
        size_t  size;
        int8_t* data;
    };

    status_t openRecord(int frameCount, audio_io_handle_t input);
    status_t obtainBuffer(Buffer* audioBuffer);

    status_t mInitCheck;
    bool mStarted;
    int mSessionId;
    sp<IAudioRecord> mAudioRecord;
    sp<IMemory> mCblkMemory;
    audio_track_cblk_t* mCblk;

    DISALLOW_EVIL_CONSTRUCTORS(FMRadioSource);
};

}  // namespace android

#endif  // FMRADIO_SOURCE_H_
+1 −14
Original line number Diff line number Diff line
@@ -69,20 +69,7 @@ LOCAL_C_INCLUDES:= \
        $(TOP)/frameworks/native/services/connectivitymanager \
        $(TOP)/external/flac/include \
        $(TOP)/external/tremolo \
        $(TOP)/external/openssl/include

ifneq ($(TI_CUSTOM_DOMX_PATH),)
LOCAL_C_INCLUDES += $(TI_CUSTOM_DOMX_PATH)/omx_core/inc
LOCAL_CPPFLAGS += -DUSE_TI_CUSTOM_DOMX
else
LOCAL_C_INCLUDES += $(TOP)/frameworks/native/include/media/openmax
endif

ifeq ($(BOARD_USES_STE_FMRADIO),true)
LOCAL_SRC_FILES += \
        FMRadioSource.cpp                 \
        PCMExtractor.cpp
endif
        $(TOP)/external/openssl/include \

ifeq ($(TARGET_QCOM_MEDIA_VARIANT),caf)
LOCAL_C_INCLUDES += \
+0 −10
Original line number Diff line number Diff line
@@ -42,7 +42,6 @@
#include <media/stagefright/AudioPlayer.h>
#include <media/stagefright/DataSource.h>
#include <media/stagefright/FileSource.h>
#include <media/stagefright/FMRadioSource.h>
#include <media/stagefright/MediaBuffer.h>
#include <media/stagefright/MediaDefs.h>
#include <media/stagefright/MediaExtractor.h>
@@ -2282,15 +2281,6 @@ status_t AwesomePlayer::finishSetDataSource_l() {
                return UNKNOWN_ERROR;
            }
        }
#ifdef STE_FM
    } else if (!strncasecmp("fmradio://rx", mUri.string(), 12)) {
        sniffedMIME = MEDIA_MIMETYPE_AUDIO_RAW;
        dataSource = new FMRadioSource();
        status_t err = dataSource->initCheck();
        if (err != OK) {
            return err;
        }
#endif
    } else {
        dataSource = DataSource::CreateFromURI(mUri.string(), &mUriHeaders);
    }
+0 −201
Original line number Diff line number Diff line
/*
 * Copyright (C) ST-Ericsson SA 2012
 * Copyright (C) 2012 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * Author: Stefan Ekenberg (stefan.ekenberg@stericsson.com) for ST-Ericsson
 */

#define LOG_TAG "FMRadioSource"
#include <utils/Log.h>

#include <media/stagefright/FMRadioSource.h>
#include <media/AudioSystem.h>
#include <private/media/AudioTrackShared.h>
#include <cutils/compiler.h>

namespace android {

static const int kSampleRate = 48000;
static const audio_format_t kAudioFormat = AUDIO_FORMAT_PCM_16_BIT;
static const audio_channel_mask_t kChannelMask = AUDIO_CHANNEL_IN_STEREO;
static const int kBufferTimeoutMs = 3000;

FMRadioSource::FMRadioSource()
    : mInitCheck(NO_INIT),
      mStarted(false),
      mSessionId(AudioSystem::newAudioSessionId()) {

    // get FM Radio RX input
    audio_io_handle_t input = AudioSystem::getInput(AUDIO_SOURCE_FM_RADIO_RX,
                                                    kSampleRate,
                                                    kAudioFormat,
                                                    kChannelMask,
                                                    mSessionId);
    if (input == 0) {
        ALOGE("Could not get audio input for FM Radio source");
        mInitCheck = UNKNOWN_ERROR;
        return;
    }

    // get frame count
    int frameCount = 0;
    status_t status = AudioRecord::getMinFrameCount(&frameCount, kSampleRate,
                                                    kAudioFormat, popcount(kChannelMask));
    if (status != NO_ERROR) {
        mInitCheck = status;
        return;
    }

    // create the IAudioRecord
    status = openRecord(frameCount, input);
    if (status != NO_ERROR) {
        mInitCheck = status;
        return;
    }

    AudioSystem::acquireAudioSessionId(mSessionId);

    mInitCheck = OK;
    return;
}

FMRadioSource::~FMRadioSource() {
    AudioSystem::releaseAudioSessionId(mSessionId);
}

status_t FMRadioSource::initCheck() const {
    return mInitCheck;
}

ssize_t FMRadioSource::readAt(off64_t offset, void *data, size_t size) {
    Buffer audioBuffer;

    if (!mStarted) {
        status_t err = mAudioRecord->start(AudioSystem::SYNC_EVENT_NONE, 0);
        if (err == OK) {
            mStarted = true;
        } else {
            ALOGE("Failed to start audio source");
            return 0;
        }
    }

    // acquire a strong reference on the IAudioRecord and IMemory so that they cannot be destroyed
    // while we are accessing the cblk
    sp<IAudioRecord> audioRecord = mAudioRecord;
    sp<IMemory> iMem = mCblkMemory;
    audio_track_cblk_t* cblk = mCblk;

    audioBuffer.frameCount = size / cblk->frameSize;

    status_t err = obtainBuffer(&audioBuffer);
    if (err != NO_ERROR) {
        ALOGE("Error obtaining an audio buffer, giving up (err:%d).", err);
        return 0;
    }

    memcpy(data, audioBuffer.data, audioBuffer.size);
    mCblk->stepUser(audioBuffer.frameCount);

    return audioBuffer.size;
}

status_t FMRadioSource::getSize(off64_t *size) {
    *size = 0;
    return OK;
}

// -------------------------------------------------------------------------

status_t FMRadioSource::openRecord(int frameCount, audio_io_handle_t input)
{
    status_t status;
    const sp<IAudioFlinger>& audioFlinger = AudioSystem::get_audio_flinger();
    if (audioFlinger == 0) {
        return NO_INIT;
    }

    sp<IAudioRecord> record = audioFlinger->openRecord(getpid(), input,
                                                       kSampleRate,
                                                       kAudioFormat,
                                                       kChannelMask,
                                                       frameCount,
                                                       IAudioFlinger::TRACK_DEFAULT,
                                                       gettid(),
                                                       &mSessionId,
                                                       &status);

    if (record == 0) {
        ALOGE("AudioFlinger could not create record track, status: %d", status);
        return status;
    }

    sp<IMemory> cblk = record->getCblk();
    if (cblk == 0) {
        ALOGE("Could not get control block");
        return NO_INIT;
    }
    mAudioRecord = record;
    mCblkMemory = cblk;
    mCblk = static_cast<audio_track_cblk_t*>(cblk->pointer());
    mCblk->buffers = (char*)mCblk + sizeof(audio_track_cblk_t);
    android_atomic_and(~CBLK_DIRECTION_MSK, &mCblk->flags);
    return NO_ERROR;
}

status_t FMRadioSource::obtainBuffer(Buffer* audioBuffer)
{
    status_t result = NO_ERROR;
    uint32_t framesReq = audioBuffer->frameCount;

    audioBuffer->frameCount = 0;
    audioBuffer->size       = 0;

    mCblk->lock.lock();
    uint32_t framesReady = mCblk->framesReady();
    if (framesReady == 0) {
        do {
            result = mCblk->cv.waitRelative(mCblk->lock, milliseconds(kBufferTimeoutMs));
            if (CC_UNLIKELY(result != NO_ERROR)) {
                ALOGE("obtainBuffer timed out (is the CPU pegged?) "
                        "user=%08x, server=%08x", mCblk->user, mCblk->server);
                mCblk->lock.unlock();
                return TIMED_OUT;
            }

            framesReady = mCblk->framesReady();
        } while (framesReady == 0);
    }
    mCblk->lock.unlock();

    if (framesReq > framesReady) {
        framesReq = framesReady;
    }

    uint32_t u = mCblk->user;
    uint32_t bufferEnd = mCblk->userBase + mCblk->frameCount;

    if (framesReq > bufferEnd - u) {
        framesReq = bufferEnd - u;
    }

    audioBuffer->frameCount = framesReq;
    audioBuffer->size       = framesReq * mCblk->frameSize;
    audioBuffer->data       = (int8_t*)mCblk->buffer(u);

    return NO_ERROR;
}

}  // namespace android
+0 −5
Original line number Diff line number Diff line
@@ -23,7 +23,6 @@
#include "include/MPEG4Extractor.h"
#include "include/WAVExtractor.h"
#include "include/OggExtractor.h"
#include "include/PCMExtractor.h"
#include "include/MPEG2PSExtractor.h"
#include "include/MPEG2TSExtractor.h"
#include "include/DRMExtractor.h"
@@ -117,10 +116,6 @@ sp<MediaExtractor> MediaExtractor::Create(
        ret = new AACExtractor(source, meta);
    } else if (!strcasecmp(mime, MEDIA_MIMETYPE_CONTAINER_MPEG2PS)) {
        ret = new MPEG2PSExtractor(source);
#ifdef STE_FM
    } else if (!strcasecmp(mime, MEDIA_MIMETYPE_AUDIO_RAW)) {
        ret = new PCMExtractor(source);
#endif
    }

    if (ret != NULL) {
Loading