Beispiel #1
0
static GstFlowReturn
gst_mse_chain_test (GstPad * pad, GstBuffer * buffer)
{
  GstMSE *fs;
  GstFlowReturn ret;
  GstBuffer *buffer_ref;

  fs = GST_MSE (gst_pad_get_parent (pad));

  GST_DEBUG_OBJECT (fs, "chain test");

  g_mutex_lock (fs->lock);
  while (fs->buffer_ref == NULL) {
    GST_DEBUG_OBJECT (fs, "waiting for ref buffer");
    g_cond_wait (fs->cond, fs->lock);
    if (fs->cancel) {
      g_mutex_unlock (fs->lock);
      gst_object_unref (fs);
      return GST_FLOW_WRONG_STATE;
    }
  }

  buffer_ref = fs->buffer_ref;
  fs->buffer_ref = NULL;
  g_cond_signal (fs->cond);

  g_mutex_unlock (fs->lock);

  if (1) {
    CogFrame *frame_ref;
    CogFrame *frame_test;
    double mse[3];

    frame_ref = gst_cog_buffer_wrap (gst_buffer_ref (buffer_ref), fs->format,
        fs->width, fs->height);
    frame_test = gst_cog_buffer_wrap (gst_buffer_ref (buffer), fs->format,
        fs->width, fs->height);

    cog_frame_mse (frame_ref, frame_test, mse);

    GST_INFO ("mse %g %g %g", mse_to_db (mse[0], FALSE),
        mse_to_db (mse[1], TRUE), mse_to_db (mse[2], TRUE));

    fs->luma_mse_sum += mse[0];
    fs->chroma_mse_sum += 0.5 * (mse[1] + mse[2]);
    fs->n_frames++;

    cog_frame_unref (frame_ref);
    cog_frame_unref (frame_test);
  }


  ret = gst_pad_push (fs->srcpad, buffer);
  gst_buffer_unref (buffer_ref);

  gst_object_unref (fs);

  return ret;
}
Beispiel #2
0
static GstFlowReturn
gst_colorconvert_transform_ip (GstBaseTransform * base_transform,
    GstBuffer * buf)
{
  GstColorconvert *li;
  CogFrame *frame;
  CogFrame *vf;

  g_return_val_if_fail (GST_IS_COLORCONVERT (base_transform), GST_FLOW_ERROR);
  li = GST_COLORCONVERT (base_transform);

  frame = gst_cog_buffer_wrap (gst_buffer_ref (buf),
      li->format, li->width, li->height);

  vf = cog_virt_frame_new_unpack (cog_frame_ref (frame));
  vf = cog_virt_frame_new_subsample (vf, COG_FRAME_FORMAT_U8_444,
      COG_CHROMA_SITE_MPEG2, 2);
  vf = cog_virt_frame_new_color_transform (vf);
  if (frame->format == COG_FRAME_FORMAT_YUYV) {
    vf = cog_virt_frame_new_subsample (vf, COG_FRAME_FORMAT_U8_422,
        COG_CHROMA_SITE_MPEG2, 2);
    vf = cog_virt_frame_new_pack_YUY2 (vf);
  } else if (frame->format == COG_FRAME_FORMAT_UYVY) {
    vf = cog_virt_frame_new_subsample (vf, COG_FRAME_FORMAT_U8_422,
        COG_CHROMA_SITE_MPEG2, 2);
    vf = cog_virt_frame_new_pack_UYVY (vf);
  } else if (frame->format == COG_FRAME_FORMAT_AYUV) {
    vf = cog_virt_frame_new_pack_AYUV (vf);
  } else if (frame->format == COG_FRAME_FORMAT_U8_420) {
    vf = cog_virt_frame_new_subsample (vf, COG_FRAME_FORMAT_U8_420,
        COG_CHROMA_SITE_MPEG2, 2);
  } else {
    g_assert_not_reached ();
  }

  cog_virt_frame_render (vf, frame);

  cog_frame_unref (frame);
  cog_frame_unref (vf);

  return GST_FLOW_OK;
}
Beispiel #3
0
static GstFlowReturn
gst_logoinsert_transform_ip (GstBaseTransform * base_transform, GstBuffer * buf)
{
  GstLogoinsert *li;
  CogFrame *frame;

  g_return_val_if_fail (GST_IS_LOGOINSERT (base_transform), GST_FLOW_ERROR);
  li = GST_LOGOINSERT (base_transform);

  if (li->argb_frame == NULL)
    return GST_FLOW_OK;

  frame = gst_cog_buffer_wrap (gst_buffer_ref (buf),
      li->format, li->width, li->height);

  if (li->overlay_frame == NULL) {
    CogFrame *f;

    f = cog_virt_frame_extract_alpha (cog_frame_ref (li->argb_frame));
    f = cog_virt_frame_new_subsample (f, frame->format,
        COG_CHROMA_SITE_MPEG2, 2);
    li->alpha_frame = cog_frame_realize (f);

    f = cog_virt_frame_new_unpack (cog_frame_ref (li->argb_frame));
    f = cog_virt_frame_new_color_matrix_RGB_to_YCbCr (f, COG_COLOR_MATRIX_SDTV,
        8);
    f = cog_virt_frame_new_subsample (f, frame->format,
        COG_CHROMA_SITE_MPEG2, 2);
    li->overlay_frame = cog_frame_realize (f);
  }

  if (1) {
    int i, j;
    int k;
    guint8 *dest;
    guint8 *src;
    guint8 *alpha;
    int offset_x, offset_y;

    for (k = 0; k < 3; k++) {
      offset_x = frame->components[k].width -
          li->alpha_frame->components[k].width;
      offset_y = frame->components[k].height -
          li->alpha_frame->components[k].height;

      for (j = 0; j < li->overlay_frame->components[k].height; j++) {
        dest = COG_FRAME_DATA_GET_LINE (frame->components + k, j + offset_y);
        src = COG_FRAME_DATA_GET_LINE (li->overlay_frame->components + k, j);
        alpha = COG_FRAME_DATA_GET_LINE (li->alpha_frame->components + k, j);

#define oil_divide_255(x) ((((x)+128) + (((x)+128)>>8))>>8)

        for (i = 0; i < li->overlay_frame->components[k].width; i++) {
          dest[i + offset_x] =
              oil_divide_255 (src[i] * alpha[i] + dest[i + offset_x] * (255 -
                  alpha[i]));
        }
      }
    }
  }

  cog_frame_unref (frame);

  return GST_FLOW_OK;
}