All of lore.kernel.org
 help / color / mirror / Atom feed
* Another asinine question
@ 2006-05-12 15:06 Juan Carlos Castro y Castro
  2006-05-16 13:38 ` Takashi Iwai
  0 siblings, 1 reply; 10+ messages in thread
From: Juan Carlos Castro y Castro @ 2006-05-12 15:06 UTC (permalink / raw)
  To: alsa-devel

If I compile and install the HG version of alsa-lib while everything 
else is 1.0.11, will Bad Things™ happen?


-------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid\x120709&bid&3057&dat\x121642

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

* Re: Another asinine question
  2006-05-12 15:06 Juan Carlos Castro y Castro
@ 2006-05-16 13:38 ` Takashi Iwai
  2006-05-16 14:33   ` Juan Carlos Castro y Castro
  0 siblings, 1 reply; 10+ messages in thread
From: Takashi Iwai @ 2006-05-16 13:38 UTC (permalink / raw)
  To: Juan Carlos Castro y Castro; +Cc: alsa-devel

At Fri, 12 May 2006 12:06:28 -0300,
Juan Carlos Castro y Castro wrote:
> 
> If I compile and install the HG version of alsa-lib while everything 
> else is 1.0.11, will Bad Things™ happen?

No, it shouldn't.  alsa-lib API is backward compatible.

But there were fixes and improvements in the driver and utils.  Better
to update all things.


Takashi


-------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid\x120709&bid&3057&dat\x121642

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

* Re: Another asinine question
  2006-05-16 13:38 ` Takashi Iwai
@ 2006-05-16 14:33   ` Juan Carlos Castro y Castro
  2006-05-16 14:38     ` Takashi Iwai
  2006-05-16 18:44     ` Juan Carlos Castro y Castro
  0 siblings, 2 replies; 10+ messages in thread
From: Juan Carlos Castro y Castro @ 2006-05-16 14:33 UTC (permalink / raw)
  To: Takashi Iwai; +Cc: alsa-devel

Thanks for the tip (again!)

(Memo to self: always CC the particular persons you're trying to reach, 
list delays are getting out of hand)

By the way, my pcm_file extensions DO work! It's the "plug" plugin 
that's not passing the reads! Stay tuned...

Takashi Iwai wrote:

>At Fri, 12 May 2006 12:06:28 -0300,
>Juan Carlos Castro y Castro wrote:
>  
>
>>If I compile and install the HG version of alsa-lib while everything 
>>else is 1.0.11, will Bad Things™ happen?
>>    
>>
>
>No, it shouldn't.  alsa-lib API is backward compatible.
>
>But there were fixes and improvements in the driver and utils.  Better
>to update all things.
>
>
>Takashi
>
>  
>



-------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid\x120709&bid&3057&dat\x121642

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

* Re: Another asinine question
  2006-05-16 14:33   ` Juan Carlos Castro y Castro
@ 2006-05-16 14:38     ` Takashi Iwai
  2006-05-16 16:28       ` Juan Carlos Castro y Castro
  2006-05-16 18:44     ` Juan Carlos Castro y Castro
  1 sibling, 1 reply; 10+ messages in thread
From: Takashi Iwai @ 2006-05-16 14:38 UTC (permalink / raw)
  To: Juan Carlos Castro y Castro; +Cc: alsa-devel

At Tue, 16 May 2006 11:33:22 -0300,
Juan Carlos Castro y Castro wrote:
> 
> Thanks for the tip (again!)
> 
> (Memo to self: always CC the particular persons you're trying to reach, 
> list delays are getting out of hand)
> 
> By the way, my pcm_file extensions DO work! It's the "plug" plugin 
> that's not passing the reads! Stay tuned...

Great, feel free to submit the patches to alsa-devel ML (Cc to me).


Takashi

> 
> Takashi Iwai wrote:
> 
> >At Fri, 12 May 2006 12:06:28 -0300,
> >Juan Carlos Castro y Castro wrote:
> >  
> >
> >>If I compile and install the HG version of alsa-lib while everything 
> >>else is 1.0.11, will Bad Things™ happen?
> >>    
> >>
> >
> >No, it shouldn't.  alsa-lib API is backward compatible.
> >
> >But there were fixes and improvements in the driver and utils.  Better
> >to update all things.
> >
> >
> >Takashi
> >
> >  
> >
> 


-------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid\x120709&bid&3057&dat\x121642

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

* Re: Another asinine question
  2006-05-16 14:38     ` Takashi Iwai
