Beispiel #1
0
        public void StartRemoteStreaming(CaptureDeviceInfo device)
        {
            if (IsRemoteStreaming)
            {
                return;
            }

            IsRemoteStreaming = true;
            _cscoreDataPlayer = new CSCoreDataPlayer(true);
            _cscoreDataPlayer.Initialize();
            _cscoreDataPlayer.SingleBlockRead += RemoteBlockRead;

            var voiceChatInfoData =
                Serializer.FastSerialize(new VoiceChatBeginCaptureInfo
            {
                Application = (int)Application,
                Bitrate     = Bitrate,
                DeviceId    = device.Id
            });

            ConnectionInfo.UnsafeSendCommand(this, new WriterCall(voiceChatInfoData.Length + 1, stream =>
            {
                stream.WriteByte((byte)VoiceChatCommunication.StartRemoteStreaming);
                stream.Write(voiceChatInfoData, 0, voiceChatInfoData.Length);
            }));

            LogService.Send((string)System.Windows.Application.Current.Resources["StartRemoteStream"]);
        }
Beispiel #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MediaPlayerComponent"/> class.
 /// </summary>
 public MediaPlayerComponent()
 {
     m_mfResourceLock       = new object();
     m_currentVideoLink     = null;
     m_currentCaptureDevice = null;
     m_audioVolume          = 1f;
 }
Beispiel #3
0
        /// <summary>
        /// Disposes all current resources.
        /// </summary>
        private void DisposeResources()
        {
            lock (m_mfResourceLock)
            {
                // Shutdown current session
                if (m_mediaSession != null)
                {
                    m_mediaSession.Shutdown();
                }

                // Clear all references
                m_currentVideoLink     = null;
                m_currentCaptureDevice = null;
                m_currentVideoDuration = TimeSpan.Zero;
                GraphicsHelper.SafeDispose(ref m_displayControl);
                GraphicsHelper.SafeDispose(ref m_audioStreamVolume);
                GraphicsHelper.SafeDispose(ref m_mediaSession);
                m_sessionEventHandler = null;

                GraphicsHelper.SafeDispose(ref m_videoSourceStream);
                GraphicsHelper.SafeDispose(ref m_videoSourceStreamNet);
            }

            // Apply new state
            this.IsPaused = false;
            this.State    = MediaPlayerState.NothingToDo;
        }
        private void StartCapturing(object sender, RoutedEventArgs e)
        {
            var devices = NpcapDeviceList.Instance;

            if (_captureDeviceInfo != null)
            {
                return;
            }

            if (cbDevices.SelectedIndex < 0)
            {
                return;
            }

            var device = devices[cbDevices.SelectedIndex];

            _captureDeviceInfo = new CaptureDeviceInfo(device);

            device.OnPacketArrival +=
                new PacketArrivalEventHandler(OnPacketArrival);

            int readTimeoutMilliseconds = 1000;

            device.Open(DeviceMode.Normal, readTimeoutMilliseconds);

            // Trace.WriteLine("Listening on " + device.ToString() + "..." + device.Name + " ... " + device.MacAddress.ToString());

            device.Filter = "udp";
            device.StartCapture();
        }
        private void ChooseSource_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            SelectedDevice = (CaptureDeviceInfo)e.Parameter;

            DialogResult = true;

            Close();
        }
        private void StopCapturing(object sender, RoutedEventArgs e)
        {
            if (_captureDeviceInfo == null)
            {
                return;
            }

            _captureDeviceInfo.device.StopCapture();
            _captureDeviceInfo = null;
        }
