mirror of
https://gitlab.freedesktop.org/pulseaudio/pulseaudio.git
synced 2025-11-10 13:29:58 -05:00
* modify pa_channel_map_init_auto() to take an extra argument specifying the standard to use (ALSA, AIFF, ...)
* add some more validity checks to pa_source_new(),pa_sink_new(),pa_sink_input_new(),pa_source_output_new() git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@888 fefdeb5f-60dc-0310-8127-8f9354f1896f
This commit is contained in:
parent
c63cc7bb79
commit
4b6ab291a7
27 changed files with 237 additions and 191 deletions
|
|
@ -141,7 +141,7 @@ int pa_scache_add_item(pa_core *c, const char *name, const pa_sample_spec *ss, c
|
|||
|
||||
if (ss) {
|
||||
e->sample_spec = *ss;
|
||||
pa_channel_map_init_auto(&e->channel_map, ss->channels);
|
||||
pa_channel_map_init_auto(&e->channel_map, ss->channels, PA_CHANNEL_MAP_DEFAULT);
|
||||
e->volume.channels = e->sample_spec.channels;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -280,7 +280,7 @@ int pa_modargs_get_channel_map(pa_modargs *ma, pa_channel_map *rmap) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
int pa_modargs_get_sample_spec_and_channel_map(pa_modargs *ma, pa_sample_spec *rss, pa_channel_map *rmap) {
|
||||
int pa_modargs_get_sample_spec_and_channel_map(pa_modargs *ma, pa_sample_spec *rss, pa_channel_map *rmap, pa_channel_map_def_t def) {
|
||||
pa_sample_spec ss;
|
||||
pa_channel_map map;
|
||||
|
||||
|
|
@ -293,7 +293,8 @@ int pa_modargs_get_sample_spec_and_channel_map(pa_modargs *ma, pa_sample_spec *r
|
|||
if (pa_modargs_get_sample_spec(ma, &ss) < 0)
|
||||
return -1;
|
||||
|
||||
pa_channel_map_init_auto(&map, ss.channels);
|
||||
if (!pa_channel_map_init_auto(&map, ss.channels, def))
|
||||
map.channels = 0;
|
||||
|
||||
if (pa_modargs_get_channel_map(ma, &map) < 0)
|
||||
return -1;
|
||||
|
|
|
|||
|
|
@ -55,6 +55,6 @@ pa_modargs_get_channel_map(). Not always suitable, since this routine
|
|||
initializes the map parameter based on the channels field of the ss
|
||||
structure if no channel_map is found, using pa_channel_map_init_auto() */
|
||||
|
||||
int pa_modargs_get_sample_spec_and_channel_map(pa_modargs *ma, pa_sample_spec *ss, pa_channel_map *map);
|
||||
int pa_modargs_get_sample_spec_and_channel_map(pa_modargs *ma, pa_sample_spec *ss, pa_channel_map *map, pa_channel_map_def_t def);
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -101,12 +101,12 @@ pa_resampler* pa_resampler_new(
|
|||
if (am)
|
||||
r->i_cm = *am;
|
||||
else
|
||||
pa_channel_map_init_auto(&r->i_cm, r->i_ss.channels);
|
||||
pa_channel_map_init_auto(&r->i_cm, r->i_ss.channels, PA_CHANNEL_MAP_DEFAULT);
|
||||
|
||||
if (bm)
|
||||
r->o_cm = *bm;
|
||||
else
|
||||
pa_channel_map_init_auto(&r->o_cm, r->o_ss.channels);
|
||||
pa_channel_map_init_auto(&r->o_cm, r->o_ss.channels, PA_CHANNEL_MAP_DEFAULT);
|
||||
|
||||
r->i_fz = pa_frame_size(a);
|
||||
r->o_fz = pa_frame_size(b);
|
||||
|
|
|
|||
|
|
@ -32,32 +32,53 @@
|
|||
#include <polypcore/xmalloc.h>
|
||||
#include <polypcore/core-subscribe.h>
|
||||
#include <polypcore/log.h>
|
||||
#include <polypcore/utf8.h>
|
||||
|
||||
#include "sink-input.h"
|
||||
|
||||
#define CONVERT_BUFFER_LENGTH 4096
|
||||
|
||||
#define CHECK_VALIDITY_RETURN_NULL(condition) \
|
||||
do {\
|
||||
if (!(condition)) \
|
||||
return NULL; \
|
||||
} while (0)
|
||||
|
||||
pa_sink_input* pa_sink_input_new(
|
||||
pa_sink *s,
|
||||
const char *driver,
|
||||
const char *name,
|
||||
const pa_sample_spec *spec,
|
||||
const pa_channel_map *map,
|
||||
const pa_cvolume *volume,
|
||||
int variable_rate,
|
||||
int resample_method) {
|
||||
pa_sink *s,
|
||||
const char *driver,
|
||||
const char *name,
|
||||
const pa_sample_spec *spec,
|
||||
const pa_channel_map *map,
|
||||
const pa_cvolume *volume,
|
||||
int variable_rate,
|
||||
int resample_method) {
|
||||
|
||||
pa_sink_input *i;
|
||||
pa_resampler *resampler = NULL;
|
||||
int r;
|
||||
char st[256];
|
||||
pa_channel_map tmap;
|
||||
pa_cvolume tvol;
|
||||
|
||||
assert(s);
|
||||
assert(spec);
|
||||
assert(s->state == PA_SINK_RUNNING);
|
||||
|
||||
CHECK_VALIDITY_RETURN_NULL(pa_sample_spec_valid(spec));
|
||||
|
||||
if (!map)
|
||||
map = pa_channel_map_init_auto(&tmap, spec->channels, PA_CHANNEL_MAP_DEFAULT);
|
||||
if (!volume)
|
||||
volume = pa_cvolume_reset(&tvol, spec->channels);
|
||||
|
||||
CHECK_VALIDITY_RETURN_NULL(map && pa_channel_map_valid(map));
|
||||
CHECK_VALIDITY_RETURN_NULL(volume && pa_cvolume_valid(volume));
|
||||
CHECK_VALIDITY_RETURN_NULL(map->channels == spec->channels);
|
||||
CHECK_VALIDITY_RETURN_NULL(volume->channels == spec->channels);
|
||||
CHECK_VALIDITY_RETURN_NULL(!driver || pa_utf8_valid(driver));
|
||||
CHECK_VALIDITY_RETURN_NULL(pa_utf8_valid(name));
|
||||
|
||||
if (pa_idxset_size(s->inputs) >= PA_MAX_INPUTS_PER_SINK) {
|
||||
pa_log_warn(__FILE__": Failed to create sink input: too many inputs per sink.");
|
||||
return NULL;
|
||||
|
|
@ -66,19 +87,6 @@ pa_sink_input* pa_sink_input_new(
|
|||
if (resample_method == PA_RESAMPLER_INVALID)
|
||||
resample_method = s->core->resample_method;
|
||||
|
||||
if (map && spec->channels != map->channels)
|
||||
return NULL;
|
||||
|
||||
if (volume && spec->channels != volume->channels)
|
||||
return NULL;
|
||||
|
||||
if (!map) {
|
||||
if (!(pa_channel_map_init_auto(&tmap, spec->channels)))
|
||||
return NULL;
|
||||
|
||||
map = &tmap;
|
||||
}
|
||||
|
||||
if (variable_rate || !pa_sample_spec_equal(spec, &s->sample_spec) || !pa_channel_map_equal(map, &s->channel_map))
|
||||
if (!(resampler = pa_resampler_new(spec, map, &s->sample_spec, &s->channel_map, s->core->memblock_stat, resample_method)))
|
||||
return NULL;
|
||||
|
|
@ -94,12 +102,8 @@ pa_sink_input* pa_sink_input_new(
|
|||
|
||||
i->sample_spec = *spec;
|
||||
i->channel_map = *map;
|
||||
|
||||
if (volume)
|
||||
i->volume = *volume;
|
||||
else
|
||||
pa_cvolume_reset(&i->volume, spec->channels);
|
||||
|
||||
i->volume = *volume;
|
||||
|
||||
i->peek = NULL;
|
||||
i->drop = NULL;
|
||||
i->kill = NULL;
|
||||
|
|
|
|||
|
|
@ -29,6 +29,7 @@
|
|||
#include <stdio.h>
|
||||
|
||||
#include <polyp/introspect.h>
|
||||
|
||||
#include <polypcore/sink-input.h>
|
||||
#include <polypcore/namereg.h>
|
||||
#include <polypcore/util.h>
|
||||
|
|
@ -36,29 +37,46 @@
|
|||
#include <polypcore/xmalloc.h>
|
||||
#include <polypcore/core-subscribe.h>
|
||||
#include <polypcore/log.h>
|
||||
#include <polypcore/utf8.h>
|
||||
|
||||
#include "sink.h"
|
||||
|
||||
#define MAX_MIX_CHANNELS 32
|
||||
|
||||
#define CHECK_VALIDITY_RETURN_NULL(condition) \
|
||||
do {\
|
||||
if (!(condition)) \
|
||||
return NULL; \
|
||||
} while (0)
|
||||
|
||||
pa_sink* pa_sink_new(
|
||||
pa_core *core,
|
||||
const char *driver,
|
||||
const char *name,
|
||||
int fail,
|
||||
const pa_sample_spec *spec,
|
||||
const pa_channel_map *map) {
|
||||
pa_core *core,
|
||||
const char *driver,
|
||||
const char *name,
|
||||
int fail,
|
||||
const pa_sample_spec *spec,
|
||||
const pa_channel_map *map) {
|
||||
|
||||
pa_sink *s;
|
||||
char *n = NULL;
|
||||
char st[256];
|
||||
int r;
|
||||
pa_channel_map tmap;
|
||||
|
||||
assert(core);
|
||||
assert(name);
|
||||
assert(*name);
|
||||
assert(spec);
|
||||
|
||||
CHECK_VALIDITY_RETURN_NULL(pa_sample_spec_valid(spec));
|
||||
|
||||
if (!map)
|
||||
map = pa_channel_map_init_auto(&tmap, spec->channels, PA_CHANNEL_MAP_DEFAULT);
|
||||
|
||||
CHECK_VALIDITY_RETURN_NULL(map && pa_channel_map_valid(map));
|
||||
CHECK_VALIDITY_RETURN_NULL(map->channels == spec->channels);
|
||||
CHECK_VALIDITY_RETURN_NULL(!driver || pa_utf8_valid(driver));
|
||||
CHECK_VALIDITY_RETURN_NULL(pa_utf8_valid(name) && *name);
|
||||
|
||||
s = pa_xnew(pa_sink, 1);
|
||||
|
||||
if (!(name = pa_namereg_register(core, name, PA_NAMEREG_SINK, s, fail))) {
|
||||
|
|
@ -75,10 +93,7 @@ pa_sink* pa_sink_new(
|
|||
s->owner = NULL;
|
||||
|
||||
s->sample_spec = *spec;
|
||||
if (map)
|
||||
s->channel_map = *map;
|
||||
else
|
||||
pa_channel_map_init_auto(&s->channel_map, spec->channels);
|
||||
s->channel_map = *map;
|
||||
|
||||
s->inputs = pa_idxset_new(NULL, NULL);
|
||||
|
||||
|
|
|
|||
|
|
@ -75,7 +75,7 @@ int pa_sound_file_load(const char *fname, pa_sample_spec *ss, pa_channel_map *ma
|
|||
}
|
||||
|
||||
if (map)
|
||||
pa_channel_map_init_auto(map, ss->channels);
|
||||
pa_channel_map_init_auto(map, ss->channels, PA_CHANNEL_MAP_DEFAULT);
|
||||
|
||||
if ((l = pa_frame_size(ss)*sfinfo.frames) > PA_SCACHE_ENTRY_SIZE_MAX) {
|
||||
pa_log(__FILE__": File too large");
|
||||
|
|
|
|||
|
|
@ -31,16 +31,23 @@
|
|||
#include <polypcore/xmalloc.h>
|
||||
#include <polypcore/core-subscribe.h>
|
||||
#include <polypcore/log.h>
|
||||
#include <polypcore/utf8.h>
|
||||
|
||||
#include "source-output.h"
|
||||
|
||||
#define CHECK_VALIDITY_RETURN_NULL(condition) \
|
||||
do {\
|
||||
if (!(condition)) \
|
||||
return NULL; \
|
||||
} while (0)
|
||||
|
||||
pa_source_output* pa_source_output_new(
|
||||
pa_source *s,
|
||||
const char *driver,
|
||||
const char *name,
|
||||
const pa_sample_spec *spec,
|
||||
const pa_channel_map *map,
|
||||
int resample_method) {
|
||||
pa_source *s,
|
||||
const char *driver,
|
||||
const char *name,
|
||||
const pa_sample_spec *spec,
|
||||
const pa_channel_map *map,
|
||||
int resample_method) {
|
||||
|
||||
pa_source_output *o;
|
||||
pa_resampler *resampler = NULL;
|
||||
|
|
@ -51,7 +58,17 @@ pa_source_output* pa_source_output_new(
|
|||
assert(s);
|
||||
assert(spec);
|
||||
assert(s->state == PA_SOURCE_RUNNING);
|
||||
|
||||
CHECK_VALIDITY_RETURN_NULL(pa_sample_spec_valid(spec));
|
||||
|
||||
if (!map)
|
||||
map = pa_channel_map_init_auto(&tmap, spec->channels, PA_CHANNEL_MAP_DEFAULT);
|
||||
|
||||
CHECK_VALIDITY_RETURN_NULL(map && pa_channel_map_valid(map));
|
||||
CHECK_VALIDITY_RETURN_NULL(map->channels == spec->channels);
|
||||
CHECK_VALIDITY_RETURN_NULL(!driver || pa_utf8_valid(driver));
|
||||
CHECK_VALIDITY_RETURN_NULL(pa_utf8_valid(name));
|
||||
|
||||
if (pa_idxset_size(s->outputs) >= PA_MAX_OUTPUTS_PER_SOURCE) {
|
||||
pa_log(__FILE__": Failed to create source output: too many outputs per source.");
|
||||
return NULL;
|
||||
|
|
@ -60,16 +77,11 @@ pa_source_output* pa_source_output_new(
|
|||
if (resample_method == PA_RESAMPLER_INVALID)
|
||||
resample_method = s->core->resample_method;
|
||||
|
||||
if (!map) {
|
||||
pa_channel_map_init_auto(&tmap, spec->channels);
|
||||
map = &tmap;
|
||||
}
|
||||
|
||||
if (!pa_sample_spec_equal(&s->sample_spec, spec) || !pa_channel_map_equal(&s->channel_map, map))
|
||||
if (!(resampler = pa_resampler_new(&s->sample_spec, &s->channel_map, spec, map, s->core->memblock_stat, resample_method)))
|
||||
return NULL;
|
||||
|
||||
o = pa_xmalloc(sizeof(pa_source_output));
|
||||
o = pa_xnew(pa_source_output, 1);
|
||||
o->ref = 1;
|
||||
o->state = PA_SOURCE_OUTPUT_RUNNING;
|
||||
o->name = pa_xstrdup(name);
|
||||
|
|
@ -137,7 +149,6 @@ static void source_output_free(pa_source_output* o) {
|
|||
pa_xfree(o);
|
||||
}
|
||||
|
||||
|
||||
void pa_source_output_unref(pa_source_output* o) {
|
||||
assert(o);
|
||||
assert(o->ref >= 1);
|
||||
|
|
|
|||
|
|
@ -34,26 +34,43 @@
|
|||
#include <polypcore/core-subscribe.h>
|
||||
#include <polypcore/log.h>
|
||||
#include <polypcore/sample-util.h>
|
||||
#include <polypcore/utf8.h>
|
||||
|
||||
#include "source.h"
|
||||
|
||||
#define CHECK_VALIDITY_RETURN_NULL(condition) \
|
||||
do {\
|
||||
if (!(condition)) \
|
||||
return NULL; \
|
||||
} while (0)
|
||||
|
||||
pa_source* pa_source_new(
|
||||
pa_core *core,
|
||||
const char *driver,
|
||||
const char *name,
|
||||
int fail,
|
||||
const pa_sample_spec *spec,
|
||||
const pa_channel_map *map) {
|
||||
pa_core *core,
|
||||
const char *driver,
|
||||
const char *name,
|
||||
int fail,
|
||||
const pa_sample_spec *spec,
|
||||
const pa_channel_map *map) {
|
||||
|
||||
pa_source *s;
|
||||
char st[256];
|
||||
int r;
|
||||
pa_channel_map tmap;
|
||||
|
||||
assert(core);
|
||||
assert(name);
|
||||
assert(*name);
|
||||
assert(spec);
|
||||
|
||||
CHECK_VALIDITY_RETURN_NULL(pa_sample_spec_valid(spec));
|
||||
|
||||
if (!map)
|
||||
map = pa_channel_map_init_auto(&tmap, spec->channels, PA_CHANNEL_MAP_DEFAULT);
|
||||
|
||||
CHECK_VALIDITY_RETURN_NULL(map && pa_channel_map_valid(map));
|
||||
CHECK_VALIDITY_RETURN_NULL(map->channels == spec->channels);
|
||||
CHECK_VALIDITY_RETURN_NULL(!driver || pa_utf8_valid(driver));
|
||||
CHECK_VALIDITY_RETURN_NULL(pa_utf8_valid(name) && *name);
|
||||
|
||||
s = pa_xnew(pa_source, 1);
|
||||
|
||||
if (!(name = pa_namereg_register(core, name, PA_NAMEREG_SOURCE, s, fail))) {
|
||||
|
|
@ -70,10 +87,7 @@ pa_source* pa_source_new(
|
|||
s->owner = NULL;
|
||||
|
||||
s->sample_spec = *spec;
|
||||
if (map)
|
||||
s->channel_map = *map;
|
||||
else
|
||||
pa_channel_map_init_auto(&s->channel_map, spec->channels);
|
||||
s->channel_map = *map;
|
||||
|
||||
s->outputs = pa_idxset_new(NULL, NULL);
|
||||
s->monitor_of = NULL;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue