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

Commit 2136d8d7 authored by Robert Wu's avatar Robert Wu
Browse files

amidi: Don't create extra write buffer

When sendWithTimestamp is called, a ~1000 byte buffer is created
even if nothing is sent. This CL adds a check to the size to save
space in the buffer if it's not needed.

Bug: 216328047
Test: atest NativeMidiEchoTest
Change-Id: I0bfddb6ca7416c5df5e938bdd09a5f1efdacaf5c
parent 91cfa7ff
Loading
Loading
Loading
Loading
+5 −1
Original line number Diff line number Diff line
@@ -401,10 +401,14 @@ ssize_t AMIDI_API AMidiInputPort_send(const AMidiInputPort *inputPort, const uin

ssize_t AMIDI_API AMidiInputPort_sendWithTimestamp(const AMidiInputPort *inputPort,
        const uint8_t *data, size_t numBytes, int64_t timestamp) {
    if (inputPort == nullptr || data == nullptr) {
    if (inputPort == nullptr || data == nullptr || numBytes < 0 || timestamp < 0) {
        return AMEDIA_ERROR_INVALID_PARAMETER;
    }

    if (numBytes == 0) {
        return 0;
    }

    // AMIDI_logBuffer(data, numBytes);

    uint8_t writeBuffer[AMIDI_BUFFER_SIZE + AMIDI_PACKET_OVERHEAD];