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

libavfilter/libmpcodecs/vf_fixpts.c

Go to the documentation of this file.
00001 /*
00002  * This file is part of MPlayer.
00003  *
00004  * MPlayer is free software; you can redistribute it and/or modify
00005  * it under the terms of the GNU General Public License as published by
00006  * the Free Software Foundation; either version 2 of the License, or
00007  * (at your option) any later version.
00008  *
00009  * MPlayer is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  * GNU General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License along
00015  * with MPlayer; if not, write to the Free Software Foundation, Inc.,
00016  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
00017  */
00018 
00019 #include <stdio.h>
00020 #include <stdlib.h>
00021 #include <string.h>
00022 #include <inttypes.h>
00023 
00024 #include "config.h"
00025 #include "mp_msg.h"
00026 #include "help_mp.h"
00027 
00028 #include "img_format.h"
00029 #include "mp_image.h"
00030 #include "vf.h"
00031 
00032 struct vf_priv_s {
00033     double current;
00034     double step;
00035     int autostart;
00036     int autostep;
00037     unsigned have_step:1;
00038     unsigned print:1;
00039 };
00040 
00041 static int put_image(vf_instance_t *vf, mp_image_t *src, double pts)
00042 {
00043     struct vf_priv_s *p = vf->priv;
00044 
00045     if (p->print) {
00046         if (pts == MP_NOPTS_VALUE)
00047             mp_msg(MSGT_VFILTER, MSGL_INFO, "PTS: undef\n");
00048         else
00049             mp_msg(MSGT_VFILTER, MSGL_INFO, "PTS: %f\n", pts);
00050     }
00051     if (pts != MP_NOPTS_VALUE && p->autostart != 0) {
00052         p->current = pts;
00053         if (p->autostart > 0)
00054             p->autostart--;
00055     } else if (pts != MP_NOPTS_VALUE && p->autostep > 0) {
00056         p->step = pts - p->current;
00057         p->current = pts;
00058         p->autostep--;
00059         p->have_step = 1;
00060     } else if (p->have_step) {
00061         p->current += p->step;
00062         pts = p->current;
00063     } else {
00064         pts = MP_NOPTS_VALUE;
00065     }
00066     return vf_next_put_image(vf, src, pts);
00067 }
00068 
00069 static void uninit(vf_instance_t *vf)
00070 {
00071     free(vf->priv);
00072 }
00073 
00074 static int parse_args(struct vf_priv_s *p, const char *args)
00075 {
00076     int pos;
00077     double num, denom = 1;
00078     int iarg;
00079 
00080     while (*args != 0) {
00081         pos = 0;
00082         if (sscanf(args, "print%n", &pos) == 0 && pos > 0) {
00083             p->print = 1;
00084         } else if (sscanf(args, "fps=%lf%n/%lf%n", &num, &pos, &denom, &pos) >=
00085                    1 && pos > 0) {
00086             p->step = denom / num;
00087             p->have_step = 1;
00088         } else if (sscanf(args, "start=%lf%n", &num, &pos) >= 1 && pos > 0) {
00089             p->current = num;
00090         } else if (sscanf(args, "autostart=%d%n", &iarg, &pos) == 1 && pos > 0) {
00091             p->autostart = iarg;
00092         } else if (sscanf(args, "autofps=%d%n", &iarg, &pos) == 1 && pos > 0) {
00093             p->autostep = iarg;
00094         } else {
00095             mp_msg(MSGT_VFILTER, MSGL_FATAL,
00096                    "fixpts: unknown suboption: %s\n", args);
00097             return 0;
00098         }
00099         args += pos;
00100         if (*args == ':')
00101             args++;
00102     }
00103     return 1;
00104 }
00105 
00106 static int open(vf_instance_t *vf, char *args)
00107 {
00108     struct vf_priv_s *p;
00109     struct vf_priv_s ptmp = {
00110         .current = 0,
00111         .step = 0,
00112         .autostart = 0,
00113         .autostep = 0,
00114         .have_step = 0,
00115         .print = 0,
00116     };
00117 
00118     if (!parse_args(&ptmp, args == NULL ? "" : args))
00119         return 0;
00120 
00121     vf->put_image = put_image;
00122     vf->uninit = uninit;
00123     vf->priv = p = malloc(sizeof(struct vf_priv_s));
00124     *p = ptmp;
00125     p->current = -p->step;
00126 
00127     return 1;
00128 }
00129 
00130 const vf_info_t vf_info_fixpts = {
00131     "Fix presentation timestamps",
00132     "fixpts",
00133     "Nicolas George",
00134     "",
00135     &open,
00136     NULL
00137 };

Generated on Fri Feb 22 2013 07:24:30 for FFmpeg by  doxygen 1.7.1