Switch to unified view

a/src/httpgate.cpp b/src/httpgate.cpp
...
...
101
        LOGDEB("data_generator: returning EOS" << endl);
101
        LOGDEB("data_generator: returning EOS" << endl);
102
        return MHD_CONTENT_READER_END_OF_STREAM;
102
        return MHD_CONTENT_READER_END_OF_STREAM;
103
    }
103
    }
104
104
105
    PTMutexLocker lock(dataqueueLock);
105
    PTMutexLocker lock(dataqueueLock);
106
    // We only do the offset-fixing thing once per called because it's
107
    // based on the (unchanging) input parameters.
108
    bool offsetfixed = false;
106
    size_t bytes = 0;
109
    size_t bytes = 0;
107
    while (bytes < max) {
110
    while (bytes < max) {
108
        while (dataqueue.empty()) {
111
        while (dataqueue.empty()) {
109
            //LOGDEB("data_generator: waiting for buffer" << endl);
112
            //LOGDEB("data_generator: waiting for buffer" << endl);
110
            pthread_cond_wait(&dataqueueWaitCond, lock.getMutex());
113
            pthread_cond_wait(&dataqueueWaitCond, lock.getMutex());
...
...
115
                dataqueue.pop();
118
                dataqueue.pop();
116
            }
119
            }
117
        }
120
        }
118
121
119
        AudioMessage *m = dataqueue.front();
122
        AudioMessage *m = dataqueue.front();
123
124
        // After initial ops to read the header, our client usually
125
        // restarts reading the stream. We can't rewind, so we
126
        // simulate rewind by discarding any partial buffer, to be
127
        // sure that we start aligned with the sample (we could also
128
        // use the sample size and channel count to adjust the offset,
129
        // but this is simpler). This is a bit of a hack, because it
130
        // won't work if the client does not behave as we expect
131
        // (seeks to a position not exactly after the header). The
132
        // proper solution would be to compare the buffer position and
133
        // read offsets modulos against chansXsamplesize and adjust
134
        // the offset (back or forward dep on avail data) so they are
135
        // the same.
136
        if (rc->baseoffset + pos == 44 && 
137
            m->m_curoffs != 0 && !offsetfixed) {
138
            //LOGDEB1("data_generator: FIXING OFFSET" << endl);
139
            m->m_curoffs = m->m_bytes;
140
            offsetfixed = true;
141
        }
120
        if (dataformat_wav && rc->baseoffset == 0 && pos == 0 && bytes == 0) {
142
        if (dataformat_wav && rc->baseoffset == 0 && pos == 0 && bytes == 0) {
121
            LOGINF("data_generator: first buf" << endl);
143
            LOGINF("data_generator: first buf" << endl);
122
            // Using buf+bytes in case we ever insert icy before the audio
144
            // Using buf+bytes in case we ever insert icy before the audio
123
            int sz = makewavheader(buf+bytes, max, 
145
            int sz = makewavheader(buf+bytes, max, 
124
                                   m->m_freq, m->m_bits, m->m_chans, databytes);
146
                                   m->m_freq, m->m_bits, m->m_chans, databytes);
...
...
203
    if (ranges.size()) {
225
    if (ranges.size()) {
204
        if (ranges[0].second != -1) {
226
        if (ranges[0].second != -1) {
205
            size = ranges[0].second - ranges[0].first + 1;
227
            size = ranges[0].second - ranges[0].first + 1;
206
        }
228
        }
207
        rc->baseoffset = ranges[0].first;
229
        rc->baseoffset = ranges[0].first;
208
        //LOGDEB("httpgate: answer: got ranges: baseoffs " << rc->baseoffset <<
230
        //LOGDEB("httpgate: answer: got " << ranges.size() << 
231
        //     " ranges: range[0]: offs " << rc->baseoffset <<
209
        //" sz " << size << endl);
232
        //     " sz " << size << endl);
210
    }
233
    }
211
234
235
    // the block size is flatly ignored by libcurl. 5280 is 440x3
236
    // (thats the songcast msg size in 24 bits mode. Any random value
237
    // would probably work the same
212
    struct MHD_Response *response = 
238
    struct MHD_Response *response = 
213
        MHD_create_response_from_callback(size, 1764, &data_generator, 
239
        MHD_create_response_from_callback(size, 5292, &data_generator, 
214
                                          rc, ContentReaderFreeCallback);
240
                                          rc, ContentReaderFreeCallback);
215
    if (response == NULL) {
241
    if (response == NULL) {
216
        LOGERR("httpgate: answer: could not create response" << endl);
242
        LOGERR("httpgate: answer: could not create response" << endl);
217
        return MHD_NO;
243
        return MHD_NO;
218
    }
244
    }