mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2024-11-26 19:01:44 +02:00
avformat/mpegts: rework clearing and adding pid to program
And use better function names. Signed-off-by: Marton Balint <cus@passwd.hu>
This commit is contained in:
parent
5ea37923a8
commit
10c8e53294
@ -285,16 +285,12 @@ static void clear_avprogram(MpegTSContext *ts, unsigned int programid)
|
|||||||
prg->nb_stream_indexes = 0;
|
prg->nb_stream_indexes = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void clear_program(MpegTSContext *ts, unsigned int programid)
|
static void clear_program(struct Program *p)
|
||||||
{
|
{
|
||||||
int i;
|
if (!p)
|
||||||
|
return;
|
||||||
clear_avprogram(ts, programid);
|
p->nb_pids = 0;
|
||||||
for (i = 0; i < ts->nb_prg; i++)
|
p->pmt_found = 0;
|
||||||
if (ts->prg[i].id == programid) {
|
|
||||||
ts->prg[i].nb_pids = 0;
|
|
||||||
ts->prg[i].pmt_found = 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void clear_programs(MpegTSContext *ts)
|
static void clear_programs(MpegTSContext *ts)
|
||||||
@ -303,24 +299,22 @@ static void clear_programs(MpegTSContext *ts)
|
|||||||
ts->nb_prg = 0;
|
ts->nb_prg = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void add_pat_entry(MpegTSContext *ts, unsigned int programid)
|
static struct Program * add_program(MpegTSContext *ts, unsigned int programid)
|
||||||
{
|
{
|
||||||
struct Program *p;
|
struct Program *p;
|
||||||
if (av_reallocp_array(&ts->prg, ts->nb_prg + 1, sizeof(*ts->prg)) < 0) {
|
if (av_reallocp_array(&ts->prg, ts->nb_prg + 1, sizeof(*ts->prg)) < 0) {
|
||||||
ts->nb_prg = 0;
|
ts->nb_prg = 0;
|
||||||
return;
|
return NULL;
|
||||||
}
|
}
|
||||||
p = &ts->prg[ts->nb_prg];
|
p = &ts->prg[ts->nb_prg];
|
||||||
p->id = programid;
|
p->id = programid;
|
||||||
p->nb_pids = 0;
|
clear_program(p);
|
||||||
p->pmt_found = 0;
|
|
||||||
ts->nb_prg++;
|
ts->nb_prg++;
|
||||||
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void add_pid_to_pmt(MpegTSContext *ts, unsigned int programid,
|
static void add_pid_to_program(struct Program *p, unsigned int pid)
|
||||||
unsigned int pid)
|
|
||||||
{
|
{
|
||||||
struct Program *p = get_program(ts, programid);
|
|
||||||
int i;
|
int i;
|
||||||
if (!p)
|
if (!p)
|
||||||
return;
|
return;
|
||||||
@ -335,15 +329,6 @@ static void add_pid_to_pmt(MpegTSContext *ts, unsigned int programid,
|
|||||||
p->pids[p->nb_pids++] = pid;
|
p->pids[p->nb_pids++] = pid;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void set_pmt_found(MpegTSContext *ts, unsigned int programid)
|
|
||||||
{
|
|
||||||
struct Program *p = get_program(ts, programid);
|
|
||||||
if (!p)
|
|
||||||
return;
|
|
||||||
|
|
||||||
p->pmt_found = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void update_av_program_info(AVFormatContext *s, unsigned int programid,
|
static void update_av_program_info(AVFormatContext *s, unsigned int programid,
|
||||||
unsigned int pid, int version)
|
unsigned int pid, int version)
|
||||||
{
|
{
|
||||||
@ -2290,6 +2275,7 @@ static void pmt_cb(MpegTSFilter *filter, const uint8_t *section, int section_len
|
|||||||
int desc_list_len;
|
int desc_list_len;
|
||||||
uint32_t prog_reg_desc = 0; /* registration descriptor */
|
uint32_t prog_reg_desc = 0; /* registration descriptor */
|
||||||
int stream_identifier = -1;
|
int stream_identifier = -1;
|
||||||
|
struct Program *prg;
|
||||||
|
|
||||||
int mp4_descr_count = 0;
|
int mp4_descr_count = 0;
|
||||||
Mp4Descr mp4_descr[MAX_MP4_DESCR_COUNT] = { { 0 } };
|
Mp4Descr mp4_descr[MAX_MP4_DESCR_COUNT] = { { 0 } };
|
||||||
@ -2313,16 +2299,20 @@ static void pmt_cb(MpegTSFilter *filter, const uint8_t *section, int section_len
|
|||||||
if (!ts->scan_all_pmts && ts->skip_changes)
|
if (!ts->scan_all_pmts && ts->skip_changes)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (ts->skip_unknown_pmt && !get_program(ts, h->id))
|
prg = get_program(ts, h->id);
|
||||||
|
|
||||||
|
if (ts->skip_unknown_pmt && !prg)
|
||||||
return;
|
return;
|
||||||
if (!ts->skip_clear)
|
if (!ts->skip_clear) {
|
||||||
clear_program(ts, h->id);
|
clear_avprogram(ts, h->id);
|
||||||
|
clear_program(prg);
|
||||||
|
}
|
||||||
|
|
||||||
pcr_pid = get16(&p, p_end);
|
pcr_pid = get16(&p, p_end);
|
||||||
if (pcr_pid < 0)
|
if (pcr_pid < 0)
|
||||||
return;
|
return;
|
||||||
pcr_pid &= 0x1fff;
|
pcr_pid &= 0x1fff;
|
||||||
add_pid_to_pmt(ts, h->id, pcr_pid);
|
add_pid_to_program(prg, pcr_pid);
|
||||||
update_av_program_info(ts->stream, h->id, pcr_pid, h->version);
|
update_av_program_info(ts->stream, h->id, pcr_pid, h->version);
|
||||||
|
|
||||||
av_log(ts->stream, AV_LOG_TRACE, "pcr_pid=0x%x\n", pcr_pid);
|
av_log(ts->stream, AV_LOG_TRACE, "pcr_pid=0x%x\n", pcr_pid);
|
||||||
@ -2362,8 +2352,8 @@ static void pmt_cb(MpegTSFilter *filter, const uint8_t *section, int section_len
|
|||||||
if (!ts->pkt)
|
if (!ts->pkt)
|
||||||
ts->stop_parse = 2;
|
ts->stop_parse = 2;
|
||||||
|
|
||||||
set_pmt_found(ts, h->id);
|
if (prg)
|
||||||
|
prg->pmt_found = 1;
|
||||||
|
|
||||||
for (i = 0; ; i++) {
|
for (i = 0; ; i++) {
|
||||||
st = 0;
|
st = 0;
|
||||||
@ -2453,7 +2443,7 @@ static void pmt_cb(MpegTSFilter *filter, const uint8_t *section, int section_len
|
|||||||
if (pes && !pes->stream_type)
|
if (pes && !pes->stream_type)
|
||||||
mpegts_set_stream_info(st, pes, stream_type, prog_reg_desc);
|
mpegts_set_stream_info(st, pes, stream_type, prog_reg_desc);
|
||||||
|
|
||||||
add_pid_to_pmt(ts, h->id, pid);
|
add_pid_to_program(prg, pid);
|
||||||
|
|
||||||
av_program_add_stream_index(ts->stream, h->id, st->index);
|
av_program_add_stream_index(ts->stream, h->id, st->index);
|
||||||
|
|
||||||
@ -2532,6 +2522,7 @@ static void pat_cb(MpegTSFilter *filter, const uint8_t *section, int section_len
|
|||||||
/* NIT info */
|
/* NIT info */
|
||||||
} else {
|
} else {
|
||||||
MpegTSFilter *fil = ts->pids[pmt_pid];
|
MpegTSFilter *fil = ts->pids[pmt_pid];
|
||||||
|
struct Program *prg;
|
||||||
program = av_new_program(ts->stream, sid);
|
program = av_new_program(ts->stream, sid);
|
||||||
if (program) {
|
if (program) {
|
||||||
program->program_num = sid;
|
program->program_num = sid;
|
||||||
@ -2545,8 +2536,8 @@ static void pat_cb(MpegTSFilter *filter, const uint8_t *section, int section_len
|
|||||||
|
|
||||||
if (!ts->pids[pmt_pid])
|
if (!ts->pids[pmt_pid])
|
||||||
mpegts_open_section_filter(ts, pmt_pid, pmt_cb, ts, 1);
|
mpegts_open_section_filter(ts, pmt_pid, pmt_cb, ts, 1);
|
||||||
add_pat_entry(ts, sid);
|
prg = add_program(ts, sid);
|
||||||
add_pid_to_pmt(ts, sid, pmt_pid);
|
add_pid_to_program(prg, pmt_pid);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user