]> git.sesse.net Git - nageru/blob - mixer.cpp
742e3fd7bec634165bf984948f6fc8700486ec53
[nageru] / mixer.cpp
1 #define WIDTH 1280
2 #define HEIGHT 720
3
4 #undef Success
5
6 #include "mixer.h"
7
8 #include <assert.h>
9 #include <effect.h>
10 #include <effect_chain.h>
11 #include <effect_util.h>
12 #include <epoxy/egl.h>
13 #include <features.h>
14 #include <image_format.h>
15 #include <init.h>
16 #include <overlay_effect.h>
17 #include <padding_effect.h>
18 #include <resample_effect.h>
19 #include <resource_pool.h>
20 #include <saturation_effect.h>
21 #include <stdint.h>
22 #include <stdio.h>
23 #include <stdlib.h>
24 #include <sys/time.h>
25 #include <time.h>
26 #include <util.h>
27 #include <white_balance_effect.h>
28 #include <ycbcr.h>
29 #include <ycbcr_input.h>
30 #include <cmath>
31 #include <condition_variable>
32 #include <cstddef>
33 #include <memory>
34 #include <mutex>
35 #include <string>
36 #include <thread>
37 #include <vector>
38
39 #include "bmusb.h"
40 #include "context.h"
41 #include "h264encode.h"
42 #include "pbo_frame_allocator.h"
43 #include "ref_counted_gl_sync.h"
44
45 class QOpenGLContext;
46
47 using namespace movit;
48 using namespace std;
49 using namespace std::placeholders;
50
51 Mixer *global_mixer = nullptr;
52
53 Mixer::Mixer(const QSurfaceFormat &format)
54         : mixer_surface(create_surface(format)),
55           h264_encoder_surface(create_surface(format))
56 {
57         CHECK(init_movit(MOVIT_SHADER_DIR, MOVIT_DEBUG_OFF));
58         check_error();
59
60         resource_pool.reset(new ResourcePool);
61         output_channel[OUTPUT_LIVE].parent = this;
62
63         ImageFormat inout_format;
64         inout_format.color_space = COLORSPACE_sRGB;
65         inout_format.gamma_curve = GAMMA_sRGB;
66
67         YCbCrFormat input_ycbcr_format;
68         input_ycbcr_format.chroma_subsampling_x = 2;
69         input_ycbcr_format.chroma_subsampling_y = 1;
70         input_ycbcr_format.cb_x_position = 0.0;
71         input_ycbcr_format.cr_x_position = 0.0;
72         input_ycbcr_format.cb_y_position = 0.5;
73         input_ycbcr_format.cr_y_position = 0.5;
74         input_ycbcr_format.luma_coefficients = YCBCR_REC_601;
75         input_ycbcr_format.full_range = false;
76
77         YCbCrFormat output_ycbcr_format;
78         output_ycbcr_format.chroma_subsampling_x = 1;
79         output_ycbcr_format.chroma_subsampling_y = 1;
80         output_ycbcr_format.luma_coefficients = YCBCR_REC_601;
81         output_ycbcr_format.full_range = false;
82
83         chain.reset(new EffectChain(WIDTH, HEIGHT, resource_pool.get()));
84         check_error();
85         input[0] = new YCbCrInput(inout_format, input_ycbcr_format, WIDTH, HEIGHT, YCBCR_INPUT_SPLIT_Y_AND_CBCR);
86         chain->add_input(input[0]);
87         input[1] = new YCbCrInput(inout_format, input_ycbcr_format, WIDTH, HEIGHT, YCBCR_INPUT_SPLIT_Y_AND_CBCR);
88         chain->add_input(input[1]);
89         resample_effect = chain->add_effect(new ResampleEffect(), input[0]);
90         padding_effect = chain->add_effect(new IntegralPaddingEffect());
91         float border_color[] = { 0.0f, 0.0f, 0.0f, 1.0f };
92         CHECK(padding_effect->set_vec4("border_color", border_color));
93
94         resample2_effect = chain->add_effect(new ResampleEffect(), input[1]);
95         Effect *saturation_effect = chain->add_effect(new SaturationEffect());
96         CHECK(saturation_effect->set_float("saturation", 0.3f));
97         Effect *wb_effect = chain->add_effect(new WhiteBalanceEffect());
98         CHECK(wb_effect->set_float("output_color_temperature", 3500.0));
99         padding2_effect = chain->add_effect(new IntegralPaddingEffect());
100
101         chain->add_effect(new OverlayEffect(), padding_effect, padding2_effect);
102
103         chain->add_output(inout_format, OUTPUT_ALPHA_FORMAT_POSTMULTIPLIED);
104         chain->add_ycbcr_output(inout_format, OUTPUT_ALPHA_FORMAT_POSTMULTIPLIED, output_ycbcr_format, YCBCR_OUTPUT_SPLIT_Y_AND_CBCR);
105         chain->set_dither_bits(8);
106         chain->set_output_origin(OUTPUT_ORIGIN_TOP_LEFT);
107         chain->finalize();
108
109         h264_encoder.reset(new H264Encoder(h264_encoder_surface, WIDTH, HEIGHT, "test.mp4"));
110
111         printf("Configuring first card...\n");
112         cards[0].usb = new BMUSBCapture(0x1edb, 0xbd3b);  // 0xbd4f
113         cards[0].usb->set_frame_callback(std::bind(&Mixer::bm_frame, this, 0, _1, _2, _3, _4, _5, _6, _7));
114         cards[0].frame_allocator.reset(new PBOFrameAllocator(1280 * 750 * 2 + 44));
115         cards[0].usb->set_video_frame_allocator(cards[0].frame_allocator.get());
116         cards[0].usb->configure_card();
117         cards[0].surface = create_surface(format);
118 #if NUM_CARDS == 2
119         cards[1].surface = create_surface(format);
120 #endif
121
122         if (NUM_CARDS == 2) {
123                 printf("Configuring second card...\n");
124                 cards[1].usb = new BMUSBCapture(0x1edb, 0xbd4f);
125                 cards[1].usb->set_frame_callback(std::bind(&Mixer::bm_frame, this, 1, _1, _2, _3, _4, _5, _6, _7));
126                 cards[1].frame_allocator.reset(new PBOFrameAllocator(1280 * 750 * 2 + 44));
127                 cards[1].usb->set_video_frame_allocator(cards[1].frame_allocator.get());
128                 cards[1].usb->configure_card();
129         }
130
131         BMUSBCapture::start_bm_thread();
132
133         for (int card_index = 0; card_index < NUM_CARDS; ++card_index) {
134                 cards[card_index].usb->start_bm_capture();
135                 input[card_index]->set_pixel_data(0, nullptr, 0);
136                 input[card_index]->set_pixel_data(1, nullptr, 0);
137         }
138
139         //chain->enable_phase_timing(true);
140
141         // Set up stuff for NV12 conversion.
142
143         // Cb/Cr shader.
144         string cbcr_vert_shader = read_file("vs-cbcr.130.vert");
145         string cbcr_frag_shader =
146                 "#version 130 \n"
147                 "in vec2 tc0; \n"
148                 "uniform sampler2D cbcr_tex; \n"
149                 "void main() { \n"
150                 "    gl_FragColor = texture2D(cbcr_tex, tc0); \n"
151                 "} \n";
152         cbcr_program_num = resource_pool->compile_glsl_program(cbcr_vert_shader, cbcr_frag_shader);
153 }
154
155 Mixer::~Mixer()
156 {
157         resource_pool->release_glsl_program(cbcr_program_num);
158         BMUSBCapture::stop_bm_thread();
159 }
160
161 void Mixer::bm_frame(int card_index, uint16_t timecode,
162                      FrameAllocator::Frame video_frame, size_t video_offset, uint16_t video_format,
163                      FrameAllocator::Frame audio_frame, size_t audio_offset, uint16_t audio_format)
164 {
165         CaptureCard *card = &cards[card_index];
166         if (!card->thread_initialized) {
167                 printf("initializing context for bmusb thread %d\n", card_index);
168                 eglBindAPI(EGL_OPENGL_API);
169                 card->context = create_context();
170                 if (!make_current(card->context, card->surface)) {
171                         printf("failed to create bmusb context\n");
172                         exit(1);
173                 }
174                 card->thread_initialized = true;
175         }       
176
177         if (video_frame.len - video_offset != 1280 * 750 * 2) {
178                 printf("dropping frame with wrong length (%ld)\n", video_frame.len - video_offset);
179                 FILE *fp = fopen("frame.raw", "wb");
180                 fwrite(video_frame.data, video_frame.len, 1, fp);
181                 fclose(fp);
182                 //exit(1);
183                 card->usb->get_video_frame_allocator()->release_frame(video_frame);
184                 card->usb->get_audio_frame_allocator()->release_frame(audio_frame);
185                 return;
186         }
187         {
188                 // Wait until the previous frame was consumed.
189                 std::unique_lock<std::mutex> lock(bmusb_mutex);
190                 card->new_data_ready_changed.wait(lock, [card]{ return !card->new_data_ready; });
191         }
192         GLuint pbo = (GLint)(intptr_t)video_frame.userdata;
193         check_error();
194         glBindBuffer(GL_PIXEL_UNPACK_BUFFER_ARB, pbo);
195         check_error();
196         glFlushMappedBufferRange(GL_PIXEL_UNPACK_BUFFER, 0, video_frame.size);
197         check_error();
198         //glMemoryBarrier(GL_CLIENT_MAPPED_BUFFER_BARRIER_BIT);
199         //check_error();
200         GLsync fence = glFenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, /*flags=*/0);              
201         check_error();
202         assert(fence != nullptr);
203         {
204                 std::unique_lock<std::mutex> lock(bmusb_mutex);
205                 card->new_data_ready = true;
206                 card->new_frame = video_frame;
207                 card->new_data_ready_fence = fence;
208                 card->new_data_ready_changed.notify_all();
209         }
210
211         // Video frame will be released later.
212         card->usb->get_audio_frame_allocator()->release_frame(audio_frame);
213 }
214         
215 void Mixer::place_rectangle(Effect *resample_effect, Effect *padding_effect, float x0, float y0, float x1, float y1)
216 {
217         float srcx0 = 0.0f;
218         float srcx1 = 1.0f;
219         float srcy0 = 0.0f;
220         float srcy1 = 1.0f;
221
222         // Cull.
223         if (x0 > 1280.0 || x1 < 0.0 || y0 > 720.0 || y1 < 0.0) {
224                 CHECK(resample_effect->set_int("width", 1));
225                 CHECK(resample_effect->set_int("height", 1));
226                 CHECK(resample_effect->set_float("zoom_x", 1280.0));
227                 CHECK(resample_effect->set_float("zoom_y", 720.0));
228                 CHECK(padding_effect->set_int("left", 2000));
229                 CHECK(padding_effect->set_int("top", 2000));
230                 return; 
231         }
232
233         // Clip. (TODO: Clip on upper/left sides, too.)
234         if (x1 > 1280.0) {
235                 srcx1 = (1280.0 - x0) / (x1 - x0);
236                 x1 = 1280.0;
237         }
238         if (y1 > 720.0) {
239                 srcy1 = (720.0 - y0) / (y1 - y0);
240                 y1 = 720.0;
241         }
242
243         float x_subpixel_offset = x0 - floor(x0);
244         float y_subpixel_offset = y0 - floor(y0);
245
246         // Resampling must be to an integral number of pixels. Round up,
247         // and then add an extra pixel so we have some leeway for the border.
248         int width = int(ceil(x1 - x0)) + 1;
249         int height = int(ceil(y1 - y0)) + 1;
250         CHECK(resample_effect->set_int("width", width));
251         CHECK(resample_effect->set_int("height", height));
252
253         // Correct the discrepancy with zoom. (This will leave a small
254         // excess edge of pixels and subpixels, which we'll correct for soon.)
255         float zoom_x = (x1 - x0) / (width * (srcx1 - srcx0));
256         float zoom_y = (y1 - y0) / (height * (srcy1 - srcy0));
257         CHECK(resample_effect->set_float("zoom_x", zoom_x));
258         CHECK(resample_effect->set_float("zoom_y", zoom_y));
259         CHECK(resample_effect->set_float("zoom_center_x", 0.0f));
260         CHECK(resample_effect->set_float("zoom_center_y", 0.0f));
261
262         // Padding must also be to a whole-pixel offset.
263         CHECK(padding_effect->set_int("left", floor(x0)));
264         CHECK(padding_effect->set_int("top", floor(y0)));
265
266         // Correct _that_ discrepancy by subpixel offset in the resampling.
267         CHECK(resample_effect->set_float("left", -x_subpixel_offset / zoom_x));
268         CHECK(resample_effect->set_float("top", -y_subpixel_offset / zoom_y));
269
270         // Finally, adjust the border so it is exactly where we want it.
271         CHECK(padding_effect->set_float("border_offset_left", x_subpixel_offset));
272         CHECK(padding_effect->set_float("border_offset_right", x1 - (floor(x0) + width)));
273         CHECK(padding_effect->set_float("border_offset_top", y_subpixel_offset));
274         CHECK(padding_effect->set_float("border_offset_bottom", y1 - (floor(y0) + height)));
275 }
276         
277 void Mixer::thread_func()
278 {
279         eglBindAPI(EGL_OPENGL_API);
280         QOpenGLContext *context = create_context();
281         if (!make_current(context, mixer_surface)) {
282                 printf("oops\n");
283                 exit(1);
284         }
285
286         struct timespec start, now;
287         clock_gettime(CLOCK_MONOTONIC, &start);
288
289         while (!should_quit) {
290                 ++frame;
291
292                 //int width0 = lrintf(848 * (1.0 + 0.2 * sin(frame * 0.02)));
293                 int width0 = 848;
294                 int height0 = lrintf(width0 * 9.0 / 16.0);
295
296                 //float top0 = 96 + 48 * sin(frame * 0.005);
297                 //float left0 = 96 + 48 * cos(frame * 0.006);
298                 float top0 = 48;
299                 float left0 = 16;
300                 float bottom0 = top0 + height0;
301                 float right0 = left0 + width0;
302
303                 int width1 = 384;
304                 int height1 = 216;
305         
306                 float bottom1 = 720 - 48;
307                 float right1 = 1280 - 16;
308                 float top1 = bottom1 - height1;
309                 float left1 = right1 - width1;
310         
311                 if (current_source == SOURCE_INPUT1) {
312                         top0 = 0.0;
313                         bottom0 = HEIGHT;
314                         left0 = 0.0;
315                         right0 = WIDTH;
316
317                         top1 = HEIGHT + 10;
318                         bottom1 = HEIGHT + 20;
319                         left1 = WIDTH + 10;
320                         right1 = WIDTH + 20;
321                 } else if (current_source == SOURCE_INPUT2) {
322                         top1 = 0.0;
323                         bottom1 = HEIGHT;
324                         left1 = 0.0;
325                         right1 = WIDTH;
326
327                         top0 = HEIGHT + 10;
328                         bottom0 = HEIGHT + 20;
329                         left0 = WIDTH + 10;
330                         right0 = WIDTH + 20;
331                 } else {
332                         float t = 0.5 + 0.5 * cos(frame * 0.006);
333                         float scale0 = 1.0 + t * (1280.0 / 848.0 - 1.0);
334                         float tx0 = 0.0 + t * (-16.0 * scale0);
335                         float ty0 = 0.0 + t * (-48.0 * scale0);
336
337                         top0 = top0 * scale0 + ty0;
338                         bottom0 = bottom0 * scale0 + ty0;
339                         left0 = left0 * scale0 + tx0;
340                         right0 = right0 * scale0 + tx0;
341
342                         top1 = top1 * scale0 + ty0;
343                         bottom1 = bottom1 * scale0 + ty0;
344                         left1 = left1 * scale0 + tx0;
345                         right1 = right1 * scale0 + tx0;
346                 }
347
348                 place_rectangle(resample_effect, padding_effect, left0, top0, right0, bottom0);
349                 place_rectangle(resample2_effect, padding2_effect, left1, top1, right1, bottom1);
350
351                 CaptureCard card_copy[NUM_CARDS];
352
353                 {
354                         std::unique_lock<std::mutex> lock(bmusb_mutex);
355
356                         // The first card is the master timer, so wait for it to have a new frame.
357                         // TODO: Make configurable, and with a timeout.
358                         cards[0].new_data_ready_changed.wait(lock, [this]{ return cards[0].new_data_ready; });
359
360                         for (int card_index = 0; card_index < NUM_CARDS; ++card_index) {
361                                 CaptureCard *card = &cards[card_index];
362                                 card_copy[card_index].usb = card->usb;
363                                 card_copy[card_index].new_data_ready = card->new_data_ready;
364                                 card_copy[card_index].new_frame = card->new_frame;
365                                 card_copy[card_index].new_data_ready_fence = card->new_data_ready_fence;
366                                 card->new_data_ready = false;
367                                 card->new_data_ready_changed.notify_all();
368                         }
369                 }
370
371                 vector<FrameAllocator::Frame> input_frames_to_release;
372         
373                 for (int card_index = 0; card_index < NUM_CARDS; ++card_index) {
374                         CaptureCard *card = &card_copy[card_index];
375                         if (!card->new_data_ready)
376                                 continue;
377
378                         // Now we're done with the previous frame, so we can definitely
379                         // release it when this is done rendering. (Actually, we could do
380                         // it one frame earlier, but before we have a new one, there's no
381                         // knowing when the current one is released.)
382                         if (bmusb_current_rendering_frame[card_index].owner != nullptr) {
383                                 input_frames_to_release.push_back(bmusb_current_rendering_frame[card_index]);
384                         }
385                         bmusb_current_rendering_frame[card_index] = card->new_frame;
386                         check_error();
387
388                         // The new texture might still be uploaded,
389                         // tell the GPU to wait until it's there.
390                         if (card->new_data_ready_fence)
391                                 glWaitSync(card->new_data_ready_fence, /*flags=*/0, GL_TIMEOUT_IGNORED);
392                         check_error();
393                         glDeleteSync(card->new_data_ready_fence);
394                         check_error();
395                         GLint input_tex_pbo = (GLint)(intptr_t)card->new_frame.userdata;
396                         input[card_index]->set_pixel_data(0, (unsigned char *)BUFFER_OFFSET((1280 * 750 * 2 + 44) / 2 + 1280 * 25 + 22), input_tex_pbo);
397                         input[card_index]->set_pixel_data(1, (unsigned char *)BUFFER_OFFSET(1280 * 25 + 22), input_tex_pbo);
398
399                         if (NUM_CARDS == 1) {
400                                 // Set to the other one, too.
401                                 input[1]->set_pixel_data(0, (unsigned char *)BUFFER_OFFSET((1280 * 750 * 2 + 44) / 2 + 1280 * 25 + 22), input_tex_pbo);
402                                 input[1]->set_pixel_data(1, (unsigned char *)BUFFER_OFFSET(1280 * 25 + 22), input_tex_pbo);
403                         }
404                 }
405
406                 GLuint y_tex, cbcr_tex;
407                 bool got_frame = h264_encoder->begin_frame(&y_tex, &cbcr_tex);
408                 assert(got_frame);
409
410                 // Render chain.
411                 GLuint cbcr_full_tex = resource_pool->create_2d_texture(GL_RG8, WIDTH, HEIGHT);
412                 GLuint rgba_tex = resource_pool->create_2d_texture(GL_RGBA8, WIDTH, HEIGHT);
413                 GLuint fbo = resource_pool->create_fbo(y_tex, cbcr_full_tex, rgba_tex);
414                 chain->render_to_fbo(fbo, WIDTH, HEIGHT);
415                 resource_pool->release_fbo(fbo);
416
417                 subsample_chroma(cbcr_full_tex, cbcr_tex);
418                 resource_pool->release_2d_texture(cbcr_full_tex);
419
420                 RefCountedGLsync fence(GL_SYNC_GPU_COMMANDS_COMPLETE, /*flags=*/0);
421                 check_error();
422                 h264_encoder->end_frame(fence, input_frames_to_release);
423
424                 output_channel[OUTPUT_LIVE].output_frame(rgba_tex, fence);
425
426                 clock_gettime(CLOCK_MONOTONIC, &now);
427                 double elapsed = now.tv_sec - start.tv_sec +
428                         1e-9 * (now.tv_nsec - start.tv_nsec);
429                 if (frame % 100 == 0) {
430                         printf("%d frames in %.3f seconds = %.1f fps (%.1f ms/frame)\n",
431                                 frame, elapsed, frame / elapsed,
432                                 1e3 * elapsed / frame);
433                 //      chain->print_phase_timing();
434                 }
435
436                 // Reset every 100 frames, so that local variations in frame times
437                 // (especially for the first few frames, when the shaders are
438                 // compiled etc.) don't make it hard to measure for the entire
439                 // remaining duration of the program.
440                 if (frame == 10000) {
441                         frame = 0;
442                         start = now;
443                 }
444                 check_error();
445         }
446 }
447
448 void Mixer::subsample_chroma(GLuint src_tex, GLuint dst_tex)
449 {
450         GLuint vao;
451         glGenVertexArrays(1, &vao);
452         check_error();
453
454         float vertices[] = {
455                 0.0f, 2.0f,
456                 0.0f, 0.0f,
457                 2.0f, 0.0f
458         };
459
460         glBindVertexArray(vao);
461         check_error();
462
463         // Extract Cb/Cr.
464         GLuint fbo = resource_pool->create_fbo(dst_tex);
465         glBindFramebuffer(GL_FRAMEBUFFER, fbo);
466         glViewport(0, 0, WIDTH/2, HEIGHT/2);
467         check_error();
468
469         glUseProgram(cbcr_program_num);
470         check_error();
471
472         glActiveTexture(GL_TEXTURE0);
473         check_error();
474         glBindTexture(GL_TEXTURE_2D, src_tex);
475         check_error();
476         glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
477         check_error();
478         glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
479         check_error();
480         glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
481         check_error();
482
483         float chroma_offset_0[] = { -0.5f / WIDTH, 0.0f };
484         set_uniform_vec2(cbcr_program_num, "foo", "chroma_offset_0", chroma_offset_0);
485
486         GLuint position_vbo = fill_vertex_attribute(cbcr_program_num, "position", 2, GL_FLOAT, sizeof(vertices), vertices);
487         GLuint texcoord_vbo = fill_vertex_attribute(cbcr_program_num, "texcoord", 2, GL_FLOAT, sizeof(vertices), vertices);  // Same as vertices.
488
489         glDrawArrays(GL_TRIANGLES, 0, 3);
490         check_error();
491
492         cleanup_vertex_attribute(cbcr_program_num, "position", position_vbo);
493         cleanup_vertex_attribute(cbcr_program_num, "texcoord", texcoord_vbo);
494
495         glUseProgram(0);
496         check_error();
497
498         resource_pool->release_fbo(fbo);
499         glDeleteVertexArrays(1, &vao);
500 }
501
502 void Mixer::release_display_frame(DisplayFrame *frame)
503 {
504         resource_pool->release_2d_texture(frame->texnum);
505         frame->texnum = 0;
506         frame->ready_fence.reset();
507 }
508
509 void Mixer::start()
510 {
511         mixer_thread = std::thread(&Mixer::thread_func, this);
512 }
513
514 void Mixer::quit()
515 {
516         should_quit = true;
517         mixer_thread.join();
518 }
519
520 void Mixer::cut(Source source)
521 {
522         current_source = source;
523 }
524
525 void Mixer::OutputChannel::output_frame(GLuint tex, RefCountedGLsync fence)
526 {
527         // Store this frame for display. Remove the ready frame if any
528         // (it was seemingly never used).
529         {
530                 std::unique_lock<std::mutex> lock(frame_mutex);
531                 if (has_ready_frame) {
532                         parent->release_display_frame(&ready_frame);
533                 }
534                 ready_frame.texnum = tex;
535                 ready_frame.ready_fence = fence;
536                 has_ready_frame = true;
537         }
538
539         if (has_new_frame_ready_callback) {
540                 new_frame_ready_callback();
541         }
542 }
543
544 bool Mixer::OutputChannel::get_display_frame(DisplayFrame *frame)
545 {
546         std::unique_lock<std::mutex> lock(frame_mutex);
547         if (!has_current_frame && !has_ready_frame) {
548                 return false;
549         }
550
551         if (has_current_frame && has_ready_frame) {
552                 // We have a new ready frame. Toss the current one.
553                 parent->release_display_frame(&current_frame);
554                 has_current_frame = false;
555         }
556         if (has_ready_frame) {
557                 assert(!has_current_frame);
558                 current_frame = ready_frame;
559                 ready_frame.ready_fence.reset();  // Drop the refcount.
560                 has_current_frame = true;
561                 has_ready_frame = false;
562         }
563
564         *frame = current_frame;
565         return true;
566 }
567
568 void Mixer::OutputChannel::set_frame_ready_callback(Mixer::new_frame_ready_callback_t callback)
569 {
570         new_frame_ready_callback = callback;
571         has_new_frame_ready_callback = true;
572 }
573