]> git.sesse.net Git - nageru/blobdiff - futatabi/video_stream.cpp
Make the MIDI play button blinking when something is ready to play, and solid when...
[nageru] / futatabi / video_stream.cpp
index 59ab8bfc936d989e9ebc7b2250788c69a8a84df4..a820411064234bef2d29aa9c7a95f91a1cd0771d 100644 (file)
@@ -241,6 +241,30 @@ VideoStream::~VideoStream()
        if (last_flow_tex != 0) {
                compute_flow->release_texture(last_flow_tex);
        }
+
+       for (const unique_ptr<InterpolatedFrameResources> &resource : interpolate_resources) {
+               glUnmapNamedBuffer(resource->pbo);
+               check_error();
+               glDeleteBuffers(1, &resource->pbo);
+               check_error();
+               glDeleteFramebuffers(2, resource->input_fbos);
+               check_error();
+               glDeleteFramebuffers(1, &resource->fade_fbo);
+               check_error();
+               glDeleteTextures(1, &resource->input_tex);
+               check_error();
+               glDeleteTextures(1, &resource->gray_tex);
+               check_error();
+               glDeleteTextures(1, &resource->fade_y_output_tex);
+               check_error();
+               glDeleteTextures(1, &resource->fade_cbcr_output_tex);
+               check_error();
+               glDeleteTextures(1, &resource->cb_tex);
+               check_error();
+               glDeleteTextures(1, &resource->cr_tex);
+               check_error();
+       }
+       assert(interpolate_resources.size() == num_interpolate_slots);
 }
 
 void VideoStream::start()
@@ -311,18 +335,14 @@ void VideoStream::schedule_original_frame(steady_clock::time_point local_pts,
 {
        fprintf(stderr, "output_pts=%ld  original      input_pts=%ld\n", output_pts, frame.pts);
 
-       // Preload the file from disk, so that the encoder thread does not get stalled.
-       // TODO: Consider sending it through the queue instead.
-       (void)frame_reader.read_frame(frame);
-
        QueuedFrame qf;
        qf.local_pts = local_pts;
        qf.type = QueuedFrame::ORIGINAL;
        qf.output_pts = output_pts;
-       qf.frame1 = frame;
        qf.display_func = move(display_func);
        qf.queue_spot_holder = move(queue_spot_holder);
        qf.subtitle = subtitle;
+       qf.encoded_jpeg.reset(new string(frame_reader.read_frame(frame)));
 
        lock_guard<mutex> lock(queue_lock);
        frame_queue.push_back(move(qf));
@@ -631,7 +651,7 @@ void VideoStream::encode_thread_func()
 
                if (qf.type == QueuedFrame::ORIGINAL) {
                        // Send the JPEG frame on, unchanged.
-                       string jpeg = frame_reader.read_frame(qf.frame1);
+                       string jpeg = move(*qf.encoded_jpeg);
                        AVPacket pkt;
                        av_init_packet(&pkt);
                        pkt.stream_index = 0;