c# - How to get a byte** from managed byte[] buffer -


i've been using ffmpeg.autogen https://github.com/ruslan-b/ffmpeg.autogen wrapper decode h264 video sometime great success , have add aac audio decoding (previous using g711 , naudio this).

i have aac stream decoding using avcodec_decode_audio4, output buffer or frame in floating point format flt , need in s16. have found unmanaged examples using swr_convert , ffmpeg.autogen have function p/invoked as;

[dllimport(swresample_library, entrypoint="swr_convert", callingconvention = callingconvention.cdecl, charset = charset.ansi)] public static extern int swr_convert(swrcontext* s, byte** @out, int out_count, byte** @in, int in_count); 

my trouble can't find successful way of converting/fixing/casting managed byte[] in byte** provide destination buffer.

has doing before?

my non-working code...

packet.resetbuffer(m_avframe->linesize[0]*2);  fixed (byte* pdata = packet.payload) {     byte** src = &m_avframe->data_0;     //byte** dst = *pdata;     intptr d = new intptr(pdata);      ffmpeginvoke.swr_convert(m_pconvertcontext, (byte**)d.topointer(), packet.length, src, (int)m_avframe->linesize[0]); } 

thanks help.

cheers

dave

the function trying call documented here: http://www.ffmpeg.org/doxygen/2.0/swresample_8c.html#a81af226d8969df314222218c56396f6a

the out_arg parameter declare this:

uint8_t* out_arg[swr_ch_max] 

that length swr_ch_max array of byte arrays. translation renders byte** , forces use unsafe code. think avoid that. declare parameter this:

[marshalas(unmanagedtype.lparray)] intptr[] out_arg 

declare array this:

intptr[] out_arg = new intptr[channelcount]; 

i guessing ch in swr_ch_max short-hand channel.

then need allocate memory output buffer. i'm not sure how want that. allocate 1 byte array per channel , pin arrays hold of pointer pass down native code. preferred approach because upon return you'd have channels in nice managed arrays. way call marshal.allochglobal.

the input buffer need handled in same way.

i not use automated pinvoke translation using. seems he'll bent on forcing use pointers , unsafe code. not massively helpful. i'd translate hand.

i'm sorry not give more specific details it's little hard because question did not contain information types used in code samples. hope general advice useful.


Comments

Popular posts from this blog

windows - Single EXE to Install Python Standalone Executable for Easy Distribution -

c# - Access objects in UserControl from MainWindow in WPF -

javascript - How to name a jQuery function to make a browser's back button work? -