mirror of
https://github.com/nyanmisaka/ffmpeg-rockchip.git
synced 2026-04-24 00:30:57 +08:00
cbs_h2645: Merge SEI message handling in common between codecs
This commit is contained in:
@@ -16,9 +16,27 @@
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
static int FUNC(sei_user_data_registered)
|
||||
static int FUNC(filler_payload)
|
||||
(CodedBitstreamContext *ctx, RWContext *rw,
|
||||
SEIRawUserDataRegistered *current, uint32_t *payload_size)
|
||||
SEIRawFillerPayload *current, SEIMessageState *state)
|
||||
{
|
||||
int err, i;
|
||||
|
||||
HEADER("Filler Payload");
|
||||
|
||||
#ifdef READ
|
||||
current->payload_size = state->payload_size;
|
||||
#endif
|
||||
|
||||
for (i = 0; i < current->payload_size; i++)
|
||||
fixed(8, ff_byte, 0xff);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int FUNC(user_data_registered)
|
||||
(CodedBitstreamContext *ctx, RWContext *rw,
|
||||
SEIRawUserDataRegistered *current, SEIMessageState *state)
|
||||
{
|
||||
int err, i, j;
|
||||
|
||||
@@ -33,14 +51,12 @@ static int FUNC(sei_user_data_registered)
|
||||
}
|
||||
|
||||
#ifdef READ
|
||||
if (*payload_size < i) {
|
||||
if (state->payload_size < i) {
|
||||
av_log(ctx->log_ctx, AV_LOG_ERROR,
|
||||
"Invalid SEI user data registered payload.\n");
|
||||
return AVERROR_INVALIDDATA;
|
||||
}
|
||||
current->data_length = *payload_size - i;
|
||||
#else
|
||||
*payload_size = i + current->data_length;
|
||||
current->data_length = state->payload_size - i;
|
||||
#endif
|
||||
|
||||
allocate(current->data, current->data_length);
|
||||
@@ -50,23 +66,21 @@ static int FUNC(sei_user_data_registered)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int FUNC(sei_user_data_unregistered)
|
||||
static int FUNC(user_data_unregistered)
|
||||
(CodedBitstreamContext *ctx, RWContext *rw,
|
||||
SEIRawUserDataUnregistered *current, uint32_t *payload_size)
|
||||
SEIRawUserDataUnregistered *current, SEIMessageState *state)
|
||||
{
|
||||
int err, i;
|
||||
|
||||
HEADER("User Data Unregistered");
|
||||
|
||||
#ifdef READ
|
||||
if (*payload_size < 16) {
|
||||
if (state->payload_size < 16) {
|
||||
av_log(ctx->log_ctx, AV_LOG_ERROR,
|
||||
"Invalid SEI user data unregistered payload.\n");
|
||||
return AVERROR_INVALIDDATA;
|
||||
}
|
||||
current->data_length = *payload_size - 16;
|
||||
#else
|
||||
*payload_size = 16 + current->data_length;
|
||||
current->data_length = state->payload_size - 16;
|
||||
#endif
|
||||
|
||||
for (i = 0; i < 16; i++)
|
||||
@@ -80,9 +94,9 @@ static int FUNC(sei_user_data_unregistered)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int FUNC(sei_mastering_display_colour_volume)
|
||||
static int FUNC(mastering_display_colour_volume)
|
||||
(CodedBitstreamContext *ctx, RWContext *rw,
|
||||
SEIRawMasteringDisplayColourVolume *current)
|
||||
SEIRawMasteringDisplayColourVolume *current, SEIMessageState *state)
|
||||
{
|
||||
int err, c;
|
||||
|
||||
@@ -104,13 +118,13 @@ static int FUNC(sei_mastering_display_colour_volume)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int FUNC(sei_content_light_level)
|
||||
static int FUNC(content_light_level_info)
|
||||
(CodedBitstreamContext *ctx, RWContext *rw,
|
||||
SEIRawContentLightLevelInfo *current)
|
||||
SEIRawContentLightLevelInfo *current, SEIMessageState *state)
|
||||
{
|
||||
int err;
|
||||
|
||||
HEADER("Content Light Level");
|
||||
HEADER("Content Light Level Information");
|
||||
|
||||
ub(16, max_content_light_level);
|
||||
ub(16, max_pic_average_light_level);
|
||||
@@ -118,9 +132,10 @@ static int FUNC(sei_content_light_level)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int FUNC(sei_alternative_transfer_characteristics)
|
||||
static int FUNC(alternative_transfer_characteristics)
|
||||
(CodedBitstreamContext *ctx, RWContext *rw,
|
||||
SEIRawAlternativeTransferCharacteristics *current)
|
||||
SEIRawAlternativeTransferCharacteristics *current,
|
||||
SEIMessageState *state)
|
||||
{
|
||||
int err;
|
||||
|
||||
@@ -130,3 +145,165 @@ static int FUNC(sei_alternative_transfer_characteristics)
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int FUNC(message)(CodedBitstreamContext *ctx, RWContext *rw,
|
||||
SEIRawMessage *current)
|
||||
{
|
||||
const SEIMessageTypeDescriptor *desc;
|
||||
int err, i;
|
||||
|
||||
desc = ff_cbs_sei_find_type(ctx, current->payload_type);
|
||||
if (desc) {
|
||||
SEIMessageState state = {
|
||||
.payload_type = current->payload_type,
|
||||
.payload_size = current->payload_size,
|
||||
.extension_present = current->extension_bit_length > 0,
|
||||
};
|
||||
int start_position, current_position, bits_written;
|
||||
|
||||
#ifdef READ
|
||||
CHECK(ff_cbs_sei_alloc_message_payload(current, desc));
|
||||
#endif
|
||||
|
||||
start_position = bit_position(rw);
|
||||
|
||||
CHECK(desc->READWRITE(ctx, rw, current->payload, &state));
|
||||
|
||||
current_position = bit_position(rw);
|
||||
bits_written = current_position - start_position;
|
||||
|
||||
if (byte_alignment(rw) || state.extension_present ||
|
||||
bits_written < 8 * current->payload_size) {
|
||||
size_t bits_left;
|
||||
|
||||
#ifdef READ
|
||||
GetBitContext tmp = *rw;
|
||||
int trailing_bits, trailing_zero_bits;
|
||||
|
||||
bits_left = 8 * current->payload_size - bits_written;
|
||||
if (bits_left > 8)
|
||||
skip_bits_long(&tmp, bits_left - 8);
|
||||
trailing_bits = get_bits(&tmp, FFMIN(bits_left, 8));
|
||||
if (trailing_bits == 0) {
|
||||
// The trailing bits must contain a bit_equal_to_one, so
|
||||
// they can't all be zero.
|
||||
return AVERROR_INVALIDDATA;
|
||||
}
|
||||
trailing_zero_bits = ff_ctz(trailing_bits);
|
||||
current->extension_bit_length =
|
||||
bits_left - 1 - trailing_zero_bits;
|
||||
#endif
|
||||
|
||||
if (current->extension_bit_length > 0) {
|
||||
allocate(current->extension_data,
|
||||
(current->extension_bit_length + 7) / 8);
|
||||
|
||||
bits_left = current->extension_bit_length;
|
||||
for (i = 0; bits_left > 0; i++) {
|
||||
int length = FFMIN(bits_left, 8);
|
||||
xu(length, reserved_payload_extension_data,
|
||||
current->extension_data[i],
|
||||
0, MAX_UINT_BITS(length), 0);
|
||||
bits_left -= length;
|
||||
}
|
||||
}
|
||||
|
||||
fixed(1, bit_equal_to_one, 1);
|
||||
while (byte_alignment(rw))
|
||||
fixed(1, bit_equal_to_zero, 0);
|
||||
}
|
||||
|
||||
#ifdef WRITE
|
||||
current->payload_size = (put_bits_count(rw) - start_position) / 8;
|
||||
#endif
|
||||
} else {
|
||||
uint8_t *data;
|
||||
|
||||
allocate(current->payload, current->payload_size);
|
||||
data = current->payload;
|
||||
|
||||
for (i = 0; i < current->payload_size; i++)
|
||||
xu(8, payload_byte[i], data[i], 0, 255, 1, i);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int FUNC(message_list)(CodedBitstreamContext *ctx, RWContext *rw,
|
||||
SEIRawMessageList *current, int prefix)
|
||||
{
|
||||
SEIRawMessage *message;
|
||||
int err, k;
|
||||
|
||||
#ifdef READ
|
||||
for (k = 0;; k++) {
|
||||
uint32_t payload_type = 0;
|
||||
uint32_t payload_size = 0;
|
||||
uint32_t tmp;
|
||||
|
||||
while (show_bits(rw, 8) == 0xff) {
|
||||
fixed(8, ff_byte, 0xff);
|
||||
payload_type += 255;
|
||||
}
|
||||
xu(8, last_payload_type_byte, tmp, 0, 254, 0);
|
||||
payload_type += tmp;
|
||||
|
||||
while (show_bits(rw, 8) == 0xff) {
|
||||
fixed(8, ff_byte, 0xff);
|
||||
payload_size += 255;
|
||||
}
|
||||
xu(8, last_payload_size_byte, tmp, 0, 254, 0);
|
||||
payload_size += tmp;
|
||||
|
||||
CHECK(ff_cbs_sei_list_add(current));
|
||||
message = ¤t->messages[k];
|
||||
|
||||
message->payload_type = payload_type;
|
||||
message->payload_size = payload_size;
|
||||
|
||||
CHECK(FUNC(message)(ctx, rw, message));
|
||||
|
||||
if (!cbs_h2645_read_more_rbsp_data(rw))
|
||||
break;
|
||||
}
|
||||
#else
|
||||
for (k = 0; k < current->nb_messages; k++) {
|
||||
PutBitContext start_state;
|
||||
uint32_t tmp;
|
||||
int trace, i;
|
||||
|
||||
message = ¤t->messages[k];
|
||||
|
||||
// We write the payload twice in order to find the size. Trace
|
||||
// output is switched off for the first write.
|
||||
trace = ctx->trace_enable;
|
||||
ctx->trace_enable = 0;
|
||||
|
||||
start_state = *rw;
|
||||
for (i = 0; i < 2; i++) {
|
||||
*rw = start_state;
|
||||
|
||||
tmp = message->payload_type;
|
||||
while (tmp >= 255) {
|
||||
fixed(8, ff_byte, 0xff);
|
||||
tmp -= 255;
|
||||
}
|
||||
xu(8, last_payload_type_byte, tmp, 0, 254, 0);
|
||||
|
||||
tmp = message->payload_size;
|
||||
while (tmp >= 255) {
|
||||
fixed(8, ff_byte, 0xff);
|
||||
tmp -= 255;
|
||||
}
|
||||
xu(8, last_payload_size_byte, tmp, 0, 254, 0);
|
||||
|
||||
err = FUNC(message)(ctx, rw, message);
|
||||
ctx->trace_enable = trace;
|
||||
if (err < 0)
|
||||
return err;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user