2019-09-12 16:00:03 +08:00
|
|
|
// SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
//
|
|
|
|
// Copyright(c) 2019 Intel Corporation. All rights reserved.
|
|
|
|
//
|
|
|
|
// Author: Adrian Bonislawski <adrian.bonislawski@intel.com>
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Probes will extract data for several probe points in one stream
|
|
|
|
* with extra headers. This app will read the resulting file,
|
|
|
|
* strip the headers and create wave files for each extracted buffer.
|
|
|
|
*
|
|
|
|
* Usage to parse data and create wave files: ./sof-probes -p data.bin
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <errno.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <stddef.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
2022-09-29 03:07:18 +08:00
|
|
|
#include "probes_demux.h"
|
2022-09-21 02:40:20 +08:00
|
|
|
|
2019-09-12 16:00:03 +08:00
|
|
|
#define APP_NAME "sof-probes"
|
|
|
|
|
|
|
|
static void usage(void)
|
|
|
|
{
|
|
|
|
fprintf(stdout, "Usage %s <option(s)> <buffer_id/file>\n\n", APP_NAME);
|
|
|
|
fprintf(stdout, "%s:\t -p file\tParse extracted file\n\n", APP_NAME);
|
2022-09-30 00:30:02 +08:00
|
|
|
fprintf(stdout, "%s:\t -l \t\tLog to stdout\n\n", APP_NAME);
|
2019-09-12 16:00:03 +08:00
|
|
|
fprintf(stdout, "%s:\t -h \t\tHelp, usage info\n", APP_NAME);
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
|
2022-09-30 00:30:02 +08:00
|
|
|
void parse_data(const char *file_in, bool log_to_stdout)
|
2019-09-12 16:00:03 +08:00
|
|
|
{
|
2022-09-26 22:03:49 +08:00
|
|
|
struct dma_frame_parser *p = parser_init();
|
2019-09-12 16:00:03 +08:00
|
|
|
FILE *fd_in;
|
2022-09-26 22:03:49 +08:00
|
|
|
uint8_t *data;
|
|
|
|
size_t len;
|
|
|
|
int ret;
|
2019-09-12 16:00:03 +08:00
|
|
|
|
2022-09-26 22:03:49 +08:00
|
|
|
if (!p) {
|
|
|
|
fprintf(stderr, "parser_init() failed\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
2019-09-12 16:00:03 +08:00
|
|
|
|
2022-09-30 00:30:02 +08:00
|
|
|
if (log_to_stdout)
|
|
|
|
parser_log_to_stdout(p);
|
|
|
|
|
|
|
|
if (file_in) {
|
|
|
|
fd_in = fopen(file_in, "rb");
|
|
|
|
if (!fd_in) {
|
|
|
|
fprintf(stderr, "error: unable to open file %s, error %d\n",
|
|
|
|
file_in, errno);
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
fd_in = stdin;
|
2019-09-12 16:00:03 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
do {
|
2022-09-26 22:03:49 +08:00
|
|
|
parser_fetch_free_buffer(p, &data, &len);
|
|
|
|
len = fread(data, 1, len, fd_in);
|
|
|
|
ret = parser_parse_data(p, len);
|
|
|
|
} while (!ret && !feof(fd_in));
|
2019-09-12 16:00:03 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
2022-09-30 00:30:02 +08:00
|
|
|
const char *fname = NULL;
|
|
|
|
bool log_to_stdout = false;
|
2019-09-12 16:00:03 +08:00
|
|
|
int opt;
|
|
|
|
|
2022-09-30 00:30:02 +08:00
|
|
|
while ((opt = getopt(argc, argv, "lhp:")) != -1) {
|
2019-09-12 16:00:03 +08:00
|
|
|
switch (opt) {
|
|
|
|
case 'p':
|
2022-09-30 00:30:02 +08:00
|
|
|
fname = optarg;
|
|
|
|
break;
|
|
|
|
case 'l':
|
|
|
|
log_to_stdout = true;
|
2019-09-12 16:00:03 +08:00
|
|
|
break;
|
|
|
|
case 'h':
|
|
|
|
default:
|
|
|
|
usage();
|
2022-09-30 00:30:02 +08:00
|
|
|
return 0;
|
2019-09-12 16:00:03 +08:00
|
|
|
}
|
|
|
|
}
|
2022-09-30 00:30:02 +08:00
|
|
|
parse_data(fname, log_to_stdout);
|
2019-09-12 16:00:03 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|