public void Release() { //lock (this) //{ _isReleased = true; try { var avmode = new AVModel() { context = FunctionEx.IntPtrToStruct <AVModel>(pAVObj).context, }; lock (this) ffimp_free_avobj(FunctionEx.StructToIntPtr(avmode)); avmode = new AVModel() { codec = FunctionEx.IntPtrToStruct <AVModel>(pAVObj).codec, }; lock (this) ffimp_free_avobj(FunctionEx.StructToIntPtr(avmode)); //ffimp_free_avobj(pAVObj); if (_ffscale != null) { _ffscale.Release(); } Marshal.FreeHGlobal(pOutBuf); } catch (Exception e) { Console.WriteLine("ffimp error:{0}", e); } //} }
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 void InitAudio(int freq, int samples, int channels) { audioCallBack = new Sdl.AudioSpecCallbackDelegate(AudioCallBack); Sdl.SDL_AudioSpec s1 = new Sdl.SDL_AudioSpec() { freq = freq, samples = (short)samples, channels = (byte)channels, format = 0x0010, callback = Marshal.GetFunctionPointerForDelegate(audioCallBack), }; Sdl.SDL_AudioSpec s2 = new Sdl.SDL_AudioSpec(); var p1 = FunctionEx.StructToIntPtr(s1); var p2 = FunctionEx.StructToIntPtr(s2); var cs = Sdl.SDL_OpenAudio(p1, p2); }
public FFImp(AVCodecCfg cfg, bool isDec, bool isvideo = true) { this.isDec = isDec; this.cfg = cfg; var pcfg = FunctionEx.StructToIntPtr(cfg); pAVObj = FunctionEx.StructToIntPtr(new AVModel()); lock (_lock) { if (!ffimp_init()) { throw new Exception("ffimp init error"); } } if (isvideo) { int pOutBufSize = cfg.width * cfg.height * 3; if (pOutBufSize == 0) { pOutBufSize = 1920 * 1080 * 4; } pOutBuf = Marshal.AllocHGlobal(pOutBufSize); int init_r = 0; lock (_lock) { if (this.isDec) { init_r = ffimp_video_decode_init(ref pAVObj, pcfg, pOutBuf, pOutBufSize); } else { init_r = ffimp_video_encode_init(ref pAVObj, pcfg, pOutBuf, pOutBufSize); } _ffscale = new FFScale(cfg.width, cfg.height, 0, 12, cfg.width, cfg.height, 0, 12); } } else { int pOutBufSize = cfg.width * cfg.height * 3; if (pOutBufSize == 0) { pOutBufSize = 2048 * 2; } pOutBuf = Marshal.AllocHGlobal(pOutBufSize); int init_r = 0; lock (_lock) { if (this.isDec) { init_r = ffimp_audio_decode_init(ref pAVObj, pcfg, pOutBuf, pOutBufSize); } else { init_r = ffimp_audio_decode_init(ref pAVObj, pcfg, pOutBuf, pOutBufSize); } // _ffscale = new FFScale(cfg.width, cfg.height, 0, 12, cfg.width, cfg.height, 0, 12); } } Marshal.FreeHGlobal(pcfg); }