]> git.sesse.net Git - nageru/commitdiff
Make the last pointers in CaptureCard into unique_ptr; the amount of manual bookkeepi...
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Tue, 24 Jan 2017 22:22:06 +0000 (23:22 +0100)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Tue, 24 Jan 2017 22:22:06 +0000 (23:22 +0100)
mixer.cpp
mixer.h

index 878e430106ef2ff8e5542786736fd3d2bac151bb..e00fff89bd37ce3dd1f565f3eafbabb2ad9da4f0 100644 (file)
--- a/mixer.cpp
+++ b/mixer.cpp
@@ -219,7 +219,7 @@ Mixer::~Mixer()
                cards[card_index].capture->stop_dequeue_thread();
                if (cards[card_index].output) {
                        cards[card_index].output->end_output();
-                       delete cards[card_index].output;
+                       cards[card_index].output.reset();
                }
        }
 
@@ -233,11 +233,12 @@ void Mixer::configure_card(unsigned card_index, CaptureInterface *capture, bool
        CaptureCard *card = &cards[card_index];
        if (card->capture != nullptr) {
                card->capture->stop_dequeue_thread();
-               delete card->capture;
        }
-       card->capture = capture;
+       card->capture.reset(capture);
        card->is_fake_capture = is_fake_capture;
-       card->output = output;
+       if (card->output.get() != output) {
+               card->output.reset(output);
+       }
        card->capture->set_frame_callback(bind(&Mixer::bm_frame, this, card_index, _1, _2, _3, _4, _5, _6, _7));
        if (card->frame_allocator == nullptr) {
                card->frame_allocator.reset(new PBOFrameAllocator(8 << 20, global_flags.width, global_flags.height));  // 8 MB.
@@ -270,20 +271,16 @@ void Mixer::set_output_card(int card_index)
                old_card->output->end_output();
 
                old_card->capture->stop_dequeue_thread();
-               delete old_card->capture;
-
-               old_card->capture = old_card->parked_capture;
+               old_card->capture = move(old_card->parked_capture);
                old_card->is_fake_capture = false;
-               old_card->parked_capture = nullptr;
                old_card->capture->start_bm_capture();
        }
 
        CaptureCard *card = &cards[card_index];
        card->capture->stop_dequeue_thread();
-       card->parked_capture = card->capture;
-       card->capture = nullptr;
+       card->parked_capture = move(card->capture);
        FakeCapture *capture = new FakeCapture(global_flags.width, global_flags.height, FAKE_FPS, OUTPUT_FREQUENCY, card_index, global_flags.fake_cards_audio);
-       configure_card(card_index, capture, /*is_fake_capture=*/true, card->output);
+       configure_card(card_index, capture, /*is_fake_capture=*/true, card->output.release());
        card->queue_length_policy.reset(card_index);
        card->capture->start_bm_capture();
        card->output->start_output(bmdModeHD720p5994, pts_int);  // FIXME
diff --git a/mixer.h b/mixer.h
index 58084817c70c9c78abef8ff9801ac71d9bd30778..b7c5ef790761fcab8fae0d9b4659d4ee63e53fc9 100644 (file)
--- a/mixer.h
+++ b/mixer.h
@@ -327,16 +327,16 @@ private:
        std::mutex card_mutex;
        bool has_bmusb_thread = false;
        struct CaptureCard {
-               bmusb::CaptureInterface *capture = nullptr;
+               std::unique_ptr<bmusb::CaptureInterface> capture;
                bool is_fake_capture;
-               DeckLinkOutput *output = nullptr;
+               std::unique_ptr<DeckLinkOutput> output;
 
                // If this card is used for output (ie., output_card_index points to it),
                // it cannot simultaneously be uesd for capture, so <capture> gets replaced
                // by a FakeCapture. However, since reconstructing the real capture object
                // with all its state can be annoying, it is not being deleted, just stopped
                // and moved here.
-               bmusb::CaptureInterface *parked_capture = nullptr;
+               std::unique_ptr<bmusb::CaptureInterface> parked_capture;
 
                std::unique_ptr<PBOFrameAllocator> frame_allocator;