Skip to contentSkip to conversation

pcm_file: add infile read support for mmap mode

PATCH Takashi Iwai 3 participants 8 messages May 21, 2019 4 messages not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): [email protected]

#3 lore raw
Quoted 11 lines · Adam (Arion Recruitment; ADITG/ESM)

From: Adam Miartus <[email protected]>

mmap_begin callback is used to copy data from input file to mmaped buffer

guard for corner use of api (multiple mmap_begin calls by user) is introduced to check if next continuous buffer was already overwritten

buffer is overwritten with input file data only in case of stream capture

Can't we copy the data in snd_pcm_file_mmap_commit() just like the playback case?

thanks,

Takashi

#4 lore raw
Quoted 17 lines
Quoted 6 lines · Adam (Arion Recruitment; ADITG/ESM)

From: Adam Miartus <[email protected]>

mmap_begin callback is used to copy data from input file to mmaped buffer

Quoted 8 lines

guard for corner use of api (multiple mmap_begin calls by user) is introduced to check if next continuous buffer was already overwritten

buffer is overwritten with input file data only in case of stream capture

Quoted 7 lines

Can't we copy the data in snd_pcm_file_mmap_commit() just like the playback case?

thanks,

Takashi

My understanding is that in case of reading data in mmap mode user would call mmap_begin, read the buffer and then call mmap_commit.

In this case overwriting the buffer in mmap_commit with data from Input file would be too late.

Best regards,
Adam

#5 lore raw
Quoted 24 lines · Adam (Arion Recruitment; ADITG/ESM)
Quoted 24 lines
Quoted 6 lines · Adam (Arion Recruitment; ADITG/ESM)

From: Adam Miartus <[email protected]>

mmap_begin callback is used to copy data from input file to mmaped buffer

Quoted 8 lines

guard for corner use of api (multiple mmap_begin calls by user) is introduced to check if next continuous buffer was already overwritten

buffer is overwritten with input file data only in case of stream capture

Can't we copy the data in snd_pcm_file_mmap_commit() just like the playback case?

thanks,

Quoted 7 lines
Quoted 1 line

Takashi

My understanding is that in case of reading data in mmap mode user would call mmap_begin, read the buffer and then call mmap_commit.

In this case overwriting the buffer in mmap_commit with data from Input file would be too late.

Hm, OK. I basically hate to add a new ops, but this might be the only way if we have to implement that.

OTOH, is this mmap support mandatory? IOW, is wrapping with the plug and mmap_emul performance-wise so bad?

thanks,

Takashi

#6 lore raw

Hi,

Quoted 28 lines · Takashi Iwai
Quoted 26 lines · Adam (Arion Recruitment; ADITG/ESM)
Quoted 25 lines
Quoted 6 lines · Adam (Arion Recruitment; ADITG/ESM)

From: Adam Miartus <[email protected]>

mmap_begin callback is used to copy data from input file to mmaped buffer

Quoted 8 lines

guard for corner use of api (multiple mmap_begin calls by user) is introduced to check if next continuous buffer was already overwritten

buffer is overwritten with input file data only in case of stream capture

Can't we copy the data in snd_pcm_file_mmap_commit() just like the playback case?

thanks,

Takashi

Quoted 8 lines
Quoted 5 lines

My understanding is that in case of reading data in mmap mode user would call mmap_begin, read the buffer and then call mmap_commit.

In this case overwriting the buffer in mmap_commit with data from Input file would be too late.

Hm, OK. I basically hate to add a new ops, but this might be the only way if we have to implement that.

I'm interested in this patch, however the patch is not blasted by list server. Would you please re-post your patchset so that the list server delivers them to subscribers and I can see the contents?

Quoted 2 lines

OTOH, is this mmap support mandatory? IOW, is wrapping with the plug and mmap_emul performance-wise so bad?

Regards

Takashi Sakamoto

#7 lore raw
In reply to Takashi Iwai
Quoted 37 lines
Quoted 24 lines · Adam (Arion Recruitment; ADITG/ESM)
Quoted 24 lines
Quoted 6 lines · Adam (Arion Recruitment; ADITG/ESM)

From: Adam Miartus <[email protected]>

mmap_begin callback is used to copy data from input file to mmaped buffer

Quoted 8 lines

guard for corner use of api (multiple mmap_begin calls by user) is introduced to check if next continuous buffer was already overwritten

buffer is overwritten with input file data only in case of stream capture

Can't we copy the data in snd_pcm_file_mmap_commit() just like the playback case?

thanks,

Quoted 7 lines
Quoted 1 line

Takashi

My understanding is that in case of reading data in mmap mode user would call mmap_begin, read the buffer and then call mmap_commit.

In this case overwriting the buffer in mmap_commit with data from Input file would be too late.

Hm, OK. I basically hate to add a new ops, but this might be the only way if we have to implement that.

Quoted 7 lines

OTOH, is this mmap support mandatory? IOW, is wrapping with the plug and mmap_emul performance-wise so bad?

thanks,

Takashi

