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
This commit is contained in:
Robert Wu
2022-01-25 19:36:02 +00:00
parent 91cfa7ff07
commit 2136d8d77e

View File

@@ -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];