Mercurial > audlegacy
comparison src/libaudtag/wma/guid.c @ 4887:0ddbd0025174 default tip
added libaudtag. (not used yet.)
| author | Yoshiki Yazawa <yaz@honeyplanet.jp> |
|---|---|
| date | Wed, 05 May 2010 18:26:06 +0900 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| 4886:54b4f7aaca24 | 4887:0ddbd0025174 |
|---|---|
| 1 /* | |
| 2 * Copyright 2009 Paula Stanciu | |
| 3 * | |
| 4 * This file is part of Audacious. | |
| 5 * | |
| 6 * Audacious is free software: you can redistribute it and/or modify it under | |
| 7 * the terms of the GNU General Public License as published by the Free Software | |
| 8 * Foundation, version 3 of the License. | |
| 9 * | |
| 10 * Audacious is distributed in the hope that it will be useful, but WITHOUT ANY | |
| 11 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR | |
| 12 * A PARTICULAR PURPOSE. See the GNU General Public License for more details. | |
| 13 * | |
| 14 * You should have received a copy of the GNU General Public License along with | |
| 15 * Audacious. If not, see <http://www.gnu.org/licenses/>. | |
| 16 * | |
| 17 * The Audacious team does not consider modular code linking to Audacious or | |
| 18 * using our public API to be a derived work. | |
| 19 */ | |
| 20 | |
| 21 /* this stuff may be moved to ../util.h if needed by other formats */ | |
| 22 | |
| 23 #include <inttypes.h> | |
| 24 | |
| 25 #include "audlegacy/vfs.h" | |
| 26 #include "../util.h" | |
| 27 #include "guid.h" | |
| 28 #include "wma_fmt.h" | |
| 29 | |
| 30 GUID *guid_read_from_file(VFSFile * f) | |
| 31 { | |
| 32 GUID temp; | |
| 33 | |
| 34 if ((f == NULL) || (vfs_fread(&temp, sizeof(GUID), 1, f) != 1)) | |
| 35 return NULL; | |
| 36 | |
| 37 temp.le32 = GUINT32_FROM_LE(temp.le32); | |
| 38 temp.le16_1 = GUINT16_FROM_LE(temp.le16_1); | |
| 39 temp.le16_2 = GUINT16_FROM_LE(temp.le16_2); | |
| 40 temp.be64 = GUINT64_FROM_BE(temp.be64); | |
| 41 | |
| 42 return g_memdup(&temp, sizeof(GUID)); | |
| 43 } | |
| 44 | |
| 45 gboolean guid_write_to_file(VFSFile * f, int guid_type) | |
| 46 { | |
| 47 g_return_val_if_fail(f != NULL, FALSE); | |
| 48 | |
| 49 GUID *g = guid_convert_from_string(wma_guid_map(guid_type)); | |
| 50 | |
| 51 gboolean ret = write_LEuint32(f, g->le32) && write_LEuint16(f, g->le16_1) && write_LEuint16(f, g->le16_1) && write_LEuint64(f, g->be64); | |
| 52 g_free(g); | |
| 53 return ret; | |
| 54 } | |
| 55 | |
| 56 GUID *guid_convert_from_string(const gchar * string) | |
| 57 { | |
| 58 GUID temp; | |
| 59 | |
| 60 if (sscanf(string, "%" SCNx32 "-%" SCNx16 "-%" SCNx16 "-%" SCNx64, &temp.le32, &temp.le16_1, &temp.le16_2, &temp.be64) != 4) | |
| 61 return NULL; | |
| 62 return g_memdup(&temp, sizeof(GUID)); | |
| 63 } | |
| 64 | |
| 65 gchar *guid_convert_to_string(const GUID * g) | |
| 66 { | |
| 67 | |
| 68 return g_strdup_printf("%8x-%hx-%hx-%" PRIx64 "\n", GUINT32_TO_LE(g->le32), GUINT16_TO_LE(g->le16_1), GUINT16_TO_LE(g->le16_2), GUINT64_TO_BE(g->be64)); | |
| 69 } | |
| 70 | |
| 71 gboolean guid_equal(GUID * g1, GUID * g2) | |
| 72 { | |
| 73 /* | |
| 74 AUDDBG("GUID 1 = %8x-%hx-%hx-%"PRIx64"\n", g1->le32, g1->le16_1, g1->le16_2, g1->be64); | |
| 75 AUDDBG("GUID 2 = %8x-%hx-%hx-%"PRIx64"\n", g2->le32, g2->le16_1, g2->le16_2, g2->be64); | |
| 76 */ | |
| 77 | |
| 78 g_return_val_if_fail((g1 != NULL) && (g2 != NULL), FALSE); | |
| 79 if (!memcmp(g1, g2, 16)) | |
| 80 { | |
| 81 // AUDDBG("equal\n"); | |
| 82 | |
| 83 return TRUE; | |
| 84 } | |
| 85 /* AUDDBG("not equal\n"); */ | |
| 86 return FALSE; | |
| 87 } | |
| 88 | |
| 89 int get_guid_type(GUID * g) | |
| 90 { | |
| 91 GUID *g1; | |
| 92 int i; | |
| 93 for (i = 0; i < ASF_OBJECT_LAST - 1; i++) | |
| 94 { | |
| 95 g1 = guid_convert_from_string(wma_guid_map(i)); | |
| 96 if (guid_equal(g, g1)) | |
| 97 { | |
| 98 | |
| 99 g_free(g1); | |
| 100 return i; | |
| 101 } | |
| 102 } | |
| 103 return -1; | |
| 104 } | |
| 105 | |
| 106 const gchar *wma_guid_map(int i) | |
| 107 { | |
| 108 const gchar *_guid_map[ASF_OBJECT_LAST] = { | |
| 109 ASF_HEADER_OBJECT_GUID, | |
| 110 ASF_FILE_PROPERTIES_OBJECT_GUID, | |
| 111 ASF_STREAM_PROPERTIES_OBJECT_GUID, | |
| 112 ASF_HEADER_EXTENSION_OBJECT_GUID, | |
| 113 ASF_CODEC_LIST_OBJECT_GUID, | |
| 114 ASF_SCRIPT_COMMAND_OBJECT_GUID, | |
| 115 ASF_MARKER_OBJECT_GUID, | |
| 116 ASF_BITRATE_MUTUAL_EXCLUSION_OBJECT_GUID, | |
| 117 ASF_ERROR_CORRECTION_OBJECT_GUID, | |
| 118 ASF_CONTENT_DESCRIPTION_OBJECT_GUID, | |
| 119 ASF_EXTENDED_CONTENT_DESCRIPTION_OBJECT_GUID, | |
| 120 ASF_CONTENT_BRANDING_OBJECT_GUID, | |
| 121 ASF_STREAM_BITRATE_PROPERTIES_OBJECT_GUID, | |
| 122 ASF_CONTENT_ENCRYPTION_OBJECT_GUID, | |
| 123 ASF_EXTENDED_CONTENT_ENCRYPTION_OBJECT_GUID, | |
| 124 ASF_DIGITAL_SIGNATURE_OBJECT_GUID, | |
| 125 ASF_PADDING_OBJECT_GUID | |
| 126 }; | |
| 127 return _guid_map[i]; | |
| 128 } |
