From patchwork Thu Oct 15 21:30:39 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Forest Crossman X-Patchwork-Id: 22976 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 8413944B8E7 for ; Fri, 16 Oct 2020 00:31:06 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 61A9C68B886; Fri, 16 Oct 2020 00:31:06 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ot1-f53.google.com (mail-ot1-f53.google.com [209.85.210.53]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 0B35468B6D4 for ; Fri, 16 Oct 2020 00:31:00 +0300 (EEST) Received: by mail-ot1-f53.google.com with SMTP id t15so603490otk.0 for ; Thu, 15 Oct 2020 14:30:59 -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=O5vHWZJhgP5ppDM37Ag3TnIxwxhvmHxuiHNoC8DOc7I=; b=foXzZVJxAhB1vMjIZc9jbLM3Fu8u1DJlpL22XJBUb0i9MJUwY19sfFvAcvUt6zND2y PKwHW3hfBafgiX+dA7VJUWUtrxBE/e6SsG/in/nV+7P/RjMaI2ItMFb5iVDgzh5s7w7M Fg4dYesAxuZqz5dWalFKUsFgFeJFyY0cvnlUCo2EhHrW7XmtAEIk99jhbB2cjhVI5haF ufFkweMh5YfLuDMGDUNm6/z66XS87boAgV5X+Rgh2xrGpI0XfrXR012vPiHr0W2h+R1R ewDHK7bicxBJfuGPwNy4U8sAYldH+g73en4LrjwKy9oRtY2X3i4r8WCooYzxP+K8AYvN DdTQ== 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=O5vHWZJhgP5ppDM37Ag3TnIxwxhvmHxuiHNoC8DOc7I=; b=oB5gdcBampfq4plaT0NG/Hn1cBTQA3LBzArzjsuv/Y93pO92aOUmjITpgmFE1lslGZ a9IuoXjxYdRk/4TOtynHGX+FIoWAZkDcK9BVpTyqx6ugKh+8MyJr5CjaYrI5iUWJiBTp vr8q/Im87fIDMxJZh5plgNvMNM/GI4GC6V1G7QkRN2BqpTuoJQEzd+ekIhUad6OlsJEa syvi2g7sw3SNEqZpMLv8AYq+8gLxWgYwxoWODEPKwmRH/MyGYz8Pgf+2ULCaHVmvaxmh z97CMgHEdPRjazMpgoVzNld050gYNxg9ViC5UrnqnFqEhC3ifR0Tcax0AIcRhyszI8SW EulA== X-Gm-Message-State: AOAM5305ew9/h9CbiW550mCyfjPIltZvLsxLIszPgTWhWGWDHCjbiQet ahXfd9iuve8Wk4Cv2IEWOxTeMLFkhqY= X-Google-Smtp-Source: ABdhPJwJftAnp4DEtm4JE3OqqUxw7pMIKUodPB4SsfcvPvCGGB0SiivlEycZFD92NflVC9SNUnw3uA== X-Received: by 2002:a05:6830:1f51:: with SMTP id u17mr311935oth.223.1602797458044; Thu, 15 Oct 2020 14:30:58 -0700 (PDT) Received: from localhost.localdomain ([170.130.31.90]) by smtp.gmail.com with ESMTPSA id 15sm233248ooy.36.2020.10.15.14.30.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Oct 2020 14:30:57 -0700 (PDT) From: Forest Crossman To: ffmpeg-devel@ffmpeg.org Date: Thu, 15 Oct 2020 16:30:39 -0500 Message-Id: <20201015213039.1019624-6-cyrozap@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201015213039.1019624-1-cyrozap@gmail.com> References: <20191020095533.15016-1-cyrozap@gmail.com> <20201015213039.1019624-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 {