diff mbox series

[FFmpeg-devel,3/3] avformat/swf: Separate mux and demux contexts

Message ID 20200920115341.1812809-3-andreas.rheinhardt@gmail.com
State Accepted
Commit 913aa4204a2a2e0f3588f628441bf8d6edc12db7
Headers show
Series [FFmpeg-devel,1/3] avformat/swfdec: Fix memleaks on error
Related show

Checks

Context Check Description
andriy/default pending
andriy/make success Make finished
andriy/make_fate success Make fate finished

Commit Message

Andreas Rheinhardt Sept. 20, 2020, 11:53 a.m. UTC
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 <andreas.rheinhardt@gmail.com>
---
 libavformat/swf.h    | 33 ---------------------------------
 libavformat/swfdec.c | 22 +++++++++++++++++-----
 libavformat/swfenc.c | 35 ++++++++++++++++++++++++++---------
 3 files changed, 43 insertions(+), 47 deletions(-)

Comments

Michael Niedermayer Sept. 20, 2020, 3:21 p.m. UTC | #1
On Sun, Sep 20, 2020 at 01:53:41PM +0200, Andreas Rheinhardt wrote:
> 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 <andreas.rheinhardt@gmail.com>
> ---
>  libavformat/swf.h    | 33 ---------------------------------
>  libavformat/swfdec.c | 22 +++++++++++++++++-----
>  libavformat/swfenc.c | 35 ++++++++++++++++++++++++++---------
>  3 files changed, 43 insertions(+), 47 deletions(-)

LGTM

thx

[...]
diff mbox series

Patch

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 <zlib.h>
-#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,