-
Notifications
You must be signed in to change notification settings - Fork 3.1k
audio/out: add libmpv callback driver #16769
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
base: master
Are you sure you want to change the base?
Conversation
f5adaf1
to
04c5398
Compare
static bool set_pause(struct ao *ao, bool paused) | ||
{ | ||
return true; // signal support so common code doesn't write silence | ||
} |
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 the client is not informed of a pause situation?
ao->bps = ao->channels.num * (int64_t)ao->samplerate * af_fmt_to_bytes(ao->format); | ||
|
||
MP_INFO(ao, "libmpv: Samplerate: %d Hz Channels: %d Format: %s\n", | ||
ao->samplerate, ao->channels.num, af_fmt_to_str(ao->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.
how does the client find out which format the blob of data he gets is, anyway?
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.
the audio current audio format can be grabbed as a property, though I suppose I could just pass that in the callback as well
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.
That's also async, so won't work reliably.
I think it would be more practical if sample rate and channels were set ahead of time and then the driver would only support s16
.
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.
Correct me if I'm wrong, but it's already possible to set the format with this option before mpv initializes, so I think that should cover it. I might just add a note about it in the docs.
Line 669 in 77dee9b
{"audio-format", OPT_AUDIOFORMAT(audio_output_format), .flags = UPDATE_AUDIO}, |
If that's not enough I could also add an option specific to this ao, I'd prefer to keep it configurable since I personally would like the samples as floats, it saves me an extra conversion step.
include/mpv/client.h
Outdated
|
||
/** | ||
* Set a custom function that should be called on new audio data. Raw PCM is passed in as an argument to the callback. | ||
* This can only be used with ao set to libmpv and after the audio driver has been initialized. |
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.
won't this mean that the client will potentially miss the first samples because he has to race against "ao init" until the callback can be set?
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.
I think registering the callback on MPV_EVENT_AUDIO_RECONFIG should be good enough, but I'll have a look at this later
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.
Not really, because events are delivered async.
Download the artifacts for this pull request: Windows |
IMO the libmpv AO initialization should block indefinitely until the client receives If the audio format can be customized, then the callback function should tell the client which format is in use, to avoid possible race conditions in accessing properties. |
9da99e5
to
11c19d4
Compare
I marked it as a draft, since it's gonna need a bit more discussion. Right now I made it so the callback can be set before ao init by storing it under MPContext, it feels a bit ugly, but it should work. |
This adds an ao driver that can be used to register a callback with libmpv to get raw PCM data. Useful for embedding mpv in applications such as game engines, which need the audio to be played in a 3D world and spatialized. Signed-off-by: Orion Moonclaw <[email protected]>
11c19d4
to
d9e3432
Compare
This adds an ao driver that can be used to register a callback with libmpv to get raw PCM data. Useful for embedding mpv in applications such as game engines, which need the audio to be played in a 3D world and spatialized.
This was tested with libmpvbridge (not public yet), which I'm developing to use mpv in Renderite.Godot.
closes #9283