Commit 06c0dfa1 authored by conrad's avatar conrad

add oggz_packet definition, and implement reader

to return oggz_packet in OggzReadPacket callback
parent 40764352
/*
Copyright (C) 2009 Annodex Association
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
- Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
- Neither the name of the Annodex Association nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE ASSOCIATION OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef __OGGZ_PACKET_H__
#define __OGGZ_PACKET_H__
/** \file
* Packet positioning
*
* oggz_packet derives from ogg_packet, and includes position information.
*/
/************************************************************
* OggzPacket
*/
/**
* The position of an oggz_packet.
*/
typedef struct {
/**
* Granulepos calculated by inspection of codec data.
* -1 if unknown
*/
ogg_int64_t calc_granulepos;
/**
* Byte offset of the start of the page on which this
* packet begins.
*/
oggz_off_t begin_page_offset;
/**
* Byte offset of the start of the page on which this
* packet ends.
*/
oggz_off_t end_page_offset;
/** Number of pages this packet spans. */
int pages;
/**
* Index into begin_page's lacing values
* for the segment that begins this packet.
* NB. if begin_page is continued then the first
* of these packets will not be reported by
* ogg_sync_packetout() after a seek.
* -1 if unknown.
*/
int begin_segment_index;
} oggz_position;
/**
* An ogg_packet and its position in the stream.
*/
typedef struct {
/** The ogg_packet structure, defined in <ogg/ogg.h> */
ogg_packet op;
/** Its position */
oggz_position pos;
} oggz_packet;
#endif /* __OGGZ_PACKET_H__ */
......@@ -37,6 +37,8 @@
* Interfaces for reading Ogg files and streams
*/
#include <oggz/oggz_packet.h>
/** \defgroup read_api Oggz Read API
*
* Oggz parses Ogg bitstreams, forming ogg_packet structures, and calling
......@@ -67,16 +69,16 @@
* with \a oggz.
*
* \param oggz The OGGZ handle
* \param op The full ogg_packet (see <ogg/ogg.h>)
* \param packet The packet, including its position in the stream.
* \param serialno Identify the logical bistream in \a oggz that contains
* \a op
* \a packet
* \param user_data A generic pointer you have provided earlier
* \returns 0 to continue, non-zero to instruct Oggz to stop.
*
* \note It is possible to provide different callbacks per logical
* bitstream -- see oggz_set_read_callback() for more information.
*/
typedef int (*OggzReadPacket) (OGGZ * oggz, ogg_packet * op, long serialno,
typedef int (*OggzReadPacket) (OGGZ * oggz, oggz_packet * packet, long serialno,
void * user_data);
/**
......
......@@ -121,7 +121,7 @@ struct _oggz_stream_t {
ogg_int64_t last_granulepos;
ogg_int64_t page_granulepos;
void * calculate_data;
ogg_packet * last_packet;
ogg_packet * last_packet;
};
struct _OggzReader {
......@@ -140,7 +140,12 @@ struct _OggzReader {
ogg_int64_t current_unit;
ogg_int64_t current_granulepos;
/* Read positioning */
long current_page_bytes;
oggz_off_t current_packet_begin_page_offset;
int current_packet_pages;
#if 0
oggz_off_t offset_page_end; /* offset of end of current page */
#endif
......
......@@ -60,6 +60,7 @@
#include "oggz_compat.h"
#include "oggz_private.h"
#include "oggz/oggz_packet.h"
#include "oggz/oggz_stream.h"
/* #define DEBUG */
......@@ -88,6 +89,9 @@ oggz_read_init (OGGZ * oggz)
reader->current_page_bytes = 0;
reader->current_packet_begin_page_offset = 0;
reader->current_packet_pages = 0;
return oggz;
}
......@@ -317,15 +321,17 @@ oggz_read_sync (OGGZ * oggz)
oggz_stream_t * stream;
ogg_stream_state * os;
ogg_packet * op;
oggz_position * pos;
long serialno;
ogg_packet packet;
oggz_packet packet;
ogg_page og;
int cb_ret = 0;
/*os = &reader->ogg_stream;*/
op = &packet;
op = &packet.op;
pos = &packet.pos;
/* handle one packet. Try to fetch it from current stream state */
/* extract packets from page */
......@@ -468,14 +474,24 @@ oggz_read_sync (OGGZ * oggz)
}
}
/* Fill in position information */
pos->calc_granulepos = reader->current_granulepos;
pos->begin_page_offset = reader->current_packet_begin_page_offset;
pos->end_page_offset = oggz->offset;
pos->pages = reader->current_packet_pages;
if (stream->read_packet) {
cb_ret =
stream->read_packet (oggz, op, serialno, stream->read_user_data);
stream->read_packet (oggz, &packet, serialno, stream->read_user_data);
} else if (reader->read_packet) {
cb_ret =
reader->read_packet (oggz, op, serialno, reader->read_user_data);
reader->read_packet (oggz, &packet, serialno, reader->read_user_data);
}
/* Prepare the position of the next page */
reader->current_packet_pages = 1;
reader->current_packet_begin_page_offset = oggz->offset;
/* Mark this stream as having delivered a non b_o_s packet if so.
* In the case where there is no packet reading callback, this is
* also valid as the page reading callback has already been called.
......@@ -494,7 +510,7 @@ oggz_read_sync (OGGZ * oggz)
return OGGZ_READ_EMPTY; /* eof. leave uninitialized */
serialno = ogg_page_serialno (&og);
reader->current_serialno = serialno; /* XXX: maybe not necessary */
reader->current_serialno = serialno;
stream = oggz_get_stream (oggz, serialno);
......@@ -544,6 +560,14 @@ oggz_read_sync (OGGZ * oggz)
}
ogg_stream_pagein(os, &og);
if (ogg_page_continued(&og)) {
if (reader->current_packet_pages != -1)
reader->current_packet_pages++;
} else {
/* Prepare the position of the next page */
reader->current_packet_pages = 1;
reader->current_packet_begin_page_offset = oggz->offset;
}
}
return cb_ret;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment