Exemplo n.º 1
0
Arquivo: file.c Projeto: Garalv/miumiu
int read_cb(OGGZ *oggz, ogg_packet *op, long serialno, void *data)
{
	struct theora_headers *th;

	const char theoraId[] = "\x80theora";
	const char speexId[] = "Speex   ";

	if ( memcmp(op->packet, theoraId, strlen(theoraId)) == 0 )
	{
		//mylog("Detected a Theora stream with serialno=%d\n", serialno);
		oggz_set_read_callback(oggz, serialno, read_theora_cb, NULL);
		video_stream->serialno = serialno;

		// Initialize theora specific data fields
		th = (struct theora_headers *)calloc(1, sizeof(struct theora_headers));
		theora_info_init(&(th->ti));
		theora_comment_init(&(th->tc));
		video_stream->data = th;

		read_theora_cb(oggz, op, serialno, data);
	} else if ( memcmp(op->packet, speexId, strlen(speexId)) == 0 )
	{
		//mylog("Detected a Speex stream with serialno=%d\n", serialno);
		oggz_set_read_callback(oggz, serialno, read_speex_cb, NULL);
		audio_stream->serialno = serialno;
		read_speex_cb(oggz, op, serialno, data);
	} else
	{
		mylog("Got unknown ogg packet, serialno=%d, size=%d, packetno=%d, granulepos=%d\n",
				serialno, op->bytes, op->packetno, op->granulepos);
	}
	return 0;
}
Exemplo n.º 2
0
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;
}
Exemplo n.º 3
0
Arquivo: file.c Projeto: Garalv/miumiu
void load_ogg_file(const char *filename)
{
	OGGZ *oggz;

	oggz = oggz_open(filename, OGGZ_READ | OGGZ_AUTO);
	if ( oggz == NULL )
	{
		mylog("Error opening ogg file\n");
	}
	mylog("Successfully opened ogg file %s\n", filename);

	// Initialize internal streams
	audio_stream = calloc(1, sizeof(struct ogg_stream));
	video_stream = calloc(1, sizeof(struct ogg_stream));

	oggz_set_read_callback(oggz, -1, read_cb, NULL);
	oggz_set_read_page(oggz, -1, read_page_cb, NULL);

	oggz_run(oggz);

	//mylog("Audio stream, serialno=%d\n", audio_stream->serialno);
	//dump_stream(audio_stream);
	//mylog("Video stream, serialno=%d\n", video_stream->serialno);
	//dump_stream(video_stream);

	oggz_close(oggz);
}
Exemplo n.º 4
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);
}
Exemplo n.º 5
0
void ogv_demuxer_init() {
    appState = STATE_BEGIN;
	bufferQueue = bq_init();
	oggz = oggz_new(OGGZ_READ | OGGZ_AUTO);
	oggz_set_read_callback(oggz, -1, readPacketCallback, NULL);
	oggz_io_set_read(oggz, readCallback, bufferQueue);
	oggz_io_set_seek(oggz, seekCallback, bufferQueue);
	oggz_io_set_tell(oggz, tellCallback, bufferQueue);
    skeleton = oggskel_new();
}
Exemplo n.º 6
0
int
main (int argc, char * argv[])
{
  OGGZ * reader, * writer;
  unsigned char buf[READ_SIZE];
  long n, remaining, err;

  INFO ("Testing ability to pause while reading (OGGZ_STOP_OK)");

  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_set_read_callback (reader, -1, read_packet, NULL);

  while ((remaining = oggz_write_output (writer, buf, READ_SIZE)) > 0) {
    n = oggz_read_input (reader, buf, remaining);

    if (n == OGGZ_ERR_READ_STOP_OK) {
      INFO ("+ Interrupted read detected");
    } else {
      remaining -= n;

      err = oggz_read_input (reader, buf+n, remaining);
      if (err == OGGZ_ERR_READ_STOP_OK) {
	INFO ("+ Interrupted read detected");
      } else {
	FAIL ("Interrupted read not reported");
      }
    }

    n = oggz_read_input (reader, buf+n, remaining);
    remaining -= n;
  }

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

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

  exit (0);
}
Exemplo n.º 7
0
static inline OMX_ERRORTYPE
set_read_packet_callback (oggdmux_prc_t * ap_prc, long serialno,
                          OggzReadPacket ap_read_cback)
{
  assert (ap_prc);
  assert (ap_read_cback);
  if (oggz_set_read_callback (ap_prc->p_oggz_, serialno, ap_read_cback, ap_prc)
      < 0)
    {
      TIZ_ERROR (handleOf (ap_prc),
                 "[OMX_ErrorInsufficientResources] : "
                 "Could not set read packet callback.");
      return OMX_ErrorInsufficientResources;
    }
  return OMX_ErrorNone;
}
Exemplo n.º 8
0
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);
}
Exemplo n.º 9
0
static FS_DecEnc *
fs_encdec_new (char * infilename, char * outfilename, int format,
	       int interleave, int blocksize)
{
  FS_DecEnc * ed;

  if (infilename == NULL || outfilename == NULL) return NULL;

  ed = malloc (sizeof (FS_DecEnc));

  ed->infilename = strdup (infilename);
  ed->outfilename = strdup (outfilename);

  ed->oggz_in = oggz_open (infilename, OGGZ_READ);
  ed->oggz_out = oggz_open (outfilename, OGGZ_WRITE);

  oggz_set_read_callback (ed->oggz_in, -1, read_packet, ed);
  ed->serialno = oggz_serialno_new (ed->oggz_out);

  ed->decoder = fish_sound_new (FISH_SOUND_DECODE, NULL);

  fish_sound_set_interleave (ed->decoder, interleave);

  fish_sound_set_decoded_float_ilv (ed->decoder, decoded, ed);

  ed->format = format;
  ed->interleave = interleave;
  ed->blocksize = blocksize;
  ed->begun = 0;
  ed->b_o_s = 1;

  /* Delay the setting of channels and allocation of PCM buffers until
   * the number of channels is known from decoding the headers */
  ed->channels = 0;
  ed->pcm = NULL;

  ed->frames_in = 0;
  ed->frames_out = 0;

  return ed;
}
Exemplo n.º 10
0
int
main (int argc, char ** argv)
{
  OGGZ * oggz;

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

  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_callback (oggz, -1, read_packet, NULL);

  oggz_run (oggz);

  oggz_close (oggz);

  exit (0);
}
Exemplo n.º 11
0
OggVorbisReadStream::OggVorbisReadStream(QString path) :
    m_path(path),
    m_d(new D(this))
{
    m_channelCount = 0;
    m_sampleRate = 0;

    if (!(m_d->m_oggz = oggz_open(path.toLocal8Bit().data(), OGGZ_READ))) {
	m_error = QString("File \"%1\" is not an OGG file.").arg(path);
	return;
    }

    FishSoundInfo fsinfo;
    m_d->m_fishSound = fish_sound_new(FISH_SOUND_DECODE, &fsinfo);

    fish_sound_set_decoded_callback(m_d->m_fishSound, D::acceptFramesStatic, m_d);
    oggz_set_read_callback(m_d->m_oggz, -1, D::acceptPacketStatic, m_d);

    // initialise m_channelCount
    while (m_channelCount == 0 && !m_d->m_finished) {
        m_d->readNextBlock(); 
    }
}
Exemplo n.º 12
0
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;
}