Browse code

Merge commit 'a3a0af4fb1237bed0af75868073f9a63db8b1864'

* commit 'a3a0af4fb1237bed0af75868073f9a63db8b1864':
avutil: make aes and sha api public
handle malloc failures in ff_get_wav_header
add xWMA demuxer
mpegts: force the default timebase
libavcodec: Bump micro after adding the dtx AVOptions

Merged-by: Michael Niedermayer <michaelni@gmx.at>

Michael Niedermayer authored on 2011/04/15 11:37:17
Showing 18 changed files
... ...
@@ -93,6 +93,7 @@ version <next>:
93 93
 - fieldorder video filter added
94 94
 - AAC encoding via libvo-aacenc
95 95
 - AMR-WB encoding via libvo-amrwbenc
96
+- xWMA demuxer
96 97
 
97 98
 
98 99
 version 0.6:
... ...
@@ -259,6 +259,8 @@ library:
259 259
     @tab Multimedia format used in Westwood Studios games.
260 260
 @item Westwood Studios VQA      @tab   @tab X
261 261
     @tab Multimedia format used in Westwood Studios games.
262
+@item xWMA                      @tab   @tab X
263
+    @tab Microsoft audio container used by XAudio 2.
262 264
 @item YUV4MPEG pipe             @tab X @tab X
263 265
 @item Psygnosis YOP             @tab   @tab X
264 266
 @end multitable
... ...
@@ -2,20 +2,20 @@
2 2
  * AAC encoder wrapper
3 3
  * Copyright (c) 2010 Martin Storsjo
4 4
  *
5
- * This file is part of Libav.
5
+ * This file is part of FFmpeg.
6 6
  *
7
- * Libav is free software; you can redistribute it and/or
7
+ * FFmpeg is free software; you can redistribute it and/or
8 8
  * modify it under the terms of the GNU Lesser General Public
9 9
  * License as published by the Free Software Foundation; either
10 10
  * version 2.1 of the License, or (at your option) any later version.
11 11
  *
12
- * Libav is distributed in the hope that it will be useful,
12
+ * FFmpeg is distributed in the hope that it will be useful,
13 13
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 14
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15 15
  * Lesser General Public License for more details.
16 16
  *
17 17
  * You should have received a copy of the GNU Lesser General Public
18
- * License along with Libav; if not, write to the Free Software
18
+ * License along with FFmpeg; if not, write to the Free Software
19 19
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 20
  */
21 21
 
... ...
@@ -2,20 +2,20 @@
2 2
  * AMR Audio encoder stub
3 3
  * Copyright (c) 2003 the ffmpeg project
4 4
  *
5
- * This file is part of Libav.
5
+ * This file is part of FFmpeg.
6 6
  *
7
- * Libav is free software; you can redistribute it and/or
7
+ * FFmpeg is free software; you can redistribute it and/or
8 8
  * modify it under the terms of the GNU Lesser General Public
9 9
  * License as published by the Free Software Foundation; either
10 10
  * version 2.1 of the License, or (at your option) any later version.
11 11
  *
12
- * Libav is distributed in the hope that it will be useful,
12
+ * FFmpeg is distributed in the hope that it will be useful,
13 13
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 14
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15 15
  * Lesser General Public License for more details.
16 16
  *
17 17
  * You should have received a copy of the GNU Lesser General Public
18
- * License along with Libav; if not, write to the Free Software
18
+ * License along with FFmpeg; if not, write to the Free Software
19 19
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 20
  */
21 21
 
... ...
@@ -22,7 +22,7 @@
22 22
 
23 23
 #define LIBAVCODEC_VERSION_MAJOR 52
24 24
 #define LIBAVCODEC_VERSION_MINOR 119
25
-#define LIBAVCODEC_VERSION_MICRO  0
25
+#define LIBAVCODEC_VERSION_MICRO  1
26 26
 
27 27
 #define LIBAVCODEC_VERSION_INT  AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \
28 28
                                                LIBAVCODEC_VERSION_MINOR, \
... ...
@@ -302,6 +302,7 @@ OBJS-$(CONFIG_WSVQA_DEMUXER)             += westwood.o
302 302
 OBJS-$(CONFIG_WTV_DEMUXER)               += wtv.o asf.o asfdec.o mpegts.o riff.o
