Mercurial > audlegacy-plugins
annotate src/flacng/seekable_stream_callbacks.c @ 3015:9e26c15e78b7
Overdoing the pointer voodoo that much is a strict-aliasing violation.
author | Tony Vroon <chainsaw@gentoo.org> |
---|---|
date | Wed, 08 Apr 2009 23:32:18 +0100 |
parents | f1b6f1b2cdb3 |
children |
rev | line source |
---|---|
930
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
1 /* |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
2 * A FLAC decoder plugin for the Audacious Media Player |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
3 * Copyright (C) 2005 Ralf Ertzinger |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
4 * |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
5 * This program is free software; you can redistribute it and/or modify |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
6 * it under the terms of the GNU General Public License as published by |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
7 * the Free Software Foundation; either version 2 of the License, or |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
8 * (at your option) any later version. |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
9 * |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
10 * This program is distributed in the hope that it will be useful, |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
13 * GNU General Public License for more details. |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
14 * |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
15 * You should have received a copy of the GNU General Public License |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
16 * along with this program; if not, write to the Free Software |
2835 | 17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
930
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
18 */ |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
19 |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
20 #include <string.h> |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
21 #include <FLAC/all.h> |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
22 #include <glib.h> |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
23 #include "flacng.h" |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
24 #include "tools.h" |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
25 #include "seekable_stream_callbacks.h" |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
26 #include "debug.h" |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
27 |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
28 /* === */ |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
29 |
1187
875baf383f0c
suppress warnings on AMD64.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
1041
diff
changeset
|
30 FLAC__StreamDecoderReadStatus read_callback(const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], size_t *bytes, void *client_data) { |
930
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
31 |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
32 callback_info* info; |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
33 gint to_read; |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
34 size_t read; |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
35 |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
36 _ENTER; |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
37 |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
38 info = (callback_info*) client_data; |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
39 _DEBUG("Using callback_info %s", info->name); |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
40 |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
41 if (NULL == info->input_stream) { |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
42 _ERROR("Trying to read data from an uninitialized file!"); |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
43 _LEAVE FLAC__STREAM_DECODER_READ_STATUS_ABORT; |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
44 } |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
45 |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
46 if (0 <= info->read_max) { |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
47 to_read = MIN(*bytes, info->read_max); |
1246 | 48 _DEBUG("Reading restricted to %ld bytes", info->read_max); |
930
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
49 } else { |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
50 to_read = *bytes; |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
51 } |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
52 |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
53 if (0 == to_read) { |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
54 _LEAVE FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM; |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
55 } |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
56 |
1978 | 57 read = aud_vfs_fread(buffer, 1, to_read, info->input_stream); |
930
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
58 |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
59 if ((0 < read) && (0 < info->read_max)) { |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
60 info->read_max -= read; |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
61 } |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
62 |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
63 _DEBUG("Wanted %d bytes, got %d bytes", *bytes, read); |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
64 *bytes = read; |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
65 |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
66 switch(read) { |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
67 case -1: |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
68 _ERROR("Error while reading from stream!"); |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
69 _LEAVE FLAC__STREAM_DECODER_READ_STATUS_ABORT; |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
70 break; |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
71 |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
72 case 0: |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
73 _DEBUG("Stream reached EOF"); |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
74 _LEAVE FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM; |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
75 break; |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
76 |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
77 default: |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
78 _LEAVE FLAC__STREAM_DECODER_READ_STATUS_CONTINUE; |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
79 } |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
80 } |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
81 |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
82 /* --- */ |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
83 |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
84 FLAC__StreamDecoderSeekStatus seek_callback(const FLAC__StreamDecoder *decoder, FLAC__uint64 absolute_byte_offset, void *client_data) { |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
85 |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
86 callback_info* info; |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
87 |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
88 _ENTER; |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
89 |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
90 info = (callback_info*) client_data; |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
91 _DEBUG("Using callback_info %s", info->name); |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
92 |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
93 _DEBUG("Seeking to %lld", absolute_byte_offset); |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
94 |
1978 | 95 if (0 != aud_vfs_fseek(info->input_stream, absolute_byte_offset, SEEK_SET)) { |
1187
875baf383f0c
suppress warnings on AMD64.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
1041
diff
changeset
|
96 _ERROR("Could not seek to %lld!", (long long)absolute_byte_offset); |
930
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
97 _LEAVE FLAC__STREAM_DECODER_SEEK_STATUS_ERROR; |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
98 } |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
99 |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
100 _LEAVE FLAC__STREAM_DECODER_SEEK_STATUS_OK; |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
101 } |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
102 |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
103 /* --- */ |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
104 |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
105 FLAC__StreamDecoderTellStatus tell_callback(const FLAC__StreamDecoder *decoder, FLAC__uint64 *absolute_byte_offset, void *client_data) { |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
106 |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
107 callback_info* info; |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
108 glong position; |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
109 |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
110 _ENTER; |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
111 |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
112 info = (callback_info*) client_data; |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
113 _DEBUG("Using callback_info %s", info->name); |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
114 |
1978 | 115 if (-1 == (position = aud_vfs_ftell(info->input_stream))) { |
931 | 116 _ERROR("Could not tell current position!"); |
1272
47559538ce3d
- stop read_metadata from stomping on the wrong file descriptors
Ralf Ertzinger <ralf@skytale.net>
parents:
1259
diff
changeset
|
117 _LEAVE FLAC__STREAM_DECODER_TELL_STATUS_ERROR; |
930
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
118 } |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
119 |
1246 | 120 _DEBUG("Current position: %ld", position); |
930
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
121 |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
122 *absolute_byte_offset = position; |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
123 |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
124 _LEAVE FLAC__STREAM_DECODER_TELL_STATUS_OK; |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
125 } |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
126 |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
127 /* --- */ |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
128 |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
129 FLAC__bool eof_callback(const FLAC__StreamDecoder *decoder, void *client_data) { |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
130 |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
131 callback_info* info; |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
132 gboolean eof; |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
133 |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
134 _ENTER; |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
135 |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
136 info = (callback_info*) client_data; |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
137 _DEBUG("Using callback_info %s", info->name); |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
138 |
1259
690659633ec5
- Fix endless looping on certain unparseable streams
Ralf Ertzinger <ralf@skytale.net>
parents:
1246
diff
changeset
|
139 /* |
690659633ec5
- Fix endless looping on certain unparseable streams
Ralf Ertzinger <ralf@skytale.net>
parents:
1246
diff
changeset
|
140 * If we are testing a stream and use restricted reading, |
690659633ec5
- Fix endless looping on certain unparseable streams
Ralf Ertzinger <ralf@skytale.net>
parents:
1246
diff
changeset
|
141 * return EOF if we have exhausted our alotted reading |
690659633ec5
- Fix endless looping on certain unparseable streams
Ralf Ertzinger <ralf@skytale.net>
parents:
1246
diff
changeset
|
142 * quota |
690659633ec5
- Fix endless looping on certain unparseable streams
Ralf Ertzinger <ralf@skytale.net>
parents:
1246
diff
changeset
|
143 */ |
690659633ec5
- Fix endless looping on certain unparseable streams
Ralf Ertzinger <ralf@skytale.net>
parents:
1246
diff
changeset
|
144 if (0 == info->read_max) { |
690659633ec5
- Fix endless looping on certain unparseable streams
Ralf Ertzinger <ralf@skytale.net>
parents:
1246
diff
changeset
|
145 _DEBUG("read_max exhausted, faking EOF"); |
1272
47559538ce3d
- stop read_metadata from stomping on the wrong file descriptors
Ralf Ertzinger <ralf@skytale.net>
parents:
1259
diff
changeset
|
146 _LEAVE TRUE; |
1259
690659633ec5
- Fix endless looping on certain unparseable streams
Ralf Ertzinger <ralf@skytale.net>
parents:
1246
diff
changeset
|
147 } |
690659633ec5
- Fix endless looping on certain unparseable streams
Ralf Ertzinger <ralf@skytale.net>
parents:
1246
diff
changeset
|
148 |
1978 | 149 eof = aud_vfs_feof(info->input_stream); |
930
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
150 |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
151 _LEAVE eof; |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
152 } |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
153 |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
154 /* --- */ |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
155 |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
156 FLAC__StreamDecoderLengthStatus length_callback(const FLAC__StreamDecoder *decoder, FLAC__uint64 *stream_length, void *client_data) { |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
157 |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
158 callback_info* info; |
966 | 159 off_t size; |
930
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
160 |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
161 _ENTER; |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
162 |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
163 info = (callback_info*) client_data; |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
164 _DEBUG("Using callback_info %s", info->name); |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
165 |
1978 | 166 if (-1 == (size = aud_vfs_fsize(info->input_stream))) { |
966 | 167 /* |
168 * Could not get the stream size. This is not necessarily an | |
169 * error, maybe the stream has no fixed size (think streaming | |
170 * audio) | |
171 */ | |
172 _DEBUG("Stream length unknown"); | |
173 *stream_length = 0; | |
174 _LEAVE FLAC__STREAM_DECODER_LENGTH_STATUS_UNSUPPORTED; | |
931 | 175 } |
176 | |
1246 | 177 _DEBUG("Stream length is %ld bytes", size); |
966 | 178 *stream_length = size; |
930
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
179 |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
180 _LEAVE FLAC__STREAM_DECODER_LENGTH_STATUS_OK; |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
181 } |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
182 |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
183 /* --- */ |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
184 |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
185 FLAC__StreamDecoderWriteStatus write_callback(const FLAC__StreamDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data) { |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
186 |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
187 glong i; |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
188 gshort j; |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
189 callback_info* info; |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
190 |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
191 _ENTER; |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
192 |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
193 info = (callback_info*) client_data; |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
194 _DEBUG("Using callback_info %s", info->name); |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
195 |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
196 _DEBUG("Frame decoded: %d samples per channel, %d channels, %d bps", |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
197 frame->header.blocksize, frame->header.channels, frame->header.bits_per_sample); |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
198 |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
199 /* |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
200 * Check if there is more data decoded than we have space |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
201 * for. This _should_ not happen given how our buffer is sized, |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
202 * but you never know. |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
203 */ |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
204 if (info->buffer_free < (frame->header.blocksize * frame->header.channels)) { |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
205 _ERROR("BUG! Too much data decoded from stream!"); |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
206 _LEAVE FLAC__STREAM_DECODER_WRITE_STATUS_ABORT; |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
207 } |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
208 |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
209 if ((frame->header.bits_per_sample != 8) && |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
210 (frame->header.bits_per_sample != 16) && |
2360
ead24454f4b7
native 24bit output for FLAC
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
1978
diff
changeset
|
211 (frame->header.bits_per_sample != 24) && |
ead24454f4b7
native 24bit output for FLAC
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
1978
diff
changeset
|
212 (frame->header.bits_per_sample != 32)) { |
930
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
213 _ERROR("Unsupported bitrate found in stream: %d!", frame->header.bits_per_sample); |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
214 _LEAVE FLAC__STREAM_DECODER_WRITE_STATUS_ABORT; |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
215 } |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
216 |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
217 /* |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
218 * Copy the frame metadata, will be compared to stream |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
219 * metadata later |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
220 * This also describes the format of the current buffer content. |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
221 */ |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
222 info->frame.channels = frame->header.channels; |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
223 info->frame.samplerate = frame->header.sample_rate; |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
224 info->frame.bits_per_sample = frame->header.bits_per_sample; |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
225 |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
226 for (i=0; i < frame->header.blocksize; i++) { |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
227 for (j=0; j < frame->header.channels; j++) { |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
228 *(info->write_pointer++) = buffer[j][i]; |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
229 info->buffer_free -= 1; |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
230 info->buffer_used += 1; |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
231 } |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
232 } |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
233 |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
234 _DEBUG("free space in buffer after copying: %d samples", info->buffer_free); |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
235 |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
236 _LEAVE FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE; |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
237 } |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
238 |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
239 /* --- */ |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
240 |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
241 void error_callback(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status, void *client_data) { |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
242 |
1041 | 243 callback_info* info = (callback_info*) client_data; |
244 | |
930
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
245 _ENTER; |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
246 |
1041 | 247 _DEBUG("Using callback_info %s", info->name); |
248 | |
249 if (!info->testing) { | |
250 _ERROR("FLAC decoder error callback was called: %d", status); | |
251 } else { | |
252 _DEBUG("FLAC decoder error callback was called: %d", status); | |
253 } | |
930
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
254 |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
255 _LEAVE; |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
256 |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
257 } |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
258 |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
259 /* --- */ |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
260 |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
261 void metadata_callback(const FLAC__StreamDecoder *decoder, const FLAC__StreamMetadata *metadata, void *client_data) { |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
262 |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
263 callback_info* info; |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
264 gint i; |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
265 FLAC__StreamMetadata_VorbisComment_Entry* entry; |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
266 FLAC__StreamMetadata* metadata_copy; |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
267 gchar* key; |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
268 gchar* value; |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
269 int artist_offset; |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
270 |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
271 _ENTER; |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
272 |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
273 info = (callback_info*) client_data; |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
274 _DEBUG("Using callback_info %s", info->name); |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
275 |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
276 /* |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
277 * We have found a metadata block. Enable unrestricted reading |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
278 */ |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
279 info->read_max = -1; |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
280 |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
281 if (FLAC__METADATA_TYPE_STREAMINFO == metadata->type) { |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
282 /* |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
283 * Basic stream information. Sample rate, channels and stuff |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
284 */ |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
285 _DEBUG("FLAC__METADATA_TYPE_STREAMINFO found"); |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
286 |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
287 info->stream.samples = metadata->data.stream_info.total_samples; |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
288 _DEBUG("total_samples=%lld", metadata->data.stream_info.total_samples); |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
289 info->stream.bits_per_sample = metadata->data.stream_info.bits_per_sample; |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
290 _DEBUG("bits_per_sample=%d", metadata->data.stream_info.bits_per_sample); |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
291 info->stream.channels = metadata->data.stream_info.channels; |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
292 _DEBUG("channels=%d", metadata->data.stream_info.channels); |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
293 info->stream.samplerate = metadata->data.stream_info.sample_rate; |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
294 _DEBUG("sample_rate=%d", metadata->data.stream_info.sample_rate); |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
295 |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
296 info->metadata_changed = TRUE; |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
297 } |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
298 |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
299 if (FLAC__METADATA_TYPE_VORBIS_COMMENT == metadata->type) { |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
300 /* |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
301 * We will possibly need to modify some of the entries |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
302 * in the metadata field, so we make a copy of it |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
303 * first. |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
304 * The original structure must not be modified. |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
305 */ |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
306 metadata_copy = FLAC__metadata_object_clone(metadata); |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
307 |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
308 /* |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
309 * A vorbis type comment field. |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
310 */ |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
311 _DEBUG("FLAC__METADATA_TYPE_VORBIS_COMMENT found"); |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
312 _DEBUG("Vorbis comment contains %d fields", metadata_copy->data.vorbis_comment.num_comments); |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
313 _DEBUG("Vendor string: %s", metadata_copy->data.vorbis_comment.vendor_string.entry); |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
314 |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
315 /* |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
316 * Find an ARTIST field |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
317 */ |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
318 if (0 <= (artist_offset = FLAC__metadata_object_vorbiscomment_find_entry_from(metadata_copy, 0, "ARTIST"))) { |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
319 _DEBUG("ARTIST field found @ %d: %s", artist_offset, |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
320 metadata_copy->data.vorbis_comment.comments[artist_offset].entry); |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
321 } |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
322 |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
323 |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
324 /* |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
325 * Enumerate the comment entries |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
326 */ |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
327 entry = metadata_copy->data.vorbis_comment.comments; |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
328 for (i=0; i < metadata_copy->data.vorbis_comment.num_comments; i++,entry++) { |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
329 _DEBUG("Comment[%d]: %s", i, entry->entry); |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
330 |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
331 /* |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
332 * Try and parse the comment. |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
333 * If FLAC__metadata_object_vorbiscomment_entry_to_name_value_pair() succeeds, |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
334 * it allocates memory for the key and value which we have to take |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
335 * care of. |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
336 */ |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
337 if (false == FLAC__metadata_object_vorbiscomment_entry_to_name_value_pair(*entry, &key, &value)) { |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
338 _DEBUG("Could not parse comment"); |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
339 } else { |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
340 _DEBUG("Key: <%s>, Value <%s>", key, value); |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
341 add_comment(info, key, value); |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
342 free(key); |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
343 free(value); |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
344 } |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
345 } |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
346 |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
347 /* |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
348 * Free our metadata copy |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
349 */ |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
350 FLAC__metadata_object_delete(metadata_copy); |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
351 |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
352 info->metadata_changed = TRUE; |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
353 } |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
354 |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
355 if (FLAC__METADATA_TYPE_SEEKTABLE == metadata->type) { |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
356 /* |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
357 * We have found a seektable, which means that we can seek |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
358 * without telling FLAC the length of the file (which we can not |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
359 * do, since Audacious lacks the functions for that) |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
360 */ |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
361 _DEBUG("FLAC__METADATA_TYPE_SEEKTABLE found"); |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
362 info->stream.has_seektable = TRUE; |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
363 } |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
364 |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
365 _LEAVE; |
2f742d127b3e
[svn] - initial import of flacng from audacious-flacng-0.012
nenolod
parents:
diff
changeset
|
366 } |