Пример #1
0
 /// <summary>
 /// Clear the queue and add 1 item in the same operation. This is useful
 /// for operation that take precedence over all others (like closing and errors)
 /// </summary>
 /// <param name="elem">New item to add</param>
 public void ClearAndEnqueue(WorkQueueElement elem)
 {
     lock (m_queue)
     {
         m_queue.Clear();
         m_queue.Enqueue(elem);
         m_queueHasItemsEvent.Set();
     }
 }
Пример #2
0
 /// <summary>
 /// Clear the queue and add 1 item in the same operation. This is useful
 /// for operation that take precedence over all others (like closing and errors)
 /// </summary>
 /// <param name="elem">New item to add</param>
 public void ClearAndEnqueue(WorkQueueElement elem)
 {
     lock (m_queue)
     {
         m_queue.Clear();
         m_queue.Enqueue(elem);
         m_queueHasItemsEvent.Set();
     }
 }
Пример #3
0
        private void timer_Tick(object sender)
        {
            Utility.Trace(String.Format("MUXProvider.timer_Tick second {0}", m_sec));

            if (m_sec > 5)
            {
                // stop the timer
                m_timer.Change(System.Threading.Timeout.Infinite, System.Threading.Timeout.Infinite);

                WorkQueueElement element = new WorkQueueElement(WorkQueueElement.Command.Close, null, 0, ChannelID);
                m_workQueue.Enqueue(element);

                Utility.Trace("MUXProvider.timer_Tick stopped!");
            }
            else
            {
                Stream tmp = null;
                switch (m_sec)
                {
                case 0:
                    tmp = s1;
                    break;

                case 1:
                    tmp = s2;
                    break;

                case 2:
                    tmp = s3;
                    break;

                case 3:
                    tmp = s4;
                    break;

                case 4:
                    tmp = s5;
                    break;

                case 5:
                    tmp = s6;
                    break;

                default:
                    break;
                }
                WorkQueueElement element = new WorkQueueElement(
                    WorkQueueElement.Command.Sample,
                    tmp,
                    m_sec,
                    ChannelID
                    );
                m_workQueue.Enqueue(element);
            }
            m_sec++;
        }
Пример #4
0
        public void WorkerThreadRun()
        {
            while (true)
            {
                if (curChannelIdx != m_MUXprovider.ChannelID)
                {
                    m_abuffer.Enqueue(null);
                    m_vbuffer.Enqueue(null);

                    Utility.Trace("Thread forced exit, channel ID changed! --" + m_WorkerThread.Name);
                    // the end of the queue, terminate thread
                    return;
                }

                Utility.Trace(" m_MUXSourceQueue WaitForWorkItem " + m_WorkerThread.Name);
                m_MUXSourceQueue.WaitForWorkItem();

                WorkQueueElement elem = m_MUXSourceQueue.Dequeue();
                if (elem == null)
                {
                    continue;
                }

                Utility.Trace(String.Format(" m_MUXSourceQueue get an item, elem.ChannelId = {0},curChannelIdx = {1}  ", elem.ChannelID, curChannelIdx) + m_WorkerThread.Name);

                // then try to parse the stream
                var command = elem.CommandToPerform;

                if ((command == WorkQueueElement.Command.Close) &&
                    (curChannelIdx == elem.ChannelID))
                {
                    m_abuffer.Enqueue(null);
                    m_vbuffer.Enqueue(null);

                    Utility.Trace("Thread normal exit --" + m_WorkerThread.Name);
                    // the end of the queue, terminate thread
                    return;
                }

                if ((command == WorkQueueElement.Command.Sample) &&
                    (curChannelIdx == elem.ChannelID))
                {
                    var v = m_demux2.ParseEntireMUX(elem.Stream);
                    if (elem.TimeIdx == 0)
                    {
                        // the first second
                        AdjustTimeStampOf1stSecond(v[curChannelIdx].msf);
                    }
                    AdjustTimeStampBase(v[curChannelIdx].msf, elem.TimeIdx);

                    m_abuffer.Enqueue(v[curChannelIdx].msf.audioBlock);
                    m_vbuffer.Enqueue(v[curChannelIdx].msf.videoBlock);
                }
            }
        }
Пример #5
0
 /// <summary>
 /// Enqueue a new work item
 /// </summary>
 /// <param name="elem">the item to add</param>
 public void Enqueue(WorkQueueElement elem)
 {
     lock (m_queue)
     {
         m_queue.Enqueue(elem);
         if (1 == m_queue.Count)
         {
             m_queueHasItemsEvent.Set();
         }
     }
 }
Пример #6
0
        /// <summary>
        /// Remove and return an item from the queue
        /// </summary>
        /// <returns>next item from the queue</returns>
        public WorkQueueElement Dequeue()
        {
            WorkQueueElement elem = null;

            lock (m_queue)
            {
                if (0 != m_queue.Count)
                {
                    elem = m_queue.Dequeue();
                    if (0 == m_queue.Count)
                    {
                        m_queueHasItemsEvent.Reset();
                    }
                }
            }

            return(elem);
        }
Пример #7
0
        public void WorkerThreadRun()
        {
            while (true)
            {
                //if ( m_AmediaStreamEnd)
                //{
                //    ReportGetSampleCompleted(new MediaStreamSample(this.audioStreamDescription, null, 0, 0, 0, emptyDict));
                //    Utility.Trace("Worker thread sent audio media end again ");
                //    continue;
                //}
                //if ( m_VmediaStreamEnd)
                //{
                //    ReportGetSampleCompleted(new MediaStreamSample(this.videoStreamDescription, null, 0, 0, 0, emptyDict));
                //    Utility.Trace("Worker thread sent video media end again ");
                //    continue;
                //}
                //if (m_AmediaStreamEnd && m_VmediaStreamEnd)
                //{
                //    ReportGetSampleCompleted(new MediaStreamSample(this.audioStreamDescription, null, 0, 0, 0, emptyDict));
                //    ReportGetSampleCompleted(new MediaStreamSample(this.videoStreamDescription, null, 0, 0, 0, emptyDict));
                //    Utility.Trace("Worker thread exit with both media end ");
                //    m_commands.Clear();
                //    return;
                //}


                Utility.Trace("Worker thread wait for command ");
                m_commands.WaitForWorkItem();
                Utility.Trace("Worker thread got an command ");

                WorkQueueElement elem = m_commands.Dequeue();

                if (elem.CommandToPerform == WorkQueueElement.Command.Close)
                {
                    Utility.Trace("Worker thread exit with close event ");
                    m_commands.Clear();
                    return;
                }

                MediaStreamType mediaStreamType = (MediaStreamType)elem.CommandParameter;

                //if (m_AmediaStreamEnd && m_VmediaStreamEnd)
                //{
                //    Utility.Trace("Worker thread exit with both media end ");
                //    m_aBufferFullEvent.Dispose();
                //    m_vBufferFullEvent.Dispose();
                //    m_commands.Clear();
                //    m_commands.Dispose();
                //    return;
                //}

                //if ((mediaStreamType == MediaStreamType.Audio) && m_AmediaStreamEnd)
                //{
                //        ReportGetSampleCompleted(new MediaStreamSample(this.audioStreamDescription, null, 0, 0, 0, emptyDict));
                //        Utility.Trace("Worker thread sent audio media end again ");
                //        continue;
                //}
                //if ((mediaStreamType == MediaStreamType.Video) && m_VmediaStreamEnd)
                //{
                //    ReportGetSampleCompleted(new MediaStreamSample(this.videoStreamDescription, null, 0, 0, 0, emptyDict));
                //    Utility.Trace("Worker thread sent video media end again ");
                //    continue;
                //}


                if (elem.CommandToPerform == WorkQueueElement.Command.Sample)
                {
                    // to check the buffer depth
                    if (mediaStreamType == MediaStreamType.Audio)
                    {
                        if (m_abuffer.Count() == 0)
                        {
                            if (m_ParserThread.ThreadState != ThreadState.Stopped)
                            {
                                ReportGetSampleProgress(0.5f);
                                Utility.Trace("Worker thread ReportGetSampleProgress sent for Audio, and wait for buffer full");
                                m_aBufferFullEvent.WaitOne();
                                Utility.Trace("Worker thread audio buffer full");
                            }
                            else
                            {
                                Utility.Trace("m_ParserThread has been stopped!, so keep going");
                            }
                            ReportGetSampleCompleted(GetAudioSample2());
                        }
                        else
                        {
                            ReportGetSampleCompleted(GetAudioSample2());
                        }
                    }
                    else if (mediaStreamType == MediaStreamType.Video)
                    {
                        if (m_vbuffer.Count() == 0)
                        {
                            if (m_ParserThread.ThreadState != ThreadState.Stopped)
                            {
                                ReportGetSampleProgress(0.5f);
                                Utility.Trace("Worker thread ReportGetSampleProgress sent for Video ");
                                m_vBufferFullEvent.WaitOne();
                                Utility.Trace("Worker thread video buffer full");
                            }
                            else
                            {
                                Utility.Trace("m_ParserThread has been stopped!, so keep going");
                            }

                            ReportGetSampleCompleted(GetVideoSample2());
                        }
                        else
                        {
                            ReportGetSampleCompleted(GetVideoSample2());
                        }
                    }
                }
            }
        }
Пример #8
0
        private void timer_Tick(object sender)
        {
            Utility.Trace(String.Format("MUXProvider.timer_Tick second {0}", m_sec));

            if (m_sec > 5)
            {
                // stop the timer
                m_timer.Change(System.Threading.Timeout.Infinite, System.Threading.Timeout.Infinite);

                WorkQueueElement element = new WorkQueueElement(WorkQueueElement.Command.Close, null, 0, ChannelID);
                m_workQueue.Enqueue(element);

                Utility.Trace("MUXProvider.timer_Tick stopped!");
            }
            else
            {
                Stream tmp = null;
                switch (m_sec)
                {
                    case 0:
                        tmp = s1;
                        break;
                    case 1:
                        tmp = s2;
                        break;
                    case 2:
                        tmp = s3;
                        break;
                    case 3:
                        tmp = s4;
                        break;
                    case 4:
                        tmp = s5;
                        break;
                    case 5:
                        tmp = s6;
                        break;
                    default:
                        break;
                }
                WorkQueueElement element = new WorkQueueElement(
                                                             WorkQueueElement.Command.Sample,
                                                             tmp,
                                                             m_sec,
                                                             ChannelID
                                                             );
                m_workQueue.Enqueue(element);
            }
            m_sec++;
        }
Пример #9
0
 /// <summary>
 /// Enqueue a new work item
 /// </summary>
 /// <param name="elem">the item to add</param>
 public void Enqueue(WorkQueueElement elem)
 {
     lock (m_queue)
     {
         m_queue.Enqueue(elem);
         if (1 == m_queue.Count)
         {
             m_queueHasItemsEvent.Set();
         }
     }
 }