| 184 | } |
| 185 | |
| 186 | static int seek_test(const char *input_filename, const char *start, const char *end) |
| 187 | { |
| 188 | const AVCodec *codec = NULL; |
| 189 | AVCodecContext *ctx= NULL; |
| 190 | AVCodecParameters *origin_par = NULL; |
| 191 | AVPacket *pkt = NULL; |
| 192 | AVFrame *fr = NULL; |
| 193 | AVFormatContext *fmt_ctx = NULL; |
| 194 | int video_stream; |
| 195 | int result; |
| 196 | int i, j; |
| 197 | long int start_ts, end_ts; |
| 198 | |
| 199 | size_of_array = 0; |
| 200 | number_of_elements = 0; |
| 201 | crc_array = NULL; |
| 202 | pts_array = NULL; |
| 203 | |
| 204 | result = avformat_open_input(&fmt_ctx, input_filename, NULL, NULL); |
| 205 | if (result < 0) { |
| 206 | av_log(NULL, AV_LOG_ERROR, "Can't open file\n"); |
| 207 | return result; |
| 208 | } |
| 209 | |
| 210 | result = avformat_find_stream_info(fmt_ctx, NULL); |
| 211 | if (result < 0) { |
| 212 | av_log(NULL, AV_LOG_ERROR, "Can't get stream info\n"); |
| 213 | goto end; |
| 214 | } |
| 215 | |
| 216 | start_ts = read_seek_range(start); |
| 217 | end_ts = read_seek_range(end); |
| 218 | if ((start_ts < 0) || (end_ts < 0)) { |
| 219 | result = -1; |
| 220 | goto end; |
| 221 | } |
| 222 | |
| 223 | //TODO: add ability to work with audio format |
| 224 | video_stream = av_find_best_stream(fmt_ctx, AVMEDIA_TYPE_VIDEO, -1, -1, NULL, 0); |
| 225 | if (video_stream < 0) { |
| 226 | av_log(NULL, AV_LOG_ERROR, "Can't find video stream in input file\n"); |
| 227 | result = video_stream; |
| 228 | goto end; |
| 229 | } |
| 230 | |
| 231 | origin_par = fmt_ctx->streams[video_stream]->codecpar; |
| 232 | |
| 233 | codec = avcodec_find_decoder(origin_par->codec_id); |
| 234 | if (!codec) { |
| 235 | av_log(NULL, AV_LOG_ERROR, "Can't find decoder\n"); |
| 236 | result = AVERROR_DECODER_NOT_FOUND; |
| 237 | goto end; |
| 238 | } |
| 239 | |
| 240 | ctx = avcodec_alloc_context3(codec); |
| 241 | if (!ctx) { |
| 242 | av_log(NULL, AV_LOG_ERROR, "Can't allocate decoder context\n"); |
| 243 | result = AVERROR(ENOMEM); |
no test coverage detected