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

When my network is borken #28

Open
LawlietJin opened this issue May 24, 2021 · 2 comments
Open

When my network is borken #28

LawlietJin opened this issue May 24, 2021 · 2 comments

Comments

@LawlietJin
Copy link

When my net work is borken 5 sec ,now how can i to restore the tex

@LawlietJin
Copy link
Author

using UnityEngine;
using System.Collections;
using System;
using UnityEngine.UI;

[RequireComponent(typeof(GstCustomTexture))]
public class CustomPipelinePlayer : MonoBehaviour
{

GstCustomTexture m_Texture;

public Texture2D BlittedImage;

public Material TargetMaterial;

public string pipeline = "";

public Rect BlitRect = new Rect(0, 0, 1, 1);
GstImageInfo _img;

public long position;
public long duration;
bool _newFrame = false;
// Use this for initialization
void Start()
{
    m_Texture = gameObject.GetComponent<GstCustomTexture>();
    m_Texture.Initialize();
    m_Texture.SetPipeline(pipeline + " ! video/x-raw,format=I420 ! videoconvert ! appsink name=videoSink");
    m_Texture.Player.CreateStream();
    m_Texture.Player.Play();

    m_Texture.OnFrameBlitted += OnFrameBlitted;
    _img = new GstImageInfo();
    _img.Create(1, 1, GstImageInfo.EPixelFormat.EPixel_R8G8B8);

    BlittedImage = new Texture2D(1, 1);
    BlittedImage.filterMode = FilterMode.Bilinear;
    BlittedImage.anisoLevel = 0;
    BlittedImage.wrapMode = TextureWrapMode.Clamp;

    if (TargetMaterial != null)
        TargetMaterial.mainTexture = BlittedImage;
}
void OnFrameBlitted(GstBaseTexture src, int index)
{
    //m_Texture.Player.CopyFrame (_img);
    float w = m_Texture.Player.FrameSizeImage.x;
    float h = m_Texture.Player.FrameSizeImage.y;
    m_Texture.Player.CopyFrameCropped(_img, (int)(BlitRect.x * w), (int)(BlitRect.y * h), (int)(BlitRect.width * w), (int)(BlitRect.height * h));
    _newFrame = true;
    Debug.Log("new frame");
    if (_newFrame)
    {
        _img.BlitToTexture(BlittedImage);
        _newFrame = false;
    }

    //		Debug.Log(String.Format("Frame Copied {0}x{1}",_img.Width,_img.Height));
}
public void OnGUI()
{
}
void OnDestroy()
{
    if (_img != null)
        _img.Destory();
    //		Debug.Log ("Destorying Image");
}

// Update is called once per frame
void Update()
{
    position = m_Texture.Player.GetPosition() / 1000;
    duration = m_Texture.Player.GetDuration() / 1000;

    if (Input.GetKeyDown(KeyCode.LeftArrow))
    {
        var p = (position - 5000);
        if (p < 0)
            p = 0;
        m_Texture.Player.Seek(p * 1000);
    }
    if (Input.GetKeyDown(KeyCode.RightArrow))
    {
        var p = (position + 5000);
        if (p >= duration)
            p = duration;
        m_Texture.Player.Seek(p * 1000);
    }
    if (Input.GetKeyDown(KeyCode.S))
        m_Texture.Stop();

    if (Input.GetKeyDown(KeyCode.P))
        m_Texture.Play();


    if (Input.GetKeyDown(KeyCode.A))
    {
        Debug.Log("重连");
        if (_img != null)
            _img.Destory();
        m_Texture.Destroy();
        m_Texture.Close();
        m_Texture.OnFrameBlitted -= OnFrameBlitted;

        m_Texture = gameObject.GetComponent<GstCustomTexture>();
        m_Texture.Initialize();
        m_Texture.SetPipeline(pipeline + " ! video/x-raw,format=I420 ! videoconvert ! appsink name=videoSink");
        m_Texture.Player.CreateStream();
        m_Texture.Player.Play();

        m_Texture.OnFrameBlitted += OnFrameBlitted;
        _img = new GstImageInfo();
        _img.Create(1, 1, GstImageInfo.EPixelFormat.EPixel_R8G8B8);

        BlittedImage = new Texture2D(1, 1);
        BlittedImage.filterMode = FilterMode.Bilinear;
        BlittedImage.anisoLevel = 0;
        BlittedImage.wrapMode = TextureWrapMode.Clamp;

        if (TargetMaterial != null)
            TargetMaterial.mainTexture = BlittedImage;
    }
}

}

@LawlietJin
Copy link
Author

KeyCode.A is my code,anything wrong?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant