~ubuntu-branches/ubuntu/karmic/pulseaudio/karmic-updates

« back to all changes in this revision

Viewing changes to src/modules/alsa/alsa-sink.c

  • Committer: Bazaar Package Importer
  • Author(s): Luke Yelavich, Daniel T Chen, Luke Yelavich
  • Date: 2009-09-11 09:24:39 UTC
  • mfrom: (1.14.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20090911092439-7dixbvy6r30alrv8
Tags: 1:0.9.16-0ubuntu1
[ Daniel T Chen ]
* debian/patches/0090-use-volume-ignore-for-analog-output.patch:
  + Realign volume control behaviour with existing Ubuntu releases,
    i.e., disable volume = merge and use volume = ignore for
    analog output

[ Luke Yelavich ]
* New upstream release
* debian/patches/0057-introspect-version-fixes.patch (LP: #426210),
  debian/patches/0056-alsa-rework.patch,
  debian/patches/0055-llvm-clang-analyzer-fixes.patch,
  0054-volume-libpulse-backported-fixes.patch,
  0053-add-input-sources.patch,
  debian/patches/0052-disable-cpu-limit.patch: Dropped, all applied upstream
* debian/patches/0051-reduce-lib-linking.patch: Drop, since we are not going
  to be doing bi-arch pulseaudio packages for karmic

Show diffs side-by-side

added added

removed removed

Lines of Context:
116
116
 
117
117
    pa_usec_t watermark_dec_not_before;
118
118
 
119
 
    unsigned nfragments;
120
119
    pa_memchunk memchunk;
121
120
 
122
121
    char *device_name;  /* name of the PCM device */
656
655
        snd_pcm_sframes_t n;
657
656
        size_t n_bytes;
658
657
        int r;
 
658
        pa_bool_t after_avail = TRUE;
659
659
 
660
660
        if (PA_UNLIKELY((n = pa_alsa_safe_avail(u->pcm_handle, u->hwbuf_size, &u->sink->sample_spec)) < 0)) {
661
661
 
710
710
        for (;;) {
711
711
            snd_pcm_sframes_t frames;
712
712
            void *p;
713
 
            pa_bool_t after_avail = TRUE;
714
713
 
715
714
/*         pa_log_debug("%lu frames to write", (unsigned long) frames); */
716
715
 
943
942
    pa_sample_spec ss;
944
943
    int err;
945
944
    pa_bool_t b, d;
946
 
    unsigned nfrags;
947
 
    snd_pcm_uframes_t period_size;
 
945
    snd_pcm_uframes_t period_size, buffer_size;
948
946
 
949
947
    pa_assert(u);
950
948
    pa_assert(!u->pcm_handle);
952
950
    pa_log_info("Trying resume...");
953
951
 
954
952
    if ((err = snd_pcm_open(&u->pcm_handle, u->device_name, SND_PCM_STREAM_PLAYBACK,
955
 
                            /*SND_PCM_NONBLOCK|*/
 
953
                            SND_PCM_NONBLOCK|
956
954
                            SND_PCM_NO_AUTO_RESAMPLE|
957
955
                            SND_PCM_NO_AUTO_CHANNELS|
958
956
                            SND_PCM_NO_AUTO_FORMAT)) < 0) {
961
959
    }
962
960
 
963
961
    ss = u->sink->sample_spec;
964
 
    nfrags = u->nfragments;
965
962
    period_size = u->fragment_size / u->frame_size;
 
963
    buffer_size = u->hwbuf_size / u->frame_size;
966
964
    b = u->use_mmap;
967
965
    d = u->use_tsched;
968
966
 
969
 
    if ((err = pa_alsa_set_hw_params(u->pcm_handle, &ss, &nfrags, &period_size, u->hwbuf_size / u->frame_size, &b, &d, TRUE)) < 0) {
 
967
    if ((err = pa_alsa_set_hw_params(u->pcm_handle, &ss, &period_size, &buffer_size, 0, &b, &d, TRUE)) < 0) {
970
968
        pa_log("Failed to set hardware parameters: %s", pa_alsa_strerror(err));
971
969
        goto fail;
972
970
    }
981
979
        goto fail;
982
980
    }
983
981
 
984
 
    if (nfrags != u->nfragments || period_size*u->frame_size != u->fragment_size) {
985
 
        pa_log_warn("Resume failed, couldn't restore original fragment settings. (Old: %lu*%lu, New %lu*%lu)",
986
 
                    (unsigned long) u->nfragments, (unsigned long) u->fragment_size,
987
 
                    (unsigned long) nfrags, period_size * u->frame_size);
 
982
    if (period_size*u->frame_size != u->fragment_size ||
 
983
        buffer_size*u->frame_size != u->hwbuf_size) {
 
984
        pa_log_warn("Resume failed, couldn't restore original fragment settings. (Old: %lu/%lu, New %lu/%lu)",
 
985
                    (unsigned long) u->hwbuf_size, (unsigned long) u->fragment_size,
 
986
                    (unsigned long) (buffer_size*u->fragment_size), (unsigned long) (period_size*u->frame_size));
988
987
        goto fail;
989
988
    }
990
989
 
1638
1637
    const char *dev_id = NULL;
1639
1638
    pa_sample_spec ss, requested_ss;
1640
1639
    pa_channel_map map;
1641
 
    uint32_t nfrags, hwbuf_size, frag_size, tsched_size, tsched_watermark;
1642
 
    snd_pcm_uframes_t period_frames, tsched_frames;
 
1640
    uint32_t nfrags, frag_size, buffer_size, tsched_size, tsched_watermark;
 
1641
    snd_pcm_uframes_t period_frames, buffer_frames, tsched_frames;
1643
1642
    size_t frame_size;
1644
1643
    pa_bool_t use_mmap = TRUE, b, use_tsched = TRUE, d, ignore_dB = FALSE;
1645
1644
    pa_sink_new_data data;
1673
1672
        goto fail;
1674
1673
    }
1675
1674
 
1676
 
    hwbuf_size = frag_size * nfrags;
 
1675
    buffer_size = nfrags * frag_size;
 
1676
 
1677
1677
    period_frames = frag_size/frame_size;
 
1678
    buffer_frames = buffer_size/frame_size;
1678
1679
    tsched_frames = tsched_size/frame_size;
1679
1680
 
1680
1681
    if (pa_modargs_get_value_boolean(ma, "mmap", &use_mmap) < 0) {
1741
1742
                      &u->device_name,
1742
1743
                      &ss, &map,
1743
1744
                      SND_PCM_STREAM_PLAYBACK,
1744
 
                      &nfrags, &period_frames, tsched_frames,
 
1745
                      &period_frames, &buffer_frames, tsched_frames,
1745
1746
                      &b, &d, mapping)))
1746
1747
 
1747
1748
            goto fail;
1756
1757
                      &u->device_name,
1757
1758
                      &ss, &map,
1758
1759
                      SND_PCM_STREAM_PLAYBACK,
1759
 
                      &nfrags, &period_frames, tsched_frames,
 
1760
                      &period_frames, &buffer_frames, tsched_frames,
1760
1761
                      &b, &d, profile_set, &mapping)))
