private void CreateTextures(int width, int height, ChromaSubsampling chromaSubsampling) { int widthUV = width; int heightUV = height; if (chromaSubsampling == ChromaSubsampling._420) { heightUV = height / 2; widthUV = width / 2; } else if (chromaSubsampling == ChromaSubsampling._422) { widthUV = width / 2; } _textureY = new Texture2D(width, height, _format, false); _textureY.wrapMode = (_clampTextures == true ? TextureWrapMode.Clamp : TextureWrapMode.Repeat); _textureY.Apply(); _textureU = new Texture2D(widthUV, heightUV, _format, false); _textureU.wrapMode = (_clampTextures == true ? TextureWrapMode.Clamp : TextureWrapMode.Repeat); _textureU.Apply(); _textureV = new Texture2D(widthUV, heightUV, _format, false); _textureV.wrapMode = (_clampTextures == true ? TextureWrapMode.Clamp : TextureWrapMode.Repeat); _textureV.Apply(); if (OnTexturesChanged != null) { foreach (TexturesChangedDelegate TexturesChanged in OnTexturesChanged.GetInvocationList()) { try { TexturesChanged(this); } catch (Exception ex) { Debug.LogException(ex); } } } }
// This needs to be called before calling Play(). public void InitializePlayer(string filename, PathType videoPathType, float framerate, AudioClip audioClip, int maxQueue, StereoVideoMode stereoMode, bool invertLeftRight, bool videoIsUpsideDown, bool pauseAtStart = true, bool loopVideo = false) { // If player was already initialized, destroy the old instance: if (_playerInstance != IntPtr.Zero) { _command.IssuePluginEventAndData(GetRenderEventFunc(), -1, _playerInstance); // -1 means destroy this player instance in the C++ plugin. Graphics.ExecuteCommandBuffer(_command); _command.Clear(); _playerInstance = IntPtr.Zero; _playState = PlayState.UNINITIALIZED; // In case the license only supports one video at a time, it is necessary to wait here for one frame. // Else, if we immediately create a new sequencer, the old license is not yet return and the application is not allowed to create a "second one". // This is not necessary, if the license does not have this limitation, so we do not wait for a frame here. } // Set player flags: _pauseAtStart = pauseAtStart; _filename = filename; _videoPathType = videoPathType; _loopVideo = loopVideo; _framerate = Mathf.Max(1f, framerate); // framerate must not be 0. _stereoMode = stereoMode; _invertLeftRight = invertLeftRight; _videoIsUpsideDown = videoIsUpsideDown; _maxQueue = maxQueue; // Create a player (sequencer) instance: _playerInstance = CreateSequencer(AbsoluteFilePath, _numberOfThreads, _videoBufferSize, _maxQueue, _shouldLog); int currentErrorCode = GetCurrentErrorCode(); if (currentErrorCode != 0) { Debug.LogError("Error Code " + currentErrorCode + " appeared after calling CreateSequencer."); return; } int playersVideoWidth = GetVideoWidth(); int playersVideoHeight = GetVideoHeight(); ChromaSubsampling playersChromaSubsampling = (ChromaSubsampling)GetVideoChromaSubsampling(); // Check if textures need to be reinitialized with new width and height: bool oldTexturesCanBeUsed = (_textureY != null && _textureY.width == playersVideoWidth && _textureY.height == playersVideoHeight && _chromaSubsampling == playersChromaSubsampling); if (oldTexturesCanBeUsed == false || _textureY == null || _textureU == null || _textureV == null) { // Destroy Textures if they are already created and create new ones with the set width and height: DestroyTextures(); CreateTextures(playersVideoWidth, playersVideoHeight, playersChromaSubsampling); _chromaSubsampling = playersChromaSubsampling; } // Pass texture pointer to the plugin and initailize the player: InitPlayer(_playerInstance, _textureY.GetNativeTexturePtr(), _textureU.GetNativeTexturePtr(), _textureV.GetNativeTexturePtr(), (int)_format); _playState = PlayState.INITIALIZED; // Load other audio clip: if (_audioSrcVideo) { if (audioClip != null) { _audioSrcVideo.clip = audioClip; } } }