1
0
Fork 0

mpegts: switch back to mpegts_get_pcr

This commit is contained in:
Hendrik Leppkes 2012-04-05 21:43:58 +02:00
parent 787b2fcd3c
commit 90f7e6aa10
Signed by: hendrik
GPG Key ID: 846079A4B0A7C1B5
1 changed files with 47 additions and 5 deletions

View File

@ -3108,6 +3108,43 @@ static void seek_back(AVFormatContext *s, AVIOContext *pb, int64_t pos) {
av_log(s, (pb->seekable & AVIO_SEEKABLE_NORMAL) ? AV_LOG_ERROR : AV_LOG_INFO, "Unable to seek back to the start\n");
}
static int parse_timestamp(int64_t *ts, const uint8_t *buf)
{
int afc, flags;
const uint8_t *p;
if(!(buf[1] & 0x40)) /* must be a start packet */
return -1;
afc = (buf[3] >> 4) & 3;
p = buf + 4;
if (afc == 0 || afc == 2) /* invalid or only adaption field */
return -1;
if (afc == 3)
p += p[0] + 1;
if (p >= buf + TS_PACKET_SIZE)
return -1;
if (p[0] != 0x00 || p[1] != 0x00 || p[2] != 0x01) /* packet_start_code_prefix */
return -1;
flags = p[3] | 0x100; /* stream type */
if (!((flags >= 0x1c0 && flags <= 0x1df) ||
(flags >= 0x1e0 && flags <= 0x1ef) ||
(flags == 0x1bd) || (flags == 0x1fd)))
return -1;
flags = p[7];
if ((flags & 0xc0) == 0x80) {
*ts = ff_parse_pes_pts(p+9);
return 0;
} else if ((flags & 0xc0) == 0xc0) {
*ts = ff_parse_pes_pts(p+9);
return 0;
}
return -1;
}
static int mpegts_read_header(AVFormatContext *s)
{
MpegTSContext *ts = s->priv_data;
@ -3315,8 +3352,9 @@ static av_unused int64_t mpegts_get_pcr(AVFormatContext *s, int stream_index,
MpegTSContext *ts = s->priv_data;
int64_t pos, timestamp;
uint8_t buf[TS_PACKET_SIZE];
int pcr_l, pcr_pid =
((PESContext *)s->streams[stream_index]->priv_data)->pcr_pid;
/* int pcr_l, pcr_pid =
((PESContext *)s->streams[stream_index]->priv_data)->pcr_pid; */
int pid = ((PESContext*)s->streams[stream_index]->priv_data)->pid;
int pos47 = ts->pos47_full % ts->raw_packet_size;
pos =
((*ppos + ts->raw_packet_size - 1 - pos47) / ts->raw_packet_size) *
@ -3332,10 +3370,14 @@ static av_unused int64_t mpegts_get_pcr(AVFormatContext *s, int stream_index,
pos = avio_tell(s->pb);
continue;
}
if ((pcr_pid < 0 || (AV_RB16(buf + 1) & 0x1fff) == pcr_pid) &&
/*if ((pcr_pid < 0 || (AV_RB16(buf + 1) & 0x1fff) == pcr_pid) &&
parse_pcr(&timestamp, &pcr_l, buf) == 0) {
*ppos = pos;
return timestamp;
}*/
if ((pid < 0 || (AV_RB16(buf + 1) & 0x1fff) == pid) && parse_timestamp(&timestamp, buf) == 0) {
*ppos = pos;
return timestamp;
}
pos += ts->raw_packet_size;
}
@ -3473,7 +3515,7 @@ const FFInputFormat ff_mpegts_demuxer = {
.read_header = mpegts_read_header,
.read_packet = mpegts_read_packet,
.read_close = mpegts_read_close,
.read_timestamp = mpegts_get_dts,
.read_timestamp = mpegts_get_pcr,
};
const FFInputFormat ff_mpegtsraw_demuxer = {
@ -3485,5 +3527,5 @@ const FFInputFormat ff_mpegtsraw_demuxer = {
.read_header = mpegts_read_header,
.read_packet = mpegts_raw_read_packet,
.read_close = mpegts_read_close,
.read_timestamp = mpegts_get_dts,
.read_timestamp = mpegts_get_pcr,
};