1 /* 2 * Copyright (C) 2016 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 #pragma once 17 18 #include <stdlib.h> 19 #include <stdint.h> 20 #include <time.h> 21 22 #include <system/audio.h> 23 24 typedef uint32_t size32_t; 25 26 struct timespec32 { 27 uint32_t tv_sec; 28 uint32_t tv_nsec; 29 30 timespec32() = default; 31 timespec32timespec3232 timespec32(const timespec &from) 33 : tv_sec(from.tv_sec), 34 tv_nsec(from.tv_nsec) { 35 } 36 }; 37 38 struct gce_audio_message { 39 static const size32_t kMaxAudioFrameLen = 65536; 40 enum message_t { 41 UNKNOWN = 0, 42 DATA_SAMPLES = 1, 43 OPEN_INPUT_STREAM = 2, 44 OPEN_OUTPUT_STREAM = 3, 45 CLOSE_INPUT_STREAM = 4, 46 CLOSE_OUTPUT_STREAM = 5, 47 CONTROL_PAUSE = 100 48 }; 49 // Size of the header + data. Used to frame when we're on TCP. 50 size32_t total_size; 51 // Size of the audio header 52 size32_t header_size; 53 message_t message_type; 54 // Identifier for the stream. 55 uint32_t stream_number; 56 // HAL assigned frame number, starts from 0. 57 int64_t frame_num; 58 // MONOTONIC_TIME when these frames were presented to the HAL. 59 timespec32 time_presented; 60 // Sample rate from the audio configuration. 61 uint32_t frame_rate; 62 // Channel mask from the audio configuration. 63 audio_channel_mask_t channel_mask; 64 // Format from the audio configuration. 65 audio_format_t format; 66 // Size of each frame in bytes. 67 size32_t frame_size; 68 // Number of frames that were presented to the HAL. 69 size32_t num_frames_presented; 70 // Number of frames that the HAL accepted. 71 // For blocking audio this will be the same as num_frames. 72 // For non-blocking audio this may be less. 73 size32_t num_frames_accepted; 74 // Count of the number of packets that were dropped because they would 75 // have blocked the HAL or exceeded the maximum message size. 76 size32_t num_packets_dropped; 77 // Count of the number of packets that were shortened to fit within 78 // kMaxAudioFrameLen. 79 size32_t num_packets_shortened; 80 // num_frames_presented (not num_frames_accepted) will follow here. 81 gce_audio_messagegce_audio_message82 gce_audio_message() : 83 total_size(sizeof(gce_audio_message)), 84 header_size(sizeof(gce_audio_message)), 85 message_type(UNKNOWN), 86 stream_number(0), 87 frame_num(0), 88 frame_rate(0), 89 channel_mask(0), 90 format(AUDIO_FORMAT_DEFAULT), 91 frame_size(0), 92 num_frames_presented(0), 93 num_frames_accepted(0), 94 num_packets_dropped(0), 95 num_packets_shortened(0) { 96 time_presented.tv_sec = 0; 97 time_presented.tv_nsec = 0; 98 } 99 }; 100