コード例 #1
0
        void RenderThread(object obj)
        {
            IntPtr hWnd = (IntPtr)obj;

            AxisMediaViewer viewer = new AxisMediaViewer();

            viewer.VMR9 = true;

            try
            {
                using (FileStream inFileStream = new FileStream(videoPath, FileMode.Open)) using (BinaryReader inFile = new BinaryReader(inFileStream, Encoding.UTF32))
                    {
                        if (inFile.PeekChar() != -1)
                        {
                            int    mediaTypeSize   = inFile.ReadInt32();
                            byte[] mediaTypeBuffer = inFile.ReadBytes(mediaTypeSize);

                            long startPosition = inFile.BaseStream.Position;

                            while (true)
                            {
                                viewer.Init(1, mediaTypeBuffer, hWnd.ToInt64());

                                viewer.Start();

                                while (inFile.PeekChar() != -1)
                                {
                                    // Read frame data
                                    int    sampleType  = inFile.ReadInt32();
                                    int    sampleFlags = inFile.ReadInt32();
                                    ulong  startTime   = inFile.ReadUInt64();
                                    ulong  stopTime    = inFile.ReadUInt64();
                                    int    bufferSize  = inFile.ReadInt32();
                                    byte[] bufferBytes = inFile.ReadBytes(bufferSize);
                                    // Check that it’s not an audio sample.
                                    if (sampleType != (int)AMV_VIDEO_SAMPLE_TYPE.AMV_VST_MPEG4_AUDIO)
                                    {
                                        // Let the viewer render the frame
                                        viewer.SetVideoPosition(VideoXPos, VideoYPos, VideoXPos + VideoWidth, VideoYPos + VideoHeight);
                                        viewer.RenderVideoSample(sampleFlags, startTime, stopTime, bufferBytes);
                                    }
                                }

                                inFile.BaseStream.Position = startPosition;

                                viewer.Stop();
                            }
                        }
                        else
                        {
                            Console.WriteLine(string.Format("File at {0} is empty or malformed", videoPath));
                            Environment.Exit(0);
                        }
                    }
            }
            catch (COMException e)
            {
                MessageBox.Show(string.Format("Exception {0}", e.Message));
            }
        }
コード例 #2
0
 /// <summary>
 /// 回调_视频信息
 /// </summary>
 /// <param name="cookieID"></param>
 /// <param name="sampleType"></param>
 /// <param name="sampleFlags"></param>
 /// <param name="startTime"></param>
 /// <param name="stopTime"></param>
 /// <param name="SampleArray"></param>
 private void OnVideoSample(int cookieID, int sampleType,
                            int sampleFlags, ulong startTime, ulong stopTime, object SampleArray)
 {
     #region 视频录像
     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);
         }
     }
     #endregion
     long renderStartTime = 0;
     long renderStopTime  = 1;
     if ((long)startTime + parser.LiveTimeOffset > 0)
     {
         renderStartTime = (long)startTime + parser.LiveTimeOffset;
         renderStopTime  = (long)stopTime + parser.LiveTimeOffset;
     }
     viewer.RenderVideoSample(sampleFlags, (ulong)renderStartTime, (ulong)renderStopTime, SampleArray);
     VideoPlayCallback(new VideoPlayCallbackValue {
         evType = Enum_VideoPlayEventType.VideoPlay
     });
     VideoPlayState = Enum_VideoPlayState.InPlayState;
 }
コード例 #3
0
        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));
            }
        }
コード例 #4
0
        void renderThreadDoUpdate(object obj)
        {
            if (!File.Exists(m_videoPath))
            {
                Console.WriteLine("startRenderThread: Could not find file {0}, exiting", m_videoPath);
                throw new Exception("File Not Found");
            }

            using (FileStream inFileStream = new FileStream(m_videoPath, FileMode.Open, FileAccess.Read))
            {
                using (BinaryReader inFile = new BinaryReader(inFileStream, Encoding.UTF32))
                {
                    if (inFile.PeekChar() == -1)
                    {
                        Console.WriteLine("startRenderThread: file {0} is empty, exiting", m_videoPath);
                        throw new Exception("File is Empty");
                    }

                    IntPtr hWnd            = (IntPtr)obj;
                    int    mediaTypeSize   = inFile.ReadInt32();
                    byte[] mediaTypeBuffer = inFile.ReadBytes(mediaTypeSize);
                    long   headerOffset    = inFileStream.Position; // save the width of the header so we don't read it again.

                    while (true)
                    {
                        AxisMediaViewer viewer = new AxisMediaViewer();
                        viewer.VMR9 = true;

                        try
                        {
                            viewer.Init(0, mediaTypeBuffer, hWnd.ToInt64());
                        }
                        catch (Exception e)
                        {
                            Console.WriteLine("Got Exception initializing player: {0} exiting", e);
                            throw new Exception("Failed to Initialize Player");
                        }

                        viewer.SetVideoPosition(m_videoXPos, m_videoYPos, m_videoXPos + m_videoWidth, m_videoYPos + m_videoHeight);
                        viewer.Start();

                        while (inFile.PeekChar() != -1)
                        {
                            // Read frame data
                            int    sampleType  = inFile.ReadInt32();
                            int    sampleFlags = inFile.ReadInt32();
                            ulong  startTime   = inFile.ReadUInt64();
                            ulong  stopTime    = inFile.ReadUInt64();
                            int    bufferSize  = inFile.ReadInt32();
                            byte[] bufferBytes = inFile.ReadBytes(bufferSize);

                            if (sampleType != (int)AMV_VIDEO_SAMPLE_TYPE.AMV_VST_MPEG4_AUDIO && bufferSize > 0)
                            {
                                try
                                {
                                    viewer.RenderVideoSample(sampleFlags, startTime, stopTime, bufferBytes);
                                }
                                catch (Exception e)
                                {
                                    Console.WriteLine("Caught Exception {0} when trying to render frame.", e);
                                }
                            }
                        }

                        inFileStream.Position = headerOffset;
                        viewer.Stop();
                    }
                }
            }
        }