ALSA: buffer size override hack
authorGrazvydas Ignotas <notasas@gmail.com>
Sun, 14 Sep 2014 13:50:06 +0000 (16:50 +0300)
committerGrazvydas Ignotas <notasas@gmail.com>
Mon, 15 Sep 2014 21:44:31 +0000 (00:44 +0300)
bsp managed to get very low latency audio in his program
even with smaller buffers than FIFO size, so allow to override it.
Not removing limits for everything by default as that breaks many programs..

include/sound/pcm.h
sound/core/pcm_native.c
sound/soc/omap/omap-mcbsp.c

index 0cf91b2..9b4b888 100644 (file)
@@ -366,6 +366,12 @@ struct snd_pcm_group {             /* keep linked substreams */
 
 struct pid;
 
+struct snd_pnd_hack_params {
+       unsigned int frames_min;
+       unsigned int frames_max;
+       unsigned int reserved[14];
+};
+
 struct snd_pcm_substream {
        struct snd_pcm *pcm;
        struct snd_pcm_str *pstr;
@@ -413,6 +419,8 @@ struct snd_pcm_substream {
 #endif
        /* misc flags */
        unsigned int hw_opened: 1;
+       /* pandora hack */
+       struct snd_pnd_hack_params pnd_hack_params;
 };
 
 #define SUBSTREAM_BUSY(substream) ((substream)->ref_count > 0)
index 638600b..650afef 100644 (file)
@@ -2585,6 +2585,15 @@ static int snd_pcm_common_ioctl1(struct file *file,
                snd_pcm_stream_unlock_irq(substream);
                return res;
        }
+       case _IOW('A', 0xfe, struct snd_pnd_hack_params):
+       {
+               /* pandora HACK */
+               if (copy_from_user(&substream->pnd_hack_params, arg,
+                   sizeof(substream->pnd_hack_params)))
+                       return -EFAULT;
+               printk(KERN_INFO "%s hack set\n", __func__);
+               return 0;
+       }
        }
        snd_printd("unknown ioctl = 0x%x\n", cmd);
        return -ENOTTY;
index f7ee0e8..308339f 100644 (file)
@@ -59,6 +59,8 @@ struct omap_mcbsp_data {
        unsigned int                    in_freq;
        int                             clk_div;
        int                             wlen;
+       /* pandora hack */
+       struct snd_pcm_substream        *substream;
 };
 
 static struct omap_mcbsp_data mcbsp_data[NUM_LINKS];
@@ -110,6 +112,7 @@ static int omap_mcbsp_hwrule_min_buffersize(struct snd_pcm_hw_params *params,
        struct snd_interval *channels = hw_param_interval(params,
                                        SNDRV_PCM_HW_PARAM_CHANNELS);
        struct omap_mcbsp_data *mcbsp_data = rule->private;
+       struct snd_pcm_substream *substream = mcbsp_data->substream;
        struct snd_interval frames;
        int size;
 
@@ -118,6 +121,15 @@ static int omap_mcbsp_hwrule_min_buffersize(struct snd_pcm_hw_params *params,
 
        frames.min = size / channels->min;
        frames.integer = 1;
+
+       if (substream && substream->pnd_hack_params.frames_min > 0
+           && substream->pnd_hack_params.frames_max
+              >= substream->pnd_hack_params.frames_min)
+       {
+               frames.min = substream->pnd_hack_params.frames_min;
+               frames.max = substream->pnd_hack_params.frames_max;
+       }
+
        return snd_interval_refine(buffer_size, &frames);
 }
 
@@ -128,8 +140,10 @@ static int omap_mcbsp_dai_startup(struct snd_pcm_substream *substream,
        int bus_id = mcbsp_data->bus_id;
        int err = 0;
 
-       if (!cpu_dai->active)
+       if (!cpu_dai->active) {
                err = omap_mcbsp_request(bus_id);
+               mcbsp_data->substream = substream;
+       }
 
        /*
         * OMAP3 McBSP FIFO is word structured.
@@ -173,6 +187,11 @@ static void omap_mcbsp_dai_shutdown(struct snd_pcm_substream *substream,
        if (!cpu_dai->active) {
                omap_mcbsp_free(mcbsp_data->bus_id);
                mcbsp_data->configured = 0;
+
+               /* undo pandora hack */
+               mcbsp_data->substream = NULL;
+               substream->pnd_hack_params.frames_min = 0;
+               substream->pnd_hack_params.frames_max = 0;
        }
 }