summaryrefslogtreecommitdiff
path: root/libavcodec/a64multienc.c
diff options
context:
space:
mode:
authorMichael Niedermayer <michaelni@gmx.at>2012-02-24 02:57:18 +0100
committerMichael Niedermayer <michaelni@gmx.at>2012-02-24 02:57:18 +0100
commite2cc39b6096ed4353293252e3955417b7766f161 (patch)
tree0bc4d98c120dedcffb9b6e50943b4fc9e3c2a877 /libavcodec/a64multienc.c
parent32e74395a8e88dee1c149aeb36e7a21df431c181 (diff)
parent31632e73f47d25e2077fce729571259ee6354854 (diff)
Merge remote-tracking branch 'qatar/master'
* qatar/master: (40 commits) swf: check return values for av_get/new_packet(). wavpack: Don't shift minclip/maxclip rtpenc: Expose the max packet size via an avoption rtpenc: Move max_packet_size to a context variable rtpenc: Add an option for not sending RTCP packets lavc: drop encode() support for video. snowenc: switch to encode2(). snowenc: don't abuse input picture for storing information. a64multienc: switch to encode2(). a64multienc: don't write into output buffer when there's no output. libxvid: switch to encode2(). tiffenc: switch to encode2(). tiffenc: properly forward error codes in encode_frame(). lavc: drop libdirac encoder. gifenc: switch to encode2(). libvpxenc: switch to encode2(). flashsvenc: switch to encode2(). Remove libpostproc. lcl: don't overwrite input memory. swscale: take first/lastline over/underflows into account for MMX. ... Conflicts: .gitignore Makefile cmdutils.c configure doc/APIchanges libavcodec/Makefile libavcodec/allcodecs.c libavcodec/libdiracenc.c libavcodec/libxvidff.c libavcodec/qtrleenc.c libavcodec/tiffenc.c libavcodec/utils.c libavformat/mov.c libavformat/movenc.c libpostproc/Makefile libpostproc/postprocess.c libpostproc/postprocess.h libpostproc/postprocess_altivec_template.c libpostproc/postprocess_internal.h libpostproc/postprocess_template.c libswscale/swscale.c libswscale/utils.c Merged-by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'libavcodec/a64multienc.c')
-rw-r--r--libavcodec/a64multienc.c42
1 files changed, 26 insertions, 16 deletions
diff --git a/libavcodec/a64multienc.c b/libavcodec/a64multienc.c
index 5a665d0592..ed8dde552c 100644
--- a/libavcodec/a64multienc.c
+++ b/libavcodec/a64multienc.c
@@ -28,6 +28,7 @@
#include "a64colors.h"
#include "a64tables.h"
#include "elbg.h"
+#include "internal.h"
#include "libavutil/intreadwrite.h"
#define DITHERSTEPS 8
@@ -221,6 +222,8 @@ static av_cold int a64multi_init_encoder(AVCodecContext *avctx)
if (!avctx->codec_tag)
avctx->codec_tag = AV_RL32("a64m");
+ c->next_pts = AV_NOPTS_VALUE;
+
return 0;
}
@@ -239,11 +242,10 @@ static void a64_compress_colram(unsigned char *buf, int *charmap, uint8_t *colra
}
}
-static int a64multi_encode_frame(AVCodecContext *avctx, unsigned char *buf,
- int buf_size, void *data)
+static int a64multi_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
+ const AVFrame *pict, int *got_packet)
{
A64Context *c = avctx->priv_data;
- AVFrame *pict = data;
AVFrame *const p = (AVFrame *) & c->picture;
int frame;
@@ -251,7 +253,8 @@ static int a64multi_encode_frame(AVCodecContext *avctx, unsigned char *buf,
int b_height;
int b_width;
- int req_size;
+ int req_size, ret;
+ uint8_t *buf;
int *charmap = c->mc_charmap;
uint8_t *colram = c->mc_colram;
@@ -274,7 +277,7 @@ static int a64multi_encode_frame(AVCodecContext *avctx, unsigned char *buf,
}
/* no data, means end encoding asap */
- if (!data) {
+ if (!pict) {
/* all done, end encoding */
if (!c->mc_lifetime) return 0;
/* no more frames in queue, prepare to flush remaining frames */
@@ -292,6 +295,8 @@ static int a64multi_encode_frame(AVCodecContext *avctx, unsigned char *buf,
p->key_frame = 1;
to_meta_with_crop(avctx, p, meta + 32000 * c->mc_frame_counter);
c->mc_frame_counter++;
+ if (c->next_pts == AV_NOPTS_VALUE)
+ c->next_pts = pict->pts;
/* lifetime is not reached so wait for next frame first */
return 0;
}
@@ -302,6 +307,13 @@ static int a64multi_encode_frame(AVCodecContext *avctx, unsigned char *buf,
req_size = 0;
/* any frames to encode? */
if (c->mc_lifetime) {
+ req_size = charset_size + c->mc_lifetime*(screen_size + colram_size);
+ if ((ret = ff_alloc_packet(pkt, req_size)) < 0) {
+ av_log(avctx, AV_LOG_ERROR, "Error getting output packet of size %d.\n", req_size);
+ return ret;
+ }
+ buf = pkt->data;
+
/* calc optimal new charset + charmaps */
ff_init_elbg(meta, 32, 1000 * c->mc_lifetime, best_cb, CHARSET_CHARS, 50, charmap, &c->randctx);
ff_do_elbg (meta, 32, 1000 * c->mc_lifetime, best_cb, CHARSET_CHARS, 50, charmap, &c->randctx);
@@ -310,15 +322,12 @@ static int a64multi_encode_frame(AVCodecContext *avctx, unsigned char *buf,
render_charset(avctx, charset, colram);
/* copy charset to buf */
- memcpy(buf,charset, charset_size);
+ memcpy(buf, charset, charset_size);
/* advance pointers */
buf += charset_size;
charset += charset_size;
- req_size += charset_size;
}
- /* no charset so clean buf */
- else memset(buf, 0, charset_size);
/* write x frames to buf */
for (frame = 0; frame < c->mc_lifetime; frame++) {
@@ -351,11 +360,12 @@ static int a64multi_encode_frame(AVCodecContext *avctx, unsigned char *buf,
/* reset counter */
c->mc_frame_counter = 0;
- if (req_size > buf_size) {
- av_log(avctx, AV_LOG_ERROR, "buf size too small (need %d, got %d)\n", req_size, buf_size);
- return -1;
- }
- return req_size;
+ pkt->pts = pkt->dts = c->next_pts;
+ c->next_pts = AV_NOPTS_VALUE;
+
+ pkt->size = req_size;
+ pkt->flags |= AV_PKT_FLAG_KEY;
+ *got_packet = !!req_size;
}
return 0;
}
@@ -366,7 +376,7 @@ AVCodec ff_a64multi_encoder = {
.id = CODEC_ID_A64_MULTI,
.priv_data_size = sizeof(A64Context),
.init = a64multi_init_encoder,
- .encode = a64multi_encode_frame,
+ .encode2 = a64multi_encode_frame,
.close = a64multi_close_encoder,
.pix_fmts = (const enum PixelFormat[]) {PIX_FMT_GRAY8, PIX_FMT_NONE},
.long_name = NULL_IF_CONFIG_SMALL("Multicolor charset for Commodore 64"),
@@ -379,7 +389,7 @@ AVCodec ff_a64multi5_encoder = {
.id = CODEC_ID_A64_MULTI5,
.priv_data_size = sizeof(A64Context),
.init = a64multi_init_encoder,
- .encode = a64multi_encode_frame,
+ .encode2 = a64multi_encode_frame,
.close = a64multi_close_encoder,
.pix_fmts = (const enum PixelFormat[]) {PIX_FMT_GRAY8, PIX_FMT_NONE},
.long_name = NULL_IF_CONFIG_SMALL("Multicolor charset for Commodore 64, extended with 5th color (colram)"),