Merge commit '44c9f374f188f92927b7a4aad2101289d446b814'

* commit '44c9f374f188f92927b7a4aad2101289d446b814':
  examples/qsvdec: convert to the new decoding API

Merged-by: Clément Bœsch <u@pkh.me>
This commit is contained in:
Clément Bœsch 2017-04-03 21:10:07 +02:00
commit 54e195cf52
1 changed files with 25 additions and 23 deletions

View File

@ -92,24 +92,27 @@ static int decode_packet(DecodeContext *decode, AVCodecContext *decoder_ctx,
AVPacket *pkt, AVIOContext *output_ctx)
{
int ret = 0;
int got_frame = 1;
while (pkt->size > 0 || (!pkt->data && got_frame)) {
ret = avcodec_decode_video2(decoder_ctx, frame, &got_frame, pkt);
ret = avcodec_send_packet(decoder_ctx, pkt);
if (ret < 0) {
fprintf(stderr, "Error during decoding\n");
return ret;
}
pkt->data += ret;
pkt->size -= ret;
while (ret >= 0) {
int i, j;
ret = avcodec_receive_frame(decoder_ctx, frame);
if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF)
break;
else if (ret < 0) {
fprintf(stderr, "Error during decoding\n");
return ret;
}
/* A real program would do something useful with the decoded frame here.
* We just retrieve the raw data and write it to a file, which is rather
* useless but pedagogic. */
if (got_frame) {
int i, j;
ret = av_hwframe_transfer_data(sw_frame, frame, 0);
if (ret < 0) {
fprintf(stderr, "Error transferring the data to system memory\n");
@ -127,7 +130,6 @@ fail:
if (ret < 0)
return ret;
}
}
return 0;
}