/// <summary>
        /// Like ConvertJpegDataToMJpegByteArray but with an index at the end
        /// </summary>
        /// <returns></returns>
        public byte[] MakeBuffer(bool writeindex)
        {
            byte[] buffer = null;
            try
            {
                //sort by time, ascending
                _jpegDataIndex.Sort(new IndexEntryComparer());

                FramePacketIndex index = new FramePacketIndex();

                using (MemoryStream memoryStream = new MemoryStream())
                    using (BinaryWriter binaryWriter = new BinaryWriter(memoryStream))
                    {
                        foreach (KeyValuePair <DateTime, byte[]> kvp in _jpegDataIndex)
                        {
                            ///debug
                            _countExported++;

                            index.Add(kvp.Key, (int)memoryStream.Position);

                            if (kvp.Value != null)
                            {
                                binaryWriter.Write(
                                    Encoding.ASCII.GetBytes(
                                        string.Format(DatabaseFramePacketWrapper.FrameHeaderFormat, kvp.Value.Length, kvp.Key)));
                                binaryWriter.Write(kvp.Value);
                            }
                            //memoryStream.WriteTo(binaryWriter.BaseStream);
                        }

                        if (writeindex)
                        {
                            byte[] indexbytes = index.ToBytes();

                            binaryWriter.Seek(0, SeekOrigin.End);
                            binaryWriter.Write(Encoding.ASCII.GetBytes("--videoboundary--"));

                            int indexPosition = (int)(binaryWriter.BaseStream.Position);

                            binaryWriter.Write(indexbytes);

                            binaryWriter.Write(BitConverter.GetBytes(indexPosition));
                        }

                        buffer = memoryStream.ToArray();
                    }
            }
            catch (Exception ee)
            {
                Console.WriteLine(ee);
            }

            return(buffer);
        }
Esempio n. 2
0
        public static FramePacketIndex MakeDummyIndex(DateTime start, int numFrames, int fps)
        {
            FramePacketIndex ind             = new FramePacketIndex();
            double           interframedelay = 1000d / (double)fps;

            for (int i = 0; i < numFrames; i++)
            {
                ind.Add(start.AddMilliseconds(i * fps), i);
            }

            return(ind);
        }
Esempio n. 3
0
        public static FramePacketIndex GetIndexFromBytes(byte[] bytes, int start, int indexlen)
        {
            int entrylength = 8 /* sizeof DateTime */ + sizeof(int);

            FramePacketIndex index = new FramePacketIndex();

            for (int pos = start; pos < bytes.Length && pos < indexlen + start; pos += entrylength)
            {
                if (pos + entrylength > bytes.Length)
                {
                    break;
                }
                DateTime dt = DateTime.FromBinary(BitConverter.ToInt64(bytes, pos));
                int      x  = BitConverter.ToInt32(bytes, pos + 8);
                index.Add(dt, x);
            }

            return(index);
        }