static int seek_test(const char *input_filename, const char *start, const char *end)

{

    AVCodec *codec = NULL;

    AVCodecContext *ctx= NULL;

    AVCodecParameters *origin_par = NULL;

    AVFrame *fr = NULL;

    AVFormatContext *fmt_ctx = NULL;

    int video_stream;

    int result;

    int i, j;

    long int start_ts, end_ts;



    size_of_array = 0;

    number_of_elements = 0;

    crc_array = pts_array = NULL;



    result = avformat_open_input(&fmt_ctx, input_filename, NULL, NULL);

    if (result < 0) {

        av_log(NULL, AV_LOG_ERROR, "Can't open file\n");

        return result;

    }



    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;

    }



    start_ts = read_seek_range(start);

    end_ts = read_seek_range(end);

    if ((start_ts < 0) || (end_ts < 0))

        return -1;



    //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;

    }



    origin_par = fmt_ctx->streams[video_stream]->codecpar;



    codec = avcodec_find_decoder(origin_par->codec_id);

    if (!codec) {

        av_log(NULL, AV_LOG_ERROR, "Can't find decoder\n");

        return -1;

    }



    ctx = avcodec_alloc_context3(codec);

    if (!ctx) {

        av_log(NULL, AV_LOG_ERROR, "Can't allocate decoder context\n");

        return AVERROR(ENOMEM);

    }



    result = avcodec_parameters_to_context(ctx, origin_par);

    if (result) {

        av_log(NULL, AV_LOG_ERROR, "Can't copy decoder context\n");

        return result;

    }



    result = avcodec_open2(ctx, codec, NULL);

    if (result < 0) {

        av_log(ctx, AV_LOG_ERROR, "Can't open decoder\n");

        return result;

    }



    fr = av_frame_alloc();

    if (!fr) {

        av_log(NULL, AV_LOG_ERROR, "Can't allocate frame\n");

        return AVERROR(ENOMEM);

    }



    result = compute_crc_of_packets(fmt_ctx, video_stream, ctx, fr, 0, 0, 1);

    if (result != 0)

        return -1;



    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;

    }



    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;

}

static int seek_test(const char *input_filename, const char *start, const char *end)

{

    AVCodec *codec = NULL;

    AVCodecContext *ctx= NULL;

    AVCodecParameters *origin_par = NULL;

    AVFrame *fr = NULL;

    AVFormatContext *fmt_ctx = NULL;

    int video_stream;

    int result;

    int i, j;

    long int start_ts, end_ts;



    size_of_array = 0;

    number_of_elements = 0;

    crc_array = pts_array = NULL;



    result = avformat_open_input(&fmt_ctx, input_filename, NULL, NULL);

    if (result < 0) {

        av_log(NULL, AV_LOG_ERROR, "Can't open file\n");

        return result;

    }



    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;

    }



    start_ts = read_seek_range(start);

    end_ts = read_seek_range(end);

    if ((start_ts < 0) || (end_ts < 0))

        return -1;



    

    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;

    }



    origin_par = fmt_ctx->streams[video_stream]->codecpar;



    codec = avcodec_find_decoder(origin_par->codec_id);

    if (!codec) {

        av_log(NULL, AV_LOG_ERROR, "Can't find decoder\n");

        return -1;

    }



    ctx = avcodec_alloc_context3(codec);

    if (!ctx) {

        av_log(NULL, AV_LOG_ERROR, "Can't allocate decoder context\n");

        return AVERROR(ENOMEM);

    }



    result = avcodec_parameters_to_context(ctx, origin_par);

    if (result) {

        av_log(NULL, AV_LOG_ERROR, "Can't copy decoder context\n");

        return result;

    }



    result = avcodec_open2(ctx, codec, NULL);

    if (result < 0) {

        av_log(ctx, AV_LOG_ERROR, "Can't open decoder\n");

        return result;

    }



    fr = av_frame_alloc();

    if (!fr) {

        av_log(NULL, AV_LOG_ERROR, "Can't allocate frame\n");

        return AVERROR(ENOMEM);

    }



    result = compute_crc_of_packets(fmt_ctx, video_stream, ctx, fr, 0, 0, 1);

    if (result != 0)

        return -1;



    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;

    }



    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;

}

static int FUNC_0(const char *VAR_0, const char *VAR_1, const char *VAR_2)

