コード例 #1
0
ファイル: gstkateenc.c プロジェクト: 0p1pp1/gst-plugins-bad
static GstFlowReturn
gst_kate_enc_chain_text (GstKateEnc * ke, GstBuffer * buf)
{
  kate_packet kp = { 0 };
  int ret = 0;
  GstFlowReturn rflow;
  GstClockTime start = GST_BUFFER_TIMESTAMP (buf);
  GstClockTime stop = GST_BUFFER_TIMESTAMP (buf) + GST_BUFFER_DURATION (buf);

  if (ke->format == GST_KATE_FORMAT_TEXT_PANGO_MARKUP) {
    ret = kate_encode_set_markup_type (&ke->k, kate_markup_simple);
  } else if (ke->format == GST_KATE_FORMAT_TEXT_UTF8) {
    ret = kate_encode_set_markup_type (&ke->k, kate_markup_none);
  } else {
    return GST_FLOW_ERROR;
  }

  if (G_UNLIKELY (ret < 0)) {
    GST_ELEMENT_ERROR (ke, STREAM, ENCODE, (NULL),
        ("Failed to set markup type: %s",
            gst_kate_util_get_error_message (ret)));
    rflow = GST_FLOW_ERROR;
  } else {
    GstMapInfo info;
    gboolean need_unmap = TRUE;
    kate_float t0 = start / (double) GST_SECOND;
    kate_float t1 = stop / (double) GST_SECOND;

    if (!gst_buffer_map (buf, &info, GST_MAP_READ)) {
      info.data = NULL;
      info.size = 0;
      need_unmap = FALSE;
      GST_WARNING_OBJECT (buf, "Failed to map buffer");
    }

    GST_LOG_OBJECT (ke, "Encoding text: %*.*s (%u bytes) from %f to %f",
        (int) info.size, (int) info.size, info.data, (int) info.size, t0, t1);
    ret = kate_encode_text (&ke->k, t0, t1, (const char *) info.data, info.size,
        &kp);
    if (G_UNLIKELY (ret < 0)) {
      GST_ELEMENT_ERROR (ke, STREAM, ENCODE, (NULL),
          ("Failed to encode text: %s", gst_kate_util_get_error_message (ret)));
      rflow = GST_FLOW_ERROR;
    } else {
      rflow = gst_kate_enc_chain_push_packet (ke, &kp, start, stop - start + 1);
    }
    if (need_unmap)
      gst_buffer_unmap (buf, &info);
  }

  return rflow;
}
コード例 #2
0
ファイル: gstkateenc.c プロジェクト: jonasl/gst-svtplayer
static GstFlowReturn
gst_kate_enc_chain_text (GstKateEnc * ke, GstBuffer * buf,
    const char *mime_type)
{
  kate_packet kp;
  int ret = 0;
  GstFlowReturn rflow;
  GstClockTime start = GST_BUFFER_TIMESTAMP (buf);
  GstClockTime stop = GST_BUFFER_TIMESTAMP (buf) + GST_BUFFER_DURATION (buf);

  if (!strcmp (mime_type, "text/x-pango-markup")) {
    ret = kate_encode_set_markup_type (&ke->k, kate_markup_simple);
  } else {
    ret = kate_encode_set_markup_type (&ke->k, kate_markup_none);
  }

  if (G_UNLIKELY (ret < 0)) {
    GST_ELEMENT_ERROR (ke, STREAM, ENCODE, (NULL),
        ("kate_encode_set_markup_type: %d", ret));
    rflow = GST_FLOW_ERROR;
  } else {
    const char *text = (const char *) GST_BUFFER_DATA (buf);
    if (text) {
      size_t text_len = GST_BUFFER_SIZE (buf);
      kate_float t0 = start / (double) GST_SECOND;
      kate_float t1 = stop / (double) GST_SECOND;
      GST_LOG_OBJECT (ke, "Encoding text: %*.*s (%u bytes) from %f to %f",
          (int) text_len, (int) text_len, GST_BUFFER_DATA (buf),
          GST_BUFFER_SIZE (buf), t0, t1);
      ret = kate_encode_text (&ke->k, t0, t1, text, text_len, &kp);
      if (G_UNLIKELY (ret < 0)) {
        GST_ELEMENT_ERROR (ke, STREAM, ENCODE, (NULL),
            ("Failed to encode text: %d", ret));
        rflow = GST_FLOW_ERROR;
      } else {
        rflow =
            gst_kate_enc_chain_push_packet (ke, &kp, start, stop - start + 1);
      }
    } else {
      /* FIXME: this should not be an error, we should ignore it and move on */
      GST_ELEMENT_ERROR (ke, STREAM, ENCODE, (NULL),
          ("no text in text packet"));
      rflow = GST_FLOW_ERROR;
    }
  }

  return rflow;
}