[10/11] rtpdec_h264: Replace sizeof(start_sequence) with a macro

Message ID 1336169215-59789-10-git-send-email-martin@martin.st
State Superseded
Headers show

Commit Message

Martin Storsjö May 4, 2012, 10:06 p.m.
This makes the code slightly more readable at places where this
is used a lot, although I guess this is very subjective.
---
 libavformat/rtpdec_h264.c |   31 ++++++++++++++++---------------
 1 file changed, 16 insertions(+), 15 deletions(-)

Comments

Luca Barbato May 5, 2012, 12:01 a.m. | #1
On 04/05/12 15:06, Martin Storsjö wrote:
> This makes the code slightly more readable at places where this
> is used a lot, although I guess this is very subjective.

fine for me.

Patch

diff --git a/libavformat/rtpdec_h264.c b/libavformat/rtpdec_h264.c
index 1021d02..5ff03ee 100644
--- a/libavformat/rtpdec_h264.c
+++ b/libavformat/rtpdec_h264.c
@@ -64,6 +64,7 @@  struct PayloadContext {
 #endif
 
 static const uint8_t start_sequence[] = { 0, 0, 0, 1 };
+#define START_SEQ_SIZE sizeof(start_sequence)
 
 static int sdp_parse_fmtp_config_h264(AVStream *stream,
                                       PayloadContext *h264_data,
@@ -130,7 +131,7 @@  static int sdp_parse_fmtp_config_h264(AVStream *stream,
             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) +
+                uint8_t *dest = av_malloc(packet_size + START_SEQ_SIZE +
                                           codec->extradata_size +
                                           FF_INPUT_BUFFER_PADDING_SIZE);
                 if (dest) {
@@ -140,14 +141,14 @@  static int sdp_parse_fmtp_config_h264(AVStream *stream,
                     }
 
                     memcpy(dest + codec->extradata_size, start_sequence,
-                           sizeof(start_sequence));
-                    memcpy(dest + codec->extradata_size + sizeof(start_sequence),
+                           START_SEQ_SIZE);
+                    memcpy(dest + codec->extradata_size + START_SEQ_SIZE,
                            decoded_packet, packet_size);
-                    memset(dest + codec->extradata_size + sizeof(start_sequence) +
+                    memset(dest + codec->extradata_size + START_SEQ_SIZE +
                            packet_size, 0, FF_INPUT_BUFFER_PADDING_SIZE);
 
                     codec->extradata = dest;
-                    codec->extradata_size += sizeof(start_sequence) + packet_size;
+                    codec->extradata_size += START_SEQ_SIZE + packet_size;
                 } else {
                     av_log(codec, AV_LOG_ERROR,
                            "Unable to allocate memory for extradata!");
@@ -187,9 +188,9 @@  static int h264_handle_packet(AVFormatContext *ctx, PayloadContext *data,
     switch (type) {
     case 0:                    /* undefined, but pass them through */
     case 1:
-        av_new_packet(pkt, len + sizeof(start_sequence));
-        memcpy(pkt->data, start_sequence, sizeof(start_sequence));
-        memcpy(pkt->data + sizeof(start_sequence), buf, len);
+        av_new_packet(pkt, len + START_SEQ_SIZE);
+        memcpy(pkt->data, start_sequence, START_SEQ_SIZE);
+        memcpy(pkt->data + START_SEQ_SIZE, buf, len);
         COUNT_NAL_TYPE(data, nal);
         break;
 
@@ -217,12 +218,12 @@  static int h264_handle_packet(AVFormatContext *ctx, PayloadContext *data,
                     if (nal_size <= src_len) {
                         if (pass == 0) {
                             /* counting */
-                            total_length += sizeof(start_sequence) + nal_size;
+                            total_length += START_SEQ_SIZE + nal_size;
                         } else {
                             /* copying */
                             assert(dst);
-                            memcpy(dst, start_sequence, sizeof(start_sequence));
-                            dst += sizeof(start_sequence);
+                            memcpy(dst, start_sequence, START_SEQ_SIZE);
+                            dst += START_SEQ_SIZE;
                             memcpy(dst, src, nal_size);
                             COUNT_NAL_TYPE(data, *src);
                             dst += nal_size;
@@ -289,10 +290,10 @@  static int h264_handle_packet(AVFormatContext *ctx, PayloadContext *data,
                 COUNT_NAL_TYPE(data, nal_type);
             if (start_bit) {
                 /* copy in the start sequence, and the reconstructed nal */
-                av_new_packet(pkt, sizeof(start_sequence) + sizeof(nal) + len);
-                memcpy(pkt->data, start_sequence, sizeof(start_sequence));
-                pkt->data[sizeof(start_sequence)] = reconstructed_nal;
-                memcpy(pkt->data + sizeof(start_sequence) + sizeof(nal), buf, len);
+                av_new_packet(pkt, START_SEQ_SIZE + sizeof(nal) + len);
+                memcpy(pkt->data, start_sequence, START_SEQ_SIZE);
+                pkt->data[START_SEQ_SIZE] = reconstructed_nal;
+                memcpy(pkt->data + START_SEQ_SIZE + sizeof(nal), buf, len);
             } else {
                 av_new_packet(pkt, len);
                 memcpy(pkt->data, buf, len);