1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2025-08-15 14:13:16 +02:00

Merge commit '86ba2327e1cf35c6f77d5fb516a1a7a8dce0b98a'

* commit '86ba2327e1cf35c6f77d5fb516a1a7a8dce0b98a':
  mpegts: K&R formatting cosmetics

Conflicts:
	libavformat/mpegts.c

Merged-by: Michael Niedermayer <michaelni@gmx.at>
This commit is contained in:
Michael Niedermayer
2014-03-18 13:16:56 +01:00

View File

@@ -38,7 +38,7 @@
#include "isom.h"
/* maximum size in which we look for synchronisation if
synchronisation is lost */
* synchronisation is lost */
#define MAX_RESYNC_SIZE 65536
#define MAX_PES_PAYLOAD 200 * 1024
@@ -59,7 +59,8 @@ enum MpegTSFilterType {
typedef struct MpegTSFilter MpegTSFilter;
typedef int PESCallback(MpegTSFilter *f, const uint8_t *buf, int len, int is_start, int64_t pos, int64_t cur_pcr);
typedef int PESCallback (MpegTSFilter *f, const uint8_t *buf, int len,
int is_start, int64_t pos, int64_t cur_pcr);
typedef struct MpegTSPESFilter {
PESCallback *pes_cb;
@@ -142,17 +143,19 @@ struct MpegTSContext {
struct Program *prg;
int8_t crc_validity[NB_PID_MAX];
/** filters for various streams specified by PMT + for the PAT and PMT */
MpegTSFilter *pids[NB_PID_MAX];
int current_pid;
};
static const AVOption mpegtsraw_options[] = {
{"compute_pcr", "Compute exact PCR for each transport stream packet.", offsetof(MpegTSContext, mpeg2ts_compute_pcr), AV_OPT_TYPE_INT,
{ "compute_pcr", "Compute exact PCR for each transport stream packet.",
offsetof(MpegTSContext, mpeg2ts_compute_pcr), AV_OPT_TYPE_INT,
{ .i64 = 0 }, 0, 1, AV_OPT_FLAG_DECODING_PARAM },
{"ts_packetsize", "Output option carrying the raw packet size.", offsetof(MpegTSContext, raw_packet_size), AV_OPT_TYPE_INT,
{.i64 = 0}, 0, 0, AV_OPT_FLAG_DECODING_PARAM | AV_OPT_FLAG_EXPORT | AV_OPT_FLAG_READONLY },
{ "ts_packetsize", "Output option carrying the raw packet size.",
offsetof(MpegTSContext, raw_packet_size), AV_OPT_TYPE_INT,
{ .i64 = 0 }, 0, 0,
AV_OPT_FLAG_DECODING_PARAM | AV_OPT_FLAG_EXPORT | AV_OPT_FLAG_READONLY },
{ NULL },
};
@@ -275,7 +278,8 @@ static void add_pat_entry(MpegTSContext *ts, unsigned int programid)
ts->nb_prg++;
}
static void add_pid_to_pmt(MpegTSContext *ts, unsigned int programid, unsigned int pid)
static void add_pid_to_pmt(MpegTSContext *ts, unsigned int programid,
unsigned int pid)
{
struct Program *p = get_program(ts, programid);
if (!p)
@@ -321,12 +325,10 @@ static int discard_pid(MpegTSContext *ts, unsigned int pid)
struct Program *p;
/* If none of the programs have .discard=AVDISCARD_ALL then there's
* no way we have to discard this packet
*/
for (k = 0; k < ts->stream->nb_programs; k++) {
* no way we have to discard this packet */
for (k = 0; k < ts->stream->nb_programs; k++)
if (ts->stream->programs[k]->discard == AVDISCARD_ALL)
break;
}
if (k == ts->stream->nb_programs)
return 0;
@@ -384,7 +386,8 @@ static void write_section_data(AVFormatContext *s, MpegTSFilter *tss1,
tss->section_h_size = len;
}
if (tss->section_h_size != -1 && tss->section_index >= tss->section_h_size) {
if (tss->section_h_size != -1 &&
tss->section_index >= tss->section_h_size) {
int crc_valid = 1;
tss->end_of_section_reached = 1;
@@ -402,10 +405,11 @@ static void write_section_data(AVFormatContext *s, MpegTSFilter *tss1,
}
}
static MpegTSFilter *mpegts_open_section_filter(MpegTSContext *ts, unsigned int pid,
SectionCallback *section_cb, void *opaque,
static MpegTSFilter *mpegts_open_section_filter(MpegTSContext *ts,
unsigned int pid,
SectionCallback *section_cb,
void *opaque,
int check_crc)
{
MpegTSFilter *filter;
MpegTSSectionFilter *sec;
@@ -418,10 +422,12 @@ static MpegTSFilter *mpegts_open_section_filter(MpegTSContext *ts, unsigned int
if (!filter)
return NULL;
ts->pids[pid] = filter;
filter->type = MPEGTS_SECTION;
filter->pid = pid;
filter->es_id = -1;
filter->last_cc = -1;
sec = &filter->u.section_filter;
sec->section_cb = section_cb;
sec->opaque = opaque;
@@ -446,11 +452,13 @@ static MpegTSFilter *mpegts_open_pes_filter(MpegTSContext *ts, unsigned int pid,
filter = av_mallocz(sizeof(MpegTSFilter));
if (!filter)
return NULL;
ts->pids[pid] = filter;
filter->type = MPEGTS_PES;
filter->pid = pid;
filter->es_id = -1;
filter->last_cc = -1;
pes = &filter->u.pes_filter;
pes->pes_cb = pes_cb;
pes->opaque = opaque;
@@ -478,7 +486,8 @@ static void mpegts_close_filter(MpegTSContext *ts, MpegTSFilter *filter)
ts->pids[pid] = NULL;
}
static int analyze(const uint8_t *buf, int size, int packet_size, int *index){
static int analyze(const uint8_t *buf, int size, int packet_size, int *index)
{
int stat[TS_MAX_PACKET_SIZE];
int i;
int best_score = 0;
@@ -491,7 +500,8 @@ static int analyze(const uint8_t *buf, int size, int packet_size, int *index){
stat[x]++;
if (stat[x] > best_score) {
best_score = stat[x];
if(index) *index= x;
if (index)
*index = x;
}
}
}
@@ -513,10 +523,14 @@ static int get_packet_size(const uint8_t *buf, int size)
av_dlog(NULL, "score: %d, dvhs_score: %d, fec_score: %d \n",
score, dvhs_score, fec_score);
if (score > fec_score && score > dvhs_score) return TS_PACKET_SIZE;
else if(dvhs_score > score && dvhs_score > fec_score) return TS_DVHS_PACKET_SIZE;
else if(score < fec_score && dvhs_score < fec_score) return TS_FEC_PACKET_SIZE;
else return -1;
if (score > fec_score && score > dvhs_score)
return TS_PACKET_SIZE;
else if (dvhs_score > score && dvhs_score > fec_score)
return TS_DVHS_PACKET_SIZE;
else if (score < fec_score && dvhs_score < fec_score)
return TS_FEC_PACKET_SIZE;
else
return -1;
}
typedef struct SectionHeader {
@@ -683,14 +697,15 @@ static const StreamType DESC_types[] = {
};
static void mpegts_find_stream_type(AVStream *st,
uint32_t stream_type, const StreamType *types)
uint32_t stream_type,
const StreamType *types)
{
if (avcodec_is_open(st->codec)) {
av_log(NULL, AV_LOG_DEBUG, "cannot set stream info, codec is open\n");
return;
}
for (; types->stream_type; types++) {
for (; types->stream_type; types++)
if (stream_type == types->stream_type) {
st->codec->codec_type = types->codec_type;
st->codec->codec_id = types->codec_id;
@@ -698,7 +713,6 @@ static void mpegts_find_stream_type(AVStream *st,
return;
}
}
}
static int mpegts_set_stream_info(AVStream *st, PESContext *pes,
uint32_t stream_type, uint32_t prog_reg_desc)
@@ -774,7 +788,8 @@ static void new_pes_packet(PESContext *pes, AVPacket *pkt)
pkt->size = pes->data_index;
if (pes->total_size != MAX_PES_PAYLOAD &&
pes->pes_header_size + pes->data_index != pes->total_size + PES_START_SIZE) {
pes->pes_header_size + pes->data_index != pes->total_size +
PES_START_SIZE) {
av_log(pes->stream, AV_LOG_WARNING, "PES packet size mismatch\n");
pes->flags |= AV_PKT_FLAG_CORRUPT;
}
@@ -806,7 +821,8 @@ static uint64_t get_ts64(GetBitContext *gb, int bits)
return get_bits64(gb, bits);
}
static int read_sl_header(PESContext *pes, SLConfigDescr *sl, const uint8_t *buf, int buf_size)
static int read_sl_header(PESContext *pes, SLConfigDescr *sl,
const uint8_t *buf, int buf_size)
{
GetBitContext gb;
int au_start_flag = 0, au_end_flag = 0, ocr_flag = 0, idle_flag = 0;
@@ -910,15 +926,17 @@ static int mpegts_push_data(MpegTSFilter *filter,
buf_size -= len;
if (pes->data_index == PES_START_SIZE) {
/* we got all the PES or section header. We can now
decide */
* decide */
if (pes->header[0] == 0x00 && pes->header[1] == 0x00 &&
pes->header[2] == 0x01) {
/* it must be an mpeg2 PES stream */
code = pes->header[3] | 0x100;
av_dlog(pes->stream, "pid=%x pes_code=%#x\n", pes->pid, code);
av_dlog(pes->stream, "pid=%x pes_code=%#x\n", pes->pid,
code);
if ((pes->st && pes->st->discard == AVDISCARD_ALL &&
(!pes->sub_st || pes->sub_st->discard == AVDISCARD_ALL)) ||
(!pes->sub_st ||
pes->sub_st->discard == AVDISCARD_ALL)) ||
code == 0x1be) /* padding_stream */
goto skip;
@@ -933,7 +951,7 @@ static int mpegts_push_data(MpegTSFilter *filter,
pes->total_size = AV_RB16(pes->header + 4);
/* NOTE: a zero total size means the PES size is
unbounded */
* unbounded */
if (!pes->total_size)
pes->total_size = MAX_PES_PAYLOAD;
@@ -949,8 +967,10 @@ static int mpegts_push_data(MpegTSFilter *filter,
code != 0x1f8) { /* ITU-T Rec. H.222.1 type E stream */
pes->state = MPEGTS_PESHEADER;
if (pes->st->codec->codec_id == AV_CODEC_ID_NONE && !pes->st->request_probe) {
av_dlog(pes->stream, "pid=%x stream_type=%x probing\n",
pes->pid, pes->stream_type);
av_dlog(pes->stream,
"pid=%x stream_type=%x probing\n",
pes->pid,
pes->stream_type);
pes->st->request_probe = 1;
}
} else {
@@ -1029,7 +1049,8 @@ static int mpegts_push_data(MpegTSFilter *filter,
pes->state = MPEGTS_PAYLOAD;
pes->data_index = 0;
if (pes->stream_type == 0x12 && buf_size > 0) {
int sl_header_bytes = read_sl_header(pes, &pes->sl, p, buf_size);
int sl_header_bytes = read_sl_header(pes, &pes->sl, p,
buf_size);
pes->pes_header_size += sl_header_bytes;
p += sl_header_bytes;
buf_size -= sl_header_bytes;
@@ -1070,14 +1091,17 @@ static int mpegts_push_data(MpegTSFilter *filter,
break;
case MPEGTS_PAYLOAD:
if (buf_size > 0 && pes->buffer) {
if (pes->data_index > 0 && pes->data_index+buf_size > pes->total_size) {
if (pes->data_index > 0 &&
pes->data_index + buf_size > pes->total_size) {
new_pes_packet(pes, ts->pkt);
pes->total_size = MAX_PES_PAYLOAD;
pes->buffer = av_buffer_alloc(pes->total_size + FF_INPUT_BUFFER_PADDING_SIZE);
pes->buffer = av_buffer_alloc(pes->total_size +
FF_INPUT_BUFFER_PADDING_SIZE);
if (!pes->buffer)
return AVERROR(ENOMEM);
ts->stop_parse = 1;
} else if (pes->data_index == 0 && buf_size > pes->total_size) {
} else if (pes->data_index == 0 &&
buf_size > pes->total_size) {
// pes packet size is < ts size packet and pes data is padded with 0xff
// not sure if this is legal in ts but see issue #2392
buf_size = pes->total_size;
@@ -1142,9 +1166,9 @@ typedef struct {
int level;
} MP4DescrParseContext;
static int init_MP4DescrParseContext(
MP4DescrParseContext *d, AVFormatContext *s, const uint8_t *buf,
unsigned size, Mp4Descr *descr, int max_descr_count)
static int init_MP4DescrParseContext(MP4DescrParseContext *d, AVFormatContext *s,
const uint8_t *buf, unsigned size,
Mp4Descr *descr, int max_descr_count)
{
int ret;
if (size > (1 << 30))
@@ -1164,7 +1188,8 @@ static int init_MP4DescrParseContext(
return 0;
}
static void update_offsets(AVIOContext *pb, int64_t *off, int *len) {
static void update_offsets(AVIOContext *pb, int64_t *off, int *len)
{
int64_t new_off = avio_tell(pb);
(*len) -= new_off - *off;
*off = new_off;
@@ -1227,7 +1252,8 @@ static int parse_MP4ESDescrTag(MP4DescrParseContext *d, int64_t off, int len)
return 0;
}
static int parse_MP4DecConfigDescrTag(MP4DescrParseContext *d, int64_t off, int len)
static int parse_MP4DecConfigDescrTag(MP4DescrParseContext *d, int64_t off,
int len)
{
Mp4Descr *descr = d->active_descr;
if (!descr)
@@ -1279,12 +1305,15 @@ static int parse_MP4SLDescrTag(MP4DescrParseContext *d, int64_t off, int len)
}
static int parse_mp4_descr(MP4DescrParseContext *d, int64_t off, int len,
int target_tag) {
int target_tag)
{
int tag;
int len1 = ff_mp4_read_descr(d->s, &d->pb, &tag);
update_offsets(&d->pb, &off, &len);
if (len < 0 || len1 > len || len1 <= 0) {
av_log(d->s, AV_LOG_ERROR, "Tag %x length violation new length %d bytes remaining %d\n", tag, len1, len);
av_log(d->s, AV_LOG_ERROR,
"Tag %x length violation new length %d bytes remaining %d\n",
tag, len1, len);
return -1;
}
@@ -1294,7 +1323,8 @@ static int parse_mp4_descr(MP4DescrParseContext *d, int64_t off, int len,
}
if (target_tag && tag != target_tag) {
av_log(d->s, AV_LOG_ERROR, "Found tag %x expected %x\n", tag, target_tag);
av_log(d->s, AV_LOG_ERROR, "Found tag %x expected %x\n", tag,
target_tag);
goto done;
}
@@ -1348,14 +1378,15 @@ static int mp4_read_od(AVFormatContext *s, const uint8_t *buf, unsigned size,
return 0;
}
static void m4sl_cb(MpegTSFilter *filter, const uint8_t *section, int section_len)
static void m4sl_cb(MpegTSFilter *filter, const uint8_t *section,
int section_len)
{
MpegTSContext *ts = filter->u.section_filter.opaque;
SectionHeader h;
const uint8_t *p, *p_end;
AVIOContext pb;
Mp4Descr mp4_descr[MAX_MP4_DESCR_COUNT] = {{ 0 }};
int mp4_descr_count = 0;
Mp4Descr mp4_descr[MAX_MP4_DESCR_COUNT] = { { 0 } };
int i, pid;
AVFormatContext *s = ts->stream;
@@ -1366,7 +1397,8 @@ static void m4sl_cb(MpegTSFilter *filter, const uint8_t *section, int section_le
if (h.tid != M4OD_TID)
return;
mp4_read_od(s, p, (unsigned)(p_end - p), mp4_descr, &mp4_descr_count, MAX_MP4_DESCR_COUNT);
mp4_read_od(s, p, (unsigned) (p_end - p), mp4_descr, &mp4_descr_count,
MAX_MP4_DESCR_COUNT);
for (pid = 0; pid < NB_PID_MAX; pid++) {
if (!ts->pids[pid])
@@ -1382,14 +1414,14 @@ static void m4sl_cb(MpegTSFilter *filter, const uint8_t *section, int section_le
}
pes = ts->pids[pid]->u.pes_filter.opaque;
st = pes->st;
if (!st) {
if (!st)
continue;
}
pes->sl = mp4_descr[i].sl;
ffio_init_context(&pb, mp4_descr[i].dec_config_descr,
mp4_descr[i].dec_config_descr_len, 0, NULL, NULL, NULL, NULL);
mp4_descr[i].dec_config_descr_len, 0,
NULL, NULL, NULL, NULL);
ff_mp4_read_dec_config_descr(s, st, &pb);
if (st->codec->codec_id == AV_CODEC_ID_AAC &&
st->codec->extradata_size > 0)
@@ -1399,15 +1431,15 @@ static void m4sl_cb(MpegTSFilter *filter, const uint8_t *section, int section_le
st->need_parsing = 0;
if (st->codec->codec_id <= AV_CODEC_ID_NONE) {
} else if (st->codec->codec_id < AV_CODEC_ID_FIRST_AUDIO) {
// do nothing
} else if (st->codec->codec_id < AV_CODEC_ID_FIRST_AUDIO)
st->codec->codec_type = AVMEDIA_TYPE_VIDEO;
} else if (st->codec->codec_id < AV_CODEC_ID_FIRST_SUBTITLE) {
else if (st->codec->codec_id < AV_CODEC_ID_FIRST_SUBTITLE)
st->codec->codec_type = AVMEDIA_TYPE_AUDIO;
} else if (st->codec->codec_id < AV_CODEC_ID_FIRST_UNKNOWN) {
else if (st->codec->codec_id < AV_CODEC_ID_FIRST_UNKNOWN)
st->codec->codec_type = AVMEDIA_TYPE_SUBTITLE;
}
}
}
for (i = 0; i < mp4_descr_count; i++)
av_free(mp4_descr[i].dec_config_descr);
}
@@ -1448,7 +1480,8 @@ int ff_parse_mpeg2_descriptor(AVFormatContext *fc, AVStream *st, int stream_type
mp4_descr[i].es_id == desc_es_id) {
AVIOContext pb;
ffio_init_context(&pb, mp4_descr[i].dec_config_descr,
mp4_descr[i].dec_config_descr_len, 0, NULL, NULL, NULL, NULL);
mp4_descr[i].dec_config_descr_len, 0,
NULL, NULL, NULL, NULL);
ff_mp4_read_dec_config_descr(fc, st, &pb);
if (st->codec->codec_id == AV_CODEC_ID_AAC &&
st->codec->extradata_size > 0)
@@ -1459,11 +1492,13 @@ int ff_parse_mpeg2_descriptor(AVFormatContext *fc, AVStream *st, int stream_type
break;
case 0x1F: /* FMC descriptor */
get16(pp, desc_end);
if (mp4_descr_count > 0 && (st->codec->codec_id == AV_CODEC_ID_AAC_LATM || st->request_probe>0) &&
if (mp4_descr_count > 0 &&
(st->codec->codec_id == AV_CODEC_ID_AAC_LATM || st->request_probe > 0) &&
mp4_descr->dec_config_descr_len && mp4_descr->es_id == pid) {
AVIOContext pb;
ffio_init_context(&pb, mp4_descr->dec_config_descr,
mp4_descr->dec_config_descr_len, 0, NULL, NULL, NULL, NULL);
mp4_descr->dec_config_descr_len, 0,
NULL, NULL, NULL, NULL);
ff_mp4_read_dec_config_descr(fc, st, &pb);
if (st->codec->codec_id == AV_CODEC_ID_AAC &&
st->codec->extradata_size > 0) {
@@ -1586,9 +1621,15 @@ int ff_parse_mpeg2_descriptor(AVFormatContext *fc, AVStream *st, int stream_type
language[i + 2] = get8(pp, desc_end);
language[i + 3] = ',';
switch (get8(pp, desc_end)) {
case 0x01: st->disposition |= AV_DISPOSITION_CLEAN_EFFECTS; break;
case 0x02: st->disposition |= AV_DISPOSITION_HEARING_IMPAIRED; break;
case 0x03: st->disposition |= AV_DISPOSITION_VISUAL_IMPAIRED; break;
case 0x01:
st->disposition |= AV_DISPOSITION_CLEAN_EFFECTS;
break;
case 0x02:
st->disposition |= AV_DISPOSITION_HEARING_IMPAIRED;
break;
case 0x03:
st->disposition |= AV_DISPOSITION_VISUAL_IMPAIRED;
break;
}
}
if (i) {
@@ -1632,8 +1673,8 @@ static void pmt_cb(MpegTSFilter *filter, const uint8_t *section, int section_len
int desc_list_len;
uint32_t prog_reg_desc = 0; /* registration descriptor */
Mp4Descr mp4_descr[MAX_MP4_DESCR_COUNT] = {{ 0 }};
int mp4_descr_count = 0;
Mp4Descr mp4_descr[MAX_MP4_DESCR_COUNT] = { { 0 } };
int i;
av_dlog(ts->stream, "PMT: len %i\n", section_len);
@@ -1697,6 +1738,7 @@ static void pmt_cb(MpegTSFilter *filter, const uint8_t *section, int section_len
set_pmt_found(ts, h->id);
for (;;) {
st = 0;
pes = NULL;
@@ -1721,7 +1763,8 @@ static void pmt_cb(MpegTSFilter *filter, const uint8_t *section, int section_len
}
st = pes->st;
} else if (stream_type != 0x13) {
if (ts->pids[pid]) mpegts_close_filter(ts, ts->pids[pid]); //wrongly added sdt filter probably
if (ts->pids[pid])
mpegts_close_filter(ts, ts->pids[pid]); // wrongly added sdt filter probably
pes = add_pes_stream(ts, pid, pcr_pid);
if (pes) {
st = avformat_new_stream(pes->stream, NULL);
@@ -1760,12 +1803,15 @@ static void pmt_cb(MpegTSFilter *filter, const uint8_t *section, int section_len
if (desc_list_end > p_end)
goto out;
for (;;) {
if (ff_parse_mpeg2_descriptor(ts->stream, st, stream_type, &p, desc_list_end,
mp4_descr, mp4_descr_count, pid, ts) < 0)
if (ff_parse_mpeg2_descriptor(ts->stream, st, stream_type, &p,
desc_list_end, mp4_descr,
mp4_descr_count, pid, ts) < 0)
break;
if (pes && prog_reg_desc == AV_RL32("HDMV") && stream_type == 0x83 && pes->sub_st) {
ff_program_add_stream_index(ts->stream, h->id, pes->sub_st->index);
if (pes && prog_reg_desc == AV_RL32("HDMV") &&
stream_type == 0x83 && pes->sub_st) {
ff_program_add_stream_index(ts->stream, h->id,
pes->sub_st->index);
pes->sub_st->codec->codec_tag = st->codec->codec_tag;
}
}
@@ -1907,7 +1953,8 @@ static void sdt_cb(MpegTSFilter *filter, const uint8_t *section, int section_len
AVProgram *program = av_new_program(ts->stream, sid);
if (program) {
av_dict_set(&program->metadata, "service_name", name, 0);
av_dict_set(&program->metadata, "service_provider", provider_name, 0);
av_dict_set(&program->metadata, "service_provider",
provider_name, 0);
}
}
av_free(name);
@@ -1953,17 +2000,17 @@ static int handle_packet(MpegTSContext *ts, const uint8_t *packet)
return 0;
has_adaptation = afc & 2;
has_payload = afc & 1;
is_discontinuity = has_adaptation
&& packet[4] != 0 /* with length > 0 */
&& (packet[5] & 0x80); /* and discontinuity indicated */
is_discontinuity = has_adaptation &&
packet[4] != 0 && /* with length > 0 */
(packet[5] & 0x80); /* and discontinuity indicated */
/* continuity check (currently not used) */
cc = (packet[3] & 0xf);
expected_cc = has_payload ? (tss->last_cc + 1) & 0x0f : tss->last_cc;
cc_ok = pid == 0x1FFF // null packet PID
|| is_discontinuity
|| tss->last_cc < 0
|| expected_cc == cc;
cc_ok = pid == 0x1FFF || // null packet PID
is_discontinuity ||
tss->last_cc < 0 ||
expected_cc == cc;
tss->last_cc = cc;
if (!cc_ok) {
@@ -2086,7 +2133,7 @@ static void reanalyze(MpegTSContext *ts) {
}
/* XXX: try to find a better synchro over several packets (use
get_packet_size() ?) */
* get_packet_size() ?) */
static int mpegts_resync(AVFormatContext *s)
{
AVIOContext *pb = s->pb;
@@ -2102,13 +2149,15 @@ static int mpegts_resync(AVFormatContext *s)
return 0;
}
}
av_log(s, AV_LOG_ERROR, "max resync size reached, could not find sync byte\n");
av_log(s, AV_LOG_ERROR,
"max resync size reached, could not find sync byte\n");
/* no sync found */
return -1;
}
/* return -1 if error or EOF. Return 0 if OK. */
static int read_packet(AVFormatContext *s, uint8_t *buf, int raw_packet_size, const uint8_t **data)
static int read_packet(AVFormatContext *s, uint8_t *buf, int raw_packet_size,
const uint8_t **data)
{
AVIOContext *pb = s->pb;
int len;
@@ -2222,13 +2271,13 @@ static int mpegts_probe(AVProbeData *p)
if (sumscore > 6) return AVPROBE_SCORE_MAX + sumscore - CHECK_COUNT;
else if (maxscore > 6) return AVPROBE_SCORE_MAX/2 + sumscore - CHECK_COUNT;
else return -1;
else
return -1;
}
/* return the 90kHz PCR and the extension for the 27MHz PCR. return
(-1) if not available */
static int parse_pcr(int64_t *ppcr_high, int *ppcr_low,
const uint8_t *packet)
* (-1) if not available */
static int parse_pcr(int64_t *ppcr_high, int *ppcr_low, const uint8_t *packet)
{
int afc, len, flags;
const uint8_t *p;
@@ -2347,7 +2396,7 @@ static int mpegts_read_header(AVFormatContext *s)
/* NOTE2: it is only the bitrate of the start of the stream */
ts->pcr_incr = (pcrs[1] - pcrs[0]) / (packet_count[1] - packet_count[0]);
ts->cur_pcr = pcrs[0] - ts->pcr_incr * packet_count[0];
s->bit_rate = (TS_PACKET_SIZE * 8) * 27e6 / ts->pcr_incr;
s->bit_rate = TS_PACKET_SIZE * 8 * 27e6 / ts->pcr_incr;
st->codec->bit_rate = s->bit_rate;
st->start_time = ts->cur_pcr;
av_dlog(ts->stream, "start=%0.3f pcr=%0.3f incr=%d\n",
@@ -2362,8 +2411,7 @@ static int mpegts_read_header(AVFormatContext *s)
#define MAX_PACKET_READAHEAD ((128 * 1024) / 188)
static int mpegts_raw_read_packet(AVFormatContext *s,
AVPacket *pkt)
static int mpegts_raw_read_packet(AVFormatContext *s, AVPacket *pkt)
{
MpegTSContext *ts = s->priv_data;
int ret, i;
@@ -2374,8 +2422,8 @@ static int mpegts_raw_read_packet(AVFormatContext *s,
if (av_new_packet(pkt, TS_PACKET_SIZE) < 0)
return AVERROR(ENOMEM);
pkt->pos= avio_tell(s->pb);
ret = read_packet(s, pkt->data, ts->raw_packet_size, &data);
pkt->pos = avio_tell(s->pb);
if (ret < 0) {
av_free_packet(pkt);
return ret;
@@ -2393,7 +2441,8 @@ static int mpegts_raw_read_packet(AVFormatContext *s,
avio_read(s->pb, pcr_buf, 12);
if (parse_pcr(&next_pcr_h, &next_pcr_l, pcr_buf) == 0) {
/* XXX: not precise enough */
ts->pcr_incr = ((next_pcr_h - pcr_h) * 300 + (next_pcr_l - pcr_l)) /
ts->pcr_incr =
((next_pcr_h - pcr_h) * 300 + (next_pcr_l - pcr_l)) /
(i + 1);
break;
}
@@ -2410,8 +2459,7 @@ static int mpegts_raw_read_packet(AVFormatContext *s,
return 0;
}
static int mpegts_read_packet(AVFormatContext *s,
AVPacket *pkt)
static int mpegts_read_packet(AVFormatContext *s, AVPacket *pkt)
{
MpegTSContext *ts = s->priv_data;
int ret, i;
@@ -2422,7 +2470,7 @@ static int mpegts_read_packet(AVFormatContext *s,
if (ret < 0) {
av_free_packet(ts->pkt);
/* flush pes data left */
for (i = 0; i < NB_PID_MAX; i++) {
for (i = 0; i < NB_PID_MAX; i++)
if (ts->pids[i] && ts->pids[i]->type == MPEGTS_PES) {
PESContext *pes = ts->pids[i]->u.pes_filter.opaque;
if (pes->state == MPEGTS_PAYLOAD && pes->data_index > 0) {
@@ -2433,7 +2481,6 @@ static int mpegts_read_packet(AVFormatContext *s,
}
}
}
}
if (!ret && pkt->size < 0)
ret = AVERROR(EINTR);
@@ -2447,7 +2494,8 @@ static void mpegts_free(MpegTSContext *ts)
clear_programs(ts);
for (i = 0; i < NB_PID_MAX; i++)
if (ts->pids[i]) mpegts_close_filter(ts, ts->pids[i]);
if (ts->pids[i])
mpegts_close_filter(ts, ts->pids[i]);
}
static int mpegts_read_close(AVFormatContext *s)
@@ -2463,9 +2511,12 @@ 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 pos47 = ts->pos47_full % ts->raw_packet_size;
pos = ((*ppos + ts->raw_packet_size - 1 - pos47) / ts->raw_packet_size) * ts->raw_packet_size + pos47;
pos =
((*ppos + ts->raw_packet_size - 1 - pos47) / ts->raw_packet_size) *
ts->raw_packet_size + pos47;
while(pos < pos_limit) {
if (avio_seek(s->pb, pos, SEEK_SET) < 0)
return AV_NOPTS_VALUE;
@@ -2542,7 +2593,7 @@ MpegTSContext *ff_mpegts_parse_open(AVFormatContext *s)
}
/* return the consumed length if a packet was output, or -1 if no
packet is output */
* packet is output */
int ff_mpegts_parse_packet(MpegTSContext *ts, AVPacket *pkt,
const uint8_t *buf, int len)
{