swr_free() private method

private swr_free ( IntPtr s ) : void
s IntPtr
return void
Ejemplo n.º 1
0
        private void ConvertAudioSample(ref WaveDataType input, IntPtr sample)
        {
            int    ret;
            IntPtr swr = AV.swr_alloc_set_opts(IntPtr.Zero,
                                               AV.av_get_default_channel_layout(codecCtx.channels),
                                               AV.AVSampleFormat.AV_SAMPLE_FMT_S16,
                                               codecCtx.sample_rate,
                                               AV.av_get_default_channel_layout(codecCtx.channels),
                                               codecCtx.sample_fmt,
                                               codecCtx.sample_rate,
                                               0,
                                               IntPtr.Zero);

            ret = AV.swr_init(swr);

            int needed_buf_size = AV.av_samples_get_buffer_size(IntPtr.Zero,
                                                                codecCtx.channels,
                                                                input.nb_samples,
                                                                AV.AVSampleFormat.AV_SAMPLE_FMT_S16, 0);
            IntPtr pOutput  = Marshal.AllocCoTaskMem(needed_buf_size);
            IntPtr ppOutput = Marshal.AllocCoTaskMem(Marshal.SizeOf(pOutput));

            Marshal.WriteIntPtr(ppOutput, pOutput);

            int len = AV.swr_convert(swr, ppOutput, input.nb_samples, sample, input.nb_samples);

            int output_len = len * 2 * AV.av_get_bytes_per_sample(AV.AVSampleFormat.AV_SAMPLE_FMT_S16);

            input.managedData = new byte[output_len];
            Marshal.Copy(pOutput, input.managedData, 0, output_len);

            Marshal.FreeCoTaskMem(pOutput);
            Marshal.FreeCoTaskMem(ppOutput);

            IntPtr ppSwr = Marshal.AllocCoTaskMem(Marshal.SizeOf(swr));

            Marshal.WriteIntPtr(ppSwr, swr);
            AV.swr_free(ppSwr);
            Marshal.FreeCoTaskMem(ppSwr);

            input.bit_per_sample = AV.av_get_bits_per_sample_fmt(AV.AVSampleFormat.AV_SAMPLE_FMT_S16);
            input.channel        = codecCtx.channels;
            input.fmt            = AV.AVSampleFormat.AV_SAMPLE_FMT_S16;
            input.size           = needed_buf_size;
        }