/* error, or stop the service. */ static VOID StopService(LPTSTR lpszMsg) { CHAR chMsg[256]; HANDLE hEventSource; LPTSTR lpszStrings[2]; dwGlobalErr = GetLastError(); /* Use event logging to log the error. */ hEventSource = RegisterEventSource(NULL, THIS_SERVICE); sprintf(chMsg, "%s error: %s", THIS_SERVICE, convert_error(dwGlobalErr)); lpszStrings[0] = chMsg; lpszStrings[1] = lpszMsg; if (hEventSource) { ReportEvent(hEventSource, /* handle of event source */ EVENTLOG_ERROR_TYPE, /* event type */ 0, /* event category */ 0, /* event ID */ NULL, /* current user's SID */ 2, /* strings in lpszStrings */ 0, /* no bytes of raw data */ lpszStrings, /* array of error strings */ NULL); /* no raw data */ (VOID) DeregisterEventSource(hEventSource); } if (threadHandle) TerminateThread(threadHandle, 1); } /* end of StopService */
static bool write_compressed_texture( mipmapped_texture& work_tex, convert_params& params, crn_comp_params& comp_params, pixel_format dst_format, progress_params& progress_state, bool perceptual, convert_stats& stats) { comp_params.m_file_type = (params.m_dst_file_type == texture_file_types::cFormatCRN) ? cCRNFileTypeCRN : cCRNFileTypeDDS; comp_params.m_pProgress_func = crn_progress_callback; comp_params.m_pProgress_func_data = &progress_state; comp_params.set_flag(cCRNCompFlagPerceptual, perceptual); crn_format crn_fmt = pixel_format_helpers::convert_pixel_format_to_best_crn_format(dst_format); comp_params.m_format = crn_fmt; console::message("Writing %s texture to file: \"%s\"", crn_get_format_string(crn_fmt), params.m_dst_filename.get_ptr()); uint32 actual_quality_level; float actual_bitrate; bool status = work_tex.write_to_file(params.m_dst_filename.get_ptr(), params.m_dst_file_type, &comp_params, &actual_quality_level, &actual_bitrate); if (!status) return convert_error(params, "Failed writing output file!"); if (!params.m_no_stats) { if (!stats.init(params.m_pInput_texture->get_source_filename().get_ptr(), params.m_dst_filename.get_ptr(), *params.m_pIntermediate_texture, params.m_dst_file_type, params.m_lzma_stats)) { console::warning("Unable to compute output statistics for file: %s", params.m_pInput_texture->get_source_filename().get_ptr()); } } return true; }
void announcer::commit(AvahiEntryGroup *group) { assert(group != 0); if (!avahi_entry_group_is_empty(group)) { int rc = avahi_entry_group_commit(group); if (rc != AVAHI_OK) { handler(convert_error(rc)); } } }
int ca_vorbis_open(ca_vorbis **_v, FILE *f) { int ret, or; ca_vorbis *v; int64_t n; ca_return_val_if_fail(_v, CA_ERROR_INVALID); ca_return_val_if_fail(f, CA_ERROR_INVALID); if (!(v = ca_new0(ca_vorbis, 1))) return CA_ERROR_OOM; if ((or = ov_open(f, &v->ovf, NULL, 0)) < 0) { ret = convert_error(or); goto fail; } if ((n = ov_pcm_total(&v->ovf, -1)) < 0) { ret = convert_error(or); ov_clear(&v->ovf); goto fail; } if (((off_t) n * (off_t) sizeof(int16_t)) > FILE_SIZE_MAX) { ret = CA_ERROR_TOOBIG; ov_clear(&v->ovf); goto fail; } v->size = (off_t) n * (off_t) sizeof(int16_t) * ca_vorbis_get_nchannels(v); *_v = v; return CA_SUCCESS; fail: ca_free(v); return ret; }
int ca_vorbis_read_s16ne(ca_vorbis *v, int16_t *d, size_t *n){ long r; int section; int length; size_t n_read = 0; ca_return_val_if_fail(v, CA_ERROR_INVALID); ca_return_val_if_fail(d, CA_ERROR_INVALID); ca_return_val_if_fail(n, CA_ERROR_INVALID); ca_return_val_if_fail(*n > 0, CA_ERROR_INVALID); length = (int) (*n * sizeof(int16_t)); do { r = ov_read(&v->ovf, (char*) d, length, #ifdef WORDS_BIGENDIAN 1, #else 0, #endif 2, 1, §ion); if (r < 0) return convert_error((int) r); if (r == 0) break; /* We only read the first section */ if (section != 0) break; length -= (int) r; d += r/sizeof(int16_t); n_read += (size_t) r; } while (length >= 4096); ca_assert(v->size >= (off_t) n_read); v->size -= (off_t) n_read; *n = n_read/sizeof(int16_t); return CA_SUCCESS; }
static int convert_response(struct zcrypt_device *zdev, struct ap_message *reply, char __user *outputdata, unsigned int outputdatalength) { /* Response type byte is the second byte in the response. */ switch (((unsigned char *) reply->message)[1]) { case TYPE82_RSP_CODE: case TYPE88_RSP_CODE: return convert_error(zdev, reply); case TYPE80_RSP_CODE: return convert_type80(zdev, reply, outputdata, outputdatalength); default: /* Unknown response type, this should NEVER EVER happen */ zdev->online = 0; pr_err("Cryptographic device %x failed and was set offline\n", zdev->ap_dev->qid); ZCRYPT_DBF_DEV(DBF_ERR, zdev, "dev%04xo%dfail", zdev->ap_dev->qid, zdev->online); return -EAGAIN; /* repeat the request on a different device. */ } }
int WIN32_CDECL service_error(DWORD error_code, char *themessage, ...) { va_list arglist; char buff[200]; /* print the message as if it was a PRINTF type message */ va_start(arglist, themessage); _vsnprintf(buff, sizeof(buff), themessage, arglist); va_end(arglist); fprintf(stderr, "%s\n", buff); if (error_code) fprintf(stderr, " ** Error %ld\n ** %s\n", error_code, convert_error(error_code)); close_service_handles(); return TRUE; } /* end of service_error */
void announcer::async_announce(const aware::contact& contact, async_announce_handler h) { assert(ptr != 0); handler = h; const AvahiPublishFlags flags = AvahiPublishFlags(0); const aware::contact::endpoint_type endpoint = contact.get_endpoint(); // Use all network interfaces const AvahiIfIndex interface_index = AVAHI_IF_UNSPEC; // Use only a specific protocol const AvahiProtocol protocol = contact.get_endpoint().protocol() == boost::asio::ip::tcp::v6() ? AVAHI_PROTO_INET6 : AVAHI_PROTO_INET; std::string name = contact.get_name(); // FIXME: from contact (endpoint.protocol()) std::string type = "_" + contact.get_type() + "._tcp"; // Use .local const char *domain = 0; // Host name boost::asio::ip::address address = endpoint.address(); std::string host = address.is_unspecified() ? "" // Use default host name : address.to_string(); property_list properties; if (!contact.get_properties().empty()) { properties = contact.get_properties(); if (properties == 0) { boost::system::error_code error(boost::system::errc::not_enough_memory, boost::system::system_category()); handler(error); return; } } while (true) { int rc = avahi_entry_group_add_service_strlst(ptr, interface_index, protocol, flags, name.c_str(), type.c_str(), domain, host.empty() ? 0 : host.c_str(), endpoint.port(), properties); if (rc == AVAHI_ERR_COLLISION) { char *alternative = avahi_alternative_service_name(name.c_str()); name = alternative; avahi_free(alternative); } else if (rc != AVAHI_OK) { handler(convert_error(rc)); return; } else { break; } } commit(ptr); }
bool process(convert_params& params, convert_stats& stats) { texture_type tex_type = params.m_texture_type; crn_comp_params comp_params(params.m_comp_params); crn_mipmap_params mipmap_params(params.m_mipmap_params); progress_params progress_state; progress_state.m_pParams = ¶ms; progress_state.m_canceled = false; progress_state.m_start_percentage = 0; params.m_status = false; params.m_error_message.clear(); if (params.m_pIntermediate_texture) { crnlib_delete(params.m_pIntermediate_texture); params.m_pIntermediate_texture = NULL; } params.m_pIntermediate_texture = crnlib_new<mipmapped_texture>(*params.m_pInput_texture); mipmapped_texture& work_tex = *params.m_pInput_texture; if ((params.m_unflip) && (work_tex.is_flipped())) { console::info("Unflipping texture"); work_tex.unflip(true, true); } if (params.m_y_flip) { console::info("Flipping texture on Y axis"); // This is awkward - if we're writing to KTX, then go ahead and properly update the work texture's orientation flags. // Otherwise, don't bother updating the orientation flags because the writer may then attempt to unflip the texture before writing to formats // that don't support flipped textures (ugh). const bool bOutputFormatSupportsFlippedTextures = params.m_dst_file_type == texture_file_types::cFormatKTX; if (!work_tex.flip_y(bOutputFormatSupportsFlippedTextures)) { console::warning("Failed flipping texture on Y axis"); } } if ((params.m_dst_format != PIXEL_FMT_INVALID) && (pixel_format_helpers::is_alpha_only(params.m_dst_format))) { if ((work_tex.get_comp_flags() & pixel_format_helpers::cCompFlagAValid) == 0) { console::warning("Output format is alpha-only, but input doesn't have alpha, so setting alpha to luminance."); work_tex.convert(PIXEL_FMT_A8, crnlib::dxt_image::pack_params()); if (tex_type == cTextureTypeNormalMap) tex_type = cTextureTypeRegularMap; } } pixel_format dst_format = params.m_dst_format; if (pixel_format_helpers::is_dxt(dst_format)) { if ((params.m_dst_file_type != texture_file_types::cFormatCRN) && (params.m_dst_file_type != texture_file_types::cFormatDDS) && (params.m_dst_file_type != texture_file_types::cFormatKTX)) { console::warning("Output file format does not support DXTc - automatically choosing a non-DXT pixel format."); dst_format = PIXEL_FMT_INVALID; } } if (dst_format == PIXEL_FMT_INVALID) { // Caller didn't specify a format to use, so try to pick something reasonable. // This is actually much trickier than it seems, and the current approach kind of sucks. dst_format = choose_pixel_format(params, comp_params, work_tex, tex_type); } if ((dst_format == PIXEL_FMT_DXT1) && (comp_params.get_flag(cCRNCompFlagDXT1AForTransparency))) dst_format = PIXEL_FMT_DXT1A; else if (dst_format == PIXEL_FMT_DXT1A) comp_params.set_flag(cCRNCompFlagDXT1AForTransparency, true); if ((dst_format == PIXEL_FMT_DXT1A) && (params.m_dst_file_type == texture_file_types::cFormatCRN)) { console::warning("CRN file format does not support DXT1A compressed textures - converting to DXT5 instead."); dst_format = PIXEL_FMT_DXT5; } const bool is_normal_map = (tex_type == cTextureTypeNormalMap); bool perceptual = comp_params.get_flag(cCRNCompFlagPerceptual); if (is_normal_map) { perceptual = false; mipmap_params.m_gamma_filtering = false; } if (pixel_format_helpers::is_pixel_format_non_srgb(dst_format)) { if (perceptual) { console::message("Output pixel format is swizzled or not RGB, disabling perceptual color metrics"); perceptual = false; } } if (pixel_format_helpers::is_normal_map(dst_format)) { if (perceptual) console::message("Output pixel format is intended for normal maps, disabling perceptual color metrics"); perceptual = false; } bool generate_mipmaps = texture_file_types::supports_mipmaps(params.m_dst_file_type); if ((params.m_write_mipmaps_to_multiple_files) && ((params.m_dst_file_type != texture_file_types::cFormatCRN) && (params.m_dst_file_type != texture_file_types::cFormatDDS) && (params.m_dst_file_type != texture_file_types::cFormatKTX))) { generate_mipmaps = true; } if (params.m_param_debugging) { params.print(); print_comp_params(comp_params); print_mipmap_params(mipmap_params); } if (!create_texture_mipmaps(work_tex, comp_params, mipmap_params, generate_mipmaps)) return convert_error(params, "Failed creating texture mipmaps!"); bool formats_differ = work_tex.get_format() != dst_format; if (formats_differ) { if (pixel_format_helpers::is_dxt1(work_tex.get_format()) && pixel_format_helpers::is_dxt1(dst_format)) formats_differ = false; } bool status = false; timer t; t.start(); if ((params.m_dst_file_type == texture_file_types::cFormatCRN) || ((params.m_dst_file_type == texture_file_types::cFormatDDS) && (pixel_format_helpers::is_dxt(dst_format)) && //((formats_differ) || (comp_params.m_target_bitrate > 0.0f) || (comp_params.m_quality_level < cCRNMaxQualityLevel)) ((comp_params.m_target_bitrate > 0.0f) || (comp_params.m_quality_level < cCRNMaxQualityLevel)))) { status = write_compressed_texture(work_tex, params, comp_params, dst_format, progress_state, perceptual, stats); } else { if ((comp_params.m_target_bitrate > 0.0f) || (comp_params.m_quality_level < cCRNMaxQualityLevel)) { console::warning("Target bitrate/quality level is not supported for this output file format.\n"); } status = convert_and_write_normal_texture(work_tex, params, comp_params, dst_format, progress_state, formats_differ, perceptual, stats); } console::progress(""); if (progress_state.m_canceled) { params.m_canceled = true; return false; } double total_write_time = t.get_elapsed_secs(); if (status) { if (params.m_param_debugging) console::info("Work texture format: %s, desired destination format: %s", pixel_format_helpers::get_pixel_format_string(work_tex.get_format()), pixel_format_helpers::get_pixel_format_string(dst_format)); console::message("Texture successfully written in %3.3fs", total_write_time); } else { dynamic_string str; if (work_tex.get_last_error().is_empty()) str.format("Failed writing texture to file \"%s\"", params.m_dst_filename.get_ptr()); else str.format("Failed writing texture to file \"%s\", Reason: %s", params.m_dst_filename.get_ptr(), work_tex.get_last_error().get_ptr()); return convert_error(params, str.get_ptr()); } if (params.m_debugging) { crnlib_print_mem_stats(); } params.m_status = true; return true; }
static bool convert_and_write_normal_texture(mipmapped_texture& work_tex, convert_params& params, const crn_comp_params& comp_params, pixel_format dst_format, progress_params& progress_state, bool formats_differ, bool perceptual, convert_stats& stats) { if (formats_differ) { dxt_image::pack_params pack_params; pack_params.m_perceptual = perceptual; pack_params.m_compressor = comp_params.m_dxt_compressor_type; pack_params.m_pProgress_callback = dxt_progress_callback_func; pack_params.m_pProgress_callback_user_data_ptr = &progress_state; pack_params.m_dxt1a_alpha_threshold = comp_params.m_dxt1a_alpha_threshold; pack_params.m_quality = comp_params.m_dxt_quality; pack_params.m_endpoint_caching = !comp_params.get_flag(cCRNCompFlagDisableEndpointCaching); pack_params.m_grayscale_sampling = comp_params.get_flag(cCRNCompFlagGrayscaleSampling); if ((!comp_params.get_flag(cCRNCompFlagUseBothBlockTypes)) && (!comp_params.get_flag(cCRNCompFlagDXT1AForTransparency))) pack_params.m_use_both_block_types = false; pack_params.m_num_helper_threads = comp_params.m_num_helper_threads; pack_params.m_use_transparent_indices_for_black = comp_params.get_flag(cCRNCompFlagUseTransparentIndicesForBlack); console::info("Converting texture format from %s to %s", pixel_format_helpers::get_pixel_format_string(work_tex.get_format()), pixel_format_helpers::get_pixel_format_string(dst_format)); timer tm; tm.start(); bool status = work_tex.convert(dst_format, pack_params); double t = tm.get_elapsed_secs(); console::info(""); if (!status) { if (progress_state.m_canceled) { params.m_canceled = true; return false; } else { return convert_error(params, "Failed converting texture to output format!"); } } console::info("Texture format conversion took %3.3fs", t); } if (params.m_write_mipmaps_to_multiple_files) { for (uint f = 0; f < work_tex.get_num_faces(); f++) { for (uint l = 0; l < work_tex.get_num_levels(); l++) { dynamic_string filename(params.m_dst_filename.get_ptr()); dynamic_string drv, dir, fn, ext; if (!file_utils::split_path(params.m_dst_filename.get_ptr(), &drv, &dir, &fn, &ext)) return false; fn += dynamic_string(cVarArg, "_face%u_mip%u", f, l).get_ptr(); filename = drv + dir + fn + ext; mip_level* pLevel = work_tex.get_level(f, l); face_vec face(1); face[0].push_back(crnlib_new<mip_level>(*pLevel)); mipmapped_texture new_tex; new_tex.assign(face); console::info("Writing texture face %u mip level %u to file %s", f, l, filename.get_ptr()); if (!new_tex.write_to_file(filename.get_ptr(), params.m_dst_file_type, NULL, NULL, NULL)) return convert_error(params, "Failed writing output file!"); } } } else { console::message("Writing texture to file: \"%s\"", params.m_dst_filename.get_ptr()); if (params.m_dst_stream) { if (!work_tex.write_to_stream(params.m_dst_stream, params.m_dst_file_type, NULL, NULL, NULL)) { return convert_error(params, "Failed writing output stream!"); } } else if (!work_tex.write_to_file(params.m_dst_filename.get_ptr(), params.m_dst_file_type, NULL, NULL, NULL)) { return convert_error(params, "Failed writing output file!"); } if (!params.m_no_stats) { if (!stats.init(params.m_pInput_texture->get_source_filename().get_ptr(), params.m_dst_filename.get_ptr(), *params.m_pIntermediate_texture, params.m_dst_file_type, params.m_lzma_stats)) { console::warning("Unable to compute output statistics for file: %s", params.m_pInput_texture->get_source_filename().get_ptr()); } } } return true; }
bool process(convert_params& params, convert_stats& stats) { texture_type tex_type = params.m_texture_type; crn_comp_params comp_params(params.m_comp_params); crn_mipmap_params mipmap_params(params.m_mipmap_params); progress_params progress_state; progress_state.m_pParams = ¶ms; progress_state.m_canceled = false; progress_state.m_start_percentage = 0; params.m_status = false; params.m_error_message.clear(); if (params.m_pIntermediate_texture) { crnlib_delete(params.m_pIntermediate_texture); params.m_pIntermediate_texture = NULL; } params.m_pIntermediate_texture = crnlib_new<dds_texture>(*params.m_pInput_texture); dds_texture& work_tex = *params.m_pInput_texture; if ((params.m_dst_format != PIXEL_FMT_INVALID) && (pixel_format_helpers::is_alpha_only(params.m_dst_format))) { if ((work_tex.get_comp_flags() & pixel_format_helpers::cCompFlagAValid) == 0) { console::warning(L"Output format is alpha-only, but input doesn't have alpha, so setting alpha to luminance."); work_tex.convert(PIXEL_FMT_A8, crnlib::dxt_image::pack_params()); if (tex_type == cTextureTypeNormalMap) tex_type = cTextureTypeRegularMap; } } pixel_format dst_format = params.m_dst_format; if (dst_format == PIXEL_FMT_INVALID) { // Caller didn't specify a format to use, so try to pick something reasonable. // This is actually much trickier than it seems, and the current approach kind of sucks. dst_format = choose_pixel_format(params, comp_params, work_tex, tex_type); } if ((dst_format == PIXEL_FMT_DXT1) && (comp_params.get_flag(cCRNCompFlagDXT1AForTransparency))) dst_format = PIXEL_FMT_DXT1A; else if (dst_format == PIXEL_FMT_DXT1A) comp_params.set_flag(cCRNCompFlagDXT1AForTransparency, true); const bool is_normal_map = (tex_type == cTextureTypeNormalMap); bool perceptual = comp_params.get_flag(cCRNCompFlagPerceptual); if (is_normal_map) { perceptual = false; mipmap_params.m_gamma_filtering = false; } if (pixel_format_helpers::is_pixel_format_non_srgb(dst_format)) { if (perceptual) { //console::warning(L"Output pixel format is swizzled or not RGB, disabling perceptual color metrics"); perceptual = false; } } if (pixel_format_helpers::is_normal_map(dst_format)) { //if (perceptual) //console::warning(L"Output pixel format is intended for normal maps, disabling perceptual color metrics"); perceptual = false; } bool generate_mipmaps = texture_file_types::supports_mipmaps(params.m_dst_file_type); if ((params.m_write_mipmaps_to_multiple_files) && ((params.m_dst_file_type != texture_file_types::cFormatCRN) && (params.m_dst_file_type != texture_file_types::cFormatDDS))) { generate_mipmaps = true; } if (params.m_param_debugging) { params.print(); print_comp_params(comp_params); print_mipmap_params(mipmap_params); } if (!create_texture_mipmaps(work_tex, comp_params, mipmap_params, generate_mipmaps)) return convert_error(params, L"Failed creating texture mipmaps!"); bool formats_differ = work_tex.get_format() != dst_format; if (formats_differ) { if (pixel_format_helpers::is_dxt1(work_tex.get_format()) && pixel_format_helpers::is_dxt1(dst_format)) formats_differ = false; } bool status = false; timer t; t.start(); if ( (params.m_dst_file_type == texture_file_types::cFormatCRN) || ( (params.m_dst_file_type == texture_file_types::cFormatDDS) && (pixel_format_helpers::is_dxt(dst_format)) && ((formats_differ) || (comp_params.m_target_bitrate > 0.0f) || (comp_params.m_quality_level < cCRNMaxQualityLevel)) ) ) { status = write_compressed_texture(work_tex, params, comp_params, dst_format, progress_state, perceptual, stats); } else { status = convert_and_write_normal_texture(work_tex, params, comp_params, dst_format, progress_state, formats_differ, perceptual, stats); } console::progress(L""); if (progress_state.m_canceled) { params.m_canceled = true; return false; } double total_write_time = t.get_elapsed_secs(); if (status) { if (params.m_param_debugging) console::info(L"Work texture format: %s, desired destination format: %s", pixel_format_helpers::get_pixel_format_string(work_tex.get_format()), pixel_format_helpers::get_pixel_format_string(dst_format)); console::message(L"Texture successfully written in %3.3fs", total_write_time); } else { dynamic_wstring str; if (work_tex.get_last_error().is_empty()) str.format(L"Failed writing texture to file \"%s\"", params.m_dst_filename.get_ptr()); else str.format(L"Failed writing texture to file \"%s\", Reason: %s", params.m_dst_filename.get_ptr(), work_tex.get_last_error().get_ptr()); return convert_error(params, str.get_ptr()); } if (params.m_debugging) { crnlib_print_mem_stats(); } params.m_status = true; return true; }