Esempio n. 1
0
static int tm2_read_stream(TM2Context *ctx, uint8_t *buf, int stream_id) {
    int i;
    int cur = 0;
    int skip = 0;
    int len, toks;
    TM2Codes codes;

    /* get stream length in dwords */
    len = BE_32(buf); buf += 4; cur += 4;
    skip = len * 4 + 4;

    if(len == 0)
        return 4;

    toks = BE_32(buf); buf += 4; cur += 4;
    if(toks & 1) {
        len = BE_32(buf); buf += 4; cur += 4;
        if(len == TM2_ESCAPE) {
            len = BE_32(buf); buf += 4; cur += 4;
        }
        if(len > 0) {
            init_get_bits(&ctx->gb, buf, (skip - cur) * 8);
            if(tm2_read_deltas(ctx, stream_id) == -1)
                return -1;
            buf += ((get_bits_count(&ctx->gb) + 31) >> 5) << 2;
            cur += ((get_bits_count(&ctx->gb) + 31) >> 5) << 2;
        }
Esempio n. 2
0
/*
 * Load the current IE mode pages
 */
static int
load_ie_modepage(ds_scsi_info_t *sip)
{
	struct scsi_ms_hdrs junk_hdrs;
	int result;
	uint_t skey, asc, ascq;

	if (!(sip->si_supp_mode & MODEPAGE_SUPP_IEC))
		return (0);

	bzero(&sip->si_iec_current, sizeof (sip->si_iec_current));
	bzero(&sip->si_iec_changeable, sizeof (sip->si_iec_changeable));

	if ((result = scsi_mode_sense(sip,
	    MODEPAGE_INFO_EXCPT, PC_CURRENT, &sip->si_iec_current,
	    MODEPAGE_INFO_EXCPT_LEN, &sip->si_hdrs, &skey, &asc,
	    &ascq)) == 0) {
		result = scsi_mode_sense(sip,
		    MODEPAGE_INFO_EXCPT, PC_CHANGEABLE,
		    &sip->si_iec_changeable,
		    MODEPAGE_INFO_EXCPT_LEN, &junk_hdrs, &skey, &asc, &ascq);
	}

	if (result != 0) {
		printf("failed to get IEC modepage (KEY=0x%x "
		    "ASC=0x%x ASCQ=0x%x)", skey, asc, ascq);
		sip->si_supp_mode &= ~MODEPAGE_SUPP_IEC;
	} else  {
		if (nvlist_add_boolean_value(sip->si_state_iec,
		    "dexcpt", sip->si_iec_current.ie_dexcpt) != 0 ||
		    nvlist_add_boolean_value(sip->si_state_iec,
		    "logerr", sip->si_iec_current.ie_logerr) != 0 ||
		    nvlist_add_uint8(sip->si_state_iec,
		    "mrie", sip->si_iec_current.ie_mrie) != 0 ||
		    nvlist_add_boolean_value(sip->si_state_iec,
		    "test", sip->si_iec_current.ie_test) != 0 ||
		    nvlist_add_boolean_value(sip->si_state_iec,
		    "ewasc", sip->si_iec_current.ie_ewasc) != 0 ||
		    nvlist_add_boolean_value(sip->si_state_iec,
		    "perf", sip->si_iec_current.ie_perf) != 0 ||
		    nvlist_add_boolean_value(sip->si_state_iec,
		    "ebf", sip->si_iec_current.ie_ebf) != 0 ||
		    nvlist_add_uint32(sip->si_state_iec,
		    "interval-timer",
		    BE_32(sip->si_iec_current.ie_interval_timer)) != 0 ||
		    nvlist_add_uint32(sip->si_state_iec,
		    "report-count",
		    BE_32(sip->si_iec_current.ie_report_count)) != 0)
			return (scsi_set_errno(sip, EDS_NOMEM));
	}

	return (0);
}
Esempio n. 3
0
File: lz4.c Progetto: 151706061/osv
/*ARGSUSED*/
size_t
lz4_compress(void *s_start, void *d_start, size_t s_len, size_t d_len, int n)
{
	uint32_t bufsiz;
	char *dest = d_start;

	ASSERT(d_len >= sizeof (bufsiz));

	bufsiz = real_LZ4_compress(s_start, &dest[sizeof (bufsiz)], s_len,
	    d_len - sizeof (bufsiz));

	/* Signal an error if the compression routine returned zero. */
	if (bufsiz == 0)
		return (s_len);

	/*
	 * Encode the compresed buffer size at the start. We'll need this in
	 * decompression to counter the effects of padding which might be
	 * added to the compressed buffer and which, if unhandled, would
	 * confuse the hell out of our decompression function.
	 */
	*(uint32_t *)dest = BE_32(bufsiz);

	return (bufsiz + sizeof (bufsiz));
}
Esempio n. 4
0
static int film_probe(AVProbeData *p)
{
    if (p->buf_size < 4)
        return 0;

    if (BE_32(&p->buf[0]) != FILM_TAG)
        return 0;

    return AVPROBE_SCORE_MAX;
}
Esempio n. 5
0
/* read a run length encoded sgi image */
static int read_rle_sgi(const SGIInfo *sgi_info,
        AVPicture *pict, ByteIOContext *f)
{
    uint8_t *dest_row;
    unsigned long *start_table;
    int y, z, xsize, ysize, zsize, tablen;
    long start_offset;
    int ret = 0;

    xsize = sgi_info->xsize;
    ysize = sgi_info->ysize;
    zsize = sgi_info->zsize;

    /* skip header */
    url_fseek(f, SGI_HEADER_SIZE, SEEK_SET);

    /* size of rle offset and length tables */
    tablen = ysize * zsize * sizeof(long);

    start_table = (unsigned long *)av_malloc(tablen);

    if (!get_buffer(f, (uint8_t *)start_table, tablen)) {
        ret = AVERROR_IO;
        goto fail;
    }

    /* skip run length table */
    url_fseek(f, tablen, SEEK_CUR);

    for (z = 0; z < zsize; z++) {
        for (y = 0; y < ysize; y++) {
            dest_row = pict->data[0] + (ysize - 1 - y) * (xsize * zsize);

            start_offset = BE_32(&start_table[y + z * ysize]);

            /* don't seek if already at the next rle start offset */
            if (url_ftell(f) != start_offset) {
                url_fseek(f, start_offset, SEEK_SET);
            }

            if (expand_rle_row(f, dest_row, z, zsize) != xsize) {
              ret =  AVERROR_INVALIDDATA;
              goto fail;
            }
        }
    }

fail:
    av_free(start_table);

    return ret;
}
Esempio n. 6
0
/*
 * The algorithm to calculate RSS Toeplitz hash is essentially as follows:
 * - Regard a Toeplitz key and an input as bit strings, with the
 * most significant bit of the first byte being the first bit
 * - Let's have a 32-bit window sliding over the Toeplitz key bit by bit
 * - Let the initial value of the hash be zero
 * - Then for every bit in the input that is set to 1, XOR the value of the
 *   window at a given bit position into the resulting hash
 *
 * First we note that since XOR is commutative and associative, the
 * resulting hash is just a XOR of subhashes for every input bit:
 *        H = H_0 XOR H_1 XOR ... XOR H_n               (1)
 * Then we note that every H_i is only dependent on the value of i and
 * the value of i'th bit of input, but not on any preceding or following
 * input bits.
 * Then we note that (1) holds also for any bit sequences,
 * e.g. for bytes of input:
 *       H = H_0_7 XOR H_8_15 XOR ... XOR H_(n-7)_n     (2)
 * and every
 *       H_i_j = H_i XOR H_(i+1) ... XOR H_j.           (3)
 *
 * It naturally follows than H_i_(i+7) only depends on the value of the byte
 * and the position of the byte in the input.
 * Therefore we may pre-calculate the value of each byte sub-hash H_i_(i+7)
 * for each possible byte value and each possible byte input position, and
 * then just assemble the hash of the packet byte-by-byte instead of
 * bit-by-bit.
 *
 * The amount of memory required for such a cache is not prohibitive:
 * - we have at most 36 bytes of input, each holding 256 possible values
 * - and the hash is 32-bit wide
 * - hence, we need only 36 * 256 * 4 = 36kBytes of cache.
 *
 * The performance gain, at least on synthetic benchmarks, is significant:
 * cache lookup is about 15 times faster than direct hash calculation
 */
const uint32_t *
toeplitz_cache_init(const uint8_t *key)
{
	uint32_t *cache = kmem_alloc(SFXGE_TOEPLITZ_CACHE_SIZE *
	    sizeof (uint32_t), KM_SLEEP);
	unsigned i;

	for (i = 0; i < SFXGE_TOEPLITZ_IN_MAX; i++, key++) {
		uint32_t key_bits[NBBY] = { 0 };
		unsigned j;
		unsigned mask;
		unsigned byte;

#if defined(BE_IN32)
		key_bits[0] = BE_IN32(key);
#else
		key_bits[0] = BE_32(*(uint32_t *)key);
#endif
		for (j = 1, mask = 1 << (NBBY - 1); j < NBBY; j++, mask >>= 1) {
			key_bits[j] = key_bits[j - 1] << 1;
			if ((key[sizeof (uint32_t)] & mask) != 0)
				key_bits[j] |= 1;
		}

		for (byte = 0; byte <= UINT8_MAX; byte++) {
			uint32_t res = 0;
			for (j = 0, mask = 1 << (NBBY - 1);
			    j < NBBY;
			    j++, mask >>= 1) {
				if (byte & mask)
					res ^= key_bits[j];
			}
			cache[i * (UINT8_MAX + 1) + byte] = res;
		}
	}
	return (cache);
}
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));

}
Esempio n. 8
0
static uint_t
interpret_ipnet(int flags, char *header, int elen, int origlen)
{
	dl_ipnetinfo_t dl;
	size_t len = elen - sizeof (dl_ipnetinfo_t);
	char *off = (char *)header + sizeof (dl_ipnetinfo_t);
	int blen = MAX(origlen, 8252);
	char szone[MAX_UINT64_STR];
	char dzone[MAX_UINT64_STR];

	(void) memcpy(&dl, header, sizeof (dl));
	if (data != NULL && datalen != 0 && datalen < blen) {
		free(data);
		data = NULL;
		datalen = 0;
	}
	if (data == NULL) {
		data = (char *)malloc(blen);
		if (!data)
			pr_err("Warning: malloc failure");
		datalen = blen;
	}

	if (dl.dli_zsrc == ALL_ZONES)
		sprintf(szone, "Unknown");
	else
		sprintf(szone, "%lu", BE_32(dl.dli_zsrc));

	if (dl.dli_zdst == ALL_ZONES)
		sprintf(dzone, "Unknown");
	else
		sprintf(dzone, "%lu", BE_32(dl.dli_zdst));

	if (flags & F_SUM) {
		(void) snprintf(get_sum_line(), MAXLINE,
		    "IPNET src zone %s dst zone %s", szone, dzone);
	}

	if (flags & F_DTAIL) {
		show_header("IPNET:  ", "IPNET Header", elen);
		show_space();
		(void) sprintf(get_line(0, 0),
		    "Packet %d arrived at %d:%02d:%d.%05d",
		    pi_frame,
		    pi_time_hour, pi_time_min, pi_time_sec,
		    pi_time_usec / 10);
		(void) sprintf(get_line(0, 0),
		    "Packet size = %d bytes",
		    elen);
		(void) snprintf(get_line(0, 0), get_line_remain(),
		    "dli_version = %d", dl.dli_version);
		(void) snprintf(get_line(0, 0), get_line_remain(),
		    "dli_family = %d", dl.dli_family);
		(void) snprintf(get_line(0, 2), get_line_remain(),
		    "dli_zsrc = %s", szone);
		(void) snprintf(get_line(0, 2), get_line_remain(),
		    "dli_zdst = %s", dzone);
		show_space();
	}
	memcpy(data, off, len);

	switch (dl.dli_family) {
	case AF_INET:
		(void) interpret_ip(flags, (struct ip *)data, len);
		break;
	case AF_INET6:
		(void) interpret_ipv6(flags, (ip6_t *)data, len);
		break;
	default:
		break;
	}

	return (0);
}
Esempio n. 9
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;
}
Esempio n. 10
0
static void nsf_decode_data (audio_decoder_t *this_gen, buf_element_t *buf) {

  nsf_decoder_t *this = (nsf_decoder_t *) this_gen;
  audio_buffer_t *audio_buffer;

  if (buf->decoder_flags & BUF_FLAG_HEADER) {

    /* When the engine sends a BUF_FLAG_HEADER flag, it is time to initialize
     * the decoder. The buffer element type has 4 decoder_info fields,
     * 0..3. Field 1 is the sample rate. Field 2 is the bits/sample. Field
     * 3 is the number of channels. */
    this->sample_rate = buf->decoder_info[1];
    this->bits_per_sample = buf->decoder_info[2];
    this->channels = buf->decoder_info[3];

    /* take this opportunity to initialize stream/meta information */
    this->stream->meta_info[XINE_META_INFO_AUDIOCODEC] = strdup("NES Music (Nosefart)");

    this->song_number = buf->content[4];
    /* allocate a buffer for the file */
    this->nsf_size = BE_32(&buf->content[0]);
    this->nsf_file = xine_xmalloc(this->nsf_size);
    this->nsf_index = 0;

    /* peform any other required initialization */
    this->last_pts = -1;
    this->iteration = 0;

    return;
  }

  /* accumulate chunks from the NSF file until whole file is received */
  if (this->nsf_index < this->nsf_size) {
    xine_fast_memcpy(&this->nsf_file[this->nsf_index], buf->content,
      buf->size);
    this->nsf_index += buf->size;

    if (this->nsf_index == this->nsf_size) {
      /* file has been received, proceed to initialize engine */
      nsf_init();
      this->nsf = nsf_load(NULL, this->nsf_file, this->nsf_size);
      if (!this->nsf) {
        printf ("nsf: could not initialize NSF\n");
        /* make the decoder return on every subsequent buffer */
        this->nsf_index = 0;
      }
      this->nsf->current_song = this->song_number;
      nsf_playtrack(this->nsf, this->nsf->current_song, this->sample_rate,
        this->bits_per_sample, this->channels);
    }
    return;
  }

  /* if the audio output is not open yet, open the audio output */
  if (!this->output_open) {
    this->output_open = this->stream->audio_out->open(
      this->stream->audio_out,
      this->stream,
      this->bits_per_sample,
      this->sample_rate,
      (this->channels == 2) ? AO_CAP_MODE_STEREO : AO_CAP_MODE_MONO);
  }

  /* if the audio still isn't open, do not go any further with the decode */
  if (!this->output_open)
    return;

  /* check if a song change was requested */
  if (buf->decoder_info[1]) {
    this->nsf->current_song = buf->decoder_info[1];
    nsf_playtrack(this->nsf, this->nsf->current_song, this->sample_rate,
      this->bits_per_sample, this->channels);
  }

  /* time to decode a frame */
  if (this->last_pts != -1) {

    /* process a frame */
    nsf_frame(this->nsf);

    /* get an audio buffer */
    audio_buffer = this->stream->audio_out->get_buffer (this->stream->audio_out);
    if (audio_buffer->mem_size == 0) {
       printf ("nsf: Help! Allocated audio buffer with nothing in it!\n");
       return;
    }

    apu_process(audio_buffer->mem, this->sample_rate / this->nsf->playback_rate);
    audio_buffer->vpts = buf->pts;
    audio_buffer->num_frames = this->sample_rate / this->nsf->playback_rate;
    this->stream->audio_out->put_buffer (this->stream->audio_out, audio_buffer, this->stream);
  }
  this->last_pts = buf->pts;
}
Esempio n. 11
0
  int pixel_ptr = 0;
  int pixel_x, pixel_y;
  int row_inc = this->width - 4;
  int block_ptr;
  int prev_block_ptr;
  int prev_block_ptr1, prev_block_ptr2;
  int prev_block_flag;
  int total_blocks;
  int color_table_index;  /* indexes to color pair, quad, or octet tables */
  int color_index;  /* indexes into palette map */

  int color_pair_index = 0;
  int color_quad_index = 0;
  int color_octet_index = 0;

  chunk_size = BE_32(&this->buf[stream_ptr]) & 0x00FFFFFF;
  stream_ptr += 4;
  if (chunk_size != this->size)
    printf(_("warning: MOV chunk size != encoded chunk size (%d != %d); using MOV chunk size\n"),
      chunk_size, this->size);

  chunk_size = this->size;
  total_blocks = (this->width * this->height) / (4 * 4);

  /* traverse through the blocks */
  while (total_blocks) {
    /* sanity checks */
    /* make sure stream ptr hasn't gone out of bounds */
    if (stream_ptr > chunk_size) {
      printf(_(
        "SMC decoder just went out of bounds (stream ptr = %d, chunk size = %d)\n"),
Esempio n. 12
0
/*
 * Enable IE reporting.  We prefer the following settings:
 *
 * (1) DEXCPT = 0
 * (3) MRIE = 6 (IE_REPORT_ON_REQUEST)
 * (4) EWASC = 1
 * (6) REPORT COUNT = 0x00000001
 * (7) LOGERR = 1
 *
 * However, not all drives support changing these values, and the current state
 * may be useful enough as-is.  For example, some drives support IE logging, but
 * don't support changing the MRIE.  In this case, we can still use the
 * information provided by the log page.
 */
static int
scsi_enable_ie(ds_scsi_info_t *sip, boolean_t *changed)
{
	scsi_ie_page_t new_iec_page;
	scsi_ms_hdrs_t hdrs;
	uint_t skey, asc, ascq;

	if (!(sip->si_supp_mode & MODEPAGE_SUPP_IEC))
		return (0);

	bzero(&new_iec_page, sizeof (new_iec_page));
	bzero(&hdrs, sizeof (hdrs));

	(void) memcpy(&new_iec_page, &sip->si_iec_current,
	    sizeof (new_iec_page));

	if (IEC_IE_CHANGEABLE(sip->si_iec_changeable))
		new_iec_page.ie_dexcpt = 0;

	if (IEC_MRIE_CHANGEABLE(sip->si_iec_changeable))
		new_iec_page.ie_mrie = IE_REPORT_ON_REQUEST;

	/*
	 * We only want to enable warning reporting if we are able to change the
	 * mrie to report on request.  Otherwise, we risk unnecessarily
	 * interrupting normal SCSI commands with a CHECK CONDITION code.
	 */
	if (IEC_EWASC_CHANGEABLE(sip->si_iec_changeable)) {
		if (new_iec_page.ie_mrie == IE_REPORT_ON_REQUEST)
			new_iec_page.ie_ewasc = 1;
		else
			new_iec_page.ie_ewasc = 0;
	}

	if (IEC_RPTCNT_CHANGEABLE(sip->si_iec_changeable))
		new_iec_page.ie_report_count = BE_32(1);

	if (IEC_LOGERR_CHANGEABLE(sip->si_iec_changeable))
		new_iec_page.ie_logerr = 1;

	/*
	 * Now compare the new mode page with the existing one.
	 * if there's no difference, there's no need for a mode select
	 */
	if (memcmp(&new_iec_page, &sip->si_iec_current,
	    MODEPAGE_INFO_EXCPT_LEN) == 0) {
		*changed = B_FALSE;
	} else {
		(void) memcpy(&hdrs, &sip->si_hdrs, sizeof (sip->si_hdrs));

		if (scsi_mode_select(sip,
		    MODEPAGE_INFO_EXCPT, MODE_SELECT_PF, &new_iec_page,
		    MODEPAGE_INFO_EXCPT_LEN, &hdrs, &skey, &asc, &ascq) == 0) {
			*changed = B_TRUE;
		} else {
			printf("failed to enable IE (KEY=0x%x "
			    "ASC=0x%x ASCQ=0x%x)\n", skey, asc, ascq);
			*changed = B_FALSE;
		}
	}

	if (nvlist_add_boolean_value(sip->si_state_iec, "changed",
	    *changed) != 0)
		return (scsi_set_errno(sip, EDS_NOMEM));

	return (0);
}
Esempio n. 13
0
File: qdrw.c Progetto: Erikhht/TCPMP
static int decode_frame(AVCodecContext *avctx, 
                        void *data, int *data_size,
                        uint8_t *buf, int buf_size)
{
    QdrawContext * const a = avctx->priv_data;
    AVFrame * const p= (AVFrame*)&a->pic;
    uint8_t* outdata;
    int colors;
    int i;
    
    if(p->data[0])
        avctx->release_buffer(avctx, p);

    p->reference= 0;
    if(avctx->get_buffer(avctx, p) < 0){
        av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
        return -1;
    }
    p->pict_type= I_TYPE;
    p->key_frame= 1;

    outdata = a->pic.data[0];
    
    buf += 0x68; /* jump to palette */
    colors = BE_32(buf);
    buf += 4;
    
    if(colors < 0 || colors > 256) {
        av_log(avctx, AV_LOG_ERROR, "Error color count - %i(0x%X)\n", colors, colors);
        return -1;
    }
    
    for (i = 0; i <= colors; i++) {
        unsigned int idx;
        idx = BE_16(buf); /* color index */
        buf += 2;
        
        if (idx > 255) {
            av_log(avctx, AV_LOG_ERROR, "Palette index out of range: %u\n", idx);
            buf += 6;
            continue;
        }
        a->palette[idx * 3 + 0] = *buf++;
        buf++;
        a->palette[idx * 3 + 1] = *buf++;
        buf++;
        a->palette[idx * 3 + 2] = *buf++;
        buf++;
    }

    buf += 18; /* skip unneeded data */
    for (i = 0; i < avctx->height; i++) {
        int size, left, code, pix;
        uint8_t *next;
        uint8_t *out;
        int tsize = 0;
        
        /* decode line */
        out = outdata;
        size = BE_16(buf); /* size of packed line */
        buf += 2;
        left = size;
        next = buf + size;
        while (left > 0) {
            code = *buf++;
            if (code & 0x80 ) { /* run */
                int i;
                pix = *buf++;
                if ((out + (257 - code) * 3) > (outdata +  a->pic.linesize[0]))
                    break;
                for (i = 0; i < 257 - code; i++) {
                    *out++ = a->palette[pix * 3 + 0];
                    *out++ = a->palette[pix * 3 + 1];
                    *out++ = a->palette[pix * 3 + 2];
                }
                tsize += 257 - code;
                left -= 2;
            } else { /* copy */
                int i, pix;
                if ((out + code * 3) > (outdata +  a->pic.linesize[0]))
                    break;
                for (i = 0; i <= code; i++) {
                    pix = *buf++;
                    *out++ = a->palette[pix * 3 + 0];
                    *out++ = a->palette[pix * 3 + 1];
                    *out++ = a->palette[pix * 3 + 2];
                }
                left -= 2 + code;
                tsize += code + 1;
            }
        }
        buf = next;
        outdata += a->pic.linesize[0];
    }

    *data_size = sizeof(AVFrame);
    *(AVFrame*)data = a->pic;
    
    return buf_size;
}
Esempio n. 14
0
File: rv10.c Progetto: VoxOx/VoxOx
static int rv10_decode_init(AVCodecContext *avctx)
{
    MpegEncContext *s = avctx->priv_data;
    static int done=0;

    MPV_decode_defaults(s);

    s->avctx= avctx;
    s->out_format = FMT_H263;
    s->codec_id= avctx->codec_id;

    s->width = avctx->width;
    s->height = avctx->height;

    s->h263_long_vectors= ((uint8_t*)avctx->extradata)[3] & 1;
    avctx->sub_id= BE_32((uint8_t*)avctx->extradata + 4);

    switch(avctx->sub_id){
    case 0x10000000:
        s->rv10_version= 0;
        s->low_delay=1;
        break;
    case 0x10002000:
        s->rv10_version= 3;
        s->low_delay=1;
        s->obmc=1;
        break;
    case 0x10003000:
        s->rv10_version= 3;
        s->low_delay=1;
        break;
    case 0x10003001:
        s->rv10_version= 3;
        s->low_delay=1;
        break;
    case 0x20001000: /* real rv20 decoder fail on this id */
    /*case 0x20100001:
    case 0x20101001:
    case 0x20103001:*/
    case 0x20100000 ... 0x2019ffff:
        s->low_delay=1;
        break;
    /*case 0x20200002:
    case 0x20201002:
    case 0x20203002:*/
    case 0x20200002 ... 0x202fffff:
    case 0x30202002:
    case 0x30203002:
        s->low_delay=0;
        s->avctx->has_b_frames=1;
        break;
    default:
        av_log(s->avctx, AV_LOG_ERROR, "unknown header %X\n", avctx->sub_id);
    }

    if(avctx->debug & FF_DEBUG_PICT_INFO){
        av_log(avctx, AV_LOG_DEBUG, "ver:%X ver0:%X\n", avctx->sub_id, avctx->extradata_size >= 4 ? ((uint32_t*)avctx->extradata)[0] : -1);
    }

    avctx->pix_fmt = PIX_FMT_YUV420P;

    if (MPV_common_init(s) < 0)
        return -1;

    h263_decode_init_vlc(s);

    /* init rv vlc */
    if (!done) {
        init_vlc(&rv_dc_lum, DC_VLC_BITS, 256,
                 rv_lum_bits, 1, 1,
                 rv_lum_code, 2, 2, 1);
        init_vlc(&rv_dc_chrom, DC_VLC_BITS, 256,
                 rv_chrom_bits, 1, 1,
                 rv_chrom_code, 2, 2, 1);
        done = 1;
    }

    return 0;
}
Esempio n. 15
0
static int film_read_header(AVFormatContext *s,
                            AVFormatParameters *ap)
{
    FilmDemuxContext *film = (FilmDemuxContext *)s->priv_data;
    ByteIOContext *pb = &s->pb;
    AVStream *st;
    unsigned char scratch[256];
    int i;
    unsigned int data_offset;
    unsigned int audio_frame_counter;

    film->sample_table = NULL;
    film->stereo_buffer = NULL;
    film->stereo_buffer_size = 0;

    /* load the main FILM header */
    if (get_buffer(pb, scratch, 16) != 16)
        return AVERROR_IO;
    data_offset = BE_32(&scratch[4]);
    film->version = BE_32(&scratch[8]);

    /* load the FDSC chunk */
    if (film->version == 0) {
        /* special case for Lemmings .film files; 20-byte header */
        if (get_buffer(pb, scratch, 20) != 20)
            return AVERROR_IO;
        /* make some assumptions about the audio parameters */
        film->audio_type = CODEC_ID_PCM_S8;
        film->audio_samplerate = 22050;
        film->audio_channels = 1;
        film->audio_bits = 8;
    } else {
        /* normal Saturn .cpk files; 32-byte header */
        if (get_buffer(pb, scratch, 32) != 32)
            return AVERROR_IO;
        film->audio_samplerate = BE_16(&scratch[24]);;
        film->audio_channels = scratch[21];
        film->audio_bits = scratch[22];
        if (film->audio_bits == 8)
            film->audio_type = CODEC_ID_PCM_S8;
        else if (film->audio_bits == 16)
            film->audio_type = CODEC_ID_PCM_S16BE;
        else
            film->audio_type = 0;
    }

    if (BE_32(&scratch[0]) != FDSC_TAG)
        return AVERROR_INVALIDDATA;

    film->cvid_extra_bytes = 0;
    if (BE_32(&scratch[8]) == CVID_TAG) {
        film->video_type = CODEC_ID_CINEPAK;
        if (film->version)
            film->cvid_extra_bytes = 2;
        else
            film->cvid_extra_bytes = 6;  /* Lemmings 3DO case */
    } else
        film->video_type = 0;

    /* initialize the decoder streams */
    if (film->video_type) {
        st = av_new_stream(s, 0);
        if (!st)
            return AVERROR_NOMEM;
        film->video_stream_index = st->index;
        st->codec->codec_type = CODEC_TYPE_VIDEO;
        st->codec->codec_id = film->video_type;
        st->codec->codec_tag = 0;  /* no fourcc */
        st->codec->width = BE_32(&scratch[16]);
        st->codec->height = BE_32(&scratch[12]);
    }

    if (film->audio_type) {
        st = av_new_stream(s, 0);
        if (!st)
            return AVERROR_NOMEM;
        film->audio_stream_index = st->index;
        st->codec->codec_type = CODEC_TYPE_AUDIO;
        st->codec->codec_id = film->audio_type;
        st->codec->codec_tag = 1;
        st->codec->channels = film->audio_channels;
        st->codec->bits_per_sample = film->audio_bits;
        st->codec->sample_rate = film->audio_samplerate;
        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 / 8;
    }

    /* load the sample table */
    if (get_buffer(pb, scratch, 16) != 16)
        return AVERROR_IO;
    if (BE_32(&scratch[0]) != STAB_TAG)
        return AVERROR_INVALIDDATA;
    film->base_clock = BE_32(&scratch[8]);
    film->sample_count = BE_32(&scratch[12]);
    if(film->sample_count >= UINT_MAX / sizeof(film_sample_t))
        return -1;
    film->sample_table = av_malloc(film->sample_count * sizeof(film_sample_t));
    
    for(i=0; i<s->nb_streams; i++)
        av_set_pts_info(s->streams[i], 33, 1, film->base_clock);
    
    audio_frame_counter = 0;
    for (i = 0; i < film->sample_count; i++) {
        /* load the next sample record and transfer it to an internal struct */
        if (get_buffer(pb, scratch, 16) != 16) {
            av_free(film->sample_table);
            return AVERROR_IO;
        }
        film->sample_table[i].sample_offset = 
            data_offset + BE_32(&scratch[0]);
        film->sample_table[i].sample_size = BE_32(&scratch[4]);
        if (BE_32(&scratch[8]) == 0xFFFFFFFF) {
            film->sample_table[i].stream = film->audio_stream_index;
            film->sample_table[i].pts = audio_frame_counter;
            film->sample_table[i].pts *= film->base_clock;
            film->sample_table[i].pts /= film->audio_samplerate;

            audio_frame_counter += (film->sample_table[i].sample_size /
                (film->audio_channels * film->audio_bits / 8));
        } else {
            film->sample_table[i].stream = film->video_stream_index;
            film->sample_table[i].pts = BE_32(&scratch[8]) & 0x7FFFFFFF;
            film->sample_table[i].keyframe = (scratch[8] & 0x80) ? 0 : 1;
        }
    }

    film->current_sample = 0;

    return 0;
}
Esempio n. 16
0
static int
get_packets(hash_obj_t *seg_hash, raw_list_t *rawlist, int offset, int length)
{
	int tag_size;
	int paylen;
	int retval;
	int seg_limit = 0;
	int pktcnt = 0;
	char *data;
	uint32_t crc;
	uint32_t origcrc;
	fru_tag_t tag;
	hash_obj_t *pkt_hash_obj;
	hash_obj_t *sec_hash;
	fru_segdesc_t *segdesc;
	fru_tagtype_t tagtype;
	char *ignore_flag;

	retval = get_packet(rawlist, &tag, sizeof (fru_tag_t), offset);
	if (retval == -1) {
		return (-1);
	}

	/* section hash object */
	sec_hash = lookup_handle_object(seg_hash->u.seg_obj->section_hdl,
	    SECTION_TYPE);

	if (sec_hash == NULL) {
		return (-1);
	}

	seg_hash->u.seg_obj->trailer_offset = offset;

	data = (char *)&tag;
	while (data[0] != SEG_TRAILER_TAG) {
		tagtype	= get_tag_type(&tag); /* verify tag type */
		if (tagtype == -1) {
			return (-1);
		}

		tag_size = get_tag_size(tagtype);
		if (tag_size == -1) {
			return (-1);
		}

		seg_limit += tag_size;
		if (seg_limit > length) {
			return (-1);
		}

		paylen = get_payload_length((void *)&tag);
		if (paylen == -1) {
			return (-1);
		}

		seg_limit += paylen;
		if (seg_limit > length) {
			return (-1);
		}
		if ((offset + tag_size + paylen) >
		    (sec_hash->u.sec_obj->section.offset +
		    sec_hash->u.sec_obj->section.length)) {
			return (-1);
		}

		pkt_hash_obj = create_packet_hash_object();
		if (pkt_hash_obj == NULL) {
			return (-1);
		}

		pkt_hash_obj->u.pkt_obj->payload = malloc(paylen);
		if (pkt_hash_obj->u.pkt_obj->payload == NULL) {
			free(pkt_hash_obj);
			return (-1);
		}

		offset += tag_size;

		retval = raw_memcpy(pkt_hash_obj->u.pkt_obj->payload, rawlist,
		    offset, paylen);

		if (retval != paylen) {
			free(pkt_hash_obj->u.pkt_obj->payload);
			free(pkt_hash_obj);
			return (-1);
		}

		/* don't change this */
		pkt_hash_obj->u.pkt_obj->tag.raw_data = 0;
		(void) memcpy(&pkt_hash_obj->u.pkt_obj->tag, &tag, tag_size);
		pkt_hash_obj->u.pkt_obj->paylen = paylen;
		pkt_hash_obj->u.pkt_obj->tag_size = tag_size;
		pkt_hash_obj->u.pkt_obj->payload_offset = offset;

		offset += paylen;

		add_hashobject_to_hashtable(pkt_hash_obj);
		add_to_pkt_object_list(seg_hash, pkt_hash_obj);

		pktcnt++;

		retval = get_packet(rawlist, &tag, sizeof (fru_tag_t),
		    offset);
		if (retval == -1) {
			return (retval);
		}

		data = (char *)&tag;
	}

	segdesc	= (fru_segdesc_t *)&seg_hash->u.seg_obj->segment.descriptor;

	seg_hash->u.seg_obj->trailer_offset = offset;

	if (!segdesc->field.ignore_checksum)  {
		crc = get_checksum_crc(seg_hash, seg_limit);
		offset = seg_hash->u.seg_obj->segment.offset;

		retval = raw_memcpy(&origcrc, rawlist, offset + seg_limit + 1,
		    sizeof (origcrc));

		ignore_flag = getenv(IGNORE_CHECK);
		if (ignore_flag != NULL) {
			return (pktcnt);
		}

		if (retval != sizeof (origcrc)) {
			return (-1);
		}

		origcrc = BE_32(origcrc);
		if (origcrc != crc) {
			seg_hash->u.seg_obj->trailer_offset = offset;
			return (-1);
		}
	}

	return (pktcnt);
}