Ticket #506: main.cpp

File main.cpp, 2.7 KB (added by castagne, 3 years ago)

Simple sample code demonstarting the issue

Line 
1/******************************************************\
2 * this bug demonstrates a bug in alsa, when snd_pcm_open-ing pulse on Fedora
3 * castagne  -    AT    -  imag.fr
4 * https://bugzilla.redhat.com/show_bug.cgi?id=482797
5 *
6 * Compile with : g++  main.cpp -lasound
7\******************************************************/
8
9
10
11
12#include <stdlib.h>
13#include <pthread.h>
14#include <iostream>
15#include <alsa/asoundlib.h>
16
17
18void call_snd_pcm_open(const char * name) {
19    int err;
20    snd_pcm_t *playback_handle;
21    if ((err = snd_pcm_open (&playback_handle, name, SND_PCM_STREAM_PLAYBACK, 0)) < 0) {
22        fprintf (stderr, "cannot open audio device %s (%s)\n",
23                 name,
24                 snd_strerror (err));
25    }
26}
27
28void * threadWork(void *arg) {
29    std::cerr << "Thread : Entering thread Test::run" << std::endl;
30    std::cerr << "Thread : call_snd_pcm_opening Pa_Intialize"<< std::endl;
31
32    call_snd_pcm_open("pulse");
33
34//     call_snd_pcm_open("hw:0,0");
35//     call_snd_pcm_open("hw:0,1");
36//     call_snd_pcm_open("hw:0,1");
37//     call_snd_pcm_open("hw:0,2");
38//     call_snd_pcm_open("front");
39//     call_snd_pcm_open("rear");
40//     call_snd_pcm_open("center_lfe");
41//     call_snd_pcm_open("side");
42//     call_snd_pcm_open("surround40");
43//     call_snd_pcm_open("surround41");
44//     call_snd_pcm_open("surround50");
45//     call_snd_pcm_open("surround51");
46//     call_snd_pcm_open("surround71");
47//     call_snd_pcm_open("iec958");
48//     call_snd_pcm_open("spdif");
49//     call_snd_pcm_open("spdif");
50//     call_snd_pcm_open("hdmi");
51//     call_snd_pcm_open("hdmi");
52//     call_snd_pcm_open("modem");
53//     call_snd_pcm_open("modem");
54//     call_snd_pcm_open("phoneline");
55//     call_snd_pcm_open("phoneline");
56//     call_snd_pcm_open("pulse");
57//     call_snd_pcm_open("pulse");
58//     call_snd_pcm_open("dmix");
59//     call_snd_pcm_open("dmix");
60//     call_snd_pcm_open("default");
61//     call_snd_pcm_open("default");
62
63    std::cerr  << "Thread : FINISHED"<< std::endl;
64
65    return NULL;
66}
67
68
69int main() {
70    std::cerr  << "****************************************"<< std::endl;
71    std::cerr  << "* ALSA TEST BUG                         *"<< std::endl;
72    std::cerr  << "****************************************"<< std::endl;
73    std::cerr  << "Main thread : starting thread"<< std::endl;
74    pthread_attr_t attr;
75    pthread_attr_init(&attr);
76    pthread_t threadid;
77
78    pthread_create( &threadid, &attr, threadWork, NULL);
79
80    std::cerr  << "Main thread : sleeping 5 secs"<< std::endl;
81
82    sleep(5);
83
84    std::cerr  << "****************************************"<< std::endl;
85    std::cerr  << "* ALSA TEST BUG TERMINATED - no problem*"<< std::endl;
86    std::cerr  << "****************************************"<< std::endl;
87
88    return EXIT_SUCCESS;
89}