void halFrameComposerAudio_UserLeft(u16 baseAddr, u8 bit, unsigned channel) { LOG_TRACE2(bit, channel); if (channel < 4) access_CoreWrite(bit, baseAddr + FC_AUDSU, channel, 1); else LOG_ERROR2("invalid channel number: ", channel); }
bool Cx_TextUtil::ReadTextFile(BYTE head[5], std::wstring& content, const std::wstring& filename, ULONG nLenLimitMB, UINT codepage) { ZeroMemory(head, sizeof(BYTE) * 5); content.resize(0); bool bRet = false; HANDLE hFile = ::CreateFileW(filename.c_str(), GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL); if (INVALID_HANDLE_VALUE == hFile) { LOG_ERROR2(LOGHEAD L"IDS_OPEN_FAIL", filename << L", " << GetSystemErrorString(GetLastError())); } else { DWORD dwLength = ::GetFileSize(hFile, NULL); HGLOBAL hBuffer = NULL; if (dwLength != INVALID_FILE_SIZE) { if (dwLength > nLenLimitMB * 1024L * 1024L) { LOG_WARNING2(LOGHEAD L"IDS_HUGE_FILE", (dwLength / (1024.0*1024.0)) << L"MB, " << filename); dwLength = nLenLimitMB * 1024L * 1024L; } hBuffer = GlobalAlloc(GHND, dwLength + 8); } if (hBuffer != NULL) { LPBYTE pBuffer = (LPBYTE)GlobalLock(hBuffer); if (pBuffer != NULL) { DWORD dwBytesRead = 0; ::ReadFile(hFile, pBuffer, dwLength, &dwBytesRead, NULL); if (dwBytesRead > 0) { CopyMemory(head, pBuffer, sizeof(BYTE) * min(5, dwBytesRead)); bRet = GetFileContent(content, pBuffer, dwBytesRead, codepage); if (!bRet) { LOG_WARNING2(LOGHEAD L"IDS_NOT_ANSIFILE", filename); } } GlobalUnlock(hBuffer); } GlobalFree(hBuffer); } ::CloseHandle(hFile); } return bRet; }
bool Cx_FileTransaction::DeletePathFile(LPCWSTR pszFileName, bool bRecycle) { Cx_Interface<Ix_FileUtility> pIFUtility(CLSID_FileUtility); if (NULL == pszFileName || 0 == pszFileName[0] || !pIFUtility->IsPathFileExists(pszFileName)) return true; if (CFileTransactions::Instance().IsRollbacking()) { LOG_ERROR2(LOGHEAD L"IDS_DELETEFILE_ROLLBACK", pszFileName); return false; } std::wstring wstrPath = pIFUtility->GetPathOfFile(pszFileName); std::wstring wstrName = pIFUtility->GetFileName(pszFileName); WCHAR szTmpFile[MAX_PATH] = { 0 }; for (int i = 1; i < 1000; i++) { swprintf_s(szTmpFile, MAX_PATH, L"%s~%s.~%d", wstrPath.c_str(), wstrName.c_str(), i); if (!pIFUtility->IsPathFileExists(szTmpFile)) break; } bool bRet = pIFUtility->RenamePathFile(pszFileName, szTmpFile); if (bRet) { CFileTransactions::Instance().AddStep( new CTransDeleteFile(szTmpFile, bRecycle), new CTransRenameFile(szTmpFile, pszFileName)); } else { LOG_ERROR2(LOGHEAD L"IDS_DELFILE_FAIL", pszFileName); CFileTransactions::Instance().EndTransaction(false); } return bRet; }
void halFrameComposerAudio_IecChannelLeft(u16 baseAddr, u8 value, unsigned channel) { LOG_TRACE2(value, channel); if (channel == 0) access_CoreWrite(value, baseAddr + FC_AUDSCHNLS5, 0, 4); else if (channel == 1) access_CoreWrite(value, baseAddr + FC_AUDSCHNLS5, 4, 4); else if (channel == 2) access_CoreWrite(value, baseAddr + FC_AUDSCHNLS6, 0, 4); else if (channel == 3) access_CoreWrite(value, baseAddr + FC_AUDSCHNLS6, 4, 4); else LOG_ERROR2("invalid channel number: ", channel); }
DWORD Cx_TextUtil::GetHeadBytes(const std::wstring& filename, BYTE head[5]) { DWORD dwBytesRead = 0; HANDLE hFile = ::CreateFileW(filename.c_str(), GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL); if (hFile != INVALID_HANDLE_VALUE) { ::ReadFile(hFile, head, 5, &dwBytesRead, NULL); ::CloseHandle(hFile); } else { LOG_ERROR2(LOGHEAD L"IDS_OPEN_FAIL", filename << L", " << GetSystemErrorString(GetLastError())); } return dwBytesRead; }
bool Cx_TextUtil::SaveTextFile(const std::string& content, const std::wstring& filename, bool utf16, UINT codepage) { bool bRet = false; ::SetFileAttributes(filename.c_str(), FILE_ATTRIBUTE_NORMAL); HANDLE hFile = ::CreateFileW(filename.c_str(), GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL); if (INVALID_HANDLE_VALUE == hFile) { LOG_ERROR2(LOGHEAD L"IDS_WRITE_FAIL", filename << L", " << GetSystemErrorString(GetLastError())); } else { DWORD dwLen, dwBytes; if (utf16) { std::wstring wstrUnicode (std::a2w(content, codepage)); BYTE head[] = { 0xFF, 0xFE }; ::WriteFile(hFile, head, 2, &dwBytes, NULL); dwLen = (DWORD)(wstrUnicode.size() * sizeof(WCHAR)); ::WriteFile(hFile, wstrUnicode.c_str(), dwLen, &dwBytes, NULL); bRet = (dwBytes == dwLen); } else { dwLen = GetSize(content); ::WriteFile(hFile, content.c_str(), dwLen, &dwBytes, NULL); bRet = (dwBytes == dwLen); } ::CloseHandle(hFile); } return bRet; }
void halVideoPacketizer_OutputSelector(u16 baseAddr, u8 value) { LOG_TRACE1(value); if (value == 0) { /* pixel packing */ access_CoreWrite(0, (baseAddr + VP_CONF), 6, 1); /* enable pixel packing */ access_CoreWrite(1, (baseAddr + VP_CONF), 5, 1); access_CoreWrite(0, (baseAddr + VP_CONF), 3, 1); } else if (value == 1) { /* YCC422 */ access_CoreWrite(0, (baseAddr + VP_CONF), 6, 1); access_CoreWrite(0, (baseAddr + VP_CONF), 5, 1); /* enable YCC422 */ access_CoreWrite(1, (baseAddr + VP_CONF), 3, 1); } else if (value == 2 || value == 3) { /* bypass */ /* enable bypass */ access_CoreWrite(1, (baseAddr + VP_CONF), 6, 1); access_CoreWrite(0, (baseAddr + VP_CONF), 5, 1); access_CoreWrite(0, (baseAddr + VP_CONF), 3, 1); } else { LOG_ERROR2("wrong output option: ", value); return; } /* YCC422 stuffing */ access_CoreWrite(1, (baseAddr + VP_STUFF), 2, 1); /* pixel packing stuffing */ access_CoreWrite(1, (baseAddr + VP_STUFF), 1, 1); /* ouput selector */ access_CoreWrite(value, (baseAddr + VP_CONF), 0, 2); }
/* Core streaming function for this module * This is what actually produces the data which gets streamed. * * returns: >0 Number of bytes read * 0 Non-fatal error. * <0 Fatal error. */ static int playlist_read(void *self, ref_buffer *rb) { playlist_state_t *pl = (playlist_state_t *)self; int bytes; unsigned char *buf; char *newfn; int result; ogg_page og; if (pl->errors > 5) { LOG_WARN0("Too many consecutive errors - exiting"); return -1; } if (!pl->current_file || pl->nexttrack) { pl->nexttrack = 0; if (pl->current_file && strcmp (pl->filename, "-")) { fclose(pl->current_file); pl->current_file = NULL; } if (pl->file_ended) { pl->file_ended(pl->data, pl->filename); } newfn = pl->get_filename(pl->data); if (!newfn) { LOG_INFO0("No more filenames available, end of playlist"); return -1; /* No more files available */ } if (strcmp (newfn, "-")) { if (!pl->allow_repeat && pl->filename && !strcmp(pl->filename, newfn)) { LOG_ERROR0("Cannot play same file twice in a row, skipping"); pl->errors++; pl->free_filename (pl->data, newfn); return 0; } pl->free_filename(pl->data, pl->filename); pl->filename = newfn; pl->current_file = fopen(pl->filename, "rb"); if (!pl->current_file) { LOG_WARN2("Error opening file \"%s\": %s",pl->filename, strerror(errno)); pl->errors++; return 0; } LOG_INFO1("Currently playing \"%s\"", pl->filename); } else { LOG_INFO0("Currently playing from stdin"); pl->current_file = stdin; pl->free_filename(pl->data, pl->filename); pl->filename = newfn; } /* Reinit sync, so that dead data from previous file is discarded */ ogg_sync_clear(&pl->oy); ogg_sync_init(&pl->oy); } input_sleep (); while(1) { result = ogg_sync_pageout(&pl->oy, &og); if(result < 0) LOG_WARN1("Corrupt or missing data in file (%s)", pl->filename); else if(result > 0) { if (ogg_page_bos (&og)) { if (ogg_page_serialno (&og) == pl->current_serial) LOG_WARN1 ("detected duplicate serial number reading \"%s\"", pl->filename); pl->current_serial = ogg_page_serialno (&og); } if (input_calculate_ogg_sleep (&og) < 0) { pl->nexttrack = 1; return 0; } rb->len = og.header_len + og.body_len; rb->buf = malloc(rb->len); rb->aux_data = og.header_len; memcpy(rb->buf, og.header, og.header_len); memcpy(rb->buf+og.header_len, og.body, og.body_len); if(ogg_page_granulepos(&og)==0) rb->critical = 1; break; } /* If we got to here, we didn't have enough data. */ buf = ogg_sync_buffer(&pl->oy, BUFSIZE); bytes = fread(buf,1, BUFSIZE, pl->current_file); if (bytes <= 0) { if (feof(pl->current_file)) { pl->nexttrack = 1; return playlist_read(pl,rb); } else { LOG_ERROR2("Read error from \"%s\": %s", pl->filename, strerror(errno)); fclose(pl->current_file); pl->current_file=NULL; pl->errors++; return 0; } } else ogg_sync_wrote(&pl->oy, bytes); } pl->errors=0; return rb->len; }
BOOL getValue(int mouseNb, MOTION_MOUSE *motion) { uint8 notReceived; //verify nb of bytes in the uart stack if(uart_GetDataSize(mice[mouseNb].uart) >= sizeof(MOTION_MOUSE)) { //wait answer during max one tick notReceived = uart_Get(mice[mouseNb].uart, (uint8*)&motion->code, sizeof(motion->code), 1); if(notReceived == 0) { if(motion->code != X_Y_MOTION) { if((mice[mouseNb].nbUnkError++ % 100)==0) { LOG_ERROR2("M%d : Unknown message = %ld", mouseNb, mice[mouseNb].nbUnkError); } mice[mouseNb].error++; return FALSE; } } else { LOG_ERROR1("Mouse %d : Time'd out ???", mouseNb); mice[mouseNb].error++; return FALSE; } //wait for the rest of mouse message during max one tick notReceived = uart_Get(mice[mouseNb].uart, ((uint8*)motion)+1, sizeof(MOTION_MOUSE)-1, 1); if(notReceived == 0) { if(computeChecksum(motion) != motion->checksum) { if((mice[mouseNb].nbCksmError++ % 100)==0) { LOG_ERROR2("M%d: Checksum error= %ld", mouseNb, mice[mouseNb].nbCksmError); } mice[mouseNb].error++; return FALSE; } else { //quick integrity verification if((fabs(motion->X.f) >= 5000.0f) || (fabs(motion->Y.f) >= 5000.0f)) { LOG_DEBUG3("M%d: %4.2g, %4.2g", mouseNb, motion->X.f, motion->Y.f); return FALSE; } mice[mouseNb].error = 0; return TRUE; } } else { LOG_ERROR1("Mouse %d : Time'd out ???", mouseNb); mice[mouseNb].error++; return FALSE; } } return FALSE; }
input_module_t *alsa_open_module(module_param_t *params) { input_module_t *mod = calloc(1, sizeof(input_module_t)); im_alsa_state *s; module_param_t *current; char *device = "plughw:0,0"; /* default device */ int format = AFMT_S16_LE; int channels, rate; int use_metadata = 1; /* Default to on */ unsigned int buffered_time; snd_pcm_stream_t stream = SND_PCM_STREAM_CAPTURE; snd_pcm_hw_params_t *hwparams; int err; mod->type = ICES_INPUT_PCM; mod->subtype = INPUT_PCM_LE_16; mod->getdata = alsa_read; mod->handle_event = event_handler; mod->metadata_update = metadata_update; mod->internal = calloc(1, sizeof(im_alsa_state)); s = mod->internal; s->fd = NULL; /* Set it to something invalid, for now */ s->rate = 44100; /* Defaults */ s->channels = 2; thread_mutex_create(&s->metadatalock); current = params; while(current) { if(!strcmp(current->name, "rate")) s->rate = atoi(current->value); else if(!strcmp(current->name, "channels")) s->channels = atoi(current->value); else if(!strcmp(current->name, "device")) device = current->value; else if(!strcmp(current->name, "metadata")) use_metadata = atoi(current->value); else if(!strcmp(current->name, "metadatafilename")) ices_config->metadata_filename = current->value; else LOG_WARN1("Unknown parameter %s for alsa module", current->name); current = current->next; } snd_pcm_hw_params_alloca(&hwparams); if ((err = snd_pcm_open(&s->fd, device, stream, 0)) < 0) { LOG_ERROR2("Failed to open audio device %s: %s", device, snd_strerror(err)); goto fail; } if ((err = snd_pcm_hw_params_any(s->fd, hwparams)) < 0) { LOG_ERROR1("Failed to initialize hwparams: %s", snd_strerror(err)); goto fail; } if ((err = snd_pcm_hw_params_set_access(s->fd, hwparams, SND_PCM_ACCESS_RW_INTERLEAVED)) < 0) { LOG_ERROR1("Error setting access: %s", snd_strerror(err)); goto fail; } if ((err = snd_pcm_hw_params_set_format(s->fd, hwparams, SND_PCM_FORMAT_S16_LE)) < 0) { LOG_ERROR1("Couldn't set sample format to SND_PCM_FORMAT_S16_LE: %s", snd_strerror(err)); goto fail; } if ((err = snd_pcm_hw_params_set_rate_near(s->fd, hwparams, &s->rate, 0)) < 0) { LOG_ERROR1("Error setting rate: %s", snd_strerror(err)); goto fail; } if ((err = snd_pcm_hw_params_set_channels(s->fd, hwparams, s->channels)) < 0) { LOG_ERROR1("Error setting channels: %s", snd_strerror(err)); goto fail; } if ((err = snd_pcm_hw_params_set_periods(s->fd, hwparams, 2, 0)) < 0) { LOG_ERROR1("Error setting periods: %s", snd_strerror(err)); goto fail; } buffered_time = 500000; if ((err = snd_pcm_hw_params_set_buffer_time_near(s->fd, hwparams, &buffered_time, 0)) < 0) { LOG_ERROR1("Error setting buffersize: %s", snd_strerror(err)); goto fail; } if ((err = snd_pcm_hw_params(s->fd, hwparams)) < 0) { LOG_ERROR1("Error setting HW params: %s", snd_strerror(err)); goto fail; } /* We're done, and we didn't fail! */ LOG_INFO3("Opened audio device %s at %d channel(s), %d Hz", device, s->channels, s->rate); if(use_metadata) { if(ices_config->metadata_filename) thread_create("im_alsa-metadata", metadata_thread_signal, mod, 1); else thread_create("im_alsa-metadata", metadata_thread_stdin, mod, 1); LOG_INFO0("Started metadata update thread"); } return mod; fail: close_module(mod); /* safe, this checks for valid contents */ return NULL; }
int packets_Configure(u16 baseAddr, videoParams_t * video, productParams_t * prod) { u8 send3d = FALSE; LOG_TRACE(); if (videoParams_GetHdmiVideoFormat(video) == 2) { if (videoParams_Get3dStructure(video) == 6 || videoParams_Get3dStructure(video) == 8) { u8 data[3]; data[0] = videoParams_GetHdmiVideoFormat(video) << 5; data[1] = videoParams_Get3dStructure(video) << 4; data[2] = videoParams_Get3dExtData(video) << 4; packets_VendorSpecificInfoFrame(baseAddr, 0x000C03, data, sizeof(data), 1); /* HDMI Licensing, LLC */ send3d = TRUE; } else { LOG_ERROR2("3D structure not supported", videoParams_Get3dStructure(video)); error_Set(ERR_3D_STRUCT_NOT_SUPPORTED); return FALSE; } } if (prod != 0) { if (productParams_IsSourceProductValid(prod)) { packets_SourceProductInfoFrame(baseAddr, productParams_GetVendorName(prod), productParams_GetVendorNameLength(prod), productParams_GetProductName(prod), productParams_GetProductNameLength(prod), productParams_GetSourceType(prod), 1); } if (productParams_IsVendorSpecificValid(prod)) { if (send3d) { LOG_WARNING("forcing Vendor Specific InfoFrame, 3D configuration will be ignored"); error_Set(ERR_FORCING_VSD_3D_IGNORED); } packets_VendorSpecificInfoFrame(baseAddr, productParams_GetOUI(prod), productParams_GetVendorPayload( prod), productParams_GetVendorPayloadLength(prod), 1); } } else { LOG_WARNING("No product info provided: not configured"); } /* set values that shall not change */ halFrameComposerPackets_MetadataFrameInterpolation(baseAddr + FC_BASE_ADDR, 1); halFrameComposerPackets_MetadataFramesPerPacket(baseAddr + FC_BASE_ADDR, 1); halFrameComposerPackets_MetadataLineSpacing(baseAddr + FC_BASE_ADDR, 1); halFrameComposerGcp_DefaultPhase(baseAddr + FC_BASE_ADDR, videoParams_GetPixelPackingDefaultPhase(video) == 1); /* default phase 1 = true */ halFrameComposerGamut_Profile(baseAddr + FC_BASE_ADDR + 0x100, 0x0); /* P0 */ halFrameComposerGamut_PacketsPerFrame(baseAddr + FC_BASE_ADDR + 0x100, 0x1); /* P0 */ halFrameComposerGamut_PacketLineSpacing(baseAddr + FC_BASE_ADDR + 0x100, 0x1); packets_AuxiliaryVideoInfoFrame(baseAddr, video); return TRUE; }
/* The main loop for each instance. Gets data passed to it from the stream * manager (which gets it from the input module), and streams it to the * specified server */ void *ices_instance_stream(void *arg) { int ret, shouterr; ref_buffer *buffer; char *connip; stream_description *sdsc = arg; instance_t *stream = sdsc->stream; input_module_t *inmod = sdsc->input; int reencoding = (inmod->type == ICES_INPUT_VORBIS) && stream->encode; int encoding = (inmod->type == ICES_INPUT_PCM) && stream->encode; char *stream_name = NULL, *stream_genre = NULL, *stream_description = NULL; char *user = NULL; vorbis_comment_init(&sdsc->vc); sdsc->shout = shout_new(); /* we only support the ice protocol and vorbis streams currently */ shout_set_format(sdsc->shout, SHOUT_FORMAT_VORBIS); //shout_set_protocol(sdsc->shout, SHOUT_PROTOCOL_ICE); shout_set_protocol(sdsc->shout, SHOUT_PROTOCOL_HTTP); signal(SIGPIPE, signal_hup_handler); connip = malloc(16); if(!resolver_getip(stream->hostname, connip, 16)) { LOG_ERROR1("Could not resolve hostname \"%s\"", stream->hostname); free(connip); stream->died = 1; return NULL; } if (!(shout_set_host(sdsc->shout, connip)) == SHOUTERR_SUCCESS) { LOG_ERROR1("libshout error: %s\n", shout_get_error(sdsc->shout)); free(connip); stream->died = 1; return NULL; } shout_set_port(sdsc->shout, stream->port); if (!(shout_set_password(sdsc->shout, stream->password)) == SHOUTERR_SUCCESS) { LOG_ERROR1("libshout error: %s\n", shout_get_error(sdsc->shout)); free(connip); stream->died = 1; return NULL; } if (stream->user) user = stream->user; else user = "******"; if(shout_set_user(sdsc->shout, user) != SHOUTERR_SUCCESS) { LOG_ERROR1("libshout error: %s\n", shout_get_error(sdsc->shout)); free(connip); stream->died = 1; return NULL; } if (!(shout_set_agent(sdsc->shout, VERSIONSTRING)) == SHOUTERR_SUCCESS) { LOG_ERROR1("libshout error: %s\n", shout_get_error(sdsc->shout)); free(connip); stream->died = 1; return NULL; } if (!(shout_set_mount(sdsc->shout, stream->mount)) == SHOUTERR_SUCCESS) { LOG_ERROR1("libshout error: %s\n", shout_get_error(sdsc->shout)); free(connip); stream->died = 1; return NULL; } /* set the metadata for the stream */ if(stream->stream_name) stream_name = stream->stream_name; else if (ices_config->stream_name) stream_name = ices_config->stream_name; if(stream->stream_description) stream_description = stream->stream_description; else if (ices_config->stream_description) stream_description = ices_config->stream_description; if(stream->stream_genre) stream_genre = stream->stream_genre; else if (ices_config->stream_genre) stream_genre = ices_config->stream_genre; if(stream_name) if (!(shout_set_name(sdsc->shout, stream_name)) == SHOUTERR_SUCCESS) { LOG_ERROR1("libshout error: %s\n", shout_get_error(sdsc->shout)); free(connip); stream->died = 1; return NULL; } if (stream_genre) if (!(shout_set_genre(sdsc->shout, stream_genre)) == SHOUTERR_SUCCESS) { LOG_ERROR1("libshout error: %s\n", shout_get_error(sdsc->shout)); free(connip); stream->died = 1; return NULL; } if (stream_description) if (!(shout_set_description(sdsc->shout, stream_description)) == SHOUTERR_SUCCESS) { LOG_ERROR1("libshout error: %s\n", shout_get_error(sdsc->shout)); free(connip); stream->died = 1; return NULL; } if(stream->downmix && encoding && stream->channels == 1) { stream->channels = 1; sdsc->downmix = downmix_initialise(); } if(stream->resampleinrate && stream->resampleoutrate && encoding) { stream->samplerate = stream->resampleoutrate; sdsc->resamp = resample_initialise(stream->channels, stream->resampleinrate, stream->resampleoutrate); } if(encoding) { if(inmod->metadata_update) inmod->metadata_update(inmod->internal, &sdsc->vc); sdsc->enc = encode_initialise(stream->channels, stream->samplerate, stream->managed, stream->min_br, stream->nom_br, stream->max_br, stream->quality, stream->serial++, &sdsc->vc); if(!sdsc->enc) { LOG_ERROR0("Failed to configure encoder"); stream->died = 1; return NULL; /* FIXME: probably leaking some memory here */ } } else if(reencoding) sdsc->reenc = reencode_init(stream); if(stream->savefilename != NULL) { stream->savefile = fopen(stream->savefilename, "wb"); if(!stream->savefile) LOG_ERROR2("Failed to open stream save file %s: %s", stream->savefilename, strerror(errno)); else LOG_INFO1("Saving stream to file %s", stream->savefilename); } if((shouterr = shout_open(sdsc->shout)) == SHOUTERR_SUCCESS) { LOG_INFO3("Connected to server: %s:%d%s", shout_get_host(sdsc->shout), shout_get_port(sdsc->shout), shout_get_mount(sdsc->shout)); while(1) { if(stream->buffer_failures > MAX_ERRORS) { LOG_WARN0("Too many errors, shutting down"); break; } buffer = stream_wait_for_data(stream); /* buffer being NULL means that either a fatal error occured, * or we've been told to shut down */ if(!buffer) break; /* If data is NULL or length is 0, we should just skip this one. * Probably, we've been signalled to shut down, and that'll be * caught next iteration. Add to the error count just in case, * so that we eventually break out anyway */ if(!buffer->buf || !buffer->len) { LOG_WARN0("Bad buffer dequeued!"); stream->buffer_failures++; continue; } if(stream->wait_for_critical) { LOG_INFO0("Trying restart on new substream"); stream->wait_for_critical = 0; } ret = process_and_send_buffer(sdsc, buffer); /* No data produced, do nothing */ if(ret == -1) ; /* Fatal error */ else if(ret == -2) { LOG_ERROR0("Serious error, waiting to restart on " "next substream. Stream temporarily suspended."); /* Set to wait until a critical buffer comes through (start of * a new substream, typically), and flush existing queue. */ thread_mutex_lock(&ices_config->flush_lock); stream->wait_for_critical = 1; input_flush_queue(stream->queue, 0); thread_mutex_unlock(&ices_config->flush_lock); } /* Non-fatal shout error */ else if(ret == 0) { LOG_ERROR2("Send error: %s (%s)", shout_get_error(sdsc->shout), strerror(errno)); if(shout_get_errno(sdsc->shout) == SHOUTERR_SOCKET) { int i=0; /* While we're trying to reconnect, don't receive data * to this instance, or we'll overflow once reconnect * succeeds */ thread_mutex_lock(&ices_config->flush_lock); stream->skip = 1; /* Also, flush the current queue */ input_flush_queue(stream->queue, 1); thread_mutex_unlock(&ices_config->flush_lock); while((i < stream->reconnect_attempts || stream->reconnect_attempts==-1) && !ices_config->shutdown) { i++; LOG_WARN0("Trying reconnect after server socket error"); shout_close(sdsc->shout); if((shouterr = shout_open(sdsc->shout)) == SHOUTERR_SUCCESS) { LOG_INFO3("Connected to server: %s:%d%s", shout_get_host(sdsc->shout), shout_get_port(sdsc->shout), shout_get_mount(sdsc->shout)); /* This stream can't restart until the next * logical stream comes along, since the * server won't have any cached headers for * this source/connection. So, don't continue * yet. */ thread_mutex_lock(&ices_config->flush_lock); stream->wait_for_critical = 1; input_flush_queue(stream->queue, 0); thread_mutex_unlock(&ices_config->flush_lock); break; } else { LOG_ERROR3("Failed to reconnect to %s:%d (%s)", shout_get_host(sdsc->shout),shout_get_port(sdsc->shout), shout_get_error(sdsc->shout)); if(i==stream->reconnect_attempts) { LOG_ERROR0("Reconnect failed too many times, " "giving up."); /* We want to die now */ stream->buffer_failures = MAX_ERRORS+1; } else /* Don't try again too soon */ sleep(stream->reconnect_delay); } } stream->skip = 0; } stream->buffer_failures++; } stream_release_buffer(buffer); } } else { LOG_ERROR3("Failed initial connect to %s:%d (%s)", shout_get_host(sdsc->shout),shout_get_port(sdsc->shout), shout_get_error(sdsc->shout)); } shout_close(sdsc->shout); if(stream->savefile != NULL) fclose(stream->savefile); shout_free(sdsc->shout); encode_clear(sdsc->enc); reencode_clear(sdsc->reenc); downmix_clear(sdsc->downmix); resample_clear(sdsc->resamp); vorbis_comment_clear(&sdsc->vc); stream->died = 1; return NULL; }
/** Standard AOLserver callback. * Initialize jk2, unless already done in another server. Register URI mappping for Tomcat * If multiple virtual servers use this module, calls to Ns_ModuleInit will be made serially * in order of appearance of those servers in nsd.tcl */ int Ns_ModuleInit(char *server, char *module) { jk_env_t *env; /* configuration-related */ char* serverName=NULL; char* confPath; static char cwdBuf[PATH_MAX]; static char* serverRoot = NULL; /* APR-related */ apr_status_t aprrc; char errbuf[512]; apr_pool_t *jk_globalPool = NULL; /* URI registration */ char *hosts[2] = {"*", NULL}; jk_map_t *vhosts; int i, j, k, l, cnt1, cnt2; jk_map_t *uriMap, *webapps, *uriMaps[3]; jk_uriEnv_t *uriEnv, *hostEnv, *appEnv; if (jkInitCount++ == 0) { /* Get Tomcat installation root - this value is same for all virtual servers*/ if (serverRoot == NULL) { confPath = Ns_ConfigGetPath (NULL, module, NULL); serverRoot = (confPath? Ns_ConfigGetValue (confPath, "serverRoot") : NULL); } /* not configured in nsd.tcl? try env. variable */ if (serverRoot == NULL) { serverRoot = getenv ("TOMCAT_HOME"); } /* not in env. variables? get it from CWD */ if (serverRoot == NULL) { serverRoot = getcwd (cwdBuf, sizeof(cwdBuf)); } /* Initialize APR */ if ((aprrc=apr_initialize()) != APR_SUCCESS) { LOG_ERROR2 ("Cannot initialize APR", apr_strerror (aprrc, errbuf, sizeof(errbuf))); return NS_ERROR; } if ((aprrc=apr_pool_create(&jk_globalPool, NULL)) != APR_SUCCESS) { LOG_ERROR2 ("Cannot create global APR pool", apr_strerror (aprrc, errbuf, sizeof(errbuf))); return NS_ERROR; } /* Initialize JNI */ if (workerEnv==NULL && jk2_create_workerEnv(jk_globalPool, serverRoot)==JK_ERR) { return NS_ERROR; } env=workerEnv->globalEnv; env->setAprPool(env, jk_globalPool); /* Initialize JK2 */ if (workerEnv->init(env, workerEnv ) != JK_OK) { LOG_ERROR("Cannot initialize worker environment"); return NS_ERROR; } workerEnv->server_name = apr_pstrcat (jk_globalPool, Ns_InfoServerName(), " ", Ns_InfoServerVersion (), NULL); apr_pool_cleanup_register(jk_globalPool, NULL, jk2_shutdown, apr_pool_cleanup_null); workerEnv->was_initialized = JK_TRUE; if ((aprrc=apr_pool_userdata_set( "INITOK", "Ns_ModuleInit", NULL, jk_globalPool )) != APR_SUCCESS) { LOG_ERROR2 ("Cannot set APR pool user data", apr_strerror (aprrc, errbuf, sizeof(errbuf))); return NS_ERROR; } if (workerEnv->parentInit( env, workerEnv) != JK_OK) { LOG_ERROR ("Cannot initialize global environment"); return NS_ERROR; } /* Obtain TLS slot - it's destructor will detach threads from JVM */ jvmGlobal = workerEnv->vm->jvm; Ns_TlsAlloc (&jkTls, jkTlsDtor); Ns_Log (Notice, "nsjk2: Initialized JK2 environment"); } else { env = workerEnv->globalEnv; } Ns_RegisterShutdown (jk2_shutdown_system, NULL); /* Register URI patterns from workers2.properties with AOLserver * * Worker environment has a list of vhosts, including "*" vhost. * Each vhost has a list of web applications (contexts) associated with it. * Each webapp has a list of exact, prefix, suffix and regexp URI patterns. * * Will register URIs that are either in vhost "*", or one with name matching * this AOLserver virtual server. Will ignore regexp patterns. Will register * exact webapp URIs (context root) as JK2 somehow doesn't include them in URI * maps, even if specified in workers2.properties. * */ /* virtual server name override if specified */ confPath = Ns_ConfigGetPath (server, module, NULL); if (confPath != NULL) serverName = Ns_ConfigGetValue (confPath, "serverName"); if (serverName == NULL) serverName = server; vhosts=workerEnv->uriMap->vhosts; hosts[1]= serverName; for (i=0; i<sizeof(hosts)/sizeof(*hosts); i++) { hostEnv=vhosts->get (env, vhosts, hosts[i]); if (hostEnv==NULL || hostEnv->webapps==NULL) continue; webapps=hostEnv->webapps; cnt1=webapps->size(env, webapps); for (j=0; j<cnt1; j++) { appEnv = webapps->valueAt (env, webapps, j); if (appEnv == NULL) continue; /* register webapp root - registerURI checks if it is "/" */ registerURI (env, appEnv, server, serverName); uriMaps[0] = appEnv->exactMatch; uriMaps[1] = appEnv->prefixMatch; uriMaps[2] = appEnv->suffixMatch; for (k=0; k<sizeof(uriMaps)/sizeof(*uriMaps); k++) { if (uriMaps[k] == NULL) continue; cnt2 = uriMaps[k]->size (env, uriMaps[k]); for (l=0; l<cnt2; l++) { registerURI (env, uriMaps[k]->valueAt (env, uriMaps[k], l), server, serverName); } } } } Ns_Log (Notice, "nsjk2: Initialized on %s", server); return NS_OK; }
input_module_t *roar_open_module(module_param_t *params) { input_module_t *mod = calloc(1, sizeof(input_module_t)); im_roar_state *s; module_param_t *current; const char * server = NULL; int dir = ROAR_DIR_MONITOR; enum { MD_NONE = 0, MD_FILE = 1, MD_STREAM = 2 } use_metadata = MD_STREAM; int err; mod->getdata = roar_read; mod->handle_event = event_handler; mod->metadata_update = metadata_update; mod->internal = calloc(1, sizeof(im_roar_state)); s = mod->internal; if(roar_profile2info(&s->info, "default") == -1) { LOG_ERROR1("Failed to get default audio profile: %s", roar_error2str(roar_error)); return NULL; } s->info.bits = 16; s->vss = NULL; s->plugins = roar_plugincontainer_new_simple(IM_ROAR_APPNAME, IM_ROAR_ABIVERSION); if (!s->plugins) { LOG_ERROR1("Failed to create plugin container: %s", roar_error2str(roar_error)); return NULL; } thread_mutex_create(&s->metadatalock); current = params; while(current) { if(!strcmp(current->name, "rate")) s->info.rate = roar_str2rate(current->value); else if(!strcmp(current->name, "channels")) s->info.channels = roar_str2channels(current->value); else if(!strcmp(current->name, "codec")) s->info.codec = roar_str2codec(current->value); else if(!strcmp(current->name, "aiprofile")) { if (roar_profile2info(&s->info, current->value) == -1) { LOG_WARN2("Can not get audio info profile %s: %s", current->value, roar_error2str(roar_error)); } s->info.bits = 16; } else if(!strcmp(current->name, "dir")) { if ( !strcasecmp(current->value, "monitor") ) { dir = ROAR_DIR_MONITOR; } else if ( !strcasecmp(current->value, "record") ) { dir = ROAR_DIR_RECORD; } else { LOG_WARN2("Unknown value %s for parameter %s for roar module", current->value, current->name); } } else if(!strcmp(current->name, "device") || !strcmp(current->name, "server")) server = current->value; else if(!strcmp(current->name, "metadata")) { if ( !strcasecmp(current->value, "none") ) { use_metadata = MD_NONE; } else if ( !strcasecmp(current->value, "file") ) { use_metadata = MD_FILE; } else if ( !strcasecmp(current->value, "stream") ) { use_metadata = MD_STREAM; } else { use_metadata = atoi(current->value); } } else if(!strcmp(current->name, "metadatafilename")) { ices_config->metadata_filename = current->value; use_metadata = MD_FILE; } else if(!strcmp(current->name, "plugin")) { roar_plugin_load(mod, current->value); } else LOG_WARN1("Unknown parameter %s for roar module", current->name); current = current->next; } mod->type = ICES_INPUT_PCM; switch (s->info.codec) { case ROAR_CODEC_PCM_LE: mod->subtype = INPUT_PCM_LE_16; break; case ROAR_CODEC_PCM_BE: mod->subtype = INPUT_PCM_BE_16; break; case ROAR_CODEC_OGG_GENERAL: LOG_WARN0("Codec may not work, specify ogg_vorbis for Vorbis streaming"); case ROAR_CODEC_OGG_VORBIS: mod->type = ICES_INPUT_VORBIS; // we do not set mod->subtype here, strange design ices2 has... break; case -1: LOG_ERROR0("Unknown Codec"); return NULL; default: LOG_ERROR1("Unsupported Codec: %s", roar_codec2str(s->info.codec)); return NULL; } roar_plugincontainer_appsched_trigger(s->plugins, ROAR_DL_APPSCHED_INIT); /* Open the VS connection */ if ( (s->vss = roar_vs_new(server, IM_ROAR_PROGNAME, &err)) == NULL ) { LOG_ERROR2("Failed to open sound server %s: %s", server, roar_vs_strerr(err)); goto fail; } /* Now, set the required parameters on that device */ if ( roar_vs_stream(s->vss, &s->info, dir, &err) == -1 ) { LOG_ERROR2("Failed to create a new stream on sound server %s: %s", server, roar_vs_strerr(err)); goto fail; } if ( _set_flags(roar_vs_connection_obj(s->vss, NULL), roar_vs_stream_obj(s->vss, NULL), ROAR_FLAG_META, ROAR_RESET_FLAG) != 0 ) { LOG_WARN0("Can not reset metadata flag from stream"); } /* We're done, and we didn't fail! */ LOG_INFO3("Opened sound server at %s at %d channel(s), %d Hz", server, s->info.channels, s->info.rate); switch (use_metadata) { case MD_NONE: break; case MD_FILE: LOG_INFO0("Starting metadata update thread"); if(ices_config->metadata_filename) thread_create("im_roar-metadata", metadata_thread_signal, mod, 1); else thread_create("im_roar-metadata", metadata_thread_stdin, mod, 1); break; case MD_STREAM: if ( _set_flags(roar_vs_connection_obj(s->vss, NULL), roar_vs_stream_obj(s->vss, NULL), ROAR_FLAG_META, ROAR_SET_FLAG) != 0 ) { LOG_WARN0("Can not set metadata flag from stream"); } break; } return mod; fail: close_module(mod); /* safe, this checks for valid contents */ return NULL; }
int get_image_chunk_tivo(gop_index_t * gop_index,module_t * module) { /* Iteration */ int i; /* The chunk we read */ chunk_t * chunk = NULL; /* The chunk linked list */ chunk_t * chunks = NULL; /* vstream */ vstream_t * vstream; int chunks_to_read; int result; chunks_to_read = 2; /* Find out how many chunks we need to read if pes and i frame is in the same chunk then two chunks if not three chunks */ vstream = new_vstream(); /* Lets fake it and do a read buffer */ vstream->start_stream = (uint8_t *)malloc(sizeof(uint8_t) * CHUNK_SIZE); vstream->size = sizeof(uint8_t) * CHUNK_SIZE ; vstream->current_pos = vstream->start_stream; vstream->end_stream = vstream->start_stream + vstream->size; tystream->vstream = vstream; for(i=0; i < chunks_to_read; i++) { vstream->current_pos = vstream->start_stream; vstream->eof=0; read_a_chunk(infile, gop_index->chunk_number_i_frame + i + tystream->start_chunk, vstream->start_stream); chunk = read_chunk(tystream, gop_index->chunk_number_i_frame_pes + i, 1); if(chunk) { chunks = add_chunk(tystream, chunk, chunks); } else { chunks_to_read++; } } free_vstream(vstream); tystream->vstream=NULL; result = get_video(gop_index->i_frame_rec_nr, module, chunks, MPEG_I, tystream); if(!result) { LOG_ERROR2("parse_chunk_video: ERROR - i-frame - chunk %lld , record %i\n", \ chunks->chunk_number,gop_index->i_frame_rec_nr ); free_junk_chunks(chunks); return(0); } //write(2,data_collector_module.data_buffer,data_collector_module.buffer_size); free_junk_chunks(chunks); return(1); }
int get_first_seq_tivo(gop_index_t * gop_index, module_t * module) { /* Iteration */ int i; /* vstream */ vstream_t * vstream; /* The chunk we read */ chunk_t * chunk = NULL; /* The chunk linked list */ chunk_t * chunks = NULL; int chunks_to_read; int result; vstream = new_vstream(); /* Lets fake it and do a read buffer */ vstream->start_stream = (uint8_t *)malloc(sizeof(uint8_t) * CHUNK_SIZE); vstream->size = sizeof(uint8_t) * CHUNK_SIZE ; vstream->current_pos = vstream->start_stream; vstream->end_stream = vstream->start_stream + vstream->size; tystream->vstream = vstream; chunks_to_read = 2; for(i=0; i < chunks_to_read; i++) { vstream->current_pos = vstream->start_stream; vstream->eof=0; read_a_chunk(infile, gop_index->chunk_number_seq + i + tystream->start_chunk, vstream->start_stream); chunk = read_chunk(tystream, gop_index->chunk_number_seq + i + tystream->start_chunk, 1); if(chunk) { chunks = add_chunk(tystream, chunk, chunks); } else { chunks_to_read++; } } free_vstream(vstream); tystream->vstream=NULL; LOG_DEVDIAG("getting seq\n"); result = get_video(gop_index->seq_rec_nr, module, chunks, MPEG_SEQ, tystream); if(!result) { LOG_ERROR2("parse_chunk_video: ERROR - seq-frame - chunk %lld , record %i\n", \ chunks->chunk_number, gop_index->seq_rec_nr); free_junk_chunks(chunks); return(get_first_seq(tystream,gop_index->next,module)); return(0); } LOG_DEVDIAG("setting seq\n"); set_seq_low_delay(tystream, module); free_junk_chunks(chunks); LOG_DEVDIAG("getting seq done\n"); return(1); }
bool CSocket::Recv( char* pszData, long nLen, bool bEmptyError /*= true*/ ) { bool bResult = false; static uint anTimeOuts[ DEFAULT_CHECK_ATTEMPTS ] = { 500, 2000, 5000 }; do { bool bLoopError = false; long nExpectedLen = 0, nRecvLen = 0, nRes = 0, nNetLen = 0; m_nBytesRead = 0; if( !nLen ) LOG_ERROR_BREAK( "Receiving buffer size is 0" ); if( !pszData ) LOG_ERROR_BREAK( "pszData is NULL" ); size_t nAttempts = 0; do { m_tvTimeOut.tv_sec = (long)anTimeOuts[nAttempts] / 1000; m_tvTimeOut.tv_usec = ( anTimeOuts[nAttempts] % 1000 ) * 1000; FD_ZERO(&m_fdReadSockets); FD_SET(m_sockMain, &m_fdReadSockets); if( SOCKET_ERROR == (nRes = select(int(m_sockMain)+1, &m_fdReadSockets, 0, 0, &m_tvTimeOut)) ) { LOG_ERROR3_BREAK( szErrorFailedWithCodeFmt, "select", WSAGetLastError() ); } } while( !nRes && m_nCheckAttempts > nAttempts++ ); if( !nRes ) break; // LOG_ERROR_BREAK( szSocketNotReady ); if( !FD_ISSET(m_sockMain, &m_fdReadSockets) ) LOG_ERROR_BREAK( "Timeout elapsed" ); nExpectedLen = nLen; if( m_bUseHeaderLength ) { nRecvLen = recv( m_sockMain, (char*)&nNetLen, sizeof(nNetLen), 0 ); if( SOCKET_ERROR == nRecvLen || !nRecvLen ) { LOG_ERROR3_BREAK( szErrorFailedWithCodeFmt, "recv", WSAGetLastError() ); } nExpectedLen = ntohl( nNetLen ); if( nExpectedLen > nLen ) { LOG_ERROR( "Too small receiving buffer" ); nExpectedLen = nLen; } //cout << nExpectedLen << " (" << nNetLen << " : " << nRecvLen << ")"; } while( nExpectedLen > 0 ) { nRecvLen = recv( m_sockMain, pszData, nExpectedLen, 0 ); if( !nRecvLen ) { if( !m_nBytesRead ) { // when it is not first read attempt we shouldn't show this error if( bEmptyError ) { LOG_ERROR( "Received 0 bytes" ); bLoopError = true; } } break; } if( SOCKET_ERROR == nRecvLen || nRecvLen < 0 ) { bLoopError = true; LOG_ERROR3_BREAK( szErrorFailedWithCodeFmt, "recv", WSAGetLastError() ); } nExpectedLen -= nRecvLen; pszData += nRecvLen; m_nBytesRead += nRecvLen; if (!nExpectedLen) { break; } sizeint siNextTimeout = m_bUseHeaderLength ? 5000 : m_nWaitNextTimeOut; if (!CanRead(siNextTimeout)) { if (m_bUseHeaderLength) { LOG_ERROR2("Wait times out %u", siNextTimeout); bLoopError = true; } break; } } bResult = !bLoopError; } while( false ); return bResult; }