/// <summary>
        /// Default constructor
        /// </summary>
        /// <param name="msd"></param>
        public H264Parser(SampleBuffer outputBuffer, IContainerMetadata metadata, HLSStream hlsStream)
            : base(outputBuffer, hlsStream)
        {
            string[] resolution = null;

            string s;
            if (metadata.Attributes != null &&
                metadata.Attributes.TryGetValue(HLSPlaylistMetaKeys.Resolution, out s))
            {
                string[] components = s.Split(new char[] { 'x' });
                if (components != null && components.Length == 2)
                    resolution = components;
            }

            if (resolution == null)
            {
                HLSTrace.WriteLine("Missing 'Resolution' tag in HLS MetaKeys, defaulting to the maximum supported resolution of 1280x720.");
                resolution = new string[] { "1280", "720" };
            }

            Dictionary<MediaStreamAttributeKeys, string> streamAttributes = new Dictionary<MediaStreamAttributeKeys, string>();
            streamAttributes[MediaStreamAttributeKeys.VideoFourCC] = "H264";
            streamAttributes[MediaStreamAttributeKeys.Width] = resolution[0];
            streamAttributes[MediaStreamAttributeKeys.Height] = resolution[1];
            Description = new MediaStreamDescription(MediaStreamType.Video, streamAttributes);
        }
        private void OnAllSubPlayListLoaded()
        {
            // DoCloseMedia may happend before the AllSubPlayListEvent event fired.
            if (_playlist == null || _program == null) return;

            uint maxBitrate = 0;
            _playback.AllSubPlayListEvent -= OnAllSubPlayListLoaded;
            foreach (HLSVariant hlsVariant in _program.Variants)
            {
                hlsVariant.Playback = null;
                if (hlsVariant.Bitrate > maxBitrate)
                {
                    maxBitrate = hlsVariant.Bitrate;
                }
            }

            //
            // Allocate video buffer based on max bitrate and buffer length plus 10 extra seconds of pending chunk progressive
            // downloading / parsing.
            // Minimal initial buffer size is 5MB (corresponding 1Mb bitrate) in case playlist returns unreasonable low bitrate.
            // Max initial buffer size is 50MB (corrsponding 10Mb bitrate) in case playlist returns unsupported high bitrate.
            //
            int initialVideoBufferSize = Math.Max((int)((_bufferLength.TotalSeconds + 10) * maxBitrate / 8), 5 * 1024 * 1024);
            initialVideoBufferSize = Math.Min(initialVideoBufferSize, 50 * 1024 * 1024);
            _videoBuffer = new SampleBuffer(initialVideoBufferSize);
            // Allocate audio buffer based on 256Kb audio bitrate and buffer length plus 10 extra seconds of pending chunk progressive
            // downloading / parsing.
            _audioBuffer = new SampleBuffer((int)((_bufferLength.TotalSeconds + 10) * 256 * 1024) / 8);

            PlayListOverrideInfo overrideInfo = new PlayListOverrideInfo();
            overrideInfo.reason = PlayListOverrideReason.ePlaylistLoaded;
            overrideInfo.position = TimeSpan.Zero;
            OverridePlaylistIfNecessary(overrideInfo);

            if (_playback.Program == null)
                _playback.Program = _program;

            if (_playback.BeginGetNextStream(new AsyncCallback(AsyncStreamCallback), _playback) == null)
            {
                RaiseError("unable to open stream");
            }
        }
 /// <summary>
 /// Default constructor
 /// </summary>
 /// <param name="msd"></param>
 public ADTSParser(SampleBuffer outputBuffer, HLSStream hlsStream)
     : base(outputBuffer, hlsStream)
 {
     _bitstream = new BitstreamReader();
 }
