comparison libmpdemux/demux_real.c @ 21989:c3dc45e16aa3

Use interleaver id to select the correct interleaver instead of guessing it from the codec id.
author rtogni
date Wed, 24 Jan 2007 21:20:08 +0000
parents d7b2fa4c39da
children 89fcce32d9d0
comparison
equal deleted inserted replaced
21988:dbdd1a73c7f7 21989:c3dc45e16aa3
109 int stream_switch; ///< Flag used to switch audio/video demuxing 109 int stream_switch; ///< Flag used to switch audio/video demuxing
110 110
111 /** 111 /**
112 * Used to reorder audio data 112 * Used to reorder audio data
113 */ 113 */
114 unsigned int intl_id[MAX_STREAMS]; ///< interleaver id, per stream
114 int sub_packet_size[MAX_STREAMS]; ///< sub packet size, per stream 115 int sub_packet_size[MAX_STREAMS]; ///< sub packet size, per stream
115 int sub_packet_h[MAX_STREAMS]; ///< number of coded frames per block 116 int sub_packet_h[MAX_STREAMS]; ///< number of coded frames per block
116 int coded_framesize[MAX_STREAMS]; ///< coded frame size, per stream 117 int coded_framesize[MAX_STREAMS]; ///< coded frame size, per stream
117 int audiopk_size[MAX_STREAMS]; ///< audio packet size 118 int audiopk_size[MAX_STREAMS]; ///< audio packet size
118 unsigned char *audio_buf; ///< place to store reordered audio data 119 unsigned char *audio_buf; ///< place to store reordered audio data
695 ds_add_packet(ds, dp); 696 ds_add_packet(ds, dp);
696 } 697 }
697 free(sub_packet_lengths); 698 free(sub_packet_lengths);
698 return 1; 699 return 1;
699 } 700 }
700 if ((((sh_audio_t*)ds->sh)->format == mmioFOURCC('2', '8', '_', '8')) || 701 if ((priv->intl_id[stream_id] == mmioFOURCC('I', 'n', 't', '4')) ||
701 (((sh_audio_t*)ds->sh)->format == mmioFOURCC('c', 'o', 'o', 'k')) || 702 (priv->intl_id[stream_id] == mmioFOURCC('g', 'e', 'n', 'r')) ||
702 (((sh_audio_t*)ds->sh)->format == mmioFOURCC('a', 't', 'r', 'c')) || 703 (priv->intl_id[stream_id] == mmioFOURCC('s', 'i', 'p', 'r'))) {
703 (((sh_audio_t*)ds->sh)->format == mmioFOURCC('s', 'i', 'p', 'r'))) {
704 sps = priv->sub_packet_size[stream_id]; 704 sps = priv->sub_packet_size[stream_id];
705 sph = priv->sub_packet_h[stream_id]; 705 sph = priv->sub_packet_h[stream_id];
706 cfs = priv->coded_framesize[stream_id]; 706 cfs = priv->coded_framesize[stream_id];
707 w = priv->audiopk_size[stream_id]; 707 w = priv->audiopk_size[stream_id];
708 spc = priv->sub_packet_cnt; 708 spc = priv->sub_packet_cnt;
709 switch (((sh_audio_t*)ds->sh)->format) { 709 switch (priv->intl_id[stream_id]) {
710 case mmioFOURCC('2', '8', '_', '8'): 710 case mmioFOURCC('I', 'n', 't', '4'):
711 for (x = 0; x < sph / 2; x++) 711 for (x = 0; x < sph / 2; x++)
712 stream_read(demuxer->stream, priv->audio_buf + x * 2 * w + spc * cfs, cfs); 712 stream_read(demuxer->stream, priv->audio_buf + x * 2 * w + spc * cfs, cfs);
713 break; 713 break;
714 case mmioFOURCC('c', 'o', 'o', 'k'): 714 case mmioFOURCC('g', 'e', 'n', 'r'):
715 case mmioFOURCC('a', 't', 'r', 'c'):
716 for (x = 0; x < w / sps; x++) 715 for (x = 0; x < w / sps; x++)
717 stream_read(demuxer->stream, priv->audio_buf + sps * (sph * x + ((sph + 1) / 2) * (spc & 1) + 716 stream_read(demuxer->stream, priv->audio_buf + sps * (sph * x + ((sph + 1) / 2) * (spc & 1) +
718 (spc >> 1)), sps); 717 (spc >> 1)), sps);
719 break; 718 break;
720 case mmioFOURCC('s', 'i', 'p', 'r'): 719 case mmioFOURCC('s', 'i', 'p', 'r'):
766 dp->pos = priv->audio_filepos; // all equal 765 dp->pos = priv->audio_filepos; // all equal
767 dp->flags = x ? 0 : 0x10; // Mark first packet as keyframe 766 dp->flags = x ? 0 : 0x10; // Mark first packet as keyframe
768 ds_add_packet(ds, dp); 767 ds_add_packet(ds, dp);
769 } 768 }
770 } 769 }
771 } else { // Not a codec that require reordering 770 } else { // No interleaving
772 dp = new_demux_packet(len); 771 dp = new_demux_packet(len);
773 stream_read(demuxer->stream, dp->buffer, len); 772 stream_read(demuxer->stream, dp->buffer, len);
774 773
775 #ifdef CRACK_MATRIX 774 #ifdef CRACK_MATRIX
776 mp_msg(MSGT_DEMUX, MSGL_V,"*** audio block len=%d\n",len); 775 mp_msg(MSGT_DEMUX, MSGL_V,"*** audio block len=%d\n",len);
1353 mp_msg(MSGT_DEMUX,MSGL_V,"samplerate: %d, channels: %d\n", 1352 mp_msg(MSGT_DEMUX,MSGL_V,"samplerate: %d, channels: %d\n",
1354 sh->samplerate, sh->channels); 1353 sh->samplerate, sh->channels);
1355 1354
1356 if (version == 5) 1355 if (version == 5)
1357 { 1356 {
1358 stream_skip(demuxer->stream, 4); // "genr" 1357 stream_read(demuxer->stream, buf, 4); // interleaver id
1358 priv->intl_id[stream_id] = MKTAG(buf[0], buf[1], buf[2], buf[3]);
1359 stream_read(demuxer->stream, buf, 4); // fourcc 1359 stream_read(demuxer->stream, buf, 4); // fourcc
1360 buf[4] = 0; 1360 buf[4] = 0;
1361 } 1361 }
1362 else 1362 else
1363 { 1363 {
1364 /* Desc #1 */ 1364 /* Interleaver id */
1365 skip_str(1, demuxer); 1365 get_str(1, demuxer, buf, sizeof(buf));
1366 /* Desc #2 */ 1366 priv->intl_id[stream_id] = MKTAG(buf[0], buf[1], buf[2], buf[3]);
1367 /* Codec FourCC */
1367 get_str(1, demuxer, buf, sizeof(buf)); 1368 get_str(1, demuxer, buf, sizeof(buf));
1368 } 1369 }
1369 } 1370 }
1370 1371
1371 /* Emulate WAVEFORMATEX struct: */ 1372 /* Emulate WAVEFORMATEX struct: */
1389 sh->wf->nBlockAlign = 0x14; 1390 sh->wf->nBlockAlign = 0x14;
1390 break; 1391 break;
1391 1392
1392 case MKTAG('2', '8', '_', '8'): 1393 case MKTAG('2', '8', '_', '8'):
1393 sh->wf->nBlockAlign = coded_frame_size; 1394 sh->wf->nBlockAlign = coded_frame_size;
1394 priv->sub_packet_size[stream_id] = sub_packet_size;
1395 priv->sub_packet_h[stream_id] = sub_packet_h;
1396 priv->coded_framesize[stream_id] = coded_frame_size;
1397 priv->audiopk_size[stream_id] = frame_size;
1398 break; 1395 break;
1399 1396
1400 case MKTAG('s', 'i', 'p', 'r'): 1397 case MKTAG('s', 'i', 'p', 'r'):
1401 case MKTAG('a', 't', 'r', 'c'): 1398 case MKTAG('a', 't', 'r', 'c'):
1402 case MKTAG('c', 'o', 'o', 'k'): 1399 case MKTAG('c', 'o', 'o', 'k'):
1411 goto skip_this_chunk; 1408 goto skip_this_chunk;
1412 } 1409 }
1413 sh->wf->cbSize = codecdata_length; 1410 sh->wf->cbSize = codecdata_length;
1414 sh->wf = realloc(sh->wf, sizeof(WAVEFORMATEX)+sh->wf->cbSize); 1411 sh->wf = realloc(sh->wf, sizeof(WAVEFORMATEX)+sh->wf->cbSize);
1415 stream_read(demuxer->stream, ((char*)(sh->wf+1)), codecdata_length); // extras 1412 stream_read(demuxer->stream, ((char*)(sh->wf+1)), codecdata_length); // extras
1416 if ((sh->format == MKTAG('a', 't', 'r', 'c')) || 1413 if (priv->intl_id[stream_id] == MKTAG('g', 'e', 'n', 'r'))
1417 (sh->format == MKTAG('c', 'o', 'o', 'k')))
1418 sh->wf->nBlockAlign = sub_packet_size; 1414 sh->wf->nBlockAlign = sub_packet_size;
1419 else 1415 else
1420 sh->wf->nBlockAlign = coded_frame_size; 1416 sh->wf->nBlockAlign = coded_frame_size;
1421 1417
1422 priv->sub_packet_size[stream_id] = sub_packet_size;
1423 priv->sub_packet_h[stream_id] = sub_packet_h;
1424 priv->coded_framesize[stream_id] = coded_frame_size;
1425 priv->audiopk_size[stream_id] = frame_size;
1426 break; 1418 break;
1427 1419
1428 case MKTAG('r', 'a', 'a', 'c'): 1420 case MKTAG('r', 'a', 'a', 'c'):
1429 case MKTAG('r', 'a', 'c', 'p'): 1421 case MKTAG('r', 'a', 'c', 'p'):
1430 /* This is just AAC. The two or five bytes of */ 1422 /* This is just AAC. The two or five bytes of */
1443 sh->format = mmioFOURCC('M', 'P', '4', 'A'); 1435 sh->format = mmioFOURCC('M', 'P', '4', 'A');
1444 break; 1436 break;
1445 default: 1437 default:
1446 mp_msg(MSGT_DEMUX,MSGL_V,"Audio: Unknown (%s)\n", buf); 1438 mp_msg(MSGT_DEMUX,MSGL_V,"Audio: Unknown (%s)\n", buf);
1447 } 1439 }
1440
1441 // Interleaver setup
1442 priv->sub_packet_size[stream_id] = sub_packet_size;
1443 priv->sub_packet_h[stream_id] = sub_packet_h;
1444 priv->coded_framesize[stream_id] = coded_frame_size;
1445 priv->audiopk_size[stream_id] = frame_size;
1448 1446
1449 sh->wf->wFormatTag = sh->format; 1447 sh->wf->wFormatTag = sh->format;
1450 1448
1451 mp_msg(MSGT_DEMUX,MSGL_V,"audio fourcc: %.4s (%x)\n", (char *)&sh->format, sh->format); 1449 mp_msg(MSGT_DEMUX,MSGL_V,"audio fourcc: %.4s (%x)\n", (char *)&sh->format, sh->format);
1452 if ( mp_msg_test(MSGT_DEMUX,MSGL_V) ) 1450 if ( mp_msg_test(MSGT_DEMUX,MSGL_V) )