-
Notifications
You must be signed in to change notification settings - Fork 20
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
Plugin support in tinycompress #6
Conversation
src/lib/utils/snd_utils.c
Outdated
@@ -0,0 +1,140 @@ | |||
/* snd_utils.c | |||
** | |||
** Copyright (c) 2019, The Linux Foundation. All rights reserved. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we switch to SPDX identifiers?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sure .. we can do that .. only thing is current files has not moved to SPDX identifiers. So followed the same.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cc: @perexg. I would say we could start using SPDX identifiers and add a mental note to change existing files later.
@rohkkumar do you have any dummy decoding .so library to better understand the interface? For example it is not very clear to me how do you decode an mp3 frame. So, with the current interface would be possible to input an mp3 file and get the corresponding uncompressed pcm file resulted after applying the decoding algorithm? We have this legacy interface: https://github.com/FreeSrk/codec/blob/master/ghdr/common/fsl_unia.h It offers the following interface:
|
src/lib/compress.c
Outdated
#include "compress_ops.h" | ||
#ifdef TINYCOMPRESS_USES_PLUGINS | ||
#include "utils/snd_utils.h" | ||
#endif |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, do you need to recompile the library to use plugins? Isn't possible to determine at runtime if one should use plugins or real hw?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, our initial implementation had the same design where virtual(plugin) device was decided if the hw node is present or not and if there is virtual node in configuration file. But as discussed in PR for tinyalsa tinyalsa/tinyalsa#137 , we got a feedback to handle it using compile time flag too so that it can be disabled for those who don't want plugin support.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rohkkumar ok.
Yes, I have implemented a ffmpeg based example plugin to decode FLAC data to PCM and do tinyalsa calls. I will plan to post that out. Thanks |
@rohkkumar Great, looking forward to read the code for that example. |
f58f3a3
to
415406c
Compare
Updated patches with SPDX identifiers and added ffmpeg based plugin example. |
|
||
/* initialize the resampling context */ | ||
if ((ret = swr_init(swr_ctx)) < 0) { | ||
fprintf(stderr, "Failed to initialize the resampling context\n"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
415406c
to
28eadca
Compare
@perexg can you please review as well, we need to make sure this aligns with overall way we want alsa plugins to behave... |
src/lib/utils/snd_utils.c
Outdated
@@ -0,0 +1,117 @@ | |||
// SPDX-License-Identifier: GPL-2.0-only |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So this needs to be modified. The Tinycompress project is dual licensed as LGPL and BSD. This license is incompatible to this project, so I can not consider this change. Please reconsider licensing as LGPL or BSD or both.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure @vinodkoul , I will update the license.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
License needs to be clarified before we forward on these patches. Right now it is incompatible
I have problem with 'libsndcardparser.so' references. It's not a standard library. It's a bit pity that compress_open() does not accept the device name (string) as argument - it's better for applications. I see the possibility to use a configuration file with card/device number to shared library mapping or special .so lookups in compress_open(). Also, the environment variable may be used to override the hardware. Also, the ops functions may copy the exported functions to let implementation on the plugin itself. The exported API for tinycompress is simple and straight, so if I understand the problem correctly, the functionality should be only redirected for given card/device to another plugin/library if configured. Why use internals like ops->ioctl(), ops->poll() ? |
@perexg , we are planning to open libsndcardparser and will be hosted soon.
The problem with calling the plugin library ops directly from compress.c is that for all the ops we would need to check if it is a virtual node or a real hw node and call either the ioctl on hw device node or ops->ioctl to plugin library. This will lead to too many if/else statements in compress.c . Currently, we set the ops to either compress_hw_ops or compress_plugin_ops at compress_open() and then use it at all other places. This way, changes in compress.c is cleaner and all plugin related implementation is handled in compress_plugin.c . It will be more inline with tinyalsa plugins where plugin related common implementation is done in mixer_plugin.c (https://github.com/tinyalsa/tinyalsa/blob/master/src/mixer_plugin.c). Please let us know your opinion. |
28eadca
to
f348d71
Compare
Fixed License in all files. |
I'm sorry, but this scheme and libtinyalsa scheme looks like a big hack to create emulated cards / devices. My problem is the dependency on another library at the time. You're proposing: libtinycompress -> libsndcardparser -> some redirection I'm proposing: libtinycompress -> redirection via open -> plugin system based on your libsndcardparser (but it should not be part of tinycompress) I don't think that libtinyalsa nor libtinycompress should be dependent on third abstraction. Just create a straight way in open functions (compress_open) to redirect the functionality to somewhere else. And then implement your plugin system based on some special libsndcardparser code out-of-tree, if you like. My proposal allows other implementations (not only libsndcardparser one), too. The much cleaner solution is to implement the counterpart to pcm_open_by_name() for example (compress_open_by_name()) and handle virtual names like 'mp3decoder:0,0' where mp3decoder specifies the plugin and the extra arguments specifies the output PCM card and device numbers. In this case, you may try to dynamically load libtinycompress_mp3decoder.so which will implement this decoder.
The virtual devices may be identified by special device names. I just say, that for this case, you can just do (for all exported functions in tinycompress.h which touches som):
... and don't deal with kernel APIs like ioctl/poll etc. Keep this only in compress_hw.c . Use the upper level abstraction also for the plugin interface. |
Thanks @perexg for the suggestion. It does solve the problem and reduces a lot of code. But I think there are certain limitation with this approach like:
Another reference for configuration file is alsa-lib which parses alsa.conf and uses the information.
Sure. Actually, our intention was :
|
@perexg , I was evaluating your proposal and changes needed to handle all ops. Other issue which I see with new approach is that: |
I would add a new function is_codec_supported_by_name() for this case. The other way may be separate open with the params setup and capabilities check (open -> codec supported? -> configure -> I/O). But it will make the current API incompatible. It's much cleaner solution in my eyes. Perhaps, we can add compress_open_by_name() without 'struct compr_config' config argument and add new functions compress_set_params() and compress_is_codec_supported() and obsolete the card/device based functions. @vinodkoul : Do you think that we can change the current compress API? I would prefer to separate the parameter setup from open.
Yes, the 'struct compress' should be private to implementation. I don't see a problem to move it to compress_hw.c completely. |
@perexg yes we can add new APIs for that, I would not change the old API as we have users for these. I think we should have compress_open_by_name()
|
Add compress_ops.h needed to support plugins. Compress_ops can be used to jump to either hw compress node ops or to virtual compress node ops. Signed-off-by: Rohit kumar <rohitkr@codeaurora.org>
f348d71
to
3454482
Compare
Thanks @vinodkoul and @perexg for the suggestions. I have updated the PR accordingly. |
01f0e60
to
d89c51e
Compare
Moved parsing of compress_name to an API as it is used by compress_open_by_name() and compress_is_codec_supported_by_name() |
@perexg , Can you please check if updated PR has proper changes. |
The overall change looks good. Some little comment: I won't insist to pass card number and device numbers to plugins, they should just receive the abstract compress device name and do own parsing. For example, we may be prepared for compress devices like: net:192.168.1.10:9999. |
Add compress_hw.c to handle all operations associated with HW compress nodes. Move handling to compress_hw using compress_hw_ops. Signed-off-by: Rohit kumar <rohitkr@codeaurora.org>
d89c51e
to
64e7e9f
Compare
Thanks @perexg for the suggestion. Updated PR accordingly. Please review. |
@charleskeepax I think you folks also have some stuff on top of this lib, can you guys test and confirm this is okay |
64e7e9f
to
2dbaf37
Compare
Addressed comments. Please review. |
@vinodkoul / @perexg / @charleskeepax , can you please check if there is any concern with latest patchset. |
@perexg any comments? |
Add compress_open_by_name() and is_codec_supported_by_name() to support plugins. Format of name is 'hw:<card>,<device>' for hw compress nodes and '<plugin_name>:<custom_data>' for virtual compress nodes. It dynamically loads the plugin library whose name is libtinycompress_module_<plugin_name>.so. Plugin library needs to expose compress_plugin_ops. Default path of plugin lib is /usr/lib/tinycompress-lib/ and it can be updated by defining TINYCOMPRESS_PLUGIN_DIR in makefile. Signed-off-by: Rohit kumar <rohitkr@codeaurora.org>
2dbaf37
to
cffaaf9
Compare
These are initial set of patches to add the plugins support to tinycompress.
This pull request corresponds to #5