Ejemplo n.º 1
0
        //  Render event

        private void getTextureFromNative()
        {
            releaseTextures();
            var nativeTexturePtrY = new IntPtr();
            var nativeTexturePtrU = new IntPtr();
            var nativeTexturePtrV = new IntPtr();
            var duration          = 0.0f;

            DecoderNative.nativeGetVideoFormat(decoderID, ref videoWidth, ref videoHeight, ref duration);
            videoTotalTime = duration > 0 ? duration : -1.0f;
            print(LOG_TAG + " Video format: (" + videoWidth + ", " + videoHeight + ")");
            if (videoTotalTime > 0)
            {
                print(LOG_TAG + " Total time: " + videoTotalTime);
            }
            DecoderNative.nativeCreateTexture(decoderID, ref nativeTexturePtrY, ref nativeTexturePtrU, ref nativeTexturePtrV);
            videoTexYch = Texture2D.CreateExternalTexture(videoWidth, videoHeight, TextureFormat.Alpha8, false, false, nativeTexturePtrY);
            videoTexUch = Texture2D.CreateExternalTexture(videoWidth / 2, videoHeight / 2, TextureFormat.Alpha8, false, false, nativeTexturePtrU);
            videoTexVch = Texture2D.CreateExternalTexture(videoWidth / 2, videoHeight / 2, TextureFormat.Alpha8, false, false, nativeTexturePtrV);
        }
Ejemplo n.º 2
0
        public static void loadVideoThumb(GameObject obj, string filePath, float time)
        {
            if (!File.Exists(filePath))
            {
                print(LOG_TAG + " File not found!");
                return;
            }

            var decID     = -1;
            var width     = 0;
            var height    = 0;
            var totalTime = 0.0f;

            DecoderNative.nativeCreateDecoder(filePath, ref decID);
            DecoderNative.nativeGetVideoFormat(decID, ref width, ref height, ref totalTime);
            if (!DecoderNative.nativeStartDecoding(decID))
            {
                print(LOG_TAG + " Decoding not start.");
                return;
            }

            var thumbY   = new Texture2D(width, height, TextureFormat.Alpha8, false);
            var thumbU   = new Texture2D(width / 2, height / 2, TextureFormat.Alpha8, false);
            var thumbV   = new Texture2D(width / 2, height / 2, TextureFormat.Alpha8, false);
            var thumbMat = obj.GetComponent <MeshRenderer>().material;

            if (thumbMat == null)
            {
                print(LOG_TAG + " Target has no MeshRenderer.");
                DecoderNative.nativeDestroyDecoder(decID);
                return;
            }

            thumbMat.SetTexture("_YTex", thumbY);
            thumbMat.SetTexture("_UTex", thumbU);
            thumbMat.SetTexture("_VTex", thumbV);

            DecoderNative.nativeLoadThumbnail(decID, time, thumbY.GetNativeTexturePtr(), thumbU.GetNativeTexturePtr(),
                                              thumbV.GetNativeTexturePtr());
            DecoderNative.nativeDestroyDecoder(decID);
        }
Ejemplo n.º 3
0
        private IEnumerator initDecoderAsync(string path)
        {
            print(LOG_TAG + " init Decoder.");
            decoderState = DecoderNative.DecoderState.INITIALIZING;

            mediaPath = path;
            decoderID = -1;
            DecoderNative.nativeCreateDecoderAsync(mediaPath, ref decoderID);

            var result = 0;

            do
            {
                yield return(null);

                result = DecoderNative.nativeGetDecoderState(decoderID);
            } while (!(result == 1 || result == -1));

            //  Init success.
            if (result == 1)
            {
                print(LOG_TAG + " Init success.");
                isVideoEnabled = DecoderNative.nativeIsVideoEnabled(decoderID);
                if (isVideoEnabled)
                {
                    var duration = 0.0f;
                    DecoderNative.nativeGetVideoFormat(decoderID, ref videoWidth, ref videoHeight, ref duration);
                    videoTotalTime = duration > 0 ? duration : -1.0f;
                    print(LOG_TAG + " Video format: (" + videoWidth + ", " + videoHeight + ")");
                    print(LOG_TAG + " Total time: " + videoTotalTime);

                    setTextures(null, null, null);
                    useDefault = true;
                }

                //	Initialize audio.
                isAudioEnabled = DecoderNative.nativeIsAudioEnabled(decoderID);
                print(LOG_TAG + " isAudioEnabled = " + isAudioEnabled);
                if (isAudioEnabled)
                {
                    if (isAllAudioChEnabled)
                    {
                        DecoderNative.nativeSetAudioAllChDataEnable(decoderID, isAllAudioChEnabled);
                        getAudioFormat();
                    }
                    else
                    {
                        getAudioFormat();
                        initAudioSource();
                    }
                }

                decoderState = DecoderNative.DecoderState.INITIALIZED;

                if (onInitComplete != null)
                {
                    onInitComplete.Invoke();
                }
            }
            else
            {
                print(LOG_TAG + " Init fail.");
                decoderState = DecoderNative.DecoderState.INIT_FAIL;
            }
        }