public int AudioEnc(byte[] inData, ref byte[] outData) { lock (this) { if (_isReleased) { return(0); } var pInData = FunctionEx.BytesToIntPtr(inData); BFrame bframe = new BFrame(); bframe.Buff = FunctionEx.BytesToIntPtr(inData); bframe.Size = inData.Length; IntPtr pbframe = FunctionEx.StructToIntPtr(bframe); var encFrameBuffLen = 192000; var encFrameBuff = Marshal.AllocHGlobal(encFrameBuffLen); var encSize = ffimp_audio_encode(pAVObj, encFrameBuff, encFrameBuffLen, pbframe); if (encSize == -1) { return(encSize); } outData = FunctionEx.IntPtrToBytes(encFrameBuff, 0, encSize); Marshal.FreeHGlobal(pInData); Marshal.FreeHGlobal(encFrameBuff); return(encSize); } }
public int AudioDec(byte[] inData, ref byte[] outData) { //lock (this) { if (_isReleased) { return(0); } // var size = System.Diagnostics.Process.GetCurrentProcess().PrivateMemorySize64; BFrame bframe = new BFrame(); //bframe.Buff = FunctionEx.BytesToIntPtr(inData); //bframe.Size = inData.Length; // IntPtr pbframe = FunctionEx.StructToIntPtr(bframe); IntPtr pbframe = IntPtr.Zero; var decSize = ffimp_audio_decode(pAVObj, inData, inData.Length, ref pbframe); bframe = FunctionEx.IntPtrToStruct <BFrame>(pbframe, 0, Marshal.SizeOf(bframe)); outData = FunctionEx.IntPtrToBytes(bframe.Buff, 0, bframe.Size); return(bframe.Size); //} }
private void YUVFrame(object sender, AForge.Video.DirectShow.RGBRawFrameEventArgs e) { byte[] buffer = FunctionEx.IntPtrToBytes(e.Buffer, 0, e.Len); buffer = _ffscale.Convert(buffer); if (_callBack != null) { _callBack(buffer); } }
//解码 public byte[] Decode(byte[] data) { if (_isDisoseing || _isDisosed) { return(null); } var pData = FunctionEx.BytesToIntPtr(data); var pOut = Marshal.AllocHGlobal(Samples * 2); var decSize = Speex.SpeexDecode(this.pSpx, data.Length, pData, pOut); var bytes = FunctionEx.IntPtrToBytes(pOut, 0, decSize); Marshal.FreeHGlobal(pOut); Marshal.FreeHGlobal(pData); return(bytes); }
//编码 public byte[] Encode(byte[] data) { if (_isDisoseing || _isDisosed) { return(null); } var pData = FunctionEx.BytesToIntPtr(data); var pOut = Marshal.AllocHGlobal(200); var encSize = Speex.SpeexEncode(this.pSpx, pData, pOut); byte[] buffer = FunctionEx.IntPtrToBytes(pOut, 0, encSize); Marshal.FreeHGlobal(pOut); Marshal.FreeHGlobal(pData); return(buffer); }
public byte[] Decode(byte[] data) { if (!_inited) { uint samplerate = 0; byte channels = 0; lock (_lock) { var r = NeAACDecInit(_handle, data, (uint)data.Length, ref samplerate, ref channels); if (r == 0) { _inited = true; } } } if (_inited) { NeAACDecFrameInfo info = new NeAACDecFrameInfo(); var pcm = NeAACDecDecode(_handle, ref info, data, data.Length); try { int bufferLenth = info.samples * info.channels; if (bufferLenth > 0 && bufferLenth <= 4096) { byte[] pcm_data = FunctionEx.IntPtrToBytes(pcm, 0, (info.samples * info.channels)); byte[] frame_mono = new byte[2048]; if (info.channels == 1) { return(pcm_data); } else if (info.channels == 2) { //从双声道的数据中提取单通道 for (int i = 0, j = 0; i < 4096 && j < 2048; i += 4, j += 2) { frame_mono[j] = pcm_data[i]; frame_mono[j + 1] = pcm_data[i + 1]; } return(frame_mono); } } } catch (Exception ex) { } } return(new byte[0]); }
public int VideoEnc(IntPtr frame, ref byte[] outData) { lock (this) { if (_isReleased) { return(0); } var encFrameBuffLen = cfg.width * cfg.height * 3; var encFrameBuff = Marshal.AllocHGlobal(encFrameBuffLen); var encSize = ffimp_video_encode(pAVObj, encFrameBuff, encFrameBuffLen, frame); if (encSize > 0) { outData = FunctionEx.IntPtrToBytes(encFrameBuff, 0, encSize); } Marshal.FreeHGlobal(encFrameBuff); return(encSize); } }
public byte[] Cancellation(byte[] play, byte[] mic) { if (_isDisoseing || _isDisosed) { return(null); } var pPlay = FunctionEx.BytesToIntPtr(play); var pMic = FunctionEx.BytesToIntPtr(mic); var pOut = Marshal.AllocHGlobal(mic.Length); Speex.SpeexEchoCancellation(pSpx, pPlay, pMic, pOut); var data = FunctionEx.IntPtrToBytes(pOut, 0, mic.Length); Marshal.FreeHGlobal(pPlay); Marshal.FreeHGlobal(pMic); Marshal.FreeHGlobal(pOut); return(data); }
//回调函数 private void SampleGrabber_Callback(double SampleTime, IntPtr pBuf, int len) { if (_isDisoseing || _isDisosed) { return; } if (!_isworking) { return; } var buf = FunctionEx.IntPtrToBytes(pBuf, 0, len); buf = _ffscale.Convert(buf); if (_callBack != null) { _callBack(buf); } }
public int VideoEnc(byte[] inData, ref byte[] outData) { lock (this) { if (_isReleased) { return(0); } var pInData = FunctionEx.BytesToIntPtr(inData); IntPtr frame = IntPtr.Zero; if (cfg.pix_fmt == (int)PixelFormat.PIX_FMT_YUV420P) { frame = ffimp_YUVBuff2YUVAVFrame1(pAVObj, pInData, inData.Length); } else if (cfg.pix_fmt == (int)PixelFormat.PIX_FMT_RGB565) { frame = ffimp_RGBBuff2YUVAVFrame1(pAVObj, pInData, inData.Length); } else { frame = ffimp_FMTBuff2YUVAVFrame1(pAVObj, cfg.pix_fmt, pInData, inData.Length); } var encFrameBuffLen = cfg.width * cfg.height * 3; var encFrameBuff = Marshal.AllocHGlobal(encFrameBuffLen); var encSize = ffimp_video_encode(pAVObj, encFrameBuff, encFrameBuffLen, frame); outData = FunctionEx.IntPtrToBytes(encFrameBuff, 0, encSize); Marshal.FreeHGlobal(pInData); Marshal.FreeHGlobal(encFrameBuff); return(encSize); } }