Je vous met ici les bouts de code concernés, peut-être que certains ici seraient en mesure de dire si le CLR 4.0 l'interprète différemment du 2.0 etc
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
| private void FLAC_WriteCallback(IntPtr context, IntPtr frame, IntPtr buffer, IntPtr clientData)
{
// Read the FLAC Frame into a memory samples buffer (m_flacSamples)
LibFLACSharp.FlacFrame flacFrame = (LibFLACSharp.FlacFrame)Marshal.PtrToStructure(frame, typeof(LibFLACSharp.FlacFrame));
if (m_flacSamples == null)
{
// First time - Create Flac sample buffer
m_samplesPerChannel = flacFrame.Header.BlockSize;
m_flacSamples = new int[m_samplesPerChannel * m_flacStreamInfo.Channels];
m_flacSampleIndex = 0;
}
// Iterate on all channels, copy the unmanaged channel bits (samples) to the a managed samples array
for (int inputChannel = 0; inputChannel < m_flacStreamInfo.Channels; inputChannel++)
{
// Get pointer to channel bits, for the current channel
IntPtr pChannelBits = Marshal.ReadIntPtr(buffer, inputChannel * IntPtr.Size);
// Copy the unmanaged bits to managed memory
Marshal.Copy(pChannelBits, m_flacSamples, inputChannel * m_samplesPerChannel, m_samplesPerChannel);
}
lock (m_repositionLock)
{
// Keep the current sample number for reporting purposes (See: Position property of FlacFileReader)
m_lastSampleNumber = flacFrame.Header.FrameOrSampleNumber;
if (m_repositionRequested)
{
m_repositionRequested = false;
FLACCheck(LibFLACSharp.FLAC__stream_decoder_seek_absolute(m_decoderContext, m_flacReposition), "Could not seek absolute: " + m_flacReposition);
}
}
} |
Dans le constructeur de la classe on a ça :
m_writeCallback = new LibFLACSharp.Decoder_WriteCallback(FLAC_WriteCallback);
La déclaration :
private LibFLACSharp.Decoder_WriteCallback m_writeCallback;
Le delegate :
1 2
| [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate void Decoder_WriteCallback(IntPtr context, IntPtr frame, IntPtr buffer, IntPtr userData); |
Voilà pour le callback du coté de la classe C#. Après recherche j'ai pu constater que le FLAC_WriteCallback ne retourne pas ce qu'il devrait, à savoir "FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE", comme montré ici dans le code en C de la librairie FLAC :
if (write_audio_frame_to_client_(decoder, &decoder->private_->frame, (const FLAC__int32 * const *)decoder->private_->output) != FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE) return false;
J'ai vérifié en testant, en .NET 3.5 on a bien FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE, et en 4.0 on a des chiffres aléatoires (valeur d'un pointeur ?). Le problème est donc directement lié à la valeur retournée par le callback, sauf que je ne vois pas où c'est géré en fait
Merci pour votre aide !
Partager