alsa-devel.alsa-project.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] ALSA: update sync header when streams are linked/unlinked
@ 2012-05-22 19:54 Pierre-Louis Bossart
  2012-05-22 19:54 ` [PATCH 2/2] ALSA: core: group read of pointer, tstamp and jiffies Pierre-Louis Bossart
  2012-05-22 23:47 ` [PATCH 1/2] ALSA: update sync header when streams are linked/unlinked Takashi Iwai
  0 siblings, 2 replies; 8+ messages in thread
From: Pierre-Louis Bossart @ 2012-05-22 19:54 UTC (permalink / raw)
  To: alsa-devel; +Cc: tiwai, Pierre-Louis Bossart

Previous code only reported card number and was not updated
when devices were linked/unlinked. This makes alsa-lib
snd_pcm_info_get_sync totally useless.
Add hooks to force update of sync header when devices are
linked/unlinked, and provide more information such as
number of devices and indices of capture/playback devices
linked to

Signed-off-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
---
 sound/core/pcm_lib.c    |   37 ++++++++++++++++++++++++++++++++-----
 sound/core/pcm_native.c |    6 ++++++
 2 files changed, 38 insertions(+), 5 deletions(-)

diff --git a/sound/core/pcm_lib.c b/sound/core/pcm_lib.c
index faedb14..ae46d75 100644
--- a/sound/core/pcm_lib.c
+++ b/sound/core/pcm_lib.c
@@ -533,11 +533,38 @@ EXPORT_SYMBOL(snd_pcm_set_ops);
 void snd_pcm_set_sync(struct snd_pcm_substream *substream)
 {
 	struct snd_pcm_runtime *runtime = substream->runtime;
-	
-	runtime->sync.id32[0] = substream->pcm->card->number;
-	runtime->sync.id32[1] = -1;
-	runtime->sync.id32[2] = -1;
-	runtime->sync.id32[3] = -1;
+	struct snd_pcm_substream *s;
+	int dev_c, dev_p;
+
+	if (snd_pcm_stream_linked(substream)) {
+		runtime->sync.id32[0] = substream->pcm->card->number;
+		/* save number of devices linked */
+		runtime->sync.id32[1] = substream->group->count-1;
+		dev_c = dev_p = 0;
+
+		snd_pcm_group_for_each_entry(s, substream) {
+			if (s == substream)
+				continue;
+			if (s->stream == SNDRV_PCM_STREAM_PLAYBACK) {
+				dev_p++;
+				if (dev_p == 1)
+					runtime->sync.id32[2] = 0;
+				/* save mask of linked playback devices */
+				runtime->sync.id32[2] |= (1<<s->number);
+			} else {
+				dev_c++;
+				if (dev_c == 1)
+					runtime->sync.id32[3] = 0;
+				/* save mask of linked capture devices */
+				runtime->sync.id32[3] |= (1<<s->number);
+			}
+		}
+	} else {
+		runtime->sync.id32[0] = -1;
+		runtime->sync.id32[1] = -1;
+		runtime->sync.id32[2] = -1;
+		runtime->sync.id32[3] = -1;
+	}
 }
 
 EXPORT_SYMBOL(snd_pcm_set_sync);
diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c
index 3fe99e6..e92bc62 100644
--- a/sound/core/pcm_native.c
+++ b/sound/core/pcm_native.c
@@ -1619,6 +1619,9 @@ static int snd_pcm_link(struct snd_pcm_substream *substream, int fd)
 	list_add_tail(&substream1->link_list, &substream->group->substreams);
 	substream->group->count++;
 	substream1->group = substream->group;
+	snd_pcm_set_sync(substream);
+	snd_pcm_set_sync(substream1);
+
  _end:
 	write_unlock_irq(&snd_pcm_link_rwlock);
 	up_write(&snd_pcm_link_rwsem);
@@ -1652,11 +1655,14 @@ static int snd_pcm_unlink(struct snd_pcm_substream *substream)
 	if (substream->group->count == 1) {	/* detach the last stream, too */
 		snd_pcm_group_for_each_entry(s, substream) {
 			relink_to_local(s);
+			snd_pcm_set_sync(s);
 			break;
 		}
 		kfree(substream->group);
 	}
 	relink_to_local(substream);
+	snd_pcm_set_sync(substream);
+
        _end:
 	write_unlock_irq(&snd_pcm_link_rwlock);
 	up_write(&snd_pcm_link_rwsem);
-- 
1.7.6.5

^ permalink raw reply related	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2012-05-25  5:54 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-05-22 19:54 [PATCH 1/2] ALSA: update sync header when streams are linked/unlinked Pierre-Louis Bossart
2012-05-22 19:54 ` [PATCH 2/2] ALSA: core: group read of pointer, tstamp and jiffies Pierre-Louis Bossart
2012-05-22 23:52   ` Takashi Iwai
2012-05-22 23:47 ` [PATCH 1/2] ALSA: update sync header when streams are linked/unlinked Takashi Iwai
2012-05-23 18:57   ` Pierre-Louis Bossart
2012-05-23 19:32     ` Clemens Ladisch
2012-05-23 22:01       ` Pierre-Louis Bossart
2012-05-25  5:54     ` Takashi Iwai

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).