Unified · Split
| @@ -30,6 +30,17 @@ · 29 unmodified lines | ||
| 30 | 30 | |
| 31 | 31 | typedef struct AVVorbisParseContext AVVorbisParseContext; |
| 32 | 32 | |
| 33 | +/** | |
| 34 | + * Used by the vorbis parser to pass new chained stream headers | |
| 35 | + * as extradata. | |
| 36 | + */ | |
| 37 | +typedef struct vorbis_new_extradata { | |
| 38 | + uint8_t *header; | |
| 39 | + size_t header_size; | |
| 40 | + uint8_t *setup; | |
| 41 | + size_t setup_size; | |
| 42 | +} vorbis_new_extradata; | |
| 43 | + | |
| 33 | 44 | /** |
| 34 | 45 | * Allocate and initialize the Vorbis parser using headers in the extradata. |
| 35 | 46 | */ |
| @@ -43,6 +43,7 @@ · 42 unmodified lines | ||
| 43 | 43 | #include "vorbis.h" |
| 44 | 44 | #include "vorbisdsp.h" |
| 45 | 45 | #include "vorbis_data.h" |
| 46 | +#include "vorbis_parser.h" | |
| 46 | 47 | #include "xiph.h" |
| 47 | 48 | |
| 48 | 49 | #define V_NB_BITS 8 |
| @@ -1778,47 +1779,59 @@ static int vorbis_decode_frame(AVCodecContext *avctx, AVFrame *frame, · 1729 unmodified lines | ||
| 1778 | 1779 | GetBitContext *gb = &vc->gb; |
| 1779 | 1780 | float *channel_ptrs[255]; |
| 1780 | 1781 | int i, len, ret; |
| 1782 | + size_t new_extradata_size; | |
| 1783 | + vorbis_new_extradata *new_extradata; | |
| 1784 | + const uint8_t *header; | |
| 1785 | + const uint8_t *setup; | |
| 1781 | 1786 | |
| 1782 | 1787 | ff_dlog(NULL, "packet length %d \n", buf_size); |
| 1783 | 1788 | |
| 1784 | − if (*buf == 1 && buf_size > 7) { | |
| 1785 | − if ((ret = init_get_bits8(gb, buf + 1, buf_size - 1)) < 0) | |
| 1786 | − return ret; | |
| 1789 | + new_extradata = (vorbis_new_extradata *)av_packet_get_side_data( | |
| 1790 | + avpkt, AV_PKT_DATA_NEW_EXTRADATA, &new_extradata_size); | |
| 1787 | 1791 | |
| 1788 | − vorbis_free(vc); | |
| 1789 | − if ((ret = vorbis_parse_id_hdr(vc))) { | |
| 1790 | − av_log(avctx, AV_LOG_ERROR, "Id header corrupt.\n"); | |
| 1791 | − vorbis_free(vc); | |
| 1792 | − return ret; | |
| 1793 | − } | |
| 1792 | + if (new_extradata) { | |
| 1793 | + header = new_extradata->header; | |
| 1794 | + setup = new_extradata->setup; | |
| 1794 | 1795 | |
| 1795 | − av_channel_layout_uninit(&avctx->ch_layout); | |
| 1796 | − if (vc->audio_channels > 8) { | |
| 1797 | − avctx->ch_layout.order = AV_CHANNEL_ORDER_UNSPEC; | |
| 1798 | − avctx->ch_layout.nb_channels = vc->audio_channels; | |
| 1799 | − } else { | |
| 1800 | − av_channel_layout_copy(&avctx->ch_layout, &ff_vorbis_ch_layouts[vc->audio_channels - 1]); | |
| 1801 | − } | |
| 1796 | + if (new_extradata->header_size > 7 && *header == 1) { | |
| 1797 | + if ((ret = init_get_bits8( | |
| 1798 | + gb, header + 1, | |
| 1799 | + new_extradata->header_size - 1)) < 0) | |
| 1800 | + return ret; | |
| 1802 | 1801 | |
| 1803 | − avctx->sample_rate = vc->audio_samplerate; | |
| 1804 | − return buf_size; | |
| 1805 | − } | |
| 1802 | + vorbis_free(vc); | |
| 1803 | + if ((ret = vorbis_parse_id_hdr(vc))) { | |
| 1804 | + av_log(avctx, AV_LOG_ERROR, "Id header corrupt.\n"); | |
| 1805 | + vorbis_free(vc); | |
| 1806 | + return ret; | |
| 1807 | + } | |
| 1806 | 1808 | |
| 1807 | − if (*buf == 3 && buf_size > 7) { | |
| 1808 | − av_log(avctx, AV_LOG_DEBUG, "Ignoring comment header\n"); | |
| 1809 | − return buf_size; | |
| 1810 | − } | |
| 1809 | + av_channel_layout_uninit(&avctx->ch_layout); | |
| 1810 | + if (vc->audio_channels > 8) { | |
| 1811 | + avctx->ch_layout.order = AV_CHANNEL_ORDER_UNSPEC; | |
| 1812 | + avctx->ch_layout.nb_channels = vc->audio_channels; | |
| 1813 | + } else { | |
| 1814 | + av_channel_layout_copy( | |
| 1815 | + &avctx->ch_layout, | |
| 1816 | + &ff_vorbis_ch_layouts[vc->audio_channels - 1]); | |
| 1817 | + } | |
| 1811 | 1818 | |
| 1812 | − if (*buf == 5 && buf_size > 7 && vc->channel_residues && !vc->modes) { | |
| 1813 | − if ((ret = init_get_bits8(gb, buf + 1, buf_size - 1)) < 0) | |
| 1814 | − return ret; | |
| 1819 | + avctx->sample_rate = vc->audio_samplerate; | |
| 1820 | + } | |
| 1815 | 1821 | |
| 1816 | − if ((ret = vorbis_parse_setup_hdr(vc))) { | |
| 1817 | − av_log(avctx, AV_LOG_ERROR, "Setup header corrupt.\n"); | |
| 1818 | − vorbis_free(vc); | |
| 1819 | − return ret; | |
| 1822 | + if (new_extradata->setup_size > 7 && *setup == 5 && | |
| 1823 | + vc->channel_residues && !vc->modes) { | |
| 1824 | + if ((ret = init_get_bits8( | |
| 1825 | + gb, setup + 1, | |
| 1826 | + new_extradata->setup_size - 1)) < 0) | |
| 1827 | + return ret; | |
| 1828 | + | |
| 1829 | + if ((ret = vorbis_parse_setup_hdr(vc))) { | |
| 1830 | + av_log(avctx, AV_LOG_ERROR, "Setup header corrupt.\n"); | |
| 1831 | + vorbis_free(vc); | |
| 1832 | + return ret; | |
| 1833 | + } | |
| 1820 | 1834 | } |
| 1821 | − return buf_size; | |
| 1822 | 1835 | } |
| 1823 | 1836 | |
| 1824 | 1837 | if (!vc->channel_residues || !vc->modes) { |
| @@ -255,12 +255,19 @@ static void vorbis_cleanup(AVFormatContext *s, int idx) · 254 unmodified lines | ||
| 255 | 255 | struct ogg *ogg = s->priv_data; |
| 256 | 256 | struct ogg_stream *os = ogg->streams + idx; |
| 257 | 257 | struct oggvorbis_private *priv = os->private; |
| 258 | + vorbis_new_extradata *new_extradata; | |
| 258 | 259 | int i; |
| 259 | 260 | if (os->private) { |
| 260 | 261 | av_vorbis_parse_free(&priv->vp); |
| 261 | 262 | for (i = 0; i < 3; i++) |
| 262 | 263 | av_freep(&priv->packet[i]); |
| 263 | 264 | } |
| 265 | + | |
| 266 | + if (os->new_extradata) { | |
| 267 | + new_extradata = (vorbis_new_extradata *)os->new_extradata; | |
| 268 | + av_freep(&new_extradata->header); | |
| 269 | + av_freep(&new_extradata->setup); | |
| 270 | + } | |
| 264 | 271 | } |
| 265 | 272 | |
| 266 | 273 | static int vorbis_update_metadata(AVFormatContext *s, int idx) |
| @@ -433,7 +440,10 @@ static int vorbis_packet(AVFormatContext *s, int idx) · 166 unmodified lines | ||
| 433 | 440 | struct ogg *ogg = s->priv_data; |
| 434 | 441 | struct ogg_stream *os = ogg->streams + idx; |
| 435 | 442 | struct oggvorbis_private *priv = os->private; |
| 443 | + vorbis_new_extradata *new_extradata; | |
| 436 | 444 | int duration, flags = 0; |
| 445 | + int skip_packet = 0; | |
| 446 | + int ret; | |
| 437 | 447 | |
| 438 | 448 | if (!priv->vp) |
| 439 | 449 | return AVERROR_INVALIDDATA; |
| @@ -496,10 +506,61 @@ static int vorbis_packet(AVFormatContext *s, int idx) · 56 unmodified lines | ||
| 496 | 506 | if (duration < 0) { |
| 497 | 507 | os->pflags |= AV_PKT_FLAG_CORRUPT; |
| 498 | 508 | return 0; |
| 499 | − } else if (flags & VORBIS_FLAG_COMMENT) { | |
| 500 | − vorbis_update_metadata(s, idx); | |
| 509 | + } | |
| 510 | + | |
| 511 | + if (flags & VORBIS_FLAG_HEADER) { | |
| 512 | + ret = vorbis_parse_header(s, s->streams[idx], os->buf + os->pstart, os->psize); | |
| 513 | + if (ret < 0) | |
| 514 | + return ret; | |
| 515 | + | |
| 516 | + if (!os->new_extradata) { | |
| 517 | + os->new_extradata = av_mallocz(sizeof(vorbis_new_extradata)); | |
| 518 | + if (!os->new_extradata) | |
| 519 | + return AVERROR(ENOMEM); | |
| 520 | + } | |
| 521 | + | |
| 522 | + os->new_extradata_size = sizeof(vorbis_new_extradata); | |
| 523 | + new_extradata = (vorbis_new_extradata *)os->new_extradata; | |
| 524 | + | |
| 525 | + ret = av_reallocp(&new_extradata->header, os->psize); | |
| 526 | + if (ret < 0) | |
| 527 | + return ret; | |
| 528 | + | |
| 529 | + memcpy(new_extradata->header, os->buf + os->pstart, os->psize); | |
| 530 | + new_extradata->header_size = os->psize; | |
| 531 | + | |
| 532 | + skip_packet = 1; | |
| 533 | + } | |
| 534 | + | |
| 535 | + if (flags & VORBIS_FLAG_COMMENT) { | |
| 536 | + ret = vorbis_update_metadata(s, idx); | |
| 537 | + if (ret < 0) | |
| 538 | + return ret; | |
| 539 | + | |
| 501 | 540 | flags = 0; |
| 541 | + skip_packet = 1; | |
| 542 | + } | |
| 543 | + | |
| 544 | + if (flags & VORBIS_FLAG_SETUP) { | |
| 545 | + if (!os->new_extradata) { | |
| 546 | + os->new_extradata = av_mallocz(sizeof(vorbis_new_extradata)); | |
| 547 | + if (!os->new_extradata) | |
| 548 | + return AVERROR(ENOMEM); | |
| 549 | + } | |
| 550 | + | |
| 551 | + os->new_extradata_size = sizeof(vorbis_new_extradata); | |
| 552 | + new_extradata = (vorbis_new_extradata *)os->new_extradata; | |
| 553 | + | |
| 554 | + ret = av_reallocp(&new_extradata->setup, os->psize); | |
| 555 | + if (ret < 0) | |
| 556 | + return ret; | |
| 557 | + | |
| 558 | + memcpy(new_extradata->setup, os->buf + os->pstart, os->psize); | |
| 559 | + new_extradata->setup_size = os->psize; | |
| 560 | + | |
| 561 | + skip_packet = 1; | |
| 502 | 562 | } |
| 563 | + | |
| 503 | 564 | os->pduration = duration; |
| 504 | 565 | } |
| 505 | 566 | |
| @@ -521,7 +582,7 @@ static int vorbis_packet(AVFormatContext *s, int idx) · 15 unmodified lines | ||
| 521 | 582 | priv->final_duration += os->pduration; |
| 522 | 583 | } |
| 523 | 584 | |
| 524 | − return 0; | |
| 585 | + return skip_packet; | |
| 525 | 586 | } |
| 526 | 587 | |
| 527 | 588 | const struct ogg_codec ff_vorbis_codec = { |
| @@ -6,10 +6,7 @@ Stream ID: 0, frame PTS: 128, metadata: N/A · 5 unmodified lines | ||
| 6 | 6 | Stream ID: 0, packet PTS: 704, packet DTS: 704 |
| 7 | 7 | Stream ID: 0, frame PTS: 704, metadata: N/A |
| 8 | 8 | Stream ID: 0, packet PTS: 0, packet DTS: 0 |
| 9 | −Stream ID: 0, packet PTS: 0, packet DTS: 0 | |
| 10 | 9 | Stream ID: 0, new metadata: encoder=Lavc61.19.100 libvorbis:title=Second Stream |
| 11 | −Stream ID: 0, packet PTS: 0, packet DTS: 0 | |
| 12 | −Stream ID: 0, packet PTS: 0, packet DTS: 0 | |
| 13 | 10 | Stream ID: 0, frame PTS: 0, metadata: N/A |
| 14 | 11 | Stream ID: 0, packet PTS: 128, packet DTS: 128 |
| 15 | 12 | Stream ID: 0, frame PTS: 128, metadata: N/A |