mirror of
https://gitlab.freedesktop.org/pulseaudio/pulseaudio.git
synced 2025-11-05 13:29:57 -05:00
stream-util: Add pa_stream_get_volume_channel_map()
The new function isn't used yet, but it soon will.
This commit is contained in:
parent
a3a795ef3d
commit
6cdb569b83
3 changed files with 137 additions and 0 deletions
|
|
@ -895,6 +895,7 @@ libpulsecore_@PA_MAJORMINOR@_la_SOURCES = \
|
||||||
pulsecore/remap_mmx.c pulsecore/remap_sse.c \
|
pulsecore/remap_mmx.c pulsecore/remap_sse.c \
|
||||||
pulsecore/resampler.c pulsecore/resampler.h \
|
pulsecore/resampler.c pulsecore/resampler.h \
|
||||||
pulsecore/rtpoll.c pulsecore/rtpoll.h \
|
pulsecore/rtpoll.c pulsecore/rtpoll.h \
|
||||||
|
pulsecore/stream-util.c pulsecore/stream-util.h \
|
||||||
pulsecore/mix.c pulsecore/mix.h \
|
pulsecore/mix.c pulsecore/mix.h \
|
||||||
pulsecore/cpu.h \
|
pulsecore/cpu.h \
|
||||||
pulsecore/cpu-arm.c pulsecore/cpu-arm.h \
|
pulsecore/cpu-arm.c pulsecore/cpu-arm.h \
|
||||||
|
|
|
||||||
86
src/pulsecore/stream-util.c
Normal file
86
src/pulsecore/stream-util.c
Normal file
|
|
@ -0,0 +1,86 @@
|
||||||
|
/***
|
||||||
|
This file is part of PulseAudio.
|
||||||
|
|
||||||
|
Copyright 2013 Intel Corporation
|
||||||
|
|
||||||
|
PulseAudio 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.
|
||||||
|
|
||||||
|
PulseAudio 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
|
||||||
|
General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
|
along with PulseAudio; if not, write to the Free Software
|
||||||
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||||
|
USA.
|
||||||
|
***/
|
||||||
|
|
||||||
|
#ifdef HAVE_CONFIG_H
|
||||||
|
#include <config.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "stream-util.h"
|
||||||
|
|
||||||
|
#include <pulse/def.h>
|
||||||
|
|
||||||
|
#include <pulsecore/core-format.h>
|
||||||
|
#include <pulsecore/macro.h>
|
||||||
|
|
||||||
|
int pa_stream_get_volume_channel_map(const pa_cvolume *volume, const pa_channel_map *original_map, const pa_format_info *format,
|
||||||
|
pa_channel_map *volume_map) {
|
||||||
|
int r;
|
||||||
|
pa_channel_map volume_map_local;
|
||||||
|
|
||||||
|
pa_assert(volume);
|
||||||
|
pa_assert(format);
|
||||||
|
pa_assert(volume_map);
|
||||||
|
|
||||||
|
if (original_map) {
|
||||||
|
if (volume->channels == original_map->channels) {
|
||||||
|
*volume_map = *original_map;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (volume->channels == 1) {
|
||||||
|
pa_channel_map_init_mono(volume_map);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
pa_log_info("Invalid stream parameters: the volume is incompatible with the channel map.");
|
||||||
|
return -PA_ERR_INVALID;
|
||||||
|
}
|
||||||
|
|
||||||
|
r = pa_format_info_get_channel_map(format, &volume_map_local);
|
||||||
|
if (r == -PA_ERR_NOENTITY) {
|
||||||
|
if (volume->channels == 1) {
|
||||||
|
pa_channel_map_init_mono(volume_map);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
pa_log_info("Invalid stream parameters: multi-channel volume is set, but channel map is not.");
|
||||||
|
return -PA_ERR_INVALID;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (r < 0) {
|
||||||
|
pa_log_info("Invalid channel map.");
|
||||||
|
return -PA_ERR_INVALID;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (volume->channels == volume_map_local.channels) {
|
||||||
|
*volume_map = volume_map_local;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (volume->channels == 1) {
|
||||||
|
pa_channel_map_init_mono(volume_map);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
pa_log_info("Invalid stream parameters: the volume is incompatible with the channel map.");
|
||||||
|
|
||||||
|
return -PA_ERR_INVALID;
|
||||||
|
}
|
||||||
50
src/pulsecore/stream-util.h
Normal file
50
src/pulsecore/stream-util.h
Normal file
|
|
@ -0,0 +1,50 @@
|
||||||
|
#ifndef foostreamutilhfoo
|
||||||
|
#define foostreamutilhfoo
|
||||||
|
|
||||||
|
/***
|
||||||
|
This file is part of PulseAudio.
|
||||||
|
|
||||||
|
Copyright 2013 Intel Corporation
|
||||||
|
|
||||||
|
PulseAudio 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.
|
||||||
|
|
||||||
|
PulseAudio 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
|
||||||
|
General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
|
along with PulseAudio; if not, write to the Free Software
|
||||||
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||||
|
USA.
|
||||||
|
***/
|
||||||
|
|
||||||
|
#include <pulse/format.h>
|
||||||
|
#include <pulse/volume.h>
|
||||||
|
|
||||||
|
/* This is a helper function that is called from pa_sink_input_new() and
|
||||||
|
* pa_source_output_new(). The job of this function is to figure out what
|
||||||
|
* channel map should be used for interpreting the volume that was set for the
|
||||||
|
* stream. The channel map that the client intended for the volume may be
|
||||||
|
* different than the final stream channel map, because the client may want the
|
||||||
|
* server to decide the stream channel map.
|
||||||
|
*
|
||||||
|
* volume is the volume for which the channel map should be figured out.
|
||||||
|
*
|
||||||
|
* original_map is the channel map that is set in the new data struct's
|
||||||
|
* channel_map field. If the channel map hasn't been set in the new data, then
|
||||||
|
* original_map should be NULL.
|
||||||
|
*
|
||||||
|
* format is the negotiated format for the stream. It's used as a fallback if
|
||||||
|
* original_map is not available.
|
||||||
|
*
|
||||||
|
* On success, the result is saved in volume_map. It's possible that this
|
||||||
|
* function fails to figure out the right channel map for the volume, in which
|
||||||
|
* case a negative error code is returned. */
|
||||||
|
int pa_stream_get_volume_channel_map(const pa_cvolume *volume, const pa_channel_map *original_map, const pa_format_info *format,
|
||||||
|
pa_channel_map *volume_map);
|
||||||
|
|
||||||
|
#endif
|
||||||
Loading…
Add table
Add a link
Reference in a new issue