Example #1
0
guint
flv_parse_tag (const guint8 * data, guint size,
    guint8 * packet_type, guint * payload_size, guint * timestamp)
{
  if (size < flv_tag_header_size)
    return 0;

  *packet_type = data[0];
  *payload_size = GST_READ_UINT24_BE (&data[1]);
  *timestamp = GST_READ_UINT24_BE (&data[4]) | (data[7] << 24);
  return flv_tag_header_size;
}
Example #2
0
static int
_parse_u24 (AmfParser * parser)
{
  int x;
  x = GST_READ_UINT24_BE (parser->data + parser->offset);
  parser->offset += 3;
  return x;
}
Example #3
0
EXPORT_C
#endif


gboolean
gst_byte_reader_peek_uint24_be (GstByteReader * reader, guint32 * val)
{
  g_return_val_if_fail (reader != NULL, FALSE);
  g_return_val_if_fail (val != NULL, FALSE);

  if (gst_byte_reader_get_remaining (reader) < 3)
    return FALSE;

  *val = GST_READ_UINT24_BE (&reader->data[reader->byte]);
  return TRUE;
}
static void
input_data_int24_max (const guint8 * _in, gfloat * out, guint len,
    guint channels, gfloat max_value, guint op, guint nfft)
{
  guint j;

  for (j = 0; j < len; j++) {
#if G_BYTE_ORDER == G_BIG_ENDIAN
    gint32 v = GST_READ_UINT24_BE (_in);
#else
    gint32 v = GST_READ_UINT24_LE (_in);
#endif
    if (v & 0x00800000)
      v |= 0xff000000;
    _in += 3 * channels;
    out[op] = v / max_value;
    op = (op + 1) % nfft;
  }
}
Example #5
0
static void
input_data_mixed_int24_max (const guint8 * _in, double* out, guint len,
    double max_value, guint op, guint nfft)
{
  guint j;

  for (j = 0; j < len; j++) {
#if G_BYTE_ORDER == G_BIG_ENDIAN
    gint32 value = GST_READ_UINT24_BE (_in);
#else
    gint32 value = GST_READ_UINT24_LE (_in);
#endif
    if (value & 0x00800000)
      value |= 0xff000000;

    out[op] = value / max_value;
    op = (op + 1) % nfft;
    _in += 3;
  }
}
static void
input_data_mixed_int24_max (const guint8 * _in, gfloat * out, guint len,
    guint channels, gfloat max_value, guint op, guint nfft)
{
  guint i, j;
  gfloat v = 0.0;

  for (j = 0; j < len; j++) {
    for (i = 0; i < channels; i++) {
#if G_BYTE_ORDER == G_BIG_ENDIAN
      gint32 value = GST_READ_UINT24_BE (_in);
#else
      gint32 value = GST_READ_UINT24_LE (_in);
#endif
      if (value & 0x00800000)
        value |= 0xff000000;
      v += value / max_value;
      _in += 3;
    }
    out[op] = v / channels;
    op = (op + 1) % nfft;
  }
}
Example #7
0
EXPORT_C
#endif


gboolean
gst_byte_reader_get_int24_be (GstByteReader * reader, gint32 * val)
{
  guint32 ret;

  g_return_val_if_fail (reader != NULL, FALSE);
  g_return_val_if_fail (val != NULL, FALSE);

  if (gst_byte_reader_get_remaining (reader) < 3)
    return FALSE;

  ret = GST_READ_UINT24_BE (&reader->data[reader->byte]);
  if (ret & 0x00800000)
    ret |= 0xff000000;

  reader->byte += 3;

  *val = ret;
  return TRUE;
}
Example #8
0
static int
parse_set_object_data (GstDVDSpu * dvdspu, guint8 type, guint8 * payload,
    guint16 len)
{
  SpuPgsState *pgs_state = &dvdspu->spu_state.pgs;
  PgsCompositionObject *obj;
  guint8 *end = payload + len;
  guint16 obj_id;
  guint8 obj_ver, flags;

  if (payload + 4 > end)
    return 0;

  obj_id = GST_READ_UINT16_BE (payload);
  obj_ver = payload[2];
  flags = payload[3];
  payload += 4;

  obj = pgs_presentation_segment_find_object (&(pgs_state->pres_seg), obj_id);

  PGS_DUMP ("Object ID %d ver %u flags 0x%02x\n", obj_id, obj_ver, flags);

  if (flags & PGS_OBJECT_UPDATE_FLAG_START_RLE) {
    obj->rle_data_ver = obj_ver;

    if (payload + 3 > end)
      return 0;

    obj->rle_data_size = GST_READ_UINT24_BE (payload);
    payload += 3;

    PGS_DUMP ("%d bytes of RLE data, of %d bytes total.\n",
        end - payload, obj->rle_data_size);

    obj->rle_data = g_realloc (obj->rle_data, obj->rle_data_size);
    obj->rle_data_used = end - payload;
    memcpy (obj->rle_data, payload, end - payload);
    payload = end;
  } else {
    PGS_DUMP ("%d bytes of additional RLE data\n", end - payload);
    /* Check that the data chunk is for this object version, and fits in the buffer */
    if (obj->rle_data_ver == obj_ver &&
        obj->rle_data_used + end - payload <= obj->rle_data_size) {

      memcpy (obj->rle_data + obj->rle_data_used, payload, end - payload);
      obj->rle_data_used += end - payload;
      payload = end;
    }
  }

  if (obj->rle_data_size == obj->rle_data_used)
    dump_rle_data (dvdspu, obj->rle_data, obj->rle_data_size);

  if (payload != end) {
    GST_ERROR ("PGS Set Object Data: %" G_GSSIZE_FORMAT " bytes not consumed",
        (gssize) (end - payload));
    dump_bytes (payload, end - payload);
  }

  return 0;
}
Example #9
0
static gboolean
read_one (GstPluginLoader * l)
{
  guint64 magic;
  guint32 to_read, packet_len, tag;
  guint8 *in;
  gint res;

  to_read = HEADER_SIZE;
  in = l->rx_buf;
  do {
    res = read (l->fd_r.fd, in, to_read);
    if (G_UNLIKELY (res < 0)) {
      if (errno == EAGAIN || errno == EINTR)
        continue;
      GST_LOG ("Failed reading packet header");
      return FALSE;
    }
    to_read -= res;
    in += res;
  } while (to_read > 0);

  magic = GST_READ_UINT32_BE (l->rx_buf + 8);
  if (magic != HEADER_MAGIC) {
    GST_WARNING
        ("Invalid packet (bad magic number) received from plugin scanner subprocess");
    return FALSE;
  }

  packet_len = GST_READ_UINT32_BE (l->rx_buf + 4);
  if (packet_len + HEADER_SIZE > BUF_MAX_SIZE) {
    GST_WARNING
        ("Received excessively large packet for plugin scanner subprocess");
    return FALSE;
  }
  tag = GST_READ_UINT24_BE (l->rx_buf + 1);

  if (packet_len > 0) {
    if (packet_len + HEADER_SIZE >= l->rx_buf_size) {
      GST_LOG ("Expanding rx buf from %d to %d",
          l->rx_buf_size, packet_len + HEADER_SIZE + BUF_GROW_EXTRA);
      l->rx_buf_size = packet_len + HEADER_SIZE + BUF_GROW_EXTRA;
      l->rx_buf = g_realloc (l->rx_buf, l->rx_buf_size);
    }

    in = l->rx_buf + HEADER_SIZE;
    to_read = packet_len;
    do {
      res = read (l->fd_r.fd, in, to_read);
      if (G_UNLIKELY (res < 0)) {
        if (errno == EAGAIN || errno == EINTR)
          continue;
        GST_ERROR ("Packet payload read failed");
        return FALSE;
      }
      to_read -= res;
      in += res;
    } while (to_read > 0);
  } else {
    GST_LOG ("No payload to read for 0 length packet type %d tag %u",
        l->rx_buf[0], tag);
  }

  return handle_rx_packet (l, l->rx_buf[0], tag,
      l->rx_buf + HEADER_SIZE, packet_len);
}
Example #10
0
static gboolean
verify_buffer (buffer_verify_data_s * vdata, GstBuffer * buffer)
{
  if (vdata->discard) {
    /* check separate header NALs */
    gint i = vdata->buffer_counter;
    guint ofs;

    /* SEI with start code prefix with 2 0-bytes */
    ofs = i == 1;

    fail_unless (i <= 2);
    fail_unless (gst_buffer_get_size (buffer) == ctx_headers[i].size - ofs);
    fail_unless (gst_buffer_memcmp (buffer, 0, ctx_headers[i].data + ofs,
            gst_buffer_get_size (buffer)) == 0);
  } else {
    GstMapInfo map;

    gst_buffer_map (buffer, &map, GST_MAP_READ);
    fail_unless (map.size > 4);
    /* only need to check avc and bs-to-nal output case */
    if (GST_READ_UINT24_BE (map.data) == 0x01) {
      /* in bs-to-nal, a leading 0x00 is stripped from output */
      fail_unless (gst_buffer_get_size (buffer) ==
          vdata->data_to_verify_size - 1);
      fail_unless (gst_buffer_memcmp (buffer, 0, vdata->data_to_verify + 1,
              vdata->data_to_verify_size - 1) == 0);
      gst_buffer_unmap (buffer, &map);
      return TRUE;
    } else if (GST_READ_UINT32_BE (map.data) == 0x01) {
      /* this is not avc, use default tests from parser.c */
      gst_buffer_unmap (buffer, &map);
      return FALSE;
    }
    /* header is merged in initial frame */
    if (vdata->buffer_counter == 0) {
      guint8 *data = map.data;

      fail_unless (map.size == vdata->data_to_verify_size +
          ctx_headers[0].size + ctx_headers[1].size + ctx_headers[2].size);
      fail_unless (GST_READ_UINT32_BE (data) == ctx_headers[0].size - 4);
      fail_unless (memcmp (data + 4, ctx_headers[0].data + 4,
              ctx_headers[0].size - 4) == 0);
      data += ctx_headers[0].size;
      fail_unless (GST_READ_UINT32_BE (data) == ctx_headers[1].size - 4);
      fail_unless (memcmp (data + 4, ctx_headers[1].data + 4,
              ctx_headers[1].size - 4) == 0);
      data += ctx_headers[1].size;
      fail_unless (GST_READ_UINT32_BE (data) == ctx_headers[2].size - 4);
      fail_unless (memcmp (data + 4, ctx_headers[2].data + 4,
              ctx_headers[2].size - 4) == 0);
      data += ctx_headers[2].size;
      fail_unless (GST_READ_UINT32_BE (data) == vdata->data_to_verify_size - 4);
      fail_unless (memcmp (data + 4, vdata->data_to_verify + 4,
              vdata->data_to_verify_size - 4) == 0);
    } else {
      fail_unless (GST_READ_UINT32_BE (map.data) == map.size - 4);
      fail_unless (map.size == vdata->data_to_verify_size);
      fail_unless (memcmp (map.data + 4, vdata->data_to_verify + 4,
              map.size - 4) == 0);
    }
    gst_buffer_unmap (buffer, &map);
    return TRUE;
  }

  return FALSE;
}