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

Commit 7b5eb023 authored by The Android Open Source Project's avatar The Android Open Source Project
Browse files

Code drop from //branches/cupcake/...@124589

parent 2729ea92
Loading
Loading
Loading
Loading
+150 −48
Original line number Diff line number Diff line
@@ -47,6 +47,19 @@ public:

    static const int DEFAULT_SAMPLE_RATE = 8000;

    /* Events used by AudioRecord callback function (callback_t).
     * 
     * to keep in sync with frameworks/base/media/java/android/media/AudioRecord.java
     */
    enum event_type {
        EVENT_MORE_DATA = 0,        // Request to reqd more data from PCM buffer.
        EVENT_OVERRUN = 1,          // PCM buffer overrun occured.
        EVENT_MARKER = 2,           // Record head is at the specified marker position
                                    // (See setMarkerPosition()).
        EVENT_NEW_POS = 3,          // Record head is at a new position 
                                    // (See setPositionUpdatePeriod()).
    };

    /* Create Buffer on the stack and pass it to obtainBuffer()
     * and releaseBuffer().
     */
@@ -75,16 +88,23 @@ public:

//    static status_t setMasterMute(bool mute);

    /* Returns AudioFlinger's frame count. AudioRecord's buffers will
     * be created with this size.
     */
    static  size_t      frameCount();

    /* As a convenience, if a callback is supplied, a handler thread
     * is automatically created with the appropriate priority. This thread
     * invokes the callback when a new buffer becomes availlable.
     * invokes the callback when a new buffer becomes ready or an overrun condition occurs.
     * Parameters:
     *
     * event:   type of event notified (see enum AudioRecord::event_type).
     * user:    Pointer to context for use by the callback receiver.
     * info:    Pointer to optional parameter according to event type:
     *          - EVENT_MORE_DATA: pointer to AudioRecord::Buffer struct. The callback must not read
     *          more bytes than indicated by 'size' field and update 'size' if less bytes are
     *          read.
     *          - EVENT_OVERRUN: unused.
     *          - EVENT_MARKER: pointer to an uin32_t containing the marker position in frames.
     *          - EVENT_NEW_POS: pointer to an uin32_t containing the new position in frames.
     */
    typedef bool (*callback_t)(void* user, const Buffer& info);

    typedef void (*callback_t)(int event, void* user, void *info);

    /* Constructs an uninitialized AudioRecord. No connection with
     * AudioFlinger takes place.
@@ -95,15 +115,33 @@ public:
     * Once created, the track needs to be started before it can be used.
     * Unspecified values are set to the audio hardware's current
     * values.
     *
     * Parameters:
     *
     * streamType:         Select the audio input to record to (e.g. AudioRecord::MIC_INPUT).
     * sampleRate:         Track sampling rate in Hz.
     * format:             PCM sample format (e.g AudioSystem::PCM_16_BIT for signed
     *                     16 bits per sample).
     * channelCount:       Number of PCM channels (e.g 2 for stereo).
     * frameCount:         Total size of track PCM buffer in frames. This defines the
     *                     latency of the track.
     * flags:              Reserved for future use.
     * cbf:                Callback function. If not null, this function is called periodically
     *                     to provide new PCM data.
     * notificationFrames: The callback function is called each time notificationFrames PCM
     *                     frames are ready in record track output buffer.
     * user                Context for use by the callback receiver.
     */

                        AudioRecord(int streamType      = 0,
                        AudioRecord(int streamType,
                                    uint32_t sampleRate = 0,
                                    int format          = 0,
                                    int channelCount    = 0,
                                    int bufferCount     = 0,
                                    int frameCount      = 0,
                                    uint32_t flags      = 0,
                                    callback_t cbf = 0, void* user = 0);
                                    callback_t cbf = 0,
                                    void* user = 0,
                                    int notificationFrames = 0);


    /* Terminates the AudioRecord and unregisters it from AudioFlinger.
@@ -112,34 +150,46 @@ public:
                        ~AudioRecord();


    /* Initialize an uninitialized AudioRecord. */
    /* Initialize an uninitialized AudioRecord.
     * Returned status (from utils/Errors.h) can be:
     *  - NO_ERROR: successful intialization
     *  - INVALID_OPERATION: AudioRecord is already intitialized or record device is already in use
     *  - BAD_VALUE: invalid parameter (channelCount, format, sampleRate...)
     *  - NO_INIT: audio server or audio hardware not initialized
     *  - PERMISSION_DENIED: recording is not allowed for the requesting process
     * */
            status_t    set(int streamType      = 0,
                            uint32_t sampleRate = 0,
                            int format          = 0,
                            int channelCount    = 0,
                            int bufferCount     = 0,
                            int frameCount      = 0,
                            uint32_t flags      = 0,
                            callback_t cbf = 0, void* user = 0);
                            callback_t cbf = 0,
                            void* user = 0,
                            int notificationFrames = 0,
                            bool threadCanCallJava = false);


    /* Result of constructing the AudioRecord. This must be checked
     * before using any AudioRecord API (except for set()), using
     * an uninitialized AudioRecord prduces undefined results.
     * an uninitialized AudioRecord produces undefined results.
     * See set() method above for possible return codes.
     */
            status_t    initCheck() const;

    /* Returns this track's latency in nanoseconds or framecount.
     * This only includes the latency due to the fill buffer size.
     * In particular, the hardware or driver latencies are not accounted.
    /* Returns this track's latency in milliseconds.
     * This includes the latency due to AudioRecord buffer size
     * and audio hardware driver.
     */
            nsecs_t     latency() const;
            uint32_t     latency() const;

   /* getters, see constructor */

            uint32_t    sampleRate() const;
            int         format() const;
            int         channelCount() const;
            int         bufferCount() const;
            uint32_t    frameCount() const;
            int         frameSize() const;


    /* After it's created the track is not active. Call start() to
@@ -158,6 +208,58 @@ public:
     */
            uint32_t    getSampleRate();

    /* Sets marker position. When record reaches the number of frames specified,
     * a callback with event type EVENT_MARKER is called. Calling setMarkerPosition
     * with marker == 0 cancels marker notification callback. 
     * If the AudioRecord has been opened with no callback function associated, 
     * the operation will fail.
     *
     * Parameters:
     *
     * marker:   marker position expressed in frames.
     *
     * Returned status (from utils/Errors.h) can be:
     *  - NO_ERROR: successful operation
     *  - INVALID_OPERATION: the AudioRecord has no callback installed.
     */
            status_t    setMarkerPosition(uint32_t marker);
            status_t    getMarkerPosition(uint32_t *marker);


    /* Sets position update period. Every time the number of frames specified has been recorded, 
     * a callback with event type EVENT_NEW_POS is called. 
     * Calling setPositionUpdatePeriod with updatePeriod == 0 cancels new position notification 
     * callback. 
     * If the AudioRecord has been opened with no callback function associated,
     * the operation will fail.
     *
     * Parameters:
     *
     * updatePeriod:  position update notification period expressed in frames.
     *
     * Returned status (from utils/Errors.h) can be:
     *  - NO_ERROR: successful operation
     *  - INVALID_OPERATION: the AudioRecord has no callback installed.
     */
            status_t    setPositionUpdatePeriod(uint32_t updatePeriod);
            status_t    getPositionUpdatePeriod(uint32_t *updatePeriod);


    /* Gets record head position. The position is the  total number of frames 
     * recorded since record start. 
     *
     * Parameters:
     *
     *  position:  Address where to return record head position within AudioRecord buffer.
     *
     * Returned status (from utils/Errors.h) can be:
     *  - NO_ERROR: successful operation
     *  - BAD_VALUE:  position is NULL
     */
            status_t    getPosition(uint32_t *position);

            
            
    /* obtains a buffer of "frameCount" frames. The buffer must be
     * filled entirely. If the track is stopped, obtainBuffer() returns
     * STOPPED instead of NO_ERROR as long as there are buffers availlable,
@@ -191,13 +293,14 @@ private:
    class ClientRecordThread : public Thread
    {
    public:
        ClientRecordThread(AudioRecord& receiver);
        ClientRecordThread(AudioRecord& receiver, bool bCanCallJava = false);
    private:
        friend class AudioRecord;
        virtual bool        threadLoop();
        virtual status_t    readyToRun() { return NO_ERROR; }
        virtual void        onFirstRef() {}
        AudioRecord& mReceiver;
        Mutex       mLock;
    };

            bool processAudioBuffer(const sp<ClientRecordThread>& thread);
@@ -209,25 +312,24 @@ private:
    Mutex                   mRecordThreadLock;

    uint32_t                mSampleRate;
    size_t                  mFrameCount;
    uint32_t                mFrameCount;

    audio_track_cblk_t*     mCblk;
    uint8_t                 mFormat;
    uint8_t                 mBufferCount;
    uint8_t                 mChannelCount   : 4;
    uint8_t                 mReserved       : 3;
    uint8_t                 mChannelCount;
    uint8_t                 mReserved[2];
    status_t                mStatus;
    nsecs_t                 mLatency;
    uint32_t                mLatency;

    volatile int32_t        mActive;

    callback_t              mCbf;
    void*                   mUserData;
    
    AudioRecord::Buffer      mAudioBuffer;
    size_t                  mPosition;

    uint32_t                mReservedFBC[4];
    uint32_t                mNotificationFrames;
    uint32_t                mRemainingFrames;
    uint32_t                mMarkerPosition;
    uint32_t                mNewPosition;
    uint32_t                mUpdatePeriod;
};

}; // namespace android
+10 −2
Original line number Diff line number Diff line
@@ -48,9 +48,10 @@ public:
    enum audio_routes {
        ROUTE_EARPIECE       = (1 << 0),
        ROUTE_SPEAKER        = (1 << 1),
        ROUTE_BLUETOOTH      = (1 << 2),
        ROUTE_BLUETOOTH_SCO  = (1 << 2),
        ROUTE_HEADSET        = (1 << 3),
        ROUTE_ALL       = (ROUTE_EARPIECE | ROUTE_SPEAKER | ROUTE_BLUETOOTH | ROUTE_HEADSET)
        ROUTE_BLUETOOTH_A2DP = (1 << 4),
        ROUTE_ALL       = 0xFFFFFFFF
    };

    /* These are static methods to control the system-wide AudioFlinger
@@ -95,6 +96,10 @@ public:
    static float linearToLog(int volume);
    static int logToLinear(float volume);

    static status_t getOutputSamplingRate(int* samplingRate);
    static status_t getOutputFrameCount(int* frameCount);
    static status_t getOutputLatency(uint32_t* latency);

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

private:
@@ -115,6 +120,9 @@ private:
    static Mutex gLock;
    static sp<IAudioFlinger> gAudioFlinger;
    static audio_error_callback gAudioErrorCallback;
    static int gOutSamplingRate;
    static int gOutFrameCount;
    static uint32_t gOutLatency;
};

};  // namespace android
+205 −51

File changed.

Preview size limit exceeded, changes collapsed.

+8 −4
Original line number Diff line number Diff line
@@ -46,8 +46,10 @@ public:
                                uint32_t sampleRate,
                                int format,
                                int channelCount,
                                int bufferCount,
                                uint32_t flags) = 0;
                                int frameCount,
                                uint32_t flags,
                                const sp<IMemory>& sharedBuffer,
                                status_t *status) = 0;

    virtual sp<IAudioRecord> openRecord(
                                pid_t pid,
@@ -55,8 +57,9 @@ public:
                                uint32_t sampleRate,
                                int format,
                                int channelCount,
                                int bufferCount,
                                uint32_t flags) = 0;
                                int frameCount,
                                uint32_t flags,
                                status_t *status) = 0;

    /* query the audio hardware state. This state never changes,
     * and therefore can be cached.
@@ -65,6 +68,7 @@ public:
    virtual     int         channelCount() const = 0;
    virtual     int         format() const = 0;
    virtual     size_t      frameCount() const = 0;
    virtual     uint32_t    latency() const = 0;

    /* set/get the audio hardware state. This will probably be used by
     * the preference panel, mostly.
+56 −0
Original line number Diff line number Diff line
/*
**
** Copyright (C) 2008 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.
*/

#ifndef ANDROID_IMEDIAMETADATARETRIEVER_H
#define ANDROID_IMEDIAMETADATARETRIEVER_H

#include <utils/RefBase.h>
#include <utils/IInterface.h>
#include <utils/Parcel.h>
#include <utils/IMemory.h>

namespace android {

class IMediaMetadataRetriever: public IInterface
{
public:
    DECLARE_META_INTERFACE(MediaMetadataRetriever);
    virtual void            disconnect() = 0;
    virtual status_t        setDataSource(const char* srcUrl) = 0;
    virtual status_t        setDataSource(int fd, int64_t offset, int64_t length) = 0;
    virtual status_t        setMode(int mode) = 0;
    virtual status_t        getMode(int* mode) const = 0;
    virtual sp<IMemory>     captureFrame() = 0;
    virtual sp<IMemory>     extractAlbumArt() = 0;
    virtual const char*     extractMetadata(int keyCode) = 0;
};

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

class BnMediaMetadataRetriever: public BnInterface<IMediaMetadataRetriever>
{
public:
    virtual status_t    onTransact(uint32_t code,
                                   const Parcel& data,
                                   Parcel* reply,
                                   uint32_t flags = 0);
};

}; // namespace android

#endif // ANDROID_IMEDIAMETADATARETRIEVER_H
Loading