I understand that extending the api is not ideal, however this approach in my opinion, simplifies the solution. API could also be used to simplify code in softvol plugin, which to my understanding loops around the buffer in avail_update callback. Maybe other plugins could benefit as well.

As for emulation of mmap I was not aware it is possible. We would like to use the file plugin in mmap mode as additional tool for debugging hw/sw, with option to overwrite the mmap buffer in read mode with data from file, in this case I think it would be preferred to access mmap area without emulation. However, if this can be accomplished without api change just by alsa configuration, perhaps there is no need for this change.

best regards,

Adam

A message that is not in the archive (sent off-list or not yet received): [email protected]

#9 lore raw

Re: [ALSA patch] FW: [PATCH - alsa-lib 1/4] pcm_file: add support for infile reading in non interleaved mode

Quoted 22 lines · Adam (Arion Recruitment; ADITG/ESM)

From: Adam Miartus <[email protected]>

add helper function to copy input file data to buffer mapped by areas, in case of an error, do not fill the areas, allowing device read buffer to be provided to api caller

previously unused rbuf variable is reused for this purpose

src/pcm/pcm_file.c +1 -0
@@ -77,6 +77,7 @@ typedef struct {
 	snd_pcm_uframes_t appl_ptr;
 	snd_pcm_uframes_t file_ptr_bytes;
 	snd_pcm_uframes_t wbuf_size;
+	snd_pcm_uframes_t rbuf_size;
 	size_t wbuf_size_bytes;
 	size_t wbuf_used_bytes;
 	char *wbuf;

src/pcm/pcm_file.c static int snd_pcm_file_open_output_file(snd_pcm_file_t *file) · line 272

Quoted 6 lines
src/pcm/pcm_file.c +3 -0
@@ -266,6 +267,37 @@ static int snd_pcm_file_open_output_file(snd_pcm_file_t *file)
 	return 0;
 }
 
