Mercurial > libavformat.hg
comparison mmst.c @ 6317:c166e5ff20b9 libavformat
Use inverse error branches, i.e. instead of if(something){success} else {error},
use if(!something) {return error;} success;, which needs less indenting.
author | rbultje |
---|---|
date | Mon, 26 Jul 2010 22:22:20 +0000 |
parents | 270f6c8aeac5 |
children | 1c7e9dfdefe3 |
comparison
equal
deleted
inserted
replaced
6316:270f6c8aeac5 | 6317:c166e5ff20b9 |
---|---|
265 { | 265 { |
266 int read_result; | 266 int read_result; |
267 MMSSCPacketType packet_type= -1; | 267 MMSSCPacketType packet_type= -1; |
268 | 268 |
269 for(;;) { | 269 for(;;) { |
270 if((read_result= url_read_complete(mms->mms_hd, mms->in_buffer, 8))==8) { | 270 read_result = url_read_complete(mms->mms_hd, mms->in_buffer, 8); |
271 if (read_result != 8) { | |
272 if(read_result < 0) { | |
273 av_log(NULL, AV_LOG_ERROR, | |
274 "Error reading packet header: %d (%s)\n", | |
275 read_result, strerror(read_result)); | |
276 packet_type = SC_PKT_CANCEL; | |
277 } else { | |
278 av_log(NULL, AV_LOG_ERROR, | |
279 "The server closed the connection\n"); | |
280 packet_type = SC_PKT_NO_DATA; | |
281 } | |
282 return packet_type; | |
283 } | |
284 | |
271 // handle command packet. | 285 // handle command packet. |
272 if(AV_RL32(mms->in_buffer + 4)==0xb00bface) { | 286 if(AV_RL32(mms->in_buffer + 4)==0xb00bface) { |
287 int length_remaining, hr; | |
288 | |
273 mms->incoming_flags= mms->in_buffer[3]; | 289 mms->incoming_flags= mms->in_buffer[3]; |
274 read_result= url_read_complete(mms->mms_hd, mms->in_buffer+8, 4); | 290 read_result= url_read_complete(mms->mms_hd, mms->in_buffer+8, 4); |
275 if(read_result == 4) { | 291 if(read_result != 4) { |
276 int length_remaining= AV_RL32(mms->in_buffer+8) + 4; | 292 av_log(NULL, AV_LOG_ERROR, |
277 int hr; | 293 "Reading command packet length failed: %d (%s)\n", |
278 | 294 read_result, |
295 read_result < 0 ? strerror(read_result) : | |
296 "The server closed the connection"); | |
297 return read_result < 0 ? read_result : AVERROR_IO; | |
298 } | |
299 | |
300 length_remaining= AV_RL32(mms->in_buffer+8) + 4; | |
279 dprintf(NULL, "Length remaining is %d\n", length_remaining); | 301 dprintf(NULL, "Length remaining is %d\n", length_remaining); |
280 // read the rest of the packet. | 302 // read the rest of the packet. |
281 if (length_remaining < 0 | 303 if (length_remaining < 0 |
282 || length_remaining > sizeof(mms->in_buffer) - 12) { | 304 || length_remaining > sizeof(mms->in_buffer) - 12) { |
283 av_log(NULL, AV_LOG_ERROR, | 305 av_log(NULL, AV_LOG_ERROR, |
285 length_remaining, sizeof(mms->in_buffer) - 12); | 307 length_remaining, sizeof(mms->in_buffer) - 12); |
286 return AVERROR_INVALIDDATA; | 308 return AVERROR_INVALIDDATA; |
287 } | 309 } |
288 read_result = url_read_complete(mms->mms_hd, mms->in_buffer + 12, | 310 read_result = url_read_complete(mms->mms_hd, mms->in_buffer + 12, |
289 length_remaining) ; | 311 length_remaining) ; |
290 if (read_result == length_remaining) { | 312 if (read_result != length_remaining) { |
291 packet_type= AV_RL16(mms->in_buffer+36); | |
292 } else { | |
293 av_log(NULL, AV_LOG_ERROR, | 313 av_log(NULL, AV_LOG_ERROR, |
294 "Reading pkt data (length=%d) failed: %d (%s)\n", | 314 "Reading pkt data (length=%d) failed: %d (%s)\n", |
295 length_remaining, read_result, | 315 length_remaining, read_result, |
296 read_result < 0 ? strerror(read_result) : | 316 read_result < 0 ? strerror(read_result) : |
297 "The server closed the connection"); | 317 "The server closed the connection"); |
298 return read_result < 0 ? read_result : AVERROR_IO; | 318 return read_result < 0 ? read_result : AVERROR_IO; |
299 } | 319 } |
320 packet_type= AV_RL16(mms->in_buffer+36); | |
300 hr = AV_RL32(mms->in_buffer + 40); | 321 hr = AV_RL32(mms->in_buffer + 40); |
301 if (hr) { | 322 if (hr) { |
302 av_log(NULL, AV_LOG_ERROR, | 323 av_log(NULL, AV_LOG_ERROR, |
303 "Server sent an error status code: 0x%08x\n", | 324 "Server sent an error status code: 0x%08x\n", |
304 hr); | 325 hr); |
305 return AVERROR_UNKNOWN; | 326 return AVERROR_UNKNOWN; |
306 } | 327 } |
307 } else { | |
308 av_log(NULL, AV_LOG_ERROR, | |
309 "Reading command packet length failed: %d (%s)\n", | |
310 read_result, | |
311 read_result < 0 ? strerror(read_result) : | |
312 "The server closed the connection"); | |
313 return read_result < 0 ? read_result : AVERROR_IO; | |
314 } | |
315 } else { | 328 } else { |
316 int length_remaining; | 329 int length_remaining; |
317 int packet_id_type; | 330 int packet_id_type; |
318 int tmp; | 331 int tmp; |
319 | 332 |
340 "Failed to read packet data of size %d: %d (%s)\n", | 353 "Failed to read packet data of size %d: %d (%s)\n", |
341 length_remaining, read_result, | 354 length_remaining, read_result, |
342 read_result < 0 ? strerror(read_result) : | 355 read_result < 0 ? strerror(read_result) : |
343 "The server closed the connection"); | 356 "The server closed the connection"); |
344 return read_result < 0 ? read_result : AVERROR_IO; | 357 return read_result < 0 ? read_result : AVERROR_IO; |
345 } else { | 358 } |
359 | |
346 // if we successfully read everything. | 360 // if we successfully read everything. |
347 if(packet_id_type == mms->header_packet_id) { | 361 if(packet_id_type == mms->header_packet_id) { |
348 packet_type = SC_PKT_ASF_HEADER; | 362 packet_type = SC_PKT_ASF_HEADER; |
349 // Store the asf header | 363 // Store the asf header |
350 if(!mms->header_parsed) { | 364 if(!mms->header_parsed) { |
368 packet_type = SC_PKT_ASF_MEDIA; | 382 packet_type = SC_PKT_ASF_MEDIA; |
369 } else { | 383 } else { |
370 dprintf(NULL, "packet id type %d is old.", packet_id_type); | 384 dprintf(NULL, "packet id type %d is old.", packet_id_type); |
371 continue; | 385 continue; |
372 } | 386 } |
373 } | |
374 } | 387 } |
375 | 388 |
376 // preprocess some packet type | 389 // preprocess some packet type |
377 if(packet_type == SC_PKT_KEEPALIVE) { | 390 if(packet_type == SC_PKT_KEEPALIVE) { |
378 send_keepalive_packet(mms); | 391 send_keepalive_packet(mms); |
381 handle_packet_stream_changing_type(mms); | 394 handle_packet_stream_changing_type(mms); |
382 } else if(packet_type == SC_PKT_ASF_MEDIA) { | 395 } else if(packet_type == SC_PKT_ASF_MEDIA) { |
383 pad_media_packet(mms); | 396 pad_media_packet(mms); |
384 } | 397 } |
385 return packet_type; | 398 return packet_type; |
386 } else { | |
387 if(read_result<0) { | |
388 av_log(NULL, AV_LOG_ERROR, | |
389 "Error reading packet header: %d (%s)\n", | |
390 read_result, strerror(read_result)); | |
391 packet_type = SC_PKT_CANCEL; | |
392 } else { | |
393 av_log(NULL, AV_LOG_ERROR, | |
394 "The server closed the connection\n"); | |
395 packet_type = SC_PKT_NO_DATA; | |
396 } | |
397 return packet_type; | |
398 } | |
399 } | 399 } |
400 } | 400 } |
401 | 401 |
402 static int mms_safe_send_recv(MMSContext *mms, | 402 static int mms_safe_send_recv(MMSContext *mms, |
403 int (*send_fun)(MMSContext *mms), | 403 int (*send_fun)(MMSContext *mms), |