Mercurial > mplayer.hg
comparison libmpdemux/demux_ts.c @ 12049:5da6a113b6af
fix wrong detection of mpeg4 as mpeg2 and wrong handling of discontinuities/transport error bit
author | nicodvb |
---|---|
date | Sat, 20 Mar 2004 13:09:08 +0000 |
parents | ec3dac7d17a0 |
children | 996757299a82 |
comparison
equal
deleted
inserted
replaced
12048:09aae06de9c8 | 12049:5da6a113b6af |
---|---|
934 } | 934 } |
935 else if ((stream_id >= 0xbc) && ((stream_id & 0xf0) == 0xe0)) | 935 else if ((stream_id >= 0xbc) && ((stream_id & 0xf0) == 0xe0)) |
936 { | 936 { |
937 es->start = p; | 937 es->start = p; |
938 es->size = packet_len; | 938 es->size = packet_len; |
939 es->type = VIDEO_MPEG2; | 939 if(type_from_pmt != UNKNOWN) |
940 es->type = type_from_pmt; | |
941 else | |
942 es->type = VIDEO_MPEG2; | |
940 if(es->payload_size) | 943 if(es->payload_size) |
941 es->payload_size -= packet_len; | 944 es->payload_size -= packet_len; |
942 | 945 |
943 mp_msg(MSGT_DEMUX, MSGL_DBG2, "pes_parse2: M2V size %d\n", es->size); | 946 mp_msg(MSGT_DEMUX, MSGL_DBG2, "pes_parse2: M2V size %d\n", es->size); |
944 return 1; | 947 return 1; |
1581 if(*broken == 0) | 1584 if(*broken == 0) |
1582 { | 1585 { |
1583 ret = *dp_offset; | 1586 ret = *dp_offset; |
1584 resize_demux_packet(*dp, ret); //shrinked to the right size | 1587 resize_demux_packet(*dp, ret); //shrinked to the right size |
1585 ds_add_packet(ds, *dp); | 1588 ds_add_packet(ds, *dp); |
1586 mp_msg(MSGT_DEMUX, MSGL_V, "ADDED %d bytes to %s fifo, PTS=%f\n", ret, (ds == demuxer->audio ? "audio" : (ds == demuxer->video ? "video" : "sub")), (*dp)->pts); | 1589 mp_msg(MSGT_DEMUX, MSGL_DBG2, "ADDED %d bytes to %s fifo, PTS=%f\n", ret, (ds == demuxer->audio ? "audio" : (ds == demuxer->video ? "video" : "sub")), (*dp)->pts); |
1587 } | 1590 } |
1588 else | 1591 else |
1589 { | 1592 { |
1590 ret = 0; | 1593 ret = 0; |
1591 mp_msg(MSGT_DEMUX, MSGL_V, "BROKEN PES, DISCARDING\n"); | 1594 mp_msg(MSGT_DEMUX, MSGL_DBG2, "BROKEN PES, DISCARDING\n"); |
1592 free_demux_packet(*dp); | 1595 free_demux_packet(*dp); |
1593 } | 1596 } |
1594 } | 1597 } |
1595 | 1598 |
1596 *broken = 1; | 1599 *broken = 1; |
1612 stream_t *stream = demuxer->stream; | 1615 stream_t *stream = demuxer->stream; |
1613 char *p, tmp[TS_FEC_PACKET_SIZE]; | 1616 char *p, tmp[TS_FEC_PACKET_SIZE]; |
1614 demux_stream_t *ds = NULL; | 1617 demux_stream_t *ds = NULL; |
1615 demux_packet_t **dp = NULL; | 1618 demux_packet_t **dp = NULL; |
1616 int *dp_offset = 0, *buffer_size = 0, *broken = NULL; | 1619 int *dp_offset = 0, *buffer_size = 0, *broken = NULL; |
1617 int32_t progid, pid_type; | 1620 int32_t progid, pid_type, bad, ts_error; |
1618 | 1621 |
1619 | 1622 |
1620 while(! done) | 1623 while(! done) |
1621 { | 1624 { |
1625 bad = ts_error = 0; | |
1622 ds = (demux_stream_t*) NULL; | 1626 ds = (demux_stream_t*) NULL; |
1623 dp = (demux_packet_t **) NULL; | 1627 dp = (demux_packet_t **) NULL; |
1624 broken = dp_offset = buffer_size = NULL; | 1628 broken = dp_offset = buffer_size = NULL; |
1625 | 1629 |
1626 buf_size = priv->ts.packet_size; | 1630 buf_size = priv->ts.packet_size; |
1637 } | 1641 } |
1638 | 1642 |
1639 | 1643 |
1640 if(! ts_sync(stream)) | 1644 if(! ts_sync(stream)) |
1641 { | 1645 { |
1642 mp_msg(MSGT_DEMUX, MSGL_V, "TS_PARSE: COULDN'T SYNC\n"); | 1646 mp_msg(MSGT_DEMUX, MSGL_DBG2, "TS_PARSE: COULDN'T SYNC\n"); |
1643 return 0; | 1647 return 0; |
1644 } | 1648 } |
1645 | 1649 |
1646 len = stream_read(stream, &packet[1], 3); | 1650 len = stream_read(stream, &packet[1], 3); |
1647 if (len != 3) | 1651 if (len != 3) |
1648 return 0; | 1652 return 0; |
1649 | 1653 |
1650 if((packet[1] >> 7) & 0x01) //transport error | 1654 if((packet[1] >> 7) & 0x01) //transport error |
1651 continue; | 1655 ts_error = 1; |
1652 | 1656 |
1653 buf_size -= 4; | 1657 buf_size -= 4; |
1654 | 1658 |
1655 is_start = packet[1] & 0x40; | 1659 is_start = packet[1] & 0x40; |
1656 pid = ((packet[1] & 0x1f) << 8) | packet[2]; | 1660 pid = ((packet[1] & 0x1f) << 8) | packet[2]; |
1671 } | 1675 } |
1672 | 1676 |
1673 | 1677 |
1674 | 1678 |
1675 if(((pid > 1) && (pid < 16)) || (pid == 8191)) //invalid pid | 1679 if(((pid > 1) && (pid < 16)) || (pid == 8191)) //invalid pid |
1680 { | |
1681 stream_skip(stream, buf_size-1); | |
1676 continue; | 1682 continue; |
1683 } | |
1677 | 1684 |
1678 cc = (packet[3] & 0xf); | 1685 cc = (packet[3] & 0xf); |
1679 cc_ok = (tss->last_cc < 0) || ((((tss->last_cc + 1) & 0x0f) == cc)); | 1686 cc_ok = (tss->last_cc < 0) || ((((tss->last_cc + 1) & 0x0f) == cc)); |
1680 tss->last_cc = cc; | 1687 tss->last_cc = cc; |
1681 | 1688 |
1682 if(cc_ok) | 1689 bad = ts_error || (! cc_ok); |
1683 { | 1690 |
1684 /* skip adaptation field, but only if cc_ok is not corrupt, | 1691 if(! bad) |
1685 otherwise we may throw away good data */ | 1692 { |
1693 // skip adaptation field, but only if cc_ok is not corrupt, | |
1694 //otherwise we may throw away good data | |
1686 afc = (packet[3] >> 4) & 3; | 1695 afc = (packet[3] >> 4) & 3; |
1687 if (afc == 0) /* reserved value */ | 1696 if(! (afc % 2)) //no payload in this TS packet |
1688 continue; | 1697 { |
1689 if (afc == 2) /* adaptation field only */ | 1698 stream_skip(stream, buf_size-1); |
1690 continue; | 1699 continue; |
1691 if (afc == 3) | 1700 } |
1701 | |
1702 if(afc == 3) | |
1692 { | 1703 { |
1693 int c; | 1704 int c; |
1694 c = stream_read_char(stream); | 1705 c = stream_read_char(stream); |
1695 buf_size--; | 1706 buf_size--; |
1696 | 1707 |
1701 continue; | 1712 continue; |
1702 | 1713 |
1703 afc = c + 1; | 1714 afc = c + 1; |
1704 } | 1715 } |
1705 else | 1716 else |
1706 afc = 0; | 1717 afc = 0; //payload only |
1707 } | 1718 } |
1708 else | 1719 else |
1709 { | 1720 { |
1710 // logically this packet should be dropped, but if I do it | 1721 // logically this packet should be dropped, but if I do it |
1711 // certain streams play corrupted. Maybe the decoders know | 1722 // certain streams play corrupted. Maybe the decoders know |
1712 // how to deal with it, but at least I consider the packet | 1723 // how to deal with it, but at least I consider the packet |
1713 // as "not initial" | 1724 // as "not initial" |
1714 mp_msg(MSGT_DEMUX, MSGL_DBG2, "ts_parse: CC Check NOT OK: PID=%d, %d -> %d\n\n", tss->pid, tss->last_cc, cc); | 1725 mp_msg(MSGT_DEMUX, MSGL_V, "ts_parse: PID=%d, Transport error: %d, CC_OK: %s\n\n", tss->pid, ts_error, (cc_ok ? "yes" : "no")); |
1715 | 1726 |
1716 if(priv->keep_broken == 0) | 1727 if(priv->keep_broken == 0) |
1728 { | |
1729 stream_skip(stream, buf_size-1); | |
1717 continue; | 1730 continue; |
1718 | 1731 } |
1719 is_start = 0; | 1732 |
1733 is_start = 0; //queued to the packet data | |
1720 } | 1734 } |
1721 | 1735 |
1722 tss->seen++; | 1736 tss->seen++; |
1723 if(tss->seen == 16 && cc_ok) //at least a complete round | 1737 if(tss->seen == 16 && cc_ok) //at least a complete round |
1724 mp_msg(MSGT_DEMUX, MSGL_V, "\nNew TS pid=%u\n", pid); | 1738 mp_msg(MSGT_DEMUX, MSGL_V, "\nNew TS pid=%u\n", pid); |
1882 | 1896 |
1883 es->pid = tss->pid; | 1897 es->pid = tss->pid; |
1884 tss->type = es->type; | 1898 tss->type = es->type; |
1885 | 1899 |
1886 if((es->pts < tss->last_pts) && es->pts) | 1900 if((es->pts < tss->last_pts) && es->pts) |
1887 mp_msg(MSGT_DEMUX, MSGL_V, "BACKWARDS PTS! : NEW: %f -> LAST: %f, PID %d\n", es->pts, tss->last_pts, tss->pid); | 1901 mp_msg(MSGT_DEMUX, MSGL_DBG2, "BACKWARDS PTS! : NEW: %f -> LAST: %f, PID %d\n", es->pts, tss->last_pts, tss->pid); |
1888 | 1902 |
1889 if(es->pts == 0.0f) | 1903 if(es->pts == 0.0f) |
1890 es->pts = tss->pts = tss->last_pts; | 1904 es->pts = tss->pts = tss->last_pts; |
1891 else | 1905 else |
1892 tss->pts = tss->last_pts = es->pts; | 1906 tss->pts = tss->last_pts = es->pts; |
1893 | 1907 |
1894 mp_msg(MSGT_DEMUX, MSGL_V, "ts_parse, NEW pid=%d, PSIZE: %u, type=%X, start=%p, len=%d\n", | 1908 mp_msg(MSGT_DEMUX, MSGL_DBG2, "ts_parse, NEW pid=%d, PSIZE: %u, type=%X, start=%p, len=%d\n", |
1895 es->pid, es->payload_size, es->type, es->start, es->size); | 1909 es->pid, es->payload_size, es->type, es->start, es->size); |
1896 | 1910 |
1897 tss->payload_size = es->payload_size; | 1911 tss->payload_size = es->payload_size; |
1898 | 1912 |
1899 demuxer->filepos = stream_tell(demuxer->stream) - es->size; | 1913 demuxer->filepos = stream_tell(demuxer->stream) - es->size; |