int compress_set_gapless_metadata(struct compress *compress, struct compr_gapless_mdata *mdata) { struct snd_compr_metadata metadata; int version; if (!is_compress_ready(compress)) return oops(compress, ENODEV, "device not ready"); version = get_compress_version(compress); if (version <= 0) return -1; if (version < SNDRV_PROTOCOL_VERSION(0, 1, 1)) return oops(compress, ENXIO, "gapless apis not supported in kernel"); metadata.key = SNDRV_COMPRESS_ENCODER_PADDING; metadata.value[0] = mdata->encoder_padding; if (ioctl(compress->fd, SNDRV_COMPRESS_SET_METADATA, &metadata)) return oops(compress, errno, "can't set metadata for stream\n"); metadata.key = SNDRV_COMPRESS_ENCODER_DELAY; metadata.value[0] = mdata->encoder_delay; if (ioctl(compress->fd, SNDRV_COMPRESS_SET_METADATA, &metadata)) return oops(compress, errno, "can't set metadata for stream\n"); compress->gapless_metadata = 1; return 0; }
struct timespec snd_pcm_hw_fast_tstamp(snd_pcm_t *pcm) { struct timespec res; snd_pcm_hw_t *hw = pcm->private_data; res = FAST_PCM_TSTAMP(hw); if (SNDRV_PROTOCOL_VERSION(2, 0, 5) > hw->version) res.tv_nsec *= 1000L; return res; }
static int snd_ctl_hw_elem_replace(snd_ctl_t *handle, snd_ctl_elem_info_t *info) { snd_ctl_hw_t *hw = handle->private_data; if (info->type == SNDRV_CTL_ELEM_TYPE_ENUMERATED && hw->protocol < SNDRV_PROTOCOL_VERSION(2, 0, 7)) return -ENXIO; if (ioctl(hw->fd, SNDRV_CTL_IOCTL_ELEM_REPLACE, info) < 0) return -errno; return 0; }
static int snd_seq_hw_get_client_info(snd_seq_t *seq, snd_seq_client_info_t * info) { snd_seq_hw_t *hw = seq->private_data; if (ioctl(hw->fd, SNDRV_SEQ_IOCTL_GET_CLIENT_INFO, info) < 0) { /*SYSERR("SNDRV_SEQ_IOCTL_GET_CLIENT_INFO failed");*/ return -errno; } if (hw->version < SNDRV_PROTOCOL_VERSION(1, 0, 2)) { info->card = -1; info->pid = -1; } return 0; }
static int snd_timer_hw_continue(snd_timer_t *handle) { snd_timer_t *tmr; unsigned int cmd; tmr = handle; if (!tmr) return -EINVAL; if (tmr->version < SNDRV_PROTOCOL_VERSION(2, 0, 4)) cmd = SNDRV_TIMER_IOCTL_CONTINUE_OLD; else cmd = SNDRV_TIMER_IOCTL_CONTINUE; if (ioctl(tmr->poll_fd, cmd) < 0) return -errno; return 0; }
static int snd_timer_hw_status(snd_timer_t *handle, snd_timer_status_t * status) { snd_timer_t *tmr; int cmd; tmr = handle; if (!tmr || !status) return -EINVAL; if (tmr->version < SNDRV_PROTOCOL_VERSION(2, 0, 1)) cmd = SNDRV_TIMER_IOCTL_STATUS_OLD; else cmd = SNDRV_TIMER_IOCTL_STATUS; if (ioctl(tmr->poll_fd, cmd, status) < 0) return -errno; return 0; }
static int snd_ctl_hw_elem_tlv(snd_ctl_t *handle, int op_flag, unsigned int numid, unsigned int *tlv, unsigned int tlv_size) { int inum; snd_ctl_hw_t *hw = handle->private_data; struct snd_ctl_tlv *xtlv; /* we don't support TLV on protocol ver 2.0.3 or earlier */ if (hw->protocol < SNDRV_PROTOCOL_VERSION(2, 0, 4)) return -ENXIO; switch (op_flag) { case -1: inum = SNDRV_CTL_IOCTL_TLV_COMMAND; break; case 0: inum = SNDRV_CTL_IOCTL_TLV_READ; break; case 1: inum = SNDRV_CTL_IOCTL_TLV_WRITE; break; default: return -EINVAL; } xtlv = malloc(sizeof(struct snd_ctl_tlv) + tlv_size); if (xtlv == NULL) return -ENOMEM; xtlv->numid = numid; xtlv->length = tlv_size; memcpy(xtlv->tlv, tlv, tlv_size); if (ioctl(hw->fd, inum, xtlv) < 0) { free(xtlv); return -errno; } if (op_flag == 0) { if (xtlv->tlv[1] + 2 * sizeof(unsigned int) > tlv_size) { free(xtlv); return -EFAULT; } memcpy(tlv, xtlv->tlv, xtlv->tlv[1] + 2 * sizeof(unsigned int)); } free(xtlv); return 0; }
int snd_timer_hw_open(snd_timer_t **handle, const char *name, int dev_class, int dev_sclass, int card, int device, int subdevice, int mode) { int fd, ver, tmode, ret; snd_timer_t *tmr; struct snd_timer_select sel; *handle = NULL; tmode = O_RDONLY; if (mode & SND_TIMER_OPEN_NONBLOCK) tmode |= O_NONBLOCK; fd = snd_open_device(SNDRV_FILE_TIMER, tmode); if (fd < 0) return -errno; if (ioctl(fd, SNDRV_TIMER_IOCTL_PVERSION, &ver) < 0) { ret = -errno; close(fd); return ret; } if (SNDRV_PROTOCOL_INCOMPATIBLE(ver, SNDRV_TIMER_VERSION_MAX)) { close(fd); return -SND_ERROR_INCOMPATIBLE_VERSION; } if (mode & SND_TIMER_OPEN_TREAD) { int arg = 1; if (ver < SNDRV_PROTOCOL_VERSION(2, 0, 3)) { ret = -ENOTTY; goto __no_tread; } if (ioctl(fd, SNDRV_TIMER_IOCTL_TREAD, &arg) < 0) { ret = -errno; __no_tread: close(fd); SNDMSG("extended read is not supported (SNDRV_TIMER_IOCTL_TREAD)"); return ret; } } memset(&sel, 0, sizeof(sel)); sel.id.dev_class = dev_class; sel.id.dev_sclass = dev_sclass; sel.id.card = card; sel.id.device = device; sel.id.subdevice = subdevice; if (ioctl(fd, SNDRV_TIMER_IOCTL_SELECT, &sel) < 0) { ret = -errno; close(fd); return ret; } tmr = (snd_timer_t *) calloc(1, sizeof(snd_timer_t)); if (tmr == NULL) { close(fd); return -ENOMEM; } tmr->type = SND_TIMER_TYPE_HW; tmr->version = ver; tmr->mode = tmode; tmr->name = strdup(name); tmr->poll_fd = fd; tmr->ops = &snd_timer_hw_ops; INIT_LIST_HEAD(&tmr->async_handlers); *handle = tmr; return 0; }