2021-03-31 16:42:58 -05:00
|
|
|
// Decompiled with JetBrains decompiler
|
|
|
|
|
// Type: Microsoft.Iris.ViewItems.Video
|
|
|
|
|
// Assembly: UIX, Version=4.8.0.0, Culture=neutral, PublicKeyToken=ddd0da4d3e678217
|
|
|
|
|
// MVID: A56C6C9D-B7F6-46A9-8BDE-B3D9B8D60B11
|
|
|
|
|
// Assembly location: C:\Program Files\Zune\UIX.dll
|
|
|
|
|
|
|
|
|
|
using Microsoft.Iris.Drawing;
|
|
|
|
|
using Microsoft.Iris.Markup;
|
|
|
|
|
using Microsoft.Iris.Render;
|
|
|
|
|
using Microsoft.Iris.RenderAPI.Drawing;
|
|
|
|
|
using Microsoft.Iris.RenderAPI.VideoPlayback;
|
|
|
|
|
using Microsoft.Iris.Session;
|
|
|
|
|
using System;
|
|
|
|
|
|
|
|
|
|
namespace Microsoft.Iris.ViewItems
|
|
|
|
|
{
|
|
|
|
|
internal class Video : ContentViewItem, IUIVideoPortal, ITrackableUIElement
|
|
|
|
|
{
|
|
|
|
|
private const int c_spriteBorderCount = 2;
|
|
|
|
|
private Color _fillLetterbox;
|
|
|
|
|
private IUIVideoStream _videoStream;
|
|
|
|
|
private ISprite[] _letterBoxSprites;
|
|
|
|
|
private EventHandler _portalChangeEvent;
|
|
|
|
|
|
|
|
|
|
public Video()
|
|
|
|
|
{
|
2021-04-02 19:10:51 -05:00
|
|
|
_fillLetterbox = Color.Black;
|
|
|
|
|
((ITrackableUIElementEvents)this).UIChange += new EventHandler(OnUIChange);
|
2021-03-31 16:42:58 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnDispose()
|
|
|
|
|
{
|
2021-04-02 19:10:51 -05:00
|
|
|
if (_videoStream != null)
|
|
|
|
|
_videoStream.RevokePortal(this);
|
|
|
|
|
_videoStream = null;
|
|
|
|
|
((ITrackableUIElementEvents)this).UIChange -= new EventHandler(OnUIChange);
|
2021-03-31 16:42:58 -05:00
|
|
|
base.OnDispose();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IUIVideoStream VideoStream
|
|
|
|
|
{
|
2021-04-02 19:10:51 -05:00
|
|
|
get => _videoStream;
|
2021-03-31 16:42:58 -05:00
|
|
|
set
|
|
|
|
|
{
|
2021-04-02 19:10:51 -05:00
|
|
|
if (_videoStream == value)
|
2021-03-31 16:42:58 -05:00
|
|
|
return;
|
2021-04-02 19:10:51 -05:00
|
|
|
ForceContentChange();
|
|
|
|
|
if (_videoStream != null)
|
|
|
|
|
_videoStream.RevokePortal(this);
|
|
|
|
|
_videoStream = value;
|
|
|
|
|
if (_videoStream != null)
|
|
|
|
|
_videoStream.RegisterPortal(this);
|
|
|
|
|
FireNotification(NotificationID.VideoStream);
|
2021-03-31 16:42:58 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Color LetterboxColor
|
|
|
|
|
{
|
2021-04-02 19:10:51 -05:00
|
|
|
get => _fillLetterbox;
|
2021-03-31 16:42:58 -05:00
|
|
|
set
|
|
|
|
|
{
|
2021-04-02 19:10:51 -05:00
|
|
|
if (!(value != LetterboxColor))
|
2021-03-31 16:42:58 -05:00
|
|
|
return;
|
2021-04-02 19:10:51 -05:00
|
|
|
_fillLetterbox = value;
|
|
|
|
|
if (_letterBoxSprites != null)
|
|
|
|
|
_letterBoxSprites[0].Effect.SetProperty("ColorElem.Color", _fillLetterbox.RenderConvert());
|
|
|
|
|
FireNotification(NotificationID.LetterboxColor);
|
2021-03-31 16:42:58 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-02 19:10:51 -05:00
|
|
|
protected override bool HasContent() => _videoStream != null;
|
2021-03-31 16:42:58 -05:00
|
|
|
|
|
|
|
|
protected override void CreateContent()
|
|
|
|
|
{
|
|
|
|
|
base.CreateContent();
|
|
|
|
|
if (!UISession.Default.RenderSession.GraphicsDevice.IsVideoComposited)
|
|
|
|
|
return;
|
|
|
|
|
IRenderSession renderSession = UISession.Default.RenderSession;
|
2021-03-31 17:15:06 -05:00
|
|
|
VideoElement videoElement = new VideoElement("VideoElement", null);
|
|
|
|
|
IEffectTemplate effectTemplate = renderSession.CreateEffectTemplate(this, nameof(Video));
|
|
|
|
|
effectTemplate.Build(videoElement);
|
|
|
|
|
IEffect instance = effectTemplate.CreateInstance(this);
|
2021-04-02 19:10:51 -05:00
|
|
|
_contents.Effect = instance;
|
2021-03-31 17:15:06 -05:00
|
|
|
instance.UnregisterUsage(this);
|
|
|
|
|
effectTemplate.UnregisterUsage(this);
|
2021-04-02 19:10:51 -05:00
|
|
|
_contents.Effect.SetProperty("VideoElement.Video", (_videoStream as Microsoft.Iris.VideoStream).RenderStream);
|
|
|
|
|
CreateBorderSprites(renderSession);
|
2021-03-31 16:42:58 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void DisposeContent(bool removeFromTree)
|
|
|
|
|
{
|
|
|
|
|
base.DisposeContent(removeFromTree);
|
2021-04-02 19:10:51 -05:00
|
|
|
if (_letterBoxSprites == null)
|
2021-03-31 16:42:58 -05:00
|
|
|
return;
|
2021-04-02 19:10:51 -05:00
|
|
|
foreach (ISprite letterBoxSprite in _letterBoxSprites)
|
2021-03-31 16:42:58 -05:00
|
|
|
{
|
|
|
|
|
if (removeFromTree)
|
|
|
|
|
letterBoxSprite.Remove();
|
2021-03-31 17:15:06 -05:00
|
|
|
letterBoxSprite.UnregisterUsage(this);
|
2021-03-31 16:42:58 -05:00
|
|
|
}
|
2021-04-02 19:10:51 -05:00
|
|
|
_letterBoxSprites = null;
|
2021-03-31 16:42:58 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnPaint(bool visible)
|
|
|
|
|
{
|
|
|
|
|
base.OnPaint(visible);
|
2021-04-02 19:10:51 -05:00
|
|
|
if (_contents == null || !UISession.Default.RenderSession.GraphicsDevice.IsVideoComposited)
|
2021-03-31 16:42:58 -05:00
|
|
|
return;
|
2021-04-02 19:10:51 -05:00
|
|
|
BasicVideoPresentation presentation = _videoStream.GetPresentation(this);
|
|
|
|
|
_contents.Position = new Vector3(presentation.DisplayedDestination.Left, presentation.DisplayedDestination.Top, 0.0f);
|
|
|
|
|
_contents.Size = new Vector2(presentation.DisplayedDestination.Size.Width, presentation.DisplayedDestination.Size.Height);
|
2021-03-31 16:42:58 -05:00
|
|
|
BasicVideoGeometry geometry = presentation.GetGeometry();
|
|
|
|
|
for (int index = 0; index < 2; ++index)
|
|
|
|
|
{
|
|
|
|
|
if (index < geometry.arrcfBorders.Length)
|
|
|
|
|
{
|
|
|
|
|
RectangleF arrcfBorder = geometry.arrcfBorders[index];
|
2021-04-02 19:10:51 -05:00
|
|
|
_letterBoxSprites[index].Visible = true;
|
|
|
|
|
_letterBoxSprites[index].Position = new Vector3(arrcfBorder.Left, arrcfBorder.Top, 0.0f);
|
|
|
|
|
_letterBoxSprites[index].Size = new Vector2(arrcfBorder.Width, arrcfBorder.Height);
|
2021-03-31 16:42:58 -05:00
|
|
|
}
|
|
|
|
|
else
|
2021-04-02 19:10:51 -05:00
|
|
|
_letterBoxSprites[index].Visible = false;
|
2021-03-31 16:42:58 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void CreateBorderSprites(IRenderSession renderSession)
|
|
|
|
|
{
|
2021-04-02 19:10:51 -05:00
|
|
|
_letterBoxSprites = new ISprite[2];
|
|
|
|
|
IEffect colorFillEffect = EffectManager.CreateColorFillEffect(this, LetterboxColor);
|
2021-03-31 16:42:58 -05:00
|
|
|
for (int index = 0; index < 2; ++index)
|
|
|
|
|
{
|
2021-03-31 17:15:06 -05:00
|
|
|
ISprite sprite = renderSession.CreateSprite(this, this);
|
2021-03-31 16:42:58 -05:00
|
|
|
sprite.Effect = colorFillEffect;
|
2021-04-02 19:10:51 -05:00
|
|
|
VisualContainer.AddChild(sprite, ContentVisual, VisualOrder.Before);
|
|
|
|
|
_letterBoxSprites[index] = sprite;
|
2021-03-31 16:42:58 -05:00
|
|
|
}
|
2021-03-31 17:15:06 -05:00
|
|
|
colorFillEffect.UnregisterUsage(this);
|
2021-03-31 16:42:58 -05:00
|
|
|
}
|
|
|
|
|
|
2021-04-02 19:10:51 -05:00
|
|
|
Rectangle IUIVideoPortal.LogicalContentRect => HasVisual ? new Rectangle(0.0f, 0.0f, VisualSize.X, VisualSize.Y) : Rectangle.Zero;
|
2021-03-31 16:42:58 -05:00
|
|
|
|
|
|
|
|
void IUIVideoPortal.OnStreamChange(bool formatChangedFlag)
|
|
|
|
|
{
|
|
|
|
|
if (formatChangedFlag)
|
2021-04-02 19:10:51 -05:00
|
|
|
MarkLayoutInvalid();
|
|
|
|
|
MarkPaintInvalid();
|
2021-03-31 16:42:58 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void IUIVideoPortal.OnRevokeStream()
|
|
|
|
|
{
|
2021-04-02 19:10:51 -05:00
|
|
|
MarkLayoutInvalid();
|
|
|
|
|
MarkPaintInvalid();
|
2021-03-31 16:42:58 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
event EventHandler IUIVideoPortal.PortalChange
|
|
|
|
|
{
|
2021-04-02 19:10:51 -05:00
|
|
|
add => _portalChangeEvent += value;
|
|
|
|
|
remove => _portalChangeEvent -= value;
|
2021-03-31 16:42:58 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnUIChange(object sender, EventArgs args)
|
|
|
|
|
{
|
2021-04-02 19:10:51 -05:00
|
|
|
if (_portalChangeEvent == null)
|
2021-03-31 16:42:58 -05:00
|
|
|
return;
|
2021-04-02 19:10:51 -05:00
|
|
|
_portalChangeEvent(sender, args);
|
2021-03-31 16:42:58 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|