}
RETURN_ON_ERROR("snd_pcm_readi()", frames);
- const int64_t prev_pts = frames_to_pts(num_frames_output);
- const int64_t pts = frames_to_pts(num_frames_output + frames);
const steady_clock::time_point now = steady_clock::now();
bool success;
do {
if (should_quit.should_quit()) return CaptureEndReason::REQUESTED_QUIT;
- success = audio_callback(buffer.get(), frames, audio_format, pts - prev_pts, now);
+ success = audio_callback(buffer.get(), frames, audio_format, now);
} while (!success);
num_frames_output += frames;
}
return CaptureEndReason::REQUESTED_QUIT;
}
-
-int64_t ALSAInput::frames_to_pts(uint64_t n) const
-{
- return (n * TIMEBASE) / sample_rate;
-}
-
// in callbacks.
//
// Note: “frame” here generally refers to the ALSA definition of frame,
-// which is a set of samples, exactly one for each channel. The only exception
-// is in frame_length, where it means the TIMEBASE length of the buffer
-// as a whole, since that's what AudioMixer::add_audio() wants.
+// which is a set of samples, exactly one for each channel.
#include <alsa/asoundlib.h>
#include <stdint.h>
class ALSAInput {
public:
- typedef std::function<bool(const uint8_t *data, unsigned num_samples, bmusb::AudioFormat audio_format, int64_t frame_length, std::chrono::steady_clock::time_point ts)> audio_callback_t;
+ typedef std::function<bool(const uint8_t *data, unsigned num_samples, bmusb::AudioFormat audio_format, std::chrono::steady_clock::time_point ts)> audio_callback_t;
ALSAInput(const char *device, unsigned sample_rate, unsigned num_channels, audio_callback_t audio_callback, ALSAPool *parent_pool, unsigned internal_dev_index);
~ALSAInput();
private:
void capture_thread_func();
- int64_t frames_to_pts(uint64_t n) const;
enum class CaptureEndReason {
REQUESTED_QUIT,
inputs[index].reset();
} else {
// TODO: Put on a background thread instead of locking?
- auto callback = bind(&AudioMixer::add_audio, global_audio_mixer, DeviceSpec{InputSourceType::ALSA_INPUT, index}, _1, _2, _3, _4, _5);
+ auto callback = bind(&AudioMixer::add_audio, global_audio_mixer, DeviceSpec{InputSourceType::ALSA_INPUT, index}, _1, _2, _3, _4);
inputs[index].reset(new ALSAInput(device->address.c_str(), OUTPUT_FREQUENCY, device->num_channels, callback, this, index));
inputs[index]->start_capture_thread();
}
}
}
-bool AudioMixer::add_audio(DeviceSpec device_spec, const uint8_t *data, unsigned num_samples, AudioFormat audio_format, int64_t frame_length, steady_clock::time_point frame_time)
+bool AudioMixer::add_audio(DeviceSpec device_spec, const uint8_t *data, unsigned num_samples, AudioFormat audio_format, steady_clock::time_point frame_time)
{
AudioDevice *device = find_audio_device(device_spec);
return true;
}
-bool AudioMixer::add_silence(DeviceSpec device_spec, unsigned samples_per_frame, unsigned num_frames, int64_t frame_length)
+bool AudioMixer::add_silence(DeviceSpec device_spec, unsigned samples_per_frame, unsigned num_frames)
{
AudioDevice *device = find_audio_device(device_spec);
// the lock wasn't successfully taken; if so, you should simply try again.
// (This is to avoid a deadlock where a card hangs on the mutex in add_audio()
// while we are trying to shut it down from another thread that also holds
- // the mutex.) frame_length is in TIMEBASE units.
- bool add_audio(DeviceSpec device_spec, const uint8_t *data, unsigned num_samples, bmusb::AudioFormat audio_format, int64_t frame_length, std::chrono::steady_clock::time_point frame_time);
- bool add_silence(DeviceSpec device_spec, unsigned samples_per_frame, unsigned num_frames, int64_t frame_length);
+ // the mutex.)
+ bool add_audio(DeviceSpec device_spec, const uint8_t *data, unsigned num_samples, bmusb::AudioFormat audio_format, std::chrono::steady_clock::time_point frame_time);
+ bool add_silence(DeviceSpec device_spec, unsigned samples_per_frame, unsigned num_frames);
// If a given device is offline for whatever reason and cannot deliver audio
// (by means of add_audio() or add_silence()), you can call put it in silence mode,
unsigned num_samples = NUM_SAMPLES + (lcgrand() % 9) - 5;
bool ok = mixer->add_audio(DeviceSpec{InputSourceType::CAPTURE_CARD, card_index},
card_index == 3 ? samples24 : samples16, num_samples, audio_format,
- NUM_SAMPLES * TIMEBASE / OUTPUT_FREQUENCY, ts);
+ ts);
assert(ok);
}
bool success;
do {
- success = audio_mixer->add_silence(device, silence_samples, dropped_frames, frame_length);
+ success = audio_mixer->add_silence(device, silence_samples, dropped_frames);
} while (!success);
}
if (num_samples > 0) {
- audio_mixer->add_audio(device, audio_frame.data + audio_offset, num_samples, audio_format, frame_length, audio_frame.received_timestamp);
+ audio_mixer->add_audio(device, audio_frame.data + audio_offset, num_samples, audio_format, audio_frame.received_timestamp);
}
// Done with the audio, so release it.