/// <summary> /// Handles the SmoothStreamingErrorOccurred event. Logs the exception. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The event args instance containg the exception data.</param> private void MediaElement_SmoothStreamingErrorOccurred(IAdaptiveMediaPlugin adaptiveMediaPlugin, Exception exception) { if (exception != null) { this.logger.Log("PlayerControl", exception); } }
void ActiveMediaPlugin_AdProgressUpdated(IAdaptiveMediaPlugin mp, IAdContext adContext, AdProgress progress) { switch (progress) { case AdProgress.Start: startTime = DateTime.Now; OnAdVideoStart(); break; case AdProgress.FirstQuartile: OnAdVideoFirstQuartile(); break; case AdProgress.Midpoint: OnAdVideoMidpoint(); break; case AdProgress.ThirdQuartile: OnAdVideoThirdQuartile(); break; case AdProgress.Complete: OnAdVideoComplete(); break; } }
private void MediaElement_ManifestReady(IAdaptiveMediaPlugin adaptiveMediaPlugin) { this.manifestReady = true; this.SelectTracks(); this.UpdateAvailableAudioTracks(); this.SelectPlaylistAudioStream(); this.SelectPlaylistVideoStream(); }
private void SetPluginForManagers() { int index = 0; this.InvokeMethodForAllMediaData( md => { IAdaptiveMediaPlugin plugin = md.MediaPlugin as IAdaptiveMediaPlugin; this.rubberBandingManagers[index].SetAdaptivePlugin(plugin); this.transitionsManagers[index].SetAdaptivePlugin(plugin); index++; }); }
void AdaptiveMediaPlugin_VideoPlaybackTrackChanged(IAdaptiveMediaPlugin arg1, IMediaTrack videoPlaybackTrack) { //When the SSME changes its playback bitrate, we need to re-set the maximum width and height of the //SSME explicitly. if (videoPlaybackTrack.Attributes.ContainsKey("MaxWidth")) { ssmeMaxWidth = Convert.ToDouble(videoPlaybackTrack.Attributes["MaxWidth"]); } if (videoPlaybackTrack.Attributes.ContainsKey("MaxHeight")) { ssmeMaxHeight = Convert.ToDouble(videoPlaybackTrack.Attributes["MaxHeight"]); } SetVideoProperties(); }
/// <summary> /// Registers a plugin so that it can be managed by this BalancedPriorityGroupMonitor. /// </summary> /// <param name="plugin">The plugin to register.</param> public void RegisterPlugin(IAdaptiveMediaPlugin plugin) { lock (_registeredPlugins) { if (!_registeredPlugins.Contains(plugin)) { _registeredPlugins.Add(plugin); } if (!_dispatcherTimer.IsEnabled) { _dispatcherTimer.Start(); } } }
/// <summary> /// Unregisters a plugin so that it is no longer managed by this BalancedPriorityGroupMonitor. /// </summary> /// <param name="plugin">The plugin to unregister.</param> public void UnregisterPlugin(IAdaptiveMediaPlugin plugin) { lock (_registeredPlugins) { if (_registeredPlugins.Contains(plugin)) { _registeredPlugins.Remove(plugin); } if (_registeredPlugins.Count == 0 && _dispatcherTimer.IsEnabled) { _dispatcherTimer.Stop(); } } }
private void OnStreamSelected(IAdaptiveMediaPlugin mediaPlugin, IMediaStream stream) { try { if ((stream.Type == StreamType.Binary || stream.Type == StreamType.Text) && stream.AvailableTracks.Count() > 0) { IMediaTrack track = stream.AvailableTracks.First(); this.rceMediaPlugin.DownloadStreamData(track); } } catch (Exception ex) { } }
private static bool IsPluginReadyForBitrateIncrease(IAdaptiveMediaPlugin plugin, long maxAllowedBitrate) { double droppedFramePercentage = plugin.DroppedFramesPerSecond / (plugin.DroppedFramesPerSecond + plugin.RenderedFramesPerSecond); long highestPossibleBitrate = plugin.VideoDownloadTrack.ParentStream.SelectedTracks .Select(i => i.Bitrate) .Where(i => i <= maxAllowedBitrate) .DefaultIfEmpty() .Max(); long currentPlaybackBitrate = plugin.VideoPlaybackTrack != null ? plugin.VideoPlaybackTrack.Bitrate : 0; return(currentPlaybackBitrate == highestPossibleBitrate && droppedFramePercentage <= TolerableDroppedFramesPercentage); }
private void OnDownloadStreamDataCompleted(IAdaptiveMediaPlugin mediaPlugin, IMediaTrack track, IStreamDownloadResult result) { try { if (result != null && result.Stream != null) { var data = new byte[result.Stream.Length]; result.Stream.Read(data, 0, data.Length); result.Stream.Flush(); this.ParseTimelineEvent(data); } } catch (Exception ex) { } }
/// <summary> /// Registers the plugin so that it can be managed. /// </summary> /// <param name="plugin">The plugin to register.</param> /// <param name="priority">The priority of the specified plugin.</param> public void RegisterPlugin(IAdaptiveMediaPlugin plugin, int priority) { if (_settings == null) { _settings = ReadSettings(); } BalancedPriorityGroupMonitor priorityGroup = _priorityGroups.Where(i => i.Priority == priority) .FirstOrDefault(); if (priorityGroup == null) { priorityGroup = new BalancedPriorityGroupMonitor(priority, _settings); priorityGroup.AllowBitrateIncreases = true; _priorityGroups.Add(priorityGroup); } priorityGroup.RegisterPlugin(plugin); }
void activeMediaPlugin_ManifestReady(IAdaptiveMediaPlugin activeMediaPlugin) { activeMediaPlugin.ManifestReady -= activeMediaPlugin_ManifestReady; // find all MAST streams selectedMastStreams = activeMediaPlugin.CurrentSegment.AvailableStreams.Where(i => IsMastStream(i)).ToList(); if (selectedMastStreams.Any()) { // wire up the DataReceived event player.DataReceived += Player_DataReceived; // select all MAST streams activeMediaPlugin.ModifySegmentSelectedStreams(activeMediaPlugin.CurrentSegment, selectedMastStreams, new List <IMediaStream>()); } else { // no MAST streams were found, release the player so playback can continue base.ReleasePlayer(); } }
void activeMediaPlugin_ManifestReady(IAdaptiveMediaPlugin activeMediaPlugin) { activeMediaPlugin.ManifestReady -= activeMediaPlugin_ManifestReady; // find all MAST streams selectedMastStreams = activeMediaPlugin.CurrentSegment.AvailableStreams.Where(i => IsMastStream(i)).ToList(); if (selectedMastStreams.Any()) { // wire up the DataReceived event player.DataReceived += Player_DataReceived; // select all MAST streams activeMediaPlugin.ModifySegmentSelectedStreams(activeMediaPlugin.CurrentSegment, selectedMastStreams, new List<IMediaStream>()); } else { // no MAST streams were found, release the player so playback can continue base.ReleasePlayer(); } }
private void OnManifestReady(IAdaptiveMediaPlugin obj) { if (this.rceMediaPlugin != null && this.rceMediaPlugin.CurrentSegment != null) { // Get currently selected streams List <IMediaStream> currentlySelectedStreams = this.rceMediaPlugin.CurrentSegment.SelectedStreams.ToList(); var selectedStreams = this.UseAllLogStreams ? this.rceMediaPlugin.CurrentSegment.AvailableStreams.Where( x => x.IsSparseStream).ToList() : this.rceMediaPlugin.CurrentSegment.AvailableStreams.Where( i => this.LogStreams.Contains(i.Name) && !currentlySelectedStreams.Contains(i)) .ToList(); if (selectedStreams.Count > 0) { selectedStreams.ForEach(currentlySelectedStreams.Add); this.rceMediaPlugin.SetSegmentSelectedStreams(this.rceMediaPlugin.CurrentSegment, currentlySelectedStreams); } } }
void ActiveMediaPlugin_AdStateChanged(IAdaptiveMediaPlugin arg1, IAdContext arg2) { switch (CurrentAdContext.CurrentAdState) { case MediaPluginState.Paused: case MediaPluginState.Buffering: if (!isLoaded) { OnAdLoaded(); isLoaded = true; } break; case MediaPluginState.Playing: if (!isStarted) { OnAdImpression(); OnAdStarted(); isStarted = true; } break; } }
private void MediaPlugin_ManifestReady(IAdaptiveMediaPlugin adaptiveMediaPlugin) { const string FourCCAttributeName = "FourCC"; const string CodecPrivateDataAttributeName = "CodecPrivateData"; var currentSegment = adaptiveMediaPlugin.CurrentSegment; if (currentSegment != null) { var firstVideoStream = currentSegment.SelectedStreams.Where(s => s.Type == StreamType.Video).FirstOrDefault(); if (firstVideoStream != null) { var fourCC = firstVideoStream.FourCC; var codecPrivateData = string.Empty; if (string.IsNullOrWhiteSpace(fourCC) && !firstVideoStream.Attributes.TryGetValue(CodecPrivateDataAttributeName, out codecPrivateData)) { var videoTrack = firstVideoStream.SelectedTracks.Where(t => t.Attributes.ContainsKey(FourCCAttributeName) && t.Attributes.ContainsKey(CodecPrivateDataAttributeName)).FirstOrDefault(); if (videoTrack != null) { fourCC = videoTrack.Attributes[FourCCAttributeName]; codecPrivateData = videoTrack.Attributes[CodecPrivateDataAttributeName]; } } try { var frameRate = this.codecPrivateDataParser.GetFrameRate(fourCC, codecPrivateData); this.OnFrameRateParsed(frameRate); } catch (Exception ex) { this.logger.Log("PlayerControl", ex); } } } }
private static bool IsPluginProblematic(IAdaptiveMediaPlugin plugin, long maxAllowedBitrate) { double droppedFramePercentage = plugin.DroppedFramesPerSecond / (plugin.DroppedFramesPerSecond + plugin.RenderedFramesPerSecond); int subObtimalTrackDifference = plugin.VideoDownloadTrack != null ? plugin.VideoDownloadTrack.ParentStream.AvailableTracks .Where(i => i.Bitrate > plugin.VideoDownloadTrack.Bitrate && i.Bitrate <= maxAllowedBitrate) .Count() : 0; if (plugin.VideoDownloadTrack != null) { Debug.WriteLine( "SOTD: {0} VideoDownloadTrack.Bitrate: {1} MaxAllowedBitrate: {2} Dropped Frame Percentage: {3}", subObtimalTrackDifference, plugin.VideoDownloadTrack.Bitrate, maxAllowedBitrate, droppedFramePercentage); } return(subObtimalTrackDifference > TolerableSubOptimalTrackDifferences || droppedFramePercentage > TolerableDroppedFramesPercentage); }
private void MediaPlugin_AdaptiveStreamingErrorOccurred(IAdaptiveMediaPlugin mediaPlugin, Exception err) { SendLogEntry(KnownLogEntryTypes.AdaptiveStreamingErrorOccurred, message: err.Message); }
void ActiveMediaPlugin_AdError(IAdaptiveMediaPlugin mp, IAdContext adContext) { if (adContext != null && adContext.Data != this) return; OnAdError(new AdMessageEventArgs("An unknown error occured while playing the ad clip.")); }
private void MediaPlugin_StreamUnselected(IAdaptiveMediaPlugin mediaPlugin, IMediaStream stream) { OnStreamUnselected(mediaPlugin, stream); }
void ActiveMediaPlugin_AdError(IAdaptiveMediaPlugin mp, IAdContext adContext) { OnAdError(new AdMessageEventArgs("An unknown error occured while playing the ad clip.")); }
void ActiveMediaPlugin_AdClickThrough(IAdaptiveMediaPlugin mediaPlugin, IAdContext adContext) { OnAdClickThru(new AdClickThruEventArgs(adContext.ClickThrough.OriginalString, AdSource.Id, true)); }
//private void MediaPlugin_VideoPlaybackTrackChanged(IAdaptiveMediaPlugin adaptiveMediaPlugin, IMediaTrack track) //{ // Dispatcher.BeginInvoke(() => OnVideoPlaybackTrackChanged(track.Bitrate)); //} private void MediaPlugin_VideoDownloadTrackChanged(IAdaptiveMediaPlugin adaptiveMediaPlugin, IMediaTrack track) { Dispatcher.BeginInvoke(() => OnVideoDownloadTrackChanged(track.Bitrate)); }
void ActiveMediaPlugin_AdClickThrough(IAdaptiveMediaPlugin mediaPlugin, IAdContext adContext) { if (adContext != null && adContext.Data != this) return; OnAdClickThru(new AdClickThruEventArgs(adContext.ClickThrough.OriginalString, AdSource.Id, true)); }
private void MediaPlugin_StreamDataAdded(IAdaptiveMediaPlugin mediaPlugin, IMediaStream stream, IDataChunk dataChunk) { Dispatcher.BeginInvoke(() => OnStreamDataAdded(mediaPlugin, stream, dataChunk)); }
private void MediaPlugin_StreamDataRemoved(IAdaptiveMediaPlugin mediaPlugin, IMediaStream mediaStream, TimeSpan timeStamp) { SendLogEntry(KnownLogEntryTypes.StreamDataRemoved, extendedProperties: new Dictionary<string, object> { { "StreamName", mediaStream.Name } }); }
private void MediaPlugin_DownloadStreamDataFailed(IAdaptiveMediaPlugin mediaPlugin, IMediaTrack track, IDataChunk dataChunk, Exception error) { string message = string.Format(SilverlightMediaFrameworkResources.GenericErrorOccurredLogMessage, "MediaPlugin_DownloadStreamDataFailed", error.Message); SendLogEntry(KnownLogEntryTypes.DownloadStreamDataFailed, LogLevel.Error, message); }
private void MediaPlugin_StreamSelectionFailed(IAdaptiveMediaPlugin mediaPlugin, IEnumerable<IMediaStream> attemptedSelection, Exception error) { string message = string.Format(SilverlightMediaFrameworkResources.GenericErrorOccurredLogMessage, "MediaPlugin_StreamSelectionFailed", error.Message); SendLogEntry(KnownLogEntryTypes.StreamSelectionFailed, LogLevel.Error, message); }
private void MediaPlugin_DownloadStreamDataCompleted(IAdaptiveMediaPlugin mediaPlugin, IMediaTrack track, IStreamDownloadResult result) { //Dispatcher.BeginInvoke(() => OnDownloadStreamDataCompleted(mediaPlugin, track, result)); OnDownloadStreamDataCompleted(mediaPlugin, track, result); }
protected virtual void OnDownloadStreamDataCompleted(IAdaptiveMediaPlugin mediaPlugin, IMediaTrack track, IStreamDownloadResult result) { try { if (DataReceived != null) { int length = (int)result.Stream.Length; var data = new byte[length]; int count; int sum = 0; do { count = result.Stream.Read(data, sum, length - sum); sum += count; } while (count > 0 && sum < length); DataReceived(this, new DataReceivedInfo(data, result.DataChunk, track.ParentStream.Attributes)); SendLogEntry(KnownLogEntryTypes.DataReceived); } } catch (Exception err) { string message = string.Format(SilverlightMediaFrameworkResources.GenericErrorOccurredLogMessage, "OnDownloadStreamDataCompleted", err.Message); SendLogEntry(KnownLogEntryTypes.DownloadStreamDataCompleted, LogLevel.Error, message); } }
private void MediaPlugin_AdClickThrough(IAdaptiveMediaPlugin mediaPlugin, IAdContext adContext) { SendLogEntry(KnownLogEntryTypes.AdClickThrough); AdvertisementClickThrough.IfNotNull(i => i(this, new CustomEventArgs<IAdContext>(adContext))); }
/// <summary> /// Gets whether the specified plugin is registered with this BalancedPriorityGroupMonitor. /// </summary> /// <param name="plugin">The plugin to check for.</param> /// <returns>True indicates that the specified plugin is registered with this BalancedPriorityGroupMonitor.</returns> public bool IsPluginRegistered(IAdaptiveMediaPlugin plugin) { return(_registeredPlugins.Contains(plugin)); }
private void MediaPlugin_ManifestReady(IAdaptiveMediaPlugin obj) { OnManifestReady(); }
protected virtual void OnStreamDataAdded(IAdaptiveMediaPlugin mediaPlugin, IMediaStream stream, IDataChunk dataChunk) { try { if (stream.AvailableTracks.Count() > 0) { IMediaTrack track = stream.AvailableTracks.First(); ActiveAdaptiveMediaPlugin.DownloadStreamData(track, dataChunk); SendLogEntry(KnownLogEntryTypes.StreamDataAdded, extendedProperties: new Dictionary<string, object> { { "StreamName", stream.Name } }); } } catch (Exception err) { string message = string.Format(SilverlightMediaFrameworkResources.GenericErrorOccurredLogMessage, "OnStreamDataAdded", err.Message); SendLogEntry(KnownLogEntryTypes.GeneralErrorOccurred, LogLevel.Error, message); } }
public void SetAdaptivePlugin(IAdaptiveMediaPlugin plugin) { }
void ActiveMediaPlugin_AdStateChanged(IAdaptiveMediaPlugin mp, IAdContext adContext) { if (adContext != null && adContext.Data != this) return; switch (currentAdContext.CurrentAdState) { case MediaPluginState.Paused: case MediaPluginState.Buffering: if (!isLoaded) { OnAdLoaded(); isLoaded = true; } break; case MediaPluginState.Playing: if (!isStarted) { OnAdImpression(); OnAdStarted(); isStarted = true; } break; } }
void AdaptiveMediaPlugin_VideoPlaybackTrackChanged(IAdaptiveMediaPlugin arg1, IMediaTrack videoPlaybackTrack) { //When the SSME changes its playback bitrate, we need to re-set the maximum width and height of the //SSME explicitly. if (videoPlaybackTrack.Attributes.ContainsKey("MaxWidth")) ssmeMaxWidth = Convert.ToDouble(videoPlaybackTrack.Attributes["MaxWidth"]); if (videoPlaybackTrack.Attributes.ContainsKey("MaxHeight")) ssmeMaxHeight = Convert.ToDouble(videoPlaybackTrack.Attributes["MaxHeight"]); SetVideoProperties(); }
private void MediaPlugin_StreamSelected(IAdaptiveMediaPlugin mediaPlugin, IMediaStream stream) { Dispatcher.BeginInvoke(() => OnStreamSelected(mediaPlugin, stream)); }
protected virtual void OnStreamUnselected(IAdaptiveMediaPlugin mediaPlugin, IMediaStream stream) { try { if ((stream.Type == StreamType.Binary || stream.Type == StreamType.Text) && stream.AvailableTracks.Any()) { IMediaTrack track = stream.AvailableTracks.First(); ActiveAdaptiveMediaPlugin.CancelDownloadStreamData(track); SendLogEntry(KnownLogEntryTypes.StreamUnselected, LogLevel.Debug, "OnStreamUnselected", extendedProperties: new Dictionary<string, object> { { "StreamName", stream.Name } }); } } catch (Exception err) { string message = string.Format(SilverlightMediaFrameworkResources.GenericErrorOccurredLogMessage, "OnStreamUnselected", err.Message); SendLogEntry(KnownLogEntryTypes.GeneralErrorOccurred, LogLevel.Error, message); } }
private void mediaPlugin_AdStateChanged(IAdaptiveMediaPlugin mediaPlugin, IAdContext adContext) { SendLogEntry(KnownLogEntryTypes.AdProgressUpdated, extendedProperties: new Dictionary<string, object> { { "State", adContext.CurrentAdState.ToString() } }); AdStateChanged(adContext); AdvertisementStateChanged.IfNotNull(i => i(this, new AdvertisementStateChangedInfo { AdContext = adContext })); }
/// <summary> /// Unregisters a plugin so that it is no longer managed. /// </summary> /// <param name="plugin"></param> public void UnregisterPlugin(IAdaptiveMediaPlugin plugin) { _priorityGroups.Where(i => i.IsPluginRegistered(plugin)) .FirstOrDefault() .IfNotNull(i => i.UnregisterPlugin(plugin)); }
void adaptiveMediaPlugin_ManifestReady(IAdaptiveMediaPlugin obj) { obj.ManifestReady -= adaptiveMediaPlugin_ManifestReady; ScheduleAds(); }
private void MediaPlugin_AdProgressUpdated(IAdaptiveMediaPlugin mediaPlugin, IAdContext adContext, AdProgress adProgress) { SendLogEntry(KnownLogEntryTypes.AdProgressUpdated, extendedProperties: new Dictionary<string, object> { { "Progress", adProgress.ToString() } }); AdProgressUpdated(adContext, adProgress); AdvertisementProgressChanged.IfNotNull(i => i(this, new AdvertisementProgressChangedInfo { AdContext = adContext, AdProgress = adProgress })); }
private static bool IsPluginReadyForBitrateIncrease(IAdaptiveMediaPlugin plugin, long maxAllowedBitrate) { double droppedFramePercentage = plugin.DroppedFramesPerSecond/ (plugin.DroppedFramesPerSecond + plugin.RenderedFramesPerSecond); long highestPossibleBitrate = plugin.VideoDownloadTrack.ParentStream.SelectedTracks .Select(i => i.Bitrate) .Where(i => i <= maxAllowedBitrate) .DefaultIfEmpty() .Max(); long currentPlaybackBitrate = plugin.VideoPlaybackTrack != null ? plugin.VideoPlaybackTrack.Bitrate : 0; return currentPlaybackBitrate == highestPossibleBitrate && droppedFramePercentage <= TolerableDroppedFramesPercentage; }
private void MediaPlugin_AdError(IAdaptiveMediaPlugin mediaPlugin, IAdContext adContext) { AdError(adContext); AdvertisementError.IfNotNull(i => i(this, new CustomEventArgs<IAdContext>(adContext))); }