static int ea_probe(AVProbeData *p)
{
    if (p->buf_size < 4)
        return 0;

    if (LE_32(&p->buf[0]) != SCHl_TAG)
        return 0;

    return AVPROBE_SCORE_MAX;
}
/*
 * Function used to perform PQI hard reset.
 */
int pqi_reset(pqisrc_softstate_t *softs)
{
	int ret = PQI_STATUS_SUCCESS;
	uint32_t val = 0;
	pqi_reset_reg_t pqi_reset_reg;

	DBG_FUNC("IN\n");

	if (true == softs->ctrl_in_pqi_mode) { 
	
		if (softs->pqi_reset_quiesce_allowed) {
			val = PCI_MEM_GET32(softs, &softs->ioa_reg->host_to_ioa_db,
					LEGACY_SIS_IDBR);
			val |= SIS_PQI_RESET_QUIESCE;
			PCI_MEM_PUT32(softs, &softs->ioa_reg->host_to_ioa_db,
					LEGACY_SIS_IDBR, LE_32(val));
			ret = pqisrc_sis_wait_for_db_bit_to_clear(softs, SIS_PQI_RESET_QUIESCE);
			if (ret) {
				DBG_ERR("failed with error %d during quiesce\n", ret);
				return ret;
			}
		}

		pqi_reset_reg.all_bits = 0;
		pqi_reset_reg.bits.reset_type = PQI_RESET_TYPE_HARD_RESET;
		pqi_reset_reg.bits.reset_action = PQI_RESET_ACTION_RESET;

		PCI_MEM_PUT32(softs, &softs->pqi_reg->dev_reset, PQI_DEV_RESET,
			LE_32(pqi_reset_reg.all_bits));

		ret = pqisrc_wait_for_pqi_reset_completion(softs);
		if (ret) {
			DBG_ERR("PQI reset timed out: ret = %d!\n", ret);
			return ret;
		}
	}
	softs->ctrl_in_pqi_mode = false;
	DBG_FUNC("OUT\n");
	return ret;
}
Beispiel #3
0
TSS_RESULT
psfile_change_num_keys(int fd, BYTE increment)
{
	int rc;
	TSS_RESULT result;
	UINT32 num_keys;

	rc = lseek(fd, TSSPS_NUM_KEYS_OFFSET, SEEK_SET);
	if (rc == ((off_t)-1)) {
		LogDebug("lseek: %s", strerror(errno));
		return TSPERR(TSS_E_INTERNAL_ERROR);
	}

	rc = read(fd, &num_keys, sizeof(UINT32));
	if (rc != sizeof(UINT32)) {
		LogDebug("read of %zd bytes: %s", sizeof(UINT32), strerror(errno));
		return TSPERR(TSS_E_INTERNAL_ERROR);
	}
	num_keys = LE_32(num_keys);

	if (increment)
		num_keys++;
	else
		num_keys--;

	rc = lseek(fd, TSSPS_NUM_KEYS_OFFSET, SEEK_SET);
	if (rc == ((off_t)-1)) {
		LogDebug("lseek: %s", strerror(errno));
		return TSPERR(TSS_E_INTERNAL_ERROR);
	}

	num_keys = LE_32(num_keys);
	if ((result = write_data(fd, (void *)&num_keys, sizeof(UINT32)))) {
		LogDebug("%s", __FUNCTION__);
		return result;
	}

	return TSS_SUCCESS;
}
Beispiel #4
0
static uint32_t search_index(const uint32_t ip,FILE *qqwry_file) {
    uint32_t index_ip;
    unsigned char head[8];
    unsigned char index_bytes[7];
    fread(head,8,1,qqwry_file);
    uint32_t index_start,index_end,index_mid;
    index_start = (uint32_t)LE_32(&head[0]);
    index_end = (uint32_t)LE_32(&head[4]);
    while (1) {
        if ((index_end-index_start)==7) {
            break;
        }
        //printf("index:%u:%u\n",index_start,index_end);
        index_mid=index_end/7 - index_start/7;
        if (index_mid%2==0) {
            index_mid=index_mid/2;
        } else {
            index_mid=(index_mid+1)/2;
        }
        index_mid=index_start+index_mid*7;
        fseek(qqwry_file,index_mid,SEEK_SET);
        fread(index_bytes,7,1,qqwry_file);
        index_ip=(uint32_t)LE_32(&index_bytes[0]);
        if (index_ip==ip) {
            break;
        } else if (index_ip<ip) {
            index_start=index_mid;
        } else {
            index_end=index_mid;
        }
    }
    if (index_ip>ip) {
        fseek(qqwry_file,index_start,SEEK_SET);
        fread(index_bytes,7,1,qqwry_file);
    }
    return (uint32_t)LE_24(&index_bytes[4]);
}
static inline int tm2_read_header(TM2Context *ctx, uint8_t *buf)
{
    uint32_t magic;
    uint8_t *obuf;
    int length;

    obuf = buf;

    magic = LE_32(buf);
    buf += 4;

    if(magic == 0x00000100) { /* old header */
/*      av_log (ctx->avctx, AV_LOG_ERROR, "TM2 old header: not implemented (yet)\n"); */
        return 40;
    } else if(magic == 0x00000101) { /* new header */
        int w, h, size, flags, xr, yr;

        length = LE_32(buf);
        buf += 4;

        init_get_bits(&ctx->gb, buf, 32 * 8);
        size = get_bits_long(&ctx->gb, 31);
        h = get_bits(&ctx->gb, 15);
        w = get_bits(&ctx->gb, 15);
        flags = get_bits_long(&ctx->gb, 31);
        yr = get_bits(&ctx->gb, 9);
        xr = get_bits(&ctx->gb, 9);

        return 40;
    } else {
        av_log (ctx->avctx, AV_LOG_ERROR, "Not a TM2 header: 0x%08X\n", magic);
        return -1;
    }

    return (buf - obuf);
}
Beispiel #6
0
static int str_probe(AVProbeData *p)
{
    int start;

    /* need at least 0x38 bytes to validate */
    if (p->buf_size < 0x38)
        return 0;

    if ((LE_32(&p->buf[0]) == RIFF_TAG) &&
        (LE_32(&p->buf[8]) == CDXA_TAG)) {

        /* RIFF header seen; skip 0x2C bytes */
        start = RIFF_HEADER_SIZE;
    } else
        start = 0;

    /* look for CD sync header (00, 0xFF x 10, 00) */
    if (memcmp(p->buf+start,sync_header,sizeof(sync_header)))
        return 0;

    /* MPEG files (like those ripped from VCDs) can also look like this;
     * only return half certainty */
    return 50;
}
Beispiel #7
0
static int flic_read_packet(AVFormatContext *s,
                            AVPacket *pkt)
{
    FlicDemuxContext *flic = (FlicDemuxContext *)s->priv_data;
    ByteIOContext *pb = &s->pb;
    int packet_read = 0;
    unsigned int size;
    int magic;
    int ret = 0;
    unsigned char preamble[FLIC_PREAMBLE_SIZE];

    while (!packet_read) {

        if ((ret = get_buffer(pb, preamble, FLIC_PREAMBLE_SIZE)) !=
                FLIC_PREAMBLE_SIZE) {
            ret = AVERROR_IO;
            break;
        }

        size = LE_32(&preamble[0]);
        magic = LE_16(&preamble[4]);

        if (((magic == FLIC_CHUNK_MAGIC_1) || (magic == FLIC_CHUNK_MAGIC_2)) && size > FLIC_PREAMBLE_SIZE) {
            if (av_new_packet(pkt, size)) {
                ret = AVERROR_IO;
                break;
            }
            pkt->stream_index = flic->video_stream_index;
            pkt->pts = flic->pts;
            pkt->pos = url_ftell(pb);
            memcpy(pkt->data, preamble, FLIC_PREAMBLE_SIZE);
            ret = get_buffer(pb, pkt->data + FLIC_PREAMBLE_SIZE,
                             size - FLIC_PREAMBLE_SIZE);
            if (ret != size - FLIC_PREAMBLE_SIZE) {
                av_free_packet(pkt);
                ret = AVERROR_IO;
            }
            flic->pts += flic->frame_pts_inc;
            packet_read = 1;
        } else {
            /* not interested in this chunk */
            url_fseek(pb, size - 6, SEEK_CUR);
        }
    }

    return ret;
}
/* Switch the adapter back to SIS mode during uninitialization */
int pqisrc_reenable_sis(pqisrc_softstate_t *softs)
{
	int ret = PQI_STATUS_SUCCESS;
	uint32_t timeout = SIS_ENABLE_TIMEOUT;

	DBG_FUNC("IN\n");

	PCI_MEM_PUT32(softs, &softs->ioa_reg->host_to_ioa_db, 
        LEGACY_SIS_IDBR, LE_32(REENABLE_SIS));

	COND_WAIT(((PCI_MEM_GET32(softs, &softs->ioa_reg->ioa_to_host_db, LEGACY_SIS_ODBR_R) &
				REENABLE_SIS) == 0), timeout)
	if (!timeout) {
		DBG_WARN(" [ %s ] failed to re enable sis\n",__func__);
		ret = PQI_STATUS_TIMEOUT;
	}
		
	DBG_FUNC("OUT\n");
	return ret;
}
int main(int argc, char *argv[])
{
  unsigned char test_value32[5] = "\xFE\xDC\xBA\x10";
  u_int32_t le_uint32 = ((((u_int32_t)(test_value32[3])) << 24) |
			 (((u_int32_t)(test_value32[2])) << 16) |
			 (((u_int32_t)(test_value32[1])) << 8)  |
    			 (((u_int32_t)(test_value32[0])) << 0));
  
  u_int32_t le_uint16 = ((((u_int32_t)(test_value32[1])) << 8)  |
    			 (((u_int32_t)(test_value32[0])) << 0));
  
  u_int32_t be_uint32 = ((((u_int32_t)(test_value32[0])) << 24) |
			 (((u_int32_t)(test_value32[1])) << 16) |
			 (((u_int32_t)(test_value32[2])) << 8)  |
    			 (((u_int32_t)(test_value32[3])) << 0));
  
  u_int32_t be_uint16 = ((((u_int32_t)(test_value32[0])) << 8)  |
    			 (((u_int32_t)(test_value32[1])) << 0));
  
  printf("test_value32: %2hhx%2hhx%2hhx%2hhx\n", test_value32[0],
	 test_value32[1], test_value32[2], test_value32[3]);
  printf("test_value32 as u_int32_t: %04x\n", *(u_int32_t*)test_value32);
  printf("le_uint32: %04x\n", le_uint32);
  printf ("LE_32(le_uint32): %08x\n", LE_32(&le_uint32));

  printf("test_value16 as u_int16_t: %04x\n", *(u_int16_t*)test_value32);
  printf("le_uint16: %04x\n", le_uint16);
  printf ("LE_16(le_uint16): %04hx\n", LE_16(&le_uint16));

  printf("be_uint32: %04x\n", be_uint32);
  printf ("BE_32(be_uint32): %08x\n", BE_32(&be_uint32));

  printf("test_value16 as u_int16_t: %04x\n", *(u_int16_t*)test_value32);
  printf("be_uint16: %04x\n", be_uint16);
  printf ("BE_16(be_uint16): %04hx\n", BE_16(&be_uint16));

}
Beispiel #10
0
/*
 * read into the PS file and return the number of keys
 */
int
get_num_keys_in_file(int fd)
{
	UINT32 num_keys;
	int rc;

	/* go to the number of keys */
	rc = lseek(fd, TSSPS_NUM_KEYS_OFFSET, SEEK_SET);
	if (rc == ((off_t) - 1)) {
		LogError("lseek: %s", strerror(errno));
		return 0;
	}

	rc = read(fd, &num_keys, sizeof(UINT32));
	if (rc < 0) {
		LogError("read of %zd bytes: %s", sizeof(UINT32), strerror(errno));
		return 0;
	} else if ((unsigned)rc < sizeof(UINT32)) {
		num_keys = 0;
	}
        num_keys = LE_32(num_keys);

	return num_keys;
}
/*
 * Get the PQI configuration table parameters.
 * Currently using for heart-beat counter scratch-pad register.
 */
