diff options
author | Uros Majstorovic <majstor@majstor.org> | 2017-09-09 15:36:21 +0200 |
---|---|---|
committer | Uros Majstorovic <majstor@majstor.org> | 2017-09-09 15:36:21 +0200 |
commit | d40fd9b1adab64182ce8af0b8e19cfc8a93171d7 (patch) | |
tree | 0cb83df16cb6f0625aa7ab60fe96f47be2cb75ab /code/test/vid/tools.c | |
parent | 55364a819692d63080d23e6dc30daf38f02f5524 (diff) |
video streaming test updated; not tested
Diffstat (limited to 'code/test/vid/tools.c')
-rw-r--r-- | code/test/vid/tools.c | 145 |
1 files changed, 127 insertions, 18 deletions
diff --git a/code/test/vid/tools.c b/code/test/vid/tools.c index 6122209..3331670 100644 --- a/code/test/vid/tools.c +++ b/code/test/vid/tools.c @@ -27,28 +27,137 @@ const VpxInterface *get_vpx_encoder_by_name(const char *name) { return NULL; } -#define LOG_ERROR(label) \ - do { \ - const char *l = label; \ - va_list ap; \ - va_start(ap, fmt); \ - if (l) fprintf(stderr, "%s: ", l); \ - vfprintf(stderr, fmt, ap); \ - fprintf(stderr, "\n"); \ - va_end(ap); \ - } while (0) - -void die(const char *fmt, ...) { - LOG_ERROR(NULL); - usage_exit(); +static const VpxInterface vpx_decoders[] = { + { "vp8", VP8_FOURCC, &vpx_codec_vp8_dx }, + { "vp9", VP9_FOURCC, &vpx_codec_vp9_dx }, +}; + +int get_vpx_decoder_count(void) { + return sizeof(vpx_decoders) / sizeof(vpx_decoders[0]); +} + +const VpxInterface *get_vpx_decoder_by_index(int i) { return &vpx_decoders[i]; } + +const VpxInterface *get_vpx_decoder_by_name(const char *name) { + int i; + + for (i = 0; i < get_vpx_decoder_count(); ++i) { + const VpxInterface *const decoder = get_vpx_decoder_by_index(i); + if (strcmp(decoder->name, name) == 0) return decoder; + } + + return NULL; } void die_codec(vpx_codec_ctx_t *ctx, const char *s) { - const char *detail = vpx_codec_error_detail(ctx); + if (ctx) { + const char *detail = vpx_codec_error_detail(ctx); - printf("%s: %s\n", s, vpx_codec_error(ctx)); - if (detail) printf(" %s\n", detail); + fprintf(stderr, "%s: %s\n", s, vpx_codec_error(ctx)); + if (detail) fprintf(stderr, " %s\n", detail); + } else { + fprintf(stderr, "%s", s); + } exit(EXIT_FAILURE); } -
\ No newline at end of file +// TODO(dkovalev): move this function to vpx_image.{c, h}, so it will be part +// of vpx_image_t support +int vpx_img_plane_width(const vpx_image_t *img, int plane) { + if (plane > 0 && img->x_chroma_shift > 0) + return (img->d_w + 1) >> img->x_chroma_shift; + else + return img->d_w; +} + +int vpx_img_plane_height(const vpx_image_t *img, int plane) { + if (plane > 0 && img->y_chroma_shift > 0) + return (img->d_h + 1) >> img->y_chroma_shift; + else + return img->d_h; +} + +int vpx_img_read(vpx_image_t *img, void *img_buf, int sz) { + int plane; + int off = 0; + + for (plane = 0; plane < 3; ++plane) { + unsigned char *buf = img->planes[plane]; + const int stride = img->stride[plane]; + const int w = vpx_img_plane_width(img, plane) * + ((img->fmt & VPX_IMG_FMT_HIGHBITDEPTH) ? 2 : 1); + const int h = vpx_img_plane_height(img, plane); + int y; + + for (y = 0; y < h; ++y) { + if (off + w > sz) return 0; + memcpy(buf, img_buf + off, w); + off += w; + buf += stride; + } + } + + return 1; +} + +int vpx_img_write(const vpx_image_t *img, void *img_buf, int sz) { + int plane; + int off = 0; + + for (plane = 0; plane < 3; ++plane) { + const unsigned char *buf = img->planes[plane]; + const int stride = img->stride[plane]; + const int w = vpx_img_plane_width(img, plane) * + ((img->fmt & VPX_IMG_FMT_HIGHBITDEPTH) ? 2 : 1); + const int h = vpx_img_plane_height(img, plane); + int y; + + for (y = 0; y < h; ++y) { + if (off + w > sz) return 0; + memcpy(img_buf + off, buf, w); + off += w; + buf += stride; + } + } + + return 1; +} + +int vpx_img_read_f(vpx_image_t *img, FILE *file) { + int plane; + + for (plane = 0; plane < 3; ++plane) { + unsigned char *buf = img->planes[plane]; + const int stride = img->stride[plane]; + const int w = vpx_img_plane_width(img, plane) * + ((img->fmt & VPX_IMG_FMT_HIGHBITDEPTH) ? 2 : 1); + const int h = vpx_img_plane_height(img, plane); + int y; + + for (y = 0; y < h; ++y) { + if (fread(buf, 1, w, file) != (size_t)w) return 0; + buf += stride; + } + } + + return 1; +} + +int vpx_img_write_f(const vpx_image_t *img, FILE *file) { + int plane; + + for (plane = 0; plane < 3; ++plane) { + const unsigned char *buf = img->planes[plane]; + const int stride = img->stride[plane]; + const int w = vpx_img_plane_width(img, plane) * + ((img->fmt & VPX_IMG_FMT_HIGHBITDEPTH) ? 2 : 1); + const int h = vpx_img_plane_height(img, plane); + int y; + + for (y = 0; y < h; ++y) { + if (fwrite(buf, 1, w, file) != (size_t)w) return 0; + buf += stride; + } + } +} + |