if (sys > invalid && sys * 9 <= pspack * 10)
return (audio > 12 || vid > 3 || pspack > 2) ? AVPROBE_SCORE_EXTENSION + 2
- : AVPROBE_SCORE_EXTENSION / 2 + 1; // 1 more than mp3
+ : AVPROBE_SCORE_EXTENSION / 2 + (audio + vid + pspack > 1); // 1 more than mp3
if (pspack > invalid && (priv1 + vid + audio) * 10 >= pspack * 9)
return pspack > 2 ? AVPROBE_SCORE_EXTENSION + 2
: AVPROBE_SCORE_EXTENSION / 2; // 1 more than .mpg
static int64_t get_pts(AVIOContext *pb, int c)
{
uint8_t buf[5];
+ int ret;
buf[0] = c < 0 ? avio_r8(pb) : c;
- avio_read(pb, buf + 1, 4);
+ ret = avio_read(pb, buf + 1, 4);
+ if (ret < 4)
+ return AV_NOPTS_VALUE;
return ff_parse_pes_pts(buf);
}
st->codecpar->channel_layout = AV_CH_LAYOUT_MONO;
st->codecpar->sample_rate = 8000;
}
- st->request_probe = request_probe;
+ st->internal->request_probe = request_probe;
st->need_parsing = AVSTREAM_PARSE_FULL;
found:
return dts;
}
-AVInputFormat ff_mpegps_demuxer = {
+const AVInputFormat ff_mpegps_demuxer = {
.name = "mpeg",
.long_name = NULL_IF_CONFIG_SMALL("MPEG-PS (MPEG-2 Program Stream)"),
.priv_data_size = sizeof(MpegDemuxContext),
return 0;
}
+static int vobsub_read_close(AVFormatContext *s)
+{
+ VobSubDemuxContext *vobsub = s->priv_data;
+ int i;
+
+ for (i = 0; i < s->nb_streams; i++)
+ ff_subtitles_queue_clean(&vobsub->q[i]);
+ if (vobsub->sub_ctx)
+ avformat_close_input(&vobsub->sub_ctx);
+ return 0;
+}
+
static int vobsub_read_header(AVFormatContext *s)
{
int i, ret = 0, header_parsed = 0, langidx = 0;
VobSubDemuxContext *vobsub = s->priv_data;
+ const AVInputFormat *iformat;
size_t fname_len;
AVBPrint header;
int64_t delay = 0;
int stream_id = -1;
char id[64] = {0};
char alt[MAX_LINE_SIZE] = {0};
- ff_const59 AVInputFormat *iformat;
if (!vobsub->sub_name) {
char *ext;
memcpy(par->extradata, header.str, header.len);
}
end:
-
+ if (ret < 0)
+ vobsub_read_close(s);
av_bprint_finalize(&header, NULL);
return ret;
}
FFDemuxSubtitlesQueue *q;
AVIOContext *pb = vobsub->sub_ctx->pb;
int ret, psize, total_read = 0, i;
- AVPacket idx_pkt = { 0 };
int64_t min_ts = INT64_MAX;
int sid = 0;
FFDemuxSubtitlesQueue *tmpq = &vobsub->q[i];
int64_t ts;
av_assert0(tmpq->nb_subs);
- ts = tmpq->subs[tmpq->current_sub_idx].pts;
+
+ if (tmpq->current_sub_idx >= tmpq->nb_subs)
+ continue;
+
+ ts = tmpq->subs[tmpq->current_sub_idx]->pts;
if (ts < min_ts) {
min_ts = ts;
sid = i;
}
}
q = &vobsub->q[sid];
- ret = ff_subtitles_queue_read_packet(q, &idx_pkt);
+ /* The returned packet will have size zero,
+ * so that it can be directly used with av_grow_packet. */
+ ret = ff_subtitles_queue_read_packet(q, pkt);
if (ret < 0)
return ret;
/* compute maximum packet size using the next packet position. This is
* useful when the len in the header is non-sense */
if (q->current_sub_idx < q->nb_subs) {
- psize = q->subs[q->current_sub_idx].pos - idx_pkt.pos;
+ psize = q->subs[q->current_sub_idx]->pos - pkt->pos;
} else {
int64_t fsize = avio_size(pb);
- psize = fsize < 0 ? 0xffff : fsize - idx_pkt.pos;
+ psize = fsize < 0 ? 0xffff : fsize - pkt->pos;
}
- avio_seek(pb, idx_pkt.pos, SEEK_SET);
-
- av_init_packet(pkt);
- pkt->size = 0;
- pkt->data = NULL;
+ avio_seek(pb, pkt->pos, SEEK_SET);
do {
int n, to_read, startcode;
if (ret < 0) {
if (pkt->size) // raise packet even if incomplete
break;
- goto fail;
+ return ret;
}
to_read = ret & 0xffff;
new_pos = avio_tell(pb);
total_read += pkt_size;
/* the current chunk doesn't match the stream index (unlikely) */
- if ((startcode & 0x1f) != s->streams[idx_pkt.stream_index]->id)
+ if ((startcode & 0x1f) != s->streams[pkt->stream_index]->id)
break;
ret = av_grow_packet(pkt, to_read);
if (ret < 0)
- goto fail;
+ return ret;
n = avio_read(pb, pkt->data + (pkt->size - to_read), to_read);
if (n < to_read)
pkt->size -= to_read - n;
} while (total_read < psize);
- pkt->pts = pkt->dts = idx_pkt.pts;
- pkt->pos = idx_pkt.pos;
- pkt->stream_index = idx_pkt.stream_index;
-
- av_packet_unref(&idx_pkt);
return 0;
-
-fail:
- av_packet_unref(pkt);
- av_packet_unref(&idx_pkt);
- return ret;
}
static int vobsub_read_seek(AVFormatContext *s, int stream_index,
min_ts, ts, max_ts, flags);
}
-static int vobsub_read_close(AVFormatContext *s)
-{
- VobSubDemuxContext *vobsub = s->priv_data;
- int i;
-
- for (i = 0; i < s->nb_streams; i++)
- ff_subtitles_queue_clean(&vobsub->q[i]);
- if (vobsub->sub_ctx)
- avformat_close_input(&vobsub->sub_ctx);
- return 0;
-}
-
static const AVOption options[] = {
{ "sub_name", "URI for .sub file", offsetof(VobSubDemuxContext, sub_name), AV_OPT_TYPE_STRING, { .str = NULL }, 0, 0, AV_OPT_FLAG_DECODING_PARAM },
{ NULL }
.version = LIBAVUTIL_VERSION_INT,
};
-AVInputFormat ff_vobsub_demuxer = {
+const AVInputFormat ff_vobsub_demuxer = {
.name = "vobsub",
.long_name = NULL_IF_CONFIG_SMALL("VobSub subtitle format"),
.priv_data_size = sizeof(VobSubDemuxContext),