Revision 4b9ac0b5

View differences:

libavcodec/parser.c
494 494
    int frame_size;
495 495
    int free_format_frame_size;
496 496
    int free_format_next_header;
497
    uint32_t header;
498
    int header_count;
497 499
} MpegAudioParseContext;
498 500

  
499 501
#define MPA_HEADER_SIZE 4
......
515 517
                           const uint8_t *buf, int buf_size)
516 518
{
517 519
    MpegAudioParseContext *s = s1->priv_data;
518
    int len, ret;
520
    int len, ret, sr;
519 521
    uint32_t header;
520 522
    const uint8_t *buf_ptr;
521 523

  
......
549 551
	    }
550 552
	    if ((s->inbuf_ptr - s->inbuf) >= MPA_HEADER_SIZE) {
551 553
            got_header:
554
                sr= avctx->sample_rate;
552 555
		header = (s->inbuf[0] << 24) | (s->inbuf[1] << 16) |
553 556
		    (s->inbuf[2] << 8) | s->inbuf[3];
554 557

  
555 558
                ret = mpa_decode_header(avctx, header);
556 559
                if (ret < 0) {
560
                    s->header_count= -2;
557 561
		    /* no sync found : move by one byte (inefficient, but simple!) */
558 562
		    memmove(s->inbuf, s->inbuf + 1, s->inbuf_ptr - s->inbuf - 1);
559 563
		    s->inbuf_ptr--;
......
562 566
                       to get a new bitrate */
563 567
                    s->free_format_frame_size = 0;
564 568
		} else {
569
                    if((header&SAME_HEADER_MASK) != (s->header&SAME_HEADER_MASK) && s->header)
570
                        s->header_count= -3;
571
                    s->header= header;
572
                    s->header_count++;
565 573
                    s->frame_size = ret;
574
                    
566 575
#if 0
567 576
                    /* free format: prepare to compute frame size */
568 577
		    if (decode_header(s, header) == 1) {
......
570 579
                    }
571 580
#endif
572 581
		}
582
                if(s->header_count <= 0)
583
                    avctx->sample_rate= sr; //FIXME ugly
573 584
	    }
574 585
        } else 
575 586
#if 0
......
642 653
        //    next_data:
643 654
        if (s->frame_size > 0 && 
644 655
            (s->inbuf_ptr - s->inbuf) >= s->frame_size) {
645
            *poutbuf = s->inbuf;
646
            *poutbuf_size = s->inbuf_ptr - s->inbuf;
656
            if(s->header_count > 0){
657
                *poutbuf = s->inbuf;
658
                *poutbuf_size = s->inbuf_ptr - s->inbuf;
659
            }
647 660
	    s->inbuf_ptr = s->inbuf;
648 661
	    s->frame_size = 0;
649 662
	    break;

Also available in: Unified diff