public static string GetSnapsotURL(Structures set, int profile = 1) { try { var tok = set.GetMediaTokens().FirstOrDefault(); if (tok == "" || !set.IsActive) { return(""); } var messageElement = new TextMessageEncodingBindingElement(); messageElement.MessageVersion = MessageVersion.CreateVersion(EnvelopeVersion.Soap12, AddressingVersion.None); HttpTransportBindingElement httpBinding = new HttpTransportBindingElement(); httpBinding.AuthenticationScheme = AuthenticationSchemes.Basic; CustomBinding bind = new CustomBinding(messageElement, httpBinding); EndpointAddress mediaAddress = new EndpointAddress(set.GetONVIF + "/onvif/Media"); MediaClient mediaClient = new MediaClient(bind, mediaAddress); mediaClient.ClientCredentials.UserName.UserName = set.Login; mediaClient.ClientCredentials.UserName.Password = set.Password; MediaUri mediaUri = mediaClient.GetSnapshotUri(set.GetMediaTokens()[profile]); return(mediaUri.Uri); } catch { return(""); } }
public static string GetStreamURL(Structures set, int profile = 0) { try { if (set.GetMediaTokens().FirstOrDefault() == "" || !set.IsActive) { return(""); } var messageElement = new TextMessageEncodingBindingElement(); messageElement.MessageVersion = MessageVersion.CreateVersion(EnvelopeVersion.Soap12, AddressingVersion.None); HttpTransportBindingElement httpBinding = new HttpTransportBindingElement(); httpBinding.AuthenticationScheme = AuthenticationSchemes.Basic; CustomBinding bind = new CustomBinding(messageElement, httpBinding); EndpointAddress mediaAddress = new EndpointAddress(set.GetONVIF + "/onvif/Media"); MediaClient mediaClient = new MediaClient(bind, mediaAddress); mediaClient.ClientCredentials.UserName.UserName = set.Login; mediaClient.ClientCredentials.UserName.Password = set.Password; ServiceReference1.StreamSetup ss = new ServiceReference1.StreamSetup(); ss.Stream = ServiceReference1.StreamType.RTPUnicast; ss.Transport = new ServiceReference1.Transport(); ss.Transport.Protocol = ServiceReference1.TransportProtocol.RTSP; MediaUri mediaUri = mediaClient.GetStreamUri(ss, set.GetMediaTokens()[profile]); return(mediaUri.Uri); } catch { return(""); } }
private void TestByCodecAndTransport(string codec, string filename, StreamType streamType, TransportProtocol protocol) { Profile deletedProfile = null; Profile createdProfile = null; Profile modifiedProfile = null; Profile profile = null; MediaConfigurationChangeLog changeLog = new MediaConfigurationChangeLog(); RunTest( () => { profile = FindSuitableProfile(changeLog, codec); if ((profile == null) || !TuneBackchannelProfile(profile, changeLog, codec)) { profile = CreateProfileByAnnex3("testprofileX", null, out deletedProfile, out createdProfile, out modifiedProfile); PrepareBackchannelProfile(profile, changeLog, codec); } StreamSetup streamSetup = new StreamSetup(); streamSetup.Stream = streamType; streamSetup.Transport = new Transport(); streamSetup.Transport.Protocol = protocol; MediaUri uri = GetStreamUri(streamSetup, profile.token); DoSequence(codec, filename, uri, streamType, protocol); }, () => { RestoreMediaConfiguration(changeLog); RestoreProfileByAnnex3(deletedProfile, createdProfile, modifiedProfile); } ); }
public string Execute([NotNull] string databaseName, [NotNull] string itemId) { Assert.ArgumentNotNull(databaseName, nameof(databaseName)); Assert.ArgumentNotNull(itemId, nameof(itemId)); var database = Factory.GetDatabase(databaseName); if (database == null) { throw new Exception("Database not found"); } var item = database.GetItem(itemId); if (item == null) { throw new Exception("Item not found"); } MediaItem mediaItem = item; var uri = MediaUri.Parse(mediaItem); var media = MediaManager.GetMedia(uri); media.ReleaseStream(); return(string.Empty); }
private void listBox_SelectionChanged(object sender, SelectionChangedEventArgs e) { bool flag = profiles != null && combobox.SelectedIndex >= 0; if (flag) { StreamSetup streamSetup = new StreamSetup(); streamSetup.Stream = StreamType.RTPUnicast; streamSetup.Transport = new Transport(); streamSetup.Transport.Protocol = TransportProtocol.RTSP; MediaUri mediaUri = new MediaUri(); mediaUri = mediaClient.GetStreamUri(streamSetup, profiles[combobox.SelectedIndex].token); UriBuilder uriBuilder = new UriBuilder(mediaUri.Uri); uriBuilder.Scheme = "rtsp"; string[] options = new string[] { ":rtsp-http", ":rtsp-http-port=" + uriBuilder.Port.ToString(), ":rtsp-user="******":rtsp-pwd=" + campassword, ":network-caching=300" }; control.Play(uriBuilder.Uri, options); stop_play.IsEnabled = true; playingrui = uriBuilder.Uri; } recordcheckbox.IsEnabled = true; }
protected virtual MediaData GetMediaData(MediaUri mediaUri) { Assert.ArgumentNotNull((object)mediaUri, nameof(mediaUri)); Database database = mediaUri.Database; if (database == null) { return((MediaData)null); } string mediaPath = mediaUri.MediaPath; if (string.IsNullOrEmpty(mediaPath)) { return((MediaData)null); } Language language = mediaUri.Language; if (language == (Language)null) { language = Context.Language; } Sitecore.Data.Version version = mediaUri.Version; if (version == (Sitecore.Data.Version)null) { version = Sitecore.Data.Version.Latest; } Item obj = database.GetItem(mediaPath, language, version); if (obj == null) { return((MediaData)null); } return(MediaManager.Config.ConstructMediaDataInstance((MediaItem)obj)); }
private Uri GetMulticastUri(Camera cam, MediaClient mediaClient, Profile mediaProfile) { if (mediaProfile?.VideoEncoderConfiguration?.Multicast != null && mediaProfile?.VideoEncoderConfiguration?.Multicast.Port != 0) { // Check for any URI supporting multicast foreach (TransportProtocol protocol in Enum.GetValues(typeof(TransportProtocol))) { // Get stream URI for the requested transport/protocol and insert the User/Password if present Transport transport = new Transport() { Protocol = protocol }; StreamSetup ss = new StreamSetup() { Stream = StreamType.RTPMulticast }; ss.Transport = transport; try { MediaUri mu = mediaClient.GetStreamUri(ss, MediaProfile.token); log.Debug(string.Format("Camera #{0} [{1}] Onvif media profile ({2}) capable of multicast [multicast URI: {3}]", cam.Number, cam.IP, mediaProfile.Name, mu.Uri)); return(new Uri(mu.Uri)); } catch { } // Ignore exception and continue checking for a multicast URI } } else { log.Debug(string.Format("Camera #{0} [{1}] Onvif media profile ({2}) does not support multicast", cam.Number, cam.IP, mediaProfile.Name)); } return(null); }
public void GetMediaUri( Profile profile, VideoSourceConfiguration videoSourceConfig, VideoEncoderConfiguration videoEncoderConfig, AudioSourceConfiguration audioSourceConfig, AudioEncoderConfiguration audioEncoderConfig, TransportProtocol protocol) { RunInBackground(new Action(() => { if (profile == null) { profile = CreateProfile(TestMediaProfileName); } ConfigureProfile(profile, videoSourceConfig, videoEncoderConfig, audioSourceConfig, audioEncoderConfig); StreamSetup streamSetup = new StreamSetup(); streamSetup.Transport = new Transport(); streamSetup.Transport.Protocol = protocol; streamSetup.Stream = StreamType.RTPUnicast; MediaUri streamUri = Client.GetStreamUri(streamSetup, profile.token); if (OnMediaUriReceived != null) { OnMediaUriReceived(streamUri, videoEncoderConfig, audioEncoderConfig); } })); }
/// <summary> /// Renders the preview. /// </summary> /// <param name="output">The output.</param><param name="item">The item.</param> private static void RenderPreview(HtmlTextWriter output, Item item) { Assert.ArgumentNotNull(output, "output"); Assert.ArgumentNotNull(item, "item"); MediaItem mediaItem = item; MediaUrlOptions shellOptions = MediaUrlOptions.GetShellOptions(); shellOptions.AllowStretch = false; shellOptions.BackgroundColor = Color.White; shellOptions.Language = item.Language; shellOptions.Thumbnail = true; shellOptions.UseDefaultIcon = true; shellOptions.Width = 192; shellOptions.Height = 192; string mediaUrl = MediaManager.GetMediaUrl(mediaItem, shellOptions); output.Write("<table width=\"100%\" height=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">"); output.Write("<tr><td align=\"center\" height=\"100%\">"); output.Write("<div class=\"scPreview\">"); output.Write("<img src=\"" + mediaUrl + "\" class=\"scPreviewImage\" border=\"0\" alt=\"\" />"); output.Write("</div>"); output.Write("<div class=\"scPreviewHeader\">"); output.Write(item.DisplayName); output.Write("</div>"); output.Write("</td></tr>"); if (!(MediaManager.GetMedia(MediaUri.Parse(mediaItem)) is ImageMedia || mediaItem.MimeType == "image/svg+xml")) { output.Write("</table>"); } else { output.Write("<tr><td class=\"scProperties\">"); output.Write("<table border=\"0\" class=\"scFormTable\" cellpadding=\"2\" cellspacing=\"0\">"); output.Write("<col align=\"right\" />"); output.Write("<col align=\"left\" />"); output.Write("<tr><td>"); output.Write(Translate.Text("Alternate text:")); output.Write("</td><td>"); output.Write("<input type=\"text\" id=\"AlternateText\" value=\"{0}\" />", HttpUtility.HtmlEncode(mediaItem.Alt)); output.Write("</td></tr>"); output.Write("<tr><td>"); output.Write(Translate.Text("Width:")); output.Write("</td><td>"); output.Write("<input type=\"text\" id=\"Width\" value=\"{0}\" />", HttpUtility.HtmlEncode(mediaItem.InnerItem["Width"])); output.Write("</td></tr>"); output.Write("<tr><td>"); output.Write(Translate.Text("Height:")); output.Write("</td><td>"); output.Write("<input type=\"text\" id=\"Height\" value=\"{0}\" />", HttpUtility.HtmlEncode(mediaItem.InnerItem["Height"])); output.Write("</td></tr>"); output.Write("</table>"); output.Write("</td></tr>"); output.Write("</table>"); SheerResponse.Eval("scAspectPreserver.reload();"); } }
//TODO remove protected attribute - temporary usage only, till GetURI will work fully OK protected void AdjustVideo( TransportProtocol protocol, StreamType streamType, MediaUri streamUri, VideoEncoderConfiguration conf) { VideoUtils.AdjustVideo(_videoForm, _username, _password, _messageTimeout, protocol, streamType, streamUri, conf); }
/// <summary> /// Returns snapshot uri from DUT /// </summary> /// <param name="profileToken">Get snapshot parameters</param> /// <returns>Snapshot uri</returns> protected MediaUri GetSnapshotUri(string profileToken) { MediaClient client = MediaClient; MediaUri response = null; RunStep(() => { response = client.GetSnapshotUri(profileToken); }, "Get snapshot URI"); DoRequestDelay(); return(response); }
private static void ProcessMediaUpload(Stream content, Database db, string itemParam, string entryName, bool skipExisting = false) { var mediaItem = (MediaItem)db.GetItem(itemParam) ?? db.GetItem(itemParam.TrimStart('/', '\\')) ?? db.GetItem(ApplicationSettings.MediaLibraryPath + itemParam); if (mediaItem == null) { var filename = itemParam.TrimEnd('/', '\\').Replace('\\', '/'); var dirName = (Path.GetDirectoryName(filename) ?? string.Empty).Replace('\\', '/'); if (!dirName.StartsWith(Constants.MediaLibraryPath)) { dirName = Constants.MediaLibraryPath + (dirName.StartsWith("/") ? dirName : "/" + dirName); } if (!String.IsNullOrEmpty(entryName)) { dirName += "/" + Path.GetDirectoryName(entryName).Replace('\\', '/'); filename = Path.GetFileName(entryName); } var mco = new MediaCreatorOptions { Database = db, Versioned = Settings.Media.UploadAsVersionableByDefault, Destination = $"{dirName}/{Path.GetFileNameWithoutExtension(filename)}", }; var mc = new MediaCreator(); using (var ms = new MemoryStream()) { content.CopyTo(ms); mc.CreateFromStream(ms, Path.GetFileName(filename), mco); } } else { if (skipExisting) { return; } var mediaUri = MediaUri.Parse(mediaItem); var media = MediaManager.GetMedia(mediaUri); using (var ms = new MemoryStream()) { content.CopyTo(ms); using (new EditContext(mediaItem, SecurityCheck.Disable)) { using (var mediaStream = new MediaStream(ms, media.Extension, mediaItem)) { media.SetStream(mediaStream); } } } } }
public Model( StreamSetup streamSetup, MediaUri mediaUri, VideoResolution encoderResolution, bool isUriEnabled, IMetadataReceiver metadataReceiver ) { this.streamSetup = streamSetup; this.mediaUri = mediaUri; this.encoderResolution = encoderResolution; this.isUriEnabled = isUriEnabled; this.metadataReceiver = metadataReceiver; }
public override Media GetMedia(MediaUri mediaUri) { Assert.ArgumentNotNull((object)mediaUri, nameof(mediaUri)); MediaData mediaData = this.GetMediaData(mediaUri); if (mediaData == null) { return((Media)null); } return(this.GetMedia(mediaData)); }
/// <summary>Handles a click on the OK button.</summary> /// <param name="sender">The sender.</param> /// <param name="args">The arguments.</param> /// <remarks> /// When the user clicks OK, the dialog is closed by calling /// the <see cref="M:Sitecore.Web.UI.Sheer.ClientResponse.CloseWindow">CloseWindow</see> method. /// </remarks> protected override void OnOK(object sender, EventArgs args) { Assert.ArgumentNotNull(sender, ExtensionMethods.nameof(() => sender)); Assert.ArgumentNotNull((object)args, ExtensionMethods.nameof(() => args)); string str = this.Filename.Value; if (str.Length == 0) { SheerResponse.Alert("Select a media item."); } else { Item root = this.DataContext.GetRoot(); if (root != null) { Item rootItem = root.Database.GetRootItem(); if (rootItem != null && root.ID != rootItem.ID) { str = FileUtil.MakePath(root.Paths.Path, str, '/'); } } MediaItem mediaItem = (MediaItem)this.DataContext.GetItem(str, this.ContentLanguage, Sitecore.Data.Version.Latest); if (mediaItem == null) { SheerResponse.Alert("The media item could not be found."); } else if (!(MediaManager.GetMedia(MediaUri.Parse((Item)mediaItem)) is ImageMedia)) { SheerResponse.Alert("The selected item is not an image. Select an image to continue."); } else { MediaUrlOptions shellOptions = MediaUrlOptions.GetShellOptions(); shellOptions.Language = this.ContentLanguage; string text = !string.IsNullOrEmpty(HttpContext.Current.Request.Form["AlternateText"]) ? HttpContext.Current.Request.Form["AlternateText"] : mediaItem.Alt; Tag image = new Tag("img"); this.SetDimensions(mediaItem, shellOptions, image); image.Add("Src", MediaManager.GetMediaUrl(mediaItem, shellOptions)); image.Add("Alt", StringUtil.EscapeQuote(text)); image.Add("_languageInserted", "true"); if (this.Mode == "webedit") { SheerResponse.SetDialogValue(StringUtil.EscapeJavascriptString(image.ToString())); base.OnOK(sender, args); } else { SheerResponse.Eval("TinyMCEEditor.InsertImage.scClose(" + StringUtil.EscapeJavascriptString(image.ToString()) + ")"); } } } }
/* postponed to Phase 2 * [Test(Name = "MEDIA STREAMING - H.264 (RTP-Unicast/TCP)", * Path = PATH, * Order = "08.01.13", * Version = 1.02, * Interactive = true, * RequirementLevel = RequirementLevel.ConditionalMust, * RequiredFeatures = new Feature[] { Feature.H264, Feature.RTPTCP })] */ public void NvtMediaStreamingH264RtpUnicastTcp() { RunTest(() => { MediaUri streamUri = GetH264MediaUri(StreamType.RTPUnicast, TransportProtocol.TCP); ValidateVideoSequence(); }, () => { VideoCleanup(); } ); }
public void NvtMediaStreamingH264SetSynchronizationPoint() { RunTest(() => { MediaUri streamUri = GetH264MediaUri(StreamType.RTPUnicast, TransportProtocol.UDP); ValidateSyncSequence(); }, () => { VideoCleanup(); } ); }
private void DoSequence(string codec, string filename, MediaUri Uri, StreamType streamType, TransportProtocol protocol) { if (NewGenVideo == null) { NewGenVideo = new VideoContainer2(); } VideoUtils.AdjustGeneral2(NewGenVideo, _username, _password, MessageTimeout, protocol, streamType, Uri); VideoUtils.AdjustBackchannel2(NewGenVideo, codec, filename); NewGenVideo.EventSink = this; NewGenVideo.SetSequence(4); NewGenVideo.SilentRun(); NewGenVideo.EventSink = null; }
public void NvtMediaStreamingJpegRtpUnicastRtspHttpTcp() { RunTest(() => { MediaUri streamUri = GetJpegMediaUri(StreamType.RTPUnicast, TransportProtocol.HTTP); ValidateVideoSequence(); }, () => { VideoCleanup(); } ); }
/* postponed to Phase 2 * [Test(Name = "MEDIA STREAMING – JPEG/AAC (RTP-Unicast/TCP)", * Path = PATH, * Order = "08.02.10", * Version = 1.02, * Interactive = true, * RequirementLevel = RequirementLevel.Must, * RequiredFeatures = new Feature[] { Feature.MediaService, Feature.Audio, Feature.AAC, Feature.RTPTCP})] */ public void NvtMediaStreamingJpegAacRtpTcp() { RunTest(() => { MediaUri streamUri = GetJpegAacMediaUri(StreamType.RTPUnicast, TransportProtocol.TCP); ValidateAudioVideoSequence(); }, () => { VideoCleanup(); } ); }
/*[ Test( Name = "MEDIA STREAMING – JPEG/AAC (RTP-Multicast/UDP, IPv6)", * Path = PATH_M, * Order = "03.02.06", * Id = "3-2-6", * Category = Category.RTSS, * Version = 2.0, * Interactive = true, * RequirementLevel = RequirementLevel.Must, * RequiredFeatures = new Feature[] { Feature.MediaService, Feature.Audio, Feature.AAC, Feature.IPv6, Feature.RTPMulticastUDP })]*/ public void NvtMediaStreamingJpegAACRtpMulticastUdpIPv6() { RunTest(() => { MediaUri streamUri = GetJpegAACMediaUri(StreamType.RTPMulticast, TransportProtocol.UDP, IPType.IPv6); ValidateAudioVideoSequence(); }, () => { VideoCleanup(); } ); }
public void NvtMediaStreamingMpeg4RtpRtspTcp() { RunTest(() => { MediaUri streamUri = GetMpeg4MediaUri(StreamType.RTPUnicast, TransportProtocol.RTSP); ValidateVideoSequence(); }, () => { VideoCleanup(); } ); }
public void NvtMediaStreamingH264RtpMulticastUdpIPv4() { RunTest( () => { MediaUri streamUri = GetH264MediaUri(StreamType.RTPMulticast, TransportProtocol.UDP, IPType.IPv4); ValidateVideoSequence(); }, () => { VideoCleanup(); } ); }
public void NvtMediaStreamingG711RtpUnicastUdp() { RunTest( () => { MediaUri streamUri = GetG711MediaUri(StreamType.RTPUnicast, TransportProtocol.UDP); ValidateAudioSequence(); }, () => { VideoCleanup(); } ); }
public void NvtMediaStreamingRtspKeepAliveTest() { RunTest(() => { MediaUri streamUri = GetJpegMediaUri(StreamType.RTPUnicast, TransportProtocol.UDP); _videoForm.KEEPALIVE = true; ValidateVideoSequence(); }, () => { VideoCleanup(); _videoForm.KEEPALIVE = false; } ); }
public void NvtMediaControlRtspTcpTest() { RunTest(() => { MediaUri streamUri = GetJpegMediaUri(StreamType.RTPUnicast, TransportProtocol.UDP); _videoForm.OPTIONS = true; ValidateVideoSequence(); }, () => { VideoCleanup(); _videoForm.OPTIONS = false; } ); }
/// <summary> /// Sets up the connection to the camera, enquires to get metadata from the Onvif service /// </summary> /// <param name="camera"></param> /// <returns></returns> static async Task AsyncHelper(BaseOnvifPtzCamera camera) { Globals.Log.Debug(string.Format("Connecting to camera at {0}", camera.HostAddress)); camera.Camera = await OnvifClientFactory.CreateDeviceClientAsync(camera.HostAddress, camera.UserName, camera.Password); camera.MediaClient = await OnvifClientFactory.CreateMediaClientAsync(camera.HostAddress, camera.UserName, camera.Password);; camera.PtzController = await OnvifClientFactory.CreatePTZClientAsync(camera.HostAddress, camera.UserName, camera.Password); Mictlanix.DotNet.Onvif.Media.GetProfilesResponse profiles = await camera.MediaClient.GetProfilesAsync(); camera.MediaProfile = profiles.Profiles.FirstOrDefault(); if (camera.MediaProfile != null) { StreamSetup streamSetup = new StreamSetup { Stream = StreamType.RTPUnicast, Transport = new Transport() }; streamSetup.Transport.Protocol = TransportProtocol.TCP; MediaUri videoStreamUriObject = await camera.MediaClient.GetStreamUriAsync(streamSetup, camera.MediaProfile.Name); camera.VideoStreamUri = videoStreamUriObject.Uri; } Mictlanix.DotNet.Onvif.Device.GetNetworkProtocolsRequest request = new Mictlanix.DotNet.Onvif.Device.GetNetworkProtocolsRequest(); Mictlanix.DotNet.Onvif.Device.GetNetworkProtocolsResponse response = await camera.Camera.GetNetworkProtocolsAsync(request); // store http and rtsp ports foreach (NetworkProtocol protocol in response.NetworkProtocols) { string protocolName = protocol.Name.ToString(); switch (protocolName) { case "HTTP": camera.HttpPort = protocol.Port[0]; break; case "RTSP": camera.RtspPort = protocol.Port[0]; break; } } Mictlanix.DotNet.Onvif.Media.GetVideoSourcesResponse video_sources = await camera.MediaClient.GetVideoSourcesAsync(); Globals.Log.Debug("Camera connected"); }
public void NvtMediaStreamingJpegAACRtpMulticastUdpIPv6() { MediaConfigurationChangeLog changeLog = new MediaConfigurationChangeLog(); RunTest(() => { MediaUri streamUri = GetJpegAACMediaUri(StreamType.RTPMulticast, TransportProtocol.UDP, IPType.IPv6, changeLog); ValidateAudioVideoSequence(); }, () => { VideoCleanup(); RestoreMediaConfiguration(changeLog); } ); }
/* postponed to Phase 2 * [Test(Name = "MEDIA STREAMING – JPEG/AAC (RTP-Unicast/TCP)", * Path = PATH, * Order = "08.02.10", * Version = 1.02, * Interactive = true, * RequirementLevel = RequirementLevel.Must, * RequiredFeatures = new Feature[] { Feature.MediaService, Feature.Audio, Feature.AAC, Feature.RTPTCP})] */ public void NvtMediaStreamingJpegAacRtpTcp() { MediaConfigurationChangeLog changeLog = new MediaConfigurationChangeLog(); RunTest(() => { MediaUri streamUri = GetJpegAacMediaUri(StreamType.RTPUnicast, TransportProtocol.TCP, changeLog); ValidateAudioVideoSequence(); }, () => { VideoCleanup(); RestoreMediaConfiguration(changeLog); } ); }
public static Model Create( StreamSetup streamSetup, MediaUri mediaUri, VideoResolution encoderResolution, bool isUriEnabled, IMetadataReceiver metadataReceiver ) { var _this = new Model(); _this.streamSetup = streamSetup; _this.mediaUri = mediaUri; _this.encoderResolution = encoderResolution; _this.isUriEnabled = isUriEnabled; _this.metadataReceiver = metadataReceiver; return(_this); }
/// <summary> /// Gets media from a media URI. /// /// </summary> /// <param name="mediaUri">The media URI.</param> /// <returns/> public static Sitecore.Resources.Media.Media GetMedia(MediaUri mediaUri) { return Provider.GetMedia(mediaUri); }