예제 #1
0
        /**
         * Wipes AVC parameter sets ( SPS/PPS ) from the packet ( inplace operation
         * )
         *
         * @param in
         *            AVC frame encoded in Annex B NAL unit format
         * @param spsList
         *            Storage for leading SPS structures ( can be null, then all
         *            leading SPSs are discarded ).
         * @param ppsList
         *            Storage for leading PPS structures ( can be null, then all
         *            leading PPSs are discarded ).
         */
        public static void wipePS(System.IO.MemoryStream inb, List <System.IO.MemoryStream> spsList, List <System.IO.MemoryStream> ppsList)
        {
            System.IO.MemoryStream dup = inb.duplicate();
            while (dup.hasRemaining())
            {
                System.IO.MemoryStream buf = nextNALUnit(dup);
                if (buf == null)
                {
                    break;
                }

                NALUnit nu = NALUnit.read(buf);
                if (nu.type == NALUnitType.PPS)
                {
                    if (ppsList != null)
                    {
                        ppsList.Add(buf);
                    }
                    inb.position(dup.Position);
                }
                else if (nu.type == NALUnitType.SPS)
                {
                    if (spsList != null)
                    {
                        spsList.Add(buf);
                    }
                    inb.position(dup.Position);
                }
                else if (nu.type == NALUnitType.IDR_SLICE || nu.type == NALUnitType.NON_IDR_SLICE)
                {
                    break;
                }
            }
        }
예제 #2
0
        /**
         * Wipes AVC parameter sets ( SPS/PPS ) from the packet
         *
         * @param in
         *            AVC frame encoded in Annex B NAL unit format
         * @param out
         *            Buffer where packet without PS will be put
         * @param spsList
         *            Storage for leading SPS structures ( can be null, then all
         *            leading SPSs are discarded ).
         * @param ppsList
         *            Storage for leading PPS structures ( can be null, then all
         *            leading PPSs are discarded ).
         */
        public static void wipePS(System.IO.MemoryStream inb, System.IO.MemoryStream outb, List <System.IO.MemoryStream> spsList, List <System.IO.MemoryStream> ppsList)
        {
            System.IO.MemoryStream dup = inb.duplicate();
            while (dup.hasRemaining())
            {
                System.IO.MemoryStream buf = nextNALUnit(dup);
                if (buf == null)
                {
                    break;
                }

                NALUnit nu = NALUnit.read(buf.duplicate());
                if (nu.type == NALUnitType.PPS)
                {
                    if (ppsList != null)
                    {
                        ppsList.Add(buf);
                    }
                }
                else if (nu.type == NALUnitType.SPS)
                {
                    if (spsList != null)
                    {
                        spsList.Add(buf);
                    }
                }
                else
                {
                    outb.putInt(1);
                    outb.put(buf);
                }
            }
            outb.flip();
        }
예제 #3
0
        public static PictureParameterSet readPPS(System.IO.MemoryStream data)
        {
            System.IO.MemoryStream input = data.duplicate();
            Utility.unescapeNAL(input);
            PictureParameterSet pps = PictureParameterSet.read(input);

            return(pps);
        }
예제 #4
0
        public static SeqParameterSet readSPS(System.IO.MemoryStream data)
        {
            System.IO.MemoryStream input = data.duplicate();
            Utility.unescapeNAL(input);
            SeqParameterSet sps = SeqParameterSet.read(input);

            return(sps);
        }
예제 #5
0
        /**
         * Encodes AVC frame in ISO BMF format. Takes Annex B format.
         *
         * Scans the packet for each NAL Unit starting with 00 00 00 01 and replaces
         * this 4 byte sequence with 4 byte integer representing this NAL unit
         * length. Removes any leading SPS/PPS structures and collects them into a
         * provided storaae.
         *
         * @param avcFrame
         *            AVC frame encoded in Annex B NAL unit format
         */
        public static void encodeMOVPacket(System.IO.MemoryStream avcFrame)
        {
            System.IO.MemoryStream dup = avcFrame.duplicate();
            System.IO.MemoryStream d1  = avcFrame.duplicate();

            for (int tot = (int)d1.Position; ;)
            {
                System.IO.MemoryStream buf = Utility.nextNALUnit(dup);
                if (buf == null)
                {
                    break;
                }
                d1.position(tot);
                d1.putInt(buf.remaining());
                tot += buf.remaining() + 4;
            }
        }
예제 #6
0
            public SliceHeader run(System.IO.MemoryStream iss, System.IO.MemoryStream os, NALUnit nu, SeqParameterSet sps, PictureParameterSet pps)
            {
                System.IO.MemoryStream nal = os.duplicate();

                Utility.unescapeNAL(iss);

                BitReader   reader = new BitReader(iss);
                SliceHeader sh     = shr.readPart1(reader);

                return(part2(iss, os, nu, sps, pps, nal, reader, sh));
            }
예제 #7
0
            public SliceHeader run(System.IO.MemoryStream iss, System.IO.MemoryStream os, NALUnit nu)
            {
                System.IO.MemoryStream nal = os.duplicate();

                Utility.unescapeNAL(iss);

                BitReader   reader = new BitReader(iss);
                SliceHeader sh     = shr.readPart1(reader);

                PictureParameterSet pp = findPPS(pps, sh.pic_parameter_set_id);

                return(part2(iss, os, nu, findSPS(sps, pp.pic_parameter_set_id), pp, nal, reader, sh));
            }
예제 #8
0
 public static bool idrSlice(System.IO.MemoryStream _data)
 {
     System.IO.MemoryStream data = _data.duplicate();
     System.IO.MemoryStream segment;
     while ((segment = nextNALUnit(data)) != null)
     {
         if (NALUnit.read(segment).type == NALUnitType.IDR_SLICE)
         {
             return(true);
         }
     }
     return(false);
 }
예제 #9
0
        public static List <System.IO.MemoryStream> splitMOVPacket(System.IO.MemoryStream buf, AvcCBox avcC)
        {
            List <System.IO.MemoryStream> result = new List <System.IO.MemoryStream>();
            int nls = avcC.getNalLengthSize();

            System.IO.MemoryStream dup = buf.duplicate();
            while (dup.remaining() >= nls)
            {
                int len = readLen(dup, nls);
                if (len == 0)
                {
                    break;
                }
                result.Add(StreamExtensions.read(dup, len));
            }
            return(result);
        }
예제 #10
0
        private static int[] searchEscapeLocations(System.IO.MemoryStream src)
        {
            List <int> points = new List <int>();

            System.IO.MemoryStream search = src.duplicate();
            short p = search.getShort();

            while (search.hasRemaining())
            {
                byte b = (byte)search.ReadByte();
                if (p == 0 && (b & ~3) == 0)
                {
                    points.Add((int)(search.Position - 1));
                    p = 3;
                }
                p <<= 8;
                p  |= (short)(b & 0xff);
            }
            int[] array = points.ToArray();
            return(array);
        }