X-Git-Url: https://code.delx.au/pulseaudio/blobdiff_plain/d7ce59de88eda4eb638f977975374359254731f7..f8e0b8659216209fe75bb9f1f49da7682320ae42:/src/modules/module-solaris.c diff --git a/src/modules/module-solaris.c b/src/modules/module-solaris.c index ee06b3be..b4fa7348 100644 --- a/src/modules/module-solaris.c +++ b/src/modules/module-solaris.c @@ -28,12 +28,9 @@ #include #include #include -#include #include #include -#include #include -#include #include #include @@ -41,14 +38,12 @@ #include #include -#include #include #include #include #include #include -#include #include #include #include @@ -80,7 +75,7 @@ PA_MODULE_USAGE( "rate= " "buffer_length= " "channel_map="); -PA_MODULE_LOAD_ONCE(FALSE); +PA_MODULE_LOAD_ONCE(false); struct userdata { pa_core *core; @@ -105,7 +100,7 @@ struct userdata { pa_rtpoll_item *rtpoll_item; pa_module *module; - pa_bool_t sink_suspended, source_suspended; + bool sink_suspended, source_suspended; uint32_t play_samples_msw, record_samples_msw; uint32_t prev_playback_samples, prev_record_samples; @@ -168,7 +163,10 @@ static uint64_t get_playback_buffered_bytes(struct userdata *u) { pa_smoother_put(u->smoother, pa_rtclock_now(), pa_bytes_to_usec(played_bytes, &u->sink->sample_spec)); - return u->written_bytes - played_bytes; + if (u->written_bytes > played_bytes) + return u->written_bytes - played_bytes; + else + return 0; } static pa_usec_t sink_get_latency(struct userdata *u, pa_sample_spec *ss) { @@ -353,7 +351,7 @@ static int suspend(struct userdata *u) { pa_log_info("Suspending..."); - ioctl(u->fd, AUDIO_DRAIN, NULL); + ioctl(u->fd, I_FLUSH, FLUSHRW); pa_close(u->fd); u->fd = -1; @@ -406,14 +404,14 @@ static int sink_process_msg(pa_msgobject *o, int code, void *data, int64_t offse if (suspend(u) < 0) return -1; } - u->sink_suspended = TRUE; + u->sink_suspended = true; break; case PA_SINK_IDLE: case PA_SINK_RUNNING: if (u->sink->thread_info.state == PA_SINK_SUSPENDED) { - pa_smoother_resume(u->smoother, pa_rtclock_now(), TRUE); + pa_smoother_resume(u->smoother, pa_rtclock_now(), true); if (!u->source || u->source_suspended) { if (unsuspend(u) < 0) @@ -421,7 +419,7 @@ static int sink_process_msg(pa_msgobject *o, int code, void *data, int64_t offse u->sink->get_volume(u->sink); u->sink->get_mute(u->sink); } - u->sink_suspended = FALSE; + u->sink_suspended = false; } break; @@ -458,7 +456,7 @@ static int source_process_msg(pa_msgobject *o, int code, void *data, int64_t off if (suspend(u) < 0) return -1; } - u->source_suspended = TRUE; + u->source_suspended = true; break; case PA_SOURCE_IDLE: @@ -470,7 +468,7 @@ static int source_process_msg(pa_msgobject *o, int code, void *data, int64_t off return -1; u->source->get_volume(u->source); } - u->source_suspended = FALSE; + u->source_suspended = false; } break; @@ -531,7 +529,7 @@ static void source_set_volume(pa_source *s) { if (u->fd >= 0) { AUDIO_INITINFO(&info); - info.play.gain = pa_cvolume_max(&s->volume) * AUDIO_MAX_GAIN / PA_VOLUME_NORM; + info.play.gain = pa_cvolume_max(&s->real_volume) * AUDIO_MAX_GAIN / PA_VOLUME_NORM; assert(info.play.gain <= AUDIO_MAX_GAIN); if (ioctl(u->fd, AUDIO_SETINFO, &info) < 0) { @@ -553,7 +551,7 @@ static void source_get_volume(pa_source *s) { if (ioctl(u->fd, AUDIO_GETINFO, &info) < 0) pa_log("AUDIO_SETINFO: %s", pa_cstrerror(errno)); else - pa_cvolume_set(&s->volume, s->sample_spec.channels, info.play.gain * PA_VOLUME_NORM / AUDIO_MAX_GAIN); + pa_cvolume_set(&s->real_volume, s->sample_spec.channels, info.play.gain * PA_VOLUME_NORM / AUDIO_MAX_GAIN); } } @@ -592,9 +590,12 @@ static void process_rewind(struct userdata *u) { pa_assert(u); - /* Figure out how much we shall rewind and reset the counter */ + if (!PA_SINK_IS_OPENED(u->sink->thread_info.state)) { + pa_sink_process_rewind(u->sink, 0); + return; + } + rewind_nbytes = u->sink->thread_info.rewind_nbytes; - u->sink->thread_info.rewind_nbytes = 0; if (rewind_nbytes > 0) { pa_log_debug("Requested to rewind %lu bytes.", (unsigned long) rewind_nbytes); @@ -630,13 +631,13 @@ static void thread_func(void *userdata) { for (;;) { /* Render some data and write it to the dsp */ + if (PA_UNLIKELY(u->sink->thread_info.rewind_requested)) + process_rewind(u); + if (u->sink && PA_SINK_IS_OPENED(u->sink->thread_info.state)) { pa_usec_t xtime0, ysleep_interval, xsleep_interval; uint64_t buffered_bytes; - if (u->sink->thread_info.rewind_requested) - process_rewind(u); - err = ioctl(u->fd, AUDIO_GETINFO, &info); if (err < 0) { pa_log("AUDIO_GETINFO ioctl failed: %s", pa_cstrerror(errno)); @@ -651,7 +652,7 @@ static void thread_func(void *userdata) { if (ioctl(u->fd, AUDIO_SETINFO, &info) < 0) pa_log("AUDIO_SETINFO: %s", pa_cstrerror(errno)); - pa_smoother_reset(u->smoother, pa_rtclock_now(), TRUE); + pa_smoother_reset(u->smoother, pa_rtclock_now(), true); } for (;;) { @@ -777,7 +778,7 @@ static void thread_func(void *userdata) { } /* Hmm, nothing to do. Let's sleep */ - if ((ret = pa_rtpoll_run(u->rtpoll, TRUE)) < 0) + if ((ret = pa_rtpoll_run(u->rtpoll, true)) < 0) goto fail; if (ret == 0) @@ -816,17 +817,17 @@ static void sig_callback(pa_mainloop_api *api, pa_signal_event*e, int sig, void pa_log_debug("caught signal"); if (u->sink) { - pa_sink_get_volume(u->sink, TRUE); - pa_sink_get_mute(u->sink, TRUE); + pa_sink_get_volume(u->sink, true); + pa_sink_get_mute(u->sink, true); } if (u->source) - pa_source_get_volume(u->source, TRUE); + pa_source_get_volume(u->source, true); } int pa__init(pa_module *m) { struct userdata *u = NULL; - pa_bool_t record = TRUE, playback = TRUE; + bool record = true, playback = true; pa_sample_spec ss; pa_channel_map map; pa_modargs *ma = NULL; @@ -836,7 +837,7 @@ int pa__init(pa_module *m) { pa_source_new_data source_new_data; char const *name; char *name_buf; - pa_bool_t namereg_fail; + bool namereg_fail; pa_assert(m); @@ -857,7 +858,7 @@ int pa__init(pa_module *m) { u = pa_xnew0(struct userdata, 1); - if (!(u->smoother = pa_smoother_new(PA_USEC_PER_SEC, PA_USEC_PER_SEC * 2, TRUE, TRUE, 10, pa_rtclock_now(), TRUE))) + if (!(u->smoother = pa_smoother_new(PA_USEC_PER_SEC, PA_USEC_PER_SEC * 2, true, true, 10, pa_rtclock_now(), true))) goto fail; /* @@ -912,11 +913,11 @@ int pa__init(pa_module *m) { if (u->mode != O_WRONLY) { name_buf = NULL; - namereg_fail = TRUE; + namereg_fail = true; if (!(name = pa_modargs_get_value(ma, "source_name", NULL))) { name = name_buf = pa_sprintf_malloc("solaris_input.%s", pa_path_get_filename(u->device_name)); - namereg_fail = FALSE; + namereg_fail = false; } pa_source_new_data_init(&source_new_data); @@ -938,7 +939,7 @@ int pa__init(pa_module *m) { goto fail; } - u->source = pa_source_new(m->core, &source_new_data, PA_SOURCE_HARDWARE|PA_SOURCE_LATENCY|PA_SOURCE_HW_VOLUME_CTRL); + u->source = pa_source_new(m->core, &source_new_data, PA_SOURCE_HARDWARE|PA_SOURCE_LATENCY); pa_source_new_data_done(&source_new_data); pa_xfree(name_buf); @@ -954,18 +955,18 @@ int pa__init(pa_module *m) { pa_source_set_rtpoll(u->source, u->rtpoll); pa_source_set_fixed_latency(u->source, pa_bytes_to_usec(u->buffer_size, &u->source->sample_spec)); - u->source->get_volume = source_get_volume; - u->source->set_volume = source_set_volume; - u->source->refresh_volume = TRUE; + pa_source_set_get_volume_callback(u->source, source_get_volume); + pa_source_set_set_volume_callback(u->source, source_set_volume); + u->source->refresh_volume = true; } else u->source = NULL; if (u->mode != O_RDONLY) { name_buf = NULL; - namereg_fail = TRUE; + namereg_fail = true; if (!(name = pa_modargs_get_value(ma, "sink_name", NULL))) { name = name_buf = pa_sprintf_malloc("solaris_output.%s", pa_path_get_filename(u->device_name)); - namereg_fail = FALSE; + namereg_fail = false; } pa_sink_new_data_init(&sink_new_data); @@ -986,7 +987,7 @@ int pa__init(pa_module *m) { goto fail; } - u->sink = pa_sink_new(m->core, &sink_new_data, PA_SINK_HARDWARE|PA_SINK_LATENCY|PA_SINK_HW_VOLUME_CTRL|PA_SINK_HW_MUTE_CTRL); + u->sink = pa_sink_new(m->core, &sink_new_data, PA_SINK_HARDWARE|PA_SINK_LATENCY); pa_sink_new_data_done(&sink_new_data); pa_assert(u->sink); @@ -999,11 +1000,11 @@ int pa__init(pa_module *m) { pa_sink_set_max_request(u->sink, u->buffer_size); pa_sink_set_max_rewind(u->sink, u->buffer_size); - u->sink->get_volume = sink_get_volume; - u->sink->set_volume = sink_set_volume; - u->sink->get_mute = sink_get_mute; - u->sink->set_mute = sink_set_mute; - u->sink->refresh_volume = u->sink->refresh_muted = TRUE; + pa_sink_set_get_volume_callback(u->sink, sink_get_volume); + pa_sink_set_set_volume_callback(u->sink, sink_set_volume); + pa_sink_set_get_mute_callback(u->sink, sink_get_mute); + pa_sink_set_set_mute_callback(u->sink, sink_set_mute); + u->sink->refresh_volume = u->sink->refresh_muted = true; } else u->sink = NULL;