Esempio n. 1
0
static gboolean
gst_base_video_codec_src_convert (GstPad * pad,
    GstFormat src_format, gint64 src_value,
    GstFormat * dest_format, gint64 * dest_value)
{
  gboolean res;
  GstBaseVideoCodec *dec;

  if (src_format == *dest_format) {
    *dest_value = src_value;
    return TRUE;
  }

  dec = GST_BASE_VIDEO_CODEC (gst_pad_get_parent (pad));

  if (src_format == GST_FORMAT_DEFAULT && *dest_format == GST_FORMAT_TIME) {
    if (dec->fps_d != 0) {
      *dest_value = gst_util_uint64_scale (granulepos_to_frame (src_value),
          dec->fps_d * GST_SECOND, dec->fps_n);
      res = TRUE;
    } else {
      res = FALSE;
    }
  } else {
    GST_WARNING ("unhandled conversion from %d to %d", src_format,
        *dest_format);
    res = FALSE;
  }

  gst_object_unref (dec);

  return res;
}
Esempio n. 2
0
gboolean
gst_base_video_encoded_video_convert (GstVideoState * state,
    GstFormat src_format, gint64 src_value,
    GstFormat * dest_format, gint64 * dest_value)
{
  gboolean res = FALSE;

  if (src_format == *dest_format) {
    *dest_value = src_value;
    return TRUE;
  }

  GST_DEBUG ("src convert");

#if 0
  if (src_format == GST_FORMAT_DEFAULT && *dest_format == GST_FORMAT_TIME) {
    if (dec->fps_d != 0) {
      *dest_value = gst_util_uint64_scale (granulepos_to_frame (src_value),
          dec->fps_d * GST_SECOND, dec->fps_n);
      res = TRUE;
    } else {
      res = FALSE;
    }
  } else {
    GST_WARNING ("unhandled conversion from %d to %d", src_format,
        *dest_format);
    res = FALSE;
  }
#endif

  return res;
}
Esempio n. 3
0
static gboolean
gst_schro_dec_sink_convert (GstPad *pad,
    GstFormat src_format, gint64 src_value,
    GstFormat * dest_format, gint64 *dest_value)
{
  gboolean res = TRUE;
  GstSchroDec *dec;

  if (src_format == *dest_format) {
    *dest_value = src_value;
    return TRUE;
  }

  dec = GST_SCHRO_DEC (gst_pad_get_parent (pad));

  /* FIXME: check if we are in a decoding state */

  switch (src_format) {
    case GST_FORMAT_DEFAULT:
      switch (*dest_format) {
        case GST_FORMAT_TIME:
          if (dec->fps_d != 0) {
            *dest_value = gst_util_uint64_scale (granulepos_to_frame (src_value),
                dec->fps_d * GST_SECOND, dec->fps_n);
          } else {
            res = FALSE;
          }
          break;
        default:
          res = FALSE;
      }
      break;
    case GST_FORMAT_TIME:
      switch (*dest_format) {
        case GST_FORMAT_DEFAULT:
        {
          GST_ERROR("fps %d %d", dec->fps_n, dec->fps_d);
          if (dec->fps_d != 0) {
            *dest_value = gst_util_uint64_scale (src_value,
                dec->fps_n, dec->fps_d * GST_SECOND);
          } else {
            res = FALSE;
          }
          break;
        }
        default:
          res = FALSE;
          break;
      }
      break;
    default:
      res = FALSE;
      break;
  }

  gst_object_unref (dec);

  return res;
}
Esempio n. 4
0
static gboolean
gst_schro_dec_src_query (GstPad *pad, GstQuery *query)
{
  GstSchroDec *dec;
  gboolean res = FALSE;

  dec = GST_SCHRO_DEC (gst_pad_get_parent(pad));

  switch (GST_QUERY_TYPE (query)) {
    case GST_QUERY_POSITION:
    {
      GstFormat format;
      gint64 time;
      gint64 value;

      gst_query_parse_position (query, &format, NULL);

      time = gst_util_uint64_scale (granulepos_to_frame (dec->granulepos),
              dec->fps_n, dec->fps_d);
      //time -= dec->segment.start;
      time += dec->segment.time;
      GST_DEBUG("query position %lld", time);
      res = gst_schro_dec_src_convert (pad, GST_FORMAT_TIME, time,
          &format, &value);
      if (!res) goto error;

      gst_query_set_position (query, format, value);
      break;
    }
    case GST_QUERY_DURATION:
      res = gst_pad_query (GST_PAD_PEER (dec->sinkpad), query);
      if (!res) goto error;
      break;
    case GST_QUERY_CONVERT:
    {
      GstFormat src_fmt, dest_fmt;
      gint64 src_val, dest_val;

      gst_query_parse_convert (query, &src_fmt, &src_val, &dest_fmt, &dest_val);
      res = gst_schro_dec_src_convert (pad, src_fmt, src_val, &dest_fmt,
          &dest_val);
      if (!res) goto error;
      gst_query_set_convert (query, src_fmt, src_val, dest_fmt, dest_val);
      break;
    }
    default:
      res = gst_pad_query_default (pad, query);
      break;
  }
done:
  gst_object_unref (dec);

  return res;
error:
  GST_DEBUG_OBJECT (dec, "query failed");
  goto done;
}
Esempio n. 5
0
static void
handle_first_access_unit (GstSchroDec *schro_dec)
{
  SchroVideoFormat *format;
  GstCaps *caps;

  format = schro_decoder_get_video_format (schro_dec->decoder);
  schro_dec->width = format->width;
  schro_dec->height = format->height;
  switch(format->chroma_format) {
    case 0:
      schro_dec->fourcc = GST_MAKE_FOURCC('A','Y','U','V');
      break;
    case 1:
      schro_dec->fourcc = GST_MAKE_FOURCC('Y','U','Y','2');
      break;
    case 2:
      schro_dec->fourcc = GST_MAKE_FOURCC('I','4','2','0');
      break;
    default:
      g_assert_not_reached();
      break;
  }

  caps = gst_caps_new_simple ("video/x-raw-yuv",
      "format", GST_TYPE_FOURCC, schro_dec->fourcc,
      "width", G_TYPE_INT, format->width,
      "height", G_TYPE_INT, format->height,
      "framerate", GST_TYPE_FRACTION,
      format->frame_rate_numerator, format->frame_rate_denominator,
      "pixel-aspect-ratio", GST_TYPE_FRACTION,
      format->aspect_ratio_numerator, format->aspect_ratio_denominator,
      NULL);

  GST_DEBUG("setting caps %" GST_PTR_FORMAT, caps);

  gst_pad_set_caps (schro_dec->srcpad, caps);

  schro_dec->fps_n = format->frame_rate_numerator;
  schro_dec->fps_d = format->frame_rate_denominator;
  schro_dec->bytes_per_picture = (format->width * format->height * 3) / 4;

  if (!GST_CLOCK_TIME_IS_VALID(schro_dec->timestamp_offset)) {
    schro_dec->timestamp_offset = gst_util_uint64_scale (
        granulepos_to_frame (schro_dec->granulepos_offset),
        schro_dec->fps_d * GST_SECOND, schro_dec->fps_n);
  }

  gst_caps_unref (caps);
  free (format);

  gst_schrodec_send_tags (schro_dec);

  schro_dec->have_access_unit = TRUE;
}
Esempio n. 6
0
static gboolean
gst_base_video_decoder_src_convert (GstPad * pad,
    GstFormat src_format, gint64 src_value,
    GstFormat * dest_format, gint64 * dest_value)
{
  gboolean res = TRUE;
  GstBaseVideoDecoder *enc;

  if (src_format == *dest_format) {
    *dest_value = src_value;
    return TRUE;
  }

  enc = GST_BASE_VIDEO_DECODER (gst_pad_get_parent (pad));

  /* FIXME: check if we are in a encoding state */

  GST_DEBUG ("src convert");
  switch (src_format) {
#if 0
    case GST_FORMAT_DEFAULT:
      switch (*dest_format) {
        case GST_FORMAT_TIME:
          *dest_value = gst_util_uint64_scale (granulepos_to_frame (src_value),
              enc->fps_d * GST_SECOND, enc->fps_n);
          break;
        default:
          res = FALSE;
      }
      break;
    case GST_FORMAT_TIME:
      switch (*dest_format) {
        case GST_FORMAT_DEFAULT:
        {
          *dest_value = gst_util_uint64_scale (src_value,
              enc->fps_n, enc->fps_d * GST_SECOND);
          break;
        }
        default:
          res = FALSE;
          break;
      }
      break;
#endif
    default:
      res = FALSE;
      break;
  }

  gst_object_unref (enc);

  return res;
}