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

Commit 6dd62fb9 authored by Glenn Kasten's avatar Glenn Kasten
Browse files

Multi-client recording

Supports multiple clients both at native sample rate and with resampling.

Change-Id: Icea55b4fd30751761b7debaa3ce016c79e712d8d
parent f3b785ae
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -462,7 +462,9 @@ status_t AudioRecord::openRecord_l(size_t epoch)
    audio_io_handle_t input = AudioSystem::getInput(mInputSource, mSampleRate, mFormat,
            mChannelMask, mSessionId);
    if (input == 0) {
        ALOGE("Could not get audio input for record source %d", mInputSource);
        ALOGE("Could not get audio input for record source %d, sample rate %u, format %#x, "
              "channel mask %#x, session %d",
              mInputSource, mSampleRate, mFormat, mChannelMask, mSessionId);
        return BAD_VALUE;
    }
    {
+29 −0
Original line number Diff line number Diff line
@@ -59,4 +59,33 @@ private:
    // releaseBuffer() not overridden

    bool                mOverflow;  // overflow on most recent attempt to fill client buffer

           // updated by RecordThread::readInputParameters()
            AudioResampler                      *mResampler;

            // interleaved stereo pairs of fixed-point signed Q19.12
            int32_t                             *mRsmpOutBuffer;
            // current allocated frame count for the above, which may be larger than needed
            size_t                              mRsmpOutFrameCount;

            size_t                              mRsmpInUnrel;   // unreleased frames remaining from
                                                                // most recent getNextBuffer
                                                                // for debug only

            // rolling counter that is never cleared
            int32_t                             mRsmpInFront;   // next available frame

            AudioBufferProvider::Buffer mSink;  // references client's buffer sink in shared memory

            // sync event triggering actual audio capture. Frames read before this event will
            // be dropped and therefore not read by the application.
            sp<SyncEvent>                       mSyncStartEvent;

            // number of captured frames to drop after the start sync event has been received.
            // when < 0, maximum frames to drop before starting capture even if sync event is
            // not received
            ssize_t                             mFramesToDrop;

            // used by resampler to find source frames
            ResamplerBufferProvider *mResamplerBufferProvider;
};
+334 −287

File changed.

Preview size limit exceeded, changes collapsed.

+19 −26
Original line number Diff line number Diff line
@@ -839,10 +839,23 @@ public:


// record thread
class RecordThread : public ThreadBase, public AudioBufferProvider
class RecordThread : public ThreadBase
{
public:

    class RecordTrack;
    class ResamplerBufferProvider : public AudioBufferProvider
                        // derives from AudioBufferProvider interface for use by resampler
    {
    public:
        ResamplerBufferProvider(RecordTrack* recordTrack) : mRecordTrack(recordTrack) { }
        virtual ~ResamplerBufferProvider() { }
        // AudioBufferProvider interface
        virtual status_t    getNextBuffer(AudioBufferProvider::Buffer* buffer, int64_t pts);
        virtual void        releaseBuffer(AudioBufferProvider::Buffer* buffer);
    private:
        RecordTrack * const mRecordTrack;
    };

#include "RecordTracks.h"

@@ -898,9 +911,6 @@ public:
            AudioStreamIn* clearInput();
            virtual audio_stream_t* stream() const;

    // AudioBufferProvider interface
    virtual status_t    getNextBuffer(AudioBufferProvider::Buffer* buffer, int64_t pts);
    virtual void        releaseBuffer(AudioBufferProvider::Buffer* buffer);

    virtual bool        checkForNewParameters_l();
    virtual String8     getParameters(const String8& keys);
@@ -921,13 +931,13 @@ public:
    virtual bool     isValidSyncEvent(const sp<SyncEvent>& event) const;

    static void syncStartEventCallback(const wp<SyncEvent>& event);
           void handleSyncStartEvent(const sp<SyncEvent>& event);
           void handleSyncStartEvent(RecordTrack *recordTrack, const sp<SyncEvent>& event);

    virtual size_t      frameCount() const { return mFrameCount; }
            bool        hasFastRecorder() const { return false; }

private:
            void    clearSyncStartEvent();
            void    clearSyncStartEvent(RecordTrack* recordTrack);

            // Enter standby if not already in standby, and set mStandby flag
            void    standbyIfNotAlreadyInStandby();
@@ -944,35 +954,18 @@ private:
            int                                 mActiveTracksGen;
            Condition                           mStartStopCond;

            // updated by RecordThread::readInputParameters()
            AudioResampler                      *mResampler;
            // interleaved stereo pairs of fixed-point signed Q19.12
            int32_t                             *mRsmpOutBuffer;

            // resampler converts input at HAL Hz to output at AudioRecord client Hz
            int16_t                             *mRsmpInBuffer; // see new[] for details on the size
            size_t                              mRsmpInFrames;  // size of resampler input in frames
            size_t                              mRsmpInFramesP2;// size rounded up to a power-of-2
            size_t                              mRsmpInUnrel;   // unreleased frames remaining from
                                                                // most recent getNextBuffer
            // these are rolling counters that are never cleared
            int32_t                             mRsmpInFront;   // next available frame

            // rolling index that is never cleared
            int32_t                             mRsmpInRear;    // last filled frame + 1
            size_t                              mRsmpInIndex;   // FIXME legacy

            // client's requested configuration, which may differ from the HAL configuration
            const uint32_t                      mReqChannelCount;
            const uint32_t                      mReqSampleRate;

            ssize_t                             mBytesRead;
            // sync event triggering actual audio capture. Frames read before this event will
            // be dropped and therefore not read by the application.
            sp<SyncEvent>                       mSyncStartEvent;
            // number of captured frames to drop after the start sync event has been received.
            // when < 0, maximum frames to drop before starting capture even if sync event is
            // not received
            ssize_t                             mFramestoDrop;

            // For dumpsys
            const sp<NBAIO_Sink>                mTeeSink;
};
+3 −1
Original line number Diff line number Diff line
@@ -34,7 +34,9 @@ public:
        RESUMING,
        ACTIVE,
        PAUSING,
        PAUSED
        PAUSED,
        STARTING_1,     // for RecordTrack only
        STARTING_2,     // for RecordTrack only
    };

                        TrackBase(ThreadBase *thread,
Loading