Exemple #1
0
        private bool getNextDataSegment(out MsvTagDataSegment dataSegment, long endPosition, MpegBox parentBox)
        {
            // return empty object when we reach data endPosition.  If endPosition is set
            // to zero, return empty object if we reach end of data.
            if (this.br.BaseStream.Position == (0 == endPosition ? this.br.BaseStream.Length : endPosition))
            {
                dataSegment = null;
                return(false);
            }

            // create new segment and note its offset in the box data
            MsvTagDataSegment ds = new MsvTagDataSegment();

            ds.offset = this.br.BaseStream.Position;
            // offset in file is equal to the start of the containing box, plus eight bytes for
            // box's size and uuid markers, plus segment offset from start of box data
            ds.absoluteOffset = msvTagBox.AbsoluteOffset() + 8 + ds.offset;
            // now get the segment header info and data
            ds.size            = BU.ReverseToUInt16(this.br.ReadBytes(2)); // size
            ds.type            = BU.ReverseToUInt32(this.br.ReadBytes(4));
            ds.language        = BU.ReverseToUInt16(this.br.ReadBytes(2));
            ds.unknownProperty = BU.ReverseToUInt16(this.br.ReadBytes(2));
            if (0 < ds.size - 10)                                 // if there is any data left after the header, get data
            {
                ds.segmentData = this.br.ReadBytes(ds.size - 10); // data
            }
            // all done, verify br's pointer is where it should be

            // return finished segment
            dataSegment = ds;
            return(true);
        }
Exemple #2
0
        private ArrayList getDataSegments(MemoryStream ms, long endPosition)
        {
            // read and validate UUID value
            // TODO:  Implement a real exception handler for this
            if ("55534D5421D24FCEBB88695CFAC9C740" !=
                BU.ByteArrayToStringHex(br.ReadBytes(16)))
            {
                throw new MsvDecoderException("Box data supplied is not of type MsvTag.");
            }
            // read box's internal data size
            this.internalSize = BU.ReverseToUInt32(br.ReadBytes(4));
            // validate next marker in header
            // TODO:  Implement a real exception handler for this
            if ("4D544454" != BU.ByteArrayToStringHex(br.ReadBytes(4)))
            {
                throw new MsvDecoderException("Box data supplied is not of type MsvTag.");
            }
            // read segment count
            this.segmentCount = BU.ReverseToUInt16(br.ReadBytes(2));
            // we should now be at the start of the first segment
            ArrayList         result = new ArrayList();
            MsvTagDataSegment ds     = null;

            while (getNextDataSegment(out ds, endPosition, null))
            {
                result.Add(ds);
            }
            // TODO: throw exception if we still have a null result
            //       or if arraylist item count != this.segmentCount
            return(result);
        }