/** * gst_mpegts_descriptor_parse_logical_channel: * @descriptor: a %GST_MTS_DESC_DTG_LOGICAL_CHANNEL #GstMpegtsDescriptor * @res: (out) (transfer none): the #GstMpegtsLogicalChannelDescriptor to fill * * Extracts the logical channels from @descriptor. * * Returns: %TRUE if parsing succeeded, else %FALSE. */ gboolean gst_mpegts_descriptor_parse_logical_channel (const GstMpegtsDescriptor * descriptor, GstMpegtsLogicalChannelDescriptor * res) { guint i; guint8 *data; g_return_val_if_fail (descriptor != NULL && res != NULL, FALSE); /* This descriptor loop can be empty, no size check required */ __common_desc_check_base (descriptor, GST_MTS_DESC_DTG_LOGICAL_CHANNEL, FALSE); data = (guint8 *) descriptor->data + 2; res->nb_channels = descriptor->length / 4; for (i = 0; i < res->nb_channels; i++) { res->channels[i].service_id = GST_READ_UINT16_BE (data); data += 2; res->channels[i].visible_service = *data >> 7; res->channels[i].logical_channel_number = GST_READ_UINT16_BE (data) & 0x03ff; data += 2; } return TRUE; }
/** * gst_rtp_buffer_get_extension_data: * @buffer: the buffer * @bits: location for result bits * @data: location for data * @wordlen: location for length of @data in 32 bits words * * Get the extension data. @bits will contain the extension 16 bits of custom * data. @data will point to the data in the extension and @wordlen will contain * the length of @data in 32 bits words. * * If @buffer did not contain an extension, this function will return %FALSE * with @bits, @data and @wordlen unchanged. * * Returns: TRUE if @buffer had the extension bit set. * * Since: 0.10.15 */ gboolean gst_rtp_buffer_get_extension_data (GstBuffer * buffer, guint16 * bits, gpointer * data, guint * wordlen) { guint len; guint8 *pdata; pdata = GST_BUFFER_DATA (buffer); if (!GST_RTP_HEADER_EXTENSION (pdata)) return FALSE; /* move to the extension */ len = GST_RTP_HEADER_LEN + GST_RTP_HEADER_CSRC_SIZE (pdata); pdata += len; if (bits) *bits = GST_READ_UINT16_BE (pdata); if (wordlen) *wordlen = GST_READ_UINT16_BE (pdata + 2); if (data) *data = pdata + 4; return TRUE; }
EXPORT_C #endif gboolean gst_rtp_buffer_get_extension_data (GstBuffer * buffer, guint16 * bits, gpointer * data, guint * wordlen) { guint len; guint8 *pdata; g_return_val_if_fail (GST_IS_BUFFER (buffer), FALSE); g_return_val_if_fail (GST_BUFFER_DATA (buffer) != NULL, FALSE); if (!GST_RTP_HEADER_EXTENSION (buffer)) return FALSE; /* move to the extension */ len = GST_RTP_HEADER_LEN + GST_RTP_HEADER_CSRC_SIZE (buffer); pdata = GST_BUFFER_DATA (buffer) + len; if (bits) *bits = GST_READ_UINT16_BE (pdata); if (wordlen) *wordlen = GST_READ_UINT16_BE (pdata + 2); if (data) *data = pdata + 4; return TRUE; }
gboolean mxf_product_version_parse (MXFProductVersion * product_version, const guint8 * data, guint size) { g_return_val_if_fail (product_version != NULL, FALSE); g_return_val_if_fail (data != NULL, FALSE); memset (product_version, 0, sizeof (MXFProductVersion)); if (size < 9) return FALSE; product_version->major = GST_READ_UINT16_BE (data); product_version->minor = GST_READ_UINT16_BE (data + 2); product_version->patch = GST_READ_UINT16_BE (data + 4); product_version->build = GST_READ_UINT16_BE (data + 6); /* Avid writes a 9 byte product version */ if (size == 9) product_version->release = GST_READ_UINT8 (data + 8); else product_version->release = GST_READ_UINT16_BE (data + 8); return TRUE; }
gboolean gst_mpegts_descriptor_parse_ca (GstMpegtsDescriptor * descriptor, guint16 * ca_system_id, guint16 * ca_pid, const guint8 ** private_data, gsize * private_data_size) { guint8 *data; g_return_val_if_fail (descriptor != NULL && ca_system_id != NULL && ca_pid != NULL, FALSE); /* The smallest CA is 4 bytes (though not having any private data * sounds a bit ... weird) */ __common_desc_checks (descriptor, GST_MTS_DESC_CA, 4, FALSE); data = (guint8 *) descriptor->data + 2; *ca_system_id = GST_READ_UINT16_BE (data); data += 2; *ca_pid = GST_READ_UINT16_BE (data) & 0x1fff; data += 2; if (private_data && private_data_size) { *private_data = data; *private_data_size = descriptor->length - 4; } return TRUE; }
static void rtp_jpeg_do_packet_loss (gdouble prob, gint num_expected) { GstHarness *h; gboolean eos = FALSE; gchar *s; guint i, buffer_count; s = g_strdup_printf ("videotestsrc pattern=ball num-buffers=100 ! " "jpegenc quality=50 ! rtpjpegpay ! identity drop-probability=%g ! " "rtpjpegdepay", prob); GST_INFO ("running pipeline %s", s); h = gst_harness_new_parse (s); g_free (s); gst_harness_play (h); do { GstEvent *event; event = gst_harness_pull_event (h); eos = (GST_EVENT_TYPE (event) == GST_EVENT_EOS); gst_event_unref (event); } while (!eos); buffer_count = gst_harness_buffers_received (h); GST_INFO ("Got %u buffers", buffer_count); if (num_expected >= 0) { fail_unless_equals_int (num_expected, buffer_count); } for (i = 0; i < buffer_count; ++i) { GstBuffer *buf; GstMapInfo map; guint16 soi, eoi; buf = gst_harness_pull (h); fail_unless (buf != NULL); fail_unless (gst_buffer_map (buf, &map, GST_MAP_READ)); GST_MEMDUMP ("jpeg frame", map.data, map.size); fail_unless (map.size > 4); soi = GST_READ_UINT16_BE (map.data); fail_unless (soi == 0xffd8, "expected JPEG frame start FFD8 not %02X", soi); eoi = GST_READ_UINT16_BE (map.data + map.size - 2); fail_unless (eoi == 0xffd9, "expected JPEG frame end FFD9 not %02X", eoi); gst_buffer_unmap (buf, &map); gst_buffer_unref (buf); } gst_harness_teardown (h); }
static gboolean parse_MThd (GstMidiParse * midiparse, guint8 * data, guint size) { guint16 format, ntracks, division; gboolean multitrack; format = GST_READ_UINT16_BE (data); switch (format) { case 0: multitrack = FALSE; break; case 1: multitrack = TRUE; break; default: case 2: goto invalid_format; } ntracks = GST_READ_UINT16_BE (data + 2); if (ntracks > 1 && !multitrack) goto invalid_tracks; division = GST_READ_UINT16_BE (data + 4); if (division & 0x8000) goto invalid_division; GST_DEBUG_OBJECT (midiparse, "format %u, tracks %u, division %u", format, ntracks, division); midiparse->ntracks = ntracks; midiparse->division = division; return TRUE; invalid_format: { GST_ERROR_OBJECT (midiparse, "unsupported midi format %u", format); return FALSE; } invalid_tracks: { GST_ERROR_OBJECT (midiparse, "invalid number of tracks %u for format %u", ntracks, format); return FALSE; } invalid_division: { GST_ERROR_OBJECT (midiparse, "unsupported division"); return FALSE; } }
guint16 gst_rdt_packet_data_get_stream_id (GstRDTPacket * packet) { guint16 result; 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; result = (bufdata[header] & 0x3e) >> 1; if (result == 31) { /* skip seq_no and header bits */ header += 3; if (length_included_flag) { /* skip length */ header += 2; } /* skip asm_rule_number and timestamp */ header += 5; /* stream_id_expansion */ result = GST_READ_UINT16_BE (&bufdata[header]); } return result; }
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 void check_rtp_buffer (GstClockTime ts, GstClockTime duration, gboolean start, gboolean end, guint rtpts, guint ssrc, guint volume, guint number, guint rtpduration) { GstBuffer *buffer; GstRTPBuffer rtpbuffer = GST_RTP_BUFFER_INIT; gchar *payload; g_mutex_lock (&check_mutex); while (buffers == NULL) g_cond_wait (&check_cond, &check_mutex); g_mutex_unlock (&check_mutex); fail_unless (buffers != NULL); buffer = buffers->data; buffers = g_list_delete_link (buffers, buffers); fail_unless (GST_BUFFER_PTS (buffer) == ts); fail_unless (GST_BUFFER_DURATION (buffer) == duration); fail_unless (gst_rtp_buffer_map (buffer, GST_MAP_READ, &rtpbuffer)); fail_unless (gst_rtp_buffer_get_marker (&rtpbuffer) == start); fail_unless (gst_rtp_buffer_get_timestamp (&rtpbuffer) == rtpts); payload = gst_rtp_buffer_get_payload (&rtpbuffer); fail_unless (payload[0] == number); fail_unless ((payload[1] & 0x7F) == volume); fail_unless (! !(payload[1] & 0x80) == end); fail_unless (GST_READ_UINT16_BE (payload + 2) == rtpduration); gst_rtp_buffer_unmap (&rtpbuffer); gst_buffer_unref (buffer); }
static gint deserialize_orientation (GstExifReader * exif_reader, GstByteReader * reader, const GstExifTagMatch * exiftag, GstExifTagData * tagdata) { gint ret = 1; const gchar *str = NULL; gint value; GST_LOG ("Starting to parse %s tag in exif 0x%x", exiftag->gst_tag, exiftag->exif_tag); /* validate tag */ if (tagdata->tag_type != EXIF_TYPE_SHORT || tagdata->count != 1) { GST_WARNING ("Orientation tag has unexpected type/count"); return ret; } if (exif_reader->byte_order == G_LITTLE_ENDIAN) { value = GST_READ_UINT16_LE (tagdata->offset_as_data); } else { value = GST_READ_UINT16_BE (tagdata->offset_as_data); } str = gst_tag_image_orientation_from_exif_value (value); if (str == NULL) { GST_WARNING ("Invalid value for exif orientation tag: %d", value); return ret; } gst_tag_list_add (exif_reader->taglist, GST_TAG_MERGE_REPLACE, exiftag->gst_tag, str, NULL); return ret; }
static gboolean gst_irtsp_parse_check_valid_frame (GstBaseParse * parse, GstBaseParseFrame * frame, guint * framesize, gint * skipsize) { GstIRTSPParse *IRTSPParse = GST_IRTSP_PARSE (parse); GstBuffer *buf = frame->buffer; GstByteReader reader = GST_BYTE_READER_INIT_FROM_BUFFER (buf); gint off; if (G_UNLIKELY (GST_BUFFER_SIZE (buf) < 4)) return FALSE; off = gst_byte_reader_masked_scan_uint32 (&reader, 0xffff0000, 0x24000000 + (IRTSPParse->channel_id << 16), 0, GST_BUFFER_SIZE (buf)); GST_LOG_OBJECT (parse, "possible sync at buffer offset %d", off); /* didn't find anything that looks like a sync word, skip */ if (off < 0) { *skipsize = GST_BUFFER_SIZE (buf) - 3; return FALSE; } /* possible frame header, but not at offset 0? skip bytes before sync */ if (off > 0) { *skipsize = off; return FALSE; } *framesize = GST_READ_UINT16_BE (GST_BUFFER_DATA (frame->buffer) + 2) + 4; GST_LOG_OBJECT (parse, "got frame size %d", *framesize); return TRUE; }
/* caller must pass buffer with full ID3 tag */ ID3TagsResult id3demux_read_id3v2_tag (GstBuffer * buffer, guint * id3v2_size, GstTagList ** tags) { guint8 *data, *uu_data = NULL; guint read_size; ID3TagsWorking work; guint8 flags; ID3TagsResult result; guint16 version; read_size = id3demux_calc_id3v2_tag_size (buffer); if (id3v2_size) *id3v2_size = read_size; /* Ignore tag if it has no frames attached, but skip the header then */ if (read_size <= ID3V2_HDR_SIZE) return ID3TAGS_BROKEN_TAG; data = GST_BUFFER_DATA (buffer); /* Read the version */ version = GST_READ_UINT16_BE (data + 3); /* Read the flags */ flags = data[5]; /* Validate the version. At the moment, we only support up to 2.4.0 */ if (ID3V2_VER_MAJOR (version) > 4 || ID3V2_VER_MINOR (version) > 0) { GST_WARNING ("ID3v2 tag is from revision 2.%d.%d, " "but decoder only supports 2.%d.%d. Ignoring as per spec.", version >> 8, version & 0xff, ID3V2_VERSION >> 8, ID3V2_VERSION & 0xff); return ID3TAGS_READ_TAG; }
static GstFlowReturn test_mpeg_audio_parse_handle_frame (GstBaseParse * parse, GstBaseParseFrame * frame, gint * skipsize) { guint8 data[2]; gst_buffer_extract (frame->buffer, 0, data, 2); if ((GST_READ_UINT16_BE (data) & 0xffe0) == 0xffe0) { if (GST_BUFFER_OFFSET (frame->buffer) == 0) { GstCaps *caps; caps = gst_caps_new_simple ("audio/mpeg", "mpegversion", G_TYPE_INT, 1, "mpegaudioversion", G_TYPE_INT, 1, "layer", G_TYPE_INT, 3, "rate", G_TYPE_INT, 44100, "channels", G_TYPE_INT, 2, NULL); gst_pad_set_caps (GST_BASE_PARSE_SRC_PAD (parse), caps); gst_caps_unref (caps); } /* this framesize is hard-coded for ../test.mp3 */ return gst_base_parse_finish_frame (parse, frame, 1045); } else { *skipsize = 1; return GST_FLOW_OK; } }
static int _parse_u16 (AmfParser * parser) { int x; x = GST_READ_UINT16_BE (parser->data + parser->offset); parser->offset += 2; return x; }
/** * 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 gst_aiff_parse_parse_comm (GstAiffParse * aiff, GstBuffer * buf) { guint8 *data; int size; if (aiff->is_aifc) size = 22; else size = 18; if (GST_BUFFER_SIZE (buf) < size) { GST_WARNING_OBJECT (aiff, "COMM chunk too short, cannot parse header"); return FALSE; } data = GST_BUFFER_DATA (buf); aiff->channels = GST_READ_UINT16_BE (data); aiff->total_frames = GST_READ_UINT32_BE (data + 2); aiff->depth = GST_READ_UINT16_BE (data + 6); aiff->width = GST_ROUND_UP_8 (aiff->depth); aiff->rate = (int) gst_aiff_parse_read_IEEE80 (data + 8); if (aiff->is_aifc) { /* We only support the 'trivial' uncompressed AIFC, but it can be * either big or little endian */ if (GST_READ_UINT32_LE (data + 18) == GST_MAKE_FOURCC ('N', 'O', 'N', 'E')) aiff->endianness = G_BIG_ENDIAN; else if (GST_READ_UINT32_LE (data + 18) == GST_MAKE_FOURCC ('s', 'o', 'w', 't')) aiff->endianness = G_LITTLE_ENDIAN; else { GST_WARNING_OBJECT (aiff, "Unsupported compression in AIFC " "file: %" GST_FOURCC_FORMAT, GST_FOURCC_ARGS (GST_READ_UINT32_LE (data + 18))); return FALSE; } } else aiff->endianness = G_BIG_ENDIAN; return TRUE; }
gboolean mxf_local_tag_parse (const guint8 * data, guint size, guint16 * tag, guint16 * tag_size, const guint8 ** tag_data) { g_return_val_if_fail (data != NULL, FALSE); if (size < 4) return FALSE; *tag = GST_READ_UINT16_BE (data); *tag_size = GST_READ_UINT16_BE (data + 2); if (size < 4 + *tag_size) return FALSE; *tag_data = data + 4; return TRUE; }
static int parse_set_window (GstDVDSpu * dvdspu, guint8 type, guint8 * payload, guint16 len) { SpuState *state = &dvdspu->spu_state; guint8 *end = payload + len; guint8 win_count, win_id G_GNUC_UNUSED; gint i; if (payload + 1 > end) return 0; dump_bytes (payload, len); win_count = payload[0]; payload++; for (i = 0; i < win_count; i++) { if (payload + 9 > end) return 0; /* FIXME: Store each window ID separately into an array */ win_id = payload[0]; state->pgs.win_x = GST_READ_UINT16_BE (payload + 1); state->pgs.win_y = GST_READ_UINT16_BE (payload + 3); state->pgs.win_w = GST_READ_UINT16_BE (payload + 5); state->pgs.win_h = GST_READ_UINT16_BE (payload + 7); payload += 9; PGS_DUMP ("Win ID %u x %d y %d w %d h %d\n", win_id, state->pgs.win_x, state->pgs.win_y, state->pgs.win_w, state->pgs.win_h); } if (payload != end) { GST_ERROR ("PGS Set Window: %" G_GSSIZE_FORMAT " bytes not consumed", (gssize) (end - payload)); dump_bytes (payload, end - payload); } return 0; }
static GstFlowReturn gst_dvd_sub_parse_chain (GstPad * pad, GstObject * parent, GstBuffer * buf) { GstDvdSubParse *parse = GST_DVD_SUB_PARSE (parent); GstAdapter *adapter; GstBuffer *outbuf = NULL; GstFlowReturn ret = GST_FLOW_OK; adapter = parse->adapter; GST_LOG_OBJECT (parse, "%" G_GSIZE_FORMAT " bytes, ts: %" GST_TIME_FORMAT, gst_buffer_get_size (buf), GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (buf))); gst_adapter_push (adapter, buf); if (!parse->needed) { guint8 data[2]; gst_adapter_copy (adapter, data, 0, 2); parse->needed = GST_READ_UINT16_BE (data); } if (GST_BUFFER_TIMESTAMP_IS_VALID (buf)) { if (GST_CLOCK_TIME_IS_VALID (parse->stamp)) /* normally, we expect only the first fragment to carry a timestamp */ GST_WARNING_OBJECT (parse, "Received more timestamps than expected."); else parse->stamp = GST_BUFFER_TIMESTAMP (buf); } if (parse->needed) { guint av; av = gst_adapter_available (adapter); if (av >= parse->needed) { if (av > parse->needed) { /* normally, we expect several fragment, boundary aligned */ GST_WARNING_OBJECT (parse, "Unexpected: needed %d, " "but more (%d) is available.", parse->needed, av); } outbuf = gst_adapter_take_buffer (adapter, parse->needed); /* decorate buffer */ GST_BUFFER_TIMESTAMP (outbuf) = parse->stamp; /* reset state */ parse->stamp = GST_CLOCK_TIME_NONE; parse->needed = 0; /* and send along */ ret = gst_pad_push (parse->srcpad, outbuf); } } return ret; }
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 */ }
/** * gst_rtp_buffer_get_header_len: * @buffer: the buffer * * Return the total length of the header in @buffer. This include the length of * the fixed header, the CSRC list and the extension header. * * Returns: The total length of the header in @buffer. */ guint gst_rtp_buffer_get_header_len (GstBuffer * buffer) { guint len; guint8 *data; data = GST_BUFFER_DATA (buffer); len = GST_RTP_HEADER_LEN + GST_RTP_HEADER_CSRC_SIZE (data); if (GST_RTP_HEADER_EXTENSION (data)) len += GST_READ_UINT16_BE (data + len + 2) * 4 + 4; return len; }
gint gstspu_exec_pgs_buffer (GstDVDSpu * dvdspu, GstBuffer * buf) { GstMapInfo map; guint8 *pos, *end; guint8 type; guint16 packet_len; gst_buffer_map (buf, &map, GST_MAP_READ); pos = map.data; end = pos + map.size; /* Need at least 3 bytes */ if (pos + 3 > end) { PGS_DUMP ("Not enough bytes to be a PGS packet\n"); goto error; } PGS_DUMP ("Begin dumping command buffer of size %u ts %" GST_TIME_FORMAT "\n", end - pos, GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (buf))); do { type = *pos++; packet_len = GST_READ_UINT16_BE (pos); pos += 2; if (pos + packet_len > end) { gst_buffer_unmap (buf, &map); PGS_DUMP ("Invalid packet length %u (only have %u bytes)\n", packet_len, end - pos); goto error; } if (parse_pgs_packet (dvdspu, type, pos, packet_len)) goto error; pos += packet_len; } while (pos + 3 <= end); PGS_DUMP ("End dumping command buffer with %u bytes remaining\n", end - pos); return (pos - map.data); /* ERRORS */ error: { gst_buffer_unmap (buf, &map); return -1; } }
static gboolean test_mpeg_audio_parse_check_valid_frame (GstBaseParse * parse, GstBaseParseFrame * frame, guint * framesize, gint * skipsize) { const guint8 *data = GST_BUFFER_DATA (frame->buffer); if ((GST_READ_UINT16_BE (data) & 0xffe0) == 0xffe0) { /* this framesize is hard-coded for ../test.mp3 */ *framesize = 1045; return TRUE; } else { *skipsize = 1; return FALSE; } }
/* FIXME: especially for multi-section tables, we need to handle pusi correctly * and handle cases where a new section starts in the same transport packet. */ gboolean gst_section_filter_push (GstSectionFilter *filter, gboolean pusi, /* determines whether start or not */ guint8 continuity_counter, GstBuffer *buf) { g_return_val_if_fail (filter != NULL, FALSE); /* check if it's the first packet of a section or * if it continues the section */ if (pusi) { const guint8* data = GST_BUFFER_DATA(buf); if (filter->last_continuity_counter != 255) { GST_WARNING ("section lost, last continuity counter: %d" "we now have a pusi at continuity counter: %d", filter->last_continuity_counter, continuity_counter); gst_section_filter_clear (filter); } filter->section_length = GST_READ_UINT16_BE (data+1); filter->section_length &= 0x0fff; if (filter->section_length > 1021) { GST_DEBUG ("section length too big"); return FALSE; } gst_adapter_push (filter->adapter, buf); filter->last_continuity_counter = continuity_counter; return gst_section_is_complete (filter); } else if (filter->last_continuity_counter == continuity_counter - 1 || (filter->last_continuity_counter == 15 && continuity_counter == 0)) { GST_DEBUG ("section still going, no pusi"); gst_adapter_push (filter->adapter, buf); filter->last_continuity_counter = continuity_counter; return gst_section_is_complete (filter); } /* we have lost the section and we are not a start * section, so clear what was in it */ else { GST_WARNING ("section lost, last continuity counter: %d" "new continuity counter but not pusi: %d", filter->last_continuity_counter, continuity_counter); gst_section_filter_clear (filter); return FALSE; } }
EXPORT_C #endif guint gst_rtp_buffer_get_header_len (GstBuffer * buffer) { guint len; g_return_val_if_fail (GST_IS_BUFFER (buffer), 0); len = GST_RTP_HEADER_LEN + GST_RTP_HEADER_CSRC_SIZE (buffer); if (GST_RTP_HEADER_EXTENSION (buffer)) len += GST_READ_UINT16_BE (GST_BUFFER_DATA (buffer) + len + 2) * 4 + 4; return len; }
guint16 gst_rdt_packet_data_get_seq (GstRDTPacket * packet) { guint header; guint8 *bufdata; g_return_val_if_fail (packet != NULL, FALSE); g_return_val_if_fail (GST_RDT_IS_DATA_TYPE (packet->type), FALSE); bufdata = GST_BUFFER_DATA (packet->buffer); /* skip header bits */ header = packet->offset + 1; /* read seq_no */ return GST_READ_UINT16_BE (&bufdata[header]); }
static void _encode_control_codes (gchar * text, gsize length, gboolean is_multibyte) { gsize pos = 0; while (pos < length) { if (is_multibyte) { guint16 code = GST_READ_UINT16_BE (text + pos); if (code == 0x000A) { text[pos] = 0xE0; text[pos + 1] = 0x8A; } pos += 2; } else { guint8 code = text[pos]; if (code == 0x0A) text[pos] = 0x8A; pos++; } } }
static gboolean gst_real_audio_demux_get_data_offset_from_header (GstRealAudioDemux * demux) { guint8 data[16]; gst_adapter_copy (demux->adapter, data, 0, 16); switch (demux->ra_version) { case 3: demux->data_offset = GST_READ_UINT16_BE (data) + 8; break; case 4: demux->data_offset = GST_READ_UINT32_BE (data + 12) + 16; break; default: demux->data_offset = 0; g_return_val_if_reached (FALSE); } return TRUE; }
gboolean mxf_timestamp_parse (MXFTimestamp * timestamp, const guint8 * data, guint size) { g_return_val_if_fail (data != NULL, FALSE); g_return_val_if_fail (timestamp != NULL, FALSE); memset (timestamp, 0, sizeof (MXFTimestamp)); if (size < 8) return FALSE; timestamp->year = GST_READ_UINT16_BE (data); timestamp->month = GST_READ_UINT8 (data + 2); timestamp->day = GST_READ_UINT8 (data + 3); timestamp->hour = GST_READ_UINT8 (data + 4); timestamp->minute = GST_READ_UINT8 (data + 5); timestamp->second = GST_READ_UINT8 (data + 6); timestamp->quarter_msecond = GST_READ_UINT8 (data + 7); return TRUE; }