コード例 #1
0
ファイル: front_panel.c プロジェクト: wucan/xmux
/*
 * @return: 1 the @cmd is response cmd
 */
int front_panel_check_recv_cmd(struct fp_cmd *recv_cmd)
{
	int cmd = SWAP_U16(recv_cmd->header.seq) & 0x7FFF;
	int is_read = SWAP_U16(recv_cmd->header.seq) & 0x8000;
	bool check_enter_fp = true;

	/*
	 * check force enter to fp management mode
	 */
	if (cmd == FP_CMD_SYS) {
		uint16_t sys_cmd = READ_U16_BE(recv_cmd->data);
		if (sys_cmd == FP_SYS_CMD_READ_TS_STATUS ||
			sys_cmd == FP_SYS_CMD_ENTER_FP_MANAGEMENT_MODE ||
			sys_cmd == FP_SYS_CMD_LEAVE_FP_MANAGEMENT_MODE) {
			check_enter_fp = false;
		}
	} else if (cmd == FP_CMD_OUT_RATE && is_read) {
		check_enter_fp = false;
	}
	if (check_enter_fp && (management_mode != MANAGEMENT_MODE_FP)) {
		trace_warn("recv cmd in none fp mode! force switch!");
		enter_fp_management_mode();
	}

	if (cmd == fp_expect_cmd) {
		static char buf[1024];
		struct fp_cmd *resp_cmd = (struct fp_cmd *)buf;
		fp_cmd_copy(resp_cmd, recv_cmd);
		if (wu_swait_wakeup(&fp_swait, resp_cmd)) {
			trace_err("recv respone cmd %d, but maybe had timeouted!", cmd);
		}
		return 1;
	}

	return 0;
}
コード例 #2
0
ファイル: audio.c プロジェクト: joncampbell123/doslib
int aiff_open(FILE *in, oe_enc_opt *opt, unsigned char *buf, int buflen)
{
    int aifc; /* AIFC or AIFF? */
    unsigned int len;
    unsigned char *buffer;
    unsigned char buf2[8];
    aiff_fmt format;
    aifffile *aiff = malloc(sizeof(aifffile));
    int i;

    if(buf[11]=='C')
        aifc=1;
    else
        aifc=0;

    if(!find_aiff_chunk(in, "COMM", &len))
    {
        fprintf(stderr, _("Warning: No common chunk found in AIFF file\n"));
        return 0; /* EOF before COMM chunk */
    }

    if(len < 18) 
    {
        fprintf(stderr, _("Warning: Truncated common chunk in AIFF header\n"));
        return 0; /* Weird common chunk */
    }

    buffer = alloca(len);

    if(fread(buffer,1,len,in) < len)
    {
        fprintf(stderr, _("Warning: Unexpected EOF in reading AIFF header\n"));
        return 0;
    }

    format.channels = READ_U16_BE(buffer);
    format.totalframes = READ_U32_BE(buffer+2);
    format.samplesize = READ_U16_BE(buffer+6);
    format.rate = (int)read_IEEE80(buffer+8);

    aiff->bigendian = 1;

    if(aifc)
    {
        if(len < 22)
        {
            fprintf(stderr, _("Warning: AIFF-C header truncated.\n"));
            return 0;
        }

        if(!memcmp(buffer+18, "NONE", 4)) 
        {
            aiff->bigendian = 1;
        }
        else if(!memcmp(buffer+18, "sowt", 4)) 
        {
            aiff->bigendian = 0;
        }
        else
        {
            fprintf(stderr, _("Warning: Can't handle compressed AIFF-C (%c%c%c%c)\n"), *(buffer+18), *(buffer+19), *(buffer+20), *(buffer+21));
            return 0; /* Compressed. Can't handle */
        }
    }

    if(!find_aiff_chunk(in, "SSND", &len))
    {
        fprintf(stderr, _("Warning: No SSND chunk found in AIFF file\n"));
        return 0; /* No SSND chunk -> no actual audio */
    }

    if(len < 8) 
    {
        fprintf(stderr, _("Warning: Corrupted SSND chunk in AIFF header\n"));
        return 0; 
    }

    if(fread(buf2,1,8, in) < 8)
    {
        fprintf(stderr, _("Warning: Unexpected EOF reading AIFF header\n"));
        return 0;
    }

    format.offset = READ_U32_BE(buf2);
    format.blocksize = READ_U32_BE(buf2+4);

    if( format.blocksize == 0 &&
        (format.samplesize == 16 || format.samplesize == 8))
    {
        /* From here on, this is very similar to the wav code. Oh well. */
        
        opt->rate = format.rate;
        opt->channels = format.channels;
        opt->read_samples = wav_read; /* Similar enough, so we use the same */
        opt->total_samples_per_channel = format.totalframes;

        aiff->f = in;
        aiff->samplesread = 0;
        aiff->channels = format.channels;
        aiff->samplesize = format.samplesize;
        aiff->totalsamples = format.totalframes;

        if(aiff->channels>3)
          fprintf(stderr,"WARNING: AIFF[-C] files with greater than three channels use\n"
                  "speaker locations incompatable with Vorbis suppound definitions.\n"
                  "Not performaing channel location mapping.\n");

        opt->readdata = (void *)aiff;

        aiff->channel_permute = malloc(aiff->channels * sizeof(int));
        if (aiff->channels <= 6)
            /* Where we know the mappings, use them. */
            memcpy(aiff->channel_permute, aiff_permute_matrix[aiff->channels-1], 
                    sizeof(int) * aiff->channels);
        else
            /* Use a default 1-1 mapping */
            for (i=0; i < aiff->channels; i++)
                aiff->channel_permute[i] = i;

        seek_forward(in, format.offset); /* Swallow some data */
        return 1;
    }
    else
    {
        fprintf(stderr, 
                _("Warning: OggEnc does not support this type of AIFF/AIFC file\n"
                " Must be 8 or 16 bit PCM.\n"));
        return 0;
    }
}