Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members
DSPaudioIO.cpp
00001 /*********************************************************************** 00002 * * 00003 * ViTooKi * 00004 * * 00005 * title: DSPaudioIO.cpp * 00006 * * 00007 * * 00008 * * 00009 * ITEC institute of the University of Klagenfurt (Austria) * 00010 * http://www.itec.uni-klu.ac.at * 00011 * * 00012 * * 00013 * For more information visit the ViTooKi homepage: * 00014 * http://ViTooKi.sourceforge.net * 00015 * vitooki-user@lists.sourceforge.net * 00016 * vitooki-devel@lists.sourceforge.net * 00017 * * 00018 * This file is part of ViTooKi, a free video toolkit. * 00019 * ViTooKi is free software; you can redistribute it and/or * 00020 * modify it under the terms of the GNU General Public License * 00021 * as published by the Free Software Foundation; either version 2 * 00022 * of the License, or (at your option) any later version. * 00023 * * 00024 * This program is distributed in the hope that it will be useful, * 00025 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00026 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 00027 * GNU General Public License for more details. * 00028 * * 00029 * You should have received a copy of the GNU General Public License * 00030 * along with this program; if not, write to the Free Software * 00031 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, * 00032 * MA 02111-1307, USA. * 00033 * * 00034 ***********************************************************************/ 00035 00036 /*********************************************************************** 00037 * * 00038 * REVISION HISTORY: * 00039 * * 00040 * * 00041 * * 00042 ***********************************************************************/ 00043 00044 #ifndef WIN32 00045 00046 00047 // DSPaudioIO.cpp: Implementing the Class DSPaudioIO. 00048 // 00050 00051 #include "DSPaudioIO.hpp" 00052 #include "AudioESInfo.hpp" 00053 #include "Frame.hpp" 00054 #include "io/Rtp.hpp" 00055 #include <stdio.h> 00056 #include <stdlib.h> 00057 #include <signal.h> 00058 00059 00060 00061 // Audio.cpp: Implementing the Class DSPaudioIO. 00062 // 00064 00065 #include "DSPaudioIO.hpp" 00066 #include "ESInfo.hpp" 00067 #include "Frame.hpp" 00068 #include <stdio.h> 00069 #include <stdlib.h> 00070 #include <signal.h> 00071 extern "C" { 00072 #include "SLASH_dev_SLASH_audio.h" 00073 } 00074 00075 #define AUDIO_FILLSZ 4608 00076 00077 int fd; 00078 00079 static u8 *audio_chunk; 00080 static u32 audio_len; 00081 00082 DSPaudioIO::DSPaudioIO(AudioESInfo *es, ESSynchronizer *ess, bool enableHeadphones) : AudioIO(es, ess) { 00083 requestUnpauseESS = false; 00084 this->enableHeadphones = enableHeadphones; 00085 } 00086 00087 00088 DSPaudioIO::~DSPaudioIO() { 00089 } 00090 00091 00092 int DSPaudioIO::initialize() { 00093 00094 if(es) { 00095 dprintf_full("DSPaudioIO::initialize with %i Hz (samples/sec) and %i channels\n", es->getSampleRate(), es->getAudioChannels()); 00096 fd = ::open(AUDIO_DEVICE, O_WRONLY); 00097 if (fd == -1) { 00098 dprintf_err("DSPaudioIO::initialize Error opening AUDIO_DEVICE\n"); 00099 return -1; 00100 } 00101 00102 if (dsp_audio_init(fd, es->getSampleRate(), es->getAudioChannels(), enableHeadphones) == -1) { 00103 ::close(fd); 00104 dprintf_err("DSPaudioIO::initialize Error in initializing audio\n"); 00105 return -1; 00106 } 00107 00108 } 00109 else { 00110 dprintf_err("DSPaudioIO::initialize() failed no ES\r\n"); 00111 } 00112 00113 return 0; 00114 } 00115 00116 00117 Frame * DSPaudioIO::getFrame() { 00118 return NULL; 00119 } 00120 00121 00122 int DSPaudioIO::writeFrame(Frame * frm, ESInfo *out_es) { 00123 dprintf_full("DSPaudioIO::writeFrame %i bytes, using %s audio device \n",frm->getAU()->size, AUDIO_DEVICE); 00124 if (firstFrame) { 00125 firstFrame = false; 00126 if(initialize() < 0) { 00127 dprintf_err("DSPaudioIO::writeFrame Error in initializing\n"); 00128 return 0; 00129 } 00130 } 00131 00132 audio_chunk = frm->getAU()->payload; 00133 audio_len = frm->getAU()->size; 00134 assert(audio_chunk != NULL); 00135 if(getState() != MUTED) { 00136 if (audio_buffer(fd, audio_chunk, audio_len ) < 0) { 00137 dprintf_err("DSPaudioIO:: Error in Playing audio chunk\n"); 00138 } 00139 } 00140 if (getESSync()) 00141 getESSync()->getGlobalTimer()->adjustToTS(frm->getAU()->cts, es->getMediaTimeScale()); 00142 if (requestUnpauseESS && getESSync()) { 00143 dprintf_full("DSPaudioIO: unpausing ESSychronizer\n"); 00144 requestUnpauseESS = false; 00145 getESSync()->setPaused(false); 00146 } 00147 00148 00149 //#ifdef _POSIX_PRIORITY_SCHEDULING 00150 // sched_yield(); //this is necessary to give parallel getFrames a chance 00151 //#endif 00152 return 1; //one frame written 00153 } 00154 00155 00156 bool DSPaudioIO::open() { 00157 if (getESSync()) { 00158 dprintf_full("DSPaudioIO::open()PAUSING ESSynchronizer\n"); 00159 getESSync()->setPaused(true); 00160 requestUnpauseESS = true; // no locking, as the SDL thread is not running yet 00161 } 00162 setState(OPEN); 00163 return true; 00164 } 00165 00166 00167 bool DSPaudioIO::close(bool immediate) { 00168 00169 ::close(fd); 00170 00171 destroy(); 00172 setState(CLOSED); 00173 //::exit(0); 00174 return true; 00175 } 00176 00177 #endif /* WIN32 */