From patchwork Fri Oct 12 13:38:39 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: joshdk@ob-encoder.com X-Patchwork-Id: 10654 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 605894468A9 for ; Fri, 12 Oct 2018 16:38:48 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 998BA68A50E; Fri, 12 Oct 2018 16:38:29 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f68.google.com (mail-wm1-f68.google.com [209.85.128.68]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 9BC5368A4BE for ; Fri, 12 Oct 2018 16:38:22 +0300 (EEST) Received: by mail-wm1-f68.google.com with SMTP id 143-v6so12279499wmf.1 for ; Fri, 12 Oct 2018 06:38:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ob-encoder-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=bCtwFeULN0cDWoCUD4ONYOc7aqi/4iPeDMcwjqt7JK4=; b=W+2+mHsmu8R64YY/4+fibnPch2JNSKxyWZRHpxJyQVpITj2ohlGg/Np+o3eMqkm/kT kWEp8Te1y33YreM5WI67yp6hc/pQlUbpOLsmKSnvmL37aWia0e3PvDLKgtzrL/D20XJq qnMy7h4TLX52k1gGHg9z76H4Jc6VHYrEfbXw2ecu3MmkFO+bw4369Q+Ov+FyE3MUyq6n 8RdeQO/2NPmJU/w/Ww8tGA6tZOj/EjXJLdsVDHFC4OQD2OVKQnJB0JDmXg0D2WtsM6mm iNi2mj/+csffm+ckjTZQtTBRqr2Q1XP/3y+jpuEIC53ebWYiNYp4Ha7k8EIX8bdi1p5x UJsw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=bCtwFeULN0cDWoCUD4ONYOc7aqi/4iPeDMcwjqt7JK4=; b=WghW5gbIlwVJ0A8EIgwMPG+10/5uJ5IhSOO9wg20ETIDFiCH2Zv6HLjXO6Zbd2hTuL BuXkvNvfaFyTEd1khiIZUWwMoO+l1qvpridinoK1DmJrtaEjEaZG35XbMYzrzwuJFz0c 07LM7bAg1HKzjM63olLaVvVGL30Z0nC/+ehdSda3iSziOGwzz4XOuSWMQH39Cqq2CZr0 QwKWgeFZRjCSbh8Ap3aACb+4Uy5GpKn5goz3eq4G0rJEZhumT//KQ5TZTqRoaEqI4wb/ Mo1rgOGP4KuoqPUaJ6iN86NzzWepHkaN2qn0LZP7coS8uuUSr8q3G2l+oN4IAYBZYTYz T6aQ== X-Gm-Message-State: ABuFfoix4fUIdLScYDU3fLCSq5MPNVmTS+nOtuqbvXoC5A6riW7jVdBs pBQ8Q5bNYa6KGhieTyEoFEgwH6DgZPE= X-Google-Smtp-Source: ACcGV62onRO0UFA+Q9m7hUL4TtNDf6X1f3T7fA6R/a9f+N5d4agHRZ840u4AIidSTlw43noC59mSBw== X-Received: by 2002:a1c:890:: with SMTP id 138-v6mr4997090wmi.128.1539351525127; Fri, 12 Oct 2018 06:38:45 -0700 (PDT) Received: from localhost.localdomain ([31.24.218.220]) by smtp.gmail.com with ESMTPSA id v129-v6sm905314wme.45.2018.10.12.06.38.44 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 12 Oct 2018 06:38:44 -0700 (PDT) From: joshdk@ob-encoder.com X-Google-Original-From: joshdk@obe.tv To: ffmpeg-devel@ffmpeg.org Date: Fri, 12 Oct 2018 14:38:39 +0100 Message-Id: <20181012133841.13921-2-joshdk@obe.tv> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181012133841.13921-1-joshdk@obe.tv> References: <20181012133841.13921-1-joshdk@obe.tv> Subject: [FFmpeg-devel] [PATCH v4 2/4] h264/pic_timing: support multiple timecodes X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: Josh de Kock MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" From: Josh de Kock --- There are no cosmetic changes which are not functional here. libavcodec/h264_sei.c | 21 ++++++++------- libavcodec/h264_sei.h | 28 +++++++++++++------ libavcodec/h264_slice.c | 59 +++++++++++++++++++++++------------------ 3 files changed, 65 insertions(+), 43 deletions(-) diff --git a/libavcodec/h264_sei.c b/libavcodec/h264_sei.c index 275224eabe..d4eb9c0dab 100644 --- a/libavcodec/h264_sei.c +++ b/libavcodec/h264_sei.c @@ -84,8 +84,10 @@ static int decode_picture_timing(H264SEIPictureTiming *h, GetBitContext *gb, return AVERROR_INVALIDDATA; num_clock_ts = sei_num_clock_ts_table[h->pic_struct]; + h->timecode_cnt = 0; for (i = 0; i < num_clock_ts; i++) { if (get_bits(gb, 1)) { /* clock_timestamp_flag */ + H264SEITimeCode *tc = &h->timecode[h->timecode_cnt++]; unsigned int full_timestamp_flag; unsigned int counting_type, cnt_dropped_flag; h->ct_type |= 1 << get_bits(gb, 2); @@ -95,20 +97,21 @@ static int decode_picture_timing(H264SEIPictureTiming *h, GetBitContext *gb, skip_bits(gb, 1); /* discontinuity_flag */ cnt_dropped_flag = get_bits(gb, 1); /* cnt_dropped_flag */ if (cnt_dropped_flag && counting_type > 1 && counting_type < 7) - h->tc_dropframe = 1; - h->tc_frames = get_bits(gb, 8); /* n_frames */ + tc->dropframe = 1; + tc->frame = get_bits(gb, 8); /* n_frames */ if (full_timestamp_flag) { - h->fulltc_received = 1; - h->tc_seconds = get_bits(gb, 6); /* seconds_value 0..59 */ - h->tc_minutes = get_bits(gb, 6); /* minutes_value 0..59 */ - h->tc_hours = get_bits(gb, 5); /* hours_value 0..23 */ + tc->full = 1; + tc->seconds = get_bits(gb, 6); /* seconds_value 0..59 */ + tc->minutes = get_bits(gb, 6); /* minutes_value 0..59 */ + tc->hours = get_bits(gb, 5); /* hours_value 0..23 */ } else { + tc->seconds = tc->minutes = tc->hours = tc->full = 0; if (get_bits(gb, 1)) { /* seconds_flag */ - h->tc_seconds = get_bits(gb, 6); + tc->seconds = get_bits(gb, 6); if (get_bits(gb, 1)) { /* minutes_flag */ - h->tc_minutes = get_bits(gb, 6); + tc->minutes = get_bits(gb, 6); if (get_bits(gb, 1)) /* hours_flag */ - h->tc_minutes = get_bits(gb, 5); + tc->hours = get_bits(gb, 5); } } } diff --git a/libavcodec/h264_sei.h b/libavcodec/h264_sei.h index 3b8806be0a..a75c3aa175 100644 --- a/libavcodec/h264_sei.h +++ b/libavcodec/h264_sei.h @@ -67,6 +67,17 @@ typedef enum { H264_SEI_FPA_TYPE_2D = 6, } H264_SEI_FpaType; +typedef struct H264SEITimeCode { + /* When not continuously receiving full timecodes, we have to reference + the previous timecode received */ + int full; + int frame; + int seconds; + int minutes; + int hours; + int dropframe; +} H264SEITimeCode; + typedef struct H264SEIPictureTiming { int present; H264_SEI_PicStructType pic_struct; @@ -88,14 +99,15 @@ typedef struct H264SEIPictureTiming { */ int cpb_removal_delay; - /* When not continuously receiving full timecodes, we have to reference - the previous timecode received */ - int fulltc_received; - int tc_frames; - int tc_seconds; - int tc_minutes; - int tc_hours; - int tc_dropframe; + /** + * Maximum three timecodes in a pic_timing SEI. + */ + H264SEITimeCode timecode[3]; + + /** + * Number of timecode in use + */ + int timecode_cnt; } H264SEIPictureTiming; typedef struct H264SEIAFD { diff --git a/libavcodec/h264_slice.c b/libavcodec/h264_slice.c index f5415ba595..2e158745a0 100644 --- a/libavcodec/h264_slice.c +++ b/libavcodec/h264_slice.c @@ -1287,42 +1287,49 @@ static int h264_export_frame_props(H264Context *h) h->avctx->properties |= FF_CODEC_PROPERTY_CLOSED_CAPTIONS; } - if (h->sei.picture_timing.fulltc_received) { + if (h->sei.picture_timing.timecode_cnt > 0) { uint32_t tc = 0; - uint32_t frames; + uint32_t *tc_sd; AVFrameSideData *tcside = av_frame_new_side_data(cur->f, AV_FRAME_DATA_S12M_TIMECODE, - sizeof(uint32_t)); + sizeof(uint32_t)*4); if (!tcside) return AVERROR(ENOMEM); - /* For SMPTE 12-M timecodes, frame count is a special case if > 30 FPS. - See SMPTE ST 12-1:2014 Sec 12.1 for more info. */ - if (av_cmp_q(h->avctx->framerate, (AVRational) {30, 1}) == 1) { - frames = h->sei.picture_timing.tc_frames / 2; - if (h->sei.picture_timing.tc_frames % 2 == 1) { - if (av_cmp_q(h->avctx->framerate, (AVRational) {50, 1}) == 0) - tc |= (1 << 7); - else - tc |= (1 << 23); + tc_sd = (uint32_t*)tcside->data; + tc_sd[0] = h->sei.picture_timing.timecode_cnt; + + for (int i = 0; i < tc_sd[0]; i++) { + uint32_t frames; + + /* For SMPTE 12-M timecodes, frame count is a special case if > 30 FPS. + See SMPTE ST 12-1:2014 Sec 12.1 for more info. */ + if (av_cmp_q(h->avctx->framerate, (AVRational) {30, 1}) == 1) { + frames = h->sei.picture_timing.timecode[i].frame / 2; + if (h->sei.picture_timing.timecode[i].frame % 2 == 1) { + if (av_cmp_q(h->avctx->framerate, (AVRational) {50, 1}) == 0) + tc |= (1 << 7); + else + tc |= (1 << 23); + } + } else { + frames = h->sei.picture_timing.timecode[i].frame; } - } else { - frames = h->sei.picture_timing.tc_frames; - } - tc |= h->sei.picture_timing.tc_dropframe << 30; - tc |= (frames / 10) << 28; - tc |= (frames % 10) << 24; - tc |= (h->sei.picture_timing.tc_seconds / 10) << 20; - tc |= (h->sei.picture_timing.tc_seconds % 10) << 16; - tc |= (h->sei.picture_timing.tc_minutes / 10) << 12; - tc |= (h->sei.picture_timing.tc_minutes % 10) << 8; - tc |= (h->sei.picture_timing.tc_hours / 10) << 4; - tc |= (h->sei.picture_timing.tc_hours % 10); + tc |= h->sei.picture_timing.timecode[i].dropframe << 30; + tc |= (frames / 10) << 28; + tc |= (frames % 10) << 24; + tc |= (h->sei.picture_timing.timecode[i].seconds / 10) << 20; + tc |= (h->sei.picture_timing.timecode[i].seconds % 10) << 16; + tc |= (h->sei.picture_timing.timecode[i].minutes / 10) << 12; + tc |= (h->sei.picture_timing.timecode[i].minutes % 10) << 8; + tc |= (h->sei.picture_timing.timecode[i].hours / 10) << 4; + tc |= (h->sei.picture_timing.timecode[i].hours % 10); - memcpy(tcside->data, &tc, sizeof(uint32_t)); - h->sei.picture_timing.fulltc_received = 0; + tc_sd[i + 1] = tc; + } + h->sei.picture_timing.timecode_cnt = 0; } if (h->sei.alternative_transfer.present &&