diff options
author | Dmitry Kovalev <dkovalev@google.com> | 2014-01-27 13:40:29 -0800 |
---|---|---|
committer | Dmitry Kovalev <dkovalev@google.com> | 2014-01-27 13:40:29 -0800 |
commit | 7ec2769687194982e0e95523665e447f277814b9 (patch) | |
tree | 0f65c0e323da24c7e807b58ee26138ceb7b20d24 /tools_common.c | |
parent | 442ff059c30d86d9dc47fd98f1a3d6cb9bacbe20 (diff) | |
download | libvpx-7ec2769687194982e0e95523665e447f277814b9.tar.gz |
Adapting simple_decoder to use new file reading API.
Change-Id: I374a0c4bb4a66c0d3dc874c6e57fdee9d1ab72df
Diffstat (limited to 'tools_common.c')
-rw-r--r-- | tools_common.c | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/tools_common.c b/tools_common.c index 9c24983de..85bedc99d 100644 --- a/tools_common.c +++ b/tools_common.c @@ -15,6 +15,10 @@ #include <stdlib.h> #include <string.h> +#if CONFIG_VP8_DECODER || CONFIG_VP9_DECODER +#include "vpx/vp8dx.h" +#endif + #if defined(_WIN32) || defined(__OS2__) #include <io.h> #include <fcntl.h> @@ -60,6 +64,15 @@ void warn(const char *fmt, ...) { LOG_ERROR("Warning"); } +void die_codec(vpx_codec_ctx_t *ctx, const char *s) { + const char *detail = vpx_codec_error_detail(ctx); + + printf("%s: %s\n", s, vpx_codec_error(ctx)); + if (detail) + printf(" %s\n", detail); + exit(EXIT_FAILURE); +} + uint16_t mem_get_le16(const void *data) { uint16_t val; const uint8_t *mem = (const uint8_t*)data; @@ -130,3 +143,34 @@ int read_yuv_frame(struct VpxInputContext *input_ctx, vpx_image_t *yuv_frame) { return shortread; } + +vpx_codec_iface_t *get_codec_interface(unsigned int fourcc) { + switch (fourcc) { +#if CONFIG_VP8_DECODER + case VP8_FOURCC: + return vpx_codec_vp8_dx(); +#endif +#if CONFIG_VP9_DECODER + case VP9_FOURCC: + return vpx_codec_vp9_dx(); +#endif + default: + return NULL; + } + return NULL; +} + +void vpx_img_write(const vpx_image_t *img, FILE *file) { + int plane, y; + + for (plane = 0; plane < 3; ++plane) { + const unsigned char *buf = img->planes[plane]; + const int stride = img->stride[plane]; + const int w = plane ? (img->d_w + 1) >> 1 : img->d_w; + const int h = plane ? (img->d_h + 1) >> 1 : img->d_h; + for (y = 0; y < h; ++y) { + fwrite(buf, 1, w, file); + buf += stride; + } + } +} |