예제 #1
0
        int track_PrepareMediaHeaders(int sliceIndex)
        {
            StreamDataBlockInfo lastData = null;

            if (sliceIndex == 0)
            {
                // hypothesize a BlockSize (we don't know it at this point)
                BlockSize = 8;
                return(0);
            }
            else if (CurrentSliceList.Count >= BlockSize)
            {
                if (BlockSize == 8)
                {
                    CalculateBlockSizeFromInitialSlices();
                    if (BlockSize > 8) // if less than or equal to 8, process it
                    {
                        return(0);
                    }
                }
                int i = CurrentSliceList.Count - 1;
                if (CurrentSliceList[i].SliceType == SliceType.IFrame)
                {
                    lastData = CurrentSliceList[i];
                    CurrentSliceList.RemoveAt(i);
                }
                else if (CurrentSliceList[i].SliceType == SliceType.DFrame)
                {
                    return(0); // extend current block until next IFrame is found
                }
            }
            else
            {
                return(0); // don't set lists (see below) for any other values of sliceIndex
            }
            ulong localCurrMDatOffset = track.ParentStream.CurrMDatOffset;

            track.TrackFormat.PrepareSampleWriting(CurrentSliceList, ref localCurrMDatOffset);
            track.ParentStream.CurrMDatOffset = localCurrMDatOffset;
            track.ParentStream.WriteSamples(CurrentSliceList.Cast <Slice>(), track.Codec.CodecType); // second param is ineffective (unnecessary)

            // when writing to destination file, we only need and use one cache buffer
            cache[readCache].SampleStreamLocations = new List <StreamDataBlockInfo>();
            // last IFrame should be part of next block
            if (lastData != null)
            {
                CurrentSliceList.Add(lastData);
                return(sliceIndex);
            }

            return(sliceIndex + 1); // we only get here if sliceIndex == 0 or slice is not video
        }
예제 #2
0
        /// <summary>
        /// UpdateRelevancyScores (with ulong time parameter)
        /// When this method is called, we have already found the requested slice, and
        /// readCache is now set to the correct buf.
        /// </summary>
        /// <param name="sliceTime"></param>
        void UpdateRelevancyScores(ulong sliceTime)
        {
            if (sliceTime == 0UL)
            {
                UpdateRelevancyScores(0);
                return;
            }

            // first, look for the slice in order to get its index
            StreamDataBlockInfo sliceInfo = CurrentSliceList[0];                 // get any slice
            uint halfOfDuration           = (uint)(sliceInfo.SliceDuration / 2); // shift to the right by one

            sliceInfo = CurrentSliceList.First(
                s => s.TimeStampNew.HasValue && ((s.TimeStampNew.Value > sliceTime - halfOfDuration) && (s.TimeStampNew.Value < sliceTime + halfOfDuration)));

            UpdateRelevancyScores(sliceInfo.index);
        }