Beispiel #1
0
        static void Main()
        {
            VRpalyer  mp = new VRpalyer();
            SDLHelper s  = new SDLHelper();

            int gap_h  = 3;
            int gap_w  = 3;
            int width  = 240;
            int height = 240;

            s.SDL_Init(width * gap_w, height * gap_h);
            Thread videoPlayer = new Thread(() => mp.RunVideo(gap_h, gap_w, width, height, s));

            //videoPlayer.IsBackground = true;
            videoPlayer.Start();

            //mp.RunVideo(480,480, s);
        }
Beispiel #2
0
        /// <summary>
        /// 音频AAC转PCM并使用SDL进行播放
        /// </summary>
        /// <param name="fileName"></param>
        /// <param name="sdlAudio"></param>
        /// <returns></returns>



        /// <summary>
        /// 开启线程
        /// </summary>
        /// <param name="fileName"></param>
        /// <param name="sdlVideo"></param>
        public void Start(int width, int height, SDLHelper sdlVideo)
        {
            // 视频线程
            threadVideo = new Thread(() =>
            {
                try
                {
                    RunVideo(1, 1, width, height, sdlVideo);
                }
                catch (Exception ex)
                {
                    //SQ.Base.ErrorLog.WriteLog4Ex("JT1078CodecForMp4.Run Video", ex);
                    Console.WriteLine(ex.ToString());
                    return;
                }
            });
            threadVideo.IsBackground = true;
            threadVideo.Start();

            /*
             * // 音频线程
             * threadAudio = new Thread(() =>
             * {
             *  try
             *  {
             *      RunAudio(fileName, sdlAudio);
             *  }
             *  catch (Exception ex)
             *  {
             *      Console.WriteLine(ex.ToString());
             *      return;
             *  }
             * });
             * threadAudio.IsBackground = true;
             * threadAudio.Start();
             */
        }
Beispiel #3
0
        public unsafe int RunVideo(int gap_h, int gap_w, int width, int height, SDLHelper sdlVideo)  //这个是用来渲染整个大画面的
        {
            int          frame_count = 0;
            Produce_data p           = new Produce_data();

            fq              = new FrameQueue();
            p.gap_h         = gap_h;
            p.gap_w         = gap_w;
            p.target_height = height;
            p.target_width  = width;
            IsRun           = true;
            exit_thread     = false;
            pause_thread    = false;
            threadVideo     = Thread.CurrentThread;
            SDL.SDL_Event even    = new SDL.SDL_Event();
            Thread        refresh = new Thread(() => sfp_refresh_thread());
            Thread        produce = new Thread(() => ProduceFrame(ref p));

            refresh.Start();
            produce.Start();
            System.Diagnostics.Stopwatch stopwatch = new System.Diagnostics.Stopwatch();
            try
            {
                for (; ;)
                {
                    //Wait
                    SDL.SDL_WaitEvent(out even);
                    if (even.type == SFM_REFRESH_EVENT)
                    {
                        FrameBuffer fb;
                        // 退出线程
                        if (exit_thread)
                        {
                            break;
                        }
                        // 暂停解析
                        if (pause_thread)
                        {
                            while (pause_thread)
                            {
                                Thread.Sleep(1);
                            }
                        }

                        while (true)
                        {
                            GetFrame(out fb);
                            if (fb == null)
                            {
                                Thread.Sleep(1);
                            }
                            else
                            {
                                fq.Pop();
                                break;
                            }
                            // Console.WriteLine("尚味获取到帧");
                        }
                        frame_count++;
                        //SDL播放YUV数据
                        //var data = fb.outbuffer;


                        int     out_buffer_size = fb.outbuffersize;
                        AVFrame pFrameYUV       = fb.av;
                        sdlVideo.SDL_Display(width * gap_w, height * gap_h, (IntPtr)(pFrameYUV.data[0]), out_buffer_size, pFrameYUV.linesize[0]);


                        //  Console.WriteLine("渲染第" + frame_count.ToString() + "帧");
                        if (frame_count == 1)
                        {
                            stopwatch.Start();
                        }
                        if (frame_count == 1000)
                        {
                            stopwatch.Stop();
                            TimeSpan timespan = stopwatch.Elapsed;
                            Console.WriteLine(timespan.TotalSeconds.ToString());
                            Thread.Sleep(100000);
                        }
                    }
                    else if (even.type == SDL.SDL_EventType.SDL_KEYDOWN)
                    {
                        //Pause
                        if (even.key.keysym.sym == SDL.SDL_Keycode.SDLK_SPACE)
                        {
                            thread_pause = 1 - thread_pause;
                        }
                    }
                    else if (even.type == SDL.SDL_EventType.SDL_QUIT)
                    {
                        thread_exit = 1;
                    }
                    else if (even.type == SFM_BREAK_EVENT)
                    {
                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
            finally
            {
            }
            IsRun = false;
            return(0);
        }