* 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
Unified · Split
| @@ -32,6 +32,12 @@ API changes, most recent first: · 31 unmodified lines | |||
| 32 | 2012-01-24 - xxxxxxx - lavfi 2.60.100 | 32 | 2012-01-24 - xxxxxxx - lavfi 2.60.100 |
| 33 | Add avfilter_graph_dump. | 33 | Add avfilter_graph_dump. |
| 34 | 34 | ||
| 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 | |||
| 35 | 2012-02-xx - xxxxxxx - lavu 51.22.1 - pixdesc.h | 41 | 2012-02-xx - xxxxxxx - lavu 51.22.1 - pixdesc.h |
| 36 | Add PIX_FMT_PSEUDOPAL flag. | 42 | Add PIX_FMT_PSEUDOPAL flag. |
| 37 | 43 | ||
| @@ -630,7 +630,7 @@ OBJS-$(CONFIG_LIBGSM_DECODER) += libgsm.o · 629 unmodified lines | |||
| 630 | OBJS-$(CONFIG_LIBGSM_ENCODER) += libgsm.o | 630 | OBJS-$(CONFIG_LIBGSM_ENCODER) += libgsm.o |
| 631 | OBJS-$(CONFIG_LIBGSM_MS_DECODER) += libgsm.o | 631 | OBJS-$(CONFIG_LIBGSM_MS_DECODER) += libgsm.o |
| 632 | OBJS-$(CONFIG_LIBGSM_MS_ENCODER) += libgsm.o | 632 | OBJS-$(CONFIG_LIBGSM_MS_ENCODER) += libgsm.o |
| 633 | OBJS-$(CONFIG_LIBMP3LAME_ENCODER) += libmp3lame.o | 633 | OBJS-$(CONFIG_LIBMP3LAME_ENCODER) += libmp3lame.o mpegaudiodecheader.o |
| 634 | OBJS-$(CONFIG_LIBOPENCORE_AMRNB_DECODER) += libopencore-amr.o | 634 | OBJS-$(CONFIG_LIBOPENCORE_AMRNB_DECODER) += libopencore-amr.o |
| 635 | OBJS-$(CONFIG_LIBOPENCORE_AMRNB_ENCODER) += libopencore-amr.o | 635 | OBJS-$(CONFIG_LIBOPENCORE_AMRNB_ENCODER) += libopencore-amr.o |
| 636 | OBJS-$(CONFIG_LIBOPENCORE_AMRWB_DECODER) += libopencore-amr.o | 636 | OBJS-$(CONFIG_LIBOPENCORE_AMRWB_DECODER) += libopencore-amr.o |
| @@ -93,7 +93,7 @@ get_next: · 92 unmodified lines | |||
| 93 | avctx->channels = s->channels; | 93 | avctx->channels = s->channels; |
| 94 | avctx->channel_layout = s->channel_layout; | 94 | avctx->channel_layout = s->channel_layout; |
| 95 | } | 95 | } |
| 96 | avctx->frame_size = s->samples; | 96 | s1->duration = s->samples; |
| 97 | avctx->audio_service_type = s->service_type; | 97 | avctx->audio_service_type = s->service_type; |
| 98 | } | 98 | } |
| 99 | 99 | ||
| @@ -125,7 +125,7 @@ static av_cold int adpcm_encode_init(AVCodecContext *avctx) · 124 unmodified lines | |||
| 125 | } | 125 | } |
| 126 | break; | 126 | break; |
| 127 | case CODEC_ID_ADPCM_YAMAHA: | 127 | case CODEC_ID_ADPCM_YAMAHA: |
| 128 | avctx->frame_size = BLKSIZE * avctx->channels; | 128 | avctx->frame_size = BLKSIZE * 2 / avctx->channels; |
| 129 | avctx->block_align = BLKSIZE; | 129 | avctx->block_align = BLKSIZE; |
| 130 | break; | 130 | break; |
| 131 | case CODEC_ID_ADPCM_SWF: | 131 | case CODEC_ID_ADPCM_SWF: |
| @@ -80,6 +80,9 @@ static int adx_parse(AVCodecParserContext *s1, · 79 unmodified lines | |||
| 80 | *poutbuf_size = 0; | 80 | *poutbuf_size = 0; |
| 81 | return buf_size; | 81 | return buf_size; |
| 82 | } | 82 | } |
| 83 | |||
| 84 | s1->duration = BLOCK_SAMPLES; | ||
| 85 | |||
| 83 | *poutbuf = buf; | 86 | *poutbuf = buf; |
| 84 | *poutbuf_size = buf_size; | 87 | *poutbuf_size = buf_size; |
| 85 | return next; | 88 | return next; |
| @@ -4182,6 +4182,13 @@ typedef struct AVCodecParserContext { · 4181 unmodified lines | |||
| 4182 | * Previous frame byte position. | 4182 | * Previous frame byte position. |
| 4183 | */ | 4183 | */ |
| 4184 | int64_t last_pos; | 4184 | 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; | ||
| 4185 | } AVCodecParserContext; | 4192 | } AVCodecParserContext; |
| 4186 | 4193 | ||
| 4187 | typedef struct AVCodecParser { | 4194 | typedef struct AVCodecParser { |
| @@ -71,6 +71,7 @@ typedef struct FLACHeaderMarker { · 70 unmodified lines | |||
| 71 | } FLACHeaderMarker; | 71 | } FLACHeaderMarker; |
| 72 | 72 | ||
| 73 | typedef struct FLACParseContext { | 73 | typedef struct FLACParseContext { |
| 74 | AVCodecParserContext *pc; /**< parent context */ | ||
| 74 | AVCodecContext *avctx; /**< codec context pointer for logging */ | 75 | AVCodecContext *avctx; /**< codec context pointer for logging */ |
| 75 | FLACHeaderMarker *headers; /**< linked-list that starts at the first | 76 | FLACHeaderMarker *headers; /**< linked-list that starts at the first |
| 76 | CRC-8 verified header within buffer */ | 77 | CRC-8 verified header within buffer */ |
| @@ -458,7 +459,7 @@ static int get_best_header(FLACParseContext* fpc, const uint8_t **poutbuf, · 381 unmodified lines | |||
| 458 | 459 | ||
| 459 | fpc->avctx->sample_rate = header->fi.samplerate; | 460 | fpc->avctx->sample_rate = header->fi.samplerate; |
| 460 | fpc->avctx->channels = header->fi.channels; | 461 | fpc->avctx->channels = header->fi.channels; |
| 461 | fpc->avctx->frame_size = header->fi.blocksize; | 462 | fpc->pc->duration = header->fi.blocksize; |
| 462 | *poutbuf = flac_fifo_read_wrap(fpc, header->offset, *poutbuf_size, | 463 | *poutbuf = flac_fifo_read_wrap(fpc, header->offset, *poutbuf_size, |
| 463 | &fpc->wrap_buf, | 464 | &fpc->wrap_buf, |
| 464 | &fpc->wrap_buf_allocated_size); | 465 | &fpc->wrap_buf_allocated_size); |
| @@ -484,7 +485,7 @@ static int flac_parse(AVCodecParserContext *s, AVCodecContext *avctx, · 19 unmodified lines | |||
| 484 | if (s->flags & PARSER_FLAG_COMPLETE_FRAMES) { | 485 | if (s->flags & PARSER_FLAG_COMPLETE_FRAMES) { |
| 485 | FLACFrameInfo fi; | 486 | FLACFrameInfo fi; |
| 486 | if (frame_header_is_valid(avctx, buf, &fi)) | 487 | if (frame_header_is_valid(avctx, buf, &fi)) |
| 487 | avctx->frame_size = fi.blocksize; | 488 | s->duration = fi.blocksize; |
| 488 | *poutbuf = buf; | 489 | *poutbuf = buf; |
| 489 | *poutbuf_size = buf_size; | 490 | *poutbuf_size = buf_size; |
| 490 | return buf_size; | 491 | return buf_size; |
| @@ -630,8 +631,8 @@ static int flac_parse(AVCodecParserContext *s, AVCodecContext *avctx, · 139 unmodified lines | |||
| 630 | av_log(avctx, AV_LOG_DEBUG, "Junk frame till offset %i\n", | 631 | av_log(avctx, AV_LOG_DEBUG, "Junk frame till offset %i\n", |
| 631 | fpc->best_header->offset); | 632 | fpc->best_header->offset); |
| 632 | 633 | ||
| 633 | /* Set frame_size to 0. It is unknown or invalid in a junk frame. */ | 634 | /* Set duration to 0. It is unknown or invalid in a junk frame. */ |
| 634 | avctx->frame_size = 0; | 635 | s->duration = 0; |
| 635 | *poutbuf_size = fpc->best_header->offset; | 636 | *poutbuf_size = fpc->best_header->offset; |
| 636 | *poutbuf = flac_fifo_read_wrap(fpc, 0, *poutbuf_size, | 637 | *poutbuf = flac_fifo_read_wrap(fpc, 0, *poutbuf_size, |
| 637 | &fpc->wrap_buf, | 638 | &fpc->wrap_buf, |
| @@ -652,6 +653,7 @@ handle_error: · 14 unmodified lines | |||
| 652 | static int flac_parse_init(AVCodecParserContext *c) | 653 | static int flac_parse_init(AVCodecParserContext *c) |
| 653 | { | 654 | { |
| 654 | FLACParseContext *fpc = c->priv_data; | 655 | FLACParseContext *fpc = c->priv_data; |
| 656 | fpc->pc = c; | ||
| 655 | /* There will generally be FLAC_MIN_HEADERS buffered in the fifo before | 657 | /* There will generally be FLAC_MIN_HEADERS buffered in the fifo before |
| 656 | it drains. This is allocated early to avoid slow reallocation. */ | 658 | it drains. This is allocated early to avoid slow reallocation. */ |
| 657 | fpc->fifo_buf = av_fifo_alloc(FLAC_AVG_FRAME_SIZE * (FLAC_MIN_HEADERS + 3)); | 659 | fpc->fifo_buf = av_fifo_alloc(FLAC_AVG_FRAME_SIZE * (FLAC_MIN_HEADERS + 3)); |
| @@ -31,6 +31,7 @@ · 30 unmodified lines | |||
| 31 | typedef struct GSMParseContext { | 31 | typedef struct GSMParseContext { |
| 32 | ParseContext pc; | 32 | ParseContext pc; |
| 33 | int block_size; | 33 | int block_size; |
| 34 | int duration; | ||
| 34 | int remaining; | 35 | int remaining; |
| 35 | } GSMParseContext; | 36 | } GSMParseContext; |
| 36 | 37 | ||
| @@ -44,8 +45,14 @@ static int gsm_parse(AVCodecParserContext *s1, AVCodecContext *avctx, · 7 unmodified lines | |||
| 44 | 45 | ||
| 45 | if (!s->block_size) { | 46 | if (!s->block_size) { |
| 46 | switch (avctx->codec_id) { | 47 | switch (avctx->codec_id) { |
| 47 | case CODEC_ID_GSM: s->block_size = GSM_BLOCK_SIZE; break; | 48 | case CODEC_ID_GSM: |
| 48 | case CODEC_ID_GSM_MS: s->block_size = GSM_MS_BLOCK_SIZE; break; | 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; | ||
| 49 | default: | 56 | default: |
| 50 | return AVERROR(EINVAL); | 57 | return AVERROR(EINVAL); |
| 51 | } | 58 | } |
| @@ -66,6 +73,9 @@ static int gsm_parse(AVCodecParserContext *s1, AVCodecContext *avctx, · 14 unmodified lines | |||
| 66 | *poutbuf_size = 0; | 73 | *poutbuf_size = 0; |
| 67 | return buf_size; | 74 | return buf_size; |
| 68 | } | 75 | } |
| 76 | |||
| 77 | s1->duration = s->duration; | ||
| 78 | |||
| 69 | *poutbuf = buf; | 79 | *poutbuf = buf; |
| 70 | *poutbuf_size = buf_size; | 80 | *poutbuf_size = buf_size; |
| 71 | return next; | 81 | return next; |
| @@ -1261,9 +1261,10 @@ static av_cold int decode_end(AVCodecContext *avctx) · 1260 unmodified lines | |||
| 1261 | #endif /* CONFIG_HUFFYUV_DECODER || CONFIG_FFVHUFF_DECODER */ | 1261 | #endif /* CONFIG_HUFFYUV_DECODER || CONFIG_FFVHUFF_DECODER */ |
| 1262 | 1262 | ||
| 1263 | #if CONFIG_HUFFYUV_ENCODER || CONFIG_FFVHUFF_ENCODER | 1263 | #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 | { | ||
| 1265 | HYuvContext *s = avctx->priv_data; | 1267 | HYuvContext *s = avctx->priv_data; |
| 1266 | AVFrame *pict = data; | ||
| 1267 | const int width= s->width; | 1268 | const int width= s->width; |
| 1268 | const int width2= s->width>>1; | 1269 | const int width2= s->width>>1; |
| 1269 | const int height= s->height; | 1270 | const int height= s->height; |
| @@ -1271,7 +1272,13 @@ static int encode_frame(AVCodecContext *avctx, unsigned char *buf, int buf_size, · 1 unmodified line | |||
| 1271 | const int fake_ustride= s->interlaced ? pict->linesize[1]*2 : pict->linesize[1]; | 1272 | const int fake_ustride= s->interlaced ? pict->linesize[1]*2 : pict->linesize[1]; |
| 1272 | const int fake_vstride= s->interlaced ? pict->linesize[2]*2 : pict->linesize[2]; | 1273 | const int fake_vstride= s->interlaced ? pict->linesize[2]*2 : pict->linesize[2]; |
| 1273 | AVFrame * const p= &s->picture; | 1274 | 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 | } | ||
| 1275 | 1282 | ||
| 1276 | *p = *pict; | 1283 | *p = *pict; |
| 1277 | p->pict_type= AV_PICTURE_TYPE_I; | 1284 | 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 | |||
| 1282 | generate_len_table(s->len[i], s->stats[i]); | 1289 | generate_len_table(s->len[i], s->stats[i]); |
| 1283 | if(generate_bits_table(s->bits[i], s->len[i])<0) | 1290 | if(generate_bits_table(s->bits[i], s->len[i])<0) |
| 1284 | return -1; | 1291 | return -1; |
| 1285 | size+= store_table(s, s->len[i], &buf[size]); | 1292 | size += store_table(s, s->len[i], &pkt->data[size]); |
| 1286 | } | 1293 | } |
| 1287 | 1294 | ||
| 1288 | for(i=0; i<3; i++) | 1295 | 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 | |||
| 1290 | s->stats[i][j] >>= 1; | 1297 | s->stats[i][j] >>= 1; |
| 1291 | } | 1298 | } |
| 1292 | 1299 | ||
| 1293 | init_put_bits(&s->pb, buf+size, buf_size-size); | 1300 | init_put_bits(&s->pb, pkt->data + size, pkt->size - size); |
| 1294 | 1301 | ||
| 1295 | if(avctx->pix_fmt == PIX_FMT_YUV422P || avctx->pix_fmt == PIX_FMT_YUV420P){ | 1302 | if(avctx->pix_fmt == PIX_FMT_YUV422P || avctx->pix_fmt == PIX_FMT_YUV420P){ |
| 1296 | int lefty, leftu, leftv, y, cy; | 1303 | 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 | |||
| 1473 | avctx->stats_out[0] = '\0'; | 1480 | avctx->stats_out[0] = '\0'; |
| 1474 | if(!(s->avctx->flags2 & CODEC_FLAG2_NO_OUTPUT)){ | 1481 | if(!(s->avctx->flags2 & CODEC_FLAG2_NO_OUTPUT)){ |
| 1475 | flush_put_bits(&s->pb); | 1482 | 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); |
| 1477 | } | 1484 | } |
| 1478 | 1485 | ||
| 1479 | s->picture_number++; | 1486 | s->picture_number++; |
| 1480 | 1487 | ||
| 1481 | return size*4; | 1488 | pkt->size = size*4; |
| 1489 | pkt->flags |= AV_PKT_FLAG_KEY; | ||
| 1490 | *got_packet = 1; | ||
| 1491 | |||
| 1492 | return 0; | ||
| 1482 | } | 1493 | } |
| 1483 | 1494 | ||
| 1484 | static av_cold int encode_end(AVCodecContext *avctx) | 1495 | static av_cold int encode_end(AVCodecContext *avctx) |
| @@ -1531,7 +1542,7 @@ AVCodec ff_huffyuv_encoder = { · 46 unmodified lines | |||
| 1531 | .id = CODEC_ID_HUFFYUV, | 1542 | .id = CODEC_ID_HUFFYUV, |
| 1532 | .priv_data_size = sizeof(HYuvContext), | 1543 | .priv_data_size = sizeof(HYuvContext), |
| 1533 | .init = encode_init, | 1544 | .init = encode_init, |
| 1534 | .encode = encode_frame, | 1545 | .encode2 = encode_frame, |
| 1535 | .close = encode_end, | 1546 | .close = encode_end, |
| 1536 | .pix_fmts= (const enum PixelFormat[]){PIX_FMT_YUV422P, PIX_FMT_RGB24, PIX_FMT_RGB32, PIX_FMT_NONE}, | 1547 | .pix_fmts= (const enum PixelFormat[]){PIX_FMT_YUV422P, PIX_FMT_RGB24, PIX_FMT_RGB32, PIX_FMT_NONE}, |
| 1537 | .long_name = NULL_IF_CONFIG_SMALL("Huffyuv / HuffYUV"), | 1548 | .long_name = NULL_IF_CONFIG_SMALL("Huffyuv / HuffYUV"), |
| @@ -1545,7 +1556,7 @@ AVCodec ff_ffvhuff_encoder = { · 7 unmodified lines | |||
| 1545 | .id = CODEC_ID_FFVHUFF, | 1556 | .id = CODEC_ID_FFVHUFF, |
| 1546 | .priv_data_size = sizeof(HYuvContext), | 1557 | .priv_data_size = sizeof(HYuvContext), |
| 1547 | .init = encode_init, | 1558 | .init = encode_init, |
| 1548 | .encode = encode_frame, | 1559 | .encode2 = encode_frame, |
| 1549 | .close = encode_end, | 1560 | .close = encode_end, |
| 1550 | .pix_fmts= (const enum PixelFormat[]){PIX_FMT_YUV420P, PIX_FMT_YUV422P, PIX_FMT_RGB24, PIX_FMT_RGB32, PIX_FMT_NONE}, | 1561 | .pix_fmts= (const enum PixelFormat[]){PIX_FMT_YUV420P, PIX_FMT_YUV422P, PIX_FMT_RGB24, PIX_FMT_RGB32, PIX_FMT_NONE}, |
| 1551 | .long_name = NULL_IF_CONFIG_SMALL("Huffyuv FFmpeg variant"), | 1562 | .long_name = NULL_IF_CONFIG_SMALL("Huffyuv FFmpeg variant"), |
| @@ -26,6 +26,7 @@ · 25 unmodified lines | |||
| 26 | 26 | ||
| 27 | #include <stdint.h> | 27 | #include <stdint.h> |
| 28 | 28 | ||
| 29 | #include "libavutil/mathematics.h" | ||
| 29 | #include "libavutil/pixfmt.h" | 30 | #include "libavutil/pixfmt.h" |
| 30 | #include "avcodec.h" | 31 | #include "avcodec.h" |
| 31 | 32 | ||
| @@ -137,4 +138,14 @@ int avpriv_unlock_avformat(void); · 105 unmodified lines | |||
| 137 | */ | 138 | */ |
| 138 | int ff_alloc_packet(AVPacket *avpkt, int size); | 139 | int ff_alloc_packet(AVPacket *avpkt, int size); |
| 139 | 140 | ||
| 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 | |||
| 140 | #endif /* AVCODEC_INTERNAL_H */ | 151 | #endif /* AVCODEC_INTERNAL_H */ |
| @@ -24,261 +24,227 @@ · 23 unmodified lines | |||
| 24 | * Interface to libmp3lame for mp3 encoding. | 24 | * Interface to libmp3lame for mp3 encoding. |
| 25 | */ | 25 | */ |
| 26 | 26 | ||
| 27 | #include <lame/lame.h> | ||
| 28 | |||
| 27 | #include "libavutil/intreadwrite.h" | 29 | #include "libavutil/intreadwrite.h" |
| 28 | #include "libavutil/log.h" | 30 | #include "libavutil/log.h" |
| 29 | #include "libavutil/opt.h" | 31 | #include "libavutil/opt.h" |
| 30 | #include "avcodec.h" | 32 | #include "avcodec.h" |
| 33 | #include "internal.h" | ||
| 31 | #include "mpegaudio.h" | 34 | #include "mpegaudio.h" |
| 32 | #include <lame/lame.h> | 35 | #include "mpegaudiodecheader.h" |
| 33 | 36 | ||
| 34 | #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. | 37 | #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 { | ||
| 36 | AVClass *class; | 40 | AVClass *class; |
| 41 | AVCodecContext *avctx; | ||
| 37 | lame_global_flags *gfp; | 42 | lame_global_flags *gfp; |
| 38 | int stereo; | ||
| 39 | uint8_t buffer[BUFFER_SIZE]; | 43 | uint8_t buffer[BUFFER_SIZE]; |
| 40 | int buffer_index; | 44 | int buffer_index; |
| 41 | struct { | ||
| 42 | int *left; | ||
| 43 | int *right; | ||
| 44 | } s32_data; | ||
| 45 | int reservoir; | 45 | int reservoir; |
| 46 | } Mp3AudioContext; | 46 | void *planar_samples[2]; |
| 47 | } LAMEContext; | ||
| 48 | |||
| 47 | 49 | ||
| 48 | static av_cold int MP3lame_encode_init(AVCodecContext *avctx) | 50 | static av_cold int mp3lame_encode_close(AVCodecContext *avctx) |
| 49 | { | 51 | { |
| 50 | Mp3AudioContext *s = avctx->priv_data; | 52 | LAMEContext *s = avctx->priv_data; |
| 51 | 53 | ||
| 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 */ | ||
| 52 | if (avctx->channels > 2) { | 74 | if (avctx->channels > 2) { |
| 53 | av_log(avctx, AV_LOG_ERROR, | 75 | av_log(avctx, AV_LOG_ERROR, |
| 54 | "Invalid number of channels %d, must be <= 2\n", avctx->channels); | 76 | "Invalid number of channels %d, must be <= 2\n", avctx->channels); |
| 55 | return AVERROR(EINVAL); | 77 | ret = AVERROR(EINVAL); |
| 78 | goto error; | ||
| 56 | } | 79 | } |
| 80 | lame_set_num_channels(s->gfp, avctx->channels); | ||
| 81 | lame_set_mode(s->gfp, avctx->channels > 1 ? JOINT_STEREO : MONO); | ||
| 57 | 82 | ||
| 58 | s->stereo = avctx->channels > 1 ? 1 : 0; | 83 | /* sample rate */ |
| 59 | 84 | lame_set_in_samplerate (s->gfp, avctx->sample_rate); | |
| 60 | if ((s->gfp = lame_init()) == NULL) | ||
| 61 | goto err; | ||
| 62 | lame_set_in_samplerate(s->gfp, avctx->sample_rate); | ||
| 63 | lame_set_out_samplerate(s->gfp, avctx->sample_rate); | 85 | lame_set_out_samplerate(s->gfp, avctx->sample_rate); |
| 64 | lame_set_num_channels(s->gfp, avctx->channels); | 86 | |
| 65 | if (avctx->compression_level == FF_COMPRESSION_DEFAULT) { | 87 | /* algorithmic quality */ |
| 88 | if (avctx->compression_level == FF_COMPRESSION_DEFAULT) | ||
| 66 | lame_set_quality(s->gfp, 5); | 89 | lame_set_quality(s->gfp, 5); |
| 67 | } else { | 90 | else |
| 68 | lame_set_quality(s->gfp, avctx->compression_level); | 91 | lame_set_quality(s->gfp, avctx->compression_level); |
| 69 | } | 92 | |
| 70 | lame_set_mode(s->gfp, s->stereo ? JOINT_STEREO : MONO); | 93 | /* rate control */ |
| 71 | lame_set_brate(s->gfp, avctx->bit_rate / 1000); | ||
| 72 | if (avctx->flags & CODEC_FLAG_QSCALE) { | 94 | if (avctx->flags & CODEC_FLAG_QSCALE) { |
| 73 | lame_set_brate(s->gfp, 0); | ||
| 74 | lame_set_VBR(s->gfp, vbr_default); | 95 | lame_set_VBR(s->gfp, vbr_default); |
| 75 | lame_set_VBR_quality(s->gfp, avctx->global_quality / (float)FF_QP2LAMBDA); | 96 | 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); | ||
| 76 | } | 100 | } |
| 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; | ||
| 81 | 101 | ||
| 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); | ||
| 83 | 104 | ||
| 84 | if(!(avctx->coded_frame= avcodec_alloc_frame())) { | 105 | /* bit reservoir usage */ |
| 85 | lame_close(s->gfp); | 106 | lame_set_disable_reservoir(s->gfp, !s->reservoir); |
| 86 | 107 | ||
| 87 | return AVERROR(ENOMEM); | 108 | /* set specified parameters */ |
| 109 | if (lame_init_params(s->gfp) < 0) { | ||
| 110 | ret = -1; | ||
| 111 | goto error; | ||
| 88 | } | 112 | } |
| 89 | 113 | ||
| 90 | if(AV_SAMPLE_FMT_S32 == avctx->sample_fmt && s->stereo) { | 114 | avctx->frame_size = lame_get_framesize(s->gfp); |
| 91 | int nelem = 2 * avctx->frame_size; | 115 | avctx->coded_frame = avcodec_alloc_frame(); |
| 92 | 116 | if (!avctx->coded_frame) { | |
| 93 | if(! (s->s32_data.left = av_malloc(nelem * sizeof(int)))) { | 117 | ret = AVERROR(ENOMEM); |
| 94 | av_freep(&avctx->coded_frame); | 118 | goto error; |
| 95 | lame_close(s->gfp); | 119 | } |
| 96 | 120 | ||
| 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 | } | ||
| 98 | } | 132 | } |
| 99 | |||
| 100 | s->s32_data.right = s->s32_data.left + avctx->frame_size; | ||
| 101 | } | 133 | } |
| 102 | 134 | ||
| 103 | return 0; | 135 | return 0; |
| 104 | 136 | error: | |
| 105 | err_close: | 137 | mp3lame_encode_close(avctx); |
| 106 | lame_close(s->gfp); | 138 | return ret; |
| 107 | err: | ||
| 108 | return -1; | ||
| 109 | } | 139 | } |
| 110 | 140 | ||
| 111 | static const int sSampleRates[] = { | 141 | #define DEINTERLEAVE(type, scale) do { \ |
| 112 | 44100, 48000, 32000, 22050, 24000, 16000, 11025, 12000, 8000, 0 | 142 | int ch, i; \ |
| 113 | }; | 143 | for (ch = 0; ch < s->avctx->channels; ch++) { \ |
| 114 | 144 | const type *input = samples; \ | |
| 115 | static const int sBitRates[2][3][15] = { | 145 | type *output = s->planar_samples[ch]; \ |
| 116 | { | 146 | input += ch; \ |
| 117 | { 0, 32, 64, 96, 128, 160, 192, 224, 256, 288, 320, 352, 384, 416, 448 }, | 147 | for (i = 0; i < s->avctx->frame_size; i++) { \ |
| 118 | { 0, 32, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320, 384 }, | 148 | output[i] = *input * scale; \ |
| 119 | { 0, 32, 40, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320 } | 149 | input += s->avctx->channels; \ |
| 120 | }, | 150 | } \ |
| 121 | { | 151 | } \ |
| 122 | { 0, 32, 48, 56, 64, 80, 96, 112, 128, 144, 160, 176, 192, 224, 256 }, | 152 | } while (0) |
| 123 | { 0, 8, 16, 24, 32, 40, 48, 56, 64, 80, 96, 112, 128, 144, 160 }, | 153 | |
| 124 | { 0, 8, 16, 24, 32, 40, 48, 56, 64, 80, 96, 112, 128, 144, 160 } | 154 | static int encode_frame_int16(LAMEContext *s, void *samples) |
| 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) | ||
| 136 | { | 155 | { |
| 137 | uint32_t header = AV_RB32(data); | 156 | if (s->avctx->channels > 1) { |
| 138 | int layerID = 3 - ((header >> 17) & 0x03); | 157 | return lame_encode_buffer_interleaved(s->gfp, samples, |
| 139 | int bitRateID = ((header >> 12) & 0x0f); | 158 | s->avctx->frame_size, |
| 140 | int sampleRateID = ((header >> 10) & 0x03); | 159 | s->buffer + s->buffer_index, |
| 141 | int bitsPerSlot = sBitsPerSlot[layerID]; | 160 | BUFFER_SIZE - s->buffer_index); |
| 142 | int isPadded = ((header >> 9) & 0x01); | 161 | } else { |
| 143 | static int const mode_tab[4] = { 2, 3, 1, 0 }; | 162 | return lame_encode_buffer(s->gfp, samples, NULL, s->avctx->frame_size, |
| 144 | int mode = mode_tab[(header >> 19) & 0x03]; | 163 | s->buffer + s->buffer_index, |
| 145 | int mpeg_id = mode > 0; | 164 | BUFFER_SIZE - s->buffer_index); |
| 146 | int temp0, temp1, bitRate; | ||
| 147 | |||
| 148 | if (((header >> 21) & 0x7ff) != 0x7ff || mode == 3 || layerID == 3 || | ||
| 149 | sampleRateID == 3) { | ||
| 150 | return -1; | ||
| 151 | } | 165 | } |
| 166 | } | ||
| 152 | 167 | ||
| 153 | if (!samplesPerFrame) | 168 | static int encode_frame_int32(LAMEContext *s, void *samples) |
| 154 | samplesPerFrame = &temp0; | 169 | { |
| 155 | if (!sampleRate) | 170 | DEINTERLEAVE(int32_t, 1); |
| 156 | sampleRate = &temp1; | ||
| 157 | 171 | ||
| 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 | } | ||
| 159 | 178 | ||
| 160 | *sampleRate = sSampleRates[sampleRateID] >> mode; | 179 | static int encode_frame_float(LAMEContext *s, void *samples) |
| 161 | bitRate = sBitRates[mpeg_id][layerID][bitRateID] * 1000; | 180 | { |
| 162 | *samplesPerFrame = sSamplesPerFrame[mpeg_id][layerID]; | 181 | DEINTERLEAVE(float, 32768.0f); |
| 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); | ||
| 166 | 182 | ||
| 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); | ||
| 168 | } | 188 | } |
| 169 | 189 | ||
| 170 | static int MP3lame_encode_frame(AVCodecContext *avctx, unsigned char *frame, | 190 | static int mp3lame_encode_frame(AVCodecContext *avctx, unsigned char *frame, |
| 171 | int buf_size, void *data) | 191 | int buf_size, void *data) |
| 172 | { | 192 | { |
| 173 | Mp3AudioContext *s = avctx->priv_data; | 193 | LAMEContext *s = avctx->priv_data; |
| 194 | MPADecodeHeader hdr; | ||
| 174 | int len; | 195 | int len; |
| 175 | int lame_result; | 196 | int lame_result; |
| 176 | 197 | ||
| 177 | /* lame 3.91 dies on '1-channel interleaved' data */ | 198 | if (data) { |
| 178 | 199 | switch (avctx->sample_fmt) { | |
| 179 | if (!data){ | 200 | case AV_SAMPLE_FMT_S16: |
| 180 | lame_result= lame_encode_flush( | 201 | lame_result = encode_frame_int16(s, data); |
| 181 | s->gfp, | 202 | break; |
| 182 | s->buffer + s->buffer_index, | 203 | case AV_SAMPLE_FMT_S32: |
| 183 | BUFFER_SIZE - s->buffer_index | 204 | lame_result = encode_frame_int32(s, data); |
| 184 | ); | 205 | break; |
| 185 | #if 2147483647 == INT_MAX | 206 | case AV_SAMPLE_FMT_FLT: |
| 186 | }else if(AV_SAMPLE_FMT_S32 == avctx->sample_fmt){ | 207 | lame_result = encode_frame_float(s, data); |
| 187 | if (s->stereo) { | 208 | break; |
| 188 | int32_t *rp = data; | 209 | default: |
| 189 | int32_t *mp = rp + 2*avctx->frame_size; | 210 | return AVERROR_BUG; |
| 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 | ); | ||
| 235 | } | 211 | } |
| 212 | } else { | ||
| 213 | lame_result = lame_encode_flush(s->gfp, s->buffer + s->buffer_index, | ||
| 214 | BUFFER_SIZE - s->buffer_index); | ||
| 236 | } | 215 | } |
| 237 | |||
| 238 | if (lame_result < 0) { | 216 | if (lame_result < 0) { |
| 239 | if (lame_result == -1) { | 217 | if (lame_result == -1) { |
| 240 | /* output buffer too small */ | ||
| 241 | av_log(avctx, AV_LOG_ERROR, | 218 | av_log(avctx, AV_LOG_ERROR, |
| 242 | "lame: output buffer too small (buffer index: %d, free bytes: %d)\n", | 219 | "lame: output buffer too small (buffer index: %d, free bytes: %d)\n", |
| 243 | s->buffer_index, BUFFER_SIZE - s->buffer_index); | 220 | s->buffer_index, BUFFER_SIZE - s->buffer_index); |
| 244 | } | 221 | } |
| 245 | return -1; | 222 | return -1; |
| 246 | } | 223 | } |
| 247 | |||
| 248 | s->buffer_index += lame_result; | 224 | s->buffer_index += lame_result; |
| 249 | 225 | ||
| 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. */ | ||
| 250 | if (s->buffer_index < 4) | 229 | if (s->buffer_index < 4) |
| 251 | return 0; | 230 | return 0; |
| 252 | 231 | if (avpriv_mpegaudio_decode_header(&hdr, AV_RB32(s->buffer))) { | |
| 253 | len = mp3len(s->buffer, NULL, NULL); | 232 | av_log(avctx, AV_LOG_ERROR, "free format output not supported\n"); |
| 254 | //av_log(avctx, AV_LOG_DEBUG, "in:%d packet-len:%d index:%d\n", | 233 | return -1; |
| 255 | // avctx->frame_size, len, s->buffer_index); | 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); | ||
| 256 | if (len <= s->buffer_index) { | 238 | if (len <= s->buffer_index) { |
| 257 | memcpy(frame, s->buffer, len); | 239 | memcpy(frame, s->buffer, len); |
| 258 | s->buffer_index -= len; | 240 | s->buffer_index -= len; |
| 259 | |||
| 260 | memmove(s->buffer, s->buffer + len, s->buffer_index); | 241 | 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 | }*/ | ||
| 265 | return len; | 242 | return len; |
| 266 | } else | 243 | } else |
| 267 | return 0; | 244 | return 0; |
| 268 | } | 245 | } |
| 269 | 246 | ||
| 270 | static av_cold int MP3lame_encode_close(AVCodecContext *avctx) | 247 | #define OFFSET(x) offsetof(LAMEContext, x) |
| 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) | ||
| 282 | #define AE AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_ENCODING_PARAM | 248 | #define AE AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_ENCODING_PARAM |
| 283 | static const AVOption options[] = { | 249 | static const AVOption options[] = { |
| 284 | { "reservoir", "Use bit reservoir.", OFFSET(reservoir), AV_OPT_TYPE_INT, { 1 }, 0, 1, AE }, | 250 | { "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 | |||
| 292 | .version = LIBAVUTIL_VERSION_INT, | 258 | .version = LIBAVUTIL_VERSION_INT, |
| 293 | }; | 259 | }; |
| 294 | 260 | ||
| 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 | |||
| 295 | AVCodec ff_libmp3lame_encoder = { | 270 | AVCodec ff_libmp3lame_encoder = { |
| 296 | .name = "libmp3lame", | 271 | .name = "libmp3lame", |
| 297 | .type = AVMEDIA_TYPE_AUDIO, | 272 | .type = AVMEDIA_TYPE_AUDIO, |
| 298 | .id = CODEC_ID_MP3, | 273 | .id = CODEC_ID_MP3, |
| 299 | .priv_data_size = sizeof(Mp3AudioContext), | 274 | .priv_data_size = sizeof(LAMEContext), |
| 300 | .init = MP3lame_encode_init, | 275 | .init = mp3lame_encode_init, |
| 301 | .encode = MP3lame_encode_frame, | 276 | .encode = mp3lame_encode_frame, |
| 302 | .close = MP3lame_encode_close, | 277 | .close = mp3lame_encode_close, |
| 303 | .capabilities = CODEC_CAP_DELAY, | 278 | .capabilities = CODEC_CAP_DELAY, |
| 304 | .sample_fmts = (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_S16, | 279 | .sample_fmts = (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_S32, |
| 305 | #if 2147483647 == INT_MAX | 280 | AV_SAMPLE_FMT_FLT, |
| 306 | AV_SAMPLE_FMT_S32, | 281 | AV_SAMPLE_FMT_S16, |
| 307 | #endif | ||
| 308 | AV_SAMPLE_FMT_NONE }, | 282 | AV_SAMPLE_FMT_NONE }, |
| 309 | .supported_samplerates = sSampleRates, | 283 | .supported_samplerates = libmp3lame_sample_rates, |
| 310 | .long_name = NULL_IF_CONFIG_SMALL("libmp3lame MP3 (MPEG audio layer 3)"), | 284 | .long_name = NULL_IF_CONFIG_SMALL("libmp3lame MP3 (MPEG audio layer 3)"), |
| 311 | .priv_class = &libmp3lame_class, | 285 | .priv_class = &libmp3lame_class, |
| 286 | .defaults = libmp3lame_defaults, | ||
| 312 | }; | 287 | }; |
| @@ -67,7 +67,6 @@ · 66 unmodified lines | |||
| 67 | #include <speex/speex.h> | 67 | #include <speex/speex.h> |
| 68 | #include <speex/speex_header.h> | 68 | #include <speex/speex_header.h> |
| 69 | #include <speex/speex_stereo.h> | 69 | #include <speex/speex_stereo.h> |
| 70 | #include "libavutil/mathematics.h" | ||
| 71 | #include "libavutil/opt.h" | 70 | #include "libavutil/opt.h" |
| 72 | #include "avcodec.h" | 71 | #include "avcodec.h" |
| 73 | #include "internal.h" | 72 | #include "internal.h" |
| @@ -258,9 +257,7 @@ static int encode_frame(AVCodecContext *avctx, uint8_t *frame, int buf_size, · 184 unmodified lines | |||
| 258 | /* write output if all frames for the packet have been encoded */ | 257 | /* write output if all frames for the packet have been encoded */ |
| 259 | if (s->pkt_frame_count == s->frames_per_packet) { | 258 | if (s->pkt_frame_count == s->frames_per_packet) { |
| 260 | s->pkt_frame_count = 0; | 259 | s->pkt_frame_count = 0; |
| 261 | avctx->coded_frame->pts = | 260 | avctx->coded_frame->pts = ff_samples_to_time_base(avctx, s->next_pts); |
| 262 | av_rescale_q(s->next_pts, (AVRational){ 1, avctx->sample_rate }, | ||
| 263 | avctx->time_base); | ||
| 264 | s->next_pts += s->pkt_sample_count; | 261 | s->next_pts += s->pkt_sample_count; |
| 265 | s->pkt_sample_count = 0; | 262 | s->pkt_sample_count = 0; |
| 266 | if (buf_size > speex_bits_nbytes(&s->bits)) { | 263 | if (buf_size > speex_bits_nbytes(&s->bits)) { |
| @@ -29,8 +29,8 @@ · 28 unmodified lines | |||
| 29 | #include "libavutil/opt.h" | 29 | #include "libavutil/opt.h" |
| 30 | #include "avcodec.h" | 30 | #include "avcodec.h" |
| 31 | #include "bytestream.h" | 31 | #include "bytestream.h" |
| 32 | #include "internal.h" | ||
| 32 | #include "vorbis.h" | 33 | #include "vorbis.h" |
| 33 | #include "libavutil/mathematics.h" | ||
| 34 | 34 | ||
| 35 | #undef NDEBUG | 35 | #undef NDEBUG |
| 36 | #include <assert.h> | 36 | #include <assert.h> |
| @@ -268,7 +268,8 @@ static int oggvorbis_encode_frame(AVCodecContext *avccontext, · 231 unmodified lines | |||
| 268 | op2->packet = context->buffer + sizeof(ogg_packet); | 268 | op2->packet = context->buffer + sizeof(ogg_packet); |
| 269 | 269 | ||
| 270 | l = op2->bytes; | 270 | 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); | ||
| 272 | //FIXME we should reorder the user supplied pts and not assume that they are spaced by 1/sample_rate | 273 | //FIXME we should reorder the user supplied pts and not assume that they are spaced by 1/sample_rate |
| 273 | 274 | ||
| 274 | if (l > buf_size) { | 275 | if (l > buf_size) { |
| @@ -314,7 +314,7 @@ static int mlp_parse(AVCodecParserContext *s, · 313 unmodified lines | |||
| 314 | else | 314 | else |
| 315 | avctx->sample_fmt = AV_SAMPLE_FMT_S16; | 315 | avctx->sample_fmt = AV_SAMPLE_FMT_S16; |
| 316 | avctx->sample_rate = mh.group1_samplerate; | 316 | avctx->sample_rate = mh.group1_samplerate; |
| 317 | avctx->frame_size = mh.access_unit_size; | 317 | s->duration = mh.access_unit_size; |
| 318 | 318 | ||
| 319 | if (mh.stream_type == 0xbb) { | 319 | if (mh.stream_type == 0xbb) { |
| 320 | /* MLP stream */ | 320 | /* MLP stream */ |
| @@ -78,7 +78,7 @@ static int mpegaudio_parse(AVCodecParserContext *s1, · 77 unmodified lines | |||
| 78 | if(s->header_count > 1){ | 78 | if(s->header_count > 1){ |
| 79 | avctx->sample_rate= sr; | 79 | avctx->sample_rate= sr; |
| 80 | avctx->channels = channels; | 80 | avctx->channels = channels; |
| 81 | avctx->frame_size = frame_size; | 81 | s1->duration = frame_size; |
| 82 | avctx->bit_rate = bit_rate; | 82 | avctx->bit_rate = bit_rate; |
| 83 | } | 83 | } |
| 84 | break; | 84 | break; |
| @@ -29,6 +29,7 @@ · 28 unmodified lines | |||
| 29 | #include "avcodec.h" | 29 | #include "avcodec.h" |
| 30 | #include "bytestream.h" | 30 | #include "bytestream.h" |
| 31 | #include "libavutil/imgutils.h" | 31 | #include "libavutil/imgutils.h" |
| 32 | #include "internal.h" | ||
| 32 | 33 | ||
| 33 | typedef struct PCXContext { | 34 | typedef struct PCXContext { |
| 34 | AVFrame picture; | 35 | AVFrame picture; |
| @@ -96,20 +97,20 @@ static int pcx_rle_encode( uint8_t *dst, int dst_size, · 61 unmodified lines | |||
| 96 | return dst - dst_start; | 97 | return dst - dst_start; |
| 97 | } | 98 | } |
| 98 | 99 | ||
| 99 | static int pcx_encode_frame(AVCodecContext *avctx, | 100 | static int pcx_encode_frame(AVCodecContext *avctx, AVPacket *pkt, |
| 100 | unsigned char *buf, int buf_size, void *data) | 101 | const AVFrame *frame, int *got_packet) |
| 101 | { | 102 | { |
| 102 | PCXContext *s = avctx->priv_data; | 103 | PCXContext *s = avctx->priv_data; |
| 103 | AVFrame *const pict = &s->picture; | 104 | AVFrame *const pict = &s->picture; |
| 104 | const uint8_t *buf_start = buf; | 105 | const uint8_t *buf_end; |
| 105 | const uint8_t *buf_end = buf + buf_size; | 106 | uint8_t *buf; |
| 106 | 107 | ||
| 107 | int bpp, nplanes, i, y, line_bytes, written; | 108 | int bpp, nplanes, i, y, line_bytes, written, ret, max_pkt_size; |
| 108 | const uint32_t *pal = NULL; | 109 | const uint32_t *pal = NULL; |
| 109 | uint32_t palette256[256]; | 110 | uint32_t palette256[256]; |
| 110 | const uint8_t *src; | 111 | const uint8_t *src; |
| 111 | 112 | ||
| 112 | *pict = *(AVFrame *)data; | 113 | *pict = *frame; |
| 113 | pict->pict_type = AV_PICTURE_TYPE_I; | 114 | pict->pict_type = AV_PICTURE_TYPE_I; |
| 114 | pict->key_frame = 1; | 115 | pict->key_frame = 1; |
| 115 | 116 | ||
| @@ -151,6 +152,14 @@ static int pcx_encode_frame(AVCodecContext *avctx, · 35 unmodified lines | |||
| 151 | line_bytes = (avctx->width * bpp + 7) >> 3; | 152 | line_bytes = (avctx->width * bpp + 7) >> 3; |
| 152 | line_bytes = (line_bytes + 1) & ~1; | 153 | line_bytes = (line_bytes + 1) & ~1; |
| 153 | 154 | ||
| 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 | |||
| 154 | bytestream_put_byte(&buf, 10); // manufacturer | 163 | bytestream_put_byte(&buf, 10); // manufacturer |
| 155 | bytestream_put_byte(&buf, 5); // version | 164 | bytestream_put_byte(&buf, 5); // version |
| 156 | bytestream_put_byte(&buf, 1); // encoding | 165 | bytestream_put_byte(&buf, 1); // encoding |
| @@ -167,7 +176,7 @@ static int pcx_encode_frame(AVCodecContext *avctx, · 10 unmodified lines | |||
| 167 | bytestream_put_byte(&buf, nplanes); // number of planes | 176 | bytestream_put_byte(&buf, nplanes); // number of planes |
| 168 | bytestream_put_le16(&buf, line_bytes); // scanline plane size in bytes | 177 | bytestream_put_le16(&buf, line_bytes); // scanline plane size in bytes |
| 169 | 178 | ||
| 170 | while (buf - buf_start < 128) | 179 | while (buf - pkt->data < 128) |
| 171 | *buf++= 0; | 180 | *buf++= 0; |
| 172 | 181 | ||
| 173 | src = pict->data[0]; | 182 | src = pict->data[0]; |
| @@ -193,7 +202,11 @@ static int pcx_encode_frame(AVCodecContext *avctx, · 19 unmodified lines | |||
| 193 | } | 202 | } |
| 194 | } | 203 | } |
| 195 | 204 | ||
| 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; | ||
| 197 | } | 210 | } |
| 198 | 211 | ||
| 199 | AVCodec ff_pcx_encoder = { | 212 | AVCodec ff_pcx_encoder = { |
| @@ -202,7 +215,7 @@ AVCodec ff_pcx_encoder = { · 2 unmodified lines | |||
| 202 | .id = CODEC_ID_PCX, | 215 | .id = CODEC_ID_PCX, |
| 203 | .priv_data_size = sizeof(PCXContext), | 216 | .priv_data_size = sizeof(PCXContext), |
| 204 | .init = pcx_encode_init, | 217 | .init = pcx_encode_init, |
| 205 | .encode = pcx_encode_frame, | 218 | .encode2 = pcx_encode_frame, |
| 206 | .pix_fmts = (const enum PixelFormat[]){ | 219 | .pix_fmts = (const enum PixelFormat[]){ |
| 207 | PIX_FMT_RGB24, | 220 | PIX_FMT_RGB24, |
| 208 | PIX_FMT_RGB8, PIX_FMT_BGR8, PIX_FMT_RGB4_BYTE, PIX_FMT_BGR4_BYTE, PIX_FMT_GRAY8, PIX_FMT_PAL8, | 221 | PIX_FMT_RGB8, PIX_FMT_BGR8, PIX_FMT_RGB4_BYTE, PIX_FMT_BGR4_BYTE, PIX_FMT_GRAY8, PIX_FMT_PAL8, |
| @@ -201,7 +201,6 @@ AVCodec ff_pgm_decoder = { · 200 unmodified lines | |||
| 201 | .close = ff_pnm_end, | 201 | .close = ff_pnm_end, |
| 202 | .decode = pnm_decode_frame, | 202 | .decode = pnm_decode_frame, |
| 203 | .capabilities = CODEC_CAP_DR1, | 203 | .capabilities = CODEC_CAP_DR1, |
| 204 | .pix_fmts = (const enum PixelFormat[]){PIX_FMT_GRAY8, PIX_FMT_GRAY16BE, PIX_FMT_NONE}, | ||
| 205 | .long_name = NULL_IF_CONFIG_SMALL("PGM (Portable GrayMap) image"), | 204 | .long_name = NULL_IF_CONFIG_SMALL("PGM (Portable GrayMap) image"), |
| 206 | }; | 205 | }; |
| 207 | #endif | 206 | #endif |
| @@ -216,7 +215,6 @@ AVCodec ff_pgmyuv_decoder = { · 8 unmodified lines | |||
| 216 | .close = ff_pnm_end, | 215 | .close = ff_pnm_end, |
| 217 | .decode = pnm_decode_frame, | 216 | .decode = pnm_decode_frame, |
| 218 | .capabilities = CODEC_CAP_DR1, | 217 | .capabilities = CODEC_CAP_DR1, |
| 219 | .pix_fmts = (const enum PixelFormat[]){PIX_FMT_YUV420P, PIX_FMT_NONE}, | ||
| 220 | .long_name = NULL_IF_CONFIG_SMALL("PGMYUV (Portable GrayMap YUV) image"), | 218 | .long_name = NULL_IF_CONFIG_SMALL("PGMYUV (Portable GrayMap YUV) image"), |
| 221 | }; | 219 | }; |
| 222 | #endif | 220 | #endif |
| @@ -231,7 +229,6 @@ AVCodec ff_ppm_decoder = { · 8 unmodified lines | |||
| 231 | .close = ff_pnm_end, | 229 | .close = ff_pnm_end, |
| 232 | .decode = pnm_decode_frame, | 230 | .decode = pnm_decode_frame, |
| 233 | .capabilities = CODEC_CAP_DR1, | 231 | .capabilities = CODEC_CAP_DR1, |
| 234 | .pix_fmts = (const enum PixelFormat[]){PIX_FMT_RGB24, PIX_FMT_RGB48BE, PIX_FMT_NONE}, | ||
| 235 | .long_name = NULL_IF_CONFIG_SMALL("PPM (Portable PixelMap) image"), | 232 | .long_name = NULL_IF_CONFIG_SMALL("PPM (Portable PixelMap) image"), |
| 236 | }; | 233 | }; |
| 237 | #endif | 234 | #endif |
| @@ -246,7 +243,6 @@ AVCodec ff_pbm_decoder = { · 8 unmodified lines | |||
| 246 | .close = ff_pnm_end, | 243 | .close = ff_pnm_end, |
| 247 | .decode = pnm_decode_frame, | 244 | .decode = pnm_decode_frame, |
| 248 | .capabilities = CODEC_CAP_DR1, | 245 | .capabilities = CODEC_CAP_DR1, |
| 249 | .pix_fmts = (const enum PixelFormat[]){PIX_FMT_MONOWHITE, PIX_FMT_NONE}, | ||
| 250 | .long_name = NULL_IF_CONFIG_SMALL("PBM (Portable BitMap) image"), | 246 | .long_name = NULL_IF_CONFIG_SMALL("PBM (Portable BitMap) image"), |
| 251 | }; | 247 | }; |
| 252 | #endif | 248 | #endif |
| @@ -261,7 +257,6 @@ AVCodec ff_pam_decoder = { · 8 unmodified lines | |||
| 261 | .close = ff_pnm_end, | 257 | .close = ff_pnm_end, |
| 262 | .decode = pnm_decode_frame, | 258 | .decode = pnm_decode_frame, |
| 263 | .capabilities = CODEC_CAP_DR1, | 259 | .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}, | ||
| 265 | .long_name = NULL_IF_CONFIG_SMALL("PAM (Portable AnyMap) image"), | 260 | .long_name = NULL_IF_CONFIG_SMALL("PAM (Portable AnyMap) image"), |
| 266 | }; | 261 | }; |
| 267 | #endif | 262 | #endif |
| @@ -20,21 +20,23 @@ · 19 unmodified lines | |||
| 20 | */ | 20 | */ |
| 21 | 21 | ||
| 22 | #include "avcodec.h" | 22 | #include "avcodec.h" |
| 23 | #include "internal.h" | ||
| 23 | #include "pnm.h" | 24 | #include "pnm.h" |
| 24 | 25 | ||
| 25 | 26 | ||
| 26 | static int pnm_encode_frame(AVCodecContext *avctx, unsigned char *outbuf, | 27 | static int pnm_encode_frame(AVCodecContext *avctx, AVPacket *pkt, |
| 27 | int buf_size, void *data) | 28 | const AVFrame *pict, int *got_packet) |
| 28 | { | 29 | { |
| 29 | PNMContext *s = avctx->priv_data; | 30 | PNMContext *s = avctx->priv_data; |
| 30 | AVFrame *pict = data; | ||
| 31 | AVFrame * const p = (AVFrame*)&s->picture; | 31 | AVFrame * const p = (AVFrame*)&s->picture; |
| 32 | int i, h, h1, c, n, linesize; | 32 | int i, h, h1, c, n, linesize, ret; |
| 33 | uint8_t *ptr, *ptr1, *ptr2; | 33 | uint8_t *ptr, *ptr1, *ptr2; |
| 34 | 34 | ||
| 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) { | ||
| 36 | av_log(avctx, AV_LOG_ERROR, "encoded frame too large\n"); | 38 | av_log(avctx, AV_LOG_ERROR, "encoded frame too large\n"); |
| 37 | return -1; | 39 | return ret; |
| 38 | } | 40 | } |
| 39 | 41 | ||
| 40 | *p = *pict; | 42 | *p = *pict; |
| @@ -42,8 +44,8 @@ static int pnm_encode_frame(AVCodecContext *avctx, unsigned char *outbuf, · 1 unmodified line | |||
| 42 | p->key_frame = 1; | 44 | p->key_frame = 1; |
| 43 | 45 | ||
| 44 | s->bytestream_start = | 46 | s->bytestream_start = |
| 45 | s->bytestream = outbuf; | 47 | s->bytestream = pkt->data; |
| 46 | s->bytestream_end = outbuf + buf_size; | 48 | s->bytestream_end = pkt->data + pkt->size; |
| 47 | 49 | ||
| 48 | h = avctx->height; | 50 | h = avctx->height; |
| 49 | h1 = h; | 51 | h1 = h; |
| @@ -107,7 +109,11 @@ static int pnm_encode_frame(AVCodecContext *avctx, unsigned char *outbuf, · 57 unmodified lines | |||
| 107 | ptr2 += p->linesize[2]; | 109 | ptr2 += p->linesize[2]; |
| 108 | } | 110 | } |
| 109 | } | 111 | } |
| 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; | ||
| 111 | } | 117 | } |
| 112 | 118 | ||
| 113 | 119 | ||
| @@ -118,7 +124,7 @@ AVCodec ff_pgm_encoder = { · 4 unmodified lines | |||
| 118 | .id = CODEC_ID_PGM, | 124 | .id = CODEC_ID_PGM, |
| 119 | .priv_data_size = sizeof(PNMContext), | 125 | .priv_data_size = sizeof(PNMContext), |
| 120 | .init = ff_pnm_init, | 126 | .init = ff_pnm_init, |
| 121 | .encode = pnm_encode_frame, | 127 | .encode2 = pnm_encode_frame, |
| 122 | .pix_fmts = (const enum PixelFormat[]){PIX_FMT_GRAY8, PIX_FMT_GRAY16BE, PIX_FMT_NONE}, | 128 | .pix_fmts = (const enum PixelFormat[]){PIX_FMT_GRAY8, PIX_FMT_GRAY16BE, PIX_FMT_NONE}, |
| 123 | .long_name = NULL_IF_CONFIG_SMALL("PGM (Portable GrayMap) image"), | 129 | .long_name = NULL_IF_CONFIG_SMALL("PGM (Portable GrayMap) image"), |
| 124 | }; | 130 | }; |
| @@ -131,7 +137,7 @@ AVCodec ff_pgmyuv_encoder = { · 6 unmodified lines | |||
| 131 | .id = CODEC_ID_PGMYUV, | 137 | .id = CODEC_ID_PGMYUV, |
| 132 | .priv_data_size = sizeof(PNMContext), | 138 | .priv_data_size = sizeof(PNMContext), |
| 133 | .init = ff_pnm_init, | 139 | .init = ff_pnm_init, |
| 134 | .encode = pnm_encode_frame, | 140 | .encode2 = pnm_encode_frame, |
| 135 | .pix_fmts = (const enum PixelFormat[]){PIX_FMT_YUV420P, PIX_FMT_NONE}, | 141 | .pix_fmts = (const enum PixelFormat[]){PIX_FMT_YUV420P, PIX_FMT_NONE}, |
| 136 | .long_name = NULL_IF_CONFIG_SMALL("PGMYUV (Portable GrayMap YUV) image"), | 142 | .long_name = NULL_IF_CONFIG_SMALL("PGMYUV (Portable GrayMap YUV) image"), |
| 137 | }; | 143 | }; |
| @@ -144,7 +150,7 @@ AVCodec ff_ppm_encoder = { · 6 unmodified lines | |||
| 144 | .id = CODEC_ID_PPM, | 150 | .id = CODEC_ID_PPM, |
| 145 | .priv_data_size = sizeof(PNMContext), | 151 | .priv_data_size = sizeof(PNMContext), |
| 146 | .init = ff_pnm_init, | 152 | .init = ff_pnm_init, |
| 147 | .encode = pnm_encode_frame, | 153 | .encode2 = pnm_encode_frame, |
| 148 | .pix_fmts = (const enum PixelFormat[]){PIX_FMT_RGB24, PIX_FMT_RGB48BE, PIX_FMT_NONE}, | 154 | .pix_fmts = (const enum PixelFormat[]){PIX_FMT_RGB24, PIX_FMT_RGB48BE, PIX_FMT_NONE}, |
| 149 | .long_name = NULL_IF_CONFIG_SMALL("PPM (Portable PixelMap) image"), | 155 | .long_name = NULL_IF_CONFIG_SMALL("PPM (Portable PixelMap) image"), |
| 150 | }; | 156 | }; |
| @@ -157,7 +163,7 @@ AVCodec ff_pbm_encoder = { · 6 unmodified lines | |||
| 157 | .id = CODEC_ID_PBM, | 163 | .id = CODEC_ID_PBM, |
| 158 | .priv_data_size = sizeof(PNMContext), | 164 | .priv_data_size = sizeof(PNMContext), |
| 159 | .init = ff_pnm_init, | 165 | .init = ff_pnm_init, |
| 160 | .encode = pnm_encode_frame, | 166 | .encode2 = pnm_encode_frame, |
| 161 | .pix_fmts = (const enum PixelFormat[]){PIX_FMT_MONOWHITE, PIX_FMT_NONE}, | 167 | .pix_fmts = (const enum PixelFormat[]){PIX_FMT_MONOWHITE, PIX_FMT_NONE}, |
| 162 | .long_name = NULL_IF_CONFIG_SMALL("PBM (Portable BitMap) image"), | 168 | .long_name = NULL_IF_CONFIG_SMALL("PBM (Portable BitMap) image"), |
| 163 | }; | 169 | }; |
| @@ -69,7 +69,7 @@ typedef struct RoqContext { · 68 unmodified lines | |||
| 69 | 69 | ||
| 70 | unsigned int framesSinceKeyframe; | 70 | unsigned int framesSinceKeyframe; |
| 71 | 71 | ||
| 72 | AVFrame *frame_to_enc; | 72 | const AVFrame *frame_to_enc; |
| 73 | uint8_t *out_buf; | 73 | uint8_t *out_buf; |
| 74 | struct RoqTempData *tmpData; | 74 | struct RoqTempData *tmpData; |
| 75 | } RoqContext; | 75 | } RoqContext; |
| @@ -59,6 +59,7 @@ · 58 unmodified lines | |||
| 59 | #include "roqvideo.h" | 59 | #include "roqvideo.h" |
| 60 | #include "bytestream.h" | 60 | #include "bytestream.h" |
| 61 | #include "elbg.h" | 61 | #include "elbg.h" |
| 62 | #include "internal.h" | ||
| 62 | #include "mathops.h" | 63 | #include "mathops.h" |
| 63 | 64 | ||
| 64 | #define CHROMA_BIAS 1 | 65 | #define CHROMA_BIAS 1 |
| @@ -112,7 +113,7 @@ static inline int square(int x) · 47 unmodified lines | |||
| 112 | return x*x; | 113 | return x*x; |
| 113 | } | 114 | } |
| 114 | 115 | ||
| 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) |
| 116 | { | 117 | { |
| 117 | int diff=0; | 118 | int diff=0; |
| 118 | 119 | ||
| @@ -124,8 +125,8 @@ static inline int eval_sse(uint8_t *a, uint8_t *b, int count) · 5 unmodified lines | |||
| 124 | 125 | ||
| 125 | // FIXME Could use DSPContext.sse, but it is not so speed critical (used | 126 | // FIXME Could use DSPContext.sse, but it is not so speed critical (used |
| 126 | // just for motion estimation). | 127 | // just for motion estimation). |
| 127 | static int block_sse(uint8_t **buf1, uint8_t **buf2, int x1, int y1, int x2, | 128 | static int block_sse(uint8_t * const *buf1, uint8_t * const *buf2, int x1, int y1, |
| 128 | int y2, int *stride1, int *stride2, int size) | 129 | int x2, int y2, const int *stride1, const int *stride2, int size) |
| 129 | { | 130 | { |
| 130 | int i, k; | 131 | int i, k; |
| 131 | int sse=0; | 132 | int sse=0; |
| @@ -260,7 +261,7 @@ static void create_cel_evals(RoqContext *enc, RoqTempdata *tempData) · 128 unmodified lines | |||
| 260 | /** | 261 | /** |
| 261 | * Get macroblocks from parts of the image | 262 | * Get macroblocks from parts of the image |
| 262 | */ | 263 | */ |
| 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) |
| 264 | { | 265 | { |
| 265 | int i, j, cp; | 266 | int i, j, cp; |
| 266 | 267 | ||
| @@ -754,8 +755,8 @@ static void reconstruct_and_encode_image(RoqContext *enc, RoqTempdata *tempData, · 487 unmodified lines | |||
| 754 | /** | 755 | /** |
| 755 | * Create a single YUV cell from a 2x2 section of the image | 756 | * Create a single YUV cell from a 2x2 section of the image |
| 756 | */ | 757 | */ |
| 757 | static inline void frame_block_to_cell(uint8_t *block, uint8_t **data, | 758 | static inline void frame_block_to_cell(uint8_t *block, uint8_t * const *data, |
| 758 | int top, int left, int *stride) | 759 | int top, int left, const int *stride) |
| 759 | { | 760 | { |
| 760 | int i, j, u=0, v=0; | 761 | int i, j, u=0, v=0; |
| 761 | 762 | ||
| @@ -775,7 +776,7 @@ static inline void frame_block_to_cell(uint8_t *block, uint8_t **data, · 13 unmodified lines | |||
| 775 | /** | 776 | /** |
| 776 | * Create YUV clusters for the entire image | 777 | * Create YUV clusters for the entire image |
| 777 | */ | 778 | */ |
| 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) |
| 779 | { | 780 | { |
| 780 | int i, j, k, l; | 781 | int i, j, k, l; |
| 781 | 782 | ||
| @@ -1001,13 +1002,12 @@ static void roq_write_video_info_chunk(RoqContext *enc) · 219 unmodified lines | |||
| 1001 | bytestream_put_byte(&enc->out_buf, 0x00); | 1002 | bytestream_put_byte(&enc->out_buf, 0x00); |
| 1002 | } | 1003 | } |
| 1003 | 1004 | ||
| 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) | ||
| 1005 | { | 1007 | { |
| 1006 | RoqContext *enc = avctx->priv_data; | 1008 | RoqContext *enc = avctx->priv_data; |
| 1007 | AVFrame *frame= data; | 1009 | int size, ret; |
| 1008 | uint8_t *buf_start = buf; | ||
| 1009 | 1010 | ||
| 1010 | enc->out_buf = buf; | ||
| 1011 | enc->avctx = avctx; | 1011 | enc->avctx = avctx; |
| 1012 | 1012 | ||
| 1013 | enc->frame_to_enc = frame; | 1013 | 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 | |||
| 1019 | 1019 | ||
| 1020 | /* 138 bits max per 8x8 block + | 1020 | /* 138 bits max per 8x8 block + |
| 1021 | * 256 codebooks*(6 bytes 2x2 + 4 bytes 4x4) + 8 bytes frame header */ | 1021 | * 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) { | 1022 | size = ((enc->width * enc->height / 64) * 138 + 7) / 8 + 256 * (6 + 4) + 8; |
| 1023 | av_log(avctx, AV_LOG_ERROR, " RoQ: Output buffer too small!\n"); | 1023 | if ((ret = ff_alloc_packet(pkt, size)) < 0) { |
| 1024 | return -1; | 1024 | av_log(avctx, AV_LOG_ERROR, "Error getting output packet with size %d.\n", size); |
| 1025 | return ret; | ||
| 1025 | } | 1026 | } |
| 1027 | enc->out_buf = pkt->data; | ||
| 1026 | 1028 | ||
| 1027 | /* Check for I frame */ | 1029 | /* Check for I frame */ |
| 1028 | if (enc->framesSinceKeyframe == avctx->gop_size) | 1030 | 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 | |||
| 1046 | /* Encode the actual frame */ | 1048 | /* Encode the actual frame */ |
| 1047 | roq_encode_video(enc); | 1049 | roq_encode_video(enc); |
| 1048 | 1050 | ||
| 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; | ||
| 1050 | } | 1057 | } |
| 1051 | 1058 | ||
| 1052 | static int roq_encode_end(AVCodecContext *avctx) | 1059 | static int roq_encode_end(AVCodecContext *avctx) |
| @@ -1071,7 +1078,7 @@ AVCodec ff_roq_encoder = { · 18 unmodified lines | |||
| 1071 | .id = CODEC_ID_ROQ, | 1078 | .id = CODEC_ID_ROQ, |
| 1072 | .priv_data_size = sizeof(RoqContext), | 1079 | .priv_data_size = sizeof(RoqContext), |
| 1073 | .init = roq_encode_init, | 1080 | .init = roq_encode_init, |
| 1074 | .encode = roq_encode_frame, | 1081 | .encode2 = roq_encode_frame, |
| 1075 | .close = roq_encode_end, | 1082 | .close = roq_encode_end, |
| 1076 | .supported_framerates = (const AVRational[]){{30,1}, {0,0}}, | 1083 | .supported_framerates = (const AVRational[]){{30,1}, {0,0}}, |
| 1077 | .pix_fmts = (const enum PixelFormat[]){PIX_FMT_YUV444P, PIX_FMT_NONE}, | 1084 | .pix_fmts = (const enum PixelFormat[]){PIX_FMT_YUV444P, PIX_FMT_NONE}, |
| @@ -21,6 +21,7 @@ · 20 unmodified lines | |||
| 21 | 21 | ||
| 22 | #include "avcodec.h" | 22 | #include "avcodec.h" |
| 23 | #include "bytestream.h" | 23 | #include "bytestream.h" |
| 24 | #include "internal.h" | ||
| 24 | #include "sgi.h" | 25 | #include "sgi.h" |
| 25 | #include "rle.h" | 26 | #include "rle.h" |
| 26 | 27 | ||
| @@ -41,17 +42,17 @@ static av_cold int encode_init(AVCodecContext *avctx) · 14 unmodified lines | |||
| 41 | return 0; | 42 | return 0; |
| 42 | } | 43 | } |
| 43 | 44 | ||
| 44 | static int encode_frame(AVCodecContext *avctx, unsigned char *buf, | 45 | static int encode_frame(AVCodecContext *avctx, AVPacket *pkt, |
| 45 | int buf_size, void *data) | 46 | const AVFrame *frame, int *got_packet) |
| 46 | { | 47 | { |
| 47 | SgiContext *s = avctx->priv_data; | 48 | SgiContext *s = avctx->priv_data; |
| 48 | AVFrame * const p = &s->picture; | 49 | AVFrame * const p = &s->picture; |
| 49 | uint8_t *offsettab, *lengthtab, *in_buf, *encode_buf; | 50 | uint8_t *offsettab, *lengthtab, *in_buf, *encode_buf, *buf; |
| 50 | int x, y, z, length, tablesize; | 51 | int x, y, z, length, tablesize, ret; |
| 51 | unsigned int width, height, depth, dimension, bytes_per_channel, pixmax, put_be; | 52 | 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; |
| 53 | 54 | ||
| 54 | *p = *(AVFrame*)data; | 55 | *p = *frame; |
| 55 | p->pict_type = AV_PICTURE_TYPE_I; | 56 | p->pict_type = AV_PICTURE_TYPE_I; |
| 56 | p->key_frame = 1; | 57 | p->key_frame = 1; |
| 57 | 58 | ||
| @@ -106,12 +107,18 @@ static int encode_frame(AVCodecContext *avctx, unsigned char *buf, · 48 unmodified lines | |||
| 106 | } | 107 | } |
| 107 | 108 | ||
| 108 | tablesize = depth * height * 4; | 109 | tablesize = depth * height * 4; |
| 109 | length = tablesize * 2 + SGI_HEADER_SIZE; | 110 | length = SGI_HEADER_SIZE; |
| 110 | 111 | if (avctx->coder_type == FF_CODER_TYPE_RAW) | |
| 111 | if (buf_size < length) { | 112 | length += depth * height * width; |
| 112 | av_log(avctx, AV_LOG_ERROR, "buf_size too small(need %d, got %d)\n", length, buf_size); | 113 | else // assume ff_rl_encode() produces at most 2x size of input |
| 113 | return -1; | 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; | ||
| 114 | } | 119 | } |
| 120 | buf = pkt->data; | ||
| 121 | end_buf = pkt->data + pkt->size; | ||
| 115 | 122 | ||
| 116 | /* Encode header. */ | 123 | /* Encode header. */ |
| 117 | bytestream_put_be16(&buf, SGI_MAGIC); | 124 | bytestream_put_be16(&buf, SGI_MAGIC); |
| @@ -153,7 +160,7 @@ static int encode_frame(AVCodecContext *avctx, unsigned char *buf, · 35 unmodified lines | |||
| 153 | in_buf = p->data[0] + p->linesize[0] * (height - 1) + z; | 160 | in_buf = p->data[0] + p->linesize[0] * (height - 1) + z; |
| 154 | 161 | ||
| 155 | for (y = 0; y < height; y++) { | 162 | for (y = 0; y < height; y++) { |
| 156 | bytestream_put_be32(&offsettab, buf - orig_buf); | 163 | bytestream_put_be32(&offsettab, buf - pkt->data); |
| 157 | 164 | ||
| 158 | for (x = 0; x < width; x++) | 165 | for (x = 0; x < width; x++) |
| 159 | encode_buf[x] = in_buf[depth * x]; | 166 | encode_buf[x] = in_buf[depth * x]; |
| @@ -193,7 +200,11 @@ static int encode_frame(AVCodecContext *avctx, unsigned char *buf, · 33 unmodified lines | |||
| 193 | } | 200 | } |
| 194 | 201 | ||
| 195 | /* total length */ | 202 | /* 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; | ||
| 197 | } | 208 | } |
| 198 | 209 | ||
| 199 | AVCodec ff_sgi_encoder = { | 210 | AVCodec ff_sgi_encoder = { |
| @@ -202,7 +213,7 @@ AVCodec ff_sgi_encoder = { · 2 unmodified lines | |||
| 202 | .id = CODEC_ID_SGI, | 213 | .id = CODEC_ID_SGI, |
| 203 | .priv_data_size = sizeof(SgiContext), | 214 | .priv_data_size = sizeof(SgiContext), |
| 204 | .init = encode_init, | 215 | .init = encode_init, |
| 205 | .encode = encode_frame, | 216 | .encode2 = encode_frame, |
| 206 | .pix_fmts= (const enum PixelFormat[]){PIX_FMT_RGB24, PIX_FMT_RGBA, | 217 | .pix_fmts= (const enum PixelFormat[]){PIX_FMT_RGB24, PIX_FMT_RGBA, |
| 207 | PIX_FMT_RGB48LE, PIX_FMT_RGB48BE, | 218 | PIX_FMT_RGB48LE, PIX_FMT_RGB48BE, |
| 208 | PIX_FMT_RGBA64LE, PIX_FMT_RGBA64BE, | 219 | PIX_FMT_RGBA64LE, PIX_FMT_RGBA64BE, |
| @@ -22,6 +22,7 @@ · 21 unmodified lines | |||
| 22 | #include "libavutil/intreadwrite.h" | 22 | #include "libavutil/intreadwrite.h" |
| 23 | #include "libavutil/pixdesc.h" | 23 | #include "libavutil/pixdesc.h" |
| 24 | #include "avcodec.h" | 24 | #include "avcodec.h" |
| 25 | #include "internal.h" | ||
| 25 | #include "rle.h" | 26 | #include "rle.h" |
| 26 | #include "targa.h" | 27 | #include "targa.h" |
| 27 | 28 | ||
| @@ -39,7 +40,7 @@ typedef struct TargaContext { · 11 unmodified lines | |||
| 39 | * @param h Image height | 40 | * @param h Image height |
| 40 | * @return Size of output in bytes, or -1 if larger than out_size | 41 | * @return Size of output in bytes, or -1 if larger than out_size |
| 41 | */ | 42 | */ |
| 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, |
| 43 | int bpp, int w, int h) | 44 | int bpp, int w, int h) |
| 44 | { | 45 | { |
| 45 | int y,ret; | 46 | int y,ret; |
| @@ -59,7 +60,7 @@ static int targa_encode_rle(uint8_t *outbuf, int out_size, AVFrame *pic, · 13 unmodified lines | |||
| 59 | return out - outbuf; | 60 | return out - outbuf; |
| 60 | } | 61 | } |
| 61 | 62 | ||
| 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) |
| 63 | { | 64 | { |
| 64 | int i, n = bpp * w; | 65 | int i, n = bpp * w; |
| 65 | uint8_t *out = outbuf; | 66 | 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 | |||
| 74 | return out - outbuf; | 75 | return out - outbuf; |
| 75 | } | 76 | } |
| 76 | 77 | ||
| 77 | static int targa_encode_frame(AVCodecContext *avctx, | 78 | static int targa_encode_frame(AVCodecContext *avctx, AVPacket *pkt, |
| 78 | unsigned char *outbuf, | 79 | const AVFrame *p, int *got_packet) |
| 79 | int buf_size, void *data){ | 80 | { |
| 80 | AVFrame *p = data; | 81 | int bpp, picsize, datasize = -1, ret; |
| 81 | int bpp, picsize, datasize = -1; | ||
| 82 | uint8_t *out; | 82 | uint8_t *out; |
| 83 | 83 | ||
| 84 | if(avctx->width > 0xffff || avctx->height > 0xffff) { | 84 | if(avctx->width > 0xffff || avctx->height > 0xffff) { |
| @@ -86,46 +86,43 @@ static int targa_encode_frame(AVCodecContext *avctx, · 1 unmodified line | |||
| 86 | return AVERROR(EINVAL); | 86 | return AVERROR(EINVAL); |
| 87 | } | 87 | } |
| 88 | picsize = avpicture_get_size(avctx->pix_fmt, avctx->width, avctx->height); | 88 | 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) { |
| 90 | av_log(avctx, AV_LOG_ERROR, "encoded frame too large\n"); | 90 | av_log(avctx, AV_LOG_ERROR, "encoded frame too large\n"); |
| 91 | return AVERROR(EINVAL); | 91 | return ret; |
| 92 | } | 92 | } |
| 93 | 93 | ||
| 94 | p->pict_type= AV_PICTURE_TYPE_I; | ||
| 95 | p->key_frame= 1; | ||
| 96 | |||
| 97 | /* zero out the header and only set applicable fields */ | 94 | /* zero out the header and only set applicable fields */ |
| 98 | memset(outbuf, 0, 12); | 95 | memset(pkt->data, 0, 12); |
| 99 | AV_WL16(outbuf+12, avctx->width); | 96 | AV_WL16(pkt->data+12, avctx->width); |
| 100 | AV_WL16(outbuf+14, avctx->height); | 97 | AV_WL16(pkt->data+14, avctx->height); |
| 101 | /* image descriptor byte: origin is always top-left, bits 0-3 specify alpha */ | 98 | /* 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); |
| 103 | 100 | ||
| 104 | switch(avctx->pix_fmt) { | 101 | switch(avctx->pix_fmt) { |
| 105 | case PIX_FMT_GRAY8: | 102 | case PIX_FMT_GRAY8: |
| 106 | outbuf[2] = TGA_BW; /* uncompressed grayscale image */ | 103 | pkt->data[2] = TGA_BW; /* uncompressed grayscale image */ |
| 107 | outbuf[16] = 8; /* bpp */ | 104 | pkt->data[16] = 8; /* bpp */ |
| 108 | break; | 105 | break; |
| 109 | case PIX_FMT_RGB555LE: | 106 | case PIX_FMT_RGB555LE: |
| 110 | outbuf[2] = TGA_RGB; /* uncompresses true-color image */ | 107 | pkt->data[2] = TGA_RGB; /* uncompresses true-color image */ |
| 111 | outbuf[16] = 16; /* bpp */ | 108 | pkt->data[16] = 16; /* bpp */ |
| 112 | break; | 109 | break; |
| 113 | case PIX_FMT_BGR24: | 110 | case PIX_FMT_BGR24: |
| 114 | outbuf[2] = TGA_RGB; /* uncompressed true-color image */ | 111 | pkt->data[2] = TGA_RGB; /* uncompressed true-color image */ |
| 115 | outbuf[16] = 24; /* bpp */ | 112 | pkt->data[16] = 24; /* bpp */ |
| 116 | break; | 113 | break; |
| 117 | case PIX_FMT_BGRA: | 114 | case PIX_FMT_BGRA: |
| 118 | outbuf[2] = TGA_RGB; /* uncompressed true-color image */ | 115 | pkt->data[2] = TGA_RGB; /* uncompressed true-color image */ |
| 119 | outbuf[16] = 32; /* bpp */ | 116 | pkt->data[16] = 32; /* bpp */ |
| 120 | break; | 117 | break; |
| 121 | default: | 118 | default: |
| 122 | av_log(avctx, AV_LOG_ERROR, "Pixel format '%s' not supported.\n", | 119 | av_log(avctx, AV_LOG_ERROR, "Pixel format '%s' not supported.\n", |
| 123 | av_get_pix_fmt_name(avctx->pix_fmt)); | 120 | av_get_pix_fmt_name(avctx->pix_fmt)); |
| 124 | return AVERROR(EINVAL); | 121 | return AVERROR(EINVAL); |
| 125 | } | 122 | } |
| 126 | bpp = outbuf[16] >> 3; | 123 | bpp = pkt->data[16] >> 3; |
| 127 | 124 | ||
| 128 | out = outbuf + 18; /* skip past the header we just output */ | 125 | out = pkt->data + 18; /* skip past the header we just output */ |
| 129 | 126 | ||
| 130 | /* try RLE compression */ | 127 | /* try RLE compression */ |
| 131 | if (avctx->coder_type != FF_CODER_TYPE_RAW) | 128 | if (avctx->coder_type != FF_CODER_TYPE_RAW) |
| @@ -133,7 +130,7 @@ static int targa_encode_frame(AVCodecContext *avctx, · 1 unmodified line | |||
| 133 | 130 | ||
| 134 | /* if that worked well, mark the picture as RLE compressed */ | 131 | /* if that worked well, mark the picture as RLE compressed */ |
| 135 | if(datasize >= 0) | 132 | if(datasize >= 0) |
| 136 | outbuf[2] |= 8; | 133 | pkt->data[2] |= 8; |
| 137 | 134 | ||
| 138 | /* if RLE didn't make it smaller, go back to no compression */ | 135 | /* if RLE didn't make it smaller, go back to no compression */ |
| 139 | else datasize = targa_encode_normal(out, p, bpp, avctx->width, avctx->height); | 136 | 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 | |||
| 145 | * aspect ratio and encoder ID fields available? */ | 142 | * aspect ratio and encoder ID fields available? */ |
| 146 | memcpy(out, "\0\0\0\0\0\0\0\0TRUEVISION-XFILE.", 26); | 143 | memcpy(out, "\0\0\0\0\0\0\0\0TRUEVISION-XFILE.", 26); |
| 147 | 144 | ||
| 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; | ||
| 149 | } | 150 | } |
| 150 | 151 | ||
| 151 | static av_cold int targa_encode_init(AVCodecContext *avctx) | 152 | 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 | |||
| 154 | 155 | ||
| 155 | avcodec_get_frame_defaults(&s->picture); | 156 | avcodec_get_frame_defaults(&s->picture); |
| 156 | s->picture.key_frame= 1; | 157 | s->picture.key_frame= 1; |
| 158 | s->picture.pict_type = AV_PICTURE_TYPE_I; | ||
| 157 | avctx->coded_frame= &s->picture; | 159 | avctx->coded_frame= &s->picture; |
| 158 | 160 | ||
| 159 | return 0; | 161 | return 0; |
| @@ -165,7 +167,7 @@ AVCodec ff_targa_encoder = { · 5 unmodified lines | |||
| 165 | .id = CODEC_ID_TARGA, | 167 | .id = CODEC_ID_TARGA, |
| 166 | .priv_data_size = sizeof(TargaContext), | 168 | .priv_data_size = sizeof(TargaContext), |
| 167 | .init = targa_encode_init, | 169 | .init = targa_encode_init, |
| 168 | .encode = targa_encode_frame, | 170 | .encode2 = targa_encode_frame, |
| 169 | .pix_fmts= (const enum PixelFormat[]){PIX_FMT_BGR24, PIX_FMT_BGRA, PIX_FMT_RGB555LE, PIX_FMT_GRAY8, PIX_FMT_NONE}, | 171 | .pix_fmts= (const enum PixelFormat[]){PIX_FMT_BGR24, PIX_FMT_BGRA, PIX_FMT_RGB555LE, PIX_FMT_GRAY8, PIX_FMT_NONE}, |
| 170 | .long_name= NULL_IF_CONFIG_SMALL("Truevision Targa image"), | 172 | .long_name= NULL_IF_CONFIG_SMALL("Truevision Targa image"), |
| 171 | }; | 173 | }; |
| @@ -993,9 +993,8 @@ int attribute_align_arg avcodec_encode_audio2(AVCodecContext *avctx, · 992 unmodified lines | |||
| 993 | if (!ret && *got_packet_ptr) { | 993 | if (!ret && *got_packet_ptr) { |
| 994 | if (!(avctx->codec->capabilities & CODEC_CAP_DELAY)) { | 994 | if (!(avctx->codec->capabilities & CODEC_CAP_DELAY)) { |
| 995 | avpkt->pts = frame->pts; | 995 | avpkt->pts = frame->pts; |
| 996 | avpkt->duration = av_rescale_q(frame->nb_samples, | 996 | avpkt->duration = ff_samples_to_time_base(avctx, |
| 997 | (AVRational){ 1, avctx->sample_rate }, | 997 | frame->nb_samples); |
| 998 | avctx->time_base); | ||
| 999 | } | 998 | } |
| 1000 | avpkt->dts = avpkt->pts; | 999 | avpkt->dts = avpkt->pts; |
| 1001 | } else { | 1000 | } else { |
| @@ -1053,9 +1052,8 @@ int attribute_align_arg avcodec_encode_audio2(AVCodecContext *avctx, · 51 unmodified lines | |||
| 1053 | once all encoders supporting CODEC_CAP_SMALL_LAST_FRAME use | 1052 | once all encoders supporting CODEC_CAP_SMALL_LAST_FRAME use |
| 1054 | encode2() */ | 1053 | encode2() */ |
| 1055 | if (fs_tmp) { | 1054 | if (fs_tmp) { |
| 1056 | avpkt->duration = av_rescale_q(avctx->frame_size, | 1055 | avpkt->duration = ff_samples_to_time_base(avctx, |
| 1057 | (AVRational){ 1, avctx->sample_rate }, | 1056 | avctx->frame_size); |
| 1058 | avctx->time_base); | ||
| 1059 | } | 1057 | } |
| 1060 | } | 1058 | } |
| 1061 | avpkt->size = ret; | 1059 | avpkt->size = ret; |
| @@ -1128,9 +1126,8 @@ int attribute_align_arg avcodec_encode_audio(AVCodecContext *avctx, · 66 unmodified lines | |||
| 1128 | this is needed because the avcodec_encode_audio() API does not have | 1126 | this is needed because the avcodec_encode_audio() API does not have |
| 1129 | a way for the user to provide pts */ | 1127 | a way for the user to provide pts */ |
| 1130 | if(avctx->sample_rate && avctx->time_base.num) | 1128 | if(avctx->sample_rate && avctx->time_base.num) |
| 1131 | frame->pts = av_rescale_q(avctx->internal->sample_count, | 1129 | frame->pts = ff_samples_to_time_base(avctx, |
| 1132 | (AVRational){ 1, avctx->sample_rate }, | 1130 | avctx->internal->sample_count); |
| 1133 | avctx->time_base); | ||
| 1134 | else | 1131 | else |
| 1135 | frame->pts = AV_NOPTS_VALUE; | 1132 | frame->pts = AV_NOPTS_VALUE; |
| 1136 | avctx->internal->sample_count += frame->nb_samples; | 1133 | avctx->internal->sample_count += frame->nb_samples; |
| @@ -22,6 +22,7 @@ · 21 unmodified lines | |||
| 22 | 22 | ||
| 23 | #include "libavutil/intreadwrite.h" | 23 | #include "libavutil/intreadwrite.h" |
| 24 | #include "avcodec.h" | 24 | #include "avcodec.h" |
| 25 | #include "internal.h" | ||
| 25 | 26 | ||
| 26 | static av_cold int v410_encode_init(AVCodecContext *avctx) | 27 | static av_cold int v410_encode_init(AVCodecContext *avctx) |
| 27 | { | 28 | { |
| @@ -40,20 +41,19 @@ static av_cold int v410_encode_init(AVCodecContext *avctx) · 12 unmodified lines | |||
| 40 | return 0; | 41 | return 0; |
| 41 | } | 42 | } |
| 42 | 43 | ||
| 43 | static int v410_encode_frame(AVCodecContext *avctx, uint8_t *buf, | 44 | static int v410_encode_frame(AVCodecContext *avctx, AVPacket *pkt, |
| 44 | int buf_size, void *data) | 45 | const AVFrame *pic, int *got_packet) |
| 45 | { | 46 | { |
| 46 | AVFrame *pic = data; | 47 | uint8_t *dst; |
| 47 | uint8_t *dst = buf; | ||
| 48 | uint16_t *y, *u, *v; | 48 | uint16_t *y, *u, *v; |
| 49 | uint32_t val; | 49 | uint32_t val; |
| 50 | int i, j; | 50 | int i, j, ret; |
| 51 | int output_size = 0; | ||
| 52 | 51 | ||
| 53 | if (buf_size < avctx->width * avctx->height * 4) { | 52 | if ((ret = ff_alloc_packet(pkt, avctx->width * avctx->height * 4)) < 0) { |
| 54 | av_log(avctx, AV_LOG_ERROR, "Out buffer is too small.\n"); | 53 | av_log(avctx, AV_LOG_ERROR, "Error getting output packet.\n"); |
| 55 | return AVERROR(ENOMEM); | 54 | return ret; |
| 56 | } | 55 | } |
| 56 | dst = pkt->data; | ||
| 57 | 57 | ||
| 58 | avctx->coded_frame->reference = 0; | 58 | avctx->coded_frame->reference = 0; |
| 59 | avctx->coded_frame->key_frame = 1; | 59 | avctx->coded_frame->key_frame = 1; |
| @@ -70,14 +70,15 @@ static int v410_encode_frame(AVCodecContext *avctx, uint8_t *buf, · 10 unmodified lines | |||
| 70 | val |= (uint32_t) v[j] << 22; | 70 | val |= (uint32_t) v[j] << 22; |
| 71 | AV_WL32(dst, val); | 71 | AV_WL32(dst, val); |
| 72 | dst += 4; | 72 | dst += 4; |
| 73 | output_size += 4; | ||
| 74 | } | 73 | } |
| 75 | y += pic->linesize[0] >> 1; | 74 | y += pic->linesize[0] >> 1; |
| 76 | u += pic->linesize[1] >> 1; | 75 | u += pic->linesize[1] >> 1; |
| 77 | v += pic->linesize[2] >> 1; | 76 | v += pic->linesize[2] >> 1; |
| 78 | } | 77 | } |
| 79 | 78 | ||
| 80 | return output_size; | 79 | pkt->flags |= AV_PKT_FLAG_KEY; |
| 80 | *got_packet = 1; | ||
| 81 | return 0; | ||
| 81 | } | 82 | } |
| 82 | 83 | ||
| 83 | static av_cold int v410_encode_close(AVCodecContext *avctx) | 84 | static av_cold int v410_encode_close(AVCodecContext *avctx) |
| @@ -92,7 +93,7 @@ AVCodec ff_v410_encoder = { · 8 unmodified lines | |||
| 92 | .type = AVMEDIA_TYPE_VIDEO, | 93 | .type = AVMEDIA_TYPE_VIDEO, |
| 93 | .id = CODEC_ID_V410, | 94 | .id = CODEC_ID_V410, |
| 94 | .init = v410_encode_init, | 95 | .init = v410_encode_init, |
| 95 | .encode = v410_encode_frame, | 96 | .encode2 = v410_encode_frame, |
| 96 | .close = v410_encode_close, | 97 | .close = v410_encode_close, |
| 97 | .pix_fmts = (const enum PixelFormat[]){ PIX_FMT_YUV444P10, PIX_FMT_NONE }, | 98 | .pix_fmts = (const enum PixelFormat[]){ PIX_FMT_YUV444P10, PIX_FMT_NONE }, |
| 98 | .long_name = NULL_IF_CONFIG_SMALL("Uncompressed 4:4:4 10-bit"), | 99 | .long_name = NULL_IF_CONFIG_SMALL("Uncompressed 4:4:4 10-bit"), |
| @@ -830,9 +830,13 @@ cglobal deblock_v_chroma_8_mmxext, 5,6 · 829 unmodified lines | |||
| 830 | ; void ff_deblock_h_chroma( uint8_t *pix, int stride, int alpha, int beta, int8_t *tc0 ) | 830 | ; void ff_deblock_h_chroma( uint8_t *pix, int stride, int alpha, int beta, int8_t *tc0 ) |
| 831 | ;----------------------------------------------------------------------------- | 831 | ;----------------------------------------------------------------------------- |
| 832 | cglobal deblock_h_chroma_8_mmxext, 5,7 | 832 | cglobal deblock_h_chroma_8_mmxext, 5,7 |
| 833 | %if ARCH_X86_64 | 833 | %if UNIX64 |
| 834 | %define buf0 [rsp-24] | 834 | %define buf0 [rsp-24] |
| 835 | %define buf1 [rsp-16] | 835 | %define buf1 [rsp-16] |
| 836 | %elif WIN64 | ||
| 837 | sub rsp, 16 | ||
| 838 | %define buf0 [rsp] | ||
| 839 | %define buf1 [rsp+8] | ||
| 836 | %else | 840 | %else |
| 837 | %define buf0 r0m | 841 | %define buf0 r0m |
| 838 | %define buf1 r2m | 842 | %define buf1 r2m |
| @@ -849,6 +853,9 @@ cglobal deblock_h_chroma_8_mmxext, 5,7 · 10 unmodified lines | |||
| 849 | movq m0, buf0 | 853 | movq m0, buf0 |
| 850 | movq m3, buf1 | 854 | movq m3, buf1 |
| 851 | TRANSPOSE8x4B_STORE PASS8ROWS(t5, r0, r1, t6) | 855 | TRANSPOSE8x4B_STORE PASS8ROWS(t5, r0, r1, t6) |
| 856 | %if WIN64 | ||
| 857 | add rsp, 16 | ||
| 858 | %endif | ||
| 852 | RET | 859 | RET |
| 853 | 860 | ||
| 854 | ALIGN 16 | 861 | ALIGN 16 |
| @@ -29,6 +29,7 @@ · 28 unmodified lines | |||
| 29 | 29 | ||
| 30 | #include "libavutil/intreadwrite.h" | 30 | #include "libavutil/intreadwrite.h" |
| 31 | #include "avcodec.h" | 31 | #include "avcodec.h" |
| 32 | #include "internal.h" | ||
| 32 | 33 | ||
| 33 | #include <zlib.h> | 34 | #include <zlib.h> |
| 34 | 35 | ||
| @@ -115,19 +116,18 @@ static int zmbv_me(ZmbvEncContext *c, uint8_t *src, int sstride, uint8_t *prev, · 80 unmodified lines | |||
| 115 | return bv; | 116 | return bv; |
| 116 | } | 117 | } |
| 117 | 118 | ||
| 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) | ||
| 119 | { | 121 | { |
| 120 | ZmbvEncContext * const c = avctx->priv_data; | 122 | ZmbvEncContext * const c = avctx->priv_data; |
| 121 | AVFrame *pict = data; | ||
| 122 | AVFrame * const p = &c->pic; | 123 | AVFrame * const p = &c->pic; |
| 123 | uint8_t *src, *prev; | 124 | uint8_t *src, *prev, *buf; |
| 124 | uint32_t *palptr; | 125 | uint32_t *palptr; |
| 125 | int len = 0; | ||
| 126 | int keyframe, chpal; | 126 | int keyframe, chpal; |
| 127 | int fl; | 127 | int fl; |
| 128 | int work_size = 0; | 128 | int work_size = 0, pkt_size; |
| 129 | int bw, bh; | 129 | int bw, bh; |
| 130 | int i, j; | 130 | int i, j, ret; |
| 131 | 131 | ||
| 132 | keyframe = !c->curfrm; | 132 | keyframe = !c->curfrm; |
| 133 | c->curfrm++; | 133 | c->curfrm++; |
| @@ -138,17 +138,6 @@ static int encode_frame(AVCodecContext *avctx, uint8_t *buf, int buf_size, void · 4 unmodified lines | |||
| 138 | p->key_frame= keyframe; | 138 | p->key_frame= keyframe; |
| 139 | chpal = !keyframe && memcmp(p->data[1], c->pal2, 1024); | 139 | chpal = !keyframe && memcmp(p->data[1], c->pal2, 1024); |
| 140 | 140 | ||
| 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 | } | ||
| 152 | palptr = (uint32_t*)p->data[1]; | 141 | palptr = (uint32_t*)p->data[1]; |
| 153 | src = p->data[0]; | 142 | src = p->data[0]; |
| 154 | prev = c->prev; | 143 | prev = c->prev; |
| @@ -223,6 +212,9 @@ static int encode_frame(AVCodecContext *avctx, uint8_t *buf, int buf_size, void · 68 unmodified lines | |||
| 223 | src += p->linesize[0]; | 212 | src += p->linesize[0]; |
| 224 | } | 213 | } |
| 225 | 214 | ||
| 215 | if (keyframe) | ||
| 216 | deflateReset(&c->zstream); | ||
| 217 | |||
| 226 | c->zstream.next_in = c->work_buf; | 218 | c->zstream.next_in = c->work_buf; |
| 227 | c->zstream.avail_in = work_size; | 219 | c->zstream.avail_in = work_size; |
| 228 | c->zstream.total_in = 0; | 220 | 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 | |||
| 235 | return -1; | 227 | return -1; |
| 236 | } | 228 | } |
| 237 | 229 | ||
| 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 | } | ||
| 238 | memcpy(buf, c->comp_buf, c->zstream.total_out); | 247 | 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; | ||
| 240 | } | 253 | } |
| 241 | 254 | ||
| 242 | 255 | ||
| @@ -329,7 +342,7 @@ AVCodec ff_zmbv_encoder = { · 86 unmodified lines | |||
| 329 | .id = CODEC_ID_ZMBV, | 342 | .id = CODEC_ID_ZMBV, |
| 330 | .priv_data_size = sizeof(ZmbvEncContext), | 343 | .priv_data_size = sizeof(ZmbvEncContext), |
| 331 | .init = encode_init, | 344 | .init = encode_init, |
| 332 | .encode = encode_frame, | 345 | .encode2 = encode_frame, |
| 333 | .close = encode_end, | 346 | .close = encode_end, |
| 334 | .pix_fmts = (const enum PixelFormat[]){PIX_FMT_PAL8, PIX_FMT_NONE}, | 347 | .pix_fmts = (const enum PixelFormat[]){PIX_FMT_PAL8, PIX_FMT_NONE}, |
| 335 | .long_name = NULL_IF_CONFIG_SMALL("Zip Motion Blocks Video"), | 348 | .long_name = NULL_IF_CONFIG_SMALL("Zip Motion Blocks Video"), |
| @@ -547,7 +547,7 @@ static int hls_read_header(AVFormatContext *s) · 546 unmodified lines | |||
| 547 | 547 | ||
| 548 | c->first_packet = 1; | 548 | c->first_packet = 1; |
| 549 | c->first_timestamp = AV_NOPTS_VALUE; | 549 | c->first_timestamp = AV_NOPTS_VALUE; |
| 550 | c->seek_timestamp = AV_NOPTS_VALUE; | 550 | c->seek_timestamp = AV_NOPTS_VALUE; |
| 551 | 551 | ||
| 552 | return 0; | 552 | return 0; |
| 553 | fail: | 553 | fail: |
| @@ -609,16 +609,13 @@ start: · 55 unmodified lines | |||
| 609 | if (var->needed && !var->pkt.data) { | 609 | if (var->needed && !var->pkt.data) { |
| 610 | while (1) { | 610 | while (1) { |
| 611 | int64_t ts_diff; | 611 | int64_t ts_diff; |
| 612 | AVStream *st; | ||
| 612 | ret = av_read_frame(var->ctx, &var->pkt); | 613 | ret = av_read_frame(var->ctx, &var->pkt); |
| 613 | if (ret < 0) { | 614 | if (ret < 0) { |
| 614 | if (!url_feof(&var->pb)) { | 615 | if (!url_feof(&var->pb)) |
| 615 | return ret; | 616 | return ret; |
| 616 | } else { | ||
| 617 | if ((var->cur_seq_no - var->start_seq_no) == (var->n_segments)) { | ||
| 618 | return AVERROR_EOF; | ||
| 619 | } | ||
| 620 | } | ||
| 621 | reset_packet(&var->pkt); | 617 | reset_packet(&var->pkt); |
| 618 | break; | ||
| 622 | } else { | 619 | } else { |
| 623 | if (c->first_timestamp == AV_NOPTS_VALUE) | 620 | if (c->first_timestamp == AV_NOPTS_VALUE) |
| 624 | c->first_timestamp = var->pkt.dts; | 621 | c->first_timestamp = var->pkt.dts; |
| @@ -632,18 +629,14 @@ start: · 7 unmodified lines | |||
| 632 | break; | 629 | break; |
| 633 | } | 630 | } |
| 634 | 631 | ||
| 635 | ts_diff = var->pkt.dts - c->seek_timestamp; | 632 | st = var->ctx->streams[var->pkt.stream_index]; |
| 636 | if (ts_diff >= 0) { | 633 | ts_diff = av_rescale_rnd(var->pkt.dts, AV_TIME_BASE, |
| 637 | if (c->seek_flags & AVSEEK_FLAG_ANY) { | 634 | st->time_base.den, AV_ROUND_DOWN) - |
| 638 | c->seek_timestamp = AV_NOPTS_VALUE; | 635 | c->seek_timestamp; |
| 639 | break; | 636 | if (ts_diff >= 0 && (c->seek_flags & AVSEEK_FLAG_ANY || |
| 640 | } | 637 | var->pkt.flags & AV_PKT_FLAG_KEY)) { |
| 641 | 638 | c->seek_timestamp = AV_NOPTS_VALUE; | |
| 642 | /* Seek to keyframe */ | 639 | break; |
| 643 | if (var->pkt.flags & AV_PKT_FLAG_KEY) { | ||
| 644 | c->seek_timestamp = AV_NOPTS_VALUE; | ||
| 645 | break; | ||
| 646 | } | ||
| 647 | } | 640 | } |
| 648 | } | 641 | } |
| 649 | } | 642 | } |
| @@ -685,8 +678,12 @@ static int hls_read_seek(AVFormatContext *s, int stream_index, · 35 unmodified lines | |||
| 685 | if ((flags & AVSEEK_FLAG_BYTE) || !c->variants[0]->finished) | 678 | if ((flags & AVSEEK_FLAG_BYTE) || !c->variants[0]->finished) |
| 686 | return AVERROR(ENOSYS); | 679 | return AVERROR(ENOSYS); |
| 687 | 680 | ||
| 688 | c->seek_timestamp = timestamp; | 681 | c->seek_flags = flags; |
| 689 | 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); | ||
| 690 | timestamp = av_rescale_rnd(timestamp, 1, stream_index >= 0 ? | 687 | timestamp = av_rescale_rnd(timestamp, 1, stream_index >= 0 ? |
| 691 | s->streams[stream_index]->time_base.den : | 688 | s->streams[stream_index]->time_base.den : |
| 692 | AV_TIME_BASE, flags & AVSEEK_FLAG_BACKWARD ? | 689 | AV_TIME_BASE, flags & AVSEEK_FLAG_BACKWARD ? |
| @@ -712,6 +709,10 @@ static int hls_read_seek(AVFormatContext *s, int stream_index, · 19 unmodified lines | |||
| 712 | av_free_packet(&var->pkt); | 709 | av_free_packet(&var->pkt); |
| 713 | reset_packet(&var->pkt); | 710 | reset_packet(&var->pkt); |
| 714 | var->pb.eof_reached = 0; | 711 | 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; | ||
| 715 | 716 | ||
| 716 | /* Locate the segment that contains the target timestamp */ | 717 | /* Locate the segment that contains the target timestamp */ |
| 717 | for (j = 0; j < var->n_segments; j++) { | 718 | 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 | |||
| 723 | } | 724 | } |
| 724 | pos += var->segments[j]->duration; | 725 | pos += var->segments[j]->duration; |
| 725 | } | 726 | } |
| 726 | if (ret != 0) | 727 | if (ret) |
| 727 | c->seek_timestamp = AV_NOPTS_VALUE; | 728 | c->seek_timestamp = AV_NOPTS_VALUE; |
| 728 | } | 729 | } |
| 729 | return ret; | 730 | return ret; |
| @@ -942,11 +942,10 @@ static void compute_pkt_fields(AVFormatContext *s, AVStream *st, · 941 unmodified lines | |||
| 942 | compute_frame_duration(&num, &den, st, pc, pkt); | 942 | compute_frame_duration(&num, &den, st, pc, pkt); |
| 943 | if (den && num) { | 943 | if (den && num) { |
| 944 | pkt->duration = av_rescale_rnd(1, num * (int64_t)st->time_base.den, den * (int64_t)st->time_base.num, AV_ROUND_DOWN); | 944 | 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); | ||
| 948 | } | 945 | } |
| 949 | } | 946 | } |
| 947 | if(pkt->duration != 0 && s->packet_buffer) | ||
| 948 | update_initial_durations(s, st, pkt); | ||
| 950 | 949 | ||
| 951 | /* correct timestamps with byte offset if demuxers only have timestamps | 950 | /* correct timestamps with byte offset if demuxers only have timestamps |
| 952 | on packet boundaries */ | 951 | on packet boundaries */ |
| @@ -1099,6 +1098,20 @@ static int read_frame_internal(AVFormatContext *s, AVPacket *pkt) · 146 unmodified lines | |||
| 1099 | if (pkt->size) { | 1098 | if (pkt->size) { |
| 1100 | got_packet: | 1099 | got_packet: |
| 1101 | pkt->duration = 0; | 1100 | 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 | } | ||
| 1102 | pkt->stream_index = st->index; | 1115 | pkt->stream_index = st->index; |
| 1103 | pkt->pts = st->parser->pts; | 1116 | pkt->pts = st->parser->pts; |
| 1104 | pkt->dts = st->parser->dts; | 1117 | pkt->dts = st->parser->dts; |
| @@ -154,7 +154,7 @@ · 153 unmodified lines | |||
| 154 | */ | 154 | */ |
| 155 | 155 | ||
| 156 | #define LIBAVUTIL_VERSION_MAJOR 51 | 156 | #define LIBAVUTIL_VERSION_MAJOR 51 |
| 157 | #define LIBAVUTIL_VERSION_MINOR 39 | 157 | #define LIBAVUTIL_VERSION_MINOR 40 |
| 158 | #define LIBAVUTIL_VERSION_MICRO 100 | 158 | #define LIBAVUTIL_VERSION_MICRO 100 |
| 159 | 159 | ||
| 160 | #define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \ | 160 | #define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \ |
| @@ -131,10 +131,17 @@ int64_t av_rescale(int64_t a, int64_t b, int64_t c){ · 130 unmodified lines | |||
| 131 | return av_rescale_rnd(a, b, c, AV_ROUND_NEAR_INF); | 131 | return av_rescale_rnd(a, b, c, AV_ROUND_NEAR_INF); |
| 132 | } | 132 | } |
| 133 | 133 | ||
| 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 | { | ||
| 135 | int64_t b= bq.num * (int64_t)cq.den; | 137 | int64_t b= bq.num * (int64_t)cq.den; |
| 136 | int64_t c= cq.num * (int64_t)bq.den; | 138 | 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); | ||
| 138 | } | 145 | } |
| 139 | 146 | ||
| 140 | int av_compare_ts(int64_t ts_a, AVRational tb_a, int64_t ts_b, AVRational tb_b){ | 147 | int av_compare_ts(int64_t ts_a, AVRational tb_a, int64_t ts_b, AVRational tb_b){ |
| @@ -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 | |||
| 95 | */ | 95 | */ |
| 96 | int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq) av_const; | 96 | int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq) av_const; |
| 97 | 97 | ||
| 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 | |||
| 98 | /** | 104 | /** |
| 99 | * Compare 2 timestamps each in its own timebases. | 105 | * Compare 2 timestamps each in its own timebases. |
| 100 | * The result of the function is undefined if one of the timestamps | 106 | * The result of the function is undefined if one of the timestamps |
| @@ -358,10 +358,11 @@ typedef struct SwsContext { · 357 unmodified lines | |||
| 358 | #define U_TEMP "11*8+4*4*256*2+24" | 358 | #define U_TEMP "11*8+4*4*256*2+24" |
| 359 | #define V_TEMP "11*8+4*4*256*2+32" | 359 | #define V_TEMP "11*8+4*4*256*2+32" |
| 360 | #define Y_TEMP "11*8+4*4*256*2+40" | 360 | #define Y_TEMP "11*8+4*4*256*2+40" |
| 361 | #define UV_OFF_PX "11*8+4*4*256*2+48" | 361 | #define ALP_MMX_FILTER_OFFSET "11*8+4*4*256*2+48" |
| 362 | #define UV_OFF_BYTE "11*8+4*4*256*2+56" | 362 | #define UV_OFF_PX "11*8+4*4*256*3+48" |
| 363 | #define DITHER16 "11*8+4*4*256*2+64" | 363 | #define UV_OFF_BYTE "11*8+4*4*256*3+56" |
| 364 | #define DITHER32 "11*8+4*4*256*2+80" | 364 | #define DITHER16 "11*8+4*4*256*3+64" |
| 365 | #define DITHER32 "11*8+4*4*256*3+80" | ||
| 365 | 366 | ||
| 366 | DECLARE_ALIGNED(8, uint64_t, redDither); | 367 | DECLARE_ALIGNED(8, uint64_t, redDither); |
| 367 | DECLARE_ALIGNED(8, uint64_t, greenDither); | 368 | DECLARE_ALIGNED(8, uint64_t, greenDither); |
| @@ -383,6 +384,7 @@ typedef struct SwsContext { · 15 unmodified lines | |||
| 383 | DECLARE_ALIGNED(8, uint64_t, u_temp); | 384 | DECLARE_ALIGNED(8, uint64_t, u_temp); |
| 384 | DECLARE_ALIGNED(8, uint64_t, v_temp); | 385 | DECLARE_ALIGNED(8, uint64_t, v_temp); |
| 385 | DECLARE_ALIGNED(8, uint64_t, y_temp); | 386 | DECLARE_ALIGNED(8, uint64_t, y_temp); |
| 387 | int32_t alpMmxFilter[4 * MAX_FILTER_SIZE]; | ||
| 386 | // alignment of these values is not necessary, but merely here | 388 | // alignment of these values is not necessary, but merely here |
| 387 | // to maintain the same offset across x8632 and x86-64. Once we | 389 | // to maintain the same offset across x8632 and x86-64. Once we |
| 388 | // use proper offset macros in the asm, they can be removed. | 390 | // use proper offset macros in the asm, they can be removed. |
| @@ -421,7 +423,6 @@ typedef struct SwsContext { · 32 unmodified lines | |||
| 421 | #if HAVE_VIS | 423 | #if HAVE_VIS |
| 422 | DECLARE_ALIGNED(8, uint64_t, sparc_coeffs)[10]; | 424 | DECLARE_ALIGNED(8, uint64_t, sparc_coeffs)[10]; |
| 423 | #endif | 425 | #endif |
| 424 | int32_t alpMmxFilter[4 * MAX_FILTER_SIZE]; | ||
| 425 | int use_mmx_vfilter; | 426 | int use_mmx_vfilter; |
| 426 | 427 | ||
| 427 | /* function pointers for swScale() */ | 428 | /* function pointers for swScale() */ |
| @@ -342,7 +342,7 @@ static void RENAME(yuv2rgb32_X_ar)(SwsContext *c, const int16_t *lumFilter, · 341 unmodified lines | |||
| 342 | "movq %%mm2, "U_TEMP"(%0) \n\t" | 342 | "movq %%mm2, "U_TEMP"(%0) \n\t" |
| 343 | "movq %%mm4, "V_TEMP"(%0) \n\t" | 343 | "movq %%mm4, "V_TEMP"(%0) \n\t" |
| 344 | "movq %%mm5, "Y_TEMP"(%0) \n\t" | 344 | "movq %%mm5, "Y_TEMP"(%0) \n\t" |
| 345 | YSCALEYUV2PACKEDX_ACCURATE_YA(LUM_MMX_FILTER_OFFSET) | 345 | YSCALEYUV2PACKEDX_ACCURATE_YA(ALP_MMX_FILTER_OFFSET) |
| 346 | "movq "Y_TEMP"(%0), %%mm5 \n\t" | 346 | "movq "Y_TEMP"(%0), %%mm5 \n\t" |
| 347 | "psraw $3, %%mm1 \n\t" | 347 | "psraw $3, %%mm1 \n\t" |
| 348 | "psraw $3, %%mm7 \n\t" | 348 | "psraw $3, %%mm7 \n\t" |
| @@ -372,7 +372,7 @@ static void RENAME(yuv2rgb32_X)(SwsContext *c, const int16_t *lumFilter, · 23 unmodified lines | |||
| 372 | if (CONFIG_SWSCALE_ALPHA && c->alpPixBuf) { | 372 | if (CONFIG_SWSCALE_ALPHA && c->alpPixBuf) { |
| 373 | YSCALEYUV2PACKEDX | 373 | YSCALEYUV2PACKEDX |
| 374 | YSCALEYUV2RGBX | 374 | 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) |
| 376 | "psraw $3, %%mm1 \n\t" | 376 | "psraw $3, %%mm1 \n\t" |
| 377 | "psraw $3, %%mm7 \n\t" | 377 | "psraw $3, %%mm7 \n\t" |
| 378 | "packuswb %%mm7, %%mm1 \n\t" | 378 | "packuswb %%mm7, %%mm1 \n\t" |
| @@ -1,4 +1,4 @@ | |||
| 1 | 006f8dc92eb4f7bab82eded314ca1124 *./tests/data/acodec/adpcm_yam.wav | 1 | e9c14f701d25947317db9367b9dc772d *./tests/data/acodec/adpcm_yam.wav |
| 2 | 266298 ./tests/data/acodec/adpcm_yam.wav | 2 | 265274 ./tests/data/acodec/adpcm_yam.wav |
| 3 | c36a9d5a1e0ad57fbe9665a31373b7c1 *./tests/data/adpcm_yam.acodec.out.wav | 3 | 1488b5974fa040a65f0d407fc0224c6a *./tests/data/adpcm_yam.acodec.out.wav |
| 4 | stddev: 1247.60 PSNR: 34.41 MAXDIFF:39895 bytes: 1064960/ 1058400 | 4 | stddev: 1247.60 PSNR: 34.41 MAXDIFF:39895 bytes: 1060864/ 1058400 |