private string GetAllAudioTracks() { if (Player.State == PlayerState.Playing || Player.State == PlayerState.Paused) { MediaTrack activeTrack = null; if (Media.AudioTrack != null) { activeTrack = Media.AudioTrack; } var audioTracks = Media.AudioTracks; int counter = 1; StringBuilder audioStringBuilder = new StringBuilder(); foreach (var track in audioTracks) { if (counter > 1) { audioStringBuilder.Append("]]"); } audioStringBuilder.Append(counter + ">>" + track.Description + ">>" + track.Type); if (activeTrack != null && track.Description == activeTrack.Description) { audioStringBuilder.Append(">>True"); } else { audioStringBuilder.Append(">>False"); } counter++; } return("AudioTracks|" + audioStringBuilder); } return(string.Empty); }
/// <summary> /// Create the local sender track from the current media track source if that source /// is active and enabled. Otherwise do nothing. /// </summary> private void CreateSender() { Debug.Assert(_source != null); if (_source.isActiveAndEnabled) { if (MediaKind == MediaKind.Audio) { var audioSource = (_source as AudioTrackSource); var initConfig = new LocalAudioTrackInitConfig { trackName = _senderTrackName }; _senderTrack = LocalAudioTrack.CreateFromSource(audioSource.Source, initConfig); } else { Debug.Assert(MediaKind == MediaKind.Video); var videoSource = (_source as VideoTrackSource); var initConfig = new LocalVideoTrackInitConfig { trackName = _senderTrackName }; _senderTrack = LocalVideoTrack.CreateFromSource(videoSource.Source, initConfig); } } }
void DeleteTrackButton_Click(object sender, EventArgs e) { //Remove the track data from the database, which also removes the MediaFile data from the data base. MediaTrack.Remove(theTrack); RedirectToEditPlayerPage(); }
void TracksGridView_RowCommand(object sender, GridViewCommandEventArgs e) { Int32 trackOrder = 0; switch (e.CommandName) { case "MoveUp": trackOrder = Convert.ToInt32(e.CommandArgument); MediaTrack.MoveTrackUp(thePlayer.PlayerId, trackOrder); RedirectToThisPage(); break; case "MoveDown": trackOrder = Convert.ToInt32(e.CommandArgument); MediaTrack.MoveTrackDown(thePlayer.PlayerId, trackOrder); RedirectToThisPage(); break; case "EditTrack": EditTrack(e.CommandArgument.ToString()); break; default: break; } }
/// <inheritdoc/> protected internal override void OnUnpaired(MediaTrack track) { Debug.Assert(track is RemoteVideoTrack); Debug.Assert(VideoTrack == track); VideoTrack = null; VideoStreamStopped.Invoke(VideoTrack); }
private string GetAllVideoTracks() { if (Player.State != PlayerState.Playing && Player.State != PlayerState.Paused) { return(string.Empty); } MediaTrack activeTrack = null; if (Media.VideoTrack != null) { activeTrack = Media.VideoTrack; } var videoTracks = Media.VideoTracks; var counter = 1; var videoStringBuilder = new StringBuilder(); foreach (var track in videoTracks) { if (counter > 1) { videoStringBuilder.Append("]]"); } videoStringBuilder.Append(counter + ">>" + track.Description + ">>" + track.Type); if (activeTrack != null && track.Description == activeTrack.Description) { videoStringBuilder.Append(">>True"); } else { videoStringBuilder.Append(">>False"); } counter++; } return("VideoTracks|" + videoStringBuilder); }
internal void OnUnpaired(MediaTrack track) { Debug.Assert(track != null); // This is called by the TrackRemoved event, which can be fired sometimes even // though we did not have any opportunity yet to pair. So only unpair if we did. // In details, the case is the answering peer being in sendonly mode, yet created // automatically by the implementation during SetRemoteDescription() in recvonly // mode (per the WebRTC spec). So the SetDirection(sendonly) triggers the TrackRemoved // event, but the pairing was never done because SetDirection() is called before // the receiver is updated. // Callbacks must be called on the main thread. _peer.InvokeOnAppThread(() => { if (_receiver != null) { bool wasReceiving = _remoteTrack != null; if (wasReceiving) { Debug.Assert(_remoteTrack == track); _receiver.OnUnpaired(_remoteTrack); } } _remoteTrack = null; }); }
private string GetAllSubtitleTracks() { if (Player.State == PlayerState.Playing || Player.State == PlayerState.Paused) { MediaTrack activeSub = null; if (Media.SubtitleTrack != null) { activeSub = Media.SubtitleTrack; } var subtitles = Media.SubtitleTracks; int counter = 1; StringBuilder subSb = new StringBuilder(); foreach (var sub in subtitles) { if (counter > 1) { subSb.Append("]]"); } subSb.Append(counter + ">>" + sub.Description + ">>" + sub.Type); if (activeSub != null && sub.Description == activeSub.Description) { subSb.Append(">>True"); } else { subSb.Append(">>False"); } counter++; } return("Subtitles|" + subSb); } return(string.Empty); }
internal void UpdateReceiverPairingIfNeeded() { Debug.Assert(Transceiver != null); // Callbacks must be called on the main Unity app thread. _peer.EnsureIsMainAppThread(); var newRemoteTrack = Transceiver.RemoteTrack; if (_receiver != null) { bool wasReceiving = _remoteTrack != null; bool isReceiving = newRemoteTrack != null; if (isReceiving && !wasReceiving) { // Transceiver started receiving, and user actually wants to receive _receiver.OnPaired(newRemoteTrack); } else if (!isReceiving && wasReceiving) { // Transceiver stopped receiving (user intent does not matter here) _receiver.OnUnpaired(_remoteTrack); } } _remoteTrack = newRemoteTrack; }
public void OnMediaReady(uint mid, WmeDirection direction, WmeSessionType mediaType, MediaTrack pTrack) { if (direction == WmeDirection.WmeDirection_Send) { if (mid > 10) { return; } if (mediaType == WmeSessionType.WmeSessionType_Audio) { mLocalAudio = pTrack; } else if (mediaType == WmeSessionType.WmeSessionType_Video) { mLocalVideo = pTrack; //pTrack.AddRenderWindow(mVideoForm.GetSelfView()); //pTrack.AddRenderWindow(SelfViewPictureBox.Handle); //pTrack.AddImageRender(LocalVideoImage); } else if (mediaType == WmeSessionType.WmeSessionType_ScreenShare) { mLocalShare = pTrack; if (mid == 2) { mLocalShare.AddScreenSource(ScreenSourceManager.Instance.defaultSource()); } } pTrack.Start(false); } else { if (mid < 10) { return; } if (mediaType == WmeSessionType.WmeSessionType_Audio) { mRemoteAudio = pTrack; } else if (mediaType == WmeSessionType.WmeSessionType_Video) { mRemoteVideo = pTrack; pTrack.AddImageRender(RemoteVideoImage1); //pTrack.AddImageRender(RemoteVideoImage2); //pTrack.AddImageRender(RemoteVideoImage3); //pTrack.AddImageRender(RemoteVideoImage4); } else if (mediaType == WmeSessionType.WmeSessionType_ScreenShare) { mRemoteShare = pTrack; if (mid == 2000) { //pTrack.AddRenderWindow(ShareViewPictureBox.Handle); pTrack.AddImageRender(ShareViewImage); } } pTrack.Start(false); } }
/// <inheritdoc/> protected internal override void OnPaired(MediaTrack track) { var remoteAudioTrack = (RemoteAudioTrack)track; Debug.Assert(Track == null); AudioTrack = remoteAudioTrack; AudioStreamStarted.Invoke(remoteAudioTrack); }
void UpdateTrackButton_Click(object sender, EventArgs e) { theTrack.Name = TrackNameTextBox.Text; theTrack.Artist = ArtistTextBox.Text; MediaTrack.Update(theTrack); RedirectToEditPlayerPage(); }
public string GetCodecDescription(MediaTrack mediaTrack) { IntPtr pStr = LibVlcMethods.libvlc_media_get_codec_description((libvlc_track_type_t)mediaTrack.TrackType, mediaTrack.iCodec); string desc = Marshal.PtrToStringAnsi(pStr); LibVlcMethods.libvlc_free(pStr); return(desc); }
public static void Track(this IMediaTracker tracker, MediaTrack track) { if (track == null) { return; } tracker.TrackMany(new[] { track }); }
/// <summary> /// Free-threaded callback invoked by the owning peer connection when a track is unpaired /// from this receiver. /// </summary> internal override void OnUnpaired(MediaTrack track) { Debug.Assert(track is RemoteAudioTrack); Debug.Assert(Track == track); _track = null; // Streaming will be stopped from the main Unity app thread, both to avoid locks on public // properties and so that listeners of the event can directly access Unity objects // from their handler function. }
public RtpSession(MediaTrack track, Session session, IRtpSource source) { _started = false; _disposed = false; _source = source; Pipelines = new List <MediaPipeline>(); Track = track; Session = session; }
/// <inheritdoc/> void IMediaReceiverInternal.OnPaired(MediaTrack track) { var remoteAudioTrack = (RemoteAudioTrack)track; Debug.Assert(Track == null); _track = remoteAudioTrack; // Streaming will be started from the main Unity app thread, both to avoid locks on public // properties and so that listeners of the event can directly access Unity objects // from their handler function. }
protected virtual void TrackSingle(BaseEntity entity, int mediaFileId, MediaTrackOperation operation) { Guard.NotNull(entity, nameof(entity)); if (mediaFileId < 1 || entity.IsTransientRecord()) { return; } var file = _dbContext.Set <MediaFile>().Find(mediaFileId); if (file != null) { var albumName = _folderService.FindAlbum(file)?.Value.Name; if (albumName.IsEmpty()) { throw new InvalidOperationException("Cannot track a media file that is not assigned to any album."); } var track = new MediaTrack { EntityId = entity.Id, EntityName = entity.GetEntityName(), MediaFileId = mediaFileId, Album = albumName }; if (operation == MediaTrackOperation.Track) { file.Tracks.Add(track); } else { var dbTrack = file.Tracks.FirstOrDefault(x => x == track); if (dbTrack != null) { file.Tracks.Remove(track); _dbContext.ChangeState(dbTrack, System.Data.Entity.EntityState.Deleted); } } if (file.Tracks.Count > 0) { // A file with tracks can NEVER be transient file.IsTransient = false; } else if (_makeFilesTransientWhenOrphaned) { // But an untracked file can OPTIONALLY be transient file.IsTransient = true; } _dbContext.SaveChanges(); } }
void AddTrackButton_Click(object sender, EventArgs e) { if (SelectedFilesListBox.Items.Count > 0) { MediaTrack mt = new MediaTrack(); //Populate the MediaTrack object. mt.PlayerId = thePlayer.PlayerId; mt.TrackType = thePlayer.PlayerType; mt.UserGuid = SiteUtils.GetCurrentSiteUser().UserGuid; mt.Name = TrackNameTextBox.Text; mt.Artist = ArtistTextBox.Text; mt.TrackOrder = TracksGridView.Rows.Count + 1; try { //Add the MediaTrack mt.TrackId = MediaTrack.Add(mt); //Add the MediaFiles foreach (ListItem filePath in SelectedFilesListBox.Items) { MediaFile mf = new MediaFile(); mf.TrackId = mt.TrackId; if (filePath.Text.StartsWith("http")) { mf.FilePath = filePath.Text; } else { mf.FilePath = "~" + filePath.Text; } mf.UserGuid = mt.UserGuid; MediaFile.Add(mf); } RedirectToThisPage(); } catch (Exception ex) { //Perform backout actions of anything already saved //The Forgien key of the MediaFiles table is set up with a Cascading delete, so //the deleting of the MediaTracks will also delete any related MediaFiles. MediaTrack.RemoveForPlayer(thePlayer.PlayerId); //Display error to user AddTrackErrorLabel.Text = ex.Message; } } else { AtLeastOneFileSelectedValidator.IsValid = false; AddTrackErrorLabel.Text = MediaPlayerResources.AtLeastOneFileSelectedValidatorErrorMessage; } }
private void DestroySender() { Debug.Assert(_senderTrack != null); if (MediaKind == MediaKind.Audio) { ((LocalAudioTrack)_senderTrack).Dispose(); } else { Debug.Assert(MediaKind == MediaKind.Video); ((LocalVideoTrack)_senderTrack).Dispose(); } _senderTrack = null; }
/// <summary> /// Internal callback when the underlying source providing media frames to the sender track /// is destroyed, and therefore the local media track needs to be destroyed too. /// </summary> /// <seealso cref="AudioTrackSource.OnDisable"/> /// <seealso cref="VideoTrackSource.OnDisable"/> internal void OnSourceDestroyed() { if (_senderTrack is LocalAudioTrack audioTrack) { audioTrack.Dispose(); } else if (_senderTrack is LocalVideoTrack videoTrack) { videoTrack.Dispose(); } _senderTrack = null; // Clear source, which is about to be destroyed Source = null; }
public async Task StopAsync() { Debug.WriteLine("MediaPlayerManager.StopAsync()"); var fireTrackChanged = false; using (await _asyncLock.LockAsync(_cancellationToken).ConfigureAwait(false)) { if (null != _mediaStreamFacade) { var stopped = false; try { stopped = await _mediaStreamFacade.RequestStopAsync(TimeSpan.FromSeconds(5), _cancellationToken).ConfigureAwait(false); } catch (Exception ex) { Debug.WriteLine("MediaPlayerManager.StopAsync() RequestStopAsync() failed: " + ex.ExtendedMessage()); } if (!stopped) { try { await CleanupMediaStreamFacadeAsync().ConfigureAwait(false); } catch (Exception ex) { Debug.WriteLine("MediaPlayerManager.StopAsync() CleanupMediaStreamFacadeAsync() failed: " + ex.ExtendedMessage()); } } } if (null != _track) { _track = null; fireTrackChanged = true; } await CloseMediaSourceAsync().WithCancellation(_cancellationToken).ConfigureAwait(false); } if (fireTrackChanged) { FireTrackChanged(); } }
/// <inheritdoc/> void IMediaReceiverInternal.OnPaired(MediaTrack track) { var remoteVideoTrack = (RemoteVideoTrack)track; // Enqueue invoking from the main Unity app thread, both to avoid locks on public // properties and so that listeners of the event can directly access Unity objects // from their handler function. InvokeOnAppThread(() => { Debug.Assert(Track == null); Track = remoteVideoTrack; _isLive = true; IsStreaming = true; VideoStreamStarted.Invoke(this); }); }
/// <summary> /// Free-threaded callback invoked by the owning peer connection when a track is paired /// with this receiver, which enqueues the <see cref="AudioSource.AudioStreamStarted"/> /// event to be fired from the main Unity app thread. /// </summary> internal override void OnPaired(MediaTrack track) { var remoteAudioTrack = (RemoteAudioTrack)track; // Enqueue invoking from the main Unity app thread, both to avoid locks on public // properties and so that listeners of the event can directly access Unity objects // from their handler function. _mainThreadWorkQueue.Enqueue(() => { Debug.Assert(Track == null); Track = remoteAudioTrack; IsLive = true; AudioStreamStarted.Invoke(this); IsStreaming = true; }); }
/// <summary> /// Free-threaded callback invoked by the owning peer connection when a track is unpaired /// from this receiver, which enqueues the <see cref="VideoSource.VideoStreamStopped"/> /// event to be fired from the main Unity thread. /// </summary> internal override void OnUnpaired(MediaTrack track) { Debug.Assert(track is RemoteVideoTrack); // Enqueue invoking from the main Unity app thread, both to avoid locks on public // properties and so that listeners of the event can directly access Unity objects // from their handler function. _mainThreadWorkQueue.Enqueue(() => { Debug.Assert(Track == track); Track = null; IsStreaming = false; IsLive = false; VideoStreamStopped.Invoke(this); }); }
/// <inheritdoc/> void IMediaReceiverInternal.OnUnpaired(MediaTrack track) { Debug.Assert(track is RemoteAudioTrack); // Enqueue invoking from the main Unity app thread, both to avoid locks on public // properties and so that listeners of the event can directly access Unity objects // from their handler function. InvokeOnAppThread(() => { Debug.Assert(Track == track); Track = null; _isLive = false; AudioStreamStopped.Invoke(this); IsStreaming = false; }); }
private bool GetRedirectUri(RtspClient client, MediaTrack track, out Uri uri) { var transport = TransportHeader.CreateBuilder() .Type(TransportType.RtspInterleaved) .InterleavedChannels(0, 1) .Build(); var method = RtspRequest.RtspMethod.SETUP; var res = CheckResponse(client.Send(RtspRequest.CreateBuilder() .Method(method) .Uri(track.ControlUri) .AddHeader(RtspHeaders.Names.TRANSPORT, transport.ToString()) .Build()), method); if (!res.Headers.ContainsKey(RtspHeaders.Names.SESSION)) { uri = null; return(false); } var rtspSession = Session.Parse(res.Headers[RtspHeaders.Names.SESSION]); method = RtspRequest.RtspMethod.PLAY; res = CheckResponse(client.Send(RtspRequest.CreateBuilder() .Method(method) .Uri(track.ControlUri) .AddHeader(RtspHeaders.Names.SESSION, rtspSession.ID) .Build()), method); var status = res.ResponseStatus; if (status.Is(RtspResponse.Status.MovedPermanently) || status.Is(RtspResponse.Status.MovedTemporarily)) { // We received a redirect lets get the uri and return it. if (res.Headers.ContainsKey(RtspHeaders.Names.LOCATION)) { var value = res.Headers[RtspHeaders.Names.LOCATION]; return(Uri.TryCreate(value, UriKind.RelativeOrAbsolute, out uri)); } } uri = null; return(false); }
internal void OnUnpaired(MediaTrack track) { Debug.Assert(track != null); Debug.Assert(Transceiver != null); Debug.Assert(Transceiver.RemoteTrack == null); // already removed // This is called by the TrackRemoved event, which can be fired sometimes even // though we did not have any opportunity yet to pair. So only unpair if we did. // In details, the case is the answering peer being in sendonly mode, yet created // automatically by the implementation during SetRemoteDescription() in recvonly // mode (per the WebRTC spec). So the SetDirection(sendonly) triggers the TrackRemoved // event, but the pairing was never done because SetDirection() is called before // the received is updated. if (_isReceiverPaired) { _peer.InvokeOnAppThread(() => _receiver.OnUnpaired(track)); _isReceiverPaired = false; } }
private MediaTrack[] MapTextTracks(string textTracks) { List <MediaTrack> tracks = new List <MediaTrack>(); if (!string.IsNullOrEmpty(textTracks)) { string[] tracksInfo = textTracks.Split(Constants.MultiItemsSeparator); foreach (string trackInfo in tracksInfo) { MediaTrack track = new MediaTrack(); string[] textTrack = trackInfo.Split(Constants.MultiItemSeparator); track.Type = textTrack[0]; track.Source = textTrack[1]; track.Language = StreamFile.GetLanguageCode(track.Source); tracks.Add(track); } } return(tracks.ToArray()); }
private void addTrack(string path, bool isTutoPatch, int episodeNumber, EditorModel model) { var seconds = Model.WindowState.TimeSet; var track = new MediaTrack(path, Model.ScaleInfo, isTutoPatch); track.ModelHash = model == null ? "" : model.Montage.RawVideoHash; track.EpisodeNumber = episodeNumber; track.LeftShiftInSeconds = seconds; track.TopShift = Top; track.DurationInPixels = 10; Model.PropertyChanged += (s, a) => track.NotifyScaleChanged(); Model.MediaTracks.Add(track); PatchWindow.MediaOpened += SetPatchDuration; PatchWindow.Stop(); PatchWindow.Source = null; PatchWindow.Source = new Uri(path); PatchWindow.Play(); //need to fire event to get duration PatchWindow.Pause(); }
public async Task StopAsync() { Debug.WriteLine("MediaPlayerManager.StopAsync()"); var fireTrackChanged = false; using (await _asyncLock.LockAsync(_cancellationToken).ConfigureAwait(false)) { if (null != _mediaStreamFacade) { var stopped = false; try { stopped = await _mediaStreamFacade.RequestStopAsync(TimeSpan.FromSeconds(5), _cancellationToken).ConfigureAwait(false); } catch (Exception ex) { Debug.WriteLine("MediaPlayerManager.StopAsync() RequestStopAsync() failed: " + ex.ExtendedMessage()); } if (!stopped) { try { await CleanupMediaStreamFacadeAsync().ConfigureAwait(false); } catch (Exception ex) { Debug.WriteLine("MediaPlayerManager.StopAsync() CleanupMediaStreamFacadeAsync() failed: " + ex.ExtendedMessage()); } } } if (null != _track) { _track = null; fireTrackChanged = true; } await CloseMediaSourceAsync().WithCancellation(_cancellationToken).ConfigureAwait(false); } if (fireTrackChanged) FireTrackChanged(); }
/* public void GetSubitems() { return GetSubitemsFunction.Delegate(InstancePointer); } */ /// <summary> /// 获取媒体的基本流的描述,注意,在调用该方法之前你需要首先调用 <see cref="VlcMedia.Parse"/> 方法,或者至少播放一次. /// 否则,你将的得到一个空数组 /// </summary> public MediaTrack[] GetTracks() { var pointer = IntPtr.Zero; uint count = GetTracksFunction.Delegate(InstancePointer, ref pointer); if(pointer == IntPtr.Zero) { String ex = VlcError.GetErrorMessage(); throw new Exception(ex); } var result = new MediaTrack[count]; var temp = pointer; for (int i = 0; i < count; i++) { var p = Marshal.ReadIntPtr(temp); result[i] = (MediaTrack)Marshal.PtrToStructure(p, typeof(MediaTrack)); temp += Marshal.SizeOf(typeof(IntPtr)); } ReleaseTracksFunction.Delegate(pointer, count); return result; }
async Task StartPlaybackAsync(MediaTrack track) { Debug.WriteLine("MediaPlayerManager.StartPlaybackAsync() " + (null == track ? "<null>" : track.ToString())); try { using (await _asyncLock.LockAsync(_cancellationToken).ConfigureAwait(false)) { _track = null; if (null == track || null == track.Url) { await CloseMediaSourceAsync().WithCancellation(_cancellationToken).ConfigureAwait(false); FireTrackChanged(); return; } var url = track.Url; BackgroundSettings.Track = url; if (url.HasExtension(".pls")) { url = await GetUrlFromPlsPlaylistAsync(url).ConfigureAwait(false); } _track = track; FireTrackChanged(); try { _mediaPlayer.AutoPlay = false; if (track.UseNativePlayer) { _mediaPlayer.SetUriSource(url); } else { await InitializeMediaStreamAsync().ConfigureAwait(false); var mss = await _mediaStreamFacade.CreateMediaStreamSourceAsync(url, _cancellationToken).ConfigureAwait(false); if (null == mss) { Debug.WriteLine("MediaPlayerManager.StartPlaybackAsync() unable to create media stream source"); return; } _mediaPlayer.SetMediaSource(mss); } return; } catch (OperationCanceledException) { } catch (Exception ex) { Debug.WriteLine("MediaPlayerManager.StartPlaybackAsync() source setup failed: " + ex.Message); } await CloseMediaSourceAsync().WithCancellation(_cancellationToken).ConfigureAwait(false); } } catch (Exception ex) { Debug.WriteLine("MediaPlayerManager.StartPlaybackAsync() failed: " + ex.Message); } }