Example #1
0
        private ArrayList GetAtoms(BinaryReader br, long endPosition)
        {
            ArrayList result = new ArrayList();
            MpegAtom  ma     = null;

            while (GetNextAtom(out ma, endPosition, null))
            {
                result.Add(ma);
            }
            // TODO: throw exception if we still have a null result
            return(result);
        }
 public MpegSonyPspAtom(MpegAtom uuidAtom)
 {
     // TODO:  Implement a real exception handler for this
     if (MpegAtom.AtomUuidType.SonyPspTag != uuidAtom.UuidType)
     {
         throw new ApplicationException("Atom supplied is not of type SonyPspTag.");
     }
     this.pspTagAtom   = uuidAtom;
     this.atomData     = uuidAtom.Data;
     this.ms           = new MemoryStream(this.atomData);
     this.br           = new BinaryReader(ms);
     this.DataSegments = getDataSegments(ms, 0);
 }
 private void getPspTags(MpegAtom mpegAtom, ref ArrayList pspAtoms)
 {
     if (mpegAtom.UuidType == MpegAtom.AtomUuidType.SonyPspTag)
     {
         pspAtoms.Add(mpegAtom);
     }
     if (mpegAtom.HasChildren())
     {
         foreach (MpegAtom ma in mpegAtom.Children)
         {
             getPspTags(ma, ref pspAtoms);
         }
     }
 }
        private bool getNextDataSegment(out SonyPspTagDataSegment dataSegment, long endPosition, MpegAtom parentAtom)
        {
            // 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 atom data
            SonyPspTagDataSegment ds = new SonyPspTagDataSegment();

            ds.offset = this.br.BaseStream.Position;
            // 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);
        }
Example #5
0
        private bool GetNextAtom(out MpegAtom mpegAtom, long endPosition, MpegAtom parentAtom)
        {
            // return empty object when we reach data endPosition.  If endPosition is set
            // to zero, return empty object if we reach EOF.
            if (this.br.BaseStream.Position == (0 == endPosition ? this.br.BaseStream.Length : endPosition))
            {
                mpegAtom = null;
                return(false);
            }

            // create new atom, fill in the byte offset
            MpegAtom ma = new MpegAtom(null, null, MpegAtom.AtomType.Unknown, this.br.BaseStream.Position, 0);

            // now get the size and type
            ma.Size = BU.ReverseToUInt32(this.br.ReadBytes(4));  // size
            // type
            try
            {
                ma.Type = (MpegAtom.AtomType)BU.ReverseToInt32(this.br.ReadBytes(4));
            }
            catch
            {
                ma.Type = MpegAtom.AtomType.Unknown;
            }

            /*
             * switch (BU.ReverseToInt32(this.br.ReadBytes(4)))  // type
             * {
             *  case 0x6D6F6F76:    ma.Type = MpegAtom.AtomType.moov;     break;   // "moov"
             *  case 0x75756964:    ma.Type = MpegAtom.AtomType.uuid;     break;   // "uuid"
             *  default:            ma.Type = MpegAtom.AtomType.Unknown;  break;   // uninteresting to us
             * }
             */

            // check the type to see if it has data or child atoms that we care about
            switch (ma.Type)
            {
            case MpegAtom.AtomType.moov:
            {
                // now that we've picked up the moov atom, leave br's pointer
                // at the start of the moov data and read in all its child atoms
                ma.Children = GetAtoms(br, ma.Offset + ma.Size);
                // TODO: verify br's pointer is now at end of moov data
                break;
            }

            case MpegAtom.AtomType.trak:
            {
                // now that we've picked up the moov atom, leave br's pointer
                // at the start of the moov data and read in all its child atoms
                ma.Children = GetAtoms(br, ma.Offset + ma.Size);
                // TODO: verify br's pointer is now at end of moov data
                break;
            }

            case MpegAtom.AtomType.uuid:      // may have data we want
            {
                // note current br pointer location
                long dataStartPos = this.br.BaseStream.Position;
                // get the 16 byte UUID value from the start of data
                ma.UuidType = GetUuidType(this.br.ReadBytes(16));
                // return pointer to previous location
                this.br.BaseStream.Position = dataStartPos;
                // if this is a uuid we care about, copy its data into the atom
                if (!(MpegAtom.AtomUuidType.Unknown == ma.UuidType ||
                      MpegAtom.AtomUuidType.None == ma.UuidType))
                {
                    // TODO: throw exception if ma.Size is bigger than an Int32 can hold
                    // read data into ma, then leave br's pointer at the end of this data/atom
                    ma.Data = br.ReadBytes((int)ma.Size - 8);      // atom size, less size/tag bytes
                }
                else
                {
                    // don't care about this uuid, move br's pointer to the end of this atom
                    this.br.BaseStream.Seek(ma.Size - 8, SeekOrigin.Current);
                    break;
                }
                break;
            }

            default:      // unrecognized, don't read any data from this atom
            {
                // just move br's pointer to the end of this atom
                this.br.BaseStream.Seek(ma.Size - 8, SeekOrigin.Current);
                break;
            }
            }

            // all done, verify br's pointer is where it should be

            // return finished atom
            mpegAtom = ma;
            return(true);
        }