Revision 73e6c53e libavformat/rtpdec.c

View differences:

libavformat/rtpdec.c
370 370
    s->parse_packet = handler->parse_packet;
371 371
}
372 372

  
373
static int rtp_parse_mp4_au(RTPDemuxContext *s, const uint8_t *buf)
374
{
375
    int au_headers_length, au_header_size, i;
376
    GetBitContext getbitcontext;
377
    RTPPayloadData *infos;
378

  
379
    infos = s->rtp_payload_data;
380

  
381
    if (infos == NULL)
382
        return -1;
383

  
384
    /* decode the first 2 bytes where the AUHeader sections are stored
385
       length in bits */
386
    au_headers_length = AV_RB16(buf);
387

  
388
    if (au_headers_length > RTP_MAX_PACKET_LENGTH)
389
      return -1;
390

  
391
    infos->au_headers_length_bytes = (au_headers_length + 7) / 8;
392

  
393
    /* skip AU headers length section (2 bytes) */
394
    buf += 2;
395

  
396
    init_get_bits(&getbitcontext, buf, infos->au_headers_length_bytes * 8);
397

  
398
    /* XXX: Wrong if optionnal additional sections are present (cts, dts etc...) */
399
    au_header_size = infos->sizelength + infos->indexlength;
400
    if (au_header_size <= 0 || (au_headers_length % au_header_size != 0))
401
        return -1;
402

  
403
    infos->nb_au_headers = au_headers_length / au_header_size;
404
    if (!infos->au_headers || infos->au_headers_allocated < infos->nb_au_headers) {
405
        av_free(infos->au_headers);
406
        infos->au_headers = av_malloc(sizeof(struct AUHeaders) * infos->nb_au_headers);
407
        infos->au_headers_allocated = infos->nb_au_headers;
408
    }
409

  
410
    /* XXX: We handle multiple AU Section as only one (need to fix this for interleaving)
411
       In my test, the FAAD decoder does not behave correctly when sending each AU one by one
412
       but does when sending the whole as one big packet...  */
413
    infos->au_headers[0].size = 0;
414
    infos->au_headers[0].index = 0;
415
    for (i = 0; i < infos->nb_au_headers; ++i) {
416
        infos->au_headers[0].size += get_bits_long(&getbitcontext, infos->sizelength);
417
        infos->au_headers[0].index = get_bits_long(&getbitcontext, infos->indexlength);
418
    }
419

  
420
    infos->nb_au_headers = 1;
421

  
422
    return 0;
423
}
424

  
425 373
/**
426 374
 * This was the second switch in rtp_parse packet.  Normalizes time, if required, sets stream_index, etc.
427 375
 */
......
563 511
            av_new_packet(pkt, len);
564 512
            memcpy(pkt->data, buf, len);
565 513
            break;
566
            // moved from below, verbatim.  this is because this section handles packets, and the lower switch handles
567
            // timestamps.
568
            // TODO: Put this into a dynamic packet handler...
569
        case CODEC_ID_AAC:
570
            if (rtp_parse_mp4_au(s, buf))
571
                return -1;
572
            {
573
                RTPPayloadData *infos = s->rtp_payload_data;
574
                if (infos == NULL)
575
                    return -1;
576
                buf += infos->au_headers_length_bytes + 2;
577
                len -= infos->au_headers_length_bytes + 2;
578

  
579
                /* XXX: Fixme we only handle the case where rtp_parse_mp4_au define
580
                    one au_header */
581
                av_new_packet(pkt, infos->au_headers[0].size);
582
                memcpy(pkt->data, buf, infos->au_headers[0].size);
583
                buf += infos->au_headers[0].size;
584
                len -= infos->au_headers[0].size;
585
            }
586
            s->read_buf_size = len;
587
            rv= 0;
588
            break;
589 514
        default:
590 515
            av_new_packet(pkt, len);
591 516
            memcpy(pkt->data, buf, len);

Also available in: Unified diff