public override void decode(MP4InputStream inStream)
        {
            base.decode(inStream);

            graphicsMode = inStream.readBytes(2);
            // 6 byte RGB color
            var c = new int[3];

            for (int i = 0; i < 3; i++)
            {
                c[i] = (inStream.read() & 0xFF) | ((inStream.read() << 8) & 0xFF);
            }
            color = Color.FromArgb(c[0], c[1], c[2]);
        }
Пример #2
0
        public override void decode(MP4InputStream inStream)
        {
            base.decode(inStream);

            dataType = forInt(flags);

            inStream.skipBytes(4); // padding?

            data = new byte[(int)getLeft(inStream)];
            inStream.read(data, 0, data.Length);
        }
        public static Descriptor createDescriptor(MP4InputStream inStream)
        {
            //read tag and size
            int type = inStream.read();
            int read = 1;
            int size = 0;
            int b    = 0;

            do
            {
                b      = inStream.read();
                size <<= 7;
                size  |= b & 0x7f;
                read++;
            }while ((b & 0x80) == 0x80);

            //create descriptor
            Descriptor desc = forTag(type);

            desc.type  = type;
            desc.size  = size;
            desc.start = inStream.getOffset();

            //decode
            desc.decode(inStream);
            //skip remaining bytes
            long remaining = size - (inStream.getOffset() - desc.start);

            if (remaining > 0)
            {
                Logger.LogBoxes(string.Format("Descriptor: bytes left: {0:N0}, offset: {1:N0}", remaining, inStream.getOffset()));
                inStream.skipBytes(remaining);
            }
            desc.size += read; //include type and size fields

            return(desc);
        }
        /// <summary>
        /// Reads the next frame from this track. If it contains no more frames to read, null is returned.
        /// </summary>
        /// <returns>the next frame or null if there are no more frames to read</returns>
        public Frame readNextFrame()
        {
            Frame frame = null;

            if (hasMoreFrames())
            {
                frame = frames[currentFrame];

                long diff = frame.getOffset() - inStream.getOffset();
                if (diff > 0)
                {
                    inStream.skipBytes(diff);
                }
                else if (diff < 0)
                {
                    if (inStream.hasRandomAccess())
                    {
                        inStream.seek(frame.getOffset());
                    }
                    else
                    {
                        Logger.LogServe(string.Format("MP4 API: readNextFrame failed: frame {0:N0} already skipped, offset:{1:N0}, stream:{2:N0}", currentFrame, frame.getOffset(), inStream.getOffset()));
                        throw new IOException("frame already skipped and no random access");
                    }
                }

                var b = new byte[(int)frame.getSize()];
                try
                {
                    inStream.read(b, 0, b.Length);
                }
                catch (Exception)
                {
                    Logger.LogServe(string.Format("MP4 API: readNextFrame failed: tried to read {0:N0} bytes at {1:N0}", frame.getSize(), inStream.getOffset()));
                    throw;
                }
                frame.setData(b);
                currentFrame++;
            }
            return(frame);
        }