[6/7] rtpdec_h264: Replace sizeof(start_sequence) with a macro

Message ID 1336217626-67994-6-git-send-email-martin@martin.st
State Deferred
Headers show

Commit Message

Martin Storsjö May 5, 2012, 11:33 a.m.
This makes the code slightly more readable at places where this
is used a lot, although I guess this is very subjective.
---
Already OK'd by Luca.

 libavformat/rtpdec_h264.c |   31 ++++++++++++++++---------------
 1 file changed, 16 insertions(+), 15 deletions(-)

Comments

Diego Biurrun May 5, 2012, 2:45 p.m. | #1
On Sat, May 05, 2012 at 02:33:45PM +0300, 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.
> ---
> Already OK'd by Luca.

This does admittedly feel a bit silly to me, but if you prefer it..

Diego
Martin Storsjö May 5, 2012, 5:44 p.m. | #2
On Sat, 5 May 2012, Diego Biurrun wrote:

> On Sat, May 05, 2012 at 02:33:45PM +0300, 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.
>> ---
>> Already OK'd by Luca.
>
> This does admittedly feel a bit silly to me, but if you prefer it..

Pushed the other ones (including your version of the cosmetic cleanup), 
leaving out this one for now since I'm not sure it's really any better, 
and the unreadable code blocks probably can be fixed in other ways 
instead.

// Martin

Patch

diff --git a/libavformat/rtpdec_h264.c b/libavformat/rtpdec_h264.c
index ae6104f..4e47cf9 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);