this repo has no description
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

First audio playback working via sox

+84 -22
+2 -4
src/CoreAudio/CoreAudio/pulse/AudioHardwareImplPA.cpp
··· 25 25 #include <CoreFoundation/CFString.h> 26 26 #include <iostream> 27 27 #include <mutex> 28 + #include <thread> 28 29 29 30 pa_context* AudioHardwareImplPA::m_context; 30 31 std::unique_ptr<PADispatchMainLoop> AudioHardwareImplPA::m_loop; ··· 182 183 // pa_proplist_sets(proplist, PA_PROP_APPLICATION_ICON_NAME, "icon-name"); 183 184 // pa_proplist_sets(proplist, PA_PROP_MEDIA_ROLE, "game"); 184 185 185 - //pa_mainloop *mainloop = pa_mainloop_new (); 186 - 187 186 m_loop.reset(new PADispatchMainLoop); 188 187 189 - m_context = pa_context_new_with_proplist(m_loop->getAPI() /*pa_mainloop_get_api(mainloop)*/, appname, proplist); 188 + m_context = pa_context_new_with_proplist(m_loop->getAPI(), appname, proplist); 190 189 pa_proplist_free(proplist); 191 190 192 191 if (!m_context) ··· 205 204 return; 206 205 } 207 206 208 - // pa_mainloop_run (mainloop, NULL); 209 207 m_loop->resume(); 210 208 } 211 209 }
+56 -17
src/CoreAudio/CoreAudio/pulse/AudioHardwareStreamPAOutput.cpp
··· 52 52 53 53 m_stream = pa_stream_new(context, "CoreAudio", &spec, nullptr); 54 54 55 - // pa_stream_set_state_callback(m_stream, paStreamStateCB, this); 55 + //pa_stream_set_state_callback(m_stream, [](pa_stream *s, void *userdata) { 56 + //std::cout << "Stream state: " << pa_stream_get_state(s) << std::endl; 57 + /*if (pa_stream_get_state(s) == 2) 58 + pa_stream_trigger(s, [](pa_stream *s, int success, void *userdata){}, nullptr);*/ 59 + //}, this); 56 60 pa_stream_set_write_callback(m_stream, paStreamWriteCB, this); 61 + //pa_stream_set_underflow_callback(m_stream, [](pa_stream *s, void *userdata) { 62 + // std::cerr << "Underflow!\n"; 63 + //}, nullptr); 57 64 58 65 start(); 59 66 }); ··· 61 68 62 69 AudioHardwareStreamPAOutput::~AudioHardwareStreamPAOutput() 63 70 { 71 + // std::cout << "AudioHardwareStreamPAOutput::~AudioHardwareStreamPAOutput()\n"; 64 72 if (m_stream) 65 73 pa_stream_unref(m_stream); 66 74 } 67 75 68 76 void AudioHardwareStreamPAOutput::paStreamWriteCB(pa_stream* s, size_t length, void* self) 69 77 { 70 - std::cout << "AudioHardwareStreamPAOutput::paStreamWriteCB()\n"; 78 + // std::cout << "AudioHardwareStreamPAOutput::paStreamWriteCB()\n"; 71 79 AudioHardwareStreamPAOutput* This = static_cast<AudioHardwareStreamPAOutput*>(self); 72 80 73 81 AudioTimeStamp fake = {0}; ··· 77 85 abl->mNumberBuffers = 1; 78 86 79 87 abl->mBuffers[0].mNumberChannels = 2; 80 - abl->mBuffers[0].mData = This->m_buffer; 81 - abl->mBuffers[0].mDataByteSize = std::min<UInt32>(This->m_bufferSize, length); 88 + 89 + /*size_t nbytes = This->m_bufferSize; 90 + pa_stream_begin_write(This->m_stream, (void**) &abl->mBuffers[0].mData, &nbytes); 91 + abl->mBuffers[0].mDataByteSize = nbytes;*/ 92 + 93 + size_t done = 0; 82 94 83 - // Call the client for more data 84 - OSStatus status = This->m_callback(This->m_hw->id(), &fake, nullptr, nullptr, abl, &fake, This->m_clientData); 85 - if (status != noErr) 95 + while (done < length) 86 96 { 87 - std::cerr << "AudioDeviceIOProc returned " << status << ", corking...\n"; 97 + abl->mBuffers[0].mData = This->m_buffer; 98 + 99 + // std::cout << "AudioHardwareStreamPAOutput() length req=" << length << ", done=" << done << std::endl; 100 + size_t rqsize = std::min<UInt32>(This->m_bufferSize, length-done); 101 + abl->mBuffers[0].mDataByteSize = rqsize; 102 + 103 + // Call the client for more data 104 + OSStatus status = This->m_callback(This->m_hw->id(), &fake, nullptr, nullptr, abl, &fake, This->m_clientData); 105 + if (status != noErr || !abl->mBuffers[0].mDataByteSize) 106 + { 107 + // std::cerr << "AudioDeviceIOProc returned " << status << ", corking...\n"; 108 + 109 + pa_stream_cork(This->m_stream, true, [](pa_stream*, int, void*) {}, nullptr); 110 + } 111 + else 112 + { 113 + // std::cout << "AudioHardwareStreamPAOutput::paStreamWriteCB(): got " << abl->mBuffers[0].mDataByteSize << " bytes\n"; 114 + int rv = pa_stream_write(This->m_stream, abl->mBuffers[0].mData, abl->mBuffers[0].mDataByteSize, nullptr, 0, PA_SEEK_RELATIVE); 115 + if (rv != 0) 116 + { 117 + // std::cerr << "pa_stream_write() failed\n"; 118 + break; 119 + } 120 + //else 121 + // std::cout << "pa_stream_write() OK\n"; 122 + } 88 123 89 - pa_stream_cork(This->m_stream, true, [](pa_stream*, int, void*) {}, nullptr); 90 - } 91 - else 92 - { 93 - std::cout << "AudioHardwareStreamPAOutput::paStreamWriteCB(): got " << abl->mBuffers[0].mDataByteSize << " bytes\n"; 94 - int rv = pa_stream_write(This->m_stream, abl->mBuffers[0].mData, abl->mBuffers[0].mDataByteSize, nullptr, 0, PA_SEEK_RELATIVE); 95 - if (rv != 0) 96 - std::cerr << "pa_stream_write() failed\n"; 124 + done += abl->mBuffers[0].mDataByteSize; 97 125 } 98 126 } 99 127 100 128 void AudioHardwareStreamPAOutput::start() 101 129 { 102 - pa_stream_connect_playback(m_stream, nullptr, nullptr, PA_STREAM_NOFLAGS /* PA_STREAM_START_CORKED */, 130 + struct pa_buffer_attr battr; 131 + 132 + battr.fragsize = uint32_t(-1); 133 + battr.maxlength = uint32_t(m_bufferSize); 134 + battr.minreq = uint32_t(-1); 135 + battr.prebuf = battr.maxlength; 136 + battr.tlength = uint32_t(-1); 137 + 138 + pa_stream_connect_playback(m_stream, nullptr, &battr, pa_stream_flags_t(PA_STREAM_INTERPOLATE_TIMING 139 + |PA_STREAM_ADJUST_LATENCY 140 + |PA_STREAM_AUTO_TIMING_UPDATE) /* PA_STREAM_START_CORKED */, 103 141 nullptr, nullptr); 104 142 105 143 // pa_stream_cork(m_stream, false, [](pa_stream*, int, void*) {}, nullptr); ··· 107 145 108 146 void AudioHardwareStreamPAOutput::stop(void(^cbDone)()) 109 147 { 148 + // std::cerr << "AudioHardwareStreamPAOutput::stop()\n"; 110 149 m_cbDone = Block_copy(cbDone); 111 150 112 151 pa_stream_cork(m_stream, true, [](pa_stream*, int, void* self) {
+26 -1
src/CoreAudio/CoreAudio/pulse/PADispatchMainLoop.cpp
··· 86 86 pa_io_event_destroy_cb_t destroy = nullptr; 87 87 pa_io_event_flags_t events; 88 88 void* userdata; 89 + int fd; 89 90 }; 90 91 91 92 pa_io_event* PADispatchMainLoop::io_new(pa_mainloop_api *a, int fd, pa_io_event_flags_t events, pa_io_event_cb_t cb, void *userdata) ··· 95 96 96 97 dual_source* dual = new dual_source; 97 98 99 + bool read = events & (PA_IO_EVENT_INPUT | PA_IO_EVENT_ERROR | PA_IO_EVENT_HANGUP); 100 + bool write = events & (PA_IO_EVENT_OUTPUT); 101 + // std::cout << "PADispatchMainLoop::io_new(): fd=" << fd << ", read=" << read << ", write=" << write << std::endl; 102 + 98 103 dual->callback = cb; 104 + dual->fd = fd; 99 105 dual->events = events; 100 106 dual->userdata = userdata; 101 107 dual->sourceRead = dispatch_source_create(DISPATCH_SOURCE_TYPE_READ, fd, 0, q); ··· 106 112 }); 107 113 108 114 dispatch_source_set_event_handler(dual->sourceWrite, ^{ 109 - std::cout << "PADispatchMainLoop::io_new(): write event\n"; 115 + // std::cout << "PADispatchMainLoop::io_new(): write event on fd " << fd << std::endl; 110 116 dual->callback(This->getAPI(), reinterpret_cast<pa_io_event*>(dual), fd, PA_IO_EVENT_OUTPUT, dual->userdata); 111 117 }); 112 118 ··· 146 152 { 147 153 if (!dual->readResumed) 148 154 { 155 + // std::cout << "PADispatchMainLoop::io_enable(): disable read fd=" << dual->fd << std::endl; 149 156 dispatch_resume(dual->sourceRead); 150 157 dual->readResumed = true; 151 158 } 152 159 } 153 160 else if (dual->readResumed) 154 161 { 162 + // std::cout << "PADispatchMainLoop::io_enable(): disable read fd=" << dual->fd << std::endl; 155 163 dispatch_suspend(dual->sourceRead); 156 164 dual->readResumed = false; 157 165 } ··· 160 168 { 161 169 if (!dual->writeResumed) 162 170 { 171 + // std::cout << "PADispatchMainLoop::io_enable(): enable write fd=" << dual->fd << std::endl; 163 172 dispatch_resume(dual->sourceWrite); 164 173 dual->writeResumed = true; 165 174 } 166 175 } 167 176 else if (dual->writeResumed) 168 177 { 178 + // std::cout << "PADispatchMainLoop::io_enable(): disable write fd=" << dual->fd << std::endl; 169 179 dispatch_suspend(dual->sourceWrite); 170 180 dual->writeResumed = false; 171 181 } ··· 174 184 void PADispatchMainLoop::io_free(pa_io_event *e) 175 185 { 176 186 dual_source* dual = reinterpret_cast<dual_source*>(e); 187 + // std::cout << "PADispatchMainLoop::io_free(): fd=" << dual->fd << std::endl; 177 188 178 189 if (!dual->readResumed) 179 190 dispatch_resume(dual->sourceRead); ··· 225 236 timer->when.tv_nsec = real_tv->tv_usec * 1000; // convert to ns 226 237 timer->tv = *real_tv; 227 238 239 + // std::cout << "PADispatchMainLoop::time_new(), sec=" << real_tv->tv_sec << ", usec=" << real_tv->tv_usec << std::endl; 240 + 228 241 dispatch_source_set_timer(timer->source, dispatch_walltime(&timer->when, 0), 0, 0); 229 242 230 243 dispatch_source_set_event_handler(timer->source, ^{ 244 + // std::cout << "PADispatchMainLoop::time_new(): fired\n"; 231 245 cb(This->getAPI(), reinterpret_cast<pa_time_event*>(timer), reinterpret_cast<const struct timeval *>(&timer->tv), timer->userdata); 232 246 }); 233 247 dispatch_source_set_cancel_handler(timer->source, ^{ ··· 249 263 timer->when.tv_sec = real_tv->tv_sec; 250 264 timer->when.tv_nsec = real_tv->tv_usec * 1000; // convert to ns 251 265 timer->tv = *real_tv; 266 + 267 + // std::cout << "PADispatchMainLoop::time_restart(), sec=" << real_tv->tv_sec << ", usec=" << real_tv->tv_usec << std::endl; 252 268 253 269 dispatch_source_set_timer(timer->source, dispatch_walltime(&timer->when, 0), 0, 0); 254 270 } ··· 264 280 { 265 281 pa_timer* timer = reinterpret_cast<pa_timer*>(e); 266 282 283 + // std::cout << "PADispatchMainLoop::time_free()\n"; 284 + 267 285 dispatch_source_cancel(timer->source); 268 286 dispatch_release(timer->source); 269 287 } ··· 285 303 pa_mainloop_api* a = ev->loop->getAPI(); 286 304 dispatch_queue_t q = static_cast<PADispatchMainLoop*>(a->userdata)->m_queue; 287 305 306 + // std::cout << "PADispatchMainLoop::defer_event_fire(): with userdata=" << ev->userdata << std::endl; 307 + 288 308 ev->callback(a, static_cast<pa_defer_event*>(context), ev->userdata); 289 309 290 310 if (ev->active) ··· 294 314 295 315 pa_defer_event *PADispatchMainLoop::defer_new(pa_mainloop_api *a, pa_defer_event_cb_t cb, void *userdata) 296 316 { 317 + // std::cout << "PADispatchMainLoop::defer_new(): with userdata=" << userdata << std::endl; 297 318 PADispatchMainLoop* This = static_cast<PADispatchMainLoop*>(a->userdata); 298 319 dispatch_queue_t q = This->m_queue; 299 320 defer_event* e = new defer_event; ··· 319 340 defer_event* ev = reinterpret_cast<defer_event*>(e); 320 341 dispatch_queue_t q = ev->loop->m_queue; 321 342 343 + // std::cout << "PADispatchMainLoop::defer_enable(): with userdata=" << ev->userdata << ", enable=" << b << std::endl; 344 + 322 345 if (!ev->active && b) 323 346 dispatch_async_f(q, e, defer_event_fire); 324 347 ev->active = !!b; ··· 328 351 { 329 352 defer_event* ev = reinterpret_cast<defer_event*>(e); 330 353 dispatch_queue_t q = ev->loop->m_queue; 354 + 355 + // std::cout << "PADispatchMainLoop::defer_free(): with userdata=" << ev->userdata << std::endl; 331 356 332 357 ev->active = false; 333 358