int pqisrc_process_config_table(pqisrc_softstate_t *softs)
{
	int ret = PQI_STATUS_FAILURE;
	uint32_t config_table_size;
	uint32_t section_off;
	uint8_t *config_table_abs_addr;
	struct pqi_conf_table *conf_table;
	struct pqi_conf_table_section_header *section_hdr;

	config_table_size = softs->pqi_cap.conf_tab_sz;

	if (config_table_size < sizeof(*conf_table) ||
		config_table_size > PQI_CONF_TABLE_MAX_LEN) {
		DBG_ERR("Invalid PQI conf table length of %u\n",
			config_table_size);
		return ret;
	}

	conf_table = os_mem_alloc(softs, config_table_size);
	if (!conf_table) {
		DBG_ERR("Failed to allocate memory for PQI conf table\n");
		return ret;
	}

	config_table_abs_addr = (uint8_t *)(softs->pci_mem_base_vaddr +
					softs->pqi_cap.conf_tab_off);

	PCI_MEM_GET_BUF(softs, config_table_abs_addr,
			softs->pqi_cap.conf_tab_off,
			(uint8_t*)conf_table, config_table_size);


	if (memcmp(conf_table->sign, PQI_CONF_TABLE_SIGNATURE,
			sizeof(conf_table->sign)) != 0) {
		DBG_ERR("Invalid PQI config signature\n");
		goto out;
	}

	section_off = LE_32(conf_table->first_section_off);

	while (section_off) {

		if (section_off+ sizeof(*section_hdr) >= config_table_size) {
			DBG_ERR("PQI config table section offset (%u) beyond \
			end of config table (config table length: %u)\n",
					section_off, config_table_size);
			break;
		}
		
		section_hdr = (struct pqi_conf_table_section_header *)((uint8_t *)conf_table + section_off);
		
		switch (LE_16(section_hdr->section_id)) {
		case PQI_CONF_TABLE_SECTION_GENERAL_INFO:
		case PQI_CONF_TABLE_SECTION_FIRMWARE_FEATURES:
		case PQI_CONF_TABLE_SECTION_FIRMWARE_ERRATA:
		case PQI_CONF_TABLE_SECTION_DEBUG:
		break;
		case PQI_CONF_TABLE_SECTION_HEARTBEAT:
		softs->heartbeat_counter_off = softs->pqi_cap.conf_tab_off +
						section_off +
						offsetof(struct pqi_conf_table_heartbeat,
						heartbeat_counter);
		softs->heartbeat_counter_abs_addr = (uint64_t *)(softs->pci_mem_base_vaddr +
							softs->heartbeat_counter_off);
		ret = PQI_STATUS_SUCCESS;
		break;
		default:
		DBG_ERR("unrecognized PQI config table section ID: 0x%x\n",
					LE_16(section_hdr->section_id));
		break;
		}
		section_off = LE_16(section_hdr->next_section_off);
	}
Beispiel #12
0
static int
efi_read(int fd, struct dk_gpt *vtoc)
{
	int			i, j;
	int			label_len;
	int			rval = 0;
	int			md_flag = 0;
	int			vdc_flag = 0;
	struct dk_minfo		disk_info;
	dk_efi_t		dk_ioc;
	efi_gpt_t		*efi;
	efi_gpe_t		*efi_parts;
	struct dk_cinfo		dki_info;
	uint32_t		user_length;
	boolean_t		legacy_label = B_FALSE;

	/*
	 * get the partition number for this file descriptor.
	 */
	if (ioctl(fd, DKIOCINFO, (caddr_t)&dki_info) == -1) {
		if (efi_debug) {
			(void) fprintf(stderr, "DKIOCINFO errno 0x%x\n", errno);
		}
		switch (errno) {
		case EIO:
			return (VT_EIO);
		case EINVAL:
			return (VT_EINVAL);
		default:
			return (VT_ERROR);
		}
	}
	if ((strncmp(dki_info.dki_cname, "pseudo", 7) == 0) &&
	    (strncmp(dki_info.dki_dname, "md", 3) == 0)) {
		md_flag++;
	} else if ((strncmp(dki_info.dki_cname, "vdc", 4) == 0) &&
	    (strncmp(dki_info.dki_dname, "vdc", 4) == 0)) {
		/*
		 * The controller and drive name "vdc" (virtual disk client)
		 * indicates a LDoms virtual disk.
		 */
		vdc_flag++;
	}

	/* get the LBA size */
	if (ioctl(fd, DKIOCGMEDIAINFO, (caddr_t)&disk_info) == -1) {
		if (efi_debug) {
			(void) fprintf(stderr,
			    "assuming LBA 512 bytes %d\n",
			    errno);
		}
		disk_info.dki_lbsize = DEV_BSIZE;
	}
	if (disk_info.dki_lbsize == 0) {
		if (efi_debug) {
			(void) fprintf(stderr,
			    "efi_read: assuming LBA 512 bytes\n");
		}
		disk_info.dki_lbsize = DEV_BSIZE;
	}
	/*
	 * Read the EFI GPT to figure out how many partitions we need
	 * to deal with.
	 */
	dk_ioc.dki_lba = 1;
	if (NBLOCKS(vtoc->efi_nparts, disk_info.dki_lbsize) < 34) {
		label_len = EFI_MIN_ARRAY_SIZE + disk_info.dki_lbsize;
	} else {
		label_len = vtoc->efi_nparts * (int) sizeof (efi_gpe_t) +
		    disk_info.dki_lbsize;
		if (label_len % disk_info.dki_lbsize) {
			/* pad to physical sector size */
			label_len += disk_info.dki_lbsize;
			label_len &= ~(disk_info.dki_lbsize - 1);
		}
	}

	if ((dk_ioc.dki_data = calloc(label_len, 1)) == NULL)
		return (VT_ERROR);

	dk_ioc.dki_length = disk_info.dki_lbsize;
	user_length = vtoc->efi_nparts;
	efi = dk_ioc.dki_data;
	if (md_flag) {
		dk_ioc.dki_length = label_len;
		if (efi_ioctl(fd, DKIOCGETEFI, &dk_ioc) == -1) {
			switch (errno) {
			case EIO:
				return (VT_EIO);
			default:
				return (VT_ERROR);
			}
		}
	} else if ((rval = check_label(fd, &dk_ioc)) == VT_EINVAL) {
		/*
		 * No valid label here; try the alternate. Note that here
		 * we just read GPT header and save it into dk_ioc.data,
		 * Later, we will read GUID partition entry array if we
		 * can get valid GPT header.
		 */

		/*
		 * This is a workaround for legacy systems. In the past, the
		 * last sector of SCSI disk was invisible on x86 platform. At
		 * that time, backup label was saved on the next to the last
		 * sector. It is possible for users to move a disk from previous
		 * solaris system to present system. Here, we attempt to search
		 * legacy backup EFI label first.
		 */
		dk_ioc.dki_lba = disk_info.dki_capacity - 2;
		dk_ioc.dki_length = disk_info.dki_lbsize;
		rval = check_label(fd, &dk_ioc);
		if (rval == VT_EINVAL) {
			/*
			 * we didn't find legacy backup EFI label, try to
			 * search backup EFI label in the last block.
			 */
			dk_ioc.dki_lba = disk_info.dki_capacity - 1;
			dk_ioc.dki_length = disk_info.dki_lbsize;
			rval = check_label(fd, &dk_ioc);
			if (rval == 0) {
				legacy_label = B_TRUE;
				if (efi_debug)
					(void) fprintf(stderr,
					    "efi_read: primary label corrupt; "
					    "using EFI backup label located on"
					    " the last block\n");
			}
		} else {
			if ((efi_debug) && (rval == 0))
				(void) fprintf(stderr, "efi_read: primary label"
				    " corrupt; using legacy EFI backup label "
				    " located on the next to last block\n");
		}

		if (rval == 0) {
			dk_ioc.dki_lba = LE_64(efi->efi_gpt_PartitionEntryLBA);
			vtoc->efi_flags |= EFI_GPT_PRIMARY_CORRUPT;
			vtoc->efi_nparts =
			    LE_32(efi->efi_gpt_NumberOfPartitionEntries);
			/*
			 * Partition tables are between backup GPT header
			 * table and ParitionEntryLBA (the starting LBA of
			 * the GUID partition entries array). Now that we
			 * already got valid GPT header and saved it in
			 * dk_ioc.dki_data, we try to get GUID partition
			 * entry array here.
			 */
			/* LINTED */
			dk_ioc.dki_data = (efi_gpt_t *)((char *)dk_ioc.dki_data
			    + disk_info.dki_lbsize);
			if (legacy_label)
				dk_ioc.dki_length = disk_info.dki_capacity - 1 -
				    dk_ioc.dki_lba;
			else
				dk_ioc.dki_length = disk_info.dki_capacity - 2 -
				    dk_ioc.dki_lba;
			dk_ioc.dki_length *= disk_info.dki_lbsize;
			if (dk_ioc.dki_length >
			    ((len_t)label_len - sizeof (*dk_ioc.dki_data))) {
				rval = VT_EINVAL;
			} else {
				/*
				 * read GUID partition entry array
				 */
				rval = efi_ioctl(fd, DKIOCGETEFI, &dk_ioc);
			}
		}

	} else if (rval == 0) {

		dk_ioc.dki_lba = LE_64(efi->efi_gpt_PartitionEntryLBA);
		/* LINTED */
		dk_ioc.dki_data = (efi_gpt_t *)((char *)dk_ioc.dki_data
		    + disk_info.dki_lbsize);
		dk_ioc.dki_length = label_len - disk_info.dki_lbsize;
		rval = efi_ioctl(fd, DKIOCGETEFI, &dk_ioc);

	} else if (vdc_flag && rval == VT_ERROR && errno == EINVAL) {
		/*
		 * When the device is a LDoms virtual disk, the DKIOCGETEFI
		 * ioctl can fail with EINVAL if the virtual disk backend
		 * is a ZFS volume serviced by a domain running an old version
		 * of Solaris. This is because the DKIOCGETEFI ioctl was
		 * initially incorrectly implemented for a ZFS volume and it
		 * expected the GPT and GPE to be retrieved with a single ioctl.
		 * So we try to read the GPT and the GPE using that old style
		 * ioctl.
		 */
		dk_ioc.dki_lba = 1;
		dk_ioc.dki_length = label_len;
		rval = check_label(fd, &dk_ioc);
	}

	if (rval < 0) {
		free(efi);
		return (rval);
	}

	/* LINTED -- always longlong aligned */
	efi_parts = (efi_gpe_t *)(((char *)efi) + disk_info.dki_lbsize);

	/*
	 * Assemble this into a "dk_gpt" struct for easier
	 * digestibility by applications.
	 */
	vtoc->efi_version = LE_32(efi->efi_gpt_Revision);
	vtoc->efi_nparts = LE_32(efi->efi_gpt_NumberOfPartitionEntries);
	vtoc->efi_part_size = LE_32(efi->efi_gpt_SizeOfPartitionEntry);
	vtoc->efi_lbasize = disk_info.dki_lbsize;
	vtoc->efi_last_lba = disk_info.dki_capacity - 1;
	vtoc->efi_first_u_lba = LE_64(efi->efi_gpt_FirstUsableLBA);
	vtoc->efi_last_u_lba = LE_64(efi->efi_gpt_LastUsableLBA);
	vtoc->efi_altern_lba = LE_64(efi->efi_gpt_AlternateLBA);
	UUID_LE_CONVERT(vtoc->efi_disk_uguid, efi->efi_gpt_DiskGUID);

	/*
	 * If the array the user passed in is too small, set the length
	 * to what it needs to be and return
	 */
	if (user_length < vtoc->efi_nparts) {
		return (VT_EINVAL);
	}

	for (i = 0; i < vtoc->efi_nparts; i++) {

		UUID_LE_CONVERT(vtoc->efi_parts[i].p_guid,
		    efi_parts[i].efi_gpe_PartitionTypeGUID);

		for (j = 0;
		    j < sizeof (conversion_array)
		    / sizeof (struct uuid_to_ptag); j++) {

			if (bcmp(&vtoc->efi_parts[i].p_guid,
			    &conversion_array[j].uuid,
			    sizeof (struct uuid)) == 0) {
				vtoc->efi_parts[i].p_tag = j;
				break;
			}
		}
		if (vtoc->efi_parts[i].p_tag == V_UNASSIGNED)
			continue;
		vtoc->efi_parts[i].p_flag =
		    LE_16(efi_parts[i].efi_gpe_Attributes.PartitionAttrs);
		vtoc->efi_parts[i].p_start =
		    LE_64(efi_parts[i].efi_gpe_StartingLBA);
		vtoc->efi_parts[i].p_size =
		    LE_64(efi_parts[i].efi_gpe_EndingLBA) -
		    vtoc->efi_parts[i].p_start + 1;
		for (j = 0; j < EFI_PART_NAME_LEN; j++) {
			vtoc->efi_parts[i].p_name[j] =
			    (uchar_t)LE_16(
			    efi_parts[i].efi_gpe_PartitionName[j]);
		}

		UUID_LE_CONVERT(vtoc->efi_parts[i].p_uguid,
		    efi_parts[i].efi_gpe_UniquePartitionGUID);
	}
	free(efi);

	return (dki_info.dki_partition);
}
static int vmd_read_header(AVFormatContext *s,
                           AVFormatParameters *ap)
{
    VmdDemuxContext *vmd = (VmdDemuxContext *)s->priv_data;
    ByteIOContext *pb = &s->pb;
    AVStream *st;
    unsigned int toc_offset;
    unsigned char *raw_frame_table;
    int raw_frame_table_size;
    offset_t current_offset;
    int i, j;
    unsigned int total_frames;
    int64_t video_pts_inc = 0;
    int64_t current_video_pts = 0;
    unsigned char chunk[BYTES_PER_FRAME_RECORD];
    int lastframe = 0;

    /* fetch the main header, including the 2 header length bytes */
    url_fseek(pb, 0, SEEK_SET);
    if (get_buffer(pb, vmd->vmd_header, VMD_HEADER_SIZE) != VMD_HEADER_SIZE)
        return AVERROR_IO;

    vmd->audio_sample_counter = 0;
    vmd->audio_frame_divisor = 1;
    vmd->audio_block_align = 1;

    /* start up the decoders */
    st = av_new_stream(s, 0);
    if (!st)
        return AVERROR_NOMEM;
    av_set_pts_info(st, 33, 1, 90000);
    vmd->video_stream_index = st->index;
    st->codec->codec_type = CODEC_TYPE_VIDEO;
    st->codec->codec_id = CODEC_ID_VMDVIDEO;
    st->codec->codec_tag = 0;  /* no fourcc */
    st->codec->width = LE_16(&vmd->vmd_header[12]);
    st->codec->height = LE_16(&vmd->vmd_header[14]);
    st->codec->time_base.num = 1;
    st->codec->time_base.den = 10;
    st->codec->extradata_size = VMD_HEADER_SIZE;
    st->codec->extradata = av_mallocz(VMD_HEADER_SIZE + FF_INPUT_BUFFER_PADDING_SIZE);
    memcpy(st->codec->extradata, vmd->vmd_header, VMD_HEADER_SIZE);

    /* if sample rate is 0, assume no audio */
    vmd->sample_rate = LE_16(&vmd->vmd_header[804]);
    if (vmd->sample_rate) {
        st = av_new_stream(s, 0);
        if (!st)
            return AVERROR_NOMEM;
        av_set_pts_info(st, 33, 1, 90000);
        vmd->audio_stream_index = st->index;
        st->codec->codec_type = CODEC_TYPE_AUDIO;
        st->codec->codec_id = CODEC_ID_VMDAUDIO;
        st->codec->codec_tag = 0;  /* no fourcc */
        st->codec->channels = vmd->audio_channels = (vmd->vmd_header[811] & 0x80) ? 2 : 1;
        st->codec->sample_rate = vmd->sample_rate;
        st->codec->block_align = vmd->audio_block_align =
            LE_16(&vmd->vmd_header[806]);
        if (st->codec->block_align & 0x8000) {
            st->codec->bits_per_sample = 16;
            st->codec->block_align = -(st->codec->block_align - 0x10000);
            vmd->audio_block_align = -(vmd->audio_block_align - 0x10000);
        } else {
            st->codec->bits_per_sample = 8;
        }
        st->codec->bit_rate = st->codec->sample_rate *
            st->codec->bits_per_sample * st->codec->channels;

        /* for calculating pts */
        vmd->audio_frame_divisor = st->codec->channels;

        video_pts_inc = 90000;
        video_pts_inc *= st->codec->block_align;
        video_pts_inc /= st->codec->sample_rate;
        video_pts_inc /= st->codec->channels;
    } else {
        /* if no audio, assume 10 frames/second */
        video_pts_inc = 90000 / 10;
    }

    toc_offset = LE_32(&vmd->vmd_header[812]);
    vmd->frame_count = LE_16(&vmd->vmd_header[6]);
    vmd->frames_per_block = LE_16(&vmd->vmd_header[18]);
    url_fseek(pb, toc_offset, SEEK_SET);

    raw_frame_table = NULL;
    vmd->frame_table = NULL;
    raw_frame_table_size = vmd->frame_count * 6;
    raw_frame_table = av_malloc(raw_frame_table_size);
    vmd->frame_table = av_malloc(vmd->frame_count * vmd->frames_per_block * sizeof(vmd_frame_t));
    if (!raw_frame_table || !vmd->frame_table) {
        av_free(raw_frame_table);
        av_free(vmd->frame_table);
        return AVERROR_NOMEM;
    }
    if (get_buffer(pb, raw_frame_table, raw_frame_table_size) !=
        raw_frame_table_size) {
        av_free(raw_frame_table);
        av_free(vmd->frame_table);
        return AVERROR_IO;
    }

    total_frames = 0;
    for (i = 0; i < vmd->frame_count; i++) {

        current_offset = LE_32(&raw_frame_table[6 * i + 2]);

        /* handle each entry in index block */
        for (j = 0; j < vmd->frames_per_block; j++) {
            int type;
            uint32_t size;

            get_buffer(pb, chunk, BYTES_PER_FRAME_RECORD);
            type = chunk[0];
            size = LE_32(&chunk[2]);
            if(!size)
                continue;
            switch(type) {
            case 1: /* Audio Chunk */
                vmd->frame_table[total_frames].frame_offset = current_offset;
                vmd->frame_table[total_frames].stream_index = vmd->audio_stream_index;
                vmd->frame_table[total_frames].frame_size = size;
                memcpy(vmd->frame_table[total_frames].frame_record, chunk, BYTES_PER_FRAME_RECORD);
                total_frames++;
                break;
            case 2: /* Video Chunk */
                vmd->frame_table[total_frames].frame_offset = current_offset;
                vmd->frame_table[total_frames].frame_size = size;
                vmd->frame_table[total_frames].stream_index = vmd->video_stream_index;
                memcpy(vmd->frame_table[total_frames].frame_record, chunk, BYTES_PER_FRAME_RECORD);
                vmd->frame_table[total_frames].pts = current_video_pts;
                if (lastframe) {
                    vmd->frame_table[lastframe].pts = current_video_pts - video_pts_inc;
                }
                lastframe = total_frames;
                total_frames++;
                break;
            }
            current_offset += size;
        }
        current_video_pts += video_pts_inc;
    }

    av_free(raw_frame_table);

    vmd->current_frame = 0;
    vmd->frame_count = total_frames;

    return 0;
}
Beispiel #14
0
static int fallback_io_tcp_connect(void *data, const char *host, int port, int *need_abort)
{

    struct hostent *h;
    int i, s;

#ifdef USE_GETHOSTBYNAME
    h = gethostbyname(host);
    if (h == NULL) {
        lprintf("mms: unable to resolve host: %s\n", host);
        return -1;
    }
    char **h_addr_list = h->h_addr_list;
#else
    char sport[10];
    snprintf (sport, 10, "%d", port);
    struct addrinfo *res;
    for (;;) {
        int err = getaddrinfo (host, sport, NULL, &res);
        if (need_abort && *need_abort) {
            if (res) {
                freeaddrinfo(res);
            }
            return -1;
        }

        if (err == EAI_AGAIN) {
            lprintf ("getaddrinfo again\n");
            continue;
        }
        else if (err == 0) {
            lprintf ("getaddrinfo success\n");
            break;
        }
        lprintf ("getaddrinfo err: %d\n", err);
        return -1;
    }
#endif

    s = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
    if (s == -1) {
        lprintf("mms: failed to create socket: %s\n", strerror(errno));
        return -1;
    }

    if (fcntl (s, F_SETFL, fcntl (s, F_GETFL) | O_NONBLOCK) == -1) {
        lprintf("mms: failed to set socket flags: %s\n", strerror(errno));
        return -1;
    }

#ifdef USE_GETHOSTBYNAME
    for (i = 0; h_addr_list[i]; i++) {
        struct in_addr ia;
        struct sockaddr_in sin;

        memcpy (&ia, h_addr_list[i], 4);
        sin.sin_family = AF_INET;
        sin.sin_addr   = ia;
        sin.sin_port   = htons(port);
#else
        struct addrinfo *rp;
        for (rp = res; rp != NULL; rp = rp->ai_next) {
            struct sockaddr_in sin;
            memset (&sin, 0, sizeof (sin));
            int l = rp->ai_addrlen;
            if (l > sizeof (sin)) {
                l = sizeof (sin);
            }
            memcpy (&sin, rp->ai_addr, l);
#endif

            time_t t = time (NULL);
            int error = 0;
            while (!need_abort || !(*need_abort)) {
                int res = connect(s, (struct sockaddr *)&sin, sizeof(sin));
                if (res == -1 && (errno == EINPROGRESS || errno == EALREADY)) {
                    if (time (NULL) - t > 3) {
                        error = -1;
                        break;
                    }
                    usleep(100000);
                    continue;
                }
                else if (res == -1 && errno == EISCONN) {
                    break;
                }
                else if (res == -1) {
                    error = -1;
                    break;
                }
            }
            if (need_abort && *need_abort) {
                lprintf ("fallback_io_tcp_connect: aborted\n");
                s = -1;
                break;
            }
            //        if (connect(s, (struct sockaddr *)&sin, sizeof(sin)) ==-1 && errno != EINPROGRESS) {
            //            continue;
            //        }
            if (error) {
                continue;
            }

#ifndef USE_GETHOSTBYNAME
            if (res) {
                freeaddrinfo(res);
            }
#endif
            return s;
        }
#ifndef USE_GETHOSTBYNAME
        if (res) {
            freeaddrinfo(res);
        }
#endif
        close(s);
        return -1;
    }

static mms_io_t fallback_io =
  {
    &fallback_io_select,
    NULL,
    &fallback_io_read,
    NULL,
    &fallback_io_write,
    NULL,
    &fallback_io_tcp_connect,
    NULL,
  };

static mms_io_t default_io =   {
    &fallback_io_select,
    NULL,
    &fallback_io_read,
    NULL,
    &fallback_io_write,
    NULL,
    &fallback_io_tcp_connect,
    NULL,
  };


#define io_read(io, args...) ((io) ? (io)->read(io->read_data , ## args) : default_io.read(NULL , ## args))
#define io_write(io, args...) ((io) ? (io)->write(io->write_data , ## args) : default_io.write(NULL , ## args))
#define io_select(io, args...) ((io) ? (io)->select(io->select_data , ## args) : default_io.select(NULL , ## args))
#define io_connect(io, args...) ((io) ? (io)->connect(io->connect_data , ## args) : default_io.connect(NULL , ## args))
  
static int get_guid (unsigned char *buffer, int offset) {
  int i;
  GUID g;
  
  g.Data1 = LE_32(buffer + offset);
  g.Data2 = LE_16(buffer + offset + 4);
  g.Data3 = LE_16(buffer + offset + 6);
  for(i = 0; i < 8; i++) {
    g.Data4[i] = buffer[offset + 8 + i];
  }
  
  for (i = 1; i < GUID_END; i++) {
    if (!memcmp(&g, &guids[i].guid, sizeof(GUID))) {
      lprintf("mmsh: GUID: %s\n", guids[i].name);
      return i;
    }
  }

  lprintf("mmsh: unknown GUID: 0x%x, 0x%x, 0x%x, "
          "{ 0x%hx, 0x%hx, 0x%hx, 0x%hx, 0x%hx, 0x%hx, 0x%hx, 0x%hx }\n",
          g.Data1, g.Data2, g.Data3,
          g.Data4[0], g.Data4[1], g.Data4[2], g.Data4[3], 
          g.Data4[4], g.Data4[5], g.Data4[6], g.Data4[7]);
  return GUID_ERROR;
}
Beispiel #15
0
/*ARGSUSED*/
int
zvol_ioctl(dev_t dev, int cmd, intptr_t arg, int flag, cred_t *cr, int *rvalp)
{
	zvol_state_t *zv;
	struct dk_cinfo dkc;
	struct dk_minfo dkm;
	dk_efi_t efi;
	efi_gpt_t gpt;
	efi_gpe_t gpe;
	struct uuid uuid = EFI_RESERVED;
	uint32_t crc;
	int error = 0;

	mutex_enter(&zvol_state_lock);

	zv = ddi_get_soft_state(zvol_state, getminor(dev));

	if (zv == NULL) {
		mutex_exit(&zvol_state_lock);
		return (ENXIO);
	}

	switch (cmd) {

	case DKIOCINFO:
		bzero(&dkc, sizeof (dkc));
		(void) strcpy(dkc.dki_cname, "zvol");
		(void) strcpy(dkc.dki_dname, "zvol");
		dkc.dki_ctype = DKC_UNKNOWN;
		dkc.dki_maxtransfer = 1 << (SPA_MAXBLOCKSHIFT - zv->zv_min_bs);
		mutex_exit(&zvol_state_lock);
		if (ddi_copyout(&dkc, (void *)arg, sizeof (dkc), flag))
			error = EFAULT;
		return (error);

	case DKIOCGMEDIAINFO:
		bzero(&dkm, sizeof (dkm));
		dkm.dki_lbsize = 1U << zv->zv_min_bs;
		dkm.dki_capacity = zv->zv_volsize >> zv->zv_min_bs;
		dkm.dki_media_type = DK_UNKNOWN;
		mutex_exit(&zvol_state_lock);
		if (ddi_copyout(&dkm, (void *)arg, sizeof (dkm), flag))
			error = EFAULT;
		return (error);

	case DKIOCGETEFI:
		if (ddi_copyin((void *)arg, &efi, sizeof (dk_efi_t), flag)) {
			mutex_exit(&zvol_state_lock);
			return (EFAULT);
		}

		bzero(&gpt, sizeof (gpt));
		bzero(&gpe, sizeof (gpe));

		efi.dki_data = (void *)(uintptr_t)efi.dki_data_64;

		if (efi.dki_length < sizeof (gpt) + sizeof (gpe)) {
			mutex_exit(&zvol_state_lock);
			return (EINVAL);
		}

		efi.dki_length = sizeof (gpt) + sizeof (gpe);

		gpt.efi_gpt_Signature = LE_64(EFI_SIGNATURE);
		gpt.efi_gpt_Revision = LE_32(EFI_VERSION_CURRENT);
		gpt.efi_gpt_HeaderSize = LE_32(sizeof (gpt));
		gpt.efi_gpt_FirstUsableLBA = LE_64(0ULL);
		gpt.efi_gpt_LastUsableLBA =
		    LE_64((zv->zv_volsize >> zv->zv_min_bs) - 1);
		gpt.efi_gpt_NumberOfPartitionEntries = LE_32(1);
		gpt.efi_gpt_SizeOfPartitionEntry = LE_32(sizeof (gpe));

		UUID_LE_CONVERT(gpe.efi_gpe_PartitionTypeGUID, uuid);
		gpe.efi_gpe_StartingLBA = gpt.efi_gpt_FirstUsableLBA;
		gpe.efi_gpe_EndingLBA = gpt.efi_gpt_LastUsableLBA;

		CRC32(crc, &gpe, sizeof (gpe), -1U, crc32_table);
		gpt.efi_gpt_PartitionEntryArrayCRC32 = LE_32(~crc);

		CRC32(crc, &gpt, sizeof (gpt), -1U, crc32_table);
		gpt.efi_gpt_HeaderCRC32 = LE_32(~crc);

		mutex_exit(&zvol_state_lock);
		if (ddi_copyout(&gpt, efi.dki_data, sizeof (gpt), flag) ||
		    ddi_copyout(&gpe, efi.dki_data + 1, sizeof (gpe), flag))
			error = EFAULT;
		return (error);

	default:
		error = ENOTSUP;
		break;

	}
	mutex_exit(&zvol_state_lock);
	return (error);
}
Beispiel #16
0
static int flic_read_header(AVFormatContext *s,
                            AVFormatParameters *ap)
{
    FlicDemuxContext *flic = (FlicDemuxContext *)s->priv_data;
    ByteIOContext *pb = &s->pb;
    unsigned char header[FLIC_HEADER_SIZE];
    AVStream *st;
    int speed;
    int magic_number;

    flic->pts = 0;

    /* load the whole header and pull out the width and height */
    if (get_buffer(pb, header, FLIC_HEADER_SIZE) != FLIC_HEADER_SIZE)
        return AVERROR_IO;

    magic_number = LE_16(&header[4]);
    speed = LE_32(&header[0x10]);

    /* initialize the decoder streams */
    st = av_new_stream(s, 0);
    if (!st)
        return AVERROR_NOMEM;
    flic->video_stream_index = st->index;
    st->codec.codec_type = CODEC_TYPE_VIDEO;
    st->codec.codec_id = CODEC_ID_FLIC;
    st->codec.codec_tag = 0;  /* no fourcc */
    st->codec.width = LE_16(&header[0x08]);
    st->codec.height = LE_16(&header[0x0A]);

    if (!st->codec.width || !st->codec.height)
        return AVERROR_INVALIDDATA;

    /* send over the whole 128-byte FLIC header */
    st->codec.extradata_size = FLIC_HEADER_SIZE;
    st->codec.extradata = av_malloc(FLIC_HEADER_SIZE);
    memcpy(st->codec.extradata, header, FLIC_HEADER_SIZE);

    av_set_pts_info(st, 33, 1, 90000);

    /* Time to figure out the framerate: If there is a FLIC chunk magic
     * number at offset 0x10, assume this is from the Bullfrog game,
     * Magic Carpet. */
    if (LE_16(&header[0x10]) == FLIC_CHUNK_MAGIC_1) {

        flic->frame_pts_inc = FLIC_MC_PTS_INC;

        /* rewind the stream since the first chunk is at offset 12 */
        url_fseek(pb, 12, SEEK_SET);

        /* send over abbreviated FLIC header chunk */
        av_free(st->codec.extradata);
        st->codec.extradata_size = 12;
        st->codec.extradata = av_malloc(12);
        memcpy(st->codec.extradata, header, 12);

    } else if (magic_number == FLIC_FILE_MAGIC_1) {
        /*
         * in this case, the speed (n) is number of 1/70s ticks between frames:
         *
         *    pts        n * frame #
         *  --------  =  -----------  => pts = n * (90000/70) * frame #
         *   90000           70
         *
         *  therefore, the frame pts increment = n * 1285.7
         */
        flic->frame_pts_inc = speed * 1285.7;
    } else if (magic_number == FLIC_FILE_MAGIC_2) {
        /*
         * in this case, the speed (n) is number of milliseconds between frames:
         *
         *    pts        n * frame #
         *  --------  =  -----------  => pts = n * 90 * frame #
         *   90000          1000
         *
         *  therefore, the frame pts increment = n * 90
         */
        flic->frame_pts_inc = speed * 90;
    } else
        return AVERROR_INVALIDDATA;

    if (flic->frame_pts_inc == 0)
        flic->frame_pts_inc = FLIC_DEFAULT_PTS_INC;

    return 0;
}
Beispiel #17
0
/*
 * Set device state.  Called with target's statlock and PHY lock held.
 */
static int
pmcs_set_dev_state(pmcs_hw_t *pwp, pmcs_phy_t *phyp, pmcs_xscsi_t *xp,
    uint8_t ds)
{
	uint32_t htag, *ptr, msg[PMCS_MSG_SIZE];
	int result;
	uint8_t pds, nds;
	struct pmcwork *pwrk;

	pmcs_prt(pwp, PMCS_PRT_DEBUG_DEV_STATE, phyp, xp,
	    "%s: ds: 0x%x tgt: 0x%p phy: 0x%p", __func__, ds, (void *)xp,
	    (void *)phyp);

	if (phyp == NULL) {
		pmcs_prt(pwp, PMCS_PRT_DEBUG_DEV_STATE, NULL, xp,
		    "%s: PHY is NULL", __func__);
		return (-1);
	}

	pwrk = pmcs_gwork(pwp, PMCS_TAG_TYPE_WAIT, phyp);
	if (pwrk == NULL) {
		pmcs_prt(pwp, PMCS_PRT_ERR, phyp, xp, pmcs_nowrk, __func__);
		return (-1);
	}
	if (phyp->valid_device_id == 0) {
		pmcs_pwork(pwp, pwrk);
		pmcs_prt(pwp, PMCS_PRT_DEBUG_DEV_STATE, phyp, xp,
		    "%s: Invalid DeviceID", __func__);
		return (-1);
	}
	pwrk->arg = msg;
	pwrk->dtype = phyp->dtype;
	htag = pwrk->htag;
	msg[0] = LE_32(PMCS_HIPRI(pwp, PMCS_OQ_GENERAL,
	    PMCIN_SET_DEVICE_STATE));
	msg[1] = LE_32(pwrk->htag);
	msg[2] = LE_32(phyp->device_id);
	msg[3] = LE_32(ds);
	CLEAN_MESSAGE(msg, 4);

	mutex_enter(&pwp->iqp_lock[PMCS_IQ_OTHER]);
	ptr = GET_IQ_ENTRY(pwp, PMCS_IQ_OTHER);
	if (ptr == NULL) {
		mutex_exit(&pwp->iqp_lock[PMCS_IQ_OTHER]);
		pmcs_pwork(pwp, pwrk);
		pmcs_prt(pwp, PMCS_PRT_ERR, phyp, xp, pmcs_nomsg, __func__);
		return (-1);
	}
	COPY_MESSAGE(ptr, msg, PMCS_MSG_SIZE);
	pwrk->state = PMCS_WORK_STATE_ONCHIP;
	INC_IQ_ENTRY(pwp, PMCS_IQ_OTHER);

	if (xp != NULL) {
		mutex_exit(&xp->statlock);
	}
	pmcs_unlock_phy(phyp);
	WAIT_FOR(pwrk, 1000, result);
	pmcs_pwork(pwp, pwrk);
	pmcs_lock_phy(phyp);
	if (xp != NULL) {
		mutex_enter(&xp->statlock);
	}

	if (result) {
		pmcs_timed_out(pwp, htag, __func__);
		pmcs_prt(pwp, PMCS_PRT_DEBUG_DEV_STATE, phyp, xp,
		    "%s: cmd timed out, returning", __func__);
		return (-1);
	}
	if (LE_32(msg[2]) == 0) {
		pds = (uint8_t)(LE_32(msg[4]) >> 4);
		nds = (uint8_t)(LE_32(msg[4]) & 0x0000000f);
		pmcs_prt(pwp, PMCS_PRT_DEBUG_DEV_STATE, phyp, xp,
		    "%s: previous_ds=0x%x, new_ds=0x%x", __func__, pds, nds);
		if (xp != NULL) {
			xp->dev_state = nds;
		}
		return (0);
	} else {
Beispiel #18
0
/*
 * A couple of special scenarios :
 * 1. Since the first logical drive's EBR is always at the beginning of the
 * extended partition, any specification that starts the first logical drive
 * out of order will need to address the following issue :
 * If the beginning of the drive is not coinciding with the beginning of the
 * extended partition  and :
 * a) The start is within MAX_LOGDRIVE_OFFSET, the offset changes from the
 *	default of 63 to less than 63.
 *	logdrive_offset is updated to keep track of the space between
 *	the beginning of the logical drive and extended partition. abs_secnum
 *	points to the beginning of the extended partition.
 * b) The start is greater than MAX_LOGDRIVE_OFFSET, the offset changes from
 *	the default of 63 to greater than 63.
 *	logdrive_offset is set to 0. abs_secnum points to the beginning of the
 *	logical drive, which is at an offset from the extended partition.
 */
void
fdisk_add_logical_drive(ext_part_t *epp, uint32_t begsec, uint32_t endsec,
    uchar_t partid)
{
	logical_drive_t *temp, *pre, *cur;
	struct ipart *part;

	temp = fdisk_alloc_ld_node();
	temp->abs_secnum = begsec;
	temp->logdrive_offset = MAX_LOGDRIVE_OFFSET;
	temp->numsect = endsec - begsec + 1 - MAX_LOGDRIVE_OFFSET;
	temp->begcyl = FDISK_SECT_TO_CYL(epp, begsec);
	temp->endcyl = FDISK_SECT_TO_CYL(epp, endsec);
	temp->modified = FDISK_MAJOR_WRITE;

	part 		= &temp->parts[0];
	part->bootid	= 0;
	part->systid	= LE_8(partid);
	part->relsect	= MAX_LOGDRIVE_OFFSET;
	part->numsect	= LE_32(temp->numsect);

	fdisk_set_CHS_values(epp, part);

	if (epp->ld_head == NULL) {
		epp->corrupt_logical_drives = 0;
		if (begsec != epp->ext_beg_sec) {
			part->relsect = LE_32(begsec - epp->ext_beg_sec);
			temp->numsect = endsec - begsec + 1;
			part->numsect = LE_32(temp->numsect);
			if (LE_32(part->relsect) > MAX_LOGDRIVE_OFFSET) {
				temp->logdrive_offset = 0;
			} else {
				temp->abs_secnum = epp->ext_beg_sec;
				temp->logdrive_offset = LE_32(part->relsect);
			}
		}
		epp->first_ebr_is_null = 0;
		epp->ld_head = temp;
		epp->sorted_ld_head = temp;
		epp->logical_drive_count = 1;
		return;
	}

	if (temp->abs_secnum == epp->ext_beg_sec) {
		part->relsect = LE_32(LE_32(part->relsect) - 1);
		temp->logdrive_offset--;
		temp->abs_secnum++;
	}

	for (pre = cur = epp->ld_head; cur != NULL; pre = cur, cur = cur->next)
		;

	part = &pre->parts[1];
	part->bootid	= 0;
	part->systid	= LE_8(EXTDOS);
	part->relsect	= LE_32(temp->abs_secnum - epp->ext_beg_sec);
	part->numsect	= LE_32(temp->numsect + temp->logdrive_offset);

	fdisk_set_CHS_values(epp, part);

	pre->next = temp;
	pre->modified = FDISK_MAJOR_WRITE;
	epp->logical_drive_count++;
	fdisk_ext_place_in_sorted_list(epp, temp);
}
Beispiel #19
0
/*
 * Get device state.  Called with statlock and PHY lock held.
 */
static int
pmcs_get_dev_state(pmcs_hw_t *pwp, pmcs_phy_t *phyp, pmcs_xscsi_t *xp,
    uint8_t *ds)
{
	uint32_t htag, *ptr, msg[PMCS_MSG_SIZE];
	int result;
	struct pmcwork *pwrk;

	pmcs_prt(pwp, PMCS_PRT_DEBUG3, phyp, xp, "%s: tgt(0x%p)", __func__,
	    (void *)xp);

	if (xp != NULL) {
		ASSERT(mutex_owned(&xp->statlock));
	}

	if (phyp == NULL) {
		pmcs_prt(pwp, PMCS_PRT_DEBUG_DEV_STATE, NULL, xp,
		    "%s: PHY is NULL", __func__);
		return (-1);
	}
	ASSERT(mutex_owned(&phyp->phy_lock));

	pwrk = pmcs_gwork(pwp, PMCS_TAG_TYPE_WAIT, phyp);
	if (pwrk == NULL) {
		pmcs_prt(pwp, PMCS_PRT_ERR, phyp, xp, pmcs_nowrk, __func__);
		return (-1);
	}
	pwrk->arg = msg;
	pwrk->dtype = phyp->dtype;

	if (phyp->valid_device_id == 0) {
		pmcs_pwork(pwp, pwrk);
		pmcs_prt(pwp, PMCS_PRT_DEBUG, phyp, xp,
		    "%s: Invalid DeviceID", __func__);
		return (-1);
	}
	htag = pwrk->htag;
	msg[0] = LE_32(PMCS_HIPRI(pwp, PMCS_OQ_GENERAL,
	    PMCIN_GET_DEVICE_STATE));
	msg[1] = LE_32(pwrk->htag);
	msg[2] = LE_32(phyp->device_id);
	CLEAN_MESSAGE(msg, 3);

	mutex_enter(&pwp->iqp_lock[PMCS_IQ_OTHER]);
	ptr = GET_IQ_ENTRY(pwp, PMCS_IQ_OTHER);
	if (ptr == NULL) {
		mutex_exit(&pwp->iqp_lock[PMCS_IQ_OTHER]);
		pmcs_pwork(pwp, pwrk);
		pmcs_prt(pwp, PMCS_PRT_ERR, phyp, xp, pmcs_nomsg, __func__);
		return (-1);
	}
	COPY_MESSAGE(ptr, msg, PMCS_MSG_SIZE);
	pwrk->state = PMCS_WORK_STATE_ONCHIP;
	INC_IQ_ENTRY(pwp, PMCS_IQ_OTHER);

	if (xp != NULL) {
		mutex_exit(&xp->statlock);
	}
	pmcs_unlock_phy(phyp);
	WAIT_FOR(pwrk, 1000, result);
	pmcs_pwork(pwp, pwrk);
	pmcs_lock_phy(phyp);

	if (xp != NULL) {
		mutex_enter(&xp->statlock);
	}

	if (result) {
		pmcs_timed_out(pwp, htag, __func__);
		pmcs_prt(pwp, PMCS_PRT_DEBUG, phyp, xp,
		    "%s: cmd timed out, returning", __func__);
		return (-1);
	}
	if (LE_32(msg[2]) == 0) {
		*ds = (uint8_t)(LE_32(msg[4]));
		if (xp == NULL) {
			pmcs_prt(pwp, PMCS_PRT_DEBUG_DEV_STATE, phyp, xp,
			    "%s: retrieved_ds=0x%x", __func__, *ds);
		} else if (*ds !=  xp->dev_state) {
			pmcs_prt(pwp, PMCS_PRT_DEBUG_DEV_STATE, phyp, xp,
			    "%s: retrieved_ds=0x%x, target_ds=0x%x", __func__,
			    *ds, xp->dev_state);
		}
		return (0);
	} else {
		pmcs_prt(pwp, PMCS_PRT_DEBUG_DEV_STATE, phyp, xp,
		    "%s: cmd failed Status(0x%x), returning ", __func__,
		    LE_32(msg[2]));
		return (-1);
	}
}
Beispiel #20
0
static int str_read_packet(AVFormatContext *s,
                           AVPacket *ret_pkt)
{
    ByteIOContext *pb = &s->pb;
    StrDemuxContext *str = (StrDemuxContext *)s->priv_data;
    unsigned char sector[RAW_CD_SECTOR_SIZE];
    int channel;
    int packet_read = 0;
    int ret = 0;
    AVPacket *pkt;

    while (!packet_read) {

        if (get_buffer(pb, sector, RAW_CD_SECTOR_SIZE) != RAW_CD_SECTOR_SIZE)
            return AVERROR_IO;

        channel = sector[0x11];
        if (channel >= 32)
            return AVERROR_INVALIDDATA;

        switch (sector[0x12] & CDXA_TYPE_MASK) {

        case CDXA_TYPE_DATA:
        case CDXA_TYPE_VIDEO:
            /* check if this the video channel we care about */
            if (channel == str->video_channel) {

                int current_sector = LE_16(&sector[0x1C]);
                int sector_count   = LE_16(&sector[0x1E]);
                int frame_size = LE_32(&sector[0x24]);
                int bytes_to_copy;
//        printf("%d %d %d\n",current_sector,sector_count,frame_size);
                /* if this is the first sector of the frame, allocate a pkt */
                pkt = &str->tmp_pkt;
                if (current_sector == 0) {
                    if (av_new_packet(pkt, frame_size))
                        return AVERROR_IO;

                    pkt->pos= url_ftell(pb) - RAW_CD_SECTOR_SIZE;
                    pkt->stream_index =
                        str->channels[channel].video_stream_index;
               //     pkt->pts = str->pts;

                    /* if there is no audio, adjust the pts after every video
                     * frame; assume 15 fps */
                   if (str->audio_channel != -1)
                       str->pts += (90000 / 15);
                }

                /* load all the constituent chunks in the video packet */
                bytes_to_copy = frame_size - current_sector*VIDEO_DATA_CHUNK_SIZE;
                if (bytes_to_copy>0) {
                    if (bytes_to_copy>VIDEO_DATA_CHUNK_SIZE) bytes_to_copy=VIDEO_DATA_CHUNK_SIZE;
                    memcpy(pkt->data + current_sector*VIDEO_DATA_CHUNK_SIZE,
                        sector + VIDEO_DATA_HEADER_SIZE, bytes_to_copy);
                }
                if (current_sector == sector_count-1) {
                    *ret_pkt = *pkt;
                    return 0;
                }

            }
            break;

        case CDXA_TYPE_AUDIO:
#ifdef PRINTSTUFF
printf (" dropping audio sector\n");
#endif
#if 1
            /* check if this the video channel we care about */
            if (channel == str->audio_channel) {
                pkt = ret_pkt;
                if (av_new_packet(pkt, 2304))
                    return AVERROR_IO;
                memcpy(pkt->data,sector+24,2304);

                pkt->stream_index =
                    str->channels[channel].audio_stream_index;
                //pkt->pts = str->pts;
                return 0;
            }
#endif
            break;
        default:
            /* drop the sector and move on */
#ifdef PRINTSTUFF
printf (" dropping other sector\n");
#endif
            break;
        }

        if (url_feof(pb))
            return AVERROR_IO;
    }

    return ret;
}
Beispiel #21
0
static int str_read_header(AVFormatContext *s,
                           AVFormatParameters *ap)
{
    ByteIOContext *pb = &s->pb;
    StrDemuxContext *str = (StrDemuxContext *)s->priv_data;
    AVStream *st;
    unsigned char sector[RAW_CD_SECTOR_SIZE];
    int start;
    int i;
    int channel;

    /* initialize context members */
    str->pts = 0;
    str->audio_channel = -1;  /* assume to audio or video */
    str->video_channel = -1;
    str->video_chunk = NULL;


    /* skip over any RIFF header */
    if (get_buffer(pb, sector, RIFF_HEADER_SIZE) != RIFF_HEADER_SIZE)
        return AVERROR_IO;
    if (LE_32(&sector[0]) == RIFF_TAG)
        start = RIFF_HEADER_SIZE;
    else
        start = 0;

    url_fseek(pb, start, SEEK_SET);

    /* check through the first 32 sectors for individual channels */
    for (i = 0; i < 32; i++) {
        if (get_buffer(pb, sector, RAW_CD_SECTOR_SIZE) != RAW_CD_SECTOR_SIZE)
            return AVERROR_IO;

//printf("%02x %02x %02x %02x\n",sector[0x10],sector[0x11],sector[0x12],sector[0x13]);

        channel = sector[0x11];
        if (channel >= 32)
            return AVERROR_INVALIDDATA;

        switch (sector[0x12] & CDXA_TYPE_MASK) {

        case CDXA_TYPE_DATA:
        case CDXA_TYPE_VIDEO:
            /* check if this channel gets to be the dominant video channel */
            if (str->video_channel == -1) {
                /* qualify the magic number */
                if (LE_32(&sector[0x18]) != STR_MAGIC)
                    break;
                str->video_channel = channel;
                str->channels[channel].type = STR_VIDEO;
                str->channels[channel].width = LE_16(&sector[0x28]);
                str->channels[channel].height = LE_16(&sector[0x2A]);

                /* allocate a new AVStream */
                st = av_new_stream(s, 0);
                if (!st)
                    return AVERROR_NOMEM;
                av_set_pts_info(st, 64, 1, 15);

                str->channels[channel].video_stream_index = st->index;

                st->codec->codec_type = CODEC_TYPE_VIDEO;
                st->codec->codec_id = CODEC_ID_MDEC;
                st->codec->codec_tag = 0;  /* no fourcc */
                st->codec->width = str->channels[channel].width;
                st->codec->height = str->channels[channel].height;
            }
            break;

        case CDXA_TYPE_AUDIO:
            /* check if this channel gets to be the dominant audio channel */
            if (str->audio_channel == -1) {
                int fmt;
                str->audio_channel = channel;
                str->channels[channel].type = STR_AUDIO;
                str->channels[channel].channels =
                    (sector[0x13] & 0x01) ? 2 : 1;
                str->channels[channel].sample_rate =
                    (sector[0x13] & 0x04) ? 18900 : 37800;
                str->channels[channel].bits =
                    (sector[0x13] & 0x10) ? 8 : 4;

                /* allocate a new AVStream */
                st = av_new_stream(s, 0);
                if (!st)
                    return AVERROR_NOMEM;
                av_set_pts_info(st, 64, 128, str->channels[channel].sample_rate);

                str->channels[channel].audio_stream_index = st->index;

                fmt = sector[0x13];
                st->codec->codec_type = CODEC_TYPE_AUDIO;
                st->codec->codec_id = CODEC_ID_ADPCM_XA;
                st->codec->codec_tag = 0;  /* no fourcc */
                st->codec->channels = (fmt&1)?2:1;
                st->codec->sample_rate = (fmt&4)?18900:37800;
            //    st->codec->bit_rate = 0; //FIXME;
                st->codec->block_align = 128;
            }
            break;

        default:
            /* ignore */
            break;
        }
    }

if (str->video_channel != -1)
  av_log (s, AV_LOG_DEBUG, " video channel = %d, %d x %d %d\n", str->video_channel,
    str->channels[str->video_channel].width,
    str->channels[str->video_channel].height,str->channels[str->video_channel].video_stream_index);
if (str->audio_channel != -1)
   av_log (s, AV_LOG_DEBUG, " audio channel = %d, %d Hz, %d channels, %d bits/sample %d\n",
    str->audio_channel,
    str->channels[str->audio_channel].sample_rate,
    str->channels[str->audio_channel].channels,
    str->channels[str->audio_channel].bits,str->channels[str->audio_channel].audio_stream_index);

    /* back to the start */
    url_fseek(pb, start, SEEK_SET);

    return 0;
}
Beispiel #22
0
/* ARGSUSED */
static int
xhci_mdb_print_slotctx(uintptr_t addr, uint_t flags, int argc,
    const mdb_arg_t *argv)
{
	uint32_t info, info2, tt, state;
	xhci_slot_context_t sctx;

	if (!(flags & DCMD_ADDRSPEC)) {
		mdb_warn("::xhci_slotctx requires an address\n");
		return (DCMD_USAGE);
	}

	if (mdb_vread(&sctx, sizeof (sctx), addr) != sizeof (sctx)) {
		mdb_warn("failed to read xhci_slot_context_t at %p", addr);
		return (DCMD_ERR);
	}

	info = LE_32(sctx.xsc_info);
	info2 = LE_32(sctx.xsc_info2);
	tt = LE_32(sctx.xsc_tt);
	state = LE_32(sctx.xsc_state);

	mdb_printf("Route: 0x%x\n", XHCI_SCTX_GET_ROUTE(info));

	mdb_printf("Slot Speed: ");
	switch (XHCI_SCTX_GET_SPEED(info)) {
	case XHCI_SPEED_FULL:
		mdb_printf("Full");
		break;
	case XHCI_SPEED_LOW:
		mdb_printf("Low");
		break;
	case XHCI_SPEED_HIGH:
		mdb_printf("High");
		break;
	case XHCI_SPEED_SUPER:
		mdb_printf("Super");
		break;
	default:
		mdb_printf("Unknown");
		break;
	}
	mdb_printf(" (%d)\n", XHCI_SCTX_GET_SPEED(info));


	mdb_printf("MTT: %d\n", XHCI_SCTX_GET_MTT(info));
	mdb_printf("HUB: %d\n", XHCI_SCTX_GET_HUB(info));
	mdb_printf("DCI: %d\n", XHCI_SCTX_GET_DCI(info));

	mdb_printf("Max Exit Latency: %d\n", XHCI_SCTX_GET_MAX_EL(info2));
	mdb_printf("Root Hub Port: %d\n", XHCI_SCTX_GET_RHPORT(info2));
	mdb_printf("Hub Number of Ports: %d\n", XHCI_SCTX_GET_NPORTS(info2));

	mdb_printf("TT Hub Slot id: %d\n", XHCI_SCTX_GET_TT_HUB_SID(tt));
	mdb_printf("TT Port Number: %d\n", XHCI_SCTX_GET_TT_PORT_NUM(tt));
	mdb_printf("TT Think Time: %d\n", XHCI_SCTX_GET_TT_THINK_TIME(tt));
	mdb_printf("IRQ Target: %d\n", XHCI_SCTX_GET_IRQ_TARGET(tt));

	mdb_printf("Device Address: 0x%x\n", XHCI_SCTX_GET_DEV_ADDR(state));
	mdb_printf("Slot State: ");
	switch (XHCI_SCTX_GET_SLOT_STATE(state)) {
	case XHCI_SLOT_DIS_ENAB:
		mdb_printf("Disabled/Enabled");
		break;
	case XHCI_SLOT_DEFAULT:
		mdb_printf("Default");
		break;
	case XHCI_SLOT_ADDRESSED:
		mdb_printf("Addressed");
		break;
	case XHCI_SLOT_CONFIGURED:
		mdb_printf("Configured");
		break;
	default:
		mdb_printf("Unknown");
		break;
	}
	mdb_printf(" (%d)\n", XHCI_SCTX_GET_SLOT_STATE(state));

	return (DCMD_OK);
}
Beispiel #23
0
/*
 * Procedure to walk through the extended partitions and build a Singly
 * Linked List out of the data.
 */
static int
fdisk_read_extpart(ext_part_t *epp)
{
	struct ipart *fdp, *ext_fdp;
	int i = 0, j = 0, ext_part_found = 0, lpart = 5;
	off_t secnum, offset;
	logical_drive_t *temp, *ep_ptr;
	unsigned char *ext_buf;
	int sectsize = epp->disk_geom.sectsize;

	if ((ext_buf = (uchar_t *)malloc(sectsize)) == NULL) {
		return (ENOMEM);
	}
	fdp = epp->mtable;

	for (i = 0; (i < FD_NUMPART) && (!ext_part_found); i++, fdp++) {
		if (fdisk_is_dos_extended(LE_8(fdp->systid))) {
			ext_part_found = 1;
			secnum = LE_32(fdp->relsect);
			offset = secnum * sectsize;
			epp->ext_beg_sec = secnum;
			epp->ext_end_sec = secnum + LE_32(fdp->numsect) - 1;
			epp->ext_beg_cyl =
			    FDISK_SECT_TO_CYL(epp, epp->ext_beg_sec);
			epp->ext_end_cyl =
			    FDISK_SECT_TO_CYL(epp, epp->ext_end_sec);

			/*LINTED*/
			while (B_TRUE) {
				if (lseek(epp->dev_fd, offset, SEEK_SET) < 0) {
					return (EIO);
				}
				if (read(epp->dev_fd, ext_buf, sectsize) <
				    sectsize) {
					return (EIO);
				}
				/*LINTED*/
				ext_fdp = (struct ipart *)
				    (&ext_buf[FDISK_PART_TABLE_START]);
				if ((LE_32(ext_fdp->relsect) == 0) &&
				    (epp->logical_drive_count == 0)) {
					/* No logical drives defined */
					epp->first_ebr_is_null = 0;
					return (FDISK_ENOLOGDRIVE);
				}

				temp = fdisk_alloc_ld_node();
				temp->abs_secnum = secnum;
				temp->logdrive_offset =
				    LE_32(ext_fdp->relsect);
				temp ->numsect = LE_32(ext_fdp->numsect);
				if (epp->ld_head == NULL) {
					/* adding first logical drive */
					if (temp->logdrive_offset >
					    MAX_LOGDRIVE_OFFSET) {
						/* out of order */
						temp->abs_secnum +=
						    temp->logdrive_offset;
						temp->logdrive_offset = 0;
					}
				}
				temp->begcyl =
				    FDISK_SECT_TO_CYL(epp, temp->abs_secnum);
				temp->endcyl = FDISK_SECT_TO_CYL(epp,
				    temp->abs_secnum +
				    temp->logdrive_offset +
				    temp->numsect - 1);

				/*
				 * Check for sanity of logical drives
				 */
				if (fdisk_validate_logical_drive(epp,
				    temp->abs_secnum, temp->logdrive_offset,
				    temp->numsect)) {
					epp->corrupt_logical_drives = 1;
					free(temp);
					return (FDISK_EBADLOGDRIVE);
				}

				temp->parts[0] = *ext_fdp;
				ext_fdp++;
				temp->parts[1] = *ext_fdp;

				if (epp->ld_head == NULL) {
					epp->ld_head = temp;
					epp->sorted_ld_head = temp;
					ep_ptr = temp;
					epp->logical_drive_count = 1;
				} else {
					ep_ptr->next = temp;
					ep_ptr = temp;
					fdisk_ext_place_in_sorted_list(epp,
					    temp);
					epp->logical_drive_count++;
				}

				/*LINTED*/
				if (LE_16((*(uint16_t *)&ext_buf[510])) !=
				    MBB_MAGIC) {
					epp->invalid_bb_sig[j++] = lpart;
					temp->modified = FDISK_MINOR_WRITE;
				}

				if (LE_32(ext_fdp->relsect) == 0)
					break;
				else {
					secnum = LE_32(fdp->relsect) +
					    LE_32(ext_fdp->relsect);
					offset = secnum * sectsize;
				}
				lpart++;
			}
		}
	}
	return (FDISK_SUCCESS);
}
Beispiel #24
0
/**
 * decode a frame
 * @param avctx codec context
 * @param data output AVFrame
 * @param data_size size of output data or 0 if no picture is returned
 * @param buf input data frame
 * @param buf_size size of input data frame
 * @return number of consumed bytes on success or negative if decode fails
 */
static int decode_frame(AVCodecContext *avctx, 
                        void *data, int *data_size,
                        uint8_t *buf, int buf_size)
{
    FrapsContext * const s = avctx->priv_data;
    AVFrame *frame = data;
    AVFrame * const f = (AVFrame*)&s->frame;
    uint32_t header;
    unsigned int version,header_size;
    unsigned int x, y;
    uint32_t *buf32;
    uint32_t *luma1,*luma2,*cb,*cr;


    header = LE_32(buf);
    version = header & 0xff;
    header_size = (header & (1<<30))? 8 : 4; /* bit 30 means pad to 8 bytes */

    if (version > 1) {
        av_log(avctx, AV_LOG_ERROR, 
               "This file is encoded with Fraps version %d. " \
               "This codec can only decode version 0 and 1.\n", version);
        return -1;
    }

    buf+=4;
    if (header_size == 8)
        buf+=4;
        
    switch(version) {
    case 0:
    default:
        /* Fraps v0 is a reordered YUV420 */
        avctx->pix_fmt = PIX_FMT_YUV420P;

        if ( (buf_size != avctx->width*avctx->height*3/2+header_size) && 
             (buf_size != header_size) ) {
            av_log(avctx, AV_LOG_ERROR,
                   "Invalid frame length %d (should be %d)\n", 
                   buf_size, avctx->width*avctx->height*3/2+header_size);
            return -1;
        }
        
        if (( (avctx->width % 8) != 0) || ( (avctx->height % 2) != 0 )) {
            av_log(avctx, AV_LOG_ERROR, "Invalid frame size %dx%d\n", 
                   avctx->width, avctx->height);
            return -1;
        }

        f->reference = 1; 
        f->buffer_hints = FF_BUFFER_HINTS_VALID | 
                          FF_BUFFER_HINTS_PRESERVE | 
                          FF_BUFFER_HINTS_REUSABLE;
        if (avctx->reget_buffer(avctx, f)) {
            av_log(avctx, AV_LOG_ERROR, "reget_buffer() failed\n");
            return -1;
        }        
        /* bit 31 means same as previous pic */
        f->pict_type = (header & (1<<31))? FF_P_TYPE : FF_I_TYPE; 
        f->key_frame = f->pict_type == FF_I_TYPE;

        if (f->pict_type == FF_I_TYPE) { 
            buf32=(uint32_t*)buf;
            for(y=0; y<avctx->height/2; y++){
                luma1=(uint32_t*)&f->data[0][ y*2*f->linesize[0] ];
                luma2=(uint32_t*)&f->data[0][ (y*2+1)*f->linesize[0] ];
                cr=(uint32_t*)&f->data[1][ y*f->linesize[1] ];
                cb=(uint32_t*)&f->data[2][ y*f->linesize[2] ];
                for(x=0; x<avctx->width; x+=8){
                    *(luma1++) = *(buf32++);
                    *(luma1++) = *(buf32++);
                    *(luma2++) = *(buf32++);
                    *(luma2++) = *(buf32++);
                    *(cr++) = *(buf32++);
                    *(cb++) = *(buf32++);
                }
            }
        }
        break;

    case 1:
        /* Fraps v1 is an upside-down BGR24 */
        avctx->pix_fmt = PIX_FMT_BGR24;

        if ( (buf_size != avctx->width*avctx->height*3+header_size) && 
             (buf_size != header_size) ) {
            av_log(avctx, AV_LOG_ERROR, 
                   "Invalid frame length %d (should be %d)\n",
                   buf_size, avctx->width*avctx->height*3+header_size);
            return -1;
        }

        f->reference = 1;
        f->buffer_hints = FF_BUFFER_HINTS_VALID |
                          FF_BUFFER_HINTS_PRESERVE |
                          FF_BUFFER_HINTS_REUSABLE;
        if (avctx->reget_buffer(avctx, f)) {
            av_log(avctx, AV_LOG_ERROR, "reget_buffer() failed\n");
            return -1;
        }
        /* bit 31 means same as previous pic */
        f->pict_type = (header & (1<<31))? FF_P_TYPE : FF_I_TYPE;
        f->key_frame = f->pict_type == FF_I_TYPE;

        if (f->pict_type == FF_I_TYPE) {
            for(y=0; y<avctx->height; y++)
                memcpy(&f->data[0][ (avctx->height-y)*f->linesize[0] ],
                       &buf[y*avctx->width*3],
                       f->linesize[0]);
        }
        break;

    case 2:
        /**
         * Fraps v2 sub-header description. All numbers are little-endian:
         * (this is all guesswork)
         *
         *       0:     DWORD 'FPSx'
         *       4:     DWORD 0x00000010   unknown, perhaps flags
         *       8:     DWORD off_2        offset to plane 2
         *      12:     DWORD off_3        offset to plane 3
         *      16: 256xDWORD freqtbl_1    frequency table for plane 1
         *    1040:           plane_1
         *     ...
         *   off_2: 256xDWORD freqtbl_2    frequency table for plane 2
         *                    plane_2
         *    ...
         *   off_3: 256xDWORD freqtbl_3    frequency table for plane 3
         *                    plane_3
         */
        if ((BE_32(buf) != FPS_TAG)||(buf_size < (3*1024 + 8))) {
            av_log(avctx, AV_LOG_ERROR, "Fraps: error in data stream\n");
            return -1;
        }

        /* NOT FINISHED */

        break;
    }

    *frame = *f;
    *data_size = sizeof(AVFrame);

    return buf_size;
}
/**
 * Decode Smacker audio data
 */
static int smka_decode_frame(AVCodecContext *avctx, void *data, int *data_size, uint8_t *buf, int buf_size)
{
    GetBitContext gb;
    HuffContext h[4];
    VLC vlc[4];
    int16_t *samples = data;
    int val;
    int i, res;
    int unp_size;
    int bits, stereo;
    int pred[2] = {0, 0};

    unp_size = LE_32(buf);

    init_get_bits(&gb, buf + 4, (buf_size - 4) * 8);

    if(!get_bits1(&gb)){
        av_log(avctx, AV_LOG_INFO, "Sound: no data\n");
        *data_size = 0;
        return 1;
    }
    stereo = get_bits1(&gb);
    bits = get_bits1(&gb);

    memset(vlc, 0, sizeof(VLC) * 4);
    memset(h, 0, sizeof(HuffContext) * 4);
    // Initialize
    for(i = 0; i < (1 << (bits + stereo)); i++) {
        h[i].length = 256;
        h[i].maxlength = 0;
        h[i].current = 0;
        h[i].bits = av_mallocz(256 * 4);
        h[i].lengths = av_mallocz(256 * sizeof(int));
        h[i].values = av_mallocz(256 * sizeof(int));
        get_bits1(&gb);
        smacker_decode_tree(&gb, &h[i], 0, 0);
        get_bits1(&gb);
        if(h[i].current > 1) {
            res = init_vlc(&vlc[i], SMKTREE_BITS, h[i].length,
                    h[i].lengths, sizeof(int), sizeof(int),
                    h[i].bits, sizeof(uint32_t), sizeof(uint32_t), INIT_VLC_LE);
            if(res < 0) {
                av_log(avctx, AV_LOG_ERROR, "Cannot build VLC table\n");
                return -1;
            }
        }
    }
    if(bits) { //decode 16-bit data
        pred[0]  = get_bits(&gb, 8);
        pred[0] |= get_bits(&gb, 8);
        *samples++ = pred[0];
        if(stereo) {
            pred[1]  = get_bits(&gb, 8);
            pred[1] |= get_bits(&gb, 8);
            *samples++ = pred[1];
        }
        for(i = 0; i < unp_size / 2; i++) {
            if(i & stereo) {
                if(vlc[2].table)
                    res = get_vlc2(&gb, vlc[2].table, SMKTREE_BITS, 3);
                else
                    res = 0;
                val  = h[2].values[res];
                if(vlc[3].table)
                    res = get_vlc2(&gb, vlc[3].table, SMKTREE_BITS, 3);
                else
                    res = 0;
                val |= h[3].values[res] << 8;
                pred[1] += (int16_t)val;
                *samples++ = pred[1];
            } else {
                if(vlc[0].table)
                    res = get_vlc2(&gb, vlc[0].table, SMKTREE_BITS, 3);
                else
                    res = 0;
                val  = h[0].values[res];
                if(vlc[1].table)
                    res = get_vlc2(&gb, vlc[1].table, SMKTREE_BITS, 3);
                else
                    res = 0;
                val |= h[1].values[res] << 8;
                pred[0] += val;
                *samples++ = pred[0];
            }
        }
    } else { //8-bit data
        pred[0] = get_bits(&gb, 8);
        *samples++ = (pred[0] - 0x80) << 8;
        if(stereo) {
            pred[1] = get_bits(&gb, 8);
            *samples++ = (pred[1] - 0x80) << 8;
        }
        for(i = 0; i < unp_size; i++) {
            if(i & stereo){
                if(vlc[1].table)
                    res = get_vlc2(&gb, vlc[1].table, SMKTREE_BITS, 3);
                else
                    res = 0;
                pred[1] += (int8_t)h[1].values[res];
                *samples++ = (pred[1] - 0x80) << 8;
            } else {
                if(vlc[0].table)
                    res = get_vlc2(&gb, vlc[0].table, SMKTREE_BITS, 3);
                else
                    res = 0;
                pred[0] += (int8_t)h[0].values[res];
                *samples++ = (pred[0] - 0x80) << 8;
            }
        }
        unp_size *= 2;
    }

    for(i = 0; i < 4; i++) {
        if(vlc[i].table)
            free_vlc(&vlc[i]);
        if(h[i].bits)
            av_free(h[i].bits);
        if(h[i].lengths)
            av_free(h[i].lengths);
        if(h[i].values)
            av_free(h[i].values);
    }

    *data_size = unp_size;
    return buf_size;
}
Beispiel #26
0
static int fourxm_read_packet(AVFormatContext *s,
                              AVPacket *pkt)
{
    FourxmDemuxContext *fourxm = s->priv_data;
    ByteIOContext *pb = &s->pb;
    unsigned int fourcc_tag;
    unsigned int size, out_size;
    int ret = 0;
    int track_number;
    int packet_read = 0;
    unsigned char header[8];
    int64_t pts_inc;
    int audio_frame_count;

    while (!packet_read) {

        if ((ret = get_buffer(&s->pb, header, 8)) < 0)
            return ret;
        fourcc_tag = LE_32(&header[0]);
        size = LE_32(&header[4]);
        if (url_feof(pb))
            return AVERROR_IO;
        switch (fourcc_tag) {

        case LIST_TAG:
            /* this is a good time to bump the video pts */
            fourxm->video_pts += fourxm->video_pts_inc;

            /* skip the LIST-* tag and move on to the next fourcc */
            get_le32(pb);
            break;

        case ifrm_TAG:
        case pfrm_TAG:
        case cfrm_TAG:{

            /* allocate 8 more bytes than 'size' to account for fourcc
             * and size */
            if (av_new_packet(pkt, size + 8))
                return AVERROR_IO;
            pkt->stream_index = fourxm->video_stream_index;
            pkt->pts = fourxm->video_pts;
            memcpy(pkt->data, header, 8);
            ret = get_buffer(&s->pb, &pkt->data[8], size);

            if (ret < 0)
                av_free_packet(pkt);
            else
                packet_read = 1;
            break;
        }

        case snd__TAG:
            track_number = get_le32(pb);
            out_size= get_le32(pb);
            size-=8;

            if (track_number == fourxm->selected_track) {
                if (av_new_packet(pkt, size))
                    return AVERROR_IO;
                pkt->stream_index = 
                    fourxm->tracks[fourxm->selected_track].stream_index;
                pkt->pts = fourxm->audio_pts;
                ret = get_buffer(&s->pb, pkt->data, size);
                if (ret < 0)
                    av_free_packet(pkt);
                else
                    packet_read = 1;

                /* pts accounting */
                audio_frame_count = size;
                if (fourxm->tracks[fourxm->selected_track].adpcm)
                    audio_frame_count -= 
                        2 * (fourxm->tracks[fourxm->selected_track].channels);
                audio_frame_count /=
                      fourxm->tracks[fourxm->selected_track].channels;
                if (fourxm->tracks[fourxm->selected_track].adpcm)
                    audio_frame_count *= 2;
                else 
                    audio_frame_count /=
                    (fourxm->tracks[fourxm->selected_track].bits / 8);
                pts_inc = audio_frame_count;
                pts_inc *= 90000;
                pts_inc /= fourxm->tracks[fourxm->selected_track].sample_rate;
                fourxm->audio_pts += pts_inc;

            } else {
                url_fseek(pb, size, SEEK_CUR);
            }
            break;

        default:
            url_fseek(pb, size, SEEK_CUR);
            break;
        }
    }
    return ret;
}
Beispiel #27
0
static int fourxm_read_header(AVFormatContext *s,
                              AVFormatParameters *ap)
{
    ByteIOContext *pb = &s->pb;
    unsigned int fourcc_tag;
    unsigned int size;
    int header_size;
    FourxmDemuxContext *fourxm = (FourxmDemuxContext *)s->priv_data;
    unsigned char *header;
    int i;
    int current_track = -1;
    AVStream *st;

    fourxm->track_count = 0;
    fourxm->tracks = NULL;
    fourxm->selected_track = 0;
    fourxm->fps = 1.0;

    /* skip the first 3 32-bit numbers */
    url_fseek(pb, 12, SEEK_CUR);

    /* check for LIST-HEAD */
    GET_LIST_HEADER();
    header_size = size - 4;
    if (fourcc_tag != HEAD_TAG)
        return AVERROR_INVALIDDATA;

    /* allocate space for the header and load the whole thing */
    header = av_malloc(header_size);
    if (!header)
        return AVERROR_NOMEM;
    if (get_buffer(pb, header, header_size) != header_size)
        return AVERROR_IO;

    /* take the lazy approach and search for any and all vtrk and strk chunks */
    for (i = 0; i < header_size - 8; i++) {
        fourcc_tag = LE_32(&header[i]);
        size = LE_32(&header[i + 4]);

        if (fourcc_tag == std__TAG) {
            fourxm->fps = get_le_float(&header[i + 12]);
            fourxm->video_pts_inc = (int)(90000.0 / fourxm->fps);
        } else if (fourcc_tag == vtrk_TAG) {
            /* check that there is enough data */
            if (size != vtrk_SIZE) {
                av_free(header);
                return AVERROR_INVALIDDATA;
            }
            fourxm->width = LE_32(&header[i + 36]);
            fourxm->height = LE_32(&header[i + 40]);
            i += 8 + size;

            /* allocate a new AVStream */
            st = av_new_stream(s, 0);
            if (!st)
                return AVERROR_NOMEM;
            av_set_pts_info(st, 33, 1, 90000);

            fourxm->video_stream_index = st->index;

            st->codec.frame_rate = fourxm->fps;
            st->codec.frame_rate_base = 1.0;
            st->codec.codec_type = CODEC_TYPE_VIDEO;
            st->codec.codec_id = CODEC_ID_4XM;
            st->codec.codec_tag = 0;  /* no fourcc */
            st->codec.width = fourxm->width;
            st->codec.height = fourxm->height;

        } else if (fourcc_tag == strk_TAG) {
            /* check that there is enough data */
            if (size != strk_SIZE) {
                av_free(header);
                return AVERROR_INVALIDDATA;
            }
            current_track = LE_32(&header[i + 8]);
            if (current_track + 1 > fourxm->track_count) {
                fourxm->track_count = current_track + 1;
                fourxm->tracks = av_realloc(fourxm->tracks, 
                    fourxm->track_count * sizeof(AudioTrack));
                if (!fourxm->tracks) {
                    av_free(header);
                    return AVERROR_NOMEM;
                }
            }
            fourxm->tracks[current_track].adpcm = LE_32(&header[i + 12]);
            fourxm->tracks[current_track].channels = LE_32(&header[i + 36]);
            fourxm->tracks[current_track].sample_rate = LE_32(&header[i + 40]);
            fourxm->tracks[current_track].bits = LE_32(&header[i + 44]);
            i += 8 + size;

            /* allocate a new AVStream */
            st = av_new_stream(s, current_track);
            if (!st)
                return AVERROR_NOMEM;

            /* set the pts reference (1 pts = 1/90000) */
            av_set_pts_info(st, 33, 1, 90000);

            fourxm->tracks[current_track].stream_index = st->index;

            st->codec.codec_type = CODEC_TYPE_AUDIO;
            st->codec.codec_tag = 1;
            st->codec.channels = fourxm->tracks[current_track].channels;
            st->codec.sample_rate = fourxm->tracks[current_track].sample_rate;
            st->codec.bits_per_sample = fourxm->tracks[current_track].bits;
            st->codec.bit_rate = st->codec.channels * st->codec.sample_rate *
                st->codec.bits_per_sample;
            st->codec.block_align = st->codec.channels * st->codec.bits_per_sample;
            if (fourxm->tracks[current_track].adpcm)
                st->codec.codec_id = CODEC_ID_ADPCM_4XM;
            else if (st->codec.bits_per_sample == 8)
                st->codec.codec_id = CODEC_ID_PCM_U8;
            else
                st->codec.codec_id = CODEC_ID_PCM_S16LE;
        }
    }

    av_free(header);

    /* skip over the LIST-MOVI chunk (which is where the stream should be */
    GET_LIST_HEADER();
    if (fourcc_tag != MOVI_TAG)
        return AVERROR_INVALIDDATA;

    /* initialize context members */
    fourxm->video_pts = -fourxm->video_pts_inc;  /* first frame will push to 0 */
    fourxm->audio_pts = 0;

    return 0;
}
int
ipw2200_load_fw(struct ipw2200_softc *sc, uint8_t *buf, size_t size)
{
	struct dma_region	dr[MAX_DR_NUM]; /* maximal, 64 * 4KB = 256KB */
	uint8_t			*p, *end, *v;
	uint32_t		mlen;
	uint32_t		src, dst, ctl, len, sum, off;
	uint32_t		sentinel;
	int			ntries, err, cnt, i;
	clock_t			clk = drv_usectohz(5000000);  /* 5 second */

	ipw2200_imem_put32(sc, 0x3000a0, 0x27000);

	p   = buf;
	end = p + size;

	cnt = 0;
	err = ipw2200_dma_region_alloc(sc, &dr[cnt], MAX_DR_SIZE, DDI_DMA_READ,
	    DDI_DMA_STREAMING);
	if (err != DDI_SUCCESS)
		goto fail0;
	off = 0;
	src = dr[cnt].dr_pbase;

	ipw2200_csr_put32(sc, IPW2200_CSR_AUTOINC_ADDR, 0x27000);

	while (p < end) {
		dst = LE_32(*((uint32_t *)(uintptr_t)p)); p += 4;
		len = LE_32(*((uint32_t *)(uintptr_t)p)); p += 4;
		v = p;
		p += len;
		IPW2200_DBG(IPW2200_DBG_FW, (sc->sc_dip, CE_CONT,
		    "ipw2200_load_fw(): dst=0x%x,len=%u\n", dst, len));

		while (len > 0) {
			/*
			 * if no DMA region is available, allocate a new one
			 */
			if (off == dr[cnt].dr_size) {
				cnt++;
				if (cnt >= MAX_DR_NUM) {
					IPW2200_WARN((sc->sc_dip, CE_WARN,
					    "ipw2200_load_fw(): "
					    "maximum %d DRs is reached\n",
					    cnt));
					cnt--; /* only free alloced DMA */
					goto fail1;
				}
				err = ipw2200_dma_region_alloc(sc, &dr[cnt],
				    MAX_DR_SIZE, DDI_DMA_WRITE,
				    DDI_DMA_STREAMING);
				if (err != DDI_SUCCESS) {
					cnt--; /* only free alloced DMA */
					goto fail1;
				}
				off = 0;
				src = dr[cnt].dr_pbase;
			}
			mlen = min(IPW2200_CB_MAXDATALEN, len);
			mlen = min(mlen, dr[cnt].dr_size - off);

			(void) memcpy(dr[cnt].dr_base + off, v, mlen);
			(void) ddi_dma_sync(dr[cnt].dr_hnd, off, mlen,
			    DDI_DMA_SYNC_FORDEV);

			ctl = IPW2200_CB_DEFAULT_CTL | mlen;
			sum = ctl ^ src ^ dst;
			/*
			 * write a command
			 */
			ipw2200_csr_put32(sc, IPW2200_CSR_AUTOINC_DATA, ctl);
			ipw2200_csr_put32(sc, IPW2200_CSR_AUTOINC_DATA, src);
			ipw2200_csr_put32(sc, IPW2200_CSR_AUTOINC_DATA, dst);
			ipw2200_csr_put32(sc, IPW2200_CSR_AUTOINC_DATA, sum);

			off += mlen;
			src += mlen;
			dst += mlen;
			v   += mlen;
			len -= mlen;
		}
	}

	sentinel = ipw2200_csr_get32(sc, IPW2200_CSR_AUTOINC_ADDR);
	ipw2200_csr_put32(sc, IPW2200_CSR_AUTOINC_DATA, 0);

	IPW2200_DBG(IPW2200_DBG_FW, (sc->sc_dip, CE_CONT,
	    "ipw2200_load_fw(): sentinel=%x\n", sentinel));

	ipw2200_csr_put32(sc, IPW2200_CSR_RST,
	    ~(IPW2200_RST_MASTER_DISABLED | IPW2200_RST_STOP_MASTER)
	    & ipw2200_csr_get32(sc, IPW2200_CSR_RST));

	ipw2200_imem_put32(sc, 0x3000a4, 0x540100);
	for (ntries = 0; ntries < 400; ntries++) {
		uint32_t val;
		val = ipw2200_imem_get32(sc, 0x3000d0);
		if (val >= sentinel)
			break;
		drv_usecwait(100);
	}
	if (ntries == 400) {
		IPW2200_WARN((sc->sc_dip, CE_WARN,
		    "ipw2200_load_fw(): timeout processing command blocks\n"));
		goto fail1;
	}

	mutex_enter(&sc->sc_ilock);

	ipw2200_imem_put32(sc, 0x3000a4, 0x540c00);

	/*
	 * enable all interrupts
	 */
	ipw2200_csr_put32(sc, IPW2200_CSR_INTR_MASK, IPW2200_INTR_MASK_ALL);

	/*
	 * tell the adapter to initialize the firmware,
	 * just simply set it to 0
	 */
	ipw2200_csr_put32(sc, IPW2200_CSR_RST, 0);
	ipw2200_csr_put32(sc, IPW2200_CSR_CTL,
	    ipw2200_csr_get32(sc, IPW2200_CSR_CTL) |
	    IPW2200_CTL_ALLOW_STANDBY);

	/*
	 * wait for interrupt to notify fw initialization is done
	 */
	sc->sc_fw_ok = 0;
	while (!sc->sc_fw_ok) {
		/*
		 * There is an enhancement! we just change from 1s to 5s
		 */
		if (cv_reltimedwait(&sc->sc_fw_cond, &sc->sc_ilock, clk,
		    TR_CLOCK_TICK) < 0)
			break;
	}
	mutex_exit(&sc->sc_ilock);

	if (!sc->sc_fw_ok) {
		IPW2200_WARN((sc->sc_dip, CE_WARN,
		    "ipw2200_load_fw(): firmware(%u) load failed!", size));
		goto fail1;
	}

	for (i = 0; i <= cnt; i++)
		ipw2200_dma_region_free(&dr[i]);

	return (DDI_SUCCESS);

fail1:
	IPW2200_WARN((sc->sc_dip, CE_WARN,
	    "ipw2200_load_fw(): DMA allocation failed, cnt=%d\n", cnt));
	for (i = 0; i <= cnt; i++)
		ipw2200_dma_region_free(&dr[i]);
fail0:
	return (DDI_FAILURE);
}
Beispiel #29
0
static void print_command(char *data, int len)
{
#ifdef DEBUG
  int i;
  int dir = LE_32 (data + 36) >> 16;
  int comm = LE_32 (data + 36) & 0xFFFF;

  lprintf ("----------------------------------------------\n");
  if (dir == 3) {
    lprintf ("send command 0x%02x, %d bytes\n", comm, len);
  } else {
    lprintf ("receive command 0x%02x, %d bytes\n", comm, len);
  }
  lprintf ("  start sequence %08x\n", LE_32 (data +  0));
  lprintf ("  command id     %08x\n", LE_32 (data +  4));
  lprintf ("  length         %8x \n", LE_32 (data +  8));
  lprintf ("  protocol       %08x\n", LE_32 (data + 12));
  lprintf ("  len8           %8x \n", LE_32 (data + 16));
  lprintf ("  sequence #     %08x\n", LE_32 (data + 20));
  lprintf ("  len8  (II)     %8x \n", LE_32 (data + 32));
  lprintf ("  dir | comm     %08x\n", LE_32 (data + 36));
  if (len >= 4)
    lprintf ("  prefix1        %08x\n", LE_32 (data + 40));
  if (len >= 8)
    lprintf ("  prefix2        %08x\n", LE_32 (data + 44));

  for (i = (CMD_HEADER_LEN + CMD_PREFIX_LEN); i < (CMD_HEADER_LEN + CMD_PREFIX_LEN + len); i += 1) {
    unsigned char c = data[i];
    
    if ((c >= 32) && (c < 128))
      lprintf ("%c", c);
    else
      lprintf (" %02x ", c);
    
  }
  if (len > CMD_HEADER_LEN)
    lprintf ("\n");
  lprintf ("----------------------------------------------\n");
#endif
}  
Beispiel #30
0
static void truespeech_read_frame(TSContext *dec, uint8_t *input)
{
    uint32_t t;

    t = LE_32(input); // first dword
    input += 4;

    dec->flag = t &1;

    dec->vector[0] = ts_codebook[0][(t >> 1) &0x1F];
    dec->vector[1] = ts_codebook[1][(t >> 6) &0x1F];
    dec->vector[2] = ts_codebook[2][(t >> 11) &0xF];
    dec->vector[3] = ts_codebook[3][(t >> 15) &0xF];
    dec->vector[4] = ts_codebook[4][(t >> 19) &0xF];
    dec->vector[5] = ts_codebook[5][(t >> 23) &0x7];
    dec->vector[6] = ts_codebook[6][(t >> 26) &0x7];
    dec->vector[7] = ts_codebook[7][(t >> 29) &0x7];


    t = LE_32(input); // second dword
    input += 4;

    dec->offset2[0] = (t >> 0) &0x7F;
    dec->offset2[1] = (t >> 7) &0x7F;
    dec->offset2[2] = (t >> 14) &0x7F;
    dec->offset2[3] = (t >> 21) &0x7F;

    dec->offset1[0] = ((t >> 28) &0xF) << 4;


    t = LE_32(input); // third dword
    input += 4;

    dec->pulseval[0] = (t >> 0) &0x3FFF;
    dec->pulseval[1] = (t >> 14) &0x3FFF;

    dec->offset1[1] = (t >> 28) &0x0F;


    t = LE_32(input); // fourth dword
    input += 4;

    dec->pulseval[2] = (t >> 0) &0x3FFF;
    dec->pulseval[3] = (t >> 14) &0x3FFF;

    dec->offset1[1] |= ((t >> 28) &0x0F) << 4;


    t = LE_32(input); // fifth dword
    input += 4;

    dec->pulsepos[0] = (t >> 4) &0x7FFFFFF;

    dec->pulseoff[0] = (t >> 0) &0xF;

    dec->offset1[0] |= (t >> 31) &1;


    t = LE_32(input); // sixth dword
    input += 4;

    dec->pulsepos[1] = (t >> 4) &0x7FFFFFF;

    dec->pulseoff[1] = (t >> 0) &0xF;

    dec->offset1[0] |= ((t >> 31) &1) << 1;


    t = LE_32(input); // seventh dword
    input += 4;

    dec->pulsepos[2] = (t >> 4) &0x7FFFFFF;

    dec->pulseoff[2] = (t >> 0) &0xF;

    dec->offset1[0] |= ((t >> 31) &1) << 2;


    t = LE_32(input); // eighth dword
    input += 4;

    dec->pulsepos[3] = (t >> 4) &0x7FFFFFF;

    dec->pulseoff[3] = (t >> 0) &0xF;

    dec->offset1[0] |= ((t >> 31) &1) << 3;
}