/* SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause) */
/*
 * Copyright (c) 2021 MediaTek Inc.
 */

#ifndef ATSC30_PARSER_ALP_PARSER_H
#define ATSC30_PARSER_ALP_PARSER_H

#include <linux/types.h>
#include "alp_lls.h"
#include "alp_stream_manager.h"
#include "alp_packet.h"
#include "net_buf.h"
#include "alp_parser_if.h"

typedef struct {
	bool initialized;
	u8 framer_idx;
	alp_sw_parser_config_t sw_cfg;

	const struct alp_parser_operations *alp_parser_ops;
	const struct alp_priv_packet_operations *alp_priv_packet_ops;

	alp_header_t alp_hdr;
	alp_plp_context_t plp_ctx;
	alp_stream_management_t strm_mgr;
} alp_context_t;

ALP_RET_CODE_T alp_parser_run(
		alp_context_t *ctx,
		net_buf_t packet,
		const alp_parser_input_info_t *input_info);

bool alp_parser_init(
		alp_context_t *ctx,
		u8 framer_idx,
		const struct alp_parser_operations *alp_parser_ops,
		const struct alp_priv_packet_operations *alp_priv_packet_ops,
		alp_sw_parser_config_t sw_cfg);

bool alp_parser_deinit(alp_context_t *ctx);

const alp_stream_t *alp_parser_get_stream(
		const alp_context_t *ctx,
		alp_stream_ID strm_id);
alp_stream_ID alp_parser_set_stream(
		alp_context_t *ctx,
		const alp_stream_t *new_strm);
bool alp_parser_update_stream_state(
		alp_context_t *ctx,
		alp_stream_ID strm_id,
		ALP_STREAM_STATE_T state);

bool alp_parser_set_plp_id_filter(
		alp_context_t *ctx,
		const u8 *plp_id_arr,
		u8 plp_cnt);
bool alp_parser_clear_plp_id_filter(
		alp_context_t *ctx,
		const u8 *plp_id_arr,
		u8 plp_cnt);
void alp_parser_clear_all_plp_id_filters(alp_context_t *ctx);
bool alp_parser_get_plp_id(
		const alp_context_t *ctx,
		u8 *plp_id_arr,
		u8 plp_cnt_max);

void alp_parser_collect_statistics(const alp_context_t *ctx);

#endif /* ATSC30_PARSER_ALP_PARSER_H */
