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); }
void TheoraDecoder::queuePage(ogg_page *page) { if (_theoraPacket) ogg_stream_pagein(&_theoraOut, page); if (_vorbisPacket) ogg_stream_pagein(&_vorbisOut, page); }
void TheoraDecoder::queuePage(ogg_page *page) { if (_hasVideo) ogg_stream_pagein(&_theoraOut, page); if (_hasAudio) ogg_stream_pagein(&_vorbisOut, page); }
int OggPlayer::Imp::queue_page(ogg_page * page) { if (theora_p) ogg_stream_pagein(&o_tsstate, page); #ifdef VORBIS_SUPPORT if (vorbis_p) ogg_stream_pagein(&o_vsstate, page); #endif return 0; }
int queue_page(ogg_page *page) { // helper: push a page into the appropriate stream. // this can be done blindly; a stream won't accept a page that doesn't belong to it if (theora_p) ogg_stream_pagein(&to,page); if (vorbis_p) ogg_stream_pagein(&vo,page); return 0; }
int VideoStreamPlaybackTheora::queue_page(ogg_page *page) { if (theora_p) { ogg_stream_pagein(&to, page); if (to.e_o_s) theora_eos = true; } if (vorbis_p) { ogg_stream_pagein(&vo, page); if (vo.e_o_s) vorbis_eos = true; } return 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); }
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 ; }
/* loadPagesToStreams return: !0 -> no data transferred (or not for all Streams) */ static int loadPagesToStreams(void) { int r=-1; int AudioPages=0; int VideoPages=0; ogg_stream_state* osptr = NULL; ogg_page og; while(!AudioPages || !VideoPages) { if(ogg_sync_pageout(&g_ogm.oy,&og) != 1) break; if(g_ogm.os_audio.serialno == ogg_page_serialno(&og)) { osptr = &g_ogm.os_audio; ++AudioPages; } if(g_ogm.os_video.serialno == ogg_page_serialno(&og)) { osptr = &g_ogm.os_video; ++VideoPages; } if(osptr!=NULL) { ogg_stream_pagein(osptr,&og); } } if(AudioPages && VideoPages) r = 0; return r; }
nsresult VorbisState::PageIn(ogg_page* aPage) { if (!mActive) return NS_OK; NS_ASSERTION(static_cast<uint32_t>(ogg_page_serialno(aPage)) == mSerial, "Page must be for this stream!"); if (ogg_stream_pagein(&mState, aPage) == -1) return NS_ERROR_FAILURE; bool foundGp; nsresult res = PacketOutUntilGranulepos(foundGp); if (NS_FAILED(res)) return res; if (foundGp && mDoneReadingHeaders) { // We've found a packet with a granulepos, and we've loaded our metadata // and initialized our decoder. Determine granulepos of buffered packets. ReconstructVorbisGranulepos(); for (uint32_t i = 0; i < mUnstamped.Length(); ++i) { ogg_packet* packet = mUnstamped[i]; AssertHasRecordedPacketSamples(packet); NS_ASSERTION(!IsHeader(packet), "Don't try to recover header packet gp"); NS_ASSERTION(packet->granulepos != -1, "Packet must have gp by now"); mPackets.Append(packet); } mUnstamped.Clear(); } return NS_OK; }
/** * @return !0 -> no data transferred (or not for all streams) */ static int CIN_OGM_LoadPagesToStream (cinematic_t* cin) { int r = -1; int audioPages = 0; int videoPages = 0; ogg_stream_state* osptr = nullptr; ogg_page og; while (!audioPages || !videoPages) { if (ogg_sync_pageout(&OGMCIN.oy, &og) != 1) break; if (OGMCIN.os_audio.serialno == ogg_page_serialno(&og)) { osptr = &OGMCIN.os_audio; ++audioPages; } if (OGMCIN.os_video.serialno == ogg_page_serialno(&og)) { osptr = &OGMCIN.os_video; ++videoPages; } if (osptr != nullptr) { ogg_stream_pagein(osptr, &og); } } if (audioPages && videoPages) r = 0; return r; }
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; }
ogg_codec_t *initial_opus_page (format_plugin_t *plugin, ogg_page *page) { ogg_state_t *ogg_info = plugin->_state; ogg_codec_t *codec = calloc (1, sizeof (ogg_codec_t)); ogg_packet packet; ogg_stream_init (&codec->os, ogg_page_serialno (page)); ogg_stream_pagein (&codec->os, page); ogg_stream_packetout (&codec->os, &packet); DEBUG0("checking for opus codec"); if (strncmp((char *)packet.packet, "OpusHead", 8) != 0) { ogg_stream_clear (&codec->os); free (codec); return NULL; } INFO0 ("seen initial opus header"); codec->process_page = process_opus_page; codec->codec_free = opus_codec_free; codec->headers = 1; codec->parent = ogg_info; codec->name = "Opus"; format_ogg_attach_header (codec, page); return codec; }
ogg_codec_t *initial_speex_page (format_plugin_t *plugin, ogg_page *page) { ogg_state_t *ogg_info = plugin->_state; ogg_codec_t *codec = acalloc (1, sizeof (ogg_codec_t)); ogg_packet packet; SpeexHeader *header; ogg_stream_init (&codec->os, ogg_page_serialno (page)); ogg_stream_pagein (&codec->os, page); ogg_stream_packetout (&codec->os, &packet); DEBUG0("checking for speex codec"); header = speex_packet_to_header ((char*)packet.packet, packet.bytes); if (header == NULL) { ogg_stream_clear (&codec->os); free (header); free (codec); return NULL; } INFO0 ("seen initial speex header"); codec->process_page = process_speex_page; codec->codec_free = speex_codec_free; codec->headers = 1; format_ogg_attach_header (ogg_info, page); free (header); return codec; }
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; }
bool Oggeyman::fast_forward_to_frame(int frameno) { if (stream_done) return false; int framect = 0; while (framect < frameno && !stream_done) { bool packet_found = false; do { // list through packets to get rid of bad packets // (the function below checks whether the packet is ok) packet_found = next_theora_packet(&ogg_theora_stream_state, &ogg_theora_packet, &theo_state); if (!packet_found) { //try new page bool is_theora_page = false; while (!stream_done && !is_theora_page) { stream_done = !next_page(); if (stream_done) continue; // submit the completed page to the streaming layer with ogg_stream_pagein. // check out the return value - it will be < 0 it the page does not correspond // to the stream whose state we are providing as the first argument is_theora_page = (ogg_stream_pagein( &ogg_theora_stream_state, ¤t_ogg_page) >= 0); } } else { framect++; } } while (!packet_found && !stream_done); } if (framect == frameno && !stream_done) { total_play_time = last_packet_time = get_packet_time(); return true; } return false; }
int ovd_header_init(ovd_handle* handle) { if (handle->init < 2) { if (handle->init < 0) return -1; while (handle->init < 2) { int result = ogg_sync_pageout(handle->oy, &handle->og); if (result == 0) return FALSE; // need more data if (result == 1) { ogg_stream_pagein(handle->os, &handle->og); while(handle->init < 2){ result = ogg_stream_packetout(handle->os, &handle->op); if (result == 0) return 0; // need more data if (result < 0) { handle->init = -1; // fatal error return -1; } vorbis_synthesis_headerin(&handle->vi, &handle->vc, &handle->op); handle->init++; } } else if (result = -1) return -1; } vorbis_synthesis_init(&handle->vd, &handle->vi); vorbis_block_init(&handle->vd, &handle->vb); return 1; } return 1; }
static sf_count_t vorbis_length_aux (SF_PRIVATE * psf) { ogg_sync_state osync ; ogg_page page ; sf_count_t len = 0 ; stream_set *processors ; processors = create_stream_set () ; if (processors == NULL) return 0 ; // out of memory? ogg_sync_init (&osync) ; while (vorbis_length_get_next_page (psf, &osync, &page)) { stream_processor *p = find_stream_processor (processors, &page) ; if (!p) { len = 0 ; break ; } ; if (p->isillegal && !p->shownillegal) { p->shownillegal = 1 ; /* If it's a new stream, we want to continue processing this page ** anyway to suppress additional spurious errors */ if (!p->isnew) continue ; } ; if (!p->isillegal) { ogg_packet packet ; int header = 0 ; ogg_stream_pagein (&p->ostream, &page) ; if (p->doneheaders < 3) header = 1 ; while (ogg_stream_packetout (&p->ostream, &packet) > 0) { if (p->doneheaders < 3) { if (vorbis_synthesis_headerin (&p->vinfo, &p->vcomment, &packet) < 0) continue ; p->doneheaders ++ ; } ; } ; if (!header) { sf_count_t gp = ogg_page_granulepos (&page) ; if (gp > 0) p->lastgranulepos = gp ; } ; if (p->end) { vorbis_end (p, &len) ; p->isillegal = 1 ; } ; } ; } ; ogg_sync_clear (&osync) ; free_stream_set (processors, &len) ; return len ; } /* vorbis_length_aux */
static ChainCodec get_page_codec (ogg_page * page) { ChainCodec codec = CODEC_UNKNOWN; ogg_stream_state state; ogg_packet packet; ogg_stream_init (&state, ogg_page_serialno (page)); if (ogg_stream_pagein (&state, page) == 0) { if (ogg_stream_packetpeek (&state, &packet) > 0) { if (strncmp ((char *) &packet.packet[1], "vorbis", strlen ("vorbis")) == 0) codec = CODEC_VORBIS; else if (strncmp ((char *) &packet.packet[1], "theora", strlen ("theora")) == 0) codec = CODEC_THEORA; else if (strncmp ((char *) &packet.packet[0], "Speex ", strlen ("Speex ")) == 0) codec = CODEC_SPEEX; } } ogg_stream_clear (&state); return codec; }
ogg_codec_t *initial_midi_page (format_plugin_t *plugin, ogg_page *page) { ogg_state_t *ogg_info = plugin->_state; ogg_codec_t *codec = calloc (1, sizeof (ogg_codec_t)); ogg_packet packet; ogg_stream_init (&codec->os, ogg_page_serialno (page)); ogg_stream_pagein (&codec->os, page); ogg_stream_packetout (&codec->os, &packet); ICECAST_LOG_DEBUG("checking for MIDI codec"); do { if (packet.bytes < 9) break; if (memcmp (packet.packet, "OggMIDI\000", 8) != 0) break; if (packet.bytes != 12) break; ICECAST_LOG_INFO("seen initial MIDI header"); codec->process_page = process_midi_page; codec->codec_free = midi_codec_free; codec->headers = 1; codec->name = "MIDI"; format_ogg_attach_header(ogg_info, page); return codec; } while (0); ogg_stream_clear(&codec->os); free(codec); return NULL; }
bool VideoClip_Theora::_readData() { int audioEos = 0; int serno = 0; float audioTime = 0; float time = this->timer->getTime(); if (this->restarted) { time = 0.0f; } char* buffer = NULL; int bytesRead = 0; ogg_int64_t granule = 0; do { buffer = ogg_sync_buffer(&this->info.OggSyncState, BUFFER_SIZE); bytesRead = this->stream->read(buffer, BUFFER_SIZE); ogg_sync_wrote(&this->info.OggSyncState, bytesRead); if (bytesRead == 0) { if (!this->autoRestart) { this->endOfFile = true; log(this->name + " finished playing"); } return false; } // when we fill the stream with enough pages, it'll start spitting out packets // which contain key frames, delta frames or audio data while (ogg_sync_pageout(&this->info.OggSyncState, &this->info.OggPage) > 0) { serno = ogg_page_serialno(&this->info.OggPage); if (serno == this->info.TheoraStreamState.serialno) { ogg_stream_pagein(&this->info.TheoraStreamState, &this->info.OggPage); } if (this->audioInterface != NULL && serno == this->info.VorbisStreamState.serialno) { granule = ogg_page_granulepos(&this->info.OggPage); audioTime = (float)vorbis_granule_time(&this->info.VorbisDSPState, granule); audioEos = ogg_page_eos(&this->info.OggPage); ogg_stream_pagein(&this->info.VorbisStreamState, &this->info.OggPage); } } } while (this->audioInterface != NULL && audioEos == 0 && audioTime < time + 1.0f); return true; }
int PushPage(ogg_page *page) { if (ogg_stream_pagein( &m_StreamState, page ) == -1) { assert( false ); } return 0; }
bool OggReader::pushOggPage(ogg_stream_state* os, ogg_page* op) { int ret = 0; ret = ogg_stream_pagein(os, op); return ret == 0; }
static PyObject * py_ogg_ogg_stream_pagein(PyObject *self, PyObject *args) { int c_out; int size1, size2; ogg_stream_state * os; ogg_page * og; PyArg_ParseTuple(args, "s#s#", &os, &size1, &og, &size2); c_out = ogg_stream_pagein(os, og); return Py_BuildValue("i", c_out); };
static OGGStream *OGG_FindStreamForPage(OGGReader *read, ogg_page *oggpage) { u32 i, count; count = gf_list_count(read->streams); for (i=0; i<count; i++) { OGGStream *st = gf_list_get(read->streams, i); if (ogg_stream_pagein(&st->os, oggpage) == 0) return st; } return NULL; }
static void process_other(stream_processor *stream, ogg_page *page, MP3FILE *pmp) { ogg_packet packet; ogg_stream_pagein(&stream->os, page); while(ogg_stream_packetout(&stream->os, &packet) > 0) { /* Should we do anything here? Currently, we don't */ } }
/* check if the provided BOS page is the start of a vorbis stream. If so * then setup a structure so it can be used */ ogg_codec_t *initial_vorbis_page (format_plugin_t *plugin, ogg_page *page) { ogg_state_t *ogg_info = plugin->_state; ogg_codec_t *codec = calloc (1, sizeof (ogg_codec_t)); ogg_packet packet; vorbis_codec_t *vorbis = calloc (1, sizeof (vorbis_codec_t)); ogg_stream_init (&codec->os, ogg_page_serialno (page)); ogg_stream_pagein (&codec->os, page); vorbis_info_init (&vorbis->vi); vorbis_comment_init (&vorbis->vc); ogg_stream_packetout (&codec->os, &packet); DEBUG0("checking for vorbis codec"); if (vorbis_synthesis_headerin (&vorbis->vi, &vorbis->vc, &packet) < 0) { ogg_stream_clear (&codec->os); vorbis_info_clear (&vorbis->vi); vorbis_comment_clear (&vorbis->vc); free (vorbis); free (codec); return NULL; } INFO0 ("seen initial vorbis header"); codec->specific = vorbis; codec->codec_free = vorbis_codec_free; codec->headers = 1; codec->parent = ogg_info; codec->name = "Vorbis"; free_ogg_packet (vorbis->header[0]); free_ogg_packet (vorbis->header[1]); free_ogg_packet (vorbis->header[2]); memset (vorbis->header, 0, sizeof (vorbis->header)); vorbis->header [0] = copy_ogg_packet (&packet); ogg_stream_init (&vorbis->new_os, rand()); codec->process_page = process_vorbis_page; codec->process = process_vorbis; plugin->set_tag = vorbis_set_tag; vorbis->bos_page.header = malloc (page->header_len + page->body_len); memcpy (vorbis->bos_page.header, page->header, page->header_len); vorbis->bos_page.header_len = page->header_len; vorbis->bos_page.body = vorbis->bos_page.header + page->header_len; memcpy (vorbis->bos_page.body, page->body, page->body_len); vorbis->bos_page.body_len = page->body_len; return codec; }
PRBool nsOggCodecState::PageInFromBuffer() { if (mBuffer.IsEmpty()) return PR_FALSE; ogg_page *p = mBuffer.PeekFront(); int ret = ogg_stream_pagein(&mState, p); NS_ENSURE_TRUE(ret == 0, PR_FALSE); mBuffer.PopFront(); delete p->header; delete p; return PR_TRUE; }
/* uses the local ogg_stream storage in vf; this is important for non-streaming input sources */ static int _fetch_headers(OggVorbis_File *vf,vorbis_info *vi,vorbis_comment *vc, long *serialno,ogg_page *og_ptr){ ogg_page og; ogg_packet op; int i,ret=0; if(!og_ptr){ ret=_get_next_page(vf,&og,CHUNKSIZE); if(ret==OV_EREAD)return(OV_EREAD); if(ret<0)return OV_ENOTVORBIS; og_ptr=&og; } if(serialno)*serialno=ogg_page_serialno(og_ptr); ogg_stream_init(&vf->os,ogg_page_serialno(og_ptr)); vf->ready_state=STREAMSET; /* extract the initial header from the first page and verify that the Ogg bitstream is in fact Vorbis data */ vorbis_info_init(vi); vorbis_comment_init(vc); i=0; while(i<3){ ogg_stream_pagein(&vf->os,og_ptr); while(i<3){ int result=ogg_stream_packetout(&vf->os,&op); if(result==0)break; if(result==-1){ ret=OV_EBADHEADER; goto bail_header; } if((ret=vorbis_synthesis_headerin(vi,vc,&op))){ goto bail_header; } i++; } if(i<3) if(_get_next_page(vf,og_ptr,CHUNKSIZE)<0){ ret=OV_EBADHEADER; goto bail_header; } } return 0; bail_header: vorbis_info_clear(vi); vorbis_comment_clear(vc); ogg_stream_clear(&vf->os); vf->ready_state=OPENED; return ret; }