Ejemplo n.º 1
0
        //void UpdateTimeDisplay(DateTime time)
        //{
        //    if (InvokeRequired)
        //    {
        //        // If called from a non UI thread, let the UI thread perform the call
        //        BeginInvoke(new Action<DateTime>(UpdateTimeDisplay), new object[] { time });
        //        return;
        //    }

        //    // Update the time label
        //    this.Text = time.ToString("yyyy-MM-dd HH:mm:ss.fff");
        //}
        // Event handler from the parser for each audio frame buffer
        private void OnAudioSample(int cookieID, int sampleType,
                                   int sampleFlags, ulong startTime, ulong stopTime, object SampleArray)
        {
            // Let viewer render audio sample
            //视频录像
            if (CurrentVideoPlaySet.VideoRecordEnable)
            {
                lock (objVideoRecordLock)
                {
                    byte[] bufferBytes = (byte[])SampleArray;
                    lstVideoRecord.AddRange(BitConverter.GetBytes(sampleType));
                    lstVideoRecord.AddRange(BitConverter.GetBytes(sampleFlags));
                    lstVideoRecord.AddRange(BitConverter.GetBytes(startTime));
                    lstVideoRecord.AddRange(BitConverter.GetBytes(stopTime));
                    lstVideoRecord.AddRange(BitConverter.GetBytes(bufferBytes.Length));
                    lstVideoRecord.AddRange(bufferBytes);
                }
            }
            // Add LiveTimeOffset to original timestamp for optimal latency when rendering
            long renderStartTime = 0;
            long renderStopTime  = 1;

            if ((long)startTime + parser.LiveTimeOffset > 0)
            {
                renderStartTime = (long)startTime + parser.LiveTimeOffset;
                renderStopTime  = (long)stopTime + parser.LiveTimeOffset;
            }
            viewer.RenderAudioSample(sampleFlags, (ulong)renderStartTime, (ulong)renderStopTime, SampleArray);
        }
        private void RenderThread()
        {
            try
            {
                // While there are frames in the in file, read each frame and let the viewer render it
                while (!doExitRenderThread)
                {
                    AmpFileSample sample = null;

                    lock (seekingLock)
                    {
                        sample = fileParser.ReadSample();
                    }

                    if (sample == null)
                    {
                        // end-of-file reached - wait for all samples to render before stopping viewer
                        if (viewer.Flush())
                        {
                            BeginInvoke(new EndOfStreamDelegate(OnEndOfStream));
                            break;
                        }
                    }
                    else
                    {
                        switch (sample.SampleType)
                        {
                        case (int)AMP_VIDEO_SAMPLE_TYPE.AMP_VST_MPEG4_VIDEO_CONFIG:
                        case (int)AMP_VIDEO_SAMPLE_TYPE.AMP_VST_MPEG4_VIDEO_IVOP:
                        case (int)AMP_VIDEO_SAMPLE_TYPE.AMP_VST_MPEG4_VIDEO_PVOP:
                        case (int)AMP_VIDEO_SAMPLE_TYPE.AMP_VST_MPEG4_VIDEO_BVOP:
                        case (int)AMP_VIDEO_SAMPLE_TYPE.AMP_VST_MPEG4_VIDEO_FRAGMENT:
                        case (int)AMP_VIDEO_SAMPLE_TYPE.AMP_VST_MJPEG_VIDEO:
                        case (int)AMP_VIDEO_SAMPLE_TYPE.AMP_VST_H264_VIDEO_CONFIG:
                        case (int)AMP_VIDEO_SAMPLE_TYPE.AMP_VST_H264_VIDEO_IDR:
                        case (int)AMP_VIDEO_SAMPLE_TYPE.AMP_VST_H264_VIDEO_NON_IDR:
                        case (int)AMP_VIDEO_SAMPLE_TYPE.AMP_VST_H264_VIDEO_SEI:
                            if ((viewer.PlayOptions & (int)AMV_PLAY_OPTIONS.AMV_PO_VIDEO) > 0)
                            {
                                if (playbackRate >= 32 && ((int)AMP_SAMPLE.AMP_S_SYNCPOINT & sample.SampleFlags) == 0)
                                {
                                    // skip non-sync point video if playback rate is x32 or higher
                                    continue;
                                }

                                viewer.RenderVideoSample(sample.SampleFlags, sample.StartTime,
                                                         sample.StopTime, sample.Buffer);
                            }
                            break;

                        case (int)AMP_VIDEO_SAMPLE_TYPE.AMP_VST_MPEG4_AUDIO:
                            if ((viewer.PlayOptions & (int)AMV_PLAY_OPTIONS.AMV_PO_AUDIO) > 0)
                            {
                                viewer.RenderAudioSample(sample.SampleFlags, sample.StartTime,
                                                         sample.StopTime, sample.Buffer);
                            }
                            break;

                        case (int)AMP_VIDEO_SAMPLE_TYPE.AMP_VST_METADATA_ONVIF:
                            if ((viewer.PlayOptions & (int)AMV_PLAY_OPTIONS.AMV_PO_META) > 0)
                            {
                                string metadataDoc = System.Text.Encoding.UTF8.GetString(sample.Buffer);
                                viewer.RenderMetadataSample(sample.SampleFlags, sample.StartTime,
                                                            sample.StopTime, metadataDoc);
                            }
                            break;

                        default:
                            throw new Exception("Unknown sample type");
                        }
                    }
                }
            }
            catch (COMException e)
            {
                MessageBox.Show(string.Format("Exception for {0}, {1}", CurrentVideoRecordInfo.RecordPath, e.Message));
            }
        }