summaryrefslogtreecommitdiff
path: root/android/hal-audio.h
diff options
context:
space:
mode:
authorAndrzej Kaczmarek <andrzej.kaczmarek@tieto.com>2014-05-21 19:06:19 +0200
committerSzymon Janc <szymon.janc@tieto.com>2014-05-23 09:20:40 +0200
commit342269ddfb7af32ac6c412ea9a801a26e5f014f8 (patch)
tree760e400aa3d1b287576a2b125c22891644f59256 /android/hal-audio.h
parent6762d9a4d752519c09b3773d51fc012b0588aa56 (diff)
downloadbluez-342269ddfb7af32ac6c412ea9a801a26e5f014f8.tar.gz
android/hal-audio: Decouple SBC codec from core HAL
Codec abstraction in hal-audio is now good enough to allow splitting code into core and codec implementation easily so this patch moves SBC codec code into separate file and provides interface required for other codecs to be implemented.
Diffstat (limited to 'android/hal-audio.h')
-rw-r--r--android/hal-audio.h110
1 files changed, 110 insertions, 0 deletions
diff --git a/android/hal-audio.h b/android/hal-audio.h
new file mode 100644
index 000000000..cc1a81c4f
--- /dev/null
+++ b/android/hal-audio.h
@@ -0,0 +1,110 @@
+/*
+ * Copyright (C) 2013 Intel Corporation
+ *
+ * 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.
+ *
+ */
+
+#include <time.h>
+#include <hardware/audio.h>
+
+#if __BYTE_ORDER == __LITTLE_ENDIAN
+
+struct rtp_header {
+ unsigned cc:4;
+ unsigned x:1;
+ unsigned p:1;
+ unsigned v:2;
+
+ unsigned pt:7;
+ unsigned m:1;
+
+ uint16_t sequence_number;
+ uint32_t timestamp;
+ uint32_t ssrc;
+ uint32_t csrc[0];
+} __attribute__ ((packed));
+
+struct rtp_payload {
+ unsigned frame_count:4;
+ unsigned rfa0:1;
+ unsigned is_last_fragment:1;
+ unsigned is_first_fragment:1;
+ unsigned is_fragmented:1;
+} __attribute__ ((packed));
+
+#elif __BYTE_ORDER == __BIG_ENDIAN
+
+struct rtp_header {
+ unsigned v:2;
+ unsigned p:1;
+ unsigned x:1;
+ unsigned cc:4;
+
+ unsigned m:1;
+ unsigned pt:7;
+
+ uint16_t sequence_number;
+ uint32_t timestamp;
+ uint32_t ssrc;
+ uint32_t csrc[0];
+} __attribute__ ((packed));
+
+struct rtp_payload {
+ unsigned is_fragmented:1;
+ unsigned is_first_fragment:1;
+ unsigned is_last_fragment:1;
+ unsigned rfa0:1;
+ unsigned frame_count:4;
+} __attribute__ ((packed));
+
+#else
+#error "Unknown byte order"
+#endif
+
+struct media_packet {
+ struct rtp_header hdr;
+ struct rtp_payload payload;
+ uint8_t data[0];
+};
+
+struct audio_input_config {
+ uint32_t rate;
+ uint32_t channels;
+ audio_format_t format;
+};
+
+struct audio_codec {
+ uint8_t type;
+
+ int (*get_presets) (struct audio_preset *preset, size_t *len);
+
+ bool (*init) (struct audio_preset *preset, uint16_t mtu,
+ void **codec_data);
+ bool (*cleanup) (void *codec_data);
+ bool (*get_config) (void *codec_data,
+ struct audio_input_config *config);
+ size_t (*get_buffer_size) (void *codec_data);
+ size_t (*get_mediapacket_duration) (void *codec_data);
+ ssize_t (*encode_mediapacket) (void *codec_data, const uint8_t *buffer,
+ size_t len, struct media_packet *mp,
+ size_t mp_data_len, size_t *written);
+ bool (*update_qos) (void *codec_data, uint8_t op);
+};
+
+#define QOS_POLICY_DEFAULT 0x00
+#define QOS_POLICY_DECREASE 0x01
+
+typedef const struct audio_codec * (*audio_codec_get_t) (void);
+
+const struct audio_codec *codec_sbc(void);