Exemplo n.º 1
0
static void
gst_logoinsert_set_data (GstLogoinsert * li, GstBuffer * buffer)
{
  if (li->buffer)
    gst_buffer_unref (li->buffer);

  /* steals the reference */
  li->buffer = buffer;

  if (li->overlay_frame) {
    cog_frame_unref (li->overlay_frame);
    li->overlay_frame = NULL;
  }
  if (li->alpha_frame) {
    cog_frame_unref (li->alpha_frame);
    li->alpha_frame = NULL;
  }
  if (li->argb_frame) {
    cog_frame_unref (li->argb_frame);
    li->argb_frame = NULL;
  }

  if (li->buffer) {
    li->argb_frame = cog_frame_new_from_png (GST_BUFFER_DATA (li->buffer),
        GST_BUFFER_SIZE (li->buffer));
  }
}
Exemplo n.º 2
0
void
gst_logoinsert_finalize (GObject * object)
{
  GstLogoinsert *logoinsert;

  g_return_if_fail (GST_IS_LOGOINSERT (object));
  logoinsert = GST_LOGOINSERT (object);

  g_free (logoinsert->location);
  if (logoinsert->buffer) {
    gst_buffer_unref (logoinsert->buffer);
  }
  if (logoinsert->overlay_frame) {
    cog_frame_unref (logoinsert->overlay_frame);
    logoinsert->overlay_frame = NULL;
  }
  if (logoinsert->alpha_frame) {
    cog_frame_unref (logoinsert->alpha_frame);
    logoinsert->alpha_frame = NULL;
  }
  if (logoinsert->argb_frame) {
    cog_frame_unref (logoinsert->argb_frame);
    logoinsert->argb_frame = NULL;
  }

  G_OBJECT_CLASS (parent_class)->finalize (object);
}
Exemplo n.º 3
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;
}
Exemplo n.º 4
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;
}
Exemplo n.º 5
0
static CogFrame *
cog_frame_realize (CogFrame * frame)
{
  CogFrame *dest;

  dest = cog_frame_clone (NULL, frame);
  cog_virt_frame_render (frame, dest);
  cog_frame_unref (frame);

  return dest;
}
Exemplo n.º 6
0
static GstFlowReturn
gst_cogdownsample_transform (GstBaseTransform * base_transform,
    GstBuffer * inbuf, GstBuffer * outbuf)
{
  GstCogdownsample *compress;
  CogFrame *outframe;
  int width, height;
  uint32_t format;
  CogFrame *frame;

  g_return_val_if_fail (GST_IS_COGDOWNSAMPLE (base_transform), GST_FLOW_ERROR);
  compress = GST_COGDOWNSAMPLE (base_transform);

  gst_structure_get_fourcc (gst_caps_get_structure (inbuf->caps, 0),
      "format", &format);
  gst_structure_get_int (gst_caps_get_structure (inbuf->caps, 0),
      "width", &width);
  gst_structure_get_int (gst_caps_get_structure (inbuf->caps, 0),
      "height", &height);

  switch (format) {
    case GST_MAKE_FOURCC ('I', '4', '2', '0'):
      frame = cog_frame_new_from_data_I420 (GST_BUFFER_DATA (inbuf),
          width, height);
      outframe = cog_frame_new_from_data_I420 (GST_BUFFER_DATA (outbuf),
          width / 2, height / 2);
      break;
    case GST_MAKE_FOURCC ('Y', 'V', '1', '2'):
      frame = cog_frame_new_from_data_YV12 (GST_BUFFER_DATA (inbuf),
          width, height);
      outframe = cog_frame_new_from_data_YV12 (GST_BUFFER_DATA (outbuf),
          width / 2, height / 2);
      break;
    case GST_MAKE_FOURCC ('Y', 'U', 'Y', '2'):
      frame = cog_frame_new_from_data_YUY2 (GST_BUFFER_DATA (inbuf),
          width, height);
      outframe = cog_frame_new_from_data_YUY2 (GST_BUFFER_DATA (outbuf),
          width / 2, height / 2);
      break;
    case GST_MAKE_FOURCC ('U', 'Y', 'V', 'Y'):
      frame = cog_frame_new_from_data_UYVY (GST_BUFFER_DATA (inbuf),
          width, height);
      outframe = cog_frame_new_from_data_UYVY (GST_BUFFER_DATA (outbuf),
          width / 2, height / 2);
      break;
    case GST_MAKE_FOURCC ('A', 'Y', 'U', 'V'):
      frame = cog_frame_new_from_data_AYUV (GST_BUFFER_DATA (inbuf),
          width, height);
      outframe = cog_frame_new_from_data_AYUV (GST_BUFFER_DATA (outbuf),
          width / 2, height / 2);
      break;
    default:
      g_assert_not_reached ();
  }

  frame = cog_virt_frame_new_unpack (frame);
  frame = cog_virt_frame_new_horiz_downsample (frame, 3);
  frame = cog_virt_frame_new_vert_downsample (frame, 2);

  switch (format) {
    case GST_MAKE_FOURCC ('Y', 'U', 'Y', '2'):
      frame = cog_virt_frame_new_pack_YUY2 (frame);
      break;
    case GST_MAKE_FOURCC ('U', 'Y', 'V', 'Y'):
      frame = cog_virt_frame_new_pack_UYVY (frame);
      break;
    case GST_MAKE_FOURCC ('A', 'Y', 'U', 'V'):
      frame = cog_virt_frame_new_pack_AYUV (frame);
      break;
    default:
      break;
  }

  cog_virt_frame_render (frame, outframe);
  cog_frame_unref (frame);
  cog_frame_unref (outframe);

  return GST_FLOW_OK;
}
Exemplo n.º 7
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;
}