]> git.sesse.net Git - nageru/blobdiff - video_stream.cpp
Fix some memory spikes.
[nageru] / video_stream.cpp
index e8d119f2a6767e905fd5864fafc6dcc58e10fa9a..bbd4616b0885935785961923973a848d841650f0 100644 (file)
@@ -292,6 +292,19 @@ void VideoStream::clear_queue()
                q = move(frame_queue);
        }
 
+       // These are not RAII-ed, unfortunately, so we'll need to clean them ourselves.
+       // Note that release_texture() is thread-safe.
+       for (const QueuedFrame &qf : q) {
+               if (qf.type == QueuedFrame::INTERPOLATED ||
+                   qf.type == QueuedFrame::FADED_INTERPOLATED) {
+                       compute_flow->release_texture(qf.flow_tex);
+               }
+               if (qf.type == QueuedFrame::INTERPOLATED) {
+                       interpolate->release_texture(qf.output_tex);
+                       interpolate->release_texture(qf.cbcr_tex);
+               }
+       }
+
        // Destroy q outside the mutex, as that would be a double-lock.
 }
 
@@ -392,6 +405,7 @@ void VideoStream::schedule_faded_frame(steady_clock::time_point local_pts, int64
        qf.fence = RefCountedGLsync(GL_SYNC_GPU_COMMANDS_COMPLETE, /*flags=*/0);
        check_error();
        qf.resources = move(resources);
+       qf.local_pts = local_pts;
 
        unique_lock<mutex> lock(queue_lock);
        frame_queue.push_back(move(qf));
@@ -438,6 +452,7 @@ void VideoStream::schedule_interpolated_frame(steady_clock::time_point local_pts
        qf.id = id;
        qf.display_func = move(display_func);
        qf.queue_spot_holder = move(queue_spot_holder);
+       qf.local_pts = local_pts;
 
        check_error();