summaryrefslogtreecommitdiff
path: root/libavformat/amr.c
diff options
context:
space:
mode:
authorMichael Niedermayer <michaelni@gmx.at>2006-10-10 23:45:12 +0000
committerMichael Niedermayer <michaelni@gmx.at>2006-10-10 23:45:12 +0000
commitb1bf48aa91ede6ff5c899bd9f808851de097d986 (patch)
tree4f1ced25df1781e0b31f048649d6bc264f274df0 /libavformat/amr.c
parenteffdc8ef2aba69423b02b3decd717b9272e43388 (diff)
factorize (untested)
Originally committed as revision 6633 to svn://svn.ffmpeg.org/ffmpeg/trunk
Diffstat (limited to 'libavformat/amr.c')
-rw-r--r--libavformat/amr.c85
1 files changed, 28 insertions, 57 deletions
diff --git a/libavformat/amr.c b/libavformat/amr.c
index 6faad121ba..5ccef995b5 100644
--- a/libavformat/amr.c
+++ b/libavformat/amr.c
@@ -134,78 +134,49 @@ static int amr_read_packet(AVFormatContext *s,
AVPacket *pkt)
{
AVCodecContext *enc = s->streams[0]->codec;
+ int read, size, toc, mode;
- if (enc->codec_id == CODEC_ID_AMR_NB)
+ if (url_feof(&s->pb))
{
- static const uint8_t packed_size[16] = {12, 13, 15, 17, 19, 20, 26, 31, 5, 0, 0, 0, 0, 0, 0, 0};
- uint8_t toc, q, ft;
- int read;
- int size;
-
- if (url_feof(&s->pb))
- {
- return AVERROR_IO;
- }
-
- toc=get_byte(&s->pb);
- q = (toc >> 2) & 0x01;
- ft = (toc >> 3) & 0x0F;
+ return AVERROR_IO;
+ }
- size=packed_size[ft];
+ toc=get_byte(&s->pb);
+ mode = (toc >> 3) & 0x0F;
- if (av_new_packet(pkt, size+1))
- {
- return AVERROR_IO;
- }
- pkt->stream_index = 0;
- pkt->pos= url_ftell(&s->pb);
- pkt->data[0]=toc;
-
- read = get_buffer(&s->pb, pkt->data+1, size);
+ if (enc->codec_id == CODEC_ID_AMR_NB)
+ {
+ static const uint8_t packed_size[16] = {12, 13, 15, 17, 19, 20, 26, 31, 5, 0, 0, 0, 0, 0, 0, 0};
- if (read != size)
- {
- av_free_packet(pkt);
- return AVERROR_IO;
- }
+ size=packed_size[mode]+1;
}
else if(enc->codec_id == CODEC_ID_AMR_WB)
{
static uint8_t packed_size[16] = {18, 24, 33, 37, 41, 47, 51, 59, 61, 6, 6, 0, 0, 0, 1, 1};
- uint8_t toc, mode;
- int read;
- int size;
-
- if (url_feof(&s->pb))
- {
- return AVERROR_IO;
- }
-
- toc=get_byte(&s->pb);
- mode = (uint8_t)((toc >> 3) & 0x0F);
- size = packed_size[mode];
-
- if ( (size==0) || av_new_packet(pkt, size))
- {
- return AVERROR_IO;
- }
- pkt->stream_index = 0;
- pkt->pos= url_ftell(&s->pb);
- pkt->data[0]=toc;
-
- read = get_buffer(&s->pb, pkt->data+1, size-1);
-
- if (read != (size-1))
- {
- av_free_packet(pkt);
- return AVERROR_IO;
- }
+ size=packed_size[mode];
}
else
{
assert(0);
}
+
+ if ( (size==0) || av_new_packet(pkt, size))
+ {
+ return AVERROR_IO;
+ }
+
+ pkt->stream_index = 0;
+ pkt->pos= url_ftell(&s->pb);
+ pkt->data[0]=toc;
+ read = get_buffer(&s->pb, pkt->data+1, size-1);
+
+ if (read != size-1)
+ {
+ av_free_packet(pkt);
+ return AVERROR_IO;
+ }
+
return 0;
}