@ 2006-05-16 16:28       ` Juan Carlos Castro y Castro
  2006-05-17 13:26         ` Takashi Iwai
  0 siblings, 1 reply; 10+ messages in thread
From: Juan Carlos Castro y Castro @ 2006-05-16 16:28 UTC (permalink / raw)
  To: Takashi Iwai; +Cc: alsa-devel

[-- Attachment #1: Type: text/plain, Size: 775 bytes --]

Takashi Iwai wrote:

>Juan Carlos Castro y Castro wrote:
>  
>
>>By the way, my pcm_file extensions DO work! It's the "plug" plugin 
>>that's not passing the reads! Stay tuned...
>>    
>>
>Great, feel free to submit the patches to alsa-devel ML (Cc to me).
>
Your wish is my command, Takashi-san. ;)

Note the interleaved read has not yet been implemented. Also, I'm not 
yet dealing with blocking versus non-blocking at the moment. When 
reading from a file, read()'s just keep getting zero bytes and arecord 
doesn't mind. Some deal of sophistication will have to be added.

Another thing: you'll see I just "hung" another snd_pcm_file_t structure 
at the bottom of the original one. I'll understand if that offends 
people's coding sensibilities -- it offended mine. :-/

[-- Attachment #2: pcm_file-infile.patch --]
[-- Type: text/x-patch, Size: 5166 bytes --]

diff -r 33b6942ac42d src/pcm/pcm_file.c
--- a/src/pcm/pcm_file.c	Fri Apr 28 15:55:32 2006 +0200
+++ b/src/pcm/pcm_file.c	Tue May 16 13:21:12 2006 -0300
@@ -42,7 +42,7 @@ typedef enum _snd_pcm_file_format {
 	SND_PCM_FILE_FORMAT_RAW
 } snd_pcm_file_format_t;
 
-typedef struct {
+typedef struct snd_pcm_file_t_struct {
 	snd_pcm_generic_t gen;
 	char *fname;
 	int fd;
@@ -55,6 +55,7 @@ typedef struct {
 	char *wbuf;
 	snd_pcm_channel_area_t *wbuf_areas;
 	size_t buffer_bytes;
+	struct snd_pcm_file_t_struct *nextfile;
 } snd_pcm_file_t;
 
 #endif /* DOC_HIDDEN */
@@ -120,6 +121,14 @@ static int snd_pcm_file_close(snd_pcm_t 
 		free((void *)file->fname);
 		close(file->fd);
 	}
+	if (file->nextfile) {
+		if (file->nextfile->fname) {
+			free((void *)file->nextfile->fname);
+			close(file->nextfile->fd);
+		}
+		free(file->nextfile);
+		file->nextfile = NULL;
+	}
 	return snd_pcm_generic_close(pcm);
 }
 
@@ -222,10 +231,20 @@ static snd_pcm_sframes_t snd_pcm_file_re
 {
 	snd_pcm_file_t *file = pcm->private_data;
 	snd_pcm_channel_area_t areas[pcm->channels];
-	snd_pcm_sframes_t n = snd_pcm_readi(file->gen.slave, buffer, size);
-	if (n > 0) {
-		snd_pcm_areas_from_buf(pcm, areas, buffer);
-		snd_pcm_file_add_frames(pcm, areas, 0, n);
+	snd_pcm_sframes_t n /* , bytesn */;
+
+	if (file->nextfile) {
+		n = /* bytesn = */ read(file->nextfile->fd, buffer, size * pcm->frame_bits / 8);
+		if (n > 0)
+			n = n * 8 / pcm->frame_bits;
+		/* SNDERR("DEBUG: channels = %d, sample_bits = %d, frame_bits = %d, bytes = %d, frames = %d",
+		        pcm->channels, pcm->sample_bits, pcm->frame_bits, bytesn, n); */
+	} else {
+		n = snd_pcm_readi(file->gen.slave, buffer, size);
+		if (n > 0) {
+			snd_pcm_areas_from_buf(pcm, areas, buffer);
+			snd_pcm_file_add_frames(pcm, areas, 0, n);
+		}
 	}
 	return n;
 }
@@ -234,7 +253,14 @@ static snd_pcm_sframes_t snd_pcm_file_re
 {
 	snd_pcm_file_t *file = pcm->private_data;
 	snd_pcm_channel_area_t areas[pcm->channels];
-	snd_pcm_sframes_t n = snd_pcm_writen(file->gen.slave, bufs, size);
+	snd_pcm_sframes_t n;
+
+	if (file->nextfile) {
+		SNDERR("DEBUG: Noninterleaved read not yet implemented.\n");
+		return 0;	/* Noninterleaved read not yet implemented */
+	}
+
+	n = snd_pcm_readn(file->gen.slave, bufs, size);
 	if (n > 0) {
 		snd_pcm_areas_from_bufs(pcm, areas, bufs);
 		snd_pcm_file_add_frames(pcm, areas, 0, n);
@@ -377,11 +403,11 @@ static snd_pcm_fast_ops_t snd_pcm_file_f
  *          changed in future.
  */
 int snd_pcm_file_open(snd_pcm_t **pcmp, const char *name,
-		      const char *fname, int fd, const char *fmt, int perm,
-		      snd_pcm_t *slave, int close_slave)
+		      const char *fname, int fd, const char *ifname, int ifd, 
+		      const char *fmt, int perm, snd_pcm_t *slave, int close_slave)
 {
 	snd_pcm_t *pcm;
-	snd_pcm_file_t *file;
+	snd_pcm_file_t *file, *ifile;
 	snd_pcm_file_format_t format;
 	int err;
 	assert(pcmp);
@@ -395,7 +421,7 @@ int snd_pcm_file_open(snd_pcm_t **pcmp, 
 	if (fname) {
 		fd = open(fname, O_WRONLY|O_CREAT, perm);
 		if (fd < 0) {
-			SYSERR("open %s failed", fname);
+			SYSERR("open %s for writing failed", fname);
 			return -errno;
 		}
 	}
@@ -405,7 +431,34 @@ int snd_pcm_file_open(snd_pcm_t **pcmp, 
 			close(fd);
 		return -ENOMEM;
 	}
-	
+
+	if (ifname) {
+		ifd = open(ifname, O_RDONLY);
+		if (ifd < 0) {
+			SYSERR("open %s for reading failed", ifname);
+			if (fname)
+				close(fd);
+			return -errno;
+		}
+	}
+	if (ifd) {
+		ifile = calloc(1, sizeof(snd_pcm_file_t));
+		if (!ifile) {
+			if (ifname)
+				close(ifd);
+			if (fname)
+				close(fd);
+			return -ENOMEM;
+		}
+		if (ifname)
+			ifile->fname = strdup(ifname);
+		ifile->fd = ifd;
+		ifile->format = format;
+		ifile->gen.slave = slave;		/* Do I really have to do this? */
+		ifile->gen.close_slave = close_slave;	/* And this?                    */
+		file->nextfile = ifile;
+	}
+
 	if (fname)
 		file->fname = strdup(fname);
 	file->fd = fd;
@@ -486,9 +539,9 @@ int _snd_pcm_file_open(snd_pcm_t **pcmp,
 	int err;
 	snd_pcm_t *spcm;
 	snd_config_t *slave = NULL, *sconf;
-	const char *fname = NULL;
+	const char *fname = NULL, *ifname = NULL;
 	const char *format = NULL;
-	long fd = -1;
+	long fd = -1, ifd = -1;
 	int perm = 0600;
 	snd_config_for_each(i, next, conf) {
 		snd_config_t *n = snd_config_iterator_entry(i);
@@ -513,6 +566,17 @@ int _snd_pcm_file_open(snd_pcm_t **pcmp,
 			err = snd_config_get_string(n, &fname);
 			if (err < 0) {
 				err = snd_config_get_integer(n, &fd);
+				if (err < 0) {
+					SNDERR("Invalid type for %s", id);
+					return -EINVAL;
+				}
+			}
+			continue;
+		}
+		if (strcmp(id, "infile") == 0) {
+			err = snd_config_get_string(n, &ifname);
+			if (err < 0) {
+				err = snd_config_get_integer(n, &ifd);
 				if (err < 0) {
 					SNDERR("Invalid type for %s", id);
 					return -EINVAL;
@@ -556,7 +620,7 @@ int _snd_pcm_file_open(snd_pcm_t **pcmp,
 	snd_config_delete(sconf);
 	if (err < 0)
 		return err;
-	err = snd_pcm_file_open(pcmp, name, fname, fd, format, perm, spcm, 1);
+	err = snd_pcm_file_open(pcmp, name, fname, fd, ifname, ifd, format, perm, spcm, 1);
 	if (err < 0)
 		snd_pcm_close(spcm);
 	return err;

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

* Re: Another asinine question
  2006-05-16 14:33   ` Juan Carlos Castro y Castro
  2006-05-16 14:38     ` Takashi Iwai
@ 2006-05-16 18:44     ` Juan Carlos Castro y Castro
  1 sibling, 0 replies; 10+ messages in thread
From: Juan Carlos Castro y Castro @ 2006-05-16 18:44 UTC (permalink / raw)
  To: Takashi Iwai; +Cc: alsa-devel

Juan Carlos Castro y Castro wrote:

> By the way, my pcm_file extensions DO work! It's the "plug" plugin 
> that's not passing the reads! Stay tuned...

I'm pretty sure now the problem lies with the plug plugin -- I am either 
not using it right (more likely) or I need to use a different plugin 
entirely (less likely) or more hacking will be needed (unlikely).

Current status is: with my changes, if I use the file PCM as microphone 
input (and use capture parameters that match the raw input file format), 
capture works. The "plug" PCM is for format conversion, and it doesn't 
work for input, only for output. Here's my current .asoundrc:

------------------------------------------------------------
pcm.fileout {
        type file
        file /home/jcastro/alsaout.raw
        infile /home/jcastro/alsain.raw
        slave.pcm null
}

pcm_slave.sl3 {
    pcm "fileout"
    format S16_LE
    channels 1
    rate 48000
}

pcm.complex_convert {
    type plug
    slave sl3
}
------------------------------------------------------------



-------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642

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

* Re: Another asinine question
  2006-05-16 16:28       ` Juan Carlos Castro y Castro
@ 2006-05-17 13:26         ` Takashi Iwai
  0 siblings, 0 replies; 10+ messages in thread
From: Takashi Iwai @ 2006-05-17 13:26 UTC (permalink / raw)
  To: Juan Carlos Castro y Castro; +Cc: alsa-devel

At Tue, 16 May 2006 13:28:23 -0300,
Juan Carlos Castro y Castro wrote:
> 
> Takashi Iwai wrote:
> 
> >Juan Carlos Castro y Castro wrote:
> >  
> >
> >>By the way, my pcm_file extensions DO work! It's the "plug" plugin 
> >>that's not passing the reads! Stay tuned...
> >>    
> >>
> >Great, feel free to submit the patches to alsa-devel ML (Cc to me).
> >
> Your wish is my command, Takashi-san. ;)
> 
> Note the interleaved read has not yet been implemented. Also, I'm not 
> yet dealing with blocking versus non-blocking at the moment. When 
> reading from a file, read()'s just keep getting zero bytes and arecord 
> doesn't mind. Some deal of sophistication will have to be added.
 
That's OK.  We can extend the feature later.

> Another thing: you'll see I just "hung" another snd_pcm_file_t structure 
> at the bottom of the original one. I'll understand if that offends 
> people's coding sensibilities -- it offended mine. :-/

Does't only one file descriptor instead of the whole snd_pcm_file
struct suffice?  Actually, it's used only in readi().


> @@ -377,11 +403,11 @@ static snd_pcm_fast_ops_t snd_pcm_file_f
>   *          changed in future.
>   */
>  int snd_pcm_file_open(snd_pcm_t **pcmp, const char *name,
> -		      const char *fname, int fd, const char *fmt, int perm,
> -		      snd_pcm_t *slave, int close_slave)
> +		      const char *fname, int fd, const char *ifname, int ifd, 
> +		      const char *fmt, int perm, snd_pcm_t *slave, int close_slave)

Don't forget to change the doxygen comment for this function.

> @@ -405,7 +431,34 @@ int snd_pcm_file_open(snd_pcm_t **pcmp, 
>  			close(fd);
>  		return -ENOMEM;
>  	}
> -	
> +
> +	if (ifname) {
> +		ifd = open(ifname, O_RDONLY);
> +		if (ifd < 0) {
> +			SYSERR("open %s for reading failed", ifname);
> +			if (fname)
> +				close(fd);
> +			return -errno;
> +		}
> +	}
> +	if (ifd) {

Should be "if (ifd >= 0)".


Also, please make a patch against the latest HG repository.
The typo in readn() was already fixed, so your last patch conflicts
with the latest tree.


Thanks,

Takashi


-------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642

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

* Re: Another asinine question
@ 2006-05-17 14:48 Juan Carlos Castro y Castro
  2006-05-17 15:24 ` Takashi Iwai
  0 siblings, 1 reply; 10+ messages in thread
From: Juan Carlos Castro y Castro @ 2006-05-17 14:48 UTC (permalink / raw)
  To: alsa-devel

[-- Attachment #1: Type: text/plain, Size: 2114 bytes --]

Ooops, forgot to send this to the list...

Takashi Iwai wrote:

>>>Great, feel free to submit the patches to alsa-devel ML (Cc to me).
>>>      
>>>
>>Your wish is my command, Takashi-san. ;)
>>
>>Note the interleaved read has not yet been implemented. Also, I'm not 
>>yet dealing with blocking versus non-blocking at the moment. When 
>>reading from a file, read()'s just keep getting zero bytes and arecord 
>>doesn't mind. Some deal of sophistication will have to be added.
>>    
>>
>That's OK.  We can extend the feature later.
>  
>
>>Another thing: you'll see I just "hung" another snd_pcm_file_t structure 
>>at the bottom of the original one. I'll understand if that offends 
>>people's coding sensibilities -- it offended mine. :-/
>>    
>>
>Does't only one file descriptor instead of the whole snd_pcm_file
>struct suffice?  Actually, it's used only in readi().
>  
>
Not really, especially when I finally tackle _readn. And even in the 
noninterleaved case, there's always the possibility read() will return a 
number of bytes that's not a multiple of the frame size (especially if 
the file is a named pipe). I'll need ->wbuf and some of those indexes to 
keep the remaining bytes for the next read.

>>@@ -377,11 +403,11 @@ static snd_pcm_fast_ops_t snd_pcm_file_f
>>  *          changed in future.
>>  */
>> int snd_pcm_file_open(snd_pcm_t **pcmp, const char *name,
>>-		      const char *fname, int fd, const char *fmt, int perm,
>>-		      snd_pcm_t *slave, int close_slave)
>>+		      const char *fname, int fd, const char *ifname, int ifd, 
>>+		      const char *fmt, int perm, snd_pcm_t *slave, int close_slave)
>>    
>>
>Don't forget to change the doxygen comment for this function.
>  
>
OK. Tell me if the two-line description for the ifd param is kosher.

>>(snip) +		}
>>+	}
>>+	if (ifd) {
>>    
>>
>Should be "if (ifd >= 0)".
>  
>
Oops.

>Also, please make a patch against the latest HG repository.
>The typo in readn() was already fixed, so your last patch conflicts
>with the latest tree.
>  
>
hg pull -u only gave me new things this morning. Updated and patch attached.

Juan



[-- Attachment #2: pcm_file-infile.2.patch --]
[-- Type: text/x-patch, Size: 5876 bytes --]

diff -r 372caededbb6 src/pcm/pcm_file.c
--- a/src/pcm/pcm_file.c	Fri May 12 15:33:44 2006 +0200
+++ b/src/pcm/pcm_file.c	Wed May 17 10:55:59 2006 -0300
@@ -42,7 +42,7 @@ typedef enum _snd_pcm_file_format {
 	SND_PCM_FILE_FORMAT_RAW
 } snd_pcm_file_format_t;
 
-typedef struct {
+typedef struct snd_pcm_file_t_struct {
 	snd_pcm_generic_t gen;
 	char *fname;
 	int fd;
@@ -55,6 +55,7 @@ typedef struct {
 	char *wbuf;
 	snd_pcm_channel_area_t *wbuf_areas;
 	size_t buffer_bytes;
+	struct snd_pcm_file_t_struct *nextfile;
 } snd_pcm_file_t;
 
 #endif /* DOC_HIDDEN */
@@ -120,6 +121,14 @@ static int snd_pcm_file_close(snd_pcm_t 
 		free((void *)file->fname);
 		close(file->fd);
 	}
+	if (file->nextfile) {
+		if (file->nextfile->fname) {
+			free((void *)file->nextfile->fname);
+			close(file->nextfile->fd);
+		}
+		free(file->nextfile);
+		file->nextfile = NULL;
+	}
 	return snd_pcm_generic_close(pcm);
 }
 
@@ -222,10 +231,20 @@ static snd_pcm_sframes_t snd_pcm_file_re
 {
 	snd_pcm_file_t *file = pcm->private_data;
 	snd_pcm_channel_area_t areas[pcm->channels];
-	snd_pcm_sframes_t n = snd_pcm_readi(file->gen.slave, buffer, size);
-	if (n > 0) {
-		snd_pcm_areas_from_buf(pcm, areas, buffer);
-		snd_pcm_file_add_frames(pcm, areas, 0, n);
+	snd_pcm_sframes_t n /* , bytesn */;
+
+	if (file->nextfile) {
+		n = /* bytesn = */ read(file->nextfile->fd, buffer, size * pcm->frame_bits / 8);
+		if (n > 0)
+			n = n * 8 / pcm->frame_bits;
+		/* SNDERR("DEBUG: channels = %d, sample_bits = %d, frame_bits = %d, bytes = %d, frames = %d",
+		        pcm->channels, pcm->sample_bits, pcm->frame_bits, bytesn, n); */
+	} else {
+		n = snd_pcm_readi(file->gen.slave, buffer, size);
+		if (n > 0) {
+			snd_pcm_areas_from_buf(pcm, areas, buffer);
+			snd_pcm_file_add_frames(pcm, areas, 0, n);
+		}
 	}
 	return n;
 }
@@ -234,7 +253,14 @@ static snd_pcm_sframes_t snd_pcm_file_re
 {
 	snd_pcm_file_t *file = pcm->private_data;
 	snd_pcm_channel_area_t areas[pcm->channels];
-	snd_pcm_sframes_t n = snd_pcm_readn(file->gen.slave, bufs, size);
+	snd_pcm_sframes_t n;
+
+	if (file->nextfile) {
+		SNDERR("DEBUG: Noninterleaved read not yet implemented.\n");
+		return 0;	/* Noninterleaved read not yet implemented */
+	}
+
+	n = snd_pcm_readn(file->gen.slave, bufs, size);
 	if (n > 0) {
 		snd_pcm_areas_from_bufs(pcm, areas, bufs);
 		snd_pcm_file_add_frames(pcm, areas, 0, n);
@@ -365,8 +391,11 @@ static snd_pcm_fast_ops_t snd_pcm_file_f
  * \brief Creates a new File PCM
  * \param pcmp Returns created PCM handle
  * \param name Name of PCM
- * \param fname Filename (or NULL if file descriptor is available)
- * \param fd File descriptor
+ * \param fname Output filename (or NULL if file descriptor fd is available)
+ * \param fd Output file descriptor
+ * \param ifname Input filename (or NULL if file descriptor ifd is available)
+ * \param ifd Input file descriptor (if (ifd < 0) && (ifname == NULL), no input
+ *            redirection will be performed)
  * \param fmt File format ("raw" is supported only)
  * \param perm File permission
  * \param slave Slave PCM handle
@@ -377,11 +406,11 @@ static snd_pcm_fast_ops_t snd_pcm_file_f
  *          changed in future.
  */
 int snd_pcm_file_open(snd_pcm_t **pcmp, const char *name,
-		      const char *fname, int fd, const char *fmt, int perm,
-		      snd_pcm_t *slave, int close_slave)
+		      const char *fname, int fd, const char *ifname, int ifd, 
+		      const char *fmt, int perm, snd_pcm_t *slave, int close_slave)
 {
 	snd_pcm_t *pcm;
-	snd_pcm_file_t *file;
+	snd_pcm_file_t *file, *ifile;
 	snd_pcm_file_format_t format;
 	int err;
 	assert(pcmp);
@@ -395,7 +424,7 @@ int snd_pcm_file_open(snd_pcm_t **pcmp, 
 	if (fname) {
 		fd = open(fname, O_WRONLY|O_CREAT, perm);
 		if (fd < 0) {
-			SYSERR("open %s failed", fname);
+			SYSERR("open %s for writing failed", fname);
 			return -errno;
 		}
 	}
@@ -405,7 +434,34 @@ int snd_pcm_file_open(snd_pcm_t **pcmp, 
 			close(fd);
 		return -ENOMEM;
 	}
-	
+
+	if (ifname) {
+		ifd = open(ifname, O_RDONLY);
+		if (ifd < 0) {
+			SYSERR("open %s for reading failed", ifname);
+			if (fname)
+				close(fd);
+			return -errno;
+		}
+	}
+	if (ifd >= 0) {
+		ifile = calloc(1, sizeof(snd_pcm_file_t));
+		if (!ifile) {
+			if (ifname)
+				close(ifd);
+			if (fname)
+				close(fd);
+			return -ENOMEM;
+		}
+		if (ifname)
+			ifile->fname = strdup(ifname);
+		ifile->fd = ifd;
+		ifile->format = format;
+		ifile->gen.slave = slave;		/* Do I really have to do this? */
+		ifile->gen.close_slave = close_slave;	/* And this?                    */
+		file->nextfile = ifile;
+	}
+
 	if (fname)
 		file->fname = strdup(fname);
 	file->fd = fd;
@@ -486,9 +542,9 @@ int _snd_pcm_file_open(snd_pcm_t **pcmp,
 	int err;
 	snd_pcm_t *spcm;
 	snd_config_t *slave = NULL, *sconf;
-	const char *fname = NULL;
+	const char *fname = NULL, *ifname = NULL;
 	const char *format = NULL;
-	long fd = -1;
+	long fd = -1, ifd = -1;
 	int perm = 0600;
 	snd_config_for_each(i, next, conf) {
 		snd_config_t *n = snd_config_iterator_entry(i);
@@ -513,6 +569,17 @@ int _snd_pcm_file_open(snd_pcm_t **pcmp,
 			err = snd_config_get_string(n, &fname);
 			if (err < 0) {
 				err = snd_config_get_integer(n, &fd);
+				if (err < 0) {
+					SNDERR("Invalid type for %s", id);
+					return -EINVAL;
+				}
+			}
+			continue;
+		}
+		if (strcmp(id, "infile") == 0) {
+			err = snd_config_get_string(n, &ifname);
+			if (err < 0) {
+				err = snd_config_get_integer(n, &ifd);
 				if (err < 0) {
 					SNDERR("Invalid type for %s", id);
 					return -EINVAL;
@@ -556,7 +623,7 @@ int _snd_pcm_file_open(snd_pcm_t **pcmp,
 	snd_config_delete(sconf);
 	if (err < 0)
 		return err;
-	err = snd_pcm_file_open(pcmp, name, fname, fd, format, perm, spcm, 1);
+	err = snd_pcm_file_open(pcmp, name, fname, fd, ifname, ifd, format, perm, spcm, 1);
 	if (err < 0)
 		snd_pcm_close(spcm);
 	return err;


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

* Re: Another asinine question
  2006-05-17 14:48 Another asinine question Juan Carlos Castro y Castro
@ 2006-05-17 15:24 ` Takashi Iwai
  2006-05-17 16:22   ` Juan Carlos Castro y Castro
  0 siblings, 1 reply; 10+ messages in thread
From: Takashi Iwai @ 2006-05-17 15:24 UTC (permalink / raw)
  To: Juan Carlos Castro y Castro; +Cc: alsa-devel

At Wed, 17 May 2006 11:48:06 -0300,
Juan Carlos Castro y Castro wrote:
> 
> Ooops, forgot to send this to the list...
> 
> Takashi Iwai wrote:
> 
> >>>Great, feel free to submit the patches to alsa-devel ML (Cc to me).
> >>>      
> >>>
> >>Your wish is my command, Takashi-san. ;)
> >>
> >>Note the interleaved read has not yet been implemented. Also, I'm not 
> >>yet dealing with blocking versus non-blocking at the moment. When 
> >>reading from a file, read()'s just keep getting zero bytes and arecord 
> >>doesn't mind. Some deal of sophistication will have to be added.
> >>    
> >>
> >That's OK.  We can extend the feature later.
> >  
> >
> >>Another thing: you'll see I just "hung" another snd_pcm_file_t structure 
> >>at the bottom of the original one. I'll understand if that offends 
> >>people's coding sensibilities -- it offended mine. :-/
> >>    
> >>
> >Does't only one file descriptor instead of the whole snd_pcm_file
> >struct suffice?  Actually, it's used only in readi().
> >  
> >
> Not really, especially when I finally tackle _readn. And even in the 
> noninterleaved case, there's always the possibility read() will return a 
> number of bytes that's not a multiple of the frame size (especially if 
> the file is a named pipe). I'll need ->wbuf and some of those indexes to 
> keep the remaining bytes for the next read.

Then let's create another object type.  It's confusing to use the
existing object for completly another purpose.

Also, "nextfile" doesn't sound intuitive in this case.  (it sounds
like a linked chain of data.)


Takashi


-------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642

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

* Re: Another asinine question
  2006-05-17 15:24 ` Takashi Iwai
@ 2006-05-17 16:22   ` Juan Carlos Castro y Castro
  0 siblings, 0 replies; 10+ messages in thread
From: Juan Carlos Castro y Castro @ 2006-05-17 16:22 UTC (permalink / raw)
  To: Takashi Iwai; +Cc: alsa-devel

Takashi Iwai wrote:

>>>>Another thing: you'll see I just "hung" another snd_pcm_file_t structure at the bottom of the original one. I'll understand if that offends people's coding sensibilities -- it offended mine. :-/
>>>>        
>>>>
>>>Does't only one file descriptor instead of the whole snd_pcm_file struct suffice?  Actually, it's used only in readi().
>>>      
>>>
>>Not really, especially when I finally tackle _readn. And even in the noninterleaved case, there's always the possibility read() will return a number of bytes that's not a multiple of the frame size (especially if the file is a named pipe). I'll need ->wbuf and some of those indexes to keep the remaining bytes for the next read.
>>    
>>
>Then let's create another object type.  It's confusing to use the existing object for completly another purpose.
>
>Also, "nextfile" doesn't sound intuitive in this case.  (it sounds like a linked chain of data.)
>  
>
Agree and agree. I DID say it was offensive. In my defense, boss was 
swinging the whip and I had to churn out code rather quickly. OK, that 
was a lame excuse. :-/

For the noninterleaved case, I think a plain dumb byte FIFO (buffer, 
head, tail) would be enough. I'll only be able to code on that tomorrow 
-- got an unrelated deadline to meet today.

Juan


-------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642

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

end of thread, other threads:[~2006-05-17 16:22 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-05-17 14:48 Another asinine question Juan Carlos Castro y Castro
2006-05-17 15:24 ` Takashi Iwai
2006-05-17 16:22   ` Juan Carlos Castro y Castro
  -- strict thread matches above, loose matches on Subject: below --
2006-05-12 15:06 Juan Carlos Castro y Castro
2006-05-16 13:38 ` Takashi Iwai
2006-05-16 14:33   ` Juan Carlos Castro y Castro
2006-05-16 14:38     ` Takashi Iwai
2006-05-16 16:28       ` Juan Carlos Castro y Castro
2006-05-17 13:26         ` Takashi Iwai
2006-05-16 18:44     ` Juan Carlos Castro y Castro

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.