~diwic/ubuntu/lucid/pulseaudio/bugfixes

« back to all changes in this revision

Viewing changes to src/pulsecore/tagstruct.c

  • Committer: Bazaar Package Importer
  • Author(s): Luke Yelavich
  • Date: 2008-11-04 15:46:00 UTC
  • mfrom: (1.2.1 upstream) (1.1.6 lenny)
  • Revision ID: james.westby@ubuntu.com-20081104154600-hlzknpcazaam0nxm
Tags: 0.9.13-1ubuntu1
* Merge from Debian unstable, remaining changes:
  - Don't build against, and create jack package. Jack is not in main.
  - Remove --disable-per-user-esound-socket from configure flags, as we still
    want per user esound sockets.
  - Remove stop links from rc0 and rc6.
  - Change default resample algorithm and bubffer size.
  - Add alsa configuration files to route alsa applications via pulseaudio.
  - Move libasound2-plugins from Recommends to Depends.
* debian/pulseaudio.preinst: When upgrading from intrepid, remove
  /etc/X11/Xsession.d/70pulseaudio, as this was used to minimize a race
  condition when starting GNOME in intrepid. This race should not exist in
  jaunty once libcanberra is built to use pulseaudio as a backend.
* Do not spawn a pulseaudio server if clients fail to find a running server.
* Remove explicit version dependency for libspeex-dev to allow the package
  to be built for now.
* Regenerate autotools files to work with Ubuntu's newer libtool/libltdl.
* debian/control: libpulsecore5 -> libpulsecore8 to match the library
  soname.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* $Id: tagstruct.c 1971 2007-10-28 19:13:50Z lennart $ */
2
 
 
3
1
/***
4
2
  This file is part of PulseAudio.
5
3
 
42
40
 
43
41
#include "tagstruct.h"
44
42
 
 
43
#define MAX_TAG_SIZE (64*1024)
 
44
 
45
45
struct pa_tagstruct {
46
46
    uint8_t *data;
47
47
    size_t length, allocated;
48
48
    size_t rindex;
49
49
 
50
 
    int dynamic;
 
50
    pa_bool_t dynamic;
51
51
};
52
52
 
53
53
pa_tagstruct *pa_tagstruct_new(const uint8_t* data, size_t length) {
154
154
 
155
155
    extend(t, 5+length);
156
156
    t->data[t->length] = PA_TAG_ARBITRARY;
157
 
    tmp = htonl(length);
 
157
    tmp = htonl((uint32_t) length);
158
158
    memcpy(t->data+t->length+1, &tmp, 4);
159
159
    if (length)
160
160
        memcpy(t->data+t->length+5, p, length);
161
161
    t->length += 5+length;
162
162
}
163
163
 
164
 
void pa_tagstruct_put_boolean(pa_tagstruct*t, int b) {
 
164
void pa_tagstruct_put_boolean(pa_tagstruct*t, pa_bool_t b) {
165
165
    pa_assert(t);
166
166
 
167
167
    extend(t, 1);
168
 
    t->data[t->length] = b ? PA_TAG_BOOLEAN_TRUE : PA_TAG_BOOLEAN_FALSE;
 
168
    t->data[t->length] = (uint8_t) (b ? PA_TAG_BOOLEAN_TRUE : PA_TAG_BOOLEAN_FALSE);
169
169
    t->length += 1;
170
170
}
171
171
 
175
175
 
176
176
    extend(t, 9);
177
177
    t->data[t->length] = PA_TAG_TIMEVAL;
178
 
    tmp = htonl(tv->tv_sec);
 
178
    tmp = htonl((uint32_t) tv->tv_sec);
179
179
    memcpy(t->data+t->length+1, &tmp, 4);
180
 
    tmp = htonl(tv->tv_usec);
 
180
    tmp = htonl((uint32_t) tv->tv_usec);
181
181
    memcpy(t->data+t->length+5, &tmp, 4);
182
182
    t->length += 9;
183
183
}
228
228
    unsigned i;
229
229
 
230
230
    pa_assert(t);
231
 
    extend(t, 2 + map->channels);
 
231
    extend(t, 2 + (size_t) map->channels);
232
232
 
233
233
    t->data[t->length++] = PA_TAG_CHANNEL_MAP;
234
234
    t->data[t->length++] = map->channels;
254
254
    }
255
255
}
256
256
 
 
257
void pa_tagstruct_put_proplist(pa_tagstruct *t, pa_proplist *p) {
 
258
    void *state = NULL;
 
259
    pa_assert(t);
 
260
    pa_assert(p);
 
261
 
 
262
    extend(t, 1);
 
263
 
 
264
    t->data[t->length++] = PA_TAG_PROPLIST;
 
265
 
 
266
    for (;;) {
 
267
        const char *k;
 
268
        const void *d;
 
269
        size_t l;
 
270
 
 
271
        if (!(k = pa_proplist_iterate(p, &state)))
 
272
            break;
 
273
 
 
274
        pa_tagstruct_puts(t, k);
 
275
        pa_assert_se(pa_proplist_get(p, k, &d, &l) >= 0);
 
276
        pa_tagstruct_putu32(t, (uint32_t) l);
 
277
        pa_tagstruct_put_arbitrary(t, d, l);
 
278
    }
 
279
 
 
280
    pa_tagstruct_puts(t, NULL);
 
281
}
 
282
 
257
283
int pa_tagstruct_gets(pa_tagstruct*t, const char **s) {
258
284
    int error = 0;
259
285
    size_t n;
379
405
    return t->data;
380
406
}
381
407
 
382
 
int pa_tagstruct_get_boolean(pa_tagstruct*t, int *b) {
 
408
int pa_tagstruct_get_boolean(pa_tagstruct*t, pa_bool_t *b) {
383
409
    pa_assert(t);
384
410
    pa_assert(b);
385
411
 
387
413
        return -1;
388
414
 
389
415
    if (t->data[t->rindex] == PA_TAG_BOOLEAN_TRUE)
390
 
        *b = 1;
 
416
        *b = TRUE;
391
417
    else if (t->data[t->rindex] == PA_TAG_BOOLEAN_FALSE)
392
 
        *b = 0;
 
418
        *b = FALSE;
393
419
    else
394
420
        return -1;
395
421
 
409
435
        return -1;
410
436
 
411
437
    memcpy(&tv->tv_sec, t->data+t->rindex+1, 4);
412
 
    tv->tv_sec = ntohl(tv->tv_sec);
 
438
    tv->tv_sec = (time_t) ntohl((uint32_t) tv->tv_sec);
413
439
    memcpy(&tv->tv_usec, t->data+t->rindex+5, 4);
414
 
    tv->tv_usec = ntohl(tv->tv_usec);
 
440
    tv->tv_usec = (suseconds_t) ntohl((uint32_t) tv->tv_usec);
415
441
    t->rindex += 9;
416
442
    return 0;
417
443
}
497
523
    for (i = 0; i < map->channels; i ++)
498
524
        map->map[i] = (int8_t) t->data[t->rindex + 2 + i];
499
525
 
500
 
    t->rindex += 2 + map->channels;
 
526
    t->rindex += 2 + (size_t) map->channels;
501
527
    return 0;
502
528
}
503
529
 
529
555
    return 0;
530
556
}
531
557
 
 
558
int pa_tagstruct_get_proplist(pa_tagstruct *t, pa_proplist *p) {
 
559
    size_t saved_rindex;
 
560
 
 
561
    pa_assert(t);
 
562
    pa_assert(p);
 
563
 
 
564
    if (t->rindex+1 > t->length)
 
565
        return -1;
 
566
 
 
567
    if (t->data[t->rindex] != PA_TAG_PROPLIST)
 
568
        return -1;
 
569
 
 
570
    saved_rindex = t->rindex;
 
571
    t->rindex++;
 
572
 
 
573
    for (;;) {
 
574
        const char *k;
 
575
        const void *d;
 
576
        uint32_t length;
 
577
 
 
578
        if (pa_tagstruct_gets(t, &k) < 0)
 
579
            goto fail;
 
580
 
 
581
        if (!k)
 
582
            break;
 
583
 
 
584
        if (pa_tagstruct_getu32(t, &length) < 0)
 
585
            goto fail;
 
586
 
 
587
        if (length > MAX_TAG_SIZE)
 
588
            goto fail;
 
589
 
 
590
        if (pa_tagstruct_get_arbitrary(t, &d, length) < 0)
 
591
            goto fail;
 
592
 
 
593
        if (pa_proplist_set(p, k, d, length) < 0)
 
594
            goto fail;
 
595
    }
 
596
 
 
597
    return 0;
 
598
 
 
599
fail:
 
600
    t->rindex = saved_rindex;
 
601
    return -1;
 
602
}
 
603
 
532
604
void pa_tagstruct_put(pa_tagstruct *t, ...) {
533
605
    va_list va;
534
606
    pa_assert(t);
591
663
                pa_tagstruct_put_cvolume(t, va_arg(va, pa_cvolume *));
592
664
                break;
593
665
 
 
666
            case PA_TAG_PROPLIST:
 
667
                pa_tagstruct_put_proplist(t, va_arg(va, pa_proplist *));
 
668
                break;
 
669
 
594
670
            default:
595
671
                pa_assert_not_reached();
596
672
        }
643
719
 
644
720
            case PA_TAG_BOOLEAN_TRUE:
645
721
            case PA_TAG_BOOLEAN_FALSE:
646
 
                ret = pa_tagstruct_get_boolean(t, va_arg(va, int*));
 
722
                ret = pa_tagstruct_get_boolean(t, va_arg(va, pa_bool_t*));
647
723
                break;
648
724
 
649
725
            case PA_TAG_TIMEVAL:
662
738
                ret = pa_tagstruct_get_cvolume(t, va_arg(va, pa_cvolume *));
663
739
                break;
664
740
 
 
741
            case PA_TAG_PROPLIST:
 
742
                ret = pa_tagstruct_get_proplist(t, va_arg(va, pa_proplist *));
 
743
                break;
 
744
 
665
745
            default:
666
746
                pa_assert_not_reached();
667
747
        }