Skip to contentSkip to conversation

pcm:plug: save converter config

PATCH Superseded [email protected] 3 participants 4 messages Mar 3, 2017 – Mar 18, 2017

v3 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

PATCH v3 6/6 pcm:plug: save converter config

From: Andreas Pape <[email protected]>

Passed config is freed after call to open, thus it is invalid when trying to extract the converter name. So config entry is saved for later usage.

src/pcm/pcm_plug.c +16 -1
index 266707b..c643278 100644
@@ -64,6 +64,10 @@ static int snd_pcm_plug_close(snd_pcm_t *pcm)
 	snd_pcm_plug_t *plug = pcm->private_data;
 	int err, result = 0;
 	free(plug->ttable);
+	if (plug->rate_converter) {
+		snd_config_delete((snd_config_t*)plug->rate_converter);
+		plug->rate_converter = NULL;
+	}
 	assert(plug->gen.slave == plug->req_slave);
 	if (plug->gen.close_slave) {
 		snd_pcm_unlink_hw_ptr(pcm, plug->req_slave);
@@ -1108,7 +1112,14 @@ int snd_pcm_plug_open(snd_pcm_t **pcmp,
 	plug->sformat = sformat;
 	plug->schannels = schannels;
 	plug->srate = srate;
-	plug->rate_converter = rate_converter;
+	if (rate_converter) {
+		if ((err = snd_config_copy((snd_config_t**)&plug->rate_converter,
+					   (snd_config_t *)rate_converter)) < 0) {
+			free(plug);
+			return err;
+		}
+	}
+
 	plug->gen.slave = plug->req_slave = slave;
 	plug->gen.close_slave = close_slave;
 	plug->route_policy = route_policy;
@@ -1119,6 +1130,10 @@ int snd_pcm_plug_open(snd_pcm_t **pcmp,
 	
 	err = snd_pcm_new(&pcm, SND_PCM_TYPE_PLUG, name, slave->stream, slave->mode);
 	if (err < 0) {
+		if (plug->rate_converter) {
+			snd_config_delete((snd_config_t*)plug->rate_converter);
+			plug->rate_converter = NULL;
+		}
 		free(plug);
 		return err;
 	}
Signature · 1 line
2.7.4
#1 lore raw

ping

-----Original Message-----
From: [email protected] [mailto:[email protected]]
Sent: 03 March 2017 15:28
To: [email protected]
Cc: [email protected]; Sutar, Mounesh <[email protected]>; Andreas Pape <[email protected]>; Mounesh Sutar <[email protected]>
Subject: [PATCH v3 6/6] pcm:plug: save converter config

From: Andreas Pape <[email protected]>

Passed config is freed after call to open, thus it is invalid when trying to extract the converter name. So config entry is saved for later usage.

src/pcm/pcm_plug.c +4 -0
@@ -64,6 +64,10 @@ static int snd_pcm_plug_close(snd_pcm_t *pcm)
 	snd_pcm_plug_t *plug = pcm->private_data;
 	int err, result = 0;
 	free(plug->ttable);
+	if (plug->rate_converter) {
+		snd_config_delete((snd_config_t*)plug->rate_converter);
+		plug->rate_converter = NULL;
+	}
 	assert(plug->gen.slave == plug->req_slave);
 	if (plug->gen.close_slave) {
 		snd_pcm_unlink_hw_ptr(pcm, plug->req_slave); @@ -1108,7 +1112,14 @@ int snd_pcm_plug_open(snd_pcm_t **pcmp,

plug->sformat = sformat;
plug->schannels = schannels;
plug->srate = srate;
- plug->rate_converter = rate_converter;
+ if (rate_converter) {
+ if ((err = snd_config_copy((snd_config_t**)&plug->rate_converter,
+ (snd_config_t *)rate_converter)) < 0) {
+ free(plug);
+ return err;
+ }
+ }
+
plug->gen.slave = plug->req_slave = slave; plug->gen.close_slave = close_slave; plug->route_policy = route_policy;
@@ -1119,6 +1130,10 @@ int snd_pcm_plug_open(snd_pcm_t **pcmp,

err = snd_pcm_new(&pcm, SND_PCM_TYPE_PLUG, name, slave->stream, slave->mode); if (err < 0) {
+ if (plug->rate_converter) {
+ snd_config_delete((snd_config_t*)plug->rate_converter);
+ plug->rate_converter = NULL;
+ }
free(plug);
return err;
}
--
2.7.4

#2 lore raw
In reply to [email protected]

ping

-----Original Message-----
From: Sutar, Mounesh
Sent: 09 March 2017 15:51
To: [email protected]
Cc: [email protected]; Andreas Pape <[email protected]>; '[email protected]' <[email protected]>
Subject: RE: [PATCH v3 6/6] pcm:plug: save converter config

ping

-----Original Message-----
From: [email protected] [mailto:[email protected]]
Sent: 03 March 2017 15:28
To: [email protected]
Cc: [email protected]; Sutar, Mounesh <[email protected]>; Andreas Pape <[email protected]>; Mounesh Sutar <[email protected]>
Subject: [PATCH v3 6/6] pcm:plug: save converter config

From: Andreas Pape <[email protected]>

Passed config is freed after call to open, thus it is invalid when trying to extract the converter name. So config entry is saved for later usage.

src/pcm/pcm_plug.c +4 -0
@@ -64,6 +64,10 @@ static int snd_pcm_plug_close(snd_pcm_t *pcm)
 	snd_pcm_plug_t *plug = pcm->private_data;
 	int err, result = 0;
 	free(plug->ttable);
+	if (plug->rate_converter) {
+		snd_config_delete((snd_config_t*)plug->rate_converter);
+		plug->rate_converter = NULL;
+	}
 	assert(plug->gen.slave == plug->req_slave);
 	if (plug->gen.close_slave) {
 		snd_pcm_unlink_hw_ptr(pcm, plug->req_slave); @@ -1108,7 +1112,14 @@ int snd_pcm_plug_open(snd_pcm_t **pcmp,

plug->sformat = sformat;
plug->schannels = schannels;
plug->srate = srate;
- plug->rate_converter = rate_converter;
+ if (rate_converter) {
+ if ((err = snd_config_copy((snd_config_t**)&plug->rate_converter,
+ (snd_config_t *)rate_converter)) < 0) {
+ free(plug);
+ return err;
+ }
+ }
+
plug->gen.slave = plug->req_slave = slave; plug->gen.close_slave = close_slave; plug->route_policy = route_policy;
@@ -1119,6 +1130,10 @@ int snd_pcm_plug_open(snd_pcm_t **pcmp,

err = snd_pcm_new(&pcm, SND_PCM_TYPE_PLUG, name, slave->stream, slave->mode); if (err < 0) {
+ if (plug->rate_converter) {
+ snd_config_delete((snd_config_t*)plug->rate_converter);
+ plug->rate_converter = NULL;
+ }
free(plug);
return err;
}
--
2.7.4

#3 lore raw
In reply to [email protected]

Hi,

Quoted 8 lines · On Mar 3 2017 18:58, [email protected] wrote:

From: Andreas Pape <[email protected]>

Passed config is freed after call to open, thus it is invalid when trying to extract the converter name. So config entry is saved for later usage.

I agree with your idea to fix this issue. However...

Quoted 18 lines
src/pcm/pcm_plug.c +4 -0
index 266707b..c643278 100644
@@ -64,6 +64,10 @@ static int snd_pcm_plug_close(snd_pcm_t *pcm)
 	snd_pcm_plug_t *plug = pcm->private_data;
 	int err, result = 0;
 	free(plug->ttable);
+	if (plug->rate_converter) {
+		snd_config_delete((snd_config_t*)plug->rate_converter);
+		plug->rate_converter = NULL;
+	}
 	assert(plug->gen.slave == plug->req_slave);
 	if (plug->gen.close_slave) {
 		snd_pcm_unlink_hw_ptr(pcm, plug->req_slave);
@@ -1108,7 +1112,14 @@ int snd_pcm_plug_open(snd_pcm_t **pcmp,
 	plug->sformat = sformat;
 	plug->schannels = schannels;

src/pcm/pcm_plug.c int snd_pcm_plug_open(snd_pcm_t **pcmp, · line 1122

Quoted 10 lines
src/pcm/pcm_plug.c +8 -1
 	plug->srate = srate;
-	plug->rate_converter = rate_converter;
+	if (rate_converter) {
+		if ((err = snd_config_copy((snd_config_t**)&plug->rate_converter,
+					   (snd_config_t *)rate_converter)) < 0) {
+			free(plug);
+			return err;
+		}
+	}
+

The 'rate_converter' member is not referred in a call of following snd_pcm_new(), thus the copy operation can be postponed enough later than the call. This dedicates code simplicity, I think.

Quoted 4 lines
src/pcm/pcm_plug.c +0 -0
 	plug->gen.slave = plug->req_slave = slave;
 	plug->gen.close_slave = close_slave;
 	plug->route_policy = route_policy;

src/pcm/pcm_plug.c int snd_pcm_plug_open(snd_pcm_t **pcmp, · line 1139

Quoted 10 lines
src/pcm/pcm_plug.c +4 -0
@@ -1119,6 +1130,10 @@ int snd_pcm_plug_open(snd_pcm_t **pcmp,
 
 	err = snd_pcm_new(&pcm, SND_PCM_TYPE_PLUG, name, slave->stream, slave->mode);
 	if (err < 0) {
+		if (plug->rate_converter) {
+			snd_config_delete((snd_config_t*)plug->rate_converter);
+			plug->rate_converter = NULL;
+		}
 		free(plug);
 		return err;
 	}

Thanks

Takashi Sakamoto