* qatar/master: (34 commits) mlp_parser: fix the channel mask value used for the top surround channel vorbisenc: check all allocations for failure roqaudioenc: return AVERROR codes instead of -1 roqaudioenc: set correct bit rate roqaudioenc: use AVCodecContext.frame_size correctly. roqaudioenc: remove unneeded sample_fmt check ra144enc: use int16_t* for input samples rather than void* ra144enc: set AVCodecContext.coded_frame ra144enc: remove unneeded sample_fmt check nellymoserenc: set AVCodecContext.coded_frame nellymoserenc: improve error checking in encode_init() nellymoserenc: return AVERROR codes instead of -1 libvorbis: improve error checking in oggvorbis_encode_init() mpegaudioenc: return AVERROR codes instead of -1 libfaac: improve error checking and handling in Faac_encode_init() avutil: add AVERROR_UNKNOWN check for coded_frame allocation failure in several audio encoders audio encoders: do not set coded_frame->key_frame. g722enc: check for trellis data allocation error libspeexenc: export encoder delay through AVCodecContext.delay ... Conflicts: doc/APIchanges libavcodec/avcodec.h libavcodec/fraps.c libavcodec/kgv1dec.c libavcodec/libfaac.c libavcodec/libgsm.c libavcodec/libvorbis.c libavcodec/mlp_parser.c libavcodec/roqaudioenc.c libavcodec/vorbisenc.c libavutil/avutil.h libavutil/error.c libavutil/error.h
Unified · Split
| @@ -35,6 +35,9 @@ API changes, most recent first: · 34 unmodified lines | ||
| 35 | 35 | 2012-01-24 - xxxxxxx - lavfi 2.60.100 |
| 36 | 36 | Add avfilter_graph_dump. |
| 37 | 37 | |
| 38 | +2012-xx-xx - xxxxxxx - lavu 51.24.0 - error.h | |
| 39 | + Add AVERROR_UNKNOWN | |
| 40 | + | |
| 38 | 41 | 2012-xx-xx - xxxxxxx - lavc 54.x.x |
| 39 | 42 | Add duration field to AVCodecParserContext |
| 40 | 43 | |
| @@ -1372,6 +1372,19 @@ typedef struct AVCodecContext { · 1371 unmodified lines | ||
| 1372 | 1372 | * the decoder output. (we assume the decoder matches the spec) |
| 1373 | 1373 | * Decoding: Number of frames delay in addition to what a standard decoder |
| 1374 | 1374 | * as specified in the spec would produce. |
| 1375 | + * | |
| 1376 | + * Video: | |
| 1377 | + * Number of frames the decoded output will be delayed relative to the | |
| 1378 | + * encoded input. | |
| 1379 | + * | |
| 1380 | + * Audio: | |
| 1381 | + * Number of "priming" samples added to the beginning of the stream | |
| 1382 | + * during encoding. The decoded output will be delayed by this many | |
| 1383 | + * samples relative to the input to the encoder. Note that this field is | |
| 1384 | + * purely informational and does not directly affect the pts output by | |
| 1385 | + * the encoder, which should always be based on the actual presentation | |
| 1386 | + * time, including any delay. | |
| 1387 | + * | |
| 1375 | 1388 | * - encoding: Set by libavcodec. |
| 1376 | 1389 | * - decoding: Set by libavcodec. |
| 1377 | 1390 | */ |
| @@ -122,7 +122,7 @@ static void cdxl_decode_ham6(CDXLVideoContext *c) · 121 unmodified lines | ||
| 122 | 122 | g = index * 0x11 << 8; |
| 123 | 123 | break; |
| 124 | 124 | } |
| 125 | − AV_WN32(out + x * 3, r | g | b); | |
| 125 | + AV_WL24(out + x * 3, r | g | b); | |
| 126 | 126 | } |
| 127 | 127 | out += c->frame.linesize[0]; |
| 128 | 128 | } |
| @@ -165,7 +165,7 @@ static void cdxl_decode_ham8(CDXLVideoContext *c) · 36 unmodified lines | ||
| 165 | 165 | g = (index << 10) | (g & (3 << 8)); |
| 166 | 166 | break; |
| 167 | 167 | } |
| 168 | − AV_WN32(out + x * 3, r | g | b); | |
| 168 | + AV_WL24(out + x * 3, r | g | b); | |
| 169 | 169 | } |
| 170 | 170 | out += c->frame.linesize[0]; |
| 171 | 171 | } |
| @@ -142,7 +142,7 @@ static int decode_frame(AVCodecContext *avctx, · 141 unmodified lines | ||
| 142 | 142 | int i, j, is_chroma; |
| 143 | 143 | const int planes = 3; |
| 144 | 144 | uint8_t *out; |
| 145 | − | |
| 145 | + enum PixelFormat pix_fmt; | |
| 146 | 146 | |
| 147 | 147 | header = AV_RL32(buf); |
| 148 | 148 | version = header & 0xff; |
| @@ -157,8 +157,6 @@ static int decode_frame(AVCodecContext *avctx, · 8 unmodified lines | ||
| 157 | 157 | |
| 158 | 158 | buf += header_size; |
| 159 | 159 | |
| 160 | − avctx->pix_fmt = version & 1 ? PIX_FMT_BGR24 : PIX_FMT_YUVJ420P; | |
| 161 | − | |
| 162 | 160 | if (version < 2) { |
| 163 | 161 | unsigned needed_size = avctx->width*avctx->height*3; |
| 164 | 162 | if (version == 0) needed_size /= 2; |
| @@ -205,6 +203,13 @@ static int decode_frame(AVCodecContext *avctx, · 40 unmodified lines | ||
| 205 | 203 | f->key_frame = 1; |
| 206 | 204 | f->reference = 0; |
| 207 | 205 | f->buffer_hints = FF_BUFFER_HINTS_VALID; |
| 206 | + | |
| 207 | + pix_fmt = version & 1 ? PIX_FMT_BGR24 : PIX_FMT_YUVJ420P; | |
| 208 | + if (avctx->pix_fmt != pix_fmt && f->data[0]) { | |
| 209 | + avctx->release_buffer(avctx, f); | |
| 210 | + } | |
| 211 | + avctx->pix_fmt = pix_fmt; | |
| 212 | + | |
| 208 | 213 | if (ff_thread_get_buffer(avctx, f)) { |
| 209 | 214 | av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); |
| 210 | 215 | return -1; |
| @@ -41,9 +41,22 @@ · 40 unmodified lines | ||
| 41 | 41 | #define MIN_TRELLIS 0 |
| 42 | 42 | #define MAX_TRELLIS 16 |
| 43 | 43 | |
| 44 | +static av_cold int g722_encode_close(AVCodecContext *avctx) | |
| 45 | +{ | |
| 46 | + G722Context *c = avctx->priv_data; | |
| 47 | + int i; | |
| 48 | + for (i = 0; i < 2; i++) { | |
| 49 | + av_freep(&c->paths[i]); | |
| 50 | + av_freep(&c->node_buf[i]); | |
| 51 | + av_freep(&c->nodep_buf[i]); | |
| 52 | + } | |
| 53 | + return 0; | |
| 54 | +} | |
| 55 | + | |
| 44 | 56 | static av_cold int g722_encode_init(AVCodecContext * avctx) |
| 45 | 57 | { |
| 46 | 58 | G722Context *c = avctx->priv_data; |
| 59 | + int ret; | |
| 47 | 60 | |
| 48 | 61 | if (avctx->channels != 1) { |
| 49 | 62 | av_log(avctx, AV_LOG_ERROR, "Only mono tracks are allowed.\n"); |
| @@ -62,6 +75,10 @@ static av_cold int g722_encode_init(AVCodecContext * avctx) · 12 unmodified lines | ||
| 62 | 75 | c->paths[i] = av_mallocz(max_paths * sizeof(**c->paths)); |
| 63 | 76 | c->node_buf[i] = av_mallocz(2 * frontier * sizeof(**c->node_buf)); |
| 64 | 77 | c->nodep_buf[i] = av_mallocz(2 * frontier * sizeof(**c->nodep_buf)); |
| 78 | + if (!c->paths[i] || !c->node_buf[i] || !c->nodep_buf[i]) { | |
| 79 | + ret = AVERROR(ENOMEM); | |
| 80 | + goto error; | |
| 81 | + } | |
| 65 | 82 | } |
| 66 | 83 | } |
| 67 | 84 | |
| @@ -100,18 +117,9 @@ static av_cold int g722_encode_init(AVCodecContext * avctx) · 32 unmodified lines | ||
| 100 | 117 | } |
| 101 | 118 | |
| 102 | 119 | return 0; |
| 103 | −} | |
| 104 | − | |
| 105 | −static av_cold int g722_encode_close(AVCodecContext *avctx) | |
| 106 | −{ | |
| 107 | − G722Context *c = avctx->priv_data; | |
| 108 | − int i; | |
| 109 | − for (i = 0; i < 2; i++) { | |
| 110 | − av_freep(&c->paths[i]); | |
| 111 | − av_freep(&c->node_buf[i]); | |
| 112 | − av_freep(&c->nodep_buf[i]); | |
| 113 | − } | |
| 114 | − return 0; | |
| 120 | +error: | |
| 121 | + g722_encode_close(avctx); | |
| 122 | + return ret; | |
| 115 | 123 | } |
| 116 | 124 | |
| 117 | 125 | static const int16_t low_quant[33] = { |
| @@ -30,10 +30,17 @@ · 29 unmodified lines | ||
| 30 | 30 | |
| 31 | 31 | typedef struct { |
| 32 | 32 | AVCodecContext *avctx; |
| 33 | − AVFrame pic; | |
| 34 | − uint16_t *prev, *cur; | |
| 33 | + AVFrame prev, cur; | |
| 35 | 34 | } KgvContext; |
| 36 | 35 | |
| 36 | +static void decode_flush(AVCodecContext *avctx) | |
| 37 | +{ | |
| 38 | + KgvContext * const c = avctx->priv_data; | |
| 39 | + | |
| 40 | + if (c->prev.data[0]) | |
| 41 | + avctx->release_buffer(avctx, &c->prev); | |
| 42 | +} | |
| 43 | + | |
| 37 | 44 | static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, AVPacket *avpkt) |
| 38 | 45 | { |
| 39 | 46 | const uint8_t *buf = avpkt->data; |
| @@ -42,7 +49,7 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, AVPac · 2 unmodified lines | ||
| 42 | 49 | int offsets[8]; |
| 43 | 50 | uint16_t *out, *prev; |
| 44 | 51 | int outcnt = 0, maxcnt; |
| 45 | − int w, h, i; | |
| 52 | + int w, h, i, res; | |
| 46 | 53 | |
| 47 | 54 | if (avpkt->size < 2) |
| 48 | 55 | return -1; |
| @@ -54,20 +61,23 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, AVPac · 5 unmodified lines | ||
| 54 | 61 | if (av_image_check_size(w, h, 0, avctx)) |
| 55 | 62 | return -1; |
| 56 | 63 | |
| 57 | − if (w != avctx->width || h != avctx->height) | |
| 64 | + if (w != avctx->width || h != avctx->height) { | |
| 65 | + if (c->prev.data[0]) | |
| 66 | + avctx->release_buffer(avctx, &c->prev); | |
| 58 | 67 | avcodec_set_dimensions(avctx, w, h); |
| 68 | + } | |
| 59 | 69 | |
| 60 | 70 | maxcnt = w * h; |
| 61 | 71 | |
| 62 | − out = av_realloc(c->cur, w * h * 2); | |
| 63 | − if (!out) | |
| 64 | − return -1; | |
| 65 | − c->cur = out; | |
| 66 | − | |
| 67 | − prev = av_realloc(c->prev, w * h * 2); | |
| 68 | − if (!prev) | |
| 69 | − return -1; | |
| 70 | − c->prev = prev; | |
| 72 | + c->cur.reference = 3; | |
| 73 | + if ((res = avctx->get_buffer(avctx, &c->cur)) < 0) | |
| 74 | + return res; | |
| 75 | + out = (uint16_t *) c->cur.data[0]; | |
| 76 | + if (c->prev.data[0]) { | |
| 77 | + prev = (uint16_t *) c->prev.data[0]; | |
| 78 | + } else { | |
| 79 | + prev = NULL; | |
| 80 | + } | |
| 71 | 81 | |
| 72 | 82 | for (i = 0; i < 8; i++) |
| 73 | 83 | offsets[i] = -1; |
| @@ -80,6 +90,7 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, AVPac · 6 unmodified lines | ||
| 80 | 90 | out[outcnt++] = code; // rgb555 pixel coded directly |
| 81 | 91 | } else { |
| 82 | 92 | int count; |
| 93 | + int inp_off; | |
| 83 | 94 | uint16_t *inp; |
| 84 | 95 | |
| 85 | 96 | if ((code & 0x6000) == 0x6000) { |
| @@ -101,7 +112,14 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, AVPac · 15 unmodified lines | ||
| 101 | 112 | if (maxcnt - start < count) |
| 102 | 113 | break; |
| 103 | 114 | |
| 104 | − inp = prev + start; | |
| 115 | + if (!prev) { | |
| 116 | + av_log(avctx, AV_LOG_ERROR, | |
| 117 | + "Frame reference does not exist\n"); | |
| 118 | + break; | |
| 119 | + } | |
| 120 | + | |
| 121 | + inp = prev; | |
| 122 | + inp_off = start; | |
| 105 | 123 | } else { |
| 106 | 124 | // copy from earlier in this frame |
| 107 | 125 | int offset = (code & 0x1FFF) + 1; |
| @@ -119,27 +137,28 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, AVPac · 11 unmodified lines | ||
| 119 | 137 | if (outcnt < offset) |
| 120 | 138 | break; |
| 121 | 139 | |
| 122 | − inp = out + outcnt - offset; | |
| 140 | + inp = out; | |
| 141 | + inp_off = outcnt - offset; | |
| 123 | 142 | } |
| 124 | 143 | |
| 125 | 144 | if (maxcnt - outcnt < count) |
| 126 | 145 | break; |
| 127 | 146 | |
| 128 | − for (i = 0; i < count; i++) | |
| 147 | + for (i = inp_off; i < count + inp_off; i++) { | |
| 129 | 148 | out[outcnt++] = inp[i]; |
| 149 | + } | |
| 130 | 150 | } |
| 131 | 151 | } |
| 132 | 152 | |
| 133 | 153 | if (outcnt - maxcnt) |
| 134 | 154 | av_log(avctx, AV_LOG_DEBUG, "frame finished with %d diff\n", outcnt - maxcnt); |
| 135 | 155 | |
| 136 | − c->pic.data[0] = (uint8_t *)c->cur; | |
| 137 | − c->pic.linesize[0] = w * 2; | |
| 138 | − | |
| 139 | 156 | *data_size = sizeof(AVFrame); |
| 140 | − *(AVFrame*)data = c->pic; | |
| 157 | + *(AVFrame*)data = c->cur; | |
| 141 | 158 | |
| 142 | − FFSWAP(uint16_t *, c->cur, c->prev); | |
| 159 | + if (c->prev.data[0]) | |
| 160 | + avctx->release_buffer(avctx, &c->prev); | |
| 161 | + FFSWAP(AVFrame, c->cur, c->prev); | |
| 143 | 162 | |
| 144 | 163 | return avpkt->size; |
| 145 | 164 | } |
| @@ -150,18 +169,14 @@ static av_cold int decode_init(AVCodecContext *avctx) · 4 unmodified lines | ||
| 150 | 169 | |
| 151 | 170 | c->avctx = avctx; |
| 152 | 171 | avctx->pix_fmt = PIX_FMT_RGB555; |
| 153 | − avcodec_get_frame_defaults(&c->pic); | |
| 172 | + avctx->flags |= CODEC_FLAG_EMU_EDGE; | |
| 154 | 173 | |
| 155 | 174 | return 0; |
| 156 | 175 | } |
| 157 | 176 | |
| 158 | 177 | static av_cold int decode_end(AVCodecContext *avctx) |
| 159 | 178 | { |
| 160 | − KgvContext * const c = avctx->priv_data; | |
| 161 | − | |
| 162 | − av_freep(&c->cur); | |
| 163 | − av_freep(&c->prev); | |
| 164 | − | |
| 179 | + decode_flush(avctx); | |
| 165 | 180 | return 0; |
| 166 | 181 | } |
| 167 | 182 | |
| @@ -173,5 +188,6 @@ AVCodec ff_kgv1_decoder = { · 5 unmodified lines | ||
| 173 | 188 | .init = decode_init, |
| 174 | 189 | .close = decode_end, |
| 175 | 190 | .decode = decode_frame, |
| 191 | + .flush = decode_flush, | |
| 176 | 192 | .long_name = NULL_IF_CONFIG_SMALL("Kega Game Video"), |
| 177 | 193 | }; |
| @@ -38,28 +38,47 @@ static const int channel_maps[][6] = { · 37 unmodified lines | ||
| 38 | 38 | { 2, 0, 1, 4, 5, 3 }, //< C L R Ls Rs LFE |
| 39 | 39 | }; |
| 40 | 40 | |
| 41 | +static av_cold int Faac_encode_close(AVCodecContext *avctx) | |
| 42 | +{ | |
| 43 | + FaacAudioContext *s = avctx->priv_data; | |
| 44 | + | |
| 45 | + av_freep(&avctx->coded_frame); | |
| 46 | + av_freep(&avctx->extradata); | |
| 47 | + | |
| 48 | + if (s->faac_handle) | |
| 49 | + faacEncClose(s->faac_handle); | |
| 50 | + return 0; | |
| 51 | +} | |
| 52 | + | |
| 41 | 53 | static av_cold int Faac_encode_init(AVCodecContext *avctx) |
| 42 | 54 | { |
| 43 | 55 | FaacAudioContext *s = avctx->priv_data; |
| 44 | 56 | faacEncConfigurationPtr faac_cfg; |
| 45 | 57 | unsigned long samples_input, max_bytes_output; |
| 58 | + int ret; | |
| 46 | 59 | |
| 47 | 60 | /* number of channels */ |
| 48 | 61 | if (avctx->channels < 1 || avctx->channels > 6) { |
| 49 | 62 | av_log(avctx, AV_LOG_ERROR, "encoding %d channel(s) is not allowed\n", avctx->channels); |
| 50 | − return -1; | |
| 63 | + ret = AVERROR(EINVAL); | |
| 64 | + goto error; | |
| 51 | 65 | } |
| 52 | 66 | |
| 53 | 67 | s->faac_handle = faacEncOpen(avctx->sample_rate, |
| 54 | 68 | avctx->channels, |
| 55 | 69 | &samples_input, &max_bytes_output); |
| 70 | + if (!s->faac_handle) { | |
| 71 | + av_log(avctx, AV_LOG_ERROR, "error in faacEncOpen()\n"); | |
| 72 | + ret = AVERROR_UNKNOWN; | |
| 73 | + goto error; | |
| 74 | + } | |
| 56 | 75 | |
| 57 | 76 | /* check faac version */ |
| 58 | 77 | faac_cfg = faacEncGetCurrentConfiguration(s->faac_handle); |
| 59 | 78 | if (faac_cfg->version != FAAC_CFG_VERSION) { |
| 60 | 79 | av_log(avctx, AV_LOG_ERROR, "wrong libfaac version (compiled for: %d, using %d)\n", FAAC_CFG_VERSION, faac_cfg->version); |
| 61 | − faacEncClose(s->faac_handle); | |
| 62 | − return -1; | |
| 80 | + ret = AVERROR(EINVAL); | |
| 81 | + goto error; | |
| 63 | 82 | } |
| 64 | 83 | |
| 65 | 84 | /* put the options in the configuration struct */ |
| @@ -79,8 +98,8 @@ static av_cold int Faac_encode_init(AVCodecContext *avctx) · 13 unmodified lines | ||
| 79 | 98 | break; |
| 80 | 99 | default: |
| 81 | 100 | av_log(avctx, AV_LOG_ERROR, "invalid AAC profile\n"); |
| 82 | − faacEncClose(s->faac_handle); | |
| 83 | − return -1; | |
| 101 | + ret = AVERROR(EINVAL); | |
| 102 | + goto error; | |
| 84 | 103 | } |
| 85 | 104 | faac_cfg->mpegVersion = MPEG4; |
| 86 | 105 | faac_cfg->useTns = 0; |
| @@ -100,7 +119,10 @@ static av_cold int Faac_encode_init(AVCodecContext *avctx) · 13 unmodified lines | ||
| 100 | 119 | avctx->frame_size = samples_input / avctx->channels; |
| 101 | 120 | |
| 102 | 121 | avctx->coded_frame= avcodec_alloc_frame(); |
| 103 | − avctx->coded_frame->key_frame= 1; | |
| 122 | + if (!avctx->coded_frame) { | |
| 123 | + ret = AVERROR(ENOMEM); | |
| 124 | + goto error; | |
| 125 | + } | |
| 104 | 126 | |
| 105 | 127 | /* Set decoder specific info */ |
| 106 | 128 | avctx->extradata_size = 0; |
| @@ -112,6 +134,10 @@ static av_cold int Faac_encode_init(AVCodecContext *avctx) · 5 unmodified lines | ||
| 112 | 134 | if (!faacEncGetDecoderSpecificInfo(s->faac_handle, &buffer, |
| 113 | 135 | &decoder_specific_info_size)) { |
| 114 | 136 | avctx->extradata = av_malloc(decoder_specific_info_size + FF_INPUT_BUFFER_PADDING_SIZE); |
| 137 | + if (!avctx->extradata) { | |
| 138 | + ret = AVERROR(ENOMEM); | |
| 139 | + goto error; | |
| 140 | + } | |
| 115 | 141 | avctx->extradata_size = decoder_specific_info_size; |
| 116 | 142 | memcpy(avctx->extradata, buffer, avctx->extradata_size); |
| 117 | 143 | faac_cfg->outputFormat = 0; |
| @@ -123,10 +149,14 @@ static av_cold int Faac_encode_init(AVCodecContext *avctx) · 5 unmodified lines | ||
| 123 | 149 | |
| 124 | 150 | if (!faacEncSetConfiguration(s->faac_handle, faac_cfg)) { |
| 125 | 151 | av_log(avctx, AV_LOG_ERROR, "libfaac doesn't support this output format!\n"); |
| 126 | − return -1; | |
| 152 | + ret = AVERROR(EINVAL); | |
| 153 | + goto error; | |
| 127 | 154 | } |
| 128 | 155 | |
| 129 | 156 | return 0; |
| 157 | +error: | |
| 158 | + Faac_encode_close(avctx); | |
| 159 | + return ret; | |
| 130 | 160 | } |
| 131 | 161 | |
| 132 | 162 | static int Faac_encode_frame(AVCodecContext *avctx, |
| @@ -145,17 +175,6 @@ static int Faac_encode_frame(AVCodecContext *avctx, · 12 unmodified lines | ||
| 145 | 175 | return bytes_written; |
| 146 | 176 | } |
| 147 | 177 | |
| 148 | −static av_cold int Faac_encode_close(AVCodecContext *avctx) | |
| 149 | −{ | |
| 150 | − FaacAudioContext *s = avctx->priv_data; | |
| 151 | − | |
| 152 | − av_freep(&avctx->coded_frame); | |
| 153 | − av_freep(&avctx->extradata); | |
| 154 | − | |
| 155 | − faacEncClose(s->faac_handle); | |
| 156 | − return 0; | |
| 157 | −} | |
| 158 | − | |
| 159 | 178 | static const AVProfile profiles[] = { |
| 160 | 179 | { FF_PROFILE_AAC_MAIN, "Main" }, |
| 161 | 180 | { FF_PROFILE_AAC_LOW, "LC" }, |
| @@ -81,7 +81,6 @@ typedef struct { · 80 unmodified lines | ||
| 81 | 81 | int cbr_quality; ///< CBR quality 0 to 10 |
| 82 | 82 | int abr; ///< flag to enable ABR |
| 83 | 83 | int pkt_frame_count; ///< frame count for the current packet |
| 84 | − int lookahead; ///< encoder delay | |
| 85 | 84 | int64_t next_pts; ///< next pts, in sample_rate time base |
| 86 | 85 | int pkt_sample_count; ///< sample count in the current packet |
| 87 | 86 | } LibSpeexEncContext; |
| @@ -200,8 +199,7 @@ static av_cold int encode_init(AVCodecContext *avctx) · 112 unmodified lines | ||
| 200 | 199 | s->header.frames_per_packet = s->frames_per_packet; |
| 201 | 200 | |
| 202 | 201 | /* set encoding delay */ |
| 203 | − speex_encoder_ctl(s->enc_state, SPEEX_GET_LOOKAHEAD, &s->lookahead); | |
| 204 | − s->next_pts = -s->lookahead; | |
| 202 | + speex_encoder_ctl(s->enc_state, SPEEX_GET_LOOKAHEAD, &avctx->delay); | |
| 205 | 203 | |
| 206 | 204 | /* create header packet bytes from header struct */ |
| 207 | 205 | /* note: libspeex allocates the memory for header_data, which is freed |
| @@ -257,7 +255,8 @@ static int encode_frame(AVCodecContext *avctx, uint8_t *frame, int buf_size, · 49 unmodified lines | ||
| 257 | 255 | /* write output if all frames for the packet have been encoded */ |
| 258 | 256 | if (s->pkt_frame_count == s->frames_per_packet) { |
| 259 | 257 | s->pkt_frame_count = 0; |
| 260 | − avctx->coded_frame->pts = ff_samples_to_time_base(avctx, s->next_pts); | |
| 258 | + avctx->coded_frame->pts = ff_samples_to_time_base(avctx, s->next_pts - | |
| 259 | + avctx->delay); | |
| 261 | 260 | s->next_pts += s->pkt_sample_count; |
| 262 | 261 | s->pkt_sample_count = 0; |
| 263 | 262 | if (buf_size > speex_bits_nbytes(&s->bits)) { |
| @@ -39,6 +39,8 @@ static av_cold int aac_encode_init(AVCodecContext *avctx) · 38 unmodified lines | ||
| 39 | 39 | int index; |
| 40 | 40 | |
| 41 | 41 | avctx->coded_frame = avcodec_alloc_frame(); |
| 42 | + if (!avctx->coded_frame) | |
| 43 | + return AVERROR(ENOMEM); | |
| 42 | 44 | avctx->frame_size = 1024; |
| 43 | 45 | |
| 44 | 46 | voGetAACEncAPI(&s->codec_api); |
| @@ -87,6 +87,8 @@ static av_cold int amr_wb_encode_init(AVCodecContext *avctx) · 86 unmodified lines | ||
| 87 | 87 | |
| 88 | 88 | avctx->frame_size = 320; |
| 89 | 89 | avctx->coded_frame = avcodec_alloc_frame(); |
| 90 | + if (!avctx->coded_frame) | |
| 91 | + return AVERROR(ENOMEM); | |
| 90 | 92 | |
| 91 | 93 | s->state = E_IF_init(); |
| 92 | 94 | |
| @@ -61,13 +61,13 @@ static const AVOption options[] = { · 60 unmodified lines | ||
| 61 | 61 | }; |
| 62 | 62 | static const AVClass class = { "libvorbis", av_default_item_name, options, LIBAVUTIL_VERSION_INT }; |
| 63 | 63 | |
| 64 | −static const char * error(int oggerr, int *averr) | |
| 64 | +static int vorbis_error_to_averror(int ov_err) | |
| 65 | 65 | { |
| 66 | − switch (oggerr) { | |
| 67 | − case OV_EFAULT: *averr = AVERROR(EFAULT); return "internal error"; | |
| 68 | − case OV_EIMPL: *averr = AVERROR(EINVAL); return "not supported"; | |
| 69 | − case OV_EINVAL: *averr = AVERROR(EINVAL); return "invalid request"; | |
| 70 | − default: *averr = AVERROR(EINVAL); return "unknown error"; | |
| 66 | + switch (ov_err) { | |
| 67 | + case OV_EFAULT: return AVERROR_BUG; | |
| 68 | + case OV_EINVAL: return AVERROR(EINVAL); | |
| 69 | + case OV_EIMPL: return AVERROR(EINVAL); | |
| 70 | + default: return AVERROR_UNKNOWN; | |
| 71 | 71 | } |
| 72 | 72 | } |
| 73 | 73 | |
| @@ -75,49 +75,41 @@ static av_cold int oggvorbis_init_encoder(vorbis_info *vi, AVCodecContext *avcco · 1 unmodified line | ||
| 75 | 75 | { |
| 76 | 76 | OggVorbisContext *context = avccontext->priv_data; |
| 77 | 77 | double cfreq; |
| 78 | − int r; | |
| 78 | + int ret; | |
| 79 | 79 | |
| 80 | 80 | if (avccontext->flags & CODEC_FLAG_QSCALE) { |
| 81 | 81 | /* variable bitrate */ |
| 82 | − float quality = avccontext->global_quality / (float)FF_QP2LAMBDA; | |
| 83 | − r = vorbis_encode_setup_vbr(vi, avccontext->channels, | |
| 84 | − avccontext->sample_rate, | |
| 85 | − quality / 10.0); | |
| 86 | − if (r) { | |
| 87 | − av_log(avccontext, AV_LOG_ERROR, | |
| 88 | − "Unable to set quality to %g: %s\n", quality, error(r, &r)); | |
| 89 | − return r; | |
| 90 | − } | |
| 82 | + float q = avccontext->global_quality / (float)FF_QP2LAMBDA; | |
| 83 | + if ((ret = vorbis_encode_setup_vbr(vi, avccontext->channels, | |
| 84 | + avccontext->sample_rate, | |
| 85 | + q / 10.0))) | |
| 86 | + goto error; | |
| 91 | 87 | } else { |
| 92 | 88 | int minrate = avccontext->rc_min_rate > 0 ? avccontext->rc_min_rate : -1; |
| 93 | 89 | int maxrate = avccontext->rc_min_rate > 0 ? avccontext->rc_max_rate : -1; |
| 94 | 90 | |
| 95 | 91 | /* constant bitrate */ |
| 96 | − r = vorbis_encode_setup_managed(vi, avccontext->channels, | |
| 97 | − avccontext->sample_rate, minrate, | |
| 98 | − avccontext->bit_rate, maxrate); | |
| 99 | − if (r) { | |
| 100 | − av_log(avccontext, AV_LOG_ERROR, | |
| 101 | − "Unable to set CBR to %d: %s\n", avccontext->bit_rate, | |
| 102 | − error(r, &r)); | |
| 103 | − return r; | |
| 104 | − } | |
| 92 | + if ((ret = vorbis_encode_setup_managed(vi, avccontext->channels, | |
| 93 | + avccontext->sample_rate, minrate, | |
| 94 | + avccontext->bit_rate, maxrate))) | |
| 95 | + goto error; | |
| 105 | 96 | |
| 106 | 97 | /* variable bitrate by estimate, disable slow rate management */ |
| 107 | 98 | if (minrate == -1 && maxrate == -1) |
| 108 | − if (vorbis_encode_ctl(vi, OV_ECTL_RATEMANAGE2_SET, NULL)) | |
| 109 | − return AVERROR(EINVAL); /* should not happen */ | |
| 99 | + if ((ret = vorbis_encode_ctl(vi, OV_ECTL_RATEMANAGE2_SET, NULL))) | |
| 100 | + goto error; /* should not happen */ | |
| 110 | 101 | } |
| 111 | 102 | |
| 112 | 103 | /* cutoff frequency */ |
| 113 | 104 | if (avccontext->cutoff > 0) { |
| 114 | 105 | cfreq = avccontext->cutoff / 1000.0; |
| 115 | − if (vorbis_encode_ctl(vi, OV_ECTL_LOWPASS_SET, &cfreq)) | |
| 116 | − return AVERROR(EINVAL); /* should not happen */ | |
| 106 | + if ((ret = vorbis_encode_ctl(vi, OV_ECTL_LOWPASS_SET, &cfreq))) | |
| 107 | + goto error; /* should not happen */ | |
| 117 | 108 | } |
| 118 | 109 | |
| 119 | 110 | if (context->iblock) { |
| 120 | − vorbis_encode_ctl(vi, OV_ECTL_IBLOCK_SET, &context->iblock); | |
| 111 | + if ((ret = vorbis_encode_ctl(vi, OV_ECTL_IBLOCK_SET, &context->iblock))) | |
| 112 | + goto error; | |
| 121 | 113 | } |
| 122 | 114 | |
| 123 | 115 | if (avccontext->channels == 3 && |
| @@ -149,7 +141,12 @@ static av_cold int oggvorbis_init_encoder(vorbis_info *vi, AVCodecContext *avcco · 25 unmodified lines | ||
| 149 | 141 | } |
| 150 | 142 | } |
| 151 | 143 | |
| 152 | − return vorbis_encode_setup_init(vi); | |
| 144 | + if ((ret = vorbis_encode_setup_init(vi))) | |
| 145 | + goto error; | |
| 146 | + | |
| 147 | + return 0; | |
| 148 | +error: | |
| 149 | + return vorbis_error_to_averror(ret); | |
| 153 | 150 | } |
| 154 | 151 | |
| 155 | 152 | /* How many bytes are needed for a buffer of length 'l' */ |
| @@ -158,34 +155,63 @@ static int xiph_len(int l) · 2 unmodified lines | ||
| 158 | 155 | return 1 + l / 255 + l; |
| 159 | 156 | } |
| 160 | 157 | |
| 158 | +static av_cold int oggvorbis_encode_close(AVCodecContext *avccontext) | |
| 159 | +{ | |
| 160 | + OggVorbisContext *context = avccontext->priv_data; | |
| 161 | +/* ogg_packet op ; */ | |
| 162 | + | |
| 163 | + vorbis_analysis_wrote(&context->vd, 0); /* notify vorbisenc this is EOF */ | |
| 164 | + | |
| 165 | + vorbis_block_clear(&context->vb); | |
| 166 | + vorbis_dsp_clear(&context->vd); | |
| 167 | + vorbis_info_clear(&context->vi); | |
| 168 | + | |
| 169 | + av_freep(&avccontext->coded_frame); | |
| 170 | + av_freep(&avccontext->extradata); | |
| 171 | + | |
| 172 | + return 0; | |
| 173 | +} | |
| 174 | + | |
| 161 | 175 | static av_cold int oggvorbis_encode_init(AVCodecContext *avccontext) |
| 162 | 176 | { |
| 163 | 177 | OggVorbisContext *context = avccontext->priv_data; |
| 164 | 178 | ogg_packet header, header_comm, header_code; |
| 165 | 179 | uint8_t *p; |
| 166 | 180 | unsigned int offset; |
| 167 | − int r; | |
| 181 | + int ret; | |
| 168 | 182 | |
| 169 | 183 | vorbis_info_init(&context->vi); |
| 170 | − r = oggvorbis_init_encoder(&context->vi, avccontext); | |
| 171 | − if (r < 0) { | |
| 172 | − av_log(avccontext, AV_LOG_ERROR, "oggvorbis_encode_init failed\n"); | |
| 173 | − return r; | |
| 184 | + if ((ret = oggvorbis_init_encoder(&context->vi, avccontext))) { | |
| 185 | + av_log(avccontext, AV_LOG_ERROR, "oggvorbis_encode_init: init_encoder failed\n"); | |
| 186 | + goto error; | |
| 187 | + } | |
| 188 | + if ((ret = vorbis_analysis_init(&context->vd, &context->vi))) { | |
| 189 | + ret = vorbis_error_to_averror(ret); | |
| 190 | + goto error; | |
| 191 | + } | |
| 192 | + if ((ret = vorbis_block_init(&context->vd, &context->vb))) { | |
| 193 | + ret = vorbis_error_to_averror(ret); | |
| 194 | + goto error; | |
| 174 | 195 | } |
| 175 | − vorbis_analysis_init(&context->vd, &context->vi); | |
| 176 | − vorbis_block_init(&context->vd, &context->vb); | |
| 177 | 196 | |
| 178 | 197 | vorbis_comment_init(&context->vc); |
| 179 | 198 | vorbis_comment_add_tag(&context->vc, "encoder", LIBAVCODEC_IDENT); |
| 180 | 199 | |
| 181 | − vorbis_analysis_headerout(&context->vd, &context->vc, &header, | |
| 182 | − &header_comm, &header_code); | |
| 200 | + if ((ret = vorbis_analysis_headerout(&context->vd, &context->vc, &header, | |
| 201 | + &header_comm, &header_code))) { | |
| 202 | + ret = vorbis_error_to_averror(ret); | |
| 203 | + goto error; | |
| 204 | + } | |
| 183 | 205 | |
| 184 | 206 | avccontext->extradata_size = |
| 185 | 207 | 1 + xiph_len(header.bytes) + xiph_len(header_comm.bytes) + |
| 186 | 208 | header_code.bytes; |
| 187 | 209 | p = avccontext->extradata = |
| 188 | 210 | av_malloc(avccontext->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE); |
| 211 | + if (!p) { | |
| 212 | + ret = AVERROR(ENOMEM); | |
| 213 | + goto error; | |
| 214 | + } | |
| 189 | 215 | p[0] = 2; |
| 190 | 216 | offset = 1; |
| 191 | 217 | offset += av_xiphlacing(&p[offset], header.bytes); |
| @@ -208,9 +234,15 @@ static av_cold int oggvorbis_encode_init(AVCodecContext *avccontext) · 16 unmodified lines | ||
| 208 | 234 | avccontext->frame_size = OGGVORBIS_FRAME_SIZE; |
| 209 | 235 | |
| 210 | 236 | avccontext->coded_frame = avcodec_alloc_frame(); |
| 211 | − avccontext->coded_frame->key_frame = 1; | |
| 237 | + if (!avccontext->coded_frame) { | |
| 238 | + ret = AVERROR(ENOMEM); | |
| 239 | + goto error; | |
| 240 | + } | |
| 212 | 241 | |
| 213 | 242 | return 0; |
| 243 | +error: | |
| 244 | + oggvorbis_encode_close(avccontext); | |
| 245 | + return ret; | |
| 214 | 246 | } |
| 215 | 247 | |
| 216 | 248 | static int oggvorbis_encode_frame(AVCodecContext *avccontext, |
| @@ -286,23 +318,6 @@ static int oggvorbis_encode_frame(AVCodecContext *avccontext, · 69 unmodified lines | ||
| 286 | 318 | return l; |
| 287 | 319 | } |
| 288 | 320 | |
| 289 | −static av_cold int oggvorbis_encode_close(AVCodecContext *avccontext) | |
| 290 | −{ | |
| 291 | − OggVorbisContext *context = avccontext->priv_data; | |
| 292 | −/* ogg_packet op ; */ | |
| 293 | − | |
| 294 | − vorbis_analysis_wrote(&context->vd, 0); /* notify vorbisenc this is EOF */ | |
| 295 | − | |
| 296 | − vorbis_block_clear(&context->vb); | |
| 297 | − vorbis_dsp_clear(&context->vd); | |
| 298 | − vorbis_info_clear(&context->vi); | |
| 299 | − | |
| 300 | − av_freep(&avccontext->coded_frame); | |
| 301 | − av_freep(&avccontext->extradata); | |
| 302 | − | |
| 303 | − return 0; | |
| 304 | −} | |
| 305 | − | |
| 306 | 321 | AVCodec ff_libvorbis_encoder = { |
| 307 | 322 | .name = "libvorbis", |
| 308 | 323 | .type = AVMEDIA_TYPE_AUDIO, |
| @@ -75,7 +75,7 @@ static av_cold int MPA_encode_init(AVCodecContext *avctx) · 74 unmodified lines | ||
| 75 | 75 | |
| 76 | 76 | if (channels <= 0 || channels > 2){ |
| 77 | 77 | av_log(avctx, AV_LOG_ERROR, "encoding %d channel(s) is not allowed in mp2\n", channels); |
| 78 | − return -1; | |
| 78 | + return AVERROR(EINVAL); | |
| 79 | 79 | } |
| 80 | 80 | bitrate = bitrate / 1000; |
| 81 | 81 | s->nb_channels = channels; |
| @@ -93,7 +93,7 @@ static av_cold int MPA_encode_init(AVCodecContext *avctx) · 11 unmodified lines | ||
| 93 | 93 | } |
| 94 | 94 | if (i == 3){ |
| 95 | 95 | av_log(avctx, AV_LOG_ERROR, "Sampling rate %d is not allowed in mp2\n", freq); |
| 96 | − return -1; | |
| 96 | + return AVERROR(EINVAL); | |
| 97 | 97 | } |
| 98 | 98 | s->freq_index = i; |
| 99 | 99 | |
| @@ -104,7 +104,7 @@ static av_cold int MPA_encode_init(AVCodecContext *avctx) · 4 unmodified lines | ||
| 104 | 104 | } |
| 105 | 105 | if (i == 15){ |
| 106 | 106 | av_log(avctx, AV_LOG_ERROR, "bitrate %d is not allowed in mp2\n", bitrate); |
| 107 | − return -1; | |
| 107 | + return AVERROR(EINVAL); | |
| 108 | 108 | } |
| 109 | 109 | s->bitrate_index = i; |
| 110 | 110 | |
| @@ -181,7 +181,8 @@ static av_cold int MPA_encode_init(AVCodecContext *avctx) · 70 unmodified lines | ||
| 181 | 181 | } |
| 182 | 182 | |
| 183 | 183 | avctx->coded_frame= avcodec_alloc_frame(); |
| 184 | − avctx->coded_frame->key_frame= 1; | |
| 184 | + if (!avctx->coded_frame) | |
| 185 | + return AVERROR(ENOMEM); | |
| 185 | 186 | |
| 186 | 187 | return 0; |
| 187 | 188 | } |
| @@ -127,14 +127,29 @@ static void apply_mdct(NellyMoserEncodeContext *s) · 126 unmodified lines | ||
| 127 | 127 | s->mdct_ctx.mdct_calc(&s->mdct_ctx, s->mdct_out + NELLY_BUF_LEN, s->buf[s->bufsel] + NELLY_BUF_LEN); |
| 128 | 128 | } |
| 129 | 129 | |
| 130 | +static av_cold int encode_end(AVCodecContext *avctx) | |
| 131 | +{ | |
| 132 | + NellyMoserEncodeContext *s = avctx->priv_data; | |
| 133 | + | |
| 134 | + ff_mdct_end(&s->mdct_ctx); | |
| 135 | + | |
| 136 | + if (s->avctx->trellis) { | |
| 137 | + av_free(s->opt); | |
| 138 | + av_free(s->path); | |
| 139 | + } | |
| 140 | + av_freep(&avctx->coded_frame); | |
| 141 | + | |
| 142 | + return 0; | |
| 143 | +} | |
| 144 | + | |
| 130 | 145 | static av_cold int encode_init(AVCodecContext *avctx) |
| 131 | 146 | { |
| 132 | 147 | NellyMoserEncodeContext *s = avctx->priv_data; |
| 133 | − int i; | |
| 148 | + int i, ret; | |
| 134 | 149 | |
| 135 | 150 | if (avctx->channels != 1) { |
| 136 | 151 | av_log(avctx, AV_LOG_ERROR, "Nellymoser supports only 1 channel\n"); |
| 137 | − return -1; | |
| 152 | + return AVERROR(EINVAL); | |
| 138 | 153 | } |
| 139 | 154 | |
| 140 | 155 | if (avctx->sample_rate != 8000 && avctx->sample_rate != 16000 && |
| @@ -142,12 +157,13 @@ static av_cold int encode_init(AVCodecContext *avctx) · 1 unmodified line | ||
| 142 | 157 | avctx->sample_rate != 22050 && avctx->sample_rate != 44100 && |
| 143 | 158 | avctx->strict_std_compliance >= FF_COMPLIANCE_NORMAL) { |
| 144 | 159 | av_log(avctx, AV_LOG_ERROR, "Nellymoser works only with 8000, 16000, 11025, 22050 and 44100 sample rate\n"); |
| 145 | − return -1; | |
| 160 | + return AVERROR(EINVAL); | |
| 146 | 161 | } |
| 147 | 162 | |
| 148 | 163 | avctx->frame_size = NELLY_SAMPLES; |
| 149 | 164 | s->avctx = avctx; |
| 150 | − ff_mdct_init(&s->mdct_ctx, 8, 0, 32768.0); | |
| 165 | + if ((ret = ff_mdct_init(&s->mdct_ctx, 8, 0, 32768.0)) < 0) | |
| 166 | + goto error; | |
| 151 | 167 | ff_dsputil_init(&s->dsp, avctx); |
| 152 | 168 | |
| 153 | 169 | /* Generate overlap window */ |
| @@ -158,23 +174,22 @@ static av_cold int encode_init(AVCodecContext *avctx) · 4 unmodified lines | ||
| 158 | 174 | if (s->avctx->trellis) { |
| 159 | 175 | s->opt = av_malloc(NELLY_BANDS * OPT_SIZE * sizeof(float )); |
| 160 | 176 | s->path = av_malloc(NELLY_BANDS * OPT_SIZE * sizeof(uint8_t)); |
| 177 | + if (!s->opt || !s->path) { | |
| 178 | + ret = AVERROR(ENOMEM); | |
| 179 | + goto error; | |
| 180 | + } | |
| 161 | 181 | } |
| 162 | 182 | |
| 163 | − return 0; | |
| 164 | −} | |
| 165 | − | |
| 166 | −static av_cold int encode_end(AVCodecContext *avctx) | |
| 167 | −{ | |
| 168 | − NellyMoserEncodeContext *s = avctx->priv_data; | |
| 169 | − | |
| 170 | − ff_mdct_end(&s->mdct_ctx); | |
| 171 | − | |
| 172 | − if (s->avctx->trellis) { | |
| 173 | − av_free(s->opt); | |
| 174 | − av_free(s->path); | |
| 183 | + avctx->coded_frame = avcodec_alloc_frame(); | |
| 184 | + if (!avctx->coded_frame) { | |
| 185 | + ret = AVERROR(ENOMEM); | |
| 186 | + goto error; | |
| 175 | 187 | } |
| 176 | 188 | |
| 177 | 189 | return 0; |
| 190 | +error: | |
| 191 | + encode_end(avctx); | |
| 192 | + return ret; | |
| 178 | 193 | } |
| 179 | 194 | |
| 180 | 195 | #define find_best(val, table, LUT, LUT_add, LUT_size) \ |
| @@ -33,15 +33,20 @@ · 32 unmodified lines | ||
| 33 | 33 | #include "ra144.h" |
| 34 | 34 | |
| 35 | 35 | |
| 36 | +static av_cold int ra144_encode_close(AVCodecContext *avctx) | |
| 37 | +{ | |
| 38 | + RA144Context *ractx = avctx->priv_data; | |
| 39 | + ff_lpc_end(&ractx->lpc_ctx); | |
| 40 | + av_freep(&avctx->coded_frame); | |
| 41 | + return 0; | |
| 42 | +} | |
| 43 | + | |
| 44 | + | |
| 36 | 45 | static av_cold int ra144_encode_init(AVCodecContext * avctx) |
| 37 | 46 | { |
| 38 | 47 | RA144Context *ractx; |
| 39 | 48 | int ret; |
| 40 | 49 | |
| 41 | − if (avctx->sample_fmt != AV_SAMPLE_FMT_S16) { | |
| 42 | − av_log(avctx, AV_LOG_ERROR, "invalid sample format\n"); | |
| 43 | − return -1; | |
| 44 | − } | |
| 45 | 50 | if (avctx->channels != 1) { |
| 46 | 51 | av_log(avctx, AV_LOG_ERROR, "invalid number of channels: %d\n", |
| 47 | 52 | avctx->channels); |
| @@ -55,15 +60,19 @@ static av_cold int ra144_encode_init(AVCodecContext * avctx) · 7 unmodified lines | ||
| 55 | 60 | ractx->avctx = avctx; |
| 56 | 61 | ret = ff_lpc_init(&ractx->lpc_ctx, avctx->frame_size, LPC_ORDER, |
| 57 | 62 | FF_LPC_TYPE_LEVINSON); |
| 58 | − return ret; | |
| 59 | −} | |
| 63 | + if (ret < 0) | |
| 64 | + goto error; | |
| 60 | 65 | |
| 66 | + avctx->coded_frame = avcodec_alloc_frame(); | |
| 67 | + if (!avctx->coded_frame) { | |
| 68 | + ret = AVERROR(ENOMEM); | |
| 69 | + goto error; | |
| 70 | + } | |
| 61 | 71 | |
| 62 | −static av_cold int ra144_encode_close(AVCodecContext *avctx) | |
| 63 | −{ | |
| 64 | − RA144Context *ractx = avctx->priv_data; | |
| 65 | − ff_lpc_end(&ractx->lpc_ctx); | |
| 66 | 72 | return 0; |
| 73 | +error: | |
| 74 | + ra144_encode_close(avctx); | |
| 75 | + return ret; | |
| 67 | 76 | } |
| 68 | 77 | |
| 69 | 78 | |
| @@ -432,6 +441,7 @@ static int ra144_encode_frame(AVCodecContext *avctx, uint8_t *frame, · 362 unmodified lines | ||
| 432 | 441 | int16_t block_coefs[NBLOCKS][LPC_ORDER]; |
| 433 | 442 | int lpc_refl[LPC_ORDER]; /**< reflection coefficients of the frame */ |
| 434 | 443 | unsigned int refl_rms[NBLOCKS]; /**< RMS of the reflection coefficients */ |
| 444 | + const int16_t *samples = data; | |
| 435 | 445 | int energy = 0; |
| 436 | 446 | int i, idx; |
| 437 | 447 | |
| @@ -506,7 +516,7 @@ static int ra144_encode_frame(AVCodecContext *avctx, uint8_t *frame, · 68 unmodified lines | ||
| 506 | 516 | ractx->lpc_refl_rms[1] = ractx->lpc_refl_rms[0]; |
| 507 | 517 | FFSWAP(unsigned int *, ractx->lpc_coef[0], ractx->lpc_coef[1]); |
| 508 | 518 | for (i = 0; i < NBLOCKS * BLOCKSIZE; i++) |
| 509 | − ractx->curr_block[i] = *((int16_t *)data + i) >> 2; | |
| 519 | + ractx->curr_block[i] = samples[i] >> 2; | |
| 510 | 520 | return FRAMESIZE; |
| 511 | 521 | } |
| 512 | 522 | |
| @@ -25,9 +25,8 @@ · 24 unmodified lines | ||
| 25 | 25 | #include "avcodec.h" |
| 26 | 26 | #include "bytestream.h" |
| 27 | 27 | |
| 28 | −#define ROQ_FIRST_FRAME_SIZE (735*8) | |
| 29 | 28 | #define ROQ_FRAME_SIZE 735 |
| 30 | − | |
| 29 | +#define ROQ_HEADER_SIZE 8 | |
| 31 | 30 | |
| 32 | 31 | #define MAX_DPCM (127*127) |
| 33 | 32 | |
| @@ -35,34 +34,59 @@ · 1 unmodified line | ||
| 35 | 34 | typedef struct |
| 36 | 35 | { |
| 37 | 36 | short lastSample[2]; |
| 37 | + int input_frames; | |
| 38 | + int buffered_samples; | |
| 39 | + int16_t *frame_buffer; | |
| 38 | 40 | } ROQDPCMContext; |
| 39 | 41 | |
| 42 | + | |
| 43 | +static av_cold int roq_dpcm_encode_close(AVCodecContext *avctx) | |
| 44 | +{ | |
| 45 | + ROQDPCMContext *context = avctx->priv_data; | |
| 46 | + | |
| 47 | + av_freep(&avctx->coded_frame); | |
| 48 | + av_freep(&context->frame_buffer); | |
| 49 | + | |
| 50 | + return 0; | |
| 51 | +} | |
| 52 | + | |
| 40 | 53 | static av_cold int roq_dpcm_encode_init(AVCodecContext *avctx) |
| 41 | 54 | { |
| 42 | 55 | ROQDPCMContext *context = avctx->priv_data; |
| 56 | + int ret; | |
| 43 | 57 | |
| 44 | 58 | if (avctx->channels > 2) { |
| 45 | 59 | av_log(avctx, AV_LOG_ERROR, "Audio must be mono or stereo\n"); |
| 46 | − return -1; | |
| 60 | + return AVERROR(EINVAL); | |
| 47 | 61 | } |
| 48 | 62 | if (avctx->sample_rate != 22050) { |
| 49 | 63 | av_log(avctx, AV_LOG_ERROR, "Audio must be 22050 Hz\n"); |
| 50 | − return -1; | |
| 51 | − } | |
| 52 | − if (avctx->sample_fmt != AV_SAMPLE_FMT_S16) { | |
| 53 | − av_log(avctx, AV_LOG_ERROR, "Audio must be signed 16-bit\n"); | |
| 54 | − return -1; | |
| 64 | + return AVERROR(EINVAL); | |
| 55 | 65 | } |
| 56 | 66 | |
| 57 | − avctx->frame_size = ROQ_FIRST_FRAME_SIZE; | |
| 67 | + avctx->frame_size = ROQ_FRAME_SIZE; | |
| 68 | + avctx->bit_rate = (ROQ_HEADER_SIZE + ROQ_FRAME_SIZE * avctx->channels) * | |
| 69 | + (22050 / ROQ_FRAME_SIZE) * 8; | |
| 70 | + | |
| 71 | + context->frame_buffer = av_malloc(8 * ROQ_FRAME_SIZE * avctx->channels * | |
| 72 | + sizeof(*context->frame_buffer)); | |
| 73 | + if (!context->frame_buffer) { | |
| 74 | + ret = AVERROR(ENOMEM); | |
| 75 | + goto error; | |
| 76 | + } | |
| 58 | 77 | |
| 59 | 78 | context->lastSample[0] = context->lastSample[1] = 0; |
| 60 | 79 | |
| 61 | 80 | avctx->coded_frame= avcodec_alloc_frame(); |
| 62 | − if (!avctx->coded_frame) | |
| 63 | − return AVERROR(ENOMEM); | |
| 81 | + if (!avctx->coded_frame) { | |
| 82 | + ret = AVERROR(ENOMEM); | |
| 83 | + goto error; | |
| 84 | + } | |
| 64 | 85 | |
| 65 | 86 | return 0; |
| 87 | +error: | |
| 88 | + roq_dpcm_encode_close(avctx); | |
| 89 | + return ret; | |
| 66 | 90 | } |
| 67 | 91 | |
| 68 | 92 | static unsigned char dpcm_predict(short *previous, short current) |
| @@ -108,25 +132,45 @@ static unsigned char dpcm_predict(short *previous, short current) · 39 unmodified lines | ||
| 108 | 132 | static int roq_dpcm_encode_frame(AVCodecContext *avctx, |
| 109 | 133 | unsigned char *frame, int buf_size, void *data) |
| 110 | 134 | { |
| 111 | − int i, samples, stereo, ch; | |
| 112 | − const short *in; | |
| 113 | − unsigned char *out; | |
| 114 | − | |
| 135 | + int i, stereo, data_size; | |
| 136 | + const int16_t *in = data; | |
| 137 | + uint8_t *out = frame; | |
| 115 | 138 | ROQDPCMContext *context = avctx->priv_data; |
| 116 | 139 | |
| 117 | 140 | stereo = (avctx->channels == 2); |
| 118 | 141 | |
| 142 | + if (!data && context->input_frames >= 8) | |
| 143 | + return 0; | |
| 144 | + | |
| 145 | + if (data && context->input_frames < 8) { | |
| 146 | + memcpy(&context->frame_buffer[context->buffered_samples * avctx->channels], | |
| 147 | + in, avctx->frame_size * avctx->channels * sizeof(*in)); | |
| 148 | + context->buffered_samples += avctx->frame_size; | |
| 149 | + if (context->input_frames < 7) { | |
| 150 | + context->input_frames++; | |
| 151 | + return 0; | |
| 152 | + } | |
| 153 | + in = context->frame_buffer; | |
| 154 | + } | |
| 155 | + | |
| 119 | 156 | if (stereo) { |
| 120 | 157 | context->lastSample[0] &= 0xFF00; |
| 121 | 158 | context->lastSample[1] &= 0xFF00; |
| 122 | 159 | } |
| 123 | 160 | |
| 124 | − out = frame; | |
| 125 | − in = data; | |
| 161 | + if (context->input_frames == 7 || !data) | |
| 162 | + data_size = avctx->channels * context->buffered_samples; | |
| 163 | + else | |
| 164 | + data_size = avctx->channels * avctx->frame_size; | |
| 165 | + | |
| 166 | + if (buf_size < ROQ_HEADER_SIZE + data_size) { | |
| 167 | + av_log(avctx, AV_LOG_ERROR, "output buffer is too small\n"); | |
| 168 | + return AVERROR(EINVAL); | |
| 169 | + } | |
| 126 | 170 | |
| 127 | 171 | bytestream_put_byte(&out, stereo ? 0x21 : 0x20); |
| 128 | 172 | bytestream_put_byte(&out, 0x10); |
| 129 | − bytestream_put_le32(&out, avctx->frame_size*avctx->channels); | |
| 173 | + bytestream_put_le32(&out, data_size); | |
| 130 | 174 | |
| 131 | 175 | if (stereo) { |
| 132 | 176 | bytestream_put_byte(&out, (context->lastSample[1])>>8); |
| @@ -135,23 +179,15 @@ static int roq_dpcm_encode_frame(AVCodecContext *avctx, · 2 unmodified lines | ||
| 135 | 179 | bytestream_put_le16(&out, context->lastSample[0]); |
| 136 | 180 | |
| 137 | 181 | /* Write the actual samples */ |
| 138 | − samples = avctx->frame_size; | |
| 139 | − for (i=0; i<samples; i++) | |
| 140 | − for (ch=0; ch<avctx->channels; ch++) | |
| 141 | − *out++ = dpcm_predict(&context->lastSample[ch], *in++); | |
| 182 | + for (i = 0; i < data_size; i++) | |
| 183 | + *out++ = dpcm_predict(&context->lastSample[i & 1], *in++); | |
| 142 | 184 | |
| 143 | − /* Use smaller frames from now on */ | |
| 144 | − avctx->frame_size = ROQ_FRAME_SIZE; | |
| 185 | + context->input_frames++; | |
| 186 | + if (!data) | |
| 187 | + context->input_frames = FFMAX(context->input_frames, 8); | |
| 145 | 188 | |
| 146 | 189 | /* Return the result size */ |
| 147 | − return out - frame; | |
| 148 | −} | |
| 149 | − | |
| 150 | −static av_cold int roq_dpcm_encode_close(AVCodecContext *avctx) | |
| 151 | −{ | |
| 152 | − av_freep(&avctx->coded_frame); | |
| 153 | − | |
| 154 | − return 0; | |
| 190 | + return ROQ_HEADER_SIZE + data_size; | |
| 155 | 191 | } |
| 156 | 192 | |
| 157 | 193 | AVCodec ff_roq_dpcm_encoder = { |
| @@ -162,6 +198,7 @@ AVCodec ff_roq_dpcm_encoder = { · 4 unmodified lines | ||
| 162 | 198 | .init = roq_dpcm_encode_init, |
| 163 | 199 | .encode = roq_dpcm_encode_frame, |
| 164 | 200 | .close = roq_dpcm_encode_close, |
| 201 | + .capabilities = CODEC_CAP_DELAY, | |
| 165 | 202 | .sample_fmts = (const enum AVSampleFormat[]){AV_SAMPLE_FMT_S16,AV_SAMPLE_FMT_NONE}, |
| 166 | 203 | .long_name = NULL_IF_CONFIG_SMALL("id RoQ DPCM"), |
| 167 | 204 | }; |
| @@ -603,6 +603,8 @@ int avcodec_default_reget_buffer(AVCodecContext *s, AVFrame *pic){ · 602 unmodified lines | ||
| 603 | 603 | return s->get_buffer(s, pic); |
| 604 | 604 | } |
| 605 | 605 | |
| 606 | + assert(s->pix_fmt == pic->pix_fmt); | |
| 607 | + | |
| 606 | 608 | /* If internal buffer type return the same buffer */ |
| 607 | 609 | if(pic->type == FF_BUFFER_TYPE_INTERNAL) { |
| 608 | 610 | return 0; |
| @@ -967,6 +969,8 @@ int attribute_align_arg avcodec_encode_audio2(AVCodecContext *avctx, · 358 unmodified lines | ||
| 967 | 969 | int user_packet = !!avpkt->data; |
| 968 | 970 | int nb_samples; |
| 969 | 971 | |
| 972 | + *got_packet_ptr = 0; | |
| 973 | + | |
| 970 | 974 | if (!(avctx->codec->capabilities & CODEC_CAP_DELAY) && !frame) { |
| 971 | 975 | av_init_packet(avpkt); |
| 972 | 976 | avpkt->size = 0; |
| @@ -988,7 +992,6 @@ int attribute_align_arg avcodec_encode_audio2(AVCodecContext *avctx, · 15 unmodified lines | ||
| 988 | 992 | } |
| 989 | 993 | |
| 990 | 994 | if (avctx->codec->encode2) { |
| 991 | − *got_packet_ptr = 0; | |
| 992 | 995 | ret = avctx->codec->encode2(avctx, avpkt, frame, got_packet_ptr); |
| 993 | 996 | if (!ret && *got_packet_ptr) { |
| 994 | 997 | if (!(avctx->codec->capabilities & CODEC_CAP_DELAY)) { |
| @@ -1196,10 +1199,11 @@ int attribute_align_arg avcodec_encode_video2(AVCodecContext *avctx, · 201 unmodified lines | ||
| 1196 | 1199 | int ret; |
| 1197 | 1200 | int user_packet = !!avpkt->data; |
| 1198 | 1201 | |
| 1202 | + *got_packet_ptr = 0; | |
| 1203 | + | |
| 1199 | 1204 | if (!(avctx->codec->capabilities & CODEC_CAP_DELAY) && !frame) { |
| 1200 | 1205 | av_init_packet(avpkt); |
| 1201 | 1206 | avpkt->size = 0; |
| 1202 | − *got_packet_ptr = 0; | |
| 1203 | 1207 | return 0; |
| 1204 | 1208 | } |
| 1205 | 1209 | |
| @@ -1208,17 +1212,15 @@ int attribute_align_arg avcodec_encode_video2(AVCodecContext *avctx, · 2 unmodified lines | ||
| 1208 | 1212 | |
| 1209 | 1213 | av_assert0(avctx->codec->encode2); |
| 1210 | 1214 | |
| 1211 | − *got_packet_ptr = 0; | |
| 1212 | 1215 | ret = avctx->codec->encode2(avctx, avpkt, frame, got_packet_ptr); |
| 1213 | 1216 | if (!ret) { |
| 1214 | 1217 | if (!*got_packet_ptr) |
| 1215 | 1218 | avpkt->size = 0; |
| 1216 | 1219 | else if (!(avctx->codec->capabilities & CODEC_CAP_DELAY)) |
| 1217 | 1220 | avpkt->pts = avpkt->dts = frame->pts; |
| 1218 | − } | |
| 1219 | 1221 | |
| 1220 | − if (!ret) | |
| 1221 | 1222 | avctx->frame_number++; |
| 1223 | + } | |
| 1222 | 1224 | |
| 1223 | 1225 | emms_c(); |
| 1224 | 1226 | return ret; |
| @@ -1710,6 +1710,17 @@ static av_cold int vorbis_decode_close(AVCodecContext *avccontext) · 1709 unmodified lines | ||
| 1710 | 1710 | return 0; |
| 1711 | 1711 | } |
| 1712 | 1712 | |
| 1713 | +static av_cold void vorbis_decode_flush(AVCodecContext *avccontext) | |
| 1714 | +{ | |
| 1715 | + vorbis_context *vc = avccontext->priv_data; | |
| 1716 | + | |
| 1717 | + if (vc->saved) { | |
| 1718 | + memset(vc->saved, 0, (vc->blocksize[1] / 4) * vc->audio_channels * | |
| 1719 | + sizeof(*vc->saved)); | |
| 1720 | + } | |
| 1721 | + vc->previous_window = 0; | |
| 1722 | +} | |
| 1723 | + | |
| 1713 | 1724 | AVCodec ff_vorbis_decoder = { |
| 1714 | 1725 | .name = "vorbis", |
| 1715 | 1726 | .type = AVMEDIA_TYPE_AUDIO, |
| @@ -1718,6 +1729,7 @@ AVCodec ff_vorbis_decoder = { · 2 unmodified lines | ||
| 1718 | 1729 | .init = vorbis_decode_init, |
| 1719 | 1730 | .close = vorbis_decode_close, |
| 1720 | 1731 | .decode = vorbis_decode_frame, |
| 1732 | + .flush = vorbis_decode_flush, | |
| 1721 | 1733 | .capabilities = CODEC_CAP_DR1, |
| 1722 | 1734 | .long_name = NULL_IF_CONFIG_SMALL("Vorbis"), |
| 1723 | 1735 | .channel_layouts = ff_vorbis_channel_layouts, |
| @@ -155,7 +155,7 @@ static int cb_lookup_vals(int lookup, int dimentions, int entries) · 154 unmodified lines | ||
| 155 | 155 | return 0; |
| 156 | 156 | } |
| 157 | 157 | |
| 158 | −static void ready_codebook(vorbis_enc_codebook *cb) | |
| 158 | +static int ready_codebook(vorbis_enc_codebook *cb) | |
| 159 | 159 | { |
| 160 | 160 | int i; |
| 161 | 161 | |
| @@ -167,6 +167,8 @@ static void ready_codebook(vorbis_enc_codebook *cb) · 5 unmodified lines | ||
| 167 | 167 | int vals = cb_lookup_vals(cb->lookup, cb->ndimentions, cb->nentries); |
| 168 | 168 | cb->dimentions = av_malloc(sizeof(float) * cb->nentries * cb->ndimentions); |
| 169 | 169 | cb->pow2 = av_mallocz(sizeof(float) * cb->nentries); |
| 170 | + if (!cb->dimentions || !cb->pow2) | |
| 171 | + return AVERROR(ENOMEM); | |
| 170 | 172 | for (i = 0; i < cb->nentries; i++) { |
| 171 | 173 | float last = 0; |
| 172 | 174 | int j; |
| @@ -187,13 +189,16 @@ static void ready_codebook(vorbis_enc_codebook *cb) · 14 unmodified lines | ||
| 187 | 189 | cb->pow2[i] /= 2.; |
| 188 | 190 | } |
| 189 | 191 | } |
| 192 | + return 0; | |
| 190 | 193 | } |
| 191 | 194 | |
| 192 | −static void ready_residue(vorbis_enc_residue *rc, vorbis_enc_context *venc) | |
| 195 | +static int ready_residue(vorbis_enc_residue *rc, vorbis_enc_context *venc) | |
| 193 | 196 | { |
| 194 | 197 | int i; |
| 195 | 198 | assert(rc->type == 2); |
| 196 | 199 | rc->maxes = av_mallocz(sizeof(float[2]) * rc->classifications); |
| 200 | + if (!rc->maxes) | |
| 201 | + return AVERROR(ENOMEM); | |
| 197 | 202 | for (i = 0; i < rc->classifications; i++) { |
| 198 | 203 | int j; |
| 199 | 204 | vorbis_enc_codebook * cb; |
| @@ -223,15 +228,16 @@ static void ready_residue(vorbis_enc_residue *rc, vorbis_enc_context *venc) · 23 unmodified lines | ||
| 223 | 228 | rc->maxes[i][0] += 0.8; |
| 224 | 229 | rc->maxes[i][1] += 0.8; |
| 225 | 230 | } |
| 231 | + return 0; | |
| 226 | 232 | } |
| 227 | 233 | |
| 228 | −static void create_vorbis_context(vorbis_enc_context *venc, | |
| 229 | − AVCodecContext *avccontext) | |
| 234 | +static int create_vorbis_context(vorbis_enc_context *venc, | |
| 235 | + AVCodecContext *avccontext) | |
| 230 | 236 | { |
| 231 | 237 | vorbis_enc_floor *fc; |
| 232 | 238 | vorbis_enc_residue *rc; |
| 233 | 239 | vorbis_enc_mapping *mc; |
| 234 | − int i, book; | |
| 240 | + int i, book, ret; | |
| 235 | 241 | |
| 236 | 242 | venc->channels = avccontext->channels; |
| 237 | 243 | venc->sample_rate = avccontext->sample_rate; |
| @@ -239,6 +245,8 @@ static void create_vorbis_context(vorbis_enc_context *venc, · 1 unmodified line | ||
| 239 | 245 | |
| 240 | 246 | venc->ncodebooks = FF_ARRAY_ELEMS(cvectors); |
| 241 | 247 | venc->codebooks = av_malloc(sizeof(vorbis_enc_codebook) * venc->ncodebooks); |
| 248 | + if (!venc->codebooks) | |
| 249 | + return AVERROR(ENOMEM); | |
| 242 | 250 | |
| 243 | 251 | // codebook 0..14 - floor1 book, values 0..255 |
| 244 | 252 | // codebook 15 residue masterbook |
| @@ -255,27 +263,36 @@ static void create_vorbis_context(vorbis_enc_context *venc, · 10 unmodified lines | ||
| 255 | 263 | |
| 256 | 264 | cb->lens = av_malloc(sizeof(uint8_t) * cb->nentries); |
| 257 | 265 | cb->codewords = av_malloc(sizeof(uint32_t) * cb->nentries); |
| 266 | + if (!cb->lens || !cb->codewords) | |
| 267 | + return AVERROR(ENOMEM); | |
| 258 | 268 | memcpy(cb->lens, cvectors[book].clens, cvectors[book].len); |
| 259 | 269 | memset(cb->lens + cvectors[book].len, 0, cb->nentries - cvectors[book].len); |
| 260 | 270 | |
| 261 | 271 | if (cb->lookup) { |
| 262 | 272 | vals = cb_lookup_vals(cb->lookup, cb->ndimentions, cb->nentries); |
| 263 | 273 | cb->quantlist = av_malloc(sizeof(int) * vals); |
| 274 | + if (!cb->quantlist) | |
| 275 | + return AVERROR(ENOMEM); | |
| 264 | 276 | for (i = 0; i < vals; i++) |
| 265 | 277 | cb->quantlist[i] = cvectors[book].quant[i]; |
| 266 | 278 | } else { |
| 267 | 279 | cb->quantlist = NULL; |
| 268 | 280 | } |
| 269 | − ready_codebook(cb); | |
| 281 | + if ((ret = ready_codebook(cb)) < 0) | |
| 282 | + return ret; | |
| 270 | 283 | } |
| 271 | 284 | |
| 272 | 285 | venc->nfloors = 1; |
| 273 | 286 | venc->floors = av_malloc(sizeof(vorbis_enc_floor) * venc->nfloors); |
| 287 | + if (!venc->floors) | |
| 288 | + return AVERROR(ENOMEM); | |
| 274 | 289 | |
| 275 | 290 | // just 1 floor |
| 276 | 291 | fc = &venc->floors[0]; |
| 277 | 292 | fc->partitions = NUM_FLOOR_PARTITIONS; |
| 278 | 293 | fc->partition_to_class = av_malloc(sizeof(int) * fc->partitions); |
| 294 | + if (!fc->partition_to_class) | |
| 295 | + return AVERROR(ENOMEM); | |
| 279 | 296 | fc->nclasses = 0; |
| 280 | 297 | for (i = 0; i < fc->partitions; i++) { |
| 281 | 298 | static const int a[] = {0, 1, 2, 2, 3, 3, 4, 4}; |
| @@ -284,6 +301,8 @@ static void create_vorbis_context(vorbis_enc_context *venc, · 2 unmodified lines | ||
| 284 | 301 | } |
| 285 | 302 | fc->nclasses++; |
| 286 | 303 | fc->classes = av_malloc(sizeof(vorbis_enc_floor_class) * fc->nclasses); |
| 304 | + if (!fc->classes) | |
| 305 | + return AVERROR(ENOMEM); | |
| 287 | 306 | for (i = 0; i < fc->nclasses; i++) { |
| 288 | 307 | vorbis_enc_floor_class * c = &fc->classes[i]; |
| 289 | 308 | int j, books; |
| @@ -292,6 +311,8 @@ static void create_vorbis_context(vorbis_enc_context *venc, · 2 unmodified lines | ||
| 292 | 311 | c->masterbook = floor_classes[i].masterbook; |
| 293 | 312 | books = (1 << c->subclass); |
| 294 | 313 | c->books = av_malloc(sizeof(int) * books); |
| 314 | + if (!c->books) | |
| 315 | + return AVERROR(ENOMEM); | |
| 295 | 316 | for (j = 0; j < books; j++) |
| 296 | 317 | c->books[j] = floor_classes[i].nbooks[j]; |
| 297 | 318 | } |
| @@ -303,6 +324,8 @@ static void create_vorbis_context(vorbis_enc_context *venc, · 5 unmodified lines | ||
| 303 | 324 | fc->values += fc->classes[fc->partition_to_class[i]].dim; |
| 304 | 325 | |
| 305 | 326 | fc->list = av_malloc(sizeof(vorbis_floor1_entry) * fc->values); |
| 327 | + if (!fc->list) | |
| 328 | + return AVERROR(ENOMEM); | |
| 306 | 329 | fc->list[0].x = 0; |
| 307 | 330 | fc->list[1].x = 1 << fc->rangebits; |
| 308 | 331 | for (i = 2; i < fc->values; i++) { |
| @@ -317,6 +340,8 @@ static void create_vorbis_context(vorbis_enc_context *venc, · 8 unmodified lines | ||
| 317 | 340 | |
| 318 | 341 | venc->nresidues = 1; |
| 319 | 342 | venc->residues = av_malloc(sizeof(vorbis_enc_residue) * venc->nresidues); |
| 343 | + if (!venc->residues) | |
| 344 | + return AVERROR(ENOMEM); | |
| 320 | 345 | |
| 321 | 346 | // single residue |
| 322 | 347 | rc = &venc->residues[0]; |
| @@ -327,6 +352,8 @@ static void create_vorbis_context(vorbis_enc_context *venc, · 4 unmodified lines | ||
| 327 | 352 | rc->classifications = 10; |
| 328 | 353 | rc->classbook = 15; |
| 329 | 354 | rc->books = av_malloc(sizeof(*rc->books) * rc->classifications); |
| 355 | + if (!rc->books) | |
| 356 | + return AVERROR(ENOMEM); | |
| 330 | 357 | { |
| 331 | 358 | static const int8_t a[10][8] = { |
| 332 | 359 | { -1, -1, -1, -1, -1, -1, -1, -1, }, |
| @@ -342,19 +369,26 @@ static void create_vorbis_context(vorbis_enc_context *venc, · 9 unmodified lines | ||
| 342 | 369 | }; |
| 343 | 370 | memcpy(rc->books, a, sizeof a); |
| 344 | 371 | } |
| 345 | − ready_residue(rc, venc); | |
| 372 | + if ((ret = ready_residue(rc, venc)) < 0) | |
| 373 | + return ret; | |
| 346 | 374 | |
| 347 | 375 | venc->nmappings = 1; |
| 348 | 376 | venc->mappings = av_malloc(sizeof(vorbis_enc_mapping) * venc->nmappings); |
| 377 | + if (!venc->mappings) | |
| 378 | + return AVERROR(ENOMEM); | |
| 349 | 379 | |
| 350 | 380 | // single mapping |
| 351 | 381 | mc = &venc->mappings[0]; |
| 352 | 382 | mc->submaps = 1; |
| 353 | 383 | mc->mux = av_malloc(sizeof(int) * venc->channels); |
| 384 | + if (!mc->mux) | |
| 385 | + return AVERROR(ENOMEM); | |
| 354 | 386 | for (i = 0; i < venc->channels; i++) |
| 355 | 387 | mc->mux[i] = 0; |
| 356 | 388 | mc->floor = av_malloc(sizeof(int) * mc->submaps); |
| 357 | 389 | mc->residue = av_malloc(sizeof(int) * mc->submaps); |
| 390 | + if (!mc->floor || !mc->residue) | |
| 391 | + return AVERROR(ENOMEM); | |
| 358 | 392 | for (i = 0; i < mc->submaps; i++) { |
| 359 | 393 | mc->floor[i] = 0; |
| 360 | 394 | mc->residue[i] = 0; |
| @@ -362,6 +396,8 @@ static void create_vorbis_context(vorbis_enc_context *venc, · 1 unmodified line | ||
| 362 | 396 | mc->coupling_steps = venc->channels == 2 ? 1 : 0; |
| 363 | 397 | mc->magnitude = av_malloc(sizeof(int) * mc->coupling_steps); |
| 364 | 398 | mc->angle = av_malloc(sizeof(int) * mc->coupling_steps); |
| 399 | + if (!mc->magnitude || !mc->angle) | |
| 400 | + return AVERROR(ENOMEM); | |
| 365 | 401 | if (mc->coupling_steps) { |
| 366 | 402 | mc->magnitude[0] = 0; |
| 367 | 403 | mc->angle[0] = 1; |
| @@ -369,6 +405,8 @@ static void create_vorbis_context(vorbis_enc_context *venc, · 1 unmodified line | ||
| 369 | 405 | |
| 370 | 406 | venc->nmodes = 1; |
| 371 | 407 | venc->modes = av_malloc(sizeof(vorbis_enc_mode) * venc->nmodes); |
| 408 | + if (!venc->modes) | |
| 409 | + return AVERROR(ENOMEM); | |
| 372 | 410 | |
| 373 | 411 | // single mode |
| 374 | 412 | venc->modes[0].blockflag = 0; |
| @@ -379,12 +417,18 @@ static void create_vorbis_context(vorbis_enc_context *venc, · 4 unmodified lines | ||
| 379 | 417 | venc->samples = av_malloc(sizeof(float) * venc->channels * (1 << venc->log2_blocksize[1])); |
| 380 | 418 | venc->floor = av_malloc(sizeof(float) * venc->channels * (1 << venc->log2_blocksize[1]) / 2); |
| 381 | 419 | venc->coeffs = av_malloc(sizeof(float) * venc->channels * (1 << venc->log2_blocksize[1]) / 2); |
| 420 | + if (!venc->saved || !venc->samples || !venc->floor || !venc->coeffs) | |
| 421 | + return AVERROR(ENOMEM); | |
| 382 | 422 | |
| 383 | 423 | venc->win[0] = ff_vorbis_vwin[venc->log2_blocksize[0] - 6]; |
| 384 | 424 | venc->win[1] = ff_vorbis_vwin[venc->log2_blocksize[1] - 6]; |
| 385 | 425 | |
| 386 | − ff_mdct_init(&venc->mdct[0], venc->log2_blocksize[0], 0, 1.0); | |
| 387 | − ff_mdct_init(&venc->mdct[1], venc->log2_blocksize[1], 0, 1.0); | |
| 426 | + if ((ret = ff_mdct_init(&venc->mdct[0], venc->log2_blocksize[0], 0, 1.0)) < 0) | |
| 427 | + return ret; | |
| 428 | + if ((ret = ff_mdct_init(&venc->mdct[1], venc->log2_blocksize[1], 0, 1.0)) < 0) | |
| 429 | + return ret; | |
| 430 | + | |
| 431 | + return 0; | |
| 388 | 432 | } |
| 389 | 433 | |
| 390 | 434 | static void put_float(PutBitContext *pb, float f) |
| @@ -647,6 +691,8 @@ static int put_main_header(vorbis_enc_context *venc, uint8_t **out) · 256 unmodified lines | ||
| 647 | 691 | |
| 648 | 692 | len = hlens[0] + hlens[1] + hlens[2]; |
| 649 | 693 | p = *out = av_mallocz(64 + len + len/255); |
| 694 | + if (!p) | |
| 695 | + return AVERROR(ENOMEM); | |
| 650 | 696 | |
| 651 | 697 | *p++ = 2; |
| 652 | 698 | p += av_xiphlacing(p, hlens[0]); |
| @@ -952,33 +998,6 @@ static int apply_window_and_mdct(vorbis_enc_context *venc, const signed short *a · 299 unmodified lines | ||
| 952 | 998 | return 1; |
| 953 | 999 | } |
| 954 | 1000 | |
| 955 | −static av_cold int vorbis_encode_init(AVCodecContext *avccontext) | |
| 956 | −{ | |
| 957 | − vorbis_enc_context *venc = avccontext->priv_data; | |
| 958 | − | |
| 959 | − if (avccontext->channels != 2) { | |
| 960 | − av_log(avccontext, AV_LOG_ERROR, "Current FFmpeg Vorbis encoder only supports 2 channels.\n"); | |
| 961 | − return -1; | |
| 962 | − } | |
| 963 | − | |
| 964 | − create_vorbis_context(venc, avccontext); | |
| 965 | − | |
| 966 | − if (avccontext->flags & CODEC_FLAG_QSCALE) | |
| 967 | − venc->quality = avccontext->global_quality / (float)FF_QP2LAMBDA / 10.; | |
| 968 | − else | |
| 969 | − venc->quality = 0.03; | |
| 970 | − venc->quality *= venc->quality; | |
| 971 | − | |
| 972 | − avccontext->extradata_size = put_main_header(venc, (uint8_t**)&avccontext->extradata); | |
| 973 | − | |
| 974 | − avccontext->frame_size = 1 << (venc->log2_blocksize[0] - 1); | |
| 975 | − | |
| 976 | − avccontext->coded_frame = avcodec_alloc_frame(); | |
| 977 | − avccontext->coded_frame->key_frame = 1; | |
| 978 | − | |
| 979 | − return 0; | |
| 980 | −} | |
| 981 | − | |
| 982 | 1001 | static int vorbis_encode_frame(AVCodecContext *avccontext, |
| 983 | 1002 | unsigned char *packets, |
| 984 | 1003 | int buf_size, void *data) |
| @@ -1102,6 +1121,43 @@ static av_cold int vorbis_encode_close(AVCodecContext *avccontext) · 117 unmodified lines | ||
| 1102 | 1121 | return 0 ; |
| 1103 | 1122 | } |
| 1104 | 1123 | |
| 1124 | +static av_cold int vorbis_encode_init(AVCodecContext *avccontext) | |
| 1125 | +{ | |
| 1126 | + vorbis_enc_context *venc = avccontext->priv_data; | |
| 1127 | + int ret; | |
| 1128 | + | |
| 1129 | + if (avccontext->channels != 2) { | |
| 1130 | + av_log(avccontext, AV_LOG_ERROR, "Current FFmpeg Vorbis encoder only supports 2 channels.\n"); | |
| 1131 | + return -1; | |
| 1132 | + } | |
| 1133 | + | |
| 1134 | + if ((ret = create_vorbis_context(venc, avccontext)) < 0) | |
| 1135 | + goto error; | |
| 1136 | + | |
| 1137 | + if (avccontext->flags & CODEC_FLAG_QSCALE) | |
| 1138 | + venc->quality = avccontext->global_quality / (float)FF_QP2LAMBDA / 10.; | |
| 1139 | + else | |
| 1140 | + venc->quality = 0.03; | |
| 1141 | + venc->quality *= venc->quality; | |
| 1142 | + | |
| 1143 | + if ((ret = put_main_header(venc, (uint8_t**)&avccontext->extradata)) < 0) | |
| 1144 | + goto error; | |
| 1145 | + avccontext->extradata_size = ret; | |
| 1146 | + | |
| 1147 | + avccontext->frame_size = 1 << (venc->log2_blocksize[0] - 1); | |
| 1148 | + | |
| 1149 | + avccontext->coded_frame = avcodec_alloc_frame(); | |
| 1150 | + if (!avccontext->coded_frame) { | |
| 1151 | + ret = AVERROR(ENOMEM); | |
| 1152 | + goto error; | |
| 1153 | + } | |
| 1154 | + | |
| 1155 | + return 0; | |
| 1156 | +error: | |
| 1157 | + vorbis_encode_close(avccontext); | |
| 1158 | + return ret; | |
| 1159 | +} | |
| 1160 | + | |
| 1105 | 1161 | AVCodec ff_vorbis_encoder = { |
| 1106 | 1162 | .name = "vorbis", |
| 1107 | 1163 | .type = AVMEDIA_TYPE_AUDIO, |
| @@ -44,7 +44,7 @@ static int xwd_encode_frame(AVCodecContext *avctx, AVPacket *pkt, · 43 unmodified lines | ||
| 44 | 44 | { |
| 45 | 45 | enum PixelFormat pix_fmt = avctx->pix_fmt; |
| 46 | 46 | uint32_t pixdepth, bpp, bpad, ncolors = 0, lsize, vclass, be = 0; |
| 47 | − uint32_t rgb[3] = { 0 }; | |
| 47 | + uint32_t rgb[3] = { 0 }, bitorder = 0; | |
| 48 | 48 | uint32_t header_size; |
| 49 | 49 | int i, out_size, ret; |
| 50 | 50 | uint8_t *ptr, *buf; |
| @@ -133,6 +133,8 @@ static int xwd_encode_frame(AVCodecContext *avctx, AVPacket *pkt, · 82 unmodified lines | ||
| 133 | 133 | ncolors = 256; |
| 134 | 134 | break; |
| 135 | 135 | case PIX_FMT_MONOWHITE: |
| 136 | + be = 1; | |
| 137 | + bitorder = 1; | |
| 136 | 138 | bpp = 1; |
| 137 | 139 | bpad = 8; |
| 138 | 140 | vclass = XWD_STATIC_GRAY; |
| @@ -164,7 +166,7 @@ static int xwd_encode_frame(AVCodecContext *avctx, AVPacket *pkt, · 25 unmodified lines | ||
| 164 | 166 | bytestream_put_be32(&buf, 0); // bitmap x offset |
| 165 | 167 | bytestream_put_be32(&buf, be); // byte order |
| 166 | 168 | bytestream_put_be32(&buf, 32); // bitmap unit |
| 167 | − bytestream_put_be32(&buf, be); // bit-order of image data | |
| 169 | + bytestream_put_be32(&buf, bitorder); // bit-order of image data | |
| 168 | 170 | bytestream_put_be32(&buf, bpad); // bitmap scan-line pad in bits |
| 169 | 171 | bytestream_put_be32(&buf, bpp); // bits per pixel |
| 170 | 172 | bytestream_put_be32(&buf, lsize); // bytes per scan-line |
| @@ -697,16 +697,19 @@ static int ebml_read_float(AVIOContext *pb, int size, double *num) · 696 unmodified lines | ||
| 697 | 697 | */ |
| 698 | 698 | static int ebml_read_ascii(AVIOContext *pb, int size, char **str) |
| 699 | 699 | { |
| 700 | − av_free(*str); | |
| 700 | + char *res; | |
| 701 | + | |
| 701 | 702 | /* EBML strings are usually not 0-terminated, so we allocate one |
| 702 | 703 | * byte more, read the string and NULL-terminate it ourselves. */ |
| 703 | − if (!(*str = av_malloc(size + 1))) | |
| 704 | + if (!(res = av_malloc(size + 1))) | |
| 704 | 705 | return AVERROR(ENOMEM); |
| 705 | − if (avio_read(pb, (uint8_t *) *str, size) != size) { | |
| 706 | − av_freep(str); | |
| 706 | + if (avio_read(pb, (uint8_t *) res, size) != size) { | |
| 707 | + av_free(res); | |
| 707 | 708 | return AVERROR(EIO); |
| 708 | 709 | } |
| 709 | − (*str)[size] = '\0'; | |
| 710 | + (res)[size] = '\0'; | |
| 711 | + av_free(*str); | |
| 712 | + *str = res; | |
| 710 | 713 | |
| 711 | 714 | return 0; |
| 712 | 715 | } |
| @@ -154,7 +154,7 @@ · 153 unmodified lines | ||
| 154 | 154 | */ |
| 155 | 155 | |
| 156 | 156 | #define LIBAVUTIL_VERSION_MAJOR 51 |
| 157 | −#define LIBAVUTIL_VERSION_MINOR 40 | |
| 157 | +#define LIBAVUTIL_VERSION_MINOR 41 | |
| 158 | 158 | #define LIBAVUTIL_VERSION_MICRO 100 |
| 159 | 159 | |
| 160 | 160 | #define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \ |
| @@ -41,6 +41,7 @@ int av_strerror(int errnum, char *errbuf, size_t errbuf_size) · 40 unmodified lines | ||
| 41 | 41 | case AVERROR_PATCHWELCOME: errstr = "Not yet implemented in FFmpeg, patches welcome"; break; |
| 42 | 42 | case AVERROR_PROTOCOL_NOT_FOUND:errstr = "Protocol not found" ; break; |
| 43 | 43 | case AVERROR_STREAM_NOT_FOUND: errstr = "Stream not found" ; break; |
| 44 | + case AVERROR_UNKNOWN: errstr = "Unknown error occurred" ; break; | |
| 44 | 45 | } |
| 45 | 46 | |
| 46 | 47 | if (errstr) { |
| @@ -64,6 +64,7 @@ · 63 unmodified lines | ||
| 64 | 64 | * it has been introduced in Libav after our AVERROR_BUG and with a modified value. |
| 65 | 65 | */ |
| 66 | 66 | #define AVERROR_BUG2 (-MKTAG( 'B','U','G',' ')) |
| 67 | +#define AVERROR_UNKNOWN (-MKTAG( 'U','N','K','N')) ///< Unknown error, typically from an external library | |
| 67 | 68 | |
| 68 | 69 | /** |
| 69 | 70 | * Put a description of the AVERROR code errnum in errbuf. |
| @@ -46,6 +46,7 @@ include $(SRC_PATH)/tests/fate/amrnb.mak · 45 unmodified lines | ||
| 46 | 46 | include $(SRC_PATH)/tests/fate/amrwb.mak |
| 47 | 47 | include $(SRC_PATH)/tests/fate/atrac.mak |
| 48 | 48 | include $(SRC_PATH)/tests/fate/audio.mak |
| 49 | +include $(SRC_PATH)/tests/fate/cdxl.mak | |
| 49 | 50 | include $(SRC_PATH)/tests/fate/dct.mak |
| 50 | 51 | include $(SRC_PATH)/tests/fate/demux.mak |
| 51 | 52 | include $(SRC_PATH)/tests/fate/dfa.mak |
| @@ -0,0 +1,14 @@ | ||
| 1 | +FATE_CDXL += fate-cdxl-ham6 | |
| 2 | +fate-cdxl-ham6: CMD = framecrc -i $(SAMPLES)/cdxl/cat.cdxl -an -frames:v 16 | |
| 3 | + | |
| 4 | +FATE_CDXL += fate-cdxl-ham8 | |
| 5 | +fate-cdxl-ham8: CMD = framecrc -i $(SAMPLES)/cdxl/mirage.cdxl -an -frames:v 1 | |
| 6 | + | |
| 7 | +FATE_CDXL += fate-cdxl-pal8 | |
| 8 | +fate-cdxl-pal8: CMD = framecrc -i $(SAMPLES)/cdxl/maku.cdxl -pix_fmt rgb24 -frames:v 11 | |
| 9 | + | |
| 10 | +FATE_CDXL += fate-cdxl-pal8-small | |
| 11 | +fate-cdxl-pal8-small: CMD = framecrc -i $(SAMPLES)/cdxl/fruit.cdxl -an -pix_fmt rgb24 -frames:v 46 | |
| 12 | + | |
| 13 | +FATE_TESTS += $(FATE_CDXL) | |
| 14 | +fate-cdxl: $(FATE_CDXL) | |
| @@ -0,0 +1,17 @@ | ||
| 1 | +#tb 0: 52/525 | |
| 2 | +0, 0, 0, 1, 57600, 0x87887a7b | |
| 3 | +0, 1, 1, 1, 57600, 0x10c301d2 | |
| 4 | +0, 2, 2, 1, 57600, 0xd1a6f910 | |
| 5 | +0, 3, 3, 1, 57600, 0x20242bb9 | |
| 6 | +0, 4, 4, 1, 57600, 0xae33cb7f | |
| 7 | +0, 5, 5, 1, 57600, 0x501b82c8 | |
| 8 | +0, 6, 6, 1, 57600, 0x84199043 | |
| 9 | +0, 7, 7, 1, 57600, 0x946a6dbb | |
| 10 | +0, 8, 8, 1, 57600, 0xeacea671 | |
| 11 | +0, 9, 9, 1, 57600, 0x77b8723f | |
| 12 | +0, 10, 10, 1, 57600, 0x371cdb09 | |
| 13 | +0, 11, 11, 1, 57600, 0xa16ef5ee | |
| 14 | +0, 12, 12, 1, 57600, 0xcb6abd9e | |
| 15 | +0, 13, 13, 1, 57600, 0xb73e800f | |
| 16 | +0, 14, 14, 1, 57600, 0x368bd93e | |
| 17 | +0, 15, 15, 1, 57600, 0xcde72dc5 | |
| @@ -0,0 +1,2 @@ | ||
| 1 | +#tb 0: 3/158 | |
| 2 | +0, 0, 0, 1, 67584, 0xce0cade5 | |
| @@ -0,0 +1,12 @@ | ||
| 1 | +#tb 0: 12/601 | |
| 2 | +0, 0, 0, 1, 67584, 0x5eae629b | |
| 3 | +0, 1, 1, 1, 67584, 0x32591227 | |
| 4 | +0, 2, 2, 1, 67584, 0x4e4424c7 | |
| 5 | +0, 3, 3, 1, 67584, 0x70db0134 | |
| 6 | +0, 4, 4, 1, 67584, 0x3550ed0b | |
| 7 | +0, 5, 5, 1, 67584, 0x86fe3eef | |
| 8 | +0, 6, 6, 1, 67584, 0x3414bb33 | |
| 9 | +0, 7, 7, 1, 67584, 0x667bfb91 | |
| 10 | +0, 8, 8, 1, 67584, 0x6e1a4ccb | |
| 11 | +0, 9, 9, 1, 67584, 0xf723f9ae | |
| 12 | +0, 10, 10, 1, 67584, 0x88481d5d | |
| @@ -0,0 +1,47 @@ | ||
| 1 | +#tb 0: 368/11025 | |
| 2 | +0, 0, 0, 1, 30720, 0x0d552cfd | |
| 3 | +0, 1, 1, 1, 30720, 0x3cf93291 | |
| 4 | +0, 2, 2, 1, 30720, 0xe45b2868 | |
| 5 | +0, 3, 3, 1, 30720, 0xb5df289b | |
| 6 | +0, 4, 4, 1, 30720, 0x2562259e | |
| 7 | +0, 5, 5, 1, 30720, 0xbf171878 | |
| 8 | +0, 6, 6, 1, 30720, 0x695b1d73 | |
| 9 | +0, 7, 7, 1, 30720, 0x89ef1614 | |
| 10 | +0, 8, 8, 1, 30720, 0xe12a1dd9 | |
| 11 | +0, 9, 9, 1, 30720, 0x49622ffa | |
| 12 | +0, 10, 10, 1, 30720, 0xd6832703 | |
| 13 | +0, 11, 11, 1, 30720, 0xec1d0cb7 | |
| 14 | +0, 12, 12, 1, 30720, 0x8bee0525 | |
| 15 | +0, 13, 13, 1, 30720, 0x1e0cf0c4 | |
| 16 | +0, 14, 14, 1, 30720, 0xf83fd9db | |
| 17 | +0, 15, 15, 1, 30720, 0xffb0d6ab | |
| 18 | +0, 16, 16, 1, 30720, 0xe37fe239 | |
| 19 | +0, 17, 17, 1, 30720, 0x74b0f856 | |
| 20 | +0, 18, 18, 1, 30720, 0x9c88d3e1 | |
| 21 | +0, 19, 19, 1, 30720, 0x714db368 | |
| 22 | +0, 20, 20, 1, 30720, 0x6c8e8860 | |
| 23 | +0, 21, 21, 1, 30720, 0x804968e6 | |
| 24 | +0, 22, 22, 1, 30720, 0x7ac56ae4 | |
| 25 | +0, 23, 23, 1, 30720, 0xffd85cbf | |
| 26 | +0, 24, 24, 1, 30720, 0x1f8455f9 | |
| 27 | +0, 25, 25, 1, 30720, 0x3ae65296 | |
| 28 | +0, 26, 26, 1, 30720, 0x9e544ecd | |
| 29 | +0, 27, 27, 1, 30720, 0x35678e5a | |
| 30 | +0, 28, 28, 1, 30720, 0x04bae866 | |
| 31 | +0, 29, 29, 1, 30720, 0xb126ed94 | |
| 32 | +0, 30, 30, 1, 30720, 0x1720efc5 | |
| 33 | +0, 31, 31, 1, 30720, 0x4c1b01c2 | |
| 34 | +0, 32, 32, 1, 30720, 0xd0a1e866 | |
| 35 | +0, 33, 33, 1, 30720, 0x0d330789 | |
| 36 | +0, 34, 34, 1, 30720, 0xf5ac08bb | |
| 37 | +0, 35, 35, 1, 30720, 0x9abe0d83 | |
| 38 | +0, 36, 36, 1, 30720, 0xa44c02f4 | |
| 39 | +0, 37, 37, 1, 30720, 0xdc4cc688 | |
| 40 | +0, 38, 38, 1, 30720, 0x22eef3c1 | |
| 41 | +0, 39, 39, 1, 30720, 0xcfbc0d1d | |
| 42 | +0, 40, 40, 1, 30720, 0x7104ea31 | |
| 43 | +0, 41, 41, 1, 30720, 0x80daecfb | |
| 44 | +0, 42, 42, 1, 30720, 0xe1bab995 | |
| 45 | +0, 43, 43, 1, 30720, 0x43f4b896 | |
| 46 | +0, 44, 44, 1, 30720, 0xa0d2bf5c | |
| 47 | +0, 45, 45, 1, 30720, 0x3556a114 | |
| @@ -1,3 +1,3 @@ | ||
| 1 | −0ab6cd4fe5fe85a3f3e87508c2eadfa0 *./tests/data/images/xwd/02.xwd | |
| 1 | +50baa5560b7d1aa3188b19c1162bf7dc *./tests/data/images/xwd/02.xwd | |
| 2 | 2 | ./tests/data/images/xwd/%02d.xwd CRC=0x6da01946 |
| 3 | 3 | 304239 ./tests/data/images/xwd/02.xwd |