From patchwork Mon Oct 28 01:37:30 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Forest Crossman X-Patchwork-Id: 15997 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 24B8844A45F for ; Mon, 28 Oct 2019 03:37:51 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id E9F8968ABD8; Mon, 28 Oct 2019 03:37:50 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qt1-f171.google.com (mail-qt1-f171.google.com [209.85.160.171]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 8AC3668AB17 for ; Mon, 28 Oct 2019 03:37:44 +0200 (EET) Received: by mail-qt1-f171.google.com with SMTP id t26so2318259qtr.5 for ; Sun, 27 Oct 2019 18:37:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=rIDUb2QJYbFqFx41xFO7/SwmOFWi/uLhxim6pn+7clc=; b=K2D5kMoeFgd7+u9RKn65IkKcZN2865ZSusVpHhMz1msrK0XYyiC8NZYz7P2NNtPrly 8e0PdYTE/Y615q7UtSNvP8m93LodN3Ku/ZayTPWQj4RuDSRUxrBCREc/zoNPjyC0SyaS +K31nzLurnVE6qC/yLwBxYirwyRgc2OyMtDPcAX5/CCtqMUbNVrfz6mKrLJYH2Q0Mbs1 7WTnPbsuyUOFnS/iqaS41Ido07+1ZlftxLjFMBweNc1s3Zk3GPQgQlr75EhpgrobEh38 Ks+y/iWr5h4v7y8OAJ5mJ+YZXwvbQpROwlmjyEkaACHvKhWdKBb3OQLHzH7LooYa6dls hYdg== 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:mime-version:content-transfer-encoding; bh=rIDUb2QJYbFqFx41xFO7/SwmOFWi/uLhxim6pn+7clc=; b=NY7UR73YMMCqYxRd5GX7iSBlFuTUZBHn2w8wysFGstBe7P9typ15Vr4Xn/6J68I8Rt KJOHx7vZ0n0u6Qgi7T8fndOq33K9Tx5ZHeuf8H+DjRfn2pSFutpnwqyPszMctpPiYvS9 v2CkAwsMQsNvl24dNK7kDSbsz7o5RsTfEJhdLF/edBp/j+7ajAqEkcxH76k2gitOT/K+ STTP4Vo0Kd5mjcuYELnN6K/zQKoAw+oLKR3O0aCQeiQOLRjEQCQcJx0BYfmZhSWteJrL TdxGtRrKYy91wbdUvfRN9hFvuBGPQd4rQli0ITQJ2xSUHB8NvLUSRBJ9Y2LKkUsAAGip W+/g== X-Gm-Message-State: APjAAAV3+qq5ynRpfzqGYulohX25sZmP3I1dsPBYtF67jWvo2hgMKJKv fehJi2TwzAZwD61lEb3qDexqd7M8FUw= X-Google-Smtp-Source: APXvYqxHqTpKFr1OlVLh/9usWb34F/w5XpCzfiuvHbgYGBh5rG5adj+dfr5fJe7FFyhYdPC5uv2WGQ== X-Received: by 2002:a0c:992e:: with SMTP id h43mr9552763qvd.145.1572226663179; Sun, 27 Oct 2019 18:37:43 -0700 (PDT) Received: from localhost.localdomain ([194.59.251.37]) by smtp.gmail.com with ESMTPSA id c15sm5212556qkc.101.2019.10.27.18.37.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 27 Oct 2019 18:37:42 -0700 (PDT) From: Forest Crossman To: ffmpeg-devel@ffmpeg.org Date: Sun, 27 Oct 2019 20:37:30 -0500 Message-Id: <98bdfd0d35e44740722d03124bedcb9b06b79219.1572226177.git.cyrozap@gmail.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: References: <20191020095533.15016-1-cyrozap@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2 5/5] libdc1394: Fix PTS wrapping 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: Forest Crossman Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Without this, the timestamp will unexpectedly wrap around after approximately 2146 frames (on a 64-bit system, at least), which is about 19 minutes at the lowest framerate supported by the IIDC standard and about 9 seconds at the highest supported framerate. To fix this, we use av_rescale() to do the PTS calculation, then we change both the current_frame and frame_rate variables to int64_t (for consistency) and keep the PTS wraparound bits set to 64. For all intents and purposes, however, the PTS will never wrap around, because even at 240 fps--the highest framerate supported by the IIDC standard--it would take over 292 million years of continuous recording before an overflow would occur. Signed-off-by: Forest Crossman --- libavdevice/libdc1394.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/libavdevice/libdc1394.c b/libavdevice/libdc1394.c index 90252f7c4a..1e138edac2 100644 --- a/libavdevice/libdc1394.c +++ b/libavdevice/libdc1394.c @@ -40,8 +40,8 @@ typedef struct dc1394_data { dc1394_t *d; dc1394camera_t *camera; dc1394video_frame_t *frame; - int current_frame; - int frame_rate; /**< frames per 1000 seconds (fps * 1000) */ + int64_t current_frame; + int64_t frame_rate; /**< frames per 1000 seconds (fps * 1000) */ char *video_size; /**< String describing video size, set by a private option. */ char *pixel_format; /**< Set by a private option. */ char *framerate; /**< Set by a private option. */ @@ -133,8 +133,8 @@ static inline int dc1394_read_common(AVFormatContext *c, break; if (!fps->frame_rate || !fmt->width) { - av_log(c, AV_LOG_ERROR, "Can't find matching camera format for %s, %dx%d@%d:1000fps\n", av_get_pix_fmt_name(pix_fmt), - width, height, dc1394->frame_rate); + av_log(c, AV_LOG_ERROR, "Can't find matching camera format for %s, %dx%d@%"PRId64":1000fps\n", + av_get_pix_fmt_name(pix_fmt), width, height, dc1394->frame_rate); ret = AVERROR(EINVAL); goto out; } @@ -342,14 +342,14 @@ static int dc1394_read_packet(AVFormatContext *c, AVPacket *pkt) /* discard stale frame */ if (dc1394->current_frame++) { if (dc1394_capture_enqueue(dc1394->camera, dc1394->frame) != DC1394_SUCCESS) - av_log(c, AV_LOG_ERROR, "failed to release %d frame\n", dc1394->current_frame); + av_log(c, AV_LOG_ERROR, "failed to release %"PRId64" frame\n", dc1394->current_frame); } res = dc1394_capture_dequeue(dc1394->camera, DC1394_CAPTURE_POLICY_WAIT, &dc1394->frame); if (res == DC1394_SUCCESS) { pkt->data = (uint8_t *)dc1394->frame->image; pkt->size = dc1394->frame->image_bytes; - pkt->pts = dc1394->current_frame * 1000000 / dc1394->frame_rate; + pkt->pts = av_rescale(dc1394->current_frame, 1000000, dc1394->frame_rate); pkt->flags |= AV_PKT_FLAG_KEY; pkt->stream_index = dc1394->stream_index; } else {