view ater8/play_cmd.c @ 52:626180a15857 default tip

ater play-d144: emit E-data frames manually, osmo_trau_frame_encode() is currently broken for this frame type
author Mychaela Falconia <falcon@freecalypso.org>
date Wed, 25 Sep 2024 06:40:43 +0000
parents 3cc26391d24d
children
line wrap: on
line source

/*
 * Here we implement user commands controlling file play functionality.
 */

#include <stdint.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <osmocom/core/select.h>

#include "globals.h"
#include "submux.h"
#include "read_file.h"

void cmd_play_file(int argc, char **argv)
{
	int nr, rc;
	struct ater_subslot *at;

	if (argc != 3) {
usage:		fprintf(stderr, "usage: %s 0-7 play-file.dec\n", argv[0]);
		return;
	}
	if (argv[1][0] < '0' || argv[1][0] > '7' || argv[1][1])
		goto usage;
	nr = argv[1][0] - '0';
	at = &subslots[nr];
	if (!at->is_active) {
		fprintf(stderr, "error: subslot %d is not active\n", nr);
		return;
	}
	if (at->is_data) {
		fprintf(stderr, "error: subslot %d is in data mode\n", nr);
		return;
	}
	if (at->play_buffer) {
		fprintf(stderr, "error: file play already in progress\n");
		return;
	}
	rc = read_binary_file(argv[2], &at->play_buffer, &at->play_buf_total);
	if (rc < 0)
		return;		/* error msg already printed */
	at->play_buf_ptr = 0;
	at->play_wait_align = true;
}

void cmd_play_stop(int argc, char **argv)
{
	int nr;
	struct ater_subslot *at;

	if (argc != 2) {
usage:		fprintf(stderr, "usage: %s 0-7\n", argv[0]);
		return;
	}
	if (argv[1][0] < '0' || argv[1][0] > '7' || argv[1][1])
		goto usage;
	nr = argv[1][0] - '0';
	at = &subslots[nr];
	if (!at->is_active) {
		fprintf(stderr, "error: subslot %d is not active\n", nr);
		return;
	}
	if (!at->play_buffer) {
		fprintf(stderr, "error: no file play in progress\n");
		return;
	}
	free(at->play_buffer);
	at->play_buffer = NULL;
}