public bool Open(IntPtr buffer, uint bufferSize) { if (this.openState == OpenStateEnum.Close) { InputLock.WaitOne(); if (!PlayCtrl.PlayM4_GetPort(ref playerPort)) return false; if (!PlayCtrl.PlayM4_SetStreamOpenMode(playerPort, PlayCtrl.STREAME_REALTIME)) return false; if (!PlayCtrl.PlayM4_OpenStream(playerPort, buffer, bufferSize, 600 * 1024)) return false; if (!PlayCtrl.PlayM4_GetPictureSize(playerPort, out this.width, out this.height)) return false; if (!PlayCtrl.PlayM4_SetDecCBStream(playerPort, 1)) return false; this.DecCBCallbackHandle = new PlayCtrl.DecCBFun(this.DecCallBack); if (!PlayCtrl.PlayM4_SetDecCallBack(playerPort, this.DecCBCallbackHandle)) return false; if (!PlayCtrl.PlayM4_Play(playerPort, IntPtr.Zero)) return false; Marshal.FreeHGlobal(buffer); this.openState = OpenStateEnum.RealDecode; InputLock.Set(); return true; } else if (this.openState == OpenStateEnum.RealDecode) { PlayCtrl.PlayM4_InputData(playerPort, buffer, bufferSize); Marshal.FreeHGlobal(buffer); } return false; }
//public void FileRefDone(int nPort, ushort nUser) //{ // ushort nSize = 0; // PlayCtrl.PlayM4_GetRefValue(nPort, IntPtr.Zero, ref nSize); // byte[] Datas = new byte[nSize]; // GCHandle hObject = GCHandle.Alloc(Datas, GCHandleType.Pinned); // IntPtr pObject = hObject.AddrOfPinnedObject(); // PlayCtrl.PlayM4_GetRefValue(nPort, pObject, ref nSize); // PlayCtrl.PlayM4_SetRefValue(nPort, pObject, nSize); // if (hObject.IsAllocated) hObject.Free(); //} public bool Open(string file, IntPtr handle) { FileInfo record = new FileInfo(file); if (!record.Exists) throw new ApplicationException("Record is not exist!|Open"); if (this.openState != OpenStateEnum.Close) throw new ApplicationException("Record has Opened!|Open"); //生成索引 //PlayCtrl.PlayM4_SetFileRefCallBack(0, FileRefDone, 0); if (!PlayCtrl.PlayM4_GetPort(ref this.playerPort)) return false; if (playerPort < 0 || playerPort > 500) throw new ArgumentOutOfRangeException("Port out of range!|Open"); if (this.handle == IntPtr.Zero && handle != IntPtr.Zero) this.handle = handle; if (this.handle != IntPtr.Zero) PlayCtrl.PlayM4_SetFileEndMsg(playerPort, handle, 0x1111); if (PlayCtrl.PlayM4_OpenFile(playerPort, file)) { this.openState = OpenStateEnum.FilePlay; this.DrawCallbackHandle = new PlayCtrl.DrawFun(DrawCallback); //注册绘图回调函数 PlayCtrl.PlayM4_RigisterDrawFun(this.playerPort, this.DrawCallbackHandle, 0); return true; } else return false; }
public bool Open(string file) { FileInfo record = new FileInfo(file); if (!record.Exists) throw new ApplicationException("Record is not exist!|OpenFileDecode"); ushort headLength = 40;//PlayCtrl.PlayM4_GetFileHeadLength(); if (record.Length < headLength) throw new ApplicationException("Head length error!|OpenFileDecode"); byte[] headData = new byte[headLength]; IntPtr headBuffer = Marshal.AllocHGlobal(headData.Length); FileStream recordStream = new FileStream(record.FullName, FileMode.Open, FileAccess.Read); recordStream.Read(headData, 0, Convert.ToInt32(headLength)); Marshal.Copy(headData, 0, headBuffer, headLength); if (!PlayCtrl.PlayM4_GetPort(ref playerPort)) return false; if (!PlayCtrl.PlayM4_SetStreamOpenMode(playerPort, PlayCtrl.STREAME_FILE)) return false; if (!PlayCtrl.PlayM4_OpenStream(playerPort, headBuffer, Convert.ToUInt32(headData.Length), 600 * 1024)) return false; if (!PlayCtrl.PlayM4_SetDecCBStream(playerPort, 1)) return false; this.DecCBCallbackHandle = new PlayCtrl.DecCBFun(this.DecCallBack); if (!PlayCtrl.PlayM4_SetDecCallBack(playerPort, this.DecCBCallbackHandle)) return false; if (!PlayCtrl.PlayM4_Play(playerPort, IntPtr.Zero)) return false; this.openState = OpenStateEnum.FileDecode; Marshal.FreeHGlobal(headBuffer); if (this.decodeCallback != null) ThreadPool.QueueUserWorkItem(new WaitCallback(RecordCall), recordStream); return true; }
public bool Close() { if (this.playerPort >= 0) { switch (this.openState) { case OpenStateEnum.FilePlay: PlayCtrl.PlayM4_CloseFile(playerPort); PlayCtrl.PlayM4_FreePort(this.playerPort); this.handle = IntPtr.Zero; this.playSpeed = 0; this.playerPort = -1; this.playState = PlayStateEnum.Other; this.openState = OpenStateEnum.Close; break; case OpenStateEnum.FileDecode: PlayCtrl.PlayM4_CloseStream(this.playerPort); PlayCtrl.PlayM4_FreePort(this.playerPort); break; case OpenStateEnum.RealDecode: break; case OpenStateEnum.Close: case OpenStateEnum.Other: default: break; } this.openState = OpenStateEnum.Close; this.playerPort = -1; } return true; }