status-go/protocol/audio/type.go
Andrea Maria Piana e58ba1e9c8
Add audio messages
Why make this change?

We are adding support of audio recorded files, similarly to how we did
with images

What has changed?

- Added protobuf definition, only AAC supported
- Added migrations to store files
- Fixed an issue with nil pointer when transaction would fail to be
created, causing the application to crash
2020-07-27 17:14:50 +02:00

30 lines
614 B
Go

package audio
import (
"github.com/status-im/status-go/protocol/protobuf"
)
func aac(buf []byte) bool {
return len(buf) > 1 &&
((buf[0] == 0xFF && buf[1] == 0xF1) ||
(buf[0] == 0xFF && buf[1] == 0xF9))
}
func amr(buf []byte) bool {
return len(buf) > 11 &&
buf[0] == 0x23 && buf[1] == 0x21 &&
buf[2] == 0x41 && buf[3] == 0x4D &&
buf[4] == 0x52 && buf[5] == 0x0A
}
func Type(buf []byte) protobuf.AudioMessage_AudioType {
switch {
case aac(buf):
return protobuf.AudioMessage_AAC
case amr(buf):
return protobuf.AudioMessage_AMR
default:
return protobuf.AudioMessage_UNKNOWN_AUDIO_TYPE
}
}