2002-03-20 21:45:03 +00:00
|
|
|
/* GStreamer
|
2001-12-22 23:26:48 +00:00
|
|
|
* Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this library; if not, write to the
|
|
|
|
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
* Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
2003-11-07 12:46:51 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
2001-12-22 23:26:48 +00:00
|
|
|
|
2005-11-14 21:20:21 +00:00
|
|
|
#include <string.h>
|
|
|
|
|
2004-07-27 21:51:28 +00:00
|
|
|
#include "gstmpegpacketize.h"
|
2001-12-22 23:26:48 +00:00
|
|
|
|
2006-06-23 11:22:04 +00:00
|
|
|
GST_DEBUG_CATEGORY_STATIC (gstmpegpacketize_debug);
|
|
|
|
#define GST_CAT_DEFAULT (gstmpegpacketize_debug)
|
|
|
|
|
2004-03-14 22:34:30 +00:00
|
|
|
GstMPEGPacketize *
|
2006-06-23 11:22:04 +00:00
|
|
|
gst_mpeg_packetize_new (GstMPEGPacketizeType type)
|
2001-12-22 23:26:48 +00:00
|
|
|
{
|
|
|
|
GstMPEGPacketize *new;
|
|
|
|
|
2006-06-23 11:22:04 +00:00
|
|
|
new = g_new0 (GstMPEGPacketize, 1);
|
2003-01-06 19:13:49 +00:00
|
|
|
new->resync = TRUE;
|
2001-12-22 23:26:48 +00:00
|
|
|
new->id = 0;
|
2005-11-14 21:20:21 +00:00
|
|
|
new->cache_head = 0;
|
|
|
|
new->cache_tail = 0;
|
|
|
|
new->cache_size = 0x4000;
|
|
|
|
new->cache = g_malloc (new->cache_size);
|
|
|
|
new->cache_byte_pos = 0;
|
2001-12-22 23:26:48 +00:00
|
|
|
new->MPEG2 = FALSE;
|
2001-12-31 03:03:05 +00:00
|
|
|
new->type = type;
|
2001-12-22 23:26:48 +00:00
|
|
|
|
2006-08-27 20:46:54 +00:00
|
|
|
#ifndef GST_DISABLE_GST_DEBUG
|
2006-06-23 11:22:04 +00:00
|
|
|
if (gstmpegpacketize_debug == NULL) {
|
|
|
|
GST_DEBUG_CATEGORY_INIT (gstmpegpacketize_debug, "mpegpacketize", 0,
|
|
|
|
"MPEG parser element packetizer");
|
|
|
|
}
|
2006-08-27 20:46:54 +00:00
|
|
|
#endif
|
2006-06-23 11:22:04 +00:00
|
|
|
|
2001-12-22 23:26:48 +00:00
|
|
|
return new;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2006-06-23 11:22:04 +00:00
|
|
|
gst_mpeg_packetize_flush_cache (GstMPEGPacketize * packetize)
|
2001-12-22 23:26:48 +00:00
|
|
|
{
|
|
|
|
g_return_if_fail (packetize != NULL);
|
|
|
|
|
2006-06-23 12:24:56 +00:00
|
|
|
packetize->cache_byte_pos += packetize->cache_tail;
|
|
|
|
|
2006-06-23 11:22:04 +00:00
|
|
|
packetize->resync = TRUE;
|
|
|
|
packetize->cache_head = 0;
|
|
|
|
packetize->cache_tail = 0;
|
|
|
|
|
|
|
|
GST_DEBUG ("flushed packetize cache");
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gst_mpeg_packetize_destroy (GstMPEGPacketize * packetize)
|
|
|
|
{
|
|
|
|
g_return_if_fail (packetize != NULL);
|
2001-12-23 22:37:07 +00:00
|
|
|
|
2005-11-14 21:20:21 +00:00
|
|
|
g_free (packetize->cache);
|
2001-12-22 23:26:48 +00:00
|
|
|
g_free (packetize);
|
|
|
|
}
|
|
|
|
|
2005-11-14 21:20:21 +00:00
|
|
|
guint64
|
|
|
|
gst_mpeg_packetize_tell (GstMPEGPacketize * packetize)
|
|
|
|
{
|
|
|
|
return packetize->cache_byte_pos + packetize->cache_head;
|
|
|
|
}
|
|
|
|
|
2006-04-13 18:21:08 +00:00
|
|
|
void
|
2005-11-14 21:20:21 +00:00
|
|
|
gst_mpeg_packetize_put (GstMPEGPacketize * packetize, GstBuffer * buf)
|
|
|
|
{
|
|
|
|
int cache_len = packetize->cache_tail - packetize->cache_head;
|
|
|
|
|
2006-06-23 12:24:56 +00:00
|
|
|
if (packetize->cache_head == 0 && cache_len == 0 &&
|
|
|
|
GST_BUFFER_OFFSET_IS_VALID (buf)) {
|
|
|
|
packetize->cache_byte_pos = GST_BUFFER_OFFSET (buf);
|
|
|
|
GST_DEBUG ("cache byte position now %" G_GINT64_FORMAT,
|
|
|
|
packetize->cache_byte_pos);
|
|
|
|
}
|
|
|
|
|
2005-11-14 21:20:21 +00:00
|
|
|
if (cache_len + GST_BUFFER_SIZE (buf) > packetize->cache_size) {
|
|
|
|
/* the buffer does not fit into the cache so grow the cache */
|
|
|
|
|
|
|
|
guint8 *new_cache;
|
|
|
|
|
|
|
|
/* get the new size of the cache */
|
|
|
|
do {
|
|
|
|
packetize->cache_size *= 2;
|
|
|
|
} while (cache_len + GST_BUFFER_SIZE (buf) > packetize->cache_size);
|
|
|
|
|
|
|
|
/* allocate new cache - do not realloc to avoid copying data twice */
|
|
|
|
new_cache = g_malloc (packetize->cache_size);
|
|
|
|
|
|
|
|
/* copy the data to the beginning of the new cache and update the cache info */
|
|
|
|
memcpy (new_cache, packetize->cache + packetize->cache_head, cache_len);
|
|
|
|
g_free (packetize->cache);
|
|
|
|
packetize->cache = new_cache;
|
|
|
|
packetize->cache_byte_pos += packetize->cache_head;
|
|
|
|
packetize->cache_head = 0;
|
|
|
|
packetize->cache_tail = cache_len;
|
|
|
|
} else if (packetize->cache_tail + GST_BUFFER_SIZE (buf) >
|
|
|
|
packetize->cache_size) {
|
|
|
|
/* the buffer does not fit into the end of the cache so move the cache data
|
|
|
|
to the beginning of the cache */
|
|
|
|
|
|
|
|
memmove (packetize->cache, packetize->cache + packetize->cache_head,
|
|
|
|
packetize->cache_tail - packetize->cache_head);
|
|
|
|
packetize->cache_byte_pos += packetize->cache_head;
|
|
|
|
packetize->cache_tail -= packetize->cache_head;
|
|
|
|
packetize->cache_head = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* copy the buffer to the cache */
|
|
|
|
memcpy (packetize->cache + packetize->cache_tail, GST_BUFFER_DATA (buf),
|
|
|
|
GST_BUFFER_SIZE (buf));
|
|
|
|
packetize->cache_tail += GST_BUFFER_SIZE (buf);
|
|
|
|
|
|
|
|
gst_buffer_unref (buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
static guint
|
|
|
|
peek_cache (GstMPEGPacketize * packetize, guint length, guint8 ** buf)
|
|
|
|
{
|
|
|
|
*buf = packetize->cache + packetize->cache_head;
|
|
|
|
|
|
|
|
if (packetize->cache_tail - packetize->cache_head < length)
|
|
|
|
return packetize->cache_tail - packetize->cache_head;
|
|
|
|
|
|
|
|
return length;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
skip_cache (GstMPEGPacketize * packetize, guint length)
|
|
|
|
{
|
|
|
|
g_assert (packetize->cache_tail - packetize->cache_head >= length);
|
|
|
|
|
|
|
|
packetize->cache_head += length;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GstFlowReturn
|
|
|
|
read_cache (GstMPEGPacketize * packetize, guint length, GstBuffer ** outbuf)
|
|
|
|
{
|
|
|
|
if (packetize->cache_tail - packetize->cache_head < length)
|
|
|
|
return GST_FLOW_RESEND;
|
|
|
|
if (length == 0)
|
|
|
|
return GST_FLOW_RESEND;
|
|
|
|
|
|
|
|
*outbuf = gst_buffer_new_and_alloc (length);
|
|
|
|
|
|
|
|
memcpy (GST_BUFFER_DATA (*outbuf), packetize->cache + packetize->cache_head,
|
|
|
|
length);
|
|
|
|
packetize->cache_head += length;
|
|
|
|
|
|
|
|
return GST_FLOW_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GstFlowReturn
|
|
|
|
parse_packhead (GstMPEGPacketize * packetize, GstBuffer ** outbuf)
|
2001-12-22 23:26:48 +00:00
|
|
|
{
|
2005-11-14 21:20:21 +00:00
|
|
|
guint length = 8 + 4;
|
2001-12-22 23:26:48 +00:00
|
|
|
guint8 *buf;
|
2005-11-14 21:20:21 +00:00
|
|
|
guint got_bytes;
|
2001-12-22 23:26:48 +00:00
|
|
|
|
2003-06-29 19:46:09 +00:00
|
|
|
GST_DEBUG ("packetize: in parse_packhead");
|
2001-12-22 23:26:48 +00:00
|
|
|
|
2005-11-14 21:20:21 +00:00
|
|
|
*outbuf = NULL;
|
|
|
|
|
|
|
|
got_bytes = peek_cache (packetize, length, &buf);
|
2003-01-19 13:42:43 +00:00
|
|
|
if (got_bytes < length)
|
2005-11-14 21:20:21 +00:00
|
|
|
return GST_FLOW_RESEND;
|
2003-03-28 17:33:20 +00:00
|
|
|
|
2001-12-22 23:26:48 +00:00
|
|
|
buf += 4;
|
|
|
|
|
2003-06-29 19:46:09 +00:00
|
|
|
GST_DEBUG ("code %02x", *buf);
|
2001-12-22 23:26:48 +00:00
|
|
|
|
|
|
|
/* start parsing the stream */
|
2003-08-13 21:15:03 +00:00
|
|
|
if ((*buf & 0xc0) == 0x40) {
|
2003-06-29 19:46:09 +00:00
|
|
|
GST_DEBUG ("packetize::parse_packhead setting mpeg2");
|
2001-12-22 23:26:48 +00:00
|
|
|
packetize->MPEG2 = TRUE;
|
|
|
|
length += 2;
|
2005-11-14 21:20:21 +00:00
|
|
|
got_bytes = peek_cache (packetize, length, &buf);
|
2003-01-19 13:42:43 +00:00
|
|
|
if (got_bytes < length)
|
2005-11-14 21:20:21 +00:00
|
|
|
return GST_FLOW_RESEND;
|
2004-03-14 22:34:30 +00:00
|
|
|
} else {
|
2003-06-29 19:46:09 +00:00
|
|
|
GST_DEBUG ("packetize::parse_packhead setting mpeg1");
|
2001-12-22 23:26:48 +00:00
|
|
|
packetize->MPEG2 = FALSE;
|
|
|
|
}
|
|
|
|
|
2005-11-14 21:20:21 +00:00
|
|
|
return read_cache (packetize, length, outbuf);
|
2001-12-22 23:26:48 +00:00
|
|
|
}
|
|
|
|
|
2005-11-14 21:20:21 +00:00
|
|
|
static GstFlowReturn
|
|
|
|
parse_end (GstMPEGPacketize * packetize, GstBuffer ** outbuf)
|
2003-03-28 17:33:20 +00:00
|
|
|
{
|
2005-11-14 21:20:21 +00:00
|
|
|
return read_cache (packetize, 4, outbuf);
|
2003-03-28 17:33:20 +00:00
|
|
|
}
|
|
|
|
|
2005-11-14 21:20:21 +00:00
|
|
|
static GstFlowReturn
|
|
|
|
parse_generic (GstMPEGPacketize * packetize, GstBuffer ** outbuf)
|
2001-12-22 23:26:48 +00:00
|
|
|
{
|
|
|
|
guchar *buf;
|
2005-11-14 21:20:21 +00:00
|
|
|
guint length = 6;
|
|
|
|
guint got_bytes;
|
2001-12-22 23:26:48 +00:00
|
|
|
|
2003-06-29 19:46:09 +00:00
|
|
|
GST_DEBUG ("packetize: in parse_generic");
|
2001-12-22 23:26:48 +00:00
|
|
|
|
2005-11-14 21:20:21 +00:00
|
|
|
got_bytes = peek_cache (packetize, length, &buf);
|
|
|
|
if (got_bytes < length)
|
|
|
|
return GST_FLOW_RESEND;
|
2003-03-28 17:33:20 +00:00
|
|
|
|
2001-12-22 23:26:48 +00:00
|
|
|
buf += 4;
|
|
|
|
|
configure.ac: bump required gstreamer version to 0.8.1.1 because of following changes [--ds]
Original commit message from CVS:
reviewed by David Schleef
* configure.ac: bump required gstreamer version to 0.8.1.1
because of following changes [--ds]
* gst-libs/gst/riff/riff-read.c: Include gst/gstutils.h.
(gst_riff_peek_head, gst_riff_peek_list, gst_riff_read_list)
(gst_riff_read_header): Use GST_READ_UINT*
macros to access possibly unaligned memory.
* gst/typefind/gsttypefindfunctions.c: Include gst/gstutils.h.
(mp3_type_find): Use GST_READ_UINT*
macros to access possibly unaligned memory.
(mp3_type_find, mpeg1_parse_header, qt_type_find)
(speex_type_find): Likewise
* gst/tags/gstvorbistag.c: (ADVANCE): Likewise
* gst/qtdemux/qtdemux.c: Include stdlib.h (needed by realloc).
(QTDEMUX_GUINT32_GET, QTDEMUX_GUINT16_GET, QTDEMUX_FP32_GET)
(QTDEMUX_FP16_GET, QTDEMUX_FOURCC_GET)
(gst_qtdemux_loop_header, gst_qtdemux_loop_header)
(qtdemux_node_dump_foreach, qtdemux_tree_get_child_by_type)
(qtdemux_tree_get_sibling_by_type): Use GST_READ_UINT*
macros to access possibly unaligned memory.
* gst/mpegstream/gstmpegpacketize.c: (parse_generic, parse_chunk):
Likewise.
* gst/mpegstream/gstmpegdemux.c: (gst_mpeg_demux_parse_syshead)
(gst_mpeg_demux_parse_packet, gst_mpeg_demux_parse_pes): Likewise.
* gst/mpegaudioparse/gstmpegaudioparse.c: (gst_mp3parse_chain):
Likewise.
* gst/mpeg2sub/gstmpeg2subt.c: (GST_BUFFER_DATA)
(gst_mpeg2subt_chain_subtitle): Likewise.
* gst/mpeg1videoparse/gstmp1videoparse.c: (mp1videoparse_parse_seq)
(gst_mp1videoparse_time_code, gst_mp1videoparse_real_chain):
Likewise.
* gst/mpeg1sys/buffer.c: (mpeg1mux_buffer_update_audio_info):
Likewise.
* gst/cdxaparse/gstcdxaparse.c: (gst_bytestream_peek_bytes):
Likewise.
* gst/asfdemux/gstasfdemux.c: (_read_var_length, _read_uint):
Likewise.
2004-04-20 21:04:22 +00:00
|
|
|
length += GST_READ_UINT16_BE (buf);
|
2003-06-29 19:46:09 +00:00
|
|
|
GST_DEBUG ("packetize: header_length %d", length);
|
2001-12-22 23:26:48 +00:00
|
|
|
|
2005-11-14 21:20:21 +00:00
|
|
|
return read_cache (packetize, length, outbuf);
|
2001-12-22 23:26:48 +00:00
|
|
|
}
|
|
|
|
|
2005-11-14 21:20:21 +00:00
|
|
|
static GstFlowReturn
|
|
|
|
parse_chunk (GstMPEGPacketize * packetize, GstBuffer ** outbuf)
|
2001-12-31 03:03:05 +00:00
|
|
|
{
|
|
|
|
guchar *buf;
|
|
|
|
gint offset;
|
|
|
|
guint32 code;
|
2005-11-14 21:20:21 +00:00
|
|
|
guint chunksize;
|
2001-12-31 03:03:05 +00:00
|
|
|
|
2005-11-14 21:20:21 +00:00
|
|
|
chunksize = peek_cache (packetize, 4096, &buf);
|
2003-01-19 13:42:43 +00:00
|
|
|
if (chunksize == 0)
|
2005-11-14 21:20:21 +00:00
|
|
|
return GST_FLOW_RESEND;
|
2003-03-28 17:33:20 +00:00
|
|
|
|
2001-12-31 03:03:05 +00:00
|
|
|
offset = 4;
|
|
|
|
|
configure.ac: bump required gstreamer version to 0.8.1.1 because of following changes [--ds]
Original commit message from CVS:
reviewed by David Schleef
* configure.ac: bump required gstreamer version to 0.8.1.1
because of following changes [--ds]
* gst-libs/gst/riff/riff-read.c: Include gst/gstutils.h.
(gst_riff_peek_head, gst_riff_peek_list, gst_riff_read_list)
(gst_riff_read_header): Use GST_READ_UINT*
macros to access possibly unaligned memory.
* gst/typefind/gsttypefindfunctions.c: Include gst/gstutils.h.
(mp3_type_find): Use GST_READ_UINT*
macros to access possibly unaligned memory.
(mp3_type_find, mpeg1_parse_header, qt_type_find)
(speex_type_find): Likewise
* gst/tags/gstvorbistag.c: (ADVANCE): Likewise
* gst/qtdemux/qtdemux.c: Include stdlib.h (needed by realloc).
(QTDEMUX_GUINT32_GET, QTDEMUX_GUINT16_GET, QTDEMUX_FP32_GET)
(QTDEMUX_FP16_GET, QTDEMUX_FOURCC_GET)
(gst_qtdemux_loop_header, gst_qtdemux_loop_header)
(qtdemux_node_dump_foreach, qtdemux_tree_get_child_by_type)
(qtdemux_tree_get_sibling_by_type): Use GST_READ_UINT*
macros to access possibly unaligned memory.
* gst/mpegstream/gstmpegpacketize.c: (parse_generic, parse_chunk):
Likewise.
* gst/mpegstream/gstmpegdemux.c: (gst_mpeg_demux_parse_syshead)
(gst_mpeg_demux_parse_packet, gst_mpeg_demux_parse_pes): Likewise.
* gst/mpegaudioparse/gstmpegaudioparse.c: (gst_mp3parse_chain):
Likewise.
* gst/mpeg2sub/gstmpeg2subt.c: (GST_BUFFER_DATA)
(gst_mpeg2subt_chain_subtitle): Likewise.
* gst/mpeg1videoparse/gstmp1videoparse.c: (mp1videoparse_parse_seq)
(gst_mp1videoparse_time_code, gst_mp1videoparse_real_chain):
Likewise.
* gst/mpeg1sys/buffer.c: (mpeg1mux_buffer_update_audio_info):
Likewise.
* gst/cdxaparse/gstcdxaparse.c: (gst_bytestream_peek_bytes):
Likewise.
* gst/asfdemux/gstasfdemux.c: (_read_var_length, _read_uint):
Likewise.
2004-04-20 21:04:22 +00:00
|
|
|
code = GST_READ_UINT32_BE (buf + offset);
|
2001-12-31 03:03:05 +00:00
|
|
|
|
2003-06-29 19:46:09 +00:00
|
|
|
GST_DEBUG ("code = %08x", code);
|
2001-12-31 03:03:05 +00:00
|
|
|
|
|
|
|
while ((code & 0xffffff00) != 0x100L) {
|
|
|
|
code = (code << 8) | buf[offset++];
|
2004-03-14 22:34:30 +00:00
|
|
|
|
2003-06-29 19:46:09 +00:00
|
|
|
GST_DEBUG (" code = %08x", code);
|
2001-12-31 03:03:05 +00:00
|
|
|
|
2003-01-19 13:42:43 +00:00
|
|
|
if (offset == chunksize) {
|
2005-11-14 21:20:21 +00:00
|
|
|
chunksize = peek_cache (packetize, offset + 4096, &buf);
|
2003-01-19 13:42:43 +00:00
|
|
|
if (chunksize == 0)
|
2005-11-14 21:20:21 +00:00
|
|
|
return GST_FLOW_RESEND;
|
2003-01-19 13:42:43 +00:00
|
|
|
chunksize += offset;
|
2001-12-31 03:03:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (offset > 4) {
|
2005-11-14 21:20:21 +00:00
|
|
|
return read_cache (packetize, offset - 4, outbuf);
|
2001-12-31 03:03:05 +00:00
|
|
|
}
|
2005-11-14 21:20:21 +00:00
|
|
|
return GST_FLOW_RESEND;
|
2001-12-31 03:03:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-12-22 23:26:48 +00:00
|
|
|
/* FIXME mmx-ify me */
|
2005-11-14 21:20:21 +00:00
|
|
|
static gboolean
|
2004-03-14 22:34:30 +00:00
|
|
|
find_start_code (GstMPEGPacketize * packetize)
|
2001-12-22 23:26:48 +00:00
|
|
|
{
|
2005-11-14 21:20:21 +00:00
|
|
|
guint8 *buf;
|
2001-12-22 23:26:48 +00:00
|
|
|
gint offset;
|
|
|
|
guint32 code;
|
2003-01-19 13:42:43 +00:00
|
|
|
gint chunksize;
|
2001-12-22 23:26:48 +00:00
|
|
|
|
2005-11-14 21:20:21 +00:00
|
|
|
chunksize = peek_cache (packetize, 4096, &buf);
|
2003-03-28 17:33:20 +00:00
|
|
|
if (chunksize < 5)
|
2001-12-22 23:26:48 +00:00
|
|
|
return FALSE;
|
2003-03-28 17:33:20 +00:00
|
|
|
|
2001-12-22 23:26:48 +00:00
|
|
|
offset = 4;
|
|
|
|
|
configure.ac: bump required gstreamer version to 0.8.1.1 because of following changes [--ds]
Original commit message from CVS:
reviewed by David Schleef
* configure.ac: bump required gstreamer version to 0.8.1.1
because of following changes [--ds]
* gst-libs/gst/riff/riff-read.c: Include gst/gstutils.h.
(gst_riff_peek_head, gst_riff_peek_list, gst_riff_read_list)
(gst_riff_read_header): Use GST_READ_UINT*
macros to access possibly unaligned memory.
* gst/typefind/gsttypefindfunctions.c: Include gst/gstutils.h.
(mp3_type_find): Use GST_READ_UINT*
macros to access possibly unaligned memory.
(mp3_type_find, mpeg1_parse_header, qt_type_find)
(speex_type_find): Likewise
* gst/tags/gstvorbistag.c: (ADVANCE): Likewise
* gst/qtdemux/qtdemux.c: Include stdlib.h (needed by realloc).
(QTDEMUX_GUINT32_GET, QTDEMUX_GUINT16_GET, QTDEMUX_FP32_GET)
(QTDEMUX_FP16_GET, QTDEMUX_FOURCC_GET)
(gst_qtdemux_loop_header, gst_qtdemux_loop_header)
(qtdemux_node_dump_foreach, qtdemux_tree_get_child_by_type)
(qtdemux_tree_get_sibling_by_type): Use GST_READ_UINT*
macros to access possibly unaligned memory.
* gst/mpegstream/gstmpegpacketize.c: (parse_generic, parse_chunk):
Likewise.
* gst/mpegstream/gstmpegdemux.c: (gst_mpeg_demux_parse_syshead)
(gst_mpeg_demux_parse_packet, gst_mpeg_demux_parse_pes): Likewise.
* gst/mpegaudioparse/gstmpegaudioparse.c: (gst_mp3parse_chain):
Likewise.
* gst/mpeg2sub/gstmpeg2subt.c: (GST_BUFFER_DATA)
(gst_mpeg2subt_chain_subtitle): Likewise.
* gst/mpeg1videoparse/gstmp1videoparse.c: (mp1videoparse_parse_seq)
(gst_mp1videoparse_time_code, gst_mp1videoparse_real_chain):
Likewise.
* gst/mpeg1sys/buffer.c: (mpeg1mux_buffer_update_audio_info):
Likewise.
* gst/cdxaparse/gstcdxaparse.c: (gst_bytestream_peek_bytes):
Likewise.
* gst/asfdemux/gstasfdemux.c: (_read_var_length, _read_uint):
Likewise.
2004-04-20 21:04:22 +00:00
|
|
|
code = GST_READ_UINT32_BE (buf);
|
2001-12-22 23:26:48 +00:00
|
|
|
|
2003-06-29 19:46:09 +00:00
|
|
|
GST_DEBUG ("code = %08x %p %08x", code, buf, chunksize);
|
2001-12-22 23:26:48 +00:00
|
|
|
|
|
|
|
while ((code & 0xffffff00) != 0x100L) {
|
|
|
|
code = (code << 8) | buf[offset++];
|
2004-03-14 22:34:30 +00:00
|
|
|
|
2003-06-29 19:46:09 +00:00
|
|
|
GST_DEBUG (" code = %08x %p %08x", code, buf, chunksize);
|
2001-12-22 23:26:48 +00:00
|
|
|
|
|
|
|
if (offset == chunksize) {
|
2005-11-14 21:20:21 +00:00
|
|
|
skip_cache (packetize, offset);
|
2003-01-19 13:42:43 +00:00
|
|
|
|
2005-11-14 21:20:21 +00:00
|
|
|
chunksize = peek_cache (packetize, 4096, &buf);
|
2003-01-19 13:42:43 +00:00
|
|
|
if (chunksize == 0)
|
2004-03-15 19:32:25 +00:00
|
|
|
return FALSE;
|
2003-01-19 13:42:43 +00:00
|
|
|
|
2001-12-22 23:26:48 +00:00
|
|
|
offset = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
packetize->id = code & 0xff;
|
|
|
|
if (offset > 4) {
|
2005-11-14 21:20:21 +00:00
|
|
|
skip_cache (packetize, offset - 4);
|
2001-12-22 23:26:48 +00:00
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2005-11-14 21:20:21 +00:00
|
|
|
GstFlowReturn
|
|
|
|
gst_mpeg_packetize_read (GstMPEGPacketize * packetize, GstBuffer ** outbuf)
|
2001-12-22 23:26:48 +00:00
|
|
|
{
|
2005-11-14 21:20:21 +00:00
|
|
|
g_return_val_if_fail (packetize != NULL, GST_FLOW_ERROR);
|
2001-12-22 23:26:48 +00:00
|
|
|
|
2005-11-14 21:20:21 +00:00
|
|
|
*outbuf = NULL;
|
2003-03-28 17:33:20 +00:00
|
|
|
|
2005-11-14 21:20:21 +00:00
|
|
|
while (*outbuf == NULL) {
|
2001-12-22 23:26:48 +00:00
|
|
|
if (!find_start_code (packetize))
|
2005-11-14 21:20:21 +00:00
|
|
|
return GST_FLOW_RESEND;
|
|
|
|
|
|
|
|
GST_DEBUG ("packetize: have chunk 0x%02X", packetize->id);
|
|
|
|
if (packetize->type == GST_MPEG_PACKETIZE_SYSTEM) {
|
|
|
|
if (packetize->resync) {
|
|
|
|
if (packetize->id != PACK_START_CODE) {
|
|
|
|
skip_cache (packetize, 4);
|
|
|
|
continue;
|
2004-03-15 19:32:25 +00:00
|
|
|
}
|
2001-12-22 23:26:48 +00:00
|
|
|
|
2005-11-14 21:20:21 +00:00
|
|
|
packetize->resync = FALSE;
|
2001-12-22 23:26:48 +00:00
|
|
|
}
|
2005-11-14 21:20:21 +00:00
|
|
|
switch (packetize->id) {
|
|
|
|
case PACK_START_CODE:
|
|
|
|
return parse_packhead (packetize, outbuf);
|
|
|
|
case SYS_HEADER_START_CODE:
|
|
|
|
return parse_generic (packetize, outbuf);
|
|
|
|
case ISO11172_END_START_CODE:
|
|
|
|
return parse_end (packetize, outbuf);
|
|
|
|
default:
|
|
|
|
if (packetize->MPEG2 && ((packetize->id < 0xBD)
|
|
|
|
|| (packetize->id > 0xFE))) {
|
|
|
|
skip_cache (packetize, 4);
|
|
|
|
g_warning ("packetize: ******** unknown id 0x%02X", packetize->id);
|
|
|
|
} else {
|
|
|
|
return parse_generic (packetize, outbuf);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (packetize->type == GST_MPEG_PACKETIZE_VIDEO) {
|
|
|
|
return parse_chunk (packetize, outbuf);
|
|
|
|
} else {
|
|
|
|
g_assert_not_reached ();
|
|
|
|
}
|
|
|
|
}
|
2001-12-22 23:26:48 +00:00
|
|
|
|
2005-11-14 21:20:21 +00:00
|
|
|
g_assert_not_reached ();
|
2010-01-22 14:55:14 +00:00
|
|
|
return GST_FLOW_ERROR;
|
2001-12-22 23:26:48 +00:00
|
|
|
}
|