[media] move to all-c allocation #1421

This commit is contained in:
nick black 2021-03-20 08:58:51 -04:00
parent c1ee44b1b7
commit fceb0b5182
2 changed files with 16 additions and 14 deletions

View File

@ -269,19 +269,23 @@ int ffmpeg_resize(ncvisual* nc, int rows, int cols) {
} }
auto ffmpeg_details_init(void) -> ncvisual_details* { auto ffmpeg_details_init(void) -> ncvisual_details* {
auto deets = new ncvisual_details{}; auto deets = static_cast<ncvisual_details*>(malloc(sizeof(ncvisual_details)));
deets->stream_index = -1; if(deets){
deets->sub_stream_index = -1; memset(deets, 0, sizeof(*deets));
if((deets->frame = av_frame_alloc()) == nullptr){ deets->stream_index = -1;
delete deets; deets->sub_stream_index = -1;
return nullptr; if((deets->frame = av_frame_alloc()) == nullptr){
free(deets);
return nullptr;
}
} }
return deets; return deets;
} }
auto ffmpeg_create() -> ncvisual* { auto ffmpeg_create() -> ncvisual* {
ncvisual* nc = static_cast<ncvisual*>(malloc(sizeof(*nc))); auto nc = static_cast<ncvisual*>(malloc(sizeof(ncvisual)));
if(nc){ if(nc){
memset(nc, 0, sizeof(*nc));
if((nc->details = ffmpeg_details_init()) == nullptr){ if((nc->details = ffmpeg_details_init()) == nullptr){
free(nc); free(nc);
return nullptr; return nullptr;
@ -591,7 +595,7 @@ auto ffmpeg_details_destroy(ncvisual_details* deets) -> void {
av_packet_free(&deets->packet); av_packet_free(&deets->packet);
avformat_close_input(&deets->fmtctx); avformat_close_input(&deets->fmtctx);
avsubtitle_free(&deets->subtitle); avsubtitle_free(&deets->subtitle);
delete deets; free(deets);
} }
static const ncvisual_implementation ffmpeg_impl = { static const ncvisual_implementation ffmpeg_impl = {

View File

@ -16,12 +16,9 @@ typedef struct ncvisual_details {
} ncvisual_details; } ncvisual_details;
auto oiio_details_init(void) -> ncvisual_details* { auto oiio_details_init(void) -> ncvisual_details* {
auto deets = new ncvisual_details{}; auto deets = static_cast<ncvisual_details*>(malloc(sizeof(ncvisual_details)));
if(deets){ if(deets){
deets->image = nullptr; memset(deets, 0, sizeof(*deets));
deets->frame = nullptr;
deets->ibuf = nullptr;
deets->framenum = 0;
} }
return deets; return deets;
} }
@ -34,8 +31,9 @@ auto oiio_details_destroy(ncvisual_details* deets) -> void {
} }
auto oiio_create() -> ncvisual* { auto oiio_create() -> ncvisual* {
ncvisual* nc = static_cast<ncvisual*>(malloc(sizeof(*nc))); auto nc = static_cast<ncvisual*>(malloc(sizeof(*nc)));
if(nc){ if(nc){
memset(nc, 0, sizeof(*nc));
if((nc->details = oiio_details_init()) == nullptr){ if((nc->details = oiio_details_init()) == nullptr){
free(nc); free(nc);
return nullptr; return nullptr;