From fe3ff1aabd21892523da6ba27b89a8484bb11252 Mon Sep 17 00:00:00 2001 From: Andrea Bondavalli Date: Tue, 16 Feb 2021 21:09:50 +0100 Subject: [PATCH] - build.sh uses the branch aes67-daemon of the new github repo https://github.com/bondagit/ravenna-alsa-lkm.git This repo is a fork of the original one with the bondagit patches applied to the aes67-daemon branch - removed ravenna-alsa-lkm driver patches from the repo --- .../ravenna-alsa-fix-playback-rw-mode.patch | 525 ---------- .../ravenna-alsa-lkm-add-codec-am824.patch | 163 --- .../patches/ravenna-alsa-lkm-arm-32bit.patch | 301 ------ ...ravenna-alsa-lkm-direct-pcm-transfer.patch | 982 ------------------ ...avenna-alsa-lkm-disable-ptp-checksum.patch | 19 - .../ravenna-alsa-lkm-enable-loopback.patch | 13 - ...avenna-alsa-lkm-enable-mono-channels.patch | 23 - 3rdparty/patches/ravenna-alsa-lkm-fixes.patch | 82 -- ...lsa-lkm-independent-playback-capture.patch | 276 ----- ...a-alsa-lkm-init-play-capture-buffers.patch | 22 - .../patches/ravenna-alsa-lkm-kernel-v5.patch | 148 --- build.sh | 19 +- 12 files changed, 2 insertions(+), 2571 deletions(-) delete mode 100644 3rdparty/patches/ravenna-alsa-fix-playback-rw-mode.patch delete mode 100644 3rdparty/patches/ravenna-alsa-lkm-add-codec-am824.patch delete mode 100644 3rdparty/patches/ravenna-alsa-lkm-arm-32bit.patch delete mode 100644 3rdparty/patches/ravenna-alsa-lkm-direct-pcm-transfer.patch delete mode 100644 3rdparty/patches/ravenna-alsa-lkm-disable-ptp-checksum.patch delete mode 100644 3rdparty/patches/ravenna-alsa-lkm-enable-loopback.patch delete mode 100644 3rdparty/patches/ravenna-alsa-lkm-enable-mono-channels.patch delete mode 100644 3rdparty/patches/ravenna-alsa-lkm-fixes.patch delete mode 100644 3rdparty/patches/ravenna-alsa-lkm-independent-playback-capture.patch delete mode 100644 3rdparty/patches/ravenna-alsa-lkm-init-play-capture-buffers.patch delete mode 100644 3rdparty/patches/ravenna-alsa-lkm-kernel-v5.patch diff --git a/3rdparty/patches/ravenna-alsa-fix-playback-rw-mode.patch b/3rdparty/patches/ravenna-alsa-fix-playback-rw-mode.patch deleted file mode 100644 index 33af6c8..0000000 --- a/3rdparty/patches/ravenna-alsa-fix-playback-rw-mode.patch +++ /dev/null @@ -1,525 +0,0 @@ -diff --git a/driver/audio_driver.c b/driver/audio_driver.c ---- a/driver/audio_driver.c -+++ b/driver/audio_driver.c -@@ -99,24 +99,14 @@ - static struct alsa_ops *g_mr_alsa_audio_ops; - - --static int mr_alsa_audio_pcm_capture_copy( struct snd_pcm_substream *substream, -- int channel, snd_pcm_uframes_t pos, -- void __user *src, -- snd_pcm_uframes_t count); - static int mr_alsa_audio_pcm_capture_copy_internal( struct snd_pcm_substream *substream, - int channel, uint32_t pos, - void __user *src, -- snd_pcm_uframes_t count, -- bool to_user_space); --static int mr_alsa_audio_pcm_playback_copy( struct snd_pcm_substream *substream, -- int channel, snd_pcm_uframes_t pos, -- void __user *src, - snd_pcm_uframes_t count); - static int mr_alsa_audio_pcm_playback_copy_internal( struct snd_pcm_substream *substream, - int channel, uint32_t pos, - void __user *src, -- snd_pcm_uframes_t count, -- bool from_user_space); -+ snd_pcm_uframes_t count); - - /// "chip" : the main private structure - struct mr_alsa_audio_chip -@@ -611,6 +601,7 @@ - chip->mr_alsa_audio_ops->get_interrupts_frame_size(chip->ravenna_peer, &ptp_frame_size); - if(direction == 1 && chip->capture_substream != NULL) - { -+ unsigned long bytes_to_frame_factor; - struct snd_pcm_runtime *runtime = chip->capture_substream->runtime; - ring_buffer_size = chip->current_dsd ? MR_ALSA_RINGBUFFER_NB_FRAMES : runtime->period_size * runtime->periods; - if (ring_buffer_size > MR_ALSA_RINGBUFFER_NB_FRAMES) -@@ -620,22 +611,15 @@ - } - - /// DMA case -- if (runtime->access == SNDRV_PCM_ACCESS_MMAP_INTERLEAVED || -- runtime->access == SNDRV_PCM_ACCESS_MMAP_NONINTERLEAVED || -- runtime->access == SNDRV_PCM_ACCESS_MMAP_COMPLEX) -- { -- unsigned long bytes_to_frame_factor = runtime->channels * chip->current_alsa_capture_stride; -- -- //printk(KERN_DEBUG "capture copy pos=%u, dma_pos=%u, count=%u, channels=%d pcm_size=%u\n", chip->capture_buffer_pos, pos, ptp_frame_size, runtime->channels, pcm_buffer_size); -- mr_alsa_audio_pcm_capture_copy_internal(chip->capture_substream, runtime->channels/*channel*/, -- chip->capture_buffer_pos, chip->dma_capture_buffer + chip->dma_capture_offset/**src*/, ptp_frame_size, false); -+ bytes_to_frame_factor = runtime->channels * chip->current_alsa_capture_stride; - -- chip->dma_capture_offset += ptp_frame_size * bytes_to_frame_factor; -- if (chip->dma_capture_offset >= chip->pcm_capture_buffer_size) -- { -- chip->dma_capture_offset -= chip->pcm_capture_buffer_size; -- } -- } -+ //printk(KERN_DEBUG "capture copy pos=%u, dma_pos=%u, count=%u, channels=%d pcm_size=%u\n", chip->capture_buffer_pos, pos, ptp_frame_size, runtime->channels, pcm_buffer_size); -+ mr_alsa_audio_pcm_capture_copy_internal(chip->capture_substream, runtime->channels/*channel*/, -+ chip->capture_buffer_pos, chip->dma_capture_buffer + chip->dma_capture_offset/**src*/, ptp_frame_size); -+ -+ chip->dma_capture_offset += ptp_frame_size * bytes_to_frame_factor; -+ if (chip->dma_capture_offset >= chip->pcm_capture_buffer_size) -+ chip->dma_capture_offset -= chip->pcm_capture_buffer_size; - - chip->capture_buffer_pos += ptp_frame_size; - if(chip->capture_buffer_pos >= ring_buffer_size) -@@ -654,6 +638,7 @@ - } - else if(direction == 0 && chip->playback_substream != NULL) - { -+ unsigned long bytes_to_frame_factor; - struct snd_pcm_runtime *runtime = chip->playback_substream->runtime; - ring_buffer_size = chip->current_dsd ? MR_ALSA_RINGBUFFER_NB_FRAMES : runtime->period_size * runtime->periods; - if (ring_buffer_size > MR_ALSA_RINGBUFFER_NB_FRAMES) -@@ -662,23 +647,14 @@ - return -2; - } - -- /// DMA case -- if (runtime->access == SNDRV_PCM_ACCESS_MMAP_INTERLEAVED || -- runtime->access == SNDRV_PCM_ACCESS_MMAP_NONINTERLEAVED || -- runtime->access == SNDRV_PCM_ACCESS_MMAP_COMPLEX) -- { -- unsigned long bytes_to_frame_factor = runtime->channels * chip->current_alsa_playback_stride; -- -- //printk(KERN_DEBUG "playback copy pos=%u, dma_pos=%u, count=%u, channels=%d pcm_size=%u\n", chip->playback_buffer_pos, pos, ptp_frame_size, runtime->channels, pcm_buffer_size); -- mr_alsa_audio_pcm_playback_copy_internal(chip->playback_substream, runtime->channels/*channel*/, -- chip->playback_buffer_pos/*pos*/, chip->dma_playback_buffer + chip->dma_playback_offset/*src*/, ptp_frame_size/*count*/, false); -- -- chip->dma_playback_offset += ptp_frame_size * bytes_to_frame_factor; -- if (chip->dma_playback_offset >= chip->pcm_playback_buffer_size) -- { -- chip->dma_playback_offset -= chip->pcm_playback_buffer_size; -- } -- } -+ bytes_to_frame_factor = runtime->channels * chip->current_alsa_playback_stride; -+ //printk(KERN_DEBUG "playback copy pos=%u, dma_pos=%u, count=%u, channels=%d pcm_size=%u\n", chip->playback_buffer_pos, pos, ptp_frame_size, runtime->channels, pcm_buffer_size); -+ mr_alsa_audio_pcm_playback_copy_internal(chip->playback_substream, runtime->channels/*channel*/, -+ chip->playback_buffer_pos/*pos*/, chip->dma_playback_buffer + chip->dma_playback_offset/*src*/, ptp_frame_size/*count*/); -+ -+ chip->dma_playback_offset += ptp_frame_size * bytes_to_frame_factor; -+ if (chip->dma_playback_offset >= chip->pcm_playback_buffer_size) -+ chip->dma_playback_offset -= chip->pcm_playback_buffer_size; - - chip->playback_buffer_pos += ptp_frame_size; - if (chip->playback_buffer_pos >= ring_buffer_size) -@@ -988,18 +964,9 @@ - if(alsa_sub->stream == SNDRV_PCM_STREAM_PLAYBACK) - { - /// DMA case -- if (alsa_sub->runtime->access == SNDRV_PCM_ACCESS_MMAP_INTERLEAVED || -- alsa_sub->runtime->access == SNDRV_PCM_ACCESS_MMAP_NONINTERLEAVED || -- alsa_sub->runtime->access == SNDRV_PCM_ACCESS_MMAP_COMPLEX) -- { -- struct snd_pcm_runtime *runtime = alsa_sub->runtime; -- unsigned long bytes_to_frame_factor = runtime->channels * chip->current_alsa_playback_stride; -- offset = chip->dma_playback_offset / bytes_to_frame_factor; -- } -- else -- { -- offset = chip->playback_buffer_pos; -- } -+ struct snd_pcm_runtime *runtime = alsa_sub->runtime; -+ unsigned long bytes_to_frame_factor = runtime->channels * chip->current_alsa_playback_stride; -+ offset = chip->dma_playback_offset / bytes_to_frame_factor; - - /// Ravenna DSD always uses a rate of 352k with eventual zero padding to maintain a 32 bit alignment - /// while DSD in ALSA uses a continuous 8, 16 or 32 bit aligned stream with at 352k, 176k or 88k -@@ -1022,19 +989,9 @@ - } - else if(alsa_sub->stream == SNDRV_PCM_STREAM_CAPTURE) - { -- /// DMA case -- if (alsa_sub->runtime->access == SNDRV_PCM_ACCESS_MMAP_INTERLEAVED || -- alsa_sub->runtime->access == SNDRV_PCM_ACCESS_MMAP_NONINTERLEAVED || -- alsa_sub->runtime->access == SNDRV_PCM_ACCESS_MMAP_COMPLEX) -- { -- struct snd_pcm_runtime *runtime = alsa_sub->runtime; -- unsigned long bytes_to_frame_factor = runtime->channels * chip->current_alsa_capture_stride; -- offset = chip->dma_capture_offset / bytes_to_frame_factor; -- } -- else -- { -- chip->mr_alsa_audio_ops->get_input_jitter_buffer_offset(chip->ravenna_peer, &offset); -- } -+ struct snd_pcm_runtime *runtime = alsa_sub->runtime; -+ unsigned long bytes_to_frame_factor = runtime->channels * chip->current_alsa_capture_stride; -+ offset = chip->dma_capture_offset / bytes_to_frame_factor; - - /// Ravenna DSD always uses a rate of 352k with eventual zero padding to maintain a 32 bit alignment - /// while DSD in ALSA uses a continuous 8, 16 or 32 bit aligned stream with at 352k, 176k or 88k -@@ -1166,36 +1123,10 @@ - }; - - --#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,13,0) --static int mr_alsa_audio_pcm_capture_copy_user( struct snd_pcm_substream *substream, -- int channel, unsigned long pos, -- void __user *src, -- unsigned long count) -- { -- struct mr_alsa_audio_chip* chip = snd_pcm_substream_chip(substream); -- struct snd_pcm_runtime *runtime = substream->runtime; -- bool interleaved = runtime->access == SNDRV_PCM_ACCESS_RW_INTERLEAVED ? 1 : 0; -- unsigned long bytes_to_frame_factor = runtime->channels * chip->current_alsa_capture_stride; -- return mr_alsa_audio_pcm_capture_copy(substream, interleaved ? -1 : channel, pos / bytes_to_frame_factor, src, count / bytes_to_frame_factor); --} --#endif -- --static int mr_alsa_audio_pcm_capture_copy( struct snd_pcm_substream *substream, -- int channel, snd_pcm_uframes_t pos, -- void __user *src, -- snd_pcm_uframes_t count) --{ -- struct mr_alsa_audio_chip *chip = snd_pcm_substream_chip(substream); -- uint32_t ravenna_buffer_pos = pos * chip->nb_capture_interrupts_per_period; -- -- return mr_alsa_audio_pcm_capture_copy_internal(substream, channel, ravenna_buffer_pos, src, count, true); --} -- - static int mr_alsa_audio_pcm_capture_copy_internal( struct snd_pcm_substream *substream, - int channel, uint32_t pos, - void __user *src, -- snd_pcm_uframes_t count, -- bool to_user_space) -+ snd_pcm_uframes_t count) - { - struct mr_alsa_audio_chip *chip = snd_pcm_substream_chip(substream); - struct snd_pcm_runtime *runtime = substream->runtime; -@@ -1204,43 +1135,22 @@ - unsigned int strideIn = chip->current_alsa_capture_stride; - uint32_t ravenna_buffer_pos = pos; - -- // todo DSD capture -- //uint32_t dsdrate = mr_alsa_audio_get_dsd_sample_rate(runtime->format, runtime->rate); -- //uint32_t dsdmode = (dsdrate > 0? mr_alsa_audio_get_dsd_mode(dsdrate) : 0); -- -- -- /// Ravenna DSD always uses a rate of 352k with eventual zero padding to maintain a 32 bit alignment -- /// while DSD in ALSA uses a continuous 8, 16 or 32 bit aligned stream with at 352k, 176k or 88k -- /// so respective ring buffers might have different scale and size -- //uint32_t alsa_ring_buffer_nb_frames = MR_ALSA_RINGBUFFER_NB_FRAMES / chip->nb_capture_interrupts_per_period; -- -- //printk("entering mr_alsa_audio_pcm_capture_copy (channel=%d, count=%lu) (substream name=%s #%d) ...\n", channel, count, substream->name, substream->number); -- //printk("Bitwidth = %u, strideIn = %u\n", nb_logical_bits, strideIn); -- -- //if(snd_BUG_ON(ravenna_buffer_pos >= MR_ALSA_RINGBUFFER_NB_FRAMES)) -- // ravenna_buffer_pos -= MR_ALSA_RINGBUFFER_NB_FRAMES; -- -- -- //printk("capture_copy: rate = %u, dsdmode = %u, #IRQ per period = %u, count = %lu, pos = %lu, ravenna_buffer_pos = %u\n", (dsdrate > 0? dsdrate : runtime->rate), dsdmode, chip->nb_capture_interrupts_per_period, count, pos, ravenna_buffer_pos); -- //printk("capture_copy: rate = %u, #IRQ per period = %u, count = %zu, pos = %u, ravenna_buffer_pos = %u, channels = %u\n", runtime->rate, chip->nb_capture_interrupts_per_period, count, pos, ravenna_buffer_pos, runtime->channels); -- -- - if(interleaved) - { - switch(nb_logical_bits) - { - case 16: -- MTConvertMappedInt32ToInt16LEInterleave(chip->capture_buffer_channels_map, ravenna_buffer_pos, src, runtime->channels, count, to_user_space); -+ MTConvertMappedInt32ToInt16LEInterleave(chip->capture_buffer_channels_map, ravenna_buffer_pos, src, runtime->channels, count, false); - break; - case 24: - { - switch(strideIn) - { - case 3: -- MTConvertMappedInt32ToInt24LEInterleave(chip->capture_buffer_channels_map, ravenna_buffer_pos, src, runtime->channels, count, to_user_space); -+ MTConvertMappedInt32ToInt24LEInterleave(chip->capture_buffer_channels_map, ravenna_buffer_pos, src, runtime->channels, count, false); - break; - case 4: -- MTConvertMappedInt32ToInt24LE4ByteInterleave(chip->capture_buffer_channels_map, ravenna_buffer_pos, src, runtime->channels, count, to_user_space); -+ MTConvertMappedInt32ToInt24LE4ByteInterleave(chip->capture_buffer_channels_map, ravenna_buffer_pos, src, runtime->channels, count, false); - break; - default: - { -@@ -1251,7 +1161,7 @@ - break; - } - case 32: -- MTConvertMappedInt32ToInt32LEInterleave(chip->capture_buffer_channels_map, ravenna_buffer_pos, src, runtime->channels, count, to_user_space); -+ MTConvertMappedInt32ToInt32LEInterleave(chip->capture_buffer_channels_map, ravenna_buffer_pos, src, runtime->channels, count, false); - break; - } - } -@@ -1263,47 +1173,11 @@ - return count; - } - --/// This callback is called whenever the alsa application wants to write data --/// We use it here to do all the de-interleaving, format conversion and DSD re-packing --/// The intermediate buffer is actually the alsa (dma) buffer, allocated in hw_params() --/// The incoming data (src) is user land memory pointer, so copy_from_user() must be used for memory copy --#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,13,0) --static int mr_alsa_audio_pcm_playback_copy_user( struct snd_pcm_substream *substream, -- int channel, unsigned long pos, -- void __user *src, -- unsigned long count) --{ -- struct mr_alsa_audio_chip* chip = snd_pcm_substream_chip(substream); -- struct snd_pcm_runtime *runtime = substream->runtime; -- unsigned long bytes_to_frame_factor = runtime->channels * chip->current_alsa_playback_stride; -- return mr_alsa_audio_pcm_playback_copy(substream, channel, pos / bytes_to_frame_factor, src, count / bytes_to_frame_factor); --} --#endif -- --/// This callback is called whenever the alsa application wants to write data --/// We use it here to do all the de-interleaving, format conversion and DSD re-packing --/// The intermediate buffer is actually the alsa (dma) buffer, allocated in hw_params() --/// The incoming data (src) is user land memory pointer, so copy_from_user() must be used for memory copy --static int mr_alsa_audio_pcm_playback_copy( struct snd_pcm_substream *substream, -- int channel, snd_pcm_uframes_t pos, -- void __user *src, -- snd_pcm_uframes_t count) --{ -- struct mr_alsa_audio_chip *chip = snd_pcm_substream_chip(substream); -- /// Ravenna DSD always uses a rate of 352k with eventual zero padding to maintain a 32 bit alignment -- /// while DSD in ALSA uses a continuous 8, 16 or 32 bit aligned stream with at 352k, 176k or 88k -- /// so respective ring buffers might have different scale and size -- uint32_t ravenna_buffer_pos = pos * chip->nb_playback_interrupts_per_period; -- -- return mr_alsa_audio_pcm_playback_copy_internal(substream, channel, ravenna_buffer_pos, src, count, true); --} -- - - static int mr_alsa_audio_pcm_playback_copy_internal( struct snd_pcm_substream *substream, - int channel, uint32_t pos, - void __user *src, -- snd_pcm_uframes_t count, -- bool from_user_space) -+ snd_pcm_uframes_t count) - { - struct mr_alsa_audio_chip *chip = snd_pcm_substream_chip(substream); - struct snd_pcm_runtime *runtime = substream->runtime; -@@ -1316,8 +1190,6 @@ - uint32_t dsdmode = (dsdrate > 0? mr_alsa_audio_get_dsd_mode(dsdrate) : 0); - uint32_t ravenna_buffer_pos = pos; - -- //printk("playback_copy: rate = %u, dsdmode = %u, #IRQ per period = %u, count = %u, pos = %lu, ravenna_buffer_pos = %u, alsa_pb_sac = %llu, ravenna_pb_sac = %llu\n", (dsdrate > 0? dsdrate : runtime->rate), dsdmode, chip->nb_playback_interrupts_per_period, count, pos, ravenna_buffer_pos, chip->playback_buffer_alsa_sac, chip->playback_buffer_rav_sac); -- - if(interleaved) - { - /// de-interleaving -@@ -1325,145 +1197,70 @@ - unsigned int stepIn = runtime->channels * strideIn; - unsigned int stepOut = strideOut * chip->nb_playback_interrupts_per_period; - uint32_t ring_buffer_size = MR_ALSA_RINGBUFFER_NB_FRAMES * strideOut; -- //printk("playback_copy: de-interleaving %u frames, pos = %llu, ravenna_buffer_pos = %u, with strideIn = %u, strideOut = %u, stepIn = %u, stepOut = %u, ravBuffer_csize = %u \n", count, pos, ravenna_buffer_pos, strideIn, strideOut, stepIn, stepOut, (unsigned int)ravBuffer_csize); - -- if (from_user_space) -+ for (chn = 0; chn < runtime->channels; ++chn) - { -- for (chn = 0; chn < runtime->channels; ++chn) -+ uint32_t currentOutPos = ravenna_buffer_pos * strideOut; -+ snd_pcm_uframes_t frmCnt = 0; -+ in = (unsigned char*)src + chn * strideIn; -+ out = chip->playback_buffer + chn * ring_buffer_size + currentOutPos; -+ // -+ ///Conversion to Signed integer 32 bit LE -+ for (frmCnt = 0; frmCnt < count; ++frmCnt) - { -- uint32_t currentOutPos = ravenna_buffer_pos * strideOut; -- snd_pcm_uframes_t frmCnt = 0; -- in = (unsigned char*)src + chn * strideIn; -- out = chip->playback_buffer + chn * ring_buffer_size + currentOutPos; -- // -- ///Conversion to Signed integer 32 bit LE -- for (frmCnt = 0; frmCnt < count; ++frmCnt) -+ /// assumes Little Endian -+ if (dsdmode == 0) - { -- /// assumes Little Endian -- int32_t val = 0; -- if (dsdmode == 0) -- { -- switch (nb_logical_bits) -- { -- case 16: -- __get_user(((unsigned char*)&val)[3], &in[1]); -- __get_user(((unsigned char*)&val)[2], &in[0]); -- break; -- case 24: -- __get_user(((unsigned char*)&val)[3], &in[2]); -- __get_user(((unsigned char*)&val)[2], &in[1]); -- __get_user(((unsigned char*)&val)[1], &in[0]); -- break; -- case 32: -- __get_user(val, (int32_t*)in); -- break; -- } -- *((int32_t*)out) = val; -- } -- else -- { -- /// interleaved DSD stream to non interleaved 32 bit aligned blocks with 1/2/4 DSD bytes per 32 bit -- uint32_t out_cnt; -- for (out_cnt = 0; out_cnt < chip->nb_playback_interrupts_per_period; ++out_cnt) -- { -- switch (dsdmode) -- { -- case 1: ///DSD64 -- __get_user(((unsigned char*)&val)[0], &in[out_cnt]); -- break; -- case 2: ///DSD128 -- __get_user(((unsigned char*)&val)[1], &in[2 * out_cnt + 1]); -- __get_user(((unsigned char*)&val)[0], &in[2 * out_cnt]); -- break; -- case 4: ///DSD256 -- __get_user(val, (int32_t*)in); -- break; -- } -- ((int32_t*)out)[out_cnt] = val; -- } -- } -- -- in += stepIn; -- if (currentOutPos + stepOut >= ring_buffer_size) -+ switch (nb_logical_bits) - { -- currentOutPos = 0; -- out = chip->playback_buffer + chn * ring_buffer_size; -- } -- else -- { -- currentOutPos += stepOut; -- out += stepOut; -+ case 16: -+ out[3] = in[1]; -+ out[2] = in[0]; -+ out[1] = 0; -+ out[0] = 0; -+ break; -+ case 24: -+ out[3] = in[2]; -+ out[2] = in[1]; -+ out[1] = in[0]; -+ out[0] = 0; -+ break; -+ case 32: -+ *(int32_t*)out = *(int32_t*)in; -+ break; - } - } -- } -- } -- else -- { -- for (chn = 0; chn < runtime->channels; ++chn) -- { -- uint32_t currentOutPos = ravenna_buffer_pos * strideOut; -- snd_pcm_uframes_t frmCnt = 0; -- in = (unsigned char*)src + chn * strideIn; -- out = chip->playback_buffer + chn * ring_buffer_size + currentOutPos; -- // -- ///Conversion to Signed integer 32 bit LE -- for (frmCnt = 0; frmCnt < count; ++frmCnt) -+ else - { -- /// assumes Little Endian -- int32_t val = 0; -- if (dsdmode == 0) -+ /// interleaved DSD stream to non interleaved 32 bit aligned blocks with 1/2/4 DSD bytes per 32 bit -+ uint32_t out_cnt; -+ for (out_cnt = 0; out_cnt < chip->nb_playback_interrupts_per_period; ++out_cnt) - { -- switch (nb_logical_bits) -+ switch (dsdmode) - { -- case 16: -- -- ((unsigned char*)&val)[3] = in[1]; -- ((unsigned char*)&val)[2] = in[0]; -+ case 1: ///DSD64 -+ ((int32_t*)out)[out_cnt] = *(int32_t*)(in + out_cnt) & 0xFF; - break; -- case 24: -- ((unsigned char*)&val)[3] = in[2]; -- ((unsigned char*)&val)[2] = in[1]; -- ((unsigned char*)&val)[1] = in[0]; -+ case 2: ///DSD128 -+ ((int32_t*)out)[out_cnt] = (((int32_t)(in[2 * out_cnt + 1]) << 8) | ((int32_t)(in[2 * out_cnt]))) & 0xFFFF; - break; -- case 32: -- val = *(int32_t*)(in); -+ case 4: ///DSD256 -+ ((int32_t*)out)[out_cnt] = *(int32_t*)(in); - break; - } -- *((int32_t*)out) = val; -- } -- else -- { -- /// interleaved DSD stream to non interleaved 32 bit aligned blocks with 1/2/4 DSD bytes per 32 bit -- uint32_t out_cnt; -- for (out_cnt = 0; out_cnt < chip->nb_playback_interrupts_per_period; ++out_cnt) -- { -- switch (dsdmode) -- { -- case 1: ///DSD64 -- val = *(int32_t*)(in + out_cnt) & 0xFF; -- break; -- case 2: ///DSD128 -- val = (((int32_t)(in[2 * out_cnt + 1]) << 8) | ((int32_t)(in[2 * out_cnt]))) & 0xFFFF; -- break; -- case 4: ///DSD256 -- val = *(int32_t*)(in); -- break; -- } -- ((int32_t*)out)[out_cnt] = val; -- } - } -+ } - -- in += stepIn; -- if (currentOutPos + stepOut >= ring_buffer_size) -- { -- currentOutPos = 0; -- out = chip->playback_buffer + chn * ring_buffer_size; -- } -- else -- { -- currentOutPos += stepOut; -- out += stepOut; -- } -+ in += stepIn; -+ if (currentOutPos + stepOut >= ring_buffer_size) -+ { -+ currentOutPos = 0; -+ out = chip->playback_buffer + chn * ring_buffer_size; -+ } -+ else -+ { -+ currentOutPos += stepOut; -+ out += stepOut; - } - } - } -@@ -2042,11 +1839,6 @@ - .prepare = mr_alsa_audio_pcm_prepare, - .trigger = mr_alsa_audio_pcm_trigger, - .pointer = mr_alsa_audio_pcm_pointer, --#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,13,0) -- .copy_user = mr_alsa_audio_pcm_playback_copy_user, --#else -- .copy = mr_alsa_audio_pcm_playback_copy, --#endif - .page = snd_pcm_lib_get_vmalloc_page, - }; - -@@ -2060,13 +1852,6 @@ - .prepare = mr_alsa_audio_pcm_prepare, - .trigger = mr_alsa_audio_pcm_trigger, - .pointer = mr_alsa_audio_pcm_pointer, --#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,13,0) -- .copy_user = mr_alsa_audio_pcm_capture_copy_user, -- .fill_silence = NULL, --#else -- .copy = mr_alsa_audio_pcm_capture_copy, -- .silence = NULL, //mr_alsa_audio_pcm_silence, --#endif - .page = snd_pcm_lib_get_vmalloc_page, - }; - diff --git a/3rdparty/patches/ravenna-alsa-lkm-add-codec-am824.patch b/3rdparty/patches/ravenna-alsa-lkm-add-codec-am824.patch deleted file mode 100644 index 7278a5b..0000000 --- a/3rdparty/patches/ravenna-alsa-lkm-add-codec-am824.patch +++ /dev/null @@ -1,163 +0,0 @@ -diff --git a/driver/MTConvert.c b/driver/MTConvert.c -index c94bc03..75063a1 100644 ---- a/driver/MTConvert.c -+++ b/driver/MTConvert.c -@@ -2097,6 +2097,95 @@ void MTConvertBigEndianInt24ToMappedInt32DeInterleave( void* input_buffer, - }*/ - - -+void MTConvertMappedInt32ToBigEndianInt32Interleave(void** input_buffer, -+ const uint32_t offset_input_buf, -+ void* output_buffer, -+ const uint32_t nb_channels, -+ const uint32_t nb_samples_in) -+{ -+ -+ uint32_t i, ch; -+ uint8_t* out = (uint8_t*)output_buffer; -+ const unsigned int stride_in = 4; -+ unsigned int in_pos = offset_input_buf * stride_in; -+ for(i = offset_input_buf; i < offset_input_buf + nb_samples_in; ++i) -+ { -+ if(Arch_is_big_endian()) -+ { -+ for(ch = 0; ch < nb_channels; ++ch) -+ { -+ const uint8_t* in = (uint8_t*)input_buffer[ch] + in_pos; -+ out[0] = in[0]; -+ out[1] = in[1]; -+ out[2] = in[2]; -+ out[3] = in[3]; -+ out += 4; -+ } -+ } -+ else -+ { -+ for(ch = 0; ch < nb_channels; ++ch) -+ { -+ const uint8_t* in = (uint8_t*)input_buffer[ch] + in_pos; -+ out[0] = in[3]; -+ out[1] = in[2]; -+ out[2] = in[1]; -+ out[3] = in[0]; -+ out += 4; -+ } -+ } -+ in_pos += stride_in; -+ } -+} -+ -+ -+ -+/////////////////////////////////////////////////////////////////////////////// -+// Convert from an interleave buffer to N non-interleave buffers -+// i.e. [A0.B0.A1.B1...A(dwNbOfSamplesByChannels-1).B(dwNbOfSamplesByChannels-1)] -> [A0..A(dwNbOfSamplesByChannels-1)][B0..B(dwNbOfSamplesByChannels-1)] -+void MTConvertBigEndianInt32ToMappedInt32DeInterleave( void* input_buffer, -+ void** output_buffer, -+ uint32_t offset_output_buf, -+ uint32_t nb_channels, -+ uint32_t nb_samples) -+{ -+ uint32_t i, ch; -+ const unsigned int stride_in = 4 * nb_channels, stride_out = 4; -+ const unsigned int out_pos = offset_output_buf * stride_out; -+ for(ch = 0; ch < nb_channels; ++ch) -+ { -+ uint8_t* in = (uint8_t*)input_buffer + 4 * ch; -+ uint8_t* out = (uint8_t*)output_buffer[ch] + out_pos; -+ -+ if(Arch_is_big_endian()) -+ { -+ for(i = 0; i < nb_samples; ++i) -+ { -+ out[0] = in[0]; -+ out[1] = in[1]; -+ out[2] = in[2]; -+ out[3] = in[3]; -+ -+ in += stride_in; -+ out += stride_out; -+ } -+ } -+ else -+ { -+ for(i = 0; i < nb_samples; ++i) -+ { -+ out[0] = in[3]; -+ out[1] = in[2]; -+ out[2] = in[1]; -+ out[3] = in[0]; -+ -+ in += stride_in; -+ out += stride_out; -+ } -+ } -+ } -+} -+ - - /////////////////////////////////////////////////////////////////////////////// - /////////////////////////////////////////////////////////////////////////////// -diff --git a/driver/MTConvert.h b/driver/MTConvert.h -index 54bc90e..483f1c6 100644 ---- a/driver/MTConvert.h -+++ b/driver/MTConvert.h -@@ -121,6 +121,8 @@ void MTConvertMappedInt24ToBigEndianInt24Interleave(void** ppi24Uninterleave, co - void MTConvertBigEndianInt24ToMappedInt24DeInterleave(void* pbyBigEndianInterleave, void** ppi24Uninterleave, uint32_t dwOffsetInUninterleaveBuffer, uint32_t dwNbOfChannels, uint32_t dwNbOfSamplesByChannels); - void MTConvertMappedInt32ToBigEndianInt24Interleave(void** ppi32Uninterleave, const uint32_t dwOffsetInUninterleaveBuffer, void* pbyBigEndianInterleave, const uint32_t dwNbOfChannels, const uint32_t dwNbOfSamplesByChannels); - void MTConvertBigEndianInt24ToMappedInt32DeInterleave(void* pbyBigEndianInterleave, void** ppi32Uninterleave, uint32_t dwOffsetInUninterleaveBuffer, uint32_t dwNbOfChannels, uint32_t dwNbOfSamplesByChannels); -+void MTConvertMappedInt32ToBigEndianInt32Interleave(void** ppi32Uninterleave, const uint32_t dwOffsetInUninterleaveBuffer, void* pbyBigEndianInterleave, const uint32_t dwNbOfChannels, const uint32_t dwNbOfSamplesByChannels); -+void MTConvertBigEndianInt32ToMappedInt32DeInterleave(void* pbyBigEndianInterleave, void** ppi32Uninterleave, uint32_t dwOffsetInUninterleaveBuffer, uint32_t dwNbOfChannels, uint32_t dwNbOfSamplesByChannels); - - // DSD - void MTConvertMappedFloatToBigEndianDSD64Interleave(void** ppfUninterleave, const uint32_t dwOffsetInUninterleaveBuffer, void* pvBigEndianInterleave, const uint32_t dwNbOfChannels, const uint32_t dwNbOfSamplesByChannels); -diff --git a/driver/RTP_audio_stream.c b/driver/RTP_audio_stream.c -index 5a160e4..403a51a 100644 ---- a/driver/RTP_audio_stream.c -+++ b/driver/RTP_audio_stream.c -@@ -170,6 +171,10 @@ int Create(TRTP_audio_stream* self, TRTP_stream_info* pRTP_stream_info, rtp_audi - { - self->m_pfnMTConvertMappedToInterleave = &MTConvertMappedInt32ToBigEndianInt24Interleave; - } -+ else if(strcmp(pRTP_stream_info->m_cCodec, "AM824") == 0) -+ { -+ self->m_pfnMTConvertMappedToInterleave = &MTConvertMappedInt32ToBigEndianInt32Interleave; -+ } - else if(strcmp(pRTP_stream_info->m_cCodec, "DSD64_32") == 0 || strcmp(pRTP_stream_info->m_cCodec, "DSD128_32") == 0 || strcmp(pRTP_stream_info->m_cCodec, "DSD256") == 0) - { - self->m_pfnMTConvertMappedToInterleave = &MTConvertMappedFloatToBigEndianDSD256Interleave; -@@ -300,6 +305,10 @@ int Create(TRTP_audio_stream* self, TRTP_stream_info* pRTP_stream_info, rtp_audi - { - self->m_pfnMTConvertInterleaveToMapped = &MTConvertBigEndianInt24ToMappedInt32DeInterleave; - } -+ else if(strcmp(pRTP_stream_info->m_cCodec, "AM824") == 0) -+ { -+ self->m_pfnMTConvertInterleaveToMapped = &MTConvertBigEndianInt32ToMappedInt32DeInterleave; -+ } - else - { - MTAL_DP("CRTP_audio_stream::Init: invalid Codec\n"); -diff --git a/driver/RTP_stream_info.c b/driver/RTP_stream_info.c -index ac65bbb..83ee967 100644 ---- a/driver/RTP_stream_info.c -+++ b/driver/RTP_stream_info.c -@@ -168,7 +168,7 @@ int is_valid(TRTP_stream_info* rtp_stream_info) - { - char* cCodec = rtp_stream_info->m_cCodec; - if (strcmp(cCodec, "L16") && strcmp(cCodec, "L24") && strcmp(cCodec, "L2432") -- && strcmp(cCodec, "DSD64_32") && strcmp(cCodec, "DSD128_32") -+ && strcmp(cCodec, "AM824") && strcmp(cCodec, "DSD64_32") && strcmp(cCodec, "DSD128_32") - && strcmp(cCodec, "DSD64") && strcmp(cCodec, "DSD128") && strcmp(cCodec, "DSD256")) - { - MTAL_DP("CRTP_stream_info::IsValid: wrong codec = %s\n", cCodec); -@@ -252,6 +252,10 @@ unsigned char get_codec_word_lenght(const char* cCodec) - { - return 4; - } -+ else if (strcmp(cCodec, "AM824") == 0) -+ { -+ return 4; -+ } - else if (strcmp(cCodec, "DSD64") == 0) - { - return 1; diff --git a/3rdparty/patches/ravenna-alsa-lkm-arm-32bit.patch b/3rdparty/patches/ravenna-alsa-lkm-arm-32bit.patch deleted file mode 100644 index 8a5fd00..0000000 --- a/3rdparty/patches/ravenna-alsa-lkm-arm-32bit.patch +++ /dev/null @@ -1,301 +0,0 @@ -diff --git a/driver/RTP_audio_stream.c b/driver/RTP_audio_stream.c -index 5a160e4..a5c84e4 100644 ---- a/driver/RTP_audio_stream.c -+++ b/driver/RTP_audio_stream.c -@@ -40,6 +40,7 @@ - - #include "RTP_audio_stream.h" - #include "MTAL_DP.h" -+#include "c_wrapper_lib.h" - - #define DEBUG_TRACE(x) MTAL_DP("[RTP Stream] "); MTAL_DP x - #define ASSERT(x) {if(!(x)) { MTAL_DP("Assert in %s line %i\n", __FILE__, __LINE__); }} -@@ -377,7 +378,7 @@ int Create(TRTP_audio_stream* self, TRTP_stream_info* pRTP_stream_info, rtp_audi - // if audio data format was changed we have to mute channels with the proper mute pattern; for now, we always mute - for(us = 0; us < pRTP_stream_info->m_byNbOfChannels; us++) - { -- //MTAL_DP("[%u] m_pvLivesInCircularBuffer[us] = 0x%x buffer length = %u wordlength = %u\n", us, m_pvLivesInCircularBuffer[us], pManager->get_live_in_jitter_buffer_length(pManager->user), m_usAudioEngineSampleWordLength); -+ //MTAL_DP("[%u] m_pvLivesInCircularBuffer[us] = 0x%x buffer length = %u wordlength = %u\n", us, self->m_pvLivesInCircularBuffer[us], pManager->get_live_in_jitter_buffer_length(pManager->user), self->m_usAudioEngineSampleWordLength); - - if(self->m_pvLivesInCircularBuffer[us]) - { // mute -@@ -413,7 +414,7 @@ int Destroy(TRTP_audio_stream* self) - unsigned short us; - for(us = 0; us < pRTP_stream_info->m_byNbOfChannels; us++) - { -- //MTAL_DP("[%u] m_pvLivesInCircularBuffer[us] = 0x%x buffer length = %u wordlength = %u\n", us, m_pvLivesInCircularBuffer[us], pManager->get_live_in_jitter_buffer_length(pManager->user), m_usAudioEngineSampleWordLength); -+ //MTAL_DP("[%u] m_pvLivesInCircularBuffer[us] = 0x%x buffer length = %u wordlength = %u\n", us, self->m_pvLivesInCircularBuffer[us], self->m_pManager->get_live_in_jitter_buffer_length(self->m_pManager->user), self->m_usAudioEngineSampleWordLength); - - if(self->m_pvLivesInCircularBuffer[us]) - { // mute -@@ -782,7 +783,7 @@ int ProcessRTPAudioPacket(TRTP_audio_stream* self, TRTPPacketBase* pRTPPacketBas - - //MTAL_DP("ui32RTPSAC %u perfcounter %I64u\n", ui32RTPSAC, MTAL_LK_GetCounterTime()); - // ui32UsedSAC is the first frame SAC when this packet will be used -- ui64UsedSAC = (ui64RTPSAC - (ui64RTPSAC % pManager->get_frame_size(pManager->user))); -+ ui64UsedSAC = (ui64RTPSAC - (CW_ll_modulo(ui64RTPSAC, pManager->get_frame_size(pManager->user)))); - - i64DeltaSAC = ui64UsedSAC - ui64GlobalSAC; - //MTAL_DP("i64DeltaSAC %I64u playout delay %u, frame size: %u\n", i64DeltaSAC, pRTP_stream_info->m_ui32PlayOutDelay, pManager->get_frame_size(pManager->user)); -diff --git a/driver/manager.c b/driver/manager.c -index 5a90eca..8023708 100644 ---- a/driver/manager.c -+++ b/driver/manager.c -@@ -1272,10 +1272,10 @@ uint32_t get_live_in_jitter_buffer_offset(void* user, const uint64_t ui64Current - struct TManager* self = (struct TManager*)user; - - #if defined(MT_TONE_TEST) || defined (MT_RAMP_TEST) || defined (MTLOOPBACK) || defined (MTTRANSPARENCY_CHECK) -- return (uint32_t)(ui64CurrentSAC % get_live_in_jitter_buffer_length(self)); -+ return (uint32_t)CW_ll_modulo(ui64CurrentSAC, get_live_in_jitter_buffer_length(self)); - #else - uint32_t live_in_jitter_buffer_length = self->m_alsa_driver_frontend->get_capture_buffer_size_in_frames(self->m_pALSAChip); -- return (uint32_t)(ui64CurrentSAC % live_in_jitter_buffer_length); -+ return (uint32_t)CW_ll_modulo(ui64CurrentSAC, live_in_jitter_buffer_length); - #endif - } - -@@ -1298,7 +1298,7 @@ uint32_t get_live_out_jitter_buffer_offset(void* user, const uint64_t ui64Curren - struct TManager* self = (struct TManager*)user; - - #if defined(MT_TONE_TEST) || defined (MT_RAMP_TEST) || defined (MTLOOPBACK) || defined (MTTRANSPARENCY_CHECK) -- return (uint32_t)(ui64CurrentSAC % get_live_out_jitter_buffer_length(self)); -+ return (uint32_t)CW_ll_modulo(ui64CurrentSAC, get_live_out_jitter_buffer_length(self)); - #else - uint32_t offset = self->m_alsa_driver_frontend->get_playback_buffer_offset(self->m_pALSAChip); - const uint32_t sacOffset = (uint32_t)(get_global_SAC(self) - get_frame_size(self) - ui64CurrentSAC); -@@ -1432,9 +1432,9 @@ void AudioFrameTIC(void* user) - { - #if defined(MT_TONE_TEST) - unsigned long p = (self->m_tone_test_phase * self->m_SampleRate) / LUTSampleRate; -- int16_t val16 = LUT[(p + 4 * chIdx) % LUTnbPoints]/* >> 1*/; -+ int16_t val16 = LUT[CW_ll_modulo((p + 4 * chIdx), LUTnbPoints)]/* >> 1*/; - int32_t val24 = val16 << 8; -- self->m_tone_test_phase = (self->m_tone_test_phase + 1) % (LUTnbPoints * 100); -+ self->m_tone_test_phase = CW_ll_modulo((self->m_tone_test_phase + 1), (LUTnbPoints * 100)); - #elif defined(MT_RAMP_TEST) - int32_t val24 = self->m_ramp_test_phase; - if(val24 >= 8388608) // 2^23 -diff --git a/driver/MTAL_DP.h b/driver/MTAL_DP.h -index 1f0fb89..8aeaba2 100644 ---- a/driver/MTAL_DP.h -+++ b/driver/MTAL_DP.h -@@ -129,26 +129,34 @@ - #include - #if LINUX_VERSION_CODE >= KERNEL_VERSION(3,10,0) - #include -- #define MTAL_DP(...) MTAL_LK_print(KERN_INFO __VA_ARGS__) -+ #define MTAL_DP(...) -+ //#define MTAL_DP(...) MTAL_LK_print(KERN_INFO __VA_ARGS__) - #define MTAL_DP_EMRG(...) MTAL_LK_print(KERN_EMERG __VA_ARGS__) - #define MTAL_DP_ALERT(...) MTAL_LK_print(KERN_ALERT __VA_ARGS__) - #define MTAL_DP_CRIT(...) MTAL_LK_print(KERN_CRIT __VA_ARGS__) - #define MTAL_DP_ERR(...) MTAL_LK_print(KERN_ERR __VA_ARGS__) - #define MTAL_DP_WARN(...) MTAL_LK_print(KERN_WARNING __VA_ARGS__) -- #define MTAL_DP_NOTICE(...) MTAL_LK_print(KERN_NOTICE __VA_ARGS__) -- #define MTAL_DP_INFO(...) MTAL_LK_print(KERN_INFO __VA_ARGS__) -- #define MTAL_DP_DEBUG(...) MTAL_LK_print(KERN_DEBUG __VA_ARGS__) -+ #define MTAL_DP_NOTICE(...) -+ //#define MTAL_DP_NOTICE(...) MTAL_LK_print(KERN_NOTICE __VA_ARGS__) -+ #define MTAL_DP_INFO(...) -+ //#define MTAL_DP_INFO(...) MTAL_LK_print(KERN_INFO __VA_ARGS__) -+ #define MTAL_DP_DEBUG(...) -+ //#define MTAL_DP_DEBUG(...) MTAL_LK_print(KERN_DEBUG __VA_ARGS__) - #else - //#include -- #define MTAL_DP(...) MTAL_LK_print(""__VA_ARGS__) -+ #define MTAL_DP(...) -+ //#define MTAL_DP(...) MTAL_LK_print(""__VA_ARGS__) - #define MTAL_DP_EMRG(...) MTAL_LK_print("<>"__VA_ARGS__) - #define MTAL_DP_ALERT(...) MTAL_LK_print("<1>"__VA_ARGS__) - #define MTAL_DP_CRIT(...) MTAL_LK_print("<2>"__VA_ARGS__) - #define MTAL_DP_ERR(...) MTAL_LK_print("<3>"__VA_ARGS__) - #define MTAL_DP_WARN(...) MTAL_LK_print("<4>"__VA_ARGS__) -- #define MTAL_DP_NOTICE(...) MTAL_LK_print("<5>"__VA_ARGS__) -- #define MTAL_DP_INFO(...) MTAL_LK_print("<6>"__VA_ARGS__) -- #define MTAL_DP_DEBUG(...) MTAL_LK_print("<7>"__VA_ARGS__) -+ #define MTAL_DP_NOTICE(...) -+ //#define MTAL_DP_NOTICE(...) MTAL_LK_print("<5>"__VA_ARGS__) -+ #define MTAL_DP_INFO(...) -+ //#define MTAL_DP_INFO(...) MTAL_LK_print("<6>"__VA_ARGS__) -+ #define MTAL_DP_DEBUG(...) -+ //#define MTAL_DP_DEBUG(...) MTAL_LK_print("<7>"__VA_ARGS__) - #endif - - -diff --git a/driver/MTConvert.c b/driver/MTConvert.c -index c94bc03..c9fdffe 100644 ---- a/driver/MTConvert.c -+++ b/driver/MTConvert.c -@@ -1318,10 +1318,10 @@ int MTConvertMappedInt32ToInt16LEInterleave(void** input_buffer, const uint32_t - { - const uint8_t* in = (uint8_t*)input_buffer[ch] + in_pos; - #if defined(MTAL_LINUX) && defined(MTAL_KERNEL) -- __put_user_x(1, in[1], (unsigned long __user *)out, ret_pu); -+ ret_pu = put_user(in[1], (unsigned char __user *)out); - ret |= ret_pu; - out++; -- __put_user_x(1, in[0], (unsigned long __user *)out, ret_pu); -+ ret_pu = put_user(in[0], (unsigned char __user *)out); - ret |= ret_pu; - out++; - #else -@@ -1358,10 +1358,10 @@ int MTConvertMappedInt32ToInt16LEInterleave(void** input_buffer, const uint32_t - { - const uint8_t* in = (uint8_t*)input_buffer[ch] + in_pos; - #if defined(MTAL_LINUX) && defined(MTAL_KERNEL) -- __put_user_x(1, in[2], (unsigned long __user *)out, ret_pu); -+ ret_pu = put_user(in[2], (unsigned char __user *)out); - ret |= ret_pu; - out++; -- __put_user_x(1, in[3], (unsigned long __user *)out, ret_pu); -+ ret_pu = put_user(in[3], (unsigned char __user *)out); - ret |= ret_pu; - out++; - #else -@@ -1411,13 +1411,13 @@ int MTConvertMappedInt32ToInt24LEInterleave(void** input_buffer, const uint32_t - { - const uint8_t* in = (uint8_t*)input_buffer[ch] + in_pos; - #if defined(MTAL_LINUX) && defined(MTAL_KERNEL) -- __put_user_x(1, in[2], (unsigned long __user *)out, ret_pu); -+ ret_pu = put_user(in[2], (unsigned char __user *)out); - ret |= ret_pu; - out++; -- __put_user_x(1, in[1], (unsigned long __user *)out, ret_pu); -+ ret_pu = put_user(in[1], (unsigned char __user *)out); - ret |= ret_pu; - out++; -- __put_user_x(1, in[0], (unsigned long __user *)out, ret_pu); -+ ret_pu = put_user(in[0], (unsigned char __user *)out); - ret |= ret_pu; - out++; - #else -@@ -1457,13 +1457,13 @@ int MTConvertMappedInt32ToInt24LEInterleave(void** input_buffer, const uint32_t - { - const uint8_t* in = (uint8_t*)input_buffer[ch] + in_pos; - #if defined(MTAL_LINUX) && defined(MTAL_KERNEL) -- __put_user_x(1, in[1], (unsigned long __user *)out, ret_pu); -+ ret_pu = put_user(in[1], (unsigned char __user *)out); - ret |= ret_pu; - out++; -- __put_user_x(1, in[2], (unsigned long __user *)out, ret_pu); -+ ret_pu = put_user(in[2], (unsigned char __user *)out); - ret |= ret_pu; - out++; -- __put_user_x(1, in[3], (unsigned long __user *)out, ret_pu); -+ ret_pu = put_user(in[3], (unsigned char __user *)out); - ret |= ret_pu; - out++; - #else -@@ -1516,16 +1516,16 @@ int MTConvertMappedInt32ToInt24LE4ByteInterleave(void** input_buffer, const uint - const uint8_t* in = (uint8_t*)input_buffer[ch] + in_pos; - #if defined(MTAL_LINUX) && defined(MTAL_KERNEL) - char zero = 0x00; -- __put_user_x(1, in[2], (unsigned long __user *)out, ret_pu); -+ ret_pu = put_user(in[2], (unsigned char __user *)out); - ret |= ret_pu; - out++; -- __put_user_x(1, in[1], (unsigned long __user *)out, ret_pu); -+ ret_pu = put_user(in[1], (unsigned char __user *)out); - ret |= ret_pu; - out++; -- __put_user_x(1, in[0], (unsigned long __user *)out, ret_pu); -+ ret_pu = put_user(in[0], (unsigned char __user *)out); - ret |= ret_pu; - out++; -- __put_user_x(1, zero, (unsigned long __user *)out, ret_pu); -+ ret_pu = put_user(zero, (unsigned char __user *)out); - ret |= ret_pu; - out++; - #else -@@ -1568,16 +1568,16 @@ int MTConvertMappedInt32ToInt24LE4ByteInterleave(void** input_buffer, const uint - const uint8_t* in = (uint8_t*)input_buffer[ch] + in_pos; - #if defined(MTAL_LINUX) && defined(MTAL_KERNEL) - char zero = 0x00; -- __put_user_x(1, in[1], (unsigned long __user *)out, ret_pu); -+ ret_pu = put_user(in[1], (unsigned char __user *)out); - ret |= ret_pu; - out++; -- __put_user_x(1, in[2], (unsigned long __user *)out, ret_pu); -+ ret_pu = put_user(in[2], (unsigned char __user *)out); - ret |= ret_pu; - out++; -- __put_user_x(1, in[3], (unsigned long __user *)out, ret_pu); -+ ret_pu = put_user(in[3], (unsigned char __user *)out); - ret |= ret_pu; - out++; -- __put_user_x(1, zero, (unsigned long __user *)out, ret_pu); -+ ret_pu = put_user(zero, (unsigned char __user *)out); - ret |= ret_pu; - out++; - #else -@@ -1600,16 +1600,16 @@ int MTConvertMappedInt32ToInt24LE4ByteInterleave(void** input_buffer, const uint - const uint8_t* in = (uint8_t*)input_buffer[ch] + in_pos; - #if defined(MTAL_LINUX) && defined(MTAL_KERNEL) - char zero = 0x00; -- __put_user_x(1, in[1], (unsigned long __user *)out, ret_pu); -+ ret_pu = put_user(in[1], (unsigned char __user *)out); - ret |= ret_pu; - out++; -- __put_user_x(1, in[2], (unsigned long __user *)out, ret_pu); -+ ret_pu = put_user(in[2], (unsigned char __user *)out); - ret |= ret_pu; - out++; -- __put_user_x(1, in[3], (unsigned long __user *)out, ret_pu); -+ ret_pu = put_user(in[3], (unsigned char __user *)out); - ret |= ret_pu; - out++; -- __put_user_x(1, zero, (unsigned long __user *)out, ret_pu); -+ ret_pu = put_user(zero, (unsigned char __user *)out); - ret |= ret_pu; - out++; - #else -@@ -1648,16 +1648,16 @@ int MTConvertMappedInt32ToInt32LEInterleave(void** input_buffer, const uint32_t - { - const uint8_t* in = (uint8_t*)input_buffer[ch] + in_pos; - #if defined(MTAL_LINUX) && defined(MTAL_KERNEL) -- __put_user_x(1, in[3], (unsigned long __user *)out, ret_pu); -+ ret_pu = put_user(in[3], (unsigned char __user *)out); - ret |= ret_pu; - out++; -- __put_user_x(1, in[2], (unsigned long __user *)out, ret_pu); -+ ret_pu = put_user(in[2], (unsigned char __user *)out); - ret |= ret_pu; - out++; -- __put_user_x(1, in[1], (unsigned long __user *)out, ret_pu); -+ ret_pu = put_user(in[1], (unsigned char __user *)out); - ret |= ret_pu; - out++; -- __put_user_x(1, in[0], (unsigned long __user *)out, ret_pu); -+ ret_pu = put_user(in[0], (unsigned char __user *)out); - ret |= ret_pu; - out++; - #else -@@ -1699,16 +1699,16 @@ int MTConvertMappedInt32ToInt32LEInterleave(void** input_buffer, const uint32_t - { - const uint8_t* in = (uint8_t*)input_buffer[ch] + in_pos; - #if defined(MTAL_LINUX) && defined(MTAL_KERNEL) -- __put_user_x(1, in[0], (unsigned long __user *)out, ret_pu); -+ ret_pu = put_user(in[0], (unsigned char __user *)out); - ret |= ret_pu; - out++; -- __put_user_x(1, in[1], (unsigned long __user *)out, ret_pu); -+ ret_pu = put_user(in[1], (unsigned char __user *)out); - ret |= ret_pu; - out++; -- __put_user_x(1, in[2], (unsigned long __user *)out, ret_pu); -+ ret_pu = put_user(in[2], (unsigned char __user *)out); - ret |= ret_pu; - out++; -- __put_user_x(1, in[3], (unsigned long __user *)out, ret_pu); -+ ret_pu = put_user(in[3], (unsigned char __user *)out); - ret |= ret_pu; - out++; - #else -@@ -1867,6 +1867,7 @@ void MTConvertBigEndianInt16ToMappedInt32DeInterleave( void* input_buffer, - uint32_t i, ch; - const unsigned int stride_in = 2 * nb_channels, stride_out = 4; - const unsigned int out_pos = offset_output_buf * stride_out; -+ - for(ch = 0; ch < nb_channels; ++ch) - { - uint8_t* in = (uint8_t*)input_buffer + 2 * ch; diff --git a/3rdparty/patches/ravenna-alsa-lkm-direct-pcm-transfer.patch b/3rdparty/patches/ravenna-alsa-lkm-direct-pcm-transfer.patch deleted file mode 100644 index 6c694ab..0000000 --- a/3rdparty/patches/ravenna-alsa-lkm-direct-pcm-transfer.patch +++ /dev/null @@ -1,982 +0,0 @@ -diff --git a/driver/audio_driver.c b/driver/audio_driver.c -index 3d9debd..3c3183e 100644 ---- a/driver/audio_driver.c -+++ b/driver/audio_driver.c -@@ -43,7 +43,6 @@ - #include - #include - #include --#include // for mmap - #include - #include - -@@ -77,11 +76,6 @@ static int index = SNDRV_DEFAULT_IDX1; /* Index 0-max */ - static char *id = SNDRV_DEFAULT_STR1; /* Id for card */ - static bool enable = SNDRV_DEFAULT_ENABLE1; /* Enable this card */ - static int pcm_devs = 1; --//static int pcm_substreams = 8; // todo --//#define MUTE_CHECK --#ifdef MUTE_CHECK --static bool playback_mute_detected = false; --#endif - - module_param(index, int, 0444); - MODULE_PARM_DESC(index, "Index value for " CARD_NAME " soundcard."); -@@ -112,7 +106,8 @@ static int mr_alsa_audio_pcm_capture_copy( struct snd_pcm_substream *substream, - static int mr_alsa_audio_pcm_capture_copy_internal( struct snd_pcm_substream *substream, - int channel, uint32_t pos, - void __user *src, -- snd_pcm_uframes_t count, bool to_user_space); -+ snd_pcm_uframes_t count, -+ bool to_user_space); - static int mr_alsa_audio_pcm_playback_copy( struct snd_pcm_substream *substream, - int channel, snd_pcm_uframes_t pos, - void __user *src, -@@ -120,10 +115,8 @@ static int mr_alsa_audio_pcm_playback_copy( struct snd_pcm_substream *substream, - static int mr_alsa_audio_pcm_playback_copy_internal( struct snd_pcm_substream *substream, - int channel, uint32_t pos, - void __user *src, -- snd_pcm_uframes_t count); --static int mr_alsa_audio_pcm_playback_silence( struct snd_pcm_substream *substream, -- int channel, snd_pcm_uframes_t pos, -- snd_pcm_uframes_t count); -+ snd_pcm_uframes_t count, -+ bool from_user_space); - - /// "chip" : the main private structure - struct mr_alsa_audio_chip -@@ -177,10 +170,14 @@ struct mr_alsa_audio_chip - struct snd_card *card; /* one card */ - struct snd_pcm *pcm; /* has one pcm */ - -- struct snd_pcm_indirect pcm_playback_indirect; -- atomic_t dma_playback_offset; // to be used with atomic_read, atomic_set -- struct snd_pcm_indirect pcm_capture_indirect; -- atomic_t dma_capture_offset; // to be used with atomic_read, atomic_set -+ uint32_t dma_playback_offset; -+ uint32_t dma_capture_offset; -+ -+ unsigned int pcm_playback_buffer_size; -+ unsigned int pcm_capture_buffer_size; -+ -+ uint8_t *dma_playback_buffer; -+ uint8_t *dma_capture_buffer; - }; - - -@@ -507,13 +504,28 @@ static void* mr_alsa_audio_get_playback_buffer(void *rawchip) - } - static uint32_t mr_alsa_audio_get_playback_buffer_size_in_frames(void *rawchip) - { -- if(rawchip) -+ uint32_t res = 0; -+ if (rawchip) - { -- struct mr_alsa_audio_chip *chip = (struct mr_alsa_audio_chip*)rawchip; -- if(chip->playback_buffer) -- return MR_ALSA_RINGBUFFER_NB_FRAMES; -+ struct mr_alsa_audio_chip* chip = (struct mr_alsa_audio_chip*)rawchip; -+ //spin_lock_irq(&chip->lock); -+ { -+ struct snd_pcm_runtime* runtime = chip->playback_substream ? chip->playback_substream->runtime : NULL; -+ if (chip->playback_buffer) -+ { -+ if (runtime && runtime->period_size != 0 && runtime->periods != 0) -+ { -+ res = chip->current_dsd ? MR_ALSA_RINGBUFFER_NB_FRAMES : runtime->period_size * runtime->periods; -+ } -+ else -+ { -+ res = MR_ALSA_RINGBUFFER_NB_FRAMES; -+ } -+ } -+ } -+ //spin_unlock_irq(&chip->lock); - } -- return 0; -+ return res; - - } - static void* mr_alsa_audio_get_capture_buffer(void *rawchip) -@@ -594,7 +606,8 @@ static int mr_alsa_audio_pcm_interrupt(void *rawchip, int direction) - uint32_t ring_buffer_size = MR_ALSA_RINGBUFFER_NB_FRAMES; // init to the max size possible - uint32_t ptp_frame_size; - struct mr_alsa_audio_chip *chip = (struct mr_alsa_audio_chip*)rawchip; -- spin_lock_irq(&chip->lock); -+ -+ spin_lock(&chip->lock); - chip->mr_alsa_audio_ops->get_interrupts_frame_size(chip->ravenna_peer, &ptp_frame_size); - if(direction == 1 && chip->capture_substream != NULL) - { -@@ -611,24 +624,22 @@ static int mr_alsa_audio_pcm_interrupt(void *rawchip, int direction) - runtime->access == SNDRV_PCM_ACCESS_MMAP_NONINTERLEAVED || - runtime->access == SNDRV_PCM_ACCESS_MMAP_COMPLEX) - { -- unsigned long bytes_to_frame_factor = runtime->channels * snd_pcm_format_physical_width(runtime->format) >> 3; -- unsigned int pcm_buffer_size = snd_pcm_lib_buffer_bytes(chip->capture_substream); -- unsigned int pos; -- uint32_t offset = 0; -- // char jitter_buffer_byte_len = 3; -- // chip->mr_alsa_audio_ops->get_jitter_buffer_sample_bytelength(chip->ravenna_peer, &jitter_buffer_byte_len); -- -- pos = atomic_read(&chip->dma_capture_offset); -- pos += ptp_frame_size * bytes_to_frame_factor; -- if (pos >= pcm_buffer_size) -+ unsigned long bytes_to_frame_factor = runtime->channels * chip->current_alsa_capture_stride; -+ -+ //printk(KERN_DEBUG "capture copy pos=%u, dma_pos=%u, count=%u, channels=%d pcm_size=%u\n", chip->capture_buffer_pos, pos, ptp_frame_size, runtime->channels, pcm_buffer_size); -+ mr_alsa_audio_pcm_capture_copy_internal(chip->capture_substream, runtime->channels/*channel*/, -+ chip->capture_buffer_pos, chip->dma_capture_buffer + chip->dma_capture_offset/**src*/, ptp_frame_size, false); -+ -+ chip->dma_capture_offset += ptp_frame_size * bytes_to_frame_factor; -+ if (chip->dma_capture_offset >= chip->pcm_capture_buffer_size) - { -- pos -= pcm_buffer_size; -+ chip->dma_capture_offset -= chip->pcm_capture_buffer_size; - } -- atomic_set(&chip->dma_capture_offset, pos); -- -- chip->mr_alsa_audio_ops->get_input_jitter_buffer_offset(chip->ravenna_peer, &offset); -- //printk(KERN_DEBUG "Interrupt Capture pos = %u \n", offset); - } -+ -+ chip->capture_buffer_pos += ptp_frame_size; -+ if(chip->capture_buffer_pos >= ring_buffer_size) -+ chip->capture_buffer_pos -= ring_buffer_size; - - /// Ravenna DSD always uses a rate of 352k with eventual zero padding to maintain a 32 bit alignment - /// while DSD in ALSA uses a continuous 8, 16 or 32 bit aligned stream with at 352k, 176k or 88k -@@ -636,7 +647,9 @@ static int mr_alsa_audio_pcm_interrupt(void *rawchip, int direction) - if(++chip->current_capture_interrupt_idx >= chip->nb_capture_interrupts_per_period) - { - chip->current_capture_interrupt_idx = 0; -+ spin_unlock(&chip->lock); - snd_pcm_period_elapsed(chip->capture_substream); -+ spin_lock(&chip->lock); - } - } - else if(direction == 0 && chip->playback_substream != NULL) -@@ -648,27 +661,27 @@ static int mr_alsa_audio_pcm_interrupt(void *rawchip, int direction) - printk(KERN_ERR "mr_alsa_audio_pcm_interrupt playback period_size*periods > MR_ALSA_RINGBUFFER_NB_FRAMES\n"); - return -2; - } -- -+ - /// DMA case - if (runtime->access == SNDRV_PCM_ACCESS_MMAP_INTERLEAVED || - runtime->access == SNDRV_PCM_ACCESS_MMAP_NONINTERLEAVED || - runtime->access == SNDRV_PCM_ACCESS_MMAP_COMPLEX) - { -- unsigned long bytes_to_frame_factor = runtime->channels * snd_pcm_format_physical_width(runtime->format) >> 3; -- unsigned int pcm_buffer_size = snd_pcm_lib_buffer_bytes(chip->playback_substream); -- unsigned int pos; -- -- pos = atomic_read(&chip->dma_playback_offset); -- pos += ptp_frame_size * bytes_to_frame_factor; -- if (pos >= pcm_buffer_size) -+ unsigned long bytes_to_frame_factor = runtime->channels * chip->current_alsa_playback_stride; -+ -+ //printk(KERN_DEBUG "playback copy pos=%u, dma_pos=%u, count=%u, channels=%d pcm_size=%u\n", chip->playback_buffer_pos, pos, ptp_frame_size, runtime->channels, pcm_buffer_size); -+ mr_alsa_audio_pcm_playback_copy_internal(chip->playback_substream, runtime->channels/*channel*/, -+ chip->playback_buffer_pos/*pos*/, chip->dma_playback_buffer + chip->dma_playback_offset/*src*/, ptp_frame_size/*count*/, false); -+ -+ chip->dma_playback_offset += ptp_frame_size * bytes_to_frame_factor; -+ if (chip->dma_playback_offset >= chip->pcm_playback_buffer_size) - { -- pos -= pcm_buffer_size; -+ chip->dma_playback_offset -= chip->pcm_playback_buffer_size; - } -- atomic_set(&chip->dma_playback_offset, pos); - } -- -+ - chip->playback_buffer_pos += ptp_frame_size; -- if(chip->playback_buffer_pos >= ring_buffer_size) -+ if (chip->playback_buffer_pos >= ring_buffer_size) - chip->playback_buffer_pos -= ring_buffer_size; - - /// Ravenna DSD always uses a rate of 352k with eventual zero padding to maintain a 32 bit alignment -@@ -678,10 +691,12 @@ static int mr_alsa_audio_pcm_interrupt(void *rawchip, int direction) - { - chip->playback_buffer_rav_sac += ptp_frame_size; - chip->current_playback_interrupt_idx = 0; -+ spin_unlock(&chip->lock); - snd_pcm_period_elapsed(chip->playback_substream); -+ spin_lock(&chip->lock); - } - } -- spin_unlock_irq(&chip->lock); -+ spin_unlock(&chip->lock); - return 0; - } - return -1; -@@ -914,18 +929,15 @@ static int mr_alsa_audio_pcm_prepare(struct snd_pcm_substream *substream) - /// Fill the additional delay between the packet output and the sound eared - chip->mr_alsa_audio_ops->get_playout_delay(chip->ravenna_peer, &runtime->delay); - -- // TODO: snd_pcm_format_set_silence(SNDRV_PCM_FORMAT_S24_3LE, chip->mr_alsa_audio_ops->, ) -- -- atomic_set(&chip->dma_playback_offset, 0); -- memset(&chip->pcm_playback_indirect, 0, sizeof(chip->pcm_playback_indirect)); -- chip->pcm_playback_indirect.hw_buffer_size = chip->pcm_playback_indirect.sw_buffer_size = snd_pcm_lib_buffer_bytes(substream); -+ chip->dma_playback_offset = 0; -+ chip->dma_playback_buffer = runtime->dma_area; -+ chip->pcm_playback_buffer_size = snd_pcm_lib_buffer_bytes(chip->playback_substream); - } - else if(substream->stream == SNDRV_PCM_STREAM_CAPTURE) - { - uint32_t offset = 0; - chip->mr_alsa_audio_ops->get_input_jitter_buffer_offset(chip->ravenna_peer, &offset); - -- - printk(KERN_DEBUG "mr_alsa_audio_pcm_prepare for capture stream\n"); - if(chip->ravenna_peer) - { -@@ -943,12 +955,10 @@ static int mr_alsa_audio_pcm_prepare(struct snd_pcm_substream *substream) - chip->capture_buffer_pos = offset; - chip->current_capture_interrupt_idx = 0; - chip->nb_capture_interrupts_per_period = ((runtime_dsd_mode != 0)? (MR_ALSA_PTP_FRAME_RATE_FOR_DSD / runtime->rate) : 1); -- // TODO: snd_pcm_format_set_silence - -- atomic_set(&chip->dma_capture_offset, 0); -- memset(&chip->pcm_capture_indirect, 0, sizeof(chip->pcm_capture_indirect)); -- chip->pcm_capture_indirect.hw_buffer_size = snd_pcm_lib_buffer_bytes(substream); -- chip->pcm_capture_indirect.sw_buffer_size = snd_pcm_lib_buffer_bytes(substream); -+ chip->dma_capture_offset = 0; -+ chip->dma_capture_buffer = runtime->dma_area; -+ chip->pcm_capture_buffer_size = snd_pcm_lib_buffer_bytes(chip->capture_substream); - } - } - else -@@ -970,6 +980,7 @@ static snd_pcm_uframes_t mr_alsa_audio_pcm_pointer(struct snd_pcm_substream *als - uint32_t offset = 0; - //printk("entering mr_alsa_audio_pcm_pointer (substream name=%s #%d) ...\n", alsa_sub->name, alsa_sub->number); - -+ spin_lock(&chip->lock); - if(alsa_sub->stream == SNDRV_PCM_STREAM_PLAYBACK) - { - /// DMA case -@@ -977,7 +988,9 @@ static snd_pcm_uframes_t mr_alsa_audio_pcm_pointer(struct snd_pcm_substream *als - alsa_sub->runtime->access == SNDRV_PCM_ACCESS_MMAP_NONINTERLEAVED || - alsa_sub->runtime->access == SNDRV_PCM_ACCESS_MMAP_COMPLEX) - { -- offset = snd_pcm_indirect_playback_pointer(alsa_sub, &chip->pcm_playback_indirect, atomic_read(&chip->dma_playback_offset)); -+ struct snd_pcm_runtime *runtime = alsa_sub->runtime; -+ unsigned long bytes_to_frame_factor = runtime->channels * chip->current_alsa_playback_stride; -+ offset = chip->dma_playback_offset / bytes_to_frame_factor; - } - else - { -@@ -1010,7 +1023,9 @@ static snd_pcm_uframes_t mr_alsa_audio_pcm_pointer(struct snd_pcm_substream *als - alsa_sub->runtime->access == SNDRV_PCM_ACCESS_MMAP_NONINTERLEAVED || - alsa_sub->runtime->access == SNDRV_PCM_ACCESS_MMAP_COMPLEX) - { -- offset = snd_pcm_indirect_capture_pointer(alsa_sub, &chip->pcm_capture_indirect, atomic_read(&chip->dma_capture_offset)); -+ struct snd_pcm_runtime *runtime = alsa_sub->runtime; -+ unsigned long bytes_to_frame_factor = runtime->channels * chip->current_alsa_capture_stride; -+ offset = chip->dma_capture_offset / bytes_to_frame_factor; - } - else - { -@@ -1036,6 +1051,7 @@ static snd_pcm_uframes_t mr_alsa_audio_pcm_pointer(struct snd_pcm_substream *als - } - //printk("mr_alsa_audio_pcm_pointer capture offset = %u\n", offset); - } -+ spin_unlock(&chip->lock); - return offset; - } - -@@ -1152,9 +1168,10 @@ static int mr_alsa_audio_pcm_capture_copy_user( struct snd_pcm_substream *subst - void __user *src, - unsigned long count) - { -+ struct mr_alsa_audio_chip* chip = snd_pcm_substream_chip(substream); - struct snd_pcm_runtime *runtime = substream->runtime; - bool interleaved = runtime->access == SNDRV_PCM_ACCESS_RW_INTERLEAVED ? 1 : 0; -- unsigned long bytes_to_frame_factor = runtime->channels * snd_pcm_format_physical_width(runtime->format) >> 3; -+ unsigned long bytes_to_frame_factor = runtime->channels * chip->current_alsa_capture_stride; - return mr_alsa_audio_pcm_capture_copy(substream, interleaved ? -1 : channel, pos / bytes_to_frame_factor, src, count / bytes_to_frame_factor); - } - #endif -@@ -1173,13 +1190,14 @@ static int mr_alsa_audio_pcm_capture_copy( struct snd_pcm_substream *substream, - static int mr_alsa_audio_pcm_capture_copy_internal( struct snd_pcm_substream *substream, - int channel, uint32_t pos, - void __user *src, -- snd_pcm_uframes_t count, bool to_user_space) -+ snd_pcm_uframes_t count, -+ bool to_user_space) - { - struct mr_alsa_audio_chip *chip = snd_pcm_substream_chip(substream); - struct snd_pcm_runtime *runtime = substream->runtime; -- int interleaved = ((channel == -1 && runtime->channels > 1)? 1 : 0); -+ bool interleaved = (runtime->access == SNDRV_PCM_ACCESS_RW_INTERLEAVED || runtime->access == SNDRV_PCM_ACCESS_MMAP_INTERLEAVED); - unsigned int nb_logical_bits = snd_pcm_format_width(runtime->format); -- unsigned int strideIn = snd_pcm_format_physical_width(runtime->format) >> 3; -+ unsigned int strideIn = chip->current_alsa_capture_stride; - uint32_t ravenna_buffer_pos = pos; - - // todo DSD capture -@@ -1204,12 +1222,7 @@ static int mr_alsa_audio_pcm_capture_copy_internal( struct snd_pcm_substream *s - - - if(interleaved) -- { -- int ret_pu; -- char val = 0xf1; -- __put_user_x(1, val, (unsigned long __user *)src, ret_pu); -- ret_pu = put_user(val, (unsigned long __user *)src); -- //put_user(val, (unsigned long __user *)src); -+ { - switch(nb_logical_bits) - { - case 16: -@@ -1244,8 +1257,8 @@ static int mr_alsa_audio_pcm_capture_copy_internal( struct snd_pcm_substream *s - return -EINVAL; - } - return count; -- - } -+ - /// This callback is called whenever the alsa application wants to write data - /// We use it here to do all the de-interleaving, format conversion and DSD re-packing - /// The intermediate buffer is actually the alsa (dma) buffer, allocated in hw_params() -@@ -1256,10 +1269,10 @@ static int mr_alsa_audio_pcm_playback_copy_user( struct snd_pcm_substream *subs - void __user *src, - unsigned long count) - { -+ struct mr_alsa_audio_chip* chip = snd_pcm_substream_chip(substream); - struct snd_pcm_runtime *runtime = substream->runtime; -- bool interleaved = runtime->access == SNDRV_PCM_ACCESS_RW_INTERLEAVED ? 1 : 0; -- unsigned long bytes_to_frame_factor = runtime->channels * snd_pcm_format_physical_width(runtime->format) >> 3; -- return mr_alsa_audio_pcm_playback_copy(substream, interleaved ? -1 : channel, pos / bytes_to_frame_factor, src, count / bytes_to_frame_factor); -+ unsigned long bytes_to_frame_factor = runtime->channels * chip->current_alsa_playback_stride; -+ return mr_alsa_audio_pcm_playback_copy(substream, channel, pos / bytes_to_frame_factor, src, count / bytes_to_frame_factor); - } - #endif - -@@ -1278,126 +1291,68 @@ static int mr_alsa_audio_pcm_playback_copy( struct snd_pcm_substream *substream, - /// so respective ring buffers might have different scale and size - uint32_t ravenna_buffer_pos = pos * chip->nb_playback_interrupts_per_period; - -- if(snd_BUG_ON(ravenna_buffer_pos >= MR_ALSA_RINGBUFFER_NB_FRAMES)) -- ravenna_buffer_pos -= MR_ALSA_RINGBUFFER_NB_FRAMES; -- -- return mr_alsa_audio_pcm_playback_copy_internal(substream, channel, ravenna_buffer_pos, src, count); -+ return mr_alsa_audio_pcm_playback_copy_internal(substream, channel, ravenna_buffer_pos, src, count, true); - } --/// -+ -+ - static int mr_alsa_audio_pcm_playback_copy_internal( struct snd_pcm_substream *substream, - int channel, uint32_t pos, - void __user *src, -- snd_pcm_uframes_t count) -+ snd_pcm_uframes_t count, -+ bool from_user_space) - { - struct mr_alsa_audio_chip *chip = snd_pcm_substream_chip(substream); - struct snd_pcm_runtime *runtime = substream->runtime; - int chn = 0; -- //int interleaved = ((channel == -1 && runtime->channels > 1)? 1 : 0); -- int interleaved = runtime->access == SNDRV_PCM_ACCESS_RW_INTERLEAVED || SNDRV_PCM_ACCESS_MMAP_INTERLEAVED ? 1 : 0; -+ bool interleaved = (runtime->access == SNDRV_PCM_ACCESS_RW_INTERLEAVED || runtime->access == SNDRV_PCM_ACCESS_MMAP_INTERLEAVED); - unsigned int nb_logical_bits = snd_pcm_format_width(runtime->format); -- unsigned int strideIn = snd_pcm_format_physical_width(runtime->format) >> 3; -+ unsigned int strideIn = chip->current_alsa_playback_stride; - unsigned int strideOut = snd_pcm_format_physical_width(SNDRV_PCM_FORMAT_S32_LE) >> 3; - uint32_t dsdrate = mr_alsa_audio_get_dsd_sample_rate(runtime->format, runtime->rate); - uint32_t dsdmode = (dsdrate > 0? mr_alsa_audio_get_dsd_mode(dsdrate) : 0); - uint32_t ravenna_buffer_pos = pos; -- //uint32_t alsa_ring_buffer_nb_frames = MR_ALSA_RINGBUFFER_NB_FRAMES / chip->nb_playback_interrupts_per_period; -- -- #ifdef MUTE_CHECK -- // mute check -- unsigned char *buffer_to_check = chip->playback_buffer + ravenna_buffer_pos * strideOut; // output buffer channel 0 -- bool mute_detected = false; -- char testblock [256]; -- memset(testblock, 0, sizeof(testblock)); -- #endif -- -- if (channel > 0 && channel >= runtime->channels) -- { -- printk(KERN_WARNING "Channel %d copy ignored because it does not fit the available runtime channels (%d)", channel, runtime->channels); -- return 0; -- } -- -- //printk(KERN_DEBUG "entering mr_alsa_audio_pcm_playback_copy (substream name=%s #%d) (runtime channels %d) access %d...\n", substream->name, substream->number, runtime->channels, runtime->access)); -- -- /*if(snd_BUG_ON(chip->playback_buffer_rav_sac > chip->playback_buffer_alsa_sac)) -- { -- printk(KERN_WARNING "mr_alsa_audio_pcm_playback_copy: Playback stall. Missing playback data from the player application."); -- return -EINVAL; -- } -- -- //printk("playback_copy: initial count = %u, alsa_ring_buffer_nb_frames = %u \n", count, alsa_ring_buffer_nb_frames); -- if(alsa_ring_buffer_nb_frames < chip->playback_buffer_alsa_sac - chip->playback_buffer_rav_sac) -- { -- count = 0; /// no room for more playback at the moment -- printk(KERN_WARNING "playback_copy: no room at the moment (count =%lu) \n", count); -- } -- -- if(count > alsa_ring_buffer_nb_frames - (chip->playback_buffer_alsa_sac - chip->playback_buffer_rav_sac)) -- { -- snd_pcm_uframes_t new_count = (snd_pcm_uframes_t)(alsa_ring_buffer_nb_frames - (chip->playback_buffer_alsa_sac - chip->playback_buffer_rav_sac)); -- printk(KERN_WARNING "playback_copy count overflow 1: change count from %lu to %lu\n", count, new_count); -- count = new_count; -- } -- if(count * chip->nb_playback_interrupts_per_period + ravenna_buffer_pos > MR_ALSA_RINGBUFFER_NB_FRAMES) -- { -- snd_pcm_uframes_t new_count = (MR_ALSA_RINGBUFFER_NB_FRAMES - ravenna_buffer_pos) / chip->nb_playback_interrupts_per_period; -- printk(KERN_WARNING "playback_copy count overflow 2: change count from %lu to %lu\n", count, new_count); -- count = new_count; -- }*/ - - //printk("playback_copy: rate = %u, dsdmode = %u, #IRQ per period = %u, count = %u, pos = %lu, ravenna_buffer_pos = %u, alsa_pb_sac = %llu, ravenna_pb_sac = %llu\n", (dsdrate > 0? dsdrate : runtime->rate), dsdmode, chip->nb_playback_interrupts_per_period, count, pos, ravenna_buffer_pos, chip->playback_buffer_alsa_sac, chip->playback_buffer_rav_sac); -- if(count == 0) -- return 0; - - if(interleaved) - { -+ /// de-interleaving -+ unsigned char *in, *out; -+ unsigned int stepIn = runtime->channels * strideIn; -+ unsigned int stepOut = strideOut * chip->nb_playback_interrupts_per_period; -+ uint32_t ring_buffer_size = MR_ALSA_RINGBUFFER_NB_FRAMES * strideOut; -+ //printk("playback_copy: de-interleaving %u frames, pos = %llu, ravenna_buffer_pos = %u, with strideIn = %u, strideOut = %u, stepIn = %u, stepOut = %u, ravBuffer_csize = %u \n", count, pos, ravenna_buffer_pos, strideIn, strideOut, stepIn, stepOut, (unsigned int)ravBuffer_csize); -+ -+ if (from_user_space) - { -- /// de-interleaving -- unsigned char *in, *out; -- unsigned int stepIn = runtime->channels * strideIn; -- unsigned int stepOut = strideOut * chip->nb_playback_interrupts_per_period; -- size_t ravBuffer_csize = MR_ALSA_RINGBUFFER_NB_FRAMES * strideOut; -- //printk("playback_copy: de-interleaving %u frames, pos = %llu, ravenna_buffer_pos = %u, with strideIn = %u, strideOut = %u, stepIn = %u, stepOut = %u, ravBuffer_csize = %u \n", count, pos, ravenna_buffer_pos, strideIn, strideOut, stepIn, stepOut, (unsigned int)ravBuffer_csize); -- for(chn = 0; chn < runtime->channels; ++chn) -+ for (chn = 0; chn < runtime->channels; ++chn) - { - uint32_t currentOutPos = ravenna_buffer_pos * strideOut; - snd_pcm_uframes_t frmCnt = 0; - in = (unsigned char*)src + chn * strideIn; -- out = chip->playback_buffer + chn * ravBuffer_csize + currentOutPos; -- -+ out = chip->playback_buffer + chn * ring_buffer_size + currentOutPos; -+ // - ///Conversion to Signed integer 32 bit LE -- for(frmCnt = 0; frmCnt < count; ++frmCnt) -+ for (frmCnt = 0; frmCnt < count; ++frmCnt) - { - /// assumes Little Endian - int32_t val = 0; -- if(dsdmode == 0) -+ if (dsdmode == 0) - { -- switch(nb_logical_bits) -+ switch (nb_logical_bits) - { -- case 16: -- //val = (((int32_t)(in[1]) << 8) | ((int32_t)(in[0]))) << 16; -- // OR -- //((unsigned char*)&val)[3] = in[1]; -- //((unsigned char*)&val)[2] = in[0]; -- // OR without intermediate copy_from_user buffer -- __get_user(((unsigned char*)&val)[3], &in[1]); -- __get_user(((unsigned char*)&val)[2], &in[0]); -- break; -- case 24: -- //val = (((int32_t)(in[2]) << 16) | ((int32_t)(in[1]) << 8) | ((int32_t)(in[0]))) << 8; -- // OR -- // ((unsigned char*)&val)[3] = in[2]; -- // ((unsigned char*)&val)[2] = in[1]; -- // ((unsigned char*)&val)[1] = in[0]; -- // OR without intermediate copy_from_user buffer -- __get_user(((unsigned char*)&val)[3], &in[2]); -- __get_user(((unsigned char*)&val)[2], &in[1]); -- __get_user(((unsigned char*)&val)[1], &in[0]); -- break; -- case 32: -- //val = *(int32_t*)(in); -- // OR without intermediate copy_from_user buffer -- __get_user(val, (int32_t*)in); -- break; -+ case 16: -+ __get_user(((unsigned char*)&val)[3], &in[1]); -+ __get_user(((unsigned char*)&val)[2], &in[0]); -+ break; -+ case 24: -+ __get_user(((unsigned char*)&val)[3], &in[2]); -+ __get_user(((unsigned char*)&val)[2], &in[1]); -+ __get_user(((unsigned char*)&val)[1], &in[0]); -+ break; -+ case 32: -+ __get_user(val, (int32_t*)in); -+ break; - } - *((int32_t*)out) = val; - } -@@ -1405,34 +1360,30 @@ static int mr_alsa_audio_pcm_playback_copy_internal( struct snd_pcm_substream *s - { - /// interleaved DSD stream to non interleaved 32 bit aligned blocks with 1/2/4 DSD bytes per 32 bit - uint32_t out_cnt; -- for(out_cnt = 0; out_cnt < chip->nb_playback_interrupts_per_period; ++out_cnt) -+ for (out_cnt = 0; out_cnt < chip->nb_playback_interrupts_per_period; ++out_cnt) - { -- switch(dsdmode) -+ switch (dsdmode) - { -- case 1: ///DSD64 -- //val = *(int32_t*)(in + out_cnt) & 0xFF; -- __get_user(((unsigned char*)&val)[0], &in[out_cnt]); -- break; -- case 2: ///DSD128 -- //val = (((int32_t)(in[2 * out_cnt + 1]) << 8) | ((int32_t)(in[2 * out_cnt]))) & 0xFFFF; -- __get_user(((unsigned char*)&val)[1], &in[2 * out_cnt + 1]); -- __get_user(((unsigned char*)&val)[0], &in[2 * out_cnt]); -- break; -- case 4: ///DSD256 -- //val = *(int32_t*)(in); -- // OR without intermediate copy_from_user buffer -- __get_user(val, (int32_t*)in); -- break; -+ case 1: ///DSD64 -+ __get_user(((unsigned char*)&val)[0], &in[out_cnt]); -+ break; -+ case 2: ///DSD128 -+ __get_user(((unsigned char*)&val)[1], &in[2 * out_cnt + 1]); -+ __get_user(((unsigned char*)&val)[0], &in[2 * out_cnt]); -+ break; -+ case 4: ///DSD256 -+ __get_user(val, (int32_t*)in); -+ break; - } - ((int32_t*)out)[out_cnt] = val; - } - } - - in += stepIn; -- if(currentOutPos + stepOut >= ravBuffer_csize) -+ if (currentOutPos + stepOut >= ring_buffer_size) - { - currentOutPos = 0; -- out = chip->playback_buffer + chn * ravBuffer_csize; -+ out = chip->playback_buffer + chn * ring_buffer_size; - } - else - { -@@ -1442,56 +1393,37 @@ static int mr_alsa_audio_pcm_playback_copy_internal( struct snd_pcm_substream *s - } - } - } -- } -- else -- { -+ else - { -- //printk("mr_alsa_audio_pcm_playback_copy: no de-interleaving, converting %u frames with strideIn = %u\n", count, strideIn); -- /// do the format conversion to the Ravenna Ring buffer -+ for (chn = 0; chn < runtime->channels; ++chn) - { -- unsigned char *in, *out; -- unsigned int stepIn = strideIn; -- unsigned int stepOut = strideOut * chip->nb_playback_interrupts_per_period; -- size_t ravBuffer_csize = MR_ALSA_RINGBUFFER_NB_FRAMES * strideOut; - uint32_t currentOutPos = ravenna_buffer_pos * strideOut; - snd_pcm_uframes_t frmCnt = 0; -- -- in = (unsigned char*)src; -- out = chip->playback_buffer + channel * ravBuffer_csize + currentOutPos; -- for(frmCnt = 0; frmCnt < count; ++frmCnt) -+ in = (unsigned char*)src + chn * strideIn; -+ out = chip->playback_buffer + chn * ring_buffer_size + currentOutPos; -+ // -+ ///Conversion to Signed integer 32 bit LE -+ for (frmCnt = 0; frmCnt < count; ++frmCnt) - { -- /// conversion to signed 32 bit integer LE - /// assumes Little Endian -- int32_t val = 0; -- if(dsdmode == 0) -+ int32_t val = 0; -+ if (dsdmode == 0) - { -- switch(nb_logical_bits) -+ switch (nb_logical_bits) - { -- case 16: -- //val = (((int32_t)(in[1]) << 8) | ((int32_t)(in[0]))) << 16; -- // OR -- //((unsigned char*)&val)[3] = in[1]; -- //((unsigned char*)&val)[2] = in[0]; -- // OR without intermediate copy_from_user buffer -- __get_user(((unsigned char*)&val)[3], &in[1]); -- __get_user(((unsigned char*)&val)[2], &in[0]); -- break; -- case 24: -- //val = (((int32_t)(in[2]) << 16) | ((int32_t)(in[1]) << 8) | ((int32_t)(in[0]))) << 8; -- // OR -- // ((unsigned char*)&val)[3] = in[2]; -- // ((unsigned char*)&val)[2] = in[1]; -- // ((unsigned char*)&val)[1] = in[0]; -- // OR without intermediate copy_from_user buffer -- __get_user(((unsigned char*)&val)[3], &in[2]); -- __get_user(((unsigned char*)&val)[2], &in[1]); -- __get_user(((unsigned char*)&val)[1], &in[0]); -- break; -- case 32: -- //val = *(int32_t*)(in); -- // OR without intermediate copy_from_user buffer -- __get_user(val, (int32_t*)in); -- break; -+ case 16: -+ -+ ((unsigned char*)&val)[3] = in[1]; -+ ((unsigned char*)&val)[2] = in[0]; -+ break; -+ case 24: -+ ((unsigned char*)&val)[3] = in[2]; -+ ((unsigned char*)&val)[2] = in[1]; -+ ((unsigned char*)&val)[1] = in[0]; -+ break; -+ case 32: -+ val = *(int32_t*)(in); -+ break; - } - *((int32_t*)out) = val; - } -@@ -1499,33 +1431,29 @@ static int mr_alsa_audio_pcm_playback_copy_internal( struct snd_pcm_substream *s - { - /// interleaved DSD stream to non interleaved 32 bit aligned blocks with 1/2/4 DSD bytes per 32 bit - uint32_t out_cnt; -- for(out_cnt = 0; out_cnt < chip->nb_playback_interrupts_per_period; ++out_cnt) -+ for (out_cnt = 0; out_cnt < chip->nb_playback_interrupts_per_period; ++out_cnt) - { -- switch(dsdmode) -+ switch (dsdmode) - { -- case 1: ///DSD64 -- //val = *(int32_t*)(in + out_cnt) & 0xFF; -- __get_user(((unsigned char*)&val)[0], &in[out_cnt]); -- break; -- case 2: ///DSD128 -- //val = (((int32_t)(in[2 * out_cnt + 1]) << 8) | ((int32_t)(in[2 * out_cnt]))) & 0xFFFF; -- __get_user(((unsigned char*)&val)[1], &in[2 * out_cnt + 1]); -- __get_user(((unsigned char*)&val)[0], &in[2 * out_cnt]); -- break; -- case 4: ///DSD256 -- //val = *(int32_t*)(in); -- // OR without intermediate copy_from_user buffer -- __get_user(val, (int32_t*)in); -- break; -+ case 1: ///DSD64 -+ val = *(int32_t*)(in + out_cnt) & 0xFF; -+ break; -+ case 2: ///DSD128 -+ val = (((int32_t)(in[2 * out_cnt + 1]) << 8) | ((int32_t)(in[2 * out_cnt]))) & 0xFFFF; -+ break; -+ case 4: ///DSD256 -+ val = *(int32_t*)(in); -+ break; - } - ((int32_t*)out)[out_cnt] = val; - } - } -+ - in += stepIn; -- if(currentOutPos + stepOut >= ravBuffer_csize) -+ if (currentOutPos + stepOut >= ring_buffer_size) - { - currentOutPos = 0; -- out = chip->playback_buffer + channel * ravBuffer_csize; -+ out = chip->playback_buffer + chn * ring_buffer_size; - } - else - { -@@ -1536,248 +1464,17 @@ static int mr_alsa_audio_pcm_playback_copy_internal( struct snd_pcm_substream *s - } - } - } -- -- -- #ifdef MUTE_CHECK -- // First channel check -- mute_detected = !memcmp(testblock, buffer_to_check, min((ssize_t )256, frames_to_bytes(runtime, count))); -- if (mute_detected != playback_mute_detected) -+ else - { -- if (mute_detected) -- printk(">>>>Playback buffer mute detected\n"); -- else -- printk(">>>>Playback buffer signal detected\n"); -- playback_mute_detected = mute_detected; -+ printk(KERN_WARNING "Uninterleaved Playback is not supported\n"); -+ return -EINVAL; - } -- #endif - - chip->playback_buffer_alsa_sac += count; - return count; - } - - --#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,13,0) --static int mr_alsa_audio_pcm_playback_fill_silence( struct snd_pcm_substream *substream, -- int channel, unsigned long pos, -- unsigned long count) --{ -- struct snd_pcm_runtime *runtime = substream->runtime; -- bool interleaved = runtime->access == SNDRV_PCM_ACCESS_RW_INTERLEAVED ? 1 : 0; -- unsigned long bytes_to_frame_factor = runtime->channels * snd_pcm_format_physical_width(runtime->format) >> 3; -- return mr_alsa_audio_pcm_playback_silence(substream, interleaved ? -1 : channel, pos / bytes_to_frame_factor, count / bytes_to_frame_factor); --} --#endif -- --static int mr_alsa_audio_pcm_playback_silence( struct snd_pcm_substream *substream, -- int channel, snd_pcm_uframes_t pos, -- snd_pcm_uframes_t count) --{ -- struct mr_alsa_audio_chip *chip = snd_pcm_substream_chip(substream); -- struct snd_pcm_runtime *runtime = substream->runtime; -- unsigned char *out; -- int interleaved = ((channel == -1 && runtime->channels > 1)? 1 : 0); -- //unsigned int strideIn = snd_pcm_format_physical_width(runtime->format) >> 3; -- unsigned int strideOut = snd_pcm_format_physical_width(SNDRV_PCM_FORMAT_S32_LE) >> 3; -- size_t ravBuffer_csize = MR_ALSA_RINGBUFFER_NB_FRAMES * strideOut; -- const unsigned char def_sil_pat[8] = {0,0,0,0,0,0,0,0}; -- const unsigned char *sil_pat = snd_pcm_format_silence_64(runtime->format); -- const uint32_t dsd_pattern = 0x55555555; -- uint32_t dsdrate = mr_alsa_audio_get_dsd_sample_rate(runtime->format, runtime->rate); -- uint32_t dsdmode = (dsdrate > 0? mr_alsa_audio_get_dsd_mode(dsdrate) : 0); -- -- /// Ravenna DSD always uses a rate of 352k with eventual zero padding to maintain a 32 bit alignment -- /// while DSD in ALSA uses a continuous 8, 16 or 32 bit aligned stream with at 352k, 176k or 88k -- /// so respective ring buffers might have different scale and size -- pos *= chip->nb_playback_interrupts_per_period; -- -- printk(KERN_DEBUG "mr_alsa_audio_pcm_playback_silence called for %lu frames at pos %lu\n", count, pos); -- -- if(sil_pat == NULL) -- sil_pat = &def_sil_pat[0]; -- -- if(interleaved) -- { -- /// mute all channels directly in the Ravenna Ring Buffer -- unsigned int samples = count; -- int chn = 0; -- for(chn = 0; chn < runtime->channels; ++chn) -- { -- out = chip->playback_buffer + chn * ravBuffer_csize + pos * strideOut; -- if(dsdmode == 0) -- { -- switch (strideOut) -- { -- case 2: -- while (samples--) { -- memcpy(out, sil_pat, 2); -- out += 2; -- } -- break; -- case 3: -- while (samples--) { -- memcpy(out, sil_pat, 3); -- out += 3; -- } -- break; -- case 4: -- while (samples--) { -- memcpy(out, sil_pat, 4); -- out += 4; -- } -- break; -- } -- } -- else -- { -- uint32_t dsdmute = dsd_pattern; -- switch(dsdmode) -- { -- case 1: ///DSD64 -- dsdmute = (dsd_pattern & 0xFF); -- break; -- case 2: ///DSD128 -- dsdmute = (dsd_pattern & 0xFFFF); -- break; -- } -- while (samples--) -- { -- memcpy(out, &dsdmute, strideOut); -- out += strideOut; -- } -- } -- } -- } -- else -- { -- /// mute the specified channel in the Ravenna Ring Buffer -- unsigned int samples = count; -- out = chip->playback_buffer + channel * ravBuffer_csize + pos * strideOut; -- if(dsdmode == 0) -- { -- switch (strideOut) -- { -- case 2: -- while (samples--) { -- memcpy(out, sil_pat, 2); -- out += 2; -- } -- break; -- case 3: -- while (samples--) { -- memcpy(out, sil_pat, 3); -- out += 3; -- } -- break; -- case 4: -- while (samples--) { -- memcpy(out, sil_pat, 4); -- out += 4; -- } -- break; -- } -- } -- else -- { -- uint32_t dsdmute = dsd_pattern; -- switch(dsdmode) -- { -- case 1: ///DSD64 -- dsdmute = (dsd_pattern & 0xFF); -- break; -- case 2: ///DSD128 -- dsdmute = (dsd_pattern & 0xFFFF); -- break; -- } -- while (samples--) -- { -- memcpy(out, &dsdmute, strideOut); -- out += strideOut; -- } -- } -- } -- return count; --} -- --static void mr_alsa_audio_pcm_capture_ack_transfer(struct snd_pcm_substream *substream, struct snd_pcm_indirect *rec, size_t bytes) --{ -- struct snd_pcm_runtime *runtime = substream->runtime; -- struct mr_alsa_audio_chip *chip = snd_pcm_substream_chip(substream); -- unsigned long bytes_to_frame_factor = runtime->channels * snd_pcm_format_physical_width(runtime->format) >> 3; -- uint32_t ring_buffer_size = MR_ALSA_RINGBUFFER_NB_FRAMES; // init to the max size possible -- uint32_t pos = chip->capture_buffer_pos; -- -- char jitter_buffer_byte_len = 3; -- chip->mr_alsa_audio_ops->get_jitter_buffer_sample_bytelength(chip->ravenna_peer, &jitter_buffer_byte_len); -- -- ring_buffer_size = chip->current_dsd ? MR_ALSA_RINGBUFFER_NB_FRAMES : runtime->period_size * runtime->periods; -- -- //printk(KERN_DEBUG "Transfer Capture pos = %u, size = %zu (ring_buffer_size = %u, bytes_to_frame_factor = %zu, jitter_buffer_byte_len = %d)\n", pos, bytes, ring_buffer_size, bytes_to_frame_factor, jitter_buffer_byte_len); -- -- chip->capture_buffer_pos += bytes / bytes_to_frame_factor; -- if (chip->capture_buffer_pos >= ring_buffer_size) -- { -- // unsigned long end_bytes = ring_buffer_size - pos; -- // unsigned long start_bytes = bytes - end_bytes; -- -- // mr_alsa_audio_pcm_capture_copy_internal(chip->capture_substream, -- // runtime->access == SNDRV_PCM_ACCESS_MMAP_INTERLEAVED ? -1 : runtime->channels/*channel*/, -- // pos, runtime->dma_area + rec->sw_data/**src*/, (end_bytes * jitter_buffer_byte_len) / bytes_to_frame_factor); -- -- // mr_alsa_audio_pcm_capture_copy_internal(chip->capture_substream, -- // runtime->access == SNDRV_PCM_ACCESS_MMAP_INTERLEAVED ? -1 : runtime->channels/*channel*/, -- // 0, runtime->dma_area + rec->sw_data + end_bytes, (start_bytes * jitter_buffer_byte_len) / bytes_to_frame_factor); -- -- // memset(runtime->dma_area + rec->sw_data, 0x00, bytes); -- -- chip->capture_buffer_pos -= ring_buffer_size; -- if (chip->capture_buffer_pos != 0) -- printk(KERN_WARNING "Capture tranfer buffer wrapping to implement"); -- } -- //else -- { -- mr_alsa_audio_pcm_capture_copy_internal(chip->capture_substream, -- runtime->access == SNDRV_PCM_ACCESS_MMAP_INTERLEAVED ? -1 : runtime->channels/*channel*/, -- pos, runtime->dma_area + rec->sw_data/**src*/, bytes / bytes_to_frame_factor, false); -- } --} -- --static void mr_alsa_audio_pcm_playback_ack_transfer(struct snd_pcm_substream *substream, struct snd_pcm_indirect *rec, size_t bytes) --{ -- struct snd_pcm_runtime *runtime = substream->runtime; -- struct mr_alsa_audio_chip *chip = snd_pcm_substream_chip(substream); -- unsigned long bytes_to_frame_factor = runtime->channels * snd_pcm_format_physical_width(runtime->format) >> 3; -- -- mr_alsa_audio_pcm_playback_copy_internal(chip->playback_substream, -- runtime->access == SNDRV_PCM_ACCESS_MMAP_INTERLEAVED ? -1 : runtime->channels/*channel*/, -- chip->playback_buffer_pos/*pos*/, runtime->dma_area + rec->sw_data/**src*/, bytes / bytes_to_frame_factor/*count*/); --} -- --static int mr_alsa_audio_pcm_ack(struct snd_pcm_substream *substream) --{ -- struct mr_alsa_audio_chip *chip = snd_pcm_substream_chip(substream); -- -- if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) -- { -- struct snd_pcm_indirect *pcm_indirect = &chip->pcm_playback_indirect; -- #if LINUX_VERSION_CODE >= KERNEL_VERSION(5,2,0) -- return snd_pcm_indirect_playback_transfer(substream, pcm_indirect, mr_alsa_audio_pcm_playback_ack_transfer); -- #else -- snd_pcm_indirect_playback_transfer(substream, pcm_indirect, mr_alsa_audio_pcm_playback_ack_transfer); -- return 0; -- #endif -- } -- else if (substream->stream == SNDRV_PCM_STREAM_CAPTURE) -- { -- struct snd_pcm_indirect *pcm_indirect = &chip->pcm_capture_indirect; -- #if LINUX_VERSION_CODE >= KERNEL_VERSION(5,2,0) -- return snd_pcm_indirect_capture_transfer(substream, pcm_indirect, mr_alsa_audio_pcm_capture_ack_transfer); -- #else -- snd_pcm_indirect_capture_transfer(substream, pcm_indirect, mr_alsa_audio_pcm_capture_ack_transfer); -- return 0; -- #endif -- } -- return 0; --} - - /// hw_params callback - /// This is called when the hardware parameter (hw_params) is set up by the application, that is, once when -@@ -2339,14 +2032,10 @@ static struct snd_pcm_ops mr_alsa_audio_pcm_playback_ops = { - .pointer = mr_alsa_audio_pcm_pointer, - #if LINUX_VERSION_CODE >= KERNEL_VERSION(4,13,0) - .copy_user = mr_alsa_audio_pcm_playback_copy_user, -- //.copy_kernel = mr_alsa_audio_pcm_playback_copy, -- .fill_silence = mr_alsa_audio_pcm_playback_fill_silence, - #else - .copy = mr_alsa_audio_pcm_playback_copy, -- .silence = mr_alsa_audio_pcm_playback_silence, - #endif - .page = snd_pcm_lib_get_vmalloc_page, -- .ack = mr_alsa_audio_pcm_ack, - }; - - ///////////////////////////////////////////////////////////////////////////////////// -@@ -2361,14 +2050,12 @@ static struct snd_pcm_ops mr_alsa_audio_pcm_capture_ops = { - .pointer = mr_alsa_audio_pcm_pointer, - #if LINUX_VERSION_CODE >= KERNEL_VERSION(4,13,0) - .copy_user = mr_alsa_audio_pcm_capture_copy_user, -- //.copy_kernel = mr_alsa_audio_pcm_capture_copy, - .fill_silence = NULL, - #else - .copy = mr_alsa_audio_pcm_capture_copy, - .silence = NULL, //mr_alsa_audio_pcm_silence, - #endif - .page = snd_pcm_lib_get_vmalloc_page, -- .ack = mr_alsa_audio_pcm_ack, - }; - - -@@ -2786,4 +2473,4 @@ void mr_alsa_audio_card_exit(void) - g_ravenna_peer = NULL; - g_mr_alsa_audio_ops = NULL; - printk(KERN_INFO "leaving mr_alsa_audio_card_exit..\n"); --} -\ No newline at end of file -+} diff --git a/3rdparty/patches/ravenna-alsa-lkm-disable-ptp-checksum.patch b/3rdparty/patches/ravenna-alsa-lkm-disable-ptp-checksum.patch deleted file mode 100644 index 054a3d9..0000000 --- a/3rdparty/patches/ravenna-alsa-lkm-disable-ptp-checksum.patch +++ /dev/null @@ -1,19 +0,0 @@ -diff --git a/driver/PTP.c b/driver/PTP.c ---- a/driver/PTP.c -+++ b/driver/PTP.c -@@ -306,6 +306,7 @@ EDispatchResult process_PTP_packet(TClock_PTP* self, TUDPPacketBase* pUDPPacketB - } - - // verify checksum -+#if 0 - if (pUDPPacketBase->UDPHeader.usCheckSum != 0) - { - uint16_t ui16CheckSum = MTAL_ComputeUDPChecksum(&pPTPPacketBase->UDPHeader, MTAL_SWAP16(pUDPPacketBase->UDPHeader.usLen), (unsigned short*)&pPTPPacketBase->IPV4Header.ui32SrcIP, (unsigned short*)&pPTPPacketBase->IPV4Header.ui32DestIP); -@@ -319,6 +320,7 @@ EDispatchResult process_PTP_packet(TClock_PTP* self, TUDPPacketBase* pUDPPacketB - return DR_PACKET_ERROR; - } - } -+#endif - - //DumpPTPV2MsgHeader(&pPTPPacketBase->V2MsgHeader); - diff --git a/3rdparty/patches/ravenna-alsa-lkm-enable-loopback.patch b/3rdparty/patches/ravenna-alsa-lkm-enable-loopback.patch deleted file mode 100644 index 497c148..0000000 --- a/3rdparty/patches/ravenna-alsa-lkm-enable-loopback.patch +++ /dev/null @@ -1,13 +0,0 @@ -diff --git a/driver/module_interface.c b/driver/module_interface.c -index 5f924f9..be0663b 100644 ---- a/driver/module_interface.c -+++ b/driver/module_interface.c -@@ -94,7 +94,7 @@ unsigned int nf_hook_func(unsigned int hooknum, struct sk_buff *skb, const struc - if (ip_header->saddr == 0x0100007f) // 127.0.0.1 - { - //printk(KERN_INFO "Loopback address detected\n"); -- return NF_ACCEPT; -+ //return NF_ACCEPT; - } - - diff --git a/3rdparty/patches/ravenna-alsa-lkm-enable-mono-channels.patch b/3rdparty/patches/ravenna-alsa-lkm-enable-mono-channels.patch deleted file mode 100644 index fd6f67d..0000000 --- a/3rdparty/patches/ravenna-alsa-lkm-enable-mono-channels.patch +++ /dev/null @@ -1,23 +0,0 @@ -diff --git a/driver/audio_driver.c b/driver/audio_driver.c -index 3d9debd..339327b 100644 ---- a/driver/audio_driver.c -+++ b/driver/audio_driver.c -@@ -1106,7 +1130,7 @@ static struct snd_pcm_hardware mr_alsa_audio_pcm_hardware_playback = - .rates = (SNDRV_PCM_RATE_KNOT|SNDRV_PCM_RATE_44100|SNDRV_PCM_RATE_48000|SNDRV_PCM_RATE_88200|SNDRV_PCM_RATE_96000|SNDRV_PCM_RATE_176400|SNDRV_PCM_RATE_192000), - .rate_min = 44100, - .rate_max = 384000, -- .channels_min = 2, -+ .channels_min = 1, - .channels_max = MR_ALSA_NB_CHANNELS_MAX, - .buffer_bytes_max = MR_ALSA_RINGBUFFER_NB_FRAMES * MR_ALSA_NB_CHANNELS_MAX * 4, // 4 bytes per sample, 128 ch - .period_bytes_min = MR_ALSA_NB_FRAMES_PER_PERIOD_AT_1FS * 2 * 3, // amount of data in bytes for 8 channels, 24bit samples, at 1Fs -@@ -1135,7 +1159,7 @@ static struct snd_pcm_hardware mr_alsa_audio_pcm_hardware_capture = - .rates = (SNDRV_PCM_RATE_KNOT|SNDRV_PCM_RATE_44100|SNDRV_PCM_RATE_48000|SNDRV_PCM_RATE_88200|SNDRV_PCM_RATE_96000|SNDRV_PCM_RATE_176400|SNDRV_PCM_RATE_192000), - .rate_min = 44100, - .rate_max = 384000, -- .channels_min = 2, -+ .channels_min = 1, - .channels_max = MR_ALSA_NB_CHANNELS_MAX, - .buffer_bytes_max = MR_ALSA_RINGBUFFER_NB_FRAMES * MR_ALSA_NB_CHANNELS_MAX * 4, // 4 bytes per sample, 128 ch - .period_bytes_min = MR_ALSA_NB_FRAMES_PER_PERIOD_AT_1FS * 2 * 4, // amount of data in bytes for 8 channels, 24bit samples, at 1Fs - diff --git a/3rdparty/patches/ravenna-alsa-lkm-fixes.patch b/3rdparty/patches/ravenna-alsa-lkm-fixes.patch deleted file mode 100644 index ba0b646..0000000 --- a/3rdparty/patches/ravenna-alsa-lkm-fixes.patch +++ /dev/null @@ -1,82 +0,0 @@ -diff --git a/common/MergingRAVENNACommon.h b/common/MergingRAVENNACommon.h -index f26368d..a21f4a7 100644 ---- a/common/MergingRAVENNACommon.h -+++ b/common/MergingRAVENNACommon.h -@@ -78,8 +78,8 @@ - #define DEFAULT_AUDIOMODE MergingRAVENNACommon::AM_PCM - #define DEFAULT_AUDIODATAFORMAT MergingRAVENNACommon::ADF_PCM - #define DEFAULT_ZONE MergingRAVENNACommon::Z_8_HP --#define DEFAULT_NUMBEROFINPUTS 8 --#define DEFAULT_NUMBEROFOUTPUTS 8 -+#define DEFAULT_NUMBEROFINPUTS 64 -+#define DEFAULT_NUMBEROFOUTPUTS 64 - #define DEFAULT_FOLLOWDOPDETECTION true - - #ifdef DSD256_at_705k6 -diff --git a/driver/PTP.c b/driver/PTP.c -index 4b2242a..1bf593a 100644 ---- a/driver/PTP.c -+++ b/driver/PTP.c -@@ -90,7 +90,7 @@ uint32_t get_FS(uint32_t ui32SamplingRate) - return 2; - default: - // TODO: should assert -- MTAL_DP("Caudio_streamer_clock::get_FS error: unknown SamplingRate = %u\n", ui32SamplingRate); -+ //MTAL_DP("Caudio_streamer_clock::get_FS error: unknown SamplingRate = %u\n", ui32SamplingRate); - case 48000: - case 44100: - return 1; -@@ -110,7 +110,7 @@ uint32_t get_samplerate_base(uint32_t ui32SamplingRate) - - default: - // TODO: should assert -- MTAL_DP("Caudio_streamer_clock::get_samplerate_base error: unknown SamplingRate = %u\n", ui32SamplingRate); -+ //MTAL_DP("Caudio_streamer_clock::get_samplerate_base error: unknown SamplingRate = %u\n", ui32SamplingRate); - case 352800: - case 176400: - case 88200: -diff --git a/driver/module_netlink.c b/driver/module_netlink.c -index 48de263..dcdcce0 100644 ---- a/driver/module_netlink.c -+++ b/driver/module_netlink.c -@@ -158,7 +158,7 @@ void recv_reply_from_user_land(struct sk_buff *skb) - // check if the given size if sufficient to copy the answered data - if (response_from_user_land->dataSize >= msg->dataSize) - { -- if (response_from_user_land->data == NULL) -+ if (response_from_user_land->data != NULL) - { - memcpy(response_from_user_land->data, msg->data, msg->dataSize); - } -diff --git a/driver/MTAL_stdint.h b/driver/MTAL_stdint.h -index 3ccc109..2f11a58 100644 ---- a/driver/MTAL_stdint.h -+++ b/driver/MTAL_stdint.h -@@ -64,9 +64,9 @@ - } - #endif // __cplusplus - #include -- #define new NEW -+ //#define new NEW - #include -- #undef new -+ //#undef new - #else - #include - #endif -diff --git a/driver/RTP_stream_info.c b/driver/RTP_stream_info.c -index ac65bbb..a65994f 100644 ---- a/driver/RTP_stream_info.c -+++ b/driver/RTP_stream_info.c -@@ -32,9 +32,9 @@ - #include "MTAL_TargetPlatform.h" - - #if (defined(MTAL_LINUX) && defined(MTAL_KERNEL)) -- #define new NEW -+ //#define new NEW - #include -- #undef new -+ //#undef new - #else - #include - #endif diff --git a/3rdparty/patches/ravenna-alsa-lkm-independent-playback-capture.patch b/3rdparty/patches/ravenna-alsa-lkm-independent-playback-capture.patch deleted file mode 100644 index 3f369a4..0000000 --- a/3rdparty/patches/ravenna-alsa-lkm-independent-playback-capture.patch +++ /dev/null @@ -1,276 +0,0 @@ -diff --git a/driver/audio_driver.c b/driver/audio_driver.c -index 3d9debd..169348b 100644 ---- a/driver/audio_driver.c -+++ b/driver/audio_driver.c -@@ -824,13 +824,13 @@ static int mr_alsa_audio_pcm_trigger(struct snd_pcm_substream *alsa_sub, int cmd - n = snd_pcm_playback_hw_avail(runtime); - n += runtime->delay; - } -- chip->mr_alsa_audio_ops->start_interrupts(chip->ravenna_peer); -+ chip->mr_alsa_audio_ops->start_interrupts(chip->ravenna_peer, alsa_sub->stream == SNDRV_PCM_STREAM_PLAYBACK); - return 0; - - case SNDRV_PCM_TRIGGER_STOP: - case SNDRV_PCM_TRIGGER_PAUSE_PUSH: - case SNDRV_PCM_TRIGGER_SUSPEND: -- chip->mr_alsa_audio_ops->stop_interrupts(chip->ravenna_peer); -+ chip->mr_alsa_audio_ops->stop_interrupts(chip->ravenna_peer, alsa_sub->stream == SNDRV_PCM_STREAM_PLAYBACK); - return 0; - default: - return -EINVAL; -@@ -870,15 +885,19 @@ static int mr_alsa_audio_pcm_prepare(struct snd_pcm_substream *substream) - { - if(runtime_dsd_mode != chip->current_dsd) - { -- chip->mr_alsa_audio_ops->stop_interrupts(chip->ravenna_peer); -+ chip->mr_alsa_audio_ops->stop_interrupts(chip->ravenna_peer, substream->stream == SNDRV_PCM_STREAM_PLAYBACK); -+ spin_unlock_irq(&chip->lock); - err = chip->mr_alsa_audio_ops->set_sample_rate(chip->ravenna_peer, runtime_dsd_rate); -+ spin_lock_irq(&chip->lock); - } - } - else if(chip->current_rate != runtime->rate) - { -- chip->mr_alsa_audio_ops->stop_interrupts(chip->ravenna_peer); -+ chip->mr_alsa_audio_ops->stop_interrupts(chip->ravenna_peer, substream->stream == SNDRV_PCM_STREAM_PLAYBACK); - //printk("\n### mr_alsa_audio_pcm_prepare: mr_alsa_audio_ops->set_sample_rate to %u\n", runtime->rate); -+ spin_unlock_irq(&chip->lock); - err = chip->mr_alsa_audio_ops->set_sample_rate(chip->ravenna_peer, runtime->rate); -+ spin_lock_irq(&chip->lock); - //printk("### mr_alsa_audio_pcm_prepare: mr_alsa_audio_ops->set_sample_rate returned %d\n\n", err); - } - -@@ -1825,14 +1526,18 @@ static int mr_alsa_audio_pcm_hw_params( struct snd_pcm_substream *substream, - { - if(dsd_mode != chip->current_dsd) - { -- chip->mr_alsa_audio_ops->stop_interrupts(chip->ravenna_peer); -+ chip->mr_alsa_audio_ops->stop_interrupts(chip->ravenna_peer, substream->stream == SNDRV_PCM_STREAM_PLAYBACK); -+ spin_unlock_irq(&chip->lock); - err = chip->mr_alsa_audio_ops->set_sample_rate(chip->ravenna_peer, dsd_rate); -+ spin_lock_irq(&chip->lock); - } - } - else if(rate != chip->current_rate) - { -- chip->mr_alsa_audio_ops->stop_interrupts(chip->ravenna_peer); -+ chip->mr_alsa_audio_ops->stop_interrupts(chip->ravenna_peer, substream->stream == SNDRV_PCM_STREAM_PLAYBACK); -+ spin_unlock_irq(&chip->lock); - err = chip->mr_alsa_audio_ops->set_sample_rate(chip->ravenna_peer, rate); -+ spin_lock_irq(&chip->lock); - } - - if(chip->ravenna_peer) -diff --git a/driver/manager.c b/driver/manager.c -index 25b77dc..ec62624 100644 ---- a/driver/manager.c -+++ b/driver/manager.c -@@ -133,6 +133,8 @@ bool init(struct TManager* self, int* errorCode) - self->m_bIORunning = false; - self->m_pALSAChip = NULL; - self->m_alsa_driver_frontend = NULL; -+ self->m_bIsPlaybackIO = false; -+ self->m_bIsRecordingIO = false; - - memset(self->m_cInterfaceName, 0, MAX_INTERFACE_NAME); - -@@ -249,8 +251,10 @@ bool start(struct TManager* self) - bool stop(struct TManager* self) - { - MTAL_DP("entering CManager::stop..\n"); -- if(self->m_bIORunning) -- stopIO(self); -+ if(self->m_bIORunning) { -+ stopIO(self, false); -+ stopIO(self, true); -+ } - EnableEtherTube(&self->m_EthernetFilter, 0); - - StopAudioFrameTICTimer(&self->m_PTP); -@@ -261,14 +265,23 @@ bool stop(struct TManager* self) - } - - ////////////////////////////////////////////////////////////////////////////////// --bool startIO(struct TManager* self) -+bool startIO(struct TManager* self, bool is_playback) - { - if(!self->m_bIsStarted) - return false; -+ - MTAL_DP("MergingRAVENNAAudioDriver::startIO\n"); - -- MuteInputBuffer(self); -- MuteOutputBuffer(self); -+ if (!is_playback) { -+ printk(KERN_DEBUG "starting capture I/O\n"); -+ MuteInputBuffer(self); -+ self->m_bIsRecordingIO = true; -+ } -+ else { -+ printk(KERN_DEBUG "starting playback I/O\n"); -+ MuteOutputBuffer(self); -+ self->m_bIsPlaybackIO = true; -+ } - - #if defined(MT_TONE_TEST) - self->m_tone_test_phase = 0; -@@ -283,12 +296,27 @@ bool startIO(struct TManager* self) - } - - ////////////////////////////////////////////////////////////////////////////////// --bool stopIO(struct TManager* self) -+bool stopIO(struct TManager* self, bool is_playback) - { - MTAL_DP("MergingRAVENNAAudioDriver::stopIO\n"); -- self->m_bIORunning = false; -- MuteInputBuffer(self); -- MuteOutputBuffer(self); -+ -+ if (is_playback && !self->m_bIsPlaybackIO) -+ return true; -+ if (!is_playback && !self->m_bIsRecordingIO) -+ return true; -+ -+ if (!is_playback) { -+ printk(KERN_DEBUG "stopping capture I/O\n"); -+ MuteInputBuffer(self); -+ self->m_bIsRecordingIO = false; -+ } else { -+ printk(KERN_DEBUG "stopping playback I/O\n"); -+ MuteOutputBuffer(self); -+ self->m_bIsPlaybackIO = false; -+ } -+ -+ self->m_bIORunning = self->m_bIsRecordingIO || self->m_bIsPlaybackIO; -+ - return true; - } - -@@ -613,7 +641,8 @@ void OnNewMessage(struct TManager* self, struct MT_ALSA_msg* msg_rcv) - case MT_ALSA_Msg_StartIO: - { - MTAL_DP("CManager::OnNewMessage MT_ALSA_Msg_StartIO..\n"); -- if (!startIO(self)) -+ /* -+ if (!startIO(self) ) - { - MTAL_DP("CManager::OnNewMessage MT_ALSA_Msg_StartIO.. failed\n"); - msg_reply.errCode = -401; -@@ -623,11 +652,14 @@ void OnNewMessage(struct TManager* self, struct MT_ALSA_msg* msg_rcv) - MTAL_DP("CManager::OnNewMessage MT_ALSA_Msg_StartIO.. succeeded\n"); - msg_reply.errCode = 0; - } -+ */ -+ msg_reply.errCode = -401; - break; - } - case MT_ALSA_Msg_StopIO: - { - MTAL_DP("CManager::OnNewMessage MT_ALSA_Msg_StopIO..\n"); -+ /* - if (!stopIO(self)) - { - MTAL_DP("CManager::OnNewMessage MT_ALSA_Msg_StopIO.. failed\n"); -@@ -638,6 +670,8 @@ void OnNewMessage(struct TManager* self, struct MT_ALSA_msg* msg_rcv) - MTAL_DP("CManager::OnNewMessage MT_ALSA_Msg_StopIO.. succeeded\n"); - msg_reply.errCode = 0; - } -+ */ -+ msg_reply.errCode = -401; - break; - } - case MT_ALSA_Msg_SetSampleRate: -@@ -1468,8 +1502,10 @@ void AudioFrameTIC(void* user) - frame_process_begin(&self->m_RTP_streams_manager); - if(self->m_pALSAChip && self->m_alsa_driver_frontend) - { -- self->m_alsa_driver_frontend->pcm_interrupt(self->m_pALSAChip, 1); -- self->m_alsa_driver_frontend->pcm_interrupt(self->m_pALSAChip, 0); -+ if (self->m_bIsRecordingIO) -+ self->m_alsa_driver_frontend->pcm_interrupt(self->m_pALSAChip, 1); -+ if (self->m_bIsPlaybackIO) -+ self->m_alsa_driver_frontend->pcm_interrupt(self->m_pALSAChip, 0); - } - frame_process_end(&self->m_RTP_streams_manager); - #endif -@@ -1680,20 +1714,25 @@ int get_interrupts_frame_size(void* user, uint32_t *framesize) - return -EINVAL; - } - --int start_interrupts(void* user) -+int start_interrupts(void* user, bool is_playback) - { - struct TManager* self = (struct TManager*)user; -- if(startIO(self)) -+ -+ MTAL_DP("entering CManager::start_interrupts..\n"); -+ if(startIO(self, is_playback)) { - return 0; -+ } - return -1; - } - --int stop_interrupts(void* user) -+int stop_interrupts(void* user, bool is_playback) - { - struct TManager* self = (struct TManager*)user; -+ - MTAL_DP("entering CManager::stop_interrupts..\n"); -- if(stopIO(self)) -+ if (stopIO(self, is_playback)) { - return 0; -+ } - return -1; - } - -diff --git a/driver/manager.h b/driver/manager.h -index a5b2fc2..3306bc9 100644 ---- a/driver/manager.h -+++ b/driver/manager.h -@@ -86,6 +86,9 @@ struct TManager - int32_t m_nPlayoutDelay; - int32_t m_nCaptureDelay; - -+ bool m_bIsPlaybackIO; -+ bool m_bIsRecordingIO; -+ - volatile bool m_bIsStarted; - volatile bool m_bIORunning; - -@@ -144,8 +147,8 @@ void destroy(struct TManager* self); - bool start(struct TManager* self); - bool stop(struct TManager* self); - --bool startIO(struct TManager* self); --bool stopIO(struct TManager* self); -+bool startIO(struct TManager* self, bool is_playback); -+bool stopIO(struct TManager* self, bool is_playback); - - bool SetInterfaceName(struct TManager* self, const char* cInterfaceName); - bool SetSamplingRate(struct TManager* self, uint32_t SamplingRate); -@@ -242,8 +245,8 @@ int get_nb_inputs(void* user, uint32_t *nb_Channels); - int get_nb_outputs(void* user, uint32_t *nb_Channels); - int get_playout_delay(void* user, snd_pcm_sframes_t *delay_in_sample); - int get_capture_delay(void* user, snd_pcm_sframes_t *delay_in_sample); --int start_interrupts(void* user); --int stop_interrupts(void* user); -+int start_interrupts(void* user, bool is_playback); -+int stop_interrupts(void* user, bool is_playback); - int notify_master_volume_change(void* user, int direction, int32_t value); - int notify_master_switch_change(void* user, int direction, int32_t value); - int get_master_volume_value(void* user, int direction, int32_t* value); -diff --git a/driver/audio_driver.h b/driver/audio_driver.h -index 930e429..3f2c76d 100644 ---- a/driver/audio_driver.h -+++ b/driver/audio_driver.h -@@ -74,8 +74,8 @@ struct alsa_ops - int (*get_nb_outputs)(void* ravenna_peer, uint32_t *nb_channels); - int (*get_playout_delay)(void* ravenna_peer, snd_pcm_sframes_t *delay_in_sample); - int (*get_capture_delay)(void* ravenna_peer, snd_pcm_sframes_t *delay_in_sample); -- int (*start_interrupts)(void* ravenna_peer); /// starts IO -- int (*stop_interrupts)(void* ravenna_peer); /// stops IO -+ int (*start_interrupts)(void* ravenna_peer, bool is_playback); /// starts IO -+ int (*stop_interrupts)(void* ravenna_peer, bool is_playback); /// stops IO - - int (*notify_master_volume_change)(void* ravenna_peer, int direction, int32_t value); /// direction: 0 for playback, 1 for capture. value: from -99 to 0 - int (*notify_master_switch_change)(void* ravenna_peer, int direction, int32_t value); /// direction: 0 for playback, 1 for capture. value: 0 for mute, 1 for enable diff --git a/3rdparty/patches/ravenna-alsa-lkm-init-play-capture-buffers.patch b/3rdparty/patches/ravenna-alsa-lkm-init-play-capture-buffers.patch deleted file mode 100644 index c06e5f0..0000000 --- a/3rdparty/patches/ravenna-alsa-lkm-init-play-capture-buffers.patch +++ /dev/null @@ -1,22 +0,0 @@ -diff --git a/driver/audio_driver.c b/driver/audio_driver.c -index 3d9debd..339327b 100644 ---- a/driver/audio_driver.c -+++ b/driver/audio_driver.c -@@ -2441,7 +2142,7 @@ static int mr_alsa_audio_preallocate_memory(struct mr_alsa_audio_chip *chip) - printk(KERN_ERR "mr_alsa_audio_preallocate_memory: could not allocate playback buffer (%zd bytes vmalloc requested...\n", wanted); - goto _failed; - } -- -+ memset(chip->playback_buffer, 0, wanted); - - wanted = mr_alsa_audio_pcm_hardware_capture.buffer_bytes_max; // MR_ALSA_RINGBUFFER_NB_FRAMES * MR_ALSA_NB_CHANNELS_MAX * 4; - -@@ -2452,6 +2153,7 @@ static int mr_alsa_audio_preallocate_memory(struct mr_alsa_audio_chip *chip) - printk(KERN_ERR "mr_alsa_audio_preallocate_memory: could not allocate capture buffer (%zd bytes vmalloc requested...\n", wanted); - goto _failed; - } -+ memset(chip->capture_buffer, 0, wanted); - for (i = 0; i < MR_ALSA_NB_CHANNELS_MAX; i++) - { - chip->capture_buffer_channels_map[i] = (void*)chip->capture_buffer + MR_ALSA_RINGBUFFER_NB_FRAMES * i * 4; - diff --git a/3rdparty/patches/ravenna-alsa-lkm-kernel-v5.patch b/3rdparty/patches/ravenna-alsa-lkm-kernel-v5.patch deleted file mode 100644 index 856b837..0000000 --- a/3rdparty/patches/ravenna-alsa-lkm-kernel-v5.patch +++ /dev/null @@ -1,148 +0,0 @@ -diff --git a/driver/module_timer.c b/driver/module_timer.c -index 5f64a8e..158d5ee 100644 ---- a/driver/module_timer.c -+++ b/driver/module_timer.c -@@ -35,12 +35,61 @@ - #include "module_main.h" - #include "module_timer.h" - --static struct tasklet_hrtimer my_hrtimer_; -+#if LINUX_VERSION_CODE >= KERNEL_VERSION(5,0,0) -+struct tasklet_hrtimer { -+ struct hrtimer timer; -+ struct tasklet_struct tasklet; -+ enum hrtimer_restart (*function)(struct hrtimer *); -+}; -+ -+static inline -+void tasklet_hrtimer_cancel(struct tasklet_hrtimer *ttimer) -+{ -+ hrtimer_cancel(&ttimer->timer); -+ tasklet_kill(&ttimer->tasklet); -+} -+ -+static enum hrtimer_restart __hrtimer_tasklet_trampoline(struct hrtimer *timer) -+{ -+ struct tasklet_hrtimer *ttimer = -+ container_of(timer, struct tasklet_hrtimer, timer); -+ tasklet_hi_schedule(&ttimer->tasklet); -+ return HRTIMER_NORESTART; -+} -+ -+static void __tasklet_hrtimer_trampoline(unsigned long data) -+{ -+ struct tasklet_hrtimer *ttimer = (void *)data; -+ enum hrtimer_restart restart; -+ restart = ttimer->function(&ttimer->timer); -+ if (restart != HRTIMER_NORESTART) -+ hrtimer_restart(&ttimer->timer); -+} -+ -+void tasklet_hrtimer_init(struct tasklet_hrtimer *ttimer, -+ enum hrtimer_restart (*function)(struct hrtimer *), -+ clockid_t which_clock, enum hrtimer_mode mode) -+{ -+ hrtimer_init(&ttimer->timer, which_clock, mode); -+ ttimer->timer.function = __hrtimer_tasklet_trampoline; -+ tasklet_init(&ttimer->tasklet, __tasklet_hrtimer_trampoline, -+ (unsigned long)ttimer); -+ ttimer->function = function; -+} -+ -+static inline -+void tasklet_hrtimer_start(struct tasklet_hrtimer *ttimer, ktime_t time, -+ const enum hrtimer_mode mode) -+{ -+ hrtimer_start(&ttimer->timer, time, mode); -+} -+#endif -+ - static uint64_t base_period_; - static uint64_t max_period_allowed; - static uint64_t min_period_allowed; - static int stop_; -- -+static struct tasklet_hrtimer my_hrtimer_; - - enum hrtimer_restart timer_callback(struct hrtimer *timer) - { -@@ -57,15 +106,15 @@ enum hrtimer_restart timer_callback(struct hrtimer *timer) - - if (now > next_wakeup) - { -- printk(KERN_INFO "Timer won't sleep, clock_timer is recall instantly\n"); -+ //printk(KERN_INFO "Timer won't sleep, clock_timer is recall instantly\n"); - period = ktime_set(0, 0); - } - else if (ktime_to_ns(period) > max_period_allowed || ktime_to_ns(period) < min_period_allowed) - { -- printk(KERN_INFO "Timer period out of range: %lld [ms]. Target period = %lld\n", ktime_to_ns(period) / 1000000, base_period_ / 1000000); -+ //printk(KERN_INFO "Timer period out of range: %lld [ms]. Target period = %lld\n", ktime_to_ns(period) / 1000000, base_period_ / 1000000); - if (ktime_to_ns(period) > (unsigned long)5E9L) - { -- printk(KERN_ERR "Timer period greater than 5s, set it to 1s!\n"); -+ //printk(KERN_ERR "Timer period greater than 5s, set it to 1s!\n"); - period = ktime_set(0,((unsigned long)1E9L)); //1s - } - } -@@ -80,8 +129,8 @@ enum hrtimer_restart timer_callback(struct hrtimer *timer) - ///ret_overrun = hrtimer_forward(timer, kt_now, period); - ret_overrun = hrtimer_forward_now(timer, period); - // comment it when running in VM -- if(ret_overrun > 1) -- printk(KERN_INFO "Timer overrun ! (%d times)\n", ret_overrun); -+ /*if(ret_overrun > 1) -+ printk(KERN_INFO "Timer overrun ! (%d times)\n", ret_overrun);*/ - return HRTIMER_RESTART; - - } -@@ -89,15 +138,10 @@ enum hrtimer_restart timer_callback(struct hrtimer *timer) - int init_clock_timer(void) - { - stop_ = 0; -- ///hrtimer_init(&my_hrtimer_, CLOCK_MONOTONIC, HRTIMER_MODE_ABS); -- tasklet_hrtimer_init(&my_hrtimer_, timer_callback, CLOCK_MONOTONIC/*_RAW*/, HRTIMER_MODE_PINNED/*HRTIMER_MODE_ABS*/); -- ///my_hrtimer_.function = &timer_callback; -- -+ tasklet_hrtimer_init(&my_hrtimer_, timer_callback, CLOCK_MONOTONIC/*_RAW*/, HRTIMER_MODE_ABS /*HRTIMER_MODE_PINNED*/); - //base_period_ = 100 * ((unsigned long)1E6L); // 100 ms - base_period_ = 1333333; // 1.3 ms - set_base_period(base_period_); -- -- //start_clock_timer(); //used when no daemon - return 0; - } - -@@ -108,24 +152,14 @@ void kill_clock_timer(void) - - int start_clock_timer(void) - { -- ktime_t period = ktime_set(0, base_period_); //100 ms -+ ktime_t period = ktime_set(0, base_period_); - tasklet_hrtimer_start(&my_hrtimer_, period, HRTIMER_MODE_ABS); -- - return 0; - } - - void stop_clock_timer(void) - { -- - tasklet_hrtimer_cancel(&my_hrtimer_); -- /*int ret_cancel = 0; -- while(hrtimer_callback_running(&my_hrtimer_)) -- ++ret_cancel; -- -- if(hrtimer_active(&my_hrtimer_) != 0) -- ret_cancel = hrtimer_cancel(&my_hrtimer_); -- if (hrtimer_is_queued(&my_hrtimer_) != 0) -- ret_cancel = hrtimer_cancel(&my_hrtimer_);*/ - } - - void get_clock_time(uint64_t* clock_time) -@@ -145,4 +179,4 @@ void set_base_period(uint64_t base_period) - min_period_allowed = base_period_ / 7; - max_period_allowed = (base_period_ * 10) / 6; - printk(KERN_INFO "Base period set to %lld ns\n", base_period_); --} -\ No newline at end of file -+} diff --git a/build.sh b/build.sh index be3554a..1f4a22d 100755 --- a/build.sh +++ b/build.sh @@ -11,23 +11,8 @@ TOPDIR=$(pwd) cd 3rdparty if [ ! -d ravenna-alsa-lkm.git ]; then - git clone https://bitbucket.org/MergingTechnologies/ravenna-alsa-lkm.git - cd ravenna-alsa-lkm - git checkout 35c708f3747474130790cf508c064360a9589ac8 - echo "Apply patches to ravenna-alsa-lkm module ..." - git apply ../patches/ravenna-alsa-lkm-kernel-v5.patch - git apply ../patches/ravenna-alsa-lkm-enable-loopback.patch - git apply ../patches/ravenna-alsa-lkm-fixes.patch - git apply ../patches/ravenna-alsa-lkm-arm-32bit.patch - git apply ../patches/ravenna-alsa-lkm-add-codec-am824.patch - git apply ../patches/ravenna-alsa-lkm-disable-ptp-checksum.patch - git apply ../patches/ravenna-alsa-lkm-independent-playback-capture.patch - git apply ../patches/ravenna-alsa-lkm-direct-pcm-transfer.patch - git apply ../patches/ravenna-alsa-lkm-enable-mono-channels.patch - git apply ../patches/ravenna-alsa-lkm-init-play-capture-buffers.patch - git apply ../patches/ravenna-alsa-fix-playback-rw-mode.patch - echo "Building ravenna-alsa-lkm kernel module ..." - cd driver + git clone --single-branch --branch aes67-daemon https://github.com/bondagit/ravenna-alsa-lkm.git + cd ravenna-alsa-lkm/driver make cd ../.. fi