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

rtp: Convert to the new bitstream reader

parent a895292f
...@@ -19,7 +19,8 @@ ...@@ -19,7 +19,8 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/ */
#include "libavcodec/get_bits.h" #include "libavcodec/bitstream.h"
#include "avformat.h" #include "avformat.h"
#include "avio_internal.h" #include "avio_internal.h"
#include "rtpdec_formats.h" #include "rtpdec_formats.h"
...@@ -118,18 +119,18 @@ static int h261_handle_packet(AVFormatContext *ctx, PayloadContext *rtp_h261_ctx ...@@ -118,18 +119,18 @@ static int h261_handle_packet(AVFormatContext *ctx, PayloadContext *rtp_h261_ctx
avio_w8(rtp_h261_ctx->buf, rtp_h261_ctx->endbyte); avio_w8(rtp_h261_ctx->buf, rtp_h261_ctx->endbyte);
} else { } else {
/* ebit/sbit values inconsistent, assuming packet loss */ /* ebit/sbit values inconsistent, assuming packet loss */
GetBitContext gb; BitstreamContext bc;
init_get_bits(&gb, buf, len*8 - ebit); bitstream_init(&bc, buf, len * 8 - ebit);
skip_bits(&gb, sbit); bitstream_skip(&bc, sbit);
if (rtp_h261_ctx->endbyte_bits) { if (rtp_h261_ctx->endbyte_bits) {
rtp_h261_ctx->endbyte |= get_bits(&gb, 8 - rtp_h261_ctx->endbyte_bits); rtp_h261_ctx->endbyte |= bitstream_read(&bc, 8 - rtp_h261_ctx->endbyte_bits);
avio_w8(rtp_h261_ctx->buf, rtp_h261_ctx->endbyte); avio_w8(rtp_h261_ctx->buf, rtp_h261_ctx->endbyte);
} }
while (get_bits_left(&gb) >= 8) while (bitstream_bits_left(&bc) >= 8)
avio_w8(rtp_h261_ctx->buf, get_bits(&gb, 8)); avio_w8(rtp_h261_ctx->buf, bitstream_read(&bc, 8));
rtp_h261_ctx->endbyte_bits = get_bits_left(&gb); rtp_h261_ctx->endbyte_bits = bitstream_bits_left(&bc);
if (rtp_h261_ctx->endbyte_bits) if (rtp_h261_ctx->endbyte_bits)
rtp_h261_ctx->endbyte = get_bits(&gb, rtp_h261_ctx->endbyte_bits) << rtp_h261_ctx->endbyte = bitstream_read(&bc, rtp_h261_ctx->endbyte_bits) <<
(8 - rtp_h261_ctx->endbyte_bits); (8 - rtp_h261_ctx->endbyte_bits);
ebit = 0; ebit = 0;
len = 0; len = 0;
......
...@@ -30,7 +30,8 @@ ...@@ -30,7 +30,8 @@
#include "rtpdec_formats.h" #include "rtpdec_formats.h"
#include "libavutil/attributes.h" #include "libavutil/attributes.h"
#include "libavutil/intreadwrite.h" #include "libavutil/intreadwrite.h"
#include "libavcodec/get_bits.h"
#include "libavcodec/bitstream.h"
struct PayloadContext { struct PayloadContext {
AVIOContext *buf; AVIOContext *buf;
...@@ -141,18 +142,18 @@ static int h263_handle_packet(AVFormatContext *ctx, PayloadContext *data, ...@@ -141,18 +142,18 @@ static int h263_handle_packet(AVFormatContext *ctx, PayloadContext *data,
avio_w8(data->buf, data->endbyte); avio_w8(data->buf, data->endbyte);
} else { } else {
/* Start/end skip bits not matching - missed packets? */ /* Start/end skip bits not matching - missed packets? */
GetBitContext gb; BitstreamContext bc;
init_get_bits(&gb, buf, len*8 - ebit); bitstream_init(&bc, buf, len * 8 - ebit);
skip_bits(&gb, sbit); bitstream_skip(&bc, sbit);
if (data->endbyte_bits) { if (data->endbyte_bits) {
data->endbyte |= get_bits(&gb, 8 - data->endbyte_bits); data->endbyte |= bitstream_read(&bc, 8 - data->endbyte_bits);
avio_w8(data->buf, data->endbyte); avio_w8(data->buf, data->endbyte);
} }
while (get_bits_left(&gb) >= 8) while (bitstream_bits_left(&bc) >= 8)
avio_w8(data->buf, get_bits(&gb, 8)); avio_w8(data->buf, bitstream_read(&bc, 8));
data->endbyte_bits = get_bits_left(&gb); data->endbyte_bits = bitstream_bits_left(&bc);
if (data->endbyte_bits) if (data->endbyte_bits)
data->endbyte = get_bits(&gb, data->endbyte_bits) << data->endbyte = bitstream_read(&bc, data->endbyte_bits) <<
(8 - data->endbyte_bits); (8 - data->endbyte_bits);
ebit = 0; ebit = 0;
len = 0; len = 0;
......
...@@ -19,11 +19,13 @@ ...@@ -19,11 +19,13 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/ */
#include "libavutil/avstring.h"
#include "libavcodec/bitstream.h"
#include "avio_internal.h" #include "avio_internal.h"
#include "rtpdec_formats.h" #include "rtpdec_formats.h"
#include "internal.h" #include "internal.h"
#include "libavutil/avstring.h"
#include "libavcodec/get_bits.h"
struct PayloadContext { struct PayloadContext {
AVIOContext *dyn_buf; AVIOContext *dyn_buf;
...@@ -92,7 +94,7 @@ static int latm_parse_packet(AVFormatContext *ctx, PayloadContext *data, ...@@ -92,7 +94,7 @@ static int latm_parse_packet(AVFormatContext *ctx, PayloadContext *data,
static int parse_fmtp_config(AVStream *st, const char *value) static int parse_fmtp_config(AVStream *st, const char *value)
{ {
int len = ff_hex_to_data(NULL, value), i, ret = 0; int len = ff_hex_to_data(NULL, value), i, ret = 0;
GetBitContext gb; BitstreamContext bc;
uint8_t *config; uint8_t *config;
int audio_mux_version, same_time_framing, num_programs, num_layers; int audio_mux_version, same_time_framing, num_programs, num_layers;
...@@ -101,12 +103,12 @@ static int parse_fmtp_config(AVStream *st, const char *value) ...@@ -101,12 +103,12 @@ static int parse_fmtp_config(AVStream *st, const char *value)
if (!config) if (!config)
return AVERROR(ENOMEM); return AVERROR(ENOMEM);
ff_hex_to_data(config, value); ff_hex_to_data(config, value);
init_get_bits(&gb, config, len*8); bitstream_init(&bc, config, len * 8);
audio_mux_version = get_bits(&gb, 1); audio_mux_version = bitstream_read(&bc, 1);
same_time_framing = get_bits(&gb, 1); same_time_framing = bitstream_read(&bc, 1);
skip_bits(&gb, 6); /* num_sub_frames */ bitstream_skip(&bc, 6); /* num_sub_frames */
num_programs = get_bits(&gb, 4); num_programs = bitstream_read(&bc, 4);
num_layers = get_bits(&gb, 3); num_layers = bitstream_read(&bc, 3);
if (audio_mux_version != 0 || same_time_framing != 1 || num_programs != 0 || if (audio_mux_version != 0 || same_time_framing != 1 || num_programs != 0 ||
num_layers != 0) { num_layers != 0) {
avpriv_report_missing_feature(NULL, "LATM config (%d,%d,%d,%d)", avpriv_report_missing_feature(NULL, "LATM config (%d,%d,%d,%d)",
...@@ -116,7 +118,7 @@ static int parse_fmtp_config(AVStream *st, const char *value) ...@@ -116,7 +118,7 @@ static int parse_fmtp_config(AVStream *st, const char *value)
goto end; goto end;
} }
av_freep(&st->codecpar->extradata); av_freep(&st->codecpar->extradata);
st->codecpar->extradata_size = (get_bits_left(&gb) + 7)/8; st->codecpar->extradata_size = (bitstream_bits_left(&bc) + 7) / 8;
st->codecpar->extradata = av_mallocz(st->codecpar->extradata_size + st->codecpar->extradata = av_mallocz(st->codecpar->extradata_size +
AV_INPUT_BUFFER_PADDING_SIZE); AV_INPUT_BUFFER_PADDING_SIZE);
if (!st->codecpar->extradata) { if (!st->codecpar->extradata) {
...@@ -124,7 +126,7 @@ static int parse_fmtp_config(AVStream *st, const char *value) ...@@ -124,7 +126,7 @@ static int parse_fmtp_config(AVStream *st, const char *value)
goto end; goto end;
} }
for (i = 0; i < st->codecpar->extradata_size; i++) for (i = 0; i < st->codecpar->extradata_size; i++)
st->codecpar->extradata[i] = get_bits(&gb, 8); st->codecpar->extradata[i] = bitstream_read(&bc, 8);
end: end:
av_free(config); av_free(config);
......
...@@ -27,11 +27,13 @@ ...@@ -27,11 +27,13 @@
* @author Romain Degez * @author Romain Degez
*/ */
#include "rtpdec_formats.h"
#include "internal.h"
#include "libavutil/attributes.h" #include "libavutil/attributes.h"
#include "libavutil/avstring.h" #include "libavutil/avstring.h"
#include "libavcodec/get_bits.h"
#include "libavcodec/bitstream.h"
#include "rtpdec_formats.h"
#include "internal.h"
#define MAX_AAC_HBR_FRAME_SIZE 8191 #define MAX_AAC_HBR_FRAME_SIZE 8191
...@@ -113,7 +115,7 @@ static int parse_fmtp_config(AVCodecParameters *par, const char *value) ...@@ -113,7 +115,7 @@ static int parse_fmtp_config(AVCodecParameters *par, const char *value)
static int rtp_parse_mp4_au(PayloadContext *data, const uint8_t *buf, int len) static int rtp_parse_mp4_au(PayloadContext *data, const uint8_t *buf, int len)
{ {
int au_headers_length, au_header_size, i; int au_headers_length, au_header_size, i;
GetBitContext getbitcontext; BitstreamContext bctx;
if (len < 2) if (len < 2)
return AVERROR_INVALIDDATA; return AVERROR_INVALIDDATA;
...@@ -134,7 +136,7 @@ static int rtp_parse_mp4_au(PayloadContext *data, const uint8_t *buf, int len) ...@@ -134,7 +136,7 @@ static int rtp_parse_mp4_au(PayloadContext *data, const uint8_t *buf, int len)
if (len < data->au_headers_length_bytes) if (len < data->au_headers_length_bytes)
return AVERROR_INVALIDDATA; return AVERROR_INVALIDDATA;
init_get_bits(&getbitcontext, buf, data->au_headers_length_bytes * 8); bitstream_init(&bctx, buf, data->au_headers_length_bytes * 8);
/* XXX: Wrong if optional additional sections are present (cts, dts etc...) */ /* XXX: Wrong if optional additional sections are present (cts, dts etc...) */
au_header_size = data->sizelength + data->indexlength; au_header_size = data->sizelength + data->indexlength;
...@@ -151,8 +153,8 @@ static int rtp_parse_mp4_au(PayloadContext *data, const uint8_t *buf, int len) ...@@ -151,8 +153,8 @@ static int rtp_parse_mp4_au(PayloadContext *data, const uint8_t *buf, int len)
} }
for (i = 0; i < data->nb_au_headers; ++i) { for (i = 0; i < data->nb_au_headers; ++i) {
data->au_headers[i].size = get_bits_long(&getbitcontext, data->sizelength); data->au_headers[i].size = bitstream_read(&bctx, data->sizelength);
data->au_headers[i].index = get_bits_long(&getbitcontext, data->indexlength); data->au_headers[i].index = bitstream_read(&bctx, data->indexlength);
} }
return 0; return 0;
......
...@@ -25,13 +25,14 @@ ...@@ -25,13 +25,14 @@
* @author Ronald S. Bultje <rbultje@ronald.bitfreak.net> * @author Ronald S. Bultje <rbultje@ronald.bitfreak.net>
*/ */
#include "libavcodec/bitstream.h"
#include "avformat.h" #include "avformat.h"
#include "internal.h" #include "internal.h"
#include "avio_internal.h" #include "avio_internal.h"
#include "rtp.h" #include "rtp.h"
#include "rtpdec.h" #include "rtpdec.h"
#include "isom.h" #include "isom.h"
#include "libavcodec/get_bits.h"
struct PayloadContext { struct PayloadContext {
AVPacket pkt; AVPacket pkt;
...@@ -45,7 +46,7 @@ static int qt_rtp_parse_packet(AVFormatContext *s, PayloadContext *qt, ...@@ -45,7 +46,7 @@ static int qt_rtp_parse_packet(AVFormatContext *s, PayloadContext *qt,
int len, uint16_t seq, int flags) int len, uint16_t seq, int flags)
{ {
AVIOContext pb; AVIOContext pb;
GetBitContext gb; BitstreamContext bc;
int packing_scheme, has_payload_desc, has_packet_info, alen, int packing_scheme, has_payload_desc, has_packet_info, alen,
has_marker_bit = flags & RTP_FLAG_MARKER, has_marker_bit = flags & RTP_FLAG_MARKER,
keyframe; keyframe;
...@@ -71,38 +72,38 @@ static int qt_rtp_parse_packet(AVFormatContext *s, PayloadContext *qt, ...@@ -71,38 +72,38 @@ static int qt_rtp_parse_packet(AVFormatContext *s, PayloadContext *qt,
* The RTP payload is described in: * The RTP payload is described in:
* http://developer.apple.com/quicktime/icefloe/dispatch026.html * http://developer.apple.com/quicktime/icefloe/dispatch026.html
*/ */
init_get_bits(&gb, buf, len << 3); bitstream_init(&bc, buf, len << 3);
ffio_init_context(&pb, buf, len, 0, NULL, NULL, NULL, NULL); ffio_init_context(&pb, buf, len, 0, NULL, NULL, NULL, NULL);
if (len < 4) if (len < 4)
return AVERROR_INVALIDDATA; return AVERROR_INVALIDDATA;
skip_bits(&gb, 4); // version bitstream_skip(&bc, 4); // version
if ((packing_scheme = get_bits(&gb, 2)) == 0) if ((packing_scheme = bitstream_read(&bc, 2)) == 0)
return AVERROR_INVALIDDATA; return AVERROR_INVALIDDATA;
keyframe = get_bits1(&gb); keyframe = bitstream_read_bit(&bc);
has_payload_desc = get_bits1(&gb); has_payload_desc = bitstream_read_bit(&bc);
has_packet_info = get_bits1(&gb); has_packet_info = bitstream_read_bit(&bc);
skip_bits(&gb, 23); // reserved:7, cache payload info:1, payload ID:15 bitstream_skip(&bc, 23); // reserved:7, cache payload info:1, payload ID:15
if (has_payload_desc) { if (has_payload_desc) {
int data_len, pos, is_start, is_finish; int data_len, pos, is_start, is_finish;
uint32_t tag; uint32_t tag;
pos = get_bits_count(&gb) >> 3; pos = bitstream_tell(&bc) >> 3;
if (pos + 12 > len) if (pos + 12 > len)
return AVERROR_INVALIDDATA; return AVERROR_INVALIDDATA;
skip_bits(&gb, 2); // has non-I-frames:1, is sparse:1 bitstream_skip(&bc, 2); // has non-I-frames:1, is sparse:1
is_start = get_bits1(&gb); is_start = bitstream_read_bit(&bc);
is_finish = get_bits1(&gb); is_finish = bitstream_read_bit(&bc);
if (!is_start || !is_finish) { if (!is_start || !is_finish) {
avpriv_request_sample(s, "RTP-X-QT with payload description " avpriv_request_sample(s, "RTP-X-QT with payload description "
"split over several packets"); "split over several packets");
return AVERROR_PATCHWELCOME; return AVERROR_PATCHWELCOME;
} }
skip_bits(&gb, 12); // reserved bitstream_skip(&bc, 12); // reserved
data_len = get_bits(&gb, 16); data_len = bitstream_read(&bc, 16);
avio_seek(&pb, pos + 4, SEEK_SET); avio_seek(&pb, pos + 4, SEEK_SET);
tag = avio_rl32(&pb); tag = avio_rl32(&pb);
......
...@@ -19,10 +19,11 @@ ...@@ -19,10 +19,11 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/ */
#include "libavcodec/bitstream.h"
#include "libavcodec/put_bits.h"
#include "avformat.h" #include "avformat.h"
#include "rtpenc.h" #include "rtpenc.h"
#include "libavcodec/put_bits.h"
#include "libavcodec/get_bits.h"
struct H263Info { struct H263Info {
int src; int src;
...@@ -103,7 +104,7 @@ void ff_rtp_send_h263_rfc2190(AVFormatContext *s1, const uint8_t *buf, int size, ...@@ -103,7 +104,7 @@ void ff_rtp_send_h263_rfc2190(AVFormatContext *s1, const uint8_t *buf, int size,
{ {
RTPMuxContext *s = s1->priv_data; RTPMuxContext *s = s1->priv_data;
int len, sbits = 0, ebits = 0; int len, sbits = 0, ebits = 0;
GetBitContext gb; BitstreamContext bc;
struct H263Info info = { 0 }; struct H263Info info = { 0 };
struct H263State state = { 0 }; struct H263State state = { 0 };
int mb_info_pos = 0, mb_info_count = mb_info_size / 12; int mb_info_pos = 0, mb_info_count = mb_info_size / 12;
...@@ -111,17 +112,17 @@ void ff_rtp_send_h263_rfc2190(AVFormatContext *s1, const uint8_t *buf, int size, ...@@ -111,17 +112,17 @@ void ff_rtp_send_h263_rfc2190(AVFormatContext *s1, const uint8_t *buf, int size,
s->timestamp = s->cur_timestamp; s->timestamp = s->cur_timestamp;
init_get_bits(&gb, buf, size*8); bitstream_init(&bc, buf, size * 8);
if (get_bits(&gb, 22) == 0x20) { /* Picture Start Code */ if (bitstream_read(&bc, 22) == 0x20) { /* Picture Start Code */
info.tr = get_bits(&gb, 8); info.tr = bitstream_read(&bc, 8);
skip_bits(&gb, 2); /* PTYPE start, H.261 disambiguation */ bitstream_skip(&bc, 2); /* PTYPE start, H.261 disambiguation */
skip_bits(&gb, 3); /* Split screen, document camera, freeze picture release */ bitstream_skip(&bc, 3); /* Split screen, document camera, freeze picture release */
info.src = get_bits(&gb, 3); info.src = bitstream_read(&bc, 3);
info.i = get_bits(&gb, 1); info.i = bitstream_read(&bc, 1);
info.u = get_bits(&gb, 1); info.u = bitstream_read(&bc, 1);
info.s = get_bits(&gb, 1); info.s = bitstream_read(&bc, 1);
info.a = get_bits(&gb, 1); info.a = bitstream_read(&bc, 1);
info.pb = get_bits(&gb, 1); info.pb = bitstream_read(&bc, 1);
} }
while (size > 0) { while (size > 0) {
......
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