303 303
 OBJS-$(CONFIG_WV_DEMUXER)                += wv.o apetag.o
304 304
 OBJS-$(CONFIG_XA_DEMUXER)                += xa.o
305
+OBJS-$(CONFIG_XWMA_DEMUXER)              += xwma.o riff.o
305 306
 OBJS-$(CONFIG_YOP_DEMUXER)               += yop.o
306 307
 OBJS-$(CONFIG_YUV4MPEGPIPE_MUXER)        += yuv4mpeg.o
307 308
 OBJS-$(CONFIG_YUV4MPEGPIPE_DEMUXER)      += yuv4mpeg.o
... ...
@@ -227,6 +227,7 @@ void av_register_all(void)
227 227
     REGISTER_DEMUXER  (WTV, wtv);
228 228
     REGISTER_DEMUXER  (WV, wv);
229 229
     REGISTER_DEMUXER  (XA, xa);
230
+    REGISTER_DEMUXER  (XWMA, xwma);
230 231
     REGISTER_DEMUXER  (YOP, yop);
231 232
     REGISTER_MUXDEMUX (YUV4MPEGPIPE, yuv4mpegpipe);
232 233
 
... ...
@@ -280,7 +280,9 @@ static int asf_read_stream_properties(AVFormatContext *s, int64_t size)
280 280
 
281 281
     st->codec->codec_type = type;
282 282
     if (type == AVMEDIA_TYPE_AUDIO) {
283
-        ff_get_wav_header(pb, st->codec, type_specific_size);
283
+        int ret = ff_get_wav_header(pb, st->codec, type_specific_size);
284
+        if (ret < 0)
285
+            return ret;
284 286
         if (is_dvr_ms_audio) {
285 287
             // codec_id and codec_tag are unreliable in dvr_ms
286 288
             // files. Set them later by probing stream.
... ...
@@ -345,6 +345,7 @@ static int avi_read_header(AVFormatContext *s, AVFormatParameters *ap)
345 345
     int avih_width=0, avih_height=0;
346 346
     int amv_file_format=0;
347 347
     uint64_t list_end = 0;
348
+    int ret;
348 349
 
349 350
     avi->stream_index= -1;
350 351
 
... ...
@@ -623,7 +624,9 @@ static int avi_read_header(AVFormatContext *s, AVFormatParameters *ap)
623 623
 //                    avio_skip(pb, size - 5 * 4);
624 624
                     break;
625 625
                 case AVMEDIA_TYPE_AUDIO:
626
-                    ff_get_wav_header(pb, st->codec, size);
626
+                    ret = ff_get_wav_header(pb, st->codec, size);
627
+                    if (ret < 0)
628
+                        return ret;
627 629
                     ast->dshow_block_align= st->codec->block_align;
628 630
                     if(ast->sample_size && st->codec->block_align && ast->sample_size != st->codec->block_align){
629 631
                         av_log(s, AV_LOG_WARNING, "sample size (%d) != block align (%d)\n", ast->sample_size, st->codec->block_align);
... ...
@@ -60,6 +60,7 @@ static int dxa_read_header(AVFormatContext *s, AVFormatParameters *ap)
60 60
     int w, h;
61 61
     int num, den;
62 62
     int flags;
63
+    int ret;
63 64
 
64 65
     tag = avio_rl32(pb);
65 66
     if (tag != MKTAG('D', 'E', 'X', 'A'))
... ...
@@ -102,7 +103,9 @@ static int dxa_read_header(AVFormatContext *s, AVFormatParameters *ap)
102 102
         ast = av_new_stream(s, 0);
103 103
         if (!ast)
104 104
             return -1;
105
-        ff_get_wav_header(pb, ast->codec, fsize);
105
+        ret = ff_get_wav_header(pb, ast->codec, fsize);
106
+        if (ret < 0)
107
+            return ret;
106 108
         // find 'data' chunk
107 109
         while(avio_tell(pb) < c->vidpos && !url_feof(pb)){
108 110
             tag = avio_rl32(pb);
... ...
@@ -1332,9 +1332,12 @@ static int matroska_read_header(AVFormatContext *s, AVFormatParameters *ap)
1332 1332
         } else if (!strcmp(track->codec_id, "A_MS/ACM")
1333 1333
                    && track->codec_priv.size >= 14
1334 1334
                    && track->codec_priv.data != NULL) {
1335
+            int ret;
1335 1336
             ffio_init_context(&b, track->codec_priv.data, track->codec_priv.size,
1336 1337
                           AVIO_RDONLY, NULL, NULL, NULL, NULL);
1337
-            ff_get_wav_header(&b, st->codec, track->codec_priv.size);
1338
+            ret = ff_get_wav_header(&b, st->codec, track->codec_priv.size);
1339
+            if (ret < 0)
1340
+                return ret;
1338 1341
             codec_id = st->codec->codec_id;
1339 1342
             extradata_offset = FFMIN(track->codec_priv.size, 18);
1340 1343
         } else if (!strcmp(track->codec_id, "V_QUICKTIME")
... ...
@@ -479,6 +479,7 @@ static int mpegts_write_header(AVFormatContext *s)
479 479
     /* assign pids to each stream */
480 480
     for(i = 0;i < s->nb_streams; i++) {
481 481
         st = s->streams[i];
482
+        av_set_pts_info(st, 33, 1, 90000);
482 483
         ts_st = av_mallocz(sizeof(MpegTSWriteStream));
483 484
         if (!ts_st)
484 485
             goto fail;
... ...
@@ -488,7 +488,7 @@ void ff_put_bmp_header(AVIOContext *pb, AVCodecContext *enc, const AVCodecTag *t
488 488
  * WAVEFORMATEX adds 'WORD  cbSize' and basically makes itself
489 489
  * an openended structure.
490 490
  */
491
-void ff_get_wav_header(AVIOContext *pb, AVCodecContext *codec, int size)
491
+int ff_get_wav_header(AVIOContext *pb, AVCodecContext *codec, int size)
492 492
 {
493 493
     int id;
494 494
 
... ...
@@ -531,6 +531,8 @@ void ff_get_wav_header(AVIOContext *pb, AVCodecContext *codec, int size)
531 531
         codec->extradata_size = cbSize;
532 532
         if (cbSize > 0) {
533 533
             codec->extradata = av_mallocz(codec->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE);
534
+            if (!codec->extradata)
535
+                return AVERROR(ENOMEM);
534 536
             avio_read(pb, codec->extradata, codec->extradata_size);
535 537
             size -= cbSize;
536 538
         }
... ...
@@ -544,6 +546,8 @@ void ff_get_wav_header(AVIOContext *pb, AVCodecContext *codec, int size)
544 544
         codec->channels    = 0;
545 545
         codec->sample_rate = 0;
546 546
     }
547
+
548
+    return 0;
547 549
 }
548 550
 
549 551
 
... ...
@@ -45,7 +45,7 @@ int ff_get_bmp_header(AVIOContext *pb, AVStream *st);
45 45
 void ff_put_bmp_header(AVIOContext *pb, AVCodecContext *enc, const AVCodecTag *tags, int for_asf);
46 46
 int ff_put_wav_header(AVIOContext *pb, AVCodecContext *enc);
47 47
 enum CodecID ff_wav_codec_get_id(unsigned int tag, int bps);
48
-void ff_get_wav_header(AVIOContext *pb, AVCodecContext *codec, int size);
48
+int ff_get_wav_header(AVIOContext *pb, AVCodecContext *codec, int size);
49 49
 
50 50
 extern const AVCodecTag ff_codec_bmp_tags[];
51 51
 extern const AVCodecTag ff_codec_wav_tags[];
... ...
@@ -24,7 +24,7 @@
24 24
 #include "libavutil/avutil.h"
25 25
 
26 26
 #define LIBAVFORMAT_VERSION_MAJOR 52
27
-#define LIBAVFORMAT_VERSION_MINOR 107
27
+#define LIBAVFORMAT_VERSION_MINOR 108
28 28
 #define LIBAVFORMAT_VERSION_MICRO  0
29 29
 
30 30
 #define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \
... ...
@@ -195,6 +195,7 @@ static int wav_read_header(AVFormatContext *s,
195 195
     AVIOContext *pb = s->pb;
196 196
     AVStream *st;
197 197
     WAVContext *wav = s->priv_data;
198
+    int ret;
198 199
 
199 200
     /* check RIFF header */
200 201
     tag = avio_rl32(pb);
... ...
@@ -227,7 +228,9 @@ static int wav_read_header(AVFormatContext *s,
227 227
     if (!st)
228 228
         return AVERROR(ENOMEM);
229 229
 
230
-    ff_get_wav_header(pb, st->codec, size);
230
+    ret = ff_get_wav_header(pb, st->codec, size);
231
+    if (ret < 0)
232
+        return ret;
231 233
     st->need_parsing = AVSTREAM_PARSE_FULL;
232 234
 
233 235
     av_set_pts_info(st, 64, 1, st->codec->sample_rate);
... ...
@@ -383,6 +386,7 @@ static int w64_read_header(AVFormatContext *s, AVFormatParameters *ap)
383 383
     WAVContext    *wav = s->priv_data;
384 384
     AVStream *st;
385 385
     uint8_t guid[16];
386
+    int ret;
386 387
 
387 388
     avio_read(pb, guid, 16);
388 389
     if (memcmp(guid, guid_riff, 16))
... ...
@@ -408,7 +412,9 @@ static int w64_read_header(AVFormatContext *s, AVFormatParameters *ap)
408 408
         return AVERROR(ENOMEM);
409 409
 
410 410
     /* subtract chunk header size - normal wav file doesn't count it */
411
-    ff_get_wav_header(pb, st->codec, size - 24);
411
+    ret = ff_get_wav_header(pb, st->codec, size - 24);
412
+    if (ret < 0)
413
+        return ret;
412 414
     avio_skip(pb, FFALIGN(size, INT64_C(8)) - size);
413 415
 
414 416
     st->need_parsing = AVSTREAM_PARSE_FULL;
... ...
@@ -645,7 +645,9 @@ static AVStream * parse_media_type(AVFormatContext *s, AVStream *st, int sid,
645 645
         if (!st)
646 646
             return NULL;
647 647
         if (!ff_guidcmp(formattype, format_waveformatex)) {
648
-            ff_get_wav_header(pb, st->codec, size);
648
+            int ret = ff_get_wav_header(pb, st->codec, size);
649
+            if (ret < 0)
650
+                return NULL;
649 651
         } else {
650 652
             if (ff_guidcmp(formattype, format_none))
651 653
                 av_log(s, AV_LOG_WARNING, "unknown formattype:"FF_PRI_GUID"\n", FF_ARG_GUID(formattype));
652 654
new file mode 100644
... ...
@@ -0,0 +1,257 @@
0
+/*
1
+ * xWMA demuxer
2
+ * Copyright (c) 2011 Max Horn
3
+ *
4
+ * This file is part of FFmpeg.
5
+ *
6
+ * FFmpeg is free software; you can redistribute it and/or
7
+ * modify it under the terms of the GNU Lesser General Public
8
+ * License as published by the Free Software Foundation; either
9
+ * version 2.1 of the License, or (at your option) any later version.
10
+ *
11
+ * FFmpeg is distributed in the hope that it will be useful,
12
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14
+ * Lesser General Public License for more details.
15
+ *
16
+ * You should have received a copy of the GNU Lesser General Public
17
+ * License along with FFmpeg; if not, write to the Free Software
18
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19
+ */
20
+
21
+#include "avformat.h"
22
+#include "riff.h"
23
+
24
+/*
25
+ * Demuxer for xWMA, a Microsoft audio container used by XAudio 2.
26
+ */
27
+
28
+typedef struct {
29
+    int64_t data_end;
30
+} XWMAContext;
31
+
32
+static int xwma_probe(AVProbeData *p)
33
+{
34
+    if (!memcmp(p->buf, "RIFF", 4) && !memcmp(p->buf + 8, "XWMA", 4))
35
+        return AVPROBE_SCORE_MAX;
36
+    return 0;
37
+}
38
+
39
+static int xwma_read_header(AVFormatContext *s, AVFormatParameters *ap)
40
+{
41
+    int64_t size, av_uninit(data_size);
42
+    int ret;
43
+    uint32_t dpds_table_size = 0;
44
+    uint32_t *dpds_table = 0;
45
+    unsigned int tag;
46
+    AVIOContext *pb = s->pb;
47
+    AVStream *st;
48
+    XWMAContext *xwma = s->priv_data;
49
+    int i;
50
+
51
+    /* The following code is mostly copied from wav.c, with some
52
+     * minor alterations.
53
+     */
54
+
55
+    /* check RIFF header */
56
+    tag = avio_rl32(pb);
57
+    if (tag != MKTAG('R', 'I', 'F', 'F'))
58
+        return -1;
59
+    avio_rl32(pb); /* file size */
60
+    tag = avio_rl32(pb);
61
+    if (tag != MKTAG('X', 'W', 'M', 'A'))
62
+        return -1;
63
+
64
+    /* parse fmt header */
65
+    tag = avio_rl32(pb);
66
+    if (tag != MKTAG('f', 'm', 't', ' '))
67
+        return -1;
68
+    size = avio_rl32(pb);
69
+    st = av_new_stream(s, 0);
70
+    if (!st)
71
+        return AVERROR(ENOMEM);
72
+
73
+    ret = ff_get_wav_header(pb, st->codec, size);
74
+    if (ret < 0)
75
+        return ret;
76
+    st->need_parsing = AVSTREAM_PARSE_NONE;
77
+
78
+    /* All xWMA files I have seen contained WMAv2 data. If there are files
79
+     * using WMA Pro or some other codec, then we need to figure out the right
80
+     * extradata for that. Thus, ask the user for feedback, but try to go on
81
+     * anyway.
82
+     */
83
+    if (st->codec->codec_id != CODEC_ID_WMAV2) {
84
+        av_log(s, AV_LOG_WARNING, "unexpected codec (tag 0x04%x; id %d)\n",
85
+                              st->codec->codec_tag, st->codec->codec_id);
86
+        av_log_ask_for_sample(s, NULL);
87
+    } else {
88
+        /* In all xWMA files I have seen, there is no extradata. But the WMA
89
+         * codecs require extradata, so we provide our own fake extradata.
90
+         *
91
+         * First, check that there really was no extradata in the header. If
92
+         * there was, then try to use, after asking the the user to provide a
93
+         * sample of this unusual file.
94
+         */
95
+        if (st->codec->extradata_size != 0) {
96
+            /* Surprise, surprise: We *did* get some extradata. No idea
97
+             * if it will work, but just go on and try it, after asking
98
+             * the user for a sample.
99
+             */
100
+            av_log(s, AV_LOG_WARNING, "unexpected extradata (%d bytes)\n",
101
+                                  st->codec->extradata_size);
102
+            av_log_ask_for_sample(s, NULL);
103
+        } else {
104
+            st->codec->extradata_size = 6;
105
+            st->codec->extradata      = av_mallocz(6 + FF_INPUT_BUFFER_PADDING_SIZE);
106
+            if (!st->codec->extradata)
107
+                return AVERROR(ENOMEM);
108
+
109
+            /* setup extradata with our experimentally obtained value */
110
+            st->codec->extradata[4] = 31;
111
+        }
112
+    }
113
+
114
+    /* set the sample rate */
115
+    av_set_pts_info(st, 64, 1, st->codec->sample_rate);
116
+
117
+    /* parse the remaining RIFF chunks */
118
+    for (;;) {
119
+        if (pb->eof_reached)
120
+            return -1;
121
+        /* read next chunk tag */
122
+        tag = avio_rl32(pb);
123
+        size = avio_rl32(pb);
124
+        if (tag == MKTAG('d', 'a', 't', 'a')) {
125
+            /* We assume that the data chunk comes last. */
126
+            break;
127
+        } else if (tag == MKTAG('d','p','d','s')) {
128
+            /* Quoting the MSDN xWMA docs on the dpds chunk: "Contains the
129
+             * decoded packet cumulative data size array, each element is the
130
+             * number of bytes accumulated after the corresponding xWMA packet
131
+             * is decoded in order"
132
+             *
133
+             * Each packet has size equal to st->codec->block_align, which in
134
+             * all cases I saw so far was always 2230. Thus, we can use the
135
+             * dpds data to compute a seeking index.
136
+             */
137
+
138
+            /* Error out if there is more than one dpds chunk. */
139
+            if (dpds_table) {
140
+                av_log(s, AV_LOG_ERROR, "two dpds chunks present\n");
141
+                return -1;
142
+            }
143
+
144
+            /* Compute the number of entries in the dpds chunk. */
145
+            if (size & 3) {  /* Size should be divisible by four */
146
+                av_log(s, AV_LOG_WARNING, "dpds chunk size "PRId64" not divisible by 4\n", size);
147
+            }
148
+            dpds_table_size = size / 4;
149
+            if (dpds_table_size == 0 || dpds_table_size >= INT_MAX / 4) {
150
+                av_log(s, AV_LOG_ERROR, "dpds chunk size "PRId64" invalid\n", size);
151
+                return -1;
152
+            }
153
+
154
+            /* Allocate some temporary storage to keep the dpds data around.
155
+             * for processing later on.
156
+             */
157
+            dpds_table = av_malloc(dpds_table_size * sizeof(uint32_t));
158
+            if (!dpds_table) {
159
+                return AVERROR(ENOMEM);
160
+            }
161
+
162
+            for (i = 0; i < dpds_table_size; ++i) {
163
+                dpds_table[i] = avio_rl32(pb);
164
+                size -= 4;
165
+            }
166
+        }
167
+        avio_skip(pb, size);
168
+    }
169
+
170
+    /* Determine overall data length */
171
+    if (size < 0)
172
+        return -1;
173
+    if (!size) {
174
+        xwma->data_end = INT64_MAX;
175
+    } else
176
+        xwma->data_end = avio_tell(pb) + size;
177
+
178
+
179
+    if (dpds_table && dpds_table_size) {
180
+        int64_t cur_pos;
181
+        const uint32_t bytes_per_sample
182
+                = (st->codec->channels * st->codec->bits_per_coded_sample) >> 3;
183
+
184
+        /* Estimate the duration from the total number of output bytes. */
185
+        const uint64_t total_decoded_bytes = dpds_table[dpds_table_size - 1];
186
+        st->duration = total_decoded_bytes / bytes_per_sample;
187
+
188
+        /* Use the dpds data to build a seek table.  We can only do this after
189
+         * we know the offset to the data chunk, as we need that to determine
190
+         * the actual offset to each input block.
191
+         * Note: If we allowed ourselves to assume that the data chunk always
192
+         * follows immediately after the dpds block, we could of course guess
193
+         * the data block's start offset already while reading the dpds chunk.
194
+         * I decided against that, just in case other chunks ever are
195
+         * discovered.
196
+         */
197
+        cur_pos = avio_tell(pb);
198
+        for (i = 0; i < dpds_table_size; ++i) {
199
+            /* From the number of output bytes that would accumulate in the
200
+             * output buffer after decoding the first (i+1) packets, we compute
201
+             * an offset / timestamp pair.
202
+             */
203
+            av_add_index_entry(st,
204
+                               cur_pos + (i+1) * st->codec->block_align, /* pos */
205
+                               dpds_table[i] / bytes_per_sample,         /* timestamp */
206
+                               st->codec->block_align,                   /* size */
207
+                               0,                                        /* duration */
208
+                               AVINDEX_KEYFRAME);
209
+        }
210
+    } else if (st->codec->bit_rate) {
211
+        /* No dpds chunk was present (or only an empty one), so estimate
212
+         * the total duration using the average bits per sample and the
213
+         * total data length.
214
+         */
215
+        st->duration = (size<<3) * st->codec->sample_rate / st->codec->bit_rate;
216
+    }
217
+
218
+    av_free(dpds_table);
219
+
220
+    return 0;
221
+}
222
+
223
+static int xwma_read_packet(AVFormatContext *s, AVPacket *pkt)
224
+{
225
+    int ret, size;
226
+    int64_t left;
227
+    AVStream *st;
228
+    XWMAContext *xwma = s->priv_data;
229
+
230
+    st = s->streams[0];
231
+
232
+    left = xwma->data_end - avio_tell(s->pb);
233
+    if (left <= 0) {
234
+        return AVERROR_EOF;
235
+    }
236
+
237
+    /* read a single block; the default block size is 2230. */
238
+    size = (st->codec->block_align > 1) ? st->codec->block_align : 2230;
239
+    size = FFMIN(size, left);
240
+
241
+    ret  = av_get_packet(s->pb, pkt, size);
242
+    if (ret < 0)
243
+        return ret;
244
+
245
+    pkt->stream_index = 0;
246
+    return ret;
247
+}
248
+
249
+AVInputFormat ff_xwma_demuxer = {
250
+    "xwma",
251
+    NULL_IF_CONFIG_SMALL("Microsoft xWMA"),
252
+    sizeof(XWMAContext),
253
+    xwma_probe,
254
+    xwma_read_header,
255
+    xwma_read_packet,
256
+};