| 74 | } |
| 75 | |
| 76 | static int compute_crc_of_packets(AVFormatContext *fmt_ctx, int video_stream, |
| 77 | AVCodecContext *ctx, AVPacket *pkt, AVFrame *fr, |
| 78 | uint64_t ts_start, uint64_t ts_end, int no_seeking) |
| 79 | { |
| 80 | int number_of_written_bytes; |
| 81 | int result; |
| 82 | int byte_buffer_size; |
| 83 | uint8_t *byte_buffer; |
| 84 | uint32_t crc; |
| 85 | |
| 86 | byte_buffer_size = av_image_get_buffer_size(ctx->pix_fmt, ctx->width, ctx->height, 16); |
| 87 | byte_buffer = av_malloc(byte_buffer_size); |
| 88 | if (!byte_buffer) { |
| 89 | av_log(NULL, AV_LOG_ERROR, "Can't allocate buffer\n"); |
| 90 | return AVERROR(ENOMEM); |
| 91 | } |
| 92 | |
| 93 | if (!no_seeking) { |
| 94 | result = av_seek_frame(fmt_ctx, video_stream, ts_start, AVSEEK_FLAG_ANY); |
| 95 | printf("Seeking to %"PRId64", computing crc for frames with pts < %"PRId64"\n", ts_start, ts_end); |
| 96 | if (result < 0) { |
| 97 | av_log(NULL, AV_LOG_ERROR, "Error in seeking\n"); |
| 98 | return result; |
| 99 | } |
| 100 | avcodec_flush_buffers(ctx); |
| 101 | } |
| 102 | |
| 103 | do { |
| 104 | result = av_read_frame(fmt_ctx, pkt); |
| 105 | if (result >= 0 && pkt->stream_index != video_stream) { |
| 106 | av_packet_unref(pkt); |
| 107 | continue; |
| 108 | } |
| 109 | |
| 110 | if (result < 0) |
| 111 | result = avcodec_send_packet(ctx, NULL); |
| 112 | else { |
| 113 | if (pkt->pts == AV_NOPTS_VALUE) { |
| 114 | av_log(NULL, AV_LOG_ERROR, "Error: frames doesn't have pts values\n"); |
| 115 | return -1; |
| 116 | } |
| 117 | result = avcodec_send_packet(ctx, pkt); |
| 118 | } |
| 119 | |
| 120 | av_packet_unref(pkt); |
| 121 | |
| 122 | if (result < 0) { |
| 123 | av_log(NULL, AV_LOG_ERROR, "Error submitting a packet for decoding\n"); |
| 124 | return result; |
| 125 | } |
| 126 | |
| 127 | while (result >= 0) { |
| 128 | result = avcodec_receive_frame(ctx, fr); |
| 129 | if (result == AVERROR_EOF) |
| 130 | goto finish; |
| 131 | else if (result == AVERROR(EAGAIN)) { |
| 132 | result = 0; |
| 133 | break; |
no test coverage detected