Skip to content

Commit 99b960d

Browse files
committed
decompress/oapv: Use RAII Oapv_Frames
1 parent 68c2d50 commit 99b960d

1 file changed

Lines changed: 6 additions & 22 deletions

File tree

src/video_decompress/openapv.cpp

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ namespace {
5353

5454
#define MOD_NAME "[OpenAPV dec.] "
5555

56-
#define MAX_NUM_FRMS (1) // support only primary frame
5756
#define FRM_INDEX (0) // index of primary frame in oapv_frms_t
5857

5958
struct state_video_decompress_openapv {
@@ -63,7 +62,7 @@ struct state_video_decompress_openapv {
6362
oapvd_t decoder_handle{};
6463
oapvd_cdesc_t cdesc{};
6564

66-
oapv_frms_t decoded_frames{};
65+
Oapv_Frames decoded_frames;
6766
oapv_bitb_t input_buffer{};
6867

6968
bool configured = false;
@@ -83,20 +82,12 @@ state_video_decompress_openapv::state_video_decompress_openapv() {
8382
if (OAPV_FAILED(ret)) {
8483
throw std::runtime_error("oapvd_create failed (" + std::string(oapv_err_str(ret)) + ")");
8584
}
86-
87-
decoded_frames.num_frms = MAX_NUM_FRMS;
8885
}
8986

9087
state_video_decompress_openapv::~state_video_decompress_openapv() {
9188
if (decoder_handle) {
9289
oapvd_delete(decoder_handle);
9390
}
94-
for (int i = 0; i < decoded_frames.num_frms; ++i) {
95-
if (auto& imgb = decoded_frames.frm[i].imgb; imgb) {
96-
ug_oapv_imgb_free(imgb);
97-
imgb = nullptr;
98-
}
99-
}
10091
}
10192

10293
bool configure_with(state_video_decompress_openapv *s, unsigned char *bitstream_buffer, size_t codestream_size) {
@@ -109,27 +100,20 @@ bool configure_with(state_video_decompress_openapv *s, unsigned char *bitstream_
109100
return false;
110101
}
111102

112-
if(auto& imgb = s->decoded_frames.frm[FRM_INDEX].imgb; imgb){
113-
ug_oapv_imgb_free(imgb);
114-
imgb = nullptr;
115-
}
116-
117103
const oapv_frm_info_t &frm_info = aui.frm_info[FRM_INDEX];
118104
int fmt = OAPV_CS_GET_FORMAT(frm_info.cs);
119105
if (fmt != OAPV_CF_YCBCR422 && fmt != OAPV_CF_YCBCR444 && fmt != OAPV_CF_YCBCR4444) {
120106
log_msg(LOG_LEVEL_ERROR, MOD_NAME "Unsupported APV color format %d for frame %d.\n", fmt, FRM_INDEX);
121107
return false;
122108
}
123109

124-
auto imgb = create_oapv_imgb(frm_info.w, frm_info.h, frm_info.cs);
125-
if (!imgb) {
110+
if (!s->decoded_frames.configure_with(frm_info.w, frm_info.h, frm_info.cs)){
126111
log_msg(LOG_LEVEL_ERROR, MOD_NAME "Failed to set up output buffer for frame %d.\n", FRM_INDEX);
127112
return false;
128113
}
129-
s->decoded_frames.frm[FRM_INDEX].imgb = imgb;
130114

131-
s->decoded_frames.frm[FRM_INDEX].pbu_type = frm_info.pbu_type;
132-
s->decoded_frames.frm[FRM_INDEX].group_id = frm_info.group_id;
115+
s->decoded_frames.get_primary()->pbu_type = frm_info.pbu_type;
116+
s->decoded_frames.get_primary()->group_id = frm_info.group_id;
133117

134118
const from_openapv_conversion *conv = get_from_openapv_conversion(s->out_codec, frm_info.cs);
135119
if (conv == nullptr) {
@@ -237,13 +221,13 @@ decompress_status openapv_decompress(void *state, unsigned char *dst, unsigned c
237221
s->input_buffer.bsize = src_len;
238222

239223
oapvd_stat_t stat{};
240-
int ret = oapvd_decode(s->decoder_handle, &s->input_buffer, &s->decoded_frames, nullptr, &stat);
224+
int ret = oapvd_decode(s->decoder_handle, &s->input_buffer, s->decoded_frames.get_frms(), nullptr, &stat);
241225
if (OAPV_FAILED(ret)) {
242226
log_msg(LOG_LEVEL_WARNING, MOD_NAME "oapvd_decode failed (%s) src_len=%u.\n", oapv_err_str(ret), src_len);
243227
return DECODER_NO_FRAME;
244228
}
245229

246-
oapv_imgb_t *imgb = s->decoded_frames.frm[FRM_INDEX].imgb;
230+
oapv_imgb_t *imgb = s->decoded_frames.get_primary()->imgb;
247231
if (imgb->cs != s->convert_from_planar->required_src_cs) {
248232
log_msg(LOG_LEVEL_WARNING, MOD_NAME "Decoded colorspace 0x%x does not match required 0x%x for output codec %s.\n",
249233
imgb->cs, s->convert_from_planar->required_src_cs, get_codec_name(s->out_codec));

0 commit comments

Comments
 (0)