Пример #1
0
        bool TryGetSegment(int index, int segmentNumber, ref Segment retrievedSegment, ref SegmentAvailabilities segAvailability)
        {
            if (store.HasSegment(index, segmentNumber))
            {
                SendDebugMessage("Broker] Segment " + index + "-" + segmentNumber.ToString() + " is available in store - retrieving");
                bool foo = store.TryGetSegmentByNumber(index, segmentNumber, ref retrievedSegment); // shouldn't block, as it's in the store
                segAvailability = SegmentAvailabilities.IsAvailable;
                return(true);
            }


            // Is there a runner
            if (Runner == null)
            {
                SendDebugMessage("Broker] require seek (runner stopped)");
                segAvailability = SegmentAvailabilities.RequiresSeek;  // require, in fact!
                return(false);
            }


            // Store does not have segment.  Is it coming soon?
            int difference2 = (index - Runner.AwaitingFileIndex);
            int difference  = (segmentNumber - Runner.AwaitingSegmentNumber);

            if (difference2 < 0 || (difference2 == 0 && difference < 0)) // requested segment is in past
            {
                SendDebugMessage("Broker] Seg " + index + "-" + segmentNumber.ToString() + " is in the past - require seek.");
                segAvailability = SegmentAvailabilities.RequiresSeek;
                return(false);
            }
//            if (difference >= NUMBER_OF_SEGMENTS_CONSIDERED_COMING_SOON)
            if (Request.NewLiveTV && (difference2 >= NUMBER_OF_SEGMENTS_CONSIDERED_COMING_SOON_NEWLIVETV))
            {
                SendDebugMessage("Broker] Seg " + index + "-" + segmentNumber.ToString() + " is a huge " + difference2 + " indexfiles away from arrival - require seek.");
                segAvailability = SegmentAvailabilities.RequiresSeek;
                return(false);
            }
            else if ((!Request.LiveTV && !Request.NewLiveTV && (difference >= NUMBER_OF_SEGMENTS_CONSIDERED_COMING_SOON)) ||
                     (Request.LiveTV && Request.NewLiveTV && (difference >= NUMBER_OF_SEGMENTS_CONSIDERED_COMING_SOON_LIVETV)))
            {
                SendDebugMessage("Broker] Seg " + index + "-" + segmentNumber.ToString() + " is a huge " + difference + " segs away from arrival - require seek.");
                segAvailability = SegmentAvailabilities.RequiresSeek;
                return(false);
            }

            // WAIT FOR A SEGMENT **************************************************************
            SendDebugMessage("Broker] Seg " + index + "-" + segmentNumber.ToString() + " is only " + difference2 + " indexfiles away from arrival - requesting from store, which will block...");

            bool didGet = (store.TryGetSegmentByNumber(index, segmentNumber, ref retrievedSegment));

            segAvailability = didGet ? SegmentAvailabilities.IsAvailable : SegmentAvailabilities.Cancelled;
            //segAvailability = segmentNumber == 99999 ? SegmentAvailabilities.IsAvailable : segAvailability;  //NewLiveTV hack, s.t. non available waitsscreen gets displayed
            //return (didGet || segmentNumber==99999);//99999 is newlivtv hack
            return(didGet);
        }
Пример #2
0
        bool TryGetSegment(int segmentNumber, ref Segment retrievedSegment, ref SegmentAvailabilities segAvailability)
        {
            if (store.HasSegment(segmentNumber))
            {
                SendDebugMessage("Broker] Segment " + segmentNumber.ToString() + " is available in store - retrieving");
                bool foo = store.TryGetSegmentByNumber(segmentNumber, ref retrievedSegment); // shouldn't block, as it's in the store
                segAvailability = SegmentAvailabilities.IsAvailable;
                return(true);
            }


            // Is there a runner
            if (Runner == null)
            {
                SendDebugMessage("Broker] require seek (runner stopped)");
                segAvailability = SegmentAvailabilities.RequiresSeek;  // require, in fact!
                return(false);
            }


            // Store does not have segment.  Is it coming soon?
            int difference = (segmentNumber - Runner.AwaitingSegmentNumber);

            if (difference < 0) // requested segment is in past
            {
                SendDebugMessage("Broker] Seg " + segmentNumber.ToString() + " is in the past - require seek.");
                segAvailability = SegmentAvailabilities.RequiresSeek;
                return(false);
            }
            if (difference >= NUMBER_OF_SEGMENTS_CONSIDERED_COMING_SOON)
            {
                SendDebugMessage("Broker] Seg " + segmentNumber.ToString() + " is a huge " + difference + " segs away from arrival - require seek.");
                segAvailability = SegmentAvailabilities.RequiresSeek;
                return(false);
            }

            // WAIT FOR A SEGMENT **************************************************************
            SendDebugMessage("Broker] Seg " + segmentNumber.ToString() + " is only " + difference + " away from arrival - requesting from store, which will block...");

            bool didGet = (store.TryGetSegmentByNumber(segmentNumber, ref retrievedSegment));

            segAvailability = didGet ? SegmentAvailabilities.IsAvailable : SegmentAvailabilities.Cancelled;
            return(didGet);
        }