Commit 2cef81a8 authored by Alexandra Hájková's avatar Alexandra Hájková Committed by Diego Biurrun

ogg: Convert to the new bitstream reader

parent 8d1997ad
...@@ -19,8 +19,10 @@ ...@@ -19,8 +19,10 @@
*/ */
#include <stdlib.h> #include <stdlib.h>
#include "libavcodec/get_bits.h"
#include "libavcodec/bitstream.h"
#include "libavcodec/flac.h" #include "libavcodec/flac.h"
#include "avformat.h" #include "avformat.h"
#include "internal.h" #include "internal.h"
#include "oggdec.h" #include "oggdec.h"
...@@ -33,28 +35,28 @@ flac_header (AVFormatContext * s, int idx) ...@@ -33,28 +35,28 @@ flac_header (AVFormatContext * s, int idx)
struct ogg *ogg = s->priv_data; struct ogg *ogg = s->priv_data;
struct ogg_stream *os = ogg->streams + idx; struct ogg_stream *os = ogg->streams + idx;
AVStream *st = s->streams[idx]; AVStream *st = s->streams[idx];
GetBitContext gb; BitstreamContext bc;
int mdt; int mdt;
if (os->buf[os->pstart] == 0xff) if (os->buf[os->pstart] == 0xff)
return 0; return 0;
init_get_bits(&gb, os->buf + os->pstart, os->psize*8); bitstream_init(&bc, os->buf + os->pstart, os->psize * 8);
skip_bits1(&gb); /* metadata_last */ bitstream_skip(&bc, 1); /* metadata_last */
mdt = get_bits(&gb, 7); mdt = bitstream_read(&bc, 7);
if (mdt == OGG_FLAC_METADATA_TYPE_STREAMINFO) { if (mdt == OGG_FLAC_METADATA_TYPE_STREAMINFO) {
uint8_t *streaminfo_start = os->buf + os->pstart + 5 + 4 + 4 + 4; uint8_t *streaminfo_start = os->buf + os->pstart + 5 + 4 + 4 + 4;
uint32_t samplerate; uint32_t samplerate;
skip_bits_long(&gb, 4*8); /* "FLAC" */ bitstream_skip(&bc, 4 * 8); /* "FLAC" */
if(get_bits(&gb, 8) != 1) /* unsupported major version */ if (bitstream_read(&bc, 8) != 1) /* unsupported major version */
return -1; return -1;
skip_bits_long(&gb, 8 + 16); /* minor version + header count */ bitstream_skip(&bc, 8 + 16); /* minor version + header count */
skip_bits_long(&gb, 4*8); /* "fLaC" */ bitstream_skip(&bc, 4 * 8); /* "fLaC" */
/* METADATA_BLOCK_HEADER */ /* METADATA_BLOCK_HEADER */
if (get_bits_long(&gb, 32) != FLAC_STREAMINFO_SIZE) if (bitstream_read(&bc, 32) != FLAC_STREAMINFO_SIZE)
return -1; return -1;
st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO;
......
...@@ -23,8 +23,11 @@ ...@@ -23,8 +23,11 @@
**/ **/
#include <stdlib.h> #include <stdlib.h>
#include "libavutil/bswap.h" #include "libavutil/bswap.h"
#include "libavcodec/get_bits.h"
#include "libavcodec/bitstream.h"
#include "avformat.h" #include "avformat.h"
#include "internal.h" #include "internal.h"
#include "oggdec.h" #include "oggdec.h"
...@@ -57,41 +60,41 @@ static int theora_header(AVFormatContext *s, int idx) ...@@ -57,41 +60,41 @@ static int theora_header(AVFormatContext *s, int idx)
switch (os->buf[os->pstart]) { switch (os->buf[os->pstart]) {
case 0x80: { case 0x80: {
GetBitContext gb; BitstreamContext bc;
AVRational timebase; AVRational timebase;
init_get_bits(&gb, os->buf + os->pstart, os->psize * 8); bitstream_init(&bc, os->buf + os->pstart, os->psize * 8);
/* 0x80"theora" */ /* 0x80"theora" */
skip_bits_long(&gb, 7 * 8); bitstream_skip(&bc, 7 * 8);
thp->version = get_bits_long(&gb, 24); thp->version = bitstream_read(&bc, 24);
if (thp->version < 0x030100) { if (thp->version < 0x030100) {
av_log(s, AV_LOG_ERROR, av_log(s, AV_LOG_ERROR,
"Too old or unsupported Theora (%x)\n", thp->version); "Too old or unsupported Theora (%x)\n", thp->version);
return AVERROR(ENOSYS); return AVERROR(ENOSYS);
} }
st->codecpar->width = get_bits(&gb, 16) << 4; st->codecpar->width = bitstream_read(&bc, 16) << 4;
st->codecpar->height = get_bits(&gb, 16) << 4; st->codecpar->height = bitstream_read(&bc, 16) << 4;
if (thp->version >= 0x030400) if (thp->version >= 0x030400)
skip_bits(&gb, 100); bitstream_skip(&bc, 100);
if (thp->version >= 0x030200) { if (thp->version >= 0x030200) {
int width = get_bits_long(&gb, 24); int width = bitstream_read(&bc, 24);
int height = get_bits_long(&gb, 24); int height = bitstream_read(&bc, 24);
if (width <= st->codecpar->width && width > st->codecpar->width - 16 && if (width <= st->codecpar->width && width > st->codecpar->width - 16 &&
height <= st->codecpar->height && height > st->codecpar->height - 16) { height <= st->codecpar->height && height > st->codecpar->height - 16) {
st->codecpar->width = width; st->codecpar->width = width;
st->codecpar->height = height; st->codecpar->height = height;
} }
skip_bits(&gb, 16); bitstream_skip(&bc, 16);
} }
timebase.den = get_bits_long(&gb, 32); timebase.den = bitstream_read(&bc, 32);
timebase.num = get_bits_long(&gb, 32); timebase.num = bitstream_read(&bc, 32);
if (!(timebase.num > 0 && timebase.den > 0)) { if (!(timebase.num > 0 && timebase.den > 0)) {
av_log(s, AV_LOG_WARNING, "Invalid time base in theora stream, assuming 25 FPS\n"); av_log(s, AV_LOG_WARNING, "Invalid time base in theora stream, assuming 25 FPS\n");
timebase.num = 1; timebase.num = 1;
...@@ -99,15 +102,15 @@ static int theora_header(AVFormatContext *s, int idx) ...@@ -99,15 +102,15 @@ static int theora_header(AVFormatContext *s, int idx)
} }
avpriv_set_pts_info(st, 64, timebase.num, timebase.den); avpriv_set_pts_info(st, 64, timebase.num, timebase.den);
st->sample_aspect_ratio.num = get_bits_long(&gb, 24); st->sample_aspect_ratio.num = bitstream_read(&bc, 24);
st->sample_aspect_ratio.den = get_bits_long(&gb, 24); st->sample_aspect_ratio.den = bitstream_read(&bc, 24);
if (thp->version >= 0x030200) if (thp->version >= 0x030200)
skip_bits_long(&gb, 38); bitstream_skip(&bc, 38);
if (thp->version >= 0x304000) if (thp->version >= 0x304000)
skip_bits(&gb, 2); bitstream_skip(&bc, 2);
thp->gpshift = get_bits(&gb, 5); thp->gpshift = bitstream_read(&bc, 5);
thp->gpmask = (1 << thp->gpshift) - 1; thp->gpmask = (1 << thp->gpshift) - 1;
st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment