2009-07-01 12:49:57 +00:00
|
|
|
/* GStreamer QuickTime atom parser
|
|
|
|
* Copyright (C) 2009 Tim-Philipp Müller <tim centricular net>
|
2009-10-23 12:06:44 +00:00
|
|
|
* Copyright (C) <2009> STEricsson <benjamin.gaignard@stericsson.com>
|
2009-07-01 12:49:57 +00:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef QT_ATOM_PARSER_H
|
|
|
|
#define QT_ATOM_PARSER_H
|
|
|
|
|
|
|
|
#include <gst/base/gstbytereader.h>
|
|
|
|
|
|
|
|
/* our inlined version of GstByteReader */
|
|
|
|
|
2009-09-24 18:33:39 +00:00
|
|
|
static inline gboolean
|
2009-10-23 12:06:44 +00:00
|
|
|
qt_atom_parser_has_remaining (GstByteReader * parser, guint64 bytes_needed)
|
2009-09-24 18:33:39 +00:00
|
|
|
{
|
|
|
|
return G_LIKELY (parser->size >= bytes_needed) &&
|
|
|
|
G_LIKELY ((parser->size - bytes_needed) >= parser->byte);
|
|
|
|
}
|
2009-08-20 00:39:17 +00:00
|
|
|
|
2009-08-25 11:11:28 +00:00
|
|
|
static inline gboolean
|
2009-10-23 12:06:44 +00:00
|
|
|
qt_atom_parser_has_chunks (GstByteReader * parser, guint32 n_chunks,
|
2009-08-25 11:11:28 +00:00
|
|
|
guint32 chunk_size)
|
|
|
|
{
|
|
|
|
/* assumption: n_chunks and chunk_size are 32-bit, we cast to 64-bit here
|
|
|
|
* to avoid overflows, to handle e.g. (guint32)-1 * size correctly */
|
|
|
|
return qt_atom_parser_has_remaining (parser, (guint64) n_chunks * chunk_size);
|
|
|
|
}
|
|
|
|
|
2009-07-01 12:49:57 +00:00
|
|
|
static inline gboolean
|
2009-10-23 12:06:44 +00:00
|
|
|
qt_atom_parser_peek_sub (GstByteReader * parser, guint offset, guint size,
|
|
|
|
GstByteReader * sub)
|
2009-07-01 12:49:57 +00:00
|
|
|
{
|
|
|
|
*sub = *parser;
|
|
|
|
|
2009-10-23 12:06:44 +00:00
|
|
|
if (G_UNLIKELY (!gst_byte_reader_skip (sub, offset)))
|
2009-07-01 12:49:57 +00:00
|
|
|
return FALSE;
|
|
|
|
|
2009-10-23 12:06:44 +00:00
|
|
|
return (gst_byte_reader_get_remaining (sub) >= size);
|
2009-07-01 12:49:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline gboolean
|
2009-10-23 12:06:44 +00:00
|
|
|
qt_atom_parser_skipn_and_get_uint32 (GstByteReader * parser,
|
2009-07-01 12:49:57 +00:00
|
|
|
guint bytes_to_skip, guint32 * val)
|
|
|
|
{
|
2009-10-23 12:06:44 +00:00
|
|
|
if (G_UNLIKELY (gst_byte_reader_get_remaining (parser) < (bytes_to_skip + 4)))
|
2009-07-01 12:49:57 +00:00
|
|
|
return FALSE;
|
|
|
|
|
2009-10-23 12:06:44 +00:00
|
|
|
gst_byte_reader_skip_unchecked (parser, bytes_to_skip);
|
|
|
|
*val = gst_byte_reader_get_uint32_be_unchecked (parser);
|
2009-07-01 12:49:57 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2009-08-15 19:38:40 +00:00
|
|
|
/* off_size must be either 4 or 8 */
|
|
|
|
static inline gboolean
|
2009-10-23 12:06:44 +00:00
|
|
|
qt_atom_parser_get_offset (GstByteReader * parser, guint off_size,
|
|
|
|
guint64 * val)
|
2009-08-15 19:38:40 +00:00
|
|
|
{
|
2009-10-23 12:06:44 +00:00
|
|
|
if (G_UNLIKELY (gst_byte_reader_get_remaining (parser) < off_size))
|
2009-08-15 19:38:40 +00:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (off_size == sizeof (guint64)) {
|
2009-10-23 12:06:44 +00:00
|
|
|
*val = gst_byte_reader_get_uint64_be_unchecked (parser);
|
2009-08-15 19:38:40 +00:00
|
|
|
} else {
|
2009-10-23 12:06:44 +00:00
|
|
|
*val = gst_byte_reader_get_uint32_be_unchecked (parser);
|
2009-08-15 19:38:40 +00:00
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* off_size must be either 4 or 8 */
|
|
|
|
static inline guint64
|
2009-10-23 12:06:44 +00:00
|
|
|
qt_atom_parser_get_offset_unchecked (GstByteReader * parser, guint off_size)
|
2009-08-15 19:38:40 +00:00
|
|
|
{
|
|
|
|
if (off_size == sizeof (guint64)) {
|
2009-10-23 12:06:44 +00:00
|
|
|
return gst_byte_reader_get_uint64_be_unchecked (parser);
|
2009-08-15 19:38:40 +00:00
|
|
|
} else {
|
2009-10-23 12:06:44 +00:00
|
|
|
return gst_byte_reader_get_uint32_be_unchecked (parser);
|
2009-08-15 19:38:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-03-11 14:34:49 +00:00
|
|
|
/* size must be from 1 to 4 */
|
|
|
|
static inline guint32
|
|
|
|
qt_atom_parser_get_uint_with_size_unchecked (GstByteReader * parser,
|
|
|
|
guint size)
|
|
|
|
{
|
|
|
|
switch (size) {
|
|
|
|
case 1:
|
|
|
|
return gst_byte_reader_get_uint8_unchecked (parser);
|
|
|
|
case 2:
|
|
|
|
return gst_byte_reader_get_uint16_be_unchecked (parser);
|
|
|
|
case 3:
|
|
|
|
return gst_byte_reader_get_uint24_be_unchecked (parser);
|
|
|
|
case 4:
|
|
|
|
return gst_byte_reader_get_uint32_be_unchecked (parser);
|
|
|
|
default:
|
|
|
|
g_assert_not_reached ();
|
|
|
|
gst_byte_reader_skip_unchecked (parser, size);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-08-19 00:36:33 +00:00
|
|
|
static inline gboolean
|
2009-10-23 12:06:44 +00:00
|
|
|
qt_atom_parser_get_fourcc (GstByteReader * parser, guint32 * fourcc)
|
2009-08-19 00:36:33 +00:00
|
|
|
{
|
|
|
|
guint32 f_be;
|
|
|
|
|
2009-10-23 12:06:44 +00:00
|
|
|
if (G_UNLIKELY (gst_byte_reader_get_remaining (parser) < 4))
|
2009-08-19 00:36:33 +00:00
|
|
|
return FALSE;
|
|
|
|
|
2009-10-23 12:06:44 +00:00
|
|
|
f_be = gst_byte_reader_get_uint32_be_unchecked (parser);
|
2009-08-19 00:36:33 +00:00
|
|
|
*fourcc = GUINT32_SWAP_LE_BE (f_be);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline guint32
|
2009-10-23 12:06:44 +00:00
|
|
|
qt_atom_parser_get_fourcc_unchecked (GstByteReader * parser)
|
2009-08-19 00:36:33 +00:00
|
|
|
{
|
|
|
|
guint32 fourcc;
|
|
|
|
|
2009-10-23 12:06:44 +00:00
|
|
|
fourcc = gst_byte_reader_get_uint32_be_unchecked (parser);
|
2009-08-19 00:36:33 +00:00
|
|
|
return GUINT32_SWAP_LE_BE (fourcc);
|
|
|
|
}
|
|
|
|
|
2009-07-01 12:49:57 +00:00
|
|
|
#endif /* QT_ATOM_PARSER_H */
|