Beispiel #1
0
        private MediaStreamSource GetMediaStreamSource(IMediaStreamDescriptor videoStreamDescriptor)
        {
            var mediaStreamSource = new MediaStreamSource(videoStreamDescriptor)
            {
                BufferTime = TimeSpan.FromSeconds(0)
            };

            mediaStreamSource.Starting        += OnStart;
            mediaStreamSource.SampleRequested += OnSampleRequested;

            return(mediaStreamSource);
        }
Beispiel #2
0
        private void CreateMediaStream(IMediaStreamDescriptor descriptor)
        {
            //			Close();

            if (_MediaStreamSource != null)
            {
                throw new Exception();
            }

            _MediaStreamSource            = new MediaStreamSource(descriptor);
            _MediaStreamSource.BufferTime = new TimeSpan(2 * 10000000);
            _MediaStreamSource.Duration   = TimeSpan.MaxValue;

            _MediaStreamSource.Starting        += OnStarting;
            _MediaStreamSource.SampleRequested += OnSampleRequested;

            Debug.WriteLine($"RTMP : {ClientId} media stream created.");
        }
        async void OpenFlvFile(StorageFile file)
        {
            long    offset       = 0;
            FlvFile flvFile      = null;
            var     randomStream = await file.OpenAsync(Windows.Storage.FileAccessMode.Read);

            mediaStreamFileSource = flvFile = new FlvFile(randomStream.AsStream(), ref offset)
            {
                Path = file.Path
            };

            //에러 체크 (익셉션 발생)
            if (ValidateCodecForFlv(flvFile))
            {
                //미디어 타입 설정
                CurrentMediaInfo.MediaType = MediaType.FlashVideo;

                //H264 NalUnit Header 생성
                SetNalUnitParameterSets(flvFile.FlvFileBody.VideoInfoFlvTag);
                //비디오/오디오 파일의 기술설명자 생성
                IMediaStreamDescriptor videoDescriptor = GetFlvVideoDescriptor(flvFile.FlvFileBody.ScriptTageList);
                IMediaStreamDescriptor audioDescriptor = GetFlvAudioDescriptor(flvFile.FlvFileBody.AudioInfoFlvTag);

                //미디어 스트림 소스 생성
                MediaStreamSource flvStreamSource = new MediaStreamSource(videoDescriptor, audioDescriptor);

                //기본 속성 설정
                var value = flvFile.FlvFileBody.ScriptTageList.FirstOrDefault().ScriptData.Values[1].Value;
                flvStreamSource.Duration = TimeSpan.FromSeconds(double.Parse(((value as ScriptObject)["duration"]).ToString(), Settings.NumberFormat));
                flvStreamSource.CanSeek  = true;

                //이벤트 등록
                flvStreamSource.VideoProperties.Title = CurrentMediaInfo.Title;
                flvStreamSource.Starting        += flvStreamSource_Starting;
                flvStreamSource.SampleRequested += flvStreamSource_SampleRequested;
                flvStreamSource.Closed          += flvStreamSource_Closed;

                //플레이어 기본 설정 및 스트림 전달
                this.SetMediaStreamSource(flvStreamSource);

                //FVL 탐색용 데이터 준비
                PrepareSeekForFlv(flvFile);
            }
        }
Beispiel #4
0
 public FrameBufferData GetFrameData(IMediaStreamDescriptor descriptor)
 {
     if (descriptor is VideoStreamDescriptor)
     {
         if (VideoFrameQueue.Count == 0)
         {
             ReadBlock(MediaTypes.Video);
         }
         return(VideoFrameQueue.Dequeue());
     }
     else if (descriptor is AudioStreamDescriptor)
     {
         if (AudioFrameQueue.Count == 0)
         {
             ReadBlock(MediaTypes.Audio);
         }
         return(AudioFrameQueue.Dequeue());
     }
     return(FrameBufferData.Empty);
 }
Beispiel #5
0
        public WinRtStreamState(string name, ContentType contentType, IStreamSource streamSource, IMediaStreamDescriptor descriptor)
        {
            if (null == name)
                throw new ArgumentNullException(nameof(name));
            if (null == contentType)
                throw new ArgumentNullException(nameof(contentType));
            if (null == streamSource)
                throw new ArgumentNullException(nameof(streamSource));
            if (null == descriptor)
                throw new ArgumentNullException(nameof(descriptor));

            _name = name;
            _contentType = contentType;
            _streamSource = streamSource;
            Descriptor = descriptor;

            var pool = _contentType.Kind == ContentKind.Video
                ? new WinRtBufferPool(1024, 4096, 16 * 1024, 64 * 1024)
                : new WinRtBufferPool(512, 1024, 2048, 8 * 1024);

            _pool = pool;

            TypedEventHandler<MediaStreamSample, object> freeBuffer = null;

            freeBuffer = (sender, args) =>
            {
                var buffer = sender.Buffer;

                if (null != buffer)
                    pool.Free(buffer);

                sender.Processed -= freeBuffer;
            };

            _freeBuffer = freeBuffer;
        }