Skip to content

Commit 779d332

Browse files
committed
Add free method
1 parent 061c2a6 commit 779d332

File tree

3 files changed

+22
-0
lines changed

3 files changed

+22
-0
lines changed

src/modcamera.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,13 @@ bool mp_camera_hal_initialized(mp_camera_obj_t *self){
315315
return self->initialized;
316316
}
317317

318+
void mp_camera_hal_free_buffer(mp_camera_obj_t *self) {
319+
if (self->captured_buffer) {
320+
esp_camera_fb_return(self->captured_buffer);
321+
self->captured_buffer = NULL;
322+
}
323+
}
324+
318325
const mp_rom_map_elem_t mp_camera_hal_pixel_format_table[] = {
319326
{ MP_ROM_QSTR(MP_QSTR_JPEG), MP_ROM_INT((mp_uint_t)PIXFORMAT_JPEG) },
320327
{ MP_ROM_QSTR(MP_QSTR_YUV422), MP_ROM_INT((mp_uint_t)PIXFORMAT_YUV422) },

src/modcamera.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,13 @@ extern mp_obj_t mp_camera_hal_capture(mp_camera_obj_t *self, int8_t out_format);
198198
*/
199199
extern mp_obj_t mp_camera_hal_convert(mp_camera_obj_t *self, int8_t out_format);
200200

201+
/**
202+
* @brief Frees the buffer of the camera object.
203+
*
204+
* @param self Pointer to the camera object.
205+
*/
206+
extern void mp_camera_hal_free_buffer(mp_camera_obj_t *self);
207+
201208
/**
202209
* @brief Table mapping pixel formats API to their corresponding values at HAL.
203210
* @details Needs to be defined in the port-specific implementation.

src/modcamera_api.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,13 @@ static mp_obj_t camera_convert(mp_obj_t self_in, mp_obj_t arg) {
161161
}
162162
static MP_DEFINE_CONST_FUN_OBJ_2(camera_convert_obj, camera_convert);
163163

164+
static mp_obj_t camera_free_buf(mp_obj_t self_in) {
165+
mp_camera_obj_t *self = MP_OBJ_TO_PTR(self_in);
166+
mp_camera_hal_free_buffer(self);
167+
return mp_const_none;
168+
}
169+
static MP_DEFINE_CONST_FUN_OBJ_1(camera_free_buf_obj, camera_free_buf);
170+
164171
static mp_obj_t camera_reconfigure(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args){
165172
mp_camera_obj_t *self = MP_OBJ_TO_PTR(pos_args[0]);
166173
enum { ARG_frame_size, ARG_pixel_format, ARG_grab_mode, ARG_fb_count };
@@ -298,6 +305,7 @@ static const mp_rom_map_elem_t camera_camera_locals_table[] = {
298305
{ MP_ROM_QSTR(MP_QSTR_reconfigure), MP_ROM_PTR(&camera_reconfigure_obj) },
299306
{ MP_ROM_QSTR(MP_QSTR_capture), MP_ROM_PTR(&camera_capture_obj) },
300307
{ MP_ROM_QSTR(MP_QSTR_convert), MP_ROM_PTR(&camera_convert_obj) },
308+
{ MP_ROM_QSTR(MP_QSTR_free_buffer), MP_ROM_PTR(&camera_free_buf_obj) },
301309
{ MP_ROM_QSTR(MP_QSTR_init), MP_ROM_PTR(&camera_init_obj) },
302310
{ MP_ROM_QSTR(MP_QSTR_deinit), MP_ROM_PTR(&mp_camera_deinit_obj) },
303311
{ MP_ROM_QSTR(MP_QSTR___del__), MP_ROM_PTR(&mp_camera_deinit_obj) },

0 commit comments

Comments
 (0)