-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
audio-cb: add audio callback driver #5566
Conversation
I don't like how this makes the audio callback a global thing. It should be connected to a mpv_handle at least, plus ideally a way that identifies the audio source (in case if mpv ever becomes able to use multiple AOs, e.g. one for each audio track). I'm also not sure whether restriction it to s16/stereo is OK, and the sample rate will still be unknown (or subject to race conditions) to the API user. |
Also, as a bikeshed comment: maybe the "-cb" should be eliminated from the name. The opengl-cb API is already being deprecated and essentially renamed (as part of the change) in my render API PR. |
Thanks for your comments. The restriction to S16 stereo isn't great, but it was my minimum requirement. I can make it so that the frontend application can call a function to restrict supported output formats, should the frontend not support all the formats supported by mpv. I will only be able to test S16 Stereo however, as the frontend I'm supporting only supports that format. I'll have a look at mpv_handle and audio source identification. The "-cb" was there because I began writing this last year. This is a simple change. What do you suggest I rename it to? Is renaming the audio callback driver to "libmpv" okay? |
Currently there's only at most 1 AO per mpv core. The same is true for VOs. But if more than 1 VO is supported in the future, the new render API can in theory easily support it by adding a new mpv_render_param that references with VO with a name or so. This is purely an API thing and internally there's nothing for it.
Should be fine. The new render API also uses
That's a possibility, but doesn't work for all audio params currently, because the memory size/organization depends on channel layout and sample format. It'd also just be possible that the client simply forces a specific format via the global mpv options, but that's also rather restrictive. I'm also a bit nervous that the API ignores playback states (like pausing etc). |
I will most likely have a need for this API in the future, and may be able to provide API design comments based on my requirements at that time. |
Thanks, that'll be helpful. |
I would also need audio callback functionality soon! |
Some feedback:
|
Thanks for the feedback. Due to my work commitments, I won't be able to continue working on this until June. |
A basic audio callback driver for libmpv. Returns samples in S16 stereo format to a buffer provided when calling mpv_audio_callback(). Tested working with libretro-mpv. Signed-off-by: Mahyar Koshkouei <mahyar.koshkouei@gmail.com>
By using the "af" option string command, the audio callback driver may be configured to output audio in a specific format. For example, prior to calling mpv_audio_callback(), the following command is called to set the audio filled in the buffer to a specific format: mpv_set_option_string(mpv, "af", "format=s16:48000:stereo"); Signed-off-by: Mahyar Koshkouei <mahyar.koshkouei@gmail.com>
Signed-off-by: Mahyar Koshkouei <mahyar.koshkouei@gmail.com>
Signed-off-by: Mahyar Koshkouei <mahyar.koshkouei@gmail.com>
Hi all. Apologies for the delay. This is still a work in progress. So far, I have the audio driver tied to an mpv_handle so more than one instance should be able to use it (but I have not tested this yet). The audio driver currently fills the buffer with whatever the audio format the input audio stream is (as long as it isn't planar *). Currently, to specify a specific format of audio, the user application must call a command similar to Instead of having to use such a command to force a specific format of audio, I plan on adding options to the libmpv audio driver to allow the user application to specify which audio formats, sample rates and channels they support, similarly to the ao_null and ao_sdl driver (the latter which seems to force s16 if the input audio stream is not compatible). This means that libmpv will not need to unnecessarily convert an input audio stream if the user application supports it. * I did have an issue whereby a media file with an AF_FORMAT_FLOATP audio stream was causing a arithmetic exception: |
Signed-off-by: Mahyar Koshkouei <mahyar.koshkouei@gmail.com>
Signed-off-by: Mahyar Koshkouei <mahyar.koshkouei@gmail.com>
Signed-off-by: Mahyar Koshkouei <mahyar.koshkouei@gmail.com>
I think I have completed the feature now. The libmpv audio driver now has channel layout, sample rate and audio format options that may be specified to obtain the audio frames in the format requested. Planar formats cause an arithmetic exception, and are therefore disabled. And whilst multiple channel layouts may be specified, only one sampling rate and and one audio format may be specified. I have not tested multi-thread support, but as the driver is now associated with an mpv_handle, this should work. Nor have I tested the changing of the output layout, sampling rate and format options mid-stream. I have tested this branch with mpv-libretro which sets the output audio to s16, stereo only, and at 48000Hz. Please let me know if I have missed anything. Thanks. |
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't comment too much on the audio stuff itself
@@ -92,6 +93,7 @@ static const struct ao_driver * const audio_out_drivers[] = { | |||
#if HAVE_COREAUDIO | |||
&audio_out_coreaudio_exclusive, | |||
#endif | |||
&audio_out_libmpv, |
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.
Shouldn't this have the highest priority? (cf. video_out_libmpv)
.resume = resume, | ||
.priv_size = sizeof(struct priv), | ||
.priv_defaults = &(const struct priv) { | ||
.init = false, |
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.
This is implicit
if (af_fmt_is_planar(priv->format)) | ||
MP_ERR(ao, "planar format not supported\n"); | ||
|
||
if (priv->format) |
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.
Style: Always use { } for if/else statements
if (priv->init == false) | ||
{ | ||
MP_ERR(ao, "libmpv audio output not initialized\n"); | ||
return -4; |
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.
What is this magic number?
* @param len Length of the buffer. | ||
* @return Number of samples in the buffer, or negative on error. | ||
*/ | ||
int mpv_audio_callback(mpv_handle *ctx, void *buffer, int len); |
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.
How do I know when to call this?
Oh, also, you need to document the |
@deltabeard @haasn Any reasons which preventing to merge this? |
My not having fixed the issues that @haasn raised is blocking this merge. I didn't have much spare time and I eventually lost interest in the application that was going to use this feature, so I haven't worked on this in a very long time. Somebody else whose interested in this feature may work on it, otherwise it may as well be rejected. Sorry. |
@deltabeard If you don't mind sharing, what led you to lose interest? It seems this being fixed is a blocker for fixing |
Hi @orbea. I lost interest for the following reasons in no particular order:
Here's another issue which tracked libretro-mpv progress if anyone is interested: libretro/RetroArch#5070 This was a quick mind dump, so apologies in advance for mistakes. There may have been other issues. I don't really remember since it's been a long time now. Kind Regards. |
Thanks a lot of the background, unfortunately I can't do much to help with these concerns. I think currently the mpv-libretro core is supposed to work on windows to some degree and another possible alternative to fixing this is to just use libretro for audio. I'm not sure what the best route would be though. |
if (priv->format) | ||
ao->format = priv->format; | ||
else { | ||
/* Required as planar audio causes arithmetic exceptions in pull API. */ |
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.
Uh what.
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.
Is any still interested in this? The current approach is a bit too singleton-ish/hardcoded for my tastes.
No, I lost interest a while back. I explained why in my earlier post on 14 Feb. |
A basic audio callback driver for libmpv. Returns samples in S16 stereo
format to a buffer provided when calling mpv_audio_callback().
Tested working with libretro-mpv.
I agree that my changes can be relicensed to LGPL 2.1 or later.
Signed-off-by: Mahyar Koshkouei mahyar.koshkouei@gmail.com