Skip to content

Commit 6db7ab7

Browse files
committed
oapv: Helper RAII class to manage oapv_frms_t with allocated buffer
1 parent 32fcaba commit 6db7ab7

2 files changed

Lines changed: 30 additions & 0 deletions

File tree

src/openapv/openapv_common.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,3 +132,17 @@ oapv_imgb_t *create_oapv_imgb(int width, int height, int colorspace){
132132
return ret.release();
133133
}
134134

135+
bool Oapv_Frames::configure_with(int width, int height, int colorspace){
136+
imgb.reset(create_oapv_imgb(width, height, colorspace));
137+
if(!imgb){
138+
frms.num_frms = 0;
139+
return false;
140+
}
141+
142+
frms.num_frms = 1;
143+
frms.frm[0].group_id = 1;
144+
frms.frm[0].pbu_type = OAPV_PBU_TYPE_PRIMARY_FRAME;
145+
frms.frm[0].imgb = imgb.get();
146+
return true;
147+
}
148+

src/openapv/openapv_common.hpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,27 @@
3838

3939
#ifndef OPENAPV_COMMON_HPP_EEE9BB2DDF414F64A86BD2DCC77D78C5
4040
#define OPENAPV_COMMON_HPP_EEE9BB2DDF414F64A86BD2DCC77D78C5
41+
#include <cassert>
42+
#include <memory>
4143
#include <oapv/oapv.h>
4244

45+
#include "utils/misc.h"
46+
4347
const char *oapv_err_str(int err);
4448

4549
oapv_imgb_t *create_oapv_imgb(int width, int height, int colorspace);
4650
void ug_oapv_imgb_free(oapv_imgb_t *imgb);
4751

52+
using oapv_imgb_uniq = std::unique_ptr<oapv_imgb_t, deleter_from_fcn<ug_oapv_imgb_free>>;
53+
54+
class Oapv_Frames{
55+
public:
56+
bool configure_with(int width, int height, int colorspace);
57+
oapv_frms_t *get_frms() { return &frms; }
58+
oapv_frm_t *get_primary() { assert(frms.num_frms > 0); return &frms.frm[0]; }
59+
private:
60+
oapv_frms_t frms{};
61+
oapv_imgb_uniq imgb;
62+
};
63+
4864
#endif //OPENAPV_COMMON_HPP_EEE9BB2DDF414F64A86BD2DCC77D78C5

0 commit comments

Comments
 (0)