Commit 29245147 authored by Michael Niedermayer's avatar Michael Niedermayer

Merge commit '9deaec78'

* commit '9deaec78':
  lavf: move internal fields from public to internal context

Conflicts:
	libavformat/avformat.h
	libavformat/internal.h
	libavformat/mux.c
	libavformat/utils.c
Merged-by: 's avatarMichael Niedermayer <michaelni@gmx.at>
parents b61170f5 9deaec78
......@@ -909,7 +909,7 @@ static int asf_get_packet(AVFormatContext *s, AVIOContext *pb)
if (asf->no_resync_search)
off = 3;
else if (s->packet_size > 0)
off = (avio_tell(pb) - s->data_offset) % s->packet_size + 3;
off = (avio_tell(pb) - s->internal->data_offset) % s->packet_size + 3;
c = d = e = -1;
while (off-- > 0) {
......@@ -1445,9 +1445,9 @@ static int64_t asf_read_pts(AVFormatContext *s, int stream_index,
start_pos[i] = pos;
if (s->packet_size > 0)
pos = (pos + s->packet_size - 1 - s->data_offset) /
pos = (pos + s->packet_size - 1 - s->internal->data_offset) /
s->packet_size * s->packet_size +
s->data_offset;
s->internal->data_offset;
*ppos = pos;
if (avio_seek(s->pb, pos, SEEK_SET) < 0)
return AV_NOPTS_VALUE;
......@@ -1526,7 +1526,7 @@ static int asf_build_simple_index(AVFormatContext *s, int stream_index)
for (i = 0; i < ict; i++) {
int pktnum = avio_rl32(s->pb);
int pktct = avio_rl16(s->pb);
int64_t pos = s->data_offset + s->packet_size * (int64_t)pktnum;
int64_t pos = s->internal->data_offset + s->packet_size * (int64_t)pktnum;
int64_t index_pts = FFMAX(av_rescale(itime, i, 10000) - asf->hdr.preroll, 0);
if (pos != last_pos) {
......@@ -1569,7 +1569,7 @@ static int asf_read_seek(AVFormatContext *s, int stream_index,
/* explicitly handle the case of seeking to 0 */
if (!pts) {
asf_reset_header(s);
avio_seek(s->pb, s->data_offset, SEEK_SET);
avio_seek(s->pb, s->internal->data_offset, SEEK_SET);
return 0;
}
......
......@@ -1503,7 +1503,6 @@ typedef struct AVFormatContext {
#define AVFMT_AVOID_NEG_TS_MAKE_NON_NEGATIVE 1 ///< Shift timestamps so they are non negative
#define AVFMT_AVOID_NEG_TS_MAKE_ZERO 2 ///< Shift timestamps so that they start at 0
/**
* Transport stream id.
* This will be moved into demuxer private options. Thus no API/ABI compatibility
......@@ -1617,56 +1616,6 @@ typedef struct AVFormatContext {
*/
char *format_whitelist;
/*****************************************************************
* All fields below this line are not part of the public API. They
* may not be used outside of libavformat and can be changed and
* removed at will.
* New public fields should be added right above.
*****************************************************************
*/
/**
* This buffer is only needed when packets were already buffered but
* not decoded, for example to get the codec parameters in MPEG
* streams.
*/
struct AVPacketList *packet_buffer;
struct AVPacketList *packet_buffer_end;
/* av_seek_frame() support */
int64_t data_offset; /**< offset of the first packet */
/**
* Raw packets from the demuxer, prior to parsing and decoding.
* This buffer is used for buffering packets until the codec can
* be identified, as parsing cannot be done without knowing the
* codec.
*/
struct AVPacketList *raw_packet_buffer;
struct AVPacketList *raw_packet_buffer_end;
/**
* Packets split by the parser get queued here.
*/
struct AVPacketList *parse_queue;
struct AVPacketList *parse_queue_end;
/**
* Remaining size available for raw_packet_buffer, in bytes.
*/
#define RAW_PACKET_BUFFER_SIZE 2500000
int raw_packet_buffer_remaining_size;
/**
* Offset to remap timestamps to be non-negative.
* Expressed in timebase units.
* @see AVStream.mux_ts_offset
*/
int64_t offset;
/**
* Timebase for the timestamp offset.
*/
AVRational offset_timebase;
/**
* An opaque field for libavformat internal usage.
* Must not be accessed in any way by callers.
......
......@@ -21,6 +21,7 @@
#include "libavutil/intreadwrite.h"
#include "avformat.h"
#include "internal.h"
static int probe(AVProbeData *p)
{
......@@ -52,11 +53,11 @@ static int read_header(AVFormatContext *s)
avio_rl32(s->pb);
st->codec->sample_rate = avio_rl32(s->pb);
st->codec->channels = avio_rl32(s->pb);
s->data_offset = avio_rl32(s->pb);
s->internal->data_offset = avio_rl32(s->pb);
avio_r8(s->pb);
st->codec->block_align = st->codec->channels * avio_rl32(s->pb);
avio_seek(s->pb, s->data_offset, SEEK_SET);
avio_seek(s->pb, s->internal->data_offset, SEEK_SET);
return 0;
}
......
......@@ -425,7 +425,7 @@ static int64_t dv_frame_offset(AVFormatContext *s, DVDemuxContext *c,
const AVDVProfile *sys = av_dv_codec_profile2(c->vst->codec->width, c->vst->codec->height,
c->vst->codec->pix_fmt, c->vst->codec->time_base);
int64_t offset;
int64_t size = avio_size(s->pb) - s->data_offset;
int64_t size = avio_size(s->pb) - s->internal->data_offset;
int64_t max_offset = ((size - 1) / sys->frame_size) * sys->frame_size;
offset = sys->frame_size * timestamp;
......@@ -435,7 +435,7 @@ static int64_t dv_frame_offset(AVFormatContext *s, DVDemuxContext *c,
else if (offset < 0)
offset = 0;
return offset + s->data_offset;
return offset + s->internal->data_offset;
}
void ff_dv_offset_reset(DVDemuxContext *c, int64_t frame_offset)
......
......@@ -54,6 +54,48 @@ struct AVFormatInternal {
*/
int nb_interleaved_streams;
/**
* This buffer is only needed when packets were already buffered but
* not decoded, for example to get the codec parameters in MPEG
* streams.
*/
struct AVPacketList *packet_buffer;
struct AVPacketList *packet_buffer_end;
/* av_seek_frame() support */
int64_t data_offset; /**< offset of the first packet */
/**
* Raw packets from the demuxer, prior to parsing and decoding.
* This buffer is used for buffering packets until the codec can
* be identified, as parsing cannot be done without knowing the
* codec.
*/
struct AVPacketList *raw_packet_buffer;
struct AVPacketList *raw_packet_buffer_end;
/**
* Packets split by the parser get queued here.
*/
struct AVPacketList *parse_queue;
struct AVPacketList *parse_queue_end;
/**
* Remaining size available for raw_packet_buffer, in bytes.
*/
#define RAW_PACKET_BUFFER_SIZE 2500000
int raw_packet_buffer_remaining_size;
/**
* Offset to remap timestamps to be non-negative.
* Expressed in timebase units.
* @see AVStream.mux_ts_offset
*/
int64_t offset;
/**
* Timebase for the timestamp offset.
*/
AVRational offset_timebase;
int inject_global_side_data;
};
......
......@@ -423,18 +423,18 @@ static int mp3_seek(AVFormatContext *s, int stream_index, int64_t timestamp,
if ( mp3->is_cbr
&& st->duration > 0
&& mp3->header_filesize > s->data_offset
&& mp3->header_filesize > s->internal->data_offset
&& mp3->frames) {
int64_t filesize = avio_size(s->pb);
int64_t duration;
if (filesize <= s->data_offset)
if (filesize <= s->internal->data_offset)
filesize = mp3->header_filesize;
filesize -= s->data_offset;
duration = av_rescale(st->duration, filesize, mp3->header_filesize - s->data_offset);
filesize -= s->internal->data_offset;
duration = av_rescale(st->duration, filesize, mp3->header_filesize - s->internal->data_offset);
ie = &ie1;
timestamp = av_clip64(timestamp, 0, duration);
ie->timestamp = timestamp;
ie->pos = av_rescale(timestamp, filesize, duration) + s->data_offset;
ie->pos = av_rescale(timestamp, filesize, duration) + s->internal->data_offset;
} else if (mp3->xing_toc) {
if (ret < 0)
return ret;
......
......@@ -200,7 +200,7 @@ static int mtv_read_packet(AVFormatContext *s, AVPacket *pkt)
AVIOContext *pb = s->pb;
int ret;
if((avio_tell(pb) - s->data_offset + mtv->img_segment_size) % mtv->full_segment_size)
if((avio_tell(pb) - s->internal->data_offset + mtv->img_segment_size) % mtv->full_segment_size)
{
avio_skip(pb, MTV_AUDIO_PADDING_SIZE);
......
......@@ -555,16 +555,16 @@ static int write_packet(AVFormatContext *s, AVPacket *pkt)
AVStream *st = s->streams[pkt->stream_index];
int64_t offset = st->mux_ts_offset;
if (s->offset == AV_NOPTS_VALUE && pkt->dts != AV_NOPTS_VALUE &&
if (s->internal->offset == AV_NOPTS_VALUE && pkt->dts != AV_NOPTS_VALUE &&
(pkt->dts < 0 || s->avoid_negative_ts == AVFMT_AVOID_NEG_TS_MAKE_ZERO)) {
s->offset = -pkt->dts;
s->offset_timebase = st->time_base;
s->internal->offset = -pkt->dts;
s->internal->offset_timebase = st->time_base;
}
if (s->offset != AV_NOPTS_VALUE && !offset) {
if (s->internal->offset != AV_NOPTS_VALUE && !offset) {
offset = st->mux_ts_offset =
av_rescale_q_rnd(s->offset,
s->offset_timebase,
av_rescale_q_rnd(s->internal->offset,
s->internal->offset_timebase,
st->time_base,
AV_ROUND_UP);
}
......@@ -694,7 +694,7 @@ FF_ENABLE_DEPRECATION_WARNINGS
if (s->streams[pkt->stream_index]->last_in_packet_buffer) {
next_point = &(st->last_in_packet_buffer->next);
} else {
next_point = &s->packet_buffer;
next_point = &s->internal->packet_buffer;
}
if (chunked) {
......@@ -718,7 +718,7 @@ FF_ENABLE_DEPRECATION_WARNINGS
if (chunked && !(this_pktl->pkt.flags & CHUNK_START))
goto next_non_null;
if (compare(s, &s->packet_buffer_end->pkt, pkt)) {
if (compare(s, &s->internal->packet_buffer_end->pkt, pkt)) {
while ( *next_point
&& ((chunked && !((*next_point)->pkt.flags&CHUNK_START))
|| !compare(s, &(*next_point)->pkt, pkt)))
......@@ -726,12 +726,12 @@ FF_ENABLE_DEPRECATION_WARNINGS
if (*next_point)
goto next_non_null;
} else {
next_point = &(s->packet_buffer_end->next);
next_point = &(s->internal->packet_buffer_end->next);
}
}
av_assert1(!*next_point);
s->packet_buffer_end = this_pktl;
s->internal->packet_buffer_end = this_pktl;
next_non_null:
this_pktl->next = *next_point;
......@@ -792,11 +792,11 @@ int ff_interleave_packet_per_dts(AVFormatContext *s, AVPacket *out,
flush = 1;
if (s->max_interleave_delta > 0 &&
s->packet_buffer &&
s->internal->packet_buffer &&
!flush &&
s->internal->nb_interleaved_streams == stream_count+noninterleaved_count
) {
AVPacket *top_pkt = &s->packet_buffer->pkt;
AVPacket *top_pkt = &s->internal->packet_buffer->pkt;
int64_t delta_dts = INT64_MIN;
int64_t top_dts = av_rescale_q(top_pkt->dts,
s->streams[top_pkt->stream_index]->time_base,
......@@ -826,13 +826,13 @@ int ff_interleave_packet_per_dts(AVFormatContext *s, AVPacket *out,
if (stream_count && flush) {
AVStream *st;
pktl = s->packet_buffer;
pktl = s->internal->packet_buffer;
*out = pktl->pkt;
st = s->streams[out->stream_index];
s->packet_buffer = pktl->next;
if (!s->packet_buffer)
s->packet_buffer_end = NULL;
s->internal->packet_buffer = pktl->next;
if (!s->internal->packet_buffer)
s->internal->packet_buffer_end = NULL;
if (st->last_in_packet_buffer == pktl)
st->last_in_packet_buffer = NULL;
......
......@@ -2322,7 +2322,7 @@ static int mxf_interleave_get_packet(AVFormatContext *s, AVPacket *out, AVPacket
stream_count += !!s->streams[i]->last_in_packet_buffer;
if (stream_count && (s->nb_streams == stream_count || flush)) {
AVPacketList *pktl = s->packet_buffer;
AVPacketList *pktl = s->internal->packet_buffer;
if (s->nb_streams != stream_count) {
AVPacketList *last = NULL;
// find last packet in edit unit
......@@ -2346,20 +2346,20 @@ static int mxf_interleave_get_packet(AVFormatContext *s, AVPacket *out, AVPacket
if (last)
last->next = NULL;
else {
s->packet_buffer = NULL;
s->packet_buffer_end= NULL;
s->internal->packet_buffer = NULL;
s->internal->packet_buffer_end= NULL;
goto out;
}
pktl = s->packet_buffer;
pktl = s->internal->packet_buffer;
}
*out = pktl->pkt;
av_dlog(s, "out st:%d dts:%"PRId64"\n", (*out).stream_index, (*out).dts);
s->packet_buffer = pktl->next;
s->internal->packet_buffer = pktl->next;
if(s->streams[pktl->pkt.stream_index]->last_in_packet_buffer == pktl)
s->streams[pktl->pkt.stream_index]->last_in_packet_buffer= NULL;
if(!s->packet_buffer)
s->packet_buffer_end= NULL;
if(!s->internal->packet_buffer)
s->internal->packet_buffer_end= NULL;
av_freep(&pktl);
return 1;
} else {
......
......@@ -790,7 +790,7 @@ static int nut_read_header(AVFormatContext *s)
decode_info_header(nut);
}
s->data_offset = pos - 8;
s->internal->data_offset = pos - 8;
if (bc->seekable) {
int64_t orig_pos = avio_tell(bc);
......
......@@ -142,7 +142,7 @@ static int ogg_reset(AVFormatContext *s)
os->segp = 0;
os->incomplete = 0;
os->got_data = 0;
if (start_pos <= s->data_offset) {
if (start_pos <= s->internal->data_offset) {
os->lastpts = 0;
}
os->end_trimming = 0;
......@@ -520,8 +520,8 @@ static int ogg_packet(AVFormatContext *s, int *sid, int *dstart, int *dsize,
// Update the header state for all streams and
// compute the data_offset.
if (!s->data_offset)
s->data_offset = os->sync_pos;
if (!s->internal->data_offset)
s->internal->data_offset = os->sync_pos;
for (i = 0; i < ogg->nstreams; i++) {
struct ogg_stream *cur_os = ogg->streams + i;
......@@ -529,7 +529,7 @@ static int ogg_packet(AVFormatContext *s, int *sid, int *dstart, int *dsize,
// if we have a partial non-header packet, its start is
// obviously at or after the data start
if (cur_os->incomplete)
s->data_offset = FFMIN(s->data_offset, cur_os->sync_pos);
s->internal->data_offset = FFMIN(s->internal->data_offset, cur_os->sync_pos);
}
} else {
os->nb_header++;
......@@ -613,7 +613,7 @@ static int ogg_get_length(AVFormatContext *s)
ogg_restore(s, 0);
ogg_save (s);
avio_seek (s->pb, s->data_offset, SEEK_SET);
avio_seek (s->pb, s->internal->data_offset, SEEK_SET);
ogg_reset(s);
while (streams_left > 0 && !ogg_packet(s, &i, NULL, NULL, NULL)) {
int64_t pts;
......
......@@ -110,13 +110,13 @@ AVFormatContext *avformat_alloc_context(void)
ic = av_malloc(sizeof(AVFormatContext));
if (!ic) return ic;
avformat_get_context_defaults(ic);
ic->offset = AV_NOPTS_VALUE;
ic->internal = av_mallocz(sizeof(*ic->internal));
if (!ic->internal) {
avformat_free_context(ic);
return NULL;
}
ic->internal->offset = AV_NOPTS_VALUE;
return ic;
}
......
......@@ -21,6 +21,7 @@
#include "libavutil/mathematics.h"
#include "avformat.h"
#include "internal.h"
#include "pcm.h"
#define RAW_SAMPLES 1024
......@@ -68,7 +69,7 @@ int ff_pcm_read_seek(AVFormatContext *s,
/* recompute exact position */
st->cur_dts = av_rescale(pos, st->time_base.den, byte_rate * (int64_t)st->time_base.num);
if ((ret = avio_seek(s->pb, pos + s->data_offset, SEEK_SET)) < 0)
if ((ret = avio_seek(s->pb, pos + s->internal->data_offset, SEEK_SET)) < 0)
return ret;
return 0;
}
......@@ -185,8 +185,8 @@ static int r3d_read_header(AVFormatContext *s)
return -1;
}
s->data_offset = avio_tell(s->pb);
av_dlog(s, "data offset %#"PRIx64"\n", s->data_offset);
s->internal->data_offset = avio_tell(s->pb);
av_dlog(s, "data offset %#"PRIx64"\n", s->internal->data_offset);
if (!s->pb->seekable)
return 0;
// find REOB/REOF/REOS to load index
......@@ -212,7 +212,7 @@ static int r3d_read_header(AVFormatContext *s)
}
out:
avio_seek(s->pb, s->data_offset, SEEK_SET);
avio_seek(s->pb, s->internal->data_offset, SEEK_SET);
return 0;
}
......
This diff is collapsed.
......@@ -31,7 +31,7 @@
#define LIBAVFORMAT_VERSION_MAJOR 56
#define LIBAVFORMAT_VERSION_MINOR 19
#define LIBAVFORMAT_VERSION_MICRO 100
#define LIBAVFORMAT_VERSION_MICRO 101
#define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \
LIBAVFORMAT_VERSION_MINOR, \
......
......@@ -275,7 +275,7 @@ static int vqf_read_seek(AVFormatContext *s,
st->cur_dts = av_rescale(pos, st->time_base.den,
st->codec->bit_rate * (int64_t)st->time_base.num);
if ((ret = avio_seek(s->pb, ((pos-7) >> 3) + s->data_offset, SEEK_SET)) < 0)
if ((ret = avio_seek(s->pb, ((pos-7) >> 3) + s->internal->data_offset, SEEK_SET)) < 0)
return ret;
c->remaining_bits = -7 - ((pos-7)&7);
......
......@@ -199,7 +199,7 @@ static int yop_read_seek(AVFormatContext *s, int stream_index,
if (!stream_index)
return -1;
pos_min = s->data_offset;
pos_min = s->internal->data_offset;
pos_max = avio_size(s->pb) - yop->frame_size;
frame_count = (pos_max - pos_min) / yop->frame_size;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment