Releasing Resources of AudioSources

Hello Everybody,
Since I am having trouble playing back video files using h.264 encoding on windows, I started to work on an alternative video component using FFmpeg. So far video/audio playback, seeking to other locations in file, etc. work pretty well. The code is based on Daniel Walz’s filmstro_ffmpeg.
Unfortunately there is one big problem left: I have trouble with deleting / releasing AudioSources. When my app shuts down I keep getting access violation exceptions. Somewhat strangely this only happens on windows.
Here a basic explanation of my „architecture“ for playing back sound:

  • I have build a FFmpegVideoReader class which inherits PositionableAudioSource, so I can access different locations in the stream. It uses a thread to read video and audio from a file into buffers.
  • I have a FFmpegVideoComponent which inherits AudioAppComponent, so it can play audio. It has a std::unique_ptr<FFmpegVideoReader> and a std::unique_ptr<juce::AudioTransportSource> for which I set the FFmpegVideoReader as a source. I the AudioTransportSource to access basic transport functions.

When I fiddle around and debug the code for destruction of my video component the problem is usually in a realeaseResources() call. I guess that some resources get released twice…or something like that.

So my questions are:
Is there something wrong with how I set the readers up?
There are so many locations with a version of releaseRessources now: one in my FFmpegVideoComponent, since it is an AudioAppComponent, another in my FFMpegVideoReader, since it is a PositionalAudioSource and the one in the AudioTransportSource. Then it’s of course also found in the corresponding base classes.
What is the correct way of using realeaseResources()? Should I call it manually somewhere? Should I rely on automatic calls from the base classes?

One more thing: I am planing to publish this as soon as possible as open source on Github. So any resources on how to publish something as Open Source is appreciated. I have never done this before.

Best
Clemens

I think you are on the right track, don’t rely on releaseResources() and prepareToPlay() to come in pairs. You can receive multiple prepareRToPlay calls and many to none releaseResources. Ideally you use RAII containers, so they are deleted with the destruction of the source together.

Thanks for your reply! I finally fixed the problem. The solution was to supply the AudioTransportSource with a nullptr as source in the destructor of the VideoComponent. That was easy. i don#t why it took me so long to find this out.