summaryrefslogtreecommitdiff
path: root/libavformat/redspark.c
diff options
context:
space:
mode:
authorJames Almer <jamrial@gmail.com>2016-06-12 16:30:32 -0300
committerJames Almer <jamrial@gmail.com>2016-06-12 17:26:40 -0300
commit8fdad638f92223c6c6f6e36fabaf42e8324fcbae (patch)
tree2edca4076b1386a4d02080c73c1d2b0d1fd8f3b6 /libavformat/redspark.c
parentaafdad1b454c1656e6ba08822de49fb7caf924f3 (diff)
avformat/redspark: remove av_malloc usage
Signed-off-by: James Almer <jamrial@gmail.com>
Diffstat (limited to 'libavformat/redspark.c')
-rw-r--r--libavformat/redspark.c29
1 files changed, 8 insertions, 21 deletions
diff --git a/libavformat/redspark.c b/libavformat/redspark.c
index 8535bef11a..764b23ec04 100644
--- a/libavformat/redspark.c
+++ b/libavformat/redspark.c
@@ -59,7 +59,7 @@ static int redspark_read_header(AVFormatContext *s)
GetByteContext gbc;
int i, coef_off, ret = 0;
uint32_t key, data;
- uint8_t *header, *pbc;
+ uint8_t header[HEADER_SIZE];
AVStream *st;
st = avformat_new_stream(s, NULL);
@@ -67,20 +67,15 @@ static int redspark_read_header(AVFormatContext *s)
return AVERROR(ENOMEM);
par = st->codecpar;
- header = av_malloc(HEADER_SIZE + AV_INPUT_BUFFER_PADDING_SIZE);
- if (!header)
- return AVERROR(ENOMEM);
- pbc = header;
-
/* Decrypt header */
data = avio_rb32(pb);
data = data ^ (key = data ^ 0x52656453);
- bytestream_put_be32(&pbc, data);
+ AV_WB32(header, data);
key = (key << 11) | (key >> 21);
for (i = 4; i < HEADER_SIZE; i += 4) {
data = avio_rb32(pb) ^ (key = ((key << 3) | (key >> 29)) + key);
- bytestream_put_be32(&pbc, data);
+ AV_WB32(header + i, data);
}
par->codec_id = AV_CODEC_ID_ADPCM_THP;
@@ -91,8 +86,7 @@ static int redspark_read_header(AVFormatContext *s)
par->sample_rate = bytestream2_get_be32u(&gbc);
if (par->sample_rate <= 0 || par->sample_rate > 96000) {
av_log(s, AV_LOG_ERROR, "Invalid sample rate: %d\n", par->sample_rate);
- ret = AVERROR_INVALIDDATA;
- goto fail;
+ return AVERROR_INVALIDDATA;
}
st->duration = bytestream2_get_be32u(&gbc) * 14;
@@ -100,8 +94,7 @@ static int redspark_read_header(AVFormatContext *s)
bytestream2_skipu(&gbc, 10);
par->channels = bytestream2_get_byteu(&gbc);
if (!par->channels) {
- ret = AVERROR_INVALIDDATA;
- goto fail;
+ return AVERROR_INVALIDDATA;
}
coef_off = 0x54 + par->channels * 8;
@@ -109,30 +102,24 @@ static int redspark_read_header(AVFormatContext *s)
coef_off += 16;
if (coef_off + par->channels * (32 + 14) > HEADER_SIZE) {
- ret = AVERROR_INVALIDDATA;
- goto fail;
+ return AVERROR_INVALIDDATA;
}
if (ff_alloc_extradata(par, 32 * par->channels)) {
- ret = AVERROR(ENOMEM);
- goto fail;
+ return AVERROR_INVALIDDATA;
}
/* Get the ADPCM table */
bytestream2_seek(&gbc, coef_off, SEEK_SET);
for (i = 0; i < par->channels; i++) {
if (bytestream2_get_bufferu(&gbc, par->extradata + i * 32, 32) != 32) {
- ret = AVERROR_INVALIDDATA;
- goto fail;
+ return AVERROR_INVALIDDATA;
}
bytestream2_skipu(&gbc, 14);
}
avpriv_set_pts_info(st, 64, 1, par->sample_rate);
-fail:
- av_free(header);
-
return ret;
}