summaryrefslogtreecommitdiff
path: root/vpx
diff options
context:
space:
mode:
authorJames Zern <jzern@google.com>2013-07-11 23:01:26 -0700
committerJames Zern <jzern@google.com>2013-07-11 23:01:26 -0700
commitb088998e5d538e99d5d9f461482b0a87c95d5931 (patch)
treef4777978f3431835a37fb7874713fa11db2aa583 /vpx
parent119decdee7f3052b5f0a6bc3f3a6e84d157054c9 (diff)
downloadlibvpx-b088998e5d538e99d5d9f461482b0a87c95d5931.tar
libvpx-b088998e5d538e99d5d9f461482b0a87c95d5931.tar.gz
libvpx-b088998e5d538e99d5d9f461482b0a87c95d5931.tar.bz2
libvpx-b088998e5d538e99d5d9f461482b0a87c95d5931.zip
vp[89]_dx_iface: factorize vp8_mmap_*()
s/vp8/vpx/ -> vpx_codec_internal.h / vpx_codec.c Change-Id: If4192b40206276a761b01d44e334fe15bcb81128
Diffstat (limited to 'vpx')
-rw-r--r--vpx/internal/vpx_codec_internal.h26
-rw-r--r--vpx/src/vpx_codec.c49
2 files changed, 75 insertions, 0 deletions
diff --git a/vpx/internal/vpx_codec_internal.h b/vpx/internal/vpx_codec_internal.h
index 0b057de4c..05fed977e 100644
--- a/vpx/internal/vpx_codec_internal.h
+++ b/vpx/internal/vpx_codec_internal.h
@@ -474,4 +474,30 @@ static void vpx_internal_error(struct vpx_internal_error_info *info,
if (info->setjmp)
longjmp(info->jmp, info->error_code);
}
+
+//------------------------------------------------------------------------------
+// mmap interface
+
+typedef struct {
+ unsigned int id;
+ unsigned long sz;
+ unsigned int align;
+ unsigned int flags;
+ unsigned long (*calc_sz)(const vpx_codec_dec_cfg_t *, vpx_codec_flags_t);
+} mem_req_t;
+
+// Allocates mmap.priv and sets mmap.base based on mmap.sz/align/flags
+// requirements.
+// Returns #VPX_CODEC_OK on success, #VPX_CODEC_MEM_ERROR otherwise.
+vpx_codec_err_t vpx_mmap_alloc(vpx_codec_mmap_t *mmap);
+
+// Frees mmap.base allocated by a call to vpx_mmap_alloc().
+void vpx_mmap_dtor(vpx_codec_mmap_t *mmap);
+
+// Checks each mmap has the size requirement specificied by mem_reqs.
+// Returns #VPX_CODEC_OK on success, #VPX_CODEC_MEM_ERROR otherwise.
+vpx_codec_err_t vpx_validate_mmaps(const vpx_codec_stream_info_t *si,
+ const vpx_codec_mmap_t *mmaps,
+ const mem_req_t *mem_reqs, int nreqs,
+ vpx_codec_flags_t init_flags);
#endif
diff --git a/vpx/src/vpx_codec.c b/vpx/src/vpx_codec.c
index 61d7f4c18..1f664ae49 100644
--- a/vpx/src/vpx_codec.c
+++ b/vpx/src/vpx_codec.c
@@ -14,6 +14,7 @@
*
*/
#include <stdarg.h>
+#include <stdlib.h>
#include "vpx/vpx_integer.h"
#include "vpx/internal/vpx_codec_internal.h"
#include "vpx_version.h"
@@ -133,3 +134,51 @@ vpx_codec_err_t vpx_codec_control_(vpx_codec_ctx_t *ctx,
return SAVE_STATUS(ctx, res);
}
+
+//------------------------------------------------------------------------------
+// mmap interface
+
+vpx_codec_err_t vpx_mmap_alloc(vpx_codec_mmap_t *mmap) {
+ unsigned int align = mmap->align ? mmap->align - 1 : 0;
+
+ if (mmap->flags & VPX_CODEC_MEM_ZERO)
+ mmap->priv = calloc(1, mmap->sz + align);
+ else
+ mmap->priv = malloc(mmap->sz + align);
+
+ if (mmap->priv == NULL) return VPX_CODEC_MEM_ERROR;
+ mmap->base = (void *)((((uintptr_t)mmap->priv) + align) & ~(uintptr_t)align);
+ mmap->dtor = vpx_mmap_dtor;
+ return VPX_CODEC_OK;
+}
+
+void vpx_mmap_dtor(vpx_codec_mmap_t *mmap) {
+ free(mmap->priv);
+}
+
+vpx_codec_err_t vpx_validate_mmaps(const vpx_codec_stream_info_t *si,
+ const vpx_codec_mmap_t *mmaps,
+ const mem_req_t *mem_reqs, int nreqs,
+ vpx_codec_flags_t init_flags) {
+ int i;
+
+ for (i = 0; i < nreqs - 1; ++i) {
+ /* Ensure the segment has been allocated */
+ if (mmaps[i].base == NULL) {
+ return VPX_CODEC_MEM_ERROR;
+ }
+
+ /* Verify variable size segment is big enough for the current si. */
+ if (mem_reqs[i].calc_sz != NULL) {
+ vpx_codec_dec_cfg_t cfg;
+
+ cfg.w = si->w;
+ cfg.h = si->h;
+
+ if (mmaps[i].sz < mem_reqs[i].calc_sz(&cfg, init_flags)) {
+ return VPX_CODEC_MEM_ERROR;
+ }
+ }
+ }
+ return VPX_CODEC_OK;
+}