Example #1
0
static int read_frame(struct AvxDecInputContext *input, uint8_t **buf,
                      size_t *bytes_in_buffer, size_t *buffer_size) {
  switch (input->aom_input_ctx->file_type) {
#if CONFIG_WEBM_IO
    case FILE_TYPE_WEBM:
      return webm_read_frame(input->webm_ctx, buf, bytes_in_buffer);
#endif
    case FILE_TYPE_RAW:
      return raw_read_frame(input->aom_input_ctx->file, buf, bytes_in_buffer,
                            buffer_size);
    case FILE_TYPE_IVF:
      return ivf_read_frame(input->aom_input_ctx->file, buf, bytes_in_buffer,
                            buffer_size);
    default: return 1;
  }
}
Example #2
0
      Dynamic read_frame(struct DecInputContext *input) {

        vpx_codec_iter_t iter = NULL;
        vpx_image_t *img;

        uint8_t *buf = NULL;
        size_t bytes_in_buffer = 0;
        size_t buffer_size = 0;
        int status = webm_read_frame(input->webm_ctx, &buf, &bytes_in_buffer, &buffer_size);
        if(status == 0) {
          if(vpx_codec_decode(input->decoder, buf, (unsigned int)bytes_in_buffer, NULL, 0)) {
            warn("Failed to decode frame: %s", vpx_codec_error(input->decoder));
          }
        } else {
          warn("EOF/Error %d", status);
        }

        if(status == 0) {
          img = vpx_codec_get_frame(input->decoder, &iter);
        } else {
          img = NULL;
        }

        /*
        {
          status:Int, (0 = success, 1 = EOF, -1 = Error)
          data:BytesData, // image bytes
          width:Int,
          height:Int,
          comp:Int, // RGBA = 4
        }
        */
        int width = 0;
        int height = 0;
        int comp = 4;
        unsigned char* rgba;


        hx::Anon result = hx::Anon_obj::Create();
        result->Add(HX_CSTRING("status"), status);

        if(img != NULL) {
          width = img->d_w;
          height = img->d_h;
          rgba = (unsigned char*)malloc(sizeof(unsigned char) * width * height * comp);
          if(img->fmt == VPX_IMG_FMT_I420) {
            ::libyuv::I420ToABGR(
              img->planes[VPX_PLANE_Y],img->stride[VPX_PLANE_Y],
              img->planes[VPX_PLANE_U],img->stride[VPX_PLANE_U],
              img->planes[VPX_PLANE_V],img->stride[VPX_PLANE_V],
              rgba, width * comp, width, height
            );

            ImgBytesData data = to_haxe_bytes(rgba, width * height * comp);
            result->Add(HX_CSTRING("data"), data);

          } else {
            warn("Img format unknown");
          }
        } else {
          warn("No image decoded!");
        }

        result->Add(HX_CSTRING("width"), width);
        result->Add(HX_CSTRING("height"), height);
        result->Add(HX_CSTRING("comp"), comp);


        return result;

      }