0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #ifndef __COMPRESS_DRIVER_H
0011 #define __COMPRESS_DRIVER_H
0012
0013 #include <linux/types.h>
0014 #include <linux/sched.h>
0015 #include <sound/core.h>
0016 #include <sound/compress_offload.h>
0017 #include <sound/asound.h>
0018 #include <sound/pcm.h>
0019
0020 struct snd_compr_ops;
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041 struct snd_compr_runtime {
0042 snd_pcm_state_t state;
0043 struct snd_compr_ops *ops;
0044 void *buffer;
0045 u64 buffer_size;
0046 u32 fragment_size;
0047 u32 fragments;
0048 u64 total_bytes_available;
0049 u64 total_bytes_transferred;
0050 wait_queue_head_t sleep;
0051 void *private_data;
0052
0053 unsigned char *dma_area;
0054 dma_addr_t dma_addr;
0055 size_t dma_bytes;
0056 struct snd_dma_buffer *dma_buffer_p;
0057 };
0058
0059
0060
0061
0062
0063
0064
0065
0066
0067
0068
0069
0070
0071
0072
0073
0074 struct snd_compr_stream {
0075 const char *name;
0076 struct snd_compr_ops *ops;
0077 struct snd_compr_runtime *runtime;
0078 struct snd_compr *device;
0079 struct delayed_work error_work;
0080 enum snd_compr_direction direction;
0081 bool metadata_set;
0082 bool next_track;
0083 bool partial_drain;
0084 bool pause_in_draining;
0085 void *private_data;
0086 struct snd_dma_buffer dma_buffer;
0087 };
0088
0089
0090
0091
0092
0093
0094
0095
0096
0097
0098
0099
0100
0101
0102
0103
0104
0105
0106
0107
0108
0109
0110
0111
0112 struct snd_compr_ops {
0113 int (*open)(struct snd_compr_stream *stream);
0114 int (*free)(struct snd_compr_stream *stream);
0115 int (*set_params)(struct snd_compr_stream *stream,
0116 struct snd_compr_params *params);
0117 int (*get_params)(struct snd_compr_stream *stream,
0118 struct snd_codec *params);
0119 int (*set_metadata)(struct snd_compr_stream *stream,
0120 struct snd_compr_metadata *metadata);
0121 int (*get_metadata)(struct snd_compr_stream *stream,
0122 struct snd_compr_metadata *metadata);
0123 int (*trigger)(struct snd_compr_stream *stream, int cmd);
0124 int (*pointer)(struct snd_compr_stream *stream,
0125 struct snd_compr_tstamp *tstamp);
0126 int (*copy)(struct snd_compr_stream *stream, char __user *buf,
0127 size_t count);
0128 int (*mmap)(struct snd_compr_stream *stream,
0129 struct vm_area_struct *vma);
0130 int (*ack)(struct snd_compr_stream *stream, size_t bytes);
0131 int (*get_caps) (struct snd_compr_stream *stream,
0132 struct snd_compr_caps *caps);
0133 int (*get_codec_caps) (struct snd_compr_stream *stream,
0134 struct snd_compr_codec_caps *codec);
0135 };
0136
0137
0138
0139
0140
0141
0142
0143
0144
0145
0146
0147
0148
0149 struct snd_compr {
0150 const char *name;
0151 struct device dev;
0152 struct snd_compr_ops *ops;
0153 void *private_data;
0154 struct snd_card *card;
0155 unsigned int direction;
0156 struct mutex lock;
0157 int device;
0158 bool use_pause_in_draining;
0159 #ifdef CONFIG_SND_VERBOSE_PROCFS
0160
0161 char id[64];
0162 struct snd_info_entry *proc_root;
0163 struct snd_info_entry *proc_info_entry;
0164 #endif
0165 };
0166
0167
0168 int snd_compress_new(struct snd_card *card, int device,
0169 int type, const char *id, struct snd_compr *compr);
0170
0171
0172
0173
0174
0175
0176
0177
0178 static inline void snd_compr_use_pause_in_draining(struct snd_compr_stream *substream)
0179 {
0180 substream->device->use_pause_in_draining = true;
0181 }
0182
0183
0184
0185
0186
0187
0188
0189
0190
0191 static inline void snd_compr_fragment_elapsed(struct snd_compr_stream *stream)
0192 {
0193 wake_up(&stream->runtime->sleep);
0194 }
0195
0196 static inline void snd_compr_drain_notify(struct snd_compr_stream *stream)
0197 {
0198 if (snd_BUG_ON(!stream))
0199 return;
0200
0201
0202 if (stream->partial_drain) {
0203 stream->runtime->state = SNDRV_PCM_STATE_RUNNING;
0204 stream->partial_drain = false;
0205 } else {
0206 stream->runtime->state = SNDRV_PCM_STATE_SETUP;
0207 }
0208
0209 wake_up(&stream->runtime->sleep);
0210 }
0211
0212
0213
0214
0215
0216
0217
0218
0219
0220 static inline void
0221 snd_compr_set_runtime_buffer(struct snd_compr_stream *stream,
0222 struct snd_dma_buffer *bufp)
0223 {
0224 struct snd_compr_runtime *runtime = stream->runtime;
0225
0226 if (bufp) {
0227 runtime->dma_buffer_p = bufp;
0228 runtime->dma_area = bufp->area;
0229 runtime->dma_addr = bufp->addr;
0230 runtime->dma_bytes = bufp->bytes;
0231 } else {
0232 runtime->dma_buffer_p = NULL;
0233 runtime->dma_area = NULL;
0234 runtime->dma_addr = 0;
0235 runtime->dma_bytes = 0;
0236 }
0237 }
0238
0239 int snd_compr_malloc_pages(struct snd_compr_stream *stream, size_t size);
0240 int snd_compr_free_pages(struct snd_compr_stream *stream);
0241
0242 int snd_compr_stop_error(struct snd_compr_stream *stream,
0243 snd_pcm_state_t state);
0244
0245 #endif