void EngineShoutcast::process(const CSAMPLE* pBuffer, const int iBufferSize) { //Check to see if Shoutcast is enabled, and pass the samples off to be broadcast if necessary. bool prefEnabled = (m_pConfig->getValueString(ConfigKey(SHOUTCAST_PREF_KEY,"enabled")).toInt() == 1); if (!prefEnabled) { if (isConnected()) { // We are conneced but shoutcast is disabled. Disconnect. serverDisconnect(); infoDialog(tr("Mixxx has successfully disconnected from the shoutcast server"), ""); } return; } // If we are here then the user wants to be connected (shoutcast is enabled // in the preferences). bool connected = isConnected(); // If we aren't connected or the user has changed their preferences, // disconnect, update from prefs, and reconnect. if (!connected || m_pUpdateShoutcastFromPrefs->get() > 0.0f) { if (connected) { serverDisconnect(); } // Initialize/update the encoder and libshout setup. updateFromPreferences(); if (serverConnect()) { infoDialog(tr("Mixxx has successfully connected to the shoutcast server"), ""); } else { errorDialog(tr("Mixxx could not connect to streaming server"), tr("Please check your connection to the Internet and verify that your username and password are correct.")); } } // If we aren't connected, bail. if (m_iShoutStatus != SHOUTERR_CONNECTED) return; // If we are connected, encode the samples. if (iBufferSize > 0 && m_encoder){ m_encoder->encodeBuffer(pBuffer, iBufferSize); } // Check if track metadata has changed and if so, update. if (metaDataHasChanged()) { updateMetaData(); } }
//------------------------------------------------------------------------- bool CVCRControl::CServerDevice::sendCommand(CVCRCommand command, const t_channel_id channel_id, const event_id_t epgid, const std::string& epgTitle, unsigned char apids) { printf("Send command: %d channel_id: " PRINTF_CHANNEL_ID_TYPE_NO_LEADING_ZEROS " epg: %s(%llx)\n", command, channel_id, epgTitle.c_str(), epgid); if(serverConnect()) { std::string extMessage = getCommandString(command, channel_id, epgid, epgTitle, apids); printf("sending to vcr-client:\n\n%s\n", extMessage.c_str()); write(sock_fd, extMessage.c_str() , extMessage.length() ); serverDisconnect(); deviceState = command; return true; } else return false; }
void workerFunc() { std::cout << "Worker: running" << std::endl; int res; MoveStateDeferred *move_state_deferred; MoveServerPacket *move_server_packet; MoveServerCameraFrameSlicePacket *move_server_camera_frame_slice_packet; move_state_deferred = (MoveStateDeferred *)malloc(sizeof(MoveStateDeferred)); move_server_packet = (MoveServerPacket *)malloc(sizeof(MoveServerPacket)); move_server_camera_frame_slice_packet = (MoveServerCameraFrameSlicePacket *)malloc(sizeof(MoveServerCameraFrameSlicePacket)); move_state_deferred->update_success = updateSuccess; move_state_deferred->update_failure = updateFailure; move_state_deferred->update_camera_success = updateCameraSuccess; move_state_deferred->update_camera_failure = updateCameraFailure; move_state_deferred->move_server_packet = move_server_packet; move_state_deferred->move_server_camera_frame_slice_packet = move_server_camera_frame_slice_packet; // Connect res = serverConnect("192.168.1.14", "7899", move_state_deferred); ROS_ERROR("connect: %d", res); while(1) { io_mutex.lock(); if(ros_down) break; io_mutex.unlock(); boost::posix_time::millisec workTime(3); // Pretend to do something useful... boost::this_thread::sleep(workTime); } io_mutex.unlock(); // Disconnect res = serverDisconnect(); ROS_ERROR("disconnect: %d", res); // Free heap free(move_state_deferred); free(move_server_packet); free(move_server_camera_frame_slice_packet); std::cout << "Worker: finished" << std::endl; }
//------------------------------------------------------------------------- bool CVCRControl::CServerDevice::sendCommand(CVCRCommand command, const t_channel_id channel_id, unsigned long long epgid, uint apid) { printf("Send command: %d channel_id: %x epgid: %llx\n",command, channel_id, epgid); if(serverConnect()) { char tmp[40]; string extCommand="unknown"; string ext_channel_id = "error"; string ext_channel_name = "unknown"; string extEpgid="error"; string extVideoPID="error"; string extAudioPID="error"; string extEPGTitle="not available"; sprintf(tmp,"%u", channel_id); ext_channel_id = tmp; sprintf(tmp,"%llu", epgid); extEpgid = tmp; // sprintf(tmp,"%u", g_RemoteControl->current_PIDs.PIDs.vpid ); CZapitClient::responseGetPIDs pids; g_Zapit->getPIDS (pids); CZapitClient::CCurrentServiceInfo si = g_Zapit->getCurrentServiceInfo (); sprintf(tmp,"%u", si.vdid ); extVideoPID = tmp; // sprintf(tmp,"%u", g_RemoteControl->current_PIDs.APIDs[g_RemoteControl->current_PIDs.PIDs.selected_apid].pid); if(apid==0) apid=(uint)si.apid; sprintf(tmp,"%u", apid); extAudioPID = tmp; CZapitClient::BouquetChannelList channellist; g_Zapit->getChannels(channellist); CZapitClient::BouquetChannelList::iterator channel = channellist.begin(); for(; channel != channellist.end();channel++) { if(channel->channel_id==channel_id) { ext_channel_name=channel->name; break; } } CSectionsdClient sections; CSectionsdClient::responseGetCurrentNextInfoChannelID current_next; if(sections.getCurrentNextServiceKey(channel_id, current_next)) { extEPGTitle=current_next.current_name; } switch(command) { case CMD_VCR_RECORD: extCommand="record"; break; case CMD_VCR_STOP: extCommand="stop"; break; case CMD_VCR_PAUSE: extCommand="pause"; break; case CMD_VCR_RESUME: extCommand="resume"; break; case CMD_VCR_AVAILABLE: extCommand="available"; break; case CMD_VCR_UNKNOWN: default: printf("CVCRControl: Unknown Command\n"); } string extMessage = "<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>\n\n"; extMessage +="<neutrino commandversion=\"1\">\n"; extMessage +=" <record command=\"" + extCommand + "\">\n"; extMessage +=" <channelname>" + ext_channel_name + "</channelname>\n"; extMessage +=" <epgtitle>" + extEPGTitle + "</epgtitle>\n"; extMessage +=" <onidsid>" + ext_channel_id + "</onidsid>\n"; extMessage +=" <epgid>" + extEpgid + "</epgid>\n"; extMessage +=" <videopid>" + extVideoPID + "</videopid>\n"; extMessage +=" <audiopids selected=\"" + extAudioPID + "\">\n"; // super hack :-), der einfachste weg an die apid descriptions ranzukommen g_RemoteControl->current_PIDs = pids; g_RemoteControl->processAPIDnames(); bool apidFound=false; for(unsigned int i= 0; i< pids.APIDs.size(); i++) { sprintf(tmp, "%u", pids.APIDs[i].pid ); extMessage +=" <audio pid=\"" + string(tmp) + "\" name=\"" + string(g_RemoteControl->current_PIDs.APIDs[i].desc) + "\">\n"; if(pids.APIDs[i].pid==apid) apidFound=true; } if(!apidFound) { // add spec apid to available extMessage +=" <audio pid=\"" + extAudioPID + "\" name=\"" + extAudioPID + "\"/>\n"; } extMessage +=" </audiopids>\n"; extMessage +=" </record>\n"; extMessage +="</neutrino>\n"; printf("sending to vcr-client:\n\n%s\n", extMessage.c_str()); write(sock_fd, extMessage.c_str() , extMessage.length() ); serverDisconnect(); deviceState = command; return true; } else return false; }
// PS3 Connect int serverConnect(const char *server_remote_address, const char *server_port, MoveStateDeferred *move_state_deferred) { int rc, last_error; unsigned int tsa_len; struct sockaddr_in service, transfer; struct addrinfo *result = NULL, *addrptr = NULL, hints; char remote_address[100], port[6]; tsa_len = sizeof(transfer); if (s_connected) { return MOVE_CLIENT_OK; } // Save deferred reference s_move_state_deferred = move_state_deferred; memset(&hints, 0, sizeof(hints)); hints.ai_family = AF_INET; hints.ai_socktype = SOCK_STREAM; hints.ai_protocol = IPPROTO_TCP; service.sin_family = AF_INET; service.sin_port = 0; service.sin_addr.s_addr = htonl(INADDR_ANY); memset(service.sin_zero, '\0', sizeof(service.sin_zero)); strncpy(remote_address, server_remote_address, sizeof(remote_address)); remote_address[sizeof(remote_address) - 1] = '\0'; strncpy(port, server_port, sizeof(port)); port[sizeof(port) - 1] = '\0'; if (getaddrinfo(remote_address, port, &hints, &result)) { return errno; } // Create transfer socket if ((s_transfer_sockfd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) == -1) { freeaddrinfo(result); return errno; } // Attempt to connect to an address until one succeeds for (addrptr = result; addrptr != NULL; addrptr = addrptr->ai_next) { if ((s_control_sockdf = socket(addrptr->ai_family, addrptr->ai_socktype, addrptr->ai_protocol)) == -1) { freeaddrinfo(result); return errno; } // Connect to server if (connect(s_control_sockdf, addrptr->ai_addr, (int)addrptr->ai_addrlen) == -1) { close(s_control_sockdf); s_control_sockdf = -1; continue; } break; } freeaddrinfo(result); if (-1 == s_control_sockdf) { last_error = errno; close(s_transfer_sockfd); return last_error; } // Update internal state after all sockets successfully created s_connected = TRUE; // Initialize socket file descriptors for select FD_ZERO(&s_fd_read); FD_ZERO(&s_fd_except); FD_SET(s_transfer_sockfd, &s_fd_read); FD_SET(s_transfer_sockfd, &s_fd_except); // Bind transfer Socket if (bind(s_transfer_sockfd, (struct sockaddr *)&service, sizeof(service)) == -1) { last_error = errno; serverDisconnect(); return last_error; } // Change transfer socket mode to non-blocking int flags = fcntl(s_transfer_sockfd, F_GETFL, 0); if (-1 == fcntl(s_transfer_sockfd, F_SETFL, O_NONBLOCK|flags)) { last_error = errno; serverDisconnect(); return last_error; } // Get transfer socket port if (getsockname(s_transfer_sockfd, (struct sockaddr *)&transfer, &tsa_len)) { last_error = errno; serverDisconnect(); return last_error; } // Start UpdateMoveServer thread if ((rc = startTransfer())) { serverDisconnect(); return rc; } // Send initialization request if ((rc = sendRequestPacket(MOVE_CLIENT_REQUEST_INIT, ntohs(transfer.sin_port)))) { serverDisconnect(); return rc; } return MOVE_CLIENT_OK; }