1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2024-12-23 12:43:46 +02:00

avio: move init_put_byte() to a new private header and rename it

init_put_byte should never be used outside of lavf, since
sizeof(AVIOContext) isn't part of public ABI.

Signed-off-by: Ronald S. Bultje <rsbultje@gmail.com>
(cherry picked from commit e731b8d872)
This commit is contained in:
Anton Khirnov 2011-02-20 11:04:13 +01:00 committed by Michael Niedermayer
parent 471fe57e1a
commit ae99313aa5
14 changed files with 87 additions and 25 deletions

View File

@ -22,6 +22,7 @@
#include "metadata.h"
#include "riff.h"
#include "asf.h"
#include "avio_internal.h"
#undef NDEBUG
#include <assert.h>
@ -578,7 +579,7 @@ static int asf_write_header(AVFormatContext *s)
asf->packet_nb_payloads = 0;
asf->packet_timestamp_start = -1;
asf->packet_timestamp_end = -1;
init_put_byte(&asf->pb, asf->packet_buf, s->packet_size, 1,
ffio_init_context(&asf->pb, asf->packet_buf, s->packet_size, 1,
NULL, NULL, NULL, NULL);
return 0;
@ -676,7 +677,7 @@ static void flush_packet(AVFormatContext *s)
asf->packet_nb_payloads = 0;
asf->packet_timestamp_start = -1;
asf->packet_timestamp_end = -1;
init_put_byte(&asf->pb, asf->packet_buf, s->packet_size, 1,
ffio_init_context(&asf->pb, asf->packet_buf, s->packet_size, 1,
NULL, NULL, NULL, NULL);
}

View File

@ -361,9 +361,8 @@ typedef struct {
#if FF_API_OLD_AVIO
typedef attribute_deprecated AVIOContext ByteIOContext;
#endif
int init_put_byte(AVIOContext *s,
attribute_deprecated int init_put_byte(AVIOContext *s,
unsigned char *buffer,
int buffer_size,
int write_flag,
@ -371,6 +370,7 @@ int init_put_byte(AVIOContext *s,
int (*read_packet)(void *opaque, uint8_t *buf, int buf_size),
int (*write_packet)(void *opaque, uint8_t *buf, int buf_size),
int64_t (*seek)(void *opaque, int64_t offset, int whence));
#endif
AVIOContext *av_alloc_put_byte(
unsigned char *buffer,
int buffer_size,

View File

@ -0,0 +1,35 @@
/*
*
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* FFmpeg is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef AVFORMAT_AVIO_INTERNAL_H
#define AVFORMAT_AVIO_INTERNAL_H
#include "avio.h"
int ffio_init_context(AVIOContext *s,
unsigned char *buffer,
int buffer_size,
int write_flag,
void *opaque,
int (*read_packet)(void *opaque, uint8_t *buf, int buf_size),
int (*write_packet)(void *opaque, uint8_t *buf, int buf_size),
int64_t (*seek)(void *opaque, int64_t offset, int whence));
#endif // AVFORMAT_AVIO_INTERNAL_H

View File

@ -23,6 +23,7 @@
#include "libavutil/intreadwrite.h"
#include "avformat.h"
#include "avio.h"
#include "avio_internal.h"
#include "internal.h"
#include <stdarg.h>
@ -40,7 +41,7 @@ static void fill_buffer(AVIOContext *s);
static int url_resetbuf(AVIOContext *s, int flags);
#endif
int init_put_byte(AVIOContext *s,
int ffio_init_context(AVIOContext *s,
unsigned char *buffer,
int buffer_size,
int write_flag,
@ -73,6 +74,21 @@ int init_put_byte(AVIOContext *s,
return 0;
}
#if FF_API_OLD_AVIO
int init_put_byte(AVIOContext *s,
unsigned char *buffer,
int buffer_size,
int write_flag,
void *opaque,
int (*read_packet)(void *opaque, uint8_t *buf, int buf_size),
int (*write_packet)(void *opaque, uint8_t *buf, int buf_size),
int64_t (*seek)(void *opaque, int64_t offset, int whence))
{
return ffio_init_context(s, buffer, buffer_size, write_flag, opaque,
read_packet, write_packet, seek);
}
#endif
AVIOContext *av_alloc_put_byte(
unsigned char *buffer,
int buffer_size,
@ -83,7 +99,7 @@ AVIOContext *av_alloc_put_byte(
int64_t (*seek)(void *opaque, int64_t offset, int whence))
{
AVIOContext *s = av_mallocz(sizeof(AVIOContext));
init_put_byte(s, buffer, buffer_size, write_flag, opaque,
ffio_init_context(s, buffer, buffer_size, write_flag, opaque,
read_packet, write_packet, seek);
return s;
}
@ -664,7 +680,7 @@ int url_fdopen(AVIOContext **s, URLContext *h)
return AVERROR(ENOMEM);
}
if (init_put_byte(*s, buffer, buffer_size,
if (ffio_init_context(*s, buffer, buffer_size,
(h->flags & URL_WRONLY || h->flags & URL_RDWR), h,
url_read, url_write, url_seek) < 0) {
av_free(buffer);
@ -865,7 +881,7 @@ int url_open_buf(AVIOContext **s, uint8_t *buf, int buf_size, int flags)
*s = av_mallocz(sizeof(AVIOContext));
if(!*s)
return AVERROR(ENOMEM);
ret = init_put_byte(*s, buf, buf_size,
ret = ffio_init_context(*s, buf, buf_size,
(flags & URL_WRONLY || flags & URL_RDWR),
NULL, NULL, NULL, NULL);
if(ret != 0)
@ -964,7 +980,7 @@ static int url_open_dyn_buf_internal(AVIOContext **s, int max_packet_size)
return AVERROR(ENOMEM);
}
d->io_buffer_size = io_buffer_size;
ret = init_put_byte(*s, d->io_buffer, io_buffer_size,
ret = ffio_init_context(*s, d->io_buffer, io_buffer_size,
1, d, NULL,
max_packet_size ? dyn_packet_buf_write : dyn_buf_write,
max_packet_size ? NULL : dyn_buf_seek);

View File

@ -24,6 +24,7 @@
#include "libavutil/avstring.h"
#include "libavutil/intreadwrite.h"
#include "metadata.h"
#include "avio_internal.h"
int ff_id3v2_match(const uint8_t *buf, const char * magic)
{
@ -216,7 +217,7 @@ static void ff_id3v2_parse(AVFormatContext *s, int len, uint8_t version, uint8_t
j--;
}
}
init_put_byte(&pb, buffer, j, 0, NULL, NULL, NULL, NULL);
ffio_init_context(&pb, buffer, j, 0, NULL, NULL, NULL, NULL);
read_ttag(s, &pb, j, tag);
} else {
read_ttag(s, s->pb, tlen, tag);

View File

@ -31,6 +31,7 @@
#include <stdio.h>
#include "avformat.h"
#include "internal.h"
#include "avio_internal.h"
/* For ff_codec_get_id(). */
#include "riff.h"
#include "isom.h"
@ -698,7 +699,7 @@ static int matroska_ebmlnum_uint(MatroskaDemuxContext *matroska,
uint8_t *data, uint32_t size, uint64_t *num)
{
AVIOContext pb;
init_put_byte(&pb, data, size, 0, NULL, NULL, NULL, NULL);
ffio_init_context(&pb, data, size, 0, NULL, NULL, NULL, NULL);
return ebml_read_num(matroska, &pb, FFMIN(size, 8), num);
}
@ -1328,7 +1329,7 @@ static int matroska_read_header(AVFormatContext *s, AVFormatParameters *ap)
} else if (!strcmp(track->codec_id, "A_MS/ACM")
&& track->codec_priv.size >= 14
&& track->codec_priv.data != NULL) {
init_put_byte(&b, track->codec_priv.data, track->codec_priv.size,
ffio_init_context(&b, track->codec_priv.data, track->codec_priv.size,
URL_RDONLY, NULL, NULL, NULL, NULL);
ff_get_wav_header(&b, st->codec, track->codec_priv.size);
codec_id = st->codec->codec_id;
@ -1373,7 +1374,7 @@ static int matroska_read_header(AVFormatContext *s, AVFormatParameters *ap)
extradata = av_mallocz(extradata_size);
if (extradata == NULL)
return AVERROR(ENOMEM);
init_put_byte(&b, extradata, extradata_size, 1,
ffio_init_context(&b, extradata, extradata_size, 1,
NULL, NULL, NULL, NULL);
put_buffer(&b, "TTA1", 4);
put_le16(&b, 1);
@ -1390,7 +1391,7 @@ static int matroska_read_header(AVFormatContext *s, AVFormatParameters *ap)
} else if (codec_id == CODEC_ID_RA_288 || codec_id == CODEC_ID_COOK ||
codec_id == CODEC_ID_ATRAC3 || codec_id == CODEC_ID_SIPR) {
int flavor;
init_put_byte(&b, track->codec_priv.data,track->codec_priv.size,
ffio_init_context(&b, track->codec_priv.data,track->codec_priv.size,
0, NULL, NULL, NULL, NULL);
url_fskip(&b, 22);
flavor = get_be16(&b);

View File

@ -31,6 +31,7 @@
#include "avformat.h"
#include "mms.h"
#include "internal.h"
#include "avio_internal.h"
#include "libavutil/intreadwrite.h"
#include "libavcodec/bytestream.h"
#include "network.h"
@ -155,7 +156,7 @@ static void mms_put_utf16(MMSContext *mms, uint8_t *src)
AVIOContext bic;
int size = mms->write_out_ptr - mms->out_buffer;
int len;
init_put_byte(&bic, mms->write_out_ptr,
ffio_init_context(&bic, mms->write_out_ptr,
sizeof(mms->out_buffer) - size, 1, NULL, NULL, NULL, NULL);
len = avio_put_str16le(&bic, src);

View File

@ -29,6 +29,7 @@
#include "libavutil/intreadwrite.h"
#include "libavutil/avstring.h"
#include "avformat.h"
#include "avio_internal.h"
#include "riff.h"
#include "isom.h"
#include "libavcodec/get_bits.h"
@ -2123,7 +2124,7 @@ static int mov_read_cmov(MOVContext *c, AVIOContext *pb, MOVAtom atom)
get_buffer(pb, cmov_data, cmov_len);
if(uncompress (moov_data, (uLongf *) &moov_len, (const Bytef *)cmov_data, cmov_len) != Z_OK)
goto free_and_return;
if(init_put_byte(&ctx, moov_data, moov_len, 0, NULL, NULL, NULL, NULL) != 0)
if(ffio_init_context(&ctx, moov_data, moov_len, 0, NULL, NULL, NULL, NULL) != 0)
goto free_and_return;
atom.type = MKTAG('m','o','o','v');
atom.size = moov_len;

View File

@ -29,6 +29,7 @@
#include "avformat.h"
#include "mpegts.h"
#include "internal.h"
#include "avio_internal.h"
#include "seek.h"
#include "mpeg.h"
#include "isom.h"
@ -855,7 +856,7 @@ static int mp4_read_iods(AVFormatContext *s, const uint8_t *buf, unsigned size,
int tag;
unsigned len;
init_put_byte(&pb, buf, size, 0, NULL, NULL, NULL, NULL);
ffio_init_context(&pb, buf, size, 0, NULL, NULL, NULL, NULL);
len = ff_mp4_read_descr(s, &pb, &tag);
if (tag == MP4IODescrTag) {
@ -914,7 +915,7 @@ int ff_parse_mpeg2_descriptor(AVFormatContext *fc, AVStream *st, int stream_type
if (st->codec->codec_id == CODEC_ID_AAC_LATM &&
mp4_dec_config_descr_len && mp4_es_id == pid) {
AVIOContext pb;
init_put_byte(&pb, mp4_dec_config_descr,
ffio_init_context(&pb, mp4_dec_config_descr,
mp4_dec_config_descr_len, 0, NULL, NULL, NULL, NULL);
ff_mp4_read_dec_config_descr(fc, st, &pb);
if (st->codec->codec_id == CODEC_ID_AAC &&

View File

@ -33,6 +33,7 @@
#include "libavutil/md5.h"
#include "rm.h"
#include "internal.h"
#include "avio_internal.h"
#include "libavcodec/get_bits.h"
struct RDTDemuxContext {
@ -150,7 +151,7 @@ rdt_load_mdpr (PayloadContext *rdt, AVStream *st, int rule_nr)
*/
if (!rdt->mlti_data)
return -1;
init_put_byte(&pb, rdt->mlti_data, rdt->mlti_data_size, 0,
ffio_init_context(&pb, rdt->mlti_data, rdt->mlti_data_size, 0,
NULL, NULL, NULL, NULL);
tag = get_le32(&pb);
if (tag == MKTAG('M', 'L', 'T', 'I')) {
@ -300,7 +301,7 @@ rdt_parse_packet (AVFormatContext *ctx, PayloadContext *rdt, AVStream *st,
if (rdt->audio_pkt_cnt == 0) {
int pos;
init_put_byte(&pb, buf, len, 0, NULL, NULL, NULL, NULL);
ffio_init_context(&pb, buf, len, 0, NULL, NULL, NULL, NULL);
flags = (flags & RTP_FLAG_KEY) ? 2 : 0;
res = ff_rm_parse_packet (rdt->rmctx, &pb, st, rdt->rmst[st->index], len, pkt,
&seq, flags, *timestamp);

View File

@ -32,6 +32,7 @@
#include "rtpdec_formats.h"
#include "rtsp.h"
#include "asf.h"
#include "avio_internal.h"
/**
* From MSDN 2.2.1.4, we learn that ASF data packets over RTP should not
@ -84,7 +85,7 @@ static int packetizer_read(void *opaque, uint8_t *buf, int buf_size)
static void init_packetizer(AVIOContext *pb, uint8_t *buf, int len)
{
init_put_byte(pb, buf, len, 0, NULL, packetizer_read, NULL, NULL);
ffio_init_context(pb, buf, len, 0, NULL, packetizer_read, NULL, NULL);
/* this "fills" the buffer with its current content */
pb->pos = len;
@ -176,7 +177,7 @@ static int asfrtp_parse_packet(AVFormatContext *s, PayloadContext *asf,
av_freep(&asf->buf);
init_put_byte(pb, buf, len, 0, NULL, NULL, NULL, NULL);
ffio_init_context(pb, buf, len, 0, NULL, NULL, NULL, NULL);
while (url_ftell(pb) + 4 < len) {
int start_off = url_ftell(pb);

View File

@ -26,6 +26,7 @@
*/
#include "avformat.h"
#include "avio_internal.h"
#include "rtp.h"
#include "rtpdec.h"
#include "isom.h"
@ -69,7 +70,7 @@ static int qt_rtp_parse_packet(AVFormatContext *s, PayloadContext *qt,
* http://developer.apple.com/quicktime/icefloe/dispatch026.html
*/
init_get_bits(&gb, buf, len << 3);
init_put_byte(&pb, buf, len, 0, NULL, NULL, NULL, NULL);
ffio_init_context(&pb, buf, len, 0, NULL, NULL, NULL, NULL);
if (len < 4)
return AVERROR_INVALIDDATA;

View File

@ -25,6 +25,7 @@
#include "libavutil/parseutils.h"
#include "libavutil/random_seed.h"
#include "avformat.h"
#include "avio_internal.h"
#include <sys/time.h>
#if HAVE_POLL_H
@ -1913,7 +1914,7 @@ static int rtp_read_header(AVFormatContext *s,
port, payload_type);
av_log(s, AV_LOG_VERBOSE, "SDP:\n%s\n", sdp);
init_put_byte(&pb, sdp, strlen(sdp), 0, NULL, NULL, NULL, NULL);
ffio_init_context(&pb, sdp, strlen(sdp), 0, NULL, NULL, NULL, NULL);
s->pb = &pb;
/* sdp_read_header initializes this again */

View File

@ -25,6 +25,7 @@
#include "network.h"
#include "os_support.h"
#include "internal.h"
#include "avio_internal.h"
#if HAVE_POLL_H
#include <poll.h>
#endif
@ -142,7 +143,7 @@ static int sap_read_header(AVFormatContext *s,
}
av_log(s, AV_LOG_VERBOSE, "SDP:\n%s\n", sap->sdp);
init_put_byte(&sap->sdp_pb, sap->sdp, strlen(sap->sdp), 0, NULL, NULL,
ffio_init_context(&sap->sdp_pb, sap->sdp, strlen(sap->sdp), 0, NULL, NULL,
NULL, NULL);
infmt = av_find_input_format("sdp");