Пример #1
0
    void PushFrame_AnnexB(byte[] H264Packet, int FrameNumber)
    {
        if (H264Packet == null)
        {
            return;
        }
        if (PendingInputFrames == null)
        {
            PendingInputFrames = new List <PopH264.FrameInput>();
        }

        //	if the last frame has the same frame number, append the bytes
        //	assuming we just have continuation packets (or say, SPS and PPS bundled together)
        if (PendingInputFrames.Count > 0)
        {
            var LastFrame = PendingInputFrames[PendingInputFrames.Count - 1];
            if (LastFrame.FrameNumber == FrameNumber)
            {
                LastFrame.Bytes = CombineTwoArrays(LastFrame.Bytes, H264Packet);
                PendingInputFrames[PendingInputFrames.Count - 1] = LastFrame;
                return;
            }
        }

        var Frame = new PopH264.FrameInput();

        Frame.Bytes       = H264Packet;
        Frame.FrameNumber = FrameNumber;
        PendingInputFrames.Add(Frame);
    }
Пример #2
0
    public void PushPacket(byte[] Data, long TimeStamp)
    {
        if (PendingPackets == null)
        {
            PendingPackets = new List <PopH264.FrameInput>();
        }

        var NewPacket = new PopH264.FrameInput();

        NewPacket.Bytes       = Data;
        NewPacket.FrameNumber = (int)TimeStamp;
        PendingPackets.Add(NewPacket);
    }
Пример #3
0
    public void PushPacket(byte[] Data, long TimeMs)
    {
        if (PendingInputFrames == null)
        {
            PendingInputFrames = new List <PopH264.FrameInput>();
        }

        //	gr: for UDP fragmented packets, we're generating massive amounts of packets which is causing a big strain
        //		the h264 decoder can now take any old bunch of packets, they don't need to be cut up into frames
        //		we still want to split them when we DO have frame numbers
        //	todo: keep adding to previous frame until we spot a NAL, would be good to have this split into packets unity side
        //		for now; keep one big buffer if the timestamp is zero (ie, no frame info)
        //	todo: even better when we have no meta, one giant buffer with minimal reallocs
        bool AppendToPrev = (TimeMs == 0);

        if (PendingInputFrames.Count == 0)
        {
            AppendToPrev = false;
        }

        if (!AppendToPrev)
        {
            var NewPacket = new PopH264.FrameInput();
            NewPacket.FrameNumber = (int)TimeMs;
            PendingInputFrames.Add(NewPacket);
            if (VerboseDebug)
            {
                Debug.Log("New packet in buffer for time " + TimeMs + " x" + Data.Length);
            }
        }

        //	replace last packet
        var Packet = PendingInputFrames[PendingInputFrames.Count - 1];

        if (Packet.Bytes == null)
        {
            Packet.Bytes = Data;
        }
        else
        {
            if (VerboseDebug)
            {
                Debug.Log("Joining packets x" + Packet.Bytes.Length + " + x" + Data.Length);
            }
            Packet.Bytes = Packet.Bytes.JoinArray(Data);
        }

        //	structs, so we're not modifying in-place, have to override prev
        PendingInputFrames[PendingInputFrames.Count - 1] = Packet;
    }
Пример #4
0
    public void PushEndOfStreamPacket()
    {
        //	manually push a endofstream h264 packet
        if (PendingInputFrames == null)
        {
            PendingInputFrames = new List <PopH264.FrameInput>();
        }

        var NewPacket = new PopH264.FrameInput();

        PendingInputFrames.Add(NewPacket);
        if (!NewPacket.EndOfStream)
        {
            throw new System.Exception("New blank PopH264.FrameInput should be marked as EndOfStream");
        }
    }