Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add interactive pause/resume functionality #14

Merged
merged 2 commits into from
Sep 19, 2022

Conversation

LaurentiuM1234
Copy link

@LaurentiuM1234 LaurentiuM1234 commented Aug 26, 2022

We want to be able to interactively pause and resume the stream.

Initially, when trying to play an MP3 song, cplay would hang during the polling on compress_write. The cause for this was the fact that, after calling get_codec_mp3, the file pointer would point to the first MP3 data, leaving out the first MP3 header. I'm assuming that this would cause the codec to be unable to process the received frames since it wouldn't be able to find the first MP3 header.

In order to be able to use the pause/resume functionality on MP3 streams, this problem had to be addressed before adding the actual functionality.

We need to reset the file cursor to the beginning of the file.

Initially, the program would simply get stuck polling the
compress fd. This was probably because of the fact that the
codec would hang because of the fact that it was expecting
to receive the MP3 data along with its associated MP3 header.

This was not the case for the first (header, data) pair because,
after parsing the first header, the file cursor would point
at the beginning of the data region.

By resetting the file cursor to the beginning of the file,
the codec will receive all the (header, data) pairs it
actually expects.

Suggested-by: Shengjiu Wang <shengjiu.wang@nxp.com>
Signed-off-by: Laurentiu Mihalcea <laurentiu.mihalcea@nxp.com>
src/utils/cplay.c Outdated Show resolved Hide resolved
@LaurentiuM1234
Copy link
Author

Update

  1. Removed the switch statement from play_samples and created new function check_stdin used to handle the pause-resume functionality. This should minimize the mix between the pause-resume code and the code for writing frames. @dbaluta Let me know what you think.

@dbaluta
Copy link
Contributor

dbaluta commented Sep 5, 2022

@perexg @vinodkoul can you please help review this?

@LaurentiuM1234
Copy link
Author

Update:

  1. Fixed commit message to reflect the actual key used for pausing/resuming.

Copy link
Member

@perexg perexg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As @dbaluta noted, the aplay tool supports Space and Enter ('\r') keys for the pause operation.

Otherwise the change looks fine in my eyes.

@LaurentiuM1234
Copy link
Author

@perexg Should be fine now

Copy link
Contributor

@vinodkoul vinodkoul left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/utilitary/utility

src/utils/cplay.c Outdated Show resolved Hide resolved
src/utils/cplay.c Outdated Show resolved Hide resolved
Copy link
Contributor

@vinodkoul vinodkoul left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm, few nitpciks though

Copy link
Contributor

@plbossart plbossart left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggesting avoiding the term 'resume', it leads to confusions between pause_push/pause_release and suspend/resume.

Also I am not sure what happens with compressed formats such as AAC_ADIF, where the information configuration is provided initially and not with a header. There might be a need to prevent the DSP from suspending to avoid losing context?

src/utils/cplay.c Outdated Show resolved Hide resolved
is_paused = true;
break;
case DO_RESUME:
if (compress_resume(compress) != 0) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

compress_pause_release

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be addressed in another series of patches as this one doesn't actually introduce compress_resume() but it just uses it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, this should be done as a different change

We want to be able to pause and resume the stream
just like the ALSA utilitary aplay does.

In order to do so, we first need to mark the read operations
on stdin as nonblocking and then enable the noncanonical mode
for the terminal. What this does is it makes the read operations
nonblocking and it makes the input available immediately.

After doing so, we can check if we receive a SPACE or ENTER
character from user and do pause/resume depending on current
stream state (and by this I mean if the stream is currently
paused and we receive a SPACE or ENTER then we resume it
and vice-versa)

Signed-off-by: Maurine Creton <maurine.creton@nxp.com>
Signed-off-by: Laurentiu Mihalcea <laurentiu.mihalcea@nxp.com>
@dbaluta
Copy link
Contributor

dbaluta commented Sep 19, 2022

@vinodkoul @plbossart @perexg I think we are good with this. All the comments have been addressed.

@vinodkoul vinodkoul merged commit 7dc18a7 into alsa-project:master Sep 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants