Example #1
0
        private void timerRestartAudio_Tick(object sender, EventArgs e)
        {
            timerRestartAudio.Stop();
            timerRestartAudio.Enabled = false;

            if (m_NeedToStopAll)
            {
                return;
            }

            if (!ckbAutoRestart.Checked || timerRestartAudio.Interval < 1000)
            {
                LogAudioMsg("Cancelled audio restart.\n");
                return;
            }
            if (m_AudioProcess != null && !m_AudioProcess.HasExited())
            {
                return;
            }

            if (m_AudioArgs.Length > 0)
            {
                try
                {
                    if (m_AudioProcess != null)
                    {
                        m_AudioProcess.StopRunningProcess();
                    }
                }
                catch { }

                if (m_AudioArgs.Contains("-f nut pipe:1"))
                {
                    // in this case, Process.Kill() will just kill "cmd", but not "ffmpeg" ...
                    m_AudioProcess = new ProcessIoWrapper("cmd", "/C ffmpeg " + m_AudioArgs, ProcessIoWrapper.FLAG_INPUT | ProcessIoWrapper.FLAG_ERROR);
                }
                else
                {
                    m_AudioProcess = new ProcessIoWrapper("ffmpeg", m_AudioArgs, ProcessIoWrapper.FLAG_INPUT | ProcessIoWrapper.FLAG_ERROR);
                }

                m_LastAudioTime = DateTime.Now;

                //m_ProcessIoWrapper.OnStandardOutputTextRead = new Action<string>((text) => { OnStderrTextRead(text); });
                m_AudioProcess.OnStandardErrorTextRead = new Action <string>((text) => { OnAudioStderrTextRead(text); });
                m_AudioProcess.OnProcessExited         = new Action(() => { OnAudioProcessExited(); });
                m_AudioProcess.StartProcess();
            }
        }
Example #2
0
        private void StopRunningProcesses()
        {
            try
            {
                if (m_VideoProcess != null)
                {
                    m_VideoProcess.WriteStandardInput("q\n");
                    Thread.Sleep(200);
                }
            }
            catch { }

            try
            {
                if (m_VideoProcess != null)
                {
                    m_VideoProcess.StopRunningProcess();
                }
            }
            catch { }

            m_VideoProcess = null;

            try
            {
                if (m_AudioProcess != null)
                {
                    m_AudioProcess.WriteStandardInput("q\n");
                    Thread.Sleep(200);
                }
            }
            catch { }

            try
            {
                if (m_AudioProcess != null)
                {
                    m_AudioProcess.StopRunningProcess();
                }
            }
            catch { }

            m_AudioProcess = null;
        }
Example #3
0
        private void timerRestartVideo_Tick(object sender, EventArgs e)
        {
            timerRestartVideo.Stop();
            timerRestartVideo.Enabled = false;

            if (!ckbAutoRestart.Checked || timerRestartVideo.Interval < 1000)
            {
                LogVideoMsg("Cancelled video restart.\n");
                return;
            }
            if (m_VideoProcess != null && !m_VideoProcess.HasExited())
            {
                return;
            }

            if (m_VideoArgs.Length > 0)
            {
                try
                {
                    if (m_VideoProcess != null)
                    {
                        m_VideoProcess.StopRunningProcess();
                    }
                }
                catch { }

                if (m_VideoArgs.Contains("-f nut pipe:1"))
                {
                    m_VideoProcess = new ProcessIoWrapper("cmd", "/C ffmpeg " + m_VideoArgs, ProcessIoWrapper.FLAG_INPUT | ProcessIoWrapper.FLAG_ERROR);
                }
                else
                {
                    m_VideoProcess = new ProcessIoWrapper("ffmpeg", m_VideoArgs, ProcessIoWrapper.FLAG_INPUT | ProcessIoWrapper.FLAG_ERROR);
                }

                //m_ProcessIoWrapper.OnStandardOutputTextRead = new Action<string>((text) => { OnStderrTextRead(text); });
                m_VideoProcess.OnStandardErrorTextRead = new Action <string>((text) => { OnVideoStderrTextRead(text); });
                m_VideoProcess.OnProcessExited         = new Action(() => { OnVideoProcessExited(); });
                m_VideoProcess.StartProcess();
            }
        }
Example #4
0
        private void StopRunningProcesses()
        {
            try
            {
                if (m_VideoProcess != null)
                {
                    m_VideoProcess.StopRunningProcess();
                }
            }
            catch { }

            m_VideoProcess = null;

            try
            {
                if (m_AudioProcess != null)
                {
                    m_AudioProcess.StopRunningProcess();
                }
            }
            catch { }

            m_AudioProcess = null;
        }
Example #5
0
        private void btnStart_Click(object sender, EventArgs e)
        {
            if (m_NeedToStopAll)
            {
                return;
            }

            if (ckbAutoRestart.Enabled && !ckbAutoRestart.Checked)
            {
                if (MessageBox.Show("Do you want to enable 'auto-restart' at the same time ?", this.Text, MessageBoxButtons.YesNo) == DialogResult.Yes)
                {
                    ckbAutoRestart.Checked = true;
                }
            }

            List <string> input = new List <string>();

            string outputVideo = "";
            string outputAudio = "";

            input = GenInputPart();
            if (input.Count <= 0)
            {
                return;
            }

            outputVideo = CommandGenerator.GenVideoOutputPart(m_VideoOutputTaskGroup.Tasks);
            outputAudio = CommandGenerator.GenAudioOutputPart(m_AudioOutputTaskGroup.Tasks, m_EncoderAAC);

            if (outputVideo.Length <= 0 && outputAudio.Length <= 0)
            {
                return;
            }

            if (input.Count <= 1)
            {
                m_VideoArgs = input[0] + " " + outputVideo + " " + outputAudio;
                m_AudioArgs = "";
            }
            else
            {
                var mpegItemCount = 0;
                foreach (var taskItem in m_VideoOutputTaskGroup.Tasks)
                {
                    if (taskItem.VideoType == "mpeg")
                    {
                        mpegItemCount++;
                    }
                }
                if (mpegItemCount > 0 && mpegItemCount == m_VideoOutputTaskGroup.Tasks.Count)
                {
                    m_VideoArgs = input[0] + " " + input[1] + " " + outputVideo;
                }
                else
                {
                    m_VideoArgs = outputVideo.Trim().Length <= 0 ? "" : (input[0].Trim().Length > 0 ? input[0] + " " + outputVideo : "");
                }

                m_AudioArgs = outputAudio.Trim().Length <= 0 ? "" : (input[1].Trim().Length > 0 ? input[1] + " " + outputAudio : "");
            }

            m_VideoArgs = m_VideoArgs.Trim();
            m_AudioArgs = m_AudioArgs.Trim();

            //MessageBox.Show(args);
            Console.WriteLine(m_VideoArgs);
            Console.WriteLine(m_AudioArgs);

            gbMediaSource.Enabled = false;
            gbVideoTask.Enabled   = false;
            gbAudioTask.Enabled   = false;

            btnStart.Enabled = false;

            m_UpdatedUI4Start = false;


            try
            {
                StopRunningProcesses();

                mmVideoLogger.Clear();
                mmAudioLogger.Clear();

                if (m_VideoArgs.Length > 0)
                {
                    if (m_VideoArgs.Contains("-f nut pipe:1"))
                    {
                        // in this case, Process.Kill() will just kill "cmd", but not "ffmpeg" ...
                        m_VideoProcess = new ProcessIoWrapper("cmd", "/C ffmpeg " + m_VideoArgs, ProcessIoWrapper.FLAG_INPUT | ProcessIoWrapper.FLAG_ERROR);
                    }
                    else
                    {
                        m_VideoProcess = new ProcessIoWrapper("ffmpeg", m_VideoArgs, ProcessIoWrapper.FLAG_INPUT | ProcessIoWrapper.FLAG_ERROR);
                    }

                    m_LastVideoTime = DateTime.Now;

                    //m_ProcessIoWrapper.OnStandardOutputTextRead = new Action<string>((text) => { OnStderrTextRead(text); });
                    m_VideoProcess.OnStandardErrorTextRead = new Action <string>((text) => { OnVideoStderrTextRead(text); });
                    m_VideoProcess.OnProcessExited         = new Action(() => { OnVideoProcessExited(); });
                    m_VideoProcess.StartProcess();
                }

                if (m_AudioArgs.Length > 0)
                {
                    if (m_AudioArgs.Contains("-f nut pipe:1"))
                    {
                        // in this case, Process.Kill() will just kill "cmd", but not "ffmpeg" ...
                        m_AudioProcess = new ProcessIoWrapper("cmd", "/C ffmpeg " + m_AudioArgs, ProcessIoWrapper.FLAG_INPUT | ProcessIoWrapper.FLAG_ERROR);
                    }
                    else
                    {
                        m_AudioProcess = new ProcessIoWrapper("ffmpeg", m_AudioArgs, ProcessIoWrapper.FLAG_INPUT | ProcessIoWrapper.FLAG_ERROR);
                    }

                    m_LastAudioTime = DateTime.Now;

                    //m_ProcessIoWrapper.OnStandardOutputTextRead = new Action<string>((text) => { OnStderrTextRead(text); });
                    m_AudioProcess.OnStandardErrorTextRead = new Action <string>((text) => { OnAudioStderrTextRead(text); });
                    m_AudioProcess.OnProcessExited         = new Action(() => { OnAudioProcessExited(); });
                    m_AudioProcess.StartProcess();
                }

                btnStop.Enabled = true;

                notifyIconMain.Icon = notifyIconStart.Icon;
                notifyIconMain.Text = this.Text + " (" + notifyIconStart.Text + ")";
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
                m_UpdatedUI4Start     = true;
                gbMediaSource.Enabled = true;
                gbVideoTask.Enabled   = true;
                gbAudioTask.Enabled   = true;
                btnStart.Enabled      = true;
            }
        }
Example #6
0
        private void timerCheckRecvTimeout_Tick(object sender, EventArgs e)
        {
            BeginInvoke((Action)(() =>
            {
                DateTime currentTime = DateTime.Now;

                var maxIdleTime = m_MaxRecvIdleSeconds;
                if (maxIdleTime <= 0)
                {
                    return;
                }

                try
                {
                    if (btnStart.Enabled == false && btnStop.Enabled == true)
                    {
                        var seconds = (currentTime - m_LastVideoTime).TotalSeconds;
                        if (seconds > maxIdleTime)
                        {
                            try
                            {
                                if (m_VideoProcess != null)
                                {
                                    m_VideoProcess.WriteStandardInput("q\n");
                                    Thread.Sleep(200);
                                }
                            }
                            catch { }

                            try
                            {
                                if (m_VideoProcess != null)
                                {
                                    m_VideoProcess.StopRunningProcess();
                                }
                            }
                            catch { }

                            m_VideoProcess = null;

                            m_LastVideoTime = DateTime.Now;
                        }
                    }
                }
                catch { }

                try
                {
                    if (btnStart.Enabled == false && btnStop.Enabled == true)
                    {
                        var seconds = (currentTime - m_LastAudioTime).TotalSeconds;
                        if (seconds > maxIdleTime)
                        {
                            try
                            {
                                if (m_AudioProcess != null)
                                {
                                    m_AudioProcess.WriteStandardInput("q\n");
                                    Thread.Sleep(200);
                                }
                            }
                            catch { }

                            try
                            {
                                if (m_AudioProcess != null)
                                {
                                    m_AudioProcess.StopRunningProcess();
                                }
                            }
                            catch { }

                            m_AudioProcess = null;

                            m_LastAudioTime = DateTime.Now;
                        }
                    }
                }
                catch { }
            }));
        }