ALSA: bebob: code refactoring to initialize/destroy stream data

This commit changes helper functions to initialize/destroy stream
data so that it has an argument for direction.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
This commit is contained in:
Takashi Sakamoto 2019-06-12 17:44:07 +09:00 committed by Takashi Iwai
parent 87a23092dd
commit 33e41a5ce5
1 changed files with 64 additions and 63 deletions

View File

@ -376,24 +376,6 @@ end:
return err; return err;
} }
static int
init_both_connections(struct snd_bebob *bebob)
{
int err;
err = cmp_connection_init(&bebob->in_conn,
bebob->unit, CMP_INPUT, 0);
if (err < 0)
goto end;
err = cmp_connection_init(&bebob->out_conn,
bebob->unit, CMP_OUTPUT, 0);
if (err < 0)
cmp_connection_destroy(&bebob->in_conn);
end:
return err;
}
static int static int
check_connection_used_by_others(struct snd_bebob *bebob, struct amdtp_stream *s) check_connection_used_by_others(struct snd_bebob *bebob, struct amdtp_stream *s)
{ {
@ -448,13 +430,6 @@ break_both_connections(struct snd_bebob *bebob)
msleep(200); msleep(200);
} }
static void
destroy_both_connections(struct snd_bebob *bebob)
{
cmp_connection_destroy(&bebob->in_conn);
cmp_connection_destroy(&bebob->out_conn);
}
static int static int
start_stream(struct snd_bebob *bebob, struct amdtp_stream *stream) start_stream(struct snd_bebob *bebob, struct amdtp_stream *stream)
{ {
@ -481,49 +456,77 @@ end:
return err; return err;
} }
int snd_bebob_stream_init_duplex(struct snd_bebob *bebob) static int init_stream(struct snd_bebob *bebob, struct amdtp_stream *stream)
{ {
enum amdtp_stream_direction dir_stream;
struct cmp_connection *conn;
enum cmp_direction dir_conn;
int err; int err;
err = init_both_connections(bebob); if (stream == &bebob->tx_stream) {
if (err < 0) dir_stream = AMDTP_IN_STREAM;
goto end; conn = &bebob->out_conn;
dir_conn = CMP_OUTPUT;
err = amdtp_am824_init(&bebob->tx_stream, bebob->unit, } else {
AMDTP_IN_STREAM, CIP_BLOCKING); dir_stream = AMDTP_OUT_STREAM;
if (err < 0) { conn = &bebob->in_conn;
amdtp_stream_destroy(&bebob->tx_stream); dir_conn = CMP_INPUT;
destroy_both_connections(bebob);
goto end;
} }
/* err = cmp_connection_init(conn, bebob->unit, dir_conn, 0);
* BeBoB v3 transfers packets with these qurks: if (err < 0)
* - In the beginning of streaming, the value of dbc is incremented return err;
* even if no data blocks are transferred.
* - The value of dbc is reset suddenly. err = amdtp_am824_init(stream, bebob->unit, dir_stream, CIP_BLOCKING);
*/ if (err < 0) {
cmp_connection_destroy(conn);
return err;
}
if (stream == &bebob->tx_stream) {
// BeBoB v3 transfers packets with these qurks:
// - In the beginning of streaming, the value of dbc is
// incremented even if no data blocks are transferred.
// - The value of dbc is reset suddenly.
if (bebob->version > 2) if (bebob->version > 2)
bebob->tx_stream.flags |= CIP_EMPTY_HAS_WRONG_DBC | bebob->tx_stream.flags |= CIP_EMPTY_HAS_WRONG_DBC |
CIP_SKIP_DBC_ZERO_CHECK; CIP_SKIP_DBC_ZERO_CHECK;
/* // At high sampling rate, M-Audio special firmware transmits
* At high sampling rate, M-Audio special firmware transmits empty // empty packet with the value of dbc incremented by 8 but the
* packet with the value of dbc incremented by 8 but the others are // others are valid to IEC 61883-1.
* valid to IEC 61883-1.
*/
if (bebob->maudio_special_quirk) if (bebob->maudio_special_quirk)
bebob->tx_stream.flags |= CIP_EMPTY_HAS_WRONG_DBC; bebob->tx_stream.flags |= CIP_EMPTY_HAS_WRONG_DBC;
err = amdtp_am824_init(&bebob->rx_stream, bebob->unit,
AMDTP_OUT_STREAM, CIP_BLOCKING);
if (err < 0) {
amdtp_stream_destroy(&bebob->tx_stream);
amdtp_stream_destroy(&bebob->rx_stream);
destroy_both_connections(bebob);
} }
end:
return 0;
}
static void destroy_stream(struct snd_bebob *bebob, struct amdtp_stream *stream)
{
amdtp_stream_destroy(stream);
if (stream == &bebob->tx_stream)
cmp_connection_destroy(&bebob->out_conn);
else
cmp_connection_destroy(&bebob->in_conn);
}
int snd_bebob_stream_init_duplex(struct snd_bebob *bebob)
{
int err;
err = init_stream(bebob, &bebob->tx_stream);
if (err < 0)
return err; return err;
err = init_stream(bebob, &bebob->rx_stream);
if (err < 0) {
destroy_stream(bebob, &bebob->tx_stream);
return err;
}
return 0;
} }
static int keep_resources(struct snd_bebob *bebob, struct amdtp_stream *stream, static int keep_resources(struct snd_bebob *bebob, struct amdtp_stream *stream,
@ -693,10 +696,8 @@ void snd_bebob_stream_stop_duplex(struct snd_bebob *bebob)
*/ */
void snd_bebob_stream_destroy_duplex(struct snd_bebob *bebob) void snd_bebob_stream_destroy_duplex(struct snd_bebob *bebob)
{ {
amdtp_stream_destroy(&bebob->rx_stream); destroy_stream(bebob, &bebob->tx_stream);
amdtp_stream_destroy(&bebob->tx_stream); destroy_stream(bebob, &bebob->rx_stream);
destroy_both_connections(bebob);
} }
/* /*