Browse code

rtpdec_h264: Cosmetic cleanup

Add/fix spacing, split long lines, align assignments where suitable.

Signed-off-by: Diego Biurrun <diego@biurrun.de>
Signed-off-by: Martin Storsjö <martin@martin.st>

Martin Storsjö authored on 2012/05/05 23:42:15
Showing 1 changed files
... ...
@@ -57,8 +57,8 @@ struct PayloadContext {
57 57
 #endif
58 58
 };
59 59
 
60
-static int sdp_parse_fmtp_config_h264(AVStream * stream,
61
-                                      PayloadContext * h264_data,
60
+static int sdp_parse_fmtp_config_h264(AVStream *stream,
61
+                                      PayloadContext *h264_data,
62 62
                                       char *attr, char *value)
63 63
 {
64 64
     AVCodecContext *codec = stream->codec;
... ...
@@ -86,24 +86,28 @@ static int sdp_parse_fmtp_config_h264(AVStream * stream,
86 86
             uint8_t profile_iop;
87 87
             uint8_t level_idc;
88 88
 
89
-            buffer[0] = value[0]; buffer[1] = value[1]; buffer[2] = '\0';
89
+            buffer[0]   = value[0];
90
+            buffer[1]   = value[1];
91
+            buffer[2]   = '\0';
90 92
             profile_idc = strtol(buffer, NULL, 16);
91
-            buffer[0] = value[2]; buffer[1] = value[3];
93
+            buffer[0]   = value[2];
94
+            buffer[1]   = value[3];
92 95
             profile_iop = strtol(buffer, NULL, 16);
93
-            buffer[0] = value[4]; buffer[1] = value[5];
94
-            level_idc = strtol(buffer, NULL, 16);
96
+            buffer[0]   = value[4];
97
+            buffer[1]   = value[5];
98
+            level_idc   = strtol(buffer, NULL, 16);
95 99
 
96 100
             av_log(codec, AV_LOG_DEBUG,
97 101
                    "RTP Profile IDC: %x Profile IOP: %x Level: %x\n",
98 102
                    profile_idc, profile_iop, level_idc);
99 103
             h264_data->profile_idc = profile_idc;
100 104
             h264_data->profile_iop = profile_iop;
101
-            h264_data->level_idc = level_idc;
105
+            h264_data->level_idc   = level_idc;
102 106
         }
103
-    } else  if (!strcmp(attr, "sprop-parameter-sets")) {
107
+    } else if (!strcmp(attr, "sprop-parameter-sets")) {
104 108
         uint8_t start_sequence[] = { 0, 0, 0, 1 };
105
-        codec->extradata_size= 0;
106
-        codec->extradata= NULL;
109
+        codec->extradata_size = 0;
110
+        codec->extradata      = NULL;
107 111
 
108 112
         while (*value) {
109 113
             char base64packet[1024];
... ...
@@ -120,49 +124,48 @@ static int sdp_parse_fmtp_config_h264(AVStream * stream,
120 120
             if (*value == ',')
121 121
                 value++;
122 122
 
123
-            packet_size= av_base64_decode(decoded_packet, base64packet, sizeof(decoded_packet));
123
+            packet_size = av_base64_decode(decoded_packet, base64packet,
124
+                                           sizeof(decoded_packet));
124 125
             if (packet_size > 0) {
125 126
                 uint8_t *dest = av_malloc(packet_size + sizeof(start_sequence) +
126
-                                         codec->extradata_size +
127
-                                         FF_INPUT_BUFFER_PADDING_SIZE);
128
-                if(dest)
129
-                {
130
-                    if(codec->extradata_size)
131
-                    {
127
+                                          codec->extradata_size +
128
+                                          FF_INPUT_BUFFER_PADDING_SIZE);
129
+                if (dest) {
130
+                    if (codec->extradata_size) {
132 131
                         memcpy(dest, codec->extradata, codec->extradata_size);
133 132
                         av_free(codec->extradata);
134 133
                     }
135 134
 
136
-                    memcpy(dest+codec->extradata_size, start_sequence, sizeof(start_sequence));
137
-                    memcpy(dest+codec->extradata_size+sizeof(start_sequence), decoded_packet, packet_size);
138
-                    memset(dest+codec->extradata_size+sizeof(start_sequence)+
135
+                    memcpy(dest + codec->extradata_size, start_sequence,
136
+                           sizeof(start_sequence));
137
+                    memcpy(dest + codec->extradata_size + sizeof(start_sequence),
138
+                           decoded_packet, packet_size);
139
+                    memset(dest + codec->extradata_size + sizeof(start_sequence) +
139 140
                            packet_size, 0, FF_INPUT_BUFFER_PADDING_SIZE);
140 141
 
141
-                    codec->extradata= dest;
142
-                    codec->extradata_size+= sizeof(start_sequence)+packet_size;
142
+                    codec->extradata       = dest;
143
+                    codec->extradata_size += sizeof(start_sequence) + packet_size;
143 144
                 } else {
144
-                    av_log(codec, AV_LOG_ERROR, "Unable to allocate memory for extradata!");
145
+                    av_log(codec, AV_LOG_ERROR,
146
+                           "Unable to allocate memory for extradata!");
145 147
                     return AVERROR(ENOMEM);
146 148
                 }
147 149
             }
148 150
         }
149
-        av_log(codec, AV_LOG_DEBUG, "Extradata set to %p (size: %d)!", codec->extradata, codec->extradata_size);
151
+        av_log(codec, AV_LOG_DEBUG, "Extradata set to %p (size: %d)!",
152
+               codec->extradata, codec->extradata_size);
150 153
     }
151 154
     return 0;
152 155
 }
153 156
 
154 157
 // return 0 on packet, no more left, 1 on packet, 1 on partial packet
155
-static int h264_handle_packet(AVFormatContext *ctx,
156
-                              PayloadContext *data,
157
-                              AVStream *st,
158
-                              AVPacket * pkt,
159
-                              uint32_t * timestamp,
160
-                              const uint8_t * buf,
161
-                              int len, int flags)
158
+static int h264_handle_packet(AVFormatContext *ctx, PayloadContext *data,
159
+                              AVStream *st, AVPacket *pkt, uint32_t *timestamp,
160
+                              const uint8_t *buf, int len, int flags)
162 161
 {
163 162
     uint8_t nal;
164 163
     uint8_t type;
165
-    int result= 0;
164
+    int result = 0;
166 165
     uint8_t start_sequence[] = { 0, 0, 0, 1 };
167 166
 
168 167
     if (!len) {
... ...
@@ -182,9 +185,9 @@ static int h264_handle_packet(AVFormatContext *ctx,
182 182
     switch (type) {
183 183
     case 0:                    // undefined, but pass them through
184 184
     case 1:
185
-        av_new_packet(pkt, len+sizeof(start_sequence));
185
+        av_new_packet(pkt, len + sizeof(start_sequence));
186 186
         memcpy(pkt->data, start_sequence, sizeof(start_sequence));
187
-        memcpy(pkt->data+sizeof(start_sequence), buf, len);
187
+        memcpy(pkt->data + sizeof(start_sequence), buf, len);
188 188
 #ifdef DEBUG
189 189
         data->packet_types_received[nal & 0x1f]++;
190 190
 #endif
... ...
@@ -196,35 +199,35 @@ static int h264_handle_packet(AVFormatContext *ctx,
196 196
         len--;
197 197
         // first we are going to figure out the total size
198 198
         {
199
-            int pass= 0;
200
-            int total_length= 0;
201
-            uint8_t *dst= NULL;
199
+            int pass         = 0;
200
+            int total_length = 0;
201
+            uint8_t *dst     = NULL;
202 202
 
203
-            for(pass= 0; pass<2; pass++) {
204
-                const uint8_t *src= buf;
205
-                int src_len= len;
203
+            for (pass = 0; pass < 2; pass++) {
204
+                const uint8_t *src = buf;
205
+                int src_len        = len;
206 206
 
207 207
                 while (src_len > 2) {
208 208
                     uint16_t nal_size = AV_RB16(src);
209 209
 
210 210
                     // consume the length of the aggregate
211
-                    src += 2;
211
+                    src     += 2;
212 212
                     src_len -= 2;
213 213
 
214 214
                     if (nal_size <= src_len) {
215
-                        if(pass==0) {
215
+                        if (pass == 0) {
216 216
                             // counting
217
-                            total_length+= sizeof(start_sequence)+nal_size;
217
+                            total_length += sizeof(start_sequence) + nal_size;
218 218
                         } else {
219 219
                             // copying
220 220
                             assert(dst);
221 221
                             memcpy(dst, start_sequence, sizeof(start_sequence));
222
-                            dst+= sizeof(start_sequence);
222
+                            dst += sizeof(start_sequence);
223 223
                             memcpy(dst, src, nal_size);
224 224
 #ifdef DEBUG
225 225
                             data->packet_types_received[*src & 0x1f]++;
226 226
 #endif
227
-                            dst+= nal_size;
227
+                            dst += nal_size;
228 228
                         }
229 229
                     } else {
230 230
                         av_log(ctx, AV_LOG_ERROR,
... ...
@@ -232,7 +235,7 @@ static int h264_handle_packet(AVFormatContext *ctx,
232 232
                     }
233 233
 
234 234
                     // eat what we handled
235
-                    src += nal_size;
235
+                    src     += nal_size;
236 236
                     src_len -= nal_size;
237 237
 
238 238
                     if (src_len < 0)
... ...
@@ -240,13 +243,13 @@ static int h264_handle_packet(AVFormatContext *ctx,
240 240
                                "Consumed more bytes than we got! (%d)\n", src_len);
241 241
                 }
242 242
 
243
-                if(pass==0) {
243
+                if (pass == 0) {
244 244
                     /* now we know the total size of the packet (with the
245 245
                      * start sequences added) */
246 246
                     av_new_packet(pkt, total_length);
247
-                    dst= pkt->data;
247
+                    dst = pkt->data;
248 248
                 } else {
249
-                    assert(dst-pkt->data==total_length);
249
+                    assert(dst - pkt->data == total_length);
250 250
                 }
251 251
             }
252 252
         }
... ...
@@ -267,17 +270,17 @@ static int h264_handle_packet(AVFormatContext *ctx,
267 267
         len--;                 // skip the fu_indicator
268 268
         if (len > 1) {
269 269
             // these are the same as above, we just redo them here for clarity
270
-            uint8_t fu_indicator = nal;
271
-            uint8_t fu_header = *buf;
272
-            uint8_t start_bit = fu_header >> 7;
270
+            uint8_t fu_indicator      = nal;
271
+            uint8_t fu_header         = *buf;
272
+            uint8_t start_bit         = fu_header >> 7;
273 273
             uint8_t av_unused end_bit = (fu_header & 0x40) >> 6;
274
-            uint8_t nal_type = (fu_header & 0x1f);
274
+            uint8_t nal_type          = fu_header & 0x1f;
275 275
             uint8_t reconstructed_nal;
276 276
 
277 277
             // Reconstruct this packet's true nal; only the data follows.
278 278
             /* The original nal forbidden bit and NRI are stored in this
279 279
              * packet's nal. */
280
-            reconstructed_nal = fu_indicator & (0xe0);
280
+            reconstructed_nal  = fu_indicator & 0xe0;
281 281
             reconstructed_nal |= nal_type;
282 282
 
283 283
             // skip the fu_header
... ...
@@ -288,12 +291,12 @@ static int h264_handle_packet(AVFormatContext *ctx,
288 288
             if (start_bit)
289 289
                 data->packet_types_received[nal_type]++;
290 290
 #endif
291
-            if(start_bit) {
291
+            if (start_bit) {
292 292
                 /* copy in the start sequence, and the reconstructed nal */
293
-                av_new_packet(pkt, sizeof(start_sequence)+sizeof(nal)+len);
293
+                av_new_packet(pkt, sizeof(start_sequence) + sizeof(nal) + len);
294 294
                 memcpy(pkt->data, start_sequence, sizeof(start_sequence));
295
-                pkt->data[sizeof(start_sequence)]= reconstructed_nal;
296
-                memcpy(pkt->data+sizeof(start_sequence)+sizeof(nal), buf, len);
295
+                pkt->data[sizeof(start_sequence)] = reconstructed_nal;
296
+                memcpy(pkt->data + sizeof(start_sequence) + sizeof(nal), buf, len);
297 297
             } else {
298 298
                 av_new_packet(pkt, len);
299 299
                 memcpy(pkt->data, buf, len);
... ...
@@ -348,25 +351,27 @@ static int parse_h264_sdp_line(AVFormatContext *s, int st_index,
348 348
         return 0;
349 349
 
350 350
     stream = s->streams[st_index];
351
-    codec = stream->codec;
351
+    codec  = stream->codec;
352 352
 
353 353
     if (av_strstart(p, "framesize:", &p)) {
354 354
         char buf1[50];
355 355
         char *dst = buf1;
356 356
 
357 357
         // remove the protocol identifier
358
-        while (*p && *p == ' ') p++; // strip spaces.
359
-        while (*p && *p != ' ') p++; // eat protocol identifier
360
-        while (*p && *p == ' ') p++; // strip trailing spaces.
361
-        while (*p && *p != '-' && (dst - buf1) < sizeof(buf1) - 1) {
358
+        while (*p && *p == ' ')
359
+            p++;                     // strip spaces.
360
+        while (*p && *p != ' ')
361
+            p++;                     // eat protocol identifier
362
+        while (*p && *p == ' ')
363
+            p++;                     // strip trailing spaces.
364
+        while (*p && *p != '-' && (dst - buf1) < sizeof(buf1) - 1)
362 365
             *dst++ = *p++;
363
-        }
364 366
         *dst = '\0';
365 367
 
366 368
         // a='framesize:96 320-240'
367 369
         // set our parameters
368
-        codec->width = atoi(buf1);
369
-        codec->height = atoi(p + 1); // skip the -
370
+        codec->width   = atoi(buf1);
371
+        codec->height  = atoi(p + 1); // skip the -
370 372
         codec->pix_fmt = PIX_FMT_YUV420P;
371 373
     } else if (av_strstart(p, "fmtp:", &p)) {
372 374
         return ff_parse_fmtp(stream, h264_data, p, sdp_parse_fmtp_config_h264);