From: Steinar H. Gunderson Date: Tue, 19 Feb 2019 23:25:43 +0000 (+0100) Subject: Remove the unused frame_length parameter to AudioMixer::add_audio(). X-Git-Tag: 1.8.3~32 X-Git-Url: https://git.sesse.net/?p=nageru;a=commitdiff_plain;h=8f9854b994be8dead8a5a1e9921402b7e1d6f12c Remove the unused frame_length parameter to AudioMixer::add_audio(). --- diff --git a/nageru/alsa_input.cpp b/nageru/alsa_input.cpp index 90a440f..ae2e7ff 100644 --- a/nageru/alsa_input.cpp +++ b/nageru/alsa_input.cpp @@ -246,21 +246,13 @@ ALSAInput::CaptureEndReason ALSAInput::do_capture() } 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; -} - diff --git a/nageru/alsa_input.h b/nageru/alsa_input.h index 060b921..825d4b6 100644 --- a/nageru/alsa_input.h +++ b/nageru/alsa_input.h @@ -5,9 +5,7 @@ // 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 #include @@ -26,7 +24,7 @@ class ALSAPool; class ALSAInput { public: - typedef std::function audio_callback_t; + typedef std::function 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(); @@ -51,7 +49,6 @@ public: private: void capture_thread_func(); - int64_t frames_to_pts(uint64_t n) const; enum class CaptureEndReason { REQUESTED_QUIT, diff --git a/nageru/alsa_pool.cpp b/nageru/alsa_pool.cpp index 3092dc3..978f236 100644 --- a/nageru/alsa_pool.cpp +++ b/nageru/alsa_pool.cpp @@ -402,7 +402,7 @@ void ALSAPool::reset_device(unsigned index) 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(); } diff --git a/nageru/audio_mixer.cpp b/nageru/audio_mixer.cpp index f63fe24..d62f1e1 100644 --- a/nageru/audio_mixer.cpp +++ b/nageru/audio_mixer.cpp @@ -244,7 +244,7 @@ void AudioMixer::reset_resampler_mutex_held(DeviceSpec device_spec) } } -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); @@ -294,7 +294,7 @@ bool AudioMixer::add_audio(DeviceSpec device_spec, const uint8_t *data, unsigned 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); diff --git a/nageru/audio_mixer.h b/nageru/audio_mixer.h index e435b46..1cf4da3 100644 --- a/nageru/audio_mixer.h +++ b/nageru/audio_mixer.h @@ -54,9 +54,9 @@ public: // 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, diff --git a/nageru/benchmark_audio_mixer.cpp b/nageru/benchmark_audio_mixer.cpp index 7ec3450..edb4955 100644 --- a/nageru/benchmark_audio_mixer.cpp +++ b/nageru/benchmark_audio_mixer.cpp @@ -73,7 +73,7 @@ vector process_frame(unsigned frame_num, AudioMixer *mixer) 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); } diff --git a/nageru/mixer.cpp b/nageru/mixer.cpp index 9fd1e15..f8c39e8 100644 --- a/nageru/mixer.cpp +++ b/nageru/mixer.cpp @@ -779,12 +779,12 @@ void Mixer::bm_frame(unsigned card_index, uint16_t timecode, 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.