BaseAudioApplication.cxx
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "BaseAudioApplication.hxx"
00023 #include "AudioManager.hxx"
00024 #include <pthread.h>
00025 #include <cstdio>
00026 #include <iostream>
00027 #ifdef WIN32
00028 #include "CLAM_windows.h"
00029 #undef GetClassName
00030 #else
00031 #include <unistd.h>
00032 #endif
00033 #include "AudioManager.hxx"
00034
00035 namespace CLAM {
00036
00037 typedef void *(*startfn) (void *);
00038 typedef void (*cleanfn) (void *);
00039
00040 BaseAudioApplication::BaseAudioApplication()
00041 :Application()
00042 {
00043 cancel = false;
00044 }
00045
00046 void BaseAudioApplication::Start(void)
00047 {
00048 cancel = false;
00049 pthread_create(&thread,NULL,(startfn)SAudioThread,this);
00050 }
00051
00052 void BaseAudioApplication::Stop(void)
00053 {
00054 pthread_cleanup_push((cleanfn)SAudioThreadCleanup,this);
00055
00056 cancel = true;
00057 pthread_join(thread,NULL);
00058
00059 pthread_cleanup_pop(1);
00060 cancel = false;
00061 }
00062
00063 void BaseAudioApplication::Run(int argc,char** argv)
00064 {
00065 Start();
00066 UserMain();
00067 Stop();
00068 }
00069
00070 void BaseAudioApplication::UserMain(void)
00071 {
00072 printf("Press enter to terminate\n");
00073 getchar();
00074 }
00075
00076 void* BaseAudioApplication::SAudioThread(BaseAudioApplication *pThis)
00077 {
00078 #ifdef WIN32
00079 BOOL res;
00080 DWORD err;
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092 res = SetPriorityClass(GetCurrentProcess(),HIGH_PRIORITY_CLASS );
00093
00094 err = GetLastError();
00095
00096
00097
00098
00099
00100
00101
00102 res = SetThreadPriority( GetCurrentThread(), THREAD_PRIORITY_HIGHEST );
00103 err = GetLastError();
00104 #else
00105 struct sched_param sched_param;
00106 int policy;
00107
00108 if (pthread_getschedparam(pthread_self(), &policy, &sched_param) < 0) {
00109 printf("Scheduler getparam failed...\n");
00110 }
00111 sched_param.sched_priority = sched_get_priority_max(SCHED_RR)-1;
00112 if (!pthread_setschedparam(pthread_self(), SCHED_RR, &sched_param)) {
00113 printf("Scheduler set to Round Robin with priority %i...\n", sched_param.sched_priority);
00114 }
00115
00116 #endif
00117
00118 pThis->AudioMain();
00119
00120 return NULL;
00121 }
00122
00123 void BaseAudioApplication::SAudioThreadCleanup(BaseAudioApplication *pThis)
00124 {
00125 }
00126
00127 }
00128