/* * Copyright (C) 2018 Knowles Electronics * * 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 #include #include #include #include #include #include #include #define LOG_TAG "ia_tunneling_hal_test" #include #include "tunnel.h" #include "conversion_routines.h" #include #include #define MAX_TUNNELS 32 #define BUF_SIZE 32768 #define MAX_FILE_PATH 256 #define DEFAULT_PATH "/data/data" #define FILE_PREFIX "/tnl_op" #define UNPARSED_OUTPUT_FILE "/unparsed_output" struct raf_format_type { uint16_t frameSizeInBytes; /*!< Frame length in bytes */ uint8_t encoding; /*!< Encoding */ uint8_t sampleRate; /*!< Sample rate */ }; struct raf_frame_type { uint64_t timeStamp; /*!< Timestamp of the frame */ uint32_t seqNo; /*!< Optional sequence number of the frame */ struct raf_format_type format; /*!< Format information for the frame */ uint32_t data[0]; /*!< Start of the variable size payload. It must start at 128 bit aligned address for all the frames */ }; volatile int capturing = 1; void sigint_handler(int sig __unused) { ALOGE("Interrupted, setting the exit condition"); capturing = 0; } void parse_audio_tunnel_data(FILE *out_fp, unsigned char *buf_itr, int frame_sz_in_bytes) { char q16_buf[BUF_SIZE]; // This can be smaller but by how much? int frameSizeInWords = (frame_sz_in_bytes + 3) >> 2; if (NULL == buf_itr || NULL == out_fp) { ALOGE("%s: Buffer or file pointer is NULL", __func__); return; } kst_float_to_q15_vector(q16_buf, buf_itr, frameSizeInWords); fwrite(q16_buf, (frameSizeInWords * 2), 1, out_fp); fflush(out_fp); } int main(int argc, char *argv[]) { struct ia_tunneling_hal *thdl = NULL; int err = 0; FILE *out_fp[MAX_TUNNELS] = { NULL }; FILE *unp_out_fp = NULL; int bytes_avail = 0, bytes_rem = 0; int bytes_read = 0; void *buf = NULL; // The magic number is ROME in ASCII reversed. So we are looking for EMOR in the byte stream const unsigned char magic_num[4] = {0x45, 0x4D, 0x4F, 0x52}; int i = 0; bool valid_frame = true; char filepath[MAX_FILE_PATH]; char filename[MAX_FILE_PATH]; int num_of_tunnels = 0; int num_tunnel_params; float timer_signal = 0; timer_t timer_id; int tunnel_src[MAX_TUNNELS] = { 0 }; int tunnel_mode[MAX_TUNNELS] = { 0 }; int tunnel_encode[MAX_TUNNELS]; int lastSeqNum[MAX_TUNNELS] = { 0 }; int notFirstFrame[MAX_TUNNELS] = { 0 }; int frameDropCount[MAX_TUNNELS] = { 0 }; uint64_t tunnel_time_stamps[MAX_TUNNELS] = { 0 }; unsigned char *frame_start, *buf_itr; // Minimum bytes required is the magic number + tunnel id + reserved and crc + raf struct int min_bytes_req = 4 + 2 + 6 + sizeof(struct raf_frame_type); int instance; if (argc < 5) { ALOGE("USAGE: %s