Skip to content

Commit

Permalink
video display: returns bool from putf API
Browse files Browse the repository at this point in the history
Use bool return value from putf - returning int here may be error-prone
because the semantics is unclear (is success 0 or TRUE).
  • Loading branch information
MartinPulec committed Jul 18, 2023
1 parent a97352a commit d2b39ac
Show file tree
Hide file tree
Showing 29 changed files with 112 additions and 116 deletions.
2 changes: 1 addition & 1 deletion src/aja_win32_stub.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ __declspec(dllimport) int display_aja_reconfigure(void *state, struct video_desc
__declspec(dllimport) void *display_aja_init(struct module * /* parent */, const char *fmt, unsigned int flags);
__declspec(dllimport) void display_aja_done(void *state);
__declspec(dllimport) struct video_frame *display_aja_getf(void *state);
__declspec(dllimport) int display_aja_putf(void *state, struct video_frame *frame, long long nonblock);
__declspec(dllimport) bool display_aja_putf(void *state, struct video_frame *frame, long long nonblock);
__declspec(dllimport) void display_aja_put_audio_frame(void *state, const struct audio_frame *frame);
__declspec(dllimport) int display_aja_reconfigure_audio(void *state, int quant_samples, int channels,
int sample_rate);
Expand Down
6 changes: 3 additions & 3 deletions src/rtp/video_decoders.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -706,9 +706,9 @@ static void *decompress_thread(void *args) {

decoder->frame->ssrc = msg->nofec_frame->ssrc;
decoder->frame->timestamp = msg->nofec_frame->timestamp;
int ret = display_put_frame(decoder->display,
decoder->frame, putf_timeout);
msg->is_displayed = ret == 0;
const bool ret = display_put_frame(
decoder->display, decoder->frame, putf_timeout);
msg->is_displayed = ret;
decoder->frame = display_get_frame(decoder->display);
}

Expand Down
14 changes: 7 additions & 7 deletions src/video_display.c
Original file line number Diff line number Diff line change
Expand Up @@ -332,10 +332,10 @@ struct video_frame *display_get_frame(struct display *d)
}
}

static int display_frame_helper(struct display *d, struct video_frame *frame, long long timeout_ns)
static bool display_frame_helper(struct display *d, struct video_frame *frame, long long timeout_ns)
{
int ret = d->funcs->putf(d->state, frame, timeout_ns);
if (ret != 0 || !d->funcs->generic_fps_indicator_prefix) {
bool ret = d->funcs->putf(d->state, frame, timeout_ns);
if (!ret || !d->funcs->generic_fps_indicator_prefix) {
return ret;
}
// display FPS
Expand All @@ -362,10 +362,10 @@ static int display_frame_helper(struct display *d, struct video_frame *frame, lo
* Should not be NULL unless we want to quit display mainloop.
* @param timeout_ns specifies timeout that should be waited (@sa putf_flags).
* displays may ignore the value and act like PUTF_NONBLOCK if blocking is not requested.
* @retval 0 if displayed succesfully (or discarded if flag=PUTF_DISCARD)
* @retval 1 if not displayed when flag=PUTF_NONBLOCK and it would block
* @retval true if displayed succesfully (or discarded if flag=PUTF_DISCARD)
* @retval false if not displayed when flag=PUTF_NONBLOCK and it would block
*/
int display_put_frame(struct display *d, struct video_frame *frame, long long timeout_ns)
bool display_put_frame(struct display *d, struct video_frame *frame, long long timeout_ns)
{
assert(d->magic == DISPLAY_MAGIC);

Expand All @@ -374,7 +374,7 @@ int display_put_frame(struct display *d, struct video_frame *frame, long long ti
}

if (d->postprocess) {
int display_ret = 0;
bool display_ret = true;
for (int i = 0; i < d->pp_output_frames_count; ++i) {
struct video_frame *display_frame = d->funcs->getf(d->state);
int ret = vo_postprocess(d->postprocess,
Expand Down
6 changes: 3 additions & 3 deletions src/video_display.h
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ enum display_prop_vid_mode {
};
/// @}

#define VIDEO_DISPLAY_ABI_VERSION 19
#define VIDEO_DISPLAY_ABI_VERSION 20

#define DISPLAY_NO_GENERIC_FPS_INDICATOR ((const char *) 0x00)

Expand All @@ -154,7 +154,7 @@ struct video_display_info {
void (*done) (void *state);
struct video_frame *(*getf) (void *state);
/// @param timeout_ns display is supposed immplement the PUTF_* macros, numerical timeout is seldom used (but double-framerate postprocess can use that)
int (*putf) (void *state, struct video_frame *frame, long long timeout_ns);
bool (*putf) (void *state, struct video_frame *frame, long long timeout_ns);
int (*reconfigure_video)(void *state, struct video_desc desc);
int (*ctl_property)(void *state, int property, void *val, size_t *len);
void (*put_audio_frame) (void *state, const struct audio_frame *frame); ///< may be NULL
Expand Down Expand Up @@ -189,7 +189,7 @@ struct video_frame *display_get_frame(struct display *d);
/// }

// documented at definition
int display_put_frame(struct display *d, struct video_frame *frame, long long timeout_ns);
bool display_put_frame(struct display *d, struct video_frame *frame, long long timeout_ns);
int display_reconfigure(struct display *d, struct video_desc desc, enum video_mode mode);
/** @brief Get/set property (similar to ioctl)
* @retval TRUE if succeeds
Expand Down
9 changes: 5 additions & 4 deletions src/video_display/aggregate.c
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ static struct video_frame *display_aggregate_getf(void *state)
return s->frame;
}

static int display_aggregate_putf(void *state, struct video_frame *frame, long long nonblock)
static bool display_aggregate_putf(void *state, struct video_frame *frame, long long nonblock)
{
unsigned int i;
struct display_aggregate_state *s = (struct display_aggregate_state *)state;
Expand All @@ -226,12 +226,13 @@ static int display_aggregate_putf(void *state, struct video_frame *frame, long l
struct video_frame *dev_frame = NULL;
if(frame)
dev_frame = s->dev_frames[i];
int ret = display_put_frame(s->devices[i], dev_frame, nonblock);
if(ret != 0)
bool ret = display_put_frame(s->devices[i], dev_frame, nonblock);
if (!ret) {
return ret;
}
}

return 0;
return true;
}

static int display_aggregate_reconfigure(void *state, struct video_desc desc)
Expand Down
14 changes: 7 additions & 7 deletions src/video_display/aja.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ struct display {
AJAStatus SetUpVideo();
AJAStatus SetUpAudio();
void RouteOutputSignal();
int Putf(struct video_frame *frame, long long nonblock);
bool Putf(struct video_frame *frame, long long flags);

static NTV2FrameRate getFrameRate(double fps);
void print_stats();
Expand Down Expand Up @@ -680,14 +680,14 @@ void display::process_frames()
}
}

int display::Putf(struct video_frame *frame, long long flags) {
bool display::Putf(struct video_frame *frame, long long flags) {
if (frame == nullptr) {
return 1;
return true;
}

if (flags == PUTF_DISCARD) {
vf_free(frame);
return 0;
return true;
}

unique_lock<mutex> lk(frames_lock);
Expand All @@ -698,13 +698,13 @@ int display::Putf(struct video_frame *frame, long long flags) {
LOG(LOG_LEVEL_NOTICE) << MODULE_NAME << mFramesDiscarded << " frames discarded - try to increase buffer count or set \"novsync\" (see \"-d aja:help\" for details).\n";
}
vf_free(frame);
return 1;
return false;
}
frames.push(frame);
lk.unlock();
frame_ready.notify_one();

return 0;
return true;
}

void aja::display::print_stats() {
Expand Down Expand Up @@ -1002,7 +1002,7 @@ LINK_SPEC struct video_frame *display_aja_getf(void *state)
return vf_alloc_desc_data(s->desc);
}

LINK_SPEC int display_aja_putf(void *state, struct video_frame *frame, long long nonblock)
LINK_SPEC bool display_aja_putf(void *state, struct video_frame *frame, long long nonblock)
{
auto s = static_cast<struct aja::display *>(state);

Expand Down
4 changes: 2 additions & 2 deletions src/video_display/blend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ static struct video_frame *display_blend_getf(void *state)
return vf_alloc_desc_data(s->desc);
}

static int display_blend_putf(void *state, struct video_frame *frame, long long flags)
static bool display_blend_putf(void *state, struct video_frame *frame, long long flags)
{
shared_ptr<struct state_blend_common> s = ((struct state_blend *)state)->common;

Expand All @@ -363,7 +363,7 @@ static int display_blend_putf(void *state, struct video_frame *frame, long long
s->cv.notify_one();
}

return 0;
return true;
}

static int display_blend_get_property(void *state, int property, void *val, size_t *len)
Expand Down
10 changes: 3 additions & 7 deletions src/video_display/bluefish444.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -889,22 +889,18 @@ display_bluefish444_getf(void *state)
return frame;
}

static int display_bluefish444_putf(void *state, struct video_frame *frame, long long nonblock)
static bool display_bluefish444_putf(void *state, struct video_frame *frame, long long nonblock)
{
UNUSED(nonblock);
display_bluefish444_state *s =
(display_bluefish444_state *) state;
int ret;

try {
s->putf(frame);
ret = 0;
return true;
} catch(runtime_error &e) {
cerr << "[Blue444 disp] " << e.what() << endl;
ret = -1;
}

return ret;
return false;
}

static int
Expand Down
6 changes: 3 additions & 3 deletions src/video_display/caca.c
Original file line number Diff line number Diff line change
Expand Up @@ -258,11 +258,11 @@ static void *worker(void *arg)
return NULL;
}

static int display_caca_putf(void *state, struct video_frame *frame, long long timeout_ns)
static bool display_caca_putf(void *state, struct video_frame *frame, long long timeout_ns)
{
if (timeout_ns == PUTF_DISCARD) {
vf_free(frame);
return 0;
return true;
}

struct state_caca *s = state;
Expand All @@ -279,7 +279,7 @@ static int display_caca_putf(void *state, struct video_frame *frame, long long t
pthread_mutex_unlock(&s->lock);
pthread_cond_signal(&s->frame_ready_cv);

return 0;
return true;
}

static int display_caca_get_property(void *state, int property, void *val, size_t *len)
Expand Down
4 changes: 2 additions & 2 deletions src/video_display/conference.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -708,7 +708,7 @@ static struct video_frame *display_conference_getf(void *state)
return vf_alloc_desc_data(s->desc);
}

static int display_conference_putf(void *state, struct video_frame *frame, long long flags)
static bool display_conference_putf(void *state, struct video_frame *frame, long long flags)
{
auto s = static_cast<state_conference *>(state)->common;

Expand All @@ -732,7 +732,7 @@ static int display_conference_putf(void *state, struct video_frame *frame, long
s->new_incoming_frame_cv.notify_one();
}

return 0;
return true;
}

static void display_conference_probe(struct device_info **available_cards, int *count, void (**deleter)(void *)) {
Expand Down
18 changes: 9 additions & 9 deletions src/video_display/decklink.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ class PlaybackDelegate : public IDeckLinkVideoOutputCallback // , public IDeckLi
ULONG STDMETHODCALLTYPE AddRef() override { return 1; }
ULONG STDMETHODCALLTYPE Release() override { return 1; }

int EnqueueFrame(DeckLinkFrame *deckLinkFrame);
bool EnqueueFrame(DeckLinkFrame *deckLinkFrame);
void ScheduleNextFrame();
void ScheduleAudio(const struct audio_frame *frame, uint32_t *samples);

Expand Down Expand Up @@ -380,18 +380,18 @@ void PlaybackDelegate::Reset()
m_avg_diff = 0;
}

int PlaybackDelegate::EnqueueFrame(DeckLinkFrame *deckLinkFrame)
bool PlaybackDelegate::EnqueueFrame(DeckLinkFrame *deckLinkFrame)
{
const unique_lock<mutex> lk(schedLock);
if (schedFrames.size() < m_max_sched_frames) {
schedFrames.push(deckLinkFrame);
return 0;
return true;
}

deckLinkFrame->Release();
LOG(LOG_LEVEL_WARNING) << MOD_NAME "Dismissed frame\n";
m_audio_sync_ts = INT64_MIN;
return 1;
return false;
}

void PlaybackDelegate::ScheduleNextFrame()
Expand Down Expand Up @@ -704,14 +704,14 @@ static void update_timecode(DeckLinkTimecode *tc, double fps)
tc->SetBCD(bcd);
}

static int display_decklink_putf(void *state, struct video_frame *frame,
static bool display_decklink_putf(void *state, struct video_frame *frame,
[[maybe_unused]] long long timeout_ns)
{
struct state_decklink *s = (struct state_decklink *)state;
int ret = 0;
bool ret = true;

if (frame == NULL)
return FALSE;
return true;

assert(s->magic == DECKLINK_MAGIC);

Expand Down Expand Up @@ -998,8 +998,8 @@ display_decklink_reconfigure(void *state, struct video_desc desc)
auto *f = allocate_new_decklink_frame(s);
for (int i = 0; i < s->delegate.m_preroll; ++i) {
f->AddRef();
const int ret = s->delegate.EnqueueFrame(f);
assert(ret == 0);
const bool ret = s->delegate.EnqueueFrame(f);
assert(ret);
s->delegate.ScheduleNextFrame();
}
f->Release(); // release initial reference from alloc
Expand Down
4 changes: 2 additions & 2 deletions src/video_display/deltacast.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ display_deltacast_getf(void *state)
return s->frame;
}

static int display_deltacast_putf(void *state, struct video_frame *frame, long long nonblock)
static bool display_deltacast_putf(void *state, struct video_frame *frame, long long nonblock)
{
struct state_deltacast *s = (struct state_deltacast *)state;
struct timeval tv;
Expand Down Expand Up @@ -178,7 +178,7 @@ static int display_deltacast_putf(void *state, struct video_frame *frame, long l
}
s->frames++;

return 0;
return true;
}

static int
Expand Down
6 changes: 3 additions & 3 deletions src/video_display/dummy.c
Original file line number Diff line number Diff line change
Expand Up @@ -210,10 +210,10 @@ static void dump_buf(unsigned char *buf, size_t len, int block_size) {
printf("\n");
}

static int display_dummy_putf(void *state, struct video_frame *frame, long long flags)
static bool display_dummy_putf(void *state, struct video_frame *frame, long long flags)
{
if (flags == PUTF_DISCARD || frame == NULL) {
return 0;
return true;
}
struct dummy_display_state *s = state;
if (s->dump_bytes > 0) {
Expand All @@ -234,7 +234,7 @@ static int display_dummy_putf(void *state, struct video_frame *frame, long long
}
}

return 0;
return true;
}

static int display_dummy_get_property(void *state, int property, void *val, size_t *len)
Expand Down
6 changes: 3 additions & 3 deletions src/video_display/dump.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,16 +114,16 @@ static struct video_frame *display_dump_getf(void *state)
return s->f;
}

static int display_dump_putf(void *state, struct video_frame *frame, long long flags)
static bool display_dump_putf(void *state, struct video_frame *frame, long long flags)
{
struct dump_display_state *s = state;
if (frame == NULL || flags == PUTF_DISCARD) {
return 0;
return true;
}
assert(frame == s->f);
export_video(s->e, frame);

return 0;
return true;
}

static int display_dump_get_property(void *state, int property, void *val, size_t *len)
Expand Down
6 changes: 3 additions & 3 deletions src/video_display/dvs.c
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,7 @@ display_dvs_getf(void *state)
return s->frame;
}

static int display_dvs_putf(void *state, struct video_frame *frame, long long flags)
static bool display_dvs_putf(void *state, struct video_frame *frame, long long flags)
{
struct state_hdsp *s = (struct state_hdsp *)state;

Expand All @@ -502,7 +502,7 @@ static int display_dvs_putf(void *state, struct video_frame *frame, long long fl
pthread_mutex_lock(&s->lock);
if(s->work_to_do && flags != PUTF_BLOCKING) {
pthread_mutex_unlock(&s->lock);
return EWOULDBLOCK;
return FALSE;
}

/* Wait for the worker to finish... */
Expand All @@ -528,7 +528,7 @@ static int display_dvs_putf(void *state, struct video_frame *frame, long long fl
}
pthread_mutex_unlock(&s->lock);

return 0;
return true;
}

static int display_dvs_reconfigure(void *state,
Expand Down
Loading

0 comments on commit d2b39ac

Please sign in to comment.