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 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; }