Commit acc155ac authored by Derek Buitenhuis's avatar Derek Buitenhuis

Merge commit 'a1335149'

* commit 'a1335149':
  qsvenc: store the sync point in heap memory
Merged-by: 's avatarDerek Buitenhuis <derek.buitenhuis@gmail.com>
parents 8cae006c a1335149
......@@ -682,7 +682,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);
......@@ -926,7 +926,7 @@ static int encode_frame(AVCodecContext *avctx, QSVEncContext *q,
mfxBitstream *bs;
mfxFrameSurface1 *surf = NULL;
mfxSyncPoint sync = NULL;
mfxSyncPoint *sync = NULL;
QSVFrame *qsv_frame = NULL;
mfxEncodeCtrl* enc_ctrl = NULL;
int ret;
......@@ -961,8 +961,15 @@ static int encode_frame(AVCodecContext *avctx, QSVEncContext *q,
q->set_encode_ctrl_cb(avctx, frame, &qsv_frame->enc_ctrl);
}
sync = av_mallocz(sizeof(*sync));
if (!sync) {
av_freep(&bs);
av_packet_unref(&new_pkt);
return AVERROR(ENOMEM);
}
do {
ret = MFXVideoENCODE_EncodeFrameAsync(q->session, enc_ctrl, surf, bs, &sync);
ret = MFXVideoENCODE_EncodeFrameAsync(q->session, enc_ctrl, surf, bs, sync);
if (ret == MFX_WRN_DEVICE_BUSY) {
av_usleep(500);
continue;
......@@ -991,6 +998,7 @@ static int encode_frame(AVCodecContext *avctx, QSVEncContext *q,
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);
}
......@@ -1011,14 +1019,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);
......@@ -1041,6 +1049,7 @@ FF_ENABLE_DEPRECATION_WARNINGS
#endif
av_freep(&bs);
av_freep(&sync);
if (pkt->data) {
if (pkt->size < new_pkt.size) {
......@@ -1087,13 +1096,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);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment