// Access Data public bool ReadNextFrame(ref float ptsSec) { //Debug.Log("[MeshReader] ReadNextFrame()"); if (!ReaderAPIPRM.BeginReadFrame(ApiKey, ref ptsSec)) { return(false); } //Debug.Log("~~~~~~~~~~~~~~~~~~~~~[ReadNextFrame] Video ptsSec ........" + ptsSec); MeshData.ptsSec = ptsSec; int numTris = ReaderAPIPRM.GetVerticesCount(ApiKey); MeshData.AllocMeshBuffer(numTris); ReaderAPIPRM.SetMeshVertices(ApiKey, MeshData.bufferSize, MeshData.gcHandlerVertices.AddrOfPinnedObject(), MeshData.gcHandlerNormals.AddrOfPinnedObject(), MeshData.gcHandlerUV.AddrOfPinnedObject(), MeshData.gcHandlerTriangles.AddrOfPinnedObject()); //Debug.Log("[MeshReader] Read Mesh Triangles = " + numTris); MeshData.AllocTextureBuffer(TextureWidth, TextureHeight, TextFormat); if (MeshData.mVersion == Version.FORMAT_NEW) { ReaderAPIPRM.SetMeshTexturesWithFormat(ApiKey, MeshData.gcHandlerColors.AddrOfPinnedObject(), (int)TextFormat); } else { ReaderAPIPRM.SetMeshTextures(ApiKey, TextureWidth, TextureHeight, 4, MeshData.gcHandlerColors.AddrOfPinnedObject()); } //Debug.Log("[MeshReader] Read Texture = " + TextureWidth + "x" + TextureHeight); ReaderAPIPRM.EndReadFrame(ApiKey); return(true); }
private AudioReader(int apiKey) { if (apiKey == -1) { ApiKey = ReaderAPIPRM.CreateApiInstance(); } else { ApiKey = apiKey; } AudioData = new AudioDataPRM(); }
// MeshReader private MeshReaderPRM(int apiKey) { if (apiKey == -1) { ApiKey = ReaderAPIPRM.CreateApiInstance(); } else { ApiKey = apiKey; } MeshData = new MeshDataPRM(); Debug.Log("[MeshReader] Create API instance " + ApiKey); }
public void Uninitialize() { if (isPlaying) { Pause(); } if (!isInitialized) { return; } ReaderAPIPRM.UnityPluginUnload(); meshReader = null; audioReader = null; isOpened = false; isInitialized = false; }
//-----------------------------// //- Functions -// //-----------------------------// public void Initialize() { if (isInitialized && meshReader != null) { return; } if (debugInfo) { DebugDelegate callback_delegate = new DebugDelegate(CallbackDebug); System.IntPtr intptr_delegate = Marshal.GetFunctionPointerForDelegate(callback_delegate); ReaderAPIPRM.SetDebugFunction(intptr_delegate); } //initial mesh reader if (meshReader == null) { meshReader = MeshReaderPRM.CreateMeshReader(ref apiKey); if (meshReader == null) { Debug.Log("[MeshPlayerPlugin][WARNING] Create Reader Instance Failed"); return; } } //initial audio reader if (audioReader == null) { audioReader = AudioReader.CreateAudioReader(meshReader.GetMeshApiKey()); if (audioReader == null) { Debug.Log("[MeshPlayerPlugin][WARNING] Create Reader Instance Failed"); return; } } meshComponent = GetComponent <MeshFilter>(); rendererComponent = GetComponent <Renderer>(); isFirstMeshDataArrived = false; isFirstAudioDataArrived = false; isFirstAudioPtsRecord = false; isInitialized = true; }
public bool GetAudioClipData(ref float ptsSec) { if (!ReaderAPIPRM.ReadAudioFrame(ApiKey, ref ptsSec)) { return(false); } //Debug.Log("[GetAudioClipData] audio ptsSec ........" + ptsSec); AudioData.ptsSec = ptsSec; int byte_count = ReaderAPIPRM.GetAudioByteCount(ApiKey); if (byte_count < 1) { Debug.Log("byte_count " + byte_count); } AudioData.AllocAudioBuffers(byte_count); ReaderAPIPRM.SetAudioByte(ApiKey, AudioData.gcHandlerAudioBytes.AddrOfPinnedObject()); AudioData.audio_data = ToAudioFloatData(AudioData.audio_bytes); AudioData.ptsSec = ptsSec; return(true); }
public void setAudioMainSwitch(bool value) { ReaderAPIPRM.SetAudioMainSwitch(ApiKey, value); }
public void audioStreamInfo() { ReaderAPIPRM.GetAudioStreamInfo(ApiKey, ref mChannels, ref mSampleRate, ref mBitDepth); }
public void ForwardOneFrame() { ReaderAPIPRM.ForwardOneFrame(ApiKey); }
public void Pause() { ReaderAPIPRM.PauseReader(ApiKey); }
public void Play() { ReaderAPIPRM.PlayReader(ApiKey); }
public void SetSpeedRatio(float speedRatio) { ReaderAPIPRM.SetSpeedRatio(ApiKey, speedRatio); return; }
public bool StartFromSecond(float sec) { ReaderAPIPRM.SetReaderStartSecond(ApiKey, sec); return(false); }
// Control public bool OpenMeshStream(string sourceUrl, bool mDataInStreamingAssets) { if (!sourceUrl.Contains(".mp4") && !sourceUrl.Contains("rtmp://")) { sourceUrl += ".mp4"; } string url = sourceUrl; if (!url.StartsWith("http") && !url.StartsWith("rtmp") && mDataInStreamingAssets) { url = Application.streamingAssetsPath + "/" + sourceUrl; Debug.Log("[MeshReader] Open in StreamingAssets: " + url); //ANDROID STREAMING ASSETS => need to copy the data somewhere else on device to acces it, beacause it is currently in jar file if (url.StartsWith("jar")) { WWW www = new WWW(url); //yield return www; //can't do yield here, not really blocking beacause the data is local while (!www.isDone) { ; } if (!string.IsNullOrEmpty(www.error)) { Debug.LogError("[MeshReader] PATH : " + url); Debug.LogError("[MeshReader] Can't read data in streaming assets: " + www.error); } else { //copy data on device url = Application.persistentDataPath + "/" + sourceUrl; if (!System.IO.File.Exists(url)) { Debug.Log("[MeshReader] NEW Roopath: " + url); System.IO.FileStream fs = System.IO.File.Create(url); fs.Write(www.bytes, 0, www.bytesDownloaded); Debug.Log("[MeshReader] data copied"); fs.Dispose(); } } } } TextFormat = getTextureFormat(); //TextFormat = TextureFormat.PVRTC_RGB4; Debug.Log("...................this platform is ............->" + TextFormat); if (!ReaderAPIPRM.OpenMeshStream(ApiKey, url, (int)TextFormat)) { return(false); } //ReaderAPIPRM.SetReaderLoop(ApiKey, false); ReaderAPIPRM.GetResolution(ApiKey, ref TextureWidth, ref TextureHeight); MeshData.mVersion = (Version)ReaderAPIPRM.GetFormatVersion(ApiKey); ReaderAPIPRM.GetMeshStreamInfo(ApiKey, ref SourceDurationSec, ref SourceFPS, ref SourceNbFrames); if (MeshData.mVersion == Version.FORMAT_OLD) { TextFormat = TextureFormat.RGBA32; } else { TextureWidth = getWidthInNewFormat(TextureWidth); TextureHeight = TextureWidth; } Debug.Log("[MeshPlayerPlugin] Open Success!"); Debug.Log("[MeshReader] Stream Duration = " + SourceDurationSec); Debug.Log("[MeshReader] Stream FPS = " + SourceFPS); Debug.Log("[MeshReader] Stream Number of Frames = " + SourceNbFrames); return(true); }