/* * Copyright (c) 2017, Alliance for Open Media. All rights reserved. * * This source code is subject to the terms of the BSD 2 Clause License and * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License * was not distributed with this source code in the LICENSE file, you can * obtain it at www.aomedia.org/license/software. If the Alliance for Open * Media Patent License 1.0 was not distributed with this source code in the * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
*/
// Reads unsigned LEB128 integer and returns 0 upon successful read and decode. // Stores raw bytes in 'value_buffer', length of the number in 'value_length', // and decoded value in 'value'. If 'buffered' is true, it is buffered in the // detect buffer first. staticint obudec_read_leb128(struct AvxInputContext *input_ctx,
uint8_t *value_buffer, size_t *value_length,
uint64_t *value, bool buffered) { if (!input_ctx || !value_buffer || !value_length || !value) return -1;
size_t len; for (len = 0; len < OBU_MAX_LENGTH_FIELD_SIZE; ++len) { const size_t num_read =
buffer_input(input_ctx, 1, &value_buffer[len], buffered); if (num_read == 0) { if (len == 0 && input_eof(input_ctx)) {
*value_length = 0; return 0;
} // Ran out of data before completing read of value. return -1;
} if ((value_buffer[len] >> 7) == 0) {
++len;
*value_length = len; break;
}
}
// Reads OBU header from 'input_ctx'. The 'buffer_capacity' passed in must be // large enough to store an OBU header with extension (2 bytes). Raw OBU data is // written to 'obu_data', parsed OBU header values are written to 'obu_header', // and total bytes read from file are written to 'bytes_read'. Returns 0 for // success, and non-zero on failure. When end of file is reached, the return // value is 0 and the 'bytes_read' value is set to 0. If 'buffered' is true, it // is buffered in the detect buffer first. staticint obudec_read_obu_header(struct AvxInputContext *input_ctx,
size_t buffer_capacity, int is_annexb,
uint8_t *obu_data, ObuHeader *obu_header,
size_t *bytes_read, bool buffered) { if (!input_ctx || buffer_capacity < (OBU_HEADER_SIZE + OBU_EXTENSION_SIZE) ||
!obu_data || !obu_header || !bytes_read) { return -1;
}
*bytes_read = buffer_input(input_ctx, 1, obu_data, buffered);
// Reads OBU payload from 'input_ctx' and returns 0 for success when all payload // bytes are read from the file. Payload data is written to 'obu_data', and // actual bytes read added to 'bytes_read'. If 'buffered' is true, it is // buffered in the detect buffer first. staticint obudec_read_obu_payload(struct AvxInputContext *input_ctx,
size_t payload_length, uint8_t *obu_data,
size_t *bytes_read, bool buffered) { if (!input_ctx || payload_length == 0 || !obu_data || !bytes_read) return -1;
if (buffer_input(input_ctx, payload_length, obu_data, buffered) !=
payload_length) {
fprintf(stderr, "obudec: Failure reading OBU payload.\n"); return -1;
}
if (is_annexb) { // read the size of first temporal unit if (obudec_read_leb128(avx_ctx, &detect_buf[0], &length_of_unit_size,
&unit_size, /*buffered=*/true) != 0) {
fprintf(stderr, "obudec: Failure reading temporal unit header\n");
rewind_detect(avx_ctx); return 0;
}
// read the size of first frame unit if (obudec_read_leb128(avx_ctx, &detect_buf[length_of_unit_size],
&annexb_header_length, &unit_size, /*buffered=*/true) != 0) {
fprintf(stderr, "obudec: Failure reading frame unit header\n");
rewind_detect(avx_ctx); return 0;
}
annexb_header_length += length_of_unit_size;
}
// Appears that input is valid Section 5 AV1 stream.
obu_ctx->buffer = (uint8_t *)malloc(OBU_BUFFER_SIZE); if (!obu_ctx->buffer) {
fprintf(stderr, "Out of memory.\n");
rewind_detect(avx_ctx); return 0;
}
obu_ctx->buffer_capacity = OBU_BUFFER_SIZE;
memcpy(obu_ctx->buffer, &detect_buf[0], bytes_read);
obu_ctx->bytes_buffered = bytes_read; // If the first OBU is a SEQUENCE_HEADER, then it will have a payload. // We need to read this in so that our buffer only contains complete OBUs. if (payload_length > 0) { if (payload_length > (obu_ctx->buffer_capacity - bytes_read)) {
fprintf(stderr, "obudec: First OBU's payload is too large\n");
rewind_detect(avx_ctx);
obudec_free(obu_ctx); return 0;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.