int i2c_read_bytes(i2c_t dev, uint8_t address, void *data, int length) { switch (dev) { #if I2C_0_EN case I2C_0: break; #endif default: return -1; } WARN_IF(I2CM_STAT & BUSY); if ( (length <= 0) || i2c_busy() ) { return 0; } WARN_IF(I2CM_STAT & BUSBSY); if (I2CM_STAT & BUSBSY) { recover_i2c_bus(); if (I2CM_STAT & BUSBSY) { return 0; } } return i2c_read_bytes_dumb(address, data, length); }
int megahal_output(const list_t *words, char **string) { size_t len = 0; uint_fast32_t i; uint32_t size; int ret; void *mem; WARN_IF(words == NULL); WARN_IF(string == NULL); WARN_IF(*string != NULL); ret = list_size(words, &size); if (ret) return ret; *string = malloc(sizeof(char) * (len + 1)); if (*string == NULL) return -ENOMEM; (*string)[0] = 0; for (i = 0; i < size; i++) { word_t word; size_t tmp_len; char *tmp; ret = list_get(words, i, &word); if (ret) return ret; ret = db_word_str(word, &tmp); if (ret) return ret; tmp_len = strlen(tmp); mem = realloc(*string, sizeof(char) * (len + tmp_len + 1)); if (mem == NULL) { free(*string); *string = NULL; free(tmp); return -ENOMEM; } *string = mem; (*string)[len + tmp_len] = 0; strcat(&(*string)[len], tmp); len += tmp_len; free(tmp); } megahal_capitalise(*string); return OK; }
int megahal_train(brain_t brain, const char *filename) { FILE *fd; char buffer[1024]; char *string; int ret = OK; WARN_IF(filename == NULL); fd = fopen(filename, "r"); if (fd == NULL) return -EIO; while (!feof(fd)) { if (fgets(buffer, 1024, fd) == NULL) break; if (buffer[0] == '#') continue; string = strtok(buffer, "\r\n"); if (string && strlen(string) > 0) { ret = megahal_process(brain, buffer, NULL, MEGAHAL_F_LEARN); if (ret) goto fail; } } fail: fclose(fd); return ret; }
void Bullet::update(float deltatime) { Vector2D newLocation = this->getLocation() + deltatime * this->speed * Vector2D(this->getRotation()); WARN_IF(!this->getOwnerWorld(), "Not assigned OwnerWorld for bullet"); Vector2D traceLocation(ZERO_VECTOR); IActor *trasedActor = RayTrace::trace(this->getOwnerWorld(), this->getLocation(), newLocation, &traceLocation); // if there nothing to hit if (trasedActor == nullptr) { this->setLocation(newLocation); } else // bullet is hiting some actor { trasedActor->hit(this, 10.f, Vector2D(this->getRotation()) * this->speed * 0.01f); this->speed = 0.0f; this->destroy(); } // bullet will be destroyed after 10 second if (this->getLifetime() > 10.f) { this->destroy(); } Actor::update(deltatime); }
static uint_fast8_t i2c_ctrl_blocking(uint_fast8_t flags) { #ifdef MODULE_XTIMER const unsigned int xtimer_timeout = 3 * (DATA_BITS + ACK_BITS) * US_PER_SEC / speed_hz; #endif mutex_trylock(&i2c_wait_mutex); assert(I2CM_IMR & 1); i2cm_ctrl_write(flags); #ifdef MODULE_XTIMER /* Set a timeout at double the expected time to transmit a byte: */ xtimer_t xtimer = { .callback = _timer_cb, .arg = NULL }; xtimer_set(&xtimer, xtimer_timeout); #endif mutex_lock(&i2c_wait_mutex); #ifdef MODULE_XTIMER xtimer_remove(&xtimer); #endif if (I2CM_STAT & BUSY) { /* If the controller is still busy, it probably will be forever */ #ifdef MODULE_XTIMER DEBUG("Master is still BUSY after %u usec. Resetting.\n", xtimer_timeout); #endif cc2538_i2c_init_master(speed_hz); } WARN_IF(I2CM_STAT & BUSY); return I2CM_STAT; }
static int exec_enroll(int argc, char **argv) { const char *dbfilename, *dn; CRYPT_KEYSET keyset; CRYPT_CERTIFICATE pki_user; char userID[CRYPT_MAX_TEXTSIZE + 1], issuePW[CRYPT_MAX_TEXTSIZE + 1], revPW[CRYPT_MAX_TEXTSIZE + 1]; int userIDlen, issuePWlen, revPWlen; int status; /* get args */ if (argc != 2) { fprintf(stderr, "usage: enroll dbfilename dn\n"); return 1; } dbfilename = argv[0]; dn = argv[1]; status = cryptKeysetOpen(&keyset, CRYPT_UNUSED, CRYPT_KEYSET_DATABASE_STORE, dbfilename, CRYPT_KEYOPT_NONE); if (!cryptStatusOK(status)) { fprintf(stderr, "(%s:%d) cryptlib error %d while closing CA privkey keyset\n", __FILE__, __LINE__, status); return 1; } status = cryptCreateCert(&pki_user, CRYPT_UNUSED, CRYPT_CERTTYPE_PKIUSER); WARN_IF(status); status = cryptSetAttributeString(pki_user, CRYPT_CERTINFO_DN, dn, strlen(dn)); WARN_IF(status); status = cryptCAAddItem(keyset, pki_user); WARN_IF(status); status = cryptKeysetClose(keyset); WARN_IF(status); status = cryptGetAttributeString(pki_user, CRYPT_CERTINFO_PKIUSER_ID, userID, &userIDlen); WARN_IF(status); userID[userIDlen] = '\0'; status = cryptGetAttributeString(pki_user, CRYPT_CERTINFO_PKIUSER_ISSUEPASSWORD, issuePW, &issuePWlen); WARN_IF(status); issuePW[issuePWlen] = '\0'; status = cryptGetAttributeString(pki_user, CRYPT_CERTINFO_PKIUSER_REVPASSWORD, revPW, &revPWlen); WARN_IF(status); revPW[revPWlen] = '\0'; fprintf(stdout, "%s\n", userID); fprintf(stdout, "%s\n", issuePW); fprintf(stdout, "%s\n", revPW); status = cryptDestroyCert(pki_user); WARN_IF(status); return 0; }
int megahal_process(brain_t brain, const char *input, char **output, uint8_t flags) { list_t *words_in; int ret; if (input != NULL) { char *tmp; tmp = strdup(input); if (tmp == NULL) return -ENOMEM; ret = megahal_parse(tmp, &words_in); free(tmp); if (ret) return ret; } else { words_in = NULL; } if ((flags & MEGAHAL_F_LEARN) != 0) { WARN_IF(words_in == NULL); ret = megahal_learn(brain, words_in); if (ret) { list_free(&words_in); return ret; } } if (output != NULL) { list_t *words_out; if (words_in == NULL) BUG(); // TODO ret = megahal_reply(brain, words_in, &words_out); list_free(&words_in); if (ret) return ret; if (words_out == NULL) { *output = strdup("I don't know enough to answer you yet!"); if (*output == NULL) return -ENOMEM; } else { ret = megahal_output(words_out, output); list_free(&words_out); if (ret) return ret; } } else { list_free(&words_in); } return OK; }
DirectionArrow::DirectionArrow(HGE *hge) : centerLocation(ZERO_VECTOR), direction(0.0f) { this->hge = hge; this->arrowTexture = this->hge->Texture_Load("arrow.png"); WARN_IF(!this->arrowTexture, "Texture 'arrow.png' not found!"); this->arrowSprite = new hgeSprite(this->arrowTexture, 0, 0, 32, 32); this->arrowSprite->SetColor(0xFF00AA00); this->arrowSprite->SetHotSpot(16, 16); bDrawable = false; }
void main(int argc, char* argv[]) { // for 宏参数预处理 // 宏参数中若包含另外的宏,那么宏参数在被代入到宏体之前会做一次完全的展开,除非宏体中含有#或##。 AFTERX(BUFSIZE)(); XAFTERX(BUFSIZE)(); // for # & ## // WARN_IF int divider = 0; WARN_IF(divider == 0); M_CONTATENOR(AA, BB, CC)(); common_print(M_CONTATENOR(AA, BB, CC)); char* templt = "apple = %d, banana = %d, orange = %d\n"; char* arg1 = "hello"; VARIADIC_MACRO_PRINT(templt, 1, 2, 3); VARIADIC_MACRO_FUNCTION(templt, 1, 2, 3); }
int i2c_write_bytes(i2c_t dev, uint8_t address, const void *data, int length) { int n = 0; const uint8_t *my_data = data; if (dev != I2C_0) { return -1; } WARN_IF(I2CM_STAT & BUSBSY); if (I2CM_STAT & BUSBSY) { recover_i2c_bus(); if (I2CM_STAT & BUSBSY) { return 0; } } I2CM_SA = address << 1; uint_fast8_t flags = START | RUN; for (n = 0; n < length; n++) { if (n >= length - 1) flags |= STOP; WARN_IF(I2CM_STAT & BUSY); I2CM_DR = my_data[n]; i2c_ctrl_blocking(flags); WARN_IF(I2CM_STAT & ARBLST); WARN_IF(I2CM_STAT & DATACK); WARN_IF(I2CM_STAT & ADRACK); WARN_IF(I2CM_STAT & ERROR); if (I2CM_STAT & ARBLST) { break; } else if (I2CM_STAT & ANY_ERROR) { i2cm_ctrl_write(STOP); break; } flags = RUN; } if (n < length) { DEBUG("%s(%u, %p, %u): %u/%u bytes delivered.\n", __FUNCTION__, address, (void *)my_data, length, n, length); } return n; }
static void count_resource_leaks( void ) { int i, j; char errbuf[200]; if( count == Count_yes ) { count = Count_reported; #if 0 /* Could break if there are still threads after atexit */ for( i = j = 0; i < Idx_max; i++ ) j |= ldap_int_thread_mutex_destroy( &resource_mutexes[i] ); WARN_IF( j, "ldap_debug_thread_destroy:mutexes" ); #endif for( i = j = 0; i < Idx_max; i++ ) if( resource_counts[i] ) j += sprintf( errbuf + j, ", %d %s", resource_counts[i], resource_names[i] ); if( j ) fprintf( stderr, "== thr_debug: Leaked%s. ==\n", errbuf + 1 ); } }
static void _main_view_camera_capturing_cb(camera_image_data_s *image_data, camera_image_data_s *postview, camera_image_data_s *thumbnail, void *user_data) { main_view *main_view_data = user_data; INF("Camera Capturing"); if (!main_view_data->camera_enabled) { ERR("Camera hasn't been initialized."); return; } if(image_data != NULL) { INF("Image Size: %u, Width: %d Height: %d", image_data->size, image_data->width, image_data->height); /* * File Operations */ FILE *file = fopen(CAMERA_DIRECTORY, "w+"); RETM_IF(!file, "fopen() failed"); size_t size = fwrite(image_data->data, image_data->size, 1, file); WARN_IF(size != 1, "fwrite() failed"); fclose(file); if(image_data->format == CAMERA_PIXEL_FORMAT_NV12) { } else if(image_data->format == CAMERA_PIXEL_FORMAT_RGBA) { } else if (image_data->format == CAMERA_PIXEL_FORMAT_JPEG) { } } // _main_view_stop_camera_preview(main_view_data->camera); }
int i2c_read_regs(i2c_t dev, uint8_t address, uint8_t reg, void *data, int length) { uint_fast8_t stat; if (dev != I2C_0) { return -1; } /* Transmit reg byte to slave */ if (i2c_busy()) { return 0; } WARN_IF(I2CM_STAT & BUSBSY); if (I2CM_STAT & BUSBSY) { recover_i2c_bus(); if (I2CM_STAT & BUSBSY) { return 0; } } I2CM_SA = address << 1; I2CM_DR = reg; stat = i2c_ctrl_blocking(START | RUN); if (stat & ARBLST) { return 0; } else if (stat & ANY_ERROR) { i2cm_ctrl_write(STOP); return 0; } else { /* Receive data from slave */ return i2c_read_bytes_dumb(address, data, length); } }
static int exec_info(int argc, char **argv) { const char *dbfilename; CRYPT_KEYSET keyset; CRYPT_CERTIFICATE pki_user; char userID[CRYPT_MAX_TEXTSIZE + 1], issuePW[CRYPT_MAX_TEXTSIZE + 1], revPW[CRYPT_MAX_TEXTSIZE + 1]; int userIDlen, issuePWlen, revPWlen; int status; CRYPT_KEYID_TYPE id_type; const char *id; if (argc < 3) return 1; dbfilename = argv[0]; status = cryptKeysetOpen(&keyset, CRYPT_UNUSED, CRYPT_KEYSET_DATABASE_STORE, dbfilename, CRYPT_KEYOPT_NONE); if (!cryptStatusOK(status)) { fprintf(stderr, "(%s:%d) cryptlib error %d while closing CA privkey keyset\n", __FILE__, __LINE__, status); return 1; } id = argv[2]; if (strcmp(argv[1], "-e") == 0) { id_type = CRYPT_KEYID_EMAIL; } else if (strcmp(argv[1], "-n") == 0) { id_type = CRYPT_KEYID_NAME; } status = cryptCAGetItem(keyset, &pki_user, CRYPT_CERTTYPE_PKIUSER, id_type, id); WARN_IF(status); status = cryptKeysetClose(keyset); WARN_IF(status); status = cryptGetAttributeString(pki_user, CRYPT_CERTINFO_PKIUSER_ID, userID, &userIDlen); WARN_IF(status); userID[userIDlen] = '\0'; status = cryptGetAttributeString(pki_user, CRYPT_CERTINFO_PKIUSER_ISSUEPASSWORD, issuePW, &issuePWlen); WARN_IF(status); issuePW[issuePWlen] = '\0'; status = cryptGetAttributeString(pki_user, CRYPT_CERTINFO_PKIUSER_REVPASSWORD, revPW, &revPWlen); WARN_IF(status); revPW[revPWlen] = '\0'; fprintf(stdout, "%s\n", userID); fprintf(stdout, "%s\n", issuePW); fprintf(stdout, "%s\n", revPW); status = cryptDestroyCert(pki_user); WARN_IF(status); return 0; }
// https://wiki.libsdl.org/SDL_RWops?highlight=%28%5CbCategoryStruct%5Cb%29%7C%28CategoryIO%29 // https://wiki.libsdl.org/SDL_RWwrite?highlight=%28%5CbCategoryIO%5Cb%29%7C%28CategoryEnum%29%7C%28CategoryStruct%29 void hex_grid_t::save_to_file(std::string const& filepath) { WARN_IF(!chunks.empty(), "Saving an empty map"); SDL_RWops* io = SDL_RWFromFile(filepath.c_str(), "wb"); if(!io) { EXPLODE("hex_grid_t::save_to_file() error"); //todo: handle errors better } hxm_header_t header; header.version = 0; header.chunk_size = chunk_size(); header.map_size = size; size_t num_written = SDL_RWwrite(io, (void*)&header, sizeof(hxm_header_t), 1); if(num_written != 1) { EXPLODE("error writing hxm header"); } for_each_chunk([&](hex_grid_chunk_t const& chunk) { SDL_RWwrite(io, (void*)&chunk.size, sizeof(glm::uvec2), 1); for(auto column : chunk.cells) { size_t num_w = SDL_RWwrite(io, column.data(), sizeof(hex_grid_cell_t), column.size()); ASSERT(num_w == column.size(), "chunk save error"); LOG("wrote %d cells", num_w); } }); SDL_RWclose(io); }
~ThreadLocalPtr() { WARN_IF (pthread_key_delete (key_), sync, "failure to drop thread-local data key"); }
static void i2cm_ctrl_write(uint_fast8_t value) { WARN_IF(I2CM_STAT & BUSY); I2CM_CTRL = value; }
int i2c_write_regs(i2c_t dev, uint8_t address, uint8_t reg, const void *data, int length) { uint_fast8_t stat; const uint8_t *my_data = data; if (dev != I2C_0) { return -1; } /* Transmit reg byte to slave */ if (i2c_busy()) { return 0; } WARN_IF(I2CM_STAT & BUSBSY); if (I2CM_STAT & BUSBSY) { recover_i2c_bus(); if (I2CM_STAT & BUSBSY) { return 0; } } I2CM_SA = address << 1; I2CM_DR = reg; uint_fast8_t flags = (length > 0)? (START | RUN) : (STOP | START | RUN); stat = i2c_ctrl_blocking(flags); if (stat & ARBLST) { return 0; } else if (stat & ANY_ERROR) { i2cm_ctrl_write(STOP); return 0; } else { /* Transmit data to slave */ int n = 0; flags &= ~START; for (n = 0; n < length; n++) { if (n >= length - 1) flags |= STOP; WARN_IF(I2CM_STAT & BUSY); I2CM_DR = my_data[n]; i2c_ctrl_blocking(flags); WARN_IF(I2CM_STAT & ARBLST); WARN_IF(I2CM_STAT & DATACK); WARN_IF(I2CM_STAT & ADRACK); WARN_IF(I2CM_STAT & ERROR); if (I2CM_STAT & ARBLST) { break; } else if (I2CM_STAT & ANY_ERROR) { i2cm_ctrl_write(STOP); break; } } if (n < length) { DEBUG( "%s(%u, %u, %u, %p, %u): %u/%u bytes delivered.\n", __FUNCTION__, dev, address, reg, data, length, n, length ); } return n; } }
int megahal_keywords(brain_t brain, const list_t *words, dict_t **keywords) { dict_t *keywords_p; uint_fast32_t i; uint32_t size; int ret; WARN_IF(words == NULL); WARN_IF(keywords == NULL); *keywords = dict_alloc(); if (*keywords == NULL) return -ENOMEM; keywords_p = *keywords; ret = list_size(words, &size); if (ret) return ret; for (i = 0; i < size; i++) { word_t word; ret = list_get(words, i, &word); if (ret) return ret; ret = db_map_get(brain, MAP_SWAP, word, &word); if (ret != OK && ret != -ENOTFOUND) return ret; ret = db_list_contains(brain, LIST_BAN, word); if (ret == OK) continue; if (ret != -ENOTFOUND) return ret; ret = db_list_contains(brain, LIST_AUX, word); if (ret == OK) continue; if (ret != -ENOTFOUND) return ret; ret = db_model_contains(brain, word); if (ret == -ENOTFOUND) continue; if (ret != OK) return ret; ret = add_keyword(keywords_p, word); if (ret) return ret; } ret = dict_size(keywords_p, &size); if (ret) return ret; if (size == 0) return OK; ret = list_size(words, &size); if (ret) return ret; for (i = 0; i < size; i++) { word_t word; ret = list_get(words, i, &word); if (ret) return ret; ret = db_map_get(brain, MAP_SWAP, word, &word); if (ret != OK && ret != -ENOTFOUND) return ret; ret = db_list_contains(brain, LIST_AUX, word); if (ret == -ENOTFOUND) continue; if (ret != OK) return ret; ret = db_model_contains(brain, word); if (ret == -ENOTFOUND) continue; if (ret != OK) return ret; ret = add_keyword(keywords_p, word); if (ret) return ret; } return OK; }
int megahal_parse(const char *string, list_t **words) { list_t *words_p; uint_fast32_t offset, len; uint32_t size; word_t word; char *tmp; int ret; WARN_IF(string == NULL); WARN_IF(words == NULL); *words = list_alloc(); if (*words == NULL) return -ENOMEM; words_p = *words; len = strlen(string); if (len == 0) return OK; offset = 0; while (1) { /* * If the current character is of the same type as the previous * character, then include it in the word. Otherwise, terminate * the current word. */ if (boundary(string, offset, len)) { /* * Add the word to the dictionary */ tmp = strndup(string, offset); if (tmp == NULL) return -ENOMEM; /* * Truncate overly long words because they won't fit in the * dictionary when saving. */ if (offset > UINT8_MAX) tmp[UINT8_MAX + 1] = 0; megahal_upper(tmp); ret = db_word_use(tmp, &word); free(tmp); if (ret) return ret; ret = list_append(words_p, word); if (ret) return ret; if (offset == len) break; string += offset; len = strlen(string); offset = 0; } else { offset++; } } /* * If the last word isn't punctuation, then replace it with a * full-stop character. */ tmp = NULL; ret = list_size(words_p, &size); if (ret) return ret; ret = list_get(words_p, size - 1, &word); if (ret) return ret; ret = db_word_str(word, &tmp); if (ret) return ret; if (isalnum((unsigned char)tmp[0])) { free(tmp); ret = db_word_use(".", &word); if (ret) return ret; ret = list_append(words_p, word); if (ret) return ret; } else if (strchr("!.?", (unsigned char)tmp[strlen(tmp) - 1]) == NULL) { free(tmp); ret = db_word_use(".", &word); if (ret) return ret; ret = list_set(words_p, size - 1, word); if (ret) return ret; } else { free(tmp); } return OK; }
static av_cold int aac_encode_init(AVCodecContext *avctx) { AACEncContext *s = avctx->priv_data; int i, ret = 0; const uint8_t *sizes[2]; uint8_t grouping[AAC_MAX_CHANNELS]; int lengths[2]; avctx->frame_size = 1024; for (i = 0; i < 16; i++) if (avctx->sample_rate == avpriv_mpeg4audio_sample_rates[i]) break; s->channels = avctx->channels; ERROR_IF(i == 16 || i >= (sizeof(swb_size_1024) / sizeof(*swb_size_1024)) || i >= (sizeof(swb_size_128) / sizeof(*swb_size_128)), "Unsupported sample rate %d\n", avctx->sample_rate); ERROR_IF(s->channels > AAC_MAX_CHANNELS, "Unsupported number of channels: %d\n", s->channels); ERROR_IF(avctx->profile != FF_PROFILE_UNKNOWN && avctx->profile != FF_PROFILE_AAC_LOW, "Unsupported profile %d\n", avctx->profile); WARN_IF(1024.0 * avctx->bit_rate / avctx->sample_rate > 6144 * s->channels, "Too many bits per frame requested, clamping to max\n"); avctx->bit_rate = (int)FFMIN( 6144 * s->channels / 1024.0 * avctx->sample_rate, avctx->bit_rate); s->samplerate_index = i; s->chan_map = aac_chan_configs[s->channels-1]; if ((ret = dsp_init(avctx, s)) < 0) goto fail; if ((ret = alloc_buffers(avctx, s)) < 0) goto fail; avctx->extradata_size = 5; put_audio_specific_config(avctx); sizes[0] = swb_size_1024[i]; sizes[1] = swb_size_128[i]; lengths[0] = ff_aac_num_swb_1024[i]; lengths[1] = ff_aac_num_swb_128[i]; for (i = 0; i < s->chan_map[0]; i++) grouping[i] = s->chan_map[i + 1] == TYPE_CPE; if ((ret = ff_psy_init(&s->psy, avctx, 2, sizes, lengths, s->chan_map[0], grouping)) < 0) goto fail; s->psypp = ff_psy_preprocess_init(avctx); s->coder = &ff_aac_coders[s->options.aac_coder]; if (HAVE_MIPSDSPR1) ff_aac_coder_init_mips(s); s->lambda = avctx->global_quality > 0 ? avctx->global_quality : 120; ff_aac_tableinit(); avctx->initial_padding = 1024; ff_af_queue_init(avctx, &s->afq); return 0; fail: aac_encode_end(avctx); return ret; }
static av_cold int aac_encode_init(AVCodecContext *avctx) { AACEncContext *s = avctx->priv_data; int i, ret = 0; const uint8_t *sizes[2]; uint8_t grouping[AAC_MAX_CHANNELS]; int lengths[2]; /* Constants */ s->last_frame_pb_count = 0; avctx->extradata_size = 5; avctx->frame_size = 1024; avctx->initial_padding = 1024; s->lambda = avctx->global_quality > 0 ? avctx->global_quality : 120; /* Channel map and unspecified bitrate guessing */ s->channels = avctx->channels; ERROR_IF(s->channels > AAC_MAX_CHANNELS || s->channels == 7, "Unsupported number of channels: %d\n", s->channels); s->chan_map = aac_chan_configs[s->channels-1]; if (!avctx->bit_rate) { for (i = 1; i <= s->chan_map[0]; i++) { avctx->bit_rate += s->chan_map[i] == TYPE_CPE ? 128000 : /* Pair */ s->chan_map[i] == TYPE_LFE ? 16000 : /* LFE */ 69000 ; /* SCE */ } } /* Samplerate */ for (i = 0; i < 16; i++) if (avctx->sample_rate == avpriv_mpeg4audio_sample_rates[i]) break; s->samplerate_index = i; ERROR_IF(s->samplerate_index == 16 || s->samplerate_index >= ff_aac_swb_size_1024_len || s->samplerate_index >= ff_aac_swb_size_128_len, "Unsupported sample rate %d\n", avctx->sample_rate); /* Bitrate limiting */ WARN_IF(1024.0 * avctx->bit_rate / avctx->sample_rate > 6144 * s->channels, "Too many bits %f > %d per frame requested, clamping to max\n", 1024.0 * avctx->bit_rate / avctx->sample_rate, 6144 * s->channels); avctx->bit_rate = (int64_t)FFMIN(6144 * s->channels / 1024.0 * avctx->sample_rate, avctx->bit_rate); /* Profile and option setting */ avctx->profile = avctx->profile == FF_PROFILE_UNKNOWN ? FF_PROFILE_AAC_LOW : avctx->profile; for (i = 0; i < FF_ARRAY_ELEMS(aacenc_profiles); i++) if (avctx->profile == aacenc_profiles[i]) break; if (avctx->profile == FF_PROFILE_MPEG2_AAC_LOW) { avctx->profile = FF_PROFILE_AAC_LOW; ERROR_IF(s->options.pred, "Main prediction unavailable in the \"mpeg2_aac_low\" profile\n"); ERROR_IF(s->options.ltp, "LTP prediction unavailable in the \"mpeg2_aac_low\" profile\n"); WARN_IF(s->options.pns, "PNS unavailable in the \"mpeg2_aac_low\" profile, turning off\n"); s->options.pns = 0; } else if (avctx->profile == FF_PROFILE_AAC_LTP) { s->options.ltp = 1; ERROR_IF(s->options.pred, "Main prediction unavailable in the \"aac_ltp\" profile\n"); } else if (avctx->profile == FF_PROFILE_AAC_MAIN) { s->options.pred = 1; ERROR_IF(s->options.ltp, "LTP prediction unavailable in the \"aac_main\" profile\n"); } else if (s->options.ltp) { avctx->profile = FF_PROFILE_AAC_LTP; WARN_IF(1, "Chainging profile to \"aac_ltp\"\n"); ERROR_IF(s->options.pred, "Main prediction unavailable in the \"aac_ltp\" profile\n"); } else if (s->options.pred) { avctx->profile = FF_PROFILE_AAC_MAIN; WARN_IF(1, "Chainging profile to \"aac_main\"\n"); ERROR_IF(s->options.ltp, "LTP prediction unavailable in the \"aac_main\" profile\n"); } s->profile = avctx->profile; /* Coder limitations */ s->coder = &ff_aac_coders[s->options.coder]; if (s->options.coder == AAC_CODER_ANMR) { ERROR_IF(avctx->strict_std_compliance > FF_COMPLIANCE_EXPERIMENTAL, "The ANMR coder is considered experimental, add -strict -2 to enable!\n"); s->options.intensity_stereo = 0; s->options.pns = 0; } ERROR_IF(s->options.ltp && avctx->strict_std_compliance > FF_COMPLIANCE_EXPERIMENTAL, "The LPT profile requires experimental compliance, add -strict -2 to enable!\n"); /* M/S introduces horrible artifacts with multichannel files, this is temporary */ if (s->channels > 3) s->options.mid_side = 0; if ((ret = dsp_init(avctx, s)) < 0) goto fail; if ((ret = alloc_buffers(avctx, s)) < 0) goto fail; put_audio_specific_config(avctx); sizes[0] = ff_aac_swb_size_1024[s->samplerate_index]; sizes[1] = ff_aac_swb_size_128[s->samplerate_index]; lengths[0] = ff_aac_num_swb_1024[s->samplerate_index]; lengths[1] = ff_aac_num_swb_128[s->samplerate_index]; for (i = 0; i < s->chan_map[0]; i++) grouping[i] = s->chan_map[i + 1] == TYPE_CPE; if ((ret = ff_psy_init(&s->psy, avctx, 2, sizes, lengths, s->chan_map[0], grouping)) < 0) goto fail; s->psypp = ff_psy_preprocess_init(avctx); ff_lpc_init(&s->lpc, 2*avctx->frame_size, TNS_MAX_ORDER, FF_LPC_TYPE_LEVINSON); s->random_state = 0x1f2e3d4c; s->abs_pow34 = abs_pow34_v; s->quant_bands = quantize_bands; if (ARCH_X86) ff_aac_dsp_init_x86(s); if (HAVE_MIPSDSP) ff_aac_coder_init_mips(s); if ((ret = ff_thread_once(&aac_table_init, &aac_encode_init_tables)) != 0) return AVERROR_UNKNOWN; ff_af_queue_init(avctx, &s->afq); return 0; fail: aac_encode_end(avctx); return ret; }
static av_cold int aac_encode_init(AVCodecContext *avctx) { AACEncContext *s = avctx->priv_data; int i, ret = 0; const uint8_t *sizes[2]; uint8_t grouping[AAC_MAX_CHANNELS]; int lengths[2]; s->channels = avctx->channels; s->chan_map = aac_chan_configs[s->channels-1]; s->lambda = avctx->global_quality > 0 ? avctx->global_quality : 120; s->last_frame_pb_count = 0; avctx->extradata_size = 5; avctx->frame_size = 1024; avctx->initial_padding = 1024; avctx->bit_rate = (int)FFMIN( 6144 * s->channels / 1024.0 * avctx->sample_rate, avctx->bit_rate); avctx->profile = avctx->profile == FF_PROFILE_UNKNOWN ? FF_PROFILE_AAC_LOW : avctx->profile; for (i = 0; i < 16; i++) if (avctx->sample_rate == avpriv_mpeg4audio_sample_rates[i]) break; s->samplerate_index = i; ERROR_IF(s->samplerate_index == 16 || s->samplerate_index >= ff_aac_swb_size_1024_len || s->samplerate_index >= ff_aac_swb_size_128_len, "Unsupported sample rate %d\n", avctx->sample_rate); ERROR_IF(s->channels > AAC_MAX_CHANNELS || s->channels == 7, "Unsupported number of channels: %d\n", s->channels); WARN_IF(1024.0 * avctx->bit_rate / avctx->sample_rate > 6144 * s->channels, "Too many bits %f > %d per frame requested, clamping to max\n", 1024.0 * avctx->bit_rate / avctx->sample_rate, 6144 * s->channels); for (i = 0; i < FF_ARRAY_ELEMS(aacenc_profiles); i++) if (avctx->profile == aacenc_profiles[i]) break; ERROR_IF(i == FF_ARRAY_ELEMS(aacenc_profiles), "Unsupported encoding profile: %d\n", avctx->profile); if (avctx->profile == FF_PROFILE_MPEG2_AAC_LOW) { avctx->profile = FF_PROFILE_AAC_LOW; ERROR_IF(s->options.pred, "Main prediction unavailable in the \"mpeg2_aac_low\" profile\n"); ERROR_IF(s->options.ltp, "LTP prediction unavailable in the \"mpeg2_aac_low\" profile\n"); WARN_IF(s->options.pns, "PNS unavailable in the \"mpeg2_aac_low\" profile, turning off\n"); s->options.pns = 0; } else if (avctx->profile == FF_PROFILE_AAC_LTP) { s->options.ltp = 1; ERROR_IF(s->options.pred, "Main prediction unavailable in the \"aac_ltp\" profile\n"); } else if (avctx->profile == FF_PROFILE_AAC_MAIN) { s->options.pred = 1; ERROR_IF(s->options.ltp, "LTP prediction unavailable in the \"aac_main\" profile\n"); } else if (s->options.ltp) { avctx->profile = FF_PROFILE_AAC_LTP; WARN_IF(1, "Chainging profile to \"aac_ltp\"\n"); ERROR_IF(s->options.pred, "Main prediction unavailable in the \"aac_ltp\" profile\n"); } else if (s->options.pred) { avctx->profile = FF_PROFILE_AAC_MAIN; WARN_IF(1, "Chainging profile to \"aac_main\"\n"); ERROR_IF(s->options.ltp, "LTP prediction unavailable in the \"aac_main\" profile\n"); } s->profile = avctx->profile; s->coder = &ff_aac_coders[s->options.coder]; if (s->options.coder != AAC_CODER_TWOLOOP) { ERROR_IF(avctx->strict_std_compliance > FF_COMPLIANCE_EXPERIMENTAL, "Coders other than twoloop require -strict -2 and some may be removed in the future\n"); WARN_IF(s->options.coder == AAC_CODER_FAAC, "The FAAC-like coder will be removed in the near future, please use twoloop!\n"); s->options.intensity_stereo = 0; s->options.pns = 0; } if ((ret = dsp_init(avctx, s)) < 0) goto fail; if ((ret = alloc_buffers(avctx, s)) < 0) goto fail; put_audio_specific_config(avctx); sizes[0] = ff_aac_swb_size_1024[s->samplerate_index]; sizes[1] = ff_aac_swb_size_128[s->samplerate_index]; lengths[0] = ff_aac_num_swb_1024[s->samplerate_index]; lengths[1] = ff_aac_num_swb_128[s->samplerate_index]; for (i = 0; i < s->chan_map[0]; i++) grouping[i] = s->chan_map[i + 1] == TYPE_CPE; if ((ret = ff_psy_init(&s->psy, avctx, 2, sizes, lengths, s->chan_map[0], grouping)) < 0) goto fail; s->psypp = ff_psy_preprocess_init(avctx); ff_lpc_init(&s->lpc, 2*avctx->frame_size, TNS_MAX_ORDER, FF_LPC_TYPE_LEVINSON); av_lfg_init(&s->lfg, 0x72adca55); if (HAVE_MIPSDSP) ff_aac_coder_init_mips(s); if ((ret = ff_thread_once(&aac_table_init, &aac_encode_init_tables)) != 0) return AVERROR_UNKNOWN; ff_af_queue_init(avctx, &s->afq); return 0; fail: aac_encode_end(avctx); return ret; }
int main(int argc, const char *argv[]) { WARN_IF(argc == 1); myprintf("f**k\n"); return 0; }