~ubuntu-branches/ubuntu/precise/espeak/precise

« back to all changes in this revision

Viewing changes to src/wave_pulse.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Luke Yelavich
  • Date: 2011-05-04 11:25:46 UTC
  • mfrom: (1.1.24 upstream) (5.1.10 sid)
  • Revision ID: james.westby@ubuntu.com-20110504112546-ykijzihgc7ybgzn2
Tags: 1.45.04-1ubuntu1
* Merge from debian unstable, remaining changes:
  - Add gbp.conf for use with git buildpackage
  - Update the explanation of the -b command-line flag in the espeak manpage

Show diffs side-by-side

added added

removed removed

Lines of Context:
80
80
static pa_stream *stream = NULL;
81
81
static pa_threaded_mainloop *mainloop = NULL;
82
82
 
83
 
static pa_cvolume volume;
84
 
static int volume_valid = 0;
85
 
 
86
83
static int do_trigger = 0;
87
84
static uint64_t written = 0;
88
85
static int time_offset_msec = 0;
131
128
//   SHOW("ti> read_index=0x%lx\n",the_time->read_index);
132
129
// }
133
130
 
134
 
 
135
 
static void info_cb(struct pa_context *c, const struct pa_sink_input_info *i, int is_last, void *userdata) {
136
 
  ENTER(__FUNCTION__);
137
 
    assert(c);
138
 
 
139
 
    if (!i)
140
 
        return;
141
 
 
142
 
    volume = i->volume;
143
 
    volume_valid = 1;
144
 
}
145
 
 
146
131
static void subscribe_cb(struct pa_context *c, enum pa_subscription_event_type t, uint32_t index, void *userdata) {
147
 
    pa_operation *o;
148
132
  ENTER(__FUNCTION__);
149
133
    
150
134
    assert(c);
154
138
        (t != (PA_SUBSCRIPTION_EVENT_SINK_INPUT|PA_SUBSCRIPTION_EVENT_CHANGE) &&
155
139
         t != (PA_SUBSCRIPTION_EVENT_SINK_INPUT|PA_SUBSCRIPTION_EVENT_NEW)))
156
140
        return;
157
 
 
158
 
    if (!(o = pa_context_get_sink_input_info(c, index, info_cb, NULL))) {
159
 
        SHOW("pa_context_get_sink_input_info() failed: %s\n", pa_strerror(pa_context_errno(c)));
160
 
        return;
161
 
    }
162
 
    
163
 
    pa_operation_unref(o);
164
141
}
165
142
 
166
143
static void context_state_cb(pa_context *c, void *userdata) {
367
344
 
368
345
  SHOW("pulse_write > length=%d\n", length);
369
346
 
370
 
    CHECK_CONNECTED();
 
347
    CHECK_CONNECTED_NO_RETVAL();
371
348
 
372
349
    pa_threaded_mainloop_lock(mainloop);
373
350
    CHECK_DEAD_GOTO(fail, 1);
481
458
    if (!pa_sample_spec_valid(&ss))
482
459
      return false;
483
460
 
484
 
/*     if (!volume_valid) { */
485
 
    pa_cvolume_reset(&volume, ss.channels);
486
 
    volume_valid = 1;
487
 
/*     } else if (volume.channels != ss.channels) */
488
 
/*         pa_cvolume_set(&volume, ss.channels, pa_cvolume_avg(&volume)); */
489
 
 
490
461
    SHOW_TIME("pa_threaded_mainloop_new (call)");
491
462
    if (!(mainloop = pa_threaded_mainloop_new())) {
492
463
      SHOW("Failed to allocate main loop\n","");
539
510
    pa_stream_set_write_callback(stream, stream_request_cb, NULL);
540
511
    pa_stream_set_latency_update_callback(stream, stream_latency_update_cb, NULL);
541
512
 
542
 
 
543
 
 
544
513
    pa_buffer_attr a_attr;
545
514
 
546
515
    a_attr.maxlength = MAXLENGTH;
550
519
    a_attr.fragsize = 0;
551
520
 
552
521
    SHOW_TIME("pa_connect_playback");
553
 
    if (pa_stream_connect_playback(stream, NULL, &a_attr, (pa_stream_flags_t)(PA_STREAM_INTERPOLATE_TIMING|PA_STREAM_AUTO_TIMING_UPDATE), &volume, NULL) < 0) {
 
522
    if (pa_stream_connect_playback(stream, NULL, &a_attr, (pa_stream_flags_t)(PA_STREAM_INTERPOLATE_TIMING|PA_STREAM_AUTO_TIMING_UPDATE), NULL, NULL) < 0) {
554
523
        SHOW("Failed to connect stream: %s", pa_strerror(pa_context_errno(context)));
555
524
        goto unlock_and_fail;
556
525
    }
578
547
        pa_threaded_mainloop_wait(mainloop);
579
548
    }
580
549
 
 
550
    pa_operation_unref(o);
 
551
 
581
552
    if (!success) {
582
553
        SHOW("pa_context_subscribe() failed: %s", pa_strerror(pa_context_errno(context)));
583
554
        goto unlock_and_fail;
584
555
    }
585
556
 
586
 
    pa_operation_unref(o);
587
 
 
588
 
    /* Now request the initial stream info */
589
 
    if (!(o = pa_context_get_sink_input_info(context, pa_stream_get_index(stream), info_cb, NULL))) {
590
 
        SHOW("pa_context_get_sink_input_info() failed: %s", pa_strerror(pa_context_errno(context)));
591
 
        goto unlock_and_fail;
592
 
    }
593
 
    
594
 
    SHOW_TIME("pa_threaded_mainloop_wait 2");
595
 
    while (pa_operation_get_state(o) != PA_OPERATION_DONE) {
596
 
        CHECK_DEAD_GOTO(fail, 1);
597
 
        pa_threaded_mainloop_wait(mainloop);
598
 
    }
599
 
 
600
 
/*     if (!volume_valid) { */
601
 
/*         SHOW("pa_context_get_sink_input_info() failed: %s", pa_strerror(pa_context_errno(context))); */
602
 
/*         goto unlock_and_fail; */
603
 
/*     } */
604
 
 
605
557
    do_trigger = 0;
606
558
    written = 0;
607
559
    time_offset_msec = 0;
608
560
    just_flushed = 0;
609
561
    connected = 1;
610
 
    //    volume_time_event = NULL;
611
562
    
612
563
    pa_threaded_mainloop_unlock(mainloop);
613
564
    SHOW_TIME("pulse_open (ret true)");
614
565
   
615
 
    //    return true;
616
566
    return PULSE_OK;
617
567
 
618
 
 
619
568
unlock_and_fail:
620
569
 
621
570
    if (o)