/// <summary> /// PutSample /// This is only used when caching is enabled. /// Slices are placed in the destination track in the order they are put. /// FIXME: In case the writes are non-sequential, gaps must be filled with zero size but non-zero duration slices. /// </summary> /// <param name="sample"></param> public virtual void PutSample(Slice sample) { //CacheMgr.SlicesForWriting.Add(sample); // FIXME: we don't need SlicesForWriting anymore because a Slice is now a StreamDataBlockInfo Slice outSlice = new Slice(); outSlice.Copy(sample as StreamDataBlockInfo); outSlice.SliceBytes = new byte[sample.SliceBytes.Length]; sample.SliceBytes.CopyTo(outSlice.SliceBytes, 0); SampleStreamLocations.Add(outSlice); }
private static Slice GetKeyResult(FutureHandle h) { Contract.Requires(h != null); var err = FdbNative.FutureGetKey(h, out ReadOnlySpan <byte> result); #if DEBUG_TRANSACTIONS Debug.WriteLine("FdbTransaction[].GetKeyResult() => err=" + err + ", result=" + result.ToString()); #endif Fdb.DieOnError(err); return(Slice.Copy(result)); }
private static Slice GetValueResultBytes(FutureHandle h) { Contract.Requires(h != null); var err = FdbNative.FutureGetValue(h, out bool present, out ReadOnlySpan <byte> result); #if DEBUG_TRANSACTIONS Debug.WriteLine("FdbTransaction[].TryGetValueResult() => err=" + err + ", present=" + present + ", valueLength=" + result.Count); #endif Fdb.DieOnError(err); return(present ? Slice.Copy(result) : Slice.Nil); }
public override Slice GetSample(StreamDataBlockInfo SampleInfo) { Slice ans = new Slice(); ans.SliceBytes = new byte[SampleInfo.SliceSize]; //ParentStream.EnterMutex(); ISMVTrackFormat ismvFormat = TrackFormat as ISMVTrackFormat; ismvFormat.boxReader.BaseStream.Position = (long)SampleInfo.StreamOffset; // if this GetSample call follows another one, file should be in position ismvFormat.boxReader.BaseStream.Read(ans.SliceBytes, 0, SampleInfo.SliceSize); //ParentStream.LeaveMutex(); ans.Copy(SampleInfo); return (ans); }
public void Test_UUid64_WriteTo() { var original = Uuid64.Parse("01234567-89ABCDEF"); Assume.That(original.ToUInt64(), Is.EqualTo(0x0123456789ABCDEF)); // span with more space var scratch = Slice.Repeat(0xAA, 16); original.WriteTo(scratch); Assert.That(scratch.ToString("X"), Is.EqualTo("01 23 45 67 89 AB CD EF AA AA AA AA AA AA AA AA")); // span with no offset and exact size scratch = Slice.Repeat(0xAA, 16); original.WriteTo(scratch.Substring(0, 8)); Assert.That(scratch.ToString("X"), Is.EqualTo("01 23 45 67 89 AB CD EF AA AA AA AA AA AA AA AA")); // span with offset scratch = Slice.Repeat(0xAA, 16); original.WriteTo(scratch.Substring(4)); Assert.That(scratch.ToString("X"), Is.EqualTo("AA AA AA AA 01 23 45 67 89 AB CD EF AA AA AA AA")); // span with offset and exact size scratch = Slice.Repeat(0xAA, 16); original.WriteTo(scratch.Substring(4, 8)); Assert.That(scratch.ToString("X"), Is.EqualTo("AA AA AA AA 01 23 45 67 89 AB CD EF AA AA AA AA")); scratch = Slice.Repeat(0xAA, 16); original.WriteToUnsafe(scratch.Array, scratch.Offset); Assert.That(scratch.ToString("X"), Is.EqualTo("01 23 45 67 89 AB CD EF AA AA AA AA AA AA AA AA")); unsafe { byte *buf = stackalloc byte[16]; UnsafeHelpers.FillUnsafe(buf, 16, 0xAA); original.WriteToUnsafe(buf + 2); Assert.That(Slice.Copy(buf, 16).ToString("X"), Is.EqualTo("AA AA 01 23 45 67 89 AB CD EF AA AA AA AA AA AA")); } // errors Assert.That(() => original.WriteTo(Slice.Empty), Throws.InstanceOf <ArgumentException>(), "Target buffer is empty"); Assert.That(() => original.WriteTo(null, 8), Throws.InstanceOf <ArgumentException>(), "Target buffer is null"); Assert.That(() => original.WriteTo(null, 0), Throws.InstanceOf <ArgumentException>(), "Target buffer is null"); scratch = Slice.Repeat(0xAA, 16); Assert.That(() => original.WriteTo(scratch.Substring(0, 7)), Throws.InstanceOf <ArgumentException>(), "Target buffer is too small"); Assert.That(scratch.ToString("X"), Is.EqualTo("AA AA AA AA AA AA AA AA AA AA AA AA AA AA AA AA"), "Buffer should not have been overwritten!"); }
public virtual Slice GetSample(StreamDataBlockInfo SampleInfo) { Slice ans = new Slice(); ans.SliceBytes = new byte[SampleInfo.SliceSize]; //ParentStream.EnterMutex(); ParentStream.Stream.Position = (long)SampleInfo.StreamOffset; // if this GetSample call follows another one, file should be in position ParentStream.Stream.Read(ans.SliceBytes, 0, SampleInfo.SliceSize); //ParentStream.LeaveMutex(); ans.Copy(SampleInfo); return(ans); }
public override Slice GetSample(StreamDataBlockInfo SampleInfo) { Slice ans = new Slice(); ans.SliceBytes = new byte[SampleInfo.SliceSize]; //ParentStream.EnterMutex(); ISMVTrackFormat ismvFormat = TrackFormat as ISMVTrackFormat; ismvFormat.boxReader.BaseStream.Position = (long)SampleInfo.StreamOffset; // if this GetSample call follows another one, file should be in position ismvFormat.boxReader.BaseStream.Read(ans.SliceBytes, 0, SampleInfo.SliceSize); //ParentStream.LeaveMutex(); ans.Copy(SampleInfo); return(ans); }
public override Slice GetSample(StreamDataBlockInfo SampleInfo) { int delimiterLength = 0; Slice ans = new Slice(); ans.Copy(SampleInfo); ans.SliceBytes = new byte[SampleInfo.SliceSize]; #if REMOVE_EXTRA_SPS NaluDelimiterBlockInfo blockInfo = SampleInfo as NaluDelimiterBlockInfo; if (blockInfo.AccessUnitDelimiter != null) { delimiterLength = blockInfo.AccessUnitDelimiter.Length + 4; // access unit delimiter length is always 2 ans.SliceBytes[3] = (byte)(delimiterLength - 4); // assume that SliceBytes[0 to 2] are all zeroes, we only need to set LSB blockInfo.AccessUnitDelimiter.CopyTo(ans.SliceBytes, 4); } #endif //ParentStream.Stream.Position = (long)SampleInfo.StreamOffset; // remove empty NALUs (length == 0) // also remove trailing bytes, if any, from each NALU Slice inSlice = SampleInfo as Slice; BinaryReader br = new BinaryReader(new MemoryStream(inSlice.SliceBytes)); //BinaryReader br = new BinaryReader(ParentStream.Stream); int totalSize = SampleInfo.SliceSize - delimiterLength; int offset = delimiterLength; while (totalSize > 4) { ulong naluLen = QBox.BE32(br.ReadUInt32()); if (naluLen > 0UL) { br.BaseStream.Position -= 4; int readLen = (int)naluLen + 4; br.Read(ans.SliceBytes, offset, readLen); offset += readLen; totalSize -= readLen; } else { naluLen = 0; // debugging break point } } return(ans); }
public override Slice GetSample(StreamDataBlockInfo SampleInfo) { Slice ans = new Slice(); ans.Copy(SampleInfo); ans.SliceBytes = new byte[SampleInfo.SliceSize]; // read H264 payload for display and processing -- // for display: ParentStream.Stream.Position = (long)ans.StreamOffset; ParentStream.Stream.Read(ans.SliceBytes, 0, ans.SliceSize); // for processing: // (hand-off the payload processing to a separate thread so this method // can return immediately) #if MV_Centerus H264Sample sample = new H264Sample(_sps, _pps, ans.SliceSize); sample.SampleDoneEvent += CompletionCallback; sample.ParseSample(ans.SliceBytes); // async call samples.Add(sample); #endif return (ans); }
public override Slice GetSample(StreamDataBlockInfo SampleInfo) { Slice ans = new Slice(); ans.Copy(SampleInfo); ans.SliceBytes = new byte[SampleInfo.SliceSize]; // read H264 payload for display and processing -- // for display: ParentStream.Stream.Position = (long)ans.StreamOffset; ParentStream.Stream.Read(ans.SliceBytes, 0, ans.SliceSize); // for processing: // (hand-off the payload processing to a separate thread so this method // can return immediately) #if MV_Centerus H264Sample sample = new H264Sample(_sps, _pps, ans.SliceSize); sample.SampleDoneEvent += CompletionCallback; sample.ParseSample(ans.SliceBytes); // async call samples.Add(sample); #endif return(ans); }
public override Slice GetSample(StreamDataBlockInfo SampleInfo) { int delimiterLength = 0; Slice ans = new Slice(); ans.Copy(SampleInfo); ans.SliceBytes = new byte[SampleInfo.SliceSize]; #if REMOVE_EXTRA_SPS NaluDelimiterBlockInfo blockInfo = SampleInfo as NaluDelimiterBlockInfo; if (blockInfo.AccessUnitDelimiter != null) { delimiterLength = blockInfo.AccessUnitDelimiter.Length + 4; // access unit delimiter length is always 2 ans.SliceBytes[3] = (byte)(delimiterLength - 4); // assume that SliceBytes[0 to 2] are all zeroes, we only need to set LSB blockInfo.AccessUnitDelimiter.CopyTo(ans.SliceBytes, 4); } #endif //ParentStream.Stream.Position = (long)SampleInfo.StreamOffset; // remove empty NALUs (length == 0) // also remove trailing bytes, if any, from each NALU Slice inSlice = SampleInfo as Slice; BinaryReader br = new BinaryReader(new MemoryStream(inSlice.SliceBytes)); //BinaryReader br = new BinaryReader(ParentStream.Stream); int totalSize = SampleInfo.SliceSize - delimiterLength; int offset = delimiterLength; while (totalSize > 4) { ulong naluLen = QBox.BE32(br.ReadUInt32()); if (naluLen > 0UL) { br.BaseStream.Position -= 4; int readLen = (int)naluLen + 4; br.Read(ans.SliceBytes, offset, readLen); offset += readLen; totalSize -= readLen; } else naluLen = 0; // debugging break point } return (ans); }
public override Slice GetSample(StreamDataBlockInfo SampleInfo) { ADTSDataBlockInfo adtsInfo = (ADTSDataBlockInfo)SampleInfo; Slice ans = new Slice(); ans.Copy(SampleInfo); #if ADTS if (adtsInfo.PESandADTSHeaders == null) // ADTS header may be absent, in which case we use the normal base.GetSample { return base.GetSample(SampleInfo); } int headerCount = adtsInfo.PESandADTSHeaders.Length; ans.SliceBytes = new byte[adtsInfo.SliceSize]; // SampleSize has already been incremented by length of PES + ADTS header adtsInfo.PESandADTSHeaders.CopyTo(ans.SliceBytes, 0); //if (ParentStream.Stream.Position != (long)adtsInfo.StreamOffset) // ParentStream.Stream.Position = (long)adtsInfo.StreamOffset; // this if statement for debugging: just to be able to put a breakpoint here BinaryReader reader = new BinaryReader(new MemoryStream(adtsInfo.SliceBytes)); //ParentStream.Stream.Read(ans.SliceBytes, headerCount, adtsInfo.SliceSize - headerCount); reader.Read(ans.SliceBytes, headerCount, adtsInfo.SliceSize - headerCount); #else ans.SliceBytes = adtsInfo.SliceBytes; #endif return (ans); }
public override Slice GetSample(StreamDataBlockInfo SampleInfo) { ADTSDataBlockInfo adtsInfo = (ADTSDataBlockInfo)SampleInfo; Slice ans = new Slice(); ans.Copy(SampleInfo); #if ADTS if (adtsInfo.PESandADTSHeaders == null) // ADTS header may be absent, in which case we use the normal base.GetSample { return(base.GetSample(SampleInfo)); } int headerCount = adtsInfo.PESandADTSHeaders.Length; ans.SliceBytes = new byte[adtsInfo.SliceSize]; // SampleSize has already been incremented by length of PES + ADTS header adtsInfo.PESandADTSHeaders.CopyTo(ans.SliceBytes, 0); //if (ParentStream.Stream.Position != (long)adtsInfo.StreamOffset) // ParentStream.Stream.Position = (long)adtsInfo.StreamOffset; // this if statement for debugging: just to be able to put a breakpoint here BinaryReader reader = new BinaryReader(new MemoryStream(adtsInfo.SliceBytes)); //ParentStream.Stream.Read(ans.SliceBytes, headerCount, adtsInfo.SliceSize - headerCount); reader.Read(ans.SliceBytes, headerCount, adtsInfo.SliceSize - headerCount); #else ans.SliceBytes = adtsInfo.SliceBytes; #endif return(ans); }
public Task <(FdbValueCheckResult Result, Slice Actual)> CheckValueAsync(ReadOnlySpan <byte> key, Slice expected, bool snapshot, CancellationToken ct) { return(FdbFuture.CreateTaskFromHandle( FdbNative.TransactionGet(m_handle, key, snapshot), (h) => { if (TryPeekValueResultBytes(h, out var actual)) { // key exists return !expected.IsNull && expected.Span.SequenceEqual(actual) ? (FdbValueCheckResult.Success, expected) : (FdbValueCheckResult.Failed, Slice.Copy(actual)); }