Example #1
0
        public void GetNowFrame(ref CTexture Texture)
        {
            if (this.bPlaying && decodedframes.Count != 0)
            {
                CTimer.t更新();
                if (decodedframes.TryPeek(out CDecodedFrame frame))
                {
                    while (frame.Time <= (CTimer.n現在時刻ms * _dbPlaySpeed))
                    {
                        if (decodedframes.TryDequeue(out CDecodedFrame cdecodedframe))
                        {
                            if (decodedframes.Count != 0)
                            {
                                if (decodedframes.TryPeek(out frame))
                                {
                                    if (frame.Time <= (CTimer.n現在時刻ms * _dbPlaySpeed))
                                    {
                                        continue;
                                    }
                                }
                            }

                            if (lastTexture != null)
                            {
                                lastTexture.Dispose();
                            }
                            lastTexture = GeneFrmTx(cdecodedframe.Bitmap);
                        }
                        break;
                    }
                }

                if (DS == DecodingState.Stopped)
                {
                    this.EnqueueFrames();
                }
            }

            if (lastTexture == null)
            {
                lastTexture = GeneFrmTx(new Bitmap(1, 1));
            }

            if (Texture == lastTexture)
            {
                return;
            }

            Texture = lastTexture;
        }
Example #2
0
        public void GetNowFrame(ref CTexture Texture)
        {
            if (this.bPlaying && decodedframes.Count != 0)
            {
                CTimer.t更新();
                if (decodedframes.TryPeek(out CDecodedFrame frame))
                {
                    while (frame.Time <= (CTimer.n現在時刻ms * _dbPlaySpeed))
                    {
                        if (decodedframes.TryDequeue(out CDecodedFrame cdecodedframe))
                        {
                            if (decodedframes.Count != 0)
                            {
                                if (decodedframes.TryPeek(out frame))
                                {
                                    if (frame.Time <= (CTimer.n現在時刻ms * _dbPlaySpeed))
                                    {
                                        cdecodedframe.Dispose();
                                        continue;
                                    }
                                }
                            }

                            lastTexture.UpdateTexture(cdecodedframe.Tex, cdecodedframe.size);

                            cdecodedframe.Dispose();
                        }
                        break;
                    }
                }

                if (DS == DecodingState.Stopped)
                {
                    this.EnqueueFrames();
                }
            }

            if (lastTexture == null)
            {
                lastTexture = new CTexture(new Device(), new Image <Rgba32>(FrameSize.Width, FrameSize.Height), false);
            }

            if (Texture == lastTexture)
            {
                return;
            }

            Texture = lastTexture;
        }
Example #3
0
        public void tGetBitmap(Device device, CTexture ctex, int timeMs, bool bCopyToCTex = true)
        {
            int pBufferSize = 0;

            DsError.ThrowExceptionForHR(grabber.GetCurrentBuffer(ref pBufferSize, IntPtr.Zero));
            if (samplePtr == IntPtr.Zero)
            {
                samplePtr = Marshal.AllocHGlobal(pBufferSize);
            }
            if (bCopyToCTex && ctex != null)
            {
                DataRectangle dataRectangle = ctex.texture.LockRectangle(0, LockFlags.None);
                DsError.ThrowExceptionForHR(grabber.GetCurrentBuffer(ref pBufferSize, dataRectangle.DataPointer));
                ctex.texture.UnlockRectangle(0);
            }
        }
Example #4
0
        public unsafe void tGetBitmap(SharpDX.Direct3D9.Device device, CTexture ctex, int timeMs)
        {
            int bufferSize = 0;
            int hr         = 0x0;

            hr = grabber.GetCurrentBuffer(ref bufferSize, IntPtr.Zero);
            DsError.ThrowExceptionForHR(hr);

            if (samplePtr == IntPtr.Zero)
            {
                samplePtr = Marshal.AllocHGlobal(bufferSize);
            }

            DataRectangle rectangle3 = ctex.texture.LockRectangle(0, SharpDX.Direct3D9.LockFlags.None);

            hr = grabber.GetCurrentBuffer(ref bufferSize, rectangle3.DataPointer);
            DsError.ThrowExceptionForHR(hr);
            ctex.texture.UnlockRectangle(0);
        }
Example #5
0
        private void GeneFrmTx(ref CTexture tex, byte[] bytearray)
        {
            //ポインタを使用し、データを直接バッファにコピーする
            if (tex == null || tex.texture == null)
            {
                GeneFrmTx(ref tex, new Bitmap(FrameSize.Width, FrameSize.Height));
            }

            DataRectangle data = tex.texture.LockRectangle(0, LockFlags.Discard);

            if (tex.szテクスチャサイズ.Width == FrameSize.Width)
            {
                Marshal.Copy(bytearray, 0, data.DataPointer, FrameSize.Width * FrameSize.Height * 4);
            }
            else
            {
                tex.Dispose();
                GeneFrmTx(ref tex, new Bitmap(FrameSize.Width, FrameSize.Height));
                Marshal.Copy(bytearray, 0, data.DataPointer, FrameSize.Width * FrameSize.Height * 4);
            }

            tex.texture.UnlockRectangle(0);
        }
Example #6
0
 public void Seek(long timestampms)
 {
     cts?.Cancel();
     while (DS != DecodingState.Stopped)
     {
         ;
     }
     if (ffmpeg.av_seek_frame(format_context, video_stream->index, timestampms, ffmpeg.AVSEEK_FLAG_BACKWARD) < 0)
     {
         Trace.TraceError("av_seek_frame failed\n");
     }
     ffmpeg.avcodec_flush_buffers(codec_context);
     CTimer.n現在時刻ms = timestampms;
     while (decodedframes.TryDequeue(out CDecodedFrame frame))
     {
         frame.Dispose();
     }
     this.EnqueueFrames();
     if (lastTexture != null)
     {
         lastTexture.Dispose();
     }
     lastTexture = new CTexture(new Device(), new Image <Rgba32>(FrameSize.Width, FrameSize.Height), false);
 }
Example #7
0
 public static Vector3 t論理画面座標をワールド座標へ変換する(Vector2 v2論理画面座標)
 {
     return(CTexture.t論理画面座標をワールド座標へ変換する(new Vector3(v2論理画面座標, 0f)));
 }
Example #8
0
 public static Vector3 t論理画面座標をワールド座標へ変換する(Point pt論理画面座標)
 {
     return(CTexture.t論理画面座標をワールド座標へ変換する(new Vector3(pt論理画面座標.X, pt論理画面座標.Y, 0.0f)));
 }
Example #9
0
 public static Vector3 t論理画面座標をワールド座標へ変換する(float x, float y)
 {
     return(CTexture.t論理画面座標をワールド座標へ変換する(new Vector3(x, y, 0f)));
 }
Example #10
0
 public static Vector3 t論理画面座標をワールド座標へ変換する(int x, int y)
 {
     return(CTexture.t論理画面座標をワールド座標へ変換する(new Vector3((float)x, (float)y, 0f)));
 }
Example #11
0
 private void GeneFrmTx(ref CTexture tex, Bitmap bitmap)
 {
     tex = new CTexture(this.device, bitmap, false);
 }
Example #12
0
        public unsafe void t現時点における最新のスナップイメージをTextureに転写する(CTexture texture)
        {
            int hr;

            #region [ 再生してないなら何もせず帰還。(一時停止中はOK。)]
            //-----------------
            if (!this.b再生中)
            {
                return;
            }
            //-----------------
            #endregion
            #region [ 音声のみなら何もしない。]
            //-----------------
            if (this.b音声のみ)
            {
                return;
            }
            //-----------------
            #endregion

            DataRectangle dr = texture.texture.LockRectangle(0, LockFlags.Discard);
            try
            {
                if (this.nスキャンライン幅byte == dr.Pitch)
                {
                    #region [ (A) ピッチが合うので、テクスチャに直接転送する。]
                    //-----------------
                    hr = this.memoryRenderer.GetCurrentBuffer(dr.DataPointer, this.nデータサイズbyte);
                    DsError.ThrowExceptionForHR(hr);
                    //-----------------
                    #endregion
                }
                else
                {
                    this.b上下反転 = false;                                 // こちらの方法では常に正常

                    #region [ (B) ピッチが合わないので、メモリに転送してからテクスチャに転送する。]
                    //-----------------

                    #region [ IMemoryRenderer からバッファにイメージデータを読み込む。]
                    //-----------------
                    if (this.ip == IntPtr.Zero)
                    {
                        this.ip = Marshal.AllocCoTaskMem(this.nデータサイズbyte);
                    }

                    hr = this.memoryRenderer.GetCurrentBuffer(this.ip, this.nデータサイズbyte);
                    DsError.ThrowExceptionForHR(hr);
                    //-----------------
                    #endregion

                    #region [ テクスチャにスナップイメージを転送。]
                    //-----------------
                    bool bARGB32 = true;

                    switch (texture.Format)
                    {
                    case Format.A8R8G8B8:
                        bARGB32 = true;
                        break;

                    case Format.X8R8G8B8:
                        bARGB32 = false;
                        break;

                    default:
                        return;                                         // 未対応のフォーマットは無視。
                    }

                    // スレッドプールを使って並列転送する準備。

                    this.ptrSnap = (byte *)this.ip.ToPointer();
                    var ptr = stackalloc UInt32 *[CDirectShow.n並列度];                            // stackalloc(GC対象外、メソッド終了時に自動開放)は、スタック変数相手にしか使えない。
                    ptr[0] = (UInt32 *)dr.DataPointer.ToPointer();                              //		↓
                    for (int i = 1; i < CDirectShow.n並列度; i++)                                  // スタック変数で確保、初期化して…
                    {
                        ptr[i] = ptr[i - 1] + this.n幅px;                                        //		↓
                    }
                    this.ptrTexture = ptr;                                                      // スタック変数をクラスメンバに渡す(これならOK)。


                    // 並列度が1ならシングルスレッド、2以上ならマルチスレッドで転送する。
                    // → CPUが1つの場合、わざわざスレッドプールのスレッドで処理するのは無駄。

                    if (CDirectShow.n並列度 == 1)
                    {
                        if (bARGB32)
                        {
                            this.tライン描画ARGB32(0);
                        }
                        else
                        {
                            this.tライン描画XRGB32(0);
                        }
                    }
                    else
                    {
                        // 転送開始。

                        var ar = new IAsyncResult[CDirectShow.n並列度];
                        for (int i = 0; i < CDirectShow.n並列度; i++)
                        {
                            ar[i] = (bARGB32) ?
                                    this.dgライン描画ARGB32[i].BeginInvoke(i, null, null) :
                                    this.dgライン描画XRGB32[i].BeginInvoke(i, null, null);
                        }


                        // 転送完了待ち。

                        for (int i = 0; i < CDirectShow.n並列度; i++)
                        {
                            if (bARGB32)
                            {
                                this.dgライン描画ARGB32[i].EndInvoke(ar[i]);
                            }
                            else
                            {
                                this.dgライン描画XRGB32[i].EndInvoke(ar[i]);
                            }
                        }
                    }

                    this.ptrSnap    = null;
                    this.ptrTexture = null;
                    //-----------------
                    #endregion

                    //-----------------
                    #endregion
                }
            }
            finally
            {
                texture.texture.UnlockRectangle(0);
            }
        }