Esempio n. 1
0
        protected ConfiguratorBase(ContentType contentType, IMediaStreamMetadata mediaStreamMetadata)
        {
            if (null == contentType)
                throw new ArgumentNullException(nameof(contentType));

            _contentType = contentType;
            _mediaStreamMetadata = mediaStreamMetadata;
        }
 protected ConfiguratorBase(ContentType contentType, IMediaStreamMetadata mediaStreamMetadata)
 {
     if ((ContentType)null == contentType)
     {
         throw new ArgumentNullException("contentType");
     }
     this._contentType         = contentType;
     this._mediaStreamMetadata = mediaStreamMetadata;
 }
        public static string GetLanguage(this IConfigurationSource configurationSource)
        {
            IMediaStreamMetadata mediaStreamMetadata = configurationSource.MediaStreamMetadata;

            if (null == mediaStreamMetadata || string.IsNullOrWhiteSpace(mediaStreamMetadata.Language))
            {
                return((string)null);
            }
            return(mediaStreamMetadata.Language);
        }
Esempio n. 4
0
        public PesStreamHandler GetPesHandler(TsStreamType streamType, uint pid, IMediaStreamMetadata mediaStreamMetadata, Action <TsPesPacket> nextHandler)
        {
            PesStreamHandler handler;

            if (this._handlers.TryGetValue(pid, out handler))
            {
                Debug.WriteLine("Found PES {0} stream ({1}) with PID {2}", (object)streamType.Contents, (object)streamType.Description, (object)pid);
            }
            else
            {
                Debug.WriteLine("Create PES {0} stream ({1}) with PID {2}", (object)streamType.Contents, (object)streamType.Description, (object)pid);
                PesStreamParameters parameters = this._parameterFactory();
                parameters.Pid                 = pid;
                parameters.StreamType          = streamType;
                parameters.NextHandler         = nextHandler;
                parameters.MediaStreamMetadata = mediaStreamMetadata;
                handler             = this._handlerFactory.CreateHandler(parameters);
                this._handlers[pid] = handler;
            }
            return(handler);
        }
Esempio n. 5
0
        public PesStreamHandler GetPesHandler(TsStreamType streamType, uint pid, IMediaStreamMetadata mediaStreamMetadata, Action<TsPesPacket> nextHandler)
        {
            PesStreamHandler handler;

            if (_handlers.TryGetValue(pid, out handler))
                Debug.WriteLine("Found PES {0} stream ({1}) with PID {2}", streamType.Contents, streamType.Description, pid);
            else
            {
                Debug.WriteLine("Create PES {0} stream ({1}) with PID {2}", streamType.Contents, streamType.Description, pid);

                var parameters = _parameterFactory();

                parameters.Pid = pid;
                parameters.StreamType = streamType;
                parameters.NextHandler = nextHandler;
                parameters.MediaStreamMetadata = mediaStreamMetadata;

                handler = _handlerFactory.CreateHandler(parameters);

                _handlers[pid] = handler;
            }

            return handler;
        }
Esempio n. 6
0
 protected VideoConfigurator(string fourCc, ContentType contentType, IMediaStreamMetadata mediaStreamMetadata)
     : base(contentType, mediaStreamMetadata)
 {
     VideoFourCc = fourCc;
 }
Esempio n. 7
0
 public Mp3Configurator(IMediaStreamMetadata mediaStreamMetadata, string streamDescription = null)
     : base(ContentTypes.Mp3, mediaStreamMetadata)
 {
     StreamDescription = streamDescription;
 }
 public AacConfigurator(IMediaStreamMetadata mediaStreamMetadata, string streamDescription = null)
     : base(ContentTypes.Aac, mediaStreamMetadata)
 {
     this.StreamDescription = streamDescription;
 }
Esempio n. 9
0
 public H262Configurator(IMediaStreamMetadata mediaStreamMetadata, string streamDescription = null)
     : base("MP2V", ContentTypes.H262, mediaStreamMetadata)
 {
     StreamDescription = streamDescription;
 }
Esempio n. 10
0
 public Mp3Configurator(IMediaStreamMetadata mediaStreamMetadata, string streamDescription = null) : base(ContentTypes.Mp3, mediaStreamMetadata)
 {
     StreamDescription = streamDescription;
 }
 public H262Configurator(IMediaStreamMetadata mediaStreamMetadata, string streamDescription = null)
     : base("MP2V", ContentTypes.H262, mediaStreamMetadata)
 {
     this.StreamDescription = streamDescription;
 }
