Exemplo n.º 1
0
        /// <summary>
        /// Add a new ad notification point
        /// </summary>
        /// <param name="point">the point to</param>
        public void Add(AdInsertionPoint point)
        {
            lock (m_adInsertionPoints)
            {
                m_adInsertionPoints.Add(point);
                m_isChanged = true;
            }

            Tracer.Trace(TraceChannel.AdsInsert, "Added ad point {0}", point.Timestamp);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Retrieve the list of insertion points as an array
        /// </summary>
        /// <returns>an array of the stored insertion points</returns>
        public AdInsertionPoint[] ToArray()
        {
            AdInsertionPoint[] ads;

            lock (m_adInsertionPoints)
            {
                ads = new AdInsertionPoint[m_adInsertionPoints.Count];
                for (int i = 0; i < m_adInsertionPoints.Count; ++i)
                {
                    ads[i] = m_adInsertionPoints[i];
                }
            }

            return ads;
        }
 /// <summary>
 /// Called by an application ahead of time to make media source to free download bandwidth for ads content
 /// </summary>
 /// <param name="adInsertPoints">the points to pause at</param>
 public void AdPauseExpectedAt(AdInsertionPoint[] adInsertPoints)
 {
     foreach (AdInsertionPoint point in adInsertPoints)
     {
         this.m_adInsertionPoints.Add(point);
     }
 }
Exemplo n.º 4
0
 /// <summary>
 /// This function is used to intialize a heuristics module. It must be implemented by all derived classes.
 /// </summary>
 /// <param name="manifestInfo">The manifest for the stream we are reading</param>
 /// <param name="playbackInfo">The playback info for the media element</param>
 /// <param name="adInsertPoints">Optional expected points for advertising. Can be null</param>
 public abstract void Initialize(ManifestInfo manifestInfo, PlaybackInfo playbackInfo, AdInsertionPoint[] adInsertPoints);
Exemplo n.º 5
0
        /// <summary>
        /// Implements Heuristics.Initialize(). Called to initialize this heuristics module with
        /// the given manifest file and optional adverting insertion points
        /// </summary>
        /// <param name="manifestInfo">The manifest of the stream we are using</param>
        /// <param name="playbackInfo">The playback info for the media element</param>
        /// <param name="adInsertPoints">Optional ad insertion points. Can be null</param>
        public override void Initialize(ManifestInfo manifestInfo, PlaybackInfo playbackInfo, AdInsertionPoint[] adInsertPoints)
        {
            Tracer.Trace(TraceChannel.MSS, "MediaSource instance {0}, sessionID: {1}", InstanceId.ToString("B"), sm_sessionId.ToString("B"));

            // Store our manifest info
            m_manifestInfo = manifestInfo;
            m_playbackInfo = playbackInfo;

            // We only support 1 audio and 1 video stream right now, so let's throw an exception
            // if someone tries to create us with more than that
            int numStreams = m_manifestInfo.NumberOfStreams;
            if (numStreams > 2)
            {
                throw new AdaptiveStreamingException("We only support 1 audio and 1 video stream at this time");
            }

            // Copy the add insertion points over
            m_adInsertPoints = new AdInsertionPoints();
            foreach (AdInsertionPoint ad in adInsertPoints)
            {
                m_adInsertPoints.Add(ad);
            }

            // Allocate some internal variables
            m_heuristicsMode = new HeuristicsMode[numStreams];
            m_fixedBitrateIndex = new int[numStreams];
            m_mediaStreamTypes = new MediaStreamType[numStreams];
            m_maxDownloadsPerStream = new int[numStreams];
            m_numDownloadsInProgress = new int[numStreams];
            m_nextChunkId = new int[numStreams];

            // Go through each stream in our manifest and do per-stream configuration
            int numVideoStreams = 0, numAudioStreams = 0;
            for (int i = 0; i < numStreams; i++)
            {
                StreamInfo streamInfo = m_manifestInfo.GetStreamInfoForStream(i);

                // Initialize some of the arrays we just created
                m_mediaStreamTypes[i] = streamInfo.MediaType;
                m_fixedBitrateIndex[i] = 0;
                m_maxDownloadsPerStream[i] = GlobalMaxDownloadsPerStream;
                m_numDownloadsInProgress[i] = 0;
                m_nextChunkId[i] = 0;

                // If we are a video stream, then we need to set our heuristics mode
                // to Full
                switch (streamInfo.MediaType)
                {
                    case MediaStreamType.Audio:
                        m_heuristicsMode[i] = HeuristicsMode.FixedRate;
                        ++numAudioStreams;
                        break;
                    case MediaStreamType.Video:
                        m_heuristicsMode[i] = HeuristicsMode.Full;
                        ++numVideoStreams;
                        break;
                    default:
                        throw new AdaptiveStreamingException(Errors.NonVideoOrAudioStreamsNotSupportedError);
                }

                // Configure this stream
                InitializeHeuristicsForStream(
                    streamInfo.StreamId,
                    (double)m_maxBufferSizeInMs / 1000,
                    m_manifestInfo.GetStreamInfoForStream(i).Bitrates.Count,
                    m_manifestInfo.GetStreamInfoForStream(i).GetBitrateArray());
            }

            // Make sure we found only 1 video and 1 audio stream
            if (numVideoStreams != 1)
            {
                throw new AdaptiveStreamingException(Errors.IncorrectNumberOfVideoStreamsError);
            }

            // Start scheduling our downloads
            ScheduleDownloads();
        }