* 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
Showing the changes to libavcodec (18 of 30 files). Show all
Unified · Split
| @@ -1372,6 +1372,19 @@ typedef struct AVCodecContext { · 1371 unmodified lines | |||
| 1372 | * the decoder output. (we assume the decoder matches the spec) | 1372 | * the decoder output. (we assume the decoder matches the spec) |
| 1373 | * Decoding: Number of frames delay in addition to what a standard decoder | 1373 | * Decoding: Number of frames delay in addition to what a standard decoder |
| 1374 | * as specified in the spec would produce. | 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 | * - encoding: Set by libavcodec. | 1388 | * - encoding: Set by libavcodec. |
| 1376 | * - decoding: Set by libavcodec. | 1389 | * - decoding: Set by libavcodec. |
| 1377 | */ | 1390 | */ |
| @@ -122,7 +122,7 @@ static void cdxl_decode_ham6(CDXLVideoContext *c) · 121 unmodified lines | |||
| 122 | g = index * 0x11 << 8; | 122 | g = index * 0x11 << 8; |
| 123 | break; | 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 | out += c->frame.linesize[0]; | 127 | out += c->frame.linesize[0]; |
| 128 | } | 128 | } |
| @@ -165,7 +165,7 @@ static void cdxl_decode_ham8(CDXLVideoContext *c) · 36 unmodified lines | |||
| 165 | g = (index << 10) | (g & (3 << 8)); | 165 | g = (index << 10) | (g & (3 << 8)); |
| 166 | break; | 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 | out += c->frame.linesize[0]; | 170 | out += c->frame.linesize[0]; |
| 171 | } | 171 | } |
| @@ -142,7 +142,7 @@ static int decode_frame(AVCodecContext *avctx, · 141 unmodified lines | |||
| 142 | int i, j, is_chroma; | 142 | int i, j, is_chroma; |
| 143 | const int planes = 3; | 143 | const int planes = 3; |
| 144 | uint8_t *out; | 144 | uint8_t *out; |
| 145 | 145 | enum PixelFormat pix_fmt; | |
| 146 | 146 | ||
| 147 | header = AV_RL32(buf); | 147 | header = AV_RL32(buf); |
| 148 | version = header & 0xff; | 148 | version = header & 0xff; |
| @@ -157,8 +157,6 @@ static int decode_frame(AVCodecContext *avctx, · 8 unmodified lines | |||
| 157 | 157 | ||
| 158 | buf += header_size; | 158 | buf += header_size; |
| 159 | 159 | ||
| 160 | avctx->pix_fmt = version & 1 ? PIX_FMT_BGR24 : PIX_FMT_YUVJ420P; | ||
| 161 | |||
| 162 | if (version < 2) { | 160 | if (version < 2) { |
| 163 | unsigned needed_size = avctx->width*avctx->height*3; | 161 | unsigned needed_size = avctx->width*avctx->height*3; |
| 164 | if (version == 0) needed_size /= 2; | 162 | if (version == 0) needed_size /= 2; |
| @@ -205,6 +203,13 @@ static int decode_frame(AVCodecContext *avctx, · 40 unmodified lines | |||
| 205 | f->key_frame = 1; | 203 | f->key_frame = 1; |
| 206 | f->reference = 0; | 204 | f->reference = 0; |
| 207 | f->buffer_hints = FF_BUFFER_HINTS_VALID; | 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 | if (ff_thread_get_buffer(avctx, f)) { | 213 | if (ff_thread_get_buffer(avctx, f)) { |
| 209 | av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); | 214 | av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); |
| 210 | return -1; | 215 | return -1; |
| @@ -41,9 +41,22 @@ · 40 unmodified lines | |||
| 41 | #define MIN_TRELLIS 0 | 41 | #define MIN_TRELLIS 0 |
| 42 | #define MAX_TRELLIS 16 | 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 | static av_cold int g722_encode_init(AVCodecContext * avctx) | 56 | static av_cold int g722_encode_init(AVCodecContext * avctx) |
| 45 | { | 57 | { |
| 46 | G722Context *c = avctx->priv_data; | 58 | G722Context *c = avctx->priv_data; |
| 59 | int ret; | ||
| 47 | 60 | ||
| 48 | if (avctx->channels != 1) { | 61 | if (avctx->channels != 1) { |
| 49 | av_log(avctx, AV_LOG_ERROR, "Only mono tracks are allowed.\n"); | 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 | c->paths[i] = av_mallocz(max_paths * sizeof(**c->paths)); | 75 | c->paths[i] = av_mallocz(max_paths * sizeof(**c->paths)); |
| 63 | c->node_buf[i] = av_mallocz(2 * frontier * sizeof(**c->node_buf)); | 76 | c->node_buf[i] = av_mallocz(2 * frontier * sizeof(**c->node_buf)); |
| 64 | c->nodep_buf[i] = av_mallocz(2 * frontier * sizeof(**c->nodep_buf)); | 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 | return 0; | 119 | return 0; |
| 103 | } | 120 | error: |
| 104 | 121 | g722_encode_close(avctx); | |
| 105 | static av_cold int g722_encode_close(AVCodecContext *avctx) | 122 | return ret; |
| 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; | ||
| 115 | } | 123 | } |
| 116 | 124 | ||
| 117 | static const int16_t low_quant[33] = { | 125 | static const int16_t low_quant[33] = { |
| @@ -30,10 +30,17 @@ · 29 unmodified lines | |||
| 30 | 30 | ||
| 31 | typedef struct { | 31 | typedef struct { |
| 32 | AVCodecContext *avctx; | 32 | AVCodecContext *avctx; |
| 33 | AVFrame pic; | 33 | AVFrame prev, cur; |
| 34 | uint16_t *prev, *cur; | ||
| 35 | } KgvContext; | 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 | static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, AVPacket *avpkt) | 44 | static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, AVPacket *avpkt) |
| 38 | { | 45 | { |
| 39 | const uint8_t *buf = avpkt->data; | 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 | int offsets[8]; | 49 | int offsets[8]; |
| 43 | uint16_t *out, *prev; | 50 | uint16_t *out, *prev; |
| 44 | int outcnt = 0, maxcnt; | 51 | int outcnt = 0, maxcnt; |
| 45 | int w, h, i; | 52 | int w, h, i, res; |
| 46 | 53 | ||
| 47 | if (avpkt->size < 2) | 54 | if (avpkt->size < 2) |
| 48 | return -1; | 55 | return -1; |
| @@ -54,20 +61,23 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, AVPac · 5 unmodified lines | |||
| 54 | if (av_image_check_size(w, h, 0, avctx)) | 61 | if (av_image_check_size(w, h, 0, avctx)) |
| 55 | return -1; | 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 | avcodec_set_dimensions(avctx, w, h); | 67 | avcodec_set_dimensions(avctx, w, h); |
| 68 | } | ||
| 59 | 69 | ||
| 60 | maxcnt = w * h; | 70 | maxcnt = w * h; |
| 61 | 71 | ||
| 62 | out = av_realloc(c->cur, w * h * 2); | 72 | c->cur.reference = 3; |
| 63 | if (!out) | 73 | if ((res = avctx->get_buffer(avctx, &c->cur)) < 0) |
| 64 | return -1; | 74 | return res; |
| 65 | c->cur = out; | 75 | out = (uint16_t *) c->cur.data[0]; |
| 66 | 76 | if (c->prev.data[0]) { | |
| 67 | prev = av_realloc(c->prev, w * h * 2); | 77 | prev = (uint16_t *) c->prev.data[0]; |
| 68 | if (!prev) | 78 | } else { |
| 69 | return -1; | 79 | prev = NULL; |
| 70 | c->prev = prev; | 80 | } |
| 71 | 81 | ||
| 72 | for (i = 0; i < 8; i++) | 82 | for (i = 0; i < 8; i++) |
| 73 | offsets[i] = -1; | 83 | offsets[i] = -1; |
| @@ -80,6 +90,7 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, AVPac · 6 unmodified lines | |||
| 80 | out[outcnt++] = code; // rgb555 pixel coded directly | 90 | out[outcnt++] = code; // rgb555 pixel coded directly |
| 81 | } else { | 91 | } else { |
| 82 | int count; | 92 | int count; |
| 93 | int inp_off; | ||
| 83 | uint16_t *inp; | 94 | uint16_t *inp; |
| 84 | 95 | ||
| 85 | if ((code & 0x6000) == 0x6000) { | 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 | if (maxcnt - start < count) | 112 | if (maxcnt - start < count) |
| 102 | break; | 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 | } else { | 123 | } else { |
| 106 | // copy from earlier in this frame | 124 | // copy from earlier in this frame |
| 107 | int offset = (code & 0x1FFF) + 1; | 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 | if (outcnt < offset) | 137 | if (outcnt < offset) |
| 120 | break; | 138 | break; |
| 121 | 139 | ||
| 122 | inp = out + outcnt - offset; | 140 | inp = out; |
| 141 | inp_off = outcnt - offset; | ||
| 123 | } | 142 | } |
| 124 | 143 | ||
| 125 | if (maxcnt - outcnt < count) | 144 | if (maxcnt - outcnt < count) |
| 126 | break; | 145 | break; |
| 127 | 146 | ||
| 128 | for (i = 0; i < count; i++) | 147 | for (i = inp_off; i < count + inp_off; i++) { |
| 129 | out[outcnt++] = inp[i]; | 148 | out[outcnt++] = inp[i]; |
| 149 | } | ||
| 130 | } | 150 | } |
| 131 | } | 151 | } |
| 132 | 152 | ||
| 133 | if (outcnt - maxcnt) | 153 | if (outcnt - maxcnt) |
| 134 | av_log(avctx, AV_LOG_DEBUG, "frame finished with %d diff\n", outcnt - maxcnt); | 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 | *data_size = sizeof(AVFrame); | 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 | return avpkt->size; | 163 | return avpkt->size; |
| 145 | } | 164 | } |
| @@ -150,18 +169,14 @@ static av_cold int decode_init(AVCodecContext *avctx) · 4 unmodified lines | |||
| 150 | 169 | ||
| 151 | c->avctx = avctx; | 170 | c->avctx = avctx; |
| 152 | avctx->pix_fmt = PIX_FMT_RGB555; | 171 | avctx->pix_fmt = PIX_FMT_RGB555; |
| 153 | avcodec_get_frame_defaults(&c->pic); | 172 | avctx->flags |= CODEC_FLAG_EMU_EDGE; |
| 154 | 173 | ||
| 155 | return 0; | 174 | return 0; |
| 156 | } | 175 | } |
| 157 | 176 | ||
| 158 | static av_cold int decode_end(AVCodecContext *avctx) | 177 | static av_cold int decode_end(AVCodecContext *avctx) |
| 159 | { | 178 | { |
| 160 | KgvContext * const c = avctx->priv_data; | 179 | decode_flush(avctx); |
| 161 | |||
| 162 | av_freep(&c->cur); | ||
| 163 | av_freep(&c->prev); | ||
| 164 | |||
| 165 | return 0; | 180 | return 0; |
| 166 | } | 181 | } |
| 167 | 182 | ||
| @@ -173,5 +188,6 @@ AVCodec ff_kgv1_decoder = { · 5 unmodified lines | |||
| 173 | .init = decode_init, | 188 | .init = decode_init, |
| 174 | .close = decode_end, | 189 | .close = decode_end, |
| 175 | .decode = decode_frame, | 190 | .decode = decode_frame, |
| 191 | .flush = decode_flush, | ||
| 176 | .long_name = NULL_IF_CONFIG_SMALL("Kega Game Video"), | 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 | { 2, 0, 1, 4, 5, 3 }, //< C L R Ls Rs LFE | 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 | static av_cold int Faac_encode_init(AVCodecContext *avctx) | 53 | static av_cold int Faac_encode_init(AVCodecContext *avctx) |
| 42 | { | 54 | { |
| 43 | FaacAudioContext *s = avctx->priv_data; | 55 | FaacAudioContext *s = avctx->priv_data; |
| 44 | faacEncConfigurationPtr faac_cfg; | 56 | faacEncConfigurationPtr faac_cfg; |
| 45 | unsigned long samples_input, max_bytes_output; | 57 | unsigned long samples_input, max_bytes_output; |
| 58 | int ret; | ||
| 46 | 59 | ||
| 47 | /* number of channels */ | 60 | /* number of channels */ |
| 48 | if (avctx->channels < 1 || avctx->channels > 6) { | 61 | if (avctx->channels < 1 || avctx->channels > 6) { |
| 49 | av_log(avctx, AV_LOG_ERROR, "encoding %d channel(s) is not allowed\n", avctx->channels); | 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 | s->faac_handle = faacEncOpen(avctx->sample_rate, | 67 | s->faac_handle = faacEncOpen(avctx->sample_rate, |
| 54 | avctx->channels, | 68 | avctx->channels, |
| 55 | &samples_input, &max_bytes_output); | 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 | /* check faac version */ | 76 | /* check faac version */ |
| 58 | faac_cfg = faacEncGetCurrentConfiguration(s->faac_handle); | 77 | faac_cfg = faacEncGetCurrentConfiguration(s->faac_handle); |
| 59 | if (faac_cfg->version != FAAC_CFG_VERSION) { | 78 | if (faac_cfg->version != FAAC_CFG_VERSION) { |
| 60 | av_log(avctx, AV_LOG_ERROR, "wrong libfaac version (compiled for: %d, using %d)\n", FAAC_CFG_VERSION, faac_cfg->version); | 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); | 80 | ret = AVERROR(EINVAL); |
| 62 | return -1; | 81 | goto error; |
| 63 | } | 82 | } |
| 64 | 83 | ||
| 65 | /* put the options in the configuration struct */ | 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 | break; | 98 | break; |
| 80 | default: | 99 | default: |
| 81 | av_log(avctx, AV_LOG_ERROR, "invalid AAC profile\n"); | 100 | av_log(avctx, AV_LOG_ERROR, "invalid AAC profile\n"); |
| 82 | faacEncClose(s->faac_handle); | 101 | ret = AVERROR(EINVAL); |
| 83 | return -1; | 102 | goto error; |
| 84 | } | 103 | } |
| 85 | faac_cfg->mpegVersion = MPEG4; | 104 | faac_cfg->mpegVersion = MPEG4; |
| 86 | faac_cfg->useTns = 0; | 105 | faac_cfg->useTns = 0; |
| @@ -100,7 +119,10 @@ static av_cold int Faac_encode_init(AVCodecContext *avctx) · 13 unmodified lines | |||
| 100 | avctx->frame_size = samples_input / avctx->channels; | 119 | avctx->frame_size = samples_input / avctx->channels; |
| 101 | 120 | ||
| 102 | avctx->coded_frame= avcodec_alloc_frame(); | 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 | /* Set decoder specific info */ | 127 | /* Set decoder specific info */ |
| 106 | avctx->extradata_size = 0; | 128 | avctx->extradata_size = 0; |
| @@ -112,6 +134,10 @@ static av_cold int Faac_encode_init(AVCodecContext *avctx) · 5 unmodified lines | |||
| 112 | if (!faacEncGetDecoderSpecificInfo(s->faac_handle, &buffer, | 134 | if (!faacEncGetDecoderSpecificInfo(s->faac_handle, &buffer, |
| 113 | &decoder_specific_info_size)) { | 135 | &decoder_specific_info_size)) { |
| 114 | avctx->extradata = av_malloc(decoder_specific_info_size + FF_INPUT_BUFFER_PADDING_SIZE); | 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 | avctx->extradata_size = decoder_specific_info_size; | 141 | avctx->extradata_size = decoder_specific_info_size; |
| 116 | memcpy(avctx->extradata, buffer, avctx->extradata_size); | 142 | memcpy(avctx->extradata, buffer, avctx->extradata_size); |
| 117 | faac_cfg->outputFormat = 0; | 143 | faac_cfg->outputFormat = 0; |
| @@ -123,10 +149,14 @@ static av_cold int Faac_encode_init(AVCodecContext *avctx) · 5 unmodified lines | |||
| 123 | 149 | ||
| 124 | if (!faacEncSetConfiguration(s->faac_handle, faac_cfg)) { | 150 | if (!faacEncSetConfiguration(s->faac_handle, faac_cfg)) { |
| 125 | av_log(avctx, AV_LOG_ERROR, "libfaac doesn't support this output format!\n"); | 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 | return 0; | 156 | return 0; |
| 157 | error: | ||
| 158 | Faac_encode_close(avctx); | ||
| 159 | return ret; | ||
| 130 | } | 160 | } |
| 131 | 161 | ||
| 132 | static int Faac_encode_frame(AVCodecContext *avctx, | 162 | static int Faac_encode_frame(AVCodecContext *avctx, |
| @@ -145,17 +175,6 @@ static int Faac_encode_frame(AVCodecContext *avctx, · 12 unmodified lines | |||
| 145 | return bytes_written; | 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 | static const AVProfile profiles[] = { | 178 | static const AVProfile profiles[] = { |
| 160 | { FF_PROFILE_AAC_MAIN, "Main" }, | 179 | { FF_PROFILE_AAC_MAIN, "Main" }, |
| 161 | { FF_PROFILE_AAC_LOW, "LC" }, | 180 | { FF_PROFILE_AAC_LOW, "LC" }, |
| @@ -81,7 +81,6 @@ typedef struct { · 80 unmodified lines | |||
| 81 | int cbr_quality; ///< CBR quality 0 to 10 | 81 | int cbr_quality; ///< CBR quality 0 to 10 |
| 82 | int abr; ///< flag to enable ABR | 82 | int abr; ///< flag to enable ABR |
| 83 | int pkt_frame_count; ///< frame count for the current packet | 83 | int pkt_frame_count; ///< frame count for the current packet |
| 84 | int lookahead; ///< encoder delay | ||
| 85 | int64_t next_pts; ///< next pts, in sample_rate time base | 84 | int64_t next_pts; ///< next pts, in sample_rate time base |
| 86 | int pkt_sample_count; ///< sample count in the current packet | 85 | int pkt_sample_count; ///< sample count in the current packet |
| 87 | } LibSpeexEncContext; | 86 | } LibSpeexEncContext; |
| @@ -200,8 +199,7 @@ static av_cold int encode_init(AVCodecContext *avctx) · 112 unmodified lines | |||
| 200 | s->header.frames_per_packet = s->frames_per_packet; | 199 | s->header.frames_per_packet = s->frames_per_packet; |
| 201 | 200 | ||
| 202 | /* set encoding delay */ | 201 | /* set encoding delay */ |
| 203 | speex_encoder_ctl(s->enc_state, SPEEX_GET_LOOKAHEAD, &s->lookahead); | 202 | speex_encoder_ctl(s->enc_state, SPEEX_GET_LOOKAHEAD, &avctx->delay); |
| 204 | s->next_pts = -s->lookahead; | ||
| 205 | 203 | ||
| 206 | /* create header packet bytes from header struct */ | 204 | /* create header packet bytes from header struct */ |
| 207 | /* note: libspeex allocates the memory for header_data, which is freed | 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 | /* write output if all frames for the packet have been encoded */ | 255 | /* write output if all frames for the packet have been encoded */ |
| 258 | if (s->pkt_frame_count == s->frames_per_packet) { | 256 | if (s->pkt_frame_count == s->frames_per_packet) { |
| 259 | s->pkt_frame_count = 0; | 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 | s->next_pts += s->pkt_sample_count; | 260 | s->next_pts += s->pkt_sample_count; |
| 262 | s->pkt_sample_count = 0; | 261 | s->pkt_sample_count = 0; |
| 263 | if (buf_size > speex_bits_nbytes(&s->bits)) { | 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 | int index; | 39 | int index; |
| 40 | 40 | ||
| 41 | avctx->coded_frame = avcodec_alloc_frame(); | 41 | avctx->coded_frame = avcodec_alloc_frame(); |
| 42 | if (!avctx->coded_frame) | ||
| 43 | return AVERROR(ENOMEM); | ||
| 42 | avctx->frame_size = 1024; | 44 | avctx->frame_size = 1024; |
| 43 | 45 | ||
| 44 | voGetAACEncAPI(&s->codec_api); | 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 | avctx->frame_size = 320; | 88 | avctx->frame_size = 320; |
| 89 | avctx->coded_frame = avcodec_alloc_frame(); | 89 | avctx->coded_frame = avcodec_alloc_frame(); |
| 90 | if (!avctx->coded_frame) | ||
| 91 | return AVERROR(ENOMEM); | ||
| 90 | 92 | ||
| 91 | s->state = E_IF_init(); | 93 | s->state = E_IF_init(); |
| 92 | 94 | ||
| @@ -61,13 +61,13 @@ static const AVOption options[] = { · 60 unmodified lines | |||
| 61 | }; | 61 | }; |
| 62 | static const AVClass class = { "libvorbis", av_default_item_name, options, LIBAVUTIL_VERSION_INT }; | 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) { | 66 | switch (ov_err) { |
| 67 | case OV_EFAULT: *averr = AVERROR(EFAULT); return "internal error"; | 67 | case OV_EFAULT: return AVERROR_BUG; |
| 68 | case OV_EIMPL: *averr = AVERROR(EINVAL); return "not supported"; | 68 | case OV_EINVAL: return AVERROR(EINVAL); |
| 69 | case OV_EINVAL: *averr = AVERROR(EINVAL); return "invalid request"; | 69 | case OV_EIMPL: return AVERROR(EINVAL); |
| 70 | default: *averr = AVERROR(EINVAL); return "unknown error"; | 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 | OggVorbisContext *context = avccontext->priv_data; | 76 | OggVorbisContext *context = avccontext->priv_data; |
| 77 | double cfreq; | 77 | double cfreq; |
| 78 | int r; | 78 | int ret; |
| 79 | 79 | ||
| 80 | if (avccontext->flags & CODEC_FLAG_QSCALE) { | 80 | if (avccontext->flags & CODEC_FLAG_QSCALE) { |
| 81 | /* variable bitrate */ | 81 | /* variable bitrate */ |
| 82 | float quality = avccontext->global_quality / (float)FF_QP2LAMBDA; | 82 | float q = avccontext->global_quality / (float)FF_QP2LAMBDA; |
| 83 | r = vorbis_encode_setup_vbr(vi, avccontext->channels, | 83 | if ((ret = vorbis_encode_setup_vbr(vi, avccontext->channels, |
| 84 | avccontext->sample_rate, | 84 | avccontext->sample_rate, |
| 85 | quality / 10.0); | 85 | q / 10.0))) |
| 86 | if (r) { | 86 | goto error; |
| 87 | av_log(avccontext, AV_LOG_ERROR, | ||
| 88 | "Unable to set quality to %g: %s\n", quality, error(r, &r)); | ||
| 89 | return r; | ||
| 90 | } | ||
| 91 | } else { | 87 | } else { |
| 92 | int minrate = avccontext->rc_min_rate > 0 ? avccontext->rc_min_rate : -1; | 88 | int minrate = avccontext->rc_min_rate > 0 ? avccontext->rc_min_rate : -1; |
| 93 | int maxrate = avccontext->rc_min_rate > 0 ? avccontext->rc_max_rate : -1; | 89 | int maxrate = avccontext->rc_min_rate > 0 ? avccontext->rc_max_rate : -1; |
| 94 | 90 | ||
| 95 | /* constant bitrate */ | 91 | /* constant bitrate */ |
| 96 | r = vorbis_encode_setup_managed(vi, avccontext->channels, | 92 | if ((ret = vorbis_encode_setup_managed(vi, avccontext->channels, |
| 97 | avccontext->sample_rate, minrate, | 93 | avccontext->sample_rate, minrate, |
| 98 | avccontext->bit_rate, maxrate); | 94 | avccontext->bit_rate, maxrate))) |
| 99 | if (r) { | 95 | goto error; |
| 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 | } | ||
| 105 | 96 | ||
| 106 | /* variable bitrate by estimate, disable slow rate management */ | 97 | /* variable bitrate by estimate, disable slow rate management */ |
| 107 | if (minrate == -1 && maxrate == -1) | 98 | if (minrate == -1 && maxrate == -1) |
| 108 | if (vorbis_encode_ctl(vi, OV_ECTL_RATEMANAGE2_SET, NULL)) | 99 | if ((ret = vorbis_encode_ctl(vi, OV_ECTL_RATEMANAGE2_SET, NULL))) |
| 109 | return AVERROR(EINVAL); /* should not happen */ | 100 | goto error; /* should not happen */ |
| 110 | } | 101 | } |
| 111 | 102 | ||
| 112 | /* cutoff frequency */ | 103 | /* cutoff frequency */ |
| 113 | if (avccontext->cutoff > 0) { | 104 | if (avccontext->cutoff > 0) { |
| 114 | cfreq = avccontext->cutoff / 1000.0; | 105 | cfreq = avccontext->cutoff / 1000.0; |
| 115 | if (vorbis_encode_ctl(vi, OV_ECTL_LOWPASS_SET, &cfreq)) | 106 | if ((ret = vorbis_encode_ctl(vi, OV_ECTL_LOWPASS_SET, &cfreq))) |
| 116 | return AVERROR(EINVAL); /* should not happen */ | 107 | goto error; /* should not happen */ |
| 117 | } | 108 | } |
| 118 | 109 | ||
| 119 | if (context->iblock) { | 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 | if (avccontext->channels == 3 && | 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 | /* How many bytes are needed for a buffer of length 'l' */ | 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 | return 1 + l / 255 + l; | 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 | static av_cold int oggvorbis_encode_init(AVCodecContext *avccontext) | 175 | static av_cold int oggvorbis_encode_init(AVCodecContext *avccontext) |
| 162 | { | 176 | { |
| 163 | OggVorbisContext *context = avccontext->priv_data; | 177 | OggVorbisContext *context = avccontext->priv_data; |
| 164 | ogg_packet header, header_comm, header_code; | 178 | ogg_packet header, header_comm, header_code; |
| 165 | uint8_t *p; | 179 | uint8_t *p; |
| 166 | unsigned int offset; | 180 | unsigned int offset; |
| 167 | int r; | 181 | int ret; |
| 168 | 182 | ||
| 169 | vorbis_info_init(&context->vi); | 183 | vorbis_info_init(&context->vi); |
| 170 | r = oggvorbis_init_encoder(&context->vi, avccontext); | 184 | if ((ret = oggvorbis_init_encoder(&context->vi, avccontext))) { |
| 171 | if (r < 0) { | 185 | av_log(avccontext, AV_LOG_ERROR, "oggvorbis_encode_init: init_encoder failed\n"); |
| 172 | av_log(avccontext, AV_LOG_ERROR, "oggvorbis_encode_init failed\n"); | 186 | goto error; |
| 173 | return r; | 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 | vorbis_comment_init(&context->vc); | 197 | vorbis_comment_init(&context->vc); |
| 179 | vorbis_comment_add_tag(&context->vc, "encoder", LIBAVCODEC_IDENT); | 198 | vorbis_comment_add_tag(&context->vc, "encoder", LIBAVCODEC_IDENT); |
| 180 | 199 | ||
| 181 | vorbis_analysis_headerout(&context->vd, &context->vc, &header, | 200 | if ((ret = vorbis_analysis_headerout(&context->vd, &context->vc, &header, |
| 182 | &header_comm, &header_code); | 201 | &header_comm, &header_code))) { |
| 202 | ret = vorbis_error_to_averror(ret); | ||
| 203 | goto error; | ||
| 204 | } | ||
| 183 | 205 | ||
| 184 | avccontext->extradata_size = | 206 | avccontext->extradata_size = |
| 185 | 1 + xiph_len(header.bytes) + xiph_len(header_comm.bytes) + | 207 | 1 + xiph_len(header.bytes) + xiph_len(header_comm.bytes) + |
| 186 | header_code.bytes; | 208 | header_code.bytes; |
| 187 | p = avccontext->extradata = | 209 | p = avccontext->extradata = |
| 188 | av_malloc(avccontext->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE); | 210 | av_malloc(avccontext->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE); |
| 211 | if (!p) { | ||
| 212 | ret = AVERROR(ENOMEM); | ||
| 213 | goto error; | ||
| 214 | } | ||
| 189 | p[0] = 2; | 215 | p[0] = 2; |
| 190 | offset = 1; | 216 | offset = 1; |
| 191 | offset += av_xiphlacing(&p[offset], header.bytes); | 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 | avccontext->frame_size = OGGVORBIS_FRAME_SIZE; | 234 | avccontext->frame_size = OGGVORBIS_FRAME_SIZE; |
| 209 | 235 | ||
| 210 | avccontext->coded_frame = avcodec_alloc_frame(); | 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 | return 0; | 242 | return 0; |
| 243 | error: | ||
| 244 | oggvorbis_encode_close(avccontext); | ||
| 245 | return ret; | ||
| 214 | } | 246 | } |
| 215 | 247 | ||
| 216 | static int oggvorbis_encode_frame(AVCodecContext *avccontext, | 248 | static int oggvorbis_encode_frame(AVCodecContext *avccontext, |
| @@ -286,23 +318,6 @@ static int oggvorbis_encode_frame(AVCodecContext *avccontext, · 69 unmodified lines | |||
| 286 | return l; | 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 | AVCodec ff_libvorbis_encoder = { | 321 | AVCodec ff_libvorbis_encoder = { |
| 307 | .name = "libvorbis", | 322 | .name = "libvorbis", |
| 308 | .type = AVMEDIA_TYPE_AUDIO, | 323 | .type = AVMEDIA_TYPE_AUDIO, |
| @@ -75,7 +75,7 @@ static av_cold int MPA_encode_init(AVCodecContext *avctx) · 74 unmodified lines | |||
| 75 | 75 | ||
| 76 | if (channels <= 0 || channels > 2){ | 76 | if (channels <= 0 || channels > 2){ |
| 77 | av_log(avctx, AV_LOG_ERROR, "encoding %d channel(s) is not allowed in mp2\n", channels); | 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 | bitrate = bitrate / 1000; | 80 | bitrate = bitrate / 1000; |
| 81 | s->nb_channels = channels; | 81 | s->nb_channels = channels; |
| @@ -93,7 +93,7 @@ static av_cold int MPA_encode_init(AVCodecContext *avctx) · 11 unmodified lines | |||
| 93 | } | 93 | } |
| 94 | if (i == 3){ | 94 | if (i == 3){ |
| 95 | av_log(avctx, AV_LOG_ERROR, "Sampling rate %d is not allowed in mp2\n", freq); | 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 | s->freq_index = i; | 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 | if (i == 15){ | 105 | if (i == 15){ |
| 106 | av_log(avctx, AV_LOG_ERROR, "bitrate %d is not allowed in mp2\n", bitrate); | 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 | s->bitrate_index = i; | 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 | avctx->coded_frame= avcodec_alloc_frame(); | 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 | return 0; | 187 | return 0; |
| 187 | } | 188 | } |
| @@ -127,14 +127,29 @@ static void apply_mdct(NellyMoserEncodeContext *s) · 126 unmodified lines | |||
| 127 | s->mdct_ctx.mdct_calc(&s->mdct_ctx, s->mdct_out + NELLY_BUF_LEN, s->buf[s->bufsel] + NELLY_BUF_LEN); | 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 | static av_cold int encode_init(AVCodecContext *avctx) | 145 | static av_cold int encode_init(AVCodecContext *avctx) |
| 131 | { | 146 | { |
| 132 | NellyMoserEncodeContext *s = avctx->priv_data; | 147 | NellyMoserEncodeContext *s = avctx->priv_data; |
| 133 | int i; | 148 | int i, ret; |
| 134 | 149 | ||
| 135 | if (avctx->channels != 1) { | 150 | if (avctx->channels != 1) { |
| 136 | av_log(avctx, AV_LOG_ERROR, "Nellymoser supports only 1 channel\n"); | 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 | if (avctx->sample_rate != 8000 && avctx->sample_rate != 16000 && | 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 | avctx->sample_rate != 22050 && avctx->sample_rate != 44100 && | 157 | avctx->sample_rate != 22050 && avctx->sample_rate != 44100 && |
| 143 | avctx->strict_std_compliance >= FF_COMPLIANCE_NORMAL) { | 158 | avctx->strict_std_compliance >= FF_COMPLIANCE_NORMAL) { |
| 144 | av_log(avctx, AV_LOG_ERROR, "Nellymoser works only with 8000, 16000, 11025, 22050 and 44100 sample rate\n"); | 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 | avctx->frame_size = NELLY_SAMPLES; | 163 | avctx->frame_size = NELLY_SAMPLES; |
| 149 | s->avctx = avctx; | 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 | ff_dsputil_init(&s->dsp, avctx); | 167 | ff_dsputil_init(&s->dsp, avctx); |
| 152 | 168 | ||
| 153 | /* Generate overlap window */ | 169 | /* Generate overlap window */ |
| @@ -158,23 +174,22 @@ static av_cold int encode_init(AVCodecContext *avctx) · 4 unmodified lines | |||
| 158 | if (s->avctx->trellis) { | 174 | if (s->avctx->trellis) { |
| 159 | s->opt = av_malloc(NELLY_BANDS * OPT_SIZE * sizeof(float )); | 175 | s->opt = av_malloc(NELLY_BANDS * OPT_SIZE * sizeof(float )); |
| 160 | s->path = av_malloc(NELLY_BANDS * OPT_SIZE * sizeof(uint8_t)); | 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; | 183 | avctx->coded_frame = avcodec_alloc_frame(); |
| 164 | } | 184 | if (!avctx->coded_frame) { |
| 165 | 185 | ret = AVERROR(ENOMEM); | |
| 166 | static av_cold int encode_end(AVCodecContext *avctx) | 186 | goto error; |
| 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); | ||
| 175 | } | 187 | } |
| 176 | 188 | ||
| 177 | return 0; | 189 | return 0; |
| 190 | error: | ||
| 191 | encode_end(avctx); | ||
| 192 | return ret; | ||
| 178 | } | 193 | } |
| 179 | 194 | ||
| 180 | #define find_best(val, table, LUT, LUT_add, LUT_size) \ | 195 | #define find_best(val, table, LUT, LUT_add, LUT_size) \ |
| @@ -33,15 +33,20 @@ · 32 unmodified lines | |||
| 33 | #include "ra144.h" | 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 | static av_cold int ra144_encode_init(AVCodecContext * avctx) | 45 | static av_cold int ra144_encode_init(AVCodecContext * avctx) |
| 37 | { | 46 | { |
| 38 | RA144Context *ractx; | 47 | RA144Context *ractx; |
| 39 | int ret; | 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 | if (avctx->channels != 1) { | 50 | if (avctx->channels != 1) { |
| 46 | av_log(avctx, AV_LOG_ERROR, "invalid number of channels: %d\n", | 51 | av_log(avctx, AV_LOG_ERROR, "invalid number of channels: %d\n", |
| 47 | avctx->channels); | 52 | avctx->channels); |
| @@ -55,15 +60,19 @@ static av_cold int ra144_encode_init(AVCodecContext * avctx) · 7 unmodified lines | |||
| 55 | ractx->avctx = avctx; | 60 | ractx->avctx = avctx; |
| 56 | ret = ff_lpc_init(&ractx->lpc_ctx, avctx->frame_size, LPC_ORDER, | 61 | ret = ff_lpc_init(&ractx->lpc_ctx, avctx->frame_size, LPC_ORDER, |
| 57 | FF_LPC_TYPE_LEVINSON); | 62 | FF_LPC_TYPE_LEVINSON); |
| 58 | return ret; | 63 | if (ret < 0) |
| 59 | } | 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 | return 0; | 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 | int16_t block_coefs[NBLOCKS][LPC_ORDER]; | 441 | int16_t block_coefs[NBLOCKS][LPC_ORDER]; |
| 433 | int lpc_refl[LPC_ORDER]; /**< reflection coefficients of the frame */ | 442 | int lpc_refl[LPC_ORDER]; /**< reflection coefficients of the frame */ |
| 434 | unsigned int refl_rms[NBLOCKS]; /**< RMS of the reflection coefficients */ | 443 | unsigned int refl_rms[NBLOCKS]; /**< RMS of the reflection coefficients */ |
| 444 | const int16_t *samples = data; | ||
| 435 | int energy = 0; | 445 | int energy = 0; |
| 436 | int i, idx; | 446 | int i, idx; |
| 437 | 447 | ||
| @@ -506,7 +516,7 @@ static int ra144_encode_frame(AVCodecContext *avctx, uint8_t *frame, · 68 unmodified lines | |||
| 506 | ractx->lpc_refl_rms[1] = ractx->lpc_refl_rms[0]; | 516 | ractx->lpc_refl_rms[1] = ractx->lpc_refl_rms[0]; |
| 507 | FFSWAP(unsigned int *, ractx->lpc_coef[0], ractx->lpc_coef[1]); | 517 | FFSWAP(unsigned int *, ractx->lpc_coef[0], ractx->lpc_coef[1]); |
| 508 | for (i = 0; i < NBLOCKS * BLOCKSIZE; i++) | 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 | return FRAMESIZE; | 520 | return FRAMESIZE; |
| 511 | } | 521 | } |
| 512 | 522 | ||
| @@ -25,9 +25,8 @@ · 24 unmodified lines | |||
| 25 | #include "avcodec.h" | 25 | #include "avcodec.h" |
| 26 | #include "bytestream.h" | 26 | #include "bytestream.h" |
| 27 | 27 | ||
| 28 | #define ROQ_FIRST_FRAME_SIZE (735*8) | ||
| 29 | #define ROQ_FRAME_SIZE 735 | 28 | #define ROQ_FRAME_SIZE 735 |
| 30 | 29 | #define ROQ_HEADER_SIZE 8 | |
| 31 | 30 | ||
| 32 | #define MAX_DPCM (127*127) | 31 | #define MAX_DPCM (127*127) |
| 33 | 32 | ||
| @@ -35,34 +34,59 @@ · 1 unmodified line | |||
| 35 | typedef struct | 34 | typedef struct |
| 36 | { | 35 | { |
| 37 | short lastSample[2]; | 36 | short lastSample[2]; |
| 37 | int input_frames; | ||
| 38 | int buffered_samples; | ||
| 39 | int16_t *frame_buffer; | ||
| 38 | } ROQDPCMContext; | 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 | static av_cold int roq_dpcm_encode_init(AVCodecContext *avctx) | 53 | static av_cold int roq_dpcm_encode_init(AVCodecContext *avctx) |
| 41 | { | 54 | { |
| 42 | ROQDPCMContext *context = avctx->priv_data; | 55 | ROQDPCMContext *context = avctx->priv_data; |
| 56 | int ret; | ||
| 43 | 57 | ||
| 44 | if (avctx->channels > 2) { | 58 | if (avctx->channels > 2) { |
| 45 | av_log(avctx, AV_LOG_ERROR, "Audio must be mono or stereo\n"); | 59 | av_log(avctx, AV_LOG_ERROR, "Audio must be mono or stereo\n"); |
| 46 | return -1; | 60 | return AVERROR(EINVAL); |
| 47 | } | 61 | } |
| 48 | if (avctx->sample_rate != 22050) { | 62 | if (avctx->sample_rate != 22050) { |
| 49 | av_log(avctx, AV_LOG_ERROR, "Audio must be 22050 Hz\n"); | 63 | av_log(avctx, AV_LOG_ERROR, "Audio must be 22050 Hz\n"); |
| 50 | return -1; | 64 | return AVERROR(EINVAL); |
| 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; | ||
| 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 | context->lastSample[0] = context->lastSample[1] = 0; | 78 | context->lastSample[0] = context->lastSample[1] = 0; |
| 60 | 79 | ||
| 61 | avctx->coded_frame= avcodec_alloc_frame(); | 80 | avctx->coded_frame= avcodec_alloc_frame(); |
| 62 | if (!avctx->coded_frame) | 81 | if (!avctx->coded_frame) { |
| 63 | return AVERROR(ENOMEM); | 82 | ret = AVERROR(ENOMEM); |
| 83 | goto error; | ||
| 84 | } | ||
| 64 | 85 | ||
| 65 | return 0; | 86 | return 0; |
| 87 | error: | ||
| 88 | roq_dpcm_encode_close(avctx); | ||
| 89 | return ret; | ||
| 66 | } | 90 | } |
| 67 | 91 | ||
| 68 | static unsigned char dpcm_predict(short *previous, short current) | 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 | static int roq_dpcm_encode_frame(AVCodecContext *avctx, | 132 | static int roq_dpcm_encode_frame(AVCodecContext *avctx, |
| 109 | unsigned char *frame, int buf_size, void *data) | 133 | unsigned char *frame, int buf_size, void *data) |
| 110 | { | 134 | { |
| 111 | int i, samples, stereo, ch; | 135 | int i, stereo, data_size; |
| 112 | const short *in; | 136 | const int16_t *in = data; |
| 113 | unsigned char *out; | 137 | uint8_t *out = frame; |
| 114 | |||
| 115 | ROQDPCMContext *context = avctx->priv_data; | 138 | ROQDPCMContext *context = avctx->priv_data; |
| 116 | 139 | ||
| 117 | stereo = (avctx->channels == 2); | 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 | if (stereo) { | 156 | if (stereo) { |
| 120 | context->lastSample[0] &= 0xFF00; | 157 | context->lastSample[0] &= 0xFF00; |
| 121 | context->lastSample[1] &= 0xFF00; | 158 | context->lastSample[1] &= 0xFF00; |
| 122 | } | 159 | } |
| 123 | 160 | ||
| 124 | out = frame; | 161 | if (context->input_frames == 7 || !data) |
| 125 | in = 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 | bytestream_put_byte(&out, stereo ? 0x21 : 0x20); | 171 | bytestream_put_byte(&out, stereo ? 0x21 : 0x20); |
| 128 | bytestream_put_byte(&out, 0x10); | 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 | if (stereo) { | 175 | if (stereo) { |
| 132 | bytestream_put_byte(&out, (context->lastSample[1])>>8); | 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 | bytestream_put_le16(&out, context->lastSample[0]); | 179 | bytestream_put_le16(&out, context->lastSample[0]); |
| 136 | 180 | ||
| 137 | /* Write the actual samples */ | 181 | /* Write the actual samples */ |
| 138 | samples = avctx->frame_size; | 182 | for (i = 0; i < data_size; i++) |
| 139 | for (i=0; i<samples; i++) | 183 | *out++ = dpcm_predict(&context->lastSample[i & 1], *in++); |
| 140 | for (ch=0; ch<avctx->channels; ch++) | ||
| 141 | *out++ = dpcm_predict(&context->lastSample[ch], *in++); | ||
| 142 | 184 | ||
| 143 | /* Use smaller frames from now on */ | 185 | context->input_frames++; |
| 144 | avctx->frame_size = ROQ_FRAME_SIZE; | 186 | if (!data) |
| 187 | context->input_frames = FFMAX(context->input_frames, 8); | ||
| 145 | 188 | ||
| 146 | /* Return the result size */ | 189 | /* Return the result size */ |
| 147 | return out - frame; | 190 | return ROQ_HEADER_SIZE + data_size; |
| 148 | } | ||
| 149 | |||
| 150 | static av_cold int roq_dpcm_encode_close(AVCodecContext *avctx) | ||
| 151 | { | ||
| 152 | av_freep(&avctx->coded_frame); | ||
| 153 | |||
| 154 | return 0; | ||
| 155 | } | 191 | } |
| 156 | 192 | ||
| 157 | AVCodec ff_roq_dpcm_encoder = { | 193 | AVCodec ff_roq_dpcm_encoder = { |
| @@ -162,6 +198,7 @@ AVCodec ff_roq_dpcm_encoder = { · 4 unmodified lines | |||
| 162 | .init = roq_dpcm_encode_init, | 198 | .init = roq_dpcm_encode_init, |
| 163 | .encode = roq_dpcm_encode_frame, | 199 | .encode = roq_dpcm_encode_frame, |
| 164 | .close = roq_dpcm_encode_close, | 200 | .close = roq_dpcm_encode_close, |
| 201 | .capabilities = CODEC_CAP_DELAY, | ||
| 165 | .sample_fmts = (const enum AVSampleFormat[]){AV_SAMPLE_FMT_S16,AV_SAMPLE_FMT_NONE}, | 202 | .sample_fmts = (const enum AVSampleFormat[]){AV_SAMPLE_FMT_S16,AV_SAMPLE_FMT_NONE}, |
| 166 | .long_name = NULL_IF_CONFIG_SMALL("id RoQ DPCM"), | 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 | return s->get_buffer(s, pic); | 603 | return s->get_buffer(s, pic); |
| 604 | } | 604 | } |
| 605 | 605 | ||
| 606 | assert(s->pix_fmt == pic->pix_fmt); | ||
| 607 | |||
| 606 | /* If internal buffer type return the same buffer */ | 608 | /* If internal buffer type return the same buffer */ |
| 607 | if(pic->type == FF_BUFFER_TYPE_INTERNAL) { | 609 | if(pic->type == FF_BUFFER_TYPE_INTERNAL) { |
| 608 | return 0; | 610 | return 0; |
| @@ -967,6 +969,8 @@ int attribute_align_arg avcodec_encode_audio2(AVCodecContext *avctx, · 358 unmodified lines | |||
| 967 | int user_packet = !!avpkt->data; | 969 | int user_packet = !!avpkt->data; |
| 968 | int nb_samples; | 970 | int nb_samples; |
| 969 | 971 | ||
| 972 | *got_packet_ptr = 0; | ||
| 973 | |||
| 970 | if (!(avctx->codec->capabilities & CODEC_CAP_DELAY) && !frame) { | 974 | if (!(avctx->codec->capabilities & CODEC_CAP_DELAY) && !frame) { |
| 971 | av_init_packet(avpkt); | 975 | av_init_packet(avpkt); |
| 972 | avpkt->size = 0; | 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 | if (avctx->codec->encode2) { | 994 | if (avctx->codec->encode2) { |
| 991 | *got_packet_ptr = 0; | ||
| 992 | ret = avctx->codec->encode2(avctx, avpkt, frame, got_packet_ptr); | 995 | ret = avctx->codec->encode2(avctx, avpkt, frame, got_packet_ptr); |
| 993 | if (!ret && *got_packet_ptr) { | 996 | if (!ret && *got_packet_ptr) { |
| 994 | if (!(avctx->codec->capabilities & CODEC_CAP_DELAY)) { | 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 | int ret; | 1199 | int ret; |
| 1197 | int user_packet = !!avpkt->data; | 1200 | int user_packet = !!avpkt->data; |
| 1198 | 1201 | ||
| 1202 | *got_packet_ptr = 0; | ||
| 1203 | |||
| 1199 | if (!(avctx->codec->capabilities & CODEC_CAP_DELAY) && !frame) { | 1204 | if (!(avctx->codec->capabilities & CODEC_CAP_DELAY) && !frame) { |
| 1200 | av_init_packet(avpkt); | 1205 | av_init_packet(avpkt); |
| 1201 | avpkt->size = 0; | 1206 | avpkt->size = 0; |
| 1202 | *got_packet_ptr = 0; | ||
| 1203 | return 0; | 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 | av_assert0(avctx->codec->encode2); | 1213 | av_assert0(avctx->codec->encode2); |
| 1210 | 1214 | ||
| 1211 | *got_packet_ptr = 0; | ||
| 1212 | ret = avctx->codec->encode2(avctx, avpkt, frame, got_packet_ptr); | 1215 | ret = avctx->codec->encode2(avctx, avpkt, frame, got_packet_ptr); |
| 1213 | if (!ret) { | 1216 | if (!ret) { |
| 1214 | if (!*got_packet_ptr) | 1217 | if (!*got_packet_ptr) |
| 1215 | avpkt->size = 0; | 1218 | avpkt->size = 0; |
| 1216 | else if (!(avctx->codec->capabilities & CODEC_CAP_DELAY)) | 1219 | else if (!(avctx->codec->capabilities & CODEC_CAP_DELAY)) |
| 1217 | avpkt->pts = avpkt->dts = frame->pts; | 1220 | avpkt->pts = avpkt->dts = frame->pts; |
| 1218 | } | ||
| 1219 | 1221 | ||
| 1220 | if (!ret) | ||
| 1221 | avctx->frame_number++; | 1222 | avctx->frame_number++; |
| 1223 | } | ||
| 1222 | 1224 | ||
| 1223 | emms_c(); | 1225 | emms_c(); |
| 1224 | return ret; | 1226 | return ret; |
| @@ -1710,6 +1710,17 @@ static av_cold int vorbis_decode_close(AVCodecContext *avccontext) · 1709 unmodified lines | |||
| 1710 | return 0; | 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 | AVCodec ff_vorbis_decoder = { | 1724 | AVCodec ff_vorbis_decoder = { |
| 1714 | .name = "vorbis", | 1725 | .name = "vorbis", |
| 1715 | .type = AVMEDIA_TYPE_AUDIO, | 1726 | .type = AVMEDIA_TYPE_AUDIO, |
| @@ -1718,6 +1729,7 @@ AVCodec ff_vorbis_decoder = { · 2 unmodified lines | |||
| 1718 | .init = vorbis_decode_init, | 1729 | .init = vorbis_decode_init, |
| 1719 | .close = vorbis_decode_close, | 1730 | .close = vorbis_decode_close, |
| 1720 | .decode = vorbis_decode_frame, | 1731 | .decode = vorbis_decode_frame, |
| 1732 | .flush = vorbis_decode_flush, | ||
| 1721 | .capabilities = CODEC_CAP_DR1, | 1733 | .capabilities = CODEC_CAP_DR1, |
| 1722 | .long_name = NULL_IF_CONFIG_SMALL("Vorbis"), | 1734 | .long_name = NULL_IF_CONFIG_SMALL("Vorbis"), |
| 1723 | .channel_layouts = ff_vorbis_channel_layouts, | 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 | return 0; | 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 | int i; | 160 | int i; |
| 161 | 161 | ||
| @@ -167,6 +167,8 @@ static void ready_codebook(vorbis_enc_codebook *cb) · 5 unmodified lines | |||
| 167 | int vals = cb_lookup_vals(cb->lookup, cb->ndimentions, cb->nentries); | 167 | int vals = cb_lookup_vals(cb->lookup, cb->ndimentions, cb->nentries); |
| 168 | cb->dimentions = av_malloc(sizeof(float) * cb->nentries * cb->ndimentions); | 168 | cb->dimentions = av_malloc(sizeof(float) * cb->nentries * cb->ndimentions); |
| 169 | cb->pow2 = av_mallocz(sizeof(float) * cb->nentries); | 169 | cb->pow2 = av_mallocz(sizeof(float) * cb->nentries); |
| 170 | if (!cb->dimentions || !cb->pow2) | ||
| 171 | return AVERROR(ENOMEM); | ||
| 170 | for (i = 0; i < cb->nentries; i++) { | 172 | for (i = 0; i < cb->nentries; i++) { |
| 171 | float last = 0; | 173 | float last = 0; |
| 172 | int j; | 174 | int j; |
| @@ -187,13 +189,16 @@ static void ready_codebook(vorbis_enc_codebook *cb) · 14 unmodified lines | |||
| 187 | cb->pow2[i] /= 2.; | 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 | int i; | 197 | int i; |
| 195 | assert(rc->type == 2); | 198 | assert(rc->type == 2); |
| 196 | rc->maxes = av_mallocz(sizeof(float[2]) * rc->classifications); | 199 | rc->maxes = av_mallocz(sizeof(float[2]) * rc->classifications); |
| 200 | if (!rc->maxes) | ||
| 201 | return AVERROR(ENOMEM); | ||
| 197 | for (i = 0; i < rc->classifications; i++) { | 202 | for (i = 0; i < rc->classifications; i++) { |
| 198 | int j; | 203 | int j; |
| 199 | vorbis_enc_codebook * cb; | 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 | rc->maxes[i][0] += 0.8; | 228 | rc->maxes[i][0] += 0.8; |
| 224 | rc->maxes[i][1] += 0.8; | 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, | 234 | static int create_vorbis_context(vorbis_enc_context *venc, |
| 229 | AVCodecContext *avccontext) | 235 | AVCodecContext *avccontext) |
| 230 | { | 236 | { |
| 231 | vorbis_enc_floor *fc; | 237 | vorbis_enc_floor *fc; |
| 232 | vorbis_enc_residue *rc; | 238 | vorbis_enc_residue *rc; |
| 233 | vorbis_enc_mapping *mc; | 239 | vorbis_enc_mapping *mc; |
| 234 | int i, book; | 240 | int i, book, ret; |
| 235 | 241 | ||
| 236 | venc->channels = avccontext->channels; | 242 | venc->channels = avccontext->channels; |
| 237 | venc->sample_rate = avccontext->sample_rate; | 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 | venc->ncodebooks = FF_ARRAY_ELEMS(cvectors); | 246 | venc->ncodebooks = FF_ARRAY_ELEMS(cvectors); |
| 241 | venc->codebooks = av_malloc(sizeof(vorbis_enc_codebook) * venc->ncodebooks); | 247 | venc->codebooks = av_malloc(sizeof(vorbis_enc_codebook) * venc->ncodebooks); |
| 248 | if (!venc->codebooks) | ||
| 249 | return AVERROR(ENOMEM); | ||
| 242 | 250 | ||
| 243 | // codebook 0..14 - floor1 book, values 0..255 | 251 | // codebook 0..14 - floor1 book, values 0..255 |
| 244 | // codebook 15 residue masterbook | 252 | // codebook 15 residue masterbook |
| @@ -255,27 +263,36 @@ static void create_vorbis_context(vorbis_enc_context *venc, · 10 unmodified lines | |||
| 255 | 263 | ||
| 256 | cb->lens = av_malloc(sizeof(uint8_t) * cb->nentries); | 264 | cb->lens = av_malloc(sizeof(uint8_t) * cb->nentries); |
| 257 | cb->codewords = av_malloc(sizeof(uint32_t) * cb->nentries); | 265 | cb->codewords = av_malloc(sizeof(uint32_t) * cb->nentries); |
| 266 | if (!cb->lens || !cb->codewords) | ||
| 267 | return AVERROR(ENOMEM); | ||
| 258 | memcpy(cb->lens, cvectors[book].clens, cvectors[book].len); | 268 | memcpy(cb->lens, cvectors[book].clens, cvectors[book].len); |
| 259 | memset(cb->lens + cvectors[book].len, 0, cb->nentries - cvectors[book].len); | 269 | memset(cb->lens + cvectors[book].len, 0, cb->nentries - cvectors[book].len); |
| 260 | 270 | ||
| 261 | if (cb->lookup) { | 271 | if (cb->lookup) { |
| 262 | vals = cb_lookup_vals(cb->lookup, cb->ndimentions, cb->nentries); | 272 | vals = cb_lookup_vals(cb->lookup, cb->ndimentions, cb->nentries); |
| 263 | cb->quantlist = av_malloc(sizeof(int) * vals); | 273 | cb->quantlist = av_malloc(sizeof(int) * vals); |
| 274 | if (!cb->quantlist) | ||
| 275 | return AVERROR(ENOMEM); | ||
| 264 | for (i = 0; i < vals; i++) | 276 | for (i = 0; i < vals; i++) |
| 265 | cb->quantlist[i] = cvectors[book].quant[i]; | 277 | cb->quantlist[i] = cvectors[book].quant[i]; |
| 266 | } else { | 278 | } else { |
| 267 | cb->quantlist = NULL; | 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 | venc->nfloors = 1; | 285 | venc->nfloors = 1; |
| 273 | venc->floors = av_malloc(sizeof(vorbis_enc_floor) * venc->nfloors); | 286 | venc->floors = av_malloc(sizeof(vorbis_enc_floor) * venc->nfloors); |
| 287 | if (!venc->floors) | ||
| 288 | return AVERROR(ENOMEM); | ||
| 274 | 289 | ||
| 275 | // just 1 floor | 290 | // just 1 floor |
| 276 | fc = &venc->floors[0]; | 291 | fc = &venc->floors[0]; |
| 277 | fc->partitions = NUM_FLOOR_PARTITIONS; | 292 | fc->partitions = NUM_FLOOR_PARTITIONS; |
| 278 | fc->partition_to_class = av_malloc(sizeof(int) * fc->partitions); | 293 | fc->partition_to_class = av_malloc(sizeof(int) * fc->partitions); |
| 294 | if (!fc->partition_to_class) | ||
| 295 | return AVERROR(ENOMEM); | ||
| 279 | fc->nclasses = 0; | 296 | fc->nclasses = 0; |
| 280 | for (i = 0; i < fc->partitions; i++) { | 297 | for (i = 0; i < fc->partitions; i++) { |
| 281 | static const int a[] = {0, 1, 2, 2, 3, 3, 4, 4}; | 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 | fc->nclasses++; | 302 | fc->nclasses++; |
| 286 | fc->classes = av_malloc(sizeof(vorbis_enc_floor_class) * fc->nclasses); | 303 | fc->classes = av_malloc(sizeof(vorbis_enc_floor_class) * fc->nclasses); |
| 304 | if (!fc->classes) | ||
| 305 | return AVERROR(ENOMEM); | ||
| 287 | for (i = 0; i < fc->nclasses; i++) { | 306 | for (i = 0; i < fc->nclasses; i++) { |
| 288 | vorbis_enc_floor_class * c = &fc->classes[i]; | 307 | vorbis_enc_floor_class * c = &fc->classes[i]; |
| 289 | int j, books; | 308 | int j, books; |
| @@ -292,6 +311,8 @@ static void create_vorbis_context(vorbis_enc_context *venc, · 2 unmodified lines | |||
| 292 | c->masterbook = floor_classes[i].masterbook; | 311 | c->masterbook = floor_classes[i].masterbook; |
| 293 | books = (1 << c->subclass); | 312 | books = (1 << c->subclass); |
| 294 | c->books = av_malloc(sizeof(int) * books); | 313 | c->books = av_malloc(sizeof(int) * books); |
| 314 | if (!c->books) | ||
| 315 | return AVERROR(ENOMEM); | ||
| 295 | for (j = 0; j < books; j++) | 316 | for (j = 0; j < books; j++) |
| 296 | c->books[j] = floor_classes[i].nbooks[j]; | 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 | fc->values += fc->classes[fc->partition_to_class[i]].dim; | 324 | fc->values += fc->classes[fc->partition_to_class[i]].dim; |
| 304 | 325 | ||
| 305 | fc->list = av_malloc(sizeof(vorbis_floor1_entry) * fc->values); | 326 | fc->list = av_malloc(sizeof(vorbis_floor1_entry) * fc->values); |
| 327 | if (!fc->list) | ||
| 328 | return AVERROR(ENOMEM); | ||
| 306 | fc->list[0].x = 0; | 329 | fc->list[0].x = 0; |
| 307 | fc->list[1].x = 1 << fc->rangebits; | 330 | fc->list[1].x = 1 << fc->rangebits; |
| 308 | for (i = 2; i < fc->values; i++) { | 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 | venc->nresidues = 1; | 341 | venc->nresidues = 1; |
| 319 | venc->residues = av_malloc(sizeof(vorbis_enc_residue) * venc->nresidues); | 342 | venc->residues = av_malloc(sizeof(vorbis_enc_residue) * venc->nresidues); |
| 343 | if (!venc->residues) | ||
| 344 | return AVERROR(ENOMEM); | ||
| 320 | 345 | ||
| 321 | // single residue | 346 | // single residue |
| 322 | rc = &venc->residues[0]; | 347 | rc = &venc->residues[0]; |
| @@ -327,6 +352,8 @@ static void create_vorbis_context(vorbis_enc_context *venc, · 4 unmodified lines | |||
| 327 | rc->classifications = 10; | 352 | rc->classifications = 10; |
| 328 | rc->classbook = 15; | 353 | rc->classbook = 15; |
| 329 | rc->books = av_malloc(sizeof(*rc->books) * rc->classifications); | 354 | rc->books = av_malloc(sizeof(*rc->books) * rc->classifications); |
| 355 | if (!rc->books) | ||
| 356 | return AVERROR(ENOMEM); | ||
| 330 | { | 357 | { |
| 331 | static const int8_t a[10][8] = { | 358 | static const int8_t a[10][8] = { |
| 332 | { -1, -1, -1, -1, -1, -1, -1, -1, }, | 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 | memcpy(rc->books, a, sizeof a); | 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 | venc->nmappings = 1; | 375 | venc->nmappings = 1; |
| 348 | venc->mappings = av_malloc(sizeof(vorbis_enc_mapping) * venc->nmappings); | 376 | venc->mappings = av_malloc(sizeof(vorbis_enc_mapping) * venc->nmappings); |
| 377 | if (!venc->mappings) | ||
| 378 | return AVERROR(ENOMEM); | ||
| 349 | 379 | ||
| 350 | // single mapping | 380 | // single mapping |
| 351 | mc = &venc->mappings[0]; | 381 | mc = &venc->mappings[0]; |
| 352 | mc->submaps = 1; | 382 | mc->submaps = 1; |
| 353 | mc->mux = av_malloc(sizeof(int) * venc->channels); | 383 | mc->mux = av_malloc(sizeof(int) * venc->channels); |
| 384 | if (!mc->mux) | ||
| 385 | return AVERROR(ENOMEM); | ||
| 354 | for (i = 0; i < venc->channels; i++) | 386 | for (i = 0; i < venc->channels; i++) |
| 355 | mc->mux[i] = 0; | 387 | mc->mux[i] = 0; |
| 356 | mc->floor = av_malloc(sizeof(int) * mc->submaps); | 388 | mc->floor = av_malloc(sizeof(int) * mc->submaps); |
| 357 | mc->residue = av_malloc(sizeof(int) * mc->submaps); | 389 | mc->residue = av_malloc(sizeof(int) * mc->submaps); |
| 390 | if (!mc->floor || !mc->residue) | ||
| 391 | return AVERROR(ENOMEM); | ||
| 358 | for (i = 0; i < mc->submaps; i++) { | 392 | for (i = 0; i < mc->submaps; i++) { |
| 359 | mc->floor[i] = 0; | 393 | mc->floor[i] = 0; |
| 360 | mc->residue[i] = 0; | 394 | mc->residue[i] = 0; |
| @@ -362,6 +396,8 @@ static void create_vorbis_context(vorbis_enc_context *venc, · 1 unmodified line | |||
| 362 | mc->coupling_steps = venc->channels == 2 ? 1 : 0; | 396 | mc->coupling_steps = venc->channels == 2 ? 1 : 0; |
| 363 | mc->magnitude = av_malloc(sizeof(int) * mc->coupling_steps); | 397 | mc->magnitude = av_malloc(sizeof(int) * mc->coupling_steps); |
| 364 | mc->angle = av_malloc(sizeof(int) * mc->coupling_steps); | 398 | mc->angle = av_malloc(sizeof(int) * mc->coupling_steps); |
| 399 | if (!mc->magnitude || !mc->angle) | ||
| 400 | return AVERROR(ENOMEM); | ||
| 365 | if (mc->coupling_steps) { | 401 | if (mc->coupling_steps) { |
| 366 | mc->magnitude[0] = 0; | 402 | mc->magnitude[0] = 0; |
| 367 | mc->angle[0] = 1; | 403 | mc->angle[0] = 1; |
| @@ -369,6 +405,8 @@ static void create_vorbis_context(vorbis_enc_context *venc, · 1 unmodified line | |||
| 369 | 405 | ||
| 370 | venc->nmodes = 1; | 406 | venc->nmodes = 1; |
| 371 | venc->modes = av_malloc(sizeof(vorbis_enc_mode) * venc->nmodes); | 407 | venc->modes = av_malloc(sizeof(vorbis_enc_mode) * venc->nmodes); |
| 408 | if (!venc->modes) | ||
| 409 | return AVERROR(ENOMEM); | ||
| 372 | 410 | ||
| 373 | // single mode | 411 | // single mode |
| 374 | venc->modes[0].blockflag = 0; | 412 | venc->modes[0].blockflag = 0; |
| @@ -379,12 +417,18 @@ static void create_vorbis_context(vorbis_enc_context *venc, · 4 unmodified lines | |||
| 379 | venc->samples = av_malloc(sizeof(float) * venc->channels * (1 << venc->log2_blocksize[1])); | 417 | venc->samples = av_malloc(sizeof(float) * venc->channels * (1 << venc->log2_blocksize[1])); |
| 380 | venc->floor = av_malloc(sizeof(float) * venc->channels * (1 << venc->log2_blocksize[1]) / 2); | 418 | venc->floor = av_malloc(sizeof(float) * venc->channels * (1 << venc->log2_blocksize[1]) / 2); |
| 381 | venc->coeffs = av_malloc(sizeof(float) * venc->channels * (1 << venc->log2_blocksize[1]) / 2); | 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 | venc->win[0] = ff_vorbis_vwin[venc->log2_blocksize[0] - 6]; | 423 | venc->win[0] = ff_vorbis_vwin[venc->log2_blocksize[0] - 6]; |
| 384 | venc->win[1] = ff_vorbis_vwin[venc->log2_blocksize[1] - 6]; | 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); | 426 | if ((ret = ff_mdct_init(&venc->mdct[0], venc->log2_blocksize[0], 0, 1.0)) < 0) |
| 387 | ff_mdct_init(&venc->mdct[1], venc->log2_blocksize[1], 0, 1.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 | static void put_float(PutBitContext *pb, float f) | 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 | len = hlens[0] + hlens[1] + hlens[2]; | 692 | len = hlens[0] + hlens[1] + hlens[2]; |
| 649 | p = *out = av_mallocz(64 + len + len/255); | 693 | p = *out = av_mallocz(64 + len + len/255); |
| 694 | if (!p) | ||
| 695 | return AVERROR(ENOMEM); | ||
| 650 | 696 | ||
| 651 | *p++ = 2; | 697 | *p++ = 2; |
| 652 | p += av_xiphlacing(p, hlens[0]); | 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 | return 1; | 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 | static int vorbis_encode_frame(AVCodecContext *avccontext, | 1001 | static int vorbis_encode_frame(AVCodecContext *avccontext, |
| 983 | unsigned char *packets, | 1002 | unsigned char *packets, |
| 984 | int buf_size, void *data) | 1003 | int buf_size, void *data) |
| @@ -1102,6 +1121,43 @@ static av_cold int vorbis_encode_close(AVCodecContext *avccontext) · 117 unmodified lines | |||
| 1102 | return 0 ; | 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 | AVCodec ff_vorbis_encoder = { | 1161 | AVCodec ff_vorbis_encoder = { |
| 1106 | .name = "vorbis", | 1162 | .name = "vorbis", |
| 1107 | .type = AVMEDIA_TYPE_AUDIO, | 1163 | .type = AVMEDIA_TYPE_AUDIO, |
| @@ -44,7 +44,7 @@ static int xwd_encode_frame(AVCodecContext *avctx, AVPacket *pkt, · 43 unmodified lines | |||
| 44 | { | 44 | { |
| 45 | enum PixelFormat pix_fmt = avctx->pix_fmt; | 45 | enum PixelFormat pix_fmt = avctx->pix_fmt; |
| 46 | uint32_t pixdepth, bpp, bpad, ncolors = 0, lsize, vclass, be = 0; | 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 | uint32_t header_size; | 48 | uint32_t header_size; |
| 49 | int i, out_size, ret; | 49 | int i, out_size, ret; |
| 50 | uint8_t *ptr, *buf; | 50 | uint8_t *ptr, *buf; |
| @@ -133,6 +133,8 @@ static int xwd_encode_frame(AVCodecContext *avctx, AVPacket *pkt, · 82 unmodified lines | |||
| 133 | ncolors = 256; | 133 | ncolors = 256; |
| 134 | break; | 134 | break; |
| 135 | case PIX_FMT_MONOWHITE: | 135 | case PIX_FMT_MONOWHITE: |
| 136 | be = 1; | ||
| 137 | bitorder = 1; | ||
| 136 | bpp = 1; | 138 | bpp = 1; |
| 137 | bpad = 8; | 139 | bpad = 8; |
| 138 | vclass = XWD_STATIC_GRAY; | 140 | vclass = XWD_STATIC_GRAY; |
| @@ -164,7 +166,7 @@ static int xwd_encode_frame(AVCodecContext *avctx, AVPacket *pkt, · 25 unmodified lines | |||
| 164 | bytestream_put_be32(&buf, 0); // bitmap x offset | 166 | bytestream_put_be32(&buf, 0); // bitmap x offset |
| 165 | bytestream_put_be32(&buf, be); // byte order | 167 | bytestream_put_be32(&buf, be); // byte order |
| 166 | bytestream_put_be32(&buf, 32); // bitmap unit | 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 | bytestream_put_be32(&buf, bpad); // bitmap scan-line pad in bits | 170 | bytestream_put_be32(&buf, bpad); // bitmap scan-line pad in bits |
| 169 | bytestream_put_be32(&buf, bpp); // bits per pixel | 171 | bytestream_put_be32(&buf, bpp); // bits per pixel |
| 170 | bytestream_put_be32(&buf, lsize); // bytes per scan-line | 172 | bytestream_put_be32(&buf, lsize); // bytes per scan-line |