Revision 50883632 libavformat/dv.c

View differences:

libavformat/dv.c
538 538
{
539 539
    const uint8_t* as_pack;
540 540
    const DVprofile* sys;
541
    int freq, smpls, quant, i;
541
    int freq, smpls, quant, i, ach;
542 542

  
543 543
    sys = dv_frame_profile(frame);
544 544
    as_pack = dv_extract_pack(frame, dv_audio_source);
......
550 550
    smpls = as_pack[1] & 0x3f; /* samples in this frame - min. samples */
551 551
    freq = (as_pack[4] >> 3) & 0x07; /* 0 - 48KHz, 1 - 44,1kHz, 2 - 32 kHz */
552 552
    quant = as_pack[4] & 0x07; /* 0 - 16bit linear, 1 - 12bit nonlinear */
553
    c->ach = (quant && freq == 2) ? 2 : 1;
554

  
555
    /* The second stereo channel could appear in IEC 61834 stream only */
556
    if (c->ach == 2 && !c->ast[1]) {
557
        c->ast[1] = av_new_stream(c->fctx, 0);
558
	if (c->ast[1]) {
559
            av_set_pts_info(c->ast[1], 64, 1, 30000);
560
	    c->ast[1]->codec.codec_type = CODEC_TYPE_AUDIO;
561
	    c->ast[1]->codec.codec_id = CODEC_ID_PCM_S16LE;
562
	} else
563
	    c->ach = 1;
564
    }
565
    for (i=0; i<c->ach; i++) {
553
    ach = (quant && freq == 2) ? 2 : 1;
554

  
555
    /* Dynamic handling of the audio streams in DV */
556
    for (i=0; i<ach; i++) {
557
       if (!c->ast[i]) {
558
           c->ast[i] = av_new_stream(c->fctx, 0);
559
	   if (!c->ast[i])
560
	       break;
561
	   av_set_pts_info(c->ast[i], 64, 1, 30000);
562
	   c->ast[i]->codec.codec_type = CODEC_TYPE_AUDIO;
563
	   c->ast[i]->codec.codec_id = CODEC_ID_PCM_S16LE;
564
       }
566 565
       c->ast[i]->codec.sample_rate = dv_audio_frequency[freq];
567 566
       c->ast[i]->codec.channels = 2;
568 567
       c->ast[i]->codec.bit_rate = 2 * dv_audio_frequency[freq] * 16;
568
       c->ast[i]->start_time = 0;
569 569
    }
570
    c->ach = i;
570 571
    
571 572
    return (sys->audio_min_samples[freq] + smpls) * 4; /* 2ch, 2bytes */;
572 573
}
......
732 733
        return NULL;
733 734

  
734 735
    c->vst = av_new_stream(s, 0);
735
    c->ast[0] = av_new_stream(s, 0);
736
    if (!c->vst || !c->ast[0])
737
        goto fail;
736
    if (!c->vst) {
737
        av_free(c);        
738
        return NULL;
739
    }
738 740
    av_set_pts_info(c->vst, 64, 1, 30000);
739
    av_set_pts_info(c->ast[0], 64, 1, 30000);
740 741

  
741 742
    c->fctx = s;
742
    c->ast[1] = NULL;
743
    c->ast[0] = c->ast[1] = NULL;
743 744
    c->ach = 0;
744 745
    c->frames = 0;
745 746
    c->abytes = 0;
......
751 752
    c->vst->codec.bit_rate = 25000000;
752 753
    c->vst->start_time = 0;
753 754
    
754
    c->ast[0]->codec.codec_type = CODEC_TYPE_AUDIO;
755
    c->ast[0]->codec.codec_id = CODEC_ID_PCM_S16LE;
756
    c->ast[0]->codec.sample_rate = 48000;
757
    c->ast[0]->codec.channels = 2;
758
    c->ast[0]->start_time = 0;
759
    
760 755
    return c;
761
    
762
fail:
763
    if (c->vst)
764
        av_free(c->vst);
765
    if (c->ast[0])
766
        av_free(c->ast[0]);
767
    av_free(c);
768
    return NULL;
769 756
}
770 757

  
771 758
static void __destruct_pkt(struct AVPacket *pkt)

Also available in: Unified diff