From patchwork Sun Sep 20 11:53:39 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 22526 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 4367F4486BF for ; Sun, 20 Sep 2020 14:54:07 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 2DC0F68B678; Sun, 20 Sep 2020 14:54:07 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f65.google.com (mail-wm1-f65.google.com [209.85.128.65]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 4457568B5F3 for ; Sun, 20 Sep 2020 14:54:00 +0300 (EEST) Received: by mail-wm1-f65.google.com with SMTP id z9so9804604wmk.1 for ; Sun, 20 Sep 2020 04:54:00 -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:reply-to:mime-version :content-transfer-encoding; bh=8t5KxhsZPMYxMsXPoy2LgrmyqKAeE9PY25FWafnqs8E=; b=Od9ftGOOnKuUaXLhMvPrYY1KApeU0m3/x6WByuZTe7no/LBzzOk09MJ4gUd7W6xcl0 t68K5SWvQVgEb9Rr9YOuqLy+PJxorH4MZ4ei8rjgQne8ASnpKJzzxsFywqQLsq98n1HO hlwoAYItsqm1HRm2GVZR3xplMERetqu/cJB0j8BErNmDfElPGgaB2ZzfPpQ6wl7kyAuo rwZwwzqxAyBe5bbCbybhLTXl9ssVRyhBGLLdgUv4pc5p068wybgbVCKqLjGgHOUBrgEQ wxNH2tey889eSezsVZHHC1AvROXXg4IecnoMhe2xBNhLzdGmMJeHPEy7vyZhww8bxgAq OYUA== 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:reply-to :mime-version:content-transfer-encoding; bh=8t5KxhsZPMYxMsXPoy2LgrmyqKAeE9PY25FWafnqs8E=; b=kxcIGQS6yGxGk26mE+xdf8ALTBzJzXMJuD+uKnMD3FieGMyi+Rh7ca7A/MUQWQt4lt UN+s5git6W0GEI9QcJI/V4i9eTyLcKROO+gvewppAfwVoX1iamxuw7mkwGjjbw7JSrHx 6p68i/k/X9kt3zZ7aNTJwcCoQHS4jOJO9LrtiZgXPbPkcGeSxl0pQxip28LXJ3tlvt4h aGvXr3JwSeFlgDWy65aStXJ+SBDAYuBF3uA4vvfI2/qjMdxQk2ERCUUZkEmZehFWll0a FDfB1EmUxA0cL91ejF6adM3dPpfEeOizYVfYcCWDJ8ZW9lLICmqCfrYCkdpJVN1LgHoR S+AQ== X-Gm-Message-State: AOAM530JIMFCoGb+r92oeESqMJrm59pqUq1Q4u6JpevYMCvLPnOBoLUE dL5PKkPqDtPf0KovO96vRCL7bI+nBGE= X-Google-Smtp-Source: ABdhPJzWzhgflOJ6+Tq8kQUIy/aqcwWNAW8NiI24sKpKiSV7z9iCMH2v3iF3nzQ5Po1peThau+Zgjw== X-Received: by 2002:a1c:59c3:: with SMTP id n186mr25054611wmb.32.1600602839408; Sun, 20 Sep 2020 04:53:59 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc1fb0f.dynamic.kabel-deutschland.de. [188.193.251.15]) by smtp.gmail.com with ESMTPSA id u126sm17057127wmu.9.2020.09.20.04.53.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 20 Sep 2020 04:53:58 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Sun, 20 Sep 2020 13:53:39 +0200 Message-Id: <20200920115341.1812809-1-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 1/3] avformat/swfdec: Fix memleaks on error 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: Andreas Rheinhardt Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Signed-off-by: Andreas Rheinhardt --- libavformat/swfdec.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/libavformat/swfdec.c b/libavformat/swfdec.c index e427998744..7a74fa3ac7 100644 --- a/libavformat/swfdec.c +++ b/libavformat/swfdec.c @@ -146,13 +146,18 @@ static int swf_read_header(AVFormatContext *s) swf->zbuf_out = av_malloc(ZBUF_SIZE); swf->zpb = avio_alloc_context(swf->zbuf_out, ZBUF_SIZE, 0, s, zlib_refill, NULL, NULL); - if (!swf->zbuf_in || !swf->zbuf_out || !swf->zpb) + if (!swf->zbuf_in || !swf->zbuf_out || !swf->zpb) { + av_freep(&swf->zbuf_in); + av_freep(&swf->zbuf_out); + avio_context_free(&swf->zpb); return AVERROR(ENOMEM); + } swf->zpb->seekable = 0; if (inflateInit(&swf->zstream) != Z_OK) { av_log(s, AV_LOG_ERROR, "Unable to init zlib context\n"); av_freep(&swf->zbuf_in); av_freep(&swf->zbuf_out); + avio_context_free(&swf->zpb); return AVERROR(EINVAL); } pb = swf->zpb; From patchwork Sun Sep 20 11:53:40 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 22527 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 783024486BF for ; Sun, 20 Sep 2020 14:54:27 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 5050568B82F; Sun, 20 Sep 2020 14:54:27 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f67.google.com (mail-wm1-f67.google.com [209.85.128.67]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 0789768B4CF for ; Sun, 20 Sep 2020 14:54:21 +0300 (EEST) Received: by mail-wm1-f67.google.com with SMTP id y15so9797789wmi.0 for ; Sun, 20 Sep 2020 04:54:21 -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:reply-to :mime-version:content-transfer-encoding; bh=igzJfP0AwmdjYMByJkiAz2xgadgy14RPbJjAvlknNtY=; b=TVE6WF4w1ncHj8vtCg8o4bIHMPJx/tY2OZdSxJ/Mooq4ZKfaPWeo4HhjQtHZI9Uv22 GbiaGj/pqASl38LcyEPB2SsqS4p6KpfdYdTD0mLfwfg7fjbrf8KrRqotvi4KJ2GUrHZ9 zHMW5cHRrMJQ+y7A4BfJ+lsKtPn/B0C5cwg+FEaMUMGDiC4H8fQZmgwDKkGY7pGWjv3g qfBdVazDzMSb4nY3HWkLLVj3PY/6awtIh2pNSgcEAu0HGaJPDNrjV5YRqoYKxV4U42bS yNgSVq0/xQRWl0WMw9gEOrT+OE2kJ0+Hx15gip6+bgLF4u75aqARf8tE6qb2UolC+/nV bSbA== 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:reply-to:mime-version:content-transfer-encoding; bh=igzJfP0AwmdjYMByJkiAz2xgadgy14RPbJjAvlknNtY=; b=hgrFc0PqUovrGVbDDijdyBxjJ43d2dlGaDVFU6m9aNUdImMOghMy7vN2Tv2PqIIjK2 zB2c6jchxvschOYDER8/7qZgtAXmvK2K2COAXuBrI2n8U70F8zfMJOfARPYfOSEhykMs VOG8iCFR31CPofPwqJrSrUujdN5Ev8wFZp3r6FsBlLgcpxvVfsySwdQ2/FldMbvKB52o Ftsy7/wIVgwmvBBAts0VD+obwNvtwq+ABdJOISETHpThOJTnZaLIWAnuskAPqVyhAaSw AmThy/8NLg1WNPYSC1AEKxZUUUUTj1umVjKSlrPo4HKYj84JqwQaS6UijopfSkoo+jAO jPpA== X-Gm-Message-State: AOAM530NOSi8fsVbIDbogZkmnGRgVJLmVtPVnT8m63f9ASnbVh+jl49N Nb3G7vrSYLrDIYBfZc1Daxbb0pa5qyU= X-Google-Smtp-Source: ABdhPJw0wxnVBRzZ/AmaXr2wZx6zHOOQtCo6dNxRXKlldqBXSWF8OclYeE0gRrqu3SMAswQRisMx+Q== X-Received: by 2002:a7b:c111:: with SMTP id w17mr23970381wmi.109.1600602860075; Sun, 20 Sep 2020 04:54:20 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc1fb0f.dynamic.kabel-deutschland.de. [188.193.251.15]) by smtp.gmail.com with ESMTPSA id u126sm17057127wmu.9.2020.09.20.04.54.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 20 Sep 2020 04:54:19 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Sun, 20 Sep 2020 13:53:40 +0200 Message-Id: <20200920115341.1812809-2-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200920115341.1812809-1-andreas.rheinhardt@gmail.com> References: <20200920115341.1812809-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 2/3] avformat/swfdec: Reorder allocations/initializations 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: Andreas Rheinhardt Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" The earlier code would first attempt to allocate two buffers, then attempt to allocate an AVIOContext, using one of the new buffers I/O buffer, then check the allocations. On success, a z_stream that is used in the AVIOContext's read_packet callback is initialized afterwards. There are two problems with this: In case the allocation of the I/O buffer fails avio_alloc_context() will be given a NULL read buffer with a size > 0. This works right now, but it is fragile. The second problem is that the z_stream used in the read_packet callback is not functional when avio_alloc_context() is allocated (it might be that avio_alloc_context() might already fill the buffer in the future). This commit fixes both of these problems by reordering the operations. Signed-off-by: Andreas Rheinhardt --- libavformat/swfdec.c | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/libavformat/swfdec.c b/libavformat/swfdec.c index 7a74fa3ac7..d1ed1e2a53 100644 --- a/libavformat/swfdec.c +++ b/libavformat/swfdec.c @@ -128,6 +128,8 @@ retry: return buf_size - z->avail_out; } + +static av_cold int swf_read_close(AVFormatContext *avctx); #endif static int swf_read_header(AVFormatContext *s) @@ -142,24 +144,18 @@ static int swf_read_header(AVFormatContext *s) if (tag == MKBETAG('C', 'W', 'S', 0)) { av_log(s, AV_LOG_INFO, "SWF compressed file detected\n"); #if CONFIG_ZLIB - swf->zbuf_in = av_malloc(ZBUF_SIZE); - swf->zbuf_out = av_malloc(ZBUF_SIZE); - swf->zpb = avio_alloc_context(swf->zbuf_out, ZBUF_SIZE, 0, s, - zlib_refill, NULL, NULL); - if (!swf->zbuf_in || !swf->zbuf_out || !swf->zpb) { - av_freep(&swf->zbuf_in); - av_freep(&swf->zbuf_out); - avio_context_free(&swf->zpb); - return AVERROR(ENOMEM); - } - swf->zpb->seekable = 0; if (inflateInit(&swf->zstream) != Z_OK) { av_log(s, AV_LOG_ERROR, "Unable to init zlib context\n"); - av_freep(&swf->zbuf_in); - av_freep(&swf->zbuf_out); - avio_context_free(&swf->zpb); return AVERROR(EINVAL); } + if (!(swf->zbuf_in = av_malloc(ZBUF_SIZE)) || + !(swf->zbuf_out = av_malloc(ZBUF_SIZE)) || + !(swf->zpb = avio_alloc_context(swf->zbuf_out, ZBUF_SIZE, 0, + s, zlib_refill, NULL, NULL))) { + swf_read_close(s); + return AVERROR(ENOMEM); + } + swf->zpb->seekable = 0; pb = swf->zpb; #else av_log(s, AV_LOG_ERROR, "zlib support is required to read SWF compressed files\n"); From patchwork Sun Sep 20 11:53:41 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 22528 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 7AB954486BF for ; Sun, 20 Sep 2020 14:54:30 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 5F0E068B83C; Sun, 20 Sep 2020 14:54:30 +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 0C2EE68B7EA for ; Sun, 20 Sep 2020 14:54:22 +0300 (EEST) Received: by mail-wm1-f68.google.com with SMTP id y15so9797825wmi.0 for ; Sun, 20 Sep 2020 04:54:22 -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:reply-to :mime-version:content-transfer-encoding; bh=iOv+lCub093+gSX9JPVY0ivrrvH3KwuHa/S8tN0Cq4w=; b=sq/vodoczCmepwyRDe5svM3WQfDo8LKJiTnS5n794ZYr8hsM1l1JAtDiKL3ufLN+uG IusVYJp5J0niMHk+R8EUk6ElOoGIGlcj8FnFqyID6cMZzlBMUGDLyqM76nL0YJnDGGuc ubOL0mCaSPz/brXH0w6uwLNVinrABD1a/r68Pz9tnvLEUg1+fYMoOuwlvvAKxccfpleq oV1GyD08AZOs2kQY8lc/ExvP8bhBXwzZO6Ryq8XWuY4ePWKSumjXs22ZXFZELy4yUHyz fZza5M4LXBIM2U7/KfNUP54yrA9pYu5n4zpbiD9FGfUXROYWH2rxwjt9Fmt+cLKdr9pF LLbg== 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:reply-to:mime-version:content-transfer-encoding; bh=iOv+lCub093+gSX9JPVY0ivrrvH3KwuHa/S8tN0Cq4w=; b=MVGgu+JJz1UjOpbqXp57EtCnStTSaY3Uqb2kxJUtdLev9s1u1mSp9Trpuw/i7UtbFm GHXA4ThHgR7zzNvcrp7Rva1/xYor9sarytBcseRz7TIQw9trXY8GrfP/Q3qngE37yNTW zk0N59MJDvFMPlHGYcYifskU9sMeeeYJI+koJP/lCtiLSmLNvkAvlqQTzzrbbBJ17BSV qpkN1ZCTIBobVDbCb+tAxmqZh1zIsr0rBAqXoVwh3BZ29EjalulOXmPNKBoeAImcqOJx GOSElInX6Yq41sM3XoFH5DSwc/ia9fFFzybNM4tawJvbwMibPicdoEGCsgztrvXJMMEQ y6vg== X-Gm-Message-State: AOAM531m+0B1ySnYVExKb415gh8eeka8h5g+c650LStRsQRiTyVDGKFv 1Flxh3DH/dqVyTDlrx7DjIluounIM0Y= X-Google-Smtp-Source: ABdhPJyq0vRGY3ERgeE+QvJsUxibEdkqIT7isYflzcxKRHU364uzSPZElQH9/ept2Eg5RJ1ahbchTw== X-Received: by 2002:a1c:7418:: with SMTP id p24mr25022997wmc.123.1600602861010; Sun, 20 Sep 2020 04:54:21 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc1fb0f.dynamic.kabel-deutschland.de. [188.193.251.15]) by smtp.gmail.com with ESMTPSA id u126sm17057127wmu.9.2020.09.20.04.54.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 20 Sep 2020 04:54:20 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Sun, 20 Sep 2020 13:53:41 +0200 Message-Id: <20200920115341.1812809-3-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200920115341.1812809-1-andreas.rheinhardt@gmail.com> References: <20200920115341.1812809-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 3/3] avformat/swf: Separate mux and demux contexts 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: Andreas Rheinhardt Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" There was almost no overlap between them: The only field used by both was an int named samples_per_frame. Therefore this commit separates them. Signed-off-by: Andreas Rheinhardt --- libavformat/swf.h | 33 --------------------------------- libavformat/swfdec.c | 22 +++++++++++++++++----- libavformat/swfenc.c | 35 ++++++++++++++++++++++++++--------- 3 files changed, 43 insertions(+), 47 deletions(-) diff --git a/libavformat/swf.h b/libavformat/swf.h index d0f0194c3f..b66420c60a 100644 --- a/libavformat/swf.h +++ b/libavformat/swf.h @@ -23,15 +23,6 @@ #ifndef AVFORMAT_SWF_H #define AVFORMAT_SWF_H -#include "config.h" - -#if CONFIG_ZLIB -#include -#endif - -#include "libavutil/fifo.h" -#include "avformat.h" -#include "avio.h" #include "internal.h" /* should have a generic way to indicate probable size */ @@ -113,35 +104,11 @@ enum { #define FLAG_SETFILL0 0x02 #define FLAG_SETFILL1 0x04 -#define AUDIO_FIFO_SIZE 65536 - /* character id used */ #define BITMAP_ID 0 #define VIDEO_ID 0 #define SHAPE_ID 1 -typedef struct SWFContext { - int64_t duration_pos; - int64_t tag_pos; - int64_t vframes_pos; - int samples_per_frame; - int sound_samples; - int swf_frame_number; - int video_frame_number; - int frame_rate; - int tag; - AVFifoBuffer *audio_fifo; - AVCodecParameters *audio_par, *video_par; - AVStream *video_st; -#if CONFIG_ZLIB -#define ZBUF_SIZE 4096 - AVIOContext *zpb; - uint8_t *zbuf_in; - uint8_t *zbuf_out; - z_stream zstream; -#endif -} SWFContext; - extern const AVCodecTag ff_swf_codec_tags[]; #endif /* AVFORMAT_SWF_H */ diff --git a/libavformat/swfdec.c b/libavformat/swfdec.c index d1ed1e2a53..2769a768de 100644 --- a/libavformat/swfdec.c +++ b/libavformat/swfdec.c @@ -34,6 +34,18 @@ #include "libavcodec/get_bits.h" #include "swf.h" +typedef struct SWFDecContext { + int samples_per_frame; + int frame_rate; +#if CONFIG_ZLIB +#define ZBUF_SIZE 4096 + AVIOContext *zpb; + uint8_t *zbuf_in; + uint8_t *zbuf_out; + z_stream zstream; +#endif +} SWFDecContext; + static const AVCodecTag swf_audio_codec_tags[] = { { AV_CODEC_ID_PCM_S16LE, 0x00 }, { AV_CODEC_ID_ADPCM_SWF, 0x01 }, @@ -101,7 +113,7 @@ static int swf_probe(const AVProbeData *p) static int zlib_refill(void *opaque, uint8_t *buf, int buf_size) { AVFormatContext *s = opaque; - SWFContext *swf = s->priv_data; + SWFDecContext *swf = s->priv_data; z_stream *z = &swf->zstream; int ret; @@ -134,7 +146,7 @@ static av_cold int swf_read_close(AVFormatContext *avctx); static int swf_read_header(AVFormatContext *s) { - SWFContext *swf = s->priv_data; + SWFDecContext *swf = s->priv_data; AVIOContext *pb = s->pb; int nbits, len, tag; @@ -203,7 +215,7 @@ static AVStream *create_new_audio_stream(AVFormatContext *s, int id, int info) static int swf_read_packet(AVFormatContext *s, AVPacket *pkt) { - SWFContext *swf = s->priv_data; + SWFDecContext *swf = s->priv_data; AVIOContext *pb = s->pb; AVStream *vst = NULL, *ast = NULL, *st = 0; int tag, len, i, frame, v, res; @@ -526,7 +538,7 @@ bitmap_end_skip: #if CONFIG_ZLIB static av_cold int swf_read_close(AVFormatContext *avctx) { - SWFContext *s = avctx->priv_data; + SWFDecContext *s = avctx->priv_data; inflateEnd(&s->zstream); av_freep(&s->zbuf_in); av_freep(&s->zbuf_out); @@ -538,7 +550,7 @@ static av_cold int swf_read_close(AVFormatContext *avctx) AVInputFormat ff_swf_demuxer = { .name = "swf", .long_name = NULL_IF_CONFIG_SMALL("SWF (ShockWave Flash)"), - .priv_data_size = sizeof(SWFContext), + .priv_data_size = sizeof(SWFDecContext), .read_probe = swf_probe, .read_header = swf_read_header, .read_packet = swf_read_packet, diff --git a/libavformat/swfenc.c b/libavformat/swfenc.c index 750ec56ec1..14be2b72aa 100644 --- a/libavformat/swfenc.c +++ b/libavformat/swfenc.c @@ -22,12 +22,29 @@ #include "libavcodec/put_bits.h" #include "libavutil/avassert.h" +#include "libavutil/fifo.h" #include "avformat.h" #include "swf.h" +#define AUDIO_FIFO_SIZE 65536 + +typedef struct SWFEncContext { + int64_t duration_pos; + int64_t tag_pos; + int64_t vframes_pos; + int samples_per_frame; + int sound_samples; + int swf_frame_number; + int video_frame_number; + int tag; + AVFifoBuffer *audio_fifo; + AVCodecParameters *audio_par, *video_par; + AVStream *video_st; +} SWFEncContext; + static void put_swf_tag(AVFormatContext *s, int tag) { - SWFContext *swf = s->priv_data; + SWFEncContext *swf = s->priv_data; AVIOContext *pb = s->pb; swf->tag_pos = avio_tell(pb); @@ -43,7 +60,7 @@ static void put_swf_tag(AVFormatContext *s, int tag) static void put_swf_end_tag(AVFormatContext *s) { - SWFContext *swf = s->priv_data; + SWFEncContext *swf = s->priv_data; AVIOContext *pb = s->pb; int64_t pos; int tag_len, tag; @@ -173,7 +190,7 @@ static void put_swf_matrix(AVIOContext *pb, static int swf_write_header(AVFormatContext *s) { - SWFContext *swf = s->priv_data; + SWFEncContext *swf = s->priv_data; AVIOContext *pb = s->pb; PutBitContext p; uint8_t buf1[256]; @@ -343,7 +360,7 @@ static int swf_write_header(AVFormatContext *s) static int swf_write_video(AVFormatContext *s, AVCodecParameters *par, const uint8_t *buf, int size) { - SWFContext *swf = s->priv_data; + SWFEncContext *swf = s->priv_data; AVIOContext *pb = s->pb; /* Flash Player limit */ @@ -448,7 +465,7 @@ static int swf_write_video(AVFormatContext *s, static int swf_write_audio(AVFormatContext *s, AVCodecParameters *par, uint8_t *buf, int size) { - SWFContext *swf = s->priv_data; + SWFEncContext *swf = s->priv_data; /* Flash Player limit */ if (swf->swf_frame_number == 16000) @@ -480,7 +497,7 @@ static int swf_write_packet(AVFormatContext *s, AVPacket *pkt) static int swf_write_trailer(AVFormatContext *s) { - SWFContext *swf = s->priv_data; + SWFEncContext *swf = s->priv_data; AVIOContext *pb = s->pb; int file_size; @@ -505,7 +522,7 @@ static int swf_write_trailer(AVFormatContext *s) static void swf_deinit(AVFormatContext *s) { - SWFContext *swf = s->priv_data; + SWFEncContext *swf = s->priv_data; av_fifo_freep(&swf->audio_fifo); } @@ -516,7 +533,7 @@ AVOutputFormat ff_swf_muxer = { .long_name = NULL_IF_CONFIG_SMALL("SWF (ShockWave Flash)"), .mime_type = "application/x-shockwave-flash", .extensions = "swf", - .priv_data_size = sizeof(SWFContext), + .priv_data_size = sizeof(SWFEncContext), .audio_codec = AV_CODEC_ID_MP3, .video_codec = AV_CODEC_ID_FLV1, .write_header = swf_write_header, @@ -531,7 +548,7 @@ AVOutputFormat ff_avm2_muxer = { .name = "avm2", .long_name = NULL_IF_CONFIG_SMALL("SWF (ShockWave Flash) (AVM2)"), .mime_type = "application/x-shockwave-flash", - .priv_data_size = sizeof(SWFContext), + .priv_data_size = sizeof(SWFEncContext), .audio_codec = AV_CODEC_ID_MP3, .video_codec = AV_CODEC_ID_FLV1, .write_header = swf_write_header,