// %BANNER_BEGIN%
// ---------------------------------------------------------------------
// %COPYRIGHT_BEGIN%
// Copyright (c) (2018-2022) Magic Leap, Inc. All Rights Reserved.
// Use of this file is governed by the Software License Agreement, located here: https://www.magicleap.com/software-license-agreement-ml2
// Terms and conditions applicable to third-party materials accompanying this distribution may also be found in the top-level NOTICE file appearing herein.
// %COPYRIGHT_END%
// ---------------------------------------------------------------------
// %BANNER_END%
namespace UnityEngine.XR.MagicLeap
{
using System;
using System.Runtime.InteropServices;
using System.Text;
///
/// MLMedia APIs.
///
public partial class MLMedia
{
///
/// CEA708 Parser.
///
public partial class ParserCEA708
{
public const string Mime = "text/cea-708";
private string subtitleText = string.Empty;
private string[] cea708Strings = new string[2];
private int cea708WindowID = -1;
public delegate void OnTextDelegate(string text);
public event OnTextDelegate OnText = delegate { };
public delegate void OnEmitEventDelegate(Cea708CaptionEmitCommand command, object obj);
public event OnEmitEventDelegate OnEmitEvent = delegate { };
private StringBuilder stringBuilder = new StringBuilder();
public ParserCEA708()
{
MLResult.Code resultCode = NativeBindings.MLMediaCea708ParserCreate(out ulong parserHandle);
MLResult.DidNativeCallSucceed(resultCode, nameof(NativeBindings.MLMediaCea708ParserCreate));
this.Handle = parserHandle;
this.gcHandle = GCHandle.Alloc(this, GCHandleType.Weak);
IntPtr gcHandlePtr = GCHandle.ToIntPtr(this.gcHandle);
resultCode = NativeBindings.MLMediaCea708ParserSetEmitEventCallback(this.Handle, NativeBindings.OnEmitEvent, gcHandlePtr);
MLResult.DidNativeCallSucceed(resultCode, nameof(NativeBindings.MLMediaCea708ParserSetEmitEventCallback));
}
~ParserCEA708()
{
MLResult.Code resultCode = NativeBindings.MLMediaCea708ParserSetEmitEventCallback(this.Handle, null, IntPtr.Zero);
MLResult.DidNativeCallSucceed(resultCode, nameof(NativeBindings.MLMediaCea708ParserSetEmitEventCallback));
resultCode = NativeBindings.MLMediaCea708ParserDestroy(this.Handle);
MLResult.DidNativeCallSucceed(resultCode, nameof(NativeBindings.MLMediaCea708ParserDestroy));
this.gcHandle.Free();
}
public void ParseAsync(IntPtr data, uint dataSize)
{
MLResult.Code resultCode = NativeBindings.MLMediaCea708ParserParse(this.Handle, data, dataSize);
MLResult.DidNativeCallSucceed(resultCode, nameof(NativeBindings.MLMediaCea708ParserParse));
}
internal ulong Handle
{
get;
private set;
}
private GCHandle gcHandle;
///
/// CEA708 Caption Pen Size constants.
/// MLCea708CaptionPenSize from ml_media_cea708_caption.h.
///
public enum Cea708CaptionPenSize
{
///
/// Small pen size.
///
Small = 0,
///
/// Standard pen size.
///
Standard = 1,
///
/// Large pen size.
///
Large = 2,
}
///
/// CEA708 Caption Pen Offset constants.
/// MLCea708CaptionPenOffset from ml_media_cea708_caption.h.
///
public enum Cea708CaptionPenOffset
{
///
/// Subscript offset.
///
Subscript = 0,
///
/// Normal offset.
///
Normal = 1,
///
/// Superscript offset.
///
Superscript = 2,
}
///
/// CEA708 Caption Emit Commands constants.
/// MLCea708CaptionEmitCommand from ml_media_cea708_caption.h.
///
public enum Cea708CaptionEmitCommand : int
{
///
/// Buffer command.
///
Buffer = 1,
///
/// Control command.
///
Control = 2,
///
/// SetCurrentWindow tells the caption decoder which window the following commands describe:
/// - SetWindowAttributes
/// - SetPenAttributes
/// - SetPenColor
/// - SetPenLocation.
/// If the window specified has not already been created with a DefineWindow command then,
/// SetCurrentWindow and the window property commands can be safely ignored.
///
CWX = 3,
///
/// ClearWindows clears all the windows specified in the 8 bit window bitmap.
///
CLW = 4,
///
/// DisplayWindows displays all the windows specified in the 8 bit window bitmap.
///
DSW = 5,
///
/// HideWindows hides all the windows specified in the 8 bit window bitmap.
///
HDW = 6,
///
/// ToggleWindows hides all displayed windows, and displays all hidden windows specified in the 8 bit window bitmap.
///
TGW = 7,
///
/// DeleteWindows deletes all the windows specified in the 8 bit window bitmap.
/// If the current window, as specified by the last SetCurrentWindow command,
/// is deleted then the current window becomes undefined and the window attribute commands
/// should have no effect until after the next SetCurrentWindow or DefineWindow command.
///
DLW = 8,
///
/// Delay suspends all processing of the current service, except for DelayCancel and Reset scanning.
///
DLY = 9,
///
/// DelayCancel terminates any active delay and resumes normal command processing. DelayCancel should be scanned for during a Delay.
///
DLC = 10,
///
/// Reset deletes all windows, cancels any active delay, and clears the buffer before the Reset command. Reset should be scanned for during a Delay.
///
RST = 11,
///
/// The SetPenAttributes command specifies how certain attributes of subsequent characters are to be rendered in the current window, until the next SetPenAttributes command.
///
SPA = 12,
///
/// SetPenColor sets the foreground, background, and edge color for the subsequent characters.
///
SPC = 13,
/// SetPenLocation sets the location of for the next bit of appended text in the current window. It has two parameters, row and column.
///
SPL = 14,
///
/// SetWindowAttributes Sets the window attributes of the current window.
///
SWA = 15,
///
/// DefineWindow0-7 creates one of the eight windows used by a caption decoder.
///
DFX = 16
}
///
/// CEA708 Caption Emit Command Control constants.
/// MLCea708CaptionEmitCommandControl from ml_media_cea708_caption.h.
///
public enum Cea708CaptionEmitCommandControl : int
{
///
/// End of text.
///
ETX = 0x03,
///
/// Back space.
///
BS = 0x08,
///
/// This code is equivalent to CEA708 CLW command
///
FF = 0x0c,
///
/// Carriage return.
///
HCR = 0x0e
}
///
/// CEA708 Caption Color Opacity constants.
/// MLCea708CaptionColorOpacity from ml_media_cea708_caption.h.
///
public enum Cea708CaptionColorOpacity : int
{
///
/// Solid opacity.
///
Solid = 0,
///
/// Flashing opacity.
///
Flash = 1,
///
/// Translucent opacity.
///
Translucent = 2,
///
/// Transparent opacity.
///
Transparent = 3
}
}
}
}