static int dv_extract_audio_info(DVDemuxContext* c, uint8_t* frame)
{
    const uint8_t* as_pack;
    int freq, stype, smpls, quant, i, ach;
    as_pack = dv_extract_pack(frame, dv_audio_source);
    if (!as_pack || !c->sys) {    /* No audio ? */
        c->ach = 0;
    smpls =  as_pack[1] & 0x3f;       /* samples in this frame - min. samples */
    freq  = (as_pack[4] >> 3) & 0x07; /* 0 - 48kHz, 1 - 44,1kHz, 2 - 32kHz */
    stype = (as_pack[3] & 0x1f);      /* 0 - 2CH, 2 - 4CH, 3 - 8CH */
    quant =  as_pack[4] & 0x07;       /* 0 - 16bit linear, 1 - 12bit nonlinear */
    if (stype > 3) {
        av_log(c->fctx, AV_LOG_ERROR, "stype %d is invalid\n", stype);
        c->ach = 0;
    /* note: ach counts PAIRS of channels (i.e. stereo channels) */
    ach = ((int[4]){  1,  0,  2,  4})[stype];
    if (ach == 1 && quant && freq == 2)
        ach = 2;
    /* Dynamic handling of the audio streams in DV */
    for (i = 0; i < ach; i++) {
       if (!c->ast[i]) {
           c->ast[i] = avformat_new_stream(c->fctx, NULL);
           if (!c->ast[i])
               break;
           avpriv_set_pts_info(c->ast[i], 64, 1, 30000);
           c->ast[i]->codec->codec_type = AVMEDIA_TYPE_AUDIO;
           c->ast[i]->codec->codec_id   = CODEC_ID_PCM_S16LE;
           av_init_packet(&c->audio_pkt[i]);
           c->audio_pkt[i].size         = 0;
           c->audio_pkt[i].data         = c->audio_buf[i];
           c->audio_pkt[i].stream_index = c->ast[i]->index;
           c->audio_pkt[i].flags       |= AV_PKT_FLAG_KEY;
       c->ast[i]->codec->sample_rate = dv_audio_frequency[freq];
       c->ast[i]->codec->channels    = 2;
       c->ast[i]->codec->bit_rate    = 2 * dv_audio_frequency[freq] * 16;
       c->ast[i]->start_time         = 0;
    c->ach = i;
    return (c->sys->audio_min_samples[freq] + smpls) * 4; /* 2ch, 2bytes */;
static int dv_extract_audio_info(DVDemuxContext* c, uint8_t* frame)
{
    const uint8_t* as_pack;
    int freq, stype, smpls, quant, i, ach;
    as_pack = dv_extract_pack(frame, dv_audio_source);
    if (!as_pack || !c->sys) {    
        c->ach = 0;
    smpls =  as_pack[1] & 0x3f;       
    freq  = (as_pack[4] >> 3) & 0x07; 
    stype = (as_pack[3] & 0x1f);      
    quant =  as_pack[4] & 0x07;       
    if (stype > 3) {
        av_log(c->fctx, AV_LOG_ERROR, "stype %d is invalid\n", stype);
        c->ach = 0;
    
    ach = ((int[4]){  1,  0,  2,  4})[stype];
    if (ach == 1 && quant && freq == 2)
        ach = 2;
    
    for (i = 0; i < ach; i++) {
       if (!c->ast[i]) {
           c->ast[i] = avformat_new_stream(c->fctx, NULL);
           if (!c->ast[i])
               break;
           avpriv_set_pts_info(c->ast[i], 64, 1, 30000);
           c->ast[i]->codec->codec_type = AVMEDIA_TYPE_AUDIO;
           c->ast[i]->codec->codec_id   = CODEC_ID_PCM_S16LE;
           av_init_packet(&c->audio_pkt[i]);
           c->audio_pkt[i].size         = 0;
           c->audio_pkt[i].data         = c->audio_buf[i];
           c->audio_pkt[i].stream_index = c->ast[i]->index;
           c->audio_pkt[i].flags       |= AV_PKT_FLAG_KEY;
       c->ast[i]->codec->sample_rate = dv_audio_frequency[freq];
       c->ast[i]->codec->channels    = 2;
       c->ast[i]->codec->bit_rate    = 2 * dv_audio_frequency[freq] * 16;
       c->ast[i]->start_time         = 0;
    c->ach = i;
    return (c->sys->audio_min_samples[freq] + smpls) * 4; ;
static int FUNC_0(DVDemuxContext* VAR_0, uint8_t* VAR_1)
{
    const uint8_t* VAR_2;
    int VAR_3, VAR_4, VAR_5, VAR_6, VAR_7, VAR_8;
    VAR_2 = dv_extract_pack(VAR_1, dv_audio_source);
    if (!VAR_2 || !VAR_0->sys) {    
        VAR_0->VAR_8 = 0;
    VAR_5 =  VAR_2[1] & 0x3f;       
    VAR_3  = (VAR_2[4] >> 3) & 0x07; 
    VAR_4 = (VAR_2[3] & 0x1f);      
    VAR_6 =  VAR_2[4] & 0x07;       
    if (VAR_4 > 3) {
        av_log(VAR_0->fctx, AV_LOG_ERROR, "VAR_4 %d is invalid\n", VAR_4);
        VAR_0->VAR_8 = 0;
    
    VAR_8 = ((int[4]){  1,  0,  2,  4})[VAR_4];
    if (VAR_8 == 1 && VAR_6 && VAR_3 == 2)
        VAR_8 = 2;
    
    for (VAR_7 = 0; VAR_7 < VAR_8; VAR_7++) {
       if (!VAR_0->ast[VAR_7]) {
           VAR_0->ast[VAR_7] = avformat_new_stream(VAR_0->fctx, NULL);
           if (!VAR_0->ast[VAR_7])
               break;
           avpriv_set_pts_info(VAR_0->ast[VAR_7], 64, 1, 30000);
           VAR_0->ast[VAR_7]->codec->codec_type = AVMEDIA_TYPE_AUDIO;
           VAR_0->ast[VAR_7]->codec->codec_id   = CODEC_ID_PCM_S16LE;
           av_init_packet(&VAR_0->audio_pkt[VAR_7]);
           VAR_0->audio_pkt[VAR_7].size         = 0;
           VAR_0->audio_pkt[VAR_7].data         = VAR_0->audio_buf[VAR_7];
           VAR_0->audio_pkt[VAR_7].stream_index = VAR_0->ast[VAR_7]->index;
           VAR_0->audio_pkt[VAR_7].flags       |= AV_PKT_FLAG_KEY;
       VAR_0->ast[VAR_7]->codec->sample_rate = dv_audio_frequency[VAR_3];
       VAR_0->ast[VAR_7]->codec->channels    = 2;
       VAR_0->ast[VAR_7]->codec->bit_rate    = 2 * dv_audio_frequency[VAR_3] * 16;
       VAR_0->ast[VAR_7]->start_time         = 0;
    VAR_0->VAR_8 = VAR_7;
    return (VAR_0->sys->audio_min_samples[VAR_3] + VAR_5) * 4; ;
static int FUNC_0(DVDemuxContext* VAR_0, uint8_t* VAR_1)
{ const uint8_t* VAR_2; int VAR_3, VAR_4, VAR_5, VAR_6, VAR_7, VAR_8; VAR_2 = dv_extract_pack(VAR_1, dv_audio_source); if (!VAR_2 || !VAR_0->sys) { VAR_0->VAR_8 = 0; VAR_5 =  VAR_2[1] & 0x3f; VAR_3  = (VAR_2[4] >> 3) & 0x07; VAR_4 = (VAR_2[3] & 0x1f); VAR_6 =  VAR_2[4] & 0x07; if (VAR_4 > 3) { av_log(VAR_0->fctx, AV_LOG_ERROR, "VAR_4 %d is invalid\n", VAR_4); VAR_0->VAR_8 = 0; VAR_8 = ((int[4]){  1,  0,  2,  4})[VAR_4]; if (VAR_8 == 1 && VAR_6 && VAR_3 == 2)
VAR_8 = 2; for (VAR_7 = 0; VAR_7 < VAR_8; VAR_7++) { if (!VAR_0->ast[VAR_7]) { VAR_0->ast[VAR_7] = avformat_new_stream(VAR_0->fctx, NULL); if (!VAR_0->ast[VAR_7])
break; avpriv_set_pts_info(VAR_0->ast[VAR_7], 64, 1, 30000); VAR_0->ast[VAR_7]->codec->codec_type = AVMEDIA_TYPE_AUDIO; VAR_0->ast[VAR_7]->codec->codec_id   = CODEC_ID_PCM_S16LE; av_init_packet(&VAR_0->audio_pkt[VAR_7]); VAR_0->audio_pkt[VAR_7].size         = 0; VAR_0->audio_pkt[VAR_7].data         = VAR_0->audio_buf[VAR_7]; VAR_0->audio_pkt[VAR_7].stream_index = VAR_0->ast[VAR_7]->index; VAR_0->audio_pkt[VAR_7].flags       |= AV_PKT_FLAG_KEY; VAR_0->ast[VAR_7]->codec->sample_rate = dv_audio_frequency[VAR_3]; VAR_0->ast[VAR_7]->codec->channels    = 2; VAR_0->ast[VAR_7]->codec->bit_rate    = 2 * dv_audio_frequency[VAR_3] * 16; VAR_0->ast[VAR_7]->start_time         = 0; VAR_0->VAR_8 = VAR_7; return (VAR_0->sys->audio_min_samples[VAR_3] + VAR_5) * 4; ;