[FFmpeg-cvslog] qsvenc: store the sync point in heap memory
Maxym Dmytrychenko
git at videolan.org
Mon Apr 11 15:46:41 CEST 2016
ffmpeg | branch: master | Maxym Dmytrychenko <maxym.dmytrychenko at intel.com> | Mon Feb 22 10:39:02 2016 +0100| [a1335149fd610b16459d9281b611282cac51c950] | committer: Anton Khirnov
qsvenc: store the sync point in heap memory
The QSV runtime expects the sync point address passed to
MFXVideoENCODE_EncodeFrameAsync() to be valid until
MFXVideoCORE_SyncOperation().
Signed-off-by: Anton Khirnov <anton at khirnov.net>
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=a1335149fd610b16459d9281b611282cac51c950
---
libavcodec/qsvenc.c | 25 ++++++++++++++++++-------
1 file changed, 18 insertions(+), 7 deletions(-)
diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c
index 453301c..473a180 100644
--- a/libavcodec/qsvenc.c
+++ b/libavcodec/qsvenc.c
@@ -662,7 +662,7 @@ int ff_qsv_enc_init(AVCodecContext *avctx, QSVEncContext *q)
q->param.AsyncDepth = q->async_depth;
q->async_fifo = av_fifo_alloc((1 + q->async_depth) *
- (sizeof(AVPacket) + sizeof(mfxSyncPoint) + sizeof(mfxBitstream*)));
+ (sizeof(AVPacket) + sizeof(mfxSyncPoint*) + sizeof(mfxBitstream*)));
if (!q->async_fifo)
return AVERROR(ENOMEM);
@@ -876,7 +876,7 @@ static int encode_frame(AVCodecContext *avctx, QSVEncContext *q,
mfxBitstream *bs;
mfxFrameSurface1 *surf = NULL;
- mfxSyncPoint sync = NULL;
+ mfxSyncPoint *sync = NULL;
int ret;
if (frame) {
@@ -901,8 +901,15 @@ static int encode_frame(AVCodecContext *avctx, QSVEncContext *q,
bs->Data = new_pkt.data;
bs->MaxLength = new_pkt.size;
+ sync = av_mallocz(sizeof(*sync));
+ if (!sync) {
+ av_freep(&bs);
+ av_packet_unref(&new_pkt);
+ return AVERROR(ENOMEM);
+ }
+
do {
- ret = MFXVideoENCODE_EncodeFrameAsync(q->session, NULL, surf, bs, &sync);
+ ret = MFXVideoENCODE_EncodeFrameAsync(q->session, NULL, surf, bs, sync);
if (ret == MFX_WRN_DEVICE_BUSY)
av_usleep(1);
} while (ret > 0);
@@ -910,17 +917,19 @@ static int encode_frame(AVCodecContext *avctx, QSVEncContext *q,
if (ret < 0) {
av_packet_unref(&new_pkt);
av_freep(&bs);
+ av_freep(&sync);
return (ret == MFX_ERR_MORE_DATA) ? 0 : ff_qsv_error(ret);
}
if (ret == MFX_WRN_INCOMPATIBLE_VIDEO_PARAM && frame->interlaced_frame)
print_interlace_msg(avctx, q);
- if (sync) {
+ if (*sync) {
av_fifo_generic_write(q->async_fifo, &new_pkt, sizeof(new_pkt), NULL);
av_fifo_generic_write(q->async_fifo, &sync, sizeof(sync), NULL);
av_fifo_generic_write(q->async_fifo, &bs, sizeof(bs), NULL);
} else {
+ av_freep(&sync);
av_packet_unref(&new_pkt);
av_freep(&bs);
}
@@ -941,14 +950,14 @@ int ff_qsv_encode(AVCodecContext *avctx, QSVEncContext *q,
(!frame && av_fifo_size(q->async_fifo))) {
AVPacket new_pkt;
mfxBitstream *bs;
- mfxSyncPoint sync;
+ mfxSyncPoint *sync;
av_fifo_generic_read(q->async_fifo, &new_pkt, sizeof(new_pkt), NULL);
av_fifo_generic_read(q->async_fifo, &sync, sizeof(sync), NULL);
av_fifo_generic_read(q->async_fifo, &bs, sizeof(bs), NULL);
do {
- ret = MFXVideoCORE_SyncOperation(q->session, sync, 1000);
+ ret = MFXVideoCORE_SyncOperation(q->session, *sync, 1000);
} while (ret == MFX_WRN_IN_EXECUTION);
new_pkt.dts = av_rescale_q(bs->DecodeTimeStamp, (AVRational){1, 90000}, avctx->time_base);
@@ -971,6 +980,7 @@ FF_ENABLE_DEPRECATION_WARNINGS
#endif
av_freep(&bs);
+ av_freep(&sync);
if (pkt->data) {
if (pkt->size < new_pkt.size) {
@@ -1017,13 +1027,14 @@ int ff_qsv_enc_close(AVCodecContext *avctx, QSVEncContext *q)
while (q->async_fifo && av_fifo_size(q->async_fifo)) {
AVPacket pkt;
- mfxSyncPoint sync;
+ mfxSyncPoint *sync;
mfxBitstream *bs;
av_fifo_generic_read(q->async_fifo, &pkt, sizeof(pkt), NULL);
av_fifo_generic_read(q->async_fifo, &sync, sizeof(sync), NULL);
av_fifo_generic_read(q->async_fifo, &bs, sizeof(bs), NULL);
+ av_freep(&sync);
av_freep(&bs);
av_packet_unref(&pkt);
}
More information about the ffmpeg-cvslog
mailing list