void CAirPlayServer::Process() { m_bStop = false; while (!m_bStop) { int max_fd = 0; fd_set rfds; struct timeval to = {1, 0}; FD_ZERO(&rfds); FD_SET(m_ServerSocket, &rfds); max_fd = m_ServerSocket; for (unsigned int i = 0; i < m_connections.size(); i++) { FD_SET(m_connections[i].m_socket, &rfds); if (m_connections[i].m_socket > max_fd) max_fd = m_connections[i].m_socket; } int res = select(max_fd+1, &rfds, NULL, NULL, &to); if (res < 0) { CLog::Log(LOGERROR, "AIRPLAY Server: Select failed"); Sleep(1000); Initialize(); } else if (res > 0) { for (int i = m_connections.size() - 1; i >= 0; i--) { int socket = m_connections[i].m_socket; if (FD_ISSET(socket, &rfds)) { char buffer[RECEIVEBUFFER] = {}; int nread = 0; nread = recv(socket, (char*)&buffer, RECEIVEBUFFER, 0); if (nread > 0) { CStdString sessionId; m_connections[i].PushBuffer(this, buffer, nread, sessionId, m_reverseSockets); } if (nread <= 0) { CLog::Log(LOGINFO, "AIRPLAY Server: Disconnection detected"); m_connections[i].Disconnect(); m_connections.erase(m_connections.begin() + i); } } } if (FD_ISSET(m_ServerSocket, &rfds)) { CLog::Log(LOGDEBUG, "AIRPLAY Server: New connection detected"); CTCPClient newconnection; newconnection.m_socket = accept(m_ServerSocket, &newconnection.m_cliaddr, &newconnection.m_addrlen); if (newconnection.m_socket == INVALID_SOCKET) CLog::Log(LOGERROR, "AIRPLAY Server: Accept of new connection failed"); else { CLog::Log(LOGINFO, "AIRPLAY Server: New connection added"); m_connections.push_back(newconnection); } } } } Deinitialize(); }
CAESinkPULSE::~CAESinkPULSE() { Deinitialize(); }
bool CAESinkPULSE::Initialize(AEAudioFormat &format, std::string &device) { { CSingleLock lock(m_sec); m_IsAllocated = false; } m_passthrough = false; m_BytesPerSecond = 0; m_BufferSize = 0; m_filled_bytes = 0; m_lastPackageStamp = 0; m_Channels = 0; m_Stream = NULL; m_Context = NULL; m_periodSize = 0; if (!SetupContext(NULL, &m_Context, &m_MainLoop)) { CLog::Log(LOGNOTICE, "PulseAudio might not be running. Context was not created."); Deinitialize(); return false; } pa_threaded_mainloop_lock(m_MainLoop); struct pa_channel_map map; pa_channel_map_init(&map); // PULSE cannot cope with e.g. planar formats so we fallback to FLOAT // when we receive an invalid pulse format if (AEFormatToPulseFormat(format.m_dataFormat) == PA_SAMPLE_INVALID) { CLog::Log(LOGDEBUG, "PULSE does not support format: %s - will fallback to AE_FMT_FLOAT", CAEUtil::DataFormatToStr(format.m_dataFormat)); format.m_dataFormat = AE_FMT_FLOAT; } m_passthrough = AE_IS_RAW(format.m_dataFormat); if(m_passthrough) { map.channels = 2; format.m_channelLayout = AE_CH_LAYOUT_2_0; } else { map = AEChannelMapToPAChannel(format.m_channelLayout); // if count has changed we need to fit the AE Map if(map.channels != format.m_channelLayout.Count()) format.m_channelLayout = PAChannelToAEChannelMap(map); } m_Channels = format.m_channelLayout.Count(); // store information about current sink SinkInfoStruct sinkStruct; sinkStruct.mainloop = m_MainLoop; sinkStruct.device_found = false; // get real sample rate of the device we want to open - to avoid resampling bool isDefaultDevice = (device == "Default"); WaitForOperation(pa_context_get_sink_info_by_name(m_Context, isDefaultDevice ? NULL : device.c_str(), SinkInfoCallback, &sinkStruct), m_MainLoop, "Get Sink Info"); // only check if the device is existing - don't alter the sample rate if (!sinkStruct.device_found) { CLog::Log(LOGERROR, "PulseAudio: Sink %s not found", device.c_str()); pa_threaded_mainloop_unlock(m_MainLoop); Deinitialize(); return false; } // Pulse can resample everything between 1 hz and 192000 hz // Make sure we are in the range that we originally added format.m_sampleRate = std::max(5512U, std::min(format.m_sampleRate, 192000U)); pa_format_info *info[1]; info[0] = pa_format_info_new(); info[0]->encoding = AEFormatToPulseEncoding(format.m_dataFormat); if(!m_passthrough) { pa_format_info_set_sample_format(info[0], AEFormatToPulseFormat(format.m_dataFormat)); pa_format_info_set_channel_map(info[0], &map); } pa_format_info_set_channels(info[0], m_Channels); // PA requires m_encodedRate in order to do EAC3 unsigned int samplerate = format.m_sampleRate; if (m_passthrough && (AEFormatToPulseEncoding(format.m_dataFormat) == PA_ENCODING_EAC3_IEC61937)) { // this is only used internally for PA to use EAC3 samplerate = format.m_encodedRate; } pa_format_info_set_rate(info[0], samplerate); if (!pa_format_info_valid(info[0])) { CLog::Log(LOGERROR, "PulseAudio: Invalid format info"); pa_format_info_free(info[0]); pa_threaded_mainloop_unlock(m_MainLoop); Deinitialize(); return false; } pa_sample_spec spec; #if PA_CHECK_VERSION(2,0,0) pa_format_info_to_sample_spec(info[0], &spec, NULL); #else spec.rate = (AEFormatToPulseEncoding(format.m_dataFormat) == PA_ENCODING_EAC3_IEC61937) ? 4 * samplerate : samplerate; spec.format = AEFormatToPulseFormat(format.m_dataFormat); spec.channels = m_Channels; #endif if (!pa_sample_spec_valid(&spec)) { CLog::Log(LOGERROR, "PulseAudio: Invalid sample spec"); pa_format_info_free(info[0]); pa_threaded_mainloop_unlock(m_MainLoop); Deinitialize(); return false; } m_BytesPerSecond = pa_bytes_per_second(&spec); unsigned int frameSize = pa_frame_size(&spec); m_Stream = pa_stream_new_extended(m_Context, "kodi audio stream", info, 1, NULL); pa_format_info_free(info[0]); if (m_Stream == NULL) { CLog::Log(LOGERROR, "PulseAudio: Could not create a stream"); pa_threaded_mainloop_unlock(m_MainLoop); Deinitialize(); return false; } pa_stream_set_state_callback(m_Stream, StreamStateCallback, m_MainLoop); pa_stream_set_write_callback(m_Stream, StreamRequestCallback, m_MainLoop); pa_stream_set_latency_update_callback(m_Stream, StreamLatencyUpdateCallback, m_MainLoop); // default buffer construction // align with AE's max buffer unsigned int latency = m_BytesPerSecond / 2.5; // 400 ms unsigned int process_time = latency / 4; // 100 ms if(sinkStruct.isHWDevice) { // on hw devices buffers can be further reduced // 200ms max latency // 50ms min packet size latency = m_BytesPerSecond / 5; process_time = latency / 4; } pa_buffer_attr buffer_attr; buffer_attr.fragsize = latency; buffer_attr.maxlength = (uint32_t) -1; buffer_attr.minreq = process_time; buffer_attr.prebuf = (uint32_t) -1; buffer_attr.tlength = latency; if (pa_stream_connect_playback(m_Stream, isDefaultDevice ? NULL : device.c_str(), &buffer_attr, ((pa_stream_flags)(PA_STREAM_INTERPOLATE_TIMING | PA_STREAM_AUTO_TIMING_UPDATE | PA_STREAM_ADJUST_LATENCY)), NULL, NULL) < 0) { CLog::Log(LOGERROR, "PulseAudio: Failed to connect stream to output"); pa_threaded_mainloop_unlock(m_MainLoop); Deinitialize(); return false; } /* Wait until the stream is ready */ do { pa_threaded_mainloop_wait(m_MainLoop); CLog::Log(LOGDEBUG, "PulseAudio: Stream %s", StreamStateToString(pa_stream_get_state(m_Stream))); } while (pa_stream_get_state(m_Stream) != PA_STREAM_READY && pa_stream_get_state(m_Stream) != PA_STREAM_FAILED); if (pa_stream_get_state(m_Stream) == PA_STREAM_FAILED) { CLog::Log(LOGERROR, "PulseAudio: Waited for the stream but it failed"); pa_threaded_mainloop_unlock(m_MainLoop); Deinitialize(); return false; } const pa_buffer_attr *a; if (!(a = pa_stream_get_buffer_attr(m_Stream))) { CLog::Log(LOGERROR, "PulseAudio: %s", pa_strerror(pa_context_errno(m_Context))); pa_threaded_mainloop_unlock(m_MainLoop); Deinitialize(); return false; } else { unsigned int packetSize = a->minreq; m_BufferSize = a->tlength; m_periodSize = a->minreq; format.m_frames = packetSize / frameSize; } { CSingleLock lock(m_sec); // Register Callback for Sink changes pa_context_set_subscribe_callback(m_Context, SinkChangedCallback, this); const pa_subscription_mask_t mask = PA_SUBSCRIPTION_MASK_SINK; pa_operation *op = pa_context_subscribe(m_Context, mask, NULL, this); if (op != NULL) pa_operation_unref(op); // Register Callback for Sink Info changes - this handles volume pa_context_set_subscribe_callback(m_Context, SinkInputInfoChangedCallback, this); const pa_subscription_mask_t mask_input = PA_SUBSCRIPTION_MASK_SINK_INPUT; pa_operation* op_sinfo = pa_context_subscribe(m_Context, mask_input, NULL, this); if (op_sinfo != NULL) pa_operation_unref(op_sinfo); } pa_threaded_mainloop_unlock(m_MainLoop); format.m_frameSize = frameSize; format.m_frameSamples = format.m_frames * format.m_channelLayout.Count(); m_format = format; format.m_dataFormat = m_passthrough ? AE_FMT_S16NE : format.m_dataFormat; CLog::Log(LOGNOTICE, "PulseAudio: Opened device %s in %s mode with Buffersize %u ms", device.c_str(), m_passthrough ? "passthrough" : "pcm", (unsigned int) ((m_BufferSize / (float) m_BytesPerSecond) * 1000)); // Cork stream will resume when adding first package Pause(true); { CSingleLock lock(m_sec); m_IsAllocated = true; } return true; }
CAESinkOSS::~CAESinkOSS() { Deinitialize(); }
// Program Entry (WinMain) int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { Application application; // Application Structure GL_Window window; // Window Structure Keys keys; // Key Structure BOOL isMessagePumpActive; // Message Pump Active? MSG msg; // Window Message Structure DWORD tickCount; // Used For The Tick Counter // Fill Out Application Data application.className = "OpenGL"; // Application Class Name application.hInstance = hInstance; // Application Instance // Fill Out Window ZeroMemory (&window, sizeof (GL_Window)); // Make Sure Memory Is Zeroed window.keys = &keys; // Window Key Structure window.init.application = &application; // Window Application window.init.title = "rIO And NeHe's RadialBlur Tutorial.";// Window Title window.init.width = 640; // Window Width window.init.height = 480; // Window Height window.init.bitsPerPixel = 32; // Bits Per Pixel window.init.isFullScreen = TRUE; // Fullscreen? (Set To TRUE) ZeroMemory (&keys, sizeof (Keys)); // Zero keys Structure // Ask The User If They Want To Start In FullScreen Mode? if (MessageBox (HWND_DESKTOP, "Would You Like To Run In Fullscreen Mode?", "Start FullScreen?", MB_YESNO | MB_ICONQUESTION) == IDNO) { window.init.isFullScreen = FALSE; // If Not, Run In Windowed Mode } // Register A Class For Our Window To Use if (RegisterWindowClass (&application) == FALSE) // Did Registering A Class Fail? { // Failure MessageBox (HWND_DESKTOP, "Error Registering Window Class!", "Error", MB_OK | MB_ICONEXCLAMATION); return -1; // Terminate Application } g_isProgramLooping = TRUE; // Program Looping Is Set To TRUE g_createFullScreen = window.init.isFullScreen; // g_createFullScreen Is Set To User Default while (g_isProgramLooping) // Loop Until WM_QUIT Is Received { // Create A Window window.init.isFullScreen = g_createFullScreen; // Set Init Param Of Window Creation To Fullscreen? if (CreateWindowGL (&window) == TRUE) // Was Window Creation Successful? { // At This Point We Should Have A Window That Is Setup To Render OpenGL if (Initialize (&window, &keys) == FALSE) // Call User Intialization { // Failure TerminateApplication (&window); // Close Window, This Will Handle The Shutdown } else // Otherwise (Start The Message Pump) { // Initialize was a success isMessagePumpActive = TRUE; // Set isMessagePumpActive To TRUE while (isMessagePumpActive == TRUE) // While The Message Pump Is Active { // Success Creating Window. Check For Window Messages if (PeekMessage (&msg, window.hWnd, 0, 0, PM_REMOVE) != 0) { // Check For WM_QUIT Message if (msg.message != WM_QUIT) // Is The Message A WM_QUIT Message? { DispatchMessage (&msg); // If Not, Dispatch The Message } else // Otherwise (If Message Is WM_QUIT) { isMessagePumpActive = FALSE; // Terminate The Message Pump } } else // If There Are No Messages { if (window.isVisible == FALSE) // If Window Is Not Visible { WaitMessage (); // Application Is Minimized Wait For A Message } else // If Window Is Visible { // Process Application Loop tickCount = GetTickCount (); // Get The Tick Count Update (tickCount - window.lastTickCount); // Update The Counter window.lastTickCount = tickCount; // Set Last Count To Current Count Draw (); // Draw Our Scene SwapBuffers (window.hDC); // Swap Buffers (Double Buffering) } } } // Loop While isMessagePumpActive == TRUE } // If (Initialize (... // Application Is Finished Deinitialize (); // User Defined DeInitialization DestroyWindowGL (&window); // Destroy The Active Window } else // If Window Creation Failed { // Error Creating Window MessageBox (HWND_DESKTOP, "Error Creating OpenGL Window", "Error", MB_OK | MB_ICONEXCLAMATION); g_isProgramLooping = FALSE; // Terminate The Loop } } // While (isProgramLooping) UnregisterClass (application.className, application.hInstance); // UnRegister Window Class return 0; } // End Of WinMain()
bool COMXCoreComponent::Initialize( const std::string &component_name, OMX_INDEXTYPE index) { OMX_ERRORTYPE omx_err; if(!m_DllOMX->Load()) return false; m_DllOMXOpen = true; m_componentName = component_name; m_callbacks.EventHandler = &COMXCoreComponent::DecoderEventHandlerCallback; m_callbacks.EmptyBufferDone = &COMXCoreComponent::DecoderEmptyBufferDoneCallback; m_callbacks.FillBufferDone = &COMXCoreComponent::DecoderFillBufferDoneCallback; // Get video component handle setting up callbacks, component is in loaded state on return. omx_err = m_DllOMX->OMX_GetHandle(&m_handle, (char*)component_name.c_str(), this, &m_callbacks); if (omx_err != OMX_ErrorNone) { CLog::Log(LOGERROR, "COMXCoreComponent::Initialize - could not get component handle for %s omx_err(0x%08x)\n", component_name.c_str(), (int)omx_err); Deinitialize(); return false; } OMX_PORT_PARAM_TYPE port_param; OMX_INIT_STRUCTURE(port_param); omx_err = OMX_GetParameter(m_handle, index, &port_param); if (omx_err != OMX_ErrorNone) { CLog::Log(LOGERROR, "COMXCoreComponent::Initialize - could not get port_param for component %s omx_err(0x%08x)\n", component_name.c_str(), (int)omx_err); } omx_err = DisableAllPorts(); if (omx_err != OMX_ErrorNone) { CLog::Log(LOGERROR, "COMXCoreComponent::Initialize - error disable ports on component %s omx_err(0x%08x)\n", component_name.c_str(), (int)omx_err); } m_input_port = port_param.nStartPortNumber; m_output_port = m_input_port + 1; if(m_componentName == "OMX.broadcom.audio_mixer") { m_input_port = port_param.nStartPortNumber + 1; m_output_port = port_param.nStartPortNumber; } if (m_output_port > port_param.nStartPortNumber+port_param.nPorts-1) m_output_port = port_param.nStartPortNumber+port_param.nPorts-1; CLog::Log(LOGDEBUG, "COMXCoreComponent::Initialize %s input port %d output port %d\n", m_componentName.c_str(), m_input_port, m_output_port); m_exit = false; m_flush_input = false; m_flush_output = false; return true; }
CAESinkIntelSMD::~CAESinkIntelSMD() { VERBOSE2(); Deinitialize(); }
CAESinkSNDIO::~CAESinkSNDIO() { Deinitialize(); }
CAESinkDirectSound::~CAESinkDirectSound() { Deinitialize(); }
bool COMXCoreComponent::Initialize( const std::string &component_name, OMX_INDEXTYPE index) { OMX_ERRORTYPE omx_err; if(!m_DllOMXOpen) return false; m_resource_error = false; m_componentName = component_name; m_callbacks.EventHandler = &COMXCoreComponent::DecoderEventHandlerCallback; m_callbacks.EmptyBufferDone = &COMXCoreComponent::DecoderEmptyBufferDoneCallback; m_callbacks.FillBufferDone = &COMXCoreComponent::DecoderFillBufferDoneCallback; if(!m_handle) { omx_err = OMX_GetHandle(&m_handle, (char*)component_name.c_str(), this, &m_callbacks); if (!m_handle || omx_err != OMX_ErrorNone) { Logger::LogOut(LOG_LEVEL_ERROR, "COMXCoreComponent::Initialize - could not get component handle for %s omx_err(0x%08x)", component_name.c_str(), (int)omx_err); Deinitialize(true); return false; } Logger::LogOut(LOG_LEVEL_DEBUG, "COMXCoreComponent::Initialize : %s handle %p dllopen : %d", m_componentName.c_str(), m_handle, m_DllOMXOpen); } OMX_PORT_PARAM_TYPE port_param; OMX_INIT_STRUCTURE(port_param); omx_err = OMX_GetParameter(m_handle, index, &port_param); if (omx_err != OMX_ErrorNone) { Logger::LogOut(LOG_LEVEL_ERROR, "COMXCoreComponent::Initialize - could not get port_param for component %s omx_err(0x%08x)", component_name.c_str(), (int)omx_err); } omx_err = DisableAllPorts(); if (omx_err != OMX_ErrorNone) { Logger::LogOut(LOG_LEVEL_ERROR, "COMXCoreComponent::Initialize - error disable ports on component %s omx_err(0x%08x)", component_name.c_str(), (int)omx_err); } m_input_port = port_param.nStartPortNumber; m_output_port = m_input_port + 1; if(m_componentName == "OMX.broadcom.audio_mixer") { m_input_port = port_param.nStartPortNumber + 1; m_output_port = port_param.nStartPortNumber; } if (m_output_port > port_param.nStartPortNumber+port_param.nPorts-1) m_output_port = port_param.nStartPortNumber+port_param.nPorts-1; Logger::LogOut(LOG_LEVEL_DEBUG, "COMXCoreComponent::Initialize %s input port %d output port %d", m_componentName.c_str(), m_input_port, m_output_port); m_exit = false; m_flush_input = false; m_flush_output = false; return true; }
//*********************************************************************************************** CWin32DirectSound::~CWin32DirectSound() { Deinitialize(); }
CCoreAudioAEHALIOS::~CCoreAudioAEHALIOS() { Deinitialize(); delete m_audioGraph; }
// 应用程序的入口 (WinMain) int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { Application application; // 应用程序 GL_Window window; // 窗口 Keys keys; // 键盘按键 MSG msg; // Window消息 BOOL isMessagePumpActive; // 给应用程序赋值 application.className = CLASSNAME; // 程序类名字 application.hInstance = hInstance; // 程序入口 // 窗口相关信息设置 ZeroMemory(&window, sizeof(GL_Window)); // 清零窗口变量的内存空间 window.keys = &keys; // 设置按键 window.init.application = &application; // 设置窗口程序 window.init.title = TITLE; // 设置标题 window.init.width = WIDTH; // 设置窗口宽度 window.init.height = HEIGHT; // 设置窗口高度 window.init.bitsPerPixel = BPP; // 设置每像素的位数 window.init.isFullScreen = FALSE; // 设置初始窗口是否全屏否(FALSE) ZeroMemory(&keys, sizeof(Keys)); // 键盘缓冲清零 if (RegisterWindowClass(&application) == FALSE) // 注册类是否失败 { MessageBox(HWND_DESKTOP, "窗口类注册失败!\nError Registering Window Class!", "Error", MB_OK | MB_ICONEXCLAMATION); return -1; // 结束程序 } g_isProgramLooping = TRUE; // 将g_isProgramLooping设TRUE g_createFullScreen = window.init.isFullScreen; // g_createFullScreen 设为默认值 while (g_isProgramLooping) // 循环直到程序停止 { // 建立窗口 window.init.isFullScreen = g_createFullScreen; // 传递是否全屏信息 if (CreateWindowGL(&window) == TRUE) // 创建GL窗口成功否? { if (Initialize(&window, &keys) == FALSE) // 初始化 { // 失败 PostMessage(window.hWnd, WM_QUIT, 0, 0); // 抛出消息WM_QUIT g_isProgramLooping = FALSE; } else { // 初始化成功 isMessagePumpActive = TRUE; // 设isMessagePumpActive为TRUE while (isMessagePumpActive == TRUE) // 当isMessagePumpActive为TRUE时 { // 成功建立窗口,监测Window消息 if (PeekMessage(&msg, window.hWnd, 0, 0, PM_REMOVE) != 0) { // 检测WM_QUIT消息 if (msg.message != WM_QUIT) // WM_QUIT消息? { DispatchMessage(&msg); // 如果不是,分派消息 } else // 否则(消息是WM_QUIT) { isMessagePumpActive = FALSE; // 结束 Message Pump } } else // 如果没有消息 { if (window.isVisible == FALSE) // 如果窗口不可见 { WaitMessage(); // 等待消息 } else // 如果窗口可见 { Update(); // 更新处理消息事件 DrawSceneGL(); // 绘制场景 SwapBuffers(window.hDC); // 交换缓存 } } } // 当isMessagePumpActive 为TRUE时循环执行 } // 程序结束 Deinitialize(); // 做扫尾工作 DestroyWindowGL(&window); // 销毁窗口 } else // 如果窗口创建失败 { MessageBox(HWND_DESKTOP, "创建OpenGL窗口失败\nError Creating OpenGL Window", "Error", MB_OK | MB_ICONEXCLAMATION); g_isProgramLooping = FALSE; // 结束循环 } } UnregisterClass(application.className, application.hInstance); // 注销窗口类 return 0; }
CIMX::~CIMX(void) { g_Windowing.Unregister(this); Deinitialize(); }
CAESinkALSA::~CAESinkALSA() { Deinitialize(); }
Physics::~Physics(void) { Deinitialize(); }
/** * デストラクタ */ CScciIf::~CScciIf() { Deinitialize(); }
CRBP::~CRBP() { Deinitialize(); delete m_OMX; delete m_DllBcmHost; }
DriverLog::~DriverLog(void) { Deinitialize(); }
BoardManager::~BoardManager() { Deinitialize(); }