1 /* GStreamer Wavpack plugin
2 * Copyright (c) 2005 Arwed v. Merkatz <v.merkatz@gmx.net>
3 * Copyright (c) 1998 - 2005 Conifer Software
4 * Copyright (c) 2006 Sebastian Dröge <slomo@circular-chaos.org>
6 * gstwavpackcommon.c: common helper functions
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Library General Public License for more details.
18 * You should have received a copy of the GNU Library General Public
19 * License along with this library; if not, write to the
20 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21 * Boston, MA 02111-1307, USA.
28 #include "gstwavpackcommon.h"
31 GST_DEBUG_CATEGORY_EXTERN (wavpack_debug);
32 #define GST_CAT_DEFAULT wavpack_debug
35 gst_wavpack_read_header (WavpackHeader * header, guint8 * buf)
37 g_memmove (header, buf, sizeof (WavpackHeader));
39 #ifndef WAVPACK_OLD_API
40 WavpackLittleEndianToNative (header, WavpackHeaderFormat);
42 little_endian_to_native (header, WavpackHeaderFormat);
45 return (memcmp (header->ckID, "wvpk", 4) == 0);
48 /* inspired by the original one in wavpack */
50 gst_wavpack_read_metadata (GstWavpackMetadata * wpmd, guint8 * header_data,
56 gst_wavpack_read_header (&hdr, header_data);
57 end = header_data + hdr.ckSize + 8;
59 if (end - *p_data < 2)
62 wpmd->id = GST_READ_UINT8 (*p_data);
63 wpmd->byte_length = 2 * (guint) GST_READ_UINT8 (*p_data + 1);
67 if ((wpmd->id & ID_LARGE) == ID_LARGE) {
70 wpmd->id &= ~ID_LARGE;
72 if (end - *p_data < 2)
75 extra = GST_READ_UINT16_LE (*p_data);
76 wpmd->byte_length += (extra << 9);
80 if ((wpmd->id & ID_ODD_SIZE) == ID_ODD_SIZE) {
81 wpmd->id &= ~ID_ODD_SIZE;
85 if (wpmd->byte_length > 0) {
86 if (end - *p_data < wpmd->byte_length + (wpmd->byte_length & 1)) {
92 *p_data += wpmd->byte_length + (wpmd->byte_length & 1);