summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--audio/aframe.c13
-rw-r--r--audio/aframe.h1
2 files changed, 14 insertions, 0 deletions
diff --git a/audio/aframe.c b/audio/aframe.c
index 35259ba208..0bb2f872b4 100644
--- a/audio/aframe.c
+++ b/audio/aframe.c
@@ -100,6 +100,19 @@ void mp_aframe_unref_data(struct mp_aframe *frame)
talloc_free(tmp);
}
+// Allocate this much data. Returns false for failure (data already allocated,
+// invalid sample count or format, allocation failures).
+// Normally you're supposed to use a frame pool and mp_aframe_pool_allocate().
+bool mp_aframe_alloc_data(struct mp_aframe *frame, int samples)
+{
+ if (mp_aframe_is_allocated(frame))
+ return false;
+ struct mp_aframe_pool *p = mp_aframe_pool_create(NULL);
+ int r = mp_aframe_pool_allocate(p, frame, samples);
+ talloc_free(p);
+ return r >= 0;
+}
+
// Return a new reference to the data in av_frame. av_frame itself is not
// touched. Returns NULL if not representable, or if input is NULL.
// Does not copy the timestamps.
diff --git a/audio/aframe.h b/audio/aframe.h
index 21d4494f5f..be456a3dd1 100644
--- a/audio/aframe.h
+++ b/audio/aframe.h
@@ -20,6 +20,7 @@ struct AVFrame *mp_aframe_to_avframe_and_unref(struct mp_aframe *frame);
struct AVFrame *mp_aframe_get_raw_avframe(struct mp_aframe *frame);
bool mp_aframe_is_allocated(struct mp_aframe *frame);
+bool mp_aframe_alloc_data(struct mp_aframe *frame, int samples);
void mp_aframe_config_copy(struct mp_aframe *dst, struct mp_aframe *src);
bool mp_aframe_config_equals(struct mp_aframe *a, struct mp_aframe *b);