Commit 541e084426ba3788f19c25e0c442323c9d31bc8d

Authored by bellard
1 parent e7cad338

VM state change support (malc)


git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@1618 c046a42c-6fe2-441c-8c8c-71466251a162
Showing 1 changed file with 43 additions and 41 deletions
audio/audio.c
... ... @@ -70,6 +70,7 @@ static struct {
70 70 int64_t ticks;
71 71 } period;
72 72 int plive;
  73 + int log_to_monitor;
73 74 } conf = {
74 75 { /* DAC fixed settings */
75 76 1, /* enabled */
... ... @@ -94,7 +95,8 @@ static struct {
94 95 },
95 96  
96 97 { 0 }, /* period */
97   - 0 /* plive */
  98 + 0, /* plive */
  99 + 0
98 100 };
99 101  
100 102 static AudioState glob_audio_state;
... ... @@ -176,7 +178,7 @@ void *audio_calloc (const char *funcname, int nmemb, size_t size)
176 178 if (audio_bug ("audio_calloc", cond)) {
177 179 AUD_log (NULL, "%s passed invalid arguments to audio_calloc\n",
178 180 funcname);
179   - AUD_log (NULL, "nmemb=%d size=%d (len=%d)\n", nmemb, size, len);
  181 + AUD_log (NULL, "nmemb=%d size=%zu (len=%zu)\n", nmemb, size, len);
180 182 return NULL;
181 183 }
182 184  
... ... @@ -300,23 +302,31 @@ static const char *audio_get_conf_str (const char *key,
300 302 }
301 303 }
302 304  
303   -void AUD_log (const char *cap, const char *fmt, ...)
  305 +void AUD_vlog (const char *cap, const char *fmt, va_list ap)
304 306 {
305   - va_list ap;
306   - if (cap) {
307   - fprintf (stderr, "%s: ", cap);
  307 + if (conf.log_to_monitor) {
  308 + if (cap) {
  309 + term_printf ("%s: ", cap);
  310 + }
  311 +
  312 + term_vprintf (fmt, ap);
  313 + }
  314 + else {
  315 + if (cap) {
  316 + fprintf (stderr, "%s: ", cap);
  317 + }
  318 +
  319 + vfprintf (stderr, fmt, ap);
308 320 }
309   - va_start (ap, fmt);
310   - vfprintf (stderr, fmt, ap);
311   - va_end (ap);
312 321 }
313 322  
314   -void AUD_vlog (const char *cap, const char *fmt, va_list ap)
  323 +void AUD_log (const char *cap, const char *fmt, ...)
315 324 {
316   - if (cap) {
317   - fprintf (stderr, "%s: ", cap);
318   - }
319   - vfprintf (stderr, fmt, ap);
  325 + va_list ap;
  326 +
  327 + va_start (ap, fmt);
  328 + AUD_vlog (cap, fmt, ap);
  329 + va_end (ap);
320 330 }
321 331  
322 332 static void audio_print_options (const char *prefix,
... ... @@ -625,8 +635,8 @@ static int audio_pcm_hw_alloc_resources_in (HWVoiceIn *hw)
625 635 {
626 636 hw->conv_buf = audio_calloc (AUDIO_FUNC, hw->samples, sizeof (st_sample_t));
627 637 if (!hw->conv_buf) {
628   - dolog ("Could not allocate ADC conversion buffer (%d bytes)\n",
629   - hw->samples * sizeof (st_sample_t));
  638 + dolog ("Could not allocate ADC conversion buffer (%d samples)\n",
  639 + hw->samples);
630 640 return -1;
631 641 }
632 642 return 0;
... ... @@ -677,8 +687,8 @@ static int audio_pcm_sw_alloc_resources_in (SWVoiceIn *sw)
677 687 int samples = ((int64_t) sw->hw->samples << 32) / sw->ratio;
678 688 sw->conv_buf = audio_calloc (AUDIO_FUNC, samples, sizeof (st_sample_t));
679 689 if (!sw->conv_buf) {
680   - dolog ("Could not allocate buffer for `%s' (%d bytes)\n",
681   - SW_NAME (sw), samples * sizeof (st_sample_t));
  690 + dolog ("Could not allocate buffer for `%s' (%d samples)\n",
  691 + SW_NAME (sw), samples);
682 692 return -1;
683 693 }
684 694  
... ... @@ -805,8 +815,8 @@ static int audio_pcm_hw_alloc_resources_out (HWVoiceOut *hw)
805 815 {
806 816 hw->mix_buf = audio_calloc (AUDIO_FUNC, hw->samples, sizeof (st_sample_t));
807 817 if (!hw->mix_buf) {
808   - dolog ("Could not allocate DAC mixing buffer (%d bytes)\n",
809   - hw->samples * sizeof (st_sample_t));
  818 + dolog ("Could not allocate DAC mixing buffer (%d samples)\n",
  819 + hw->samples);
810 820 return -1;
811 821 }
812 822  
... ... @@ -884,8 +894,8 @@ static int audio_pcm_sw_alloc_resources_out (SWVoiceOut *sw)
884 894 {
885 895 sw->buf = audio_calloc (AUDIO_FUNC, sw->hw->samples, sizeof (st_sample_t));
886 896 if (!sw->buf) {
887   - dolog ("Could not allocate buffer for `%s' (%d bytes)\n",
888   - SW_NAME (sw), sw->hw->samples * sizeof (st_sample_t));
  897 + dolog ("Could not allocate buffer for `%s' (%d samples)\n",
  898 + SW_NAME (sw), sw->hw->samples);
889 899 return -1;
890 900 }
891 901  
... ... @@ -1346,6 +1356,10 @@ static struct audio_option audio_options[] = {
1346 1356 {"PLIVE", AUD_OPT_BOOL, &conf.plive,
1347 1357 "(undocumented)", NULL, 0},
1348 1358  
  1359 +
  1360 + {"LOG_TO_MONITOR", AUD_OPT_BOOL, &conf.log_to_monitor,
  1361 + "print logging messages to montior instead of stderr", NULL, 0},
  1362 +
1349 1363 {NULL, 0, NULL, NULL, NULL, 0}
1350 1364 };
1351 1365  
... ... @@ -1513,31 +1527,19 @@ static int audio_driver_init (AudioState *s, struct audio_driver *drv)
1513 1527 }
1514 1528 }
1515 1529  
1516   -static void audio_vm_stop_handler (void *opaque, int reason)
  1530 +static void audio_vm_change_state_handler (void *opaque, int running)
1517 1531 {
1518 1532 AudioState *s = opaque;
1519 1533 HWVoiceOut *hwo = NULL;
1520 1534 HWVoiceIn *hwi = NULL;
1521   - int op = reason ? VOICE_ENABLE : VOICE_DISABLE;
1522   -
1523   - while ((hwo = audio_pcm_hw_find_any_out (s, hwo))) {
1524   - if (!hwo->pcm_ops) {
1525   - continue;
1526   - }
  1535 + int op = running ? VOICE_ENABLE : VOICE_DISABLE;
1527 1536  
1528   - if (hwo->enabled != reason) {
1529   - hwo->pcm_ops->ctl_out (hwo, op);
1530   - }
  1537 + while ((hwo = audio_pcm_hw_find_any_enabled_out (s, hwo))) {
  1538 + hwo->pcm_ops->ctl_out (hwo, op);
1531 1539 }
1532 1540  
1533   - while ((hwi = audio_pcm_hw_find_any_in (s, hwi))) {
1534   - if (!hwi->pcm_ops) {
1535   - continue;
1536   - }
1537   -
1538   - if (hwi->enabled != reason) {
1539   - hwi->pcm_ops->ctl_in (hwi, op);
1540   - }
  1541 + while ((hwi = audio_pcm_hw_find_any_enabled_in (s, hwi))) {
  1542 + hwi->pcm_ops->ctl_in (hwi, op);
1541 1543 }
1542 1544 }
1543 1545  
... ... @@ -1690,7 +1692,7 @@ AudioState *AUD_init (void)
1690 1692 conf.period.ticks = ticks_per_sec / conf.period.hz;
1691 1693 }
1692 1694  
1693   - qemu_add_vm_stop_handler (audio_vm_stop_handler, NULL);
  1695 + qemu_add_vm_change_state_handler (audio_vm_change_state_handler, s);
1694 1696 }
1695 1697 else {
1696 1698 qemu_del_timer (s->ts);
... ...