Revision ec23a472

View differences:

libavformat/mpeg.c
405 405

  
406 406
static int mpegps_probe(AVProbeData *p)
407 407
{
408
    int code;
408
    int code, c, i;
409 409
    const uint8_t *d;
410 410

  
411
    code = 0xff;
411 412
    /* we search the first start code. If it is a packet start code,
412 413
       then we decide it is mpeg ps. We do not send highest value to
413 414
       give a chance to mpegts */
......
416 417

  
417 418
    if (p->buf_size < 6)
418 419
        return 0;
419
    d = p->buf;
420
    code = (d[0] << 24) | (d[1] << 16) | (d[2] << 8) | (d[3]);
421
    if ((code & 0xffffff00) == 0x100) {
422
        if (code == PACK_START_CODE ||
423
            code == SYSTEM_HEADER_START_CODE ||
424
            (code >= 0x1e0 && code <= 0x1ef) ||
425
            (code >= 0x1c0 && code <= 0x1df) ||
426
            code == PRIVATE_STREAM_2 ||
427
            code == PROGRAM_STREAM_MAP ||
428
            code == PRIVATE_STREAM_1 ||
429
            code == PADDING_STREAM)
430
            return AVPROBE_SCORE_MAX - 1;
431
        else
432
            return 0;
420

  
421
    for (i = 0; i < 20; i++) {
422
        c = p->buf[i];
423
        code = (code << 8) | c;
424
        if ((code & 0xffffff00) == 0x100) {
425
            if (code == PACK_START_CODE ||
426
                code == SYSTEM_HEADER_START_CODE ||
427
                (code >= 0x1e0 && code <= 0x1ef) ||
428
                (code >= 0x1c0 && code <= 0x1df) ||
429
                code == PRIVATE_STREAM_2 ||
430
                code == PROGRAM_STREAM_MAP ||
431
                code == PRIVATE_STREAM_1 ||
432
                code == PADDING_STREAM)
433
                return AVPROBE_SCORE_MAX - 1;
434
            else
435
                return 0;
436
        }
433 437
    }
434 438
    return 0;
435 439
}
libavformat/mpegts.c
387 387
        case STREAM_TYPE_AUDIO_MPEG2:
388 388
        case STREAM_TYPE_VIDEO_MPEG1:
389 389
        case STREAM_TYPE_VIDEO_MPEG2:
390
        case STREAM_TYPE_AUDIO_AC3:
390 391
            add_pes_stream(ts->stream, pid);
391 392
            break;
392 393
        default:
......
613 614
                if (pes->header[0] == 0x00 && pes->header[1] == 0x00 &&
614 615
                    pes->header[2] == 0x01) {
615 616
                    /* it must be an mpeg2 PES stream */
616
                    /* XXX: add AC3 support */
617 617
                    code = pes->header[3] | 0x100;
618 618
                    if (!((code >= 0x1c0 && code <= 0x1df) ||
619
                          (code >= 0x1e0 && code <= 0x1ef)))
619
                          (code >= 0x1e0 && code <= 0x1ef) ||
620
                          (code == 0x1bd)))
620 621
                        goto skip;
621 622
                    if (!pes->st) {
622 623
                        /* allocate stream */
623 624
                        if (code >= 0x1c0 && code <= 0x1df) {
624 625
                            codec_type = CODEC_TYPE_AUDIO;
625 626
                            codec_id = CODEC_ID_MP2;
627
                        } else if (code == 0x1bd) {
628
                            codec_type = CODEC_TYPE_AUDIO;
629
                            codec_id = CODEC_ID_AC3;
626 630
                        } else {
627 631
                            codec_type = CODEC_TYPE_VIDEO;
628 632
                            codec_id = CODEC_ID_MPEG1VIDEO;
......
805 809
    ByteIOContext *pb = &s->pb;
806 810
    uint8_t packet[TS_FEC_PACKET_SIZE];
807 811
    int packet_num, len;
812
    int i, found = 0;
813
    int64_t pos;
808 814

  
809 815
    ts->stop_parse = 0;
810 816
    packet_num = 0;
......
814 820
        packet_num++;
815 821
        if (nb_packets != 0 && packet_num >= nb_packets)
816 822
            break;
823
        pos = url_ftell(pb);
817 824
        len = get_buffer(pb, packet, ts->raw_packet_size);
818 825
        if (len != ts->raw_packet_size)
819 826
            return AVERROR_IO;
820 827
        /* check paquet sync byte */
821
        /* XXX: accept to resync ? */
822 828
        if (packet[0] != 0x47)
823
            return AVERROR_INVALIDDATA;
829
        {
830
           //printf("bad packet: 0x%x\n", packet[0]);
831
           found = 0;
832
           for (i = 0; i < ts->raw_packet_size; i++)
833
           {
834
               if (packet[i] == 0x47)
835
               {
836
                   found = 1;
837
                   //printf("packet start at: %d\n", i);
838
                   break;
839
               }
840
           }
841
           
842
           if (found)
843
           {
844
               url_fseek(pb, pos + i, SEEK_SET);
845
               continue;
846
           }
847
           return AVERROR_INVALIDDATA;
848
        }
824 849
        handle_packet(s, packet);
825 850
    }
826 851
    return 0;
libavformat/mpegts.h
38 38
#define STREAM_TYPE_PRIVATE_SECTION 0x05
39 39
#define STREAM_TYPE_PRIVATE_DATA    0x06
40 40

  
41
#define STREAM_TYPE_AUDIO_AC3       0x81
42

  
41 43
unsigned int mpegts_crc32(const uint8_t *data, int len);
42 44
extern AVOutputFormat mpegts_mux;

Also available in: Unified diff