SDLaudioIO Class Reference

provides raw-audio output via the SDL library methods <short description=""> More...

#include <SDLaudioIO.hpp>

Inheritance diagram for SDLaudioIO:

AudioIO IO VThread List of all members.

Public Member Functions

 SDLaudioIO (AudioESInfo *es, ESSynchronizer *ess=NULL)
 Constructor.
int initialize ()
FramegetFrame ()
 returns a frame if one complete frame is available, otherwise null is returned.
int writeFrame (Frame *frm, ESInfo *out_es=NULL)
 returns the number of packets sent.
bool open ()
 opens the IO connection.
bool close (bool immediate=false)
 closes the IO class.
IO::State play (double prefetchTime=0.0)
IO::State pause ()
IO::State mute ()
int packet_queue_get (PacketQueue *q, APacket *pkt, int block)
void resume ()
void clearBuffer ()
 clear packet buffer
int getPacketsInQueue ()

Friends

void sdl_audio_callback (void *opaque, Uint8 *stream, int length)

Detailed Description

provides raw-audio output via the SDL library methods <short description="">

Author:
Mithlesh Kumar
Version:
Id
SDLaudioIO.hpp,v 1.13 2006/01/20 15:37:18 mkropfbe Exp

Definition at line 132 of file SDLaudioIO.hpp.


Constructor & Destructor Documentation

SDLaudioIO::SDLaudioIO AudioESInfo *  es,
ESSynchronizer ess = NULL
 

Constructor.

Parameters:
ess the ESSynchronizer object attached to the video DataChannel; needed for A/V synchronization.
Definition at line 59 of file SDLaudioIO.cpp.
00059 : AudioIO(es, ess) { 00060 initialized = false; 00061 requestUnpauseESS = false; 00062 is = NULL; 00063 }


Member Function Documentation

bool SDLaudioIO::close bool  immediate = false  )  [virtual]
 

closes the IO class.

Parameters:
immediate specifies, if (optional) buffered data should be read/sent to the client (==false), or immediately dumped (==true)

Implements IO.

Definition at line 587 of file SDLaudioIO.cpp.

References IO::setState().

00587 { 00588 00589 if (!immediate) { 00590 while (this->getPacketsInQueue() > 0) msleep(500); 00591 } 00592 00593 if(initialized) { 00594 packet_queue_abort(/*&is->audioq*/); 00595 SDL_CloseAudio(); 00596 packet_queue_end(/*&is->audioq*/); 00597 if(is) 00598 delete is; 00599 } 00600 setState(CLOSED); 00601 dprintf_full("SDLaudioIO::close() SDL audio state after SDL_CloseAudio() = %s\n", 00602 get_sdl_audio_state()); 00603 initialized = false; 00604 return true; 00605 }

Frame * SDLaudioIO::getFrame  )  [virtual]
 

returns a frame if one complete frame is available, otherwise null is returned.

This function is typically blocking. Don't use a NULL return value to conclude STREAMEOF, always check with getState()!

Implements IO.

Definition at line 437 of file SDLaudioIO.cpp.

00437 { 00438 dprintf_full("SDLaudioIO::getFrame NOT IMPLEMENTED!\n"); 00439 00440 #ifdef _POSIX_PRIORITY_SCHEDULING 00441 sched_yield(); //this is necessary to give parallel getFrames a chance 00442 #endif 00443 00444 return NULL; 00445 }

bool SDLaudioIO::open  )  [virtual]
 

opens the IO connection.

State is set to OPENING. When the connection is ready for use, State is OPEN

Implements IO.

Definition at line 542 of file SDLaudioIO.cpp.

References ESSynchronizer::setPaused(), and IO::setState().