Esempio n. 12
0
        private void MapProgramStreams()
        {
            this._streamList.Clear();
            foreach (TsProgramMapTable.ProgramMap programMap1 in this._programStreamMap.Values)
            {
                TsProgramMapTable.ProgramMap programMap2;
                if (this._newProgramStreams.TryGetValue(programMap1.Pid, out programMap2))
                {
                    if (!object.Equals((object)programMap2.StreamType, (object)programMap1.StreamType))
                    {
                        this._streamList.Add(programMap1);
                    }
                }
                else
                {
                    this._streamList.Add(programMap1);
                }
            }
            if (this._streamList.Count > 0)
            {
                foreach (TsProgramMapTable.ProgramMap program in this._streamList)
                {
                    Debug.WriteLine("*** TsProgramMapTable.MapProgramStreams(): retiring " + (object)program);
                    this.ClearProgram(program);
                    this._retiredProgramStreams[Tuple.Create <uint, TsStreamType>(program.Pid, program.StreamType)] = program;
                }
                this._streamList.Clear();
            }
            string         programLanguage = Iso639_2Normalization.Normalize(TsDescriptors.GetDefaultLanguage((IEnumerable <TsDescriptor>) this._newProgramDescriptors));
            ProgramStreams programStreams  = new ProgramStreams()
            {
                ProgramNumber = this._programNumber,
                Language      = programLanguage,
                Streams       = (ICollection <IProgramStream>)Enumerable.ToArray <ProgramStreams.ProgramStream>(Enumerable.Select <TsProgramMapTable.ProgramMap, ProgramStreams.ProgramStream>((IEnumerable <TsProgramMapTable.ProgramMap>) this._newProgramStreams.Values, (Func <TsProgramMapTable.ProgramMap, ProgramStreams.ProgramStream>)(s => new ProgramStreams.ProgramStream()
                {
                    Pid        = s.Pid,
                    StreamType = s.StreamType,
                    Language   = Iso639_2Normalization.Normalize(TsDescriptors.GetDefaultLanguage((IEnumerable <TsDescriptor>)s.StreamDescriptors)) ?? programLanguage
                })))
            };

            if (null != this._streamFilter)
            {
                this._streamFilter((IProgramStreams)programStreams);
            }
            foreach (var fAnonymousType1 in Enumerable.Join((IEnumerable <IProgramStream>)programStreams.Streams, (IEnumerable <TsProgramMapTable.ProgramMap>) this._newProgramStreams.Values, (Func <IProgramStream, uint>)(ps => ps.Pid), (Func <TsProgramMapTable.ProgramMap, uint>)(pm => pm.Pid), (ps, pm) =>
            {
                var fAnonymousType1 = new
                {
                    BlockStream = ps.BlockStream,
                    ProgramStream = pm,
                    Language = ps.Language
                };
                return(fAnonymousType1);
            }))
            {
                bool         flag       = !fAnonymousType1.BlockStream;
                uint         index      = fAnonymousType1.ProgramStream.Pid;
                TsStreamType streamType = fAnonymousType1.ProgramStream.StreamType;
                string       language   = fAnonymousType1.Language;
                TsProgramMapTable.ProgramMap program;
                if (this._programStreamMap.TryGetValue(index, out program))
                {
                    if (!object.Equals((object)program.StreamType, (object)streamType) || !flag)
                    {
                        this.ClearProgram(program);
                    }
                    else
                    {
                        continue;
                    }
                }
                if (flag)
                {
                    Tuple <uint, TsStreamType>   key = Tuple.Create <uint, TsStreamType>(index, streamType);
                    TsProgramMapTable.ProgramMap programMap;
                    TsPacketizedElementaryStream pes;
                    if (this._retiredProgramStreams.TryGetValue(key, out programMap))
                    {
                        Debug.WriteLine("*** TsProgramMapTable.MapProgramStreams(): remapping retired program " + (object)programMap);
                        Debug.Assert(this._retiredProgramStreams.Remove(key), "Unable to remove program from retired");
                        pes = programMap.Stream;
                        this._programStreamMap[index] = programMap;
                    }
                    else
                    {
                        IMediaStreamMetadata mediaStreamMetadata = (IMediaStreamMetadata)null;
                        if (null != language)
                        {
                            mediaStreamMetadata = (IMediaStreamMetadata) new MediaStreamMetadata()
                            {
                                Language = language
                            }
                        }
                        ;
                        pes = this._decoder.CreateStream(streamType, index, mediaStreamMetadata);
                        fAnonymousType1.ProgramStream.Stream = pes;
                        this._programStreamMap[index]        = fAnonymousType1.ProgramStream;
                    }
                    if ((int)index == (int)this._pcrPid)
                    {
                        this._foundPcrPid = true;
                        this._decoder.RegisterHandler(index, (Action <TsPacket>)(p =>
                        {
                            this.AddPcr(p);
                            pes.Add(p);
                        }));
                    }
                    else
                    {
                        this._decoder.RegisterHandler(index, new Action <TsPacket>(pes.Add));
                    }
                }
                else if ((int)index == (int)this._pcrPid)
                {
                    this._foundPcrPid = true;
                    this._decoder.RegisterHandler(index, new Action <TsPacket>(this.AddPcr));
                }
            }
            this._newProgramStreams.Clear();
            if (this._foundPcrPid)
            {
                return;
            }
            this._foundPcrPid = true;
            this._decoder.RegisterHandler(this._pcrPid, new Action <TsPacket>(this.AddPcr));
        }
