[02/13] rtpdec_h264: Use av_realloc instead of av_malloc+mempcy

Message ID 1424378051-6607-2-git-send-email-martin@martin.st
State Committed
Commit 7650caf013f45ebebf128855735a0c6350836ea4
Headers show

Commit Message

Martin Storsjö Feb. 19, 2015, 8:34 p.m.
This is similar to what was done for rtpdec_hevc in ced7238cd01.
---
 libavformat/rtpdec_h264.c | 13 +++++--------
 1 file changed, 5 insertions(+), 8 deletions(-)

Comments

Luca Barbato Feb. 19, 2015, 9:04 p.m. | #1
On 19/02/15 21:34, Martin Storsjö wrote:
> This is similar to what was done for rtpdec_hevc in ced7238cd01.
> ---
>  libavformat/rtpdec_h264.c | 13 +++++--------
>  1 file changed, 5 insertions(+), 8 deletions(-)
> 

Is it safe and expected to have the extradata non-aligned?
Martin Storsjö Feb. 19, 2015, 9:24 p.m. | #2
On Thu, 19 Feb 2015, Luca Barbato wrote:

> On 19/02/15 21:34, Martin Storsjö wrote:
>> This is similar to what was done for rtpdec_hevc in ced7238cd01.
>> ---
>>  libavformat/rtpdec_h264.c | 13 +++++--------
>>  1 file changed, 5 insertions(+), 8 deletions(-)
>>
>
> Is it safe and expected to have the extradata non-aligned?

Hmm, good point - I'm not sure if we have any strict requirements about 
that. But just in case, I can keep it as is, I don't think this one is 
critical for the rest of the set.

// Martin
Luca Barbato Feb. 20, 2015, 12:04 a.m. | #3
On 19/02/15 22:24, Martin Storsjö wrote:
> On Thu, 19 Feb 2015, Luca Barbato wrote:
> 
>> On 19/02/15 21:34, Martin Storsjö wrote:
>>> This is similar to what was done for rtpdec_hevc in ced7238cd01.
>>> ---
>>>  libavformat/rtpdec_h264.c | 13 +++++--------
>>>  1 file changed, 5 insertions(+), 8 deletions(-)
>>>
>>
>> Is it safe and expected to have the extradata non-aligned?
> 
> Hmm, good point - I'm not sure if we have any strict requirements about
> that. But just in case, I can keep it as is, I don't think this one is
> critical for the rest of the set.
> 
> // Martin
> _______________________________________________
> libav-devel mailing list
> libav-devel@libav.org
> https://lists.libav.org/mailman/listinfo/libav-devel

Thanks.
Anton Khirnov Feb. 20, 2015, 6:40 a.m. | #4
Quoting Luca Barbato (2015-02-19 22:04:24)
> On 19/02/15 21:34, Martin Storsjö wrote:
> > This is similar to what was done for rtpdec_hevc in ced7238cd01.
> > ---
> >  libavformat/rtpdec_h264.c | 13 +++++--------
> >  1 file changed, 5 insertions(+), 8 deletions(-)
> > 
> 
> Is it safe and expected to have the extradata non-aligned?

Extradata follows the same rules as packet data, and those don't have to
be aligned.
Martin Storsjö Feb. 20, 2015, 10:14 a.m. | #5
On Fri, 20 Feb 2015, Anton Khirnov wrote:

> Quoting Luca Barbato (2015-02-19 22:04:24)
>> On 19/02/15 21:34, Martin Storsjö wrote:
>> > This is similar to what was done for rtpdec_hevc in ced7238cd01.
>> > ---
>> >  libavformat/rtpdec_h264.c | 13 +++++--------
>> >  1 file changed, 5 insertions(+), 8 deletions(-)
>> > 
>> 
>> Is it safe and expected to have the extradata non-aligned?
>
> Extradata follows the same rules as packet data, and those don't have to
> be aligned.

Ok then - thus I consider this patch accepted.

// Martin

Patch

diff --git a/libavformat/rtpdec_h264.c b/libavformat/rtpdec_h264.c
index 7abfde7..d24fa32 100644
--- a/libavformat/rtpdec_h264.c
+++ b/libavformat/rtpdec_h264.c
@@ -115,18 +115,16 @@  static int parse_sprop_parameter_sets(AVFormatContext *s,
         packet_size = av_base64_decode(decoded_packet, base64packet,
                                        sizeof(decoded_packet));
         if (packet_size > 0) {
-            uint8_t *dest = av_malloc(packet_size + sizeof(start_sequence) +
-                                      codec->extradata_size +
-                                      FF_INPUT_BUFFER_PADDING_SIZE);
+            uint8_t *dest = av_realloc(codec->extradata,
+                                       packet_size + sizeof(start_sequence) +
+                                       codec->extradata_size +
+                                       FF_INPUT_BUFFER_PADDING_SIZE);
             if (!dest) {
                 av_log(s, AV_LOG_ERROR,
                        "Unable to allocate memory for extradata!\n");
                 return AVERROR(ENOMEM);
             }
-            if (codec->extradata_size) {
-                memcpy(dest, codec->extradata, codec->extradata_size);
-                av_free(codec->extradata);
-            }
+            codec->extradata = dest;
 
             memcpy(dest + codec->extradata_size, start_sequence,
                    sizeof(start_sequence));
@@ -135,7 +133,6 @@  static int parse_sprop_parameter_sets(AVFormatContext *s,
             memset(dest + codec->extradata_size + sizeof(start_sequence) +
                    packet_size, 0, FF_INPUT_BUFFER_PADDING_SIZE);
 
-            codec->extradata       = dest;
             codec->extradata_size += sizeof(start_sequence) + packet_size;
         }
     }