Audio.cs 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. namespace OpenVIII.AV
  2. {
  3. using FFmpeg.AutoGen;
  4. public class Audio : Ffcc
  5. {
  6. #region Methods
  7. /// <summary>
  8. /// Opens filename and init class.
  9. /// </summary>
  10. public static Audio Load(string filename, int loopstart = -1) => Load<Audio>(filename, AVMediaType.AVMEDIA_TYPE_AUDIO, FfccMode.STATE_MACH, loopstart);
  11. /// <summary>
  12. /// Opens filename and init class.
  13. /// </summary>
  14. /// <remarks>
  15. /// Could be better, but theres alot of hoops to jump through.
  16. /// </remarks>
  17. /// <see cref="https://stackoverflow.com/questions/9604633/reading-a-file-located-in-memory-with-libavformat"/>
  18. /// <seealso cref="http://www.ffmpeg.org/doxygen/trunk/doc_2examples_2avio_reading_8c-example.html"/>
  19. /// <seealso cref="https://stackoverflow.com/questions/24758386/intptr-to-callback-function"/>
  20. public static unsafe Audio Play(BufferData buffer_Data, byte[] headerData, int loopstart = -1)
  21. {
  22. Audio r = new Audio();
  23. fixed (byte* tmp = &headerData[0])
  24. {
  25. lock (r.Decoder)
  26. {
  27. buffer_Data.SetHeader(tmp);
  28. r.LoadFromRAM(&buffer_Data);
  29. r.Init(null, AVMediaType.AVMEDIA_TYPE_AUDIO, FfccMode.PROCESS_ALL, loopstart);
  30. ffmpeg.avformat_free_context(r.Decoder.Format);
  31. //ffmpeg.avio_context_free(&Decoder._format->pb); //CTD
  32. r.Decoder.Format = null;
  33. }
  34. r.Dispose(false);
  35. }
  36. return r;
  37. }
  38. #endregion Methods
  39. }
  40. }