Project

General

Profile

feature1075.diff

Jim Turner, April 03, 2021 15:50

View differences:

src/flac/Makefile
14 14

  
15 15
CFLAGS += ${PLUGIN_CFLAGS}
16 16
CPPFLAGS += ${PLUGIN_CPPFLAGS} ${LIBFLAC_CFLAGS} -I../..
17
LIBS += ${LIBFLAC_LIBS}
17
LIBS += ${LIBFLAC_LIBS} -laudtag -lm
src/flac/metadata.cc
143 143

  
144 144
    chain = FLAC__metadata_chain_new();
145 145

  
146
    if (!FLAC__metadata_chain_read_with_callbacks(chain, &file, io_callbacks))
147
        goto ERR;
146
    String mime = file.get_metadata("content-type");
147
    if (FLAC_API_SUPPORTS_OGG_FLAC && mime && strstr(mime, "ogg"))
148
    {
149
        AUDERR("Tags in OGG/FLAC streams are currently readonly!");
150
        goto ERR_RETURN;
151
    }
152
    else
153
    {
154
        if (! FLAC__metadata_chain_read_with_callbacks(chain, &file, io_callbacks))
155
            goto ERR;
156
    }
148 157

  
149 158
    iter = FLAC__metadata_iterator_new();
150 159

  
......
275 284

  
276 285
    chain = FLAC__metadata_chain_new();
277 286

  
278
    if (!FLAC__metadata_chain_read_with_callbacks(chain, &file, io_callbacks))
279
        goto ERR;
287
    String mime = file.get_metadata("content-type");
288
    if (FLAC_API_SUPPORTS_OGG_FLAC && mime && strstr(mime, "ogg"))
289
    {
290
        if (! FLAC__metadata_chain_read_ogg_with_callbacks(chain, &file, io_callbacks))
291
            goto ERR;
292
    }
293
    else
294
    {
295
        if (! FLAC__metadata_chain_read_with_callbacks(chain, &file, io_callbacks))
296
            goto ERR;
297
    }
280 298

  
281 299
    iter = FLAC__metadata_iterator_new();
282 300

  
src/flac/plugin.cc
21 21
#include <string.h>
22 22

  
23 23
#include <libaudcore/runtime.h>
24
#include <audacious/audtag.h>
24 25

  
25 26
#include "flacng.h"
26 27

  
27 28
EXPORT FLACng aud_plugin_instance;
28 29

  
29
static FLAC__StreamDecoder *decoder;
30
static FLAC__StreamDecoder *decoder, *ogg_decoder;
30 31
static callback_info *cinfo;
31 32

  
32 33
bool FLACng::init()
......
60 61
        return false;
61 62
    }
62 63

  
64
    if (FLAC_API_SUPPORTS_OGG_FLAC && ((ogg_decoder = FLAC__stream_decoder_new()) == nullptr
65
            || FLAC__stream_decoder_init_ogg_stream(
66
        ogg_decoder,
67
        read_callback,
68
        seek_callback,
69
        tell_callback,
70
        length_callback,
71
        eof_callback,
72
        write_callback,
73
        metadata_callback,
74
        error_callback,
75
        cinfo)))
76
    {
77
        AUDWARN("Could not initialize the extra OGG FLAC decoder:  so no playing OGG-FLAC streams!\n");
78
    }
79

  
63 80
    AUDDBG("Plugin initialized.\n");
64 81
    return true;
65 82
}
66 83

  
67 84
void FLACng::cleanup()
68 85
{
86
    if (ogg_decoder)  FLAC__stream_decoder_delete(ogg_decoder);
69 87
    FLAC__stream_decoder_delete(decoder);
70 88
    delete cinfo;
71 89
}
......
115 133
{
116 134
    Index<char> play_buffer;
117 135
    bool error = false;
136
    bool stream = (file.fsize() < 0);
137
    Tuple tuple;
138
    if (stream)
139
    {
140
        tuple = get_playback_tuple();
141
        if (audtag::read_tag(file, tuple, nullptr))
142
            set_playback_tuple(tuple.ref());
143
    }
118 144

  
119 145
    cinfo->fd = &file;
120 146

  
121
    if (read_metadata(decoder, cinfo) == false)
147
    FLAC__StreamDecoder *which_decoder = decoder;
148
    if (FLAC_API_SUPPORTS_OGG_FLAC && ogg_decoder)
149
    {
150
        String mime = file.get_metadata("content-type");
151
        if (mime && strstr(mime, "ogg"))  which_decoder = ogg_decoder;
152
    }
153

  
154
    if (read_metadata(which_decoder, cinfo) == false)
122 155
    {
123 156
        AUDERR("Could not prepare file for playing!\n");
124 157
        error = true;
......
128 161
    play_buffer.resize(BUFFER_SIZE_BYTE);
129 162

  
130 163
    set_stream_bitrate(cinfo->bitrate);
164

  
165
    if (stream && tuple.fetch_stream_info(file))
166
        set_playback_tuple(tuple.ref());
167

  
131 168
    open_audio(SAMPLE_FMT(cinfo->bits_per_sample), cinfo->sample_rate, cinfo->channels);
132 169

  
133
    while (FLAC__stream_decoder_get_state(decoder) != FLAC__STREAM_DECODER_END_OF_STREAM)
170
    while (FLAC__stream_decoder_get_state(which_decoder) != FLAC__STREAM_DECODER_END_OF_STREAM)
134 171
    {
135 172
        if (check_stop ())
136 173
            break;
137 174

  
138 175
        int seek_value = check_seek ();
139 176
        if (seek_value >= 0)
140
            FLAC__stream_decoder_seek_absolute (decoder, (int64_t)
177
            FLAC__stream_decoder_seek_absolute(which_decoder, (int64_t)
141 178
             seek_value * cinfo->sample_rate / 1000);
142 179

  
143 180
        /* Try to decode a single frame of audio */
144
        if (FLAC__stream_decoder_process_single(decoder) == false)
181
        if (FLAC__stream_decoder_process_single(which_decoder) == false)
145 182
        {
146 183
            AUDERR("Error while decoding!\n");
147 184
            error = true;
......
159 196
ERR_NO_CLOSE:
160 197
    cinfo->reset();
161 198

  
162
    if (FLAC__stream_decoder_flush(decoder) == false)
199
    if (FLAC__stream_decoder_flush(which_decoder) == false)
163 200
        AUDERR("Could not flush decoder state!\n");
164 201

  
165 202
    return ! error;
......
172 209

  
173 210
const char *const FLACng::exts[] = { "flac", "fla", nullptr };
174 211

  
175
const char *const FLACng::mimes[] = { "audio/flac", "audio/x-flac", nullptr };
212
const char *const FLACng::mimes[] = { "audio/flac", "audio/x-flac", "audio/ogg", "application/ogg", nullptr };