vaapi_encode: Write sequence header as extradata
authorMark Thompson <sw@jkqxz.net>
Sun, 2 Oct 2016 07:48:34 +0000 (08:48 +0100)
committerMark Thompson <sw@jkqxz.net>
Mon, 17 Oct 2016 20:07:25 +0000 (21:07 +0100)
Only works if packed headers are supported, where we can know the
output before generating the first frame.

libavcodec/vaapi_encode.c
libavcodec/vaapi_encode.h

index b600a00..11e46ea 100644 (file)
@@ -1399,6 +1399,28 @@ av_cold int ff_vaapi_encode_init(AVCodecContext *avctx)
     // where it actually overlaps properly, though.)
     ctx->issue_mode = ISSUE_MODE_MAXIMISE_THROUGHPUT;
 
     // where it actually overlaps properly, though.)
     ctx->issue_mode = ISSUE_MODE_MAXIMISE_THROUGHPUT;
 
+    if (ctx->va_packed_headers & VA_ENC_PACKED_HEADER_SEQUENCE &&
+        ctx->codec->write_sequence_header) {
+        char data[MAX_PARAM_BUFFER_SIZE];
+        size_t bit_len = 8 * sizeof(data);
+
+        err = ctx->codec->write_sequence_header(avctx, data, &bit_len);
+        if (err < 0) {
+            av_log(avctx, AV_LOG_ERROR, "Failed to write sequence header "
+                   "for extradata: %d.\n", err);
+            goto fail;
+        } else {
+            avctx->extradata_size = (bit_len + 7) / 8;
+            avctx->extradata = av_mallocz(avctx->extradata_size +
+                                          AV_INPUT_BUFFER_PADDING_SIZE);
+            if (!avctx->extradata) {
+                err = AVERROR(ENOMEM);
+                goto fail;
+            }
+            memcpy(avctx->extradata, data, avctx->extradata_size);
+        }
+    }
+
     return 0;
 
 fail:
     return 0;
 
 fail:
index c47d979..a9ab527 100644 (file)
@@ -235,6 +235,8 @@ typedef struct VAAPIEncodeType {
     int slice_header_type;
 
     // Write the packed header data to the provided buffer.
     int slice_header_type;
 
     // Write the packed header data to the provided buffer.
+    // The sequence header is also used to fill the codec extradata
+    // when the encoder is starting.
     int (*write_sequence_header)(AVCodecContext *avctx,
                                  char *data, size_t *data_len);
     int  (*write_picture_header)(AVCodecContext *avctx,
     int (*write_sequence_header)(AVCodecContext *avctx,
                                  char *data, size_t *data_len);
     int  (*write_picture_header)(AVCodecContext *avctx,