/*
   forward-alsa-io.h - ALSA capture driver for SoftLab-NSK Forward video boards

   Copyright (C) 2017 - 2023 Konstantin Oblaukhov <oblaukhov@sl.iae.nsk.su>

   This program is free software; you can redistribute it and/or
   modify it under the terms of the GNU General Public License
   as published by the Free Software Foundation; either version 2
   of the License, or (at your option) any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
*/

#ifndef FORWARD_ALSA_IO_H
#define FORWARD_ALSA_IO_H

#include "forward.h"
#include "forward-alsa.h"
#include "forward-irq.h"

struct forward_alsa_io {
	struct forward_alsa *alsa;

	enum forward_io_state state;
	int index;
	int number;

	struct snd_pcm *pcm;
	struct snd_pcm_substream *stream;
	struct mutex lock;
	struct forward_irq_listener irq;
	bool ready;
	bool streaming;
	int forced_channels;

	struct snd_kcontrol *ctl;

	void *hw_buffer;
	bool hw_streaming;
	u32 hw_buffer_address;
	u32 hw_buffer_size;

	enum forward_alsa_stream_type type;

	snd_pcm_sframes_t position[FORWARD_ALSA_MAX_SDI_GROUPS];
	snd_pcm_sframes_t hw_rd_position, hw_wr_position, sw_rd_position;
	snd_pcm_sframes_t last_period_position[FORWARD_ALSA_MAX_SDI_GROUPS];

	u64 position_time;
};

int forward_alsa_io_init(struct forward_alsa_io *io);
void forward_alsa_io_deinit(struct forward_alsa_io *io);

#endif // FORWARD_ALSA_IO_H
