mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2025-01-08 13:22:53 +02:00
api-seek-test: use non-obsolete decoding API
This commit is contained in:
parent
88e098029d
commit
bb2651a921
@ -73,16 +73,14 @@ static int compare_crc_in_array(uint32_t crc, int64_t pts)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int compute_crc_of_packets(AVFormatContext *fmt_ctx, int video_stream,
|
static int compute_crc_of_packets(AVFormatContext *fmt_ctx, int video_stream,
|
||||||
AVCodecContext *ctx, AVFrame *fr, uint64_t ts_start, uint64_t ts_end, int no_seeking)
|
AVCodecContext *ctx, AVPacket *pkt, AVFrame *fr,
|
||||||
|
uint64_t ts_start, uint64_t ts_end, int no_seeking)
|
||||||
{
|
{
|
||||||
int number_of_written_bytes;
|
int number_of_written_bytes;
|
||||||
int got_frame = 0;
|
|
||||||
int result;
|
int result;
|
||||||
int end_of_stream = 0;
|
|
||||||
int byte_buffer_size;
|
int byte_buffer_size;
|
||||||
uint8_t *byte_buffer;
|
uint8_t *byte_buffer;
|
||||||
uint32_t crc;
|
uint32_t crc;
|
||||||
AVPacket pkt;
|
|
||||||
|
|
||||||
byte_buffer_size = av_image_get_buffer_size(ctx->pix_fmt, ctx->width, ctx->height, 16);
|
byte_buffer_size = av_image_get_buffer_size(ctx->pix_fmt, ctx->width, ctx->height, 16);
|
||||||
byte_buffer = av_malloc(byte_buffer_size);
|
byte_buffer = av_malloc(byte_buffer_size);
|
||||||
@ -101,27 +99,42 @@ static int compute_crc_of_packets(AVFormatContext *fmt_ctx, int video_stream,
|
|||||||
avcodec_flush_buffers(ctx);
|
avcodec_flush_buffers(ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
av_init_packet(&pkt);
|
|
||||||
do {
|
do {
|
||||||
if (!end_of_stream)
|
result = av_read_frame(fmt_ctx, pkt);
|
||||||
if (av_read_frame(fmt_ctx, &pkt) < 0)
|
if (result >= 0 && pkt->stream_index != video_stream) {
|
||||||
end_of_stream = 1;
|
av_packet_unref(pkt);
|
||||||
if (end_of_stream) {
|
continue;
|
||||||
pkt.data = NULL;
|
|
||||||
pkt.size = 0;
|
|
||||||
}
|
}
|
||||||
if (pkt.stream_index == video_stream || end_of_stream) {
|
|
||||||
got_frame = 0;
|
if (result < 0)
|
||||||
if ((pkt.pts == AV_NOPTS_VALUE) && (!end_of_stream)) {
|
result = avcodec_send_packet(ctx, NULL);
|
||||||
|
else {
|
||||||
|
if (pkt->pts == AV_NOPTS_VALUE) {
|
||||||
av_log(NULL, AV_LOG_ERROR, "Error: frames doesn't have pts values\n");
|
av_log(NULL, AV_LOG_ERROR, "Error: frames doesn't have pts values\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
result = avcodec_decode_video2(ctx, fr, &got_frame, &pkt);
|
result = avcodec_send_packet(ctx, pkt);
|
||||||
|
}
|
||||||
|
|
||||||
|
av_packet_unref(pkt);
|
||||||
|
|
||||||
if (result < 0) {
|
if (result < 0) {
|
||||||
|
av_log(NULL, AV_LOG_ERROR, "Error submitting a packet for decoding\n");
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
while (result >= 0) {
|
||||||
|
result = avcodec_receive_frame(ctx, fr);
|
||||||
|
if (result == AVERROR_EOF)
|
||||||
|
goto finish;
|
||||||
|
else if (result == AVERROR(EAGAIN)) {
|
||||||
|
result = 0;
|
||||||
|
break;
|
||||||
|
} else if (result < 0) {
|
||||||
av_log(NULL, AV_LOG_ERROR, "Error decoding frame\n");
|
av_log(NULL, AV_LOG_ERROR, "Error decoding frame\n");
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
if (got_frame) {
|
|
||||||
number_of_written_bytes = av_image_copy_to_buffer(byte_buffer, byte_buffer_size,
|
number_of_written_bytes = av_image_copy_to_buffer(byte_buffer, byte_buffer_size,
|
||||||
(const uint8_t* const *)fr->data, (const int*) fr->linesize,
|
(const uint8_t* const *)fr->data, (const int*) fr->linesize,
|
||||||
ctx->pix_fmt, ctx->width, ctx->height, 1);
|
ctx->pix_fmt, ctx->width, ctx->height, 1);
|
||||||
@ -141,13 +154,11 @@ static int compute_crc_of_packets(AVFormatContext *fmt_ctx, int video_stream,
|
|||||||
if (compare_crc_in_array(crc, fr->pts) < 0)
|
if (compare_crc_in_array(crc, fr->pts) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
av_frame_unref(fr);
|
||||||
}
|
}
|
||||||
}
|
} while (result >= 0 && (no_seeking || (fr->pts + fr->pkt_duration <= ts_end)));
|
||||||
av_packet_unref(&pkt);
|
|
||||||
av_init_packet(&pkt);
|
|
||||||
} while ((!end_of_stream || got_frame) && (no_seeking || (fr->pts + fr->pkt_duration <= ts_end)));
|
|
||||||
|
|
||||||
av_packet_unref(&pkt);
|
finish:
|
||||||
av_freep(&byte_buffer);
|
av_freep(&byte_buffer);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@ -176,6 +187,7 @@ static int seek_test(const char *input_filename, const char *start, const char *
|
|||||||
AVCodec *codec = NULL;
|
AVCodec *codec = NULL;
|
||||||
AVCodecContext *ctx= NULL;
|
AVCodecContext *ctx= NULL;
|
||||||
AVCodecParameters *origin_par = NULL;
|
AVCodecParameters *origin_par = NULL;
|
||||||
|
AVPacket *pkt = NULL;
|
||||||
AVFrame *fr = NULL;
|
AVFrame *fr = NULL;
|
||||||
AVFormatContext *fmt_ctx = NULL;
|
AVFormatContext *fmt_ctx = NULL;
|
||||||
int video_stream;
|
int video_stream;
|
||||||
@ -250,13 +262,20 @@ static int seek_test(const char *input_filename, const char *start, const char *
|
|||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
|
|
||||||
result = compute_crc_of_packets(fmt_ctx, video_stream, ctx, fr, 0, 0, 1);
|
pkt = av_packet_alloc();
|
||||||
|
if (!pkt) {
|
||||||
|
av_log(NULL, AV_LOG_ERROR, "Cannot allocate packet\n");
|
||||||
|
result = AVERROR(ENOMEM);
|
||||||
|
goto end;
|
||||||
|
}
|
||||||
|
|
||||||
|
result = compute_crc_of_packets(fmt_ctx, video_stream, ctx, pkt, fr, 0, 0, 1);
|
||||||
if (result != 0)
|
if (result != 0)
|
||||||
goto end;
|
goto end;
|
||||||
|
|
||||||
for (i = start_ts; i < end_ts; i += 100) {
|
for (i = start_ts; i < end_ts; i += 100) {
|
||||||
for (j = i + 100; j < end_ts; j += 100) {
|
for (j = i + 100; j < end_ts; j += 100) {
|
||||||
result = compute_crc_of_packets(fmt_ctx, video_stream, ctx, fr, i, j, 0);
|
result = compute_crc_of_packets(fmt_ctx, video_stream, ctx, pkt, fr, i, j, 0);
|
||||||
if (result != 0)
|
if (result != 0)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -265,6 +284,7 @@ static int seek_test(const char *input_filename, const char *start, const char *
|
|||||||
end:
|
end:
|
||||||
av_freep(&crc_array);
|
av_freep(&crc_array);
|
||||||
av_freep(&pts_array);
|
av_freep(&pts_array);
|
||||||
|
av_packet_free(&pkt);
|
||||||
av_frame_free(&fr);
|
av_frame_free(&fr);
|
||||||
avformat_close_input(&fmt_ctx);
|
avformat_close_input(&fmt_ctx);
|
||||||
avcodec_free_context(&ctx);
|
avcodec_free_context(&ctx);
|
||||||
|
Loading…
Reference in New Issue
Block a user