private void Initialize() { var codecInfoStruct = new StreamTalk80.CODECINFO(); var codecInfoExStruct = new StreamTalk80.CODECINFOEX(); StreamTalk80.GetCodecInfo(ref codecInfoStruct); StreamTalk80.GetCodecInfoEx(ref codecInfoExStruct, Marshal.SizeOf(typeof(StreamTalk80.CODECINFOEX))); PMSIZE = codecInfoExStruct.wInputBufferSize; CODESIZE = codecInfoExStruct.wCodedBufferSize; if (PMSIZE == 0) { PMSIZE = 4096; } if (CODESIZE == 0) { CODESIZE = 4096; } if ((_hDecoder = StreamTalk80.OpenDecoder(StreamTalk80.OPENCODERFLAGS.LINEAR_PCM_16_BIT)) == IntPtr.Zero) { throw new StreamTalk80Exception("Could not open decoder"); } if ((_hCoder = StreamTalk80.OpenCoder(StreamTalk80.OPENCODERFLAGS.LINEAR_PCM_16_BIT)) == IntPtr.Zero) { throw new StreamTalk80Exception("Could not open encoder"); } }
public int Encode(byte[] inputBuffer, int inputBufferOffset, int dataLength, byte[] outputBuffer, int outputBufferOffset) { var compDecodeSize = 0; var loopCount = dataLength; var outputCodedSize = CODESIZE; var pinnedInputBufferHandle = GCHandle.Alloc(inputBuffer, GCHandleType.Pinned); var inputPtr = Marshal.UnsafeAddrOfPinnedArrayElement(inputBuffer, inputBufferOffset); var pinnedOutputBufferHandle = GCHandle.Alloc(outputBuffer, GCHandleType.Pinned); var outputPtr = Marshal.UnsafeAddrOfPinnedArrayElement(outputBuffer, outputBufferOffset); while (loopCount > 0) { var decodeSize = (short)loopCount; if (decodeSize > PMSIZE) { decodeSize = PMSIZE; } else if (decodeSize < PMSIZE) { break; } var errorCode = StreamTalk80.Encode( _hCoder, inputPtr, ref decodeSize, outputPtr, ref outputCodedSize ); if (errorCode == StreamTalk80.LH_ERRCODE.LH_EBADARG) { throw new StreamTalk80Exception("Bad argument."); } if (errorCode == StreamTalk80.LH_ERRCODE.LH_BADHANDLE) { throw new StreamTalk80Exception("Bad handle."); } if (errorCode == StreamTalk80.LH_ERRCODE.LH_EFAILURE) { throw new StreamTalk80Exception("Compress failed."); } inputPtr = new IntPtr(inputPtr.ToInt64() + decodeSize); outputPtr = new IntPtr(outputPtr.ToInt64() + outputCodedSize); loopCount -= decodeSize; compDecodeSize += outputCodedSize; } pinnedInputBufferHandle.Free(); pinnedOutputBufferHandle.Free(); return(compDecodeSize); }
private void CloseCodecStreams() { StreamTalk80.CloseCoder(_hCoder); StreamTalk80.CloseDecoder(_hDecoder); }