1
0
mirror of https://github.com/mpv-player/mpv synced 2024-12-30 11:02:10 +00:00

various: replace if + abort() with MP_HANDLE_OOM()

MP_HANDLE_OOM also aborts but calls assert() first, which
will result in an useful message if compiled in debug mode.
This commit is contained in:
sfan5 2023-01-10 18:59:21 +01:00
parent b6b8380518
commit 7b03cd367d
16 changed files with 24 additions and 48 deletions

View File

@ -52,8 +52,7 @@ struct mp_aframe *mp_aframe_create(void)
{
struct mp_aframe *frame = talloc_zero(NULL, struct mp_aframe);
frame->av_frame = av_frame_alloc();
if (!frame->av_frame)
abort();
MP_HANDLE_OOM(frame->av_frame);
talloc_set_destructor(frame, free_frame);
mp_aframe_reset(frame);
return frame;
@ -701,8 +700,7 @@ int mp_aframe_pool_allocate(struct mp_aframe_pool *pool, struct mp_aframe *frame
if (planes > AV_NUM_DATA_POINTERS) {
av_frame->extended_data =
av_calloc(planes, sizeof(av_frame->extended_data[0]));
if (!av_frame->extended_data)
abort();
MP_HANDLE_OOM(av_frame->extended_data);
} else {
av_frame->extended_data = av_frame->data;
}

View File

@ -169,8 +169,7 @@ static int init_filter(struct mp_filter *da, AVPacket *pkt)
goto fail;
void *buffer = av_mallocz(OUTBUF_SIZE);
if (!buffer)
abort();
MP_HANDLE_OOM(buffer);
lavf_ctx->pb = avio_alloc_context(buffer, OUTBUF_SIZE, 1, spdif_ctx, NULL,
write_packet, NULL);
if (!lavf_ctx->pb) {

View File

@ -210,8 +210,7 @@ static void encode(struct ao *ao, struct mp_aframe *af)
double outpts = mp_aframe_get_pts(af);
AVFrame *frame = mp_aframe_to_avframe(af);
if (!frame)
abort();
MP_HANDLE_OOM(frame);
frame->pts = rint(outpts * av_q2d(av_inv_q(encoder->time_base)));

View File

@ -2658,8 +2658,7 @@ static int dequeue_packet(struct demux_stream *ds, double min_pts,
return -1;
ds->attached_picture_added = true;
struct demux_packet *pkt = demux_copy_packet(ds->sh->attached_picture);
if (!pkt)
abort();
MP_HANDLE_OOM(pkt);
pkt->stream = ds->sh->index;
*res = pkt;
return 1;

View File

@ -247,8 +247,7 @@ static int demux_rawvideo_open(demuxer_t *demuxer, enum demux_check check)
c->disp_h = height;
if (mp_imgfmt) {
c->lav_codecpar = avcodec_parameters_alloc();
if (!c->lav_codecpar)
abort();
MP_HANDLE_OOM(c->lav_codecpar);
c->lav_codecpar->codec_type = AVMEDIA_TYPE_VIDEO;
c->lav_codecpar->codec_id = mp_codec_to_av_codec_id(decoder);
c->lav_codecpar->format = imgfmt2pixfmt(mp_imgfmt);

View File

@ -260,8 +260,7 @@ static void precreate_graph(struct lavfi *c, bool first_init)
c->failed = false;
c->graph = avfilter_graph_alloc();
if (!c->graph)
abort();
MP_HANDLE_OOM(c->graph);
if (mp_set_avopts(c->log, c->graph, c->graph_opts) < 0)
goto error;
@ -852,8 +851,7 @@ static struct lavfi *lavfi_alloc(struct mp_filter *parent)
c->log = f->log;
c->public.f = f;
c->tmp_frame = av_frame_alloc();
if (!c->tmp_frame)
abort();
MP_HANDLE_OOM(c->tmp_frame);
return c;
}

View File

@ -313,8 +313,7 @@ static bool keep_weak_gapless_format(struct mp_aframe *old, struct mp_aframe* ne
{
bool res = false;
struct mp_aframe *new_mod = mp_aframe_new_ref(new);
if (!new_mod)
abort();
MP_HANDLE_OOM(new_mod);
// If the sample formats are compatible (== libswresample generally can
// convert them), keep the AO. On other changes, recreate it.
@ -366,8 +365,7 @@ static int reinit_audio_filters_and_output(struct MPContext *mpctx)
// The "ideal" filter output format
struct mp_aframe *out_fmt = mp_aframe_new_ref(ao_c->filter->output_aformat);
if (!out_fmt)
abort();
MP_HANDLE_OOM(out_fmt);
if (!mp_aframe_config_is_valid(out_fmt)) {
talloc_free(out_fmt);

View File

@ -68,8 +68,7 @@ struct mp_refqueue *mp_refqueue_alloc(struct mp_filter *f)
q->filter = f;
q->conv = mp_autoconvert_create(f);
if (!q->conv)
abort();
MP_HANDLE_OOM(q->conv);
q->in = q->conv->f->pins[1];
mp_pin_connect(q->conv->f->pins[0], f->ppins[0]);
@ -267,8 +266,7 @@ struct mp_image *mp_refqueue_execute_reinit(struct mp_refqueue *q)
mp_refqueue_flush(q);
q->in_format = mp_image_new_ref(cur);
if (!q->in_format)
abort();
MP_HANDLE_OOM(q->in_format);
mp_image_unref_data(q->in_format);
mp_refqueue_add_input(q, cur);

View File

@ -102,8 +102,7 @@ static struct mp_image *alloc_pool(void *pctx, int fmt, int w, int h)
return NULL;
struct mp_image *mpi = mp_image_new_custom_ref(NULL, texture, release_tex);
if (!mpi)
abort();
MP_HANDLE_OOM(mpi);
mp_image_setfmt(mpi, IMGFMT_D3D11);
mp_image_set_size(mpi, w, h);

View File

@ -172,8 +172,7 @@ static struct mp_image *alloc_out(struct mp_filter *vf)
}
AVFrame *av_frame = av_frame_alloc();
if (!av_frame)
abort();
MP_HANDLE_OOM(av_frame);
if (av_hwframe_get_buffer(p->hw_pool, av_frame, 0) < 0) {
MP_ERR(vf, "Failed to allocate frame from hw pool.\n");
av_frame_free(&av_frame);

View File

@ -1102,24 +1102,21 @@ struct AVFrame *mp_image_to_av_frame(struct mp_image *src)
dst->chroma_location = mp_chroma_location_to_av(src->params.chroma_location);
dst->opaque_ref = av_buffer_alloc(sizeof(struct mp_image_params));
if (!dst->opaque_ref)
abort();
MP_HANDLE_OOM(dst->opaque_ref);
*(struct mp_image_params *)dst->opaque_ref->data = src->params;
if (src->icc_profile) {
AVFrameSideData *sd =
av_frame_new_side_data_from_buf(dst, AV_FRAME_DATA_ICC_PROFILE,
new_ref->icc_profile);
if (!sd)
abort();
MP_HANDLE_OOM(sd);
new_ref->icc_profile = NULL;
}
if (src->params.color.sig_peak) {
AVContentLightMetadata *clm =
av_content_light_metadata_create_side_data(dst);
if (!clm)
abort();
MP_HANDLE_OOM(clm);
clm->MaxCLL = src->params.color.sig_peak * MP_REF_WHITE;
}
@ -1130,8 +1127,7 @@ struct AVFrame *mp_image_to_av_frame(struct mp_image *src)
if (!av_frame_get_side_data(dst, mpsd->type)) {
AVFrameSideData *sd = av_frame_new_side_data_from_buf(dst, mpsd->type,
mpsd->buf);
if (!sd)
abort();
MP_HANDLE_OOM(sd);
mpsd->buf = NULL;
}
}

View File

@ -140,8 +140,7 @@ static void sync_get_image(void *ptr)
AVBufferRef *new_ref = av_buffer_create(ctx->ref->data, ctx->ref->size,
free_dr_buffer_on_dr_thread, ctx, 0);
if (!new_ref)
abort(); // tiny malloc OOM
MP_HANDLE_OOM(new_ref);
cmd->res->bufs[0] = new_ref;

View File

@ -317,8 +317,7 @@ bool gl_lcms_get_lut3d(struct gl_lcms *p, struct lut3d **result_lut3d,
if (vid_profile) {
MP_VERBOSE(p, "Got an embedded ICC profile.\n");
p->vid_profile = av_buffer_ref(vid_profile);
if (!p->vid_profile)
abort();
MP_HANDLE_OOM(p->vid_profile);
}
if (!gl_parse_3dlut_size(p->opts->size_str, &s_r, &s_g, &s_b))
@ -344,8 +343,7 @@ bool gl_lcms_get_lut3d(struct gl_lcms *p, struct lut3d **result_lut3d,
uint8_t hash[32];
struct AVSHA *sha = av_sha_alloc();
if (!sha)
abort();
MP_HANDLE_OOM(sha);
av_sha_init(sha, 256);
av_sha_update(sha, cache_info, strlen(cache_info));
if (vid_profile)

View File

@ -579,8 +579,7 @@ static bool create_pass(struct gl_shader_cache *sc, struct sc_entry *entry)
cache_dir = mp_get_user_path(tmp, sc->global, sc->cache_dir);
struct AVSHA *sha = av_sha_alloc();
if (!sha)
abort();
MP_HANDLE_OOM(sha);
av_sha_init(sha, 256);
av_sha_update(sha, entry->total.start, entry->total.len);

View File

@ -1431,8 +1431,7 @@ struct vo_frame *vo_frame_ref(struct vo_frame *frame)
*new = *frame;
for (int n = 0; n < frame->num_frames; n++) {
new->frames[n] = mp_image_new_ref(frame->frames[n]);
if (!new->frames[n])
abort(); // OOM on tiny allocs
MP_HANDLE_OOM(new->frames[n]);
}
new->current = new->num_frames ? new->frames[0] : NULL;
return new;

View File

@ -217,8 +217,7 @@ static void draw_frame(struct vo *vo, struct vo_frame *voframe)
pthread_mutex_unlock(&ectx->lock);
AVFrame *frame = mp_image_to_av_frame(mpi);
if (!frame)
abort();
MP_HANDLE_OOM(frame);
frame->pts = rint(outpts * av_q2d(av_inv_q(avc->time_base)));
frame->pict_type = 0; // keep this at unknown/undefined