Esempio n. 1
0
        public void SDLCallback(Span <byte> buffer)
        {
            while (buffer.Length != 0 && !tok.IsCancellationRequested)
            {
                if (currentOffset != -1)
                {
                    int toCopy = Math.Min(currentBlock.Length - currentOffset, buffer.Length);
                    currentBlock.Buffer.AsSpan().Slice(currentOffset, toCopy).CopyTo(buffer);

                    buffer         = buffer.Slice(toCopy);
                    currentOffset += toCopy;
                }

                if (currentOffset >= currentBlock.Length)
                {
                    currentOffset = -1;
                    currentBlock.Free();
                }

                if (currentOffset == -1 && buffer.Length != 0)
                {
                    try
                    {
                        currentBlock  = samples.Take(tok);
                        currentOffset = 0;
                    }
                    catch (OperationCanceledException)
                    {
                        return;
                    }
                }
            }
        }
Esempio n. 2
0
        override public void SendData(PoolBuffer block, ulong ts)
        {
            Span <byte> data = block;
            var         nal  = FindNalOffset(data);

            while (nal != null)
            {
                InvokeEvent(nal, ts / 1000);
                nal = FindNalOffset(nal);
            }
            block.Free();
        }
Esempio n. 3
0
        public void SendData(PoolBuffer data, UInt64 ts)
        {
            Console.WriteLine($"{filename} - ts: {ts}");
            bin.Write(0xAAAAAAAA);
            bin.Write(sw.ElapsedMilliseconds);
            bin.Write(ts);
            bin.Write(data.Length);
            bin.Write(data.Span);
            sw.Restart();

            data.Free();
        }
Esempio n. 4
0
        public unsafe void SendData(PoolBuffer data, ulong ts)
        {
            byte[] buffer = data.Buffer;
            int    size   = data.Length;

            if (firstTs == -1)
                firstTs = (long)ts;

            fixed(byte *nal_data = buffer)
            {
                AVPacket pkt;

                av_init_packet(&pkt);

                pkt.data = nal_data;
                pkt.size = size;
                pkt.pts  = pkt.dts = (long)(((long)ts - firstTs) / 1E+6 * timebase_den);

                int res = 0;

send_again:
                lock (ctx.CodecLock)
                    res = avcodec_send_packet(ctx.CodecCtx, &pkt);

                if (res == AVERROR(EAGAIN))
                {
                    if (!tok.IsCancellationRequested)
                    {
                        // This never seems to happen
                        goto send_again;
                    }
                }
                else if (res != 0)
                {
                    Console.WriteLine($"avcodec_send_packet {res}");
                }
            }

            data.Free();
        }
Esempio n. 5
0
 public override void SendData(PoolBuffer block, ulong ts)
 {
     InvokeEvent(block, ts / 1000);
     block.Free();
 }
Esempio n. 6
0
 public void SendData(PoolBuffer block, ulong ts)
 {
     SendData(block.Buffer, block.Length, ts);
     block.Free();
 }