00542 { 00543 if (essync) { 00544 dprintf_full("SDLaudioIO::open() SDL audio state = %s, PAUSING ESSynchronizer\n", 00545 get_sdl_audio_state()); 00546 essync->setPaused(true); 00547 requestUnpauseESS = true; // no locking, as the SDL thread is not running yet 00548 } 00549 initialized = false; 00550 setState(OPEN); 00551 return true; 00552 }

int SDLaudioIO::writeFrame Frame frm,
ESInfo out_es = NULL
[virtual]
 

returns the number of packets sent.

Returns 0 on error

Implements IO.

Definition at line 450 of file SDLaudioIO.cpp.

References Frame::getAU().

00450 { 00451 int ntrials = 20; // number of delay calls when queue is full 00452 int i; 00453 00454 if (!initialized) { 00455 if(initialize() < 0) { 00456 dprintf_err("SDLaudioIO::writeFrame() Error in initializing\n"); 00457 return 0; 00458 } 00459 } 00460 if (!frm->getAU()->size) { 00461 return 0; 00462 } 00463 if(firstFrame) { 00464 firstFrame = false; 00465 } 00466 num_frames++; 00467 00468 if (!is->audio_pkt_time_increment) { 00469 u32 bits_per_second = es->getSampleRate() * es->getBitsPerSample() * es->getAudioChannels(); 00470 if (bits_per_second) { 00471 is->audio_pkt_time_increment = frm->getAU()->size * 1000 * 8 / bits_per_second; 00472 dprintf_full("SDLaudioIO::writeFrame(): is->audio_pkt_time_increment = %d, AUsize = %d, bps = %d", is->audio_pkt_time_increment, frm->getAU()->size, bits_per_second); 00473 } 00474 else 00475 is->audio_pkt_time_increment = 1000; 00476 /* compute blocking delay (in ms) when queue is full; 00477 * (ntrials * delay) >= audio_pkt_time_increment 00478 * is minimally required to avoid loosing packets. 00479 */ 00480 //is->queue_full_delay = is->audio_pkt_time_increment * 2 / ntrials; 00481 is->queue_full_delay = is->audio_pkt_time_increment * 2; 00482 if (is->audio_pkt_time_increment > 50 || is->audio_pkt_time_increment <= 0) is->audio_pkt_time_increment = 50; //100 msecs 00483 00484 dprintf_full("SDLaudioIO::writeFrame() pkt_time_increment = %u ms, " 00485 "queue_full_delay = %u ms\n", 00486 is->audio_pkt_time_increment, is->queue_full_delay); 00487 } 00488 00489 if(IO::getState() != IO::MUTED) { 00490 assert(frm->getAU()->payload != NULL); 00491 /* work around a problem on Linux where the SDL audio thread happens to die 00492 * unexpectedly 00493 */ 00494 if (SDL_GetAudioStatus() == SDL_AUDIO_STOPPED) { 00495 dprintf_small("SDLaudioIO::writeFrame() detected dead SDL thread - re-starting\n"); 00496 restartSDLThread(); 00497 } 00498 00499 /* if the queue is full, block for a finite period of time */ 00500 for (i = ntrials; is->audioq.size > SDL_MAX_AUDIOQ_SIZE && i > 0; i--) { 00501 dprintf_full("SDLaudioIO::writeFrame() Queue Full! aqsize=%d max=%d i=%d\n", is->audioq.size, SDL_MAX_AUDIOQ_SIZE, i); 00502 SDL_Delay(is->queue_full_delay); 00503 } 00504 00505 if (is->audioq.size > SDL_MAX_AUDIOQ_SIZE) { 00506 dprintf_small("SDLaudioIO::writeFrame() Queue full - dropping packet!\n" 00507 " SDL audio state = %s\n", 00508 get_sdl_audio_state()); 00509 return 0; 00510 } 00511 00512 /* enqueue new packet */ 00513 APacket pkt1, *pkt = &pkt1; 00514 pkt->size = frm->getAU()->size; //size 00515 pkt->pts = frm->getAU()->cts; //presentation timestamp 00516 pkt->data = new u8[pkt->size]; 00517 00518 memcpy(pkt->data, frm->getAU()->payload, pkt->size); 00519 00520 dprintf_full("SDLaudioIO::writeFrame() PTS %u SIZE %i audioq size = %i\n", 00521 ((u32)pkt->pts), pkt->size, is->audioq.size); 00522 00523 if(packet_queue_put(pkt) < 0) { 00524 dprintf_err("SDLaudioIO::writeFrame() Error in putting packet into Queue\n"); 00525 delete pkt->data; 00526 return 0; 00527 } 00528 } 00529 00530 #ifdef _POSIX_PRIORITY_SCHEDULING 00531 sched_yield(); //this is necessary to give parallel getFrames a chance 00532 #endif 00533 00534 return 1; 00535 }


The documentation for this class was generated from the following files: