Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mray streaming #10

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file added Assets/Bad Plugins/GStreamerReader.dll
Binary file not shown.
69 changes: 69 additions & 0 deletions Assets/Bad Plugins/GStreamerReader.dll.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file added Assets/Bad Plugins/GStreamerUnityPlugin.dll
Binary file not shown.
69 changes: 69 additions & 0 deletions Assets/Bad Plugins/GStreamerUnityPlugin.dll.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file added Assets/Delorian/Delorian.skp
Binary file not shown.
104 changes: 104 additions & 0 deletions Assets/Delorian/Delorian.skp.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Assets/GStreamerUnity.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions Assets/GStreamerUnity/Components.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

109 changes: 109 additions & 0 deletions Assets/GStreamerUnity/Components/BaseVideoPlayer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public abstract class BaseVideoPlayer : DependencyRoot {

private GstCustomTexture m_Texture = null;
Material material;
OffscreenProcessor _Processor;

public Shader[] PostProcessors;

OffscreenProcessor[] _postProcessors;

public Texture VideoTexture;

public bool ConvertToRGB=true;

public GstCustomTexture InternalTexture
{
get{return m_Texture;}
}


public delegate void Delg_OnFrameAvailable(BaseVideoPlayer src,Texture tex);
public event Delg_OnFrameAvailable OnFrameAvailable;

protected abstract string _GetPipeline ();

// Use this for initialization
protected override void Start () {

_Processor=new OffscreenProcessor();
m_Texture = gameObject.GetComponent<GstCustomTexture>();

material=gameObject.GetComponent<MeshRenderer> ().material;
// Check to make sure we have an instance.
if (m_Texture == null)
{
DestroyImmediate(this);
}

m_Texture.Initialize ();
// pipeline = "filesrc location=\""+VideoPath+"\" ! decodebin ! videoconvert ! video/x-raw,format=I420 ! appsink name=videoSink sync=true";
// pipeline = "filesrc location=~/Documents/Projects/BeyondAR/Equirectangular_projection_SW.jpg ! jpegdec ! videoconvert ! imagefreeze ! videoconvert ! imagefreeze ! videoconvert ! video/x-raw,format=I420 ! appsink name=videoSink sync=true";
// pipeline = "videotestsrc ! videoconvert ! video/x-raw,width=3280,height=2048,format=I420 ! appsink name=videoSink sync=true";
m_Texture.SetPipeline (_GetPipeline());
m_Texture.Play ();


m_Texture.OnFrameGrabbed += OnFrameGrabbed;

_Processor.ShaderName="Image/I420ToRGB";

if (PostProcessors != null) {
_postProcessors = new OffscreenProcessor[PostProcessors.Length];
for (int i = 0; i < PostProcessors.Length; ++i) {
_postProcessors [i] = new OffscreenProcessor ();
_postProcessors [i].ProcessingShader = PostProcessors [i];
}
}

Debug.Log ("Starting Base");
base.Start ();
}

bool _newFrame=false;
void OnFrameGrabbed(GstBaseTexture src,int index)
{
_newFrame = true;
}

void _processNewFrame()
{
_newFrame = false;
if (m_Texture.PlayerTexture ().Length == 0)
return;

Texture tex=m_Texture.PlayerTexture () [0];

if (ConvertToRGB) {
if (m_Texture.PlayerTexture () [0].format == TextureFormat.Alpha8)
VideoTexture = _Processor.ProcessTexture (tex);
else
VideoTexture = tex;

} else {
VideoTexture = tex;
}

if (_postProcessors != null) {
foreach (var p in _postProcessors) {
VideoTexture = p.ProcessTexture (VideoTexture);
}
}
material.mainTexture = VideoTexture;

if (OnFrameAvailable != null)
OnFrameAvailable (this, VideoTexture);

}

// Update is called once per frame
void Update () {

if (_newFrame)
_processNewFrame ();
}
}
Loading