X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=nageru%2Fdecklink_capture.cpp;h=eefb537cd1b3409d9f51593b1432e9360ff534b4;hb=3e4002cd9c16df872b4f4fd67816814a3696403a;hp=a09aefaaec14661bafcc3bedc5555d054fe19038;hpb=3a4f297238b16eb74c1dc9fee60b628d9a6d7547;p=nageru diff --git a/nageru/decklink_capture.cpp b/nageru/decklink_capture.cpp index a09aefa..eefb537 100644 --- a/nageru/decklink_capture.cpp +++ b/nageru/decklink_capture.cpp @@ -63,20 +63,20 @@ DeckLinkCapture::DeckLinkCapture(IDeckLink *card, int card_index) if (card->QueryInterface(IID_IDeckLinkInput, (void**)&input) != S_OK) { fprintf(stderr, "Card %d has no inputs\n", card_index); - exit(1); + abort(); } IDeckLinkAttributes *attr; if (card->QueryInterface(IID_IDeckLinkAttributes, (void**)&attr) != S_OK) { fprintf(stderr, "Card %d has no attributes\n", card_index); - exit(1); + abort(); } // Get the list of available video inputs. int64_t video_input_mask; if (attr->GetInt(BMDDeckLinkVideoInputConnections, &video_input_mask) != S_OK) { fprintf(stderr, "Failed to enumerate video inputs for card %d\n", card_index); - exit(1); + abort(); } const vector> video_input_types = { { bmdVideoConnectionSDI, "SDI" }, @@ -96,7 +96,7 @@ DeckLinkCapture::DeckLinkCapture(IDeckLink *card, int card_index) int64_t audio_input_mask; if (attr->GetInt(BMDDeckLinkAudioInputConnections, &audio_input_mask) != S_OK) { fprintf(stderr, "Failed to enumerate audio inputs for card %d\n", card_index); - exit(1); + abort(); } const vector> audio_input_types = { { bmdAudioConnectionEmbedded, "Embedded" }, @@ -134,7 +134,7 @@ DeckLinkCapture::DeckLinkCapture(IDeckLink *card, int card_index) /* Set up the video and audio sources. */ if (card->QueryInterface(IID_IDeckLinkConfiguration, (void**)&config) != S_OK) { fprintf(stderr, "Failed to get configuration interface for card %d\n", card_index); - exit(1); + abort(); } BMDVideoConnection connection = pick_default_video_connection(card, BMDDeckLinkVideoInputConnections, card_index); @@ -145,7 +145,7 @@ DeckLinkCapture::DeckLinkCapture(IDeckLink *card, int card_index) IDeckLinkDisplayModeIterator *mode_it; if (input->GetDisplayModeIterator(&mode_it) != S_OK) { fprintf(stderr, "Failed to enumerate display modes for card %d\n", card_index); - exit(1); + abort(); } video_modes = summarize_video_modes(mode_it, card_index); @@ -198,7 +198,7 @@ HRESULT STDMETHODCALLTYPE DeckLinkCapture::VideoInputFormatChanged( } if (display_mode->GetFrameRate(&frame_duration, &time_scale) != S_OK) { fprintf(stderr, "Could not get new frame rate\n"); - exit(1); + abort(); } field_dominance = display_mode->GetFieldDominance(); return S_OK; @@ -252,7 +252,7 @@ HRESULT STDMETHODCALLTYPE DeckLinkCapture::VideoInputFrameArrived( assert(stride == width * 2); } - current_video_frame = video_frame_allocator->alloc_frame(); + current_video_frame = video_frame_allocator->create_frame(width, height, stride); if (current_video_frame.data != nullptr) { const uint8_t *src; video_frame->GetBytes((void **)&src); @@ -283,12 +283,12 @@ HRESULT STDMETHODCALLTYPE DeckLinkCapture::VideoInputFrameArrived( if (current_audio_frame.data != nullptr) { const uint8_t *src; audio_frame->GetBytes((void **)&src); - current_audio_frame.len = sizeof(int32_t) * 2 * num_samples; + current_audio_frame.len = sizeof(int32_t) * 8 * num_samples; memcpy(current_audio_frame.data, src, current_audio_frame.len); audio_format.bits_per_sample = 32; - audio_format.num_channels = 2; + audio_format.num_channels = 8; } } @@ -326,16 +326,16 @@ void DeckLinkCapture::start_bm_capture() } if (input->EnableVideoInput(current_video_mode, pixel_format_to_bmd(current_pixel_format), supports_autodetect ? bmdVideoInputEnableFormatDetection : 0) != S_OK) { fprintf(stderr, "Failed to set video mode 0x%04x for card %d\n", current_video_mode, card_index); - exit(1); + abort(); } - if (input->EnableAudioInput(48000, bmdAudioSampleType32bitInteger, 2) != S_OK) { + if (input->EnableAudioInput(48000, bmdAudioSampleType32bitInteger, 8) != S_OK) { fprintf(stderr, "Failed to enable audio input for card %d\n", card_index); - exit(1); + abort(); } if (input->StartStreams() != S_OK) { fprintf(stderr, "StartStreams failed\n"); - exit(1); + abort(); } running = true; } @@ -348,13 +348,16 @@ void DeckLinkCapture::stop_dequeue_thread() HRESULT result = input->StopStreams(); if (result != S_OK) { fprintf(stderr, "StopStreams failed with error 0x%x\n", result); + abort(); + } + if (input->DisableVideoInput() != S_OK) { + fprintf(stderr, "Failed to disable video input for card %d\n", card_index); + exit(1); + } + if (input->DisableAudioInput() != S_OK) { + fprintf(stderr, "Failed to disable audio input for card %d\n", card_index); exit(1); } - - // We could call DisableVideoInput() and DisableAudioInput() here, - // but they seem to be taking a really long time, and we only do this - // during shutdown anyway, so StopStreams() will suffice. - running = false; } @@ -363,11 +366,11 @@ void DeckLinkCapture::set_video_mode(uint32_t video_mode_id) if (running) { if (input->PauseStreams() != S_OK) { fprintf(stderr, "PauseStreams failed\n"); - exit(1); + abort(); } if (input->FlushStreams() != S_OK) { fprintf(stderr, "FlushStreams failed\n"); - exit(1); + abort(); } } @@ -376,7 +379,7 @@ void DeckLinkCapture::set_video_mode(uint32_t video_mode_id) if (running) { if (input->StartStreams() != S_OK) { fprintf(stderr, "StartStreams failed\n"); - exit(1); + abort(); } } } @@ -393,17 +396,17 @@ void DeckLinkCapture::set_video_mode_no_restart(uint32_t video_mode_id) IDeckLinkDisplayMode *display_mode; if (input->DoesSupportVideoMode(video_mode_id, pixel_format_to_bmd(current_pixel_format), /*flags=*/0, &support, &display_mode)) { fprintf(stderr, "Failed to query display mode for card %d\n", card_index); - exit(1); + abort(); } if (support == bmdDisplayModeNotSupported) { fprintf(stderr, "Card %d does not support display mode\n", card_index); - exit(1); + abort(); } if (display_mode->GetFrameRate(&frame_duration, &time_scale) != S_OK) { fprintf(stderr, "Could not get frame rate for card %d\n", card_index); - exit(1); + abort(); } field_dominance = display_mode->GetFieldDominance(); @@ -411,7 +414,7 @@ void DeckLinkCapture::set_video_mode_no_restart(uint32_t video_mode_id) if (running) { if (input->EnableVideoInput(video_mode_id, pixel_format_to_bmd(current_pixel_format), supports_autodetect ? bmdVideoInputEnableFormatDetection : 0) != S_OK) { fprintf(stderr, "Failed to set video mode 0x%04x for card %d\n", video_mode_id, card_index); - exit(1); + abort(); } } @@ -422,7 +425,7 @@ void DeckLinkCapture::set_video_input(uint32_t video_input_id) { if (config->SetInt(bmdDeckLinkConfigVideoInputConnection, video_input_id) != S_OK) { fprintf(stderr, "Failed to set video input connection for card %d\n", card_index); - exit(1); + abort(); } current_video_input = video_input_id; @@ -432,7 +435,7 @@ void DeckLinkCapture::set_audio_input(uint32_t audio_input_id) { if (config->SetInt(bmdDeckLinkConfigAudioInputConnection, audio_input_id) != S_OK) { fprintf(stderr, "Failed to set audio input connection for card %d\n", card_index); - exit(1); + abort(); } current_audio_input = audio_input_id;