From patchwork Sat Oct 24 00:32:25 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Keeley X-Patchwork-Id: 23189 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 7BBB444AD22 for ; Sat, 24 Oct 2020 03:32:45 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 6140F689A8D; Sat, 24 Oct 2020 03:32:45 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail.keeley.nz (mail.keeley.nz [149.28.178.61]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 4BB44688316 for ; Sat, 24 Oct 2020 03:32:38 +0300 (EEST) Received: from mail.keeley.nz ([127.0.0.1]) by mail.keeley.nz with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kW7U1-00085m-Lc for ffmpeg-devel@ffmpeg.org; Sat, 24 Oct 2020 00:32:34 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=keeley.net.nz; s=mail; h=Content-Transfer-Encoding:MIME-Version:Message-Id: Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:In-Reply-To:References:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=J7XweT1CEdPMhECBayPeLVBsjb6cImlOWmo3vFiPDsA=; b=gzc+EjgTv9dCVw8ea1yxQKIKB8 4L8UKlCarjuJ1wAKqgUy7ywkP2NRBqN5vhxTPf+t5umMcz8u5W4b8+xMHJOg0Rc9jMMZ8dlut7fq/ sfXo1WtmayQ5Xq3BKzrXrUSqPaV+0+bHBWy1Goymxq5XFxBayZaMovwraJn7U5ZWYWGU=; From: Michael Keeley To: ffmpeg-devel@ffmpeg.org Date: Sat, 24 Oct 2020 13:32:25 +1300 Message-Id: <20201024003225.216806-1-mike@keeley.net.nz> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH] avformat/dhav: also support ZLAV packets 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: Michael Keeley Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Some DVRs (e.g. D7008FH made by Zhuhai Ltd) output the same format .dav file, but use ZLAV/zlav tags to delimit the packets instead of DHAV/dhav. Signed-off-by: Michael Keeley --- Changelog | 1 + libavformat/dhav.c | 31 ++++++++++++++++++++++--------- libavformat/version.h | 2 +- 3 files changed, 24 insertions(+), 10 deletions(-) diff --git a/Changelog b/Changelog index 21a4be731b..8e289733e2 100644 --- a/Changelog +++ b/Changelog @@ -37,6 +37,7 @@ version : - Cintel RAW decoder - VDPAU accelerated VP9 10/12bit decoding - afreqshift and aphaseshift filters +- Add ZLAV format to DHAV demuxer version 4.3: diff --git a/libavformat/dhav.c b/libavformat/dhav.c index 79afe9be03..e2f3c40065 100644 --- a/libavformat/dhav.c +++ b/libavformat/dhav.c @@ -1,5 +1,5 @@ /* - * DHAV demuxer + * DHAV/ZLAV demuxer * * Copyright (c) 2018 Paul B Mahol * @@ -57,7 +57,7 @@ static int dhav_probe(const AVProbeData *p) if (!memcmp(p->buf, "DAHUA", 5)) return AVPROBE_SCORE_MAX; - if (memcmp(p->buf, "DHAV", 4)) + if (memcmp(p->buf, "DHAV", 4) != 0 && memcmp(p->buf, "ZLAV", 4) != 0) return 0; if (p->buf[4] == 0xf0 || @@ -163,6 +163,19 @@ static int parse_ext(AVFormatContext *s, int length) return 0; } +static int read_start_tag(AVIOContext *pb) +{ + unsigned int start_tag = avio_rl32(pb); + return start_tag == MKTAG('D','H','A','V') || start_tag == MKTAG('Z','L','A','V'); +} + +static int read_end_tag(AVIOContext *pb) +{ + unsigned int end_tag = avio_rl32(pb); + return end_tag == MKTAG('d','h','a','v') || end_tag == MKTAG('z','l','a','v'); +} + + static int read_chunk(AVFormatContext *s) { DHAVContext *dhav = s->priv_data; @@ -173,11 +186,11 @@ static int read_chunk(AVFormatContext *s) if (avio_feof(s->pb)) return AVERROR_EOF; - if (avio_rl32(s->pb) != MKTAG('D','H','A','V')) { + if (!read_start_tag(s->pb)) { dhav->last_good_pos += 0x8000; avio_seek(s->pb, dhav->last_good_pos, SEEK_SET); - while (avio_rl32(s->pb) != MKTAG('D','H','A','V')) { + while (!read_start_tag(s->pb)) { if (avio_feof(s->pb)) return AVERROR_EOF; dhav->last_good_pos += 0x8000; @@ -247,7 +260,7 @@ static int64_t get_duration(AVFormatContext *s) return 0; avio_seek(s->pb, avio_size(s->pb) - 8, SEEK_SET); - if (avio_rl32(s->pb) == MKTAG('d','h','a','v')) { + if (read_end_tag(s->pb)) { int seek_back = avio_rl32(s->pb); avio_seek(s->pb, -seek_back, SEEK_CUR); @@ -281,12 +294,12 @@ static int dhav_read_header(AVFormatContext *s) avio_skip(s->pb, 0x400 - 5); dhav->last_good_pos = avio_tell(s->pb); } else { - if (!memcmp(signature, "DHAV", 4)) { + if (memcmp(signature, "DHAV", 4) == 0 || memcmp(signature, "ZLAV", 4) == 0) { avio_seek(s->pb, -5, SEEK_CUR); dhav->last_good_pos = avio_tell(s->pb); } else if (s->pb->seekable) { avio_seek(s->pb, avio_size(s->pb) - 8, SEEK_SET); - while (avio_rl32(s->pb) == MKTAG('d','h','a','v')) { + while (read_end_tag(s->pb)) { int seek_back; seek_back = avio_rl32(s->pb) + 8; @@ -409,7 +422,7 @@ retry: stream_index = dhav->type == 0xf0 ? dhav->audio_stream_index : dhav->video_stream_index; if (stream_index < 0) { avio_skip(s->pb, ret); - if (avio_rl32(s->pb) == MKTAG('d','h','a','v')) + if (read_end_tag(s->pb)) avio_skip(s->pb, 4); goto retry; } @@ -425,7 +438,7 @@ retry: if (pkt->stream_index >= 0) pkt->pts = get_pts(s, pkt->stream_index); pkt->pos = dhav->last_good_pos; - if (avio_rl32(s->pb) == MKTAG('d','h','a','v')) + if (read_end_tag(s->pb)) avio_skip(s->pb, 4); return ret; diff --git a/libavformat/version.h b/libavformat/version.h index 86e0a232ee..7853068649 100644 --- a/libavformat/version.h +++ b/libavformat/version.h @@ -32,7 +32,7 @@ // Major bumping may affect Ticket5467, 5421, 5451(compatibility with Chromium) // Also please add any ticket numbers that you believe might be affected here #define LIBAVFORMAT_VERSION_MAJOR 58 -#define LIBAVFORMAT_VERSION_MINOR 62 +#define LIBAVFORMAT_VERSION_MINOR 63 #define LIBAVFORMAT_VERSION_MICRO 100 #define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \