And move x264-specific printing in a separate function. --- libavcodec/h264_sei.c | 88 ++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 76 insertions(+), 12 deletions(-)
diff --git a/libavcodec/h264_sei.c b/libavcodec/h264_sei.c index 1fb1fc5..069ab9b 100644 --- a/libavcodec/h264_sei.c +++ b/libavcodec/h264_sei.c @@ -25,6 +25,8 @@ * @author Michael Niedermayer <[email protected]> */ +#include <ctype.h> + #include "avcodec.h" #include "golomb.h" #include "h264.h" @@ -213,30 +215,92 @@ static int decode_registered_user_data(H264Context *h, int size) return 0; } +static const uint8_t x264_version_uuid[] = { + 0xdc, 0x45, 0xe9, 0xbd, 0xe6, 0xd9, 0x48, 0xb7, + 0x96, 0x2c, 0xd8, 0x20, 0xd9, 0x23, 0xee, 0xef +}; + +static void safe_read(GetBitContext *gb, uint8_t *buf, int size) +{ + int i; + + for (i = 0; i < size - 1; i++) { + int val = get_bits(gb, 8); + if (isprint(val)) + buf[i] = val; + else + buf[i] = ' '; + } + buf[i] = '\0'; +} + +static int decode_x264_version(H264Context *h, int size) +{ + int build = 0, i = 0; + uint8_t *x264_string; + + if (size < 13) + goto skip; + + x264_string = av_malloc(size + 1); + if (!x264_string) + return AVERROR(ENOMEM); + + safe_read(&h->gb, x264_string, size + 1); + + if (!memcmp(x264_string, "x264 - core ", 12)) + build = atoi(x264_string + 12); + + if (build > 0) + h->x264_build = build; + + av_log(h->avctx, AV_LOG_DEBUG, "x264 version string:\"%s\"\n", x264_string); + + av_free(x264_string); + +skip: + for (; i < size; i++) + skip_bits(&h->gb, 8); + + return 0; +} + static int decode_unregistered_user_data(H264Context *h, int size) { + int i; + uint8_t uuid[16]; uint8_t *user_data; - int e, build, i; - if (size < 16 || size >= INT_MAX - 16) + if (size < 16) return AVERROR_INVALIDDATA; - user_data = av_malloc(16 + size + 1); + for (i = 0; i < 16; i++) + uuid[i] = get_bits(&h->gb, 8); + + if (!memcmp(uuid, x264_version_uuid, 16)) + return decode_x264_version(h, size - 16); + + av_log(h->avctx, AV_LOG_DEBUG, + "uuid 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x " + "0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n", + uuid[0], uuid[1], uuid[2], uuid[3], + uuid[4], uuid[5], uuid[6], uuid[7], + uuid[8], uuid[9], uuid[10], uuid[11], + uuid[12], uuid[13], uuid[14], uuid[15]); + + if (size >= INT_MAX) + return AVERROR_INVALIDDATA; + + user_data = av_malloc(size - 16 + 1); if (!user_data) return AVERROR(ENOMEM); - for (i = 0; i < size + 16; i++) - user_data[i] = get_bits(&h->gb, 8); - - user_data[i] = 0; - e = sscanf(user_data + 16, "x264 - core %d", &build); - if (e == 1 && build > 0) - h->x264_build = build; + safe_read(&h->gb, user_data, size - 16 + 1); - if (strlen(user_data + 16) > 0) - av_log(h->avctx, AV_LOG_DEBUG, "user data:\"%s\"\n", user_data + 16); + av_log(h->avctx, AV_LOG_DEBUG, "user data:\"%s\"\n", user_data); av_free(user_data); + return 0; } -- 2.6.1 _______________________________________________ libav-devel mailing list [email protected] https://lists.libav.org/mailman/listinfo/libav-devel
