/// <summary> /// Retrieves the compressed stream from the encoder state that was previously used in one of the encoder functions.<para/> /// Note: Synchronizes on stream. For async use IntPtr! /// </summary> /// <param name="stream">CUDA stream where all the required device operations will be placed.</param> /// <returns>Byte array containing the data.</returns> public byte[] RetrieveBitstream(CudaStream stream) { SizeT size = new SizeT(); res = NvJpegNativeMethods.nvjpegEncodeRetrieveBitstream(_nvJpeg.Handle, _state, IntPtr.Zero, ref size, stream.Stream); Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "nvjpegEncodeRetrieveBitstream", res)); if (res != nvjpegStatus.Success) { throw new NvJpegException(res); } byte[] data = new byte[size]; GCHandle handle = GCHandle.Alloc(data, GCHandleType.Pinned); try { IntPtr ptr = handle.AddrOfPinnedObject(); res = NvJpegNativeMethods.nvjpegEncodeRetrieveBitstream(_nvJpeg.Handle, _state, ptr, ref size, stream.Stream); Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "nvjpegEncodeRetrieveBitstream", res)); stream.Synchronize(); } finally { handle.Free(); } if (res != nvjpegStatus.Success) { throw new NvJpegException(res); } return(data); }
/// <summary> /// Retrieves the compressed stream from the encoder state that was previously used in one of the encoder functions. /// </summary> /// <param name="ptr">Pointer to the buffer in the host memory where the compressed stream will be stored. Can be NULL</param> /// <param name="length">input buffer size.</param> /// <param name="stream">CUDA stream where all the required device operations will be placed.</param> /// <returns>On return the NVJPEG library will give the actual compressed stream size in this value.</returns> public SizeT RetrieveBitstream(IntPtr ptr, SizeT length, CudaStream stream) { res = NvJpegNativeMethods.nvjpegEncodeRetrieveBitstream(_nvJpeg.Handle, _state, ptr, ref length, stream.Stream); Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "nvjpegEncodeRetrieveBitstream", res)); if (res != nvjpegStatus.Success) { throw new NvJpegException(res); } return(length); }