diff mbox series

[FFmpeg-devel,09/17] avformat/mxfenc: Avoid allocation for timecode track

Message ID AM7PR03MB666081228D8FD707E6B8B7B38F929@AM7PR03MB6660.eurprd03.prod.outlook.com
State Accepted
Commit bb69b734c74cc22301a4fa2c3263077ffe7064b1
Headers show
Series [FFmpeg-devel,01/17] avformat/mxfenc: Auto-insert h264_mp4toannexb BSF if needed | expand

Checks

Context Check Description
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished
andriy/make_ppc success Make finished
andriy/make_fate_ppc success Make fate finished

Commit Message

Andreas Rheinhardt Nov. 9, 2021, 6:01 p.m. UTC
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
 libavformat/mxfenc.c | 10 +++-------
 1 file changed, 3 insertions(+), 7 deletions(-)

Comments

Tomas Härdin Nov. 9, 2021, 9:26 p.m. UTC | #1
tis 2021-11-09 klockan 19:01 +0100 skrev Andreas Rheinhardt:
> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
> ---
>  libavformat/mxfenc.c | 10 +++-------
>  1 file changed, 3 insertions(+), 7 deletions(-)
> 
> diff --git a/libavformat/mxfenc.c b/libavformat/mxfenc.c
> index cf63340313..aa9857fcff 100644
> --- a/libavformat/mxfenc.c
> +++ b/libavformat/mxfenc.c
> @@ -421,6 +421,7 @@ typedef struct MXFContext {
>      int track_instance_count; // used to generate MXFTrack uuids
>      int cbr_index;           ///< use a constant bitrate index
>      uint8_t unused_tags[MXF_NUM_TAGS];  ///< local tags that we know
> will not be used
> +    MXFStreamContext timecode_track_priv;
>  } MXFContext;
>  
>  static void mxf_write_uuid(AVIOContext *pb, enum MXFMetadataSetType
> type, int value)
> @@ -2712,9 +2713,7 @@ static int mxf_init(AVFormatContext *s)
>      mxf->timecode_track = av_mallocz(sizeof(*mxf->timecode_track));
>      if (!mxf->timecode_track)
>          return AVERROR(ENOMEM);
> -    mxf->timecode_track->priv_data =
> av_mallocz(sizeof(MXFStreamContext));
> -    if (!mxf->timecode_track->priv_data)
> -        return AVERROR(ENOMEM);
> +    mxf->timecode_track->priv_data = &mxf->timecode_track_priv;
>      mxf->timecode_track->index = -1;
>  
>      return 0;
> @@ -3087,10 +3086,7 @@ static void mxf_deinit(AVFormatContext *s)
>  
>      av_freep(&mxf->index_entries);
>      av_freep(&mxf->body_partition_offset);
> -    if (mxf->timecode_track) {
> -        av_freep(&mxf->timecode_track->priv_data);
> -        av_freep(&mxf->timecode_track);
> -    }
> +    av_freep(&mxf->timecode_track);
>  }
>  
>  static int mxf_interleave_get_packet(AVFormatContext *s, AVPacket
> *out, int flush)

Looks OK. We never have more than one timecode track.

/Tomas
Andreas Rheinhardt Nov. 9, 2021, 9:28 p.m. UTC | #2
Tomas Härdin:
> tis 2021-11-09 klockan 19:01 +0100 skrev Andreas Rheinhardt:
>> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
>> ---
>>  libavformat/mxfenc.c | 10 +++-------
>>  1 file changed, 3 insertions(+), 7 deletions(-)
>>
>> diff --git a/libavformat/mxfenc.c b/libavformat/mxfenc.c
>> index cf63340313..aa9857fcff 100644
>> --- a/libavformat/mxfenc.c
>> +++ b/libavformat/mxfenc.c
>> @@ -421,6 +421,7 @@ typedef struct MXFContext {
>>      int track_instance_count; // used to generate MXFTrack uuids
>>      int cbr_index;           ///< use a constant bitrate index
>>      uint8_t unused_tags[MXF_NUM_TAGS];  ///< local tags that we know
>> will not be used
>> +    MXFStreamContext timecode_track_priv;
>>  } MXFContext;
>>  
>>  static void mxf_write_uuid(AVIOContext *pb, enum MXFMetadataSetType
>> type, int value)
>> @@ -2712,9 +2713,7 @@ static int mxf_init(AVFormatContext *s)
>>      mxf->timecode_track = av_mallocz(sizeof(*mxf->timecode_track));
>>      if (!mxf->timecode_track)
>>          return AVERROR(ENOMEM);
>> -    mxf->timecode_track->priv_data =
>> av_mallocz(sizeof(MXFStreamContext));
>> -    if (!mxf->timecode_track->priv_data)
>> -        return AVERROR(ENOMEM);
>> +    mxf->timecode_track->priv_data = &mxf->timecode_track_priv;
>>      mxf->timecode_track->index = -1;
>>  
>>      return 0;
>> @@ -3087,10 +3086,7 @@ static void mxf_deinit(AVFormatContext *s)
>>  
>>      av_freep(&mxf->index_entries);
>>      av_freep(&mxf->body_partition_offset);
>> -    if (mxf->timecode_track) {
>> -        av_freep(&mxf->timecode_track->priv_data);
>> -        av_freep(&mxf->timecode_track);
>> -    }
>> +    av_freep(&mxf->timecode_track);
>>  }
>>  
>>  static int mxf_interleave_get_packet(AVFormatContext *s, AVPacket
>> *out, int flush)
> 
> Looks OK. We never have more than one timecode track.
> 

We also avoid the allocation of the extra AVStream, but somehow it feels
even more of a hack to put it into the context than allocating it,
although it actually isn't any more of a hack.

- Andreas
diff mbox series

Patch

diff --git a/libavformat/mxfenc.c b/libavformat/mxfenc.c
index cf63340313..aa9857fcff 100644
--- a/libavformat/mxfenc.c
+++ b/libavformat/mxfenc.c
@@ -421,6 +421,7 @@  typedef struct MXFContext {
     int track_instance_count; // used to generate MXFTrack uuids
     int cbr_index;           ///< use a constant bitrate index
     uint8_t unused_tags[MXF_NUM_TAGS];  ///< local tags that we know will not be used
+    MXFStreamContext timecode_track_priv;
 } MXFContext;
 
 static void mxf_write_uuid(AVIOContext *pb, enum MXFMetadataSetType type, int value)
@@ -2712,9 +2713,7 @@  static int mxf_init(AVFormatContext *s)
     mxf->timecode_track = av_mallocz(sizeof(*mxf->timecode_track));
     if (!mxf->timecode_track)
         return AVERROR(ENOMEM);
-    mxf->timecode_track->priv_data = av_mallocz(sizeof(MXFStreamContext));
-    if (!mxf->timecode_track->priv_data)
-        return AVERROR(ENOMEM);
+    mxf->timecode_track->priv_data = &mxf->timecode_track_priv;
     mxf->timecode_track->index = -1;
 
     return 0;
@@ -3087,10 +3086,7 @@  static void mxf_deinit(AVFormatContext *s)
 
     av_freep(&mxf->index_entries);
     av_freep(&mxf->body_partition_offset);
-    if (mxf->timecode_track) {
-        av_freep(&mxf->timecode_track->priv_data);
-        av_freep(&mxf->timecode_track);
-    }
+    av_freep(&mxf->timecode_track);
 }
 
 static int mxf_interleave_get_packet(AVFormatContext *s, AVPacket *out, int flush)