private void OnDestroy()
 {
     isExit = true;
     DeleteSession();
     //释放动态库
     StreamDecoder.FreeLibrary();
 }
예제 #2
0
 private void OnDestroy()
 {
     applicationIsQuit = true;
     DeleteSession();
     //释放动态库
     StreamDecoder.FreeLibrary();
 }
예제 #3
0
        private Console()
        {
            ReadLock  = new Object();
            WriteLock = new Object();
            String csname = encoding();

            if (csname != null)
            {
                try
                {
                    Cs = Charset.ForName(csname);
                }
                catch (Exception)
                {
                }
            }
            if (Cs == null)
            {
                Cs = Charset.DefaultCharset();
            }
            @out           = StreamEncoder.forOutputStreamWriter(new FileOutputStream(FileDescriptor.@out), WriteLock, Cs);
            Pw             = new PrintWriterAnonymousInnerClassHelper(this, @out);
            Formatter      = new Formatter(@out);
            Reader_Renamed = new LineReader(this, StreamDecoder.forInputStreamReader(new FileInputStream(FileDescriptor.@in), ReadLock, Cs));
            Rcb            = new char[1024];
        }
예제 #4
0
 public FlacMediaDecoder()
 {
     this._streamDecoder = new StreamDecoder();
     this._streamDecoder.WriteCallback    += this.WriteCallback;
     this._streamDecoder.MetadataCallback += this.MetadataCallback;
     this._currentData = _noCurrentData;
 }
예제 #5
0
 public FlacMediaDecoder()
 {
     this._streamDecoder = new StreamDecoder();
     this._streamDecoder.WriteCallback += this.WriteCallback;
     this._streamDecoder.MetadataCallback += this.MetadataCallback;
     this._currentData = _noCurrentData;
 }
예제 #6
0
    // Use this for initialization
    void Start()
    {
        rimg.transform.parent.gameObject.SetActive(false);
        mat = rimg.material;
#if UNITY_EDITOR
        StreamDecoder.dllPath = Application.streamingAssetsPath + "/../../../../bin/";
#else
        StreamDecoder.dllPath = Application.streamingAssetsPath + "/../../../../../bin/";
#endif
        adbController.adbPath = StreamDecoder.dllPath + "adb.exe";

        //启动ADB
        adbController.AdbStartServer();


        StreamDecoder.LoadLibrary();
        player = StreamPlayer.CreateSession();
        player.SetOption(OptionType.DataCacheSize, 2000000);
        player.SetOption(OptionType.DemuxTimeout, 2000);
        //player.SetOption(OptionType.PushFrameInterval, 0);
        player.SetOption(OptionType.AlwaysWaitBitStream, 1);
        //player.SetOption(OptionType.WaitBitStreamTimeout, waitBitStreamTimeout);
        player.SetOption(OptionType.AutoDecode, 1);
        player.SetOption(OptionType.DecodeThreadCount, 0);
        //player.SetOption(OptionType.UseCPUConvertYUV, 0);
        //player.SetOption(OptionType.ConvertPixelFormat, (int)PixelFormat.RGBA);
        //player.SetOption(OptionType.AsyncUpdate, 0);
        player.SetPlayerCb(null, OnFrame);
    }
예제 #7
0
 public void SetEventCallBack(Action <int, int> onSessionEvent, Action <Frame> onFrameEvent, object opaque)
 {
     if (session == IntPtr.Zero)
     {
         return;
     }
     StreamDecoder._SetEventCallBack(session, opaque);
 }
예제 #8
0
        public MultiTest()
        {
            InitializeComponent();
            TextBox.CheckForIllegalCrossThreadCalls = false;
            ChatMsgReceivedEvent += chatMsgReceivedEventHandler;

            DecoderBufferSize = 0x5000;

            _secsDecoder = new StreamDecoder(DecoderBufferSize, HandleControlMessage, HandleDataMessage);

            messageBytes = new byte[DecoderBufferSize];
        }
예제 #9
0
    /// <summary>
    /// 创建一个StreamDecoder
    /// </summary>
    /// <param name="playerID">唯一ID</param>
    /// <param name="onReceiveEventCb">事件回调</param>
    /// <param name="onReceiveOneFrameCb">绘制回调</param>
    /// <returns></returns>
    public static StreamPlayer CreateSession()
    {
        int id = StreamDecoder.GetNewID();

        if (!StreamDecoder.IsInit)
        {
            StreamDecoder.InitStreamDecoder();
        }
        IntPtr s = Native.Invoke <IntPtr, StreamDecoder.CreateSession>(StreamDecoder.streamDecoder_dll, id);

        return(new StreamPlayer(s, id));
    }
예제 #10
0
    private void OnDestroy()
    {
        CloseServer();

        if (player != null)
        {
            StreamPlayer.DeleteSession(ref player);
        }

        StreamDecoder.FreeLibrary();

        isExit = true;
    }
예제 #11
0
        static void Main(string[] args)
        {
            var url = "http://www.quirksmode.org/html5/videos/big_buck_bunny.mp4";
            //var decoder = new OT2Player.VideoDecoder.VideoDecoder(OT2Player.VideoDecoder.Models.Codec.H264, new OT2Player.VideoDecoder.Models.Resolution());
            var decoder = new StreamDecoder(url, new Ot2Player.VideoDecoder.Models.DecoderConfiguration {
                outputPixelFormat = Models.PixelFormat.RGB, outputResolution = new Models.Resolution(1080, 1920)
            });

            decoder.newFrameEvent += NewFrame;
            decoder.Start();
            while (true)
            {
                ;
            }
        }
예제 #12
0
    // Use this for initialization
    void Start()
    {
#if UNITY_EDITOR
        StreamDecoder.dllPath = Application.streamingAssetsPath + "/../../../../bin/";
#else
        StreamDecoder.dllPath = Application.streamingAssetsPath + "/../../../../../bin/";
#endif

        //加载动态库
        if (!StreamDecoder.LoadLibrary())
        {
            return;
        }

        mat = rimg.material;
    }
예제 #13
0
        private static void RenderFrameX(StreamDecoder d, mfxFrameSurface1 surf)
        {
            var m_pDXGIBackBuffer = swapChain.GetBackBuffer <Texture2D>(0);

            if (useSystemMemoryNotVideoMemory)
            {
                Trace.Assert(surf.Data.B != IntPtr.Zero);

                //ResourceRegion? rr = new ResourceRegion(0, 0, 0, 1920, 1080, 1);
                ResourceRegion?rr = null;
                device.ImmediateContext.UpdateSubresource(m_pDXGIBackBuffer, 0, rr, surf.Data.B, surf.Data.Pitch, 0);
            }
            else
            {
                Trace.Assert(surf.Data.MemId != IntPtr.Zero);

                IntPtr dx11frameHandle = d.lowLevelDecoder.videoAccelerationSupport.FrameGetHandle(surf.Data.MemId);
                //  CustomMemId* cm = (CustomMemId*)
                var texture2d = new Texture2D(dx11frameHandle);
                device.ImmediateContext.CopySubresourceRegion(texture2d, 0, null, m_pDXGIBackBuffer, 0);
            }

            swapChain.Present(2, PresentFlags.None);
        }
예제 #14
0
        static void Main(string[] args)
        {
            if (Directory.Exists(FramesDir))
            {
                Directory.Delete(FramesDir, true);
            }

            if (!Directory.Exists(FramesDir))
            {
                Directory.CreateDirectory(FramesDir);
            }

            var decoder = new StreamDecoder();

            decoder.OnFrameReceived += Decoder_OnFrameReceived;
            decoder.StartDecodingAsync("http://83.128.74.78:8083/mjpg/video.mjpg");

            Console.ReadLine();

            //while (true)
            //{
            //    Thread.Sleep(1000);

            //    var frame = decoder.GetLastFrame();

            //    if (frame == null) continue;

            //    Console.WriteLine($"Frame received at: {DateTime.Now}");

            //    using (FileStream fs = new FileStream($"Frames\\{DateTime.Now:HH-mm-ss}.jpeg", FileMode.CreateNew))
            //    {
            //        fs.Write(frame, 0, frame.Length);
            //        fs.Flush();
            //    }
            //}
        }
예제 #15
0
        unsafe static void Main(string[] args)
        {
            ConfirmQuickSyncReadiness.HaltIfNotReady();

            Environment.CurrentDirectory = AppDomain.CurrentDomain.BaseDirectory;
            // keep ascending directories until 'media' folder is found
            for (int i = 0; i < 10 && !Directory.Exists("Media"); i++)
            {
                Directory.SetCurrentDirectory("..");
            }
            Directory.SetCurrentDirectory("Media");


            CodecId codecId = CodecId.MFX_CODEC_JPEG;
            FourCC  fourcc  = FourCC.UYVY;  // supported: RGB4, YUY2 NV12 [UYVY through tricks! see below]
            mfxIMPL impl    = mfxIMPL.MFX_IMPL_AUTO;



            string fourccString = fourcc.ToString().Substring(0, 4);
            string inFilename;

            //inFilename = "BigBuckBunny_320x180.UYVY.enc.jpeg";
            inFilename = "BigBuckBunny_1920x1080.UYVY.enc.jpeg";
            //inFilename = "BigBuckBunny_3840x2160.UYVY.enc.jpeg";
            string outFilename = Path.ChangeExtension(inFilename, ".yuv");

            Console.WriteLine("Working directory: {0}", Environment.CurrentDirectory);
            Console.WriteLine("Input filename: {0}", inFilename);
            Console.WriteLine();

            if (!File.Exists(inFilename))
            {
                Console.WriteLine("Input file not found. Press any key to exit.");
                Console.ReadKey();
                return;
            }


            Stream         infs, outfs;
            BenchmarkTimer bt = null;


#if !ENABLE_BENCHMARK
            infs  = File.Open(inFilename, FileMode.Open);
            outfs = File.Open(outFilename, FileMode.Create);
#else       // delete this code for most simple example
            // * Benchmark Mode *
            // this block does a couple things:
            //   1. causes the file to be pre-read into memory so we are not timing disk reads.
            //   2. replaces the output stream with a NullStream so nothing gets written to disk.
            //   3. Starts the timer for benchmarking
            // this pre-reads file into memory for benchmarking
            long maximumMemoryToAllocate = (long)4L * 1024 * 1024 * 1024;
            Console.WriteLine("Pre-reading input");
            infs = new PreReadLargeMemoryStream(File.Open(inFilename, FileMode.Open), maximumMemoryToAllocate);



            Console.WriteLine("Input read");

            outfs = new NullStream();
            bt    = new BenchmarkTimer();
            bt.Start();

            int minimumFrames = 4000;
#endif



            Console.WriteLine("Output filename: {0}",
                              Path.GetFileName((outfs as FileStream)?.Name ?? "NO OUTPUT"));
            Console.WriteLine();

            var outIOPattern = IOPattern.MFX_IOPATTERN_OUT_SYSTEM_MEMORY;


            // The encoder cannot encode UYVY, but if you are the only decoder of the JPEG
            // files, you can encode UYVY as YUY2 and everything is good.
            if (fourcc == FourCC.UYVY)
            {
                fourcc = FourCC.YUY2;
            }

            mfxVideoParam decoderParameters = QuickSyncStatic.ReadFileHeaderInfo(codecId, impl, infs, outIOPattern);
            decoderParameters.mfx.FrameInfo.FourCC = fourcc;

            AssignChromaFormat(fourcc, ref decoderParameters);


            var decoder = new StreamDecoder(infs, decoderParameters, null, impl);

#if ENABLE_BENCHMARK     // delete this code for most simple example
            decoder.benchmarkNeverStopMode = true;
#endif

            string impltext = QuickSyncStatic.ImplementationString(decoder.lowLevelDecoder.session);
            Console.WriteLine("Implementation = {0}", impltext);

            // not needed
            //var formatConverter = new NV12ToXXXXConverter(fourcc, decoder.width, decoder.height);

            int width  = decoderParameters.mfx.FrameInfo.CropW;
            int height = decoderParameters.mfx.FrameInfo.CropH;
            var tmpbuf = new byte[width * height * 2];

            int count = 0;

            foreach (var frame in decoder.GetFrames())
            {
                //var frameBytes = formatConverter.ConvertFromNV12(frame.Data);        // Convert to format requested


                Trace.Assert(frame.Data.Pitch == width * 2);  // yuy2 only

                fixed(byte *aa = &tmpbuf[0])
                FastMemcpyMemmove.memcpy((IntPtr)aa, frame.Data.Y, height * width * 2);

                outfs.Write(tmpbuf, 0, tmpbuf.Length);

                if (++count % 100 == 0)
                {
                    Console.Write("Frame {0}\r", count);
                }

#if ENABLE_BENCHMARK     // delete this code for most simple example
                if (count > minimumFrames)
                {
                    break;
                }
#endif
            }

            if (bt != null)
            {
                bt.StopAndReport(count, infs.Position, outfs.Position);
            }

            infs.Close();
            outfs.Close();

            Console.WriteLine("Decoded {0} frames", count);

            // make sure program always waits for user, except F5-Release run
            if (Debugger.IsAttached ||
                Environment.GetEnvironmentVariable("VisualStudioVersion") == null)
            {
                Console.WriteLine("done - press a key to exit");
                Console.ReadKey();
            }
        }
예제 #16
0
        unsafe static void Main(string[] args)
        {
            ConfirmQuickSyncReadiness.HaltIfNotReady();

            if (Environment.OSVersion.Platform != PlatformID.Win32NT)
            {
                throw new Exception("DirectX sample only works on Windows");
            }


            Environment.CurrentDirectory = AppDomain.CurrentDomain.BaseDirectory;
            // keep ascending directories until 'media' folder is found
            for (int i = 0; i < 10 && !Directory.Exists("Media"); i++)
            {
                Directory.SetCurrentDirectory("..");
            }
            Directory.SetCurrentDirectory("Media");

            string fn;

            fn = @"BigBuckBunny_320x180.264";
            //fn = @"C:\w\BigBuckBunny_1920x1080.264";
            //fn = @"C:\w\bbb_sunflower_2160p_30fps_normal_track1.h264";


            var s = File.Open(fn, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);


            var buf = new byte[1000];
            int n   = s.Read(buf, 0, buf.Length);

            s.Position = 0;
            Trace.Assert(n == buf.Length);

            var decVideoParam = QuickSyncStatic.DecodeHeader(buf, CodecId.MFX_CODEC_AVC);

            mfxVideoParam vppVideoParam = new mfxVideoParam();// = SetupVPPConfiguration(decVideoParam.mfx.FrameInfo.CropW, decVideoParam.mfx.FrameInfo.CropH);

            vppVideoParam.vpp.In  = decVideoParam.mfx.FrameInfo;
            vppVideoParam.vpp.Out = decVideoParam.mfx.FrameInfo;

            decVideoParam.IOPattern = IOPattern.MFX_IOPATTERN_OUT_SYSTEM_MEMORY;
            vppVideoParam.IOPattern = IOPattern.MFX_IOPATTERN_IN_SYSTEM_MEMORY;

            vppVideoParam.IOPattern |= useSystemMemoryNotVideoMemory ?
                                       IOPattern.MFX_IOPATTERN_OUT_SYSTEM_MEMORY : IOPattern.MFX_IOPATTERN_OUT_VIDEO_MEMORY;

            int vppOutWidth;
            int vppOutHeight;

            Console.WriteLine($"Bitstream -- width {0} height {1}",
                              decVideoParam.mfx.FrameInfo.CropW,
                              decVideoParam.mfx.FrameInfo.CropH);

            // vppOutWidth = 1920;
            //  vppOutHeight = 1080;
            bool doResize = true;

            if (doResize)
            {
            }
            else
            {
            }
            vppOutWidth  = decVideoParam.mfx.FrameInfo.CropW; // HxW of actual bitstream
            vppOutHeight = decVideoParam.mfx.FrameInfo.CropH;

            //resizing setup
            vppOutWidth  = decVideoParam.mfx.FrameInfo.CropW / 4;
            vppOutHeight = decVideoParam.mfx.FrameInfo.CropH / 4;

            Console.WriteLine($"VPP output -- width {0} height {1}",
                              vppOutWidth,
                              vppOutHeight);

            vppVideoParam.vpp.Out.FourCC = FourCC.RGB4;
            vppVideoParam.vpp.Out.CropW  = (ushort)(vppOutWidth);
            vppVideoParam.vpp.Out.CropH  = (ushort)(vppOutHeight);

            var form = new SharpDX.Windows.RenderForm();


            form.Width = vppOutWidth; form.Height = vppOutHeight;                                            // use resized HxW
            form.Width = decVideoParam.mfx.FrameInfo.CropW; form.Height = decVideoParam.mfx.FrameInfo.CropH; // use original HxW

            Console.WriteLine($"vppOutWidth {vppOutWidth}  vppOutHeight {vppOutHeight}");
            Console.WriteLine($"form.Width {form.Width}  form.Height {form.Height}");



            var impl = mfxIMPL.MFX_IMPL_VIA_D3D11 | mfxIMPL.MFX_IMPL_HARDWARE;

            var decoder = new StreamDecoder(s, decVideoParam, vppVideoParam, impl);

            //string impltext = QuickSyncStatic.ImplementationString(decoder.lowLevelDecoder.session);
            //Console.WriteLine("Implementation = {0}", impltext);
            //string memtext = QuickSyncStatic.ImplementationString(decoder.lowLevelDecoder.deviceSetup.memType);
            //Console.WriteLine("Memory type = {0}", memtext);


            if (useSystemMemoryNotVideoMemory)
            {
                device = new SharpDX.Direct3D11.Device(DriverType.Hardware);
            }
            else
            {
                IntPtr dx11device = decoder.lowLevelDecoder.videoAccelerationSupport.DeviceGetHandle(mfxHandleType.MFX_HANDLE_D3D11_DEVICE);
                device = new SharpDX.Direct3D11.Device(dx11device);
            }



            var fps = new FPSCounter();



            var sd = new SwapChainDescription()
            {
                BufferCount       = 1,
                ModeDescription   = new ModeDescription(vppOutWidth, vppOutHeight, new Rational(60, 1), Format.B8G8R8A8_UNorm),
                IsWindowed        = true,
                OutputHandle      = form.Handle,
                SampleDescription = new SampleDescription(1, 0),
                SwapEffect        = SwapEffect.Discard,
                Usage             = Usage.RenderTargetOutput,
                Flags             = SwapChainFlags.None
            };

            var a = device.QueryInterface <SharpDX.DXGI.Device>();
            var b = a.Adapter.QueryInterface <Adapter2>();
            var c = b.GetParent <Factory2>();

            swapChain = new SwapChain(c, device, sd);


            var enumerator = decoder.GetFrames().GetEnumerator();

            RenderLoop.Run(form, () =>
            {
                enumerator.MoveNext();
                RenderFrameX(decoder, enumerator.Current);
                fps.PrintFPS();
            });


            swapChain.Dispose();
            device.Dispose();
        }
예제 #17
0
 public SimpleService()
 {
     _decoder = new StreamDecoder();
 }
예제 #18
0
        static public void Main()
        {
            ConfirmQuickSyncReadiness.HaltIfNotReady();

            Environment.CurrentDirectory = AppDomain.CurrentDomain.BaseDirectory;
            // keep ascending directories until 'media' folder is found
            for (int i = 0; i < 10 && !Directory.Exists("Media"); i++)
            {
                Directory.SetCurrentDirectory("..");
            }
            Directory.SetCurrentDirectory("Media");

            mfxIMPL impl    = mfxIMPL.MFX_IMPL_AUTO; //automatic GPU/CPU mode
            CodecId codecId = CodecId.MFX_CODEC_AVC;
            // avc fourcc supported: RGB3 RGB4 BGR4 BGR3 NV12 I420 IYUV YUY2 UYVY YV12 P411 P422
            FourCC fourcc       = FourCC.NV12;
            string fourccString = fourcc.ToString().Substring(0, 4);

            string inFilename;

            inFilename = "BigBuckBunny_320x180.264";
            //inFilename = "BigBuckBunny_1920x1080.264";
            //inFilename = "BigBuckBunny_3840x2160.264";
            string outFilename = Path.ChangeExtension(inFilename, fourccString + ".yuv");

            Console.WriteLine("Working directory: {0}", Environment.CurrentDirectory);
            Console.WriteLine("Input filename: {0}", inFilename);
            Console.WriteLine();

            if (!File.Exists(inFilename))
            {
                Console.WriteLine("Input file not found. Press any key to exit.");
                Console.ReadKey();
                return;
            }


            Stream         infs, outfs;
            BenchmarkTimer bt = null;


#if !ENABLE_BENCHMARK
            infs  = File.Open(inFilename, FileMode.Open);
            outfs = File.Open(outFilename, FileMode.Create);
#else       // delete this code for most simple example
            // * Benchmark Mode *
            // this block does a couple things:
            //   1. causes the file to be pre-read into memory so we are not timing disk reads.
            //   2. replaces the output stream with a NullStream so nothing gets written to disk.
            //   3. Starts the timer for benchmarking
            // this pre-reads file into memory for benchmarking
            // maximumMemoryToAllocate = (long)4L * 1024 * 1024 * 1024;
            Console.WriteLine("Pre-reading input");
            infs = new PreReadLargeMemoryStream(File.Open(inFilename, FileMode.Open));
            Console.WriteLine("Input read");

            outfs = new NullStream();
            bt    = new BenchmarkTimer();
            bt.Start();

            //int minimumFrames = 4000;
#endif

            Console.WriteLine("Output filename: {0}",
                              Path.GetFileName((outfs as FileStream)?.Name ?? "NO OUTPUT"));
            Console.WriteLine();

            var outIOPattern = IOPattern.MFX_IOPATTERN_OUT_SYSTEM_MEMORY;

            mfxVideoParam decoderParameters = QuickSyncStatic.ReadFileHeaderInfo(codecId, impl, infs, outIOPattern);
            decoderParameters.mfx.FrameInfo.FourCC = fourcc;

            var decoder = new StreamDecoder(infs, CodecId.MFX_CODEC_AVC, impl, outIOPattern);

            string impltext = QuickSyncStatic.ImplementationString(decoder.lowLevelDecoder.session);
            Console.WriteLine("Implementation = {0}", impltext);



            var formatConverter = new NV12ToXXXXConverter(fourcc, decoder.width, decoder.height);



            int count = 0;



            foreach (var frame in decoder.GetFrames())
            {
                var frameBytes = formatConverter.ConvertFromNV12(frame.Data);        // Convert to format requested
                outfs.Write(frameBytes, 0, frameBytes.Length);



                if (++count % 100 == 0)
                {
                    Console.Write("Frame {0}\r", count);
                }
            }
            Console.WriteLine("Decoded {0} frames", count);
            Console.WriteLine();

            if (bt != null)
            {
                bt.StopAndReport(count, infs.Position, outfs.Position);
            }

            infs.Close();
            outfs.Close();



            // make sure program always waits for user, except F5-Release run
            if (!UnitTest.IsRunning && Debugger.IsAttached ||
                Environment.GetEnvironmentVariable("VisualStudioVersion") == null)
            {
                Console.WriteLine("done - press a key to exit");
                Console.ReadKey();
            }
        }
예제 #19
0
 public void Initialize()
 {
     _decoder = new StreamDecoder();
 }
예제 #20
0
        // -- Character streams from channels --

        /// <summary>
        /// Constructs a reader that decodes bytes from the given channel using the
        /// given decoder.
        ///
        /// <para> The resulting stream will contain an internal input buffer of at
        /// least <tt>minBufferCap</tt> bytes.  The stream's <tt>read</tt> methods
        /// will, as needed, fill the buffer by reading bytes from the underlying
        /// channel; if the channel is in non-blocking mode when bytes are to be
        /// read then an <seealso cref="IllegalBlockingModeException"/> will be thrown.  The
        /// resulting stream will not otherwise be buffered, and it will not support
        /// the <seealso cref="Reader#mark mark"/> or <seealso cref="Reader#reset reset"/> methods.
        /// Closing the stream will in turn cause the channel to be closed.  </para>
        /// </summary>
        /// <param name="ch">
        ///         The channel from which bytes will be read
        /// </param>
        /// <param name="dec">
        ///         The charset decoder to be used
        /// </param>
        /// <param name="minBufferCap">
        ///         The minimum capacity of the internal byte buffer,
        ///         or <tt>-1</tt> if an implementation-dependent
        ///         default capacity is to be used
        /// </param>
        /// <returns>  A new reader </returns>
        public static Reader NewReader(ReadableByteChannel ch, CharsetDecoder dec, int minBufferCap)
        {
            CheckNotNull(ch, "ch");
            return(StreamDecoder.forDecoder(ch, dec.Reset(), minBufferCap));
        }