Example #4
0
        /// <summary>
        /// Common construction code for all constructors
        /// </summary>
        /// <param name="stream"></param>
        /// <param name="audioBuffer"></param>
        /// <param name="videoBuffer"></param>
        private void CommonConstruct(EncryptedStream stream, SampleBuffer audioBuffer,
                                    SampleBuffer videoBuffer, IContainerMetadata metadata, uint bitrate,
                                    BandwidthHistory BWHistory)
        {
            if (stream == null)
                throw new ArgumentNullException("stream");
            _stream = stream;
            _metadata = metadata;
            _audioBuffer = audioBuffer;
            _audioBuffer.ResetOnSegmentStart();
            _videoBuffer = videoBuffer;
            _videoBuffer.ResetOnSegmentStart();

            _previousReadEndTime = stream.RequestStartTime;

            _bitrate = bitrate;

            _downloadChunkBuffer = new byte[_downloadChunkSize];
            _TSPacketBuffer = new byte[TSPacketSize];

            _BWHistory = BWHistory;
        }
 /// <summary>
 /// Handler for Close command
 /// </summary>
 private void DoCloseMedia()
 {
     lock (_workQueueThreadLock)
     {
         HLSTrace.WriteLine("DoCloseMedia");
         _bwHistory.Close();
         _playback.AbortStreamDownloads();
         _isWorkQueueThreadStarted = false;
         _workQueueThread = null;
         _workQueue = null;
         _audioBuffer = null;
         _videoBuffer = null;
         _playlist = null;
         _playback = null;
         _program = null;
         if (_demux != null)
         {
             _demux.Dispose();
             _demux = null;
         }
     }
 }
Example #6
0
 /// <summary>
 ///  Default constructor.
 /// </summary>
 /// <param name="stream"></param>
 /// <param name="audioBuffer"></param>
 /// <param name="videoBuffer"></param>
 public TSDemux(EncryptedStream stream, SampleBuffer audioBuffer,
                SampleBuffer videoBuffer, IContainerMetadata metadata, uint bitrate, 
                BandwidthHistory BWHistory)
 {
     CommonConstruct(stream, audioBuffer, videoBuffer, metadata, bitrate, BWHistory);
 }
 /// <summary>
 /// Default constructor.
 /// </summary>
 /// <param name="msd"></param>
 public MediaFormatParser(SampleBuffer outputBuffer, HLSStream hlsStream)
 {
     _outputBuffer = outputBuffer;
     _byteBuffer = new byte[InitialBufferSize];
     _hlsStream = hlsStream;
 }
Example #8
0
 /// <summary>
 /// Default constructor
 /// </summary>
 /// <param name="msd"></param>
 public NullParser(SampleBuffer outputBuffer)
     : base(outputBuffer, null)
 {
 }
 public void Reset(long timestamp, long duration, uint bitrate, HLSStream hlsStream, int dataSize, MediaStreamDescription msd, SampleBuffer buffer)
 {
     _timestamp = timestamp;
     _duration = duration;
     _bitrate = bitrate;
     _hlsStream = hlsStream;
     _msd = msd;
     _isKeyFrame = false;
     _adjustedTimeStamp = 0;
     if (dataSize != -1 && null != buffer)
     {
         _dataItem = buffer.FIFOMemoryPool.Alloc(dataSize);
     }
     else
     {
         _dataItem = null;
     }
     _sampleBuffer = buffer;
 }
Example #10
0
        /// <summary>
        /// Default constructor
        /// </summary>
        /// <param name="timestamp"></param>
        /// <param name="timestamp">Sample timestamp in HNS units</param>
        /// <param name="duration">Sample duartion in HNS units</param>
        /// <param name="bitrate">Bitrate of the stream that this sample was created from</param>
        public Sample(long timestamp, long duration, uint bitrate, HLSStream hlsStream, int dataSize, MediaStreamDescription msd, SampleBuffer buffer)
        {
            if (null == _keyFrameAttr)
            {
                _keyFrameAttr = new Dictionary<MediaSampleAttributeKeys,string>();
                _keyFrameAttr[MediaSampleAttributeKeys.KeyFrameFlag] = Boolean.TrueString;
            }

            if (null == _nonKeyFrameAttr)
            {
                _nonKeyFrameAttr = new Dictionary<MediaSampleAttributeKeys,string>();
                _nonKeyFrameAttr[MediaSampleAttributeKeys.KeyFrameFlag] = Boolean.FalseString;
            }

            Reset(timestamp, duration, bitrate, hlsStream, dataSize, msd, buffer);
        }