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

Commit bc0cc34a authored by jiabin's avatar jiabin
Browse files

Return actual processed size from FixedBlockAdapter.

By returning actual processed size from FixedBlockAdapter, the client
can return whatever size of data it has from the data callback.

Bug: 389124986
Test: test_compress_offload -Fdata/tmp/sine.mp3 -f6 -c2 -r44100 -z88
Flag: EXEMPT bugfix
Change-Id: I33106f1e210cba9bdd2fe60315abbd877a5a9fc5
parent f2498667
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -424,6 +424,13 @@ public:
        printf("          2 = PCM_FLOAT\n");
        printf("          3 = PCM_I24_PACKED\n");
        printf("          4 = PCM_I32\n");
        printf("          6 = MP3\n");
        printf("          7 = AAC_LC\n");
        printf("          8 = AAC_HE_V1\n");
        printf("          9 = AAC_HE_V2\n");
        printf("          10 = AAC_ELD\n");
        printf("          12 = AAC_XHE\n");
        printf("          13 = OPUS\n");
        printf("      -i{inputPreset} eg. 5 for AAUDIO_INPUT_PRESET_CAMCORDER\n");
        printf("      -m{0|1|2|3} set MMAP policy\n");
        printf("          0 = _UNSPECIFIED, use aaudio.mmap_policy system property, default\n");
+1 −1
Original line number Diff line number Diff line
@@ -71,7 +71,7 @@ static float s_burnCPU(int32_t workload) {
class AAudioSimplePlayer {
public:
    AAudioSimplePlayer() {}
    ~AAudioSimplePlayer() {
    virtual ~AAudioSimplePlayer() {
        close();
    };

+19 −13
Original line number Diff line number Diff line
@@ -105,27 +105,33 @@ size_t AudioStreamLegacy::onMoreData(const android::AudioTrack::Buffer& buffer)
        // If the caller specified an exact size then use a block size adapter.
        if (mBlockAdapter != nullptr) {
            int32_t byteCount = buffer.getFrameCount() * getBytesPerDeviceFrame();
            callbackResult = mBlockAdapter->processVariableBlock(
            std::tie(callbackResult, written) = mBlockAdapter->processVariableBlock(
                    buffer.data(), byteCount);
        } else {
            // Call using the AAudio callback interface.
            callbackResult = callDataCallbackFrames(buffer.data(),
                                                    buffer.getFrameCount());
            written = callbackResult == AAUDIO_CALLBACK_RESULT_CONTINUE ?
                    buffer.getFrameCount() * getBytesPerDeviceFrame() : 0;
        }
        if (callbackResult == AAUDIO_CALLBACK_RESULT_CONTINUE) {
            written = buffer.getFrameCount() * getBytesPerDeviceFrame();
        } else {

        if (callbackResult != AAUDIO_CALLBACK_RESULT_CONTINUE) {
            if (callbackResult == AAUDIO_CALLBACK_RESULT_STOP) {
                ALOGD("%s() callback returned AAUDIO_CALLBACK_RESULT_STOP", __func__);
            } else {
                ALOGW("%s() callback returned invalid result = %d",
                      __func__, callbackResult);
            }
            written = 0;
            if (callbackResult != AAUDIO_CALLBACK_RESULT_STOP || shouldStopStream()) {
                // If the callback result is STOP, stop the stream if it should be stopped.
                // Currently, the framework will not call stop if the client is doing offload
                // playback and waiting for stream end. The client will already be STOPPING
                // state when waiting for stream end.
                systemStopInternal();
                // Disable the callback just in case the system keeps trying to call us.
                mCallbackEnabled.store(false);
            }
        }

        if (processCommands() != AAUDIO_OK) {
            forceDisconnect();
@@ -170,23 +176,23 @@ size_t AudioStreamLegacy::onMoreData(const android::AudioRecord::Buffer& buffer)
        // If the caller specified an exact size then use a block size adapter.
        if (mBlockAdapter != nullptr) {
            int32_t byteCount = buffer.getFrameCount() * getBytesPerDeviceFrame();
            callbackResult = mBlockAdapter->processVariableBlock(
            std::tie(callbackResult, written) = mBlockAdapter->processVariableBlock(
                    buffer.data(), byteCount);
        } else {
            // Call using the AAudio callback interface.
            callbackResult = callDataCallbackFrames(buffer.data(),
                                                    buffer.getFrameCount());
            written = callbackResult == AAUDIO_CALLBACK_RESULT_CONTINUE ?
                    buffer.getFrameCount() * getBytesPerDeviceFrame() : 0;
        }
        if (callbackResult == AAUDIO_CALLBACK_RESULT_CONTINUE) {
            written = buffer.getFrameCount() * getBytesPerDeviceFrame();
        } else {
        if (callbackResult != AAUDIO_CALLBACK_RESULT_CONTINUE) {
            if (callbackResult == AAUDIO_CALLBACK_RESULT_STOP) {
                ALOGD("%s() callback returned AAUDIO_CALLBACK_RESULT_STOP", __func__);
            } else {
                ALOGW("%s() callback returned invalid result = %d",
                      __func__, callbackResult);
            }
            written = 0;
            // Always stop the recording case if callback result is not CONTINUE.
            systemStopInternal();
            // Disable the callback just in case the system keeps trying to call us.
            mCallbackEnabled.store(false);
+2 −0
Original line number Diff line number Diff line
@@ -126,6 +126,8 @@ protected:
     */
    virtual int32_t getBufferCapacityFromDevice() const = 0;

    virtual bool shouldStopStream() const { return true; }

    // This is used for exact matching by MediaMetrics. So do not change it.
    // MediaMetricsConstants.h: AMEDIAMETRICS_PROP_CALLERNAME_VALUE_AAUDIO
    static constexpr char     kCallerName[] = "aaudio";
+1 −0
Original line number Diff line number Diff line
@@ -686,6 +686,7 @@ aaudio_result_t AudioStreamTrack::setOffloadEndOfStream() {
        return result;
    }
    mOffloadEosPending = true;
    setState(AAUDIO_STREAM_STATE_STOPPING);
    return AAUDIO_OK;
}

Loading