1761
1762
 
1762
1763
            goto fail;
1768
1769
                      &u->device_name,
1769
1770
                      &ss, &map,
1770
1771
                      SND_PCM_STREAM_PLAYBACK,
1771
 
                      &nfrags, &period_frames, tsched_frames,
 
1772
                      &period_frames, &buffer_frames, tsched_frames,
1772
1773
                      &b, &d, FALSE)))
1773
1774
            goto fail;
1774
1775
    }
1794
1795
        u->use_tsched = use_tsched = FALSE;
1795
1796
    }
1796
1797
 
1797
 
    if (use_tsched && !pa_alsa_pcm_is_hw(u->pcm_handle)) {
1798
 
        pa_log_info("Device is not a hardware device, disabling timer-based scheduling.");
1799
 
        u->use_tsched = use_tsched = FALSE;
1800
 
    }
1801
 
 
1802
1798
    if (u->use_mmap)
1803
1799
        pa_log_info("Successfully enabled mmap() mode.");
1804
1800
 
1820
1816
 
1821
1817
    pa_alsa_init_proplist_pcm(m->core, data.proplist, u->pcm_handle);
1822
1818
    pa_proplist_sets(data.proplist, PA_PROP_DEVICE_STRING, u->device_name);
1823
 
    pa_proplist_setf(data.proplist, PA_PROP_DEVICE_BUFFERING_BUFFER_SIZE, "%lu", (unsigned long) (period_frames * frame_size * nfrags));
 
1819
    pa_proplist_setf(data.proplist, PA_PROP_DEVICE_BUFFERING_BUFFER_SIZE, "%lu", (unsigned long) (buffer_frames * frame_size));
1824
1820
    pa_proplist_setf(data.proplist, PA_PROP_DEVICE_BUFFERING_FRAGMENT_SIZE, "%lu", (unsigned long) (period_frames * frame_size));
1825
1821
    pa_proplist_sets(data.proplist, PA_PROP_DEVICE_ACCESS_MODE, u->use_tsched ? "mmap+timer" : (u->use_mmap ? "mmap" : "serial"));
1826
1822
 
1861
1857
    pa_sink_set_rtpoll(u->sink, u->rtpoll);
1862
1858
 
1863
1859
    u->frame_size = frame_size;
1864
 
    u->fragment_size = frag_size = (uint32_t) (period_frames * frame_size);
1865
 
    u->nfragments = nfrags;
1866
 
    u->hwbuf_size = u->fragment_size * nfrags;
 
1860
    u->fragment_size = frag_size = (size_t) (period_frames * frame_size);
 
1861
    u->hwbuf_size = buffer_size = (size_t) (buffer_frames * frame_size);
1867
1862
    pa_cvolume_mute(&u->hardware_volume, u->sink->sample_spec.channels);
1868
1863
 
1869
 
    pa_log_info("Using %u fragments of size %lu bytes, buffer time is %0.2fms",
1870
 
                nfrags, (long unsigned) u->fragment_size,
 
1864
    pa_log_info("Using %0.1f fragments of size %lu bytes (%0.2fms), buffer size is %lu bytes (%0.2fms)",
 
1865
                (double) u->hwbuf_size / (double) u->fragment_size,
 
1866
                (long unsigned) u->fragment_size,
 
1867
                (double) pa_bytes_to_usec(u->fragment_size, &ss) / PA_USEC_PER_MSEC,
 
1868
                (long unsigned) u->hwbuf_size,
1871
1869
                (double) pa_bytes_to_usec(u->hwbuf_size, &ss) / PA_USEC_PER_MSEC);
1872
1870
 
1873
1871
    pa_sink_set_max_request(u->sink, u->hwbuf_size);