Browse code

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>

Anton Khirnov authored on 2011/02/20 19:04:13
Showing 14 changed files
... ...
@@ -22,6 +22,7 @@
22 22
 #include "metadata.h"
23 23
 #include "riff.h"
24 24
 #include "asf.h"
25
+#include "avio_internal.h"
25 26
 
26 27
 #undef NDEBUG
27 28
 #include <assert.h>
... ...
@@ -578,7 +579,7 @@ static int asf_write_header(AVFormatContext *s)
578 578
     asf->packet_nb_payloads = 0;
579 579
     asf->packet_timestamp_start = -1;
580 580
     asf->packet_timestamp_end = -1;
581
-    init_put_byte(&asf->pb, asf->packet_buf, s->packet_size, 1,
581
+    ffio_init_context(&asf->pb, asf->packet_buf, s->packet_size, 1,
582 582
                   NULL, NULL, NULL, NULL);
583 583
 
584 584
     return 0;
... ...
@@ -676,7 +677,7 @@ static void flush_packet(AVFormatContext *s)
676 676
     asf->packet_nb_payloads = 0;
677 677
     asf->packet_timestamp_start = -1;
678 678
     asf->packet_timestamp_end = -1;
679
-    init_put_byte(&asf->pb, asf->packet_buf, s->packet_size, 1,
679
+    ffio_init_context(&asf->pb, asf->packet_buf, s->packet_size, 1,
680 680
                   NULL, NULL, NULL, NULL);
681 681
 }
682 682
 
... ...
@@ -361,9 +361,8 @@ typedef struct {
361 361
 
362 362
 #if FF_API_OLD_AVIO
363 363
 typedef attribute_deprecated AVIOContext ByteIOContext;
364
-#endif
365 364
 
366
-int init_put_byte(AVIOContext *s,
365
+attribute_deprecated int init_put_byte(AVIOContext *s,
367 366
                   unsigned char *buffer,
368 367
                   int buffer_size,
369 368
                   int write_flag,
... ...
@@ -371,6 +370,7 @@ int init_put_byte(AVIOContext *s,
371 371
                   int (*read_packet)(void *opaque, uint8_t *buf, int buf_size),
372 372
                   int (*write_packet)(void *opaque, uint8_t *buf, int buf_size),
373 373
                   int64_t (*seek)(void *opaque, int64_t offset, int whence));
374
+#endif
374 375
 AVIOContext *av_alloc_put_byte(
375 376
                   unsigned char *buffer,
376 377
                   int buffer_size,
377 378
new file mode 100644
... ...
@@ -0,0 +1,35 @@
0
+/*
1
+ *
2
+ * This file is part of FFmpeg.
3
+ *
4
+ * FFmpeg is free software; you can redistribute it and/or
5
+ * modify it under the terms of the GNU Lesser General Public
6
+ * License as published by the Free Software Foundation; either
7
+ * version 2.1 of the License, or (at your option) any later version.
8
+ *
9
+ * FFmpeg is distributed in the hope that it will be useful,
10
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12
+ * Lesser General Public License for more details.
13
+ *
14
+ * You should have received a copy of the GNU Lesser General Public
15
+ * License along with FFmpeg; if not, write to the Free Software
16
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17
+ */
18
+
19
+#ifndef AVFORMAT_AVIO_INTERNAL_H
20
+#define AVFORMAT_AVIO_INTERNAL_H
21
+
22
+#include "avio.h"
23
+
24
+int ffio_init_context(AVIOContext *s,
25
+                  unsigned char *buffer,
26
+                  int buffer_size,
27
+                  int write_flag,
28
+                  void *opaque,
29
+                  int (*read_packet)(void *opaque, uint8_t *buf, int buf_size),
30
+                  int (*write_packet)(void *opaque, uint8_t *buf, int buf_size),
31
+                  int64_t (*seek)(void *opaque, int64_t offset, int whence));
32
+
33
+
34
+#endif // AVFORMAT_AVIO_INTERNAL_H
... ...
@@ -23,6 +23,7 @@
23 23
 #include "libavutil/intreadwrite.h"
24 24
 #include "avformat.h"
25 25
 #include "avio.h"
26
+#include "avio_internal.h"
26 27
 #include "internal.h"
27 28
 #include <stdarg.h>
28 29
 
... ...
@@ -40,7 +41,7 @@ static void fill_buffer(AVIOContext *s);
40 40
 static int url_resetbuf(AVIOContext *s, int flags);
41 41
 #endif
42 42
 
43
-int init_put_byte(AVIOContext *s,
43
+int ffio_init_context(AVIOContext *s,
44 44
                   unsigned char *buffer,
45 45
                   int buffer_size,
46 46
                   int write_flag,
... ...
@@ -73,6 +74,21 @@ int init_put_byte(AVIOContext *s,
73 73
     return 0;
74 74
 }
75 75
 
76
+#if FF_API_OLD_AVIO
77
+int init_put_byte(AVIOContext *s,
78
+                  unsigned char *buffer,
79
+                  int buffer_size,
80
+                  int write_flag,
81
+                  void *opaque,
82
+                  int (*read_packet)(void *opaque, uint8_t *buf, int buf_size),
83
+                  int (*write_packet)(void *opaque, uint8_t *buf, int buf_size),
84
+                  int64_t (*seek)(void *opaque, int64_t offset, int whence))
85
+{
86
+    return ffio_init_context(s, buffer, buffer_size, write_flag, opaque,
87
+                                read_packet, write_packet, seek);
88
+}
89
+#endif
90
+
76 91
 AVIOContext *av_alloc_put_byte(
77 92
                   unsigned char *buffer,
78 93
                   int buffer_size,
... ...
@@ -83,7 +99,7 @@ AVIOContext *av_alloc_put_byte(
83 83
                   int64_t (*seek)(void *opaque, int64_t offset, int whence))
84 84
 {
85 85
     AVIOContext *s = av_mallocz(sizeof(AVIOContext));
86
-    init_put_byte(s, buffer, buffer_size, write_flag, opaque,
86
+    ffio_init_context(s, buffer, buffer_size, write_flag, opaque,
87 87
                   read_packet, write_packet, seek);
88 88
     return s;
89 89
 }
... ...
@@ -664,7 +680,7 @@ int url_fdopen(AVIOContext **s, URLContext *h)
664 664
         return AVERROR(ENOMEM);
665 665
     }
666 666
 
667
-    if (init_put_byte(*s, buffer, buffer_size,
667
+    if (ffio_init_context(*s, buffer, buffer_size,
668 668
                       (h->flags & URL_WRONLY || h->flags & URL_RDWR), h,
669 669
                       url_read, url_write, url_seek) < 0) {
670 670
         av_free(buffer);
... ...
@@ -865,7 +881,7 @@ int url_open_buf(AVIOContext **s, uint8_t *buf, int buf_size, int flags)
865 865
     *s = av_mallocz(sizeof(AVIOContext));
866 866
     if(!*s)
867 867
         return AVERROR(ENOMEM);
868
-    ret = init_put_byte(*s, buf, buf_size,
868
+    ret = ffio_init_context(*s, buf, buf_size,
869 869
                         (flags & URL_WRONLY || flags & URL_RDWR),
870 870
                         NULL, NULL, NULL, NULL);
871 871
     if(ret != 0)
... ...
@@ -964,7 +980,7 @@ static int url_open_dyn_buf_internal(AVIOContext **s, int max_packet_size)
964 964
         return AVERROR(ENOMEM);
965 965
     }
966 966
     d->io_buffer_size = io_buffer_size;
967
-    ret = init_put_byte(*s, d->io_buffer, io_buffer_size,
967
+    ret = ffio_init_context(*s, d->io_buffer, io_buffer_size,
968 968
                         1, d, NULL,
969 969
                         max_packet_size ? dyn_packet_buf_write : dyn_buf_write,
970 970
                         max_packet_size ? NULL : dyn_buf_seek);
... ...
@@ -24,6 +24,7 @@
24 24
 #include "libavutil/avstring.h"
25 25
 #include "libavutil/intreadwrite.h"
26 26
 #include "metadata.h"
27
+#include "avio_internal.h"
27 28
 
28 29
 int ff_id3v2_match(const uint8_t *buf, const char * magic)
29 30
 {
... ...
@@ -216,7 +217,7 @@ static void ff_id3v2_parse(AVFormatContext *s, int len, uint8_t version, uint8_t
216 216
                         j--;
217 217
                     }
218 218
                 }
219
-                init_put_byte(&pb, buffer, j, 0, NULL, NULL, NULL, NULL);
219
+                ffio_init_context(&pb, buffer, j, 0, NULL, NULL, NULL, NULL);
220 220
                 read_ttag(s, &pb, j, tag);
221 221
             } else {
222 222
                 read_ttag(s, s->pb, tlen, tag);
... ...
@@ -31,6 +31,7 @@
31 31
 #include <stdio.h>
32 32
 #include "avformat.h"
33 33
 #include "internal.h"
34
+#include "avio_internal.h"
34 35
 /* For ff_codec_get_id(). */
35 36
 #include "riff.h"
36 37
 #include "isom.h"
... ...
@@ -698,7 +699,7 @@ static int matroska_ebmlnum_uint(MatroskaDemuxContext *matroska,
698 698
                                  uint8_t *data, uint32_t size, uint64_t *num)
699 699
 {
700 700
     AVIOContext pb;
701
-    init_put_byte(&pb, data, size, 0, NULL, NULL, NULL, NULL);
701
+    ffio_init_context(&pb, data, size, 0, NULL, NULL, NULL, NULL);
702 702
     return ebml_read_num(matroska, &pb, FFMIN(size, 8), num);
703 703
 }
704 704
 
... ...
@@ -1328,7 +1329,7 @@ static int matroska_read_header(AVFormatContext *s, AVFormatParameters *ap)
1328 1328
         } else if (!strcmp(track->codec_id, "A_MS/ACM")
1329 1329
                    && track->codec_priv.size >= 14
1330 1330
                    && track->codec_priv.data != NULL) {
1331
-            init_put_byte(&b, track->codec_priv.data, track->codec_priv.size,
1331
+            ffio_init_context(&b, track->codec_priv.data, track->codec_priv.size,
1332 1332
                           URL_RDONLY, NULL, NULL, NULL, NULL);
1333 1333
             ff_get_wav_header(&b, st->codec, track->codec_priv.size);
1334 1334
             codec_id = st->codec->codec_id;
... ...
@@ -1373,7 +1374,7 @@ static int matroska_read_header(AVFormatContext *s, AVFormatParameters *ap)
1373 1373
             extradata = av_mallocz(extradata_size);
1374 1374
             if (extradata == NULL)
1375 1375
                 return AVERROR(ENOMEM);
1376
-            init_put_byte(&b, extradata, extradata_size, 1,
1376
+            ffio_init_context(&b, extradata, extradata_size, 1,
1377 1377
                           NULL, NULL, NULL, NULL);
1378 1378
             put_buffer(&b, "TTA1", 4);
1379 1379
             put_le16(&b, 1);
... ...
@@ -1390,7 +1391,7 @@ static int matroska_read_header(AVFormatContext *s, AVFormatParameters *ap)
1390 1390
         } else if (codec_id == CODEC_ID_RA_288 || codec_id == CODEC_ID_COOK ||
1391 1391
                    codec_id == CODEC_ID_ATRAC3 || codec_id == CODEC_ID_SIPR) {
1392 1392
             int flavor;
1393
-            init_put_byte(&b, track->codec_priv.data,track->codec_priv.size,
1393
+            ffio_init_context(&b, track->codec_priv.data,track->codec_priv.size,
1394 1394
                           0, NULL, NULL, NULL, NULL);
1395 1395
             url_fskip(&b, 22);
1396 1396
             flavor                       = get_be16(&b);
... ...
@@ -31,6 +31,7 @@
31 31
 #include "avformat.h"
32 32
 #include "mms.h"
33 33
 #include "internal.h"
34
+#include "avio_internal.h"
34 35
 #include "libavutil/intreadwrite.h"
35 36
 #include "libavcodec/bytestream.h"
36 37
 #include "network.h"
... ...
@@ -155,7 +156,7 @@ static void mms_put_utf16(MMSContext *mms, uint8_t *src)
155 155
     AVIOContext bic;
156 156
     int size = mms->write_out_ptr - mms->out_buffer;
157 157
     int len;
158
-    init_put_byte(&bic, mms->write_out_ptr,
158
+    ffio_init_context(&bic, mms->write_out_ptr,
159 159
             sizeof(mms->out_buffer) - size, 1, NULL, NULL, NULL, NULL);
160 160
 
161 161
     len = avio_put_str16le(&bic, src);
... ...
@@ -29,6 +29,7 @@
29 29
 #include "libavutil/intreadwrite.h"
30 30
 #include "libavutil/avstring.h"
31 31
 #include "avformat.h"
32
+#include "avio_internal.h"
32 33
 #include "riff.h"
33 34
 #include "isom.h"
34 35
 #include "libavcodec/get_bits.h"
... ...
@@ -2123,7 +2124,7 @@ static int mov_read_cmov(MOVContext *c, AVIOContext *pb, MOVAtom atom)
2123 2123
     get_buffer(pb, cmov_data, cmov_len);
2124 2124
     if(uncompress (moov_data, (uLongf *) &moov_len, (const Bytef *)cmov_data, cmov_len) != Z_OK)
2125 2125
         goto free_and_return;
2126
-    if(init_put_byte(&ctx, moov_data, moov_len, 0, NULL, NULL, NULL, NULL) != 0)
2126
+    if(ffio_init_context(&ctx, moov_data, moov_len, 0, NULL, NULL, NULL, NULL) != 0)
2127 2127
         goto free_and_return;
2128 2128
     atom.type = MKTAG('m','o','o','v');
2129 2129
     atom.size = moov_len;
... ...
@@ -29,6 +29,7 @@
29 29
 #include "avformat.h"
30 30
 #include "mpegts.h"
31 31
 #include "internal.h"
32
+#include "avio_internal.h"
32 33
 #include "seek.h"
33 34
 #include "mpeg.h"
34 35
 #include "isom.h"
... ...
@@ -855,7 +856,7 @@ static int mp4_read_iods(AVFormatContext *s, const uint8_t *buf, unsigned size,
855 855
     int tag;
856 856
     unsigned len;
857 857
 
858
-    init_put_byte(&pb, buf, size, 0, NULL, NULL, NULL, NULL);
858
+    ffio_init_context(&pb, buf, size, 0, NULL, NULL, NULL, NULL);
859 859
 
860 860
     len = ff_mp4_read_descr(s, &pb, &tag);
861 861
     if (tag == MP4IODescrTag) {
... ...
@@ -914,7 +915,7 @@ int ff_parse_mpeg2_descriptor(AVFormatContext *fc, AVStream *st, int stream_type
914 914
         if (st->codec->codec_id == CODEC_ID_AAC_LATM &&
915 915
             mp4_dec_config_descr_len && mp4_es_id == pid) {
916 916
             AVIOContext pb;
917
-            init_put_byte(&pb, mp4_dec_config_descr,
917
+            ffio_init_context(&pb, mp4_dec_config_descr,
918 918
                           mp4_dec_config_descr_len, 0, NULL, NULL, NULL, NULL);
919 919
             ff_mp4_read_dec_config_descr(fc, st, &pb);
920 920
             if (st->codec->codec_id == CODEC_ID_AAC &&
... ...
@@ -33,6 +33,7 @@
33 33
 #include "libavutil/md5.h"
34 34
 #include "rm.h"
35 35
 #include "internal.h"
36
+#include "avio_internal.h"
36 37
 #include "libavcodec/get_bits.h"
37 38
 
38 39
 struct RDTDemuxContext {
... ...
@@ -150,7 +151,7 @@ rdt_load_mdpr (PayloadContext *rdt, AVStream *st, int rule_nr)
150 150
      */
151 151
     if (!rdt->mlti_data)
152 152
         return -1;
153
-    init_put_byte(&pb, rdt->mlti_data, rdt->mlti_data_size, 0,
153
+    ffio_init_context(&pb, rdt->mlti_data, rdt->mlti_data_size, 0,
154 154
                   NULL, NULL, NULL, NULL);
155 155
     tag = get_le32(&pb);
156 156
     if (tag == MKTAG('M', 'L', 'T', 'I')) {
... ...
@@ -300,7 +301,7 @@ rdt_parse_packet (AVFormatContext *ctx, PayloadContext *rdt, AVStream *st,
300 300
     if (rdt->audio_pkt_cnt == 0) {
301 301
         int pos;
302 302
 
303
-        init_put_byte(&pb, buf, len, 0, NULL, NULL, NULL, NULL);
303
+        ffio_init_context(&pb, buf, len, 0, NULL, NULL, NULL, NULL);
304 304
         flags = (flags & RTP_FLAG_KEY) ? 2 : 0;
305 305
         res = ff_rm_parse_packet (rdt->rmctx, &pb, st, rdt->rmst[st->index], len, pkt,
306 306
                                   &seq, flags, *timestamp);
... ...
@@ -32,6 +32,7 @@
32 32
 #include "rtpdec_formats.h"
33 33
 #include "rtsp.h"
34 34
 #include "asf.h"
35
+#include "avio_internal.h"
35 36
 
36 37
 /**
37 38
  * 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)
84 84
 
85 85
 static void init_packetizer(AVIOContext *pb, uint8_t *buf, int len)
86 86
 {
87
-    init_put_byte(pb, buf, len, 0, NULL, packetizer_read, NULL, NULL);
87
+    ffio_init_context(pb, buf, len, 0, NULL, packetizer_read, NULL, NULL);
88 88
 
89 89
     /* this "fills" the buffer with its current content */
90 90
     pb->pos     = len;
... ...
@@ -176,7 +177,7 @@ static int asfrtp_parse_packet(AVFormatContext *s, PayloadContext *asf,
176 176
 
177 177
         av_freep(&asf->buf);
178 178
 
179
-        init_put_byte(pb, buf, len, 0, NULL, NULL, NULL, NULL);
179
+        ffio_init_context(pb, buf, len, 0, NULL, NULL, NULL, NULL);
180 180
 
181 181
         while (url_ftell(pb) + 4 < len) {
182 182
             int start_off = url_ftell(pb);
... ...
@@ -26,6 +26,7 @@
26 26
  */
27 27
 
28 28
 #include "avformat.h"
29
+#include "avio_internal.h"
29 30
 #include "rtp.h"
30 31
 #include "rtpdec.h"
31 32
 #include "isom.h"
... ...
@@ -69,7 +70,7 @@ static int qt_rtp_parse_packet(AVFormatContext *s, PayloadContext *qt,
69 69
      * http://developer.apple.com/quicktime/icefloe/dispatch026.html
70 70
      */
71 71
     init_get_bits(&gb, buf, len << 3);
72
-    init_put_byte(&pb, buf, len, 0, NULL, NULL, NULL, NULL);
72
+    ffio_init_context(&pb, buf, len, 0, NULL, NULL, NULL, NULL);
73 73
 
74 74
     if (len < 4)
75 75
         return AVERROR_INVALIDDATA;
... ...
@@ -25,6 +25,7 @@
25 25
 #include "libavutil/parseutils.h"
26 26
 #include "libavutil/random_seed.h"
27 27
 #include "avformat.h"
28
+#include "avio_internal.h"
28 29
 
29 30
 #include <sys/time.h>
30 31
 #if HAVE_POLL_H
... ...
@@ -1913,7 +1914,7 @@ static int rtp_read_header(AVFormatContext *s,
1913 1913
              port, payload_type);
1914 1914
     av_log(s, AV_LOG_VERBOSE, "SDP:\n%s\n", sdp);
1915 1915
 
1916
-    init_put_byte(&pb, sdp, strlen(sdp), 0, NULL, NULL, NULL, NULL);
1916
+    ffio_init_context(&pb, sdp, strlen(sdp), 0, NULL, NULL, NULL, NULL);
1917 1917
     s->pb = &pb;
1918 1918
 
1919 1919
     /* sdp_read_header initializes this again */
... ...
@@ -25,6 +25,7 @@
25 25
 #include "network.h"
26 26
 #include "os_support.h"
27 27
 #include "internal.h"
28
+#include "avio_internal.h"
28 29
 #if HAVE_POLL_H
29 30
 #include <poll.h>
30 31
 #endif
... ...
@@ -142,7 +143,7 @@ static int sap_read_header(AVFormatContext *s,
142 142
     }
143 143
 
144 144
     av_log(s, AV_LOG_VERBOSE, "SDP:\n%s\n", sap->sdp);
145
-    init_put_byte(&sap->sdp_pb, sap->sdp, strlen(sap->sdp), 0, NULL, NULL,
145
+    ffio_init_context(&sap->sdp_pb, sap->sdp, strlen(sap->sdp), 0, NULL, NULL,
146 146
                   NULL, NULL);
147 147
 
148 148
     infmt = av_find_input_format("sdp");