2 Copyright (C) 2003 Commonwealth Scientific and Industrial Research
3 Organisation (CSIRO) Australia
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions
9 - Redistributions of source code must retain the above copyright
10 notice, this list of conditions and the following disclaimer.
12 - Redistributions in binary form must reproduce the above copyright
13 notice, this list of conditions and the following disclaimer in the
14 documentation and/or other materials provided with the distribution.
16 - Neither the name of CSIRO Australia nor the names of its
17 contributors may be used to endorse or promote products derived from
18 this software without specific prior written permission.
20 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
23 PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE ORGANISATION OR
24 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 * Shane Stephens <shane.stephens@annodex.net>
39 #ifndef __OGGPLAY_PRIVATE_H__
40 #define __OGGPLAY_PRIVATE_H__
46 #include <oggplay/oggplay.h>
48 #include <oggz/oggz.h>
49 #include <theora/theora.h>
50 #include <fishsound/fishsound.h>
53 #include <kate/kate.h>
56 #include <tiger/tiger.h>
59 #include <skeleton/skeleton.h>
63 #include "config_win32.h"
71 // for Win32 <windows.h> has to be included last
72 #include "std_semaphore.h"
76 * has_been_presented: 0 until the data has been added as a "required" element,
79 struct _OggPlayDataHeader
{
81 struct _OggPlayDataHeader
* next
;
82 ogg_int64_t presentation_time
;
83 ogg_int64_t samples_in_record
;
84 int has_been_presented
;
88 OggPlayDataHeader header
;
89 OggPlayVideoData data
;
93 OggPlayDataHeader header
;
94 OggPlayOverlayData data
;
95 } OggPlayOverlayRecord
;
98 OggPlayDataHeader header
;
100 } OggPlayAudioRecord
;
103 OggPlayDataHeader header
;
111 void ** buffer_mirror
;
118 struct _OggPlayCallbackInfo
{
119 OggPlayDataType data_type
;
120 int available_records
;
121 int required_records
;
122 OggPlayStreamInfo stream_info
;
123 OggPlayDataHeader
** records
;
124 OggPlayBuffer
* buffer
;
130 * A structure that contains information about a single track within the Ogg
133 * data_list, end_of_data_list: Contain decoded data packets for this track.
134 * These packets are time-ordered, and have a
135 * known presentation time
137 * untimed_data_list: Contains decoded data packets for this track.
138 * These packets are reverse time-ordered, and
139 * have not got a known presentation time. This
140 * list gets constructed when a new Ogg file is
141 * first being read, and gets torn down as soon as
142 * the first packet with a granulepos is processed
144 * granuleperiod The period between adjacent samples in this
148 long serialno
; /**< identifies the logical bit stream */
150 const char * content_type_name
;
151 OggPlayDataType decoded_type
; /**< type of the track @see OggPlayDataType */
152 ogg_int64_t granuleperiod
;
153 ogg_int64_t last_granulepos
; /**< last seen granule position */
154 ogg_int64_t offset
; /**< */
155 ogg_int64_t current_loc
; /**< current location in the stream (in ) */
156 int active
; /**< indicates whether the track is active or not */
157 ogg_int64_t final_granulepos
; /**< */
158 struct _OggPlay
* player
; /**< reference to the OggPlay handle */
159 OggPlayDataHeader
* data_list
;
160 OggPlayDataHeader
* end_of_data_list
;
161 OggPlayDataHeader
* untimed_data_list
;
162 OggPlayStreamInfo stream_info
; /**< @see OggPlayStreamInfo */
163 int preroll
; /**< num. of past content packets to take into account when decoding the current Ogg page */
164 short initialised
; /**< */
165 int num_header_packets
; /**< number of header packets left to process for the stream.*/
169 OggPlayDecode decoder
;
170 theora_state video_handle
;
171 theora_info video_info
;
172 theora_comment video_comment
;
184 } OggPlayTheoraDecode
;
187 OggPlayDecode decoder
;
188 FishSound
* sound_handle
;
189 FishSoundInfo sound_info
;
190 } OggPlayAudioDecode
;
193 OggPlayDecode decoder
;
198 * OggPlaySkeletonDecode
201 OggPlayDecode decoder
;
203 OggSkeleton
* skeleton
;
205 ogg_int64_t presentation_time
;
206 ogg_int64_t base_time
;
208 } OggPlaySkeletonDecode
;
211 OggPlayDecode decoder
;
216 kate_comment k_comment
;
229 struct OggPlaySeekTrash
;
234 typedef struct OggPlaySeekTrash
{
235 OggPlayDataHeader
* old_data
;
236 OggPlayBuffer
* old_buffer
;
237 struct OggPlaySeekTrash
* next
;
244 OggPlayReader
* reader
; /**< @see OggPlayReader */
245 OGGZ
* oggz
; /**< @see OGGZ */
246 OggPlayDecode
** decode_data
; /**< */
247 OggPlayCallbackInfo
* callback_info
; /**< */
248 int num_tracks
; /**< number of tracks in the Ogg container */
249 int all_tracks_initialised
; /**< "= 1" indicates that all tracks are initialised */
250 ogg_int64_t callback_period
; /**< */
251 OggPlayDataCallback
* callback
; /**< */
252 void * callback_user_ptr
; /**< */
253 ogg_int64_t target
; /**< */
254 int active_tracks
; /**< number of active tracks */
255 volatile OggPlayBuffer
* buffer
; /**< @see OggPlayBuffer */
256 ogg_int64_t presentation_time
; /**< */
257 OggPlaySeekTrash
* trash
; /**< @see OggPlaySeekTrash */
258 int shutdown
; /**< "= 1" indicates shutdown event */
259 int pt_update_valid
; /**< */
260 ogg_int64_t duration
; /**< The value of the duration the last time it was retrieved.*/
264 oggplay_set_data_callback_force(OggPlay
*me
, OggPlayDataCallback callback
,
268 oggplay_take_out_trash(OggPlay
*me
, OggPlaySeekTrash
*trash
);
271 oggplay_seek_cleanup(OggPlay
*me
, ogg_int64_t milliseconds
);
274 void (*init
) (void *user_data
);
275 int (*callback
) (OGGZ
* oggz
, ogg_packet
* op
, long serialno
,
277 void (*shutdown
) (void *user_data
);
279 } OggPlayCallbackFunctions
;
282 * Conversion function for fixed point 32.32 representation of time.
284 * OGGPLAY_TIME_INT_TO_FP(x)
285 * converts 'x' to a 32.32 fixed point integer
287 * OGGPLAY_TIME_FP_TO_INT
288 * converts 'x' - a 32.32 fixed point integer - back to normal integer representation
289 * + changes the order of magnitude by 1000
290 * e.g. if the fixed point number - 32.32 format - represents seconds
291 * then the macro will convert it to milliseconds.
293 #define OGGPLAY_TIME_INT_TO_FP(x) ((x) << 32)
294 #define OGGPLAY_TIME_FP_TO_INT(x) (((((x) >> 16) * 1000) >> 16) & 0xFFFFFFFF)
296 /* Allocate and free dynamic memory used by ogg.
297 * By default they are the ones from stdlib */
298 #define oggplay_malloc _ogg_malloc
299 #define oggplay_calloc _ogg_calloc
300 #define oggplay_realloc _ogg_realloc
301 #define oggplay_free _ogg_free
304 * macros for obtaining a type's max and min values
305 * http://www.fefe.de/intof.html
307 #define OGGPLAY_TYPE_HALF_MAX_SIGNED(type) ((type)1 << (sizeof(type)*8-2))
308 #define OGGPLAY_TYPE_MAX_SIGNED(type) (OGGPLAY_TYPE_HALF_MAX_SIGNED(type) - 1 + OGGPLAY_TYPE_HALF_MAX_SIGNED(type))
309 #define OGGPLAY_TYPE_MIN_SIGNED(type) (-1 - OGGPLAY_TYPE_MAX_SIGNED(type))
310 #define OGGPLAY_TYPE_MIN(type) ((type)-1 < 1?OGGPLAY_TYPE_MIN_SIGNED(type):(type)0)
311 #define OGGPLAY_TYPE_MAX(type) ((type)~OGGPLAY_TYPE_MIN(type))
314 oggplay_check_add_overflow (size_t a
, long b
, size_t* r
) {
315 /* we cannot assume that sizeof(size_t) >= sizeof(long) !!! */
316 if (sizeof(size_t) < sizeof(long)) {
317 /* check whether the number fits into a size_t */
321 ((OGGPLAY_TYPE_MAX(size_t)+b
>= 0) ? 0 : 1) :
322 ((OGGPLAY_TYPE_MAX(size_t)-b
>= 0) ? 0 : 1)
325 return E_OGGPLAY_TYPE_OVERFLOW
;
328 /* check whether the sum of the 'a' and 'b' fits into a size_t */
332 ((OGGPLAY_TYPE_MIN(size_t)-b
<= a
) ? 0 : 1) :
333 ((OGGPLAY_TYPE_MAX(size_t)-b
>= a
) ? 0 : 1)
336 return E_OGGPLAY_TYPE_OVERFLOW
;
339 /* if 'r' is supplied give back the sum of 'a' and 'b' */
347 oggplay_mul_signed_overflow_generic(long a
, long b
, long *re
) {
348 long _a
, _b
, ah
, bh
, x
, y
, r
= 0;
353 ah
= _a
>> (sizeof(long)*4);
354 bh
= _b
>> (sizeof(long)*4);
359 if (_b
== 0 || _b
== 1) {
367 ah
= _a
>> (sizeof(long)*4);
373 if (_a
== 0 || (_a
== 1 && sign
== 1)) {
381 bh
= _b
>> (sizeof(long)*4);
384 if (ah
!= 0 && bh
!= 0) {
388 if (ah
== 0 && bh
== 0) {
404 if (y
>= (1L << (sizeof(long)*4 - 1)))
406 _a
&= (1L << sizeof(long)*4) - 1;
410 x
+= (y
<< sizeof(long)*4);
422 return E_OGGPLAY_TYPE_OVERFLOW
;
426 oggplay_mul_signed_overflow(long a
, long b
, long *r
) {
427 if (sizeof(long) > 4) {
428 return oggplay_mul_signed_overflow_generic (a
, b
, r
);
430 ogg_int64_t c
= (ogg_int64_t
) a
*b
;
432 /* check whether the result fits in a long bit */
436 ((OGGPLAY_TYPE_MIN (long) > c
) ? 1 : 0) :
437 ((OGGPLAY_TYPE_MAX (long) < c
) ? 1 : 0)
440 return E_OGGPLAY_TYPE_OVERFLOW
;
450 #include "oggplay_callback.h"
451 #include "oggplay_data.h"
452 #include "oggplay_buffer.h"