From patchwork Fri Aug 7 13:37:33 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jun Zhao X-Patchwork-Id: 21522 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 B647444A3D5 for ; Fri, 7 Aug 2020 16:37:49 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 7D39E68B77C; Fri, 7 Aug 2020 16:37:49 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f48.google.com (mail-wm1-f48.google.com [209.85.128.48]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 1F29E68B4BD for ; Fri, 7 Aug 2020 16:37:43 +0300 (EEST) Received: by mail-wm1-f48.google.com with SMTP id t14so1883497wmi.3 for ; Fri, 07 Aug 2020 06:37:43 -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; bh=vRvnGYvixgg5C82Zbi2qWbkQ4YbKnJsFT2kw5nnGGe8=; b=mtD1HoK67uRTYLmdiQtRIPxYyFsR8ERCCK1nm3osrZDOsJT1n7Ln2UnwKfaAY1zKbJ E43kTH4COY+rq800w2dN3SIylKU4qIxdXTdkxOEmSJGyfIak1J5T1++TX4emOx1OsgID 01M5gJHAdztuzyW7cWX4ozG1Z3lxuTMhxgR4uRHiJEjc2u08pyU3wgWYnTRJxf7BMo6f hSZLdkWpOwNc0m3bK8Nn+O6LBpQRdvZ9GbQwrZc5IdHbNMrBMsCZHXMLBpsLuGlLPuu7 fNRGqlPL03Zqc9OOCzCOcmVcfZg2vZSbAaKbErpzUp913Wb2Qsz9nseszT2MNsELK5Qo npOg== 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; bh=vRvnGYvixgg5C82Zbi2qWbkQ4YbKnJsFT2kw5nnGGe8=; b=BRvG7WUJVAsMh6bDmctrOnrE2ZupIgNrt+ZFxeF2Jh9rJWAZNwIzCSsN5YEjgfjS5p ef6J6K0DAZ5rq/EtXdvVsOdvzCRp7v0mB547Ex3NfUjUE1NCRtJ4thfmxvTOlZP2mu56 ybA+W39SQde+g51ZwJ3K+eBpQhT9QWBqZqmVEiOWPlrUWeJ6gZVh/N7bTjTeNSJMOCmO Lf96sb0sBX+RKlASGPaE7FFKbCzX3v92WHx/JGzkqo+Z9+fJ4Ecaw/yTZqH3ykhRfUTt DzmbTLItTQI6qRDrO4ufZwEG3oUcJqSzCGyntNMIZ/nexgrp6sp9IeCN92MBRR7AF9WK P8jg== X-Gm-Message-State: AOAM532f9yVHyoECW8//4zVw2rvJRkHna2GIv41EC0QwCCeanrRxPyKX Y/+cTTeEeHJ77C/pxQ7f+2VpRiBH X-Google-Smtp-Source: ABdhPJzaPsqpKb1dvo784LPirMz+Dqy2Ins77yS7/mYpj6GmA2Z6VCa/KC62tWCa4HtHjbhs6EXGaQ== X-Received: by 2002:a1c:7e44:: with SMTP id z65mr13619554wmc.13.1596807462278; Fri, 07 Aug 2020 06:37:42 -0700 (PDT) Received: from localhost.localdomain ([49.51.162.193]) by smtp.gmail.com with ESMTPSA id m126sm10590362wmf.3.2020.08.07.06.37.41 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 07 Aug 2020 06:37:41 -0700 (PDT) From: Jun Zhao To: ffmpeg-devel@ffmpeg.org Date: Fri, 7 Aug 2020 21:37:33 +0800 Message-Id: <1596807454-17939-1-git-send-email-mypopydev@gmail.com> X-Mailer: git-send-email 2.7.4 Subject: [FFmpeg-devel] [PATCH 1/2] lavf/mov: Remove redundant code 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: Jun Zhao MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" From: Jun Zhao Signed-off-by: Jun Zhao --- libavformat/mov.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libavformat/mov.c b/libavformat/mov.c index 1532e74..808ef7c 100644 --- a/libavformat/mov.c +++ b/libavformat/mov.c @@ -587,7 +587,7 @@ static int mov_read_dref(MOVContext *c, AVIOContext *pb, MOVAtom atom) entries > (atom.size - 1) / MIN_DATA_ENTRY_BOX_SIZE + 1 || entries >= UINT_MAX / sizeof(*sc->drefs)) return AVERROR_INVALIDDATA; - sc->drefs_count = 0; + av_free(sc->drefs); sc->drefs_count = 0; sc->drefs = av_mallocz(entries * sizeof(*sc->drefs)); From patchwork Fri Aug 7 13:37:34 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jun Zhao X-Patchwork-Id: 21523 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 EAC5044A3D5 for ; Fri, 7 Aug 2020 16:37:50 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id D97F968B8E7; Fri, 7 Aug 2020 16:37:50 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f41.google.com (mail-wm1-f41.google.com [209.85.128.41]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id BC5EF68B4BD for ; Fri, 7 Aug 2020 16:37:43 +0300 (EEST) Received: by mail-wm1-f41.google.com with SMTP id d190so1760876wmd.4 for ; Fri, 07 Aug 2020 06:37:43 -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; bh=/RWc9DfHAtX0Plm0OPPAMAEFp8NAr0WqFaHJH3nmrd8=; b=ciWFtjypR2vytCq3u5k2lF4nNxeOarnnWUMzeyQnhsi48NwmuluQNTy3m6MLReCTKH Mp1rM+ui3Ogf9/VyXuD9GnTrdVaO/SLio6Kf24WVBEAc9l30OCRCpoppPyrFlRPdUrjH CBHIy3AEXylAieZVnxBE1fCIn2Mx3cZdzKSkhofHXJrhutFU15yQ2hDSN5XRjIFz5W5h 50h3BXGSEzNg0fiU4R1jcaM9i8719GqN9QHchY/BFGkTJUciU8zoAfvToFoHlqb1RlId 5HmjwlG28fvC1lDdQj6T8TLtB5T1N4lObuG7e2C67Kow0E6WADWz0ruBCNo816jezLBW 8K2A== 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=/RWc9DfHAtX0Plm0OPPAMAEFp8NAr0WqFaHJH3nmrd8=; b=e+A90NNV0BR/+/Q7PhTy/PZfsIX7ogMYZVEcwvCFgG8GSYAWUi4EwWNSJQr/k9TFKH wOdo6n3AtiwjX2HV1Vk4SCH09EY/IkqU4IgP+sLRoxiKC7oMxk4v5lUFFsxL+PBI76tW s4OO9M86MBmM+gAF4bxZq8Sq3rC/iIVD47ydOjMAX/uhmBsl5Ctm9WMx0okSNeIZU05w zIim6SP1swbXVBO38zmQOFCmc5q2tQI8vifhTnHvtnjoQeBAzkevzUrvZhBzNTJwkFtv CRwHasnthwmK7Iwiw3abBr0QOJpm7kf5QI0V/zrJFTjAeGh4vCdZvPF8JZizt71G/TfY IpFg== X-Gm-Message-State: AOAM533kjsVNu3M2avo54VIpTjoKhSICIilBiIQvKOtHnuOu6nuWeLLU rV4Ms5T9sg/TacuxZnrNt20Wybyv X-Google-Smtp-Source: ABdhPJwIYuWyO7F1BKPy9vRlt8a1RzI5En8HxczPz4/DN7+22nI++kyj7OPE4Hh/SH1wTbJeAzaJeQ== X-Received: by 2002:a1c:790b:: with SMTP id l11mr13190563wme.127.1596807462880; Fri, 07 Aug 2020 06:37:42 -0700 (PDT) Received: from localhost.localdomain ([49.51.162.193]) by smtp.gmail.com with ESMTPSA id m126sm10590362wmf.3.2020.08.07.06.37.42 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 07 Aug 2020 06:37:42 -0700 (PDT) From: Jun Zhao To: ffmpeg-devel@ffmpeg.org Date: Fri, 7 Aug 2020 21:37:34 +0800 Message-Id: <1596807454-17939-2-git-send-email-mypopydev@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1596807454-17939-1-git-send-email-mypopydev@gmail.com> References: <1596807454-17939-1-git-send-email-mypopydev@gmail.com> Subject: [FFmpeg-devel] [PATCH 2/2] lavf/mov: Support dref.url box for ISO 14496-12 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: Jun Zhao MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" From: Jun Zhao Enable the dref.url box Signed-off-by: Jun Zhao --- libavformat/isom.h | 6 ++++++ libavformat/mov.c | 45 ++++++++++++++++++++++++++++++++++++++------- 2 files changed, 44 insertions(+), 7 deletions(-) diff --git a/libavformat/isom.h b/libavformat/isom.h index 41a9c64..01e2c33 100644 --- a/libavformat/isom.h +++ b/libavformat/isom.h @@ -77,6 +77,12 @@ typedef struct MOVDref { char volume[28]; char filename[64]; int16_t nlvl_to, nlvl_from; + + /* + * DataEntryUrlBox + */ + char *location; /* a location to find the resource with the given name */ + uint32_t location_len; } MOVDref; typedef struct MOVAtom { diff --git a/libavformat/mov.c b/libavformat/mov.c index 808ef7c..8fe2981 100644 --- a/libavformat/mov.c +++ b/libavformat/mov.c @@ -575,6 +575,7 @@ static int mov_read_dref(MOVContext *c, AVIOContext *pb, MOVAtom atom) AVStream *st; MOVStreamContext *sc; int entries, i, j; + int flags; if (c->fc->nb_streams < 1) return 0; @@ -599,18 +600,19 @@ static int mov_read_dref(MOVContext *c, AVIOContext *pb, MOVAtom atom) MOVDref *dref = &sc->drefs[i]; uint32_t size = avio_rb32(pb); int64_t next = avio_tell(pb) + size - 4; + int ret; if (size < 12) return AVERROR_INVALIDDATA; dref->type = avio_rl32(pb); - avio_rb32(pb); // version + flags + avio_r8(pb); /* version */ + flags = avio_rb24(pb); if (dref->type == MKTAG('a','l','i','s') && size > 150) { /* macintosh alias record */ uint16_t volume_len, len; int16_t type; - int ret; avio_skip(pb, 10); @@ -696,6 +698,24 @@ static int mov_read_dref(MOVContext *c, AVIOContext *pb, MOVAtom atom) } else avio_skip(pb, len); } + } else if (dref->type == MKTAG('u','r','l',' ') && size >= 12) { + if (flags == 1) { + /* do noting when elementray stream in the same file */ + av_log(c->fc, AV_LOG_TRACE, "media data location in the same file\n"); + } else { + uint32_t len = size - 12; + dref->location = av_malloc(len + 1); /* Add null terminator */ + if (!dref->location) + return AVERROR(ENOMEM); + + ret = ffio_read_size(pb, dref->location, len); + if (ret < 0) { + av_freep(&dref->location); + return ret; + } + dref->location_len = len; + dref->location[len] = 0; + } } else { av_log(c->fc, AV_LOG_DEBUG, "Unknown dref type 0x%08"PRIx32" size %"PRIu32"\n", dref->type, size); @@ -4169,6 +4189,11 @@ static int mov_open_dref(MOVContext *c, AVIOContext **pb, const char *src, MOVDr if (!c->fc->io_open(c->fc, pb, filename, AVIO_FLAG_READ, NULL)) return 0; } + } else if (ref->location) { + av_log(c->fc, AV_LOG_WARNING, "Try to open the media file in separate file from %s.\n", + ref->location); + if (!c->fc->io_open(c->fc, pb, ref->location, AVIO_FLAG_READ, NULL)) + return 0; } else if (c->use_absolute_path) { av_log(c->fc, AV_LOG_WARNING, "Using absolute path on user request, " "this is a possible security issue\n"); @@ -4243,23 +4268,28 @@ static int mov_read_trak(MOVContext *c, AVIOContext *pb, MOVAtom atom) mov_build_index(c, st); - if (sc->dref_id-1 < sc->drefs_count && sc->drefs[sc->dref_id-1].path) { + if (sc->dref_id-1 < sc->drefs_count && + (sc->drefs[sc->dref_id-1].path || sc->drefs[sc->dref_id-1].location)) { MOVDref *dref = &sc->drefs[sc->dref_id - 1]; if (c->enable_drefs) { if (mov_open_dref(c, &sc->pb, c->fc->url, dref) < 0) av_log(c->fc, AV_LOG_ERROR, "stream %d, error opening alias: path='%s', dir='%s', " - "filename='%s', volume='%s', nlvl_from=%d, nlvl_to=%d\n", + "filename='%s', volume='%s', nlvl_from=%d, nlvl_to=%d, " + "url : len=%d, location='%s'\n", st->index, dref->path, dref->dir, dref->filename, - dref->volume, dref->nlvl_from, dref->nlvl_to); + dref->volume, dref->nlvl_from, dref->nlvl_to, + dref->location_len, dref->location); } else { av_log(c->fc, AV_LOG_WARNING, "Skipped opening external track: " "stream %d, alias: path='%s', dir='%s', " - "filename='%s', volume='%s', nlvl_from=%d, nlvl_to=%d." + "filename='%s', volume='%s', nlvl_from=%d, nlvl_to=%d. " + "url : len=%d, location='%s' " "Set enable_drefs to allow this.\n", st->index, dref->path, dref->dir, dref->filename, - dref->volume, dref->nlvl_from, dref->nlvl_to); + dref->volume, dref->nlvl_from, dref->nlvl_to, + dref->location_len, dref->location); } } else { sc->pb = c->fc->pb; @@ -7318,6 +7348,7 @@ static int mov_read_close(AVFormatContext *s) for (j = 0; j < sc->drefs_count; j++) { av_freep(&sc->drefs[j].path); av_freep(&sc->drefs[j].dir); + av_freep(&sc->drefs[j].location); } av_freep(&sc->drefs);