コード例 #1
0
        public Media.MediaUri[] GetStreamURIs(Media.Profile[] profiles)
        {
            var list  = new List <Media.MediaUri>();
            var setup = new Media.StreamSetup();

            setup.Transport = new Media.Transport();
            foreach (var p in profiles.Where(p => p.VideoEncoderConfiguration.Multicast.Address.IPv4Address == "0.0.0.0"))
            {
                setup.Stream             = Media.StreamType.RTPUnicast;
                setup.Transport.Protocol = Media.TransportProtocol.RTSP;
                try
                {
                    list.Add(Client.GetStreamUri(setup, p.token));
                }
                catch { }
            }

            foreach (var p in profiles.Where(p => p.VideoEncoderConfiguration.Multicast.Address.IPv4Address != "0.0.0.0"))
            {
                setup.Stream             = Media.StreamType.RTPMulticast;
                setup.Transport.Protocol = Media.TransportProtocol.UDP;
                try
                {
                    list.Add(Client.GetStreamUri(setup, p.token));
                }
                catch { }
            }

            return(list.ToArray());
        }
コード例 #2
0
 private StreamSetup GetstreamSetup(MediaClient mediaClient, Profile[] profiles)
 {
     Media.StreamSetup streamSetup = new Media.StreamSetup();
     streamSetup.Stream             = Media.StreamType.RTPUnicast;
     streamSetup.Transport          = new Media.Transport();
     streamSetup.Transport.Protocol = Media.TransportProtocol.RTSP;
     return(streamSetup);
 }
コード例 #3
0
        public void connectIPC()
        {
            try
            {
                Device.DeviceClient deviceClient = GetDeviceClient(ipad);
                Device.Service[]    services     = deviceClient.GetServices(false);
                Device.Service      xmedia       = services.FirstOrDefault(s => s.Namespace == "http://www.onvif.org/ver10/media/wsdl");
                if (xmedia != null)
                {
                    this.Dispatcher.BeginInvoke(DispatcherPriority.Normal,
                                                (ThreadStart) delegate()
                    {
                        mediaClient = GetMediaClient();

                        profiles = GetProfiles(mediaClient);
                        Media.StreamSetup streamSetup = GetstreamSetup(mediaClient, profiles);
                        if (profiles != null)
                        {
                            foreach (var p in profiles)
                            {
                                if (combobox.Items.Contains(p.Name))
                                {
                                    break;
                                }
                                else
                                {
                                    this.Dispatcher.Invoke(() => { combobox.Items.Add(p.Name); });
                                }
                            }
                        }
                    });
                }

                combobox.SelectionChanged += new SelectionChangedEventHandler(listBox_SelectionChanged);
            }
            catch (Exception ex)
            { //System.Windows.MessageBox.Show(ex.ToString(), "aa");
            }
        }
コード例 #4
0
        private bool PlayVideo()
        {
            Media.StreamSetup streamSetup;
            string            msg, returnString, errorMessage = "";
            string            URI, soapFault;

            stopPlayer();
            Cursor.Current = Cursors.WaitCursor;

            btn_LiveVideo.Text = "Connecting";
            btn_LiveVideo.Update();

            // get the URI for the selected profile
            if (VideoProfiles == null)
            {
                btn_LiveVideo.Text = "Connect";
                return(false);
            }


            // if the selected index is greater then the known profiles length return
            if (cb_VideoStreams.SelectedIndex > VideoProfiles.Length)
            {
                btn_LiveVideo.Text = "Connect";
                return(false);
            }

            if ((Parameters.Media_ServiceAddress == "") && !(PollMediaConfigurationAddress(true)))
            {
                System.Windows.Forms.MessageBox.Show("Unable to retrieve Media Service Address.  Unable to view video stream.", "Error", MessageBoxButtons.OK);
                btn_LiveVideo.Text = "Connect";
                return(false);
            }

            // configure the video stream

            SetVideoProfileType(VideoProfiles[cb_VideoStreams.SelectedIndex].VideoEncoderConfiguration.Encoding, VideoProfiles[cb_VideoStreams.SelectedIndex].VideoEncoderConfiguration);


            // if the user wishes to see the video stream from the selected profile set it up

            streamSetup           = new Media.StreamSetup();
            streamSetup.Stream    = new Media.StreamType();
            streamSetup.Transport = new Media.Transport();

            streamSetup.Transport.Protocol = Media.TransportProtocol.UDP;
            streamSetup.Stream             = Media.StreamType.RTPUnicast;

            msg = TestMessage.Build_Media_GetStreamUriRequest(VideoProfiles[cb_VideoStreams.SelectedIndex].token, streamSetup);


            try
            {
                returnString = NetworkInterface.POST_Message(Parameters.TestTimeout, Parameters.Media_ServiceAddress, msg, Parameters.UserName, Parameters.Password);

                if (TestMessage.Check_SoapFault(returnString, out soapFault))
                {
                    MessageBox.Show("SOAP Fault, unable to connect." + Environment.NewLine + Environment.NewLine + soapFault, "Error", MessageBoxButtons.OK);
                    btn_LiveVideo.Text = "Connect";
                    return(false);
                }

                Media.GetStreamUriResponse GSR = (Media.GetStreamUriResponse)TestMessage.Parse_SoapMessage(returnString, typeof(Media.GetStreamUriResponse));

                if (GSR.MediaUri == null)
                {
                    MessageBox.Show("Unable to connect, Get Stream URI Response MediaUri is NULL" + Environment.NewLine + Environment.NewLine + soapFault, "Error", MessageBoxButtons.OK);
                    btn_LiveVideo.Text = "Connect";
                    return(false);
                }

                if (GSR.MediaUri.Uri == null)
                {
                    MessageBox.Show("Unable to connect, Get Stream URI Response does not contain a Media URI" + Environment.NewLine + Environment.NewLine + soapFault, "Error", MessageBoxButtons.OK);
                    btn_LiveVideo.Text = "Connect";
                    return(false);
                }

                URI = GSR.MediaUri.Uri;

                if (URI.Contains("&line=0"))
                {
                    URI = URI.Replace("&line=0", "");
                }

                //sc_VideoStream.StreamUri = URI;
                //sc_VideoStream.Play();

                OpenVideoStream(URI);
            }
            catch (Exception err)
            {
                errorMessage       = err.Message;
                btn_LiveVideo.Text = "Connect";
            }

            if (errorMessage != "")
            {
                MessageBox.Show("Unable to connect - " + errorMessage, "Error", MessageBoxButtons.OK);
                btn_LiveVideo.Text = "Connect";
            }
            Cursor.Current     = Cursors.Default;
            btn_LiveVideo.Text = "Stop";
            return(true);
        }