annotate libmpcodecs/vf_softskip.c @ 30795:1001c606f94c

Make emulated Win32 critical sections thread safe. Earlier, cs->locked was accessed outside the mutex to get around the problem that default pthread mutexes are not recursive (ie., you cannot do a double-lock from the same thread), causing a thread-safety problem, as both detected by Helgrind and showing up in some multithreaded codecs. The ideal solution here would be to simply use recursive pthread mutexes, but there were concerns about reduced debuggability and possibly portability. Thus, instead, rewrite the critical sections to be a simple lock count (with owner) protected by a regular mutex. Whenever a thread wants to enter the critical section and lock_count is not 0, it sleeps on a special event that tells it when the critical section is available.
author sesse
date Thu, 04 Mar 2010 15:57:08 +0000
parents a972c1a4a012
children 7af3e6f901fd
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
30421
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29263
diff changeset
1 /*
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29263
diff changeset
2 * This file is part of MPlayer.
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29263
diff changeset
3 *
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29263
diff changeset
4 * MPlayer is free software; you can redistribute it and/or modify
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29263
diff changeset
5 * it under the terms of the GNU General Public License as published by
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29263
diff changeset
6 * the Free Software Foundation; either version 2 of the License, or
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29263
diff changeset
7 * (at your option) any later version.
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29263
diff changeset
8 *
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29263
diff changeset
9 * MPlayer is distributed in the hope that it will be useful,
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29263
diff changeset
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29263
diff changeset
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29263
diff changeset
12 * GNU General Public License for more details.
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29263
diff changeset
13 *
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29263
diff changeset
14 * You should have received a copy of the GNU General Public License along
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29263
diff changeset
15 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29263
diff changeset
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29263
diff changeset
17 */
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29263
diff changeset
18
12337
6f1b4c989914 soft skipping for mencoder. rather than skipping decoding/filtering
rfelker
parents:
diff changeset
19 #include <stdio.h>
6f1b4c989914 soft skipping for mencoder. rather than skipping decoding/filtering
rfelker
parents:
diff changeset
20 #include <stdlib.h>
6f1b4c989914 soft skipping for mencoder. rather than skipping decoding/filtering
rfelker
parents:
diff changeset
21 #include <string.h>
6f1b4c989914 soft skipping for mencoder. rather than skipping decoding/filtering
rfelker
parents:
diff changeset
22
17012
6ff3379a0862 Unify include path handling, -I.. is in CFLAGS.
diego
parents: 12337
diff changeset
23 #include "config.h"
6ff3379a0862 Unify include path handling, -I.. is in CFLAGS.
diego
parents: 12337
diff changeset
24 #include "mp_msg.h"
12337
6f1b4c989914 soft skipping for mencoder. rather than skipping decoding/filtering
rfelker
parents:
diff changeset
25
6f1b4c989914 soft skipping for mencoder. rather than skipping decoding/filtering
rfelker
parents:
diff changeset
26 #include "img_format.h"
6f1b4c989914 soft skipping for mencoder. rather than skipping decoding/filtering
rfelker
parents:
diff changeset
27 #include "mp_image.h"
6f1b4c989914 soft skipping for mencoder. rather than skipping decoding/filtering
rfelker
parents:
diff changeset
28 #include "vf.h"
6f1b4c989914 soft skipping for mencoder. rather than skipping decoding/filtering
rfelker
parents:
diff changeset
29
6f1b4c989914 soft skipping for mencoder. rather than skipping decoding/filtering
rfelker
parents:
diff changeset
30 struct vf_priv_s {
6f1b4c989914 soft skipping for mencoder. rather than skipping decoding/filtering
rfelker
parents:
diff changeset
31 int skipflag;
6f1b4c989914 soft skipping for mencoder. rather than skipping decoding/filtering
rfelker
parents:
diff changeset
32 };
6f1b4c989914 soft skipping for mencoder. rather than skipping decoding/filtering
rfelker
parents:
diff changeset
33
30642
a972c1a4a012 cosmetics: Rename struct vf_instance_s --> vf_instance.
diego
parents: 30638
diff changeset
34 static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts)
12337
6f1b4c989914 soft skipping for mencoder. rather than skipping decoding/filtering
rfelker
parents:
diff changeset
35 {
6f1b4c989914 soft skipping for mencoder. rather than skipping decoding/filtering
rfelker
parents:
diff changeset
36 mp_image_t *dmpi;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 25221
diff changeset
37
12337
6f1b4c989914 soft skipping for mencoder. rather than skipping decoding/filtering
rfelker
parents:
diff changeset
38 if (vf->priv->skipflag)
6f1b4c989914 soft skipping for mencoder. rather than skipping decoding/filtering
rfelker
parents:
diff changeset
39 return vf->priv->skipflag = 0;
6f1b4c989914 soft skipping for mencoder. rather than skipping decoding/filtering
rfelker
parents:
diff changeset
40
6f1b4c989914 soft skipping for mencoder. rather than skipping decoding/filtering
rfelker
parents:
diff changeset
41 dmpi = vf_get_image(vf->next, mpi->imgfmt,
6f1b4c989914 soft skipping for mencoder. rather than skipping decoding/filtering
rfelker
parents:
diff changeset
42 MP_IMGTYPE_EXPORT, 0, mpi->width, mpi->height);
21698
009635b12924 Pass quant tables to next filters
gpoirier
parents: 17906
diff changeset
43 vf_clone_mpi_attributes(dmpi, mpi);
12337
6f1b4c989914 soft skipping for mencoder. rather than skipping decoding/filtering
rfelker
parents:
diff changeset
44
6f1b4c989914 soft skipping for mencoder. rather than skipping decoding/filtering
rfelker
parents:
diff changeset
45 dmpi->planes[0] = mpi->planes[0];
6f1b4c989914 soft skipping for mencoder. rather than skipping decoding/filtering
rfelker
parents:
diff changeset
46 dmpi->stride[0] = mpi->stride[0];
6f1b4c989914 soft skipping for mencoder. rather than skipping decoding/filtering
rfelker
parents:
diff changeset
47 if (dmpi->flags&MP_IMGFLAG_PLANAR) {
6f1b4c989914 soft skipping for mencoder. rather than skipping decoding/filtering
rfelker
parents:
diff changeset
48 dmpi->planes[1] = mpi->planes[1];
6f1b4c989914 soft skipping for mencoder. rather than skipping decoding/filtering
rfelker
parents:
diff changeset
49 dmpi->stride[1] = mpi->stride[1];
6f1b4c989914 soft skipping for mencoder. rather than skipping decoding/filtering
rfelker
parents:
diff changeset
50 dmpi->planes[2] = mpi->planes[2];
6f1b4c989914 soft skipping for mencoder. rather than skipping decoding/filtering
rfelker
parents:
diff changeset
51 dmpi->stride[2] = mpi->stride[2];
6f1b4c989914 soft skipping for mencoder. rather than skipping decoding/filtering
rfelker
parents:
diff changeset
52 }
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 25221
diff changeset
53
17906
20aca9baf5d8 passing pts through the filter layer (lets see if pts or cola comes out at the end)
michael
parents: 17012
diff changeset
54 return vf_next_put_image(vf, dmpi, pts);
12337
6f1b4c989914 soft skipping for mencoder. rather than skipping decoding/filtering
rfelker
parents:
diff changeset
55 }
6f1b4c989914 soft skipping for mencoder. rather than skipping decoding/filtering
rfelker
parents:
diff changeset
56
30642
a972c1a4a012 cosmetics: Rename struct vf_instance_s --> vf_instance.
diego
parents: 30638
diff changeset
57 static int control(struct vf_instance *vf, int request, void* data)
12337
6f1b4c989914 soft skipping for mencoder. rather than skipping decoding/filtering
rfelker
parents:
diff changeset
58 {
6f1b4c989914 soft skipping for mencoder. rather than skipping decoding/filtering
rfelker
parents:
diff changeset
59 switch (request) {
6f1b4c989914 soft skipping for mencoder. rather than skipping decoding/filtering
rfelker
parents:
diff changeset
60 case VFCTRL_SKIP_NEXT_FRAME:
6f1b4c989914 soft skipping for mencoder. rather than skipping decoding/filtering
rfelker
parents:
diff changeset
61 vf->priv->skipflag = 1;
6f1b4c989914 soft skipping for mencoder. rather than skipping decoding/filtering
rfelker
parents:
diff changeset
62 return CONTROL_TRUE;
6f1b4c989914 soft skipping for mencoder. rather than skipping decoding/filtering
rfelker
parents:
diff changeset
63 }
6f1b4c989914 soft skipping for mencoder. rather than skipping decoding/filtering
rfelker
parents:
diff changeset
64 return vf_next_control(vf, request, data);
6f1b4c989914 soft skipping for mencoder. rather than skipping decoding/filtering
rfelker
parents:
diff changeset
65 }
6f1b4c989914 soft skipping for mencoder. rather than skipping decoding/filtering
rfelker
parents:
diff changeset
66
24605
8a6f80593529 Disable unused query_format functions for now until they are
diego
parents: 23373
diff changeset
67 #if 0
30642
a972c1a4a012 cosmetics: Rename struct vf_instance_s --> vf_instance.
diego
parents: 30638
diff changeset
68 static int query_format(struct vf_instance *vf, unsigned int fmt)
12337
6f1b4c989914 soft skipping for mencoder. rather than skipping decoding/filtering
rfelker
parents:
diff changeset
69 {
6f1b4c989914 soft skipping for mencoder. rather than skipping decoding/filtering
rfelker
parents:
diff changeset
70 /* FIXME - figure out which other formats work */
6f1b4c989914 soft skipping for mencoder. rather than skipping decoding/filtering
rfelker
parents:
diff changeset
71 switch (fmt) {
6f1b4c989914 soft skipping for mencoder. rather than skipping decoding/filtering
rfelker
parents:
diff changeset
72 case IMGFMT_YV12:
6f1b4c989914 soft skipping for mencoder. rather than skipping decoding/filtering
rfelker
parents:
diff changeset
73 case IMGFMT_IYUV:
6f1b4c989914 soft skipping for mencoder. rather than skipping decoding/filtering
rfelker
parents:
diff changeset
74 case IMGFMT_I420:
6f1b4c989914 soft skipping for mencoder. rather than skipping decoding/filtering
rfelker
parents:
diff changeset
75 return vf_next_query_format(vf, fmt);
6f1b4c989914 soft skipping for mencoder. rather than skipping decoding/filtering
rfelker
parents:
diff changeset
76 }
6f1b4c989914 soft skipping for mencoder. rather than skipping decoding/filtering
rfelker
parents:
diff changeset
77 return 0;
6f1b4c989914 soft skipping for mencoder. rather than skipping decoding/filtering
rfelker
parents:
diff changeset
78 }
24605
8a6f80593529 Disable unused query_format functions for now until they are
diego
parents: 23373
diff changeset
79 #endif
12337
6f1b4c989914 soft skipping for mencoder. rather than skipping decoding/filtering
rfelker
parents:
diff changeset
80
30642
a972c1a4a012 cosmetics: Rename struct vf_instance_s --> vf_instance.
diego
parents: 30638
diff changeset
81 static void uninit(struct vf_instance *vf)
12337
6f1b4c989914 soft skipping for mencoder. rather than skipping decoding/filtering
rfelker
parents:
diff changeset
82 {
6f1b4c989914 soft skipping for mencoder. rather than skipping decoding/filtering
rfelker
parents:
diff changeset
83 free(vf->priv);
6f1b4c989914 soft skipping for mencoder. rather than skipping decoding/filtering
rfelker
parents:
diff changeset
84 }
6f1b4c989914 soft skipping for mencoder. rather than skipping decoding/filtering
rfelker
parents:
diff changeset
85
30638
a7b908875c14 Rename open() vf initialization function to vf_open().
diego
parents: 30633
diff changeset
86 static int vf_open(vf_instance_t *vf, char *args)
12337
6f1b4c989914 soft skipping for mencoder. rather than skipping decoding/filtering
rfelker
parents:
diff changeset
87 {
6f1b4c989914 soft skipping for mencoder. rather than skipping decoding/filtering
rfelker
parents:
diff changeset
88 vf->put_image = put_image;
6f1b4c989914 soft skipping for mencoder. rather than skipping decoding/filtering
rfelker
parents:
diff changeset
89 vf->control = control;
6f1b4c989914 soft skipping for mencoder. rather than skipping decoding/filtering
rfelker
parents:
diff changeset
90 vf->uninit = uninit;
6f1b4c989914 soft skipping for mencoder. rather than skipping decoding/filtering
rfelker
parents:
diff changeset
91 vf->priv = calloc(1, sizeof(struct vf_priv_s));
6f1b4c989914 soft skipping for mencoder. rather than skipping decoding/filtering
rfelker
parents:
diff changeset
92 return 1;
6f1b4c989914 soft skipping for mencoder. rather than skipping decoding/filtering
rfelker
parents:
diff changeset
93 }
6f1b4c989914 soft skipping for mencoder. rather than skipping decoding/filtering
rfelker
parents:
diff changeset
94
25221
00fff9a3b735 Make all vf_info_t structs const
reimar
parents: 24605
diff changeset
95 const vf_info_t vf_info_softskip = {
12337
6f1b4c989914 soft skipping for mencoder. rather than skipping decoding/filtering
rfelker
parents:
diff changeset
96 "soft (post-filter) frame skipping for encoding",
6f1b4c989914 soft skipping for mencoder. rather than skipping decoding/filtering
rfelker
parents:
diff changeset
97 "softskip",
6f1b4c989914 soft skipping for mencoder. rather than skipping decoding/filtering
rfelker
parents:
diff changeset
98 "Rich Felker",
6f1b4c989914 soft skipping for mencoder. rather than skipping decoding/filtering
rfelker
parents:
diff changeset
99 "",
30638
a7b908875c14 Rename open() vf initialization function to vf_open().
diego
parents: 30633
diff changeset
100 vf_open,
12337
6f1b4c989914 soft skipping for mencoder. rather than skipping decoding/filtering
rfelker
parents:
diff changeset
101 NULL
6f1b4c989914 soft skipping for mencoder. rather than skipping decoding/filtering
rfelker
parents:
diff changeset
102 };