ad_ffmpeg: return failure from init() if initial decode fails
[mplayer/greg.git] / libmpcodecs / vf_softpulldown.c
blob5bd5e66bfdc7313895581f2642f4c36afa87539b
1 /*
2 * This file is part of MPlayer.
4 * MPlayer is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * MPlayer is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 #include <stdio.h>
20 #include <stdlib.h>
21 #include <string.h>
23 #include "config.h"
24 #include "mp_msg.h"
26 #include "img_format.h"
27 #include "mp_image.h"
28 #include "vf.h"
30 #include "libvo/fastmemcpy.h"
32 struct vf_priv_s {
33 int state;
34 long long in;
35 long long out;
36 struct vf_detc_pts_buf ptsbuf;
37 int last_frame_duration;
38 double buffered_pts;
39 mp_image_t *buffered_mpi;
40 int buffered_last_frame_duration;
43 static int continue_buffered_image(struct vf_instance *vf)
45 double pts = vf->priv->buffered_pts;
46 mp_image_t *mpi = vf->priv->buffered_mpi;
47 vf->priv->out++;
48 vf->priv->state=0;
49 return vf_next_put_image(vf, mpi, vf_softpulldown_adjust_pts(&vf->priv->ptsbuf, pts, 0, 0, vf->priv->buffered_last_frame_duration));
52 static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts)
54 mp_image_t *dmpi;
55 int ret = 0;
56 int flags = mpi->fields;
57 int state = vf->priv->state;
59 dmpi = vf_get_image(vf->next, mpi->imgfmt,
60 MP_IMGTYPE_STATIC, MP_IMGFLAG_ACCEPT_STRIDE |
61 MP_IMGFLAG_PRESERVE, mpi->width, mpi->height);
63 vf->priv->in++;
65 if ((state == 0 &&
66 !(flags & MP_IMGFIELD_TOP_FIRST)) ||
67 (state == 1 &&
68 flags & MP_IMGFIELD_TOP_FIRST)) {
69 mp_msg(MSGT_VFILTER, MSGL_WARN,
70 "softpulldown: Unexpected field flags: state=%d top_field_first=%d repeat_first_field=%d\n",
71 state,
72 (flags & MP_IMGFIELD_TOP_FIRST) != 0,
73 (flags & MP_IMGFIELD_REPEAT_FIRST) != 0);
74 state ^= 1;
77 if (state == 0) {
78 ret = vf_next_put_image(vf, mpi, vf_softpulldown_adjust_pts(&vf->priv->ptsbuf, pts, 0, 0, vf->priv->last_frame_duration));
79 vf->priv->out++;
80 if (flags & MP_IMGFIELD_REPEAT_FIRST) {
81 my_memcpy_pic(dmpi->planes[0],
82 mpi->planes[0], mpi->w, mpi->h/2,
83 dmpi->stride[0]*2, mpi->stride[0]*2);
84 if (mpi->flags & MP_IMGFLAG_PLANAR) {
85 my_memcpy_pic(dmpi->planes[1],
86 mpi->planes[1],
87 mpi->chroma_width,
88 mpi->chroma_height/2,
89 dmpi->stride[1]*2,
90 mpi->stride[1]*2);
91 my_memcpy_pic(dmpi->planes[2],
92 mpi->planes[2],
93 mpi->chroma_width,
94 mpi->chroma_height/2,
95 dmpi->stride[2]*2,
96 mpi->stride[2]*2);
98 state=1;
100 } else {
101 my_memcpy_pic(dmpi->planes[0]+dmpi->stride[0],
102 mpi->planes[0]+mpi->stride[0], mpi->w, mpi->h/2,
103 dmpi->stride[0]*2, mpi->stride[0]*2);
104 if (mpi->flags & MP_IMGFLAG_PLANAR) {
105 my_memcpy_pic(dmpi->planes[1]+dmpi->stride[1],
106 mpi->planes[1]+mpi->stride[1],
107 mpi->chroma_width, mpi->chroma_height/2,
108 dmpi->stride[1]*2, mpi->stride[1]*2);
109 my_memcpy_pic(dmpi->planes[2]+dmpi->stride[2],
110 mpi->planes[2]+mpi->stride[2],
111 mpi->chroma_width, mpi->chroma_height/2,
112 dmpi->stride[2]*2, mpi->stride[2]*2);
114 ret = vf_next_put_image(vf, dmpi, vf_softpulldown_adjust_pts(&vf->priv->ptsbuf, pts, 0, 0, vf->priv->last_frame_duration));
115 vf->priv->out++;
116 if (flags & MP_IMGFIELD_REPEAT_FIRST) {
117 vf->priv->buffered_mpi = mpi;
118 vf->priv->buffered_pts = pts;
119 vf->priv->buffered_last_frame_duration = vf->priv->last_frame_duration;
120 vf_queue_frame(vf, continue_buffered_image);
121 } else {
122 my_memcpy_pic(dmpi->planes[0],
123 mpi->planes[0], mpi->w, mpi->h/2,
124 dmpi->stride[0]*2, mpi->stride[0]*2);
125 if (mpi->flags & MP_IMGFLAG_PLANAR) {
126 my_memcpy_pic(dmpi->planes[1],
127 mpi->planes[1],
128 mpi->chroma_width,
129 mpi->chroma_height/2,
130 dmpi->stride[1]*2,
131 mpi->stride[1]*2);
132 my_memcpy_pic(dmpi->planes[2],
133 mpi->planes[2],
134 mpi->chroma_width,
135 mpi->chroma_height/2,
136 dmpi->stride[2]*2,
137 mpi->stride[2]*2);
142 vf->priv->state = state;
143 if (flags & MP_IMGFIELD_REPEAT_FIRST)
144 vf->priv->last_frame_duration = 3;
145 else
146 vf->priv->last_frame_duration = 2;
148 return ret;
151 static int config(struct vf_instance *vf,
152 int width, int height, int d_width, int d_height,
153 unsigned int flags, unsigned int outfmt)
155 return vf_next_config(vf,width,height,d_width,d_height,flags,outfmt);
158 static void uninit(struct vf_instance *vf)
160 mp_msg(MSGT_VFILTER, MSGL_INFO, "softpulldown: %lld frames in, %lld frames out\n", vf->priv->in, vf->priv->out);
161 free(vf->priv);
164 static int vf_open(vf_instance_t *vf, char *args)
166 struct vf_priv_s *p;
167 vf->config = config;
168 vf->put_image = put_image;
169 vf->uninit = uninit;
170 vf->default_reqs = VFCAP_ACCEPT_STRIDE;
171 vf->priv = p = calloc(1, sizeof(struct vf_priv_s));
172 vf->priv->state = 0;
173 vf->priv->last_frame_duration = 2;
174 vf_detc_init_pts_buf(&vf->priv->ptsbuf);
175 return 1;
178 const vf_info_t vf_info_softpulldown = {
179 "mpeg2 soft 3:2 pulldown",
180 "softpulldown",
181 "Tobias Diedrich <ranma+mplayer@tdiedrich.de>",
183 vf_open,
184 NULL