private void Init(Format cFormat) { _cGCHandle = GCHandle.Alloc(aBuffer, GCHandleType.Pinned); _pBytes = _cGCHandle.AddrOfPinnedObject(); if (null == cFormat) return; AVFrame cAVFrame; if (null != aBuffer) { int nResult; if (cFormat is Format.Video) { Format.Video cFormatVideo = (Format.Video)cFormat; //lock (helper._oSyncRootGlobal) if (0 > (nResult = Functions.avpicture_fill(_pAVFrame, aBuffer, cFormatVideo.ePixelFormat, cFormatVideo.nWidth, cFormatVideo.nHeight))) throw new Exception("Frame.AVFrameInit.avpicture_fill = " + nResult); cAVFrame = (AVFrame)Marshal.PtrToStructure(_pAVFrame, typeof(AVFrame)); cAVFrame.quality = 1; cAVFrame.pts = 0; Marshal.StructureToPtr(cAVFrame, _pAVFrame, true); } else { Format.Audio cFormatAudio = (Format.Audio)cFormat; cAVFrame = (AVFrame)Marshal.PtrToStructure(_pAVFrame, typeof(AVFrame)); if (1 > (cAVFrame.nb_samples = cFormatAudio.stAVCodecContext.frame_size)) cAVFrame.nb_samples = aBuffer.Length / ((cFormatAudio.nBitsPerSample / 8) * cFormatAudio.nChannelsQty); cAVFrame.channel_layout = cFormatAudio.stAVCodecContext.channel_layout; cAVFrame.format = (int)cFormatAudio.stAVCodecContext.sample_fmt; Marshal.StructureToPtr(cAVFrame, _pAVFrame, true); //lock (helper._oSyncRootGlobal) if (0 > (nResult = Functions.avcodec_fill_audio_frame(_pAVFrame, cFormatAudio.nChannelsQty, cFormatAudio.eSampleFormat, aBuffer, nLengthBuffer, 1))) throw new Exception("Frame.AVFrameInit.avcodec_fill_audio_frame = " + nResult); } } }
public Frame(Format cFormat, byte[] aBytes) : this() { _aBuffer = aBytes; nLength = aBytes.Length; Init(cFormat); }
public Frame(Format cFormat) : this(cFormat, cFormat.nBufferSize) { }
public Frame(Format cFormat, int nLength) : this(cFormat, new byte[nLength]) { }
public Frame(Format.Audio cFormat, Frame cFrame) : this() { if (null != cFrame._aBuffer) throw new NotImplementedException(); AVFrame cAVFrame = (AVFrame)Marshal.PtrToStructure(cFrame._pAVFrame, typeof(AVFrame)); if (0 < cAVFrame.width || 0 < cAVFrame.height || 1 > cAVFrame.nb_samples) throw new NotImplementedException(); int nLineSize = cFormat.nBitsPerSample / 8 * cAVFrame.nb_samples; //int nReminder = nLineSize % 64; //if(0 < nReminder) // nLineSize += 64 - nReminder; _nLength = cFormat.nChannelsQty * nLineSize; _aBuffer = new byte[_nLength]; bool bPlanar = (1 < cAVFrame.data.Count(o => NULL != o)); if (!bPlanar) nLineSize = nLength; for (int nIndx = 0; cAVFrame.data.Length > nIndx; nIndx++) { if (NULL == cAVFrame.data[nIndx]) break; Marshal.Copy(cAVFrame.data[nIndx], _aBuffer, nIndx * nLineSize, nLineSize); } Init(cFormat); }