{

    AVCodec *codec = NULL;

    AVCodecContext *ctx= NULL;

    AVCodecParameters *origin_par = NULL;

    AVFrame *fr = NULL;

    AVFormatContext *fmt_ctx = NULL;

    int VAR_3;

    int VAR_4;

    int VAR_5, VAR_6;

    long int VAR_7, VAR_8;



    size_of_array = 0;

    number_of_elements = 0;

    crc_array = pts_array = NULL;



    VAR_4 = avformat_open_input(&fmt_ctx, VAR_0, NULL, NULL);

    if (VAR_4 < 0) {

        av_log(NULL, AV_LOG_ERROR, "Can't open file\n");

        return VAR_4;

    }



    VAR_4 = avformat_find_stream_info(fmt_ctx, NULL);

    if (VAR_4 < 0) {

        av_log(NULL, AV_LOG_ERROR, "Can't get stream info\n");

        return VAR_4;

    }



    VAR_7 = read_seek_range(VAR_1);

    VAR_8 = read_seek_range(VAR_2);

    if ((VAR_7 < 0) || (VAR_8 < 0))

        return -1;



    

    VAR_3 = av_find_best_stream(fmt_ctx, AVMEDIA_TYPE_VIDEO, -1, -1, NULL, 0);

    if (VAR_3 < 0) {

      av_log(NULL, AV_LOG_ERROR, "Can't find video stream in input file\n");

      return -1;

    }



    origin_par = fmt_ctx->streams[VAR_3]->codecpar;



    codec = avcodec_find_decoder(origin_par->codec_id);

    if (!codec) {

        av_log(NULL, AV_LOG_ERROR, "Can't find decoder\n");

        return -1;

    }



    ctx = avcodec_alloc_context3(codec);

    if (!ctx) {

        av_log(NULL, AV_LOG_ERROR, "Can't allocate decoder context\n");

        return AVERROR(ENOMEM);

    }



    VAR_4 = avcodec_parameters_to_context(ctx, origin_par);

    if (VAR_4) {

        av_log(NULL, AV_LOG_ERROR, "Can't copy decoder context\n");

        return VAR_4;

    }



    VAR_4 = avcodec_open2(ctx, codec, NULL);

    if (VAR_4 < 0) {

        av_log(ctx, AV_LOG_ERROR, "Can't open decoder\n");

        return VAR_4;

    }



    fr = av_frame_alloc();

    if (!fr) {

        av_log(NULL, AV_LOG_ERROR, "Can't allocate frame\n");

        return AVERROR(ENOMEM);

    }



    VAR_4 = compute_crc_of_packets(fmt_ctx, VAR_3, ctx, fr, 0, 0, 1);

    if (VAR_4 != 0)

        return -1;



    for (VAR_5 = VAR_7; VAR_5 < VAR_8; VAR_5 += 100) {

        for (VAR_6 = VAR_5 + 100; VAR_6 < VAR_8; VAR_6 += 100)

        VAR_4 = compute_crc_of_packets(fmt_ctx, VAR_3, ctx, fr, VAR_5, VAR_6, 0);

        if (VAR_4 != 0)

            return -1;

    }



    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;

}

static int FUNC_0(const char *VAR_0, const char *VAR_1, const char *VAR_2)
{ AVCodec *codec = NULL; AVCodecContext *ctx= NULL; AVCodecParameters *origin_par = NULL; AVFrame *fr = NULL; AVFormatContext *fmt_ctx = NULL; int VAR_3; int VAR_4; int VAR_5, VAR_6; long int VAR_7, VAR_8; size_of_array = 0; number_of_elements = 0; crc_array = pts_array = NULL; VAR_4 = avformat_open_input(&fmt_ctx, VAR_0, NULL, NULL); if (VAR_4 < 0) { av_log(NULL, AV_LOG_ERROR, "Can't open file\n"); return VAR_4; } VAR_4 = avformat_find_stream_info(fmt_ctx, NULL); if (VAR_4 < 0) { av_log(NULL, AV_LOG_ERROR, "Can't get stream info\n"); return VAR_4; } VAR_7 = read_seek_range(VAR_1); VAR_8 = read_seek_range(VAR_2); if ((VAR_7 < 0) || (VAR_8 < 0))
return -1; VAR_3 = av_find_best_stream(fmt_ctx, AVMEDIA_TYPE_VIDEO, -1, -1, NULL, 0); if (VAR_3 < 0) { av_log(NULL, AV_LOG_ERROR, "Can't find video stream in input file\n"); return -1; } origin_par = fmt_ctx->streams[VAR_3]->codecpar; codec = avcodec_find_decoder(origin_par->codec_id); if (!codec) { av_log(NULL, AV_LOG_ERROR, "Can't find decoder\n"); return -1; } ctx = avcodec_alloc_context3(codec); if (!ctx) { av_log(NULL, AV_LOG_ERROR, "Can't allocate decoder context\n"); return AVERROR(ENOMEM); } VAR_4 = avcodec_parameters_to_context(ctx, origin_par); if (VAR_4) { av_log(NULL, AV_LOG_ERROR, "Can't copy decoder context\n"); return VAR_4; } VAR_4 = avcodec_open2(ctx, codec, NULL); if (VAR_4 < 0) { av_log(ctx, AV_LOG_ERROR, "Can't open decoder\n"); return VAR_4; } fr = av_frame_alloc(); if (!fr) { av_log(NULL, AV_LOG_ERROR, "Can't allocate frame\n"); return AVERROR(ENOMEM); } VAR_4 = compute_crc_of_packets(fmt_ctx, VAR_3, ctx, fr, 0, 0, 1); if (VAR_4 != 0)
return -1; for (VAR_5 = VAR_7; VAR_5 < VAR_8; VAR_5 += 100) { for (VAR_6 = VAR_5 + 100; VAR_6 < VAR_8; VAR_6 += 100) VAR_4 = compute_crc_of_packets(fmt_ctx, VAR_3, ctx, fr, VAR_5, VAR_6, 0); if (VAR_4 != 0)
return -1; } 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; }