AMPEG4AudioAssembler::AMPEG4AudioAssembler( const sp<AMessage> ¬ify, const AString ¶ms) : mNotifyMsg(notify), mMuxConfigPresent(false), mAccessUnitRTPTime(0), mNextExpectedSeqNoValid(false), mNextExpectedSeqNo(0), mAccessUnitDamaged(false) { AString val; if (!GetAttribute(params.c_str(), "cpresent", &val)) { mMuxConfigPresent = true; } else if (val == "0") { mMuxConfigPresent = false; } else { CHECK(val == "1"); mMuxConfigPresent = true; } CHECK(GetAttribute(params.c_str(), "config", &val)); sp<ABuffer> config = decodeHex(val); CHECK(config != NULL); ABitReader bits(config->data(), config->size()); status_t err = parseStreamMuxConfig( &bits, &mNumSubFrames, &mFrameLengthType, &mFixedFrameLength, &mOtherDataPresent, &mOtherDataLenBits); CHECK_EQ(err, (status_t)NO_ERROR); }
int main() { auto result = decodeHex("FF3F643F"); for (auto& i : result) std::cout << (int)i << std::endl; }
/** Parses method name and arguments @param input Input string to be parsed. Modified in the process. @param nargs Set to number of arguments parsed (output) @param args */ static char *parse_acpi_args(char *input, int *nargs, union acpi_object **args) { char *s = input; int i; *nargs = 0; *args = NULL; // the method name is separated from the arguments by a space while (*s && *s != ' ') s++; // if no space is found, return 0 arguments if (*s == 0) return input; *args = (union acpi_object *) kmalloc(MAX_ACPI_ARGS * sizeof(union acpi_object), GFP_KERNEL); if (!*args) { printk(KERN_ERR "acpi_call: unable to allocate buffer\n"); return NULL; } while (*s) { if (*s == ' ') { if (*nargs == 0) *s = 0; // change first space to nul ++ *nargs; ++ s; } else { union acpi_object *arg = (*args) + (*nargs - 1); if (*s == '"') { // decode string arg->type = ACPI_TYPE_STRING; arg->string.pointer = ++s; arg->string.length = 0; while (*s && *s++ != '"') arg->string.length ++; // skip the last " if (*s == '"') ++s; } else if (*s == 'b') { // decode buffer - bXXXX char *p = ++s; int len = 0, i; u8 *buf = NULL; while (*p && *p!=' ') p++; len = p - s; if (len % 2 == 1) { printk(KERN_ERR "acpi_call: buffer arg%d is not multiple of 8 bits\n", *nargs); --*nargs; goto err; } len /= 2; buf = (u8*) kmalloc(len, GFP_KERNEL); if (!buf) { printk(KERN_ERR "acpi_call: unable to allocate buffer\n"); --*nargs; goto err; } for (i=0; i<len; i++) { buf[i] = decodeHex(s + i*2); } s = p; arg->type = ACPI_TYPE_BUFFER; arg->buffer.pointer = buf; arg->buffer.length = len; } else if (*s == '{') { // decode buffer - { b1, b2 ...} u8 *buf = temporary_buffer; arg->type = ACPI_TYPE_BUFFER; arg->buffer.pointer = buf; arg->buffer.length = 0; while (*s && *s++ != '}') { if (buf >= temporary_buffer + sizeof(temporary_buffer)) { printk(KERN_ERR "acpi_call: buffer arg%d is truncated because the buffer is full\n", *nargs); // clear remaining arguments while (*s && *s != '}') ++s; break; } else if (*s >= '0' && *s <= '9') { // decode integer into buffer arg->buffer.length ++; if (s[0] == '0' && s[1] == 'x') *buf++ = simple_strtol(s+2, 0, 16); else *buf++ = simple_strtol(s, 0, 10); } // skip until space or comma or '}' while (*s && *s != ' ' && *s != ',' && *s != '}') ++s; } // store the result in new allocated buffer buf = (u8*) kmalloc(arg->buffer.length, GFP_KERNEL); if (!buf) { printk(KERN_ERR "acpi_call: unable to allocate buffer\n"); --*nargs; goto err; } memcpy(buf, temporary_buffer, arg->buffer.length); arg->buffer.pointer = buf; } else { // decode integer, N or 0xN arg->type = ACPI_TYPE_INTEGER; if (s[0] == '0' && s[1] == 'x') { arg->integer.value = simple_strtol(s+2, 0, 16); } else { arg->integer.value = simple_strtol(s, 0, 10); } while (*s && *s != ' ') { ++s; } } } } return input; err: for (i=0; i<*nargs; i++) if ((*args)[i].type == ACPI_TYPE_BUFFER && (*args)[i].buffer.pointer) kfree((*args)[i].buffer.pointer); kfree(*args); return NULL; }
std::vector<uint8_t> decodeHex(std::string const& container) { return decodeHex(container.begin(), container.end()); }