public void WriteValue(IBufferWriter <byte> writer, MediaDescription value) { if (value == null) { throw new SerializationException("Media field must have value"); } SerializationHelpers.EnsureFieldIsPresent("Media field: Media", value.Media); SerializationHelpers.CheckForReserverdChars("Media field: Media", value.Media, ReservedChars); SerializationHelpers.EnsureFieldIsPresent("Media field: Port", value.Port); SerializationHelpers.CheckForReserverdChars("Media field: Port", value.Port, ReservedChars); SerializationHelpers.EnsureFieldIsPresent("Media field: Proto", value.Proto); SerializationHelpers.CheckForReserverdChars("Media field: Proto", value.Proto, ReservedChars); if (value.Fmts == null || !value.Fmts.Any()) { throw new SerializationException("Invalid Media field: fmt, expected required values"); } var field = $"m={value.Media} {value.Port} {value.Proto}"; writer.WriteString(field); foreach (var fmt in value.Fmts) { SerializationHelpers.EnsureFieldIsPresent("Media field: fmt", fmt); SerializationHelpers.CheckForReserverdChars("Media field: fmt", fmt, ReservedChars); writer.WriteString($" {fmt}"); } writer.WriteString(SDPSerializer.CRLF); }
private bool CheckIfOriginSareSame(MediaDescription a, MediaDescription b) { return(a.Media == b.Media && a.Port == b.Port && a.Proto == b.Proto && a.Fmts.SequenceEqual(b.Fmts)); }
/// <summary> /// 视频信息浏览窗体加载 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void frmVideoInfoScan_Load(object sender, EventArgs e) { try { //////////////////////////////////////////////////////////////////////////在控件中显示视频文件的各种属性 MediaProperty mediaProperty = MediaDescription.GetMediaProperty(videoFileName); propertyGrid_Media.SelectedObject = mediaProperty; } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); this.Close(); this.Dispose(); GC.Collect(); } }
void OnOpen(MediaSink mediaSink, MediaDescription description, SocketStream sock) { _sockStream = sock; if (_useHttp) { if (_httpStreamer != null) { _httpStreamer.Stop(); } _httpStreamer = new MediaHTTPStreamer(_mediaSink); _httpStreamer.Start(sock, description.MimeType, (UInt32)description.Size, HTTP_PORT); } else { _running = true; RxLoop(); } }
public void CanDeSerialize() { var field = $"m=video 49170/2 RTP/AVP 31 35".ToByteArray(); var value = MediaSerializer.Instance.ReadValue(field); var expected = new MediaDescription() { Media = "video", Port = "49170/2", Proto = "RTP/AVP", Fmts = new List <string>() { "31", "35" } }; Assert.True(CheckIfOriginSareSame(expected, value)); }
public MediaDescription ReadValue(ReadOnlySpan <byte> data) { var remainingSlice = data; //header SerializationHelpers.ParseRequiredHeader("Media field", remainingSlice, HeaderBytes); remainingSlice = remainingSlice.Slice(HeaderBytes.Length); var mDescr = new MediaDescription(); // Media mDescr.Media = SerializationHelpers.ParseRequiredString("Media field: Media", SerializationHelpers.NextRequiredDelimitedField("Media field: Media", SDPSerializer.ByteSpace, remainingSlice, out var consumed)); remainingSlice = remainingSlice.Slice(consumed + 1); // port mDescr.Port = SerializationHelpers.ParseRequiredString("Media field: Port", SerializationHelpers.NextRequiredDelimitedField("Media field: Port", SDPSerializer.ByteSpace, remainingSlice, out consumed)); remainingSlice = remainingSlice.Slice(consumed + 1); // Proto mDescr.Proto = SerializationHelpers.ParseRequiredString("Media field: Proto", SerializationHelpers.NextRequiredDelimitedField("Media field: Proto", SDPSerializer.ByteSpace, remainingSlice, out consumed)); remainingSlice = remainingSlice.Slice(consumed + 1); // fmt if (remainingSlice.Length == 0) { throw new DeserializationException("Invalid Media field: fmt, expected required values"); } else { mDescr.Fmts = Encoding.UTF8.GetString(remainingSlice).Split((char)SDPSerializer.ByteSpace); } return(mDescr); }
public override RtspResponse Describe(RtspRequest request) { var origin = SessionOriginator.CreateBuilder() .Username("-") .SessionId(1) .SessionVersion(1) .NetType(NetworkType.IN) .AddrType(AddressType.IP4) .UnicastAddress(request.RemoteEndpoint.Address.ToString()) .Build(); var connection = ConnectionInfo.CreateBuilder() .NetType(NetworkType.IN) .AddrType(AddressType.IP4) .Address("0.0.0.0") .Build(); var media = MediaDescription.CreateBuilder() .MediaType(MediaType.APPLICATION) .Port(0) .Protocol(TransportProtocol.RTP_AVP) .AddFormat(98) .AddAttribute(new Attribute("control", request.URI.ToString())) .AddAttribute(new Attribute("rtpmap", "98 application/vnd.pelco.test.metadata/90000")) .Build(); var sdp = new SessionDescription() { SessionInformation = "Test session", Origin = origin, Connection = connection, }; sdp.MediaDescriptions.Add(media); return RtspResponse.CreateBuilder() .Status(RtspResponse.Status.Ok) .Body(sdp) .Build(); }
public async Task CanSerialize() { var expected = $"m=video 49170/2 RTP/AVP 31 35{SDPLib.SDPSerializer.CRLF}".ToByteArray(); var pipe = new Pipe(); var value = new MediaDescription() { Media = "video", Port = "49170/2", Proto = "RTP/AVP", Fmts = new List <string>() { "31", "35" } }; MediaSerializer.Instance.WriteValue(pipe.Writer, value); pipe.Writer.Complete(); var serialized = (await pipe.Reader.ReadAsync()).Buffer.ToArray(); Assert.Equal(expected, serialized); }
/// <summary> /// Converts media entity to corresponding media lines. Attributes included. /// </summary> /// <returns></returns> public string ToValue() { /* * m= (media name and transport address) * i=* (media title) * c=* (connection information -- optional if included at session level) * b=* (zero or more bandwidth information lines) * k=* (encryption key) * a=* (zero or more media attribute lines) */ StringBuilder retVal = new StringBuilder(); // m Media description if (MediaDescription != null) { retVal.Append(MediaDescription.ToValue()); } // i media title if (!string.IsNullOrEmpty(Title)) { retVal.AppendLine("i=" + Title); } // c Connection Data if (ConnectionData != null) { retVal.Append(ConnectionData.ToValue()); } // a Attributes foreach (SDP_Attribute attribute in Attributes) { retVal.Append(attribute.ToValue()); } return(retVal.ToString()); }
private SessionDescription CreateSdp(Uri uri) { var sdp = new SessionDescription(); var media = MediaDescription.CreateBuilder() .MediaType(MediaType.APPLICATION) .Port(0) .Protocol(TransportProtocol.RTP_AVP) .AddFormat(PAYLOAD_TYPE) .AddAttribute(new Pelco.Media.RTSP.SDP.Attribute("control", uri.ToString())) .AddAttribute(new Pelco.Media.RTSP.SDP.Attribute("rtpmap", $"{PAYLOAD_TYPE} {MIME_TYPE}/90000")) .Build(); sdp.SessionInformation = "OpenCV Facial Detection RTSP Session"; sdp.MediaDescriptions.Add(media); sdp.Connection = ConnectionInfo.CreateBuilder() .NetType(NetworkType.IN) .AddrType(AddressType.IP4) .Address("0.0.0.0") .Build(); return(sdp); }
public static async Task Run( [QueueTrigger("visionscanner")] string tweetQuery, [Table("visiontweet")] CloudTable visionTweetTable, [Queue("visionscanned")] IAsyncCollector <string> visionScannedQueue, TraceWriter log) { log.Info($"VisionScanner processing TweetId: {tweetQuery}"); long tweetId = long.Parse(tweetQuery); long originalTweetId = tweetId; List <string> screenNamesToReplyTo = new List <string>(); var service = Helper.TwitterService(); TwitterStatus tweet = null; TweetEntity tweetEntity = null; while (tweet == null) { //moving this check inside the while loop to stop processing retweets var tweetDetails = Helper.FetchTweetFromStorage(tweetId.ToString()); if (tweetDetails != null) //already processed { log.Info($"VisionScanner Already Processed TweetId: {tweetId}"); return; } tweet = service.GetTweet(new GetTweetOptions { Id = tweetId, IncludeEntities = true, TweetMode = TweetMode.Extended }); //build up mentions list for replyto - will distinct later screenNamesToReplyTo.Add("@" + tweet.User.ScreenName); foreach (var mention in tweet.Entities.Mentions) { screenNamesToReplyTo.Add("@" + mention.ScreenName); } tweetEntity = new TweetEntity(tweet); //no media? try the parent if (!tweet.Entities.Media.Any()) { log.Info($"VisionScanner No media found in TweetId: {tweetQuery}"); // Documentation Link: Add an entity to a table - https://cda.ms/nn visionTweetTable.Execute(TableOperation.Insert(tweetEntity)); if (tweet.InReplyToStatusId == null) { //walked up the whole chain - no media found return; } else { tweetId = ((long)tweet.InReplyToStatusId); tweet = null; } } } var mediaDesc = new MediaDescription(tweet.Id); var photos = tweet.Entities.Media.Where(m => m.MediaType == TwitterMediaType.Photo); foreach (var media in photos) { log.Info($"VisionScanner FetchVisionDescriptionAsync TweetId/MediaId: {tweetQuery}/{media.Id}"); var vision = await Helper.FetchVisionDescriptionAsync(tweet, media); mediaDesc.VisionDescription.Add(media.IdAsString, vision); } tweetEntity.VisionJson = JsonConvert.SerializeObject(mediaDesc); // Documentation Link: Add an entity to a table - https://cda.ms/nn visionTweetTable.Execute(TableOperation.Insert(tweetEntity)); var dto = new TweetScannedDTO { TwitterStatus = tweetEntity.BuildTwitterStatus(), OriginalTweetId = originalTweetId, UsersToReplyTo = screenNamesToReplyTo.Distinct().ToArray(), MediaDescription = mediaDesc }; log.Info($"VisionScanner Queuing VisionScanned TweetId: {tweetQuery}"); await visionScannedQueue.AddAsync(JsonConvert.SerializeObject(dto)); log.Info($"VisionScanner processed TweetId: {tweetQuery}"); }
Notification CreateNotification() { LogHelper.Debug(Tag, "updateNotificationMetadata. mMetadata=" + metadata); if (metadata == null || playbackState == null) { return(null); } var notificationBuilder = new Notification.Builder(service); int playPauseButtonPosition = 0; // If skip to previous action is enabled if ((playbackState.Actions & PlaybackState.ActionSkipToPrevious) != 0) { notificationBuilder.AddAction(Resource.Drawable.ic_skip_previous_white_24dp, service.GetString(Resource.String.label_previous), previousIntent); playPauseButtonPosition = 1; } AddPlayPauseAction(notificationBuilder); // If skip to next action is enabled if ((playbackState.Actions & PlaybackState.ActionSkipToNext) != 0) { notificationBuilder.AddAction(Resource.Drawable.ic_skip_next_white_24dp, service.GetString(Resource.String.label_next), nextIntent); } MediaDescription description = metadata.Description; var fetchArtUrl = string.Empty; Bitmap art = null; if (description.IconUri != null) { String artUrl = description.IconUri.ToString(); art = AlbumArtCache.Instance.GetBigImage(artUrl); if (art == null) { fetchArtUrl = artUrl; art = BitmapFactory.DecodeResource(service.Resources, Resource.Drawable.ic_default_art); } } notificationBuilder .SetStyle(new Notification.MediaStyle() .SetShowActionsInCompactView( new [] { playPauseButtonPosition }) // show only play/pause in compact view .SetMediaSession(sessionToken)) .SetColor(notificationColor) .SetSmallIcon(Resource.Drawable.ic_notification) .SetVisibility(NotificationVisibility.Public) .SetUsesChronometer(true) .SetContentIntent(CreateContentIntent()) .SetContentTitle(description.Title) .SetContentText(description.Subtitle) .SetLargeIcon(art); SetNotificationPlaybackState(notificationBuilder); if (fetchArtUrl != null) { FetchBitmapFromURL(fetchArtUrl, notificationBuilder); } return(notificationBuilder.Build()); }
// ------------------------------------------------------------------------------- // ------------------------------------------------------------------------------- /// <summary> /// Sets the parent XElement with the contents of the RssMediaExtension object /// properties /// </summary> /// <param name="parEl">Parent element</param> // ------------------------------------------------------------------------------- // ------------------------------------------------------------------------------- public void SetEl(XElement parEl) { for (int i = 0; i < MediaRatings.Count; i++) { parEl.Add(MediaRatings[i].GetEl()); } if (MediaTitle != null) { parEl.Add(MediaTitle.GetEl()); } if (MediaDescription != null) { parEl.Add(MediaDescription.GetEl()); } if (MediaKeywords != null) { parEl.Add(MediaKeywords.GetEl()); } if (MediaThumbnails.Count > 0) { for (int i = 0; i < MediaThumbnails.Count; i++) { parEl.Add(MediaThumbnails[i].GetEl()); } } if (MediaCategories.Count > 0) { for (int i = 0; i < MediaCategories.Count; i++) { parEl.Add(MediaCategories[i].GetEl()); } } if (MediaHashes.Count > 0) { for (int i = 0; i < MediaHashes.Count; i++) { parEl.Add(MediaHashes[i].GetEl()); } } if (MediaPlayer != null) { parEl.Add(MediaPlayer.GetEl()); } if (MediaCredits.Count > 0) { for (int i = 0; i < MediaCredits.Count; i++) { parEl.Add(MediaCredits[i].GetEl()); } } if (MediaCopyright != null) { parEl.Add(MediaCopyright.GetEl()); } if (MediaTexts.Count > 0) { // sort the list MediaTexts.Sort(new SortMediaText()); // now iterate for (int i = 0; i < MediaTexts.Count; i++) { parEl.Add(MediaTexts[i].GetEl()); } } if (MediaRestrictions.Count > 0) { for (int i = 0; i < MediaRestrictions.Count; i++) { parEl.Add(MediaRestrictions[i].GetEl()); } } if (MediaCommunity != null) { parEl.Add(MediaCommunity.GetEl()); } if (MediaComments != null) { parEl.Add(MediaComments.GetEl()); } if (MediaEmbed != null) { parEl.Add(MediaEmbed.GetEl()); } if (MediaResponses != null) { parEl.Add(MediaResponses.GetEl()); } if (MediaBacklinks != null) { parEl.Add(MediaBacklinks.GetEl()); } if (MediaStatus != null) { parEl.Add(MediaStatus.GetEl()); } if (MediaPrices.Count > 0) { for (int i = 0; i < MediaPrices.Count; i++) { parEl.Add(MediaPrices[i].GetEl()); } } if (MediaLicense != null) { parEl.Add(MediaLicense.GetEl()); } if (MediaSubtitles.Count > 0) { for (int i = 0; i < MediaSubtitles.Count; i++) { parEl.Add(MediaSubtitles[i].GetEl()); } } if (MediaPeerLink != null) { parEl.Add(MediaPeerLink.GetEl()); } if (MediaRights != null) { parEl.Add(MediaRights.GetEl()); } if (MediaScenes != null) { parEl.Add(MediaScenes.GetEl()); } if (MediaLocations.Count > 0) { for (int i = 0; i < MediaLocations.Count; i++) { parEl.Add(MediaLocations[i].GetEl()); } } if (MediaValid != null) { parEl.Add(MediaValid.GetEl()); } }
public static SDP Parse(string data) { TimeDescription currentTd = null; MediaDescription currentMd = null; try { SDP sdp = new SDP(); var lines = Regex.Split(data, CRLF); foreach (var line in lines) { var trimmed = line.Trim(); if (trimmed.StartsWith("v=")) { var value = ParseKeyValueLine(trimmed, "Session Version"); decimal version; if (!decimal.TryParse(value, out version)) { // TODO(frank.lamar): warn. } else { sdp.Version = version; } } else if (trimmed.StartsWith("o=")) { sdp.Origin = SessionOriginator.Parse(trimmed); } else if (trimmed.StartsWith("s=")) { sdp.SessionName = ParseKeyValueLine(trimmed, "Session Name"); } else if (trimmed.StartsWith("i=")) { var info = ParseKeyValueLine(trimmed, "Session Information"); if (currentMd != null) { // Media Title at the media level currentMd.MediaTitle = info; } else { // Session information at the Session level. sdp.SessionInformation = info; } } else if (trimmed.StartsWith("u=")) { var value = ParseKeyValueLine(trimmed, "Session URI"); Uri uri; if (!Uri.TryCreate(value, UriKind.RelativeOrAbsolute, out uri)) { throw new SdpParseException($"Unable to parse malformed Session URI {value}"); } sdp.URI = uri; } else if (trimmed.StartsWith("e=")) { sdp.Email = ParseKeyValueLine(trimmed, "Session Email"); } else if (trimmed.StartsWith("p=")) { sdp.PhoneNumber = ParseKeyValueLine(trimmed, "Session Phone Number"); } else if (trimmed.StartsWith("c=")) { var connection = ConnectionInfo.Parse(trimmed); if (currentMd != null) { // Media Description connection currentMd.Connection = connection; } else { // Session level connection sdp.Connection = connection; } } else if (trimmed.StartsWith("b=")) { var bandwidth = BandwidthInfo.Parse(trimmed); if (currentMd != null) { // Media Description bandwidth currentMd.Bandwidths.Add(bandwidth); } else { // Session level bandwidth sdp.Bandwidths.Add(bandwidth); } } else if (trimmed.StartsWith("t=")) { currentTd = TimeDescription.Parse(trimmed); sdp.TimeDescriptions.Add(currentTd); } else if (trimmed.StartsWith("r=")) { if (currentTd != null) { currentTd.RepeatTimes.Add(RepeatTime.Parse(trimmed)); } // Just ignore the repeate time if no current time was defined. } else if (trimmed.StartsWith("z=")) { sdp.TimeZone = TimeZone.Parse(trimmed); } else if (trimmed.StartsWith("a=")) { if (currentMd != null) { // Media Description level attribute currentMd.Attributes.Add(Attribute.Parse(trimmed)); } else { // Session level attribute sdp.Attributes.Add(Attribute.Parse(trimmed)); } } else if (trimmed.StartsWith("m=")) { currentMd = MediaDescription.Parse(trimmed); sdp.MediaDescriptions.Add(currentMd); } } // end foreach... return(sdp); } catch (Exception e) { if (e is SdpParseException) { throw e; } throw new SdpParseException("Failed to parse session description", e); } }