X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=nageru%2Fdecklink_capture.cpp;h=722221ea21f3f68a2e1179c958a093188e94cd18;hb=f34a3e1bbc207541842e0b54d5418d95bafc8e5b;hp=881e1817b1b7262f295584ac24e7f6d80fd1b65e;hpb=392f9d1ccb835c05a3874c4bea163788b2c37024;p=nageru diff --git a/nageru/decklink_capture.cpp b/nageru/decklink_capture.cpp index 881e181..722221e 100644 --- a/nageru/decklink_capture.cpp +++ b/nageru/decklink_capture.cpp @@ -21,7 +21,7 @@ #include "bmusb/bmusb.h" #include "decklink_util.h" #include "flags.h" -#include "memcpy_interleaved.h" +#include "shared/memcpy_interleaved.h" #include "v210_converter.h" #define FRAME_SIZE (8 << 20) // 8 MB. @@ -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; @@ -246,24 +246,27 @@ HRESULT STDMETHODCALLTYPE DeckLinkCapture::VideoInputFrameArrived( const int stride = video_frame->GetRowBytes(); const BMDPixelFormat format = video_frame->GetPixelFormat(); assert(format == pixel_format_to_bmd(current_pixel_format)); - if (global_flags.ten_bit_input) { + if (global_flags.bit_depth > 8) { assert(stride == int(v210Converter::get_v210_stride(width))); } else { 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 *frame_bytes; - video_frame->GetBytes((void **)&frame_bytes); + const uint8_t *src; + video_frame->GetBytes((void **)&src); size_t num_bytes = stride * height; if (current_video_frame.interleaved) { uint8_t *data = current_video_frame.data; uint8_t *data2 = current_video_frame.data2; - memcpy_interleaved(data, data2, frame_bytes, num_bytes); + memcpy_interleaved(data, data2, src, num_bytes); } else { - memcpy(current_video_frame.data, frame_bytes, num_bytes); + memcpy(current_video_frame.data, src, num_bytes); + } + if (current_video_frame.data_copy != nullptr) { + memcpy(current_video_frame.data_copy, src, num_bytes); } current_video_frame.len += num_bytes; @@ -278,14 +281,14 @@ HRESULT STDMETHODCALLTYPE DeckLinkCapture::VideoInputFrameArrived( current_audio_frame = audio_frame_allocator->alloc_frame(); if (current_audio_frame.data != nullptr) { - const uint8_t *frame_bytes; - audio_frame->GetBytes((void **)&frame_bytes); - current_audio_frame.len = sizeof(int32_t) * 2 * num_samples; + const uint8_t *src; + audio_frame->GetBytes((void **)&src); + current_audio_frame.len = sizeof(int32_t) * 8 * num_samples; - memcpy(current_audio_frame.data, frame_bytes, current_audio_frame.len); + 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; } } @@ -323,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; } @@ -345,12 +348,13 @@ void DeckLinkCapture::stop_dequeue_thread() HRESULT result = input->StopStreams(); if (result != S_OK) { fprintf(stderr, "StopStreams failed with error 0x%x\n", result); - exit(1); + abort(); } // 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. + // during shutdown anyway (except when switching to output mode, + // where DeckLinkOutput does the disabling), so StopStreams() will suffice. running = false; } @@ -360,11 +364,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(); } } @@ -373,7 +377,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(); } } } @@ -390,17 +394,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(); @@ -408,7 +412,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(); } } @@ -419,7 +423,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; @@ -429,7 +433,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;