1 #include <movit/effect_util.h>
2 #include <movit/util.h>
3 #include <movit/resource_pool.h> // Must be above the Xlib includes.
11 #include "chroma_subsampler.h"
12 #include "decklink_output.h"
13 #include "decklink_util.h"
15 #include "shared/metrics.h"
16 #include "print_latency.h"
17 #include "shared/timebase.h"
18 #include "v210_converter.h"
20 using namespace movit;
22 using namespace std::chrono;
26 // This class can be deleted during regular use, so make all the metrics static.
27 once_flag decklink_metrics_inited;
28 LatencyHistogram latency_histogram;
29 atomic<int64_t> metric_decklink_output_width_pixels{-1};
30 atomic<int64_t> metric_decklink_output_height_pixels{-1};
31 atomic<int64_t> metric_decklink_output_frame_rate_den{-1};
32 atomic<int64_t> metric_decklink_output_frame_rate_nom{-1};
33 atomic<int64_t> metric_decklink_output_inflight_frames{0};
34 atomic<int64_t> metric_decklink_output_color_mismatch_frames{0};
36 atomic<int64_t> metric_decklink_output_scheduled_frames_dropped{0};
37 atomic<int64_t> metric_decklink_output_scheduled_frames_late{0};
38 atomic<int64_t> metric_decklink_output_scheduled_frames_normal{0};
39 atomic<int64_t> metric_decklink_output_scheduled_frames_preroll{0};
41 atomic<int64_t> metric_decklink_output_completed_frames_completed{0};
42 atomic<int64_t> metric_decklink_output_completed_frames_dropped{0};
43 atomic<int64_t> metric_decklink_output_completed_frames_flushed{0};
44 atomic<int64_t> metric_decklink_output_completed_frames_late{0};
45 atomic<int64_t> metric_decklink_output_completed_frames_unknown{0};
47 atomic<int64_t> metric_decklink_output_scheduled_samples{0};
49 Summary metric_decklink_output_margin_seconds;
53 DeckLinkOutput::DeckLinkOutput(ResourcePool *resource_pool, QSurface *surface, unsigned width, unsigned height, unsigned card_index)
54 : resource_pool(resource_pool), surface(surface), width(width), height(height), card_index(card_index)
56 chroma_subsampler.reset(new ChromaSubsampler(resource_pool));
58 call_once(decklink_metrics_inited, [](){
59 latency_histogram.init("decklink_output");
60 global_metrics.add("decklink_output_width_pixels", &metric_decklink_output_width_pixels, Metrics::TYPE_GAUGE);
61 global_metrics.add("decklink_output_height_pixels", &metric_decklink_output_height_pixels, Metrics::TYPE_GAUGE);
62 global_metrics.add("decklink_output_frame_rate_den", &metric_decklink_output_frame_rate_den, Metrics::TYPE_GAUGE);
63 global_metrics.add("decklink_output_frame_rate_nom", &metric_decklink_output_frame_rate_nom, Metrics::TYPE_GAUGE);
64 global_metrics.add("decklink_output_inflight_frames", &metric_decklink_output_inflight_frames, Metrics::TYPE_GAUGE);
65 global_metrics.add("decklink_output_color_mismatch_frames", &metric_decklink_output_color_mismatch_frames);
67 global_metrics.add("decklink_output_scheduled_frames", {{ "status", "dropped" }}, &metric_decklink_output_scheduled_frames_dropped);
68 global_metrics.add("decklink_output_scheduled_frames", {{ "status", "late" }}, &metric_decklink_output_scheduled_frames_late);
69 global_metrics.add("decklink_output_scheduled_frames", {{ "status", "normal" }}, &metric_decklink_output_scheduled_frames_normal);
70 global_metrics.add("decklink_output_scheduled_frames", {{ "status", "preroll" }}, &metric_decklink_output_scheduled_frames_preroll);
72 global_metrics.add("decklink_output_completed_frames", {{ "status", "completed" }}, &metric_decklink_output_completed_frames_completed);
73 global_metrics.add("decklink_output_completed_frames", {{ "status", "dropped" }}, &metric_decklink_output_completed_frames_dropped);
74 global_metrics.add("decklink_output_completed_frames", {{ "status", "flushed" }}, &metric_decklink_output_completed_frames_flushed);
75 global_metrics.add("decklink_output_completed_frames", {{ "status", "late" }}, &metric_decklink_output_completed_frames_late);
76 global_metrics.add("decklink_output_completed_frames", {{ "status", "unknown" }}, &metric_decklink_output_completed_frames_unknown);
78 global_metrics.add("decklink_output_scheduled_samples", &metric_decklink_output_scheduled_samples);
79 vector<double> quantiles{0.01, 0.1, 0.25, 0.5, 0.75, 0.9, 0.99};
80 metric_decklink_output_margin_seconds.init(quantiles, 60.0);
81 global_metrics.add("decklink_output_margin_seconds", &metric_decklink_output_margin_seconds);
85 bool DeckLinkOutput::set_device(IDeckLink *decklink)
87 if (decklink->QueryInterface(IID_IDeckLinkOutput, (void**)&output) != S_OK) {
88 fprintf(stderr, "Warning: Card %u has no outputs\n", card_index);
92 IDeckLinkDisplayModeIterator *mode_it;
93 if (output->GetDisplayModeIterator(&mode_it) != S_OK) {
94 fprintf(stderr, "Warning: Failed to enumerate output display modes for card %u\n", card_index);
100 for (const auto &it : summarize_video_modes(mode_it, card_index)) {
101 if (it.second.width != width || it.second.height != height) {
105 // We could support interlaced modes, but let's stay out of it for now,
106 // since we don't have interlaced stream output.
107 if (it.second.interlaced) {
111 video_modes.insert(it);
116 // HDMI or SDI generally mean “both HDMI and SDI at the same time” on DeckLink cards
117 // that support both; pick_default_video_connection() will generally pick one of those
118 // if they exist. (--prefer-hdmi-input would also affect the selection despite the name
119 // of the option, but since either generally means both, it's inconsequential.)
120 // We're not very likely to need analog outputs, so we don't need a way to change
122 video_connection = pick_default_video_connection(decklink, BMDDeckLinkVideoOutputConnections, card_index);
126 void DeckLinkOutput::start_output(uint32_t mode, int64_t base_pts)
129 assert(!playback_initiated);
131 if (video_modes.empty()) {
132 fprintf(stderr, "ERROR: No matching output modes for %dx%d found\n", width, height);
136 should_quit.unquit();
137 playback_initiated = true;
138 playback_started = false;
139 this->base_pts = base_pts;
141 IDeckLinkConfiguration *config = nullptr;
142 if (output->QueryInterface(IID_IDeckLinkConfiguration, (void**)&config) != S_OK) {
143 fprintf(stderr, "Failed to get configuration interface for output card\n");
146 if (config->SetFlag(bmdDeckLinkConfigLowLatencyVideoOutput, true) != S_OK) {
147 fprintf(stderr, "Failed to set low latency output\n");
150 if (config->SetInt(bmdDeckLinkConfigVideoOutputConnection, video_connection) != S_OK) {
151 fprintf(stderr, "Failed to set video output connection for card %u\n", card_index);
154 if (config->SetFlag(bmdDeckLinkConfigUse1080pNotPsF, true) != S_OK) {
155 fprintf(stderr, "Failed to set PsF flag for card\n");
158 if (config->SetFlag(bmdDeckLinkConfigSMPTELevelAOutput, true) != S_OK) {
159 // This affects at least some no-name SDI->HDMI converters.
160 // Warn, but don't die.
161 fprintf(stderr, "WARNING: Failed to enable SMTPE Level A; resolutions like 1080p60 might have issues.\n");
164 BMDDisplayModeSupport support;
165 IDeckLinkDisplayMode *display_mode;
166 BMDPixelFormat pixel_format = global_flags.ten_bit_output ? bmdFormat10BitYUV : bmdFormat8BitYUV;
167 if (output->DoesSupportVideoMode(mode, pixel_format, bmdVideoOutputFlagDefault,
168 &support, &display_mode) != S_OK) {
169 fprintf(stderr, "Couldn't ask for format support\n");
173 if (support == bmdDisplayModeNotSupported) {
174 fprintf(stderr, "Requested display mode not supported\n");
178 current_mode_flags = display_mode->GetFlags();
180 BMDTimeValue time_value;
181 BMDTimeScale time_scale;
182 if (display_mode->GetFrameRate(&time_value, &time_scale) != S_OK) {
183 fprintf(stderr, "Couldn't get frame rate\n");
187 metric_decklink_output_width_pixels = width;
188 metric_decklink_output_height_pixels = height;
189 metric_decklink_output_frame_rate_nom = time_value;
190 metric_decklink_output_frame_rate_den = time_scale;
192 frame_duration = time_value * TIMEBASE / time_scale;
194 display_mode->Release();
196 HRESULT result = output->EnableVideoOutput(mode, bmdVideoOutputFlagDefault);
197 if (result != S_OK) {
198 fprintf(stderr, "Couldn't enable output with error 0x%x\n", result);
201 if (output->SetScheduledFrameCompletionCallback(this) != S_OK) {
202 fprintf(stderr, "Couldn't set callback\n");
205 assert(OUTPUT_FREQUENCY == 48000);
206 if (output->EnableAudioOutput(bmdAudioSampleRate48kHz, bmdAudioSampleType32bitInteger, 2, bmdAudioOutputStreamTimestamped) != S_OK) {
207 fprintf(stderr, "Couldn't enable audio output\n");
210 if (output->BeginAudioPreroll() != S_OK) {
211 fprintf(stderr, "Couldn't begin audio preroll\n");
215 present_thread = thread([this]{
216 QOpenGLContext *context = create_context(this->surface);
217 eglBindAPI(EGL_OPENGL_API);
218 if (!make_current(context, this->surface)) {
219 printf("display=%p surface=%p context=%p curr=%p err=%d\n", eglGetCurrentDisplay(), this->surface, context, eglGetCurrentContext(),
223 present_thread_func();
224 delete_context(context);
228 void DeckLinkOutput::end_output()
230 if (!playback_initiated) {
235 frame_queues_changed.notify_all();
236 present_thread.join();
237 playback_initiated = false;
239 output->StopScheduledPlayback(0, nullptr, 0);
240 output->DisableVideoOutput();
241 output->DisableAudioOutput();
243 // Wait until all frames are accounted for, and free them.
245 unique_lock<mutex> lock(frame_queue_mutex);
246 while (!(frame_freelist.empty() && num_frames_in_flight == 0)) {
247 frame_queues_changed.wait(lock, [this]{ return !frame_freelist.empty(); });
248 frame_freelist.pop();
252 if (output != nullptr) {
258 void DeckLinkOutput::send_frame(GLuint y_tex, GLuint cbcr_tex, YCbCrLumaCoefficients output_ycbcr_coefficients, const vector<RefCountedFrame> &input_frames, int64_t pts, int64_t duration)
260 assert(!should_quit.should_quit());
262 if ((current_mode_flags & bmdDisplayModeColorspaceRec601) && output_ycbcr_coefficients == YCBCR_REC_709) {
263 if (!last_frame_had_mode_mismatch) {
264 fprintf(stderr, "WARNING: Chosen output mode expects Rec. 601 Y'CbCr coefficients.\n");
265 fprintf(stderr, " Consider --output-ycbcr-coefficients=rec601 (or =auto).\n");
267 last_frame_had_mode_mismatch = true;
268 ++metric_decklink_output_color_mismatch_frames;
269 } else if ((current_mode_flags & bmdDisplayModeColorspaceRec709) && output_ycbcr_coefficients == YCBCR_REC_601) {
270 if (!last_frame_had_mode_mismatch) {
271 fprintf(stderr, "WARNING: Chosen output mode expects Rec. 709 Y'CbCr coefficients.\n");
272 fprintf(stderr, " Consider --output-ycbcr-coefficients=rec709 (or =auto).\n");
274 last_frame_had_mode_mismatch = true;
275 ++metric_decklink_output_color_mismatch_frames;
277 last_frame_had_mode_mismatch = false;
280 unique_ptr<Frame> frame = get_frame();
281 if (global_flags.ten_bit_output) {
282 chroma_subsampler->create_v210(y_tex, cbcr_tex, width, height, frame->uyvy_tex);
284 chroma_subsampler->create_uyvy(y_tex, cbcr_tex, width, height, frame->uyvy_tex);
287 // Download the UYVY texture to the PBO.
288 glPixelStorei(GL_PACK_ROW_LENGTH, 0);
291 glBindBuffer(GL_PIXEL_PACK_BUFFER, frame->pbo);
294 if (global_flags.ten_bit_output) {
295 glBindTexture(GL_TEXTURE_2D, frame->uyvy_tex);
297 glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_UNSIGNED_INT_2_10_10_10_REV, BUFFER_OFFSET(0));
300 glBindTexture(GL_TEXTURE_2D, frame->uyvy_tex);
302 glGetTexImage(GL_TEXTURE_2D, 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, BUFFER_OFFSET(0));
306 glBindTexture(GL_TEXTURE_2D, 0);
308 glBindBuffer(GL_PIXEL_PACK_BUFFER, 0);
311 glMemoryBarrier(GL_TEXTURE_UPDATE_BARRIER_BIT | GL_CLIENT_MAPPED_BUFFER_BARRIER_BIT);
314 frame->fence = RefCountedGLsync(GL_SYNC_GPU_COMMANDS_COMPLETE, /*flags=*/0);
316 glFlush(); // Make the DeckLink thread see the fence as soon as possible.
319 frame->input_frames = input_frames;
320 frame->received_ts = find_received_timestamp(input_frames);
322 frame->duration = duration;
325 lock_guard<mutex> lock(frame_queue_mutex);
326 pending_video_frames.push(move(frame));
328 frame_queues_changed.notify_all();
331 void DeckLinkOutput::send_audio(int64_t pts, const std::vector<float> &samples)
333 unique_ptr<int32_t[]> int_samples(new int32_t[samples.size()]);
334 for (size_t i = 0; i < samples.size(); ++i) {
335 int_samples[i] = lrintf(samples[i] * 2147483648.0f);
338 uint32_t frames_written;
339 HRESULT result = output->ScheduleAudioSamples(int_samples.get(), samples.size() / 2,
340 pts, TIMEBASE, &frames_written);
341 if (result != S_OK) {
342 fprintf(stderr, "ScheduleAudioSamples(pts=%" PRId64 ") failed (result=0x%08x)\n", pts, result);
344 if (frames_written != samples.size() / 2) {
345 fprintf(stderr, "ScheduleAudioSamples() returned short write (%u/%zu)\n", frames_written, samples.size() / 2);
348 metric_decklink_output_scheduled_samples += samples.size() / 2;
351 void DeckLinkOutput::wait_for_frame(int64_t pts, int *dropped_frames, int64_t *frame_duration, bool *is_preroll, steady_clock::time_point *frame_timestamp)
353 assert(!should_quit.should_quit());
356 *frame_duration = this->frame_duration;
358 const BMDTimeValue buffer = lrint(*frame_duration * global_flags.output_buffer_frames);
359 const BMDTimeValue max_overshoot = lrint(*frame_duration * global_flags.output_slop_frames);
360 BMDTimeValue target_time = pts - buffer;
362 // While prerolling, we send out frames as quickly as we can.
363 if (target_time < base_pts) {
365 ++metric_decklink_output_scheduled_frames_preroll;
369 *is_preroll = !playback_started;
371 if (!playback_started) {
372 if (output->EndAudioPreroll() != S_OK) {
373 fprintf(stderr, "Could not end audio preroll\n");
376 if (output->StartScheduledPlayback(base_pts, TIMEBASE, 1.0) != S_OK) {
377 fprintf(stderr, "Could not start playback\n");
380 playback_started = true;
383 BMDTimeValue stream_frame_time;
384 double playback_speed;
385 output->GetScheduledStreamTime(TIMEBASE, &stream_frame_time, &playback_speed);
387 *frame_timestamp = steady_clock::now() +
388 nanoseconds((target_time - stream_frame_time) * 1000000000 / TIMEBASE);
390 metric_decklink_output_margin_seconds.count_event(
391 (target_time - stream_frame_time) / double(TIMEBASE));
393 // If we're ahead of time, wait for the frame to (approximately) start.
394 if (stream_frame_time < target_time) {
395 should_quit.sleep_until(*frame_timestamp);
396 ++metric_decklink_output_scheduled_frames_normal;
400 // If we overshot the previous frame by just a little,
401 // fire off one immediately.
402 if (stream_frame_time < target_time + max_overshoot) {
403 fprintf(stderr, "Warning: Frame was %ld ms late (but not skipping it due to --output-slop-frames).\n",
404 lrint((stream_frame_time - target_time) * 1000.0 / TIMEBASE));
405 ++metric_decklink_output_scheduled_frames_late;
409 // Oops, we missed by more than one frame. Return immediately,
410 // but drop so that we catch up.
411 *dropped_frames = (stream_frame_time - target_time + *frame_duration - 1) / *frame_duration;
412 const int64_t ns_per_frame = this->frame_duration * 1000000000 / TIMEBASE;
413 *frame_timestamp += nanoseconds(*dropped_frames * ns_per_frame);
414 fprintf(stderr, "Dropped %d output frames; skipping.\n", *dropped_frames);
415 metric_decklink_output_scheduled_frames_dropped += *dropped_frames;
416 ++metric_decklink_output_scheduled_frames_normal;
419 uint32_t DeckLinkOutput::pick_video_mode(uint32_t mode) const
421 if (video_modes.count(mode)) {
425 // Prioritize 59.94 > 60 > 29.97. If none of those are found, then pick the highest one.
426 for (const pair<int, int> &desired : vector<pair<int, int>>{ { 60000, 1001 }, { 60, 0 }, { 30000, 1001 } }) {
427 for (const auto &it : video_modes) {
428 if (it.second.frame_rate_num * desired.second == desired.first * it.second.frame_rate_den) {
434 uint32_t best_mode = 0;
435 double best_fps = 0.0;
436 for (const auto &it : video_modes) {
437 double fps = double(it.second.frame_rate_num) / it.second.frame_rate_den;
438 if (fps > best_fps) {
439 best_mode = it.first;
446 YCbCrLumaCoefficients DeckLinkOutput::preferred_ycbcr_coefficients() const
448 if (current_mode_flags & bmdDisplayModeColorspaceRec601) {
449 return YCBCR_REC_601;
451 // Don't bother checking bmdDisplayModeColorspaceRec709;
452 // if none is set, 709 is a good default anyway.
453 return YCBCR_REC_709;
457 HRESULT DeckLinkOutput::ScheduledFrameCompleted(/* in */ IDeckLinkVideoFrame *completedFrame, /* in */ BMDOutputFrameCompletionResult result)
459 Frame *frame = static_cast<Frame *>(completedFrame);
461 case bmdOutputFrameCompleted:
462 ++metric_decklink_output_completed_frames_completed;
464 case bmdOutputFrameDisplayedLate:
465 fprintf(stderr, "Output frame displayed late (pts=%" PRId64 ")\n", frame->pts);
466 fprintf(stderr, "Consider increasing --output-buffer-frames if this persists.\n");
467 ++metric_decklink_output_completed_frames_late;
469 case bmdOutputFrameDropped:
470 fprintf(stderr, "Output frame was dropped (pts=%" PRId64 ")\n", frame->pts);
471 fprintf(stderr, "Consider increasing --output-buffer-frames if this persists.\n");
472 ++metric_decklink_output_completed_frames_dropped;
474 case bmdOutputFrameFlushed:
475 fprintf(stderr, "Output frame was flushed (pts=%" PRId64 ")\n", frame->pts);
476 ++metric_decklink_output_completed_frames_flushed;
479 fprintf(stderr, "Output frame completed with unknown status %d\n", result);
480 ++metric_decklink_output_completed_frames_unknown;
484 static int frameno = 0;
485 print_latency("DeckLink output latency (frame received → output on HDMI):", frame->received_ts, false, &frameno, &latency_histogram);
488 lock_guard<mutex> lock(frame_queue_mutex);
489 frame_freelist.push(unique_ptr<Frame>(frame));
490 --num_frames_in_flight;
491 --metric_decklink_output_inflight_frames;
497 HRESULT DeckLinkOutput::ScheduledPlaybackHasStopped()
499 printf("playback stopped!\n");
503 unique_ptr<DeckLinkOutput::Frame> DeckLinkOutput::get_frame()
505 lock_guard<mutex> lock(frame_queue_mutex);
507 if (!frame_freelist.empty()) {
508 unique_ptr<Frame> frame = move(frame_freelist.front());
509 frame_freelist.pop();
513 unique_ptr<Frame> frame(new Frame);
516 if (global_flags.ten_bit_output) {
517 stride = v210Converter::get_v210_stride(width);
518 GLint v210_width = stride / sizeof(uint32_t);
519 frame->uyvy_tex = resource_pool->create_2d_texture(GL_RGB10_A2, v210_width, height);
521 // We need valid texture state, or NVIDIA won't allow us to write to the texture.
522 glBindTexture(GL_TEXTURE_2D, frame->uyvy_tex);
524 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
528 frame->uyvy_tex = resource_pool->create_2d_texture(GL_RGBA8, width / 2, height);
531 glGenBuffers(1, &frame->pbo);
533 glBindBuffer(GL_PIXEL_PACK_BUFFER, frame->pbo);
535 glBufferStorage(GL_PIXEL_PACK_BUFFER, stride * height, nullptr, GL_MAP_READ_BIT | GL_MAP_PERSISTENT_BIT);
537 frame->uyvy_ptr = (uint8_t *)glMapBufferRange(GL_PIXEL_PACK_BUFFER, 0, stride * height, GL_MAP_READ_BIT | GL_MAP_PERSISTENT_BIT);
539 frame->uyvy_ptr_local.reset(new uint8_t[stride * height]);
540 frame->resource_pool = resource_pool;
545 void DeckLinkOutput::present_thread_func()
547 pthread_setname_np(pthread_self(), "DeckLinkOutput");
549 unique_ptr<Frame> frame;
551 unique_lock<mutex> lock(frame_queue_mutex);
552 frame_queues_changed.wait(lock, [this]{
553 return should_quit.should_quit() || !pending_video_frames.empty();
555 if (should_quit.should_quit()) {
558 frame = move(pending_video_frames.front());
559 pending_video_frames.pop();
560 ++num_frames_in_flight;
561 ++metric_decklink_output_inflight_frames;
565 int err = glClientWaitSync(frame->fence.get(), /*flags=*/0, 0);
566 if (err == GL_TIMEOUT_EXPIRED) {
567 // NVIDIA likes to busy-wait; yield instead.
568 this_thread::sleep_for(milliseconds(1));
574 frame->fence.reset();
576 if (global_flags.ten_bit_output) {
577 memcpy(frame->uyvy_ptr_local.get(), frame->uyvy_ptr, v210Converter::get_v210_stride(width) * height);
579 memcpy(frame->uyvy_ptr_local.get(), frame->uyvy_ptr, width * height * 2);
582 // Release any input frames we needed to render this frame.
583 frame->input_frames.clear();
585 BMDTimeValue pts = frame->pts;
586 BMDTimeValue duration = frame->duration;
587 HRESULT res = output->ScheduleVideoFrame(frame.get(), pts, duration, TIMEBASE);
589 frame.release(); // Owned by the driver now.
591 fprintf(stderr, "Could not schedule video frame! (error=0x%08x)\n", res);
593 lock_guard<mutex> lock(frame_queue_mutex);
594 frame_freelist.push(move(frame));
595 --num_frames_in_flight;
596 --metric_decklink_output_inflight_frames;
601 HRESULT STDMETHODCALLTYPE DeckLinkOutput::QueryInterface(REFIID, LPVOID *)
603 return E_NOINTERFACE;
606 ULONG STDMETHODCALLTYPE DeckLinkOutput::AddRef()
608 return refcount.fetch_add(1) + 1;
611 ULONG STDMETHODCALLTYPE DeckLinkOutput::Release()
613 int new_ref = refcount.fetch_sub(1) - 1;
619 DeckLinkOutput::Frame::~Frame()
621 glBindBuffer(GL_PIXEL_PACK_BUFFER, pbo);
623 glUnmapBuffer(GL_PIXEL_PACK_BUFFER);
625 glBindBuffer(GL_PIXEL_PACK_BUFFER, 0);
627 glDeleteBuffers(1, &pbo);
629 resource_pool->release_2d_texture(uyvy_tex);
633 HRESULT STDMETHODCALLTYPE DeckLinkOutput::Frame::QueryInterface(REFIID, LPVOID *)
635 return E_NOINTERFACE;
638 ULONG STDMETHODCALLTYPE DeckLinkOutput::Frame::AddRef()
640 return refcount.fetch_add(1) + 1;
643 ULONG STDMETHODCALLTYPE DeckLinkOutput::Frame::Release()
645 int new_ref = refcount.fetch_sub(1) - 1;
651 long DeckLinkOutput::Frame::GetWidth()
653 return global_flags.width;
656 long DeckLinkOutput::Frame::GetHeight()
658 return global_flags.height;
661 long DeckLinkOutput::Frame::GetRowBytes()
663 if (global_flags.ten_bit_output) {
664 return v210Converter::get_v210_stride(global_flags.width);
666 return global_flags.width * 2;
670 BMDPixelFormat DeckLinkOutput::Frame::GetPixelFormat()
672 if (global_flags.ten_bit_output) {
673 return bmdFormat10BitYUV;
675 return bmdFormat8BitYUV;
679 BMDFrameFlags DeckLinkOutput::Frame::GetFlags()
681 return bmdFrameFlagDefault;
684 HRESULT DeckLinkOutput::Frame::GetBytes(/* out */ void **buffer)
686 *buffer = uyvy_ptr_local.get();
690 HRESULT DeckLinkOutput::Frame::GetTimecode(/* in */ BMDTimecodeFormat format, /* out */ IDeckLinkTimecode **timecode)
692 fprintf(stderr, "STUB: GetTimecode()\n");
696 HRESULT DeckLinkOutput::Frame::GetAncillaryData(/* out */ IDeckLinkVideoFrameAncillary **ancillary)
698 fprintf(stderr, "STUB: GetAncillaryData()\n");