Exemple #1
0
        public static HRTimer create(TimerType type)
        {
            HRTimer timer = null;

            switch (type)
            {
            case TimerType.DEFAULT:
            {
                timer = new DefaultTimer();
                break;
            }

            case TimerType.MULTI_MEDIA:
            {
                timer = new MultiMediaTimer();
                break;
            }

            case TimerType.TIMER_QUEUE:
            {
                timer = new TimerQueueTimer();
                break;
            }
            }

            return(timer);
        }
Exemple #2
0
        public static void test()
        {
            timer = HRTimerFactory.create(HRTimerFactory.TimerType.TIMER_QUEUE);
            //timer = HRTimerFactory.create(HRTimerFactory.TimerType.DEFAULT);
            //timer = HRTimerFactory.create(HRTimerFactory.TimerType.MULTI_MEDIA);



            //testTimerAccuracy(timer);
            testTimerAutoResetFunctionality(timer);
        }
Exemple #3
0
        static void testTimerAutoResetFunctionality(HRTimer timer)
        {
            timer.Tick     += new EventHandler(tick2);
            timer.AutoReset = false;

            for (int interval = 100; interval > 0; interval -= 5)
            {
                counter   = 0;
                autoEvent = new AutoResetEvent(false);

                timer.Interval = interval;
                timer.start();

                autoEvent.WaitOne();
                Thread.Sleep(interval * 3);

                Debug.WriteLine(interval.ToString() + ": " + counter.ToString());
            }
        }
Exemple #4
0
        static void testTimerAutoResetFunctionality(HRTimer timer)
        {

            timer.Tick += new EventHandler(tick2);
            timer.AutoReset = false;

            for (int interval = 100; interval > 0; interval -= 5)
            {
                counter = 0;
                autoEvent = new AutoResetEvent(false);

                timer.Interval = interval;
                timer.start();

                autoEvent.WaitOne();
                Thread.Sleep(interval * 3);

                Debug.WriteLine(interval.ToString() + ": " + counter.ToString());
               
            }

        }
Exemple #5
0
        static void testAverageTimerAccuracy(HRTimer timer)
        {
            timer.Tick += new EventHandler(tick1);

            for (int interval = 100; interval > 0; interval -= 5)
            {
                autoEvent = new AutoResetEvent(false);

                timer.Interval = interval;

                stopWatch = Stopwatch.StartNew();
                timer.start();

                autoEvent.WaitOne();

                double avgTime = (double)(stopWatch.ElapsedMilliseconds) / counter;

                Debug.WriteLine("Test period: " + interval.ToString() + " (ms) : " + avgTime.ToString() + " avg period (ms)");

                counter = 0;
            }
        }
Exemple #6
0
		static void testAverageTimerAccuracy(HRTimer timer) {

			timer.Tick += new EventHandler(tick1);
			
			for(int interval = 100; interval > 0; interval-=5) {

				autoEvent = new AutoResetEvent(false);

				timer.Interval = interval;

				stopWatch = Stopwatch.StartNew();
				timer.start();

				autoEvent.WaitOne();

				double avgTime = (double)(stopWatch.ElapsedMilliseconds) / counter;

				Debug.WriteLine("Test period: " + interval.ToString() + " (ms) : " + avgTime.ToString() + " avg period (ms)");

				counter = 0;
			}
			
		}
Exemple #7
0
		public static void test() {

            timer = HRTimerFactory.create(HRTimerFactory.TimerType.TIMER_QUEUE);
			//timer = HRTimerFactory.create(HRTimerFactory.TimerType.DEFAULT);
            //timer = HRTimerFactory.create(HRTimerFactory.TimerType.MULTI_MEDIA);

          

			//testTimerAccuracy(timer);
            testTimerAutoResetFunctionality(timer);

			

        
	
		}
        protected virtual void Dispose(bool safe)
        {
            if (safe)
            {
                if (videoRender != null)
                {
                    videoRender.Dispose();
                    videoRender = null;
                }
                if (audioPlayer != null)
                {
                    audioPlayer.Dispose();
                    audioPlayer = null;
                }
                if (videoDecoder != null)
                {
                    videoDecoder.Dispose();
                    videoDecoder = null;
                }
                /*if (demuxPacketsTask != null)
                {
                    demuxPacketsTask.Dispose();
                    demuxPacketsTask = null;
                }*/
                if (CancelTokenSource != null)
                {
                    CancelTokenSource.Dispose();
                    CancelTokenSource = null;
                }
                if (demuxPacketsCancellationTokenSource != null)
                {
                    demuxPacketsCancellationTokenSource.Dispose();
                    demuxPacketsCancellationTokenSource = null;
                }
                if (videoRefreshTimer != null)
                {
                    videoRefreshTimer.Dispose();
                    videoRefreshTimer = null;
                }
                if (audioRefreshTimer != null)
                {
                    audioRefreshTimer.Dispose();
                    audioRefreshTimer = null;
                }

            }
        }
        public VideoPlayerViewModel(Control owner,
            VideoLib.VideoPlayer.OutputPixelFormat decodedVideoFormat = VideoLib.VideoPlayer.OutputPixelFormat.YUV420P)
        {

            this.owner = owner;
            DecodedVideoFormat = decodedVideoFormat;

            videoDecoder = new VideoLib.VideoPlayer();

            videoDecoder.FrameQueue.Finished += new EventHandler((s, e) =>
            {
                owner.BeginInvoke(new Func<Task>(async () => await close()));
            });

            videoDecoder.FrameQueue.IsBufferingChanged += new EventHandler((s, e) =>
                {
                    owner.BeginInvoke(new Action(() =>
                    {
                        if (IsBufferingChanged != null)
                        {
                            IsBufferingChanged(this, videoDecoder.FrameQueue.IsBuffering);
                        }
                    }));
                });

            audioPlayer = new AudioPlayer(owner);
            videoRender = new VideoRender(owner);

            audioDiffAvgCoef = Math.Exp(Math.Log(0.01) / AUDIO_DIFF_AVG_NB);

            //syncMode = SyncMode.AUDIO_SYNCS_TO_VIDEO;
            syncMode = SyncMode.VIDEO_SYNCS_TO_AUDIO;

            videoRefreshTimer = HRTimerFactory.create(HRTimerFactory.TimerType.TIMER_QUEUE);
            videoRefreshTimer.Tick += new EventHandler(videoRefreshTimer_Tick);
            videoRefreshTimer.AutoReset = false;

            audioRefreshTimer = HRTimerFactory.create(HRTimerFactory.TimerType.TIMER_QUEUE);
            audioRefreshTimer.Tick += new EventHandler(audioRefreshTimer_Tick);
            audioRefreshTimer.AutoReset = false;

            DurationSeconds = 0;
            PositionSeconds = 0;

            videoPts = 0;
            audioPts = 0;

            owner.HandleDestroyed += new EventHandler(async (s, e) => await close());

            VideoState = VideoState.CLOSED;
            VideoLocation = "";

            Subtitles = new Subtitles(Log);
            //interruptIOTokenSource = new CancellationTokenSource();       
        }