• Main Page
  • Related Pages
  • Modules
  • Data Structures
  • Files
  • File List
  • Globals

tests/seek_test.c

Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2003 Fabrice Bellard
00003  * Copyright (c) 2007 Michael Niedermayer
00004  *
00005  * This file is part of FFmpeg.
00006  *
00007  * FFmpeg is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU Lesser General Public
00009  * License as published by the Free Software Foundation; either
00010  * version 2.1 of the License, or (at your option) any later version.
00011  *
00012  * FFmpeg is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015  * Lesser General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU Lesser General Public
00018  * License along with FFmpeg; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
00020  */
00021 
00022 #include <stdint.h>
00023 #include <stdlib.h>
00024 #include <stdio.h>
00025 #include <string.h>
00026 
00027 #include "libavutil/common.h"
00028 #include "libavformat/avformat.h"
00029 
00030 #undef exit
00031 #undef printf
00032 #undef fprintf
00033 
00034 static char buffer[20];
00035 
00036 static const char *ret_str(int v)
00037 {
00038     switch (v) {
00039     case AVERROR_EOF:     return "-EOF";
00040     case AVERROR(EIO):    return "-EIO";
00041     case AVERROR(ENOMEM): return "-ENOMEM";
00042     case AVERROR(EINVAL): return "-EINVAL";
00043     default:
00044         snprintf(buffer, sizeof(buffer), "%2d", v);
00045         return buffer;
00046     }
00047 }
00048 
00049 static void ts_str(char buffer[60], int64_t ts, AVRational base)
00050 {
00051     double tsval;
00052     if (ts == AV_NOPTS_VALUE) {
00053         strcpy(buffer, " NOPTS   ");
00054         return;
00055     }
00056     tsval = ts * av_q2d(base);
00057     snprintf(buffer, 60, "%9f", tsval);
00058 }
00059 
00060 int main(int argc, char **argv)
00061 {
00062     const char *filename;
00063     AVFormatContext *ic = NULL;
00064     int i, ret, stream_id;
00065     int64_t timestamp;
00066     AVFormatParameters params, *ap= &params;
00067     memset(ap, 0, sizeof(params));
00068     ap->channels=1;
00069     ap->sample_rate= 22050;
00070 
00071     /* initialize libavcodec, and register all codecs and formats */
00072     av_register_all();
00073 
00074     if (argc != 2) {
00075         printf("usage: %s input_file\n"
00076                "\n", argv[0]);
00077         exit(1);
00078     }
00079 
00080     filename = argv[1];
00081 
00082     ret = av_open_input_file(&ic, filename, NULL, 0, ap);
00083     if (ret < 0) {
00084         fprintf(stderr, "cannot open %s\n", filename);
00085         exit(1);
00086     }
00087 
00088     ret = av_find_stream_info(ic);
00089     if (ret < 0) {
00090         fprintf(stderr, "%s: could not find codec parameters\n", filename);
00091         exit(1);
00092     }
00093 
00094     for(i=0; ; i++){
00095         AVPacket pkt;
00096         AVStream *av_uninit(st);
00097         char ts_buf[60];
00098 
00099         memset(&pkt, 0, sizeof(pkt));
00100         if(ret>=0){
00101             ret= av_read_frame(ic, &pkt);
00102             if(ret>=0){
00103                 char dts_buf[60];
00104                 st= ic->streams[pkt.stream_index];
00105                 ts_str(dts_buf, pkt.dts, st->time_base);
00106                 ts_str(ts_buf,  pkt.pts, st->time_base);
00107                 printf("ret:%-10s st:%2d flags:%d dts:%s pts:%s pos:%7" PRId64 " size:%6d", ret_str(ret), pkt.stream_index, pkt.flags, dts_buf, ts_buf, pkt.pos, pkt.size);
00108                 av_free_packet(&pkt);
00109             } else
00110                 printf("ret:%s", ret_str(ret)); // necessary to avoid trailing whitespace
00111             printf("\n");
00112         }
00113 
00114         if(i>25) break;
00115 
00116         stream_id= (i>>1)%(ic->nb_streams+1) - 1;
00117         timestamp= (i*19362894167LL) % (4*AV_TIME_BASE) - AV_TIME_BASE;
00118         if(stream_id>=0){
00119             st= ic->streams[stream_id];
00120             timestamp= av_rescale_q(timestamp, AV_TIME_BASE_Q, st->time_base);
00121         }
00122         //FIXME fully test the new seek API
00123         if(i&1) ret = avformat_seek_file(ic, stream_id, INT64_MIN, timestamp, timestamp, 0);
00124         else    ret = avformat_seek_file(ic, stream_id, timestamp, timestamp, INT64_MAX, 0);
00125         ts_str(ts_buf, timestamp, stream_id < 0 ? AV_TIME_BASE_Q : st->time_base);
00126         printf("ret:%-10s st:%2d flags:%d  ts:%s\n", ret_str(ret), stream_id, i&1, ts_buf);
00127     }
00128 
00129     av_close_input_file(ic);
00130 
00131     return 0;
00132 }

Generated on Fri Sep 16 2011 17:17:52 for FFmpeg by  doxygen 1.7.1