Compare commits
137 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 58e212c1fb | |||
| 4ddbe89d40 | |||
| d83dff2e09 | |||
| 5e708b4de3 | |||
| 8528feb13c | |||
| 2e57d4ba24 | |||
| 7c72398787 | |||
| 048e284201 | |||
| e31518e86e | |||
| 1c896e865c | |||
| 39d76907c9 | |||
| 1825d6d096 | |||
| a5115752ca | |||
| cb297f6ae7 | |||
| 3667874833 | |||
| ae9652605a | |||
| d2f4846591 | |||
| 62c8bf00bb | |||
| a1b82c6b1c | |||
| 2ed8a550da | |||
| 86d0bf0e96 | |||
| ef67d8107e | |||
| be8b796f55 | |||
| 8119336df4 | |||
| 8297853917 | |||
| b8ba48c725 | |||
| 1682c9fb59 | |||
| 5971631d84 | |||
| c08127c5e6 | |||
| 558c1f35fa | |||
| 8096691a68 | |||
| abb41f19cc | |||
| 36fc320747 | |||
| 4a11d773f9 | |||
| c1ebdef01b | |||
| cda26ab21e | |||
| d2eddcfc83 | |||
| 3cc05e0d9d | |||
| b98a824c3e | |||
| e930b112d1 | |||
| 067713f159 | |||
| 5312fb8287 | |||
| a9ebc17b2d | |||
| 2da49df19e | |||
| c25bbb6fdb | |||
| 12dc01bb1f | |||
| cd9b0bb07a | |||
| 53c76b6803 | |||
| 7999ff8966 | |||
| a0b8f85f29 | |||
| c02b9e6e63 | |||
| efe710f8a0 | |||
| aedde1a48d | |||
| c5da487a38 | |||
| f21dce6044 | |||
| 89d56f3be1 | |||
| 0d1ae06fe9 | |||
| f66ecdb1b4 | |||
| f6057c5a62 | |||
| f3dc3bef4b | |||
| 4a5bb426e2 | |||
| a99aff4e4b | |||
| 9300b1f64e | |||
| 5230f1529a | |||
| 1a311ad99a | |||
| ef8145270f | |||
| e288124394 | |||
| 20854f9bff | |||
| d8af960e7e | |||
| c8ca385676 | |||
| c6a4397410 | |||
| 210a437e10 | |||
| 3308b443f9 | |||
| 91ad27e8f5 | |||
| 9978c24abf | |||
| b0ca5fef09 | |||
| 5473d23ece | |||
| 7a9af1da39 | |||
| 068c867286 | |||
| 23f73fc241 | |||
| 8d2a86a290 | |||
| 5773065a71 | |||
| c225c620c6 | |||
| 37e69e2dee | |||
| 3dff283de1 | |||
| 86c169c5b6 | |||
| 91355bec88 | |||
| 54e0386369 | |||
| 896baaaad8 | |||
| 15620c153a | |||
| 75b1b13aff | |||
| 9c779b5dd0 | |||
| 8006716f21 | |||
| 246e0e2c99 | |||
| 0d24adbe8d | |||
| a593d2e92e | |||
| 729143e2d2 | |||
| 36921fcdd3 | |||
| e2dcb8208e | |||
| 609345cd5e | |||
| 06c52faef2 | |||
| ba5dfc25ee | |||
| 9e552b6512 | |||
| 506ad68d87 | |||
| ef475620b5 | |||
| a88ed5a481 | |||
| f33d5af1f3 | |||
| 93c524c0f0 | |||
| 68b1008719 | |||
| 763519536b | |||
| 521cbcb7d3 | |||
| ce3ce08850 | |||
| 62c3547539 | |||
| 47baf9ca87 | |||
| 9c3c08ba98 | |||
| 9c05debdcd | |||
| 195b9f290c | |||
| 57efb6d94c | |||
| b64bd2e18b | |||
| cb198f945f | |||
| e27bc85b31 | |||
| 3f4fb49d1b | |||
| d06dda65b4 | |||
| b9dea1a085 | |||
| 90acd3bfe7 | |||
| 40ee4de6a6 | |||
| e06623c480 | |||
| 09a098fb8b | |||
| 7296ee7af1 | |||
| 26589aa810 | |||
| c6942a4b03 | |||
| fe8b5a37d5 | |||
| 42ad4178fd | |||
| 139f352daf | |||
| c69b4bdf58 | |||
| f4392277b0 | |||
| 49f434ce2e |
@@ -4,6 +4,97 @@ releases are sorted from youngest to oldest.
|
||||
version next:
|
||||
|
||||
|
||||
version 0.10.10
|
||||
|
||||
- x86: fft: Remove 3DNow! optimizations, they break FATE
|
||||
- x86: ac3dsp: Drop mmx variant of ac3_max_msb_abs_int16
|
||||
- aac: Check init_get_bits return value
|
||||
- aac: return meaningful errors
|
||||
- dsicinav: K&R formatting cosmetics
|
||||
- mov: Seek back if overreading an individual atom
|
||||
- vcr1: add sanity checks
|
||||
- pictordec: pass correct context to avpriv_request_sample
|
||||
- dsicinav: Clip the source size to the expected maximum
|
||||
- alsdec: Clean up error paths
|
||||
- ogg: Fix potential infinite discard loop
|
||||
- nuv: check rtjpeg_decode_frame_yuv420 return value
|
||||
- nuv: Reset the frame on resize
|
||||
- nuv: Use av_fast_realloc
|
||||
- nuv: return meaningful error codes.
|
||||
- nuv: Pad the lzo outbuf
|
||||
- nuv: Do not ignore lzo decompression failures
|
||||
- oma: correctly mark and decrypt partial packets
|
||||
- oma: check geob tag boundary
|
||||
- oma: refactor seek function
|
||||
- 8bps: Bound-check the input buffer
|
||||
- rtmp: Do not misuse memcmp
|
||||
- rtmp: rename data_size to size
|
||||
- lavc: set the default rc_initial_buffer_occupancy
|
||||
- 4xm: Reject not a multiple of 16 dimension
|
||||
- 4xm: do not overread the prestream buffer
|
||||
- 4xm: validate the buffer size before parsing it
|
||||
- indeo: Do not reference mismatched tiles
|
||||
- indeo: Sanitize ff_ivi_init_planes fail paths
|
||||
- indeo: Bound-check before applying motion compensation
|
||||
- indeo: Bound-check before applying transform
|
||||
- indeo: reject negative array indexes
|
||||
- indeo: Cosmetic formatting
|
||||
- indeo: Refactor ff_ivi_init_tiles and ivi_decode_blocks
|
||||
- indeo: Refactor ff_ivi_dec_huff_desc
|
||||
- lavf: fix the comparison in an overflow check
|
||||
- dv: Add a guard to not overread the ppcm array
|
||||
- mpegvideo: Avoid 32-bit wrapping of linesize multiplications
|
||||
- mjpegb: Detect changing number of planes in interlaced video
|
||||
- matroskadec: Check that .lang was allocated and set before reading it
|
||||
- ape demuxer: check for EOF in potentially long loops
|
||||
- lavf: avoid integer overflow when estimating bitrate
|
||||
- pictordec: break out of both decoding loops when y drops below 0
|
||||
- ac3: Return proper error codes
|
||||
- ac3: Clean up the error paths
|
||||
- ac3: Do not clash with normal AVERROR
|
||||
- dxa: Make sure the reference frame exists
|
||||
- h261: check the mtype index
|
||||
- segafilm: Error out on impossible packet size
|
||||
- ogg: Always alloc the private context in vorbis_header
|
||||
- vc1: check mb_height validity.
|
||||
- vc1: check the source buffer in vc1_mc functions
|
||||
- bink: Bound check the quantization matrix.
|
||||
- xl: Make sure the width is valid
|
||||
- alsdec: Fix the clipping range
|
||||
- dsicinav: Bound-check the source buffer when needed
|
||||
- mov: Do not allow updating the time scale after it has been set
|
||||
- ac3dec: Don't consume more data than the actual input packet size
|
||||
- indeo: Reject impossible FRAMETYPE_NULL
|
||||
- indeo5: return proper error codes
|
||||
- indeo4: Validate scantable dimension
|
||||
- indeo4: Check the quantization matrix index
|
||||
- indeo4: Do not access missing reference MV
|
||||
- adpcm: Unbreak ima-dk4
|
||||
- ac3dec: validate channel output mode against channel count
|
||||
- dca: Respect the current limits in the downmixing capabilities
|
||||
- dca: Error out on missing DSYNC
|
||||
- pcm: always use codec->id instead of codec_id
|
||||
- mlpdec: Do not set invalid context in read_restart_header
|
||||
- pcx: Do not overread source buffer in pcx_rle_decode
|
||||
- wmavoice: conceal clearly corrupted blocks
|
||||
- iff: Do not read over the source buffer
|
||||
- qdm2: Conceal broken samples
|
||||
- qdm2: refactor joined stereo support
|
||||
- adpcm: Write the correct number of samples for ima-dk4
|
||||
- imc: Catch a division by zero
|
||||
- atrac3: Error on impossible encoding/channel combinations
|
||||
- atrac3: set the getbits context the right buffer_end
|
||||
- atrac3: fix error handling
|
||||
- qdm2: check and reset dithering index per channel
|
||||
- westwood_vqa: do not free extradata on error in read_header
|
||||
- vqavideo: check the version
|
||||
- rmdec: Use the AVIOContext given as parameter in rm_read_metadata()
|
||||
- avio: Handle AVERROR_EOF in the same way as the return value 0
|
||||
- wtv: Mark attachment with a negative stream id
|
||||
- avidec: Let the inner dv demuxer take care of discarding
|
||||
- swfdec: do better validation of tag length
|
||||
|
||||
|
||||
version 0.10.8
|
||||
- kmvc: Clip pixel position to valid range
|
||||
- kmvc: use fixed sized arrays in the context
|
||||
|
||||
@@ -31,7 +31,7 @@ PROJECT_NAME = FFmpeg
|
||||
# This could be handy for archiving the generated documentation or
|
||||
# if some version control system is used.
|
||||
|
||||
PROJECT_NUMBER = 0.10.8
|
||||
PROJECT_NUMBER = 0.10.10
|
||||
|
||||
# With the PROJECT_LOGO tag one can specify an logo or icon that is included
|
||||
# in the documentation. The maximum height of the logo should not exceed 55
|
||||
|
||||
@@ -4057,8 +4057,6 @@ static OutputStream *new_video_stream(OptionsContext *o, AVFormatContext *oc)
|
||||
if (p) p++;
|
||||
}
|
||||
video_enc->rc_override_count = i;
|
||||
if (!video_enc->rc_initial_buffer_occupancy)
|
||||
video_enc->rc_initial_buffer_occupancy = video_enc->rc_buffer_size * 3 / 4;
|
||||
video_enc->intra_dc_precision = intra_dc_precision - 8;
|
||||
|
||||
if (do_psnr)
|
||||
|
||||
+27
-9
@@ -403,6 +403,8 @@ static int decode_p_frame(FourXContext *f, const uint8_t *buf, int length){
|
||||
unsigned int bitstream_size, bytestream_size, wordstream_size, extra, bytestream_offset, wordstream_offset;
|
||||
|
||||
if(f->version>1){
|
||||
if (length < 20)
|
||||
return AVERROR_INVALIDDATA;
|
||||
extra=20;
|
||||
if (length < extra)
|
||||
return -1;
|
||||
@@ -560,7 +562,10 @@ static int decode_i_mb(FourXContext *f){
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const uint8_t *read_huffman_tables(FourXContext *f, const uint8_t * const buf, int buf_size){
|
||||
static const uint8_t *read_huffman_tables(FourXContext *f,
|
||||
const uint8_t * const buf,
|
||||
int buf_size)
|
||||
{
|
||||
int frequency[512];
|
||||
uint8_t flag[512];
|
||||
int up[512];
|
||||
@@ -581,6 +586,9 @@ static const uint8_t *read_huffman_tables(FourXContext *f, const uint8_t * const
|
||||
|
||||
if (start <= end && ptr_end - ptr < end - start + 1 + 1)
|
||||
return NULL;
|
||||
if (end < start || buf_size < 0)
|
||||
return NULL;
|
||||
|
||||
for(i=start; i<=end; i++){
|
||||
frequency[i]= *ptr++;
|
||||
}
|
||||
@@ -767,25 +775,35 @@ static int decode_frame(AVCodecContext *avctx,
|
||||
AVFrame *p, temp;
|
||||
int i, frame_4cc, frame_size;
|
||||
|
||||
if (buf_size < 12)
|
||||
if (buf_size < 20)
|
||||
return AVERROR_INVALIDDATA;
|
||||
|
||||
if (avctx->width % 16 || avctx->height % 16) {
|
||||
av_log(avctx, AV_LOG_ERROR,
|
||||
"Dimensions non-multiple of 16 are invalid.\n");
|
||||
return AVERROR_INVALIDDATA;
|
||||
frame_4cc= AV_RL32(buf);
|
||||
if(buf_size != AV_RL32(buf+4)+8 || buf_size < 20){
|
||||
av_log(f->avctx, AV_LOG_ERROR, "size mismatch %d %d\n", buf_size, AV_RL32(buf+4));
|
||||
}
|
||||
|
||||
if (buf_size < AV_RL32(buf + 4) + 8) {
|
||||
av_log(f->avctx, AV_LOG_ERROR,
|
||||
"size mismatch %d %d\n", buf_size, AV_RL32(buf + 4));
|
||||
}
|
||||
|
||||
frame_4cc = AV_RL32(buf);
|
||||
|
||||
if(frame_4cc == AV_RL32("cfrm")){
|
||||
int free_index=-1;
|
||||
const int data_size= buf_size - 20;
|
||||
const int id= AV_RL32(buf+12);
|
||||
const int whole_size= AV_RL32(buf+16);
|
||||
int id, whole_size;
|
||||
const int data_size = buf_size - 20;
|
||||
CFrameBuffer *cfrm;
|
||||
|
||||
id = AV_RL32(buf + 12);
|
||||
whole_size = AV_RL32(buf + 16);
|
||||
|
||||
if (data_size < 0 || whole_size < 0){
|
||||
av_log(f->avctx, AV_LOG_ERROR, "sizes invalid\n");
|
||||
return AVERROR_INVALIDDATA;
|
||||
}
|
||||
|
||||
for(i=0; i<CFRAME_BUFFER_COUNT; i++){
|
||||
if(f->cfrm[i].id && f->cfrm[i].id < avctx->frame_number)
|
||||
av_log(f->avctx, AV_LOG_ERROR, "lost c frame %d\n", f->cfrm[i].id);
|
||||
|
||||
+7
-3
@@ -69,7 +69,7 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, AVPac
|
||||
unsigned char *pixptr, *pixptr_end;
|
||||
unsigned int height = avctx->height; // Real image height
|
||||
unsigned int dlen, p, row;
|
||||
const unsigned char *lp, *dp;
|
||||
const unsigned char *lp, *dp, *ep;
|
||||
unsigned char count;
|
||||
unsigned int planes = c->planes;
|
||||
unsigned char *planemap = c->planemap;
|
||||
@@ -84,6 +84,8 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, AVPac
|
||||
return -1;
|
||||
}
|
||||
|
||||
ep = encoded + buf_size;
|
||||
|
||||
/* Set data pointer after line lengths */
|
||||
dp = encoded + planes * (height << 1);
|
||||
|
||||
@@ -95,16 +97,18 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, AVPac
|
||||
for(row = 0; row < height; row++) {
|
||||
pixptr = c->pic.data[0] + row * c->pic.linesize[0] + planemap[p];
|
||||
pixptr_end = pixptr + c->pic.linesize[0];
|
||||
if (ep - lp < row * 2 + 2)
|
||||
return AVERROR_INVALIDDATA;
|
||||
dlen = av_be2ne16(*(const unsigned short *)(lp+row*2));
|
||||
/* Decode a row of this plane */
|
||||
while(dlen > 0) {
|
||||
if(dp + 1 >= buf+buf_size) return -1;
|
||||
if(ep - dp <= 1) return -1;
|
||||
if ((count = *dp++) <= 127) {
|
||||
count++;
|
||||
dlen -= count + 1;
|
||||
if (pixptr + count * planes > pixptr_end)
|
||||
break;
|
||||
if(dp + count > buf+buf_size) return -1;
|
||||
if(ep - dp < count) return -1;
|
||||
while(count--) {
|
||||
*pixptr = *dp++;
|
||||
pixptr += planes;
|
||||
|
||||
@@ -28,13 +28,13 @@
|
||||
#include "parser.h"
|
||||
|
||||
typedef enum {
|
||||
AAC_AC3_PARSE_ERROR_SYNC = -1,
|
||||
AAC_AC3_PARSE_ERROR_BSID = -2,
|
||||
AAC_AC3_PARSE_ERROR_SAMPLE_RATE = -3,
|
||||
AAC_AC3_PARSE_ERROR_FRAME_SIZE = -4,
|
||||
AAC_AC3_PARSE_ERROR_FRAME_TYPE = -5,
|
||||
AAC_AC3_PARSE_ERROR_CRC = -6,
|
||||
AAC_AC3_PARSE_ERROR_CHANNEL_CFG = -7,
|
||||
AAC_AC3_PARSE_ERROR_SYNC = -0x1030c0a,
|
||||
AAC_AC3_PARSE_ERROR_BSID = -0x2030c0a,
|
||||
AAC_AC3_PARSE_ERROR_SAMPLE_RATE = -0x3030c0a,
|
||||
AAC_AC3_PARSE_ERROR_FRAME_SIZE = -0x4030c0a,
|
||||
AAC_AC3_PARSE_ERROR_FRAME_TYPE = -0x5030c0a,
|
||||
AAC_AC3_PARSE_ERROR_CRC = -0x6030c0a,
|
||||
AAC_AC3_PARSE_ERROR_CHANNEL_CFG = -0x7030c0a,
|
||||
} AACAC3ParseError;
|
||||
|
||||
typedef struct AACAC3ParseContext {
|
||||
|
||||
+39
-31
@@ -362,7 +362,7 @@ static int decode_pce(AVCodecContext *avctx, MPEG4AudioConfig *m4ac,
|
||||
comment_len = get_bits(gb, 8) * 8;
|
||||
if (get_bits_left(gb) < comment_len) {
|
||||
av_log(avctx, AV_LOG_ERROR, overread_err);
|
||||
return -1;
|
||||
return AVERROR_INVALIDDATA;
|
||||
}
|
||||
skip_bits_long(gb, comment_len);
|
||||
return 0;
|
||||
@@ -383,7 +383,7 @@ static av_cold int set_default_channel_config(AVCodecContext *avctx,
|
||||
if (channel_config < 1 || channel_config > 7) {
|
||||
av_log(avctx, AV_LOG_ERROR, "invalid default channel configuration (%d)\n",
|
||||
channel_config);
|
||||
return -1;
|
||||
return AVERROR_INVALIDDATA;
|
||||
}
|
||||
|
||||
/* default channel configurations:
|
||||
@@ -501,20 +501,21 @@ static int decode_audio_specific_config(AACContext *ac,
|
||||
int sync_extension)
|
||||
{
|
||||
GetBitContext gb;
|
||||
int i;
|
||||
int i, ret;
|
||||
|
||||
av_dlog(avctx, "extradata size %d\n", avctx->extradata_size);
|
||||
for (i = 0; i < avctx->extradata_size; i++)
|
||||
av_dlog(avctx, "%02x ", avctx->extradata[i]);
|
||||
av_dlog(avctx, "\n");
|
||||
|
||||
init_get_bits(&gb, data, bit_size);
|
||||
if ((ret = init_get_bits(&gb, data, bit_size)) < 0)
|
||||
return ret;
|
||||
|
||||
if ((i = avpriv_mpeg4audio_get_config(m4ac, data, bit_size, sync_extension)) < 0)
|
||||
return -1;
|
||||
return AVERROR_INVALIDDATA;
|
||||
if (m4ac->sampling_index > 12) {
|
||||
av_log(avctx, AV_LOG_ERROR, "invalid sampling rate index %d\n", m4ac->sampling_index);
|
||||
return -1;
|
||||
return AVERROR_INVALIDDATA;
|
||||
}
|
||||
|
||||
skip_bits_long(&gb, i);
|
||||
@@ -523,13 +524,14 @@ static int decode_audio_specific_config(AACContext *ac,
|
||||
case AOT_AAC_MAIN:
|
||||
case AOT_AAC_LC:
|
||||
case AOT_AAC_LTP:
|
||||
if (decode_ga_specific_config(ac, avctx, &gb, m4ac, m4ac->chan_config))
|
||||
return -1;
|
||||
if ((ret = decode_ga_specific_config(ac, avctx, &gb,
|
||||
m4ac, m4ac->chan_config)) < 0)
|
||||
return ret;
|
||||
break;
|
||||
default:
|
||||
av_log(avctx, AV_LOG_ERROR, "Audio object type %s%d is not supported.\n",
|
||||
m4ac->sbr == 1? "SBR+" : "", m4ac->object_type);
|
||||
return -1;
|
||||
return AVERROR(ENOSYS);
|
||||
}
|
||||
|
||||
av_dlog(avctx, "AOT %d chan config %d sampling index %d (%d) SBR %d PS %d\n",
|
||||
@@ -600,16 +602,17 @@ static void reset_predictor_group(PredictorState *ps, int group_num)
|
||||
static av_cold int aac_decode_init(AVCodecContext *avctx)
|
||||
{
|
||||
AACContext *ac = avctx->priv_data;
|
||||
int ret;
|
||||
float output_scale_factor;
|
||||
|
||||
ac->avctx = avctx;
|
||||
ac->m4ac.sample_rate = avctx->sample_rate;
|
||||
|
||||
if (avctx->extradata_size > 0) {
|
||||
if (decode_audio_specific_config(ac, ac->avctx, &ac->m4ac,
|
||||
if ((ret = decode_audio_specific_config(ac, ac->avctx, &ac->m4ac,
|
||||
avctx->extradata,
|
||||
avctx->extradata_size*8, 1) < 0)
|
||||
return -1;
|
||||
avctx->extradata_size*8, 1)) < 0)
|
||||
return ret;
|
||||
} else {
|
||||
int sr, i;
|
||||
enum ChannelPosition new_che_pos[4][MAX_ELEM_ID];
|
||||
@@ -702,7 +705,7 @@ static int skip_data_stream_element(AACContext *ac, GetBitContext *gb)
|
||||
|
||||
if (get_bits_left(gb) < 8 * count) {
|
||||
av_log(ac->avctx, AV_LOG_ERROR, overread_err);
|
||||
return -1;
|
||||
return AVERROR_INVALIDDATA;
|
||||
}
|
||||
skip_bits_long(gb, 8 * count);
|
||||
return 0;
|
||||
@@ -716,7 +719,7 @@ static int decode_prediction(AACContext *ac, IndividualChannelStream *ics,
|
||||
ics->predictor_reset_group = get_bits(gb, 5);
|
||||
if (ics->predictor_reset_group == 0 || ics->predictor_reset_group > 30) {
|
||||
av_log(ac->avctx, AV_LOG_ERROR, "Invalid Predictor Reset Group.\n");
|
||||
return -1;
|
||||
return AVERROR_INVALIDDATA;
|
||||
}
|
||||
}
|
||||
for (sfb = 0; sfb < FFMIN(ics->max_sfb, ff_aac_pred_sfb_max[ac->m4ac.sampling_index]); sfb++) {
|
||||
@@ -826,20 +829,20 @@ static int decode_band_types(AACContext *ac, enum BandType band_type[120],
|
||||
int sect_band_type = get_bits(gb, 4);
|
||||
if (sect_band_type == 12) {
|
||||
av_log(ac->avctx, AV_LOG_ERROR, "invalid band type\n");
|
||||
return -1;
|
||||
return AVERROR_INVALIDDATA;
|
||||
}
|
||||
do {
|
||||
sect_len_incr = get_bits(gb, bits);
|
||||
sect_end += sect_len_incr;
|
||||
if (get_bits_left(gb) < 0) {
|
||||
av_log(ac->avctx, AV_LOG_ERROR, overread_err);
|
||||
return -1;
|
||||
return AVERROR_INVALIDDATA;
|
||||
}
|
||||
if (sect_end > ics->max_sfb) {
|
||||
av_log(ac->avctx, AV_LOG_ERROR,
|
||||
"Number of bands (%d) exceeds limit (%d).\n",
|
||||
sect_end, ics->max_sfb);
|
||||
return -1;
|
||||
return AVERROR_INVALIDDATA;
|
||||
}
|
||||
} while (sect_len_incr == (1 << bits) - 1);
|
||||
for (; k < sect_end; k++) {
|
||||
@@ -911,7 +914,7 @@ static int decode_scalefactors(AACContext *ac, float sf[120], GetBitContext *gb,
|
||||
if (offset[0] > 255U) {
|
||||
av_log(ac->avctx, AV_LOG_ERROR,
|
||||
"%s (%d) out of range.\n", sf_str[0], offset[0]);
|
||||
return -1;
|
||||
return AVERROR_INVALIDDATA;
|
||||
}
|
||||
sf[idx] = -ff_aac_pow2sf_tab[offset[0] - 100 + POW_SF2_ZERO];
|
||||
}
|
||||
@@ -969,7 +972,7 @@ static int decode_tns(AACContext *ac, TemporalNoiseShaping *tns,
|
||||
av_log(ac->avctx, AV_LOG_ERROR, "TNS filter order %d is greater than maximum %d.\n",
|
||||
tns->order[w][filt], tns_max_order);
|
||||
tns->order[w][filt] = 0;
|
||||
return -1;
|
||||
return AVERROR_INVALIDDATA;
|
||||
}
|
||||
if (tns->order[w][filt]) {
|
||||
tns->direction[w][filt] = get_bits1(gb);
|
||||
@@ -1252,7 +1255,7 @@ static int decode_spectrum_and_dequant(AACContext *ac, float coef[1024],
|
||||
|
||||
if (b > 8) {
|
||||
av_log(ac->avctx, AV_LOG_ERROR, "error in spectral data, ESC overflow\n");
|
||||
return -1;
|
||||
return AVERROR_INVALIDDATA;
|
||||
}
|
||||
|
||||
SKIP_BITS(re, gb, b + 1);
|
||||
@@ -1395,6 +1398,7 @@ static int decode_ics(AACContext *ac, SingleChannelElement *sce,
|
||||
IndividualChannelStream *ics = &sce->ics;
|
||||
float *out = sce->coeffs;
|
||||
int global_gain, pulse_present = 0;
|
||||
int ret;
|
||||
|
||||
/* This assignment is to silence a GCC warning about the variable being used
|
||||
* uninitialized when in fact it always is.
|
||||
@@ -1408,25 +1412,27 @@ static int decode_ics(AACContext *ac, SingleChannelElement *sce,
|
||||
return AVERROR_INVALIDDATA;
|
||||
}
|
||||
|
||||
if (decode_band_types(ac, sce->band_type, sce->band_type_run_end, gb, ics) < 0)
|
||||
return -1;
|
||||
if (decode_scalefactors(ac, sce->sf, gb, global_gain, ics, sce->band_type, sce->band_type_run_end) < 0)
|
||||
return -1;
|
||||
if ((ret = decode_band_types(ac, sce->band_type,
|
||||
sce->band_type_run_end, gb, ics)) < 0)
|
||||
return ret;
|
||||
if ((ret = decode_scalefactors(ac, sce->sf, gb, global_gain, ics,
|
||||
sce->band_type, sce->band_type_run_end)) < 0)
|
||||
return ret;
|
||||
|
||||
pulse_present = 0;
|
||||
if (!scale_flag) {
|
||||
if ((pulse_present = get_bits1(gb))) {
|
||||
if (ics->window_sequence[0] == EIGHT_SHORT_SEQUENCE) {
|
||||
av_log(ac->avctx, AV_LOG_ERROR, "Pulse tool not allowed in eight short sequence.\n");
|
||||
return -1;
|
||||
return AVERROR_INVALIDDATA;
|
||||
}
|
||||
if (decode_pulses(&pulse, gb, ics->swb_offset, ics->num_swb)) {
|
||||
av_log(ac->avctx, AV_LOG_ERROR, "Pulse data corrupt or invalid.\n");
|
||||
return -1;
|
||||
return AVERROR_INVALIDDATA;
|
||||
}
|
||||
}
|
||||
if ((tns->present = get_bits1(gb)) && decode_tns(ac, tns, gb, ics))
|
||||
return -1;
|
||||
return AVERROR_INVALIDDATA;
|
||||
if (get_bits1(gb)) {
|
||||
av_log_missing_feature(ac->avctx, "SSR", 1);
|
||||
return -1;
|
||||
@@ -1434,7 +1440,7 @@ static int decode_ics(AACContext *ac, SingleChannelElement *sce,
|
||||
}
|
||||
|
||||
if (decode_spectrum_and_dequant(ac, out, gb, sce->sf, pulse_present, &pulse, ics, sce->band_type) < 0)
|
||||
return -1;
|
||||
return AVERROR_INVALIDDATA;
|
||||
|
||||
if (ac->m4ac.object_type == AOT_AAC_MAIN && !common_window)
|
||||
apply_prediction(ac, sce);
|
||||
@@ -1532,7 +1538,7 @@ static int decode_cpe(AACContext *ac, GetBitContext *gb, ChannelElement *cpe)
|
||||
ms_present = get_bits(gb, 2);
|
||||
if (ms_present == 3) {
|
||||
av_log(ac->avctx, AV_LOG_ERROR, "ms_present = 3 is reserved.\n");
|
||||
return -1;
|
||||
return AVERROR_INVALIDDATA;
|
||||
} else if (ms_present)
|
||||
decode_mid_side_stereo(cpe, gb, ms_present);
|
||||
}
|
||||
@@ -2323,7 +2329,8 @@ static int aac_decode_frame(AVCodecContext *avctx, void *data,
|
||||
return AVERROR_INVALIDDATA;
|
||||
}
|
||||
|
||||
init_get_bits(&gb, buf, buf_size * 8);
|
||||
if ((err = init_get_bits(&gb, buf, buf_size * 8)) < 0)
|
||||
return err;
|
||||
|
||||
if ((err = aac_decode_frame_int(avctx, data, got_frame_ptr, &gb)) < 0)
|
||||
return err;
|
||||
@@ -2568,7 +2575,8 @@ static int latm_decode_frame(AVCodecContext *avctx, void *out,
|
||||
int muxlength, err;
|
||||
GetBitContext gb;
|
||||
|
||||
init_get_bits(&gb, avpkt->data, avpkt->size * 8);
|
||||
if ((err = init_get_bits(&gb, avpkt->data, avpkt->size * 8)) < 0)
|
||||
return err;
|
||||
|
||||
// check for LOAS sync word
|
||||
if (get_bits(&gb, 11) != LOAS_SYNC_WORD)
|
||||
|
||||
+30
-25
@@ -297,7 +297,7 @@ static int parse_frame_header(AC3DecodeContext *s)
|
||||
return ff_eac3_parse_header(s);
|
||||
} else {
|
||||
av_log(s->avctx, AV_LOG_ERROR, "E-AC-3 support not compiled in\n");
|
||||
return -1;
|
||||
return AVERROR(ENOSYS);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -822,12 +822,12 @@ static int decode_audio_block(AC3DecodeContext *s, int blk)
|
||||
if (start_subband >= end_subband) {
|
||||
av_log(s->avctx, AV_LOG_ERROR, "invalid spectral extension "
|
||||
"range (%d >= %d)\n", start_subband, end_subband);
|
||||
return -1;
|
||||
return AVERROR_INVALIDDATA;
|
||||
}
|
||||
if (dst_start_freq >= src_start_freq) {
|
||||
av_log(s->avctx, AV_LOG_ERROR, "invalid spectral extension "
|
||||
"copy start bin (%d >= %d)\n", dst_start_freq, src_start_freq);
|
||||
return -1;
|
||||
return AVERROR_INVALIDDATA;
|
||||
}
|
||||
|
||||
s->spx_dst_start_freq = dst_start_freq;
|
||||
@@ -904,7 +904,7 @@ static int decode_audio_block(AC3DecodeContext *s, int blk)
|
||||
|
||||
if (channel_mode < AC3_CHMODE_STEREO) {
|
||||
av_log(s->avctx, AV_LOG_ERROR, "coupling not allowed in mono or dual-mono\n");
|
||||
return -1;
|
||||
return AVERROR_INVALIDDATA;
|
||||
}
|
||||
|
||||
/* check for enhanced coupling */
|
||||
@@ -934,7 +934,7 @@ static int decode_audio_block(AC3DecodeContext *s, int blk)
|
||||
if (cpl_start_subband >= cpl_end_subband) {
|
||||
av_log(s->avctx, AV_LOG_ERROR, "invalid coupling range (%d >= %d)\n",
|
||||
cpl_start_subband, cpl_end_subband);
|
||||
return -1;
|
||||
return AVERROR_INVALIDDATA;
|
||||
}
|
||||
s->start_freq[CPL_CH] = cpl_start_subband * 12 + 37;
|
||||
s->end_freq[CPL_CH] = cpl_end_subband * 12 + 37;
|
||||
@@ -956,7 +956,7 @@ static int decode_audio_block(AC3DecodeContext *s, int blk)
|
||||
if (!blk) {
|
||||
av_log(s->avctx, AV_LOG_ERROR, "new coupling strategy must "
|
||||
"be present in block 0\n");
|
||||
return -1;
|
||||
return AVERROR_INVALIDDATA;
|
||||
} else {
|
||||
s->cpl_in_use[blk] = s->cpl_in_use[blk-1];
|
||||
}
|
||||
@@ -986,7 +986,7 @@ static int decode_audio_block(AC3DecodeContext *s, int blk)
|
||||
} else if (!blk) {
|
||||
av_log(s->avctx, AV_LOG_ERROR, "new coupling coordinates must "
|
||||
"be present in block 0\n");
|
||||
return -1;
|
||||
return AVERROR_INVALIDDATA;
|
||||
}
|
||||
} else {
|
||||
/* channel not in coupling */
|
||||
@@ -1041,7 +1041,7 @@ static int decode_audio_block(AC3DecodeContext *s, int blk)
|
||||
int bandwidth_code = get_bits(gbc, 6);
|
||||
if (bandwidth_code > 60) {
|
||||
av_log(s->avctx, AV_LOG_ERROR, "bandwidth code = %d > 60\n", bandwidth_code);
|
||||
return -1;
|
||||
return AVERROR_INVALIDDATA;
|
||||
}
|
||||
s->end_freq[ch] = bandwidth_code * 3 + 73;
|
||||
}
|
||||
@@ -1064,7 +1064,7 @@ static int decode_audio_block(AC3DecodeContext *s, int blk)
|
||||
s->num_exp_groups[ch], s->dexps[ch][0],
|
||||
&s->dexps[ch][s->start_freq[ch]+!!ch])) {
|
||||
av_log(s->avctx, AV_LOG_ERROR, "exponent out-of-range\n");
|
||||
return -1;
|
||||
return AVERROR_INVALIDDATA;
|
||||
}
|
||||
if (ch != CPL_CH && ch != s->lfe_ch)
|
||||
skip_bits(gbc, 2); /* skip gainrng */
|
||||
@@ -1084,7 +1084,7 @@ static int decode_audio_block(AC3DecodeContext *s, int blk)
|
||||
} else if (!blk) {
|
||||
av_log(s->avctx, AV_LOG_ERROR, "new bit allocation info must "
|
||||
"be present in block 0\n");
|
||||
return -1;
|
||||
return AVERROR_INVALIDDATA;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1115,7 +1115,7 @@ static int decode_audio_block(AC3DecodeContext *s, int blk)
|
||||
}
|
||||
} else if (!s->eac3 && !blk) {
|
||||
av_log(s->avctx, AV_LOG_ERROR, "new snr offsets must be present in block 0\n");
|
||||
return -1;
|
||||
return AVERROR_INVALIDDATA;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1154,7 +1154,7 @@ static int decode_audio_block(AC3DecodeContext *s, int blk)
|
||||
} else if (!s->eac3 && !blk) {
|
||||
av_log(s->avctx, AV_LOG_ERROR, "new coupling leak info must "
|
||||
"be present in block 0\n");
|
||||
return -1;
|
||||
return AVERROR_INVALIDDATA;
|
||||
}
|
||||
s->first_cpl_leak = 0;
|
||||
}
|
||||
@@ -1166,7 +1166,7 @@ static int decode_audio_block(AC3DecodeContext *s, int blk)
|
||||
s->dba_mode[ch] = get_bits(gbc, 2);
|
||||
if (s->dba_mode[ch] == DBA_RESERVED) {
|
||||
av_log(s->avctx, AV_LOG_ERROR, "delta bit allocation strategy reserved\n");
|
||||
return -1;
|
||||
return AVERROR_INVALIDDATA;
|
||||
}
|
||||
bit_alloc_stages[ch] = FFMAX(bit_alloc_stages[ch], 2);
|
||||
}
|
||||
@@ -1207,7 +1207,7 @@ static int decode_audio_block(AC3DecodeContext *s, int blk)
|
||||
s->dba_offsets[ch], s->dba_lengths[ch],
|
||||
s->dba_values[ch], s->mask[ch])) {
|
||||
av_log(s->avctx, AV_LOG_ERROR, "error in bit allocation\n");
|
||||
return -1;
|
||||
return AVERROR_INVALIDDATA;
|
||||
}
|
||||
}
|
||||
if (bit_alloc_stages[ch] > 0) {
|
||||
@@ -1328,7 +1328,7 @@ static int ac3_decode_frame(AVCodecContext * avctx, void *data,
|
||||
switch (err) {
|
||||
case AAC_AC3_PARSE_ERROR_SYNC:
|
||||
av_log(avctx, AV_LOG_ERROR, "frame sync error\n");
|
||||
return -1;
|
||||
return AVERROR_INVALIDDATA;
|
||||
case AAC_AC3_PARSE_ERROR_BSID:
|
||||
av_log(avctx, AV_LOG_ERROR, "invalid bitstream id\n");
|
||||
break;
|
||||
@@ -1342,17 +1342,20 @@ static int ac3_decode_frame(AVCodecContext * avctx, void *data,
|
||||
/* skip frame if CRC is ok. otherwise use error concealment. */
|
||||
/* TODO: add support for substreams and dependent frames */
|
||||
if (s->frame_type == EAC3_FRAME_TYPE_DEPENDENT || s->substreamid) {
|
||||
av_log(avctx, AV_LOG_ERROR, "unsupported frame type : "
|
||||
av_log(avctx, AV_LOG_WARNING, "unsupported frame type : "
|
||||
"skipping frame\n");
|
||||
*got_frame_ptr = 0;
|
||||
return s->frame_size;
|
||||
return buf_size;
|
||||
} else {
|
||||
av_log(avctx, AV_LOG_ERROR, "invalid frame type\n");
|
||||
}
|
||||
break;
|
||||
default:
|
||||
av_log(avctx, AV_LOG_ERROR, "invalid header\n");
|
||||
case AAC_AC3_PARSE_ERROR_CRC:
|
||||
case AAC_AC3_PARSE_ERROR_CHANNEL_CFG:
|
||||
break;
|
||||
default: // Normal AVERROR do not try to recover.
|
||||
*got_frame_ptr = 0;
|
||||
return err;
|
||||
}
|
||||
} else {
|
||||
/* check that reported frame size fits in input buffer */
|
||||
@@ -1373,8 +1376,10 @@ static int ac3_decode_frame(AVCodecContext * avctx, void *data,
|
||||
if (!err) {
|
||||
avctx->sample_rate = s->sample_rate;
|
||||
avctx->bit_rate = s->bit_rate;
|
||||
}
|
||||
|
||||
/* channel config */
|
||||
/* channel config */
|
||||
if (!err || (s->channels && s->out_channels != s->channels)) {
|
||||
s->out_channels = s->channels;
|
||||
s->output_mode = s->channel_mode;
|
||||
if (s->lfe_on)
|
||||
@@ -1397,18 +1402,18 @@ static int ac3_decode_frame(AVCodecContext * avctx, void *data,
|
||||
s->fbw_channels == s->out_channels)) {
|
||||
set_downmix_coeffs(s);
|
||||
}
|
||||
} else if (!s->out_channels) {
|
||||
s->out_channels = avctx->channels;
|
||||
if (s->out_channels < s->channels)
|
||||
s->output_mode = s->out_channels == 1 ? AC3_CHMODE_MONO : AC3_CHMODE_STEREO;
|
||||
} else if (!s->channels) {
|
||||
av_log(avctx, AV_LOG_ERROR, "unable to determine channel mode\n");
|
||||
return AVERROR_INVALIDDATA;
|
||||
}
|
||||
avctx->channels = s->out_channels;
|
||||
|
||||
/* set audio service type based on bitstream mode for AC-3 */
|
||||
avctx->audio_service_type = s->bitstream_mode;
|
||||
if (s->bitstream_mode == 0x7 && s->channels > 1)
|
||||
avctx->audio_service_type = AV_AUDIO_SERVICE_TYPE_KARAOKE;
|
||||
|
||||
/* get output buffer */
|
||||
avctx->channels = s->out_channels;
|
||||
s->frame.nb_samples = s->num_blocks * 256;
|
||||
if ((ret = avctx->get_buffer(avctx, &s->frame)) < 0) {
|
||||
av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
|
||||
|
||||
+1
-1
@@ -717,7 +717,7 @@ static int adpcm_decode_frame(AVCodecContext *avctx, void *data,
|
||||
src++;
|
||||
*samples++ = cs->predictor;
|
||||
}
|
||||
for (n = nb_samples >> (1 - st); n > 0; n--, src++) {
|
||||
for (n = (nb_samples >> (1 - st)) - 1; n > 0; n--, src++) {
|
||||
uint8_t v = *src;
|
||||
*samples++ = adpcm_ima_expand_nibble(&c->status[0 ], v >> 4 , 3);
|
||||
*samples++ = adpcm_ima_expand_nibble(&c->status[st], v & 0x0F, 3);
|
||||
|
||||
+88
-67
@@ -294,12 +294,12 @@ static av_cold int read_specific_config(ALSDecContext *ctx)
|
||||
avctx->extradata_size * 8, 1);
|
||||
|
||||
if (config_offset < 0)
|
||||
return -1;
|
||||
return AVERROR_INVALIDDATA;
|
||||
|
||||
skip_bits_long(&gb, config_offset);
|
||||
|
||||
if (get_bits_left(&gb) < (30 << 3))
|
||||
return -1;
|
||||
return AVERROR_INVALIDDATA;
|
||||
|
||||
// read the fixed items
|
||||
als_id = get_bits_long(&gb, 32);
|
||||
@@ -334,7 +334,7 @@ static av_cold int read_specific_config(ALSDecContext *ctx)
|
||||
|
||||
// check for ALSSpecificConfig struct
|
||||
if (als_id != MKBETAG('A','L','S','\0'))
|
||||
return -1;
|
||||
return AVERROR_INVALIDDATA;
|
||||
|
||||
ctx->cur_frame_length = sconf->frame_length;
|
||||
|
||||
@@ -349,7 +349,7 @@ static av_cold int read_specific_config(ALSDecContext *ctx)
|
||||
int chan_pos_bits = av_ceil_log2(avctx->channels);
|
||||
int bits_needed = avctx->channels * chan_pos_bits + 7;
|
||||
if (get_bits_left(&gb) < bits_needed)
|
||||
return -1;
|
||||
return AVERROR_INVALIDDATA;
|
||||
|
||||
if (!(sconf->chan_pos = av_malloc(avctx->channels * sizeof(*sconf->chan_pos))))
|
||||
return AVERROR(ENOMEM);
|
||||
@@ -367,7 +367,7 @@ static av_cold int read_specific_config(ALSDecContext *ctx)
|
||||
// read fixed header and trailer sizes,
|
||||
// if size = 0xFFFFFFFF then there is no data field!
|
||||
if (get_bits_left(&gb) < 64)
|
||||
return -1;
|
||||
return AVERROR_INVALIDDATA;
|
||||
|
||||
header_size = get_bits_long(&gb, 32);
|
||||
trailer_size = get_bits_long(&gb, 32);
|
||||
@@ -381,10 +381,10 @@ static av_cold int read_specific_config(ALSDecContext *ctx)
|
||||
|
||||
// skip the header and trailer data
|
||||
if (get_bits_left(&gb) < ht_size)
|
||||
return -1;
|
||||
return AVERROR_INVALIDDATA;
|
||||
|
||||
if (ht_size > INT32_MAX)
|
||||
return -1;
|
||||
return AVERROR_PATCHWELCOME;
|
||||
|
||||
skip_bits_long(&gb, ht_size);
|
||||
|
||||
@@ -392,7 +392,7 @@ static av_cold int read_specific_config(ALSDecContext *ctx)
|
||||
// initialize CRC calculation
|
||||
if (sconf->crc_enabled) {
|
||||
if (get_bits_left(&gb) < 32)
|
||||
return -1;
|
||||
return AVERROR_INVALIDDATA;
|
||||
|
||||
if (avctx->err_recognition & (AV_EF_CRCCHECK|AV_EF_CAREFUL)) {
|
||||
ctx->crc_table = av_crc_get_table(AV_CRC_32_IEEE_LE);
|
||||
@@ -632,7 +632,7 @@ static int read_var_block_data(ALSDecContext *ctx, ALSBlockData *bd)
|
||||
if (bd->block_length & (sub_blocks - 1)) {
|
||||
av_log(avctx, AV_LOG_WARNING,
|
||||
"Block length is not evenly divisible by the number of subblocks.\n");
|
||||
return -1;
|
||||
return AVERROR_INVALIDDATA;
|
||||
}
|
||||
|
||||
sb_length = bd->block_length >> log2_sub_blocks;
|
||||
@@ -963,18 +963,18 @@ static int decode_var_block_data(ALSDecContext *ctx, ALSBlockData *bd)
|
||||
*/
|
||||
static int read_block(ALSDecContext *ctx, ALSBlockData *bd)
|
||||
{
|
||||
int ret = 0;
|
||||
GetBitContext *gb = &ctx->gb;
|
||||
|
||||
*bd->shift_lsbs = 0;
|
||||
// read block type flag and read the samples accordingly
|
||||
if (get_bits1(gb)) {
|
||||
if (read_var_block_data(ctx, bd))
|
||||
return -1;
|
||||
ret = read_var_block_data(ctx, bd);
|
||||
} else {
|
||||
read_const_block_data(ctx, bd);
|
||||
}
|
||||
|
||||
return 0;
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
@@ -983,12 +983,16 @@ static int read_block(ALSDecContext *ctx, ALSBlockData *bd)
|
||||
static int decode_block(ALSDecContext *ctx, ALSBlockData *bd)
|
||||
{
|
||||
unsigned int smp;
|
||||
int ret = 0;
|
||||
|
||||
// read block type flag and read the samples accordingly
|
||||
if (*bd->const_block)
|
||||
decode_const_block_data(ctx, bd);
|
||||
else if (decode_var_block_data(ctx, bd))
|
||||
return -1;
|
||||
else
|
||||
ret = decode_var_block_data(ctx, bd); // always return 0
|
||||
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
|
||||
// TODO: read RLSLMS extension data
|
||||
|
||||
@@ -1006,14 +1010,10 @@ static int read_decode_block(ALSDecContext *ctx, ALSBlockData *bd)
|
||||
{
|
||||
int ret;
|
||||
|
||||
ret = read_block(ctx, bd);
|
||||
|
||||
if (ret)
|
||||
if ((ret = read_block(ctx, bd)) < 0)
|
||||
return ret;
|
||||
|
||||
ret = decode_block(ctx, bd);
|
||||
|
||||
return ret;
|
||||
return decode_block(ctx, bd);
|
||||
}
|
||||
|
||||
|
||||
@@ -1039,6 +1039,7 @@ static int decode_blocks_ind(ALSDecContext *ctx, unsigned int ra_frame,
|
||||
unsigned int c, const unsigned int *div_blocks,
|
||||
unsigned int *js_blocks)
|
||||
{
|
||||
int ret;
|
||||
unsigned int b;
|
||||
ALSBlockData bd;
|
||||
|
||||
@@ -1061,10 +1062,10 @@ static int decode_blocks_ind(ALSDecContext *ctx, unsigned int ra_frame,
|
||||
for (b = 0; b < ctx->num_blocks; b++) {
|
||||
bd.block_length = div_blocks[b];
|
||||
|
||||
if (read_decode_block(ctx, &bd)) {
|
||||
if ((ret = read_decode_block(ctx, &bd)) < 0) {
|
||||
// damaged block, write zero for the rest of the frame
|
||||
zero_remaining(b, ctx->num_blocks, div_blocks, bd.raw_samples);
|
||||
return -1;
|
||||
return ret;
|
||||
}
|
||||
bd.raw_samples += div_blocks[b];
|
||||
bd.ra_block = 0;
|
||||
@@ -1083,6 +1084,7 @@ static int decode_blocks(ALSDecContext *ctx, unsigned int ra_frame,
|
||||
ALSSpecificConfig *sconf = &ctx->sconf;
|
||||
unsigned int offset = 0;
|
||||
unsigned int b;
|
||||
int ret;
|
||||
ALSBlockData bd[2];
|
||||
|
||||
memset(bd, 0, 2 * sizeof(ALSBlockData));
|
||||
@@ -1126,12 +1128,10 @@ static int decode_blocks(ALSDecContext *ctx, unsigned int ra_frame,
|
||||
bd[0].raw_other = bd[1].raw_samples;
|
||||
bd[1].raw_other = bd[0].raw_samples;
|
||||
|
||||
if(read_decode_block(ctx, &bd[0]) || read_decode_block(ctx, &bd[1])) {
|
||||
// damaged block, write zero for the rest of the frame
|
||||
zero_remaining(b, ctx->num_blocks, div_blocks, bd[0].raw_samples);
|
||||
zero_remaining(b, ctx->num_blocks, div_blocks, bd[1].raw_samples);
|
||||
return -1;
|
||||
}
|
||||
if ((ret = read_decode_block(ctx, &bd[0])) < 0 ||
|
||||
(ret = read_decode_block(ctx, &bd[1])) < 0)
|
||||
goto fail;
|
||||
|
||||
|
||||
// reconstruct joint-stereo blocks
|
||||
if (bd[0].js_blocks) {
|
||||
@@ -1157,8 +1157,19 @@ static int decode_blocks(ALSDecContext *ctx, unsigned int ra_frame,
|
||||
sizeof(*ctx->raw_samples[c]) * sconf->max_order);
|
||||
|
||||
return 0;
|
||||
fail:
|
||||
// damaged block, write zero for the rest of the frame
|
||||
zero_remaining(b, ctx->num_blocks, div_blocks, bd[0].raw_samples);
|
||||
zero_remaining(b, ctx->num_blocks, div_blocks, bd[1].raw_samples);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static inline int als_weighting(GetBitContext *gb, int k, int off)
|
||||
{
|
||||
int idx = av_clip(decode_rice(gb, k) + off,
|
||||
0, FF_ARRAY_ELEMS(mcc_weightings) - 1);
|
||||
return mcc_weightings[idx];
|
||||
}
|
||||
|
||||
/** Read the channel data.
|
||||
*/
|
||||
@@ -1174,19 +1185,19 @@ static int read_channel_data(ALSDecContext *ctx, ALSChannelData *cd, int c)
|
||||
|
||||
if (current->master_channel >= channels) {
|
||||
av_log(ctx->avctx, AV_LOG_ERROR, "Invalid master channel!\n");
|
||||
return -1;
|
||||
return AVERROR_INVALIDDATA;
|
||||
}
|
||||
|
||||
if (current->master_channel != c) {
|
||||
current->time_diff_flag = get_bits1(gb);
|
||||
current->weighting[0] = mcc_weightings[av_clip(decode_rice(gb, 1) + 16, 0, 31)];
|
||||
current->weighting[1] = mcc_weightings[av_clip(decode_rice(gb, 2) + 14, 0, 31)];
|
||||
current->weighting[2] = mcc_weightings[av_clip(decode_rice(gb, 1) + 16, 0, 31)];
|
||||
current->weighting[0] = als_weighting(gb, 1, 16);
|
||||
current->weighting[1] = als_weighting(gb, 2, 14);
|
||||
current->weighting[2] = als_weighting(gb, 1, 16);
|
||||
|
||||
if (current->time_diff_flag) {
|
||||
current->weighting[3] = mcc_weightings[av_clip(decode_rice(gb, 1) + 16, 0, 31)];
|
||||
current->weighting[4] = mcc_weightings[av_clip(decode_rice(gb, 1) + 16, 0, 31)];
|
||||
current->weighting[5] = mcc_weightings[av_clip(decode_rice(gb, 1) + 16, 0, 31)];
|
||||
current->weighting[3] = als_weighting(gb, 1, 16);
|
||||
current->weighting[4] = als_weighting(gb, 1, 16);
|
||||
current->weighting[5] = als_weighting(gb, 1, 16);
|
||||
|
||||
current->time_diff_sign = get_bits1(gb);
|
||||
current->time_diff_index = get_bits(gb, ctx->ltp_lag_length - 3) + 3;
|
||||
@@ -1199,7 +1210,7 @@ static int read_channel_data(ALSDecContext *ctx, ALSChannelData *cd, int c)
|
||||
|
||||
if (entries == channels) {
|
||||
av_log(ctx->avctx, AV_LOG_ERROR, "Damaged channel data!\n");
|
||||
return -1;
|
||||
return AVERROR_INVALIDDATA;
|
||||
}
|
||||
|
||||
align_get_bits(gb);
|
||||
@@ -1231,7 +1242,7 @@ static int revert_channel_correlation(ALSDecContext *ctx, ALSBlockData *bd,
|
||||
|
||||
if (dep == channels) {
|
||||
av_log(ctx->avctx, AV_LOG_WARNING, "Invalid channel correlation!\n");
|
||||
return -1;
|
||||
return AVERROR_INVALIDDATA;
|
||||
}
|
||||
|
||||
bd->const_block = ctx->const_block + c;
|
||||
@@ -1304,6 +1315,7 @@ static int read_frame_data(ALSDecContext *ctx, unsigned int ra_frame)
|
||||
unsigned int js_blocks[2];
|
||||
|
||||
uint32_t bs_info = 0;
|
||||
int ret;
|
||||
|
||||
// skip the size of the ra unit if present in the frame
|
||||
if (sconf->ra_flag == RA_FLAG_FRAMES && ra_frame)
|
||||
@@ -1334,13 +1346,15 @@ static int read_frame_data(ALSDecContext *ctx, unsigned int ra_frame)
|
||||
independent_bs = 1;
|
||||
|
||||
if (independent_bs) {
|
||||
if (decode_blocks_ind(ctx, ra_frame, c, div_blocks, js_blocks))
|
||||
return -1;
|
||||
|
||||
ret = decode_blocks_ind(ctx, ra_frame, c,
|
||||
div_blocks, js_blocks);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
independent_bs--;
|
||||
} else {
|
||||
if (decode_blocks(ctx, ra_frame, c, div_blocks, js_blocks))
|
||||
return -1;
|
||||
ret = decode_blocks(ctx, ra_frame, c, div_blocks, js_blocks);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
|
||||
c++;
|
||||
}
|
||||
@@ -1359,7 +1373,7 @@ static int read_frame_data(ALSDecContext *ctx, unsigned int ra_frame)
|
||||
for (c = 0; c < avctx->channels; c++)
|
||||
if (ctx->chan_data[c] < ctx->chan_data_buffer) {
|
||||
av_log(ctx->avctx, AV_LOG_ERROR, "Invalid channel data!\n");
|
||||
return -1;
|
||||
return AVERROR_INVALIDDATA;
|
||||
}
|
||||
|
||||
memset(&bd, 0, sizeof(ALSBlockData));
|
||||
@@ -1391,11 +1405,12 @@ static int read_frame_data(ALSDecContext *ctx, unsigned int ra_frame)
|
||||
return -1;
|
||||
}
|
||||
|
||||
for (c = 0; c < avctx->channels; c++)
|
||||
if (revert_channel_correlation(ctx, &bd, ctx->chan_data,
|
||||
reverted_channels, offset, c))
|
||||
return -1;
|
||||
|
||||
for (c = 0; c < avctx->channels; c++) {
|
||||
ret = revert_channel_correlation(ctx, &bd, ctx->chan_data,
|
||||
reverted_channels, offset, c);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
}
|
||||
for (c = 0; c < avctx->channels; c++) {
|
||||
bd.const_block = ctx->const_block + c;
|
||||
bd.shift_lsbs = ctx->shift_lsbs + c;
|
||||
@@ -1592,29 +1607,30 @@ static av_cold int decode_init(AVCodecContext *avctx)
|
||||
{
|
||||
unsigned int c;
|
||||
unsigned int channel_size;
|
||||
int num_buffers;
|
||||
int num_buffers, ret;
|
||||
ALSDecContext *ctx = avctx->priv_data;
|
||||
ALSSpecificConfig *sconf = &ctx->sconf;
|
||||
ctx->avctx = avctx;
|
||||
|
||||
if (!avctx->extradata) {
|
||||
av_log(avctx, AV_LOG_ERROR, "Missing required ALS extradata.\n");
|
||||
return -1;
|
||||
return AVERROR_INVALIDDATA;
|
||||
}
|
||||
|
||||
if (read_specific_config(ctx)) {
|
||||
if ((ret = read_specific_config(ctx)) < 0) {
|
||||
av_log(avctx, AV_LOG_ERROR, "Reading ALSSpecificConfig failed.\n");
|
||||
decode_end(avctx);
|
||||
return -1;
|
||||
goto fail;
|
||||
}
|
||||
|
||||
if (check_specific_config(ctx)) {
|
||||
decode_end(avctx);
|
||||
return -1;
|
||||
if ((ret = check_specific_config(ctx)) < 0) {
|
||||
goto fail;
|
||||
}
|
||||
|
||||
if (sconf->bgmc)
|
||||
ff_bgmc_init(avctx, &ctx->bgmc_lut, &ctx->bgmc_lut_status);
|
||||
if (sconf->bgmc) {
|
||||
ret = ff_bgmc_init(avctx, &ctx->bgmc_lut, &ctx->bgmc_lut_status);
|
||||
if (ret < 0)
|
||||
goto fail;
|
||||
}
|
||||
|
||||
if (sconf->floating) {
|
||||
avctx->sample_fmt = AV_SAMPLE_FMT_FLT;
|
||||
@@ -1650,7 +1666,8 @@ static av_cold int decode_init(AVCodecContext *avctx)
|
||||
!ctx->quant_cof_buffer || !ctx->lpc_cof_buffer ||
|
||||
!ctx->lpc_cof_reversed_buffer) {
|
||||
av_log(avctx, AV_LOG_ERROR, "Allocating buffer memory failed.\n");
|
||||
return AVERROR(ENOMEM);
|
||||
ret = AVERROR(ENOMEM);
|
||||
goto fail;
|
||||
}
|
||||
|
||||
// assign quantized parcor coefficient buffers
|
||||
@@ -1675,8 +1692,8 @@ static av_cold int decode_init(AVCodecContext *avctx)
|
||||
!ctx->use_ltp || !ctx->ltp_lag ||
|
||||
!ctx->ltp_gain || !ctx->ltp_gain_buffer) {
|
||||
av_log(avctx, AV_LOG_ERROR, "Allocating buffer memory failed.\n");
|
||||
decode_end(avctx);
|
||||
return AVERROR(ENOMEM);
|
||||
ret = AVERROR(ENOMEM);
|
||||
goto fail;
|
||||
}
|
||||
|
||||
for (c = 0; c < num_buffers; c++)
|
||||
@@ -1693,8 +1710,8 @@ static av_cold int decode_init(AVCodecContext *avctx)
|
||||
|
||||
if (!ctx->chan_data_buffer || !ctx->chan_data || !ctx->reverted_channels) {
|
||||
av_log(avctx, AV_LOG_ERROR, "Allocating buffer memory failed.\n");
|
||||
decode_end(avctx);
|
||||
return AVERROR(ENOMEM);
|
||||
ret = AVERROR(ENOMEM);
|
||||
goto fail;
|
||||
}
|
||||
|
||||
for (c = 0; c < num_buffers; c++)
|
||||
@@ -1715,8 +1732,8 @@ static av_cold int decode_init(AVCodecContext *avctx)
|
||||
// allocate previous raw sample buffer
|
||||
if (!ctx->prev_raw_samples || !ctx->raw_buffer|| !ctx->raw_samples) {
|
||||
av_log(avctx, AV_LOG_ERROR, "Allocating buffer memory failed.\n");
|
||||
decode_end(avctx);
|
||||
return AVERROR(ENOMEM);
|
||||
ret = AVERROR(ENOMEM);
|
||||
goto fail;
|
||||
}
|
||||
|
||||
// assign raw samples buffers
|
||||
@@ -1733,8 +1750,8 @@ static av_cold int decode_init(AVCodecContext *avctx)
|
||||
av_get_bytes_per_sample(avctx->sample_fmt));
|
||||
if (!ctx->crc_buffer) {
|
||||
av_log(avctx, AV_LOG_ERROR, "Allocating buffer memory failed.\n");
|
||||
decode_end(avctx);
|
||||
return AVERROR(ENOMEM);
|
||||
ret = AVERROR(ENOMEM);
|
||||
goto fail;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1744,6 +1761,10 @@ static av_cold int decode_init(AVCodecContext *avctx)
|
||||
avctx->coded_frame = &ctx->frame;
|
||||
|
||||
return 0;
|
||||
|
||||
fail:
|
||||
decode_end(avctx);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
|
||||
+5
-2
@@ -690,7 +690,8 @@ static int decodeChannelSoundUnit (ATRAC3Context *q, GetBitContext *gb, channel_
|
||||
if (result) return result;
|
||||
|
||||
pSnd->numComponents = decodeTonalComponents (gb, pSnd->components, pSnd->bandsCoded);
|
||||
if (pSnd->numComponents == -1) return -1;
|
||||
if (pSnd->numComponents < 0)
|
||||
return pSnd->numComponents;
|
||||
|
||||
numSubbands = decodeSpectrum (gb, pSnd->spectrum);
|
||||
|
||||
@@ -772,7 +773,7 @@ static int decodeFrame(ATRAC3Context *q, const uint8_t* databuf,
|
||||
|
||||
|
||||
/* set the bitstream reader at the start of the second Sound Unit*/
|
||||
init_get_bits(&q->gb,ptr1,q->bits_per_frame);
|
||||
init_get_bits(&q->gb, ptr1, (q->bytes_per_frame - i) * 8);
|
||||
|
||||
/* Fill the Weighting coeffs delay buffer */
|
||||
memmove(q->weighting_delay,&(q->weighting_delay[2]),4*sizeof(int));
|
||||
@@ -975,6 +976,8 @@ static av_cold int atrac3_decode_init(AVCodecContext *avctx)
|
||||
if (q->codingMode == STEREO) {
|
||||
av_log(avctx,AV_LOG_DEBUG,"Normal stereo detected.\n");
|
||||
} else if (q->codingMode == JOINT_STEREO) {
|
||||
if (avctx->channels != 2)
|
||||
return AVERROR_INVALIDDATA;
|
||||
av_log(avctx,AV_LOG_DEBUG,"Joint stereo detected.\n");
|
||||
} else {
|
||||
av_log(avctx,AV_LOG_ERROR,"Unknown channel coding mode %x!\n",q->codingMode);
|
||||
|
||||
@@ -679,6 +679,9 @@ static int read_dct_coeffs(GetBitContext *gb, int32_t block[64], const uint8_t *
|
||||
quant_idx = q;
|
||||
}
|
||||
|
||||
if (quant_idx >= 16)
|
||||
return AVERROR_INVALIDDATA;
|
||||
|
||||
quant = quant_matrices[quant_idx];
|
||||
|
||||
block[0] = (block[0] * quant[0]) >> 11;
|
||||
|
||||
@@ -804,6 +804,13 @@ static int dca_subframe_header(DCAContext *s, int base_channel, int block_index)
|
||||
"Invalid channel mode %d\n", am);
|
||||
return AVERROR_INVALIDDATA;
|
||||
}
|
||||
|
||||
if (s->prim_channels > FF_ARRAY_ELEMS(dca_default_coeffs[0])) {
|
||||
av_log_ask_for_sample(s->avctx, "Downmixing %d channels",
|
||||
s->prim_channels);
|
||||
return AVERROR_PATCHWELCOME;
|
||||
}
|
||||
|
||||
for (j = base_channel; j < s->prim_channels; j++) {
|
||||
s->downmix_coef[j][0] = dca_default_coeffs[am][j][0];
|
||||
s->downmix_coef[j][1] = dca_default_coeffs[am][j][1];
|
||||
@@ -1253,6 +1260,7 @@ static int dca_subsubframe(DCAContext *s, int base_channel, int block_index)
|
||||
#endif
|
||||
} else {
|
||||
av_log(s->avctx, AV_LOG_ERROR, "Didn't get subframe DSYNC\n");
|
||||
return AVERROR_INVALIDDATA;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+67
-50
@@ -108,27 +108,31 @@ static av_cold int cinvideo_decode_init(AVCodecContext *avctx)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void cin_apply_delta_data(const unsigned char *src, unsigned char *dst, int size)
|
||||
static void cin_apply_delta_data(const unsigned char *src, unsigned char *dst,
|
||||
int size)
|
||||
{
|
||||
while (size--)
|
||||
*dst++ += *src++;
|
||||
}
|
||||
|
||||
static int cin_decode_huffman(const unsigned char *src, int src_size, unsigned char *dst, int dst_size)
|
||||
static int cin_decode_huffman(const unsigned char *src, int src_size,
|
||||
unsigned char *dst, int dst_size)
|
||||
{
|
||||
int b, huff_code = 0;
|
||||
unsigned char huff_code_table[15];
|
||||
unsigned char *dst_cur = dst;
|
||||
unsigned char *dst_end = dst + dst_size;
|
||||
unsigned char *dst_cur = dst;
|
||||
unsigned char *dst_end = dst + dst_size;
|
||||
const unsigned char *src_end = src + src_size;
|
||||
|
||||
memcpy(huff_code_table, src, 15); src += 15; src_size -= 15;
|
||||
memcpy(huff_code_table, src, 15);
|
||||
src += 15;
|
||||
src_size -= 15;
|
||||
|
||||
while (src < src_end) {
|
||||
huff_code = *src++;
|
||||
if ((huff_code >> 4) == 15) {
|
||||
b = huff_code << 4;
|
||||
huff_code = *src++;
|
||||
b = huff_code << 4;
|
||||
huff_code = *src++;
|
||||
*dst_cur++ = b | (huff_code >> 4);
|
||||
} else
|
||||
*dst_cur++ = huff_code_table[huff_code >> 4];
|
||||
@@ -147,11 +151,12 @@ static int cin_decode_huffman(const unsigned char *src, int src_size, unsigned c
|
||||
return dst_cur - dst;
|
||||
}
|
||||
|
||||
static int cin_decode_lzss(const unsigned char *src, int src_size, unsigned char *dst, int dst_size)
|
||||
static int cin_decode_lzss(const unsigned char *src, int src_size,
|
||||
unsigned char *dst, int dst_size)
|
||||
{
|
||||
uint16_t cmd;
|
||||
int i, sz, offset, code;
|
||||
unsigned char *dst_end = dst + dst_size, *dst_start = dst;
|
||||
unsigned char *dst_end = dst + dst_size, *dst_start = dst;
|
||||
const unsigned char *src_end = src + src_size;
|
||||
|
||||
while (src < src_end && dst < dst_end) {
|
||||
@@ -160,13 +165,15 @@ static int cin_decode_lzss(const unsigned char *src, int src_size, unsigned char
|
||||
if (code & (1 << i)) {
|
||||
*dst++ = *src++;
|
||||
} else {
|
||||
cmd = AV_RL16(src); src += 2;
|
||||
cmd = AV_RL16(src);
|
||||
src += 2;
|
||||
offset = cmd >> 4;
|
||||
if ((int) (dst - dst_start) < offset + 1)
|
||||
if ((int)(dst - dst_start) < offset + 1)
|
||||
return AVERROR_INVALIDDATA;
|
||||
sz = (cmd & 0xF) + 2;
|
||||
/* don't use memcpy/memmove here as the decoding routine (ab)uses */
|
||||
/* buffer overlappings to repeat bytes in the destination */
|
||||
/* don't use memcpy/memmove here as the decoding routine
|
||||
* (ab)uses buffer overlappings to repeat bytes in the
|
||||
* destination */
|
||||
sz = FFMIN(sz, dst_end - dst);
|
||||
while (sz--) {
|
||||
*dst = *(dst - offset - 1);
|
||||
@@ -179,20 +186,23 @@ static int cin_decode_lzss(const unsigned char *src, int src_size, unsigned char
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void cin_decode_rle(const unsigned char *src, int src_size, unsigned char *dst, int dst_size)
|
||||
static void cin_decode_rle(const unsigned char *src, int src_size,
|
||||
unsigned char *dst, int dst_size)
|
||||
{
|
||||
int len, code;
|
||||
unsigned char *dst_end = dst + dst_size;
|
||||
unsigned char *dst_end = dst + dst_size;
|
||||
const unsigned char *src_end = src + src_size;
|
||||
|
||||
while (src < src_end && dst < dst_end) {
|
||||
code = *src++;
|
||||
if (code & 0x80) {
|
||||
if (src >= src_end)
|
||||
break;
|
||||
len = code - 0x7F;
|
||||
memset(dst, *src++, FFMIN(len, dst_end - dst));
|
||||
} else {
|
||||
len = code + 1;
|
||||
memcpy(dst, src, FFMIN(len, dst_end - dst));
|
||||
memcpy(dst, src, FFMIN3(len, dst_end - dst, src_end - src));
|
||||
src += len;
|
||||
}
|
||||
dst += len;
|
||||
@@ -203,15 +213,16 @@ static int cinvideo_decode_frame(AVCodecContext *avctx,
|
||||
void *data, int *data_size,
|
||||
AVPacket *avpkt)
|
||||
{
|
||||
const uint8_t *buf = avpkt->data;
|
||||
int buf_size = avpkt->size;
|
||||
const uint8_t *buf = avpkt->data;
|
||||
int buf_size = avpkt->size;
|
||||
CinVideoContext *cin = avctx->priv_data;
|
||||
int i, y, palette_type, palette_colors_count, bitmap_frame_type, bitmap_frame_size, res = 0;
|
||||
int i, y, palette_type, palette_colors_count,
|
||||
bitmap_frame_type, bitmap_frame_size, res = 0;
|
||||
|
||||
palette_type = buf[0];
|
||||
palette_type = buf[0];
|
||||
palette_colors_count = AV_RL16(buf+1);
|
||||
bitmap_frame_type = buf[3];
|
||||
buf += 4;
|
||||
bitmap_frame_type = buf[3];
|
||||
buf += 4;
|
||||
|
||||
bitmap_frame_size = buf_size - 4;
|
||||
|
||||
@@ -222,46 +233,50 @@ static int cinvideo_decode_frame(AVCodecContext *avctx,
|
||||
if (palette_colors_count > 256)
|
||||
return AVERROR_INVALIDDATA;
|
||||
for (i = 0; i < palette_colors_count; ++i) {
|
||||
cin->palette[i] = 0xFF << 24 | bytestream_get_le24(&buf);
|
||||
cin->palette[i] = 0xFF << 24 | bytestream_get_le24(&buf);
|
||||
bitmap_frame_size -= 3;
|
||||
}
|
||||
} else {
|
||||
for (i = 0; i < palette_colors_count; ++i) {
|
||||
cin->palette[buf[0]] = 0xFF << 24 | AV_RL24(buf+1);
|
||||
buf += 4;
|
||||
bitmap_frame_size -= 4;
|
||||
cin->palette[buf[0]] = 0xFF << 24 | AV_RL24(buf + 1);
|
||||
buf += 4;
|
||||
bitmap_frame_size -= 4;
|
||||
}
|
||||
}
|
||||
|
||||
/* note: the decoding routines below assumes that surface.width = surface.pitch */
|
||||
bitmap_frame_size = FFMIN(cin->bitmap_size, bitmap_frame_size);
|
||||
|
||||
/* note: the decoding routines below assumes that
|
||||
* surface.width = surface.pitch */
|
||||
switch (bitmap_frame_type) {
|
||||
case 9:
|
||||
cin_decode_rle(buf, bitmap_frame_size,
|
||||
cin->bitmap_table[CIN_CUR_BMP], cin->bitmap_size);
|
||||
cin->bitmap_table[CIN_CUR_BMP], cin->bitmap_size);
|
||||
break;
|
||||
case 34:
|
||||
cin_decode_rle(buf, bitmap_frame_size,
|
||||
cin->bitmap_table[CIN_CUR_BMP], cin->bitmap_size);
|
||||
cin->bitmap_table[CIN_CUR_BMP], cin->bitmap_size);
|
||||
cin_apply_delta_data(cin->bitmap_table[CIN_PRE_BMP],
|
||||
cin->bitmap_table[CIN_CUR_BMP], cin->bitmap_size);
|
||||
cin->bitmap_table[CIN_CUR_BMP], cin->bitmap_size);
|
||||
break;
|
||||
case 35:
|
||||
cin_decode_huffman(buf, bitmap_frame_size,
|
||||
cin->bitmap_table[CIN_INT_BMP], cin->bitmap_size);
|
||||
cin->bitmap_table[CIN_INT_BMP], cin->bitmap_size);
|
||||
cin_decode_rle(cin->bitmap_table[CIN_INT_BMP], bitmap_frame_size,
|
||||
cin->bitmap_table[CIN_CUR_BMP], cin->bitmap_size);
|
||||
cin->bitmap_table[CIN_CUR_BMP], cin->bitmap_size);
|
||||
break;
|
||||
case 36:
|
||||
bitmap_frame_size = cin_decode_huffman(buf, bitmap_frame_size,
|
||||
cin->bitmap_table[CIN_INT_BMP], cin->bitmap_size);
|
||||
cin->bitmap_table[CIN_INT_BMP],
|
||||
cin->bitmap_size);
|
||||
cin_decode_rle(cin->bitmap_table[CIN_INT_BMP], bitmap_frame_size,
|
||||
cin->bitmap_table[CIN_CUR_BMP], cin->bitmap_size);
|
||||
cin->bitmap_table[CIN_CUR_BMP], cin->bitmap_size);
|
||||
cin_apply_delta_data(cin->bitmap_table[CIN_PRE_BMP],
|
||||
cin->bitmap_table[CIN_CUR_BMP], cin->bitmap_size);
|
||||
cin->bitmap_table[CIN_CUR_BMP], cin->bitmap_size);
|
||||
break;
|
||||
case 37:
|
||||
cin_decode_huffman(buf, bitmap_frame_size,
|
||||
cin->bitmap_table[CIN_CUR_BMP], cin->bitmap_size);
|
||||
cin->bitmap_table[CIN_CUR_BMP], cin->bitmap_size);
|
||||
break;
|
||||
case 38:
|
||||
res = cin_decode_lzss(buf, bitmap_frame_size,
|
||||
@@ -277,24 +292,26 @@ static int cinvideo_decode_frame(AVCodecContext *avctx,
|
||||
if (res < 0)
|
||||
return res;
|
||||
cin_apply_delta_data(cin->bitmap_table[CIN_PRE_BMP],
|
||||
cin->bitmap_table[CIN_CUR_BMP], cin->bitmap_size);
|
||||
cin->bitmap_table[CIN_CUR_BMP], cin->bitmap_size);
|
||||
break;
|
||||
}
|
||||
|
||||
cin->frame.buffer_hints = FF_BUFFER_HINTS_VALID | FF_BUFFER_HINTS_PRESERVE | FF_BUFFER_HINTS_REUSABLE;
|
||||
if (avctx->reget_buffer(avctx, &cin->frame)) {
|
||||
av_log(cin->avctx, AV_LOG_ERROR, "delphinecinvideo: reget_buffer() failed to allocate a frame\n");
|
||||
return -1;
|
||||
if ((res = avctx->reget_buffer(avctx, &cin->frame)) < 0) {
|
||||
av_log(cin->avctx, AV_LOG_ERROR,
|
||||
"delphinecinvideo: reget_buffer() failed to allocate a frame\n");
|
||||
return res;
|
||||
}
|
||||
|
||||
memcpy(cin->frame.data[1], cin->palette, sizeof(cin->palette));
|
||||
cin->frame.palette_has_changed = 1;
|
||||
for (y = 0; y < cin->avctx->height; ++y)
|
||||
memcpy(cin->frame.data[0] + (cin->avctx->height - 1 - y) * cin->frame.linesize[0],
|
||||
cin->bitmap_table[CIN_CUR_BMP] + y * cin->avctx->width,
|
||||
cin->avctx->width);
|
||||
cin->bitmap_table[CIN_CUR_BMP] + y * cin->avctx->width,
|
||||
cin->avctx->width);
|
||||
|
||||
FFSWAP(uint8_t *, cin->bitmap_table[CIN_CUR_BMP], cin->bitmap_table[CIN_PRE_BMP]);
|
||||
FFSWAP(uint8_t *, cin->bitmap_table[CIN_CUR_BMP],
|
||||
cin->bitmap_table[CIN_PRE_BMP]);
|
||||
|
||||
*data_size = sizeof(AVFrame);
|
||||
*(AVFrame *)data = cin->frame;
|
||||
@@ -338,8 +355,8 @@ static av_cold int cinaudio_decode_init(AVCodecContext *avctx)
|
||||
static int cinaudio_decode_frame(AVCodecContext *avctx, void *data,
|
||||
int *got_frame_ptr, AVPacket *avpkt)
|
||||
{
|
||||
const uint8_t *buf = avpkt->data;
|
||||
CinAudioContext *cin = avctx->priv_data;
|
||||
const uint8_t *buf = avpkt->data;
|
||||
CinAudioContext *cin = avctx->priv_data;
|
||||
const uint8_t *buf_end = buf + avpkt->size;
|
||||
int16_t *samples;
|
||||
int delta, ret;
|
||||
@@ -355,13 +372,13 @@ static int cinaudio_decode_frame(AVCodecContext *avctx, void *data,
|
||||
delta = cin->delta;
|
||||
if (cin->initial_decode_frame) {
|
||||
cin->initial_decode_frame = 0;
|
||||
delta = sign_extend(AV_RL16(buf), 16);
|
||||
buf += 2;
|
||||
*samples++ = delta;
|
||||
delta = sign_extend(AV_RL16(buf), 16);
|
||||
buf += 2;
|
||||
*samples++ = delta;
|
||||
}
|
||||
while (buf < buf_end) {
|
||||
delta += cinaudio_delta16_table[*buf++];
|
||||
delta = av_clip_int16(delta);
|
||||
delta += cinaudio_delta16_table[*buf++];
|
||||
delta = av_clip_int16(delta);
|
||||
*samples++ = delta;
|
||||
}
|
||||
cin->delta = delta;
|
||||
|
||||
@@ -1912,7 +1912,7 @@ void ff_set_cmp(DSPContext* c, me_cmp_func *cmp, int type){
|
||||
|
||||
static void add_bytes_c(uint8_t *dst, uint8_t *src, int w){
|
||||
long i;
|
||||
for(i=0; i<=w-sizeof(long); i+=sizeof(long)){
|
||||
for(i=0; i<=w-(int)sizeof(long); i+=sizeof(long)){
|
||||
long a = *(long*)(src+i);
|
||||
long b = *(long*)(dst+i);
|
||||
*(long*)(dst+i) = ((a&pb_7f) + (b&pb_7f)) ^ ((a^b)&pb_80);
|
||||
@@ -1937,7 +1937,7 @@ static void diff_bytes_c(uint8_t *dst, uint8_t *src1, uint8_t *src2, int w){
|
||||
}
|
||||
}else
|
||||
#endif
|
||||
for(i=0; i<=w-sizeof(long); i+=sizeof(long)){
|
||||
for(i=0; i<=w-(int)sizeof(long); i+=sizeof(long)){
|
||||
long a = *(long*)(src1+i);
|
||||
long b = *(long*)(src2+i);
|
||||
*(long*)(dst+i) = ((a|pb_80) - (b&pb_7f)) ^ ((a^b^pb_80)&pb_80);
|
||||
|
||||
@@ -33,6 +33,7 @@
|
||||
#include "libavutil/intreadwrite.h"
|
||||
#include "avcodec.h"
|
||||
|
||||
typedef int emuedge_linesize_type;
|
||||
|
||||
//#define DEBUG
|
||||
/* dct code */
|
||||
|
||||
@@ -255,6 +255,12 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, AVPac
|
||||
case 5:
|
||||
c->pic.key_frame = !(compr & 1);
|
||||
c->pic.pict_type = (compr & 1) ? AV_PICTURE_TYPE_P : AV_PICTURE_TYPE_I;
|
||||
|
||||
if (!tmpptr && !c->pic.key_frame) {
|
||||
av_log(avctx, AV_LOG_ERROR, "Missing reference frame.\n");
|
||||
return AVERROR_INVALIDDATA;
|
||||
}
|
||||
|
||||
for(j = 0; j < avctx->height; j++){
|
||||
if(compr & 1){
|
||||
for(i = 0; i < avctx->width; i++)
|
||||
|
||||
+1
-1
@@ -451,7 +451,7 @@ static av_always_inline int encode_line(FFV1Context *s, int w,
|
||||
int run_mode=0;
|
||||
|
||||
if(s->ac){
|
||||
if(c->bytestream_end - c->bytestream < w*20){
|
||||
if(c->bytestream_end - c->bytestream < w*35){
|
||||
av_log(s->avctx, AV_LOG_ERROR, "encoded frame too large\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -388,6 +388,10 @@ static int flashsv_decode_frame(AVCodecContext *avctx, void *data,
|
||||
}
|
||||
s->diff_start = get_bits(&gb, 8);
|
||||
s->diff_height = get_bits(&gb, 8);
|
||||
if (s->diff_start + s->diff_height > cur_blk_height) {
|
||||
av_log(avctx, AV_LOG_ERROR, "Block parameters invalid\n");
|
||||
return AVERROR_INVALIDDATA;
|
||||
}
|
||||
av_log(avctx, AV_LOG_DEBUG,
|
||||
"%dx%d diff start %d height %d\n",
|
||||
i, j, s->diff_start, s->diff_height);
|
||||
|
||||
@@ -287,7 +287,8 @@ static int h261_decode_mb(H261Context *h){
|
||||
// Read mtype
|
||||
h->mtype = get_vlc2(&s->gb, h261_mtype_vlc.table, H261_MTYPE_VLC_BITS, 2);
|
||||
if (h->mtype < 0) {
|
||||
av_log(s->avctx, AV_LOG_ERROR, "illegal mtype %d\n", h->mtype);
|
||||
av_log(s->avctx, AV_LOG_ERROR, "Invalid mtype index %d\n",
|
||||
h->mtype);
|
||||
return SLICE_ERROR;
|
||||
}
|
||||
h->mtype = h261_mtype_map[h->mtype];
|
||||
|
||||
@@ -516,7 +516,7 @@ int ff_h264_execute_ref_pic_marking(H264Context *h, MMCO *mmco, int mmco_count){
|
||||
if(!pic){
|
||||
if(mmco[i].opcode != MMCO_SHORT2LONG || !h->long_ref[mmco[i].long_arg]
|
||||
|| h->long_ref[mmco[i].long_arg]->frame_num != frame_num) {
|
||||
av_log(h->s.avctx, AV_LOG_ERROR, "mmco: unref short failure\n");
|
||||
av_log(h->s.avctx, h->short_ref_count ? AV_LOG_ERROR : AV_LOG_DEBUG, "mmco: unref short failure\n");
|
||||
err = AVERROR_INVALIDDATA;
|
||||
}
|
||||
continue;
|
||||
@@ -653,7 +653,7 @@ int ff_h264_execute_ref_pic_marking(H264Context *h, MMCO *mmco, int mmco_count){
|
||||
print_short_term(h);
|
||||
print_long_term(h);
|
||||
|
||||
if(err >= 0 && h->long_ref_count==0 && h->short_ref_count<=2 && h->pps.ref_count[0]<=1 + (s->picture_structure != PICT_FRAME) && s->current_picture_ptr->f.pict_type == AV_PICTURE_TYPE_I){
|
||||
if(err >= 0 && h->long_ref_count==0 && h->short_ref_count<=2 && h->pps.ref_count[0]<=2 + (s->picture_structure != PICT_FRAME) && s->current_picture_ptr->f.pict_type == AV_PICTURE_TYPE_I){
|
||||
s->current_picture_ptr->sync |= 1;
|
||||
if(!h->s.avctx->has_b_frames)
|
||||
h->sync = 2;
|
||||
|
||||
+1
-1
@@ -514,7 +514,7 @@ static int decode_frame_ilbm(AVCodecContext *avctx,
|
||||
}
|
||||
} else if (avctx->codec_tag == MKTAG('I','L','B','M')) { // interleaved
|
||||
if (avctx->pix_fmt == PIX_FMT_PAL8 || avctx->pix_fmt == PIX_FMT_GRAY8) {
|
||||
for(y = 0; y < avctx->height; y++ ) {
|
||||
for (y = 0; y < avctx->height && buf < buf_end; y++ ) {
|
||||
uint8_t *row = &s->frame.data[0][ y*s->frame.linesize[0] ];
|
||||
memset(row, 0, avctx->width);
|
||||
for (plane = 0; plane < s->bpp && buf < buf_end; plane++) {
|
||||
|
||||
@@ -365,6 +365,10 @@ static int bit_allocation (IMCContext* q, int stream_format_code, int freebits,
|
||||
iacc += q->bandWidthT[i];
|
||||
summa += q->bandWidthT[i] * q->flcoeffs4[i];
|
||||
}
|
||||
|
||||
if (!iacc)
|
||||
return AVERROR_INVALIDDATA;
|
||||
|
||||
q->bandWidthT[BANDS-1] = 0;
|
||||
summa = (summa * 0.5 - freebits) / iacc;
|
||||
|
||||
|
||||
+33
-10
@@ -211,6 +211,7 @@ static int decode_pic_hdr(IVI45DecContext *ctx, AVCodecContext *avctx)
|
||||
if (ivi_pic_config_cmp(&pic_conf, &ctx->pic_conf)) {
|
||||
if (ff_ivi_init_planes(ctx->planes, &pic_conf)) {
|
||||
av_log(avctx, AV_LOG_ERROR, "Couldn't reallocate color planes!\n");
|
||||
ctx->pic_conf.luma_bands = 0;
|
||||
return AVERROR(ENOMEM);
|
||||
}
|
||||
|
||||
@@ -348,12 +349,25 @@ static int decode_band_hdr(IVI45DecContext *ctx, IVIBandDesc *band,
|
||||
band->inv_transform = transforms[transform_id].inv_trans;
|
||||
band->dc_transform = transforms[transform_id].dc_trans;
|
||||
band->is_2d_trans = transforms[transform_id].is_2d_trans;
|
||||
if (transform_id < 10)
|
||||
band->transform_size = 8;
|
||||
else
|
||||
band->transform_size = 4;
|
||||
|
||||
if (band->blk_size != band->transform_size)
|
||||
return AVERROR_INVALIDDATA;
|
||||
|
||||
scan_indx = get_bits(&ctx->gb, 4);
|
||||
if (scan_indx == 15) {
|
||||
av_log(avctx, AV_LOG_ERROR, "Custom scan pattern encountered!\n");
|
||||
return AVERROR_INVALIDDATA;
|
||||
}
|
||||
if (scan_indx > 4 && scan_indx < 10) {
|
||||
if (band->blk_size != 4)
|
||||
return AVERROR_INVALIDDATA;
|
||||
} else if (band->blk_size != 8)
|
||||
return AVERROR_INVALIDDATA;
|
||||
|
||||
band->scan = scan_index_to_tab[scan_indx];
|
||||
|
||||
band->quant_mat = get_bits(&ctx->gb, 5);
|
||||
@@ -361,6 +375,11 @@ static int decode_band_hdr(IVI45DecContext *ctx, IVIBandDesc *band,
|
||||
av_log(avctx, AV_LOG_ERROR, "Custom quant matrix encountered!\n");
|
||||
return AVERROR_INVALIDDATA;
|
||||
}
|
||||
if (band->quant_mat >= FF_ARRAY_ELEMS(quant_index_to_tab)) {
|
||||
av_log_ask_for_sample(avctx, "Quantization matrix %d",
|
||||
band->quant_mat);
|
||||
return AVERROR_INVALIDDATA;
|
||||
}
|
||||
}
|
||||
|
||||
/* decode block huffman codebook */
|
||||
@@ -463,7 +482,7 @@ static int decode_mb_info(IVI45DecContext *ctx, IVIBandDesc *band,
|
||||
}
|
||||
|
||||
mb->mv_x = mb->mv_y = 0; /* no motion vector coded */
|
||||
if (band->inherit_mv) {
|
||||
if (band->inherit_mv && ref_mb) {
|
||||
/* motion vector inheritance */
|
||||
if (mv_scale) {
|
||||
mb->mv_x = ivi_scale_mv(ref_mb->mv_x, mv_scale);
|
||||
@@ -475,7 +494,10 @@ static int decode_mb_info(IVI45DecContext *ctx, IVIBandDesc *band,
|
||||
}
|
||||
} else {
|
||||
if (band->inherit_mv) {
|
||||
mb->type = ref_mb->type; /* copy mb_type from corresponding reference mb */
|
||||
/* copy mb_type from corresponding reference mb */
|
||||
if (!ref_mb)
|
||||
return AVERROR_INVALIDDATA;
|
||||
mb->type = ref_mb->type;
|
||||
} else if (ctx->frame_type == FRAMETYPE_INTRA) {
|
||||
mb->type = 0; /* mb_type is always INTRA for intra-frames */
|
||||
} else {
|
||||
@@ -498,14 +520,15 @@ static int decode_mb_info(IVI45DecContext *ctx, IVIBandDesc *band,
|
||||
mb->mv_x = mb->mv_y = 0; /* there is no motion vector in intra-macroblocks */
|
||||
} else {
|
||||
if (band->inherit_mv) {
|
||||
/* motion vector inheritance */
|
||||
if (mv_scale) {
|
||||
mb->mv_x = ivi_scale_mv(ref_mb->mv_x, mv_scale);
|
||||
mb->mv_y = ivi_scale_mv(ref_mb->mv_y, mv_scale);
|
||||
} else {
|
||||
mb->mv_x = ref_mb->mv_x;
|
||||
mb->mv_y = ref_mb->mv_y;
|
||||
}
|
||||
if (ref_mb)
|
||||
/* motion vector inheritance */
|
||||
if (mv_scale) {
|
||||
mb->mv_x = ivi_scale_mv(ref_mb->mv_x, mv_scale);
|
||||
mb->mv_y = ivi_scale_mv(ref_mb->mv_y, mv_scale);
|
||||
} else {
|
||||
mb->mv_x = ref_mb->mv_x;
|
||||
mb->mv_y = ref_mb->mv_y;
|
||||
}
|
||||
} else {
|
||||
/* decode motion vector deltas */
|
||||
mv_delta = get_vlc2(&ctx->gb, ctx->mb_vlc.tab->table,
|
||||
|
||||
+55
-41
@@ -74,7 +74,7 @@ static int decode_gop_header(IVI45DecContext *ctx, AVCodecContext *avctx)
|
||||
tile_size = (ctx->gop_flags & 0x40) ? 64 << get_bits(&ctx->gb, 2) : 0;
|
||||
if (tile_size > 256) {
|
||||
av_log(avctx, AV_LOG_ERROR, "Invalid tile size: %d\n", tile_size);
|
||||
return -1;
|
||||
return AVERROR_INVALIDDATA;
|
||||
}
|
||||
|
||||
/* decode number of wavelet bands */
|
||||
@@ -85,7 +85,7 @@ static int decode_gop_header(IVI45DecContext *ctx, AVCodecContext *avctx)
|
||||
if (is_scalable && (pic_conf.luma_bands != 4 || pic_conf.chroma_bands != 1)) {
|
||||
av_log(avctx, AV_LOG_ERROR, "Scalability: unsupported subdivision! Luma bands: %d, chroma bands: %d\n",
|
||||
pic_conf.luma_bands, pic_conf.chroma_bands);
|
||||
return -1;
|
||||
return AVERROR_INVALIDDATA;
|
||||
}
|
||||
|
||||
pic_size_indx = get_bits(&ctx->gb, 4);
|
||||
@@ -98,8 +98,8 @@ static int decode_gop_header(IVI45DecContext *ctx, AVCodecContext *avctx)
|
||||
}
|
||||
|
||||
if (ctx->gop_flags & 2) {
|
||||
av_log(avctx, AV_LOG_ERROR, "YV12 picture format not supported!\n");
|
||||
return -1;
|
||||
av_log_missing_feature(avctx, "YV12 picture format", 0);
|
||||
return AVERROR_PATCHWELCOME;
|
||||
}
|
||||
|
||||
pic_conf.chroma_height = (pic_conf.pic_height + 3) >> 2;
|
||||
@@ -113,11 +113,11 @@ static int decode_gop_header(IVI45DecContext *ctx, AVCodecContext *avctx)
|
||||
}
|
||||
|
||||
/* check if picture layout was changed and reallocate buffers */
|
||||
if (ivi_pic_config_cmp(&pic_conf, &ctx->pic_conf)) {
|
||||
if (ivi_pic_config_cmp(&pic_conf, &ctx->pic_conf) || ctx->gop_invalid) {
|
||||
result = ff_ivi_init_planes(ctx->planes, &pic_conf);
|
||||
if (result) {
|
||||
if (result < 0) {
|
||||
av_log(avctx, AV_LOG_ERROR, "Couldn't reallocate color planes!\n");
|
||||
return -1;
|
||||
return result;
|
||||
}
|
||||
ctx->pic_conf = pic_conf;
|
||||
ctx->is_scalable = is_scalable;
|
||||
@@ -141,46 +141,54 @@ static int decode_gop_header(IVI45DecContext *ctx, AVCodecContext *avctx)
|
||||
}
|
||||
|
||||
if (get_bits1(&ctx->gb)) {
|
||||
av_log(avctx, AV_LOG_ERROR, "Extended transform info encountered!\n");
|
||||
return -1;
|
||||
av_log_missing_feature(avctx, "Extended transform info", 0);
|
||||
return AVERROR_PATCHWELCOME;
|
||||
}
|
||||
|
||||
/* select transform function and scan pattern according to plane and band number */
|
||||
switch ((p << 2) + i) {
|
||||
case 0:
|
||||
band->inv_transform = ff_ivi_inverse_slant_8x8;
|
||||
band->dc_transform = ff_ivi_dc_slant_2d;
|
||||
band->scan = ff_zigzag_direct;
|
||||
band->inv_transform = ff_ivi_inverse_slant_8x8;
|
||||
band->dc_transform = ff_ivi_dc_slant_2d;
|
||||
band->scan = ff_zigzag_direct;
|
||||
band->transform_size = 8;
|
||||
break;
|
||||
|
||||
case 1:
|
||||
band->inv_transform = ff_ivi_row_slant8;
|
||||
band->dc_transform = ff_ivi_dc_row_slant;
|
||||
band->scan = ff_ivi_vertical_scan_8x8;
|
||||
band->inv_transform = ff_ivi_row_slant8;
|
||||
band->dc_transform = ff_ivi_dc_row_slant;
|
||||
band->scan = ff_ivi_vertical_scan_8x8;
|
||||
band->transform_size = 8;
|
||||
break;
|
||||
|
||||
case 2:
|
||||
band->inv_transform = ff_ivi_col_slant8;
|
||||
band->dc_transform = ff_ivi_dc_col_slant;
|
||||
band->scan = ff_ivi_horizontal_scan_8x8;
|
||||
band->inv_transform = ff_ivi_col_slant8;
|
||||
band->dc_transform = ff_ivi_dc_col_slant;
|
||||
band->scan = ff_ivi_horizontal_scan_8x8;
|
||||
band->transform_size = 8;
|
||||
break;
|
||||
|
||||
case 3:
|
||||
band->inv_transform = ff_ivi_put_pixels_8x8;
|
||||
band->dc_transform = ff_ivi_put_dc_pixel_8x8;
|
||||
band->scan = ff_ivi_horizontal_scan_8x8;
|
||||
band->inv_transform = ff_ivi_put_pixels_8x8;
|
||||
band->dc_transform = ff_ivi_put_dc_pixel_8x8;
|
||||
band->scan = ff_ivi_horizontal_scan_8x8;
|
||||
band->transform_size = 8;
|
||||
break;
|
||||
|
||||
case 4:
|
||||
band->inv_transform = ff_ivi_inverse_slant_4x4;
|
||||
band->dc_transform = ff_ivi_dc_slant_2d;
|
||||
band->scan = ff_ivi_direct_scan_4x4;
|
||||
band->inv_transform = ff_ivi_inverse_slant_4x4;
|
||||
band->dc_transform = ff_ivi_dc_slant_2d;
|
||||
band->scan = ff_ivi_direct_scan_4x4;
|
||||
band->transform_size = 4;
|
||||
break;
|
||||
}
|
||||
|
||||
band->is_2d_trans = band->inv_transform == ff_ivi_inverse_slant_8x8 ||
|
||||
band->inv_transform == ff_ivi_inverse_slant_4x4;
|
||||
|
||||
if (band->transform_size != band->blk_size)
|
||||
return AVERROR_INVALIDDATA;
|
||||
|
||||
/* select dequant matrix according to plane and band number */
|
||||
if (!p) {
|
||||
quant_mat = (pic_conf.luma_bands > 1) ? i+1 : 0;
|
||||
@@ -206,7 +214,7 @@ static int decode_gop_header(IVI45DecContext *ctx, AVCodecContext *avctx)
|
||||
|
||||
if (get_bits(&ctx->gb, 2)) {
|
||||
av_log(avctx, AV_LOG_ERROR, "End marker missing!\n");
|
||||
return -1;
|
||||
return AVERROR_INVALIDDATA;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -235,17 +243,17 @@ static int decode_gop_header(IVI45DecContext *ctx, AVCodecContext *avctx)
|
||||
if (blk_size_changed) {
|
||||
result = ff_ivi_init_tiles(ctx->planes, pic_conf.tile_width,
|
||||
pic_conf.tile_height);
|
||||
if (result) {
|
||||
if (result < 0) {
|
||||
av_log(avctx, AV_LOG_ERROR,
|
||||
"Couldn't reallocate internal structures!\n");
|
||||
return -1;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
if (ctx->gop_flags & 8) {
|
||||
if (get_bits(&ctx->gb, 3)) {
|
||||
av_log(avctx, AV_LOG_ERROR, "Alignment bits are not zero!\n");
|
||||
return -1;
|
||||
return AVERROR_INVALIDDATA;
|
||||
}
|
||||
|
||||
if (get_bits1(&ctx->gb))
|
||||
@@ -294,25 +302,27 @@ static inline void skip_hdr_extension(GetBitContext *gb)
|
||||
*/
|
||||
static int decode_pic_hdr(IVI45DecContext *ctx, AVCodecContext *avctx)
|
||||
{
|
||||
int ret;
|
||||
|
||||
if (get_bits(&ctx->gb, 5) != 0x1F) {
|
||||
av_log(avctx, AV_LOG_ERROR, "Invalid picture start code!\n");
|
||||
return -1;
|
||||
return AVERROR_INVALIDDATA;
|
||||
}
|
||||
|
||||
ctx->prev_frame_type = ctx->frame_type;
|
||||
ctx->frame_type = get_bits(&ctx->gb, 3);
|
||||
if (ctx->frame_type >= 5) {
|
||||
av_log(avctx, AV_LOG_ERROR, "Invalid frame type: %d \n", ctx->frame_type);
|
||||
return -1;
|
||||
return AVERROR_INVALIDDATA;
|
||||
}
|
||||
|
||||
ctx->frame_num = get_bits(&ctx->gb, 8);
|
||||
|
||||
if (ctx->frame_type == FRAMETYPE_INTRA) {
|
||||
ctx->gop_invalid = 1;
|
||||
if (decode_gop_header(ctx, avctx)) {
|
||||
if ((ret = decode_gop_header(ctx, avctx)) < 0) {
|
||||
av_log(avctx, AV_LOG_ERROR, "Invalid GOP header, skipping frames.\n");
|
||||
return AVERROR_INVALIDDATA;
|
||||
ctx->gop_invalid = 1;
|
||||
return ret;
|
||||
}
|
||||
ctx->gop_invalid = 0;
|
||||
}
|
||||
@@ -329,8 +339,10 @@ static int decode_pic_hdr(IVI45DecContext *ctx, AVCodecContext *avctx)
|
||||
skip_hdr_extension(&ctx->gb); /* XXX: untested */
|
||||
|
||||
/* decode macroblock huffman codebook */
|
||||
if (ff_ivi_dec_huff_desc(&ctx->gb, ctx->frame_flags & 0x40, IVI_MB_HUFF, &ctx->mb_vlc, avctx))
|
||||
return -1;
|
||||
ret = ff_ivi_dec_huff_desc(&ctx->gb, ctx->frame_flags & 0x40,
|
||||
IVI_MB_HUFF, &ctx->mb_vlc, avctx);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
|
||||
skip_bits(&ctx->gb, 3); /* FIXME: unknown meaning! */
|
||||
}
|
||||
@@ -352,7 +364,7 @@ static int decode_pic_hdr(IVI45DecContext *ctx, AVCodecContext *avctx)
|
||||
static int decode_band_hdr(IVI45DecContext *ctx, IVIBandDesc *band,
|
||||
AVCodecContext *avctx)
|
||||
{
|
||||
int i;
|
||||
int i, ret;
|
||||
uint8_t band_flags;
|
||||
|
||||
band_flags = get_bits(&ctx->gb, 8);
|
||||
@@ -376,7 +388,7 @@ static int decode_band_hdr(IVI45DecContext *ctx, IVIBandDesc *band,
|
||||
if (band->num_corr > 61) {
|
||||
av_log(avctx, AV_LOG_ERROR, "Too many corrections: %d\n",
|
||||
band->num_corr);
|
||||
return -1;
|
||||
return AVERROR_INVALIDDATA;
|
||||
}
|
||||
|
||||
/* read correction pairs */
|
||||
@@ -388,8 +400,10 @@ static int decode_band_hdr(IVI45DecContext *ctx, IVIBandDesc *band,
|
||||
band->rvmap_sel = (band_flags & 0x40) ? get_bits(&ctx->gb, 3) : 8;
|
||||
|
||||
/* decode block huffman codebook */
|
||||
if (ff_ivi_dec_huff_desc(&ctx->gb, band_flags & 0x80, IVI_BLK_HUFF, &band->blk_vlc, avctx))
|
||||
return -1;
|
||||
ret = ff_ivi_dec_huff_desc(&ctx->gb, band_flags & 0x80, IVI_BLK_HUFF,
|
||||
&band->blk_vlc, avctx);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
|
||||
band->checksum_present = get_bits1(&ctx->gb);
|
||||
if (band->checksum_present)
|
||||
@@ -456,7 +470,7 @@ static int decode_mb_info(IVI45DecContext *ctx, IVIBandDesc *band,
|
||||
if (get_bits1(&ctx->gb)) {
|
||||
if (ctx->frame_type == FRAMETYPE_INTRA) {
|
||||
av_log(avctx, AV_LOG_ERROR, "Empty macroblock in an INTRA picture!\n");
|
||||
return -1;
|
||||
return AVERROR_INVALIDDATA;
|
||||
}
|
||||
mb->type = 1; /* empty macroblocks are always INTER */
|
||||
mb->cbp = 0; /* all blocks are empty */
|
||||
@@ -622,7 +636,7 @@ static av_cold int decode_init(AVCodecContext *avctx)
|
||||
result = ff_ivi_init_planes(ctx->planes, &ctx->pic_conf);
|
||||
if (result) {
|
||||
av_log(avctx, AV_LOG_ERROR, "Couldn't allocate color planes!\n");
|
||||
return -1;
|
||||
return AVERROR_INVALIDDATA;
|
||||
}
|
||||
|
||||
ctx->buf_switch = 0;
|
||||
|
||||
+271
-175
@@ -42,6 +42,26 @@ VLC ff_ivi_blk_vlc_tabs[8];
|
||||
typedef void (*ivi_mc_func) (int16_t *buf, const int16_t *ref_buf,
|
||||
uint32_t pitch, int mc_type);
|
||||
|
||||
static int ivi_mc(IVIBandDesc *band, ivi_mc_func mc,
|
||||
int offs, int mv_x, int mv_y, int mc_type)
|
||||
{
|
||||
int ref_offs = offs + mv_y * band->pitch + mv_x;
|
||||
int buf_size = band->pitch * band->aheight;
|
||||
int min_size = band->pitch * (band->blk_size - 1) + band->blk_size;
|
||||
int ref_size = (mc_type > 1) * band->pitch + (mc_type & 1);
|
||||
|
||||
if (offs < 0 || ref_offs < 0 || !band->ref_buf)
|
||||
return AVERROR_INVALIDDATA;
|
||||
if (buf_size - min_size < offs)
|
||||
return AVERROR_INVALIDDATA;
|
||||
if (buf_size - min_size - ref_size < ref_offs)
|
||||
return AVERROR_INVALIDDATA;
|
||||
|
||||
mc(band->buf + offs, band->ref_buf + ref_offs, band->pitch, mc_type);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse "nbits" bits of the value "val" and return the result
|
||||
* in the least significant bits.
|
||||
@@ -51,9 +71,10 @@ static uint16_t inv_bits(uint16_t val, int nbits)
|
||||
uint16_t res;
|
||||
|
||||
if (nbits <= 8) {
|
||||
res = av_reverse[val] >> (8-nbits);
|
||||
res = av_reverse[val] >> (8 - nbits);
|
||||
} else
|
||||
res = ((av_reverse[val & 0xFF] << 8) + (av_reverse[val >> 8])) >> (16-nbits);
|
||||
res = ((av_reverse[val & 0xFF] << 8) +
|
||||
(av_reverse[val >> 8])) >> (16 - nbits);
|
||||
|
||||
return res;
|
||||
}
|
||||
@@ -103,10 +124,12 @@ void ff_ivi_init_static_vlc(void)
|
||||
for (i = 0; i < 8; i++) {
|
||||
ff_ivi_mb_vlc_tabs[i].table = table_data + i * 2 * 8192;
|
||||
ff_ivi_mb_vlc_tabs[i].table_allocated = 8192;
|
||||
ff_ivi_create_huff_from_desc(&ff_ivi_mb_huff_desc[i], &ff_ivi_mb_vlc_tabs[i], 1);
|
||||
ff_ivi_create_huff_from_desc(&ff_ivi_mb_huff_desc[i],
|
||||
&ff_ivi_mb_vlc_tabs[i], 1);
|
||||
ff_ivi_blk_vlc_tabs[i].table = table_data + (i * 2 + 1) * 8192;
|
||||
ff_ivi_blk_vlc_tabs[i].table_allocated = 8192;
|
||||
ff_ivi_create_huff_from_desc(&ff_ivi_blk_huff_desc[i], &ff_ivi_blk_vlc_tabs[i], 1);
|
||||
ff_ivi_create_huff_from_desc(&ff_ivi_blk_huff_desc[i],
|
||||
&ff_ivi_blk_vlc_tabs[i], 1);
|
||||
}
|
||||
initialized_vlcs = 1;
|
||||
}
|
||||
@@ -114,47 +137,48 @@ void ff_ivi_init_static_vlc(void)
|
||||
int ff_ivi_dec_huff_desc(GetBitContext *gb, int desc_coded, int which_tab,
|
||||
IVIHuffTab *huff_tab, AVCodecContext *avctx)
|
||||
{
|
||||
int i, result;
|
||||
int i, result;
|
||||
IVIHuffDesc new_huff;
|
||||
|
||||
if (!desc_coded) {
|
||||
/* select default table */
|
||||
huff_tab->tab = (which_tab) ? &ff_ivi_blk_vlc_tabs[7]
|
||||
: &ff_ivi_mb_vlc_tabs [7];
|
||||
} else {
|
||||
huff_tab->tab_sel = get_bits(gb, 3);
|
||||
if (huff_tab->tab_sel == 7) {
|
||||
/* custom huffman table (explicitly encoded) */
|
||||
new_huff.num_rows = get_bits(gb, 4);
|
||||
if (!new_huff.num_rows) {
|
||||
av_log(avctx, AV_LOG_ERROR, "Empty custom Huffman table!\n");
|
||||
return AVERROR_INVALIDDATA;
|
||||
}
|
||||
: &ff_ivi_mb_vlc_tabs [7];
|
||||
return 0;
|
||||
}
|
||||
|
||||
for (i = 0; i < new_huff.num_rows; i++)
|
||||
new_huff.xbits[i] = get_bits(gb, 4);
|
||||
|
||||
/* Have we got the same custom table? Rebuild if not. */
|
||||
if (ff_ivi_huff_desc_cmp(&new_huff, &huff_tab->cust_desc)) {
|
||||
ff_ivi_huff_desc_copy(&huff_tab->cust_desc, &new_huff);
|
||||
|
||||
if (huff_tab->cust_tab.table)
|
||||
ff_free_vlc(&huff_tab->cust_tab);
|
||||
result = ff_ivi_create_huff_from_desc(&huff_tab->cust_desc,
|
||||
&huff_tab->cust_tab, 0);
|
||||
if (result) {
|
||||
huff_tab->cust_desc.num_rows = 0; // reset faulty description
|
||||
av_log(avctx, AV_LOG_ERROR,
|
||||
"Error while initializing custom vlc table!\n");
|
||||
return result;
|
||||
}
|
||||
}
|
||||
huff_tab->tab = &huff_tab->cust_tab;
|
||||
} else {
|
||||
/* select one of predefined tables */
|
||||
huff_tab->tab = (which_tab) ? &ff_ivi_blk_vlc_tabs[huff_tab->tab_sel]
|
||||
: &ff_ivi_mb_vlc_tabs [huff_tab->tab_sel];
|
||||
huff_tab->tab_sel = get_bits(gb, 3);
|
||||
if (huff_tab->tab_sel == 7) {
|
||||
/* custom huffman table (explicitly encoded) */
|
||||
new_huff.num_rows = get_bits(gb, 4);
|
||||
if (!new_huff.num_rows) {
|
||||
av_log(avctx, AV_LOG_ERROR, "Empty custom Huffman table!\n");
|
||||
return AVERROR_INVALIDDATA;
|
||||
}
|
||||
|
||||
for (i = 0; i < new_huff.num_rows; i++)
|
||||
new_huff.xbits[i] = get_bits(gb, 4);
|
||||
|
||||
/* Have we got the same custom table? Rebuild if not. */
|
||||
if (ff_ivi_huff_desc_cmp(&new_huff, &huff_tab->cust_desc)) {
|
||||
ff_ivi_huff_desc_copy(&huff_tab->cust_desc, &new_huff);
|
||||
|
||||
if (huff_tab->cust_tab.table)
|
||||
ff_free_vlc(&huff_tab->cust_tab);
|
||||
result = ff_ivi_create_huff_from_desc(&huff_tab->cust_desc,
|
||||
&huff_tab->cust_tab, 0);
|
||||
if (result) {
|
||||
huff_tab->cust_desc.num_rows = 0; // reset faulty description
|
||||
av_log(avctx, AV_LOG_ERROR,
|
||||
"Error while initializing custom vlc table!\n");
|
||||
return result;
|
||||
}
|
||||
}
|
||||
huff_tab->tab = &huff_tab->cust_tab;
|
||||
} else {
|
||||
/* select one of predefined tables */
|
||||
huff_tab->tab = (which_tab) ? &ff_ivi_blk_vlc_tabs[huff_tab->tab_sel]
|
||||
: &ff_ivi_mb_vlc_tabs [huff_tab->tab_sel];
|
||||
}
|
||||
|
||||
return 0;
|
||||
@@ -174,12 +198,17 @@ void ff_ivi_huff_desc_copy(IVIHuffDesc *dst, const IVIHuffDesc *src)
|
||||
|
||||
int av_cold ff_ivi_init_planes(IVIPlaneDesc *planes, const IVIPicConfig *cfg)
|
||||
{
|
||||
int p, b;
|
||||
uint32_t b_width, b_height, align_fac, width_aligned, height_aligned, buf_size;
|
||||
int p, b;
|
||||
uint32_t b_width, b_height, align_fac, width_aligned,
|
||||
height_aligned, buf_size;
|
||||
IVIBandDesc *band;
|
||||
|
||||
ff_ivi_free_buffers(planes);
|
||||
|
||||
if (cfg->pic_width < 1 || cfg->pic_height < 1 ||
|
||||
cfg->luma_bands < 1 || cfg->chroma_bands < 1)
|
||||
return AVERROR_INVALIDDATA;
|
||||
|
||||
/* fill in the descriptor of the luminance plane */
|
||||
planes[0].width = cfg->pic_width;
|
||||
planes[0].height = cfg->pic_height;
|
||||
@@ -198,8 +227,10 @@ int av_cold ff_ivi_init_planes(IVIPlaneDesc *planes, const IVIPicConfig *cfg)
|
||||
/* select band dimensions: if there is only one band then it
|
||||
* has the full size, if there are several bands each of them
|
||||
* has only half size */
|
||||
b_width = planes[p].num_bands == 1 ? planes[p].width : (planes[p].width + 1) >> 1;
|
||||
b_height = planes[p].num_bands == 1 ? planes[p].height : (planes[p].height + 1) >> 1;
|
||||
b_width = planes[p].num_bands == 1 ? planes[p].width
|
||||
: (planes[p].width + 1) >> 1;
|
||||
b_height = planes[p].num_bands == 1 ? planes[p].height
|
||||
: (planes[p].height + 1) >> 1;
|
||||
|
||||
/* luma band buffers will be aligned on 16x16 (max macroblock size) */
|
||||
/* chroma band buffers will be aligned on 8x8 (max macroblock size) */
|
||||
@@ -227,8 +258,8 @@ int av_cold ff_ivi_init_planes(IVIPlaneDesc *planes, const IVIPicConfig *cfg)
|
||||
if (!band->bufs[2])
|
||||
return AVERROR(ENOMEM);
|
||||
}
|
||||
|
||||
planes[p].bands[0].blk_vlc.cust_desc.num_rows = 0; /* reset custom vlc */
|
||||
/* reset custom vlc */
|
||||
planes[p].bands[0].blk_vlc.cust_desc.num_rows = 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -252,14 +283,51 @@ void av_cold ff_ivi_free_buffers(IVIPlaneDesc *planes)
|
||||
av_freep(&planes[p].bands[b].tiles);
|
||||
}
|
||||
av_freep(&planes[p].bands);
|
||||
planes[p].num_bands = 0;
|
||||
}
|
||||
}
|
||||
|
||||
static int ivi_init_tiles(IVIBandDesc *band, IVITile *ref_tile,
|
||||
int p, int b, int t_height, int t_width)
|
||||
{
|
||||
int x, y;
|
||||
IVITile *tile = band->tiles;
|
||||
|
||||
for (y = 0; y < band->height; y += t_height) {
|
||||
for (x = 0; x < band->width; x += t_width) {
|
||||
tile->xpos = x;
|
||||
tile->ypos = y;
|
||||
tile->mb_size = band->mb_size;
|
||||
tile->width = FFMIN(band->width - x, t_width);
|
||||
tile->height = FFMIN(band->height - y, t_height);
|
||||
tile->is_empty = tile->data_size = 0;
|
||||
/* calculate number of macroblocks */
|
||||
tile->num_MBs = IVI_MBs_PER_TILE(tile->width, tile->height,
|
||||
band->mb_size);
|
||||
|
||||
av_freep(&tile->mbs);
|
||||
tile->mbs = av_malloc(tile->num_MBs * sizeof(IVIMbInfo));
|
||||
if (!tile->mbs)
|
||||
return AVERROR(ENOMEM);
|
||||
|
||||
tile->ref_mbs = 0;
|
||||
if (p || b) {
|
||||
if (tile->num_MBs != ref_tile->num_MBs)
|
||||
return AVERROR_INVALIDDATA;
|
||||
tile->ref_mbs = ref_tile->mbs;
|
||||
ref_tile++;
|
||||
}
|
||||
tile++;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int av_cold ff_ivi_init_tiles(IVIPlaneDesc *planes, int tile_width, int tile_height)
|
||||
{
|
||||
int p, b, x, y, x_tiles, y_tiles, t_width, t_height;
|
||||
int p, b, x_tiles, y_tiles, t_width, t_height, ret;
|
||||
IVIBandDesc *band;
|
||||
IVITile *tile, *ref_tile;
|
||||
|
||||
for (p = 0; p < 3; p++) {
|
||||
t_width = !p ? tile_width : (tile_width + 3) >> 2;
|
||||
@@ -283,41 +351,14 @@ int av_cold ff_ivi_init_tiles(IVIPlaneDesc *planes, int tile_width, int tile_hei
|
||||
if (!band->tiles)
|
||||
return AVERROR(ENOMEM);
|
||||
|
||||
tile = band->tiles;
|
||||
|
||||
/* use the first luma band as reference for motion vectors
|
||||
* and quant */
|
||||
ref_tile = planes[0].bands[0].tiles;
|
||||
|
||||
for (y = 0; y < band->height; y += t_height) {
|
||||
for (x = 0; x < band->width; x += t_width) {
|
||||
tile->xpos = x;
|
||||
tile->ypos = y;
|
||||
tile->mb_size = band->mb_size;
|
||||
tile->width = FFMIN(band->width - x, t_width);
|
||||
tile->height = FFMIN(band->height - y, t_height);
|
||||
tile->is_empty = tile->data_size = 0;
|
||||
/* calculate number of macroblocks */
|
||||
tile->num_MBs = IVI_MBs_PER_TILE(tile->width, tile->height,
|
||||
band->mb_size);
|
||||
|
||||
av_freep(&tile->mbs);
|
||||
tile->mbs = av_malloc(tile->num_MBs * sizeof(IVIMbInfo));
|
||||
if (!tile->mbs)
|
||||
return AVERROR(ENOMEM);
|
||||
|
||||
tile->ref_mbs = 0;
|
||||
if (p || b) {
|
||||
tile->ref_mbs = ref_tile->mbs;
|
||||
ref_tile++;
|
||||
}
|
||||
|
||||
tile++;
|
||||
}
|
||||
}
|
||||
|
||||
}// for b
|
||||
}// for p
|
||||
ret = ivi_init_tiles(band, planes[0].bands[0].tiles,
|
||||
p, b, t_height, t_width);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -339,25 +380,125 @@ int ff_ivi_dec_tile_data_size(GetBitContext *gb)
|
||||
return len;
|
||||
}
|
||||
|
||||
static int ivi_dc_transform(IVIBandDesc *band, int *prev_dc, int buf_offs,
|
||||
int blk_size)
|
||||
{
|
||||
int buf_size = band->pitch * band->aheight - buf_offs;
|
||||
int min_size = (blk_size - 1) * band->pitch + blk_size;
|
||||
|
||||
if (!band->dc_transform)
|
||||
return 0;
|
||||
|
||||
|
||||
if (min_size > buf_size)
|
||||
return AVERROR_INVALIDDATA;
|
||||
|
||||
band->dc_transform(prev_dc, band->buf + buf_offs,
|
||||
band->pitch, blk_size);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int ivi_decode_coded_blocks(GetBitContext *gb, IVIBandDesc *band,
|
||||
ivi_mc_func mc, int mv_x, int mv_y,
|
||||
int *prev_dc, int is_intra, int mc_type,
|
||||
uint32_t quant, int offs)
|
||||
{
|
||||
const uint16_t *base_tab = is_intra ? band->intra_base : band->inter_base;
|
||||
RVMapDesc *rvmap = band->rv_map;
|
||||
uint8_t col_flags[8];
|
||||
int32_t trvec[64];
|
||||
uint32_t sym = 0, lo, hi, q;
|
||||
int pos, run, val;
|
||||
int blk_size = band->blk_size;
|
||||
int num_coeffs = blk_size * blk_size;
|
||||
int col_mask = blk_size - 1;
|
||||
int scan_pos = -1;
|
||||
int min_size = band->pitch * (band->transform_size - 1) +
|
||||
band->transform_size;
|
||||
int buf_size = band->pitch * band->aheight - offs;
|
||||
|
||||
if (min_size > buf_size)
|
||||
return AVERROR_INVALIDDATA;
|
||||
|
||||
if (!band->scan)
|
||||
return AVERROR_INVALIDDATA;
|
||||
|
||||
/* zero transform vector */
|
||||
memset(trvec, 0, num_coeffs * sizeof(trvec[0]));
|
||||
/* zero column flags */
|
||||
memset(col_flags, 0, sizeof(col_flags));
|
||||
while (scan_pos <= num_coeffs) {
|
||||
sym = get_vlc2(gb, band->blk_vlc.tab->table,
|
||||
IVI_VLC_BITS, 1);
|
||||
if (sym == rvmap->eob_sym)
|
||||
break; /* End of block */
|
||||
|
||||
/* Escape - run/val explicitly coded using 3 vlc codes */
|
||||
if (sym == rvmap->esc_sym) {
|
||||
run = get_vlc2(gb, band->blk_vlc.tab->table, IVI_VLC_BITS, 1) + 1;
|
||||
lo = get_vlc2(gb, band->blk_vlc.tab->table, IVI_VLC_BITS, 1);
|
||||
hi = get_vlc2(gb, band->blk_vlc.tab->table, IVI_VLC_BITS, 1);
|
||||
/* merge them and convert into signed val */
|
||||
val = IVI_TOSIGNED((hi << 6) | lo);
|
||||
} else {
|
||||
if (sym >= 256U)
|
||||
return AVERROR_INVALIDDATA;
|
||||
|
||||
run = rvmap->runtab[sym];
|
||||
val = rvmap->valtab[sym];
|
||||
}
|
||||
|
||||
/* de-zigzag and dequantize */
|
||||
scan_pos += run;
|
||||
if (scan_pos >= num_coeffs || scan_pos < 0)
|
||||
break;
|
||||
pos = band->scan[scan_pos];
|
||||
|
||||
q = (base_tab[pos] * quant) >> 9;
|
||||
if (q > 1)
|
||||
val = val * q + FFSIGN(val) * (((q ^ 1) - 1) >> 1);
|
||||
trvec[pos] = val;
|
||||
/* track columns containing non-zero coeffs */
|
||||
col_flags[pos & col_mask] |= !!val;
|
||||
}
|
||||
|
||||
if (scan_pos < 0 || scan_pos >= num_coeffs && sym != rvmap->eob_sym)
|
||||
return AVERROR_INVALIDDATA; /* corrupt block data */
|
||||
|
||||
/* undoing DC coeff prediction for intra-blocks */
|
||||
if (is_intra && band->is_2d_trans) {
|
||||
*prev_dc += trvec[0];
|
||||
trvec[0] = *prev_dc;
|
||||
col_flags[0] |= !!*prev_dc;
|
||||
}
|
||||
|
||||
/* apply inverse transform */
|
||||
band->inv_transform(trvec, band->buf + offs,
|
||||
band->pitch, col_flags);
|
||||
|
||||
/* apply motion compensation */
|
||||
if (!is_intra)
|
||||
return ivi_mc(band, mc, offs, mv_x, mv_y, mc_type);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ff_ivi_decode_blocks(GetBitContext *gb, IVIBandDesc *band, IVITile *tile)
|
||||
{
|
||||
int mbn, blk, num_blocks, num_coeffs, blk_size, scan_pos, run, val,
|
||||
pos, is_intra, mc_type, mv_x, mv_y, col_mask;
|
||||
uint8_t col_flags[8];
|
||||
int32_t prev_dc, trvec[64];
|
||||
uint32_t cbp, sym, lo, hi, quant, buf_offs, q;
|
||||
IVIMbInfo *mb;
|
||||
RVMapDesc *rvmap = band->rv_map;
|
||||
int mbn, blk, num_blocks, blk_size, ret, is_intra, mc_type = 0;
|
||||
int mv_x = 0, mv_y = 0;
|
||||
int32_t prev_dc;
|
||||
uint32_t cbp, quant, buf_offs;
|
||||
IVIMbInfo *mb;
|
||||
ivi_mc_func mc_with_delta_func, mc_no_delta_func;
|
||||
const uint16_t *base_tab;
|
||||
const uint8_t *scale_tab;
|
||||
|
||||
prev_dc = 0; /* init intra prediction for the DC coefficient */
|
||||
const uint8_t *scale_tab;
|
||||
|
||||
/* init intra prediction for the DC coefficient */
|
||||
prev_dc = 0;
|
||||
blk_size = band->blk_size;
|
||||
col_mask = blk_size - 1; /* column mask for tracking non-zero coeffs */
|
||||
num_blocks = (band->mb_size != blk_size) ? 4 : 1; /* number of blocks per mb */
|
||||
num_coeffs = blk_size * blk_size;
|
||||
/* number of blocks per mb */
|
||||
num_blocks = (band->mb_size != blk_size) ? 4 : 1;
|
||||
if (blk_size == 8) {
|
||||
mc_with_delta_func = ff_ivi_mc_8x8_delta;
|
||||
mc_no_delta_func = ff_ivi_mc_8x8_no_delta;
|
||||
@@ -373,7 +514,6 @@ int ff_ivi_decode_blocks(GetBitContext *gb, IVIBandDesc *band, IVITile *tile)
|
||||
|
||||
quant = av_clip(band->glob_quant + mb->q_delta, 0, 23);
|
||||
|
||||
base_tab = is_intra ? band->intra_base : band->inter_base;
|
||||
scale_tab = is_intra ? band->intra_scale : band->inter_scale;
|
||||
if (scale_tab)
|
||||
quant = scale_tab[quant];
|
||||
@@ -396,10 +536,10 @@ int ff_ivi_decode_blocks(GetBitContext *gb, IVIBandDesc *band, IVITile *tile)
|
||||
cx = mb->mv_x & band->is_halfpel;
|
||||
cy = mb->mv_y & band->is_halfpel;
|
||||
|
||||
if ( mb->xpos + dmv_x < 0
|
||||
|| mb->xpos + dmv_x + band->mb_size + cx > band->pitch
|
||||
|| mb->ypos + dmv_y < 0
|
||||
|| mb->ypos + dmv_y + band->mb_size + cy > band->aheight) {
|
||||
if (mb->xpos + dmv_x < 0 ||
|
||||
mb->xpos + dmv_x + band->mb_size + cx > band->pitch ||
|
||||
mb->ypos + dmv_y < 0 ||
|
||||
mb->ypos + dmv_y + band->mb_size + cy > band->aheight) {
|
||||
return AVERROR_INVALIDDATA;
|
||||
}
|
||||
}
|
||||
@@ -415,81 +555,25 @@ int ff_ivi_decode_blocks(GetBitContext *gb, IVIBandDesc *band, IVITile *tile)
|
||||
}
|
||||
|
||||
if (cbp & 1) { /* block coded ? */
|
||||
if (!band->scan) {
|
||||
av_log(NULL, AV_LOG_ERROR, "Scan pattern is not set.\n");
|
||||
return AVERROR_INVALIDDATA;
|
||||
}
|
||||
|
||||
scan_pos = -1;
|
||||
memset(trvec, 0, num_coeffs*sizeof(trvec[0])); /* zero transform vector */
|
||||
memset(col_flags, 0, sizeof(col_flags)); /* zero column flags */
|
||||
|
||||
while (scan_pos <= num_coeffs) {
|
||||
sym = get_vlc2(gb, band->blk_vlc.tab->table, IVI_VLC_BITS, 1);
|
||||
if (sym == rvmap->eob_sym)
|
||||
break; /* End of block */
|
||||
|
||||
if (sym == rvmap->esc_sym) { /* Escape - run/val explicitly coded using 3 vlc codes */
|
||||
run = get_vlc2(gb, band->blk_vlc.tab->table, IVI_VLC_BITS, 1) + 1;
|
||||
lo = get_vlc2(gb, band->blk_vlc.tab->table, IVI_VLC_BITS, 1);
|
||||
hi = get_vlc2(gb, band->blk_vlc.tab->table, IVI_VLC_BITS, 1);
|
||||
val = IVI_TOSIGNED((hi << 6) | lo); /* merge them and convert into signed val */
|
||||
} else {
|
||||
if (sym >= 256U) {
|
||||
av_log(NULL, AV_LOG_ERROR, "Invalid sym encountered: %d.\n", sym);
|
||||
return AVERROR_INVALIDDATA;
|
||||
}
|
||||
run = rvmap->runtab[sym];
|
||||
val = rvmap->valtab[sym];
|
||||
}
|
||||
|
||||
/* de-zigzag and dequantize */
|
||||
scan_pos += run;
|
||||
if (scan_pos >= num_coeffs)
|
||||
break;
|
||||
pos = band->scan[scan_pos];
|
||||
|
||||
if (!val)
|
||||
av_dlog(NULL, "Val = 0 encountered!\n");
|
||||
|
||||
q = (base_tab[pos] * quant) >> 9;
|
||||
if (q > 1)
|
||||
val = val * q + FFSIGN(val) * (((q ^ 1) - 1) >> 1);
|
||||
trvec[pos] = val;
|
||||
col_flags[pos & col_mask] |= !!val; /* track columns containing non-zero coeffs */
|
||||
}// while
|
||||
|
||||
if (scan_pos >= num_coeffs && sym != rvmap->eob_sym)
|
||||
return AVERROR_INVALIDDATA; /* corrupt block data */
|
||||
|
||||
/* undoing DC coeff prediction for intra-blocks */
|
||||
if (is_intra && band->is_2d_trans) {
|
||||
prev_dc += trvec[0];
|
||||
trvec[0] = prev_dc;
|
||||
col_flags[0] |= !!prev_dc;
|
||||
}
|
||||
|
||||
/* apply inverse transform */
|
||||
band->inv_transform(trvec, band->buf + buf_offs,
|
||||
band->pitch, col_flags);
|
||||
|
||||
/* apply motion compensation */
|
||||
if (!is_intra)
|
||||
mc_with_delta_func(band->buf + buf_offs,
|
||||
band->ref_buf + buf_offs + mv_y * band->pitch + mv_x,
|
||||
band->pitch, mc_type);
|
||||
ret = ivi_decode_coded_blocks(gb, band, mc_with_delta_func,
|
||||
mv_x, mv_y, &prev_dc, is_intra,
|
||||
mc_type, quant, buf_offs);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
} else {
|
||||
/* block not coded */
|
||||
/* for intra blocks apply the dc slant transform */
|
||||
/* for inter - perform the motion compensation without delta */
|
||||
if (is_intra) {
|
||||
if (band->dc_transform)
|
||||
band->dc_transform(&prev_dc, band->buf + buf_offs,
|
||||
band->pitch, blk_size);
|
||||
} else
|
||||
mc_no_delta_func(band->buf + buf_offs,
|
||||
band->ref_buf + buf_offs + mv_y * band->pitch + mv_x,
|
||||
band->pitch, mc_type);
|
||||
ret = ivi_dc_transform(band, &prev_dc, buf_offs, blk_size);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
} else {
|
||||
ret = ivi_mc(band, mc_no_delta_func, buf_offs,
|
||||
mv_x, mv_y, mc_type);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
cbp >>= 1;
|
||||
@@ -514,7 +598,7 @@ static int ivi_process_empty_tile(AVCodecContext *avctx, IVIBandDesc *band,
|
||||
IVITile *tile, int32_t mv_scale)
|
||||
{
|
||||
int x, y, need_mc, mbn, blk, num_blocks, mv_x, mv_y, mc_type;
|
||||
int offs, mb_offset, row_offset;
|
||||
int offs, mb_offset, row_offset, ret;
|
||||
IVIMbInfo *mb, *ref_mb;
|
||||
const int16_t *src;
|
||||
int16_t *dst;
|
||||
@@ -592,9 +676,10 @@ static int ivi_process_empty_tile(AVCodecContext *avctx, IVIBandDesc *band,
|
||||
for (blk = 0; blk < num_blocks; blk++) {
|
||||
/* adjust block position in the buffer according with its number */
|
||||
offs = mb->buf_offs + band->blk_size * ((blk & 1) + !!(blk & 2) * band->pitch);
|
||||
mc_no_delta_func(band->buf + offs,
|
||||
band->ref_buf + offs + mv_y * band->pitch + mv_x,
|
||||
band->pitch, mc_type);
|
||||
ret = ivi_mc(band, mc_no_delta_func, offs,
|
||||
mv_x, mv_y, mc_type);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@@ -757,7 +842,8 @@ static int decode_band(IVI45DecContext *ctx, int plane_num,
|
||||
}
|
||||
}
|
||||
|
||||
/* restore the selected rvmap table by applying its corrections in reverse order */
|
||||
/* restore the selected rvmap table by applying its corrections in
|
||||
* reverse order */
|
||||
for (i = band->num_corr-1; i >= 0; i--) {
|
||||
idx1 = band->corr[i*2];
|
||||
idx2 = band->corr[i*2+1];
|
||||
@@ -770,7 +856,8 @@ static int decode_band(IVI45DecContext *ctx, int plane_num,
|
||||
uint16_t chksum = ivi_calc_band_checksum(band);
|
||||
if (chksum != band->checksum) {
|
||||
av_log(avctx, AV_LOG_ERROR,
|
||||
"Band checksum mismatch! Plane %d, band %d, received: %x, calculated: %x\n",
|
||||
"Band checksum mismatch! Plane %d, band %d, "
|
||||
"received: %x, calculated: %x\n",
|
||||
band->plane, band->band_num, band->checksum, chksum);
|
||||
}
|
||||
}
|
||||
@@ -822,6 +909,14 @@ int ff_ivi_decode_frame(AVCodecContext *avctx, void *data, int *data_size,
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (ctx->is_scalable)
|
||||
return AVERROR_INVALIDDATA;
|
||||
|
||||
for (p = 0; p < 3; p++) {
|
||||
if (!ctx->planes[p].bands[0].buf)
|
||||
return AVERROR_INVALIDDATA;
|
||||
}
|
||||
}
|
||||
|
||||
//STOP_TIMER("decode_planes"); }
|
||||
@@ -829,7 +924,8 @@ int ff_ivi_decode_frame(AVCodecContext *avctx, void *data, int *data_size,
|
||||
/* If the bidirectional mode is enabled, next I and the following P frame will */
|
||||
/* be sent together. Unfortunately the approach below seems to be the only way */
|
||||
/* to handle the B-frames mode. That's exactly the same Intel decoders do. */
|
||||
if (avctx->codec_id == CODEC_ID_INDEO4 && ctx->frame_type == 0/*FRAMETYPE_INTRA*/) {
|
||||
if (avctx->codec_id == CODEC_ID_INDEO4 &&
|
||||
ctx->frame_type == 0/*FRAMETYPE_INTRA*/) {
|
||||
while (get_bits(&ctx->gb, 8)); // skip version string
|
||||
skip_bits_long(&ctx->gb, 64); // skip padding, TODO: implement correct 8-bytes alignment
|
||||
if (get_bits_left(&ctx->gb) > 18 && show_bits(&ctx->gb, 18) == 0x3FFF8)
|
||||
|
||||
@@ -162,6 +162,7 @@ typedef struct {
|
||||
int num_tiles; ///< number of tiles in this band
|
||||
IVITile *tiles; ///< array of tile descriptors
|
||||
InvTransformPtr *inv_transform;
|
||||
int transform_size;
|
||||
DCTransformPtr *dc_transform;
|
||||
int is_2d_trans; ///< 1 indicates that the two-dimensional inverse transform is used
|
||||
int32_t checksum; ///< for debug purposes
|
||||
|
||||
@@ -28,6 +28,7 @@
|
||||
#include "avcodec.h"
|
||||
#include "bytestream.h"
|
||||
#include "j2k.h"
|
||||
#include "libavutil/avassert.h"
|
||||
#include "libavutil/common.h"
|
||||
|
||||
#define JP2_SIG_TYPE 0x6A502020
|
||||
@@ -289,6 +290,10 @@ static int get_cox(J2kDecoderContext *s, J2kCodingStyle *c)
|
||||
c->log2_cblk_width = bytestream_get_byte(&s->buf) + 2; // cblk width
|
||||
c->log2_cblk_height = bytestream_get_byte(&s->buf) + 2; // cblk height
|
||||
|
||||
if (c->log2_cblk_width > 6 || c->log2_cblk_height > 6) {
|
||||
return AVERROR_PATCHWELCOME;
|
||||
}
|
||||
|
||||
c->cblk_style = bytestream_get_byte(&s->buf);
|
||||
if (c->cblk_style != 0){ // cblk style
|
||||
av_log(s->avctx, AV_LOG_WARNING, "extra cblk styles %X\n", c->cblk_style);
|
||||
@@ -705,6 +710,9 @@ static int decode_cblk(J2kDecoderContext *s, J2kCodingStyle *codsty, J2kT1Contex
|
||||
int bpass_csty_symbol = J2K_CBLK_BYPASS & codsty->cblk_style;
|
||||
int vert_causal_ctx_csty_symbol = J2K_CBLK_VSC & codsty->cblk_style;
|
||||
|
||||
av_assert0(width <= J2K_MAX_CBLKW);
|
||||
av_assert0(height <= J2K_MAX_CBLKH);
|
||||
|
||||
for (y = 0; y < height+2; y++)
|
||||
memset(t1->flags[y], 0, (width+2)*sizeof(int));
|
||||
|
||||
|
||||
@@ -143,6 +143,8 @@ static inline int ls_get_code_runterm(GetBitContext *gb, JLSState *state, int RI
|
||||
ret = ret >> 1;
|
||||
}
|
||||
|
||||
if(FFABS(ret) > 0xFFFF)
|
||||
return -0x10000;
|
||||
/* update state */
|
||||
state->A[Q] += FFABS(ret) - RItype;
|
||||
ret *= state->twonear;
|
||||
|
||||
@@ -255,6 +255,13 @@ int ff_mjpeg_decode_sof(MJpegDecodeContext *s)
|
||||
if (nb_components <= 0 ||
|
||||
nb_components > MAX_COMPONENTS)
|
||||
return -1;
|
||||
if (s->interlaced && (s->bottom_field == !s->interlace_polarity)) {
|
||||
if (nb_components != s->nb_components) {
|
||||
av_log(s->avctx, AV_LOG_ERROR,
|
||||
"nb_components changing in interlaced picture\n");
|
||||
return AVERROR_INVALIDDATA;
|
||||
}
|
||||
}
|
||||
if (s->ls && !(s->bits <= 8 || nb_components == 1)) {
|
||||
av_log(s->avctx, AV_LOG_ERROR,
|
||||
"only <= 8 bits/component or 16-bit gray accepted for JPEG-LS\n");
|
||||
@@ -712,6 +719,12 @@ static int ljpeg_decode_rgb_scan(MJpegDecodeContext *s, int nb_components, int p
|
||||
int resync_mb_y = 0;
|
||||
int resync_mb_x = 0;
|
||||
|
||||
if (s->nb_components != 3 && s->nb_components != 4)
|
||||
return AVERROR_INVALIDDATA;
|
||||
if (s->v_max != 1 || s->h_max != 1 || !s->lossless)
|
||||
return AVERROR_INVALIDDATA;
|
||||
|
||||
|
||||
s->restart_count = s->restart_interval;
|
||||
|
||||
av_fast_malloc(&s->ljpeg_buffer, &s->ljpeg_buffer_size,
|
||||
|
||||
+18
-12
@@ -369,9 +369,10 @@ static int read_restart_header(MLPDecodeContext *m, GetBitContext *gbp,
|
||||
uint8_t checksum;
|
||||
uint8_t lossless_check;
|
||||
int start_count = get_bits_count(gbp);
|
||||
const int max_matrix_channel = m->avctx->codec_id == CODEC_ID_MLP
|
||||
? MAX_MATRIX_CHANNEL_MLP
|
||||
: MAX_MATRIX_CHANNEL_TRUEHD;
|
||||
int min_channel, max_channel, max_matrix_channel;
|
||||
const int std_max_matrix_channel = m->avctx->codec_id == CODEC_ID_MLP
|
||||
? MAX_MATRIX_CHANNEL_MLP
|
||||
: MAX_MATRIX_CHANNEL_TRUEHD;
|
||||
|
||||
sync_word = get_bits(gbp, 13);
|
||||
|
||||
@@ -390,18 +391,18 @@ static int read_restart_header(MLPDecodeContext *m, GetBitContext *gbp,
|
||||
|
||||
skip_bits(gbp, 16); /* Output timestamp */
|
||||
|
||||
s->min_channel = get_bits(gbp, 4);
|
||||
s->max_channel = get_bits(gbp, 4);
|
||||
s->max_matrix_channel = get_bits(gbp, 4);
|
||||
min_channel = get_bits(gbp, 4);
|
||||
max_channel = get_bits(gbp, 4);
|
||||
max_matrix_channel = get_bits(gbp, 4);
|
||||
|
||||
if (s->max_matrix_channel > max_matrix_channel) {
|
||||
if (max_matrix_channel > std_max_matrix_channel) {
|
||||
av_log(m->avctx, AV_LOG_ERROR,
|
||||
"Max matrix channel cannot be greater than %d.\n",
|
||||
max_matrix_channel);
|
||||
return AVERROR_INVALIDDATA;
|
||||
}
|
||||
|
||||
if (s->max_channel != s->max_matrix_channel) {
|
||||
if (max_channel != max_matrix_channel) {
|
||||
av_log(m->avctx, AV_LOG_ERROR,
|
||||
"Max channel must be equal max matrix channel.\n");
|
||||
return AVERROR_INVALIDDATA;
|
||||
@@ -416,15 +417,20 @@ static int read_restart_header(MLPDecodeContext *m, GetBitContext *gbp,
|
||||
return AVERROR_INVALIDDATA;
|
||||
}
|
||||
|
||||
if (s->min_channel > s->max_channel) {
|
||||
if (min_channel > max_channel) {
|
||||
av_log(m->avctx, AV_LOG_ERROR,
|
||||
"Substream min channel cannot be greater than max channel.\n");
|
||||
return AVERROR_INVALIDDATA;
|
||||
}
|
||||
|
||||
if (m->avctx->request_channels > 0
|
||||
&& s->max_channel + 1 >= m->avctx->request_channels
|
||||
&& substr < m->max_decoded_substream) {
|
||||
|
||||
s->min_channel = min_channel;
|
||||
s->max_channel = max_channel;
|
||||
s->max_matrix_channel = max_matrix_channel;
|
||||
|
||||
if (m->avctx->request_channels > 0 &&
|
||||
m->avctx->request_channels <= s->max_channel + 1 &&
|
||||
m->max_decoded_substream > substr) {
|
||||
av_log(m->avctx, AV_LOG_DEBUG,
|
||||
"Extracting %d channel downmix from substream %d. "
|
||||
"Further substreams will be skipped.\n",
|
||||
|
||||
@@ -244,7 +244,8 @@ void mpeg_motion_internal(MpegEncContext *s,
|
||||
{
|
||||
uint8_t *ptr_y, *ptr_cb, *ptr_cr;
|
||||
int dxy, uvdxy, mx, my, src_x, src_y,
|
||||
uvsrc_x, uvsrc_y, v_edge_pos, uvlinesize, linesize;
|
||||
uvsrc_x, uvsrc_y, v_edge_pos;
|
||||
emuedge_linesize_type uvlinesize, linesize;
|
||||
|
||||
#if 0
|
||||
if(s->quarter_sample)
|
||||
|
||||
+31
-19
@@ -85,7 +85,7 @@ static int get_quant(AVCodecContext *avctx, NuvContext *c,
|
||||
int i;
|
||||
if (size < 2 * 64 * 4) {
|
||||
av_log(avctx, AV_LOG_ERROR, "insufficient rtjpeg quant data\n");
|
||||
return -1;
|
||||
return AVERROR_INVALIDDATA;
|
||||
}
|
||||
for (i = 0; i < 64; i++, buf += 4)
|
||||
c->lq[i] = AV_RL32(buf);
|
||||
@@ -108,6 +108,8 @@ static void get_quant_quality(NuvContext *c, int quality) {
|
||||
|
||||
static int codec_reinit(AVCodecContext *avctx, int width, int height, int quality) {
|
||||
NuvContext *c = avctx->priv_data;
|
||||
int ret;
|
||||
|
||||
width = FFALIGN(width, 2);
|
||||
height = FFALIGN(height, 2);
|
||||
if (quality >= 0)
|
||||
@@ -115,12 +117,14 @@ static int codec_reinit(AVCodecContext *avctx, int width, int height, int qualit
|
||||
if (width != c->width || height != c->height) {
|
||||
// also reserve space for a possible additional header
|
||||
int buf_size = 24 + height * width * 3 / 2 + AV_LZO_OUTPUT_PADDING;
|
||||
if (av_image_check_size(height, width, 0, avctx) < 0 ||
|
||||
buf_size > INT_MAX/8)
|
||||
if (buf_size > INT_MAX/8)
|
||||
return -1;
|
||||
if ((ret = av_image_check_size(height, width, 0, avctx)) < 0)
|
||||
return ret;
|
||||
avctx->width = c->width = width;
|
||||
avctx->height = c->height = height;
|
||||
av_fast_malloc(&c->decomp_buf, &c->decomp_size, buf_size);
|
||||
av_fast_malloc(&c->decomp_buf, &c->decomp_size,
|
||||
buf_size);
|
||||
if (!c->decomp_buf) {
|
||||
av_log(avctx, AV_LOG_ERROR, "Can't allocate decompression buffer.\n");
|
||||
return AVERROR(ENOMEM);
|
||||
@@ -142,13 +146,14 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *data_size,
|
||||
int keyframe;
|
||||
int size_change = 0;
|
||||
int result;
|
||||
int ret;
|
||||
enum {NUV_UNCOMPRESSED = '0', NUV_RTJPEG = '1',
|
||||
NUV_RTJPEG_IN_LZO = '2', NUV_LZO = '3',
|
||||
NUV_BLACK = 'N', NUV_COPY_LAST = 'L'} comptype;
|
||||
|
||||
if (buf_size < 12) {
|
||||
av_log(avctx, AV_LOG_ERROR, "coded frame too small\n");
|
||||
return -1;
|
||||
return AVERROR_INVALIDDATA;
|
||||
}
|
||||
|
||||
// codec data (rtjpeg quant tables)
|
||||
@@ -166,7 +171,7 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *data_size,
|
||||
|
||||
if (buf[0] != 'V' || buf_size < 12) {
|
||||
av_log(avctx, AV_LOG_ERROR, "not a nuv video frame\n");
|
||||
return -1;
|
||||
return AVERROR_INVALIDDATA;
|
||||
}
|
||||
comptype = buf[1];
|
||||
switch (comptype) {
|
||||
@@ -183,14 +188,17 @@ retry:
|
||||
buf = &buf[12];
|
||||
buf_size -= 12;
|
||||
if (comptype == NUV_RTJPEG_IN_LZO || comptype == NUV_LZO) {
|
||||
int outlen = c->decomp_size - AV_LZO_OUTPUT_PADDING, inlen = buf_size;
|
||||
if (av_lzo1x_decode(c->decomp_buf, &outlen, buf, &inlen))
|
||||
int outlen = c->decomp_size - FFMAX(FF_INPUT_BUFFER_PADDING_SIZE, AV_LZO_OUTPUT_PADDING);
|
||||
int inlen = buf_size;
|
||||
if (av_lzo1x_decode(c->decomp_buf, &outlen, buf, &inlen)) {
|
||||
av_log(avctx, AV_LOG_ERROR, "error during lzo decompression\n");
|
||||
return AVERROR_INVALIDDATA;
|
||||
}
|
||||
buf = c->decomp_buf;
|
||||
buf_size = c->decomp_size - AV_LZO_OUTPUT_PADDING - outlen;
|
||||
buf_size = c->decomp_size - FFMAX(FF_INPUT_BUFFER_PADDING_SIZE, AV_LZO_OUTPUT_PADDING) - outlen;
|
||||
}
|
||||
if (c->codec_frameheader) {
|
||||
int w, h, q, res;
|
||||
int w, h, q;
|
||||
if (buf_size < RTJPEG_HEADER_SIZE || buf[4] != RTJPEG_HEADER_SIZE ||
|
||||
buf[5] != RTJPEG_FILE_VERSION) {
|
||||
av_log(avctx, AV_LOG_ERROR, "invalid nuv video frame\n");
|
||||
@@ -199,11 +207,10 @@ retry:
|
||||
w = AV_RL16(&buf[6]);
|
||||
h = AV_RL16(&buf[8]);
|
||||
q = buf[10];
|
||||
if ((result = codec_reinit(avctx, w, h, q)) < 0)
|
||||
return result;
|
||||
|
||||
res = codec_reinit(avctx, w, h, q);
|
||||
if (res < 0)
|
||||
return res;
|
||||
if (res) {
|
||||
if (result) {
|
||||
buf = avpkt->data;
|
||||
buf_size = avpkt->size;
|
||||
size_change = 1;
|
||||
@@ -221,7 +228,7 @@ retry:
|
||||
result = avctx->reget_buffer(avctx, &c->pic);
|
||||
if (result < 0) {
|
||||
av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
|
||||
return -1;
|
||||
return result;
|
||||
}
|
||||
|
||||
c->pic.pict_type = keyframe ? AV_PICTURE_TYPE_I : AV_PICTURE_TYPE_P;
|
||||
@@ -240,7 +247,9 @@ retry:
|
||||
}
|
||||
case NUV_RTJPEG_IN_LZO:
|
||||
case NUV_RTJPEG: {
|
||||
rtjpeg_decode_frame_yuv420(&c->rtj, &c->pic, buf, buf_size);
|
||||
ret = rtjpeg_decode_frame_yuv420(&c->rtj, &c->pic, buf, buf_size);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
break;
|
||||
}
|
||||
case NUV_BLACK: {
|
||||
@@ -255,7 +264,7 @@ retry:
|
||||
}
|
||||
default:
|
||||
av_log(avctx, AV_LOG_ERROR, "unknown compression\n");
|
||||
return -1;
|
||||
return AVERROR_INVALIDDATA;
|
||||
}
|
||||
|
||||
*picture = c->pic;
|
||||
@@ -265,6 +274,8 @@ retry:
|
||||
|
||||
static av_cold int decode_init(AVCodecContext *avctx) {
|
||||
NuvContext *c = avctx->priv_data;
|
||||
int ret;
|
||||
|
||||
avctx->pix_fmt = PIX_FMT_YUV420P;
|
||||
c->pic.data[0] = NULL;
|
||||
c->decomp_buf = NULL;
|
||||
@@ -275,8 +286,9 @@ static av_cold int decode_init(AVCodecContext *avctx) {
|
||||
if (avctx->extradata_size)
|
||||
get_quant(avctx, c, avctx->extradata, avctx->extradata_size);
|
||||
dsputil_init(&c->dsp, avctx);
|
||||
if (codec_reinit(avctx, avctx->width, avctx->height, -1) < 0)
|
||||
return 1;
|
||||
if ((ret = codec_reinit(avctx, avctx->width, avctx->height, -1)) < 0)
|
||||
return ret;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
+7
-3
@@ -241,8 +241,10 @@ int ff_combine_frame(ParseContext *pc, int next, const uint8_t **buf, int *buf_s
|
||||
if(next == END_NOT_FOUND){
|
||||
void* new_buffer = av_fast_realloc(pc->buffer, &pc->buffer_size, (*buf_size) + pc->index + FF_INPUT_BUFFER_PADDING_SIZE);
|
||||
|
||||
if(!new_buffer)
|
||||
if(!new_buffer) {
|
||||
pc->index = 0;
|
||||
return AVERROR(ENOMEM);
|
||||
}
|
||||
pc->buffer = new_buffer;
|
||||
memcpy(&pc->buffer[pc->index], *buf, *buf_size);
|
||||
pc->index += *buf_size;
|
||||
@@ -255,9 +257,11 @@ int ff_combine_frame(ParseContext *pc, int next, const uint8_t **buf, int *buf_s
|
||||
/* append to buffer */
|
||||
if(pc->index){
|
||||
void* new_buffer = av_fast_realloc(pc->buffer, &pc->buffer_size, next + pc->index + FF_INPUT_BUFFER_PADDING_SIZE);
|
||||
|
||||
if(!new_buffer)
|
||||
if(!new_buffer) {
|
||||
pc->overread_index =
|
||||
pc->index = 0;
|
||||
return AVERROR(ENOMEM);
|
||||
}
|
||||
pc->buffer = new_buffer;
|
||||
if (next > -FF_INPUT_BUFFER_PADDING_SIZE)
|
||||
memcpy(&pc->buffer[pc->index], *buf,
|
||||
|
||||
+1
-1
@@ -268,7 +268,7 @@ static int pcm_decode_frame(AVCodecContext *avctx, void *data,
|
||||
|
||||
/* av_get_bits_per_sample returns 0 for CODEC_ID_PCM_DVD */
|
||||
samples_per_block = 1;
|
||||
if (CODEC_ID_PCM_DVD == avctx->codec_id) {
|
||||
if (avctx->codec->id == CODEC_ID_PCM_DVD) {
|
||||
if (avctx->bits_per_coded_sample != 20 &&
|
||||
avctx->bits_per_coded_sample != 24) {
|
||||
av_log(avctx, AV_LOG_ERROR,
|
||||
|
||||
+18
-9
@@ -43,16 +43,19 @@ static av_cold int pcx_init(AVCodecContext *avctx) {
|
||||
/**
|
||||
* @return advanced src pointer
|
||||
*/
|
||||
static const uint8_t *pcx_rle_decode(const uint8_t *src, uint8_t *dst,
|
||||
unsigned int bytes_per_scanline, int compressed) {
|
||||
static const uint8_t *pcx_rle_decode(const uint8_t *src,
|
||||
const uint8_t *end,
|
||||
uint8_t *dst,
|
||||
unsigned int bytes_per_scanline,
|
||||
int compressed) {
|
||||
unsigned int i = 0;
|
||||
unsigned char run, value;
|
||||
|
||||
if (compressed) {
|
||||
while (i<bytes_per_scanline) {
|
||||
while (i < bytes_per_scanline && src < end) {
|
||||
run = 1;
|
||||
value = *src++;
|
||||
if (value >= 0xc0) {
|
||||
if (value >= 0xc0 && src < end) {
|
||||
run = value & 0x3f;
|
||||
value = *src++;
|
||||
}
|
||||
@@ -87,6 +90,7 @@ static int pcx_decode_frame(AVCodecContext *avctx, void *data, int *data_size,
|
||||
unsigned int w, h, bits_per_pixel, bytes_per_line, nplanes, stride, y, x,
|
||||
bytes_per_scanline;
|
||||
uint8_t *ptr;
|
||||
const uint8_t *buf_end = buf + buf_size;
|
||||
uint8_t const *bufstart = buf;
|
||||
uint8_t *scanline;
|
||||
int ret = -1;
|
||||
@@ -115,7 +119,8 @@ static int pcx_decode_frame(AVCodecContext *avctx, void *data, int *data_size,
|
||||
nplanes = buf[65];
|
||||
bytes_per_scanline = nplanes * bytes_per_line;
|
||||
|
||||
if (bytes_per_scanline < w * bits_per_pixel * nplanes / 8) {
|
||||
if (bytes_per_scanline < w * bits_per_pixel * nplanes / 8 ||
|
||||
(!compressed && bytes_per_scanline > buf_size / h)) {
|
||||
av_log(avctx, AV_LOG_ERROR, "PCX data is corrupted\n");
|
||||
return -1;
|
||||
}
|
||||
@@ -163,7 +168,8 @@ static int pcx_decode_frame(AVCodecContext *avctx, void *data, int *data_size,
|
||||
|
||||
if (nplanes == 3 && bits_per_pixel == 8) {
|
||||
for (y=0; y<h; y++) {
|
||||
buf = pcx_rle_decode(buf, scanline, bytes_per_scanline, compressed);
|
||||
buf = pcx_rle_decode(buf, buf_end,
|
||||
scanline, bytes_per_scanline, compressed);
|
||||
|
||||
for (x=0; x<w; x++) {
|
||||
ptr[3*x ] = scanline[x ];
|
||||
@@ -178,7 +184,8 @@ static int pcx_decode_frame(AVCodecContext *avctx, void *data, int *data_size,
|
||||
const uint8_t *palstart = bufstart + buf_size - 769;
|
||||
|
||||
for (y=0; y<h; y++, ptr+=stride) {
|
||||
buf = pcx_rle_decode(buf, scanline, bytes_per_scanline, compressed);
|
||||
buf = pcx_rle_decode(buf, buf_end,
|
||||
scanline, bytes_per_scanline, compressed);
|
||||
memcpy(ptr, scanline, w);
|
||||
}
|
||||
|
||||
@@ -197,7 +204,8 @@ static int pcx_decode_frame(AVCodecContext *avctx, void *data, int *data_size,
|
||||
for (y=0; y<h; y++) {
|
||||
init_get_bits(&s, scanline, bytes_per_scanline<<3);
|
||||
|
||||
buf = pcx_rle_decode(buf, scanline, bytes_per_scanline, compressed);
|
||||
buf = pcx_rle_decode(buf, buf_end,
|
||||
scanline, bytes_per_scanline, compressed);
|
||||
|
||||
for (x=0; x<w; x++)
|
||||
ptr[x] = get_bits(&s, bits_per_pixel);
|
||||
@@ -208,7 +216,8 @@ static int pcx_decode_frame(AVCodecContext *avctx, void *data, int *data_size,
|
||||
int i;
|
||||
|
||||
for (y=0; y<h; y++) {
|
||||
buf = pcx_rle_decode(buf, scanline, bytes_per_scanline, compressed);
|
||||
buf = pcx_rle_decode(buf, buf_end,
|
||||
scanline, bytes_per_scanline, compressed);
|
||||
|
||||
for (x=0; x<w; x++) {
|
||||
int m = 0x80 >> (x&7), v = 0;
|
||||
|
||||
@@ -235,6 +235,8 @@ static int decode_frame(AVCodecContext *avctx,
|
||||
|
||||
if (bits_per_plane == 8) {
|
||||
picmemset_8bpp(s, val, run, &x, &y);
|
||||
if (y < 0)
|
||||
goto finish;
|
||||
} else {
|
||||
picmemset(s, val, run, &x, &y, &plane, bits_per_plane);
|
||||
}
|
||||
@@ -247,6 +249,7 @@ static int decode_frame(AVCodecContext *avctx,
|
||||
y--;
|
||||
}
|
||||
}
|
||||
finish:
|
||||
|
||||
*data_size = sizeof(AVFrame);
|
||||
*(AVFrame*)data = s->frame;
|
||||
|
||||
+1
-1
@@ -121,7 +121,7 @@ static void png_put_interlaced_row(uint8_t *dst, int width,
|
||||
static void add_bytes_l2_c(uint8_t *dst, uint8_t *src1, uint8_t *src2, int w)
|
||||
{
|
||||
long i;
|
||||
for(i=0; i<=w-sizeof(long); i+=sizeof(long)){
|
||||
for(i=0; i<=w-(int)sizeof(long); i+=sizeof(long)){
|
||||
long a = *(long*)(src1+i);
|
||||
long b = *(long*)(src2+i);
|
||||
*(long*)(dst+i) = ((a&pb_7f) + (b&pb_7f)) ^ ((a^b)&pb_80);
|
||||
|
||||
+25
-16
@@ -498,7 +498,8 @@ static void build_sb_samples_from_noise (QDM2Context *q, int sb)
|
||||
* @param channels number of channels
|
||||
* @param coding_method q->coding_method[0][0][0]
|
||||
*/
|
||||
static void fix_coding_method_array (int sb, int channels, sb_int8_array coding_method)
|
||||
static int fix_coding_method_array(int sb, int channels,
|
||||
sb_int8_array coding_method)
|
||||
{
|
||||
int j,k;
|
||||
int ch;
|
||||
@@ -507,8 +508,10 @@ static void fix_coding_method_array (int sb, int channels, sb_int8_array coding_
|
||||
|
||||
for (ch = 0; ch < channels; ch++) {
|
||||
for (j = 0; j < 64; ) {
|
||||
if((coding_method[ch][sb][j] - 8) > 22) {
|
||||
run = 1;
|
||||
if (coding_method[ch][sb][j] < 8)
|
||||
return -1;
|
||||
if ((coding_method[ch][sb][j] - 8) > 22) {
|
||||
run = 1;
|
||||
case_val = 8;
|
||||
} else {
|
||||
switch (switchtable[coding_method[ch][sb][j]-8]) {
|
||||
@@ -533,6 +536,7 @@ static void fix_coding_method_array (int sb, int channels, sb_int8_array coding_
|
||||
j += run;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -769,7 +773,7 @@ static void fill_coding_method_array (sb_int8_array tone_level_idx, sb_int8_arra
|
||||
static void synthfilt_build_sb_samples (QDM2Context *q, GetBitContext *gb, int length, int sb_min, int sb_max)
|
||||
{
|
||||
int sb, j, k, n, ch, run, channels;
|
||||
int joined_stereo, zero_encoding, chs;
|
||||
int joined_stereo, zero_encoding;
|
||||
int type34_first;
|
||||
float type34_div = 0;
|
||||
float type34_predictor;
|
||||
@@ -784,8 +788,6 @@ static void synthfilt_build_sb_samples (QDM2Context *q, GetBitContext *gb, int l
|
||||
}
|
||||
|
||||
for (sb = sb_min; sb < sb_max; sb++) {
|
||||
FIX_NOISE_IDX(q->noise_idx);
|
||||
|
||||
channels = q->nb_channels;
|
||||
|
||||
if (q->nb_channels <= 1 || sb < 12)
|
||||
@@ -804,11 +806,16 @@ static void synthfilt_build_sb_samples (QDM2Context *q, GetBitContext *gb, int l
|
||||
if (q->coding_method[1][sb][j] > q->coding_method[0][sb][j])
|
||||
q->coding_method[0][sb][j] = q->coding_method[1][sb][j];
|
||||
|
||||
fix_coding_method_array(sb, q->nb_channels, q->coding_method);
|
||||
if (fix_coding_method_array(sb, q->nb_channels,
|
||||
q->coding_method)) {
|
||||
build_sb_samples_from_noise(q, sb);
|
||||
continue;
|
||||
}
|
||||
channels = 1;
|
||||
}
|
||||
|
||||
for (ch = 0; ch < channels; ch++) {
|
||||
FIX_NOISE_IDX(q->noise_idx);
|
||||
zero_encoding = (BITS_LEFT(length,gb) >= 1) ? get_bits1(gb) : 0;
|
||||
type34_predictor = 0.0;
|
||||
type34_first = 1;
|
||||
@@ -924,16 +931,18 @@ static void synthfilt_build_sb_samples (QDM2Context *q, GetBitContext *gb, int l
|
||||
}
|
||||
|
||||
if (joined_stereo) {
|
||||
float tmp[10][MPA_MAX_CHANNELS];
|
||||
|
||||
for (k = 0; k < run; k++) {
|
||||
tmp[k][0] = samples[k];
|
||||
tmp[k][1] = (sign_bits[(j + k) / 8]) ? -samples[k] : samples[k];
|
||||
for (k = 0; k < run && j + k < 128; k++) {
|
||||
q->sb_samples[0][j + k][sb] =
|
||||
q->tone_level[0][sb][(j + k) / 2] * samples[k];
|
||||
if (q->nb_channels == 2) {
|
||||
if (sign_bits[(j + k) / 8])
|
||||
q->sb_samples[1][j + k][sb] =
|
||||
q->tone_level[1][sb][(j + k) / 2] * -samples[k];
|
||||
else
|
||||
q->sb_samples[1][j + k][sb] =
|
||||
q->tone_level[1][sb][(j + k) / 2] * samples[k];
|
||||
}
|
||||
}
|
||||
for (chs = 0; chs < q->nb_channels; chs++)
|
||||
for (k = 0; k < run; k++)
|
||||
if ((j + k) < 128)
|
||||
q->sb_samples[chs][j + k][sb] = q->tone_level[chs][sb][((j + k)/2)] * tmp[k][chs];
|
||||
} else {
|
||||
for (k = 0; k < run; k++)
|
||||
if ((j + k) < 128)
|
||||
|
||||
+4
-4
@@ -83,7 +83,7 @@ static void rpza_decode_stream(RpzaContext *s)
|
||||
unsigned short *pixels = (unsigned short *)s->frame.data[0];
|
||||
|
||||
int row_ptr = 0;
|
||||
int pixel_ptr = 0;
|
||||
int pixel_ptr = -4;
|
||||
int block_ptr;
|
||||
int pixel_x, pixel_y;
|
||||
int total_blocks;
|
||||
@@ -139,6 +139,7 @@ static void rpza_decode_stream(RpzaContext *s)
|
||||
colorA = AV_RB16 (&s->buf[stream_ptr]);
|
||||
stream_ptr += 2;
|
||||
while (n_blocks--) {
|
||||
ADVANCE_BLOCK()
|
||||
block_ptr = row_ptr + pixel_ptr;
|
||||
for (pixel_y = 0; pixel_y < 4; pixel_y++) {
|
||||
for (pixel_x = 0; pixel_x < 4; pixel_x++){
|
||||
@@ -147,7 +148,6 @@ static void rpza_decode_stream(RpzaContext *s)
|
||||
}
|
||||
block_ptr += row_inc;
|
||||
}
|
||||
ADVANCE_BLOCK();
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -186,6 +186,7 @@ static void rpza_decode_stream(RpzaContext *s)
|
||||
if (s->size - stream_ptr < n_blocks * 4)
|
||||
return;
|
||||
while (n_blocks--) {
|
||||
ADVANCE_BLOCK();
|
||||
block_ptr = row_ptr + pixel_ptr;
|
||||
for (pixel_y = 0; pixel_y < 4; pixel_y++) {
|
||||
index = s->buf[stream_ptr++];
|
||||
@@ -196,7 +197,6 @@ static void rpza_decode_stream(RpzaContext *s)
|
||||
}
|
||||
block_ptr += row_inc;
|
||||
}
|
||||
ADVANCE_BLOCK();
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -204,6 +204,7 @@ static void rpza_decode_stream(RpzaContext *s)
|
||||
case 0x00:
|
||||
if (s->size - stream_ptr < 16)
|
||||
return;
|
||||
ADVANCE_BLOCK();
|
||||
block_ptr = row_ptr + pixel_ptr;
|
||||
for (pixel_y = 0; pixel_y < 4; pixel_y++) {
|
||||
for (pixel_x = 0; pixel_x < 4; pixel_x++){
|
||||
@@ -217,7 +218,6 @@ static void rpza_decode_stream(RpzaContext *s)
|
||||
}
|
||||
block_ptr += row_inc;
|
||||
}
|
||||
ADVANCE_BLOCK();
|
||||
break;
|
||||
|
||||
/* Unknown opcode */
|
||||
|
||||
@@ -903,14 +903,14 @@ static av_cold int decode_init(AVCodecContext *avctx){
|
||||
if (!l->Y1_base || !l->Y2_base || !l->U1_base ||
|
||||
!l->V1_base || !l->U2_base || !l->V2_base ||
|
||||
!l->last || !l->clast) {
|
||||
av_freep(l->Y1_base);
|
||||
av_freep(l->Y2_base);
|
||||
av_freep(l->U1_base);
|
||||
av_freep(l->U2_base);
|
||||
av_freep(l->V1_base);
|
||||
av_freep(l->V2_base);
|
||||
av_freep(l->last);
|
||||
av_freep(l->clast);
|
||||
av_freep(&l->Y1_base);
|
||||
av_freep(&l->Y2_base);
|
||||
av_freep(&l->U1_base);
|
||||
av_freep(&l->U2_base);
|
||||
av_freep(&l->V1_base);
|
||||
av_freep(&l->V2_base);
|
||||
av_freep(&l->last);
|
||||
av_freep(&l->clast);
|
||||
return AVERROR(ENOMEM);
|
||||
}
|
||||
l->Y1 = l->Y1_base + l->y_stride * 4 + 4;
|
||||
|
||||
@@ -895,6 +895,9 @@ int attribute_align_arg avcodec_open2(AVCodecContext *avctx, AVCodec *codec, AVD
|
||||
} else if (avctx->channel_layout) {
|
||||
avctx->channels = av_get_channel_layout_nb_channels(avctx->channel_layout);
|
||||
}
|
||||
|
||||
if (!avctx->rc_initial_buffer_occupancy)
|
||||
avctx->rc_initial_buffer_occupancy = avctx->rc_buffer_size * 3 / 4;
|
||||
}
|
||||
|
||||
avctx->pts_correction_num_faulty_pts =
|
||||
|
||||
+22
-1
@@ -395,6 +395,11 @@ static void vc1_mc_1mv(VC1Context *v, int dir)
|
||||
}
|
||||
}
|
||||
|
||||
if (!srcY || !srcU) {
|
||||
av_log(v->s.avctx, AV_LOG_ERROR, "Referenced frame missing.\n");
|
||||
return;
|
||||
}
|
||||
|
||||
src_x = s->mb_x * 16 + (mx >> 2);
|
||||
src_y = s->mb_y * 16 + (my >> 2);
|
||||
uvsrc_x = s->mb_x * 8 + (uvmx >> 2);
|
||||
@@ -570,6 +575,11 @@ static void vc1_mc_4mv_luma(VC1Context *v, int n, int dir)
|
||||
} else
|
||||
srcY = s->next_picture.f.data[0];
|
||||
|
||||
if (!srcY) {
|
||||
av_log(v->s.avctx, AV_LOG_ERROR, "Referenced frame missing.\n");
|
||||
return;
|
||||
}
|
||||
|
||||
if (v->field_mode) {
|
||||
if (v->cur_field_type != v->ref_field_type[dir])
|
||||
my = my - 2 + 4 * v->cur_field_type;
|
||||
@@ -856,6 +866,11 @@ static void vc1_mc_4mv_chroma(VC1Context *v, int dir)
|
||||
srcV = s->next_picture.f.data[2] + uvsrc_y * s->uvlinesize + uvsrc_x;
|
||||
}
|
||||
|
||||
if (!srcU) {
|
||||
av_log(v->s.avctx, AV_LOG_ERROR, "Referenced frame missing.\n");
|
||||
return;
|
||||
}
|
||||
|
||||
if (v->field_mode) {
|
||||
if (chroma_ref_type) {
|
||||
srcU += s->current_picture_ptr->f.linesize[1];
|
||||
@@ -3949,7 +3964,7 @@ static int vc1_decode_p_mb_intfi(VC1Context *v)
|
||||
s->current_picture.f.mb_type[mb_pos + v->mb_off] = MB_TYPE_16x16;
|
||||
for (i = 0; i < 6; i++) v->mb_type[0][s->block_index[i]] = 0;
|
||||
if (idx_mbmode <= 5) { // 1-MV
|
||||
dmv_x = dmv_y = 0;
|
||||
dmv_x = dmv_y = pred_flag = 0;
|
||||
if (idx_mbmode & 1) {
|
||||
get_mvdata_interlaced(v, &dmv_x, &dmv_y, &pred_flag);
|
||||
}
|
||||
@@ -5569,6 +5584,12 @@ static int vc1_decode_frame(AVCodecContext *avctx, void *data,
|
||||
v->mv_f[1] = tmp[1];
|
||||
}
|
||||
mb_height = s->mb_height >> v->field_mode;
|
||||
|
||||
if (!mb_height) {
|
||||
av_log(v->s.avctx, AV_LOG_ERROR, "Invalid mb_height.\n");
|
||||
goto err;
|
||||
}
|
||||
|
||||
for (i = 0; i <= n_slices; i++) {
|
||||
if (i > 0 && slices[i - 1].mby_start >= mb_height) {
|
||||
if (v->field_mode <= 0) {
|
||||
|
||||
@@ -69,9 +69,13 @@ static int decode_frame(AVCodecContext *avctx,
|
||||
p->pict_type= AV_PICTURE_TYPE_I;
|
||||
p->key_frame= 1;
|
||||
|
||||
if (buf_size < 32)
|
||||
goto packet_small;
|
||||
|
||||
for(i=0; i<16; i++){
|
||||
a->delta[i]= *(bytestream++);
|
||||
bytestream++;
|
||||
buf_size--;
|
||||
}
|
||||
|
||||
for(y=0; y<avctx->height; y++){
|
||||
@@ -82,8 +86,12 @@ static int decode_frame(AVCodecContext *avctx,
|
||||
uint8_t *cb= &a->picture.data[1][ (y>>2)*a->picture.linesize[1] ];
|
||||
uint8_t *cr= &a->picture.data[2][ (y>>2)*a->picture.linesize[2] ];
|
||||
|
||||
if (buf_size < 4 + avctx->width)
|
||||
goto packet_small;
|
||||
|
||||
for(i=0; i<4; i++)
|
||||
a->offset[i]= *(bytestream++);
|
||||
buf_size -= 4;
|
||||
|
||||
offset= a->offset[0] - a->delta[ bytestream[2]&0xF ];
|
||||
for(x=0; x<avctx->width; x+=4){
|
||||
@@ -97,8 +105,12 @@ static int decode_frame(AVCodecContext *avctx,
|
||||
*(cr++) = bytestream[1];
|
||||
|
||||
bytestream+= 4;
|
||||
buf_size -= 4;
|
||||
}
|
||||
}else{
|
||||
if (buf_size < avctx->width / 2)
|
||||
goto packet_small;
|
||||
|
||||
offset= a->offset[y&3] - a->delta[ bytestream[2]&0xF ];
|
||||
|
||||
for(x=0; x<avctx->width; x+=8){
|
||||
@@ -112,6 +124,7 @@ static int decode_frame(AVCodecContext *avctx,
|
||||
luma[7]=( offset += a->delta[ bytestream[1]>>4 ]);
|
||||
luma += 8;
|
||||
bytestream+= 4;
|
||||
buf_size -= 4;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -120,6 +133,9 @@ static int decode_frame(AVCodecContext *avctx,
|
||||
*data_size = sizeof(AVPicture);
|
||||
|
||||
return buf_size;
|
||||
packet_small:
|
||||
av_log(avctx, AV_LOG_ERROR, "Input packet too small.\n");
|
||||
return AVERROR_INVALIDDATA;
|
||||
}
|
||||
|
||||
#if CONFIG_VCR1_ENCODER
|
||||
@@ -157,6 +173,11 @@ static av_cold int decode_init(AVCodecContext *avctx){
|
||||
|
||||
avctx->pix_fmt= PIX_FMT_YUV410P;
|
||||
|
||||
if (avctx->width & 7) {
|
||||
av_log(avctx, AV_LOG_ERROR, "Width %d is not divisble by 8.\n", avctx->width);
|
||||
return AVERROR_INVALIDDATA;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
+10
-3
@@ -134,9 +134,16 @@ static av_cold int vqa_decode_init(AVCodecContext *avctx)
|
||||
|
||||
/* load up the VQA parameters from the header */
|
||||
s->vqa_version = s->avctx->extradata[0];
|
||||
if (s->vqa_version < 1 || s->vqa_version > 3) {
|
||||
av_log(s->avctx, AV_LOG_ERROR, " VQA video: unsupported version %d\n", s->vqa_version);
|
||||
return -1;
|
||||
switch (s->vqa_version) {
|
||||
case 1:
|
||||
case 2:
|
||||
break;
|
||||
case 3:
|
||||
av_log_missing_feature(avctx, "VQA Version 3", 0);
|
||||
return AVERROR_PATCHWELCOME;
|
||||
default:
|
||||
av_log_missing_feature(avctx, "VQA Version", 1);
|
||||
return AVERROR_PATCHWELCOME;
|
||||
}
|
||||
s->width = AV_RL16(&s->avctx->extradata[6]);
|
||||
s->height = AV_RL16(&s->avctx->extradata[8]);
|
||||
|
||||
@@ -534,6 +534,10 @@ static int wma_decode_block(WMACodecContext *s)
|
||||
coef escape coding */
|
||||
total_gain = 1;
|
||||
for(;;) {
|
||||
if (get_bits_left(&s->gb) < 7) {
|
||||
av_log(s->avctx, AV_LOG_ERROR, "total_gain overread\n");
|
||||
return AVERROR_INVALIDDATA;
|
||||
}
|
||||
a = get_bits(&s->gb, 7);
|
||||
total_gain += a;
|
||||
if (a != 127)
|
||||
|
||||
+17
-4
@@ -1046,9 +1046,10 @@ static void aw_parse_coords(WMAVoiceContext *s, GetBitContext *gb,
|
||||
* @param gb bit I/O context
|
||||
* @param block_idx block index in frame [0, 1]
|
||||
* @param fcb structure containing fixed codebook vector info
|
||||
* @return -1 on error, 0 otherwise
|
||||
*/
|
||||
static void aw_pulse_set2(WMAVoiceContext *s, GetBitContext *gb,
|
||||
int block_idx, AMRFixed *fcb)
|
||||
static int aw_pulse_set2(WMAVoiceContext *s, GetBitContext *gb,
|
||||
int block_idx, AMRFixed *fcb)
|
||||
{
|
||||
uint16_t use_mask_mem[9]; // only 5 are used, rest is padding
|
||||
uint16_t *use_mask = use_mask_mem + 2;
|
||||
@@ -1110,7 +1111,7 @@ static void aw_pulse_set2(WMAVoiceContext *s, GetBitContext *gb,
|
||||
else if (use_mask[2]) idx = 0x2F;
|
||||
else if (use_mask[3]) idx = 0x3F;
|
||||
else if (use_mask[4]) idx = 0x4F;
|
||||
else return;
|
||||
else return -1;
|
||||
idx -= av_log2_16bit(use_mask[idx >> 4]);
|
||||
}
|
||||
if (use_mask[idx >> 4] & (0x8000 >> (idx & 15))) {
|
||||
@@ -1127,6 +1128,7 @@ static void aw_pulse_set2(WMAVoiceContext *s, GetBitContext *gb,
|
||||
/* set offset for next block, relative to start of that block */
|
||||
n = (MAX_FRAMESIZE / 2 - start_off) % fcb->pitch_lag;
|
||||
s->aw_next_pulse_off_cache = n ? fcb->pitch_lag - n : 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1289,7 +1291,18 @@ static void synth_block_fcb_acb(WMAVoiceContext *s, GetBitContext *gb,
|
||||
* (fixed) codebook pulses of the speech signal. */
|
||||
if (frame_desc->fcb_type == FCB_TYPE_AW_PULSES) {
|
||||
aw_pulse_set1(s, gb, block_idx, &fcb);
|
||||
aw_pulse_set2(s, gb, block_idx, &fcb);
|
||||
if (aw_pulse_set2(s, gb, block_idx, &fcb)) {
|
||||
/* Conceal the block with silence and return.
|
||||
* Skip the correct amount of bits to read the next
|
||||
* block from the correct offset. */
|
||||
int r_idx = pRNG(s->frame_cntr, block_idx, size);
|
||||
|
||||
for (n = 0; n < size; n++)
|
||||
excitation[n] =
|
||||
wmavoice_std_codebook[r_idx + n] * s->silence_gain;
|
||||
skip_bits(gb, 7 + 1);
|
||||
return;
|
||||
}
|
||||
} else /* FCB_TYPE_EXC_PULSES */ {
|
||||
int offset_nbits = 5 - frame_desc->log_n_blocks;
|
||||
|
||||
|
||||
@@ -3,8 +3,6 @@ OBJS-$(CONFIG_TRUEHD_DECODER) += x86/mlpdsp.o
|
||||
|
||||
YASM-OBJS-$(CONFIG_DCT) += x86/dct32_sse.o
|
||||
|
||||
YASM-OBJS-FFT-$(HAVE_AMD3DNOW) += x86/fft_3dn.o
|
||||
YASM-OBJS-FFT-$(HAVE_AMD3DNOWEXT) += x86/fft_3dn2.o
|
||||
YASM-OBJS-FFT-$(HAVE_SSE) += x86/fft_sse.o
|
||||
YASM-OBJS-$(CONFIG_FFT) += x86/fft_mmx.o \
|
||||
$(YASM-OBJS-FFT-yes)
|
||||
|
||||
@@ -86,7 +86,6 @@ AC3_EXPONENT_MIN sse2
|
||||
; This function uses 2 different methods to calculate a valid result.
|
||||
; 1) logical 'or' of abs of each element
|
||||
; This is used for ssse3 because of the pabsw instruction.
|
||||
; It is also used for mmx because of the lack of min/max instructions.
|
||||
; 2) calculate min/max for the array, then or(abs(min),abs(max))
|
||||
; This is used for mmxext and sse2 because they have pminsw/pmaxsw.
|
||||
;-----------------------------------------------------------------------------
|
||||
@@ -104,15 +103,9 @@ cglobal ac3_max_msb_abs_int16_%1, 2,2,5, src, len
|
||||
pmaxsw m3, m0
|
||||
pmaxsw m3, m1
|
||||
%else ; or_abs
|
||||
%ifidn %1, mmx
|
||||
mova m0, [srcq]
|
||||
mova m1, [srcq+mmsize]
|
||||
ABS2 m0, m1, m3, m4
|
||||
%else ; ssse3
|
||||
; using memory args is faster for ssse3
|
||||
pabsw m0, [srcq]
|
||||
pabsw m1, [srcq+mmsize]
|
||||
%endif
|
||||
por m2, m0
|
||||
por m2, m1
|
||||
%endif
|
||||
@@ -137,9 +130,7 @@ cglobal ac3_max_msb_abs_int16_%1, 2,2,5, src, len
|
||||
%endmacro
|
||||
|
||||
INIT_MMX
|
||||
%define ABS2 ABS2_MMX
|
||||
%define PSHUFLW pshufw
|
||||
AC3_MAX_MSB_ABS_INT16 mmx, or_abs
|
||||
%define ABS2 ABS2_MMX2
|
||||
AC3_MAX_MSB_ABS_INT16 mmxext, min_max
|
||||
INIT_XMM
|
||||
|
||||
@@ -27,7 +27,6 @@ extern void ff_ac3_exponent_min_mmx (uint8_t *exp, int num_reuse_blocks, int n
|
||||
extern void ff_ac3_exponent_min_mmxext(uint8_t *exp, int num_reuse_blocks, int nb_coefs);
|
||||
extern void ff_ac3_exponent_min_sse2 (uint8_t *exp, int num_reuse_blocks, int nb_coefs);
|
||||
|
||||
extern int ff_ac3_max_msb_abs_int16_mmx (const int16_t *src, int len);
|
||||
extern int ff_ac3_max_msb_abs_int16_mmxext(const int16_t *src, int len);
|
||||
extern int ff_ac3_max_msb_abs_int16_sse2 (const int16_t *src, int len);
|
||||
extern int ff_ac3_max_msb_abs_int16_ssse3 (const int16_t *src, int len);
|
||||
@@ -55,7 +54,6 @@ av_cold void ff_ac3dsp_init_x86(AC3DSPContext *c, int bit_exact)
|
||||
|
||||
if (mm_flags & AV_CPU_FLAG_MMX) {
|
||||
c->ac3_exponent_min = ff_ac3_exponent_min_mmx;
|
||||
c->ac3_max_msb_abs_int16 = ff_ac3_max_msb_abs_int16_mmx;
|
||||
c->ac3_lshift_int16 = ff_ac3_lshift_int16_mmx;
|
||||
c->ac3_rshift_int32 = ff_ac3_rshift_int32_mmx;
|
||||
}
|
||||
|
||||
@@ -39,16 +39,6 @@ av_cold void ff_fft_init_mmx(FFTContext *s)
|
||||
s->fft_permute = ff_fft_permute_sse;
|
||||
s->fft_calc = ff_fft_calc_sse;
|
||||
s->fft_permutation = FF_FFT_PERM_SWAP_LSBS;
|
||||
} else if (has_vectors & AV_CPU_FLAG_3DNOWEXT && HAVE_AMD3DNOWEXT) {
|
||||
/* 3DNowEx for K7 */
|
||||
s->imdct_calc = ff_imdct_calc_3dn2;
|
||||
s->imdct_half = ff_imdct_half_3dn2;
|
||||
s->fft_calc = ff_fft_calc_3dn2;
|
||||
} else if (has_vectors & AV_CPU_FLAG_3DNOW && HAVE_AMD3DNOW) {
|
||||
/* 3DNow! for K6-2/3 */
|
||||
s->imdct_calc = ff_imdct_calc_3dn;
|
||||
s->imdct_half = ff_imdct_half_3dn;
|
||||
s->fft_calc = ff_fft_calc_3dn;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -1,23 +0,0 @@
|
||||
/*
|
||||
* FFT/MDCT transform with 3DNow! optimizations
|
||||
* Copyright (c) 2008 Loren Merritt
|
||||
*
|
||||
* This file is part of FFmpeg.
|
||||
*
|
||||
* FFmpeg is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* FFmpeg is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with FFmpeg; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#define EMULATE_3DNOWEXT
|
||||
#include "fft_3dn2.c"
|
||||
@@ -1,174 +0,0 @@
|
||||
/*
|
||||
* FFT/MDCT transform with Extended 3DNow! optimizations
|
||||
* Copyright (c) 2006-2008 Zuxy MENG Jie, Loren Merritt
|
||||
*
|
||||
* This file is part of FFmpeg.
|
||||
*
|
||||
* FFmpeg is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* FFmpeg is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with FFmpeg; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include "libavutil/x86_cpu.h"
|
||||
#include "libavcodec/dsputil.h"
|
||||
#include "fft.h"
|
||||
|
||||
DECLARE_ALIGNED(8, static const unsigned int, m1m1)[2] = { 1U<<31, 1U<<31 };
|
||||
|
||||
#ifdef EMULATE_3DNOWEXT
|
||||
#define PSWAPD(s,d)\
|
||||
"movq "#s","#d"\n"\
|
||||
"psrlq $32,"#d"\n"\
|
||||
"punpckldq "#s","#d"\n"
|
||||
#define ff_fft_calc_3dn2 ff_fft_calc_3dn
|
||||
#define ff_fft_dispatch_3dn2 ff_fft_dispatch_3dn
|
||||
#define ff_fft_dispatch_interleave_3dn2 ff_fft_dispatch_interleave_3dn
|
||||
#define ff_imdct_calc_3dn2 ff_imdct_calc_3dn
|
||||
#define ff_imdct_half_3dn2 ff_imdct_half_3dn
|
||||
#else
|
||||
#define PSWAPD(s,d) "pswapd "#s","#d"\n"
|
||||
#endif
|
||||
|
||||
void ff_fft_dispatch_3dn2(FFTComplex *z, int nbits);
|
||||
void ff_fft_dispatch_interleave_3dn2(FFTComplex *z, int nbits);
|
||||
|
||||
void ff_fft_calc_3dn2(FFTContext *s, FFTComplex *z)
|
||||
{
|
||||
int n = 1<<s->nbits;
|
||||
int i;
|
||||
ff_fft_dispatch_interleave_3dn2(z, s->nbits);
|
||||
__asm__ volatile("femms");
|
||||
if(n <= 8)
|
||||
for(i=0; i<n; i+=2)
|
||||
FFSWAP(FFTSample, z[i].im, z[i+1].re);
|
||||
}
|
||||
|
||||
void ff_imdct_half_3dn2(FFTContext *s, FFTSample *output, const FFTSample *input)
|
||||
{
|
||||
x86_reg j, k;
|
||||
long n = s->mdct_size;
|
||||
long n2 = n >> 1;
|
||||
long n4 = n >> 2;
|
||||
long n8 = n >> 3;
|
||||
const uint16_t *revtab = s->revtab;
|
||||
const FFTSample *tcos = s->tcos;
|
||||
const FFTSample *tsin = s->tsin;
|
||||
const FFTSample *in1, *in2;
|
||||
FFTComplex *z = (FFTComplex *)output;
|
||||
|
||||
/* pre rotation */
|
||||
in1 = input;
|
||||
in2 = input + n2 - 1;
|
||||
#ifdef EMULATE_3DNOWEXT
|
||||
__asm__ volatile("movd %0, %%mm7" ::"r"(1U<<31));
|
||||
#endif
|
||||
for(k = 0; k < n4; k++) {
|
||||
// FIXME a single block is faster, but gcc 2.95 and 3.4.x on 32bit can't compile it
|
||||
__asm__ volatile(
|
||||
"movd %0, %%mm0 \n"
|
||||
"movd %2, %%mm1 \n"
|
||||
"punpckldq %1, %%mm0 \n"
|
||||
"punpckldq %3, %%mm1 \n"
|
||||
"movq %%mm0, %%mm2 \n"
|
||||
PSWAPD( %%mm1, %%mm3 )
|
||||
"pfmul %%mm1, %%mm0 \n"
|
||||
"pfmul %%mm3, %%mm2 \n"
|
||||
#ifdef EMULATE_3DNOWEXT
|
||||
"movq %%mm0, %%mm1 \n"
|
||||
"punpckhdq %%mm2, %%mm0 \n"
|
||||
"punpckldq %%mm2, %%mm1 \n"
|
||||
"pxor %%mm7, %%mm0 \n"
|
||||
"pfadd %%mm1, %%mm0 \n"
|
||||
#else
|
||||
"pfpnacc %%mm2, %%mm0 \n"
|
||||
#endif
|
||||
::"m"(in2[-2*k]), "m"(in1[2*k]),
|
||||
"m"(tcos[k]), "m"(tsin[k])
|
||||
);
|
||||
__asm__ volatile(
|
||||
"movq %%mm0, %0 \n\t"
|
||||
:"=m"(z[revtab[k]])
|
||||
);
|
||||
}
|
||||
|
||||
ff_fft_dispatch_3dn2(z, s->nbits);
|
||||
|
||||
#define CMUL(j,mm0,mm1)\
|
||||
"movq (%2,"#j",2), %%mm6 \n"\
|
||||
"movq 8(%2,"#j",2), "#mm0"\n"\
|
||||
"movq %%mm6, "#mm1"\n"\
|
||||
"movq "#mm0",%%mm7 \n"\
|
||||
"pfmul (%3,"#j"), %%mm6 \n"\
|
||||
"pfmul (%4,"#j"), "#mm0"\n"\
|
||||
"pfmul (%4,"#j"), "#mm1"\n"\
|
||||
"pfmul (%3,"#j"), %%mm7 \n"\
|
||||
"pfsub %%mm6, "#mm0"\n"\
|
||||
"pfadd %%mm7, "#mm1"\n"
|
||||
|
||||
/* post rotation */
|
||||
j = -n2;
|
||||
k = n2-8;
|
||||
__asm__ volatile(
|
||||
"1: \n"
|
||||
CMUL(%0, %%mm0, %%mm1)
|
||||
CMUL(%1, %%mm2, %%mm3)
|
||||
"movd %%mm0, (%2,%0,2) \n"
|
||||
"movd %%mm1,12(%2,%1,2) \n"
|
||||
"movd %%mm2, (%2,%1,2) \n"
|
||||
"movd %%mm3,12(%2,%0,2) \n"
|
||||
"psrlq $32, %%mm0 \n"
|
||||
"psrlq $32, %%mm1 \n"
|
||||
"psrlq $32, %%mm2 \n"
|
||||
"psrlq $32, %%mm3 \n"
|
||||
"movd %%mm0, 8(%2,%0,2) \n"
|
||||
"movd %%mm1, 4(%2,%1,2) \n"
|
||||
"movd %%mm2, 8(%2,%1,2) \n"
|
||||
"movd %%mm3, 4(%2,%0,2) \n"
|
||||
"sub $8, %1 \n"
|
||||
"add $8, %0 \n"
|
||||
"jl 1b \n"
|
||||
:"+r"(j), "+r"(k)
|
||||
:"r"(z+n8), "r"(tcos+n8), "r"(tsin+n8)
|
||||
:"memory"
|
||||
);
|
||||
__asm__ volatile("femms");
|
||||
}
|
||||
|
||||
void ff_imdct_calc_3dn2(FFTContext *s, FFTSample *output, const FFTSample *input)
|
||||
{
|
||||
x86_reg j, k;
|
||||
long n = s->mdct_size;
|
||||
long n4 = n >> 2;
|
||||
|
||||
ff_imdct_half_3dn2(s, output+n4, input);
|
||||
|
||||
j = -n;
|
||||
k = n-8;
|
||||
__asm__ volatile(
|
||||
"movq %4, %%mm7 \n"
|
||||
"1: \n"
|
||||
PSWAPD((%2,%1), %%mm0)
|
||||
PSWAPD((%3,%0), %%mm1)
|
||||
"pxor %%mm7, %%mm0 \n"
|
||||
"movq %%mm1, (%3,%1) \n"
|
||||
"movq %%mm0, (%2,%0) \n"
|
||||
"sub $8, %1 \n"
|
||||
"add $8, %0 \n"
|
||||
"jl 1b \n"
|
||||
:"+r"(j), "+r"(k)
|
||||
:"r"(output+n4), "r"(output+n4*3),
|
||||
"m"(*m1m1)
|
||||
);
|
||||
__asm__ volatile("femms");
|
||||
}
|
||||
|
||||
@@ -69,6 +69,11 @@ static int decode_frame(AVCodecContext *avctx,
|
||||
|
||||
stride = avctx->width - 4;
|
||||
|
||||
if (avctx->width % 4) {
|
||||
av_log(avctx, AV_LOG_ERROR, "Width not a multiple of 4.\n");
|
||||
return AVERROR_INVALIDDATA;
|
||||
}
|
||||
|
||||
if (buf_size < avctx->width * avctx->height) {
|
||||
av_log(avctx, AV_LOG_ERROR, "Packet is too small\n");
|
||||
return AVERROR_INVALIDDATA;
|
||||
|
||||
@@ -176,9 +176,9 @@ void avfilter_insert_pad(unsigned idx, unsigned *count, size_t padidx_off,
|
||||
(*links)[idx] = NULL;
|
||||
|
||||
(*count)++;
|
||||
for (i = idx+1; i < *count; i++)
|
||||
if (*links[i])
|
||||
(*(unsigned *)((uint8_t *) *links[i] + padidx_off))++;
|
||||
for (i = idx + 1; i < *count; i++)
|
||||
if ((*links)[i])
|
||||
(*(unsigned *)((uint8_t *) (*links)[i] + padidx_off))++;
|
||||
}
|
||||
|
||||
int avfilter_link(AVFilterContext *src, unsigned srcpad,
|
||||
|
||||
+3
-1
@@ -276,7 +276,9 @@ static int ape_read_header(AVFormatContext * s, AVFormatParameters * ap)
|
||||
ape->seektable = av_malloc(ape->seektablelength);
|
||||
if (!ape->seektable)
|
||||
return AVERROR(ENOMEM);
|
||||
for (i = 0; i < ape->seektablelength / sizeof(uint32_t); i++)
|
||||
for (i = 0;
|
||||
i < ape->seektablelength / sizeof(uint32_t) && !pb->eof_reached;
|
||||
i++)
|
||||
ape->seektable[i] = avio_rl32(pb);
|
||||
}else{
|
||||
av_log(s, AV_LOG_ERROR, "Missing seektable\n");
|
||||
|
||||
@@ -980,9 +980,12 @@ start_sync:
|
||||
}
|
||||
|
||||
|
||||
if( (st->discard >= AVDISCARD_DEFAULT && size==0)
|
||||
/*|| (st->discard >= AVDISCARD_NONKEY && !(pkt->flags & AV_PKT_FLAG_KEY))*/ //FIXME needs a little reordering
|
||||
|| st->discard >= AVDISCARD_ALL){
|
||||
if (!avi->dv_demux &&
|
||||
((st->discard >= AVDISCARD_DEFAULT && size==0) /* ||
|
||||
//FIXME needs a little reordering
|
||||
(st->discard >= AVDISCARD_NONKEY &&
|
||||
!(pkt->flags & AV_PKT_FLAG_KEY)) */
|
||||
|| st->discard >= AVDISCARD_ALL)) {
|
||||
if (!exit_early) {
|
||||
ast->frame_offset += get_duration(ast, size);
|
||||
avio_skip(pb, size);
|
||||
@@ -1280,7 +1283,7 @@ static int avi_read_idx1(AVFormatContext *s, int size)
|
||||
st = s->streams[index];
|
||||
ast = st->priv_data;
|
||||
|
||||
if(first_packet && first_packet_pos && len) {
|
||||
if (first_packet && first_packet_pos) {
|
||||
data_offset = first_packet_pos - pos;
|
||||
first_packet = 0;
|
||||
}
|
||||
|
||||
+1
-1
@@ -359,7 +359,7 @@ static inline int retry_transfer_wrapper(URLContext *h, unsigned char *buf, int
|
||||
else
|
||||
usleep(1000);
|
||||
} else if (ret < 1)
|
||||
return ret < 0 ? ret : len;
|
||||
return (ret < 0 && ret != AVERROR_EOF) ? ret : len;
|
||||
if (ret)
|
||||
fast_retries = FFMAX(fast_retries, 2);
|
||||
len += ret;
|
||||
|
||||
+2
-2
@@ -106,7 +106,7 @@ static const uint8_t* dv_extract_pack(uint8_t* frame, enum dv_pack_type t)
|
||||
* 3. Audio is always returned as 16bit linear samples: 12bit nonlinear samples
|
||||
* are converted into 16bit linear ones.
|
||||
*/
|
||||
static int dv_extract_audio(uint8_t* frame, uint8_t* ppcm[4],
|
||||
static int dv_extract_audio(uint8_t *frame, uint8_t **ppcm,
|
||||
const DVprofile *sys)
|
||||
{
|
||||
int size, chan, i, j, d, of, smpls, freq, quant, half_ch;
|
||||
@@ -374,7 +374,7 @@ int avpriv_dv_produce_packet(DVDemuxContext *c, AVPacket *pkt,
|
||||
uint8_t* buf, int buf_size, int64_t pos)
|
||||
{
|
||||
int size, i;
|
||||
uint8_t *ppcm[4] = {0};
|
||||
uint8_t *ppcm[5] = { 0 };
|
||||
|
||||
if (buf_size < DV_PROFILE_BYTES ||
|
||||
!(c->sys = avpriv_dv_frame_profile(c->sys, buf, buf_size)) ||
|
||||
|
||||
@@ -1114,7 +1114,8 @@ static void matroska_convert_tag(AVFormatContext *s, EbmlList *list,
|
||||
int i;
|
||||
|
||||
for (i=0; i < list->nb_elem; i++) {
|
||||
const char *lang = strcmp(tags[i].lang, "und") ? tags[i].lang : NULL;
|
||||
const char *lang = tags[i].lang && strcmp(tags[i].lang, "und") ?
|
||||
tags[i].lang : NULL;
|
||||
|
||||
if (!tags[i].name) {
|
||||
av_log(s, AV_LOG_WARNING, "Skipping invalid tag with no TagName.\n");
|
||||
@@ -2074,10 +2075,11 @@ static int matroska_read_seek(AVFormatContext *s, int stream_index,
|
||||
if (tracks[i].type == MATROSKA_TRACK_TYPE_SUBTITLE
|
||||
&& !tracks[i].stream->discard != AVDISCARD_ALL) {
|
||||
index_sub = av_index_search_timestamp(tracks[i].stream, st->index_entries[index].timestamp, AVSEEK_FLAG_BACKWARD);
|
||||
if (index_sub >= 0
|
||||
&& st->index_entries[index_sub].pos < st->index_entries[index_min].pos
|
||||
&& st->index_entries[index].timestamp - st->index_entries[index_sub].timestamp < 30000000000/matroska->time_scale)
|
||||
index_min = index_sub;
|
||||
while(index_sub >= 0
|
||||
&& index_min >= 0
|
||||
&& tracks[i].stream->index_entries[index_sub].pos < st->index_entries[index_min].pos
|
||||
&& st->index_entries[index].timestamp - tracks[i].stream->index_entries[index_sub].timestamp < 30000000000/matroska->time_scale)
|
||||
index_min--;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -360,6 +360,12 @@ static int mov_read_default(MOVContext *c, AVIOContext *pb, MOVAtom atom)
|
||||
left = a.size - avio_tell(pb) + start_pos;
|
||||
if (left > 0) /* skip garbage at atom end */
|
||||
avio_skip(pb, left);
|
||||
else if (left < 0) {
|
||||
av_log(c->fc, AV_LOG_WARNING,
|
||||
"overread end of atom '%.4s' by %"PRId64" bytes\n",
|
||||
(char*)&a.type, -left);
|
||||
avio_seek(pb, left, SEEK_CUR);
|
||||
}
|
||||
}
|
||||
|
||||
total_size += a.size;
|
||||
@@ -754,6 +760,11 @@ static int mov_read_mdhd(MOVContext *c, AVIOContext *pb, MOVAtom atom)
|
||||
st = c->fc->streams[c->fc->nb_streams-1];
|
||||
sc = st->priv_data;
|
||||
|
||||
if (sc->time_scale) {
|
||||
av_log(c->fc, AV_LOG_ERROR, "Multiple mdhd?\n");
|
||||
return AVERROR_INVALIDDATA;
|
||||
}
|
||||
|
||||
version = avio_r8(pb);
|
||||
if (version > 1) {
|
||||
av_log_ask_for_sample(c, "unsupported version %d\n", version);
|
||||
|
||||
@@ -375,7 +375,11 @@ static int ogg_packet(AVFormatContext *s, int *str, int *dstart, int *dsize,
|
||||
|
||||
if (!complete && os->segp == os->nsegs){
|
||||
ogg->curidx = -1;
|
||||
os->incomplete = 1;
|
||||
// Do not set incomplete for empty packets.
|
||||
// Together with the code in ogg_read_page
|
||||
// that discards all continuation of empty packets
|
||||
// we would get an infinite loop.
|
||||
os->incomplete = !!os->psize;
|
||||
}
|
||||
}while (!complete);
|
||||
|
||||
|
||||
@@ -208,15 +208,15 @@ vorbis_header (AVFormatContext * s, int idx)
|
||||
struct oggvorbis_private *priv;
|
||||
int pkt_type = os->buf[os->pstart];
|
||||
|
||||
if (!(pkt_type & 1))
|
||||
return 0;
|
||||
|
||||
if (!os->private) {
|
||||
os->private = av_mallocz(sizeof(struct oggvorbis_private));
|
||||
if (!os->private)
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!(pkt_type & 1))
|
||||
return 0;
|
||||
|
||||
if (os->psize < 1 || pkt_type > 5)
|
||||
return -1;
|
||||
|
||||
|
||||
+49
-22
@@ -113,13 +113,18 @@ static int kset(AVFormatContext *s, const uint8_t *r_val, const uint8_t *n_val,
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int rprobe(AVFormatContext *s, uint8_t *enc_header, const uint8_t *r_val)
|
||||
#define OMA_RPROBE_M_VAL 48 + 1
|
||||
|
||||
static int rprobe(AVFormatContext *s, uint8_t *enc_header, unsigned size,
|
||||
const uint8_t *r_val)
|
||||
{
|
||||
OMAContext *oc = s->priv_data;
|
||||
unsigned int pos;
|
||||
struct AVDES av_des;
|
||||
|
||||
if (!enc_header || !r_val)
|
||||
if (!enc_header || !r_val ||
|
||||
size < OMA_ENC_HEADER_SIZE + oc->k_size + oc->e_size + oc->i_size ||
|
||||
size < OMA_RPROBE_M_VAL)
|
||||
return -1;
|
||||
|
||||
/* m_val */
|
||||
@@ -140,19 +145,25 @@ static int rprobe(AVFormatContext *s, uint8_t *enc_header, const uint8_t *r_val)
|
||||
return memcmp(&enc_header[pos], oc->sm_val, 8) ? -1 : 0;
|
||||
}
|
||||
|
||||
static int nprobe(AVFormatContext *s, uint8_t *enc_header, int size, const uint8_t *n_val)
|
||||
static int nprobe(AVFormatContext *s, uint8_t *enc_header, unsigned size,
|
||||
const uint8_t *n_val)
|
||||
{
|
||||
OMAContext *oc = s->priv_data;
|
||||
uint32_t pos, taglen, datalen;
|
||||
uint64_t pos;
|
||||
uint32_t taglen, datalen;
|
||||
struct AVDES av_des;
|
||||
|
||||
if (!enc_header || !n_val)
|
||||
if (!enc_header || !n_val ||
|
||||
size < OMA_ENC_HEADER_SIZE + oc->k_size + 4)
|
||||
return -1;
|
||||
|
||||
pos = OMA_ENC_HEADER_SIZE + oc->k_size;
|
||||
if (!memcmp(&enc_header[pos], "EKB ", 4))
|
||||
pos += 32;
|
||||
|
||||
if (size < pos + 44)
|
||||
return -1;
|
||||
|
||||
if (AV_RB32(&enc_header[pos]) != oc->rid)
|
||||
av_log(s, AV_LOG_DEBUG, "Mismatching RID\n");
|
||||
|
||||
@@ -164,11 +175,14 @@ static int nprobe(AVFormatContext *s, uint8_t *enc_header, int size, const uint8
|
||||
|
||||
pos += 44 + taglen;
|
||||
|
||||
if (datalen << 4 > size - pos)
|
||||
return -1;
|
||||
|
||||
av_des_init(&av_des, n_val, 192, 1);
|
||||
while (datalen-- > 0) {
|
||||
av_des_crypt(&av_des, oc->r_val, &enc_header[pos], 2, NULL, 1);
|
||||
kset(s, oc->r_val, NULL, 16);
|
||||
if (!rprobe(s, enc_header, oc->r_val))
|
||||
if (!rprobe(s, enc_header, size, oc->r_val))
|
||||
return 0;
|
||||
pos += 16;
|
||||
}
|
||||
@@ -231,7 +245,7 @@ static int decrypt_init(AVFormatContext *s, ID3v2ExtraMeta *em, uint8_t *header)
|
||||
kset(s, s->key, s->key, s->keylen);
|
||||
}
|
||||
if (!memcmp(oc->r_val, (const uint8_t[8]){0}, 8) ||
|
||||
rprobe(s, gdata, oc->r_val) < 0 &&
|
||||
rprobe(s, gdata, geob->datasize, oc->r_val) < 0 &&
|
||||
nprobe(s, gdata, geob->datasize, oc->n_val) < 0) {
|
||||
int i;
|
||||
for (i = 0; i < FF_ARRAY_ELEMS(leaf_table); i += 2) {
|
||||
@@ -239,7 +253,8 @@ static int decrypt_init(AVFormatContext *s, ID3v2ExtraMeta *em, uint8_t *header)
|
||||
AV_WL64(buf, leaf_table[i]);
|
||||
AV_WL64(&buf[8], leaf_table[i+1]);
|
||||
kset(s, buf, buf, 16);
|
||||
if (!rprobe(s, gdata, oc->r_val) || !nprobe(s, gdata, geob->datasize, oc->n_val))
|
||||
if (!rprobe(s, gdata, geob->datasize, oc->r_val) ||
|
||||
!nprobe(s, gdata, geob->datasize, oc->n_val))
|
||||
break;
|
||||
}
|
||||
if (i >= sizeof(leaf_table)) {
|
||||
@@ -380,14 +395,22 @@ static int oma_read_packet(AVFormatContext *s, AVPacket *pkt)
|
||||
int packet_size = s->streams[0]->codec->block_align;
|
||||
int ret = av_get_packet(s->pb, pkt, packet_size);
|
||||
|
||||
if (ret < packet_size)
|
||||
pkt->flags |= AV_PKT_FLAG_CORRUPT;
|
||||
|
||||
if (ret <= 0)
|
||||
return AVERROR(EIO);
|
||||
|
||||
pkt->stream_index = 0;
|
||||
|
||||
if (oc->encrypted) {
|
||||
/* previous unencrypted block saved in IV for the next packet (CBC mode) */
|
||||
av_des_crypt(&oc->av_des, pkt->data, pkt->data, (packet_size >> 3), oc->iv, 1);
|
||||
/* previous unencrypted block saved in IV for
|
||||
* the next packet (CBC mode) */
|
||||
if (ret == packet_size)
|
||||
av_des_crypt(&oc->av_des, pkt->data, pkt->data,
|
||||
(packet_size >> 3), oc->iv, 1);
|
||||
else
|
||||
memset(oc->iv, 0, 8);
|
||||
}
|
||||
|
||||
return ret;
|
||||
@@ -425,22 +448,26 @@ static int oma_read_seek(struct AVFormatContext *s, int stream_index, int64_t ti
|
||||
{
|
||||
OMAContext *oc = s->priv_data;
|
||||
|
||||
pcm_read_seek(s, stream_index, timestamp, flags);
|
||||
int err = pcm_read_seek(s, stream_index, timestamp, flags);
|
||||
|
||||
if (oc->encrypted) {
|
||||
/* readjust IV for CBC */
|
||||
int64_t pos = avio_tell(s->pb);
|
||||
if (pos < oc->content_start)
|
||||
memset(oc->iv, 0, 8);
|
||||
else {
|
||||
if (avio_seek(s->pb, -8, SEEK_CUR) < 0 || avio_read(s->pb, oc->iv, 8) < 8) {
|
||||
memset(oc->iv, 0, 8);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
if (!oc->encrypted)
|
||||
return err;
|
||||
|
||||
/* readjust IV for CBC */
|
||||
if (err || avio_tell(s->pb) < oc->content_start)
|
||||
goto wipe;
|
||||
if ((err = avio_seek(s->pb, -8, SEEK_CUR)) < 0)
|
||||
goto wipe;
|
||||
if ((err = avio_read(s->pb, oc->iv, 8)) < 8) {
|
||||
if (err >= 0)
|
||||
err = AVERROR_EOF;
|
||||
goto wipe;
|
||||
}
|
||||
|
||||
return 0;
|
||||
wipe:
|
||||
memset(oc->iv, 0, 8);
|
||||
return err;
|
||||
}
|
||||
|
||||
AVInputFormat ff_oma_demuxer = {
|
||||
|
||||
+70
-37
@@ -75,26 +75,26 @@ int ff_rtmp_packet_read(URLContext *h, RTMPPacket *p,
|
||||
int chunk_size, RTMPPacket *prev_pkt)
|
||||
{
|
||||
uint8_t hdr, t, buf[16];
|
||||
int channel_id, timestamp, data_size, offset = 0;
|
||||
int channel_id, timestamp, size, offset = 0;
|
||||
uint32_t extra = 0;
|
||||
enum RTMPPacketType type;
|
||||
int size = 0;
|
||||
int written = 0;
|
||||
|
||||
if (ffurl_read(h, &hdr, 1) != 1)
|
||||
return AVERROR(EIO);
|
||||
size++;
|
||||
written++;
|
||||
channel_id = hdr & 0x3F;
|
||||
|
||||
if (channel_id < 2) { //special case for channel number >= 64
|
||||
buf[1] = 0;
|
||||
if (ffurl_read_complete(h, buf, channel_id + 1) != channel_id + 1)
|
||||
return AVERROR(EIO);
|
||||
size += channel_id + 1;
|
||||
written += channel_id + 1;
|
||||
channel_id = AV_RL16(buf) + 64;
|
||||
}
|
||||
data_size = prev_pkt[channel_id].data_size;
|
||||
type = prev_pkt[channel_id].type;
|
||||
extra = prev_pkt[channel_id].extra;
|
||||
size = prev_pkt[channel_id].size;
|
||||
type = prev_pkt[channel_id].type;
|
||||
extra = prev_pkt[channel_id].extra;
|
||||
|
||||
hdr >>= 6;
|
||||
if (hdr == RTMP_PS_ONEBYTE) {
|
||||
@@ -102,21 +102,21 @@ int ff_rtmp_packet_read(URLContext *h, RTMPPacket *p,
|
||||
} else {
|
||||
if (ffurl_read_complete(h, buf, 3) != 3)
|
||||
return AVERROR(EIO);
|
||||
size += 3;
|
||||
written += 3;
|
||||
timestamp = AV_RB24(buf);
|
||||
if (hdr != RTMP_PS_FOURBYTES) {
|
||||
if (ffurl_read_complete(h, buf, 3) != 3)
|
||||
return AVERROR(EIO);
|
||||
size += 3;
|
||||
data_size = AV_RB24(buf);
|
||||
written += 3;
|
||||
size = AV_RB24(buf);
|
||||
if (ffurl_read_complete(h, buf, 1) != 1)
|
||||
return AVERROR(EIO);
|
||||
size++;
|
||||
written++;
|
||||
type = buf[0];
|
||||
if (hdr == RTMP_PS_TWELVEBYTES) {
|
||||
if (ffurl_read_complete(h, buf, 4) != 4)
|
||||
return AVERROR(EIO);
|
||||
size += 4;
|
||||
written += 4;
|
||||
extra = AV_RL32(buf);
|
||||
}
|
||||
}
|
||||
@@ -129,33 +129,33 @@ int ff_rtmp_packet_read(URLContext *h, RTMPPacket *p,
|
||||
if (hdr != RTMP_PS_TWELVEBYTES)
|
||||
timestamp += prev_pkt[channel_id].timestamp;
|
||||
|
||||
if (ff_rtmp_packet_create(p, channel_id, type, timestamp, data_size))
|
||||
if (ff_rtmp_packet_create(p, channel_id, type, timestamp, size))
|
||||
return -1;
|
||||
p->extra = extra;
|
||||
// save history
|
||||
prev_pkt[channel_id].channel_id = channel_id;
|
||||
prev_pkt[channel_id].type = type;
|
||||
prev_pkt[channel_id].data_size = data_size;
|
||||
prev_pkt[channel_id].size = size;
|
||||
prev_pkt[channel_id].ts_delta = timestamp - prev_pkt[channel_id].timestamp;
|
||||
prev_pkt[channel_id].timestamp = timestamp;
|
||||
prev_pkt[channel_id].extra = extra;
|
||||
while (data_size > 0) {
|
||||
int toread = FFMIN(data_size, chunk_size);
|
||||
while (size > 0) {
|
||||
int toread = FFMIN(size, chunk_size);
|
||||
if (ffurl_read_complete(h, p->data + offset, toread) != toread) {
|
||||
ff_rtmp_packet_destroy(p);
|
||||
return AVERROR(EIO);
|
||||
}
|
||||
data_size -= chunk_size;
|
||||
offset += chunk_size;
|
||||
size += chunk_size;
|
||||
if (data_size > 0) {
|
||||
size -= chunk_size;
|
||||
offset += chunk_size;
|
||||
written += chunk_size;
|
||||
if (size > 0) {
|
||||
ffurl_read_complete(h, &t, 1); //marker
|
||||
size++;
|
||||
written++;
|
||||
if (t != (0xC0 + channel_id))
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
return size;
|
||||
return written;
|
||||
}
|
||||
|
||||
int ff_rtmp_packet_write(URLContext *h, RTMPPacket *pkt,
|
||||
@@ -164,7 +164,7 @@ int ff_rtmp_packet_write(URLContext *h, RTMPPacket *pkt,
|
||||
uint8_t pkt_hdr[16], *p = pkt_hdr;
|
||||
int mode = RTMP_PS_TWELVEBYTES;
|
||||
int off = 0;
|
||||
int size = 0;
|
||||
int written = 0;
|
||||
|
||||
pkt->ts_delta = pkt->timestamp - prev_pkt[pkt->channel_id].timestamp;
|
||||
|
||||
@@ -172,7 +172,7 @@ int ff_rtmp_packet_write(URLContext *h, RTMPPacket *pkt,
|
||||
if (prev_pkt[pkt->channel_id].channel_id &&
|
||||
pkt->extra == prev_pkt[pkt->channel_id].extra) {
|
||||
if (pkt->type == prev_pkt[pkt->channel_id].type &&
|
||||
pkt->data_size == prev_pkt[pkt->channel_id].data_size) {
|
||||
pkt->size == prev_pkt[pkt->channel_id].size) {
|
||||
mode = RTMP_PS_FOURBYTES;
|
||||
if (pkt->ts_delta == prev_pkt[pkt->channel_id].ts_delta)
|
||||
mode = RTMP_PS_ONEBYTE;
|
||||
@@ -196,7 +196,7 @@ int ff_rtmp_packet_write(URLContext *h, RTMPPacket *pkt,
|
||||
timestamp = pkt->ts_delta;
|
||||
bytestream_put_be24(&p, timestamp >= 0xFFFFFF ? 0xFFFFFF : timestamp);
|
||||
if (mode != RTMP_PS_FOURBYTES) {
|
||||
bytestream_put_be24(&p, pkt->data_size);
|
||||
bytestream_put_be24(&p, pkt->size);
|
||||
bytestream_put_byte(&p, pkt->type);
|
||||
if (mode == RTMP_PS_TWELVEBYTES)
|
||||
bytestream_put_le32(&p, pkt->extra);
|
||||
@@ -207,7 +207,7 @@ int ff_rtmp_packet_write(URLContext *h, RTMPPacket *pkt,
|
||||
// save history
|
||||
prev_pkt[pkt->channel_id].channel_id = pkt->channel_id;
|
||||
prev_pkt[pkt->channel_id].type = pkt->type;
|
||||
prev_pkt[pkt->channel_id].data_size = pkt->data_size;
|
||||
prev_pkt[pkt->channel_id].size = pkt->size;
|
||||
prev_pkt[pkt->channel_id].timestamp = pkt->timestamp;
|
||||
if (mode != RTMP_PS_TWELVEBYTES) {
|
||||
prev_pkt[pkt->channel_id].ts_delta = pkt->ts_delta;
|
||||
@@ -217,18 +217,18 @@ int ff_rtmp_packet_write(URLContext *h, RTMPPacket *pkt,
|
||||
prev_pkt[pkt->channel_id].extra = pkt->extra;
|
||||
|
||||
ffurl_write(h, pkt_hdr, p-pkt_hdr);
|
||||
size = p - pkt_hdr + pkt->data_size;
|
||||
while (off < pkt->data_size) {
|
||||
int towrite = FFMIN(chunk_size, pkt->data_size - off);
|
||||
written = p - pkt_hdr + pkt->size;
|
||||
while (off < pkt->size) {
|
||||
int towrite = FFMIN(chunk_size, pkt->size - off);
|
||||
ffurl_write(h, pkt->data + off, towrite);
|
||||
off += towrite;
|
||||
if (off < pkt->data_size) {
|
||||
if (off < pkt->size) {
|
||||
uint8_t marker = 0xC0 | pkt->channel_id;
|
||||
ffurl_write(h, &marker, 1);
|
||||
size++;
|
||||
written++;
|
||||
}
|
||||
}
|
||||
return size;
|
||||
return written;
|
||||
}
|
||||
|
||||
int ff_rtmp_packet_create(RTMPPacket *pkt, int channel_id, RTMPPacketType type,
|
||||
@@ -239,7 +239,7 @@ int ff_rtmp_packet_create(RTMPPacket *pkt, int channel_id, RTMPPacketType type,
|
||||
if (!pkt->data)
|
||||
return AVERROR(ENOMEM);
|
||||
}
|
||||
pkt->data_size = size;
|
||||
pkt->size = size;
|
||||
pkt->channel_id = channel_id;
|
||||
pkt->type = type;
|
||||
pkt->timestamp = timestamp;
|
||||
@@ -254,7 +254,7 @@ void ff_rtmp_packet_destroy(RTMPPacket *pkt)
|
||||
if (!pkt)
|
||||
return;
|
||||
av_freep(&pkt->data);
|
||||
pkt->data_size = 0;
|
||||
pkt->size = 0;
|
||||
}
|
||||
|
||||
int ff_amf_tag_size(const uint8_t *data, const uint8_t *data_end)
|
||||
@@ -425,9 +425,9 @@ static void ff_amf_tag_contents(void *ctx, const uint8_t *data, const uint8_t *d
|
||||
void ff_rtmp_packet_dump(void *ctx, RTMPPacket *p)
|
||||
{
|
||||
av_log(ctx, AV_LOG_DEBUG, "RTMP packet type '%s'(%d) for channel %d, timestamp %d, extra field %d size %d\n",
|
||||
rtmp_packet_type(p->type), p->type, p->channel_id, p->timestamp, p->extra, p->data_size);
|
||||
rtmp_packet_type(p->type), p->type, p->channel_id, p->timestamp, p->extra, p->size);
|
||||
if (p->type == RTMP_PT_INVOKE || p->type == RTMP_PT_NOTIFY) {
|
||||
uint8_t *src = p->data, *src_end = p->data + p->data_size;
|
||||
uint8_t *src = p->data, *src_end = p->data + p->size;
|
||||
while (src < src_end) {
|
||||
int sz;
|
||||
ff_amf_tag_contents(ctx, src, src_end);
|
||||
@@ -442,8 +442,41 @@ void ff_rtmp_packet_dump(void *ctx, RTMPPacket *p)
|
||||
av_log(ctx, AV_LOG_DEBUG, "Client BW = %d\n", AV_RB32(p->data));
|
||||
} else if (p->type != RTMP_PT_AUDIO && p->type != RTMP_PT_VIDEO && p->type != RTMP_PT_METADATA) {
|
||||
int i;
|
||||
for (i = 0; i < p->data_size; i++)
|
||||
for (i = 0; i < p->size; i++)
|
||||
av_log(ctx, AV_LOG_DEBUG, " %02X", p->data[i]);
|
||||
av_log(ctx, AV_LOG_DEBUG, "\n");
|
||||
}
|
||||
}
|
||||
|
||||
int ff_amf_match_string(const uint8_t *data, int size, const char *str)
|
||||
{
|
||||
int len = strlen(str);
|
||||
int amf_len, type;
|
||||
|
||||
if (size < 1)
|
||||
return 0;
|
||||
|
||||
type = *data++;
|
||||
|
||||
if (type != AMF_DATA_TYPE_LONG_STRING &&
|
||||
type != AMF_DATA_TYPE_STRING)
|
||||
return 0;
|
||||
|
||||
if (type == AMF_DATA_TYPE_LONG_STRING) {
|
||||
if ((size -= 4 + 1) < 0)
|
||||
return 0;
|
||||
amf_len = bytestream_get_be32(&data);
|
||||
} else {
|
||||
if ((size -= 2 + 1) < 0)
|
||||
return 0;
|
||||
amf_len = bytestream_get_be16(&data);
|
||||
}
|
||||
|
||||
if (amf_len > size)
|
||||
return 0;
|
||||
|
||||
if (amf_len != len)
|
||||
return 0;
|
||||
|
||||
return !memcmp(data, str, len);
|
||||
}
|
||||
|
||||
@@ -80,7 +80,7 @@ typedef struct RTMPPacket {
|
||||
uint32_t ts_delta; ///< timestamp increment to the previous one in milliseconds (latter only for media packets)
|
||||
uint32_t extra; ///< probably an additional channel ID used during streaming data
|
||||
uint8_t *data; ///< packet payload
|
||||
int data_size; ///< packet payload size
|
||||
int size; ///< packet payload size
|
||||
} RTMPPacket;
|
||||
|
||||
/**
|
||||
@@ -218,6 +218,13 @@ void ff_amf_write_field_name(uint8_t **dst, const char *str);
|
||||
*/
|
||||
void ff_amf_write_object_end(uint8_t **dst);
|
||||
|
||||
/**
|
||||
* Match AMF string with a NULL-terminated string.
|
||||
*
|
||||
* @return 0 if the strings do not match.
|
||||
*/
|
||||
int ff_amf_match_string(const uint8_t *data, int size, const char *str);
|
||||
|
||||
/** @} */ // AMF funcs
|
||||
|
||||
#endif /* AVFORMAT_RTMPPKT_H */
|
||||
|
||||
+22
-21
@@ -147,7 +147,7 @@ static void gen_connect(URLContext *s, RTMPContext *rt, const char *proto,
|
||||
}
|
||||
ff_amf_write_object_end(&p);
|
||||
|
||||
pkt.data_size = p - pkt.data;
|
||||
pkt.size = p - pkt.data;
|
||||
|
||||
ff_rtmp_packet_write(rt->stream, &pkt, rt->chunk_size, rt->prev_pkt[1]);
|
||||
ff_rtmp_packet_destroy(&pkt);
|
||||
@@ -549,7 +549,7 @@ static int rtmp_handshake(URLContext *s, RTMPContext *rt)
|
||||
static int rtmp_parse_result(URLContext *s, RTMPContext *rt, RTMPPacket *pkt)
|
||||
{
|
||||
int i, t;
|
||||
const uint8_t *data_end = pkt->data + pkt->data_size;
|
||||
const uint8_t *data_end = pkt->data + pkt->size;
|
||||
|
||||
#ifdef DEBUG
|
||||
ff_rtmp_packet_dump(s, pkt);
|
||||
@@ -557,9 +557,9 @@ static int rtmp_parse_result(URLContext *s, RTMPContext *rt, RTMPPacket *pkt)
|
||||
|
||||
switch (pkt->type) {
|
||||
case RTMP_PT_CHUNK_SIZE:
|
||||
if (pkt->data_size != 4) {
|
||||
if (pkt->size != 4) {
|
||||
av_log(s, AV_LOG_ERROR,
|
||||
"Chunk size change packet is not 4 bytes long (%d)\n", pkt->data_size);
|
||||
"Chunk size change packet is not 4 bytes long (%d)\n", pkt->size);
|
||||
return -1;
|
||||
}
|
||||
if (!rt->is_input)
|
||||
@@ -577,10 +577,10 @@ static int rtmp_parse_result(URLContext *s, RTMPContext *rt, RTMPPacket *pkt)
|
||||
gen_pong(s, rt, pkt);
|
||||
break;
|
||||
case RTMP_PT_CLIENT_BW:
|
||||
if (pkt->data_size < 4) {
|
||||
if (pkt->size < 4) {
|
||||
av_log(s, AV_LOG_ERROR,
|
||||
"Client bandwidth report packet is less than 4 bytes long (%d)\n",
|
||||
pkt->data_size);
|
||||
pkt->size);
|
||||
return -1;
|
||||
}
|
||||
av_log(s, AV_LOG_DEBUG, "Client bandwidth = %d\n", AV_RB32(pkt->data));
|
||||
@@ -588,14 +588,14 @@ static int rtmp_parse_result(URLContext *s, RTMPContext *rt, RTMPPacket *pkt)
|
||||
break;
|
||||
case RTMP_PT_INVOKE:
|
||||
//TODO: check for the messages sent for wrong state?
|
||||
if (!memcmp(pkt->data, "\002\000\006_error", 9)) {
|
||||
if (ff_amf_match_string(pkt->data, pkt->size, "_error")) {
|
||||
uint8_t tmpstr[256];
|
||||
|
||||
if (!ff_amf_get_field_value(pkt->data + 9, data_end,
|
||||
"description", tmpstr, sizeof(tmpstr)))
|
||||
av_log(s, AV_LOG_ERROR, "Server error: %s\n",tmpstr);
|
||||
return -1;
|
||||
} else if (!memcmp(pkt->data, "\002\000\007_result", 10)) {
|
||||
} else if (ff_amf_match_string(pkt->data, pkt->size, "_result")) {
|
||||
switch (rt->state) {
|
||||
case STATE_HANDSHAKED:
|
||||
if (!rt->is_input) {
|
||||
@@ -636,7 +636,7 @@ static int rtmp_parse_result(URLContext *s, RTMPContext *rt, RTMPPacket *pkt)
|
||||
rt->state = STATE_READY;
|
||||
break;
|
||||
}
|
||||
} else if (!memcmp(pkt->data, "\002\000\010onStatus", 11)) {
|
||||
} else if (ff_amf_match_string(pkt->data, pkt->size, "onStatus")) {
|
||||
const uint8_t* ptr = pkt->data + 11;
|
||||
uint8_t tmpstr[256];
|
||||
|
||||
@@ -683,7 +683,7 @@ static int get_packet(URLContext *s, int for_header)
|
||||
int ret;
|
||||
uint8_t *p;
|
||||
const uint8_t *next;
|
||||
uint32_t data_size;
|
||||
uint32_t size;
|
||||
uint32_t ts, cts, pts=0;
|
||||
|
||||
if (rt->state == STATE_STOPPED)
|
||||
@@ -719,38 +719,39 @@ static int get_packet(URLContext *s, int for_header)
|
||||
ff_rtmp_packet_destroy(&rpkt);
|
||||
return 0;
|
||||
}
|
||||
if (!rpkt.data_size || !rt->is_input) {
|
||||
if (!rpkt.size || !rt->is_input) {
|
||||
ff_rtmp_packet_destroy(&rpkt);
|
||||
continue;
|
||||
}
|
||||
if (rpkt.type == RTMP_PT_VIDEO || rpkt.type == RTMP_PT_AUDIO ||
|
||||
(rpkt.type == RTMP_PT_NOTIFY && !memcmp("\002\000\012onMetaData", rpkt.data, 13))) {
|
||||
(rpkt.type == RTMP_PT_NOTIFY &&
|
||||
ff_amf_match_string(rpkt.data, rpkt.size, "onMetaData"))) {
|
||||
ts = rpkt.timestamp;
|
||||
|
||||
// generate packet header and put data into buffer for FLV demuxer
|
||||
rt->flv_off = 0;
|
||||
rt->flv_size = rpkt.data_size + 15;
|
||||
rt->flv_size = rpkt.size + 15;
|
||||
rt->flv_data = p = av_realloc(rt->flv_data, rt->flv_size);
|
||||
bytestream_put_byte(&p, rpkt.type);
|
||||
bytestream_put_be24(&p, rpkt.data_size);
|
||||
bytestream_put_be24(&p, rpkt.size);
|
||||
bytestream_put_be24(&p, ts);
|
||||
bytestream_put_byte(&p, ts >> 24);
|
||||
bytestream_put_be24(&p, 0);
|
||||
bytestream_put_buffer(&p, rpkt.data, rpkt.data_size);
|
||||
bytestream_put_buffer(&p, rpkt.data, rpkt.size);
|
||||
bytestream_put_be32(&p, 0);
|
||||
ff_rtmp_packet_destroy(&rpkt);
|
||||
return 0;
|
||||
} else if (rpkt.type == RTMP_PT_METADATA) {
|
||||
// we got raw FLV data, make it available for FLV demuxer
|
||||
rt->flv_off = 0;
|
||||
rt->flv_size = rpkt.data_size;
|
||||
rt->flv_size = rpkt.size;
|
||||
rt->flv_data = av_realloc(rt->flv_data, rt->flv_size);
|
||||
/* rewrite timestamps */
|
||||
next = rpkt.data;
|
||||
ts = rpkt.timestamp;
|
||||
while (next - rpkt.data < rpkt.data_size - 11) {
|
||||
while (next - rpkt.data < rpkt.size - 11) {
|
||||
next++;
|
||||
data_size = bytestream_get_be24(&next);
|
||||
size = bytestream_get_be24(&next);
|
||||
p=next;
|
||||
cts = bytestream_get_be24(&next);
|
||||
cts |= bytestream_get_byte(&next) << 24;
|
||||
@@ -760,9 +761,9 @@ static int get_packet(URLContext *s, int for_header)
|
||||
pts = cts;
|
||||
bytestream_put_be24(&p, ts);
|
||||
bytestream_put_byte(&p, ts >> 24);
|
||||
next += data_size + 3 + 4;
|
||||
next += size + 3 + 4;
|
||||
}
|
||||
memcpy(rt->flv_data, rpkt.data, rpkt.data_size);
|
||||
memcpy(rt->flv_data, rpkt.data, rpkt.size);
|
||||
ff_rtmp_packet_destroy(&rpkt);
|
||||
return 0;
|
||||
}
|
||||
@@ -776,7 +777,7 @@ static int rtmp_close(URLContext *h)
|
||||
|
||||
if (!rt->is_input) {
|
||||
rt->flv_data = NULL;
|
||||
if (rt->out_pkt.data_size)
|
||||
if (rt->out_pkt.size)
|
||||
ff_rtmp_packet_destroy(&rt->out_pkt);
|
||||
if (rt->state > STATE_FCPUBLISH)
|
||||
gen_fcunpublish_stream(h, rt);
|
||||
|
||||
@@ -211,6 +211,8 @@ static int film_read_header(AVFormatContext *s,
|
||||
film->sample_table[i].sample_offset =
|
||||
data_offset + AV_RB32(&scratch[0]);
|
||||
film->sample_table[i].sample_size = AV_RB32(&scratch[4]);
|
||||
if (film->sample_table[i].sample_size > INT_MAX / 4)
|
||||
return AVERROR_INVALIDDATA;
|
||||
if (AV_RB32(&scratch[8]) == 0xFFFFFFFF) {
|
||||
film->sample_table[i].stream = film->audio_stream_index;
|
||||
film->sample_table[i].pts = audio_frame_counter;
|
||||
|
||||
+11
-4
@@ -1083,12 +1083,14 @@ static void compute_pkt_fields(AVFormatContext *s, AVStream *st,
|
||||
if (pkt->dts != AV_NOPTS_VALUE) {
|
||||
// got DTS from the stream, update reference timestamp
|
||||
st->reference_dts = pkt->dts - pc->dts_ref_dts_delta * num / den;
|
||||
pkt->pts = pkt->dts + pc->pts_dts_delta * num / den;
|
||||
} else if (st->reference_dts != AV_NOPTS_VALUE) {
|
||||
// compute DTS based on reference timestamp
|
||||
pkt->dts = st->reference_dts + pc->dts_ref_dts_delta * num / den;
|
||||
pkt->pts = pkt->dts + pc->pts_dts_delta * num / den;
|
||||
}
|
||||
|
||||
if (st->reference_dts != AV_NOPTS_VALUE && pkt->pts == AV_NOPTS_VALUE)
|
||||
pkt->pts = pkt->dts + pc->pts_dts_delta * num / den;
|
||||
|
||||
if (pc->dts_sync_point > 0)
|
||||
st->reference_dts = pkt->dts; // new reference
|
||||
}
|
||||
@@ -2057,8 +2059,13 @@ static void estimate_timings_from_bit_rate(AVFormatContext *ic)
|
||||
bit_rate = 0;
|
||||
for(i=0;i<ic->nb_streams;i++) {
|
||||
st = ic->streams[i];
|
||||
if (st->codec->bit_rate > 0)
|
||||
bit_rate += st->codec->bit_rate;
|
||||
if (st->codec->bit_rate > 0) {
|
||||
if (INT_MAX - st->codec->bit_rate < bit_rate) {
|
||||
bit_rate = 0;
|
||||
break;
|
||||
}
|
||||
bit_rate += st->codec->bit_rate;
|
||||
}
|
||||
}
|
||||
ic->bit_rate = bit_rate;
|
||||
}
|
||||
|
||||
@@ -104,7 +104,6 @@ static int wsvqa_read_header(AVFormatContext *s,
|
||||
header = (unsigned char *)st->codec->extradata;
|
||||
if (avio_read(pb, st->codec->extradata, VQA_HEADER_SIZE) !=
|
||||
VQA_HEADER_SIZE) {
|
||||
av_free(st->codec->extradata);
|
||||
return AVERROR(EIO);
|
||||
}
|
||||
st->codec->width = AV_RL16(&header[6]);
|
||||
|
||||
@@ -423,6 +423,7 @@ static void get_attachment(AVFormatContext *s, AVIOContext *pb, int length)
|
||||
st->codec->codec_id = CODEC_ID_MJPEG;
|
||||
st->codec->codec_type = AVMEDIA_TYPE_ATTACHMENT;
|
||||
st->codec->extradata = av_mallocz(filesize);
|
||||
st->id = -1;
|
||||
if (!st->codec->extradata)
|
||||
goto done;
|
||||
st->codec->extradata_size = filesize;
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
1, 20898, 4096, 0x28f7c6e5
|
||||
0, 21021, 460800, 0x4b7f4df0
|
||||
1, 22988, 4096, 0xca9d9df2
|
||||
0, 24024, 460800, 0xa57f20d0
|
||||
1, 25078, 4096, 0x5c6b95a9
|
||||
1, 27167, 4096, 0x0bdfc0bf
|
||||
1, 29257, 4096, 0xd95a9277
|
||||
|
||||
Reference in New Issue
Block a user