comparison libao2/ao_nas.c @ 27449:5723b671a0f6

Handle AOPLAY_FINAL_CHUNK
author ranma
date Sun, 24 Aug 2008 13:36:04 +0000
parents 9f14e20aaea4
children bc49998d5745
comparison
equal deleted inserted replaced
27448:5137a84907a1 27449:5723b671a0f6
39 39
40 #include "audio_out.h" 40 #include "audio_out.h"
41 #include "audio_out_internal.h" 41 #include "audio_out_internal.h"
42 #include "libaf/af_format.h" 42 #include "libaf/af_format.h"
43 43
44 /* NAS_FRAG_SIZE must be a power-of-two value */
44 #define NAS_FRAG_SIZE 4096 45 #define NAS_FRAG_SIZE 4096
45 46
46 static char *nas_event_types[] = { 47 static char *nas_event_types[] = {
47 "Undefined", 48 "Undefined",
48 "Undefined", 49 "Undefined",
564 // plays 'len' bytes of 'data' 565 // plays 'len' bytes of 'data'
565 // it should round it down to outburst*n 566 // it should round it down to outburst*n
566 // return: number of bytes played 567 // return: number of bytes played
567 static int play(void* data,int len,int flags) 568 static int play(void* data,int len,int flags)
568 { 569 {
569 int maxbursts, playbursts, writelen; 570 int written, maxbursts = 0, playbursts = 0;
570 AuStatus as; 571 AuStatus as;
571 572
572 mp_msg(MSGT_AO, MSGL_DBG3, 573 mp_msg(MSGT_AO, MSGL_DBG3,
573 "ao_nas: play(%p, %d, %d)\n", 574 "ao_nas: play(%p, %d, %d)\n",
574 data, len, flags); 575 data, len, flags);
575 576
576 if (len == 0) 577 if (len == 0)
577 return 0; 578 return 0;
578 579
579 if (len < ao_data.outburst) { 580 if (!(flags & AOPLAY_FINAL_CHUNK)) {
580 unsigned tempbufsz = ao_data.outburst; 581 pthread_mutex_lock(&nas_data->buffer_mutex);
581 void *tempbuf = malloc(tempbufsz); 582 maxbursts = (nas_data->client_buffer_size -
582 583 nas_data->client_buffer_used) / ao_data.outburst;
583 memset(tempbuf, 0, tempbufsz); 584 playbursts = len / ao_data.outburst;
584 memcpy(tempbuf, data, len); 585 len = (playbursts > maxbursts ? maxbursts : playbursts) *
585 586 ao_data.outburst;
586 play(tempbuf, ao_data.outburst, flags); 587 pthread_mutex_unlock(&nas_data->buffer_mutex);
587 588 }
588 if (nas_data->state != AuStateStart) { 589
589 mp_msg(MSGT_AO, MSGL_DBG2, "ao_nas: play(): Starting flow.\n"); 590 /*
590 nas_data->expect_underrun = 1; 591 * If AOPLAY_FINAL_CHUNK is set, we did not actually check len fits
591 nas_data->state = AuStateStart; 592 * into the available buffer space, but mplayer.c shouldn't give us
592 AuStartFlow(nas_data->aud, nas_data->flow, &as); 593 * more to play than we report to it by get_space(), so this should be
593 if (as != AuSuccess) 594 * fine.
594 nas_print_error(nas_data->aud, "play(): AuStartFlow", as); 595 */
595 } 596 written = nas_writeBuffer(nas_data, data, len);
596
597 free(tempbuf);
598
599 return len;
600 }
601
602 pthread_mutex_lock(&nas_data->buffer_mutex);
603 maxbursts = (nas_data->client_buffer_size -
604 nas_data->client_buffer_used) / ao_data.outburst;
605 playbursts = len / ao_data.outburst;
606 writelen = (playbursts > maxbursts ? maxbursts : playbursts) *
607 ao_data.outburst;
608 pthread_mutex_unlock(&nas_data->buffer_mutex);
609
610 writelen = nas_writeBuffer(nas_data, data, writelen);
611 597
612 if (nas_data->state != AuStateStart && 598 if (nas_data->state != AuStateStart &&
613 maxbursts == playbursts) { 599 (maxbursts == playbursts ||
600 flags & AOPLAY_FINAL_CHUNK)) {
614 mp_msg(MSGT_AO, MSGL_DBG2, "ao_nas: play(): Starting flow.\n"); 601 mp_msg(MSGT_AO, MSGL_DBG2, "ao_nas: play(): Starting flow.\n");
615 nas_data->expect_underrun = 1; 602 nas_data->expect_underrun = 1;
616 AuStartFlow(nas_data->aud, nas_data->flow, &as); 603 AuStartFlow(nas_data->aud, nas_data->flow, &as);
617 if (as != AuSuccess) 604 if (as != AuSuccess)
618 nas_print_error(nas_data->aud, "play(): AuStartFlow", as); 605 nas_print_error(nas_data->aud, "play(): AuStartFlow", as);
619 } 606 }
620 607
621 return writelen; 608 return written;
622 } 609 }
623 610
624 // return: delay in seconds between first and last sample in buffer 611 // return: delay in seconds between first and last sample in buffer
625 static float get_delay(void) 612 static float get_delay(void)
626 { 613 {