comparison mmst.c @ 6318:1c7e9dfdefe3 libavformat

Reindent after r24516.
author rbultje
date Mon, 26 Jul 2010 22:22:42 +0000
parents c166e5ff20b9
children eff600bc4261
comparison
equal deleted inserted replaced
6317:c166e5ff20b9 6318:1c7e9dfdefe3
280 packet_type = SC_PKT_NO_DATA; 280 packet_type = SC_PKT_NO_DATA;
281 } 281 }
282 return packet_type; 282 return packet_type;
283 } 283 }
284 284
285 // handle command packet. 285 // handle command packet.
286 if(AV_RL32(mms->in_buffer + 4)==0xb00bface) { 286 if(AV_RL32(mms->in_buffer + 4)==0xb00bface) {
287 int length_remaining, hr; 287 int length_remaining, hr;
288 288
289 mms->incoming_flags= mms->in_buffer[3]; 289 mms->incoming_flags= mms->in_buffer[3];
290 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);
291 if(read_result != 4) { 291 if(read_result != 4) {
292 av_log(NULL, AV_LOG_ERROR, 292 av_log(NULL, AV_LOG_ERROR,
293 "Reading command packet length failed: %d (%s)\n", 293 "Reading command packet length failed: %d (%s)\n",
294 read_result, 294 read_result,
295 read_result < 0 ? strerror(read_result) : 295 read_result < 0 ? strerror(read_result) :
296 "The server closed the connection"); 296 "The server closed the connection");
297 return read_result < 0 ? read_result : AVERROR_IO; 297 return read_result < 0 ? read_result : AVERROR_IO;
298 }
299
300 length_remaining= AV_RL32(mms->in_buffer+8) + 4;
301 dprintf(NULL, "Length remaining is %d\n", length_remaining);
302 // read the rest of the packet.
303 if (length_remaining < 0
304 || length_remaining > sizeof(mms->in_buffer) - 12) {
305 av_log(NULL, AV_LOG_ERROR,
306 "Incoming packet length %d exceeds bufsize %zu\n",
307 length_remaining, sizeof(mms->in_buffer) - 12);
308 return AVERROR_INVALIDDATA;
309 }
310 read_result = url_read_complete(mms->mms_hd, mms->in_buffer + 12,
311 length_remaining) ;
312 if (read_result != length_remaining) {
313 av_log(NULL, AV_LOG_ERROR,
314 "Reading pkt data (length=%d) failed: %d (%s)\n",
315 length_remaining, read_result,
316 read_result < 0 ? strerror(read_result) :
317 "The server closed the connection");
318 return read_result < 0 ? read_result : AVERROR_IO;
319 }
320 packet_type= AV_RL16(mms->in_buffer+36);
321 hr = AV_RL32(mms->in_buffer + 40);
322 if (hr) {
323 av_log(NULL, AV_LOG_ERROR,
324 "Server sent an error status code: 0x%08x\n", hr);
325 return AVERROR_UNKNOWN;
326 }
327 } else {
328 int length_remaining;
329 int packet_id_type;
330 int tmp;
331
332 // note we cache the first 8 bytes,
333 // then fill up the buffer with the others
334 tmp = AV_RL16(mms->in_buffer + 6);
335 length_remaining = (tmp - 8) & 0xffff;
336 mms->incoming_packet_seq = AV_RL32(mms->in_buffer);
337 packet_id_type = mms->in_buffer[4];
338 mms->incoming_flags = mms->in_buffer[5];
339
340 if (length_remaining < 0
341 || length_remaining > sizeof(mms->in_buffer) - 8) {
342 av_log(NULL, AV_LOG_ERROR,
343 "Data length %d is invalid or too large (max=%zu)\n",
344 length_remaining, sizeof(mms->in_buffer));
345 return AVERROR_INVALIDDATA;
346 }
347 mms->remaining_in_len = length_remaining;
348 mms->read_in_ptr = mms->in_buffer;
349 read_result= url_read_complete(mms->mms_hd, mms->in_buffer, length_remaining);
350 if(read_result != length_remaining) {
351 av_log(NULL, AV_LOG_ERROR,
352 "Failed to read packet data of size %d: %d (%s)\n",
353 length_remaining, read_result,
354 read_result < 0 ? strerror(read_result) :
355 "The server closed the connection");
356 return read_result < 0 ? read_result : AVERROR_IO;
357 }
358
359 // if we successfully read everything.
360 if(packet_id_type == mms->header_packet_id) {
361 packet_type = SC_PKT_ASF_HEADER;
362 // Store the asf header
363 if(!mms->header_parsed) {
364 void *p = av_realloc(mms->asf_header,
365 mms->asf_header_size + mms->remaining_in_len);
366 if (!p) {
367 av_freep(&mms->asf_header);
368 return AVERROR(ENOMEM);
369 }
370 mms->asf_header = p;
371 memcpy(mms->asf_header + mms->asf_header_size,
372 mms->read_in_ptr, mms->remaining_in_len);
373 mms->asf_header_size += mms->remaining_in_len;
298 } 374 }
299 375 // 0x04 means asf header is sent in multiple packets.
300 length_remaining= AV_RL32(mms->in_buffer+8) + 4; 376 if (mms->incoming_flags == 0x04)
301 dprintf(NULL, "Length remaining is %d\n", length_remaining); 377 continue;
302 // read the rest of the packet. 378 } else if(packet_id_type == mms->packet_id) {
303 if (length_remaining < 0 379 packet_type = SC_PKT_ASF_MEDIA;
304 || length_remaining > sizeof(mms->in_buffer) - 12) {
305 av_log(NULL, AV_LOG_ERROR,
306 "Incoming packet length %d exceeds bufsize %zu\n",
307 length_remaining, sizeof(mms->in_buffer) - 12);
308 return AVERROR_INVALIDDATA;
309 }
310 read_result = url_read_complete(mms->mms_hd, mms->in_buffer + 12,
311 length_remaining) ;
312 if (read_result != length_remaining) {
313 av_log(NULL, AV_LOG_ERROR,
314 "Reading pkt data (length=%d) failed: %d (%s)\n",
315 length_remaining, read_result,
316 read_result < 0 ? strerror(read_result) :
317 "The server closed the connection");
318 return read_result < 0 ? read_result : AVERROR_IO;
319 }
320 packet_type= AV_RL16(mms->in_buffer+36);
321 hr = AV_RL32(mms->in_buffer + 40);
322 if (hr) {
323 av_log(NULL, AV_LOG_ERROR,
324 "Server sent an error status code: 0x%08x\n",
325 hr);
326 return AVERROR_UNKNOWN;
327 }
328 } else { 380 } else {
329 int length_remaining; 381 dprintf(NULL, "packet id type %d is old.", packet_id_type);
330 int packet_id_type;
331 int tmp;
332
333 // note we cache the first 8 bytes,
334 // then fill up the buffer with the others
335 tmp = AV_RL16(mms->in_buffer + 6);
336 length_remaining = (tmp - 8) & 0xffff;
337 mms->incoming_packet_seq = AV_RL32(mms->in_buffer);
338 packet_id_type = mms->in_buffer[4];
339 mms->incoming_flags = mms->in_buffer[5];
340
341 if (length_remaining < 0
342 || length_remaining > sizeof(mms->in_buffer) - 8) {
343 av_log(NULL, AV_LOG_ERROR,
344 "Data length %d is invalid or too large (max=%zu)\n",
345 length_remaining, sizeof(mms->in_buffer));
346 return AVERROR_INVALIDDATA;
347 }
348 mms->remaining_in_len = length_remaining;
349 mms->read_in_ptr = mms->in_buffer;
350 read_result= url_read_complete(mms->mms_hd, mms->in_buffer, length_remaining);
351 if(read_result != length_remaining) {
352 av_log(NULL, AV_LOG_ERROR,
353 "Failed to read packet data of size %d: %d (%s)\n",
354 length_remaining, read_result,
355 read_result < 0 ? strerror(read_result) :
356 "The server closed the connection");
357 return read_result < 0 ? read_result : AVERROR_IO;
358 }
359
360 // if we successfully read everything.
361 if(packet_id_type == mms->header_packet_id) {
362 packet_type = SC_PKT_ASF_HEADER;
363 // Store the asf header
364 if(!mms->header_parsed) {
365 void *p = av_realloc(mms->asf_header,
366 mms->asf_header_size
367 + mms->remaining_in_len);
368 if (!p) {
369 av_freep(&mms->asf_header);
370 return AVERROR(ENOMEM);
371 }
372 mms->asf_header = p;
373 memcpy(mms->asf_header + mms->asf_header_size,
374 mms->read_in_ptr,
375 mms->remaining_in_len);
376 mms->asf_header_size += mms->remaining_in_len;
377 }
378 // 0x04 means asf header is sent in multiple packets.
379 if (mms->incoming_flags == 0x04)
380 continue;
381 } else if(packet_id_type == mms->packet_id) {
382 packet_type = SC_PKT_ASF_MEDIA;
383 } else {
384 dprintf(NULL, "packet id type %d is old.", packet_id_type);
385 continue;
386 }
387 }
388
389 // preprocess some packet type
390 if(packet_type == SC_PKT_KEEPALIVE) {
391 send_keepalive_packet(mms);
392 continue; 382 continue;
393 } else if(packet_type == SC_PKT_STREAM_CHANGING) { 383 }
394 handle_packet_stream_changing_type(mms); 384 }
395 } else if(packet_type == SC_PKT_ASF_MEDIA) { 385
396 pad_media_packet(mms); 386 // preprocess some packet type
397 } 387 if(packet_type == SC_PKT_KEEPALIVE) {
398 return packet_type; 388 send_keepalive_packet(mms);
389 continue;
390 } else if(packet_type == SC_PKT_STREAM_CHANGING) {
391 handle_packet_stream_changing_type(mms);
392 } else if(packet_type == SC_PKT_ASF_MEDIA) {
393 pad_media_packet(mms);
394 }
395 return packet_type;
399 } 396 }
400 } 397 }
401 398
402 static int mms_safe_send_recv(MMSContext *mms, 399 static int mms_safe_send_recv(MMSContext *mms,
403 int (*send_fun)(MMSContext *mms), 400 int (*send_fun)(MMSContext *mms),