[FFmpeg-cvslog] flashsv2enc: switch to encode2()

Michael Niedermayer git at videolan.org
Fri Feb 24 04:35:04 CET 2012


ffmpeg | branch: master | Michael Niedermayer <michaelni at gmx.at> | Fri Feb 24 03:30:42 2012 +0100| [131698af55bef251f07e8f7499213001515458ef] | committer: Michael Niedermayer

flashsv2enc: switch to encode2()

Signed-off-by: Michael Niedermayer <michaelni at gmx.at>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=131698af55bef251f07e8f7499213001515458ef
---

 libavcodec/flashsv2enc.c |   27 +++++++++++++++------------
 1 files changed, 15 insertions(+), 12 deletions(-)

diff --git a/libavcodec/flashsv2enc.c b/libavcodec/flashsv2enc.c
index 6466be7..8efdb46 100644
--- a/libavcodec/flashsv2enc.c
+++ b/libavcodec/flashsv2enc.c
@@ -823,17 +823,22 @@ static int reconfigure_at_keyframe(FlashSV2Context * s, const uint8_t * image,
     return 0;
 }
 
-static int flashsv2_encode_frame(AVCodecContext * avctx, uint8_t * buf,
-                                 int buf_size, void *data)
+static int flashsv2_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
+                                 const AVFrame *pict, int *got_packet)
 {
     FlashSV2Context *const s = avctx->priv_data;
-    AVFrame *pict = data;
     AVFrame *const p = &s->frame;
     int res;
     int keyframe = 0;
 
     *p = *pict;
 
+    if (!pkt->data &&
+        (res = av_new_packet(pkt, s->frame_size + FF_MIN_BUFFER_SIZE)) < 0) {
+        av_log(avctx, AV_LOG_ERROR, "Error getting output packet.\n");
+        return res;
+    }
+
     /* First frame needs to be a keyframe */
     if (avctx->frame_number == 0)
         keyframe = 1;
@@ -844,12 +849,6 @@ static int flashsv2_encode_frame(AVCodecContext * avctx, uint8_t * buf,
             keyframe = 1;
     }
 
-    if (buf_size < s->frame_size) {
-        //Conservative upper bound check for compressed data
-        av_log(avctx, AV_LOG_ERROR, "buf_size %d <  %d\n", buf_size, s->frame_size);
-        return -1;
-    }
-
     if (!keyframe
         && avctx->frame_number > s->last_key_frame + avctx->keyint_min) {
         recommend_keyframe(s, &keyframe);
@@ -866,13 +865,14 @@ static int flashsv2_encode_frame(AVCodecContext * avctx, uint8_t * buf,
     if (s->use15_7)
         s->dist = optimum_dist(s);
 
-    res = write_bitstream(s, p->data[0], p->linesize[0], buf, buf_size, keyframe);
+    res = write_bitstream(s, p->data[0], p->linesize[0], pkt->data, pkt->size, keyframe);
 
     if (keyframe) {
         new_key_frame(s);
         p->pict_type = AV_PICTURE_TYPE_I;
         p->key_frame = 1;
         s->last_key_frame = avctx->frame_number;
+        pkt->flags |= AV_PKT_FLAG_KEY;
         av_log(avctx, AV_LOG_DEBUG, "Inserting key frame at frame %d\n", avctx->frame_number);
     } else {
         p->pict_type = AV_PICTURE_TYPE_P;
@@ -881,7 +881,10 @@ static int flashsv2_encode_frame(AVCodecContext * avctx, uint8_t * buf,
 
     avctx->coded_frame = p;
 
-    return res;
+    pkt->size = res;
+    *got_packet = 1;
+
+    return 0;
 }
 
 static av_cold int flashsv2_encode_end(AVCodecContext * avctx)
@@ -899,7 +902,7 @@ AVCodec ff_flashsv2_encoder = {
     .id             = CODEC_ID_FLASHSV2,
     .priv_data_size = sizeof(FlashSV2Context),
     .init           = flashsv2_encode_init,
-    .encode         = flashsv2_encode_frame,
+    .encode2        = flashsv2_encode_frame,
     .close          = flashsv2_encode_end,
     .pix_fmts = (enum PixelFormat[]) {PIX_FMT_BGR24, PIX_FMT_NONE},
     .long_name = NULL_IF_CONFIG_SMALL("Flash Screen Video Version 2"),



More information about the ffmpeg-cvslog mailing list