ImageDescription *
image_description_from_codec_data (GstBuffer * buf, guint32 codectype)
{
  ImageDescription *desc = NULL;

  GST_LOG ("codectype:%" GST_FOURCC_FORMAT " buf:%p",
      GST_FOURCC_ARGS (codectype), buf);

  if ((GST_BUFFER_SIZE (buf) == GST_READ_UINT32_BE (GST_BUFFER_DATA (buf))) &&
      (QT_MAKE_FOURCC_LE ('s', 't', 's',
              'd') == GST_READ_UINT32_BE (GST_BUFFER_DATA (buf) + 4))) {
    /* We have the full stsd (ImageDescription) in our codec_data */
    desc = image_description_from_stsd_buffer (buf);
  } else {
    switch (codectype) {
      case QT_MAKE_FOURCC_LE ('m', 'p', '4', 'v'):
        desc = image_description_for_mp4v (buf);
        break;
      case QT_MAKE_FOURCC_LE ('a', 'v', 'c', '1'):
        desc = image_description_for_avc1 (buf);
        break;
      default:
        GST_WARNING ("Format not handled !");
    }
  }
  return desc;
}
static gboolean
write_one (GstPluginLoader * l)
{
  guint8 *out;
  guint32 to_write, magic;
  int res;

  if (l->tx_buf_read + HEADER_SIZE > l->tx_buf_write)
    return FALSE;

  out = l->tx_buf + l->tx_buf_read;

  magic = GST_READ_UINT32_BE (out + 8);
  if (magic != HEADER_MAGIC) {
    GST_ERROR ("Packet magic number is missing. Memory corruption detected");
    goto fail_and_cleanup;
  }

  to_write = GST_READ_UINT32_BE (out + 4) + HEADER_SIZE;
  /* Check that the magic is intact, and the size is sensible */
  if (to_write > l->tx_buf_size) {
    GST_ERROR ("Indicated packet size is too large. Corruption detected");
    goto fail_and_cleanup;
  }

  l->tx_buf_read += to_write;

  GST_LOG ("Writing packet of size %d bytes to fd %d", to_write, l->fd_w.fd);

  do {
    res = write (l->fd_w.fd, out, to_write);
    if (G_UNLIKELY (res < 0)) {
      if (errno == EAGAIN || errno == EINTR)
        continue;
      /* Failed to write -> child died */
      goto fail_and_cleanup;
    }
    to_write -= res;
    out += res;
  } while (to_write > 0);

  if (l->tx_buf_read == l->tx_buf_write) {
    gst_poll_fd_ctl_write (l->fdset, &l->fd_w, FALSE);
    l->tx_buf_read = l->tx_buf_write = 0;
  }

  return TRUE;

fail_and_cleanup:
  plugin_loader_cleanup_child (l);
  return FALSE;
}
static GstBuffer *
create_overlay_buffer (void)
{
  GZlibDecompressor *decompress;
  GConverterResult decomp_res;
  guchar *gzipped_pixdata, *pixdata;
  gsize gzipped_size, bytes_read, pixdata_size;
  GstBuffer *logo_pixels;
  guint w, h, stride;

  gzipped_pixdata = g_base64_decode (gzipped_pixdata_base64, &gzipped_size);
  g_assert (gzipped_pixdata != NULL);

  pixdata = g_malloc (64 * 1024);

  decompress = g_zlib_decompressor_new (G_ZLIB_COMPRESSOR_FORMAT_GZIP);
  decomp_res = g_converter_convert (G_CONVERTER (decompress),
      gzipped_pixdata, gzipped_size, pixdata, 64 * 1024,
      G_CONVERTER_INPUT_AT_END, &bytes_read, &pixdata_size, NULL);
  g_assert (decomp_res == G_CONVERTER_FINISHED);
  g_assert (bytes_read == gzipped_size);
  g_free (gzipped_pixdata);
  g_object_unref (decompress);

  /* 0: Pixbuf magic (0x47646b50) */
  g_assert (GST_READ_UINT32_BE (pixdata) == 0x47646b50);

  /* 4: length incl. header */
  /* 8: pixdata_type */
  /* 12: rowstride (900) */
  stride = GST_READ_UINT32_BE (pixdata + 12);
  /* 16: width (225) */
  w = GST_READ_UINT32_BE (pixdata + 16);
  /* 20: height (57) */
  h = GST_READ_UINT32_BE (pixdata + 20);
  /* 24: pixel_data */
  GST_LOG ("%dx%d @ %d", w, h, stride);
  /* we assume that the last line also has padding at the end */
  g_assert (pixdata_size - 24 >= h * stride);

  logo_pixels = gst_buffer_new_and_alloc (h * stride);
  gst_buffer_fill (logo_pixels, 0, pixdata + 24, h * stride);
  gst_buffer_add_video_meta (logo_pixels, GST_VIDEO_FRAME_FLAG_NONE,
      GST_VIDEO_OVERLAY_COMPOSITION_FORMAT_RGB, w, h);

  g_free (pixdata);

  return logo_pixels;
}
static ImageDescription *
image_description_from_stsd_buffer (GstBuffer * buf)
{
  ImageDescription *desc = NULL;
  guint8 *content;
  guint size;
  gint imds;

  GST_LOG ("buffer %p, size:%u", buf, GST_BUFFER_SIZE (buf));

  /* The buffer contains a full atom, we only need the contents */
  /* This buffer has data in big-endian, we need to read it as such.
   * except for the fourcc which are ALWAYS big-endian. */
  content = GST_BUFFER_DATA (buf) + 16;
  size = GST_BUFFER_SIZE (buf) - 16;

#if DEBUG_DUMP
  GST_LOG ("incoming data in big-endian");
  gst_util_dump_mem (content, size);
#endif

  desc = g_malloc0 (size);
  desc->idSize = size;
  desc->cType = GST_READ_UINT32_BE (content + 4);
  desc->version = QT_UINT16 (content + 16);
  desc->revisionLevel = QT_UINT16 (content + 18);
  desc->vendor = GST_READ_UINT32_BE (content + 20);
  desc->temporalQuality = QT_UINT32 (content + 24);
  desc->spatialQuality = QT_UINT32 (content + 24);
  desc->dataSize = QT_UINT32 (content + 44);
  desc->frameCount = QT_UINT16 (content + 48);
  desc->depth = QT_UINT16 (content + 82);
  desc->clutID = QT_UINT16 (content + 84);

  imds = 86;                    /* sizeof (ImageDescription); */

  if (desc->idSize > imds) {
    GST_LOG ("Copying %d bytes from %p to %p",
        size - imds, content + imds, desc + imds);
    memcpy ((guint8 *) desc + imds, (guint8 *) content + imds, size - imds);
  }
#if DEBUG_DUMP
  GST_LOG ("outgoing data in machine-endian");
  dump_image_description (desc);
#endif

  return desc;
}
static gboolean
moov_recov_parse_tkhd (MoovRecovFile * moovrf, TrakRecovData * trakrd)
{
  guint32 size;
  guint32 fourcc;
  guint8 data[4];

  /* make sure we are on a tkhd atom */
  if (!read_atom_header (moovrf->file, &fourcc, &size))
    return FALSE;
  if (fourcc != FOURCC_tkhd)
    return FALSE;

  trakrd->tkhd_file_offset = ftell (moovrf->file) - 8;

  /* move 8 bytes forward to the trak_id pos */
  if (fseek (moovrf->file, 12, SEEK_CUR) != 0)
    return FALSE;
  if (fread (data, 1, 4, moovrf->file) != 4)
    return FALSE;

  /* advance the rest of tkhd */
  fseek (moovrf->file, 68, SEEK_CUR);

  trakrd->trak_id = GST_READ_UINT32_BE (data);
  return TRUE;
}
static gboolean
moov_recov_parse_mdhd (MoovRecovFile * moovrf, TrakRecovData * trakrd)
{
  guint32 size;
  guint32 fourcc;
  guint8 data[4];

  /* make sure we are on a tkhd atom */
  if (!read_atom_header (moovrf->file, &fourcc, &size))
    return FALSE;
  if (fourcc != FOURCC_mdhd)
    return FALSE;

  trakrd->mdhd_file_offset = ftell (moovrf->file) - 8;

  /* get the timescale */
  if (fseek (moovrf->file, 12, SEEK_CUR) != 0)
    return FALSE;
  if (fread (data, 1, 4, moovrf->file) != 4)
    return FALSE;
  trakrd->timescale = GST_READ_UINT32_BE (data);
  if (fseek (moovrf->file, 8, SEEK_CUR) != 0)
    return FALSE;
  return TRUE;
}
Exemple #7
0
static gboolean
parse_exif_tag_header (GstByteReader * reader, gint byte_order,
    GstExifTagData * _tagdata)
{
  g_assert (_tagdata);

  /* read the fields */
  if (byte_order == G_LITTLE_ENDIAN) {
    if (!gst_byte_reader_get_uint16_le (reader, &_tagdata->tag) ||
        !gst_byte_reader_get_uint16_le (reader, &_tagdata->tag_type) ||
        !gst_byte_reader_get_uint32_le (reader, &_tagdata->count) ||
        !gst_byte_reader_get_data (reader, 4, &_tagdata->offset_as_data)) {
      return FALSE;
    }
    _tagdata->offset = GST_READ_UINT32_LE (_tagdata->offset_as_data);
  } else {
    if (!gst_byte_reader_get_uint16_be (reader, &_tagdata->tag) ||
        !gst_byte_reader_get_uint16_be (reader, &_tagdata->tag_type) ||
        !gst_byte_reader_get_uint32_be (reader, &_tagdata->count) ||
        !gst_byte_reader_get_data (reader, 4, &_tagdata->offset_as_data)) {
      return FALSE;
    }
    _tagdata->offset = GST_READ_UINT32_BE (_tagdata->offset_as_data);
  }

  return TRUE;
}
Exemple #8
0
static gboolean
verify_buffer_packetized (buffer_verify_data_s * vdata, GstBuffer * buffer)
{
  GstMapInfo map;

  gst_buffer_map (buffer, &map, GST_MAP_READ);

  fail_unless (map.size > 4);
  fail_unless (GST_READ_UINT32_BE (map.data) == 0x01);
  if (vdata->discard) {
    /* check separate header NALs */
    guint8 *data;
    gint size;

    if (vdata->buffer_counter == 0) {
      data = h264_sps;
      size = sizeof (h264_sps);
    } else {
      data = h264_pps;
      size = sizeof (h264_pps);
    }

    fail_unless (map.size == size);
    fail_unless (memcmp (map.data + 4, data + 4, size - 4) == 0);
  } else {
    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;
}
Exemple #9
0
guint32
gst_rdt_packet_data_get_timestamp (GstRDTPacket * packet)
{
  guint header;
  gboolean length_included_flag;
  guint8 *bufdata;

  g_return_val_if_fail (packet != NULL, 0);
  g_return_val_if_fail (GST_RDT_IS_DATA_TYPE (packet->type), 0);

  bufdata = GST_BUFFER_DATA (packet->buffer);

  header = packet->offset;

  length_included_flag = (bufdata[header] & 0x80) == 0x80;

  /* skip seq_no and header bits */
  header += 3;

  if (length_included_flag) {
    /* skip length */
    header += 2;
  }
  /* skip asm_rule_number */
  header += 1;

  /* get timestamp */
  return GST_READ_UINT32_BE (&bufdata[header]);
}
Exemple #10
0
static gboolean
verify_buffer_packetized (buffer_verify_data_s * vdata, GstBuffer * buffer)
{
  fail_unless (GST_BUFFER_SIZE (buffer) > 4);
  fail_unless (GST_READ_UINT32_BE (GST_BUFFER_DATA (buffer)) == 0x01);
  if (vdata->discard) {
    /* check separate header NALs */
    guint8 *data;
    gint size;

    if (vdata->buffer_counter == 0) {
      data = h264_sps;
      size = sizeof (h264_sps);
    } else {
      data = h264_pps;
      size = sizeof (h264_pps);
    }

    fail_unless (GST_BUFFER_SIZE (buffer) == size);
    fail_unless (memcmp (GST_BUFFER_DATA (buffer) + 4, data + 4,
            size - 4) == 0);
  } else {
    fail_unless (GST_BUFFER_SIZE (buffer) == vdata->data_to_verify_size);
    fail_unless (memcmp (GST_BUFFER_DATA (buffer) + 4,
            vdata->data_to_verify + 4, GST_BUFFER_SIZE (buffer) - 4) == 0);
  }

  return TRUE;
}
static gboolean
flv_script_data_read_string(FlvScriptDataReader* reader, gchar** dest, gboolean longString)
{
    gsize length;

    /* Read length of string */
    if ((reader->position + (longString ? 4 : 2)) > reader->end)
        return FALSE;
    if (longString) {
        length = GST_READ_UINT32_BE(reader->position);
        reader->position += 4;
    } else {
        length = GST_READ_UINT16_BE(reader->position);
        reader->position += 2;
    }

    /* Alloc buffer and copy string into it */
    if ((reader->position + length) > reader->end)
        return FALSE;

    if (length >= G_MAXSIZE - 1)
        return FALSE;

    *dest = g_malloc(length + 1);
    if (*dest == NULL)
        return FALSE;
    memcpy(*dest, reader->position, length);
    (*dest)[length] = 0;
    reader->position += length;

    return TRUE;
}
static gboolean
check_protocol_version (GstPluginLoader * l, guint8 * payload,
    guint payload_len)
{
  guint32 got_version;
  guint8 *binary_reg_ver;

  if (payload_len < sizeof (guint32) + GST_MAGIC_BINARY_VERSION_LEN)
    return FALSE;

  got_version = GST_READ_UINT32_BE (payload);
  GST_LOG ("Got VERSION %u from child. Ours is %u", got_version,
      loader_protocol_version);
  if (got_version != loader_protocol_version)
    return FALSE;

  binary_reg_ver = payload + sizeof (guint32);
  if (strcmp ((gchar *) binary_reg_ver, GST_MAGIC_BINARY_VERSION_STR)) {
    GST_LOG ("Binary chunk format of child is different. Ours: %s, child %s\n",
        GST_MAGIC_BINARY_VERSION_STR, binary_reg_ver);
    return FALSE;
  }

  return TRUE;
};
Exemple #13
0
gboolean
mxf_fraction_parse (MXFFraction * fraction, const guint8 * data, guint size)
{
  g_return_val_if_fail (fraction != NULL, FALSE);
  g_return_val_if_fail (data != NULL, FALSE);

  memset (fraction, 0, sizeof (MXFFraction));

  if (size < 8)
    return FALSE;

  fraction->n = GST_READ_UINT32_BE (data);
  fraction->d = GST_READ_UINT32_BE (data + 4);

  return TRUE;
}
guint32
gst_rdt_packet_data_get_timestamp (GstRDTPacket * packet)
{
  GstMapInfo map;
  guint header;
  gboolean length_included_flag;
  guint32 result;

  g_return_val_if_fail (packet != NULL, 0);
  g_return_val_if_fail (GST_RDT_IS_DATA_TYPE (packet->type), 0);

  gst_buffer_map (packet->buffer, &map, GST_MAP_READ);

  header = packet->offset;

  length_included_flag = (map.data[header] & 0x80) == 0x80;

  /* skip seq_no and header bits */
  header += 3;

  if (length_included_flag) {
    /* skip length */
    header += 2;
  }
  /* skip asm_rule_number */
  header += 1;

  /* get timestamp */
  result = GST_READ_UINT32_BE (&map.data[header]);
  gst_buffer_unmap (packet->buffer, &map);

  return result;
}
Exemple #15
0
static GstFlowReturn
gst_omx_h264_enc_handle_output_frame (GstOMXVideoEnc * self, GstOMXPort * port,
    GstOMXBuffer * buf, GstVideoFrame * frame)
{
  if (buf->omx_buf->nFlags & OMX_BUFFERFLAG_CODECCONFIG) {
    /* The codec data is SPS/PPS with a startcode => bytestream stream format
     * For bytestream stream format the SPS/PPS is only in-stream and not
     * in the caps!
     */
    if (buf->omx_buf->nFilledLen >= 4 &&
        GST_READ_UINT32_BE (buf->omx_buf->pBuffer +
            buf->omx_buf->nOffset) == 0x00000001) {
      GstBuffer *hdrs;

      GST_DEBUG_OBJECT (self, "got codecconfig in byte-stream format");
      buf->omx_buf->nFlags &= ~OMX_BUFFERFLAG_CODECCONFIG;

      hdrs = gst_buffer_new_and_alloc (buf->omx_buf->nFilledLen);
      memcpy (GST_BUFFER_DATA (hdrs),
          buf->omx_buf->pBuffer + buf->omx_buf->nOffset,
          buf->omx_buf->nFilledLen);
      gst_base_video_encoder_set_headers (GST_BASE_VIDEO_ENCODER (self), hdrs);
      gst_buffer_unref (hdrs);
    }
  }

  return GST_OMX_VIDEO_ENC_CLASS (parent_class)->handle_output_frame (self,
      port, buf, frame);
}
Exemple #16
0
static GstPadProbeReturn
drop_theora_config (GstPad *pad, GstPadProbeInfo *info, gpointer user_data)
{
  GstBuffer *buffer = GST_PAD_PROBE_INFO_BUFFER (info);
  GstRTPBuffer rtpbuffer = GST_RTP_BUFFER_INIT;
  guint8 *payload;
  guint32 header;
  guchar TDT;

  gst_rtp_buffer_map (buffer, GST_MAP_READ, &rtpbuffer);

  payload = gst_rtp_buffer_get_payload (&rtpbuffer);

  header = GST_READ_UINT32_BE (payload);
  /*
   *  0                   1                   2                   3
   *  0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
   * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   * |                     Ident                     | F |TDT|# pkts.|
   * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   *
   * F: Fragment type (0=none, 1=start, 2=cont, 3=end)
   * TDT: Theora data type (0=theora, 1=config, 2=comment, 3=reserved)
   * pkts: number of packets.
   */
  TDT = (header & 0x30) >> 4;

  gst_rtp_buffer_unmap (&rtpbuffer);

  if (TDT == 1)
    return GST_PAD_PROBE_DROP;
  else
    return GST_PAD_PROBE_OK;
}
Exemple #17
0
static int
_parse_u32 (AmfParser * parser)
{
  int x;
  x = GST_READ_UINT32_BE (parser->data + parser->offset);
  parser->offset += 4;
  return x;
}
Exemple #18
0
static gboolean
verify_buffer (buffer_verify_data_s * vdata, GstBuffer * buffer)
{
  if (vdata->discard) {
    /* check separate header NALs */
    gint i = vdata->buffer_counter;

    fail_unless (i <= 1);
    fail_unless (GST_BUFFER_SIZE (buffer) == ctx_headers[i].size);
    fail_unless (memcmp (GST_BUFFER_DATA (buffer), ctx_headers[i].data,
            GST_BUFFER_SIZE (buffer)) == 0);
  } else {
    fail_unless (GST_BUFFER_SIZE (buffer) > 4);
    /* only need to check avc output case */
    if (GST_READ_UINT32_BE (GST_BUFFER_DATA (buffer)) == 0x01)
      return FALSE;
    /* header is merged in initial frame */
    if (vdata->buffer_counter == 0) {
      guint8 *data = GST_BUFFER_DATA (buffer);

      fail_unless (GST_BUFFER_SIZE (buffer) == vdata->data_to_verify_size +
          ctx_headers[0].size + ctx_headers[1].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) == 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 (GST_BUFFER_DATA (buffer)) ==
          GST_BUFFER_SIZE (buffer) - 4);
      fail_unless (GST_BUFFER_SIZE (buffer) == vdata->data_to_verify_size);
      fail_unless (memcmp (GST_BUFFER_DATA (buffer) + 4,
              vdata->data_to_verify + 4, GST_BUFFER_SIZE (buffer) - 4) == 0);
    }
    return TRUE;
  }

  return FALSE;
}
static gboolean
moov_recov_parse_moov_timescale (MoovRecovFile * moovrf)
{
  guint8 ts[4];
  if (fread (ts, 1, 4, moovrf->file) != 4)
    return FALSE;
  moovrf->timescale = GST_READ_UINT32_BE (ts);
  return TRUE;
}
static gboolean
moov_recov_parse_num_traks (MoovRecovFile * moovrf)
{
  guint8 traks[4];
  if (fread (traks, 1, 4, moovrf->file) != 4)
    return FALSE;
  moovrf->num_traks = GST_READ_UINT32_BE (traks);
  return TRUE;
}
/**
 * gst_audio_format_fill_silence:
 * @info: a #GstAudioFormatInfo
 * @dest: (array length=length) (element-type guint8): a destination
 *   to fill
 * @length: the length to fill
 *
 * Fill @length bytes in @dest with silence samples for @info.
 */
void
gst_audio_format_fill_silence (const GstAudioFormatInfo * info,
    gpointer dest, gsize length)
{
  guint8 *dptr = dest;

  g_return_if_fail (info != NULL);
  g_return_if_fail (dest != NULL);

  if (info->flags & GST_AUDIO_FORMAT_FLAG_FLOAT ||
      info->flags & GST_AUDIO_FORMAT_FLAG_SIGNED) {
    /* float or signed always 0 */
    orc_memset (dest, 0, length);
  } else {
    gint i, j, bps = info->width >> 3;

    switch (bps) {
      case 1:
        orc_memset (dest, info->silence[0], length);
        break;
      case 2:{
#if G_BYTE_ORDER == G_LITTLE_ENDIAN
        guint16 silence = GST_READ_UINT16_LE (info->silence);
#else
        guint16 silence = GST_READ_UINT16_BE (info->silence);
#endif
        audio_orc_splat_u16 (dest, silence, length / bps);
        break;
      }
      case 4:{
#if G_BYTE_ORDER == G_LITTLE_ENDIAN
        guint32 silence = GST_READ_UINT32_LE (info->silence);
#else
        guint32 silence = GST_READ_UINT32_BE (info->silence);
#endif
        audio_orc_splat_u32 (dest, silence, length / bps);
        break;
      }
      case 8:{
#if G_BYTE_ORDER == G_LITTLE_ENDIAN
        guint64 silence = GST_READ_UINT64_LE (info->silence);
#else
        guint64 silence = GST_READ_UINT64_BE (info->silence);
#endif
        audio_orc_splat_u64 (dest, silence, length / bps);
        break;
      }
      default:
        for (i = 0; i < length; i += bps) {
          for (j = 0; j < bps; j++)
            *dptr++ = info->silence[j];
        }
        break;
    }
  }
}
static gboolean
flv_script_data_read_ui32(FlvScriptDataReader* reader, guint32* dest)
{
    if (reader->position + 4 > reader->end) {
        return FALSE;
    }
    *dest = GST_READ_UINT32_BE(reader->position);
    reader->position+=4;
    return TRUE;
}
Exemple #23
0
static gboolean
gst_dirac_parse_frame_header (GstDiracParse * diracparse,
    GstBuffer * buffer, guint * framesize)
{
  int next_header;

  next_header = GST_READ_UINT32_BE (GST_BUFFER_DATA (buffer) + 5);

  *framesize = next_header;
  return TRUE;
}
static gboolean
read_atom_header (FILE * f, guint32 * fourcc, guint32 * size)
{
  guint8 aux[8];

  if (fread (aux, 1, 8, f) != 8)
    return FALSE;
  *size = GST_READ_UINT32_BE (aux);
  *fourcc = GST_READ_UINT32_LE (aux + 4);
  return TRUE;
}
static gboolean
moov_recov_parse_buffer_entry (MoovRecovFile * moovrf, TrakBufferEntryInfo * b)
{
  guint8 data[TRAK_BUFFER_ENTRY_INFO_SIZE];
  gint read;

  read = fread (data, 1, TRAK_BUFFER_ENTRY_INFO_SIZE, moovrf->file);
  if (read != TRAK_BUFFER_ENTRY_INFO_SIZE)
    return FALSE;

  b->track_id = GST_READ_UINT32_BE (data);
  b->nsamples = GST_READ_UINT32_BE (data + 4);
  b->delta = GST_READ_UINT32_BE (data + 8);
  b->size = GST_READ_UINT32_BE (data + 12);
  b->chunk_offset = GST_READ_UINT64_BE (data + 16);
  b->sync = data[24] != 0;
  b->do_pts = data[25] != 0;
  b->pts_offset = GST_READ_UINT64_BE (data + 26);
  return TRUE;
}
Exemple #26
0
/**
 * gst_rtp_buffer_get_csrc:
 * @buffer: the buffer
 * @idx: the index of the CSRC to get
 *
 * Get the CSRC at index @idx in @buffer.
 * 
 * Returns: the CSRC at index @idx in host order.
 */
guint32
gst_rtp_buffer_get_csrc (GstBuffer * buffer, guint8 idx)
{
  guint8 *data;

  data = GST_BUFFER_DATA (buffer);

  g_return_val_if_fail (idx < GST_RTP_HEADER_CSRC_COUNT (data), 0);

  return GST_READ_UINT32_BE (GST_RTP_HEADER_CSRC_LIST_OFFSET (data, idx));
}
Exemple #27
0
EXPORT_C
#endif

guint32
gst_rtp_buffer_get_csrc (GstBuffer * buffer, guint8 idx)
{
  g_return_val_if_fail (GST_IS_BUFFER (buffer), 0);
  g_return_val_if_fail (GST_BUFFER_DATA (buffer) != NULL, 0);
  g_return_val_if_fail (idx < GST_RTP_HEADER_CSRC_COUNT (buffer), 0);

  return GST_READ_UINT32_BE (GST_RTP_HEADER_CSRC_LIST_OFFSET (buffer, idx));
}
static void
check_rgb_buf (const guint8 * pixels, guint32 r_mask, guint32 g_mask,
    guint32 b_mask, guint32 a_mask, guint8 r_expected, guint8 g_expected,
    guint8 b_expected, guint bpp, guint depth)
{
  guint32 pixel, red, green, blue, alpha;

  switch (bpp) {
    case 32:
      pixel = GST_READ_UINT32_BE (pixels);
      break;
    case 24:
      pixel = (GST_READ_UINT8 (pixels) << 16) |
          (GST_READ_UINT8 (pixels + 1) << 8) |
          (GST_READ_UINT8 (pixels + 2) << 0);
      break;
    case 16:
      if (G_BYTE_ORDER == G_LITTLE_ENDIAN)
        pixel = GST_READ_UINT16_LE (pixels);
      else
        pixel = GST_READ_UINT16_BE (pixels);
      break;
    default:
      g_return_if_reached ();
  }

  red = right_shift_colour (r_mask, pixel);
  green = right_shift_colour (g_mask, pixel);
  blue = right_shift_colour (b_mask, pixel);
  alpha = right_shift_colour (a_mask, pixel);

  /* can't enable this by default, valgrind will complain about accessing
   * uninitialised memory for the depth=24,bpp=32 formats ... */
  /* GST_LOG ("pixels: 0x%02x 0x%02x 0x%02x 0x%02x => pixel = 0x%08x",
     pixels[0], (guint) pixels[1], pixels[2], pixels[3], pixel); */

  /* fix up the mask (for rgb15/16) */
  if (bpp == 16) {
    r_expected = fix_expected_colour (r_mask, r_expected);
    g_expected = fix_expected_colour (g_mask, g_expected);
    b_expected = fix_expected_colour (b_mask, b_expected);
  }

  fail_unless (red == r_expected, "RED: expected 0x%02x, found 0x%02x",
      r_expected, red);
  fail_unless (green == g_expected, "GREEN: expected 0x%02x, found 0x%02x",
      g_expected, green);
  fail_unless (blue == b_expected, "BLUE: expected 0x%02x, found 0x%02x",
      b_expected, blue);

  fail_unless (a_mask == 0 || alpha != 0);      /* better than nothing */
}
Exemple #29
0
static int
scan_fast (guint8 * data, guint32 pattern, guint32 mask, int n)
{
  int i;

  pattern &= mask;
  for (i = 0; i < n; i++) {
    if ((GST_READ_UINT32_BE (data + i) & mask) == pattern) {
      return i;
    }
  }
  return n;
}
Exemple #30
0
static GstFlowReturn
mq_dummypad_chain (GstPad * sinkpad, GstObject * parent, GstBuffer * buf)
{
  guint32 cur_id;
  struct PadData *pad_data;
  GstMapInfo info;

  pad_data = gst_pad_get_element_private (sinkpad);

  g_mutex_lock (&_check_lock);
  fail_if (pad_data == NULL);
  /* Read an ID from the first 4 bytes of the buffer data and check it's
   * what we expect */
  fail_unless (gst_buffer_map (buf, &info, GST_MAP_READ));
  fail_unless (info.size >= 4);
  g_mutex_unlock (&_check_lock);
  cur_id = GST_READ_UINT32_BE (info.data);
  gst_buffer_unmap (buf, &info);

  g_mutex_lock (pad_data->mutex);

  /* For not-linked pads, ensure that we're not running ahead of the 'linked'
   * pads. The first buffer is allowed to get ahead, because otherwise things can't
   * always pre-roll correctly */
  if (!pad_data->is_linked) {
    /* If there are no linked pads, we can't track a max_id for them :) */
    if (pad_data->n_linked > 0 && !pad_data->first_buf) {
      g_mutex_lock (&_check_lock);
      fail_unless (cur_id <= *(pad_data->max_linked_id_ptr) + 1,
          "Got buffer %u on pad %u before buffer %u was seen on a "
          "linked pad (max: %u)", cur_id, pad_data->pad_num, cur_id - 1,
          *(pad_data->max_linked_id_ptr));
      g_mutex_unlock (&_check_lock);
    }
  } else {
    /* Update the max_id value */
    if (cur_id > *(pad_data->max_linked_id_ptr))
      *(pad_data->max_linked_id_ptr) = cur_id;
  }
  pad_data->first_buf = FALSE;

  g_mutex_unlock (pad_data->mutex);

  /* Unref the buffer */
  gst_buffer_unref (buf);

  /* Return OK or not-linked as indicated */
  return pad_data->is_linked ? GST_FLOW_OK : GST_FLOW_NOT_LINKED;
}