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 support for getting list of supported codecs #16

Closed
wants to merge 1 commit into from

Conversation

SanchayanMaity
Copy link

@SanchayanMaity SanchayanMaity commented Oct 5, 2022

Right now, there is no way to expose a list of codecs from tinycompress. While one could theoretically call is_codec_supported multiple times in an application to check against a list of codecs, an API would make it easy to enumerate supported codecs. The IOCTL SNDRV_COMPRESS_GET_CAPS after all already exists.

Our use case is Pipewire where we would like the compressed sink node to advertise only codecs supported by the underlying hardware. So far we were just advertising the complete list of codecs and let node linking fail at runtime based on result from is_codec_supported.

Pipewire MR: https://gitlab.freedesktop.org/pipewire/pipewire/-/merge_requests/1431

@SanchayanMaity SanchayanMaity changed the title Get caps Add support for getting list of supported codecs Oct 5, 2022
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.

Doesn't seem terribly safe to me in terms of memory use.

include/tinycompress/tinycompress.h Outdated Show resolved Hide resolved
src/lib/compress_hw.c 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.

Few nitpicks to avoid memory issues

@perexg
Copy link
Member

perexg commented Oct 14, 2022

Two notes:

  • i don't think that we need a special function to obtain the number of codecs - what about to use codecs == NULL argument to obtain the number of supported codecs ?
  • the new APIs may support only more universal name identifiers (avoid card/device - the older functions may be marked as obsolete), I vote to remove compress_get_supported_codecs

…decs

Right now, there is no way to expose a list of codecs from tinycompress. While
one could theoretically call is_codec_supported multiple times in an application
to check against a list of codecs, an API would make it easy to enumerate supported
codecs. The IOCTL SNDRV_COMPRESS_GET_CAPS after all already exists.

The use case is Pipewire where we would like the compressed sink Pipewire node to
advertise only codecs supported by the underlying hardware.

Signed-off-by: Sanchayan Maity <sanchayan@asymptotic.io>
@SanchayanMaity
Copy link
Author

Two notes:

* i don't think that we need a special function to obtain the number of codecs - what about to use `codecs == NULL` argument to obtain the number of supported codecs ?

* the new APIs may support only more universal name identifiers (avoid card/device - the older functions may be marked as obsolete), I vote to remove `compress_get_supported_codecs`

Assuming this is the consensus made the changes.

SanchayanMaity added a commit to asymptotic-io/meta-asymptotic that referenced this pull request Nov 2, 2022
Need the supported codecs API which is yet to be merged upstream.

alsa-project/tinycompress#16
@SanchayanMaity
Copy link
Author

SanchayanMaity commented Jan 26, 2023

Any chance of progressing on this?

The PipeWire support has been merged upstream and is included in the 0.3.65 release.
https://gitlab.freedesktop.org/pipewire/pipewire/-/releases#highlights
https://gitlab.freedesktop.org/pipewire/pipewire/-/merge_requests/1431

It could use this to detect the supported codecs properly.

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 recommend you add TWO callbacks

get_supported_codecs_number()
get_supported_codecs_by_device_name()

a single callback is difficult to use, applications will have to use a larger buffer than necessary or guess, none of these solutions is desirable.

*
* format of name is :
* hw:<card>,<device> for real hw compress node
* <plugin_libname>:<custom string> for virtual compress node
Copy link
Contributor

Choose a reason for hiding this comment

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

what is a 'virtual compress node'?

What is a 'node' in general? That's not a terminology we use in this area. please explain.

* <plugin_libname>:<custom string> for virtual compress node
*
* @name: name of the compress node
* @flags: stream flags
Copy link
Contributor

Choose a reason for hiding this comment

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

what is the definition of those flags?

* @name: name of the compress node
* @flags: stream flags
* @codecs: Pointer to an array which will hold the list of codecs
* @size: Size in bytes of the codecs array
Copy link
Contributor

Choose a reason for hiding this comment

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

still weird. Why not add a callback to get the number of codecs first? How would userspace guessestimate what to add here?

Copy link
Member

Choose a reason for hiding this comment

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

There is a missing description. If codecs == NULL the size should be returned by the API. I don't think that we need two exported functions / callbacks for this simple job.

Copy link
Contributor

Choose a reason for hiding this comment

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

that'd be fine, yes

if (!compress)
return ret;

if ((name[0] == 'h') || (name[1] == 'w') || (name[2] == ':')) {
Copy link
Contributor

Choose a reason for hiding this comment

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

check is name != NULL first and string size > 3 ?

Copy link
Member

Choose a reason for hiding this comment

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

It's an undefined input so the crash is ok. The assert may be added. The size checking is not required, because the '\0' termination character is matched correctly.

Copy link
Contributor

Choose a reason for hiding this comment

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

"the crash is ok" ? not following, sorry.

src/lib/compress.c Show resolved Hide resolved
src/lib/compress_hw.c Show resolved Hide resolved

if (num_codecs > codecs_buf_sz)
return oops(&bad_compress, EINVAL,
"Input not big enough to hold %d available codecs", num_codecs);
Copy link
Contributor

Choose a reason for hiding this comment

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

why not return that number of codecs earlier with a separate API, that would help applications know what buffer size they need to provide?

Of course you still want to check the size.

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