{
boost::mutex::scoped_lock lm (_pending_images_mutex);
- _pending_images[image->data()[0]] = image;
+ auto key = image->data()[0];
+ auto iter = _pending_images.find(key);
+ if (iter != _pending_images.end()) {
+ iter->second.second++;
+ } else {
+ _pending_images[key] = { image, 1 };
+ }
}
for (int i = 0; i < 3; ++i) {
FFmpegFileEncoder::buffer_free2 (uint8_t* data)
{
boost::mutex::scoped_lock lm (_pending_images_mutex);
- if (_pending_images.find(data) != _pending_images.end()) {
- _pending_images.erase (data);
+ auto iter = _pending_images.find(data);
+ if (iter != _pending_images.end()) {
+ iter->second.second--;
+ if (iter->second.second == 0) {
+ _pending_images.erase(data);
+ }
}
}
std::shared_ptr<AudioBuffers> _pending_audio;
/** Store of shared_ptr<Image> to keep them alive whilst raw pointers into
- their data have been passed to FFmpeg.
+ their data have been passed to FFmpeg. The second part of the pair is
+ a count of how many copies of the same key must be kept.
*/
- std::map<uint8_t*, std::shared_ptr<const Image>> _pending_images;
+ std::map<uint8_t*, std::pair<std::shared_ptr<const Image>, int>> _pending_images;
boost::mutex _pending_images_mutex;
static int _video_stream_index;