Exemple #1
0
static int get_next_page(FILE *f, ogg_sync_state *sync, ogg_page *page, 
        ogg_int64_t *written)
{
    int ret;
    char *buffer;
    int bytes;

    while((ret = ogg_sync_pageout(sync, page)) <= 0) {
        if(ret < 0)
#ifdef _WIN32
            DPRINTF(E_WARN, L_SCAN, "Hole in data found at approximate offset %I64d bytes. Corrupted ogg.\n", *written);
#else
            DPRINTF(E_WARN, L_SCAN, "Hole in data found at approximate offset %lld bytes. Corrupted ogg.\n", *written);
#endif

        buffer = ogg_sync_buffer(sync, CHUNK);
        bytes = fread(buffer, 1, CHUNK, f);
        if(bytes <= 0) {
            ogg_sync_wrote(sync, 0);
            return 0;
        }
        ogg_sync_wrote(sync, bytes);
        *written += bytes;
    }

    return 1;
}
int VideoStreamPlaybackTheora::buffer_data() {

	char *buffer = ogg_sync_buffer(&oy, 4096);

#ifdef THEORA_USE_THREAD_STREAMING

	int read;

	do {
		thread_sem->post();
		read = MIN(ring_buffer.data_left(), 4096);
		if (read) {
			ring_buffer.read((uint8_t *)buffer, read);
			ogg_sync_wrote(&oy, read);
		} else {
			OS::get_singleton()->delay_usec(100);
		}

	} while (read == 0);

	return read;

#else

	int bytes = file->get_buffer((uint8_t *)buffer, 4096);
	ogg_sync_wrote(&oy, bytes);
	return (bytes);

#endif
}
Exemple #3
0
static int64_t get_data( demux_t *p_demux, int64_t i_bytes_to_read )
{
    demux_sys_t *p_sys  = p_demux->p_sys;

    char *buf;
    int64_t i_result;

    if ( p_sys->i_total_length > 0 )
    {
        if ( p_sys->i_input_position + i_bytes_to_read > p_sys->i_total_length )
        {
            i_bytes_to_read = p_sys->i_total_length - p_sys->i_input_position;
            if ( i_bytes_to_read <= 0 ) {
                return 0;
            }
        }
    }

    seek_byte ( p_demux, p_sys->i_input_position );

    buf = ogg_sync_buffer( &p_sys->oy, i_bytes_to_read );

    i_result = stream_Read( p_demux->s, buf, i_bytes_to_read );

    p_sys->b_page_waiting = false;

    ogg_sync_wrote( &p_sys->oy, i_result );
    return i_result;
}
Exemple #4
0
bool Oggeyman::next_page() {
	bool have_next_page = false;
	// ogg_sync_pageout takes the data stored in the buffer of the ogg_sync_state struct
	// and inserts them into an ogg_page.
	// The ogg_sync_state struct tracks the synchronization of the current page
	// return values for ogg_sync_pageout:
	//case -1: //stream has not yet captured sync (bytes were skipped)
	//case  0: // more data needed or an internal error occurred
	//case 1: //indicates a page was synced and returned

	if (ogg_sync_pageout(&overall_sync_state, &current_ogg_page) > 0) {
		// we have some leftovers from the last time
		have_next_page = true;

	} else while (ogg_sync_pageout(&overall_sync_state, &current_ogg_page) <= 0) {
		// allocate buffer of the appropriate size
		char* ogg_buffer = (char *) ogg_sync_buffer(&overall_sync_state, IN_CHUNK_SIZE);
		size_t bytes_written = fread(ogg_buffer, 1, IN_CHUNK_SIZE, infptr);
		// shouldn't we be checking whether we are done here?
		if (bytes_written) {
			ogg_sync_wrote(&overall_sync_state, bytes_written);
			have_next_page = true;
		} else {
			break;
		}
	}
	if (!current_ogg_page.header) // we didn't write anything, probably not ogg at all
		have_next_page = false;

	return have_next_page;
}
Exemple #5
0
static gboolean demux_next_page(VideoPlayer* player, GError** err)
{
  int serialno;
  ogg_stream_state* ostream;

  /* Demux the next page into player->current_page. */
  while (ogg_sync_pageout(&player->osync, &player->current_page) != 1) {
    char* buf = ogg_sync_buffer(&player->osync, 65536);
    int bytes = fread(buf, 1, 65536, player->file);
    if (bytes == 0) {
      player->eof = TRUE;
      return TRUE;
    } else if (bytes < 0) {
      g_set_error(err, G_FILE_ERROR, g_file_error_from_errno(errno),
        "Failed to read video: %s", g_strerror(errno));
      return FALSE;
    }
    ogg_sync_wrote(&player->osync, bytes);
  }

  /* Dispatch it to the correct ogg_stream_state. */
  serialno = ogg_page_serialno(&player->current_page);
  ostream = g_hash_table_lookup(player->stream_table, &serialno);
  if (ostream != NULL) {
    ogg_stream_pagein(ostream, &player->current_page);
  } else if (ogg_page_bos(&player->current_page)) {
    int* key = g_new(int, 1);
    *key = serialno;
    ostream = g_new(ogg_stream_state, 1);
    ogg_stream_init(ostream, serialno);
    g_hash_table_insert(player->stream_table, key, ostream);
    ogg_stream_pagein(ostream, &player->current_page);
  }
/* submit the given buffer to the ogg sync */
static GstFlowReturn
gst_ogg_parse_submit_buffer (GstOggParse * ogg, GstBuffer * buffer)
{
  gsize size;
  gchar *oggbuffer;
  GstFlowReturn ret = GST_FLOW_OK;

  size = gst_buffer_get_size (buffer);

  GST_DEBUG_OBJECT (ogg, "submitting %" G_GSIZE_FORMAT " bytes", size);
  if (G_UNLIKELY (size == 0))
    goto done;

  oggbuffer = ogg_sync_buffer (&ogg->sync, size);
  if (G_UNLIKELY (oggbuffer == NULL)) {
    GST_ELEMENT_ERROR (ogg, STREAM, DECODE,
        (NULL), ("failed to get ogg sync buffer"));
    ret = GST_FLOW_ERROR;
    goto done;
  }

  size = gst_buffer_extract (buffer, 0, oggbuffer, size);
  if (G_UNLIKELY (ogg_sync_wrote (&ogg->sync, size) < 0)) {
    GST_ELEMENT_ERROR (ogg, STREAM, DECODE, (NULL),
        ("failed to write %" G_GSIZE_FORMAT " bytes to the sync buffer", size));
    ret = GST_FLOW_ERROR;
  }

done:
  gst_buffer_unref (buffer);

  return ret;
}
Exemple #7
0
BOOL ovd_parse_stream(ovd_stream_buf* buf)
{
	ovd_handle* handle = (ovd_handle*)buf->handle;

	ogg_sync_wrote(handle->oy, buf->len);
	if (ogg_sync_pageout(handle->oy, &handle->og) != 1)
		goto fail;

//	ogg_stream_init(&handle->os, ogg_page_serialno(&handle->og));
	handle->os = ogg_stream_create(ogg_page_serialno(&handle->og));
	vorbis_info_init(&handle->vi);
    vorbis_comment_init(&handle->vc);
	if (ogg_stream_pagein(handle->os, &handle->og) < 0)
		goto fail;

	if (ogg_stream_packetout(handle->os,&handle->op) != 1)
		goto fail;

	if (vorbis_synthesis_headerin(&handle->vi, &handle->vc, &handle->op) < 0)
		goto fail;

	handle->init = 0;
	handle->eof = 0;
	ovd_header_init(handle);

	buf->buf = ogg_sync_bufferin(handle->oy, OVD_STREAM_BUF_LEN);
	buf->len = OVD_STREAM_BUF_LEN;
	return TRUE;
fail:
//	ogg_sync_init(&handle->oy);
	handle->oy = ogg_sync_create();
	buf->buf = ogg_sync_bufferin(handle->oy, OVD_STREAM_BUF_LEN);
	buf->len = OVD_STREAM_BUF_LEN;
	return FALSE;
}
Exemple #8
0
/*
   Reads an OGG page from the stream. Returns 0 if there are no more pages
   left, EMOREDATA otherwise.
*/
int
ogm_reader_c::read_page(ogg_page *og) {
  int np, done, nread;
  unsigned char *buf;

  done = 0;
  while (!done) {
    np = ogg_sync_pageseek(&oy, og);

    // np == 0 means that there is not enough data for a complete page.
    if (0 >= np) {
      // np < 0 is the error case. Should not happen with local OGG files.
      if (0 > np)
        mxwarn_fn(m_ti.m_fname, Y("Could not find the next Ogg page. This indicates a damaged Ogg/Ogm file. Will try to continue.\n"));

      buf = (unsigned char *)ogg_sync_buffer(&oy, BUFFER_SIZE);
      if (!buf)
        mxerror_fn(m_ti.m_fname, Y("ogg_sync_buffer failed\n"));

      if (0 >= (nread = m_in->read(buf, BUFFER_SIZE)))
        return 0;

      ogg_sync_wrote(&oy, nread);
    } else
      // Alright, we have a page.
      done = 1;
  }

  // Here EMOREDATA actually indicates success - a page has been read.
  return FILE_STATUS_MOREDATA;
}
Exemple #9
0
    hBool hSoundResource::NextAudioBlockReady( hSoundPlaybackHandle handle )
    {
#if 1
        hcPrintf("Stub :"__FUNCTION__);
        return hFalse;
#else
        hUint32 read;
        hPlaybackInfo* info = &playbackInfos_[handle];

        if ( info->eoSource_ )
            return hTrue;

        if ( PollSteamRead( info->readOpID_, &read ) == 0 )
        {
            info->inSizes = read;
            info->readOpID_ = ~0U;
            info->tell_ += read;

            hChar* buffer = ogg_sync_buffer( &oggState_, hPlaybackInfo::OGG_BUFFER_SIZE );
            hMemCpy( buffer, info->inBuffer_, read );
            int er = ogg_sync_wrote( &oggState_, read );
            hcAssert( er == 0 );

            if ( read == 0 ) 
            {
                info->eoSource_ = hTrue;
            }

            return hTrue;
        }

        return hFalse;
#endif
    }
Exemple #10
0
int get_packet(ogg_sync_state *oy,ogg_stream_state *os,int *init,ogg_packet *op)
{
  char *buffer;
  size_t bytes;
  ogg_page og;

  /* try to get a packet from the stream */
  if (*init && ogg_stream_packetout(os,op)) return 0;

  /* read data and feed the pages to ogg */
  buffer=ogg_sync_buffer(oy,4096);
  bytes=fread(buffer,1,4096,stdin);
  if (bytes==0) return 1; /* we're done */
  ogg_sync_wrote(oy,bytes);
  while (ogg_sync_pageout(oy,&og)>0) {
    if (!*init && ogg_page_bos(&og)) {
      ogg_stream_init(os,ogg_page_serialno(&og));
    }
    ogg_stream_pagein(os,&og);
    if (!*init && ogg_page_bos(&og)) {
      ogg_packet op;
      ogg_stream_packetpeek(os,&op);
      if (op.bytes>=8 && !memcmp(op.packet,"\200kate\0\0\0",8)) {
        *init=1;
      }
      else {
        ogg_stream_clear(os);
      }
    }
  }

  /* try again with the new data */
  return get_packet(oy,os,init,op);
}
Exemple #11
0
static int ogg_read_header(AVFormatContext *avfcontext, AVFormatParameters *ap)
{
    OggContext *context = avfcontext->priv_data;
    char *buf ;
    ogg_page og ;
    AVStream *ast ;
    
    ogg_sync_init(&context->oy) ;
    buf = ogg_sync_buffer(&context->oy, DECODER_BUFFER_SIZE) ;

    if(get_buffer(&avfcontext->pb, buf, DECODER_BUFFER_SIZE) <= 0)
	return -EIO ;
    
    ogg_sync_wrote(&context->oy, DECODER_BUFFER_SIZE) ;   
    ogg_sync_pageout(&context->oy, &og) ;
    ogg_stream_init(&context->os, ogg_page_serialno(&og)) ;
    ogg_stream_pagein(&context->os, &og) ;
  
    /* currently only one vorbis stream supported */

    ast = av_new_stream(avfcontext, 0) ;
    if(!ast)
	return AVERROR_NOMEM ;

    ast->codec.codec_type = CODEC_TYPE_AUDIO ;
    ast->codec.codec_id = CODEC_ID_VORBIS ;
    
    return 0 ;
}
int VideoStreamTheora::	buffer_data() {
  char *buffer=ogg_sync_buffer(&oy,4096);
  int bytes=file->get_buffer((uint8_t*)buffer, 4096);

  ogg_sync_wrote(&oy,bytes);
  return(bytes);
}
Exemple #13
0
/** --
 *
 * \return -1 on error
 * \return  0 on end of file
 * \return  1 on successful page read
 */
static int
get_page(mm_file *mf, ogg_page *pg)
{
    const int bufsize = 8192;
    char *p = NULL;
    int n = 0;
    int res = 0;

    assert(mf);

    while (0 == (res = ogg_sync_pageout(&mf->sync, pg))) {
        p = ogg_sync_buffer(&mf->sync, bufsize);

        if (!p) {
            ERROR1("ogg buffer synchronization failed");
            return -1;
        }

        if (0 == (n = fread(p, 1, bufsize, mf->file))) {
            return (feof(mf->file)) ? 0 : -1;
        }

        if (ogg_sync_wrote(&mf->sync, n)) {
            ERROR1("buffer overflow in ogg_sync_wrote");
            return -1;
        }
    }

    /* XXX: following may segfault if non-ogg file is read */
    if (res < 0 || ogg_page_version(pg) != 0) {
        return -1;
    }

    return 1;
}
Exemple #14
0
static int AddBuffer(ogg* p,format_buffer* Buffer)
{
	if (!Buffer)
		return ERR_NEED_MORE_DATA;
	
	if (Buffer->Length)
	{
		ogg_buffer* Ptr = ogg_sync_bufferinext(p->OggSync);
		if (!Ptr)
		{
			Format_BufferRelease(&p->Format,Buffer);
			return ERR_OUT_OF_MEMORY;
		}

		Ptr->ext = &p->Format;
		Ptr->extdata = Buffer;
		Ptr->data = Buffer->Block.Ptr;
		Ptr->size = Buffer->Length;
		ogg_sync_wrote(p->OggSync,Buffer->Length);
	}
	else
		Format_BufferRelease(&p->Format,Buffer);

	return ERR_NONE;
}
int32 TheoraPlayer::BufferData()
{
    char * buffer = ogg_sync_buffer(&theoraData->syncState, 4096);
    int32 bytes = file->Read(buffer, 4096);
    ogg_sync_wrote(&theoraData->syncState, bytes);
    return bytes;
}
Exemple #16
0
/* submit the given buffer to the ogg sync */
static GstFlowReturn
gst_ogg_parse_submit_buffer (GstOggParse * ogg, GstBuffer * buffer)
{
  guint size;
  guint8 *data;
  gchar *oggbuffer;
  GstFlowReturn ret = GST_FLOW_OK;

  size = GST_BUFFER_SIZE (buffer);
  data = GST_BUFFER_DATA (buffer);

  GST_DEBUG_OBJECT (ogg, "submitting %u bytes", size);
  if (G_UNLIKELY (size == 0))
    goto done;

  oggbuffer = ogg_sync_buffer (&ogg->sync, size);
  if (G_UNLIKELY (oggbuffer == NULL)) {
    GST_ELEMENT_ERROR (ogg, STREAM, DECODE,
        (NULL), ("failed to get ogg sync buffer"));
    ret = GST_FLOW_ERROR;
    goto done;
  }

  memcpy (oggbuffer, data, size);
  if (G_UNLIKELY (ogg_sync_wrote (&ogg->sync, size) < 0)) {
    GST_ELEMENT_ERROR (ogg, STREAM, DECODE,
        (NULL), ("failed to write %d bytes to the sync buffer", size));
    ret = GST_FLOW_ERROR;
  }

done:
  gst_buffer_unref (buffer);

  return ret;
}
bool
flac_header_extractor_c::read_page() {
  while (1) {
    int np = ogg_sync_pageseek(&oy, &og);

    if (np <= 0) {
      if (np < 0)
        return false;

      unsigned char *buf = (unsigned char *)ogg_sync_buffer(&oy, BUFFER_SIZE);
      if (!buf)
        return false;

      int nread;
      if ((nread = file->read(buf, BUFFER_SIZE)) <= 0)
        return false;

      ogg_sync_wrote(&oy, nread);

    } else if (ogg_page_serialno(&og) == sid)
      break;
  }

  if (ogg_page_bos(&og))
    ogg_stream_init(&os, sid);
  ogg_stream_pagein(&os, &og);

  return true;
}
int TheoraDecoder::bufferData() {
	char *buffer = ogg_sync_buffer(&_oggSync, 4096);
	int bytes = _fileStream->read(buffer, 4096);

	ogg_sync_wrote(&_oggSync, bytes);

	return bytes;
}
Exemple #19
0
size_t DGVideo::_bufferData(ogg_sync_state* oy) {
    char *buffer = ogg_sync_buffer(oy, DGVideoBuffer);
	size_t bytes = fread(buffer, 1, DGVideoBuffer, _handle);
	
	ogg_sync_wrote(oy, bytes);
	
	return(bytes);
}
Exemple #20
0
int buffer_data(ogg_sync_state *oy, CStretchyBuffer& buffer)
// Helper; just grab some more compressed bitstream and sync it for page extraction
{
	static const UINT CHUNK_SIZE = 4096;
	char *pBuffer = ogg_sync_buffer(oy, CHUNK_SIZE);
	const UINT wBytesRead = buffer.ReadChunk(pBuffer, CHUNK_SIZE);
	ogg_sync_wrote(oy, wBytesRead);
	return wBytesRead;
}
Exemple #21
0
static void get_more_data (struct spx_data *data)
{
	char *buf;
	ssize_t nb_read;

	buf = ogg_sync_buffer (&data->oy, 200);
	nb_read = io_read (data->stream, buf, 200);
	ogg_sync_wrote (&data->oy, nb_read);
}
Exemple #22
0
static PyObject * py_ogg_ogg_sync_wrote(PyObject *self, PyObject *args) {
  int c_out;
  int size;
  ogg_sync_state * oy;
  long bytes;
  PyArg_ParseTuple(args, "s#l", &oy, &size, &bytes);
  c_out = ogg_sync_wrote(oy, bytes);
  return Py_BuildValue("i", c_out);
};
Exemple #23
0
static int
vorbis_length_get_next_page (SF_PRIVATE *psf, ogg_sync_state * osync, ogg_page *page)
{	static const int CHUNK_SIZE = 4500 ;

	while (ogg_sync_pageout (osync, page) <= 0)
	{	char * buffer = ogg_sync_buffer (osync, CHUNK_SIZE) ;
		int bytes = psf_fread (buffer, 1, 4096, psf) ;

		if (bytes <= 0)
		{	ogg_sync_wrote (osync, 0) ;
			return 0 ;
		} ;

		ogg_sync_wrote (osync, bytes) ;
	} ;

	return 1 ;
} /* vorbis_length_get_next_page */
Exemple #24
0
static int buffer_data( FILE *f, ogg_sync_state *oy )
{
   char * buffer;
   int bytes;
   buffer = ogg_sync_buffer( oy, 4096 );
   bytes = fread( buffer, 1, 4096, f );	    
   ogg_sync_wrote( oy, bytes );

   return bytes;
}
Exemple #25
0
int LoadChunk( FILE* pFile, ogg_sync_state* pOggSyncState )
{
  const int c_BufferSize = 8192;
  
  // get buffer from ogg
  char* pBuffer = ogg_sync_buffer( pOggSyncState, c_BufferSize );
  long nBytes = fread( pBuffer, 1, c_BufferSize, pFile ); 
  ogg_sync_wrote( pOggSyncState, nBytes );
  
  return nBytes;  
}
Exemple #26
0
/* read a little more data from the file/pipe into the ogg_sync framer */
static long _get_data(OggVorbis_File *vf){
  errno=0;
  if(vf->datasource){
    unsigned char *buffer=ogg_sync_bufferin(vf->oy,CHUNKSIZE);
    long bytes=(vf->callbacks.read_func)(buffer,1,CHUNKSIZE,vf->datasource);
    if(bytes>0)ogg_sync_wrote(vf->oy,bytes);
    if(bytes==0 && errno)return(-1);
    return(bytes);
  }else
    return(0);
}
Exemple #27
0
static int get_more_data(ogg_sync_state *oy)
{
    int bytes;
    char *buffer;

    buffer = (char *)ogg_sync_buffer(oy, CHUNKSIZE);
    bytes = ci->read_filebuf(buffer, CHUNKSIZE);
    ogg_sync_wrote(oy,bytes);

    return bytes;
}
Exemple #28
0
bool OggPlayer::Imp::buffer_data() {
	if (!file_in.is_open())
		return 0;
	if (file_in.eof()) {
		file_in.close();
		return 0;
	}
	char *buffer = ogg_sync_buffer(&o_sync, 4096);
	int bytes = file_in.read(buffer, 4096).gcount();
	ogg_sync_wrote(&o_sync, bytes);
	return (bytes != 0);
}
Exemple #29
0
FLAC__StreamDecoderReadStatus read_callback_(const FLAC__StreamDecoder *unused, FLAC__byte buffer[], unsigned *bytes, void *client_data)
{
	static const unsigned OGG_BYTES_CHUNK = 8192;
	OggFLAC__StreamDecoder *decoder = (OggFLAC__StreamDecoder*)client_data;
	unsigned ogg_bytes_to_read, ogg_bytes_read;
	ogg_page page;
	char *oggbuf;

	(void)unused;

	/*
	 * We have to be careful not to read in more than the
	 * FLAC__StreamDecoder says it has room for.  We know
	 * that the size of the decoded data must be no more
	 * than the encoded data we will read.
	 */
	ogg_bytes_to_read = min(*bytes, OGG_BYTES_CHUNK);
	oggbuf = ogg_sync_buffer(&decoder->private_->ogg.sync_state, ogg_bytes_to_read);

	if(decoder->private_->read_callback(decoder, oggbuf, &ogg_bytes_to_read, decoder->private_->client_data) != FLAC__STREAM_DECODER_READ_STATUS_CONTINUE) {
		decoder->protected_->state = OggFLAC__STREAM_DECODER_READ_ERROR;
		return FLAC__STREAM_DECODER_READ_STATUS_ABORT;
	}
	ogg_bytes_read = ogg_bytes_to_read;

	if(ogg_sync_wrote(&decoder->private_->ogg.sync_state, ogg_bytes_read) < 0) {
		decoder->protected_->state = OggFLAC__STREAM_DECODER_READ_ERROR;
		return FLAC__STREAM_DECODER_READ_STATUS_ABORT;
	}

	*bytes = 0;
	while(ogg_sync_pageout(&decoder->private_->ogg.sync_state, &page) == 1) {
		/* grab the serial number if necessary */
		if(decoder->private_->ogg.need_serial_number) {
			decoder->private_->ogg.stream_state.serialno = decoder->protected_->serial_number = ogg_page_serialno(&page);
			decoder->private_->ogg.need_serial_number = false;
		}
		if(ogg_stream_pagein(&decoder->private_->ogg.stream_state, &page) == 0) {
			ogg_packet packet;

			while(ogg_stream_packetout(&decoder->private_->ogg.stream_state, &packet) == 1) {
				memcpy(buffer, packet.packet, packet.bytes);
				*bytes += packet.bytes;
				buffer += packet.bytes;
			}
		} else {
			decoder->protected_->state = OggFLAC__STREAM_DECODER_READ_ERROR;
			return FLAC__STREAM_DECODER_READ_STATUS_ABORT;
		}
	}

	return FLAC__STREAM_DECODER_READ_STATUS_CONTINUE;
}
Exemple #30
0
static int ogg_read_header(AVFormatContext *avfcontext, AVFormatParameters *ap)
{
    OggContext *context = avfcontext->priv_data;
    ogg_packet op ;
    char *buf ;
    ogg_page og ;
    AVStream *ast ;
    AVCodecContext *codec;
    uint8_t *p;
    int i;

    ogg_sync_init(&context->oy) ;
    buf = ogg_sync_buffer(&context->oy, DECODER_BUFFER_SIZE) ;

    if(get_buffer(&avfcontext->pb, buf, DECODER_BUFFER_SIZE) <= 0)
        return AVERROR_IO ;

    ogg_sync_wrote(&context->oy, DECODER_BUFFER_SIZE) ;
    ogg_sync_pageout(&context->oy, &og) ;
    ogg_stream_init(&context->os, ogg_page_serialno(&og)) ;
    ogg_stream_pagein(&context->os, &og) ;

    /* currently only one vorbis stream supported */

    ast = av_new_stream(avfcontext, 0) ;
    if(!ast)
        return AVERROR_NOMEM ;
    av_set_pts_info(ast, 60, 1, AV_TIME_BASE);

    codec= &ast->codec;
    codec->codec_type = CODEC_TYPE_AUDIO;
    codec->codec_id = CODEC_ID_VORBIS;
    for(i=0; i<3; i++){
        if(next_packet(avfcontext, &op)){
            return -1;
        }
        if(op.bytes >= (1<<16) || op.bytes < 0)
            return -1;
        codec->extradata_size+= 2 + op.bytes;
        codec->extradata= av_realloc(codec->extradata, codec->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE);
        memset(codec->extradata + codec->extradata_size, 0, FF_INPUT_BUFFER_PADDING_SIZE);
        p= codec->extradata + codec->extradata_size - 2 - op.bytes;
        *(p++)= op.bytes>>8;
        *(p++)= op.bytes&0xFF;
        memcpy(p, op.packet, op.bytes);
    }

    return 0 ;
}