コード例 #1
0
int
main (int argc, char * argv[])
{
  OGGZ * reader, * writer;
  unsigned char data_buf[DATA_BUF_LEN];
  long n;

  INFO ("Testing override of IO seeking");

  writer = oggz_new (OGGZ_WRITE);
  if (writer == NULL)
    FAIL("newly created OGGZ writer == NULL");

  serialno = oggz_serialno_new (writer);

  if (oggz_write_set_hungry_callback (writer, hungry, 1, NULL) == -1)
    FAIL("Could not set hungry callback");

  reader = oggz_new (OGGZ_READ);
  if (reader == NULL)
    FAIL("newly created OGGZ reader == NULL");

  oggz_io_set_read (reader, my_io_read, data_buf);
  oggz_io_set_seek (reader, my_io_seek, data_buf);
  oggz_io_set_tell (reader, my_io_tell, data_buf);

  oggz_set_read_callback (reader, -1, read_packet, NULL);

  n = oggz_write_output (writer, data_buf, DATA_BUF_LEN);

  if (n >= DATA_BUF_LEN)
    FAIL("Too much data generated by writer");

  offset_end = n;

  oggz_read (reader, n);

  if (read_called == 0)
    FAIL("Read method ignored");

  if (oggz_seek (reader, 0, SEEK_SET) != 0)
    FAIL("Seek failure");

  read_called = 0;

  oggz_read (reader, n);

  if (read_called == 0)
    FAIL("Read method ignored after seeking");

  if (oggz_close (reader) != 0)
    FAIL("Could not close OGGZ reader");

  if (oggz_close (writer) != 0)
    FAIL("Could not close OGGZ writer");

  exit (0);
}
コード例 #2
0
ファイル: play.c プロジェクト: roaraudio/roaraudio
int play (char * file, char ** opts) {
 OGGZ * oggz;
 struct roarfish_play_inst inst;

 inst.roarfh = -1;
 inst.begun  = 0;

 inst.fsound = fish_sound_new(FISH_SOUND_DECODE, &inst.fsinfo);
 fish_sound_set_interleave(inst.fsound, 1);

 fish_sound_set_decoded_float_ilv(inst.fsound, decoded_float, (void*)&inst);

 if ((oggz = oggz_open(file, OGGZ_READ)) == NULL) {
  ROAR_ERR("Can not open input file: %s", file);
  return -1;
 }

 oggz_set_read_callback(oggz, -1, read_packet, inst.fsound);

 // TODO: add some status display here?
 while (oggz_read(oggz, 1024));

 oggz_close(oggz);

 fish_sound_delete(inst.fsound);

 return -1;
}
コード例 #3
0
int ogv_demuxer_process() {
	do {
		// read at most this many bytes in one go
		// should be enough to resync ogg stream
		int64_t headroom = bq_headroom(bufferQueue);
		size_t bufsize = 65536;
		if (headroom < bufsize) {
			bufsize = headroom;
		}

		int ret = oggz_read(oggz, bufsize);
		//printf("demuxer returned %d on %d bytes\n", ret, bufsize);
		if (ret == OGGZ_ERR_STOP_OK) {
			// We got a packet!
			return 1;
		} else if (ret > 0) {
			// We read some data, but no packets yet.
			//printf("read %d bytes\n", ret);
			continue;
		} else if (ret == 0) {
			//printf("EOF %d from oggz_read\n", ret);
			return 0;
		} else if (ret < 0) {
			printf("Error %d from oggz_read\n", ret);
			return 0;
		}
	} while(1);

	return 0;
}
コード例 #4
0
int
main (int argc, char ** argv)
{
  OGGZ * oggz;
  OggzTable * tracks;
  long n;

  if (argc < 2) {
    printf ("usage: %s filename\n", argv[0]);
  }

  tracks = oggz_table_new ();

  if ((oggz = oggz_open ((char *)argv[1], OGGZ_READ | OGGZ_AUTO)) == NULL) {
    printf ("unable to open file %s\n", argv[1]);
    exit (1);
  }

  oggz_set_read_page (oggz, -1, read_page, tracks);

  while ((n = oggz_read (oggz, 1024)) > 0);

  oggz_close (oggz);

  oggz_table_delete (tracks);

  exit (0);
}
コード例 #5
0
ファイル: read-io.c プロジェクト: ezdev128/liboggz
int
main (int argc, char ** argv)
{
  FILE * f;
  OGGZ * oggz;
  long n;
  ogg_int64_t units;

  if (argc < 2) {
    printf ("usage: %s filename\n", argv[0]);
  }

  if ((f = fopen ((char *)argv[1], "rb")) == NULL) {
    printf ("unable to open file %s\n", argv[1]);
    exit (1);
  }

  if ((oggz = oggz_new (OGGZ_READ | OGGZ_AUTO)) == NULL) {
    printf ("unable to create oggz\n");
    exit (1);
  }

  oggz_io_set_read (oggz, my_io_read, f);
  oggz_io_set_seek (oggz, my_io_seek, f);
  oggz_io_set_tell (oggz, my_io_tell, f);

  oggz_set_read_callback (oggz, -1, read_packet, NULL);

  while ((n = oggz_read (oggz, 1024)) > 0);

  units = oggz_tell_units (oggz);
  printf ("Total length: %" PRId64 " ms\n", units);

  oggz_seek_units (oggz, units/2, SEEK_SET);

  printf ("seeked to byte offset %" PRId64 "\n", oggz_tell (oggz));

  while ((n = oggz_read (oggz, 1024)) > 0);

  oggz_close (oggz);

  exit (0);
}
コード例 #6
0
ファイル: dec_speex.c プロジェクト: alex1818/aqualung
/* return 1 if reached end of stream, 0 else */
int
decode_speex(decoder_t * dec) {

	speex_pdata_t * pd = (speex_pdata_t *)dec->pdata;


	if (oggz_read(pd->oggz, 1024) > 0) {
		return 0;
	} else {
		return 1;
	}
}
コード例 #7
0
ファイル: oggz.c プロジェクト: pojala/twentytwenty
long
oggz_run (OGGZ * oggz)
{
  long n = OGGZ_ERR_DISABLED;

  if (oggz == NULL) return OGGZ_ERR_BAD_OGGZ;

  if (OGGZ_CONFIG_WRITE && (oggz->flags & OGGZ_WRITE)) {
    while ((n = oggz_write (oggz, oggz->run_blocksize)) > 0);
  } else if (OGGZ_CONFIG_READ) {
    while ((n = oggz_read (oggz, oggz->run_blocksize)) > 0);
  }

  return n;
}
コード例 #8
0
static OMX_ERRORTYPE
demux_file (oggdmux_prc_t * ap_prc)
{
  int run_status = 0;
  assert (ap_prc);

  do
    {
      run_status
        = oggz_read (ap_prc->p_oggz_, TIZ_OGG_DEMUXER_DEFAULT_READ_BLOCKSIZE);
      TIZ_TRACE (handleOf (ap_prc), "run_status [%d]", run_status);
    }
  while (buffers_available (ap_prc) && run_status > 0);

  if (0 == run_status) /* This indicates end of file */
    {
      int remaining = 0;
      ap_prc->file_eos_ = true;
      /* Try to empty the temp stores out to an omx buffer */
      remaining = flush_stores (ap_prc);
      TIZ_TRACE (handleOf (ap_prc),
                 "aud_store_offset [%d] vid_store_offset [%d] - total [%d]",
                 ap_prc->aud_store_offset_, ap_prc->vid_store_offset_,
                 remaining);

      if (!ap_prc->aud_eos_)
        {
          ap_prc->aud_eos_ = release_header_with_eos (
            ap_prc, ARATELIA_OGG_DEMUXER_AUDIO_PORT_BASE_INDEX);
        }
      if (!ap_prc->vid_eos_)
        {
          ap_prc->vid_eos_ = release_header_with_eos (
            ap_prc, ARATELIA_OGG_DEMUXER_VIDEO_PORT_BASE_INDEX);
        }
    }

  return OMX_ErrorNone;
}
コード例 #9
0
static OMX_ERRORTYPE
obtain_tracks (oggdmux_prc_t * ap_prc)
{
  oggdmux_prc_t * p_prc = ap_prc;
  long n = 0;
  assert (p_prc);

  /* Seek to beginning of file and set the first pass callback that will help
   * with the discovery of the codecs */
  tiz_check_omx (seek_to_byte_offset (p_prc, 0));
  tiz_check_omx (set_read_page_callback (p_prc, read_page_first_pass));

  while (
    (n = oggz_read (p_prc->p_oggz_, TIZ_OGG_DEMUXER_INITIAL_READ_BLOCKSIZE))
    > 0)
    ;

  /* Seek to beginning of file and set the normal callback (no-op function) */
  tiz_check_omx (seek_to_byte_offset (p_prc, 0));
  tiz_check_omx (set_read_page_callback (p_prc, read_page_normal));

  return OMX_ErrorNone;
}
コード例 #10
0
ファイル: fishsound-decenc.c プロジェクト: EQ4/libfishsound
int
main (int argc, char ** argv)
{
  int i;
  char * infilename = NULL, * outfilename = NULL;
  int format, interleave = 0;
  FS_DecEnc * ed;
  int blocksize = 1024;
  long n;

  if (argc < 3) {
    usage (argv[0]);
    exit (1);
  }

  /* Set the default output format based on what's available */
  format = HAVE_VORBIS ? FISH_SOUND_VORBIS : FISH_SOUND_SPEEX;

  for (i = 1; i < argc; i++) {
    if (!strcmp (argv[i], "--vorbis")) {
      format = FISH_SOUND_VORBIS;
    } else if (!strcmp (argv[i], "--speex")) {
      format = FISH_SOUND_SPEEX;
    } else if (!strcmp (argv[i], "--flac")) {
      format = FISH_SOUND_FLAC;
    } else if (!strcmp (argv[i], "--interleave")) {
      interleave = 1;
    } else if (!strcmp (argv[i], "--help") || !strcmp (argv[i], "-h")) {
      usage(argv[0]);
    } else if (argv[i] && argv[i][0] != '-') {
      if (infilename == NULL) {
	infilename = argv[i];
      } else {
	outfilename = argv[i];
      }
    }
  }

  if (format == FISH_SOUND_VORBIS) {
    if (HAVE_VORBIS) {
      printf ("Using Vorbis as the output codec\n");
    } else {
      fprintf (stderr, "Error: Vorbis support disabled\n");
      exit (1);
    }
  }

  if (format == FISH_SOUND_SPEEX) {
    if (HAVE_SPEEX) {
      printf ("Using Speex as the output codec\n");
    } else {
      fprintf (stderr, "Error: Speex support disabled\n");
      exit (1);
    }
  }

  if (format == FISH_SOUND_FLAC) {
    if (HAVE_FLAC) {
      printf ("Using Flac as the output codec\n");
    } else {
      fprintf (stderr, "Error: Flac support disabled\n");
      exit (1);
    }
  }

  ed = fs_encdec_new (infilename, outfilename, format, interleave, blocksize);

  while ((n = oggz_read (ed->oggz_in, 1024)) > 0)
    while (oggz_write (ed->oggz_out, 1024) > 0);

  fs_encdec_delete (ed);

  exit (0);
}
コード例 #11
0
ファイル: dec_speex.c プロジェクト: alex1818/aqualung
int
speex_dec_open(decoder_t * dec, char * filename) {

	speex_pdata_t * pd = (speex_pdata_t *)dec->pdata;
	file_decoder_t * fdec = dec->fdec;

	int enh = 1;
	char ogg_sig[4];
	long length_in_bytes = 0;
	long length_in_samples = 0;


	if ((pd->speex_file = fopen(filename, "rb")) == NULL) {
		fprintf(stderr, "speex_decoder_open: fopen() failed\n");
		return DECODER_OPEN_FERROR;
	}

	if (fread(ogg_sig, 1, 4, pd->speex_file) != 4) {
		fprintf(stderr, "couldn't read OGG signature from %s\n", filename);
		return DECODER_OPEN_FERROR;
	}

	if ((ogg_sig[0] != 'O') ||
	    (ogg_sig[1] != 'g') ||
	    (ogg_sig[2] != 'g') ||
	    (ogg_sig[3] != 'S')) {
		/* not an OGG stream */
		fclose(pd->speex_file);
		return DECODER_OPEN_BADLIB;
	}

        if ((pd->oggz = oggz_open(filename, OGGZ_READ | OGGZ_AUTO)) == NULL) {
                printf("nonexistent or unaccessible file %s\n", filename);
                return DECODER_OPEN_FERROR;
        }

        oggz_set_read_callback(pd->oggz, -1, read_ogg_packet, dec);

	pd->packetno = 0;
	pd->exploring = 1;
	pd->error = 0;
	while (pd->packetno < 2) { /* process Speex header and comments */
		oggz_read(pd->oggz, 1024);
	}

	if (pd->error != 0) {
		printf("Error opening Speex\n");
		oggz_close(pd->oggz);
		return DECODER_OPEN_BADLIB;
	}

	/* parse ogg packets till eof to get the last granulepos */
	while (oggz_read(pd->oggz, 1024) > 0)
		;

	length_in_bytes = oggz_tell(pd->oggz);

	oggz_close(pd->oggz);
	speex_bits_destroy(&(pd->bits));
        speex_decoder_destroy(pd->decoder);
	
	if ((pd->channels != 1) && (pd->channels != 2)) {
		printf("Sorry, Ogg Speex with %d channels is unsupported\n", pd->channels);
		return DECODER_OPEN_FERROR;
	}
	
	pd->packetno = 0;
	pd->exploring = 0;
	pd->error = 0;
        pd->oggz = oggz_open(filename, OGGZ_READ | OGGZ_AUTO);
	oggz_set_read_callback(pd->oggz, -1, read_ogg_packet, dec);
	speex_bits_init(&(pd->bits));
	pd->decoder = speex_decoder_init(pd->mode);
	speex_decoder_ctl(pd->decoder, SPEEX_SET_ENH, &enh);

	pd->is_eos = 0;
	pd->rb = rb_create(pd->channels * sample_size * RB_SPEEX_SIZE);
	fdec->fileinfo.channels = pd->channels;
	fdec->fileinfo.sample_rate = pd->sample_rate;
	length_in_samples = pd->granulepos + pd->nframes - 1;
	fdec->fileinfo.total_samples = length_in_samples;
	fdec->fileinfo.bps = 8 * length_in_bytes / (length_in_samples / pd->sample_rate);

	fdec->file_lib = SPEEX_LIB;
	strcpy(dec->format_str, "Ogg Speex");

	return DECODER_OPEN_SUCCESS;
}
コード例 #12
0
 void readNextBlock() {
     if (m_finished) return;
     if (oggz_read(m_oggz, 1024) <= 0) {
         m_finished = true;
     }
 }