X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=nageru%2Fdecklink_output.cpp;h=6b21edb0c45d066ebf3d8d68a6f8ed27410f4f8d;hb=0eaa4d8a29782ae20d7b54fd8334371e724f1c57;hp=e37002918cb4891f645827dcef74dc7115429031;hpb=3630741c0d8c1d73fb7d888e1eb772e53f117105;p=nageru diff --git a/nageru/decklink_output.cpp b/nageru/decklink_output.cpp index e370029..6b21edb 100644 --- a/nageru/decklink_output.cpp +++ b/nageru/decklink_output.cpp @@ -130,7 +130,7 @@ void DeckLinkOutput::start_output(uint32_t mode, int64_t base_pts) if (video_modes.empty()) { fprintf(stderr, "ERROR: No matching output modes for %dx%d found\n", width, height); - exit(1); + abort(); } should_quit.unquit(); @@ -141,19 +141,19 @@ void DeckLinkOutput::start_output(uint32_t mode, int64_t base_pts) IDeckLinkConfiguration *config = nullptr; if (output->QueryInterface(IID_IDeckLinkConfiguration, (void**)&config) != S_OK) { fprintf(stderr, "Failed to get configuration interface for output card\n"); - exit(1); + abort(); } if (config->SetFlag(bmdDeckLinkConfigLowLatencyVideoOutput, true) != S_OK) { fprintf(stderr, "Failed to set low latency output\n"); - exit(1); + abort(); } if (config->SetInt(bmdDeckLinkConfigVideoOutputConnection, video_connection) != S_OK) { fprintf(stderr, "Failed to set video output connection for card %u\n", card_index); - exit(1); + abort(); } if (config->SetFlag(bmdDeckLinkConfigUse1080pNotPsF, true) != S_OK) { fprintf(stderr, "Failed to set PsF flag for card\n"); - exit(1); + abort(); } if (config->SetFlag(bmdDeckLinkConfigSMPTELevelAOutput, true) != S_OK) { // This affects at least some no-name SDI->HDMI converters. @@ -167,12 +167,12 @@ void DeckLinkOutput::start_output(uint32_t mode, int64_t base_pts) if (output->DoesSupportVideoMode(mode, pixel_format, bmdVideoOutputFlagDefault, &support, &display_mode) != S_OK) { fprintf(stderr, "Couldn't ask for format support\n"); - exit(1); + abort(); } if (support == bmdDisplayModeNotSupported) { fprintf(stderr, "Requested display mode not supported\n"); - exit(1); + abort(); } current_mode_flags = display_mode->GetFlags(); @@ -181,7 +181,7 @@ void DeckLinkOutput::start_output(uint32_t mode, int64_t base_pts) BMDTimeScale time_scale; if (display_mode->GetFrameRate(&time_value, &time_scale) != S_OK) { fprintf(stderr, "Couldn't get frame rate\n"); - exit(1); + abort(); } metric_decklink_output_width_pixels = width; @@ -196,20 +196,20 @@ void DeckLinkOutput::start_output(uint32_t mode, int64_t base_pts) HRESULT result = output->EnableVideoOutput(mode, bmdVideoOutputFlagDefault); if (result != S_OK) { fprintf(stderr, "Couldn't enable output with error 0x%x\n", result); - exit(1); + abort(); } if (output->SetScheduledFrameCompletionCallback(this) != S_OK) { fprintf(stderr, "Couldn't set callback\n"); - exit(1); + abort(); } assert(OUTPUT_FREQUENCY == 48000); if (output->EnableAudioOutput(bmdAudioSampleRate48kHz, bmdAudioSampleType32bitInteger, 2, bmdAudioOutputStreamTimestamped) != S_OK) { fprintf(stderr, "Couldn't enable audio output\n"); - exit(1); + abort(); } if (output->BeginAudioPreroll() != S_OK) { fprintf(stderr, "Couldn't begin audio preroll\n"); - exit(1); + abort(); } present_thread = thread([this]{ @@ -218,7 +218,7 @@ void DeckLinkOutput::start_output(uint32_t mode, int64_t base_pts) if (!make_current(context, this->surface)) { printf("display=%p surface=%p context=%p curr=%p err=%d\n", eglGetCurrentDisplay(), this->surface, context, eglGetCurrentContext(), eglGetError()); - exit(1); + abort(); } present_thread_func(); delete_context(context); @@ -248,6 +248,11 @@ void DeckLinkOutput::end_output() frame_freelist.pop(); } } + + if (output != nullptr) { + output->Release(); + output = nullptr; + } } void DeckLinkOutput::send_frame(GLuint y_tex, GLuint cbcr_tex, YCbCrLumaCoefficients output_ycbcr_coefficients, const vector &input_frames, int64_t pts, int64_t duration) @@ -366,11 +371,11 @@ void DeckLinkOutput::wait_for_frame(int64_t pts, int *dropped_frames, int64_t *f if (!playback_started) { if (output->EndAudioPreroll() != S_OK) { fprintf(stderr, "Could not end audio preroll\n"); - exit(1); // TODO + abort(); // TODO } if (output->StartScheduledPlayback(base_pts, TIMEBASE, 1.0) != S_OK) { fprintf(stderr, "Could not start playback\n"); - exit(1); // TODO + abort(); // TODO } playback_started = true; } @@ -462,12 +467,12 @@ HRESULT DeckLinkOutput::ScheduledFrameCompleted(/* in */ IDeckLinkVideoFrame *co ++metric_decklink_output_completed_frames_late; break; case bmdOutputFrameDropped: - fprintf(stderr, "Output frame was dropped (pts=%" PRId64 "ld)\n", frame->pts); + fprintf(stderr, "Output frame was dropped (pts=%" PRId64 ")\n", frame->pts); fprintf(stderr, "Consider increasing --output-buffer-frames if this persists.\n"); ++metric_decklink_output_completed_frames_dropped; break; case bmdOutputFrameFlushed: - fprintf(stderr, "Output frame was flushed (pts=%" PRId64 "ld)\n", frame->pts); + fprintf(stderr, "Output frame was flushed (pts=%" PRId64 ")\n", frame->pts); ++metric_decklink_output_completed_frames_flushed; break; default: