-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
Draft
OrionMoonclaw
wants to merge
1
commit into
mpv-player:master
Choose a base branch
from
OrionMoonclaw:ao_libmpv
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,107 @@ | ||
| /* | ||
| * libmpv audio output driver | ||
| * | ||
| * This file is part of mpv. | ||
| * | ||
| * mpv is free software; you can redistribute it and/or | ||
| * modify it under the terms of the GNU Lesser General Public | ||
| * License as published by the Free Software Foundation; either | ||
| * version 2.1 of the License, or (at your option) any later version. | ||
| * | ||
| * mpv is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| * GNU Lesser General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU Lesser General Public | ||
| * License along with mpv. If not, see <http://www.gnu.org/licenses/>. | ||
| */ | ||
|
|
||
| #include "ao.h" | ||
| #include "audio/format.h" | ||
| #include "ao_libmpv.h" | ||
| #include "internal.h" | ||
| #include "common/msg.h" | ||
|
|
||
| struct priv { | ||
| void (*write_cb)(void *userdata, const void *data, int bytes); | ||
| void *userdata; | ||
| }; | ||
|
|
||
| void ao_libmpv_set_cb(struct ao *ao, void (*cb)(void *userdata, const void *data, int bytes), void *userdata) | ||
| { | ||
| struct priv *p = ao->priv; | ||
| p->write_cb = cb; | ||
| p->userdata = userdata; | ||
| } | ||
|
|
||
| static int init(struct ao *ao) | ||
| { | ||
| ao->format = af_fmt_from_planar(ao->format); | ||
|
|
||
| struct mp_chmap_sel sel = {0}; | ||
| mp_chmap_sel_add_waveext(&sel); | ||
| if (!ao_chmap_sel_adjust(ao, &sel, &ao->channels)) | ||
| return -1; | ||
|
|
||
| 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)); | ||
|
|
||
| ao->untimed = true; | ||
| ao->device_buffer = 1 << 16; | ||
|
|
||
| return 0; | ||
| } | ||
|
|
||
| static void uninit(struct ao *ao) | ||
| { | ||
| } | ||
|
|
||
| static bool audio_write(struct ao *ao, void **data, int samples) | ||
| { | ||
| struct priv *priv = ao->priv; | ||
| const int len = samples * ao->sstride; | ||
|
|
||
| if (priv->write_cb) | ||
| priv->write_cb(priv->userdata, data[0], len); | ||
|
|
||
| return true; | ||
| } | ||
|
|
||
| static void get_state(struct ao *ao, struct mp_pcm_state *state) | ||
| { | ||
| state->free_samples = ao->device_buffer; | ||
| state->queued_samples = 0; | ||
| state->delay = 0; | ||
| } | ||
|
|
||
| static bool set_pause(struct ao *ao, bool paused) | ||
| { | ||
| return true; // signal support so common code doesn't write silence | ||
| } | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. so the client is not informed of a pause situation? |
||
|
|
||
| static void start(struct ao *ao) | ||
| { | ||
| // we use data immediately | ||
| } | ||
|
|
||
| static void reset(struct ao *ao) | ||
| { | ||
| } | ||
|
|
||
| #define OPT_BASE_STRUCT struct priv | ||
|
|
||
| const struct ao_driver audio_out_libmpv = { | ||
| .description = "libmpv audio output with a callback", | ||
| .name = "libmpv", | ||
| .init = init, | ||
| .uninit = uninit, | ||
| .get_state = get_state, | ||
| .set_pause = set_pause, | ||
| .write = audio_write, | ||
| .start = start, | ||
| .reset = reset, | ||
| .priv_size = sizeof(struct priv), | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| /* | ||
| * libmpv audio output driver | ||
| * | ||
| * This file is part of mpv. | ||
| * | ||
| * mpv is free software; you can redistribute it and/or | ||
| * modify it under the terms of the GNU Lesser General Public | ||
| * License as published by the Free Software Foundation; either | ||
| * version 2.1 of the License, or (at your option) any later version. | ||
| * | ||
| * mpv is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| * GNU Lesser General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU Lesser General Public | ||
| * License along with mpv. If not, see <http://www.gnu.org/licenses/>. | ||
| */ | ||
|
|
||
| #pragma once | ||
|
|
||
| #include "ao.h" | ||
|
|
||
| void ao_libmpv_set_cb(struct ao *ao, void (*cb)(void *userdata, const void *data, int bytes), void *userdata); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back 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.
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.
mpv/options/options.c
Line 669 in 77dee9b
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.