3 Copyright 2008 Tor-Einar Jarnbjo
5 Licensed under the Apache License, Version 2.0 (the "License");
6 you may not use this file except in compliance with the License.
7 You may obtain a copy of the License at
9 http://www.apache.org/licenses/LICENSE-2.0
11 Unless required by applicable law or agreed to in writing, software
12 distributed under the License is distributed on an "AS IS" BASIS,
13 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 See the License for the specific language governing permissions and
15 limitations under the License.
19 package org.omtk.ogg {
22 import flash.utils.ByteArray;
24 public class OggPage {
26 private var _version:int;
27 private var _continued:Boolean;
28 private var _bos:Boolean;
29 private var _eos:Boolean;
30 private var _absoluteGranulePosition:int;
31 private var _streamSerialNumber:int;
32 private var _pageSequenceNumber:int;
33 private var _pageCheckSum:int;
34 private var _segmentOffsets:Array;
35 private var _segmentLengths:Array;
36 private var _totalLength:int;
37 private var _data:ByteArray;
39 public function OggPage(stream:URLStream) {
41 var capture:int = stream.readInt();
42 if(capture != 0x5367674f) {
43 throw new Error("Ogg page does not start with 'OggS': "+capture);
46 _version = stream.readByte()&0xff;
47 var tmp:int = stream.readByte();
49 _continued = (tmp&1)!=0;;
53 // absoluteGranulePosition is really 64 bits
54 _absoluteGranulePosition = stream.readUnsignedInt();
55 stream.readUnsignedInt(); // last 32 bits of _absoluteGranulePosition
57 _streamSerialNumber = stream.readUnsignedInt();
58 _pageSequenceNumber = stream.readUnsignedInt();
59 _pageCheckSum = stream.readUnsignedInt();
61 //trace("_pageSequenceNumber: " + _pageSequenceNumber);
63 var pageSegments:int = stream.readUnsignedByte();
65 //stream.waitFor(pageSegments);
69 _data = new ByteArray();
76 for( i= 0 ; i < pageSegments ; i++ ) {
77 l = stream.readUnsignedByte();
78 _segmentLengths.push( l );
79 _segmentOffsets.push( totalLength );
83 stream.readBytes(_data, 0, totalLength);
86 public function get absoluteGranulePosition():int {
87 return _absoluteGranulePosition;
90 public function get segmentOffsets():Array {
91 return _segmentOffsets;
94 public function get segmentLengths():Array {
95 return _segmentLengths;
98 public function get data():ByteArray {
102 public function get eos():Boolean {
106 public function get bos():Boolean {
110 public function get continued():Boolean {