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

Commit 286782b4 authored by Andy Hung's avatar Andy Hung Committed by Android (Google) Code Review
Browse files

Merge "AudioFlinger: Extract inner AudioStreamIn and Source classes" into main

parents 2683971b 4dbf0e90
Loading
Loading
Loading
Loading
+1 −24
Original line number Diff line number Diff line
@@ -98,6 +98,7 @@
#include <timing/SynchronizedRecordState.h>

#include <datapath/AudioHwDevice.h>
#include <datapath/AudioStreamIn.h>
#include <datapath/AudioStreamOut.h>
#include <datapath/SpdifStreamOut.h>
#include <datapath/ThreadMetrics.h>
@@ -577,7 +578,6 @@ public:
    class PatchPanel;
    class DeviceEffectManagerCallback;
private:
    struct AudioStreamIn;
    struct TeePatch;
public:
    using TeePatches = std::vector<TeePatch>;
@@ -770,29 +770,6 @@ private:
                        audio_io_handle_t upStream, const String8& keyValuePairs,
                        const std::function<bool(const sp<PlaybackThread>&)>& useThread = nullptr);

    // AudioStreamIn is immutable, so their fields are const.
    // For emphasis, we could also make all pointers to them be "const *",
    // but that would clutter the code unnecessarily.

    struct AudioStreamIn : public Source {
        AudioHwDevice* const audioHwDev;
        sp<StreamInHalInterface> stream;
        audio_input_flags_t flags;

        sp<DeviceHalInterface> hwDev() const { return audioHwDev->hwDevice(); }

        AudioStreamIn(AudioHwDevice *dev, const sp<StreamInHalInterface>& in,
                audio_input_flags_t flags) :
            audioHwDev(dev), stream(in), flags(flags) {}
        status_t read(void *buffer, size_t bytes, size_t *read) override {
            return stream->read(buffer, bytes, read);
        }
        status_t getCapturePosition(int64_t *frames, int64_t *time) override {
            return stream->getCapturePosition(frames, time);
        }
        status_t standby() override { return stream->standby(); }
    };

    struct TeePatch {
        sp<IAfPatchRecord> patchRecord;
        sp<IAfPatchTrack> patchTrack;
+0 −9
Original line number Diff line number Diff line
@@ -549,15 +549,6 @@ public:
                                             *  even if it might glitch. */);
};

// Abstraction for the Audio Source for the RecordThread (HAL or PassthruPatchRecord).
struct Source {
    virtual ~Source() = default;
    // The following methods have the same signatures as in StreamHalInterface.
    virtual status_t read(void* buffer, size_t bytes, size_t* read) = 0;
    virtual status_t getCapturePosition(int64_t* frames, int64_t* time) = 0;
    virtual status_t standby() = 0;
};

class IAfPatchRecord : public virtual IAfRecordTrack, public virtual IAfPatchTrackBase {
public:
    static sp<IAfPatchRecord> create(
+2 −2
Original line number Diff line number Diff line
@@ -9467,7 +9467,7 @@ KeyedVector<audio_session_t, bool> AudioFlinger::RecordThread::sessionIds() cons
    return ids;
}

AudioFlinger::AudioStreamIn* AudioFlinger::RecordThread::clearInput()
AudioStreamIn* AudioFlinger::RecordThread::clearInput()
{
    Mutex::Autolock _l(mLock);
    AudioStreamIn *input = mInput;
@@ -10886,7 +10886,7 @@ status_t AudioFlinger::MmapCaptureThread::exitStandby_l()
    return MmapThread::exitStandby_l();
}

AudioFlinger::AudioStreamIn* AudioFlinger::MmapCaptureThread::clearInput()
AudioStreamIn* AudioFlinger::MmapCaptureThread::clearInput()
{
    Mutex::Autolock _l(mLock);
    AudioStreamIn *input = mInput;
+59 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2023 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.
 */

#pragma once

#include <media/audiohal/DeviceHalInterface.h>
#include <media/audiohal/StreamHalInterface.h>

namespace android {

// Abstraction for the Audio Source for the RecordThread (HAL or PassthruPatchRecord).
struct Source {
    virtual ~Source() = default;
    // The following methods have the same signatures as in StreamHalInterface.
    virtual status_t read(void* buffer, size_t bytes, size_t* read) = 0;
    virtual status_t getCapturePosition(int64_t* frames, int64_t* time) = 0;
    virtual status_t standby() = 0;
};

// AudioStreamIn is immutable, so its fields are const.
// The methods must not be const to match StreamHalInterface signature.

struct AudioStreamIn : public Source {
    const AudioHwDevice* const audioHwDev;
    const sp<StreamInHalInterface> stream;
    const audio_input_flags_t flags;

    AudioStreamIn(
            const AudioHwDevice* dev, const sp<StreamInHalInterface>& in,
            audio_input_flags_t flags)
        : audioHwDev(dev), stream(in), flags(flags) {}

    status_t read(void* buffer, size_t bytes, size_t* read) final {
        return stream->read(buffer, bytes, read);
    }

    status_t getCapturePosition(int64_t* frames, int64_t* time) final {
        return stream->getCapturePosition(frames, time);
    }

    status_t standby() final { return stream->standby(); }

    sp<DeviceHalInterface> hwDev() const { return audioHwDev->hwDevice(); }
};

}  // namespace android