summaryrefslogtreecommitdiff
path: root/tests/api
diff options
context:
space:
mode:
authorJames Almer <jamrial@gmail.com>2017-03-12 10:36:44 -0300
committerJames Almer <jamrial@gmail.com>2017-03-12 14:29:11 -0300
commitbdd07d7796e939e920842eb7280e1bce488fb95d (patch)
treef414a465c4800f0413c72c1ff8858822f588c6eb /tests/api
parent88deeb3eba00271e9fb82177860c743fc564e8c0 (diff)
downloadffmpeg-bdd07d7796e939e920842eb7280e1bce488fb95d.tar.gz
test/api-seek: clean up properly on failure
Also propagate better error values. Reviewed-by: Michael Niedermayer <michael@niedermayer.cc> Signed-off-by: James Almer <jamrial@gmail.com>
Diffstat (limited to 'tests/api')
-rw-r--r--tests/api/api-seek-test.c31
1 files changed, 19 insertions, 12 deletions
diff --git a/tests/api/api-seek-test.c b/tests/api/api-seek-test.c
index 6ef3b91933..e4276eb9c8 100644
--- a/tests/api/api-seek-test.c
+++ b/tests/api/api-seek-test.c
@@ -197,19 +197,22 @@ static int seek_test(const char *input_filename, const char *start, const char *
result = avformat_find_stream_info(fmt_ctx, NULL);
if (result < 0) {
av_log(NULL, AV_LOG_ERROR, "Can't get stream info\n");
- return result;
+ goto end;
}
start_ts = read_seek_range(start);
end_ts = read_seek_range(end);
- if ((start_ts < 0) || (end_ts < 0))
- return -1;
+ if ((start_ts < 0) || (end_ts < 0)) {
+ result = -1;
+ goto end;
+ }
//TODO: add ability to work with audio format
video_stream = av_find_best_stream(fmt_ctx, AVMEDIA_TYPE_VIDEO, -1, -1, NULL, 0);
if (video_stream < 0) {
av_log(NULL, AV_LOG_ERROR, "Can't find video stream in input file\n");
- return -1;
+ result = video_stream;
+ goto end;
}
origin_par = fmt_ctx->streams[video_stream]->codecpar;
@@ -217,52 +220,56 @@ static int seek_test(const char *input_filename, const char *start, const char *
codec = avcodec_find_decoder(origin_par->codec_id);
if (!codec) {
av_log(NULL, AV_LOG_ERROR, "Can't find decoder\n");
- return -1;
+ result = AVERROR_DECODER_NOT_FOUND;
+ goto end;
}
ctx = avcodec_alloc_context3(codec);
if (!ctx) {
av_log(NULL, AV_LOG_ERROR, "Can't allocate decoder context\n");
- return AVERROR(ENOMEM);
+ result = AVERROR(ENOMEM);
+ goto end;
}
result = avcodec_parameters_to_context(ctx, origin_par);
if (result) {
av_log(NULL, AV_LOG_ERROR, "Can't copy decoder context\n");
- return result;
+ goto end;
}
result = avcodec_open2(ctx, codec, NULL);
if (result < 0) {
av_log(ctx, AV_LOG_ERROR, "Can't open decoder\n");
- return result;
+ goto end;
}
fr = av_frame_alloc();
if (!fr) {
av_log(NULL, AV_LOG_ERROR, "Can't allocate frame\n");
- return AVERROR(ENOMEM);
+ result = AVERROR(ENOMEM);
+ goto end;
}
result = compute_crc_of_packets(fmt_ctx, video_stream, ctx, fr, 0, 0, 1);
if (result != 0)
- return -1;
+ goto end;
for (i = start_ts; i < end_ts; i += 100) {
for (j = i + 100; j < end_ts; j += 100) {
result = compute_crc_of_packets(fmt_ctx, video_stream, ctx, fr, i, j, 0);
if (result != 0)
- return -1;
+ break;
}
}
+end:
av_freep(&crc_array);
av_freep(&pts_array);
av_frame_free(&fr);
avcodec_close(ctx);
avformat_close_input(&fmt_ctx);
avcodec_free_context(&ctx);
- return 0;
+ return result;
}
int main(int argc, char **argv)