+/* fill areas with data from input file, return bytes red */ static int 
+snd_pcm_file_areas_read_infile(snd_pcm_t *pcm, const snd_pcm_channel_area_t *areas,
+	snd_pcm_uframes_t offset, snd_pcm_uframes_t frames) {

Please follow the standard coding style.

Quoted 14 lines
src/pcm/pcm_file.c +14 -0
+	snd_pcm_file_t *file = pcm->private_data;
+	snd_pcm_channel_area_t areas_if[pcm->channels];
+	ssize_t bytes;
+
+	if (file->ifd < 0)
+		return -EBADF;
+
+	if (file->rbuf == NULL)
+		return -ENOMEM;
+
+	if (file->rbuf_size < frames) {
+		SYSERR("requested more frames than pcm buffer");
+		return -ENOMEM;
+	}

src/pcm/pcm_file.c static int snd_pcm_file_open_output_file(snd_pcm_file_t *file) · line 296

Quoted 10 lines
src/pcm/pcm_file.c +10 -0
+
+	bytes = read(file->ifd, file->rbuf, snd_pcm_frames_to_bytes(pcm, frames));
+	if (bytes < 0) {
+		SYSERR("read from file failed, error: %d", bytes);
+		return bytes;
+	}
+
+	snd_pcm_areas_from_buf(pcm, areas_if, file->rbuf);
+	snd_pcm_areas_copy(areas, offset, areas_if, 0, pcm->channels, 
+snd_pcm_bytes_to_frames(pcm, bytes), pcm->format);

Wrong indentation.

thanks,

Takashi

#10 lore raw

Re: [ALSA patch] FW: [PATCH - alsa-lib 1/4] pcm_file: add support for infile reading in non interleaved mode

Quoted 67 lines
Quoted 4 lines · Adam (Arion Recruitment; ADITG/ESM)

From: Adam Miartus <[email protected]>

add helper function to copy input file data to buffer mapped by areas, in

case of an error, do not fill the areas, allowing device read buffer to be provided to api caller

src/pcm/pcm_file.c index

Quoted 7 lines

previously unused rbuf variable is reused for this purpose

src/pcm/pcm_file.c index renamed from src/pcm/pcm_file.c +0 -0

3a19cef..7998b64 100644

src/pcm/pcm_file.c static int

Quoted 11 lines
src/pcm/pcm_file.c +1 -0
@@ -77,6 +77,7 @@ typedef struct {
 	snd_pcm_uframes_t appl_ptr;
 	snd_pcm_uframes_t file_ptr_bytes;
 	snd_pcm_uframes_t wbuf_size;
+	snd_pcm_uframes_t rbuf_size;
 	size_t wbuf_size_bytes;
 	size_t wbuf_used_bytes;
 	char *wbuf;
@@ -266,6 +267,37 @@ static int

snd_pcm_file_open_output_file(snd_pcm_file_t *file)

src/pcm/pcm_file.c static int · line 271

Quoted 5 lines
src/pcm/pcm_file.c +2 -0
 	return 0;
 }
 
+/* fill areas with data from input file, return bytes red */ static int
+snd_pcm_file_areas_read_infile(snd_pcm_t *pcm, const

snd_pcm_channel_area_t *areas,

src/pcm/pcm_file.c static int · line 272

Quoted 1 line
src/pcm/pcm_file.c +1 -0
+	snd_pcm_uframes_t offset, snd_pcm_uframes_t frames) {

Please follow the standard coding style.

Quoted 6 lines
src/pcm/pcm_file.c +6 -0
+	snd_pcm_file_t *file = pcm->private_data;
+	snd_pcm_channel_area_t areas_if[pcm->channels];
+	ssize_t bytes;
+
+	if (file->ifd < 0)
+		return -EBADF;

src/pcm/pcm_file.c static int · line 288

Quoted 10 lines
src/pcm/pcm_file.c +10 -0
+
+	if (file->rbuf == NULL)
+		return -ENOMEM;
+
+	if (file->rbuf_size < frames) {
+		SYSERR("requested more frames than pcm buffer");
+		return -ENOMEM;
+	}
+
+	bytes = read(file->ifd, file->rbuf, snd_pcm_frames_to_bytes(pcm,

frames));

src/pcm/pcm_file.c static int · line 296

Quoted 8 lines
src/pcm/pcm_file.c +8 -0
+	if (bytes < 0) {
+		SYSERR("read from file failed, error: %d", bytes);
+		return bytes;
+	}
+
+	snd_pcm_areas_from_buf(pcm, areas_if, file->rbuf);
+	snd_pcm_areas_copy(areas, offset, areas_if, 0, pcm->channels,
+snd_pcm_bytes_to_frames(pcm, bytes), pcm->format);

Wrong indentation.

Quoted 3 lines

thanks,

Takashi

Sorry, my email client messed up the whitespace. I re-sent the patch using git send-mail.

Best Regards,

Adam

#11 lore raw

Re: [ALSA patch] FW: [PATCH - alsa-lib 1/4] pcm_file: add support for infile reading in non interleaved mode

Quoted 68 lines · Adam (Arion Recruitment; ADITG/ESM)
Quoted 68 lines
Quoted 4 lines · Adam (Arion Recruitment; ADITG/ESM)

From: Adam Miartus <[email protected]>

add helper function to copy input file data to buffer mapped by areas, in

case of an error, do not fill the areas, allowing device read buffer to be provided to api caller

src/pcm/pcm_file.c index

Quoted 7 lines

previously unused rbuf variable is reused for this purpose

src/pcm/pcm_file.c index renamed from src/pcm/pcm_file.c +0 -0

3a19cef..7998b64 100644

src/pcm/pcm_file.c static int

Quoted 11 lines
src/pcm/pcm_file.c +1 -0
@@ -77,6 +77,7 @@ typedef struct {
 	snd_pcm_uframes_t appl_ptr;
 	snd_pcm_uframes_t file_ptr_bytes;
 	snd_pcm_uframes_t wbuf_size;
+	snd_pcm_uframes_t rbuf_size;
 	size_t wbuf_size_bytes;
 	size_t wbuf_used_bytes;
 	char *wbuf;
@@ -266,6 +267,37 @@ static int

snd_pcm_file_open_output_file(snd_pcm_file_t *file)

src/pcm/pcm_file.c static int · line 271

Quoted 5 lines
src/pcm/pcm_file.c +2 -0
 	return 0;
 }
 
+/* fill areas with data from input file, return bytes red */ static int
+snd_pcm_file_areas_read_infile(snd_pcm_t *pcm, const

snd_pcm_channel_area_t *areas,

src/pcm/pcm_file.c static int · line 272

Quoted 1 line
src/pcm/pcm_file.c +1 -0
+	snd_pcm_uframes_t offset, snd_pcm_uframes_t frames) {

Please follow the standard coding style.

Quoted 6 lines
src/pcm/pcm_file.c +6 -0
+	snd_pcm_file_t *file = pcm->private_data;
+	snd_pcm_channel_area_t areas_if[pcm->channels];
+	ssize_t bytes;
+
+	if (file->ifd < 0)
+		return -EBADF;

src/pcm/pcm_file.c static int · line 288

Quoted 10 lines
src/pcm/pcm_file.c +10 -0
+
+	if (file->rbuf == NULL)
+		return -ENOMEM;
+
+	if (file->rbuf_size < frames) {
+		SYSERR("requested more frames than pcm buffer");
+		return -ENOMEM;
+	}
+
+	bytes = read(file->ifd, file->rbuf, snd_pcm_frames_to_bytes(pcm,

frames));

src/pcm/pcm_file.c static int · line 296

Quoted 8 lines
src/pcm/pcm_file.c +8 -0
+	if (bytes < 0) {
+		SYSERR("read from file failed, error: %d", bytes);
+		return bytes;
+	}
+
+	snd_pcm_areas_from_buf(pcm, areas_if, file->rbuf);
+	snd_pcm_areas_copy(areas, offset, areas_if, 0, pcm->channels,
+snd_pcm_bytes_to_frames(pcm, bytes), pcm->format);

Wrong indentation.

Quoted 5 lines
Quoted 3 lines

thanks,

Takashi

Sorry, my email client messed up the whitespace. I re-sent the patch using git send-mail.

Could you resubmit the whole patch set, at best with a cover letter?

thanks,

Takashi