Esempio n. 13
0
        private TsPacketizedElementaryStream CreatePacketizedElementaryStream(TsStreamType streamType, uint pid, IMediaStreamMetadata mediaStreamMetadata)
        {
            IStreamBuffer    streamBuffer = this._bufferingManager.CreateStreamBuffer(streamType);
            MediaStream      mediaStream  = (MediaStream)null;
            PesStreamHandler pesHandler   = this._pesHandlers.GetPesHandler(streamType, pid, mediaStreamMetadata, (Action <TsPesPacket>)(packet =>
            {
                if (null != mediaStream)
                {
                    mediaStream.EnqueuePacket(packet);
                }
                else
                {
                    if (null == packet)
                    {
                        return;
                    }
                    this._tsPesPacketPool.FreePesPacket(packet);
                }
            }));
            TsPacketizedElementaryStream elementaryStream = new TsPacketizedElementaryStream(this._bufferPool, this._tsPesPacketPool, new Action <TsPesPacket>(pesHandler.PacketHandler), streamType, pid);
            IConfigurationSource         configurator     = pesHandler.Configurator;

            if (null != configurator)
            {
                EventHandler configuratorOnConfigurationComplete = (EventHandler)null;
                configuratorOnConfigurationComplete = (EventHandler)((o, e) =>
                {
                    configurator.ConfigurationComplete -= configuratorOnConfigurationComplete;
                    this.CheckConfigurationComplete();
                });
                configurator.ConfigurationComplete += configuratorOnConfigurationComplete;
            }
            mediaStream = new MediaStream(configurator, streamBuffer, new Action <TsPesPacket>(this._tsPesPacketPool.FreePesPacket));
            this.AddMediaStream(mediaStream);
            this._tsTimemestamp.RegisterMediaStream(mediaStream, new Func <TsPesPacket, TimeSpan?>(pesHandler.GetDuration));
            if (null == configurator)
            {
                this.CheckConfigurationComplete();
            }
            return(elementaryStream);
        }
Esempio n. 14
0
 public TsPacketizedElementaryStream CreateStream(TsStreamType streamType, uint pid, IMediaStreamMetadata mediaStreamMetadata)
 {
     return(this._pesStreamFactory(streamType, pid, mediaStreamMetadata));
 }
Esempio n. 15
0
 protected VideoConfigurator(string fourCc, ContentType contentType, IMediaStreamMetadata mediaStreamMetadata)
     : base(contentType, mediaStreamMetadata)
 {
     this.VideoFourCc = fourCc;
 }
Esempio n. 16
0
 public TsPacketizedElementaryStream CreateStream(TsStreamType streamType, uint pid, IMediaStreamMetadata mediaStreamMetadata)
 {
     return _pesStreamFactory(streamType, pid, mediaStreamMetadata);
 }
Esempio n. 17
0
        TsPacketizedElementaryStream CreatePacketizedElementaryStream(TsStreamType streamType, uint pid, IMediaStreamMetadata mediaStreamMetadata)
        {
            var streamBuffer = _bufferingManager.CreateStreamBuffer(streamType);

            MediaStream mediaStream = null;

            var pesStreamHandler = _pesHandlers.GetPesHandler(streamType, pid, mediaStreamMetadata, packet =>
            {
                // ReSharper disable AccessToModifiedClosure
                if (null != mediaStream)
                    mediaStream.EnqueuePacket(packet);
                else if (null != packet)
                    _tsPesPacketPool.FreePesPacket(packet);
                // ReSharper restore AccessToModifiedClosure
            });

            var pes = new TsPacketizedElementaryStream(_bufferPool, _tsPesPacketPool, pesStreamHandler.PacketHandler, streamType, pid);

            var configurator = pesStreamHandler.Configurator;

            if (null != configurator)
            {
                EventHandler configuratorOnConfigurationComplete = null;

                configuratorOnConfigurationComplete = (o, e) =>
                {
                    configurator.ConfigurationComplete -= configuratorOnConfigurationComplete;

                    CheckConfigurationComplete();
                };

                configurator.ConfigurationComplete += configuratorOnConfigurationComplete;
            }

            mediaStream = new MediaStream(configurator, streamBuffer, _tsPesPacketPool.FreePesPacket);

            AddMediaStream(mediaStream);

            _tsTimemestamp.RegisterMediaStream(mediaStream, pesStreamHandler.GetDuration);

            if (null == configurator)
                CheckConfigurationComplete();

            return pes;
        }