本文整理汇总了C++中pa_bytes_to_usec函数的典型用法代码示例。如果您正苦于以下问题:C++ pa_bytes_to_usec函数的具体用法?C++ pa_bytes_to_usec怎么用?C++ pa_bytes_to_usec使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了pa_bytes_to_usec函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: source_process_msg
static int source_process_msg(pa_msgobject *o, int code, void *data, int64_t offset, pa_memchunk *chunk) {
struct userdata *u = PA_SOURCE(o)->userdata;
int err;
audio_info_t info;
switch (code) {
case PA_SOURCE_MESSAGE_GET_LATENCY: {
pa_usec_t r = 0;
if (u->fd) {
err = ioctl(u->fd, AUDIO_GETINFO, &info);
pa_assert(err >= 0);
r += pa_bytes_to_usec(info.record.samples * u->frame_size, &PA_SOURCE(o)->sample_spec);
r -= pa_bytes_to_usec(u->read_bytes, &PA_SOURCE(o)->sample_spec);
}
*((pa_usec_t*) data) = r;
return 0;
}
case PA_SOURCE_MESSAGE_SET_VOLUME:
if (u->fd >= 0) {
AUDIO_INITINFO(&info);
info.record.gain = pa_cvolume_avg((pa_cvolume*) data) * AUDIO_MAX_GAIN / PA_VOLUME_NORM;
assert(info.record.gain <= AUDIO_MAX_GAIN);
if (ioctl(u->fd, AUDIO_SETINFO, &info) < 0) {
if (errno == EINVAL)
pa_log("AUDIO_SETINFO: Unsupported volume.");
else
pa_log("AUDIO_SETINFO: %s", pa_cstrerror(errno));
} else {
return 0;
}
}
break;
case PA_SOURCE_MESSAGE_GET_VOLUME:
if (u->fd >= 0) {
err = ioctl(u->fd, AUDIO_GETINFO, &info);
pa_assert(err >= 0);
pa_cvolume_set((pa_cvolume*) data, ((pa_cvolume*) data)->channels,
info.record.gain * PA_VOLUME_NORM / AUDIO_MAX_GAIN);
return 0;
}
break;
}
return pa_source_process_msg(o, code, data, offset, chunk);
}
示例2: get_delay
// Return the current latency in seconds
static float get_delay(struct ao *ao)
{
/* This code basically does what pa_stream_get_latency() _should_
* do, but doesn't due to multiple known bugs in PulseAudio (at
* PulseAudio version 2.1). In particular, the timing interpolation
* mode (PA_STREAM_INTERPOLATE_TIMING) can return completely bogus
* values, and the non-interpolating code has a bug causing too
* large results at end of stream (so a stream never seems to finish).
* This code can still return wrong values in some cases due to known
* PulseAudio bugs that can not be worked around on the client side.
*
* We always query the server for latest timing info. This may take
* too long to work well with remote audio servers, but at least
* this should be enough to fix the normal local playback case.
*/
struct priv *priv = ao->priv;
pa_threaded_mainloop_lock(priv->mainloop);
if (!waitop(priv, pa_stream_update_timing_info(priv->stream, NULL, NULL))) {
GENERIC_ERR_MSG(priv->context, "pa_stream_update_timing_info() failed");
return 0;
}
pa_threaded_mainloop_lock(priv->mainloop);
const pa_timing_info *ti = pa_stream_get_timing_info(priv->stream);
if (!ti) {
pa_threaded_mainloop_unlock(priv->mainloop);
GENERIC_ERR_MSG(priv->context, "pa_stream_get_timing_info() failed");
return 0;
}
const struct pa_sample_spec *ss = pa_stream_get_sample_spec(priv->stream);
if (!ss) {
pa_threaded_mainloop_unlock(priv->mainloop);
GENERIC_ERR_MSG(priv->context, "pa_stream_get_sample_spec() failed");
return 0;
}
// data left in PulseAudio's main buffers (not written to sink yet)
int64_t latency = pa_bytes_to_usec(ti->write_index - ti->read_index, ss);
// since this info may be from a while ago, playback has progressed since
latency -= ti->transport_usec;
// data already moved from buffers to sink, but not played yet
int64_t sink_latency = ti->sink_usec;
if (!ti->playing)
/* At the end of a stream, part of the data "left" in the sink may
* be padding silence after the end; that should be subtracted to
* get the amount of real audio from our stream. This adjustment
* is missing from Pulseaudio's own get_latency calculations
* (as of PulseAudio 2.1). */
sink_latency -= pa_bytes_to_usec(ti->since_underrun, ss);
if (sink_latency > 0)
latency += sink_latency;
if (latency < 0)
latency = 0;
pa_threaded_mainloop_unlock(priv->mainloop);
return latency / 1e6;
}
示例3: sink_get_latency
static pa_usec_t sink_get_latency(struct userdata *u, pa_sample_spec *ss) {
pa_usec_t r = 0;
pa_assert(u);
pa_assert(ss);
if (u->fd >= 0) {
r = pa_bytes_to_usec(get_playback_buffered_bytes(u), ss);
if (u->memchunk.memblock)
r += pa_bytes_to_usec(u->memchunk.length, ss);
}
return r;
}
示例4: source_get_latency
static pa_usec_t source_get_latency(struct userdata *u, pa_sample_spec *ss) {
pa_usec_t r = 0;
audio_info_t info;
pa_assert(u);
pa_assert(ss);
if (u->fd) {
int err = ioctl(u->fd, AUDIO_GETINFO, &info);
pa_assert(err >= 0);
r = pa_bytes_to_usec(get_recorded_bytes(u), ss) - pa_bytes_to_usec(u->read_bytes, ss);
}
return r;
}
示例5: get_playback_buffered_bytes
static uint64_t get_playback_buffered_bytes(struct userdata *u) {
audio_info_t info;
uint64_t played_bytes;
int err;
pa_assert(u->sink);
err = ioctl(u->fd, AUDIO_GETINFO, &info);
pa_assert(err >= 0);
/* Handle wrap-around of the device's sample counter, which is a uint_32. */
if (u->prev_playback_samples > info.play.samples) {
/*
* Unfortunately info.play.samples can sometimes go backwards, even before it wraps!
* The bug seems to be absent on Solaris x86 nv117 with audio810 driver, at least on this (UP) machine.
* The bug is present on a different (SMP) machine running Solaris x86 nv103 with audioens driver.
* An earlier revision of this file mentions the same bug independently (unknown configuration).
*/
if (u->prev_playback_samples + info.play.samples < 240000) {
++u->play_samples_msw;
} else {
pa_log_debug("play.samples went backwards %d bytes", u->prev_playback_samples - info.play.samples);
}
}
u->prev_playback_samples = info.play.samples;
played_bytes = (((uint64_t)u->play_samples_msw << 32) + info.play.samples) * u->frame_size;
pa_smoother_put(u->smoother, pa_rtclock_now(), pa_bytes_to_usec(played_bytes, &u->sink->sample_spec));
if (u->written_bytes > played_bytes)
return u->written_bytes - played_bytes;
else
return 0;
}
示例6: inputStreamStateCallback
static void inputStreamStateCallback(pa_stream *stream, void *userdata)
{
Q_UNUSED(userdata);
pa_stream_state_t state = pa_stream_get_state(stream);
#ifdef DEBUG_PULSE
qDebug() << "Stream state: " << QPulseAudioInternal::stateToQString(state);
#endif
switch (state) {
case PA_STREAM_CREATING:
break;
case PA_STREAM_READY: {
#ifdef DEBUG_PULSE
QPulseAudioInput *audioInput = static_cast<QPulseAudioInput*>(userdata);
const pa_buffer_attr *buffer_attr = pa_stream_get_buffer_attr(stream);
qDebug() << "*** maxlength: " << buffer_attr->maxlength;
qDebug() << "*** prebuf: " << buffer_attr->prebuf;
qDebug() << "*** fragsize: " << buffer_attr->fragsize;
qDebug() << "*** minreq: " << buffer_attr->minreq;
qDebug() << "*** tlength: " << buffer_attr->tlength;
pa_sample_spec spec = QPulseAudioInternal::audioFormatToSampleSpec(audioInput->format());
qDebug() << "*** bytes_to_usec: " << pa_bytes_to_usec(buffer_attr->fragsize, &spec);
#endif
}
break;
case PA_STREAM_TERMINATED:
break;
case PA_STREAM_FAILED:
default:
qWarning() << QString("Stream error: %1").arg(pa_strerror(pa_context_errno(pa_stream_get_context(stream))));
QPulseAudioEngine *pulseEngine = QPulseAudioEngine::instance();
pa_threaded_mainloop_signal(pulseEngine->mainloop(), 0);
break;
}
}
示例7: pa_bytes_to_usec
qint64 QPulseAudioInput::processedUSecs() const
{
pa_sample_spec spec = QPulseAudioInternal::audioFormatToSampleSpec(m_format);
qint64 result = pa_bytes_to_usec(m_totalTimeValue, &spec);
return result;
}
示例8: sink_process_msg
static int sink_process_msg(pa_msgobject *o, int code, void *data, int64_t offset, pa_memchunk *chunk) {
struct userdata *u = PA_SINK(o)->userdata;
switch (code) {
case PA_SINK_MESSAGE_GET_LATENCY: {
pa_usec_t w, r;
r = pa_smoother_get(u->smoother, pa_rtclock_now());
w = pa_bytes_to_usec((uint64_t) u->offset + u->memchunk.length, &u->sink->sample_spec);
*((int64_t*) data) = (int64_t)w - r;
return 0;
}
case SINK_MESSAGE_PASS_SOCKET: {
struct pollfd *pollfd;
pa_assert(!u->rtpoll_item);
u->rtpoll_item = pa_rtpoll_item_new(u->rtpoll, PA_RTPOLL_NEVER, 1);
pollfd = pa_rtpoll_item_get_pollfd(u->rtpoll_item, NULL);
pollfd->fd = u->fd;
pollfd->events = pollfd->revents = 0;
return 0;
}
}
return pa_sink_process_msg(o, code, data, offset, chunk);
}
示例9: sink_process_msg
/* Called from I/O thread context */
static int sink_process_msg(pa_msgobject *o, int code, void *data, int64_t offset, pa_memchunk *chunk) {
struct userdata *u = PA_SINK(o)->userdata;
switch (code) {
case PA_SINK_MESSAGE_GET_LATENCY:
/* The sink is _put() before the sink input is, so let's
* make sure we don't access it yet */
if (!PA_SINK_IS_LINKED(u->sink->thread_info.state) ||
!PA_SINK_INPUT_IS_LINKED(u->sink_input->thread_info.state)) {
*((pa_usec_t*) data) = 0;
return 0;
}
*((pa_usec_t*) data) =
/* Get the latency of the master sink */
pa_sink_get_latency_within_thread(u->sink_input->sink) +
/* Add the latency internal to our sink input on top */
pa_bytes_to_usec(pa_memblockq_get_length(u->sink_input->thread_info.render_memblockq), &u->sink_input->sink->sample_spec);
return 0;
}
return pa_sink_process_msg(o, code, data, offset, chunk);
}
示例10: sink_process_msg
static int sink_process_msg(pa_msgobject * o, int code, void *data,
int64_t offset, pa_memchunk * chunk)
{
int r;
struct userdata *u = PA_SINK(o)->userdata;
int state;
switch (code) {
case PA_SINK_MESSAGE_SET_STATE:
state = PA_PTR_TO_UINT(data);
r = pa_sink_process_msg(o, code, data, offset, chunk);
if (r >= 0) {
pa_log("sink cork req state =%d, now state=%d\n", state,
(int) (u->sink->state));
}
return r;
case PA_SINK_MESSAGE_GET_LATENCY: {
size_t n = 0;
n += u->memchunk_sink.length;
*((pa_usec_t *) data) =
pa_bytes_to_usec(n, &u->sink->sample_spec);
return 0;
}
}
return pa_sink_process_msg(o, code, data, offset, chunk);
}
示例11: source_process_msg
static int source_process_msg(
pa_msgobject *o,
int code,
void *data,
int64_t offset,
pa_memchunk *chunk) {
struct userdata *u = PA_SOURCE(o)->userdata;
switch (code) {
case PA_SOURCE_MESSAGE_GET_LATENCY: {
size_t n = 0;
#ifdef FIONREAD
int l;
if (ioctl(u->fd, FIONREAD, &l) >= 0 && l > 0)
n = (size_t) l;
#endif
*((int64_t*) data) = pa_bytes_to_usec(n, &u->source->sample_spec);
return 0;
}
}
return pa_source_process_msg(o, code, data, offset, chunk);
}
示例12: process_render
static void process_render(struct userdata *u, pa_usec_t now) {
pa_memchunk chunk;
int request_bytes;
//int index;
pa_assert(u);
if (u->got_max_latency) {
return;
}
//index = 0;
while (u->timestamp < now + u->block_usec) {
//index++;
//if (index > 3) {
/* used when u->block_usec and
u->sink->thread_info.max_request get big
using got_max_latency now */
// return;
//}
request_bytes = u->sink->thread_info.max_request;
request_bytes = MIN(request_bytes, 16 * 1024);
pa_sink_render(u->sink, request_bytes, &chunk);
//pa_log("bytes %d index %d", chunk.length, index);
data_send(u, &chunk);
pa_memblock_unref(chunk.memblock);
u->timestamp += pa_bytes_to_usec(chunk.length, &u->sink->sample_spec);
}
}
示例13: source_process_msg_cb
/* Called from I/O thread context */
static int source_process_msg_cb(pa_msgobject *o, int code, void *data, int64_t offset, pa_memchunk *chunk) {
struct userdata *u = PA_SOURCE(o)->userdata;
switch (code) {
case PA_SOURCE_MESSAGE_GET_LATENCY:
/* The source is _put() before the source output is, so let's
* make sure we don't access it in that time. Also, the
* source output is first shut down, the source second. */
if (!PA_SOURCE_IS_LINKED(u->source->thread_info.state) ||
!PA_SOURCE_OUTPUT_IS_LINKED(u->source_output->thread_info.state)) {
*((pa_usec_t*) data) = 0;
return 0;
}
*((pa_usec_t*) data) =
/* Get the latency of the master source */
pa_source_get_latency_within_thread(u->source_output->source) +
/* Add the latency internal to our source output on top */
pa_bytes_to_usec(pa_memblockq_get_length(u->source_output->thread_info.delay_memblockq), &u->source_output->source->sample_spec);
return 0;
}
return pa_source_process_msg(o, code, data, offset, chunk);
}
示例14: process_rewind
static void process_rewind(struct userdata *u, pa_usec_t now) {
size_t rewind_nbytes, in_buffer;
pa_usec_t delay;
pa_assert(u);
rewind_nbytes = u->sink->thread_info.rewind_nbytes;
if (!PA_SINK_IS_OPENED(u->sink->thread_info.state) || rewind_nbytes <= 0)
goto do_nothing;
pa_log_debug("Requested to rewind %lu bytes.", (unsigned long) rewind_nbytes);
if (u->timestamp <= now)
goto do_nothing;
delay = u->timestamp - now;
in_buffer = pa_usec_to_bytes(delay, &u->sink->sample_spec);
if (in_buffer <= 0)
goto do_nothing;
if (rewind_nbytes > in_buffer)
rewind_nbytes = in_buffer;
pa_sink_process_rewind(u->sink, rewind_nbytes);
u->timestamp -= pa_bytes_to_usec(rewind_nbytes, &u->sink->sample_spec);
pa_log_debug("Rewound %lu bytes.", (unsigned long) rewind_nbytes);
return;
do_nothing:
pa_sink_process_rewind(u->sink, 0);
}
示例15: voip_source_process_msg
/* Called from I/O thread context */
static int voip_source_process_msg(pa_msgobject *o, int code, void *data, int64_t offset, pa_memchunk *chunk) {
struct userdata *u = PA_SOURCE(o)->userdata;
switch (code) {
case VOICE_SOURCE_SET_UL_DEADLINE: {
u->ul_deadline = offset;
pa_log_debug("Uplink deadline set to %lld (%lld usec from now)",
u->ul_deadline, u->ul_deadline - pa_rtclock_now());
return 0;
}
case PA_SOURCE_MESSAGE_GET_LATENCY: {
pa_usec_t usec = 0;
if (PA_MSGOBJECT(u->master_source)->process_msg(
PA_MSGOBJECT(u->master_source), PA_SOURCE_MESSAGE_GET_LATENCY, &usec, 0, NULL) < 0)
usec = 0;
usec += pa_bytes_to_usec(pa_memblockq_get_length(u->ul_memblockq),
&u->aep_sample_spec);
*((pa_usec_t*) data) = usec;
return 0;
}
}
return pa_source_process_msg(o, code, data, offset, chunk);
}