[07/13] rtpdec_h264: Generalize parse_sprop_parameter_sets

Message ID 1424378051-6607-7-git-send-email-martin@martin.st
State Committed
Commit 48183b3ad45c95e386a4cb02e1a68b53e6835ac5
Headers show

Commit Message

Martin Storsjö Feb. 19, 2015, 8:34 p.m.
Don't write directly into an AVCodecContext, write into given
pointers.
---
 libavformat/rtpdec_h264.c | 26 ++++++++++++++------------
 1 file changed, 14 insertions(+), 12 deletions(-)

Comments

Luca Barbato Feb. 21, 2015, 12:24 a.m. | #1
On 19/02/15 21:34, Martin Storsjö wrote:
> Don't write directly into an AVCodecContext, write into given
> pointers.
> ---
>   libavformat/rtpdec_h264.c | 26 ++++++++++++++------------
>   1 file changed, 14 insertions(+), 12 deletions(-)
>

Ok.

Patch

diff --git a/libavformat/rtpdec_h264.c b/libavformat/rtpdec_h264.c
index 277b3cd..bc563f2 100644
--- a/libavformat/rtpdec_h264.c
+++ b/libavformat/rtpdec_h264.c
@@ -93,7 +93,7 @@  static void parse_profile_level_id(AVFormatContext *s,
 }
 
 static int parse_sprop_parameter_sets(AVFormatContext *s,
-                                      AVCodecContext *codec,
+                                      uint8_t **data_ptr, int *size_ptr,
                                       const char *value)
 {
     char base64packet[1024];
@@ -115,31 +115,28 @@  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_realloc(codec->extradata,
+            uint8_t *dest = av_realloc(*data_ptr,
                                        packet_size + sizeof(start_sequence) +
-                                       codec->extradata_size +
+                                       *size_ptr +
                                        FF_INPUT_BUFFER_PADDING_SIZE);
             if (!dest) {
                 av_log(s, AV_LOG_ERROR,
                        "Unable to allocate memory for extradata!\n");
                 return AVERROR(ENOMEM);
             }
-            codec->extradata = dest;
+            *data_ptr = dest;
 
-            memcpy(dest + codec->extradata_size, start_sequence,
+            memcpy(dest + *size_ptr, start_sequence,
                    sizeof(start_sequence));
-            memcpy(dest + codec->extradata_size + sizeof(start_sequence),
+            memcpy(dest + *size_ptr + sizeof(start_sequence),
                    decoded_packet, packet_size);
-            memset(dest + codec->extradata_size + sizeof(start_sequence) +
+            memset(dest + *size_ptr + sizeof(start_sequence) +
                    packet_size, 0, FF_INPUT_BUFFER_PADDING_SIZE);
 
-            codec->extradata_size += sizeof(start_sequence) + packet_size;
+            *size_ptr += sizeof(start_sequence) + packet_size;
         }
     }
 
-    av_log(s, AV_LOG_DEBUG, "Extradata set to %p (size: %d)\n",
-           codec->extradata, codec->extradata_size);
-
     return 0;
 }
 
@@ -167,9 +164,14 @@  static int sdp_parse_fmtp_config_h264(AVFormatContext *s,
         if (strlen(value) == 6)
             parse_profile_level_id(s, h264_data, value);
     } else if (!strcmp(attr, "sprop-parameter-sets")) {
+        int ret;
         codec->extradata_size = 0;
         av_freep(&codec->extradata);
-        return parse_sprop_parameter_sets(s, codec, value);
+        ret = parse_sprop_parameter_sets(s, &codec->extradata,
+                                         &codec->extradata_size, value);
+        av_log(s, AV_LOG_DEBUG, "Extradata set to %p (size: %d)\n",
+               codec->extradata, codec->extradata_size);
+        return ret;
     }
     return 0;
 }