History

Merge remote-tracking branch 'qatar/master'

* qatar/master: (36 commits) adpcmenc: Use correct frame_size for Yamaha ADPCM. avcodec: add ff_samples_to_time_base() convenience function to internal.h adx parser: set duration mlp parser: set duration instead of frame_size gsm parser: set duration mpegaudio parser: set duration instead of frame_size (e)ac3 parser: set duration instead of frame_size flac parser: set duration instead of frame_size avcodec: add duration field to AVCodecParserContext avutil: add av_rescale_q_rnd() to allow different rounding pnmdec: remove useless .pix_fmts libmp3lame: support float and s32 sample formats libmp3lame: renaming, rearrangement, alignment, and comments libmp3lame: use the LAME default bit rate libmp3lame: use avpriv_mpegaudio_decode_header() for output frame parsing libmp3lame: cosmetics: remove some pointless comments libmp3lame: convert some debugging code to av_dlog() libmp3lame: remove outdated comment. libmp3lame: do not set coded_frame->key_frame. libmp3lame: improve error handling in MP3lame_encode_init() ... Conflicts: doc/APIchanges libavcodec/libmp3lame.c libavcodec/pcxenc.c libavcodec/pnmdec.c libavcodec/pnmenc.c libavcodec/sgienc.c libavcodec/utils.c libavformat/hls.c libavutil/avutil.h libswscale/x86/swscale_mmx.c

Michael Niedermayer committed 14 years ago

Commit eadd4262 parents a923b6b 770a5c634 files · +485 −382Browse files

Unified · Split

34 files
  1. doc/APIchanges +6 −0
  2. libavcodec/Makefile +1 −1
  3. libavcodec/aac_ac3_parser.c +1 −1
  4. libavcodec/adpcmenc.c +1 −1
  5. libavcodec/adx_parser.c +3 −0
  6. libavcodec/avcodec.h +7 −0
  7. libavcodec/flac_parser.c +6 −4
  8. libavcodec/gsm_parser.c +12 −2
  9. libavcodec/huffyuv.c +20 −9
  10. libavcodec/internal.h +11 −0
  11. libavcodec/libmp3lame.c +164 −189
  12. libavcodec/libspeexenc.c +1 −4
  13. libavcodec/libvorbis.c +3 −2
  14. libavcodec/mlp_parser.c +1 −1
  15. libavcodec/mpegaudio_parser.c +1 −1
  16. libavcodec/pcxenc.c +22 −9
  17. libavcodec/pnmdec.c +0 −5
  18. libavcodec/pnmenc.c +19 −13
  19. libavcodec/roqvideo.h +1 −1
  20. libavcodec/roqvideoenc.c +23 −16
  21. libavcodec/sgienc.c +25 −14
  22. libavcodec/targaenc.c +31 −29
  23. libavcodec/utils.c +6 −9
  24. libavcodec/v410enc.c +13 −12
  25. libavcodec/x86/h264_deblock.asm +8 −1
  26. libavcodec/zmbvenc.c +32 −19
  27. libavformat/hls.c +23 −22
  28. libavformat/utils.c +16 −3
  29. libavutil/avutil.h +1 −1
  30. libavutil/mathematics.c +9 −2
  31. libavutil/mathematics.h +6 −0
  32. libswscale/swscale_internal.h +6 −5
  33. libswscale/x86/swscale_template.c +2 −2
  34. tests/ref/acodec/adpcm_yam +4 −4