Beispiel #7
0
        /// <summary>
        /// Opens the given video file and plays it directly.
        /// </summary>
        /// <param name="videoLink">The link to the video file.</param>
        public async Task OpenAndShowVideoFileAsync(ResourceLink videoLink)
        {
            // Check for correct state
            if (this.State != MediaPlayerState.NothingToDo)
            {
                throw new InvalidOperationException("Unable to open video file as long as there is another video playing!");
            }

            // Apply new state
            this.State = MediaPlayerState.Opening;

            try
            {
                // Create media session and a corresponding event listener obect for async events
                MF.MediaFactory.CreateMediaSession(null, out m_mediaSession);
                m_sessionEventHandler = MFSessionEventListener.AttachTo(m_mediaSession);
                m_sessionEventHandler.EndOfPresentation += OnSessionEventHandlerEndOfPresentationReached;

                // Create source object
                MF.SourceResolver sourceResolver = new MF.SourceResolver();
                MF.ObjectType     objType        = MF.ObjectType.Invalid;
                m_videoSourceStreamNet = videoLink.OpenInputStream();
                m_videoSourceStream    = new MF.ByteStream(m_videoSourceStreamNet);
                SharpDX.ComObject objSource = sourceResolver.CreateObjectFromStream(
                    m_videoSourceStream,
                    "Dummy." + videoLink.FileExtension,
                    MF.SourceResolverFlags.MediaSource,
                    out objType);
                using (MF.MediaSource mediaSource = objSource.QueryInterface <MF.MediaSource>())
                {
                    GraphicsHelper.SafeDispose(ref objSource);
                    GraphicsHelper.SafeDispose(ref sourceResolver);

                    await ShowVideoAsync(mediaSource);
                }

                // Video opened successfully
                m_currentVideoLink     = videoLink;
                m_currentCaptureDevice = null;
                this.State             = MediaPlayerState.Playing;
            }
            catch (Exception)
            {
                // Unload all resources in case of an exception
                DisposeResources();

                throw;
            }
        }
        private void FillAvailableCaptureSourcesList()
        {
            AvailableCaptureSources = new List <CaptureDeviceInfo>();

            DsDevice[] videoCaptureDevice = DsDevice.GetDevicesOfCat(FilterCategory.VideoInputDevice);

            for (int i = 0; i < videoCaptureDevice.Length; i++)
            {
                DsDevice          device = videoCaptureDevice[i];
                CaptureDeviceInfo info   = new CaptureDeviceInfo()
                {
                    DeviceID = i, Name = device.Name
                };

                AvailableCaptureSources.Add(info);
            }
        }
Beispiel #9
0
        public FFMEWebcam(ITraceManager traceManager)
        {
            _traceManager = traceManager;

            var videoDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice);

            CaptureDevices = new List <CaptureDeviceInfo>();
            foreach (FilterInfo filterInfo in videoDevices)
            {
                var device = new CaptureDeviceInfo(filterInfo);
                if (device.SupportedVideoResolutions.Any())
                {
                    CaptureDevices.Add(device);
                }
            }
            CaptureDevices.Sort();
        }
Beispiel #10
0
        public async Task ShowCaptureDeviceAsync(CaptureDeviceInfo captureDevice)
        {
            // Check for correct state
            if (this.State != MediaPlayerState.NothingToDo)
            {
                throw new InvalidOperationException("Unable to open video file as long as there is another video playing!");
            }

            // Apply new state
            this.State = MediaPlayerState.Opening;

            try
            {
                // Create media session and a corresponding event listener obect for async events
                MF.MediaFactory.CreateMediaSession(null, out m_mediaSession);
                m_sessionEventHandler = MFSessionEventListener.AttachTo(m_mediaSession);
                m_sessionEventHandler.EndOfPresentation += OnSessionEventHandlerEndOfPresentationReached;

                // Create the media source
                using (MF.MediaSource mediaSource = captureDevice.CreateMediaSource())
                {
                    // Show the video
                    await ShowVideoAsync(mediaSource);
                }

                // Video opened successfully
                m_currentVideoLink     = null;
                m_currentCaptureDevice = captureDevice;
                this.State             = MediaPlayerState.Playing;
            }
            catch (Exception)
            {
                // Unload all resources in case of an exception
                DisposeResources();

                throw;
            }
        }