From b9115fa102a6f775090e285486bd7fc1cac7ad9a Mon Sep 17 00:00:00 2001 From: "Steinar H. Gunderson" Date: Sat, 27 Feb 2016 12:52:08 +0100 Subject: [PATCH] Refactor card setup into its own function. --- mixer.cpp | 49 ++++++++++++++++++++++++++++--------------------- mixer.h | 1 + 2 files changed, 29 insertions(+), 21 deletions(-) diff --git a/mixer.cpp b/mixer.cpp index 9c5c853..5f023cf 100644 --- a/mixer.cpp +++ b/mixer.cpp @@ -136,27 +136,7 @@ Mixer::Mixer(const QSurfaceFormat &format, unsigned num_cards) h264_encoder.reset(new H264Encoder(h264_encoder_surface, global_flags.va_display, WIDTH, HEIGHT, &httpd)); for (unsigned card_index = 0; card_index < num_cards; ++card_index) { - printf("Configuring card %d...\n", card_index); - CaptureCard *card = &cards[card_index]; - card->capture = new BMUSBCapture(card_index); - card->capture->set_frame_callback(bind(&Mixer::bm_frame, this, card_index, _1, _2, _3, _4, _5, _6, _7)); - card->frame_allocator.reset(new PBOFrameAllocator(8 << 20, WIDTH, HEIGHT)); // 8 MB. - card->capture->set_video_frame_allocator(card->frame_allocator.get()); - card->surface = create_surface(format); - card->capture->set_dequeue_thread_callbacks( - [card]{ - eglBindAPI(EGL_OPENGL_API); - card->context = create_context(card->surface); - if (!make_current(card->context, card->surface)) { - printf("failed to create bmusb context\n"); - exit(1); - } - }, - [this]{ - resource_pool->clean_context(); - }); - card->resampling_queue.reset(new ResamplingQueue(OUTPUT_FREQUENCY, OUTPUT_FREQUENCY, 2)); - card->capture->configure_card(); + configure_card(card_index, format, new BMUSBCapture(card_index)); } BMUSBCapture::start_bm_thread(); @@ -238,6 +218,33 @@ Mixer::~Mixer() h264_encoder.reset(nullptr); } +void Mixer::configure_card(unsigned card_index, const QSurfaceFormat &format, CaptureInterface *capture) +{ + printf("Configuring card %d...\n", card_index); + + CaptureCard *card = &cards[card_index]; + card->capture = capture; + card->capture->set_frame_callback(bind(&Mixer::bm_frame, this, card_index, _1, _2, _3, _4, _5, _6, _7)); + card->frame_allocator.reset(new PBOFrameAllocator(8 << 20, WIDTH, HEIGHT)); // 8 MB. + card->capture->set_video_frame_allocator(card->frame_allocator.get()); + card->surface = create_surface(format); + card->capture->set_dequeue_thread_callbacks( + [card]{ + eglBindAPI(EGL_OPENGL_API); + card->context = create_context(card->surface); + if (!make_current(card->context, card->surface)) { + printf("failed to create bmusb context\n"); + exit(1); + } + }, + [this]{ + resource_pool->clean_context(); + }); + card->resampling_queue.reset(new ResamplingQueue(OUTPUT_FREQUENCY, OUTPUT_FREQUENCY, 2)); + card->capture->configure_card(); +} + + namespace { int unwrap_timecode(uint16_t current_wrapped, int last) diff --git a/mixer.h b/mixer.h index d59b6a3..8f37f38 100644 --- a/mixer.h +++ b/mixer.h @@ -242,6 +242,7 @@ public: } private: + void configure_card(unsigned card_index, const QSurfaceFormat &format, CaptureInterface *capture); void bm_frame(unsigned card_index, uint16_t timecode, FrameAllocator::Frame video_frame, size_t video_offset, VideoFormat video_format, FrameAllocator::Frame audio_frame, size_t audio_offset, uint16_t audio_format); -- 2.39.2