doc/APIchanges+6−0
@@ -32,6 +32,12 @@ API changes, most recent first: · 31 unmodified lines
3232 2012-01-24 - xxxxxxx - lavfi 2.60.100
3333 Add avfilter_graph_dump.
3434
35+2012-xx-xx - xxxxxxx - lavc 54.x.x
36+ Add duration field to AVCodecParserContext
37+
38+2012-02-xx - xxxxxxx - lavu 51.23.1 - mathematics.h
39+ Add av_rescale_q_rnd()
40+
3541 2012-02-xx - xxxxxxx - lavu 51.22.1 - pixdesc.h
3642 Add PIX_FMT_PSEUDOPAL flag.
3743
libavcodec/Makefile+1−1
@@ -630,7 +630,7 @@ OBJS-$(CONFIG_LIBGSM_DECODER) += libgsm.o · 629 unmodified lines
630630 OBJS-$(CONFIG_LIBGSM_ENCODER) += libgsm.o
631631 OBJS-$(CONFIG_LIBGSM_MS_DECODER) += libgsm.o
632632 OBJS-$(CONFIG_LIBGSM_MS_ENCODER) += libgsm.o
633−OBJS-$(CONFIG_LIBMP3LAME_ENCODER) += libmp3lame.o
633+OBJS-$(CONFIG_LIBMP3LAME_ENCODER) += libmp3lame.o mpegaudiodecheader.o
634634 OBJS-$(CONFIG_LIBOPENCORE_AMRNB_DECODER) += libopencore-amr.o
635635 OBJS-$(CONFIG_LIBOPENCORE_AMRNB_ENCODER) += libopencore-amr.o
636636 OBJS-$(CONFIG_LIBOPENCORE_AMRWB_DECODER) += libopencore-amr.o
libavcodec/aac_ac3_parser.c+1−1
@@ -93,7 +93,7 @@ get_next: · 92 unmodified lines
9393 avctx->channels = s->channels;
9494 avctx->channel_layout = s->channel_layout;
9595 }
96− avctx->frame_size = s->samples;
96+ s1->duration = s->samples;
9797 avctx->audio_service_type = s->service_type;
9898 }
9999
libavcodec/adpcmenc.c+1−1
@@ -125,7 +125,7 @@ static av_cold int adpcm_encode_init(AVCodecContext *avctx) · 124 unmodified lines
125125 }
126126 break;
127127 case CODEC_ID_ADPCM_YAMAHA:
128− avctx->frame_size = BLKSIZE * avctx->channels;
128+ avctx->frame_size = BLKSIZE * 2 / avctx->channels;
129129 avctx->block_align = BLKSIZE;
130130 break;
131131 case CODEC_ID_ADPCM_SWF:
libavcodec/adx_parser.c+3−0
@@ -80,6 +80,9 @@ static int adx_parse(AVCodecParserContext *s1, · 79 unmodified lines
8080 *poutbuf_size = 0;
8181 return buf_size;
8282 }
83+
84+ s1->duration = BLOCK_SAMPLES;
85+
8386 *poutbuf = buf;
8487 *poutbuf_size = buf_size;
8588 return next;
libavcodec/avcodec.h+7−0
@@ -4182,6 +4182,13 @@ typedef struct AVCodecParserContext { · 4181 unmodified lines
41824182 * Previous frame byte position.
41834183 */
41844184 int64_t last_pos;
4185+
4186+ /**
4187+ * Duration of the current frame.
4188+ * For audio, this is in units of 1 / AVCodecContext.sample_rate.
4189+ * For all other types, this is in units of AVCodecContext.time_base.
4190+ */
4191+ int duration;
41854192 } AVCodecParserContext;
41864193
41874194 typedef struct AVCodecParser {
libavcodec/flac_parser.c+6−4
@@ -71,6 +71,7 @@ typedef struct FLACHeaderMarker { · 70 unmodified lines
7171 } FLACHeaderMarker;
7272
7373 typedef struct FLACParseContext {
74+ AVCodecParserContext *pc; /**< parent context */
7475 AVCodecContext *avctx; /**< codec context pointer for logging */
7576 FLACHeaderMarker *headers; /**< linked-list that starts at the first
7677 CRC-8 verified header within buffer */
@@ -458,7 +459,7 @@ static int get_best_header(FLACParseContext* fpc, const uint8_t **poutbuf, · 381 unmodified lines
458459
459460 fpc->avctx->sample_rate = header->fi.samplerate;
460461 fpc->avctx->channels = header->fi.channels;
461− fpc->avctx->frame_size = header->fi.blocksize;
462+ fpc->pc->duration = header->fi.blocksize;
462463 *poutbuf = flac_fifo_read_wrap(fpc, header->offset, *poutbuf_size,
463464 &fpc->wrap_buf,
464465 &fpc->wrap_buf_allocated_size);
@@ -484,7 +485,7 @@ static int flac_parse(AVCodecParserContext *s, AVCodecContext *avctx, · 19 unmodified lines
484485 if (s->flags & PARSER_FLAG_COMPLETE_FRAMES) {
485486 FLACFrameInfo fi;
486487 if (frame_header_is_valid(avctx, buf, &fi))
487− avctx->frame_size = fi.blocksize;
488+ s->duration = fi.blocksize;
488489 *poutbuf = buf;
489490 *poutbuf_size = buf_size;
490491 return buf_size;
@@ -630,8 +631,8 @@ static int flac_parse(AVCodecParserContext *s, AVCodecContext *avctx, · 139 unmodified lines
630631 av_log(avctx, AV_LOG_DEBUG, "Junk frame till offset %i\n",
631632 fpc->best_header->offset);
632633
633− /* Set frame_size to 0. It is unknown or invalid in a junk frame. */
634− avctx->frame_size = 0;
634+ /* Set duration to 0. It is unknown or invalid in a junk frame. */
635+ s->duration = 0;
635636 *poutbuf_size = fpc->best_header->offset;
636637 *poutbuf = flac_fifo_read_wrap(fpc, 0, *poutbuf_size,
637638 &fpc->wrap_buf,
@@ -652,6 +653,7 @@ handle_error: · 14 unmodified lines
652653 static int flac_parse_init(AVCodecParserContext *c)
653654 {
654655 FLACParseContext *fpc = c->priv_data;
656+ fpc->pc = c;
655657 /* There will generally be FLAC_MIN_HEADERS buffered in the fifo before
656658 it drains. This is allocated early to avoid slow reallocation. */
657659 fpc->fifo_buf = av_fifo_alloc(FLAC_AVG_FRAME_SIZE * (FLAC_MIN_HEADERS + 3));
libavcodec/gsm_parser.c+12−2
@@ -31,6 +31,7 @@ · 30 unmodified lines
3131 typedef struct GSMParseContext {
3232 ParseContext pc;
3333 int block_size;
34+ int duration;
3435 int remaining;
3536 } GSMParseContext;
3637
@@ -44,8 +45,14 @@ static int gsm_parse(AVCodecParserContext *s1, AVCodecContext *avctx, · 7 unmodified lines
4445
4546 if (!s->block_size) {
4647 switch (avctx->codec_id) {
47− case CODEC_ID_GSM: s->block_size = GSM_BLOCK_SIZE; break;
48− case CODEC_ID_GSM_MS: s->block_size = GSM_MS_BLOCK_SIZE; break;
48+ case CODEC_ID_GSM:
49+ s->block_size = GSM_BLOCK_SIZE;
50+ s->duration = GSM_FRAME_SIZE;
51+ break;
52+ case CODEC_ID_GSM_MS:
53+ s->block_size = GSM_MS_BLOCK_SIZE;
54+ s->duration = GSM_FRAME_SIZE * 2;
55+ break;
4956 default:
5057 return AVERROR(EINVAL);
5158 }
@@ -66,6 +73,9 @@ static int gsm_parse(AVCodecParserContext *s1, AVCodecContext *avctx, · 14 unmodified lines
6673 *poutbuf_size = 0;
6774 return buf_size;
6875 }
76+
77+ s1->duration = s->duration;
78+
6979 *poutbuf = buf;
7080 *poutbuf_size = buf_size;
7181 return next;
libavcodec/huffyuv.c+20−9
@@ -1261,9 +1261,10 @@ static av_cold int decode_end(AVCodecContext *avctx) · 1260 unmodified lines
12611261 #endif /* CONFIG_HUFFYUV_DECODER || CONFIG_FFVHUFF_DECODER */
12621262
12631263 #if CONFIG_HUFFYUV_ENCODER || CONFIG_FFVHUFF_ENCODER
1264−static int encode_frame(AVCodecContext *avctx, unsigned char *buf, int buf_size, void *data){
1264+static int encode_frame(AVCodecContext *avctx, AVPacket *pkt,
1265+ const AVFrame *pict, int *got_packet)
1266+{
12651267 HYuvContext *s = avctx->priv_data;
1266− AVFrame *pict = data;
12671268 const int width= s->width;
12681269 const int width2= s->width>>1;
12691270 const int height= s->height;
@@ -1271,7 +1272,13 @@ static int encode_frame(AVCodecContext *avctx, unsigned char *buf, int buf_size, · 1 unmodified line
12711272 const int fake_ustride= s->interlaced ? pict->linesize[1]*2 : pict->linesize[1];
12721273 const int fake_vstride= s->interlaced ? pict->linesize[2]*2 : pict->linesize[2];
12731274 AVFrame * const p= &s->picture;
1274− int i, j, size=0;
1275+ int i, j, size = 0, ret;
1276+
1277+ if (!pkt->data &&
1278+ (ret = av_new_packet(pkt, width * height * 3 * 4 + FF_MIN_BUFFER_SIZE)) < 0) {
1279+ av_log(avctx, AV_LOG_ERROR, "Error allocating output packet.\n");
1280+ return ret;
1281+ }
12751282
12761283 *p = *pict;
12771284 p->pict_type= AV_PICTURE_TYPE_I;
@@ -1282,7 +1289,7 @@ static int encode_frame(AVCodecContext *avctx, unsigned char *buf, int buf_size, · 4 unmodified lines
12821289 generate_len_table(s->len[i], s->stats[i]);
12831290 if(generate_bits_table(s->bits[i], s->len[i])<0)
12841291 return -1;
1285− size+= store_table(s, s->len[i], &buf[size]);
1292+ size += store_table(s, s->len[i], &pkt->data[size]);
12861293 }
12871294
12881295 for(i=0; i<3; i++)
@@ -1290,7 +1297,7 @@ static int encode_frame(AVCodecContext *avctx, unsigned char *buf, int buf_size, · 1 unmodified line
12901297 s->stats[i][j] >>= 1;
12911298 }
12921299
1293− init_put_bits(&s->pb, buf+size, buf_size-size);
1300+ init_put_bits(&s->pb, pkt->data + size, pkt->size - size);
12941301
12951302 if(avctx->pix_fmt == PIX_FMT_YUV422P || avctx->pix_fmt == PIX_FMT_YUV420P){
12961303 int lefty, leftu, leftv, y, cy;
@@ -1473,12 +1480,16 @@ static int encode_frame(AVCodecContext *avctx, unsigned char *buf, int buf_size, · 176 unmodified lines
14731480 avctx->stats_out[0] = '\0';
14741481 if(!(s->avctx->flags2 & CODEC_FLAG2_NO_OUTPUT)){
14751482 flush_put_bits(&s->pb);
1476− s->dsp.bswap_buf((uint32_t*)buf, (uint32_t*)buf, size);
1483+ s->dsp.bswap_buf((uint32_t*)pkt->data, (uint32_t*)pkt->data, size);
14771484 }
14781485
14791486 s->picture_number++;
14801487
1481− return size*4;
1488+ pkt->size = size*4;
1489+ pkt->flags |= AV_PKT_FLAG_KEY;
1490+ *got_packet = 1;
1491+
1492+ return 0;
14821493 }
14831494
14841495 static av_cold int encode_end(AVCodecContext *avctx)
@@ -1531,7 +1542,7 @@ AVCodec ff_huffyuv_encoder = { · 46 unmodified lines
15311542 .id = CODEC_ID_HUFFYUV,
15321543 .priv_data_size = sizeof(HYuvContext),
15331544 .init = encode_init,
1534− .encode = encode_frame,
1545+ .encode2 = encode_frame,
15351546 .close = encode_end,
15361547 .pix_fmts= (const enum PixelFormat[]){PIX_FMT_YUV422P, PIX_FMT_RGB24, PIX_FMT_RGB32, PIX_FMT_NONE},
15371548 .long_name = NULL_IF_CONFIG_SMALL("Huffyuv / HuffYUV"),
@@ -1545,7 +1556,7 @@ AVCodec ff_ffvhuff_encoder = { · 7 unmodified lines
15451556 .id = CODEC_ID_FFVHUFF,
15461557 .priv_data_size = sizeof(HYuvContext),
15471558 .init = encode_init,
1548− .encode = encode_frame,
1559+ .encode2 = encode_frame,
15491560 .close = encode_end,
15501561 .pix_fmts= (const enum PixelFormat[]){PIX_FMT_YUV420P, PIX_FMT_YUV422P, PIX_FMT_RGB24, PIX_FMT_RGB32, PIX_FMT_NONE},
15511562 .long_name = NULL_IF_CONFIG_SMALL("Huffyuv FFmpeg variant"),
libavcodec/internal.h+11−0
@@ -26,6 +26,7 @@ · 25 unmodified lines
2626
2727 #include <stdint.h>
2828
29+#include "libavutil/mathematics.h"
2930 #include "libavutil/pixfmt.h"
3031 #include "avcodec.h"
3132
@@ -137,4 +138,14 @@ int avpriv_unlock_avformat(void); · 105 unmodified lines
137138 */
138139 int ff_alloc_packet(AVPacket *avpkt, int size);
139140
141+/**
142+ * Rescale from sample rate to AVCodecContext.time_base.
143+ */
144+static av_always_inline int64_t ff_samples_to_time_base(AVCodecContext *avctx,
145+ int64_t samples)
146+{
147+ return av_rescale_q(samples, (AVRational){ 1, avctx->sample_rate },
148+ avctx->time_base);
149+}
150+
140151 #endif /* AVCODEC_INTERNAL_H */
libavcodec/libmp3lame.c+164−189
@@ -24,261 +24,227 @@ · 23 unmodified lines
2424 * Interface to libmp3lame for mp3 encoding.
2525 */
2626
27+#include <lame/lame.h>
28+
2729 #include "libavutil/intreadwrite.h"
2830 #include "libavutil/log.h"
2931 #include "libavutil/opt.h"
3032 #include "avcodec.h"
33+#include "internal.h"
3134 #include "mpegaudio.h"
32−#include <lame/lame.h>
35+#include "mpegaudiodecheader.h"
3336
3437 #define BUFFER_SIZE (7200 + 2 * MPA_FRAME_SIZE + MPA_FRAME_SIZE / 4+1000) // FIXME: Buffer size to small? Adding 1000 to make up for it.
35−typedef struct Mp3AudioContext {
38+
39+typedef struct LAMEContext {
3640 AVClass *class;
41+ AVCodecContext *avctx;
3742 lame_global_flags *gfp;
38− int stereo;
3943 uint8_t buffer[BUFFER_SIZE];
4044 int buffer_index;
41− struct {
42− int *left;
43− int *right;
44− } s32_data;
4545 int reservoir;
46−} Mp3AudioContext;
46+ void *planar_samples[2];
47+} LAMEContext;
48+
4749
48−static av_cold int MP3lame_encode_init(AVCodecContext *avctx)
50+static av_cold int mp3lame_encode_close(AVCodecContext *avctx)
4951 {
50− Mp3AudioContext *s = avctx->priv_data;
52+ LAMEContext *s = avctx->priv_data;
5153
54+ av_freep(&avctx->coded_frame);
55+ av_freep(&s->planar_samples[0]);
56+ av_freep(&s->planar_samples[1]);
57+
58+ lame_close(s->gfp);
59+ return 0;
60+}
61+
62+static av_cold int mp3lame_encode_init(AVCodecContext *avctx)
63+{
64+ LAMEContext *s = avctx->priv_data;
65+ int ret;
66+
67+ s->avctx = avctx;
68+
69+ /* initialize LAME and get defaults */
70+ if ((s->gfp = lame_init()) == NULL)
71+ return AVERROR(ENOMEM);
72+
73+ /* channels */
5274 if (avctx->channels > 2) {
5375 av_log(avctx, AV_LOG_ERROR,
5476 "Invalid number of channels %d, must be <= 2\n", avctx->channels);
55− return AVERROR(EINVAL);
77+ ret = AVERROR(EINVAL);
78+ goto error;
5679 }
80+ lame_set_num_channels(s->gfp, avctx->channels);
81+ lame_set_mode(s->gfp, avctx->channels > 1 ? JOINT_STEREO : MONO);
5782
58− s->stereo = avctx->channels > 1 ? 1 : 0;
59−
60− if ((s->gfp = lame_init()) == NULL)
61− goto err;
62− lame_set_in_samplerate(s->gfp, avctx->sample_rate);
83+ /* sample rate */
84+ lame_set_in_samplerate (s->gfp, avctx->sample_rate);
6385 lame_set_out_samplerate(s->gfp, avctx->sample_rate);
64− lame_set_num_channels(s->gfp, avctx->channels);
65− if (avctx->compression_level == FF_COMPRESSION_DEFAULT) {
86+
87+ /* algorithmic quality */
88+ if (avctx->compression_level == FF_COMPRESSION_DEFAULT)
6689 lame_set_quality(s->gfp, 5);
67− } else {
90+ else
6891 lame_set_quality(s->gfp, avctx->compression_level);
69− }
70− lame_set_mode(s->gfp, s->stereo ? JOINT_STEREO : MONO);
71− lame_set_brate(s->gfp, avctx->bit_rate / 1000);
92+
93+ /* rate control */
7294 if (avctx->flags & CODEC_FLAG_QSCALE) {
73− lame_set_brate(s->gfp, 0);
7495 lame_set_VBR(s->gfp, vbr_default);
7596 lame_set_VBR_quality(s->gfp, avctx->global_quality / (float)FF_QP2LAMBDA);
97+ } else {
98+ if (avctx->bit_rate)
99+ lame_set_brate(s->gfp, avctx->bit_rate / 1000);
76100 }
77− lame_set_bWriteVbrTag(s->gfp,0);
78− lame_set_disable_reservoir(s->gfp, !s->reservoir);
79− if (lame_init_params(s->gfp) < 0)
80− goto err_close;
81101
82− avctx->frame_size = lame_get_framesize(s->gfp);
102+ /* do not get a Xing VBR header frame from LAME */
103+ lame_set_bWriteVbrTag(s->gfp,0);
83104
84− if(!(avctx->coded_frame= avcodec_alloc_frame())) {
85− lame_close(s->gfp);
105+ /* bit reservoir usage */
106+ lame_set_disable_reservoir(s->gfp, !s->reservoir);
86107
87− return AVERROR(ENOMEM);
108+ /* set specified parameters */
109+ if (lame_init_params(s->gfp) < 0) {
110+ ret = -1;
111+ goto error;
88112 }
89113
90− if(AV_SAMPLE_FMT_S32 == avctx->sample_fmt && s->stereo) {
91− int nelem = 2 * avctx->frame_size;
92−
93− if(! (s->s32_data.left = av_malloc(nelem * sizeof(int)))) {
94− av_freep(&avctx->coded_frame);
95− lame_close(s->gfp);
114+ avctx->frame_size = lame_get_framesize(s->gfp);
115+ avctx->coded_frame = avcodec_alloc_frame();
116+ if (!avctx->coded_frame) {
117+ ret = AVERROR(ENOMEM);
118+ goto error;
119+ }
96120
97− return AVERROR(ENOMEM);
121+ /* sample format */
122+ if (avctx->sample_fmt == AV_SAMPLE_FMT_S32 ||
123+ avctx->sample_fmt == AV_SAMPLE_FMT_FLT) {
124+ int ch;
125+ for (ch = 0; ch < avctx->channels; ch++) {
126+ s->planar_samples[ch] = av_malloc(avctx->frame_size *
127+ av_get_bytes_per_sample(avctx->sample_fmt));
128+ if (!s->planar_samples[ch]) {
129+ ret = AVERROR(ENOMEM);
130+ goto error;
131+ }
98132 }
99−
100− s->s32_data.right = s->s32_data.left + avctx->frame_size;
101133 }
102134
103135 return 0;
104−
105−err_close:
106− lame_close(s->gfp);
107−err:
108− return -1;
136+error:
137+ mp3lame_encode_close(avctx);
138+ return ret;
109139 }
110140
111−static const int sSampleRates[] = {
112− 44100, 48000, 32000, 22050, 24000, 16000, 11025, 12000, 8000, 0
113−};
114−
115−static const int sBitRates[2][3][15] = {
116− {
117− { 0, 32, 64, 96, 128, 160, 192, 224, 256, 288, 320, 352, 384, 416, 448 },
118− { 0, 32, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320, 384 },
119− { 0, 32, 40, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320 }
120− },
121− {
122− { 0, 32, 48, 56, 64, 80, 96, 112, 128, 144, 160, 176, 192, 224, 256 },
123− { 0, 8, 16, 24, 32, 40, 48, 56, 64, 80, 96, 112, 128, 144, 160 },
124− { 0, 8, 16, 24, 32, 40, 48, 56, 64, 80, 96, 112, 128, 144, 160 }
125− },
126−};
127−
128−static const int sSamplesPerFrame[2][3] = {
129− { 384, 1152, 1152 },
130− { 384, 1152, 576 }
131−};
132−
133−static const int sBitsPerSlot[3] = { 32, 8, 8 };
134−
135−static int mp3len(void *data, int *samplesPerFrame, int *sampleRate)
141+#define DEINTERLEAVE(type, scale) do { \
142+ int ch, i; \
143+ for (ch = 0; ch < s->avctx->channels; ch++) { \
144+ const type *input = samples; \
145+ type *output = s->planar_samples[ch]; \
146+ input += ch; \
147+ for (i = 0; i < s->avctx->frame_size; i++) { \
148+ output[i] = *input * scale; \
149+ input += s->avctx->channels; \
150+ } \
151+ } \
152+} while (0)
153+
154+static int encode_frame_int16(LAMEContext *s, void *samples)
136155 {
137− uint32_t header = AV_RB32(data);
138− int layerID = 3 - ((header >> 17) & 0x03);
139− int bitRateID = ((header >> 12) & 0x0f);
140− int sampleRateID = ((header >> 10) & 0x03);
141− int bitsPerSlot = sBitsPerSlot[layerID];
142− int isPadded = ((header >> 9) & 0x01);
143− static int const mode_tab[4] = { 2, 3, 1, 0 };
144− int mode = mode_tab[(header >> 19) & 0x03];
145− int mpeg_id = mode > 0;
146− int temp0, temp1, bitRate;
147−
148− if (((header >> 21) & 0x7ff) != 0x7ff || mode == 3 || layerID == 3 ||
149− sampleRateID == 3) {
150− return -1;
156+ if (s->avctx->channels > 1) {
157+ return lame_encode_buffer_interleaved(s->gfp, samples,
158+ s->avctx->frame_size,
159+ s->buffer + s->buffer_index,
160+ BUFFER_SIZE - s->buffer_index);
161+ } else {
162+ return lame_encode_buffer(s->gfp, samples, NULL, s->avctx->frame_size,
163+ s->buffer + s->buffer_index,
164+ BUFFER_SIZE - s->buffer_index);
151165 }
166+}
152167
153− if (!samplesPerFrame)
154− samplesPerFrame = &temp0;
155− if (!sampleRate)
156− sampleRate = &temp1;
168+static int encode_frame_int32(LAMEContext *s, void *samples)
169+{
170+ DEINTERLEAVE(int32_t, 1);
157171
158− //*isMono = ((header >> 6) & 0x03) == 0x03;
172+ return lame_encode_buffer_int(s->gfp,
173+ s->planar_samples[0], s->planar_samples[1],
174+ s->avctx->frame_size,
175+ s->buffer + s->buffer_index,
176+ BUFFER_SIZE - s->buffer_index);
177+}
159178
160− *sampleRate = sSampleRates[sampleRateID] >> mode;
161− bitRate = sBitRates[mpeg_id][layerID][bitRateID] * 1000;
162− *samplesPerFrame = sSamplesPerFrame[mpeg_id][layerID];
163− //av_log(NULL, AV_LOG_DEBUG,
164− // "sr:%d br:%d spf:%d l:%d m:%d\n",
165− // *sampleRate, bitRate, *samplesPerFrame, layerID, mode);
179+static int encode_frame_float(LAMEContext *s, void *samples)
180+{
181+ DEINTERLEAVE(float, 32768.0f);
166182
167− return *samplesPerFrame * bitRate / (bitsPerSlot * *sampleRate) + isPadded;
183+ return lame_encode_buffer_float(s->gfp,
184+ s->planar_samples[0], s->planar_samples[1],
185+ s->avctx->frame_size,
186+ s->buffer + s->buffer_index,
187+ BUFFER_SIZE - s->buffer_index);
168188 }
169189
170−static int MP3lame_encode_frame(AVCodecContext *avctx, unsigned char *frame,
190+static int mp3lame_encode_frame(AVCodecContext *avctx, unsigned char *frame,
171191 int buf_size, void *data)
172192 {
173− Mp3AudioContext *s = avctx->priv_data;
193+ LAMEContext *s = avctx->priv_data;
194+ MPADecodeHeader hdr;
174195 int len;
175196 int lame_result;
176197
177− /* lame 3.91 dies on '1-channel interleaved' data */
178−
179− if (!data){
180− lame_result= lame_encode_flush(
181− s->gfp,
182− s->buffer + s->buffer_index,
183− BUFFER_SIZE - s->buffer_index
184− );
185−#if 2147483647 == INT_MAX
186− }else if(AV_SAMPLE_FMT_S32 == avctx->sample_fmt){
187− if (s->stereo) {
188− int32_t *rp = data;
189− int32_t *mp = rp + 2*avctx->frame_size;
190− int *wpl = s->s32_data.left;
191− int *wpr = s->s32_data.right;
192−
193− while (rp < mp) {
194− *wpl++ = *rp++;
195− *wpr++ = *rp++;
196− }
197−
198− lame_result = lame_encode_buffer_int(
199− s->gfp,
200− s->s32_data.left,
201− s->s32_data.right,
202− avctx->frame_size,
203− s->buffer + s->buffer_index,
204− BUFFER_SIZE - s->buffer_index
205− );
206− } else {
207− lame_result = lame_encode_buffer_int(
208− s->gfp,
209− data,
210− data,
211− avctx->frame_size,
212− s->buffer + s->buffer_index,
213− BUFFER_SIZE - s->buffer_index
214− );
215− }
216−#endif
217− }else{
218− if (s->stereo) {
219− lame_result = lame_encode_buffer_interleaved(
220− s->gfp,
221− data,
222− avctx->frame_size,
223− s->buffer + s->buffer_index,
224− BUFFER_SIZE - s->buffer_index
225− );
226− } else {
227− lame_result = lame_encode_buffer(
228− s->gfp,
229− data,
230− data,
231− avctx->frame_size,
232− s->buffer + s->buffer_index,
233− BUFFER_SIZE - s->buffer_index
234− );
198+ if (data) {
199+ switch (avctx->sample_fmt) {
200+ case AV_SAMPLE_FMT_S16:
201+ lame_result = encode_frame_int16(s, data);
202+ break;
203+ case AV_SAMPLE_FMT_S32:
204+ lame_result = encode_frame_int32(s, data);
205+ break;
206+ case AV_SAMPLE_FMT_FLT:
207+ lame_result = encode_frame_float(s, data);
208+ break;
209+ default:
210+ return AVERROR_BUG;
235211 }
212+ } else {
213+ lame_result = lame_encode_flush(s->gfp, s->buffer + s->buffer_index,
214+ BUFFER_SIZE - s->buffer_index);
236215 }
237−
238216 if (lame_result < 0) {
239217 if (lame_result == -1) {
240− /* output buffer too small */
241218 av_log(avctx, AV_LOG_ERROR,
242219 "lame: output buffer too small (buffer index: %d, free bytes: %d)\n",
243220 s->buffer_index, BUFFER_SIZE - s->buffer_index);
244221 }
245222 return -1;
246223 }
247−
248224 s->buffer_index += lame_result;
249225
226+ /* Move 1 frame from the LAME buffer to the output packet, if available.
227+ We have to parse the first frame header in the output buffer to
228+ determine the frame size. */
250229 if (s->buffer_index < 4)
251230 return 0;
252−
253− len = mp3len(s->buffer, NULL, NULL);
254− //av_log(avctx, AV_LOG_DEBUG, "in:%d packet-len:%d index:%d\n",
255− // avctx->frame_size, len, s->buffer_index);
231+ if (avpriv_mpegaudio_decode_header(&hdr, AV_RB32(s->buffer))) {
232+ av_log(avctx, AV_LOG_ERROR, "free format output not supported\n");
233+ return -1;
234+ }
235+ len = hdr.frame_size;
236+ av_dlog(avctx, "in:%d packet-len:%d index:%d\n", avctx->frame_size, len,
237+ s->buffer_index);
256238 if (len <= s->buffer_index) {
257239 memcpy(frame, s->buffer, len);
258240 s->buffer_index -= len;
259−
260241 memmove(s->buffer, s->buffer + len, s->buffer_index);
261− // FIXME fix the audio codec API, so we do not need the memcpy()
262− /*for(i=0; i<len; i++) {
263− av_log(avctx, AV_LOG_DEBUG, "%2X ", frame[i]);
264− }*/
265242 return len;
266243 } else
267244 return 0;
268245 }
269246
270−static av_cold int MP3lame_encode_close(AVCodecContext *avctx)
271−{
272− Mp3AudioContext *s = avctx->priv_data;
273−
274− av_freep(&s->s32_data.left);
275− av_freep(&avctx->coded_frame);
276−
277− lame_close(s->gfp);
278− return 0;
279−}
280−
281−#define OFFSET(x) offsetof(Mp3AudioContext, x)
247+#define OFFSET(x) offsetof(LAMEContext, x)
282248 #define AE AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
283249 static const AVOption options[] = {
284250 { "reservoir", "Use bit reservoir.", OFFSET(reservoir), AV_OPT_TYPE_INT, { 1 }, 0, 1, AE },
@@ -292,21 +258,30 @@ static const AVClass libmp3lame_class = { · 7 unmodified lines
292258 .version = LIBAVUTIL_VERSION_INT,
293259 };
294260
261+static const AVCodecDefault libmp3lame_defaults[] = {
262+ { "b", "0" },
263+ { NULL },
264+};
265+
266+static const int libmp3lame_sample_rates[] = {
267+ 44100, 48000, 32000, 22050, 24000, 16000, 11025, 12000, 8000, 0
268+};
269+
295270 AVCodec ff_libmp3lame_encoder = {
296271 .name = "libmp3lame",
297272 .type = AVMEDIA_TYPE_AUDIO,
298273 .id = CODEC_ID_MP3,
299− .priv_data_size = sizeof(Mp3AudioContext),
300− .init = MP3lame_encode_init,
301− .encode = MP3lame_encode_frame,
302− .close = MP3lame_encode_close,
274+ .priv_data_size = sizeof(LAMEContext),
275+ .init = mp3lame_encode_init,
276+ .encode = mp3lame_encode_frame,
277+ .close = mp3lame_encode_close,
303278 .capabilities = CODEC_CAP_DELAY,
304− .sample_fmts = (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_S16,
305−#if 2147483647 == INT_MAX
306− AV_SAMPLE_FMT_S32,
307−#endif
279+ .sample_fmts = (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_S32,
280+ AV_SAMPLE_FMT_FLT,
281+ AV_SAMPLE_FMT_S16,
308282 AV_SAMPLE_FMT_NONE },
309− .supported_samplerates = sSampleRates,
283+ .supported_samplerates = libmp3lame_sample_rates,
310284 .long_name = NULL_IF_CONFIG_SMALL("libmp3lame MP3 (MPEG audio layer 3)"),
311285 .priv_class = &libmp3lame_class,
286+ .defaults = libmp3lame_defaults,
312287 };
libavcodec/libspeexenc.c+1−4
@@ -67,7 +67,6 @@ · 66 unmodified lines
6767 #include <speex/speex.h>
6868 #include <speex/speex_header.h>
6969 #include <speex/speex_stereo.h>
70−#include "libavutil/mathematics.h"
7170 #include "libavutil/opt.h"
7271 #include "avcodec.h"
7372 #include "internal.h"
@@ -258,9 +257,7 @@ static int encode_frame(AVCodecContext *avctx, uint8_t *frame, int buf_size, · 184 unmodified lines
258257 /* write output if all frames for the packet have been encoded */
259258 if (s->pkt_frame_count == s->frames_per_packet) {
260259 s->pkt_frame_count = 0;
261− avctx->coded_frame->pts =
262− av_rescale_q(s->next_pts, (AVRational){ 1, avctx->sample_rate },
263− avctx->time_base);
260+ avctx->coded_frame->pts = ff_samples_to_time_base(avctx, s->next_pts);
264261 s->next_pts += s->pkt_sample_count;
265262 s->pkt_sample_count = 0;
266263 if (buf_size > speex_bits_nbytes(&s->bits)) {
libavcodec/libvorbis.c+3−2
@@ -29,8 +29,8 @@ · 28 unmodified lines
2929 #include "libavutil/opt.h"
3030 #include "avcodec.h"
3131 #include "bytestream.h"
32+#include "internal.h"
3233 #include "vorbis.h"
33−#include "libavutil/mathematics.h"
3434
3535 #undef NDEBUG
3636 #include <assert.h>
@@ -268,7 +268,8 @@ static int oggvorbis_encode_frame(AVCodecContext *avccontext, · 231 unmodified lines
268268 op2->packet = context->buffer + sizeof(ogg_packet);
269269
270270 l = op2->bytes;
271− avccontext->coded_frame->pts = av_rescale_q(op2->granulepos, (AVRational) { 1, avccontext->sample_rate }, avccontext->time_base);
271+ avccontext->coded_frame->pts = ff_samples_to_time_base(avccontext,
272+ op2->granulepos);
272273 //FIXME we should reorder the user supplied pts and not assume that they are spaced by 1/sample_rate
273274
274275 if (l > buf_size) {
libavcodec/mlp_parser.c+1−1
@@ -314,7 +314,7 @@ static int mlp_parse(AVCodecParserContext *s, · 313 unmodified lines
314314 else
315315 avctx->sample_fmt = AV_SAMPLE_FMT_S16;
316316 avctx->sample_rate = mh.group1_samplerate;
317− avctx->frame_size = mh.access_unit_size;
317+ s->duration = mh.access_unit_size;
318318
319319 if (mh.stream_type == 0xbb) {
320320 /* MLP stream */
libavcodec/mpegaudio_parser.c+1−1
@@ -78,7 +78,7 @@ static int mpegaudio_parse(AVCodecParserContext *s1, · 77 unmodified lines
7878 if(s->header_count > 1){
7979 avctx->sample_rate= sr;
8080 avctx->channels = channels;
81− avctx->frame_size = frame_size;
81+ s1->duration = frame_size;
8282 avctx->bit_rate = bit_rate;
8383 }
8484 break;
libavcodec/pcxenc.c+22−9
@@ -29,6 +29,7 @@ · 28 unmodified lines
2929 #include "avcodec.h"
3030 #include "bytestream.h"
3131 #include "libavutil/imgutils.h"
32+#include "internal.h"
3233
3334 typedef struct PCXContext {
3435 AVFrame picture;
@@ -96,20 +97,20 @@ static int pcx_rle_encode( uint8_t *dst, int dst_size, · 61 unmodified lines
9697 return dst - dst_start;
9798 }
9899
99−static int pcx_encode_frame(AVCodecContext *avctx,
100− unsigned char *buf, int buf_size, void *data)
100+static int pcx_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
101+ const AVFrame *frame, int *got_packet)
101102 {
102103 PCXContext *s = avctx->priv_data;
103104 AVFrame *const pict = &s->picture;
104− const uint8_t *buf_start = buf;
105− const uint8_t *buf_end = buf + buf_size;
105+ const uint8_t *buf_end;
106+ uint8_t *buf;
106107
107− int bpp, nplanes, i, y, line_bytes, written;
108+ int bpp, nplanes, i, y, line_bytes, written, ret, max_pkt_size;
108109 const uint32_t *pal = NULL;
109110 uint32_t palette256[256];
110111 const uint8_t *src;
111112
112− *pict = *(AVFrame *)data;
113+ *pict = *frame;
113114 pict->pict_type = AV_PICTURE_TYPE_I;
114115 pict->key_frame = 1;
115116
@@ -151,6 +152,14 @@ static int pcx_encode_frame(AVCodecContext *avctx, · 35 unmodified lines
151152 line_bytes = (avctx->width * bpp + 7) >> 3;
152153 line_bytes = (line_bytes + 1) & ~1;
153154
155+ max_pkt_size = 128 + avctx->height * 2 * line_bytes * nplanes + (pal ? 256*3 + 1 : 0);
156+ if ((ret = ff_alloc_packet(pkt, max_pkt_size)) < 0) {
157+ av_log(avctx, AV_LOG_ERROR, "Error getting output packet of size %d.\n", max_pkt_size);
158+ return ret;
159+ }
160+ buf = pkt->data;
161+ buf_end = pkt->data + pkt->size;
162+
154163 bytestream_put_byte(&buf, 10); // manufacturer
155164 bytestream_put_byte(&buf, 5); // version
156165 bytestream_put_byte(&buf, 1); // encoding
@@ -167,7 +176,7 @@ static int pcx_encode_frame(AVCodecContext *avctx, · 10 unmodified lines
167176 bytestream_put_byte(&buf, nplanes); // number of planes
168177 bytestream_put_le16(&buf, line_bytes); // scanline plane size in bytes
169178
170− while (buf - buf_start < 128)
179+ while (buf - pkt->data < 128)
171180 *buf++= 0;
172181
173182 src = pict->data[0];
@@ -193,7 +202,11 @@ static int pcx_encode_frame(AVCodecContext *avctx, · 19 unmodified lines
193202 }
194203 }
195204
196− return buf - buf_start;
205+ pkt->size = buf - pkt->data;
206+ pkt->flags |= AV_PKT_FLAG_KEY;
207+ *got_packet = 1;
208+
209+ return 0;
197210 }
198211
199212 AVCodec ff_pcx_encoder = {
@@ -202,7 +215,7 @@ AVCodec ff_pcx_encoder = { · 2 unmodified lines
202215 .id = CODEC_ID_PCX,
203216 .priv_data_size = sizeof(PCXContext),
204217 .init = pcx_encode_init,
205− .encode = pcx_encode_frame,
218+ .encode2 = pcx_encode_frame,
206219 .pix_fmts = (const enum PixelFormat[]){
207220 PIX_FMT_RGB24,
208221 PIX_FMT_RGB8, PIX_FMT_BGR8, PIX_FMT_RGB4_BYTE, PIX_FMT_BGR4_BYTE, PIX_FMT_GRAY8, PIX_FMT_PAL8,
libavcodec/pnmdec.c+0−5
@@ -201,7 +201,6 @@ AVCodec ff_pgm_decoder = { · 200 unmodified lines
201201 .close = ff_pnm_end,
202202 .decode = pnm_decode_frame,
203203 .capabilities = CODEC_CAP_DR1,
204− .pix_fmts = (const enum PixelFormat[]){PIX_FMT_GRAY8, PIX_FMT_GRAY16BE, PIX_FMT_NONE},
205204 .long_name = NULL_IF_CONFIG_SMALL("PGM (Portable GrayMap) image"),
206205 };
207206 #endif
@@ -216,7 +215,6 @@ AVCodec ff_pgmyuv_decoder = { · 8 unmodified lines
216215 .close = ff_pnm_end,
217216 .decode = pnm_decode_frame,
218217 .capabilities = CODEC_CAP_DR1,
219− .pix_fmts = (const enum PixelFormat[]){PIX_FMT_YUV420P, PIX_FMT_NONE},
220218 .long_name = NULL_IF_CONFIG_SMALL("PGMYUV (Portable GrayMap YUV) image"),
221219 };
222220 #endif
@@ -231,7 +229,6 @@ AVCodec ff_ppm_decoder = { · 8 unmodified lines
231229 .close = ff_pnm_end,
232230 .decode = pnm_decode_frame,
233231 .capabilities = CODEC_CAP_DR1,
234− .pix_fmts = (const enum PixelFormat[]){PIX_FMT_RGB24, PIX_FMT_RGB48BE, PIX_FMT_NONE},
235232 .long_name = NULL_IF_CONFIG_SMALL("PPM (Portable PixelMap) image"),
236233 };
237234 #endif
@@ -246,7 +243,6 @@ AVCodec ff_pbm_decoder = { · 8 unmodified lines
246243 .close = ff_pnm_end,
247244 .decode = pnm_decode_frame,
248245 .capabilities = CODEC_CAP_DR1,
249− .pix_fmts = (const enum PixelFormat[]){PIX_FMT_MONOWHITE, PIX_FMT_NONE},
250246 .long_name = NULL_IF_CONFIG_SMALL("PBM (Portable BitMap) image"),
251247 };
252248 #endif
@@ -261,7 +257,6 @@ AVCodec ff_pam_decoder = { · 8 unmodified lines
261257 .close = ff_pnm_end,
262258 .decode = pnm_decode_frame,
263259 .capabilities = CODEC_CAP_DR1,
264− .pix_fmts = (const enum PixelFormat[]){PIX_FMT_RGB24, PIX_FMT_RGB32, PIX_FMT_GRAY8, PIX_FMT_MONOBLACK, PIX_FMT_NONE},
265260 .long_name = NULL_IF_CONFIG_SMALL("PAM (Portable AnyMap) image"),
266261 };
267262 #endif
libavcodec/pnmenc.c+19−13
@@ -20,21 +20,23 @@ · 19 unmodified lines
2020 */
2121
2222 #include "avcodec.h"
23+#include "internal.h"
2324 #include "pnm.h"
2425
2526
26−static int pnm_encode_frame(AVCodecContext *avctx, unsigned char *outbuf,
27− int buf_size, void *data)
27+static int pnm_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
28+ const AVFrame *pict, int *got_packet)
2829 {
2930 PNMContext *s = avctx->priv_data;
30− AVFrame *pict = data;
3131 AVFrame * const p = (AVFrame*)&s->picture;
32− int i, h, h1, c, n, linesize;
32+ int i, h, h1, c, n, linesize, ret;
3333 uint8_t *ptr, *ptr1, *ptr2;
3434
35− if (buf_size < avpicture_get_size(avctx->pix_fmt, avctx->width, avctx->height) + 200) {
35+ if ((ret = ff_alloc_packet(pkt, avpicture_get_size(avctx->pix_fmt,
36+ avctx->width,
37+ avctx->height) + 200)) < 0) {
3638 av_log(avctx, AV_LOG_ERROR, "encoded frame too large\n");
37− return -1;
39+ return ret;
3840 }
3941
4042 *p = *pict;
@@ -42,8 +44,8 @@ static int pnm_encode_frame(AVCodecContext *avctx, unsigned char *outbuf, · 1 unmodified line
4244 p->key_frame = 1;
4345
4446 s->bytestream_start =
45− s->bytestream = outbuf;
46− s->bytestream_end = outbuf + buf_size;
47+ s->bytestream = pkt->data;
48+ s->bytestream_end = pkt->data + pkt->size;
4749
4850 h = avctx->height;
4951 h1 = h;
@@ -107,7 +109,11 @@ static int pnm_encode_frame(AVCodecContext *avctx, unsigned char *outbuf, · 57 unmodified lines
107109 ptr2 += p->linesize[2];
108110 }
109111 }
110− return s->bytestream - s->bytestream_start;
112+ pkt->size = s->bytestream - s->bytestream_start;
113+ pkt->flags |= AV_PKT_FLAG_KEY;
114+ *got_packet = 1;
115+
116+ return 0;
111117 }
112118
113119
@@ -118,7 +124,7 @@ AVCodec ff_pgm_encoder = { · 4 unmodified lines
118124 .id = CODEC_ID_PGM,
119125 .priv_data_size = sizeof(PNMContext),
120126 .init = ff_pnm_init,
121− .encode = pnm_encode_frame,
127+ .encode2 = pnm_encode_frame,
122128 .pix_fmts = (const enum PixelFormat[]){PIX_FMT_GRAY8, PIX_FMT_GRAY16BE, PIX_FMT_NONE},
123129 .long_name = NULL_IF_CONFIG_SMALL("PGM (Portable GrayMap) image"),
124130 };
@@ -131,7 +137,7 @@ AVCodec ff_pgmyuv_encoder = { · 6 unmodified lines
131137 .id = CODEC_ID_PGMYUV,
132138 .priv_data_size = sizeof(PNMContext),
133139 .init = ff_pnm_init,
134− .encode = pnm_encode_frame,
140+ .encode2 = pnm_encode_frame,
135141 .pix_fmts = (const enum PixelFormat[]){PIX_FMT_YUV420P, PIX_FMT_NONE},
136142 .long_name = NULL_IF_CONFIG_SMALL("PGMYUV (Portable GrayMap YUV) image"),
137143 };
@@ -144,7 +150,7 @@ AVCodec ff_ppm_encoder = { · 6 unmodified lines
144150 .id = CODEC_ID_PPM,
145151 .priv_data_size = sizeof(PNMContext),
146152 .init = ff_pnm_init,
147− .encode = pnm_encode_frame,
153+ .encode2 = pnm_encode_frame,
148154 .pix_fmts = (const enum PixelFormat[]){PIX_FMT_RGB24, PIX_FMT_RGB48BE, PIX_FMT_NONE},
149155 .long_name = NULL_IF_CONFIG_SMALL("PPM (Portable PixelMap) image"),
150156 };
@@ -157,7 +163,7 @@ AVCodec ff_pbm_encoder = { · 6 unmodified lines
157163 .id = CODEC_ID_PBM,
158164 .priv_data_size = sizeof(PNMContext),
159165 .init = ff_pnm_init,
160− .encode = pnm_encode_frame,
166+ .encode2 = pnm_encode_frame,
161167 .pix_fmts = (const enum PixelFormat[]){PIX_FMT_MONOWHITE, PIX_FMT_NONE},
162168 .long_name = NULL_IF_CONFIG_SMALL("PBM (Portable BitMap) image"),
163169 };
libavcodec/roqvideo.h+1−1
@@ -69,7 +69,7 @@ typedef struct RoqContext { · 68 unmodified lines
6969
7070 unsigned int framesSinceKeyframe;
7171
72− AVFrame *frame_to_enc;
72+ const AVFrame *frame_to_enc;
7373 uint8_t *out_buf;
7474 struct RoqTempData *tmpData;
7575 } RoqContext;
libavcodec/roqvideoenc.c+23−16
@@ -59,6 +59,7 @@ · 58 unmodified lines
5959 #include "roqvideo.h"
6060 #include "bytestream.h"
6161 #include "elbg.h"
62+#include "internal.h"
6263 #include "mathops.h"
6364
6465 #define CHROMA_BIAS 1
@@ -112,7 +113,7 @@ static inline int square(int x) · 47 unmodified lines
112113 return x*x;
113114 }
114115
115−static inline int eval_sse(uint8_t *a, uint8_t *b, int count)
116+static inline int eval_sse(const uint8_t *a, const uint8_t *b, int count)
116117 {
117118 int diff=0;
118119
@@ -124,8 +125,8 @@ static inline int eval_sse(uint8_t *a, uint8_t *b, int count) · 5 unmodified lines
124125
125126 // FIXME Could use DSPContext.sse, but it is not so speed critical (used
126127 // just for motion estimation).
127−static int block_sse(uint8_t **buf1, uint8_t **buf2, int x1, int y1, int x2,
128− int y2, int *stride1, int *stride2, int size)
128+static int block_sse(uint8_t * const *buf1, uint8_t * const *buf2, int x1, int y1,
129+ int x2, int y2, const int *stride1, const int *stride2, int size)
129130 {
130131 int i, k;
131132 int sse=0;
@@ -260,7 +261,7 @@ static void create_cel_evals(RoqContext *enc, RoqTempdata *tempData) · 128 unmodified lines
260261 /**
261262 * Get macroblocks from parts of the image
262263 */
263−static void get_frame_mb(AVFrame *frame, int x, int y, uint8_t mb[], int dim)
264+static void get_frame_mb(const AVFrame *frame, int x, int y, uint8_t mb[], int dim)
264265 {
265266 int i, j, cp;
266267
@@ -754,8 +755,8 @@ static void reconstruct_and_encode_image(RoqContext *enc, RoqTempdata *tempData, · 487 unmodified lines
754755 /**
755756 * Create a single YUV cell from a 2x2 section of the image
756757 */
757−static inline void frame_block_to_cell(uint8_t *block, uint8_t **data,
758− int top, int left, int *stride)
758+static inline void frame_block_to_cell(uint8_t *block, uint8_t * const *data,
759+ int top, int left, const int *stride)
759760 {
760761 int i, j, u=0, v=0;
761762
@@ -775,7 +776,7 @@ static inline void frame_block_to_cell(uint8_t *block, uint8_t **data, · 13 unmodified lines
775776 /**
776777 * Create YUV clusters for the entire image
777778 */
778−static void create_clusters(AVFrame *frame, int w, int h, uint8_t *yuvClusters)
779+static void create_clusters(const AVFrame *frame, int w, int h, uint8_t *yuvClusters)
779780 {
780781 int i, j, k, l;
781782
@@ -1001,13 +1002,12 @@ static void roq_write_video_info_chunk(RoqContext *enc) · 219 unmodified lines
10011002 bytestream_put_byte(&enc->out_buf, 0x00);
10021003 }
10031004
1004−static int roq_encode_frame(AVCodecContext *avctx, unsigned char *buf, int buf_size, void *data)
1005+static int roq_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
1006+ const AVFrame *frame, int *got_packet)
10051007 {
10061008 RoqContext *enc = avctx->priv_data;
1007− AVFrame *frame= data;
1008− uint8_t *buf_start = buf;
1009+ int size, ret;
10091010
1010− enc->out_buf = buf;
10111011 enc->avctx = avctx;
10121012
10131013 enc->frame_to_enc = frame;
@@ -1019,10 +1019,12 @@ static int roq_encode_frame(AVCodecContext *avctx, unsigned char *buf, int buf_s · 5 unmodified lines
10191019
10201020 /* 138 bits max per 8x8 block +
10211021 * 256 codebooks*(6 bytes 2x2 + 4 bytes 4x4) + 8 bytes frame header */
1022− if (((enc->width*enc->height/64)*138+7)/8 + 256*(6+4) + 8 > buf_size) {
1023− av_log(avctx, AV_LOG_ERROR, " RoQ: Output buffer too small!\n");
1024− return -1;
1022+ size = ((enc->width * enc->height / 64) * 138 + 7) / 8 + 256 * (6 + 4) + 8;
1023+ if ((ret = ff_alloc_packet(pkt, size)) < 0) {
1024+ av_log(avctx, AV_LOG_ERROR, "Error getting output packet with size %d.\n", size);
1025+ return ret;
10251026 }
1027+ enc->out_buf = pkt->data;
10261028
10271029 /* Check for I frame */
10281030 if (enc->framesSinceKeyframe == avctx->gop_size)
@@ -1046,7 +1048,12 @@ static int roq_encode_frame(AVCodecContext *avctx, unsigned char *buf, int buf_s · 17 unmodified lines
10461048 /* Encode the actual frame */
10471049 roq_encode_video(enc);
10481050
1049− return enc->out_buf - buf_start;
1051+ pkt->size = enc->out_buf - pkt->data;
1052+ if (enc->framesSinceKeyframe == 1)
1053+ pkt->flags |= AV_PKT_FLAG_KEY;
1054+ *got_packet = 1;
1055+
1056+ return 0;
10501057 }
10511058
10521059 static int roq_encode_end(AVCodecContext *avctx)
@@ -1071,7 +1078,7 @@ AVCodec ff_roq_encoder = { · 18 unmodified lines
10711078 .id = CODEC_ID_ROQ,
10721079 .priv_data_size = sizeof(RoqContext),
10731080 .init = roq_encode_init,
1074− .encode = roq_encode_frame,
1081+ .encode2 = roq_encode_frame,
10751082 .close = roq_encode_end,
10761083 .supported_framerates = (const AVRational[]){{30,1}, {0,0}},
10771084 .pix_fmts = (const enum PixelFormat[]){PIX_FMT_YUV444P, PIX_FMT_NONE},
libavcodec/sgienc.c+25−14
@@ -21,6 +21,7 @@ · 20 unmodified lines
2121
2222 #include "avcodec.h"
2323 #include "bytestream.h"
24+#include "internal.h"
2425 #include "sgi.h"
2526 #include "rle.h"
2627
@@ -41,17 +42,17 @@ static av_cold int encode_init(AVCodecContext *avctx) · 14 unmodified lines
4142 return 0;
4243 }
4344
44−static int encode_frame(AVCodecContext *avctx, unsigned char *buf,
45− int buf_size, void *data)
45+static int encode_frame(AVCodecContext *avctx, AVPacket *pkt,
46+ const AVFrame *frame, int *got_packet)
4647 {
4748 SgiContext *s = avctx->priv_data;
4849 AVFrame * const p = &s->picture;
49− uint8_t *offsettab, *lengthtab, *in_buf, *encode_buf;
50− int x, y, z, length, tablesize;
50+ uint8_t *offsettab, *lengthtab, *in_buf, *encode_buf, *buf;
51+ int x, y, z, length, tablesize, ret;
5152 unsigned int width, height, depth, dimension, bytes_per_channel, pixmax, put_be;
52− unsigned char *orig_buf = buf, *end_buf = buf + buf_size;
53+ unsigned char *end_buf;
5354
54− *p = *(AVFrame*)data;
55+ *p = *frame;
5556 p->pict_type = AV_PICTURE_TYPE_I;
5657 p->key_frame = 1;
5758
@@ -106,12 +107,18 @@ static int encode_frame(AVCodecContext *avctx, unsigned char *buf, · 48 unmodified lines
106107 }
107108
108109 tablesize = depth * height * 4;
109− length = tablesize * 2 + SGI_HEADER_SIZE;
110−
111− if (buf_size < length) {
112− av_log(avctx, AV_LOG_ERROR, "buf_size too small(need %d, got %d)\n", length, buf_size);
113− return -1;
110+ length = SGI_HEADER_SIZE;
111+ if (avctx->coder_type == FF_CODER_TYPE_RAW)
112+ length += depth * height * width;
113+ else // assume ff_rl_encode() produces at most 2x size of input
114+ length += tablesize * 2 + depth * height * (2 * width + 1);
115+
116+ if ((ret = ff_alloc_packet(pkt, length)) < 0) {
117+ av_log(avctx, AV_LOG_ERROR, "Error getting output packet of size %d.\n", length);
118+ return ret;
114119 }
120+ buf = pkt->data;
121+ end_buf = pkt->data + pkt->size;
115122
116123 /* Encode header. */
117124 bytestream_put_be16(&buf, SGI_MAGIC);
@@ -153,7 +160,7 @@ static int encode_frame(AVCodecContext *avctx, unsigned char *buf, · 35 unmodified lines
153160 in_buf = p->data[0] + p->linesize[0] * (height - 1) + z;
154161
155162 for (y = 0; y < height; y++) {
156− bytestream_put_be32(&offsettab, buf - orig_buf);
163+ bytestream_put_be32(&offsettab, buf - pkt->data);
157164
158165 for (x = 0; x < width; x++)
159166 encode_buf[x] = in_buf[depth * x];
@@ -193,7 +200,11 @@ static int encode_frame(AVCodecContext *avctx, unsigned char *buf, · 33 unmodified lines
193200 }
194201
195202 /* total length */
196− return buf - orig_buf;
203+ pkt->size = buf - pkt->data;
204+ pkt->flags |= AV_PKT_FLAG_KEY;
205+ *got_packet = 1;
206+
207+ return 0;
197208 }
198209
199210 AVCodec ff_sgi_encoder = {
@@ -202,7 +213,7 @@ AVCodec ff_sgi_encoder = { · 2 unmodified lines
202213 .id = CODEC_ID_SGI,
203214 .priv_data_size = sizeof(SgiContext),
204215 .init = encode_init,
205− .encode = encode_frame,
216+ .encode2 = encode_frame,
206217 .pix_fmts= (const enum PixelFormat[]){PIX_FMT_RGB24, PIX_FMT_RGBA,
207218 PIX_FMT_RGB48LE, PIX_FMT_RGB48BE,
208219 PIX_FMT_RGBA64LE, PIX_FMT_RGBA64BE,
libavcodec/targaenc.c+31−29
@@ -22,6 +22,7 @@ · 21 unmodified lines
2222 #include "libavutil/intreadwrite.h"
2323 #include "libavutil/pixdesc.h"
2424 #include "avcodec.h"
25+#include "internal.h"
2526 #include "rle.h"
2627 #include "targa.h"
2728
@@ -39,7 +40,7 @@ typedef struct TargaContext { · 11 unmodified lines
3940 * @param h Image height
4041 * @return Size of output in bytes, or -1 if larger than out_size
4142 */
42−static int targa_encode_rle(uint8_t *outbuf, int out_size, AVFrame *pic,
43+static int targa_encode_rle(uint8_t *outbuf, int out_size, const AVFrame *pic,
4344 int bpp, int w, int h)
4445 {
4546 int y,ret;
@@ -59,7 +60,7 @@ static int targa_encode_rle(uint8_t *outbuf, int out_size, AVFrame *pic, · 13 unmodified lines
5960 return out - outbuf;
6061 }
6162
62−static int targa_encode_normal(uint8_t *outbuf, AVFrame *pic, int bpp, int w, int h)
63+static int targa_encode_normal(uint8_t *outbuf, const AVFrame *pic, int bpp, int w, int h)
6364 {
6465 int i, n = bpp * w;
6566 uint8_t *out = outbuf;
@@ -74,11 +75,10 @@ static int targa_encode_normal(uint8_t *outbuf, AVFrame *pic, int bpp, int w, in · 8 unmodified lines
7475 return out - outbuf;
7576 }
7677
77−static int targa_encode_frame(AVCodecContext *avctx,
78− unsigned char *outbuf,
79− int buf_size, void *data){
80− AVFrame *p = data;
81− int bpp, picsize, datasize = -1;
78+static int targa_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
79+ const AVFrame *p, int *got_packet)
80+{
81+ int bpp, picsize, datasize = -1, ret;
8282 uint8_t *out;
8383
8484 if(avctx->width > 0xffff || avctx->height > 0xffff) {
@@ -86,46 +86,43 @@ static int targa_encode_frame(AVCodecContext *avctx, · 1 unmodified line
8686 return AVERROR(EINVAL);
8787 }
8888 picsize = avpicture_get_size(avctx->pix_fmt, avctx->width, avctx->height);
89− if(buf_size < picsize + 45) {
89+ if ((ret = ff_alloc_packet(pkt, picsize + 45)) < 0) {
9090 av_log(avctx, AV_LOG_ERROR, "encoded frame too large\n");
91− return AVERROR(EINVAL);
91+ return ret;
9292 }
9393
94− p->pict_type= AV_PICTURE_TYPE_I;
95− p->key_frame= 1;
96−
9794 /* zero out the header and only set applicable fields */
98− memset(outbuf, 0, 12);
99− AV_WL16(outbuf+12, avctx->width);
100− AV_WL16(outbuf+14, avctx->height);
95+ memset(pkt->data, 0, 12);
96+ AV_WL16(pkt->data+12, avctx->width);
97+ AV_WL16(pkt->data+14, avctx->height);
10198 /* image descriptor byte: origin is always top-left, bits 0-3 specify alpha */
102− outbuf[17] = 0x20 | (avctx->pix_fmt == PIX_FMT_BGRA ? 8 : 0);
99+ pkt->data[17] = 0x20 | (avctx->pix_fmt == PIX_FMT_BGRA ? 8 : 0);
103100
104101 switch(avctx->pix_fmt) {
105102 case PIX_FMT_GRAY8:
106− outbuf[2] = TGA_BW; /* uncompressed grayscale image */
107− outbuf[16] = 8; /* bpp */
103+ pkt->data[2] = TGA_BW; /* uncompressed grayscale image */
104+ pkt->data[16] = 8; /* bpp */
108105 break;
109106 case PIX_FMT_RGB555LE:
110− outbuf[2] = TGA_RGB; /* uncompresses true-color image */
111− outbuf[16] = 16; /* bpp */
107+ pkt->data[2] = TGA_RGB; /* uncompresses true-color image */
108+ pkt->data[16] = 16; /* bpp */
112109 break;
113110 case PIX_FMT_BGR24:
114− outbuf[2] = TGA_RGB; /* uncompressed true-color image */
115− outbuf[16] = 24; /* bpp */
111+ pkt->data[2] = TGA_RGB; /* uncompressed true-color image */
112+ pkt->data[16] = 24; /* bpp */
116113 break;
117114 case PIX_FMT_BGRA:
118− outbuf[2] = TGA_RGB; /* uncompressed true-color image */
119− outbuf[16] = 32; /* bpp */
115+ pkt->data[2] = TGA_RGB; /* uncompressed true-color image */
116+ pkt->data[16] = 32; /* bpp */
120117 break;
121118 default:
122119 av_log(avctx, AV_LOG_ERROR, "Pixel format '%s' not supported.\n",
123120 av_get_pix_fmt_name(avctx->pix_fmt));
124121 return AVERROR(EINVAL);
125122 }
126− bpp = outbuf[16] >> 3;
123+ bpp = pkt->data[16] >> 3;
127124
128− out = outbuf + 18; /* skip past the header we just output */
125+ out = pkt->data + 18; /* skip past the header we just output */
129126
130127 /* try RLE compression */
131128 if (avctx->coder_type != FF_CODER_TYPE_RAW)
@@ -133,7 +130,7 @@ static int targa_encode_frame(AVCodecContext *avctx, · 1 unmodified line
133130
134131 /* if that worked well, mark the picture as RLE compressed */
135132 if(datasize >= 0)
136− outbuf[2] |= 8;
133+ pkt->data[2] |= 8;
137134
138135 /* if RLE didn't make it smaller, go back to no compression */
139136 else datasize = targa_encode_normal(out, p, bpp, avctx->width, avctx->height);
@@ -145,7 +142,11 @@ static int targa_encode_frame(AVCodecContext *avctx, · 5 unmodified lines
145142 * aspect ratio and encoder ID fields available? */
146143 memcpy(out, "\0\0\0\0\0\0\0\0TRUEVISION-XFILE.", 26);
147144
148− return out + 26 - outbuf;
145+ pkt->size = out + 26 - pkt->data;
146+ pkt->flags |= AV_PKT_FLAG_KEY;
147+ *got_packet = 1;
148+
149+ return 0;
149150 }
150151
151152 static av_cold int targa_encode_init(AVCodecContext *avctx)
@@ -154,6 +155,7 @@ static av_cold int targa_encode_init(AVCodecContext *avctx) · 2 unmodified lines
154155
155156 avcodec_get_frame_defaults(&s->picture);
156157 s->picture.key_frame= 1;
158+ s->picture.pict_type = AV_PICTURE_TYPE_I;
157159 avctx->coded_frame= &s->picture;
158160
159161 return 0;
@@ -165,7 +167,7 @@ AVCodec ff_targa_encoder = { · 5 unmodified lines
165167 .id = CODEC_ID_TARGA,
166168 .priv_data_size = sizeof(TargaContext),
167169 .init = targa_encode_init,
168− .encode = targa_encode_frame,
170+ .encode2 = targa_encode_frame,
169171 .pix_fmts= (const enum PixelFormat[]){PIX_FMT_BGR24, PIX_FMT_BGRA, PIX_FMT_RGB555LE, PIX_FMT_GRAY8, PIX_FMT_NONE},
170172 .long_name= NULL_IF_CONFIG_SMALL("Truevision Targa image"),
171173 };
libavcodec/utils.c+6−9
@@ -993,9 +993,8 @@ int attribute_align_arg avcodec_encode_audio2(AVCodecContext *avctx, · 992 unmodified lines
993993 if (!ret && *got_packet_ptr) {
994994 if (!(avctx->codec->capabilities & CODEC_CAP_DELAY)) {
995995 avpkt->pts = frame->pts;
996− avpkt->duration = av_rescale_q(frame->nb_samples,
997− (AVRational){ 1, avctx->sample_rate },
998− avctx->time_base);
996+ avpkt->duration = ff_samples_to_time_base(avctx,
997+ frame->nb_samples);
999998 }
1000999 avpkt->dts = avpkt->pts;
10011000 } else {
@@ -1053,9 +1052,8 @@ int attribute_align_arg avcodec_encode_audio2(AVCodecContext *avctx, · 51 unmodified lines
10531052 once all encoders supporting CODEC_CAP_SMALL_LAST_FRAME use
10541053 encode2() */
10551054 if (fs_tmp) {
1056− avpkt->duration = av_rescale_q(avctx->frame_size,
1057− (AVRational){ 1, avctx->sample_rate },
1058− avctx->time_base);
1055+ avpkt->duration = ff_samples_to_time_base(avctx,
1056+ avctx->frame_size);
10591057 }
10601058 }
10611059 avpkt->size = ret;
@@ -1128,9 +1126,8 @@ int attribute_align_arg avcodec_encode_audio(AVCodecContext *avctx, · 66 unmodified lines
11281126 this is needed because the avcodec_encode_audio() API does not have
11291127 a way for the user to provide pts */
11301128 if(avctx->sample_rate && avctx->time_base.num)
1131− frame->pts = av_rescale_q(avctx->internal->sample_count,
1132− (AVRational){ 1, avctx->sample_rate },
1133− avctx->time_base);
1129+ frame->pts = ff_samples_to_time_base(avctx,
1130+ avctx->internal->sample_count);
11341131 else
11351132 frame->pts = AV_NOPTS_VALUE;
11361133 avctx->internal->sample_count += frame->nb_samples;
libavcodec/v410enc.c+13−12
@@ -22,6 +22,7 @@ · 21 unmodified lines
2222
2323 #include "libavutil/intreadwrite.h"
2424 #include "avcodec.h"
25+#include "internal.h"
2526
2627 static av_cold int v410_encode_init(AVCodecContext *avctx)
2728 {
@@ -40,20 +41,19 @@ static av_cold int v410_encode_init(AVCodecContext *avctx) · 12 unmodified lines
4041 return 0;
4142 }
4243
43−static int v410_encode_frame(AVCodecContext *avctx, uint8_t *buf,
44− int buf_size, void *data)
44+static int v410_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
45+ const AVFrame *pic, int *got_packet)
4546 {
46− AVFrame *pic = data;
47− uint8_t *dst = buf;
47+ uint8_t *dst;
4848 uint16_t *y, *u, *v;
4949 uint32_t val;
50− int i, j;
51− int output_size = 0;
50+ int i, j, ret;
5251
53− if (buf_size < avctx->width * avctx->height * 4) {
54− av_log(avctx, AV_LOG_ERROR, "Out buffer is too small.\n");
55− return AVERROR(ENOMEM);
52+ if ((ret = ff_alloc_packet(pkt, avctx->width * avctx->height * 4)) < 0) {
53+ av_log(avctx, AV_LOG_ERROR, "Error getting output packet.\n");
54+ return ret;
5655 }
56+ dst = pkt->data;
5757
5858 avctx->coded_frame->reference = 0;
5959 avctx->coded_frame->key_frame = 1;
@@ -70,14 +70,15 @@ static int v410_encode_frame(AVCodecContext *avctx, uint8_t *buf, · 10 unmodified lines
7070 val |= (uint32_t) v[j] << 22;
7171 AV_WL32(dst, val);
7272 dst += 4;
73− output_size += 4;
7473 }
7574 y += pic->linesize[0] >> 1;
7675 u += pic->linesize[1] >> 1;
7776 v += pic->linesize[2] >> 1;
7877 }
7978
80− return output_size;
79+ pkt->flags |= AV_PKT_FLAG_KEY;
80+ *got_packet = 1;
81+ return 0;
8182 }
8283
8384 static av_cold int v410_encode_close(AVCodecContext *avctx)
@@ -92,7 +93,7 @@ AVCodec ff_v410_encoder = { · 8 unmodified lines
9293 .type = AVMEDIA_TYPE_VIDEO,
9394 .id = CODEC_ID_V410,
9495 .init = v410_encode_init,
95− .encode = v410_encode_frame,
96+ .encode2 = v410_encode_frame,
9697 .close = v410_encode_close,
9798 .pix_fmts = (const enum PixelFormat[]){ PIX_FMT_YUV444P10, PIX_FMT_NONE },
9899 .long_name = NULL_IF_CONFIG_SMALL("Uncompressed 4:4:4 10-bit"),
libavcodec/x86/h264_deblock.asm+8−1
@@ -830,9 +830,13 @@ cglobal deblock_v_chroma_8_mmxext, 5,6 · 829 unmodified lines
830830 ; void ff_deblock_h_chroma( uint8_t *pix, int stride, int alpha, int beta, int8_t *tc0 )
831831 ;-----------------------------------------------------------------------------
832832 cglobal deblock_h_chroma_8_mmxext, 5,7
833−%if ARCH_X86_64
833+%if UNIX64
834834 %define buf0 [rsp-24]
835835 %define buf1 [rsp-16]
836+%elif WIN64
837+ sub rsp, 16
838+ %define buf0 [rsp]
839+ %define buf1 [rsp+8]
836840 %else
837841 %define buf0 r0m
838842 %define buf1 r2m
@@ -849,6 +853,9 @@ cglobal deblock_h_chroma_8_mmxext, 5,7 · 10 unmodified lines
849853 movq m0, buf0
850854 movq m3, buf1
851855 TRANSPOSE8x4B_STORE PASS8ROWS(t5, r0, r1, t6)
856+%if WIN64
857+ add rsp, 16
858+%endif
852859 RET
853860
854861 ALIGN 16
libavcodec/zmbvenc.c+32−19
@@ -29,6 +29,7 @@ · 28 unmodified lines
2929
3030 #include "libavutil/intreadwrite.h"
3131 #include "avcodec.h"
32+#include "internal.h"
3233
3334 #include <zlib.h>
3435
@@ -115,19 +116,18 @@ static int zmbv_me(ZmbvEncContext *c, uint8_t *src, int sstride, uint8_t *prev, · 80 unmodified lines
115116 return bv;
116117 }
117118
118−static int encode_frame(AVCodecContext *avctx, uint8_t *buf, int buf_size, void *data)
119+static int encode_frame(AVCodecContext *avctx, AVPacket *pkt,
120+ const AVFrame *pict, int *got_packet)
119121 {
120122 ZmbvEncContext * const c = avctx->priv_data;
121− AVFrame *pict = data;
122123 AVFrame * const p = &c->pic;
123− uint8_t *src, *prev;
124+ uint8_t *src, *prev, *buf;
124125 uint32_t *palptr;
125− int len = 0;
126126 int keyframe, chpal;
127127 int fl;
128− int work_size = 0;
128+ int work_size = 0, pkt_size;
129129 int bw, bh;
130− int i, j;
130+ int i, j, ret;
131131
132132 keyframe = !c->curfrm;
133133 c->curfrm++;
@@ -138,17 +138,6 @@ static int encode_frame(AVCodecContext *avctx, uint8_t *buf, int buf_size, void · 4 unmodified lines
138138 p->key_frame= keyframe;
139139 chpal = !keyframe && memcmp(p->data[1], c->pal2, 1024);
140140
141− fl = (keyframe ? ZMBV_KEYFRAME : 0) | (chpal ? ZMBV_DELTAPAL : 0);
142− *buf++ = fl; len++;
143− if(keyframe){
144− deflateReset(&c->zstream);
145− *buf++ = 0; len++; // hi ver
146− *buf++ = 1; len++; // lo ver
147− *buf++ = 1; len++; // comp
148− *buf++ = 4; len++; // format - 8bpp
149− *buf++ = ZMBV_BLOCK; len++; // block width
150− *buf++ = ZMBV_BLOCK; len++; // block height
151− }
152141 palptr = (uint32_t*)p->data[1];
153142 src = p->data[0];
154143 prev = c->prev;
@@ -223,6 +212,9 @@ static int encode_frame(AVCodecContext *avctx, uint8_t *buf, int buf_size, void · 68 unmodified lines
223212 src += p->linesize[0];
224213 }
225214
215+ if (keyframe)
216+ deflateReset(&c->zstream);
217+
226218 c->zstream.next_in = c->work_buf;
227219 c->zstream.avail_in = work_size;
228220 c->zstream.total_in = 0;
@@ -235,8 +227,29 @@ static int encode_frame(AVCodecContext *avctx, uint8_t *buf, int buf_size, void · 6 unmodified lines
235227 return -1;
236228 }
237229
230+ pkt_size = c->zstream.total_out + 1 + 6*keyframe;
231+ if ((ret = ff_alloc_packet(pkt, pkt_size)) < 0) {
232+ av_log(avctx, AV_LOG_ERROR, "Error getting packet of size %d.\n", pkt_size);
233+ return ret;
234+ }
235+ buf = pkt->data;
236+
237+ fl = (keyframe ? ZMBV_KEYFRAME : 0) | (chpal ? ZMBV_DELTAPAL : 0);
238+ *buf++ = fl;
239+ if (keyframe) {
240+ *buf++ = 0; // hi ver
241+ *buf++ = 1; // lo ver
242+ *buf++ = 1; // comp
243+ *buf++ = 4; // format - 8bpp
244+ *buf++ = ZMBV_BLOCK; // block width
245+ *buf++ = ZMBV_BLOCK; // block height
246+ }
238247 memcpy(buf, c->comp_buf, c->zstream.total_out);
239− return len + c->zstream.total_out;
248+
249+ pkt->flags |= AV_PKT_FLAG_KEY*keyframe;
250+ *got_packet = 1;
251+
252+ return 0;
240253 }
241254
242255
@@ -329,7 +342,7 @@ AVCodec ff_zmbv_encoder = { · 86 unmodified lines
329342 .id = CODEC_ID_ZMBV,
330343 .priv_data_size = sizeof(ZmbvEncContext),
331344 .init = encode_init,
332− .encode = encode_frame,
345+ .encode2 = encode_frame,
333346 .close = encode_end,
334347 .pix_fmts = (const enum PixelFormat[]){PIX_FMT_PAL8, PIX_FMT_NONE},
335348 .long_name = NULL_IF_CONFIG_SMALL("Zip Motion Blocks Video"),
libavformat/hls.c+23−22
@@ -547,7 +547,7 @@ static int hls_read_header(AVFormatContext *s) · 546 unmodified lines
547547
548548 c->first_packet = 1;
549549 c->first_timestamp = AV_NOPTS_VALUE;
550− c->seek_timestamp = AV_NOPTS_VALUE;
550+ c->seek_timestamp = AV_NOPTS_VALUE;
551551
552552 return 0;
553553 fail:
@@ -609,16 +609,13 @@ start: · 55 unmodified lines
609609 if (var->needed && !var->pkt.data) {
610610 while (1) {
611611 int64_t ts_diff;
612+ AVStream *st;
612613 ret = av_read_frame(var->ctx, &var->pkt);
613614 if (ret < 0) {
614− if (!url_feof(&var->pb)) {
615+ if (!url_feof(&var->pb))
615616 return ret;
616− } else {
617− if ((var->cur_seq_no - var->start_seq_no) == (var->n_segments)) {
618− return AVERROR_EOF;
619− }
620− }
621617 reset_packet(&var->pkt);
618+ break;
622619 } else {
623620 if (c->first_timestamp == AV_NOPTS_VALUE)
624621 c->first_timestamp = var->pkt.dts;
@@ -632,18 +629,14 @@ start: · 7 unmodified lines
632629 break;
633630 }
634631
635− ts_diff = var->pkt.dts - c->seek_timestamp;
636− if (ts_diff >= 0) {
637− if (c->seek_flags & AVSEEK_FLAG_ANY) {
638− c->seek_timestamp = AV_NOPTS_VALUE;
639− break;
640− }
641−
642− /* Seek to keyframe */
643− if (var->pkt.flags & AV_PKT_FLAG_KEY) {
644− c->seek_timestamp = AV_NOPTS_VALUE;
645− break;
646− }
632+ st = var->ctx->streams[var->pkt.stream_index];
633+ ts_diff = av_rescale_rnd(var->pkt.dts, AV_TIME_BASE,
634+ st->time_base.den, AV_ROUND_DOWN) -
635+ c->seek_timestamp;
636+ if (ts_diff >= 0 && (c->seek_flags & AVSEEK_FLAG_ANY ||
637+ var->pkt.flags & AV_PKT_FLAG_KEY)) {
638+ c->seek_timestamp = AV_NOPTS_VALUE;
639+ break;
647640 }
648641 }
649642 }
@@ -685,8 +678,12 @@ static int hls_read_seek(AVFormatContext *s, int stream_index, · 35 unmodified lines
685678 if ((flags & AVSEEK_FLAG_BYTE) || !c->variants[0]->finished)
686679 return AVERROR(ENOSYS);
687680
688− c->seek_timestamp = timestamp;
689− c->seek_flags = flags;
681+ c->seek_flags = flags;
682+ c->seek_timestamp = stream_index < 0 ? timestamp :
683+ av_rescale_rnd(timestamp, AV_TIME_BASE,
684+ s->streams[stream_index]->time_base.den,
685+ flags & AVSEEK_FLAG_BACKWARD ?
686+ AV_ROUND_DOWN : AV_ROUND_UP);
690687 timestamp = av_rescale_rnd(timestamp, 1, stream_index >= 0 ?
691688 s->streams[stream_index]->time_base.den :
692689 AV_TIME_BASE, flags & AVSEEK_FLAG_BACKWARD ?
@@ -712,6 +709,10 @@ static int hls_read_seek(AVFormatContext *s, int stream_index, · 19 unmodified lines
712709 av_free_packet(&var->pkt);
713710 reset_packet(&var->pkt);
714711 var->pb.eof_reached = 0;
712+ /* Clear any buffered data */
713+ var->pb.buf_end = var->pb.buf_ptr = var->pb.buffer;
714+ /* Reset the pos, to let the mpegts demuxer know we've seeked. */
715+ var->pb.pos = 0;
715716
716717 /* Locate the segment that contains the target timestamp */
717718 for (j = 0; j < var->n_segments; j++) {
@@ -723,7 +724,7 @@ static int hls_read_seek(AVFormatContext *s, int stream_index, · 5 unmodified lines
723724 }
724725 pos += var->segments[j]->duration;
725726 }
726− if (ret != 0)
727+ if (ret)
727728 c->seek_timestamp = AV_NOPTS_VALUE;
728729 }
729730 return ret;
libavformat/utils.c+16−3
@@ -942,11 +942,10 @@ static void compute_pkt_fields(AVFormatContext *s, AVStream *st, · 941 unmodified lines
942942 compute_frame_duration(&num, &den, st, pc, pkt);
943943 if (den && num) {
944944 pkt->duration = av_rescale_rnd(1, num * (int64_t)st->time_base.den, den * (int64_t)st->time_base.num, AV_ROUND_DOWN);
945−
946− if(pkt->duration != 0 && s->packet_buffer)
947− update_initial_durations(s, st, pkt);
948945 }
949946 }
947+ if(pkt->duration != 0 && s->packet_buffer)
948+ update_initial_durations(s, st, pkt);
950949
951950 /* correct timestamps with byte offset if demuxers only have timestamps
952951 on packet boundaries */
@@ -1099,6 +1098,20 @@ static int read_frame_internal(AVFormatContext *s, AVPacket *pkt) · 146 unmodified lines
10991098 if (pkt->size) {
11001099 got_packet:
11011100 pkt->duration = 0;
1101+ if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO) {
1102+ if (st->codec->sample_rate > 0) {
1103+ pkt->duration = av_rescale_q_rnd(st->parser->duration,
1104+ (AVRational){ 1, st->codec->sample_rate },
1105+ st->time_base,
1106+ AV_ROUND_DOWN);
1107+ }
1108+ } else if (st->codec->time_base.num != 0 &&
1109+ st->codec->time_base.den != 0) {
1110+ pkt->duration = av_rescale_q_rnd(st->parser->duration,
1111+ st->codec->time_base,
1112+ st->time_base,
1113+ AV_ROUND_DOWN);
1114+ }
11021115 pkt->stream_index = st->index;
11031116 pkt->pts = st->parser->pts;
11041117 pkt->dts = st->parser->dts;
libavutil/avutil.h+1−1
@@ -154,7 +154,7 @@ · 153 unmodified lines
154154 */
155155
156156 #define LIBAVUTIL_VERSION_MAJOR 51
157−#define LIBAVUTIL_VERSION_MINOR 39
157+#define LIBAVUTIL_VERSION_MINOR 40
158158 #define LIBAVUTIL_VERSION_MICRO 100
159159
160160 #define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \
libavutil/mathematics.c+9−2
@@ -131,10 +131,17 @@ int64_t av_rescale(int64_t a, int64_t b, int64_t c){ · 130 unmodified lines
131131 return av_rescale_rnd(a, b, c, AV_ROUND_NEAR_INF);
132132 }
133133
134−int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq){
134+int64_t av_rescale_q_rnd(int64_t a, AVRational bq, AVRational cq,
135+ enum AVRounding rnd)
136+{
135137 int64_t b= bq.num * (int64_t)cq.den;
136138 int64_t c= cq.num * (int64_t)bq.den;
137− return av_rescale_rnd(a, b, c, AV_ROUND_NEAR_INF);
139+ return av_rescale_rnd(a, b, c, rnd);
140+}
141+
142+int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
143+{
144+ return av_rescale_q_rnd(a, bq, cq, AV_ROUND_NEAR_INF);
138145 }
139146
140147 int av_compare_ts(int64_t ts_a, AVRational tb_a, int64_t ts_b, AVRational tb_b){
libavutil/mathematics.h+6−0
@@ -95,6 +95,12 @@ int64_t av_rescale_rnd(int64_t a, int64_t b, int64_t c, enum AVRounding) av_cons · 94 unmodified lines
9595 */
9696 int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq) av_const;
9797
98+/**
99+ * Rescale a 64-bit integer by 2 rational numbers with specified rounding.
100+ */
101+int64_t av_rescale_q_rnd(int64_t a, AVRational bq, AVRational cq,
102+ enum AVRounding) av_const;
103+
98104 /**
99105 * Compare 2 timestamps each in its own timebases.
100106 * The result of the function is undefined if one of the timestamps
libswscale/swscale_internal.h+6−5
@@ -358,10 +358,11 @@ typedef struct SwsContext { · 357 unmodified lines
358358 #define U_TEMP "11*8+4*4*256*2+24"
359359 #define V_TEMP "11*8+4*4*256*2+32"
360360 #define Y_TEMP "11*8+4*4*256*2+40"
361−#define UV_OFF_PX "11*8+4*4*256*2+48"
362−#define UV_OFF_BYTE "11*8+4*4*256*2+56"
363−#define DITHER16 "11*8+4*4*256*2+64"
364−#define DITHER32 "11*8+4*4*256*2+80"
361+#define ALP_MMX_FILTER_OFFSET "11*8+4*4*256*2+48"
362+#define UV_OFF_PX "11*8+4*4*256*3+48"
363+#define UV_OFF_BYTE "11*8+4*4*256*3+56"
364+#define DITHER16 "11*8+4*4*256*3+64"
365+#define DITHER32 "11*8+4*4*256*3+80"
365366
366367 DECLARE_ALIGNED(8, uint64_t, redDither);
367368 DECLARE_ALIGNED(8, uint64_t, greenDither);
@@ -383,6 +384,7 @@ typedef struct SwsContext { · 15 unmodified lines
383384 DECLARE_ALIGNED(8, uint64_t, u_temp);
384385 DECLARE_ALIGNED(8, uint64_t, v_temp);
385386 DECLARE_ALIGNED(8, uint64_t, y_temp);
387+ int32_t alpMmxFilter[4 * MAX_FILTER_SIZE];
386388 // alignment of these values is not necessary, but merely here
387389 // to maintain the same offset across x8632 and x86-64. Once we
388390 // use proper offset macros in the asm, they can be removed.
@@ -421,7 +423,6 @@ typedef struct SwsContext { · 32 unmodified lines
421423 #if HAVE_VIS
422424 DECLARE_ALIGNED(8, uint64_t, sparc_coeffs)[10];
423425 #endif
424− int32_t alpMmxFilter[4 * MAX_FILTER_SIZE];
425426 int use_mmx_vfilter;
426427
427428 /* function pointers for swScale() */
libswscale/x86/swscale_template.c+2−2
@@ -342,7 +342,7 @@ static void RENAME(yuv2rgb32_X_ar)(SwsContext *c, const int16_t *lumFilter, · 341 unmodified lines
342342 "movq %%mm2, "U_TEMP"(%0) \n\t"
343343 "movq %%mm4, "V_TEMP"(%0) \n\t"
344344 "movq %%mm5, "Y_TEMP"(%0) \n\t"
345− YSCALEYUV2PACKEDX_ACCURATE_YA(LUM_MMX_FILTER_OFFSET)
345+ YSCALEYUV2PACKEDX_ACCURATE_YA(ALP_MMX_FILTER_OFFSET)
346346 "movq "Y_TEMP"(%0), %%mm5 \n\t"
347347 "psraw $3, %%mm1 \n\t"
348348 "psraw $3, %%mm7 \n\t"
@@ -372,7 +372,7 @@ static void RENAME(yuv2rgb32_X)(SwsContext *c, const int16_t *lumFilter, · 23 unmodified lines
372372 if (CONFIG_SWSCALE_ALPHA && c->alpPixBuf) {
373373 YSCALEYUV2PACKEDX
374374 YSCALEYUV2RGBX
375− YSCALEYUV2PACKEDX_YA(LUM_MMX_FILTER_OFFSET, %%mm0, %%mm3, %%mm6, %%mm1, %%mm7)
375+ YSCALEYUV2PACKEDX_YA(ALP_MMX_FILTER_OFFSET, %%mm0, %%mm3, %%mm6, %%mm1, %%mm7)
376376 "psraw $3, %%mm1 \n\t"
377377 "psraw $3, %%mm7 \n\t"
378378 "packuswb %%mm7, %%mm1 \n\t"
tests/ref/acodec/adpcm_yam+4−4
@@ -1,4 +1,4 @@
1−006f8dc92eb4f7bab82eded314ca1124 *./tests/data/acodec/adpcm_yam.wav
2−266298 ./tests/data/acodec/adpcm_yam.wav
3−c36a9d5a1e0ad57fbe9665a31373b7c1 *./tests/data/adpcm_yam.acodec.out.wav
4−stddev: 1247.60 PSNR: 34.41 MAXDIFF:39895 bytes: 1064960/ 1058400
1+e9c14f701d25947317db9367b9dc772d *./tests/data/acodec/adpcm_yam.wav
2+265274 ./tests/data/acodec/adpcm_yam.wav
3+1488b5974fa040a65f0d407fc0224c6a *./tests/data/adpcm_yam.acodec.out.wav
4+stddev: 1247.60 PSNR: 34.41 MAXDIFF:39895 bytes: 1060864/ 1058400

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t