Skip to content

Commit

Permalink
Remove redundant get() call on std::shared_ptr
Browse files Browse the repository at this point in the history
Also fix them.
- replaces reference-type of std::shared_ptr with the base pointer type
  for readability.
- Fix `return NULL` where it should be `return false`.
  • Loading branch information
norihiro committed Aug 6, 2024
1 parent 22c3ddc commit 529844b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
15 changes: 8 additions & 7 deletions src/face-tracker-ptz.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -900,7 +900,7 @@ static inline bool operator != (const struct video_scale_info &a, const struct v
return false;
}

static bool scale_set_texture(struct face_tracker_ptz *s, std::shared_ptr<texture_object> &cvtex, struct obs_source_frame *frame)
static bool scale_set_texture(struct face_tracker_ptz *s, texture_object *cvtex, struct obs_source_frame *frame)
{
const struct video_scale_info scaler_src_info = {
frame->format,
Expand Down Expand Up @@ -946,10 +946,10 @@ static bool scale_set_texture(struct face_tracker_ptz *s, std::shared_ptr<textur

if (!video_scaler_scale(s->scaler, scaled_frame.data, scaled_frame.linesize, frame->data, frame->linesize)) {
blog(LOG_ERROR, "video_scaler_scale failed");
return NULL;
return false;
}

cvtex.get()->set_texture_obsframe(&scaled_frame, 1);
cvtex->set_texture_obsframe(&scaled_frame, 1);
return true;
}

Expand All @@ -961,13 +961,14 @@ static struct obs_source_frame *ftptz_filter_video(void *data, struct obs_source
auto *s = (struct face_tracker_ptz*)data;

std::shared_ptr<texture_object> cvtex(new texture_object());
cvtex.get()->scale = s->ftm->scale;
cvtex.get()->tick = s->ftm->tick_cnt;
cvtex->scale = s->ftm->scale;
cvtex->tick = s->ftm->tick_cnt;

if (is_rgb_format(frame->format)) {
cvtex.get()->set_texture_obsframe(frame, s->ftm->scale);
cvtex->set_texture_obsframe(frame, s->ftm->scale);
} else {
scale_set_texture(s, cvtex, frame);
if (!scale_set_texture(s, cvtex.get(), frame))
return frame;
}

s->known_width = frame->width;
Expand Down
6 changes: 3 additions & 3 deletions src/face-tracker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -742,8 +742,8 @@ static inline std::shared_ptr<texture_object> surface_to_cvtex(struct face_track
uint32_t height = gs_stagesurface_get_height(s->stagesurface);

std::shared_ptr<texture_object> cvtex(new texture_object);
cvtex.get()->scale = scale;
cvtex.get()->tick = s->ftm->tick_cnt;
cvtex->scale = scale;
cvtex->tick = s->ftm->tick_cnt;

struct obs_source_frame frame;
memset(&frame, 0, sizeof(frame));
Expand All @@ -752,7 +752,7 @@ static inline std::shared_ptr<texture_object> surface_to_cvtex(struct face_track
frame.width = width;
frame.height = height;
frame.format = VIDEO_FORMAT_BGRA;
cvtex.get()->set_texture_obsframe(&frame, 1);
cvtex->set_texture_obsframe(&frame, 1);

gs_stagesurface_unmap(s->stagesurface);

Expand Down

0 comments on commit 529844b

Please sign in to comment.