mirror of
https://git.ffmpeg.org/ffmpeg.git
synced 2025-02-25 16:21:13 +00:00
Add ByteIOContext argument to public ff_rm_* functions so that we can
specify the data source as function argument instead of in s->pb before calling the function. Discussed in ML thread "[PATCH] fix small memleak in rdt.c". Originally committed as revision 15849 to svn://svn.ffmpeg.org/ffmpeg/trunk
This commit is contained in:
parent
074bfa7de7
commit
fcc995a533
@ -159,8 +159,7 @@ rdt_load_mdpr (PayloadContext *rdt, AVStream *st, int rule_nr)
|
|||||||
size = rdt->mlti_data_size;
|
size = rdt->mlti_data_size;
|
||||||
url_fseek(pb, 0, SEEK_SET);
|
url_fseek(pb, 0, SEEK_SET);
|
||||||
}
|
}
|
||||||
rdt->rmctx->pb = pb;
|
if (ff_rm_read_mdpr_codecdata(rdt->rmctx, pb, st, size) < 0)
|
||||||
if (ff_rm_read_mdpr_codecdata(rdt->rmctx, st, size) < 0)
|
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
url_close_buf(pb);
|
url_close_buf(pb);
|
||||||
@ -259,7 +258,7 @@ rdt_parse_packet (PayloadContext *rdt, AVStream *st,
|
|||||||
const uint8_t *buf, int len, int flags)
|
const uint8_t *buf, int len, int flags)
|
||||||
{
|
{
|
||||||
int seq = 1, res;
|
int seq = 1, res;
|
||||||
ByteIOContext *pb = rdt->rmctx->pb;
|
ByteIOContext *pb;
|
||||||
RMContext *rm = rdt->rmctx->priv_data;
|
RMContext *rm = rdt->rmctx->priv_data;
|
||||||
|
|
||||||
if (rm->audio_pkt_cnt == 0) {
|
if (rm->audio_pkt_cnt == 0) {
|
||||||
@ -267,8 +266,7 @@ rdt_parse_packet (PayloadContext *rdt, AVStream *st,
|
|||||||
|
|
||||||
url_open_buf (&pb, buf, len, URL_RDONLY);
|
url_open_buf (&pb, buf, len, URL_RDONLY);
|
||||||
flags = (flags & PKT_FLAG_KEY) ? 2 : 0;
|
flags = (flags & PKT_FLAG_KEY) ? 2 : 0;
|
||||||
rdt->rmctx->pb = pb;
|
res = ff_rm_parse_packet (rdt->rmctx, pb, st, len, pkt,
|
||||||
res = ff_rm_parse_packet (rdt->rmctx, st, len, pkt,
|
|
||||||
&seq, &flags, timestamp);
|
&seq, &flags, timestamp);
|
||||||
pos = url_ftell(pb);
|
pos = url_ftell(pb);
|
||||||
url_close_buf (pb);
|
url_close_buf (pb);
|
||||||
@ -277,14 +275,13 @@ rdt_parse_packet (PayloadContext *rdt, AVStream *st,
|
|||||||
if (rm->audio_pkt_cnt > 0 &&
|
if (rm->audio_pkt_cnt > 0 &&
|
||||||
st->codec->codec_id == CODEC_ID_AAC) {
|
st->codec->codec_id == CODEC_ID_AAC) {
|
||||||
memcpy (rdt->buffer, buf + pos, len - pos);
|
memcpy (rdt->buffer, buf + pos, len - pos);
|
||||||
url_open_buf (&pb, rdt->buffer, len - pos, URL_RDONLY);
|
url_open_buf (&rdt->rmctx->pb, rdt->buffer, len - pos, URL_RDONLY);
|
||||||
rdt->rmctx->pb = pb;
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
ff_rm_retrieve_cache (rdt->rmctx, st, pkt);
|
ff_rm_retrieve_cache (rdt->rmctx, rdt->rmctx->pb, st, pkt);
|
||||||
if (rm->audio_pkt_cnt == 0 &&
|
if (rm->audio_pkt_cnt == 0 &&
|
||||||
st->codec->codec_id == CODEC_ID_AAC)
|
st->codec->codec_id == CODEC_ID_AAC)
|
||||||
url_close_buf (pb);
|
url_close_buf (rdt->rmctx->pb);
|
||||||
}
|
}
|
||||||
pkt->stream_index = st->index;
|
pkt->stream_index = st->index;
|
||||||
pkt->pts = *timestamp;
|
pkt->pts = *timestamp;
|
||||||
|
@ -71,17 +71,20 @@ extern AVInputFormat rdt_demuxer;
|
|||||||
* parameters.
|
* parameters.
|
||||||
*
|
*
|
||||||
* @param s context containing RMContext and ByteIOContext for stream reading
|
* @param s context containing RMContext and ByteIOContext for stream reading
|
||||||
|
* @param pb context to read the data from
|
||||||
* @param st the stream that the MDPR chunk belongs to and where to store the
|
* @param st the stream that the MDPR chunk belongs to and where to store the
|
||||||
* parameters read from the chunk into
|
* parameters read from the chunk into
|
||||||
* @param codec_data_size size of the MDPR chunk
|
* @param codec_data_size size of the MDPR chunk
|
||||||
* @return 0 on success, errno codes on error
|
* @return 0 on success, errno codes on error
|
||||||
*/
|
*/
|
||||||
int ff_rm_read_mdpr_codecdata (AVFormatContext *s, AVStream *st, int codec_data_size);
|
int ff_rm_read_mdpr_codecdata (AVFormatContext *s, ByteIOContext *pb,
|
||||||
|
AVStream *st, int codec_data_size);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parse one rm-stream packet from the input bytestream.
|
* Parse one rm-stream packet from the input bytestream.
|
||||||
*
|
*
|
||||||
* @param s context containing RMContext and ByteIOContext for stream reading
|
* @param s context containing RMContext and ByteIOContext for stream reading
|
||||||
|
* @param pb context to read the data from
|
||||||
* @param st stream to which the packet to be read belongs
|
* @param st stream to which the packet to be read belongs
|
||||||
* @param len packet length to read from the input
|
* @param len packet length to read from the input
|
||||||
* @param pkt packet location to store the parsed packet data
|
* @param pkt packet location to store the parsed packet data
|
||||||
@ -92,7 +95,8 @@ int ff_rm_read_mdpr_codecdata (AVFormatContext *s, AVStream *st, int codec_data_
|
|||||||
* @param ts pointer to timestamp, may be updated
|
* @param ts pointer to timestamp, may be updated
|
||||||
* @return 0 on success, errno codes on error
|
* @return 0 on success, errno codes on error
|
||||||
*/
|
*/
|
||||||
int ff_rm_parse_packet (AVFormatContext *s, AVStream *st, int len,
|
int ff_rm_parse_packet (AVFormatContext *s, ByteIOContext *pb,
|
||||||
|
AVStream *st, int len,
|
||||||
AVPacket *pkt, int *seq, int *flags, int64_t *ts);
|
AVPacket *pkt, int *seq, int *flags, int64_t *ts);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -104,9 +108,11 @@ int ff_rm_parse_packet (AVFormatContext *s, AVStream *st, int len,
|
|||||||
* of those packets can be retrieved sequentially.
|
* of those packets can be retrieved sequentially.
|
||||||
*
|
*
|
||||||
* @param s context containing RMContext and ByteIOContext for stream reading
|
* @param s context containing RMContext and ByteIOContext for stream reading
|
||||||
|
* @param pb context to read the data from
|
||||||
* @param st stream that this packet belongs to
|
* @param st stream that this packet belongs to
|
||||||
* @param pkt location to store the packet data
|
* @param pkt location to store the packet data
|
||||||
*/
|
*/
|
||||||
void ff_rm_retrieve_cache (AVFormatContext *s, AVStream *st, AVPacket *pkt);
|
void ff_rm_retrieve_cache (AVFormatContext *s, ByteIOContext *pb,
|
||||||
|
AVStream *st, AVPacket *pkt);
|
||||||
|
|
||||||
#endif /* AVFORMAT_RM_H */
|
#endif /* AVFORMAT_RM_H */
|
||||||
|
@ -47,11 +47,10 @@ static void get_str8(ByteIOContext *pb, char *buf, int buf_size)
|
|||||||
get_strl(pb, buf, buf_size, get_byte(pb));
|
get_strl(pb, buf, buf_size, get_byte(pb));
|
||||||
}
|
}
|
||||||
|
|
||||||
static int rm_read_audio_stream_info(AVFormatContext *s, AVStream *st,
|
static int rm_read_audio_stream_info(AVFormatContext *s, ByteIOContext *pb,
|
||||||
int read_all)
|
AVStream *st, int read_all)
|
||||||
{
|
{
|
||||||
RMContext *rm = s->priv_data;
|
RMContext *rm = s->priv_data;
|
||||||
ByteIOContext *pb = s->pb;
|
|
||||||
char buf[256];
|
char buf[256];
|
||||||
uint32_t version;
|
uint32_t version;
|
||||||
int i;
|
int i;
|
||||||
@ -196,9 +195,9 @@ static int rm_read_audio_stream_info(AVFormatContext *s, AVStream *st,
|
|||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
ff_rm_read_mdpr_codecdata (AVFormatContext *s, AVStream *st, int codec_data_size)
|
ff_rm_read_mdpr_codecdata (AVFormatContext *s, ByteIOContext *pb,
|
||||||
|
AVStream *st, int codec_data_size)
|
||||||
{
|
{
|
||||||
ByteIOContext *pb = s->pb;
|
|
||||||
unsigned int v;
|
unsigned int v;
|
||||||
int size;
|
int size;
|
||||||
int64_t codec_pos;
|
int64_t codec_pos;
|
||||||
@ -208,7 +207,7 @@ ff_rm_read_mdpr_codecdata (AVFormatContext *s, AVStream *st, int codec_data_size
|
|||||||
v = get_be32(pb);
|
v = get_be32(pb);
|
||||||
if (v == MKTAG(0xfd, 'a', 'r', '.')) {
|
if (v == MKTAG(0xfd, 'a', 'r', '.')) {
|
||||||
/* ra type header */
|
/* ra type header */
|
||||||
if (rm_read_audio_stream_info(s, st, 0))
|
if (rm_read_audio_stream_info(s, pb, st, 0))
|
||||||
return -1;
|
return -1;
|
||||||
} else {
|
} else {
|
||||||
int fps, fps2;
|
int fps, fps2;
|
||||||
@ -275,7 +274,7 @@ static int rm_read_header_old(AVFormatContext *s, AVFormatParameters *ap)
|
|||||||
st = av_new_stream(s, 0);
|
st = av_new_stream(s, 0);
|
||||||
if (!st)
|
if (!st)
|
||||||
return -1;
|
return -1;
|
||||||
return rm_read_audio_stream_info(s, st, 1);
|
return rm_read_audio_stream_info(s, s->pb, st, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int rm_read_header(AVFormatContext *s, AVFormatParameters *ap)
|
static int rm_read_header(AVFormatContext *s, AVFormatParameters *ap)
|
||||||
@ -357,7 +356,7 @@ static int rm_read_header(AVFormatContext *s, AVFormatParameters *ap)
|
|||||||
get_str8(pb, buf, sizeof(buf)); /* desc */
|
get_str8(pb, buf, sizeof(buf)); /* desc */
|
||||||
get_str8(pb, buf, sizeof(buf)); /* mimetype */
|
get_str8(pb, buf, sizeof(buf)); /* mimetype */
|
||||||
st->codec->codec_type = CODEC_TYPE_DATA;
|
st->codec->codec_type = CODEC_TYPE_DATA;
|
||||||
if (ff_rm_read_mdpr_codecdata(s, st, get_be32(pb)) < 0)
|
if (ff_rm_read_mdpr_codecdata(s, s->pb, st, get_be32(pb)) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
break;
|
break;
|
||||||
case MKTAG('D', 'A', 'T', 'A'):
|
case MKTAG('D', 'A', 'T', 'A'):
|
||||||
@ -452,9 +451,9 @@ skip:
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int rm_assemble_video_frame(AVFormatContext *s, RMContext *rm, AVPacket *pkt, int len)
|
static int rm_assemble_video_frame(AVFormatContext *s, ByteIOContext *pb,
|
||||||
|
RMContext *rm, AVPacket *pkt, int len)
|
||||||
{
|
{
|
||||||
ByteIOContext *pb = s->pb;
|
|
||||||
int hdr, seq, pic_num, len2, pos;
|
int hdr, seq, pic_num, len2, pos;
|
||||||
int type;
|
int type;
|
||||||
|
|
||||||
@ -550,15 +549,15 @@ rm_ac3_swap_bytes (AVStream *st, AVPacket *pkt)
|
|||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
ff_rm_parse_packet (AVFormatContext *s, AVStream *st, int len, AVPacket *pkt,
|
ff_rm_parse_packet (AVFormatContext *s, ByteIOContext *pb,
|
||||||
|
AVStream *st, int len, AVPacket *pkt,
|
||||||
int *seq, int *flags, int64_t *timestamp)
|
int *seq, int *flags, int64_t *timestamp)
|
||||||
{
|
{
|
||||||
ByteIOContext *pb = s->pb;
|
|
||||||
RMContext *rm = s->priv_data;
|
RMContext *rm = s->priv_data;
|
||||||
|
|
||||||
if (st->codec->codec_type == CODEC_TYPE_VIDEO) {
|
if (st->codec->codec_type == CODEC_TYPE_VIDEO) {
|
||||||
rm->current_stream= st->id;
|
rm->current_stream= st->id;
|
||||||
if(rm_assemble_video_frame(s, rm, pkt, len) == 1)
|
if(rm_assemble_video_frame(s, pb, rm, pkt, len) == 1)
|
||||||
return -1; //got partial frame
|
return -1; //got partial frame
|
||||||
} else if (st->codec->codec_type == CODEC_TYPE_AUDIO) {
|
} else if (st->codec->codec_type == CODEC_TYPE_AUDIO) {
|
||||||
if ((st->codec->codec_id == CODEC_ID_RA_288) ||
|
if ((st->codec->codec_id == CODEC_ID_RA_288) ||
|
||||||
@ -649,9 +648,9 @@ ff_rm_parse_packet (AVFormatContext *s, AVStream *st, int len, AVPacket *pkt,
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ff_rm_retrieve_cache (AVFormatContext *s, AVStream *st, AVPacket *pkt)
|
ff_rm_retrieve_cache (AVFormatContext *s, ByteIOContext *pb,
|
||||||
|
AVStream *st, AVPacket *pkt)
|
||||||
{
|
{
|
||||||
ByteIOContext *pb = s->pb;
|
|
||||||
RMContext *rm = s->priv_data;
|
RMContext *rm = s->priv_data;
|
||||||
|
|
||||||
assert (rm->audio_pkt_cnt > 0);
|
assert (rm->audio_pkt_cnt > 0);
|
||||||
@ -681,7 +680,7 @@ static int rm_read_packet(AVFormatContext *s, AVPacket *pkt)
|
|||||||
if (rm->audio_pkt_cnt) {
|
if (rm->audio_pkt_cnt) {
|
||||||
// If there are queued audio packet return them first
|
// If there are queued audio packet return them first
|
||||||
st = s->streams[rm->audio_stream_num];
|
st = s->streams[rm->audio_stream_num];
|
||||||
ff_rm_retrieve_cache(s, st, pkt);
|
ff_rm_retrieve_cache(s, s->pb, st, pkt);
|
||||||
} else if (rm->old_format) {
|
} else if (rm->old_format) {
|
||||||
st = s->streams[0];
|
st = s->streams[0];
|
||||||
if (st->codec->codec_id == CODEC_ID_RA_288) {
|
if (st->codec->codec_id == CODEC_ID_RA_288) {
|
||||||
@ -717,7 +716,7 @@ resync:
|
|||||||
return AVERROR(EIO);
|
return AVERROR(EIO);
|
||||||
st = s->streams[i];
|
st = s->streams[i];
|
||||||
|
|
||||||
if (ff_rm_parse_packet (s, st, len, pkt, &seq, &flags, ×tamp) < 0)
|
if (ff_rm_parse_packet (s, s->pb, st, len, pkt, &seq, &flags, ×tamp) < 0)
|
||||||
goto resync;
|
goto resync;
|
||||||
|
|
||||||
if((flags&2) && (seq&0x7F) == 1)
|
if((flags&2) && (seq&0x7F) == 1)
|
||||||
|
Loading…
Reference in New Issue
Block a user