~medibuntu-maintainers/mplayer/medibuntu.precise

« back to all changes in this revision

Viewing changes to ffmpeg/libavcodec/w32thread.c

  • Committer: Gauvain Pocentek
  • Date: 2012-03-06 11:59:12 UTC
  • mfrom: (66.1.15 precise)
  • Revision ID: gauvain@pocentek.net-20120306115912-h9d6kt9j0l532oo5
* Merge from Ubuntu:
  - put back faac support
  - recommends apport-hooks-medibuntu
  - change Maintainer, Uploaders & Vcs-* fields.
* New upstream snapshot
* upload to unstable
* Build against external libmpeg2
* drop 51_FTBFS_arm.patch again
* no longer build depend on libcdparanoia-dev on the Hurd
* Fix FTBFS on the hurd.
  Thanks to Samuel Thibault <sthibault@debian.org> (Closes: #654974)
* Fix FTBFS on arm
* New upstream snapshot, Closes: #650339, #643621, #481807
* Imported Upstream version 1.0~rc4+svn34492
* Bump standards version
* Bump dependency on libav >= 4:0.8~, Closes: #653887
* Fix build-indep
* Build mplayer-gui again, Closes: #568514
* Drop debian/all-lang-config-mak.sh, no longer needed
* include .dfsg1 in version number
* remove get-orig-source target
* no longer prune compiler flags from the environment
* No longer advertise nor build 3fdx, mga and dxr3 backends,
  Closes: #496106, #442181, #533546
* beautify mplayer version identification string
* Brown paperbag upload.
* Next try to fix build failure on sparce after recent binutils change.
* Brown paperbag upload.
* Really fix build failure on sparc after recent binutils change.
* Properly set Replaces/Conflicts on mplayer2{,-dbg} to avoid
  file overwrite errors.
* Adjust versioning of mplayer listed in the mplayer-dbg's Depends field.
* Fix build failure on sparc after recent binutils change.
* Urgency medium bumped because of RC-level bugfix
  and speeding up x264 transition.
* Update to my @debian.org email.
* Upload to unstable
* Enable joystick support on Linux only, Closes: #638408
* Rebuild fixes toolchain issue on arm, Closes: #637077
* New upstream snapshot
* following the discussion started by Diego Biurrun <diego@biurrun.de>
  in debian-devel, I have prepared a new packaging of 'mplayer'
  (with code that comes from CVS)
* the upstream tar.bz cannot be distributed by Debian, since it contains
   CSS code; so I am repackaging it 
* I have tried my best to address all known issues:
  - the package contains the detailed Copyright made by Diego Biurrun 
  - the package does not contain CSS code, or  AFAIK other code on which 
     there is active patent enforcement
  - there is a script  debian/cvs-changelog.sh  that shows all changes
     done to files included in this source.
    This should comply with GPLv2 sec 2.a  (in spirit if not in letter)
    For this reason, the source code contains CVS directories.
* needs   make (>= 3.80) for 'html-chunked-$(1)' in DOCS/xml/Makefile

* some corrections, as suggested Diego Biurrun
  - binary codecs should go into /usr/lib/codecs (upstream default)
  - better template 'mplayer/install_codecs'
  - an empty 'font=' in mplayer.conf breaks mplayer: postinst corrected
* correction in 'mplayer/cfgnote'
* better mplayer.postinst and mplayer.config

* New upstream release
* better debian/copyright file
* do not ship a skin
* New upstream release
* changed DEB_BUILD_OPTIONS to DEB_BUILD_CONFIGURE ,
  DEB_BUILD_OPTIONS is used as in debian policy
* use gcc-3.4
* changed xlibs-dev to a long list of dependencies, for Debian/etch
* try to adhere to  http://www.mplayerhq.hu/DOCS/tech/binary-packaging.txt
  (see README.Debian for details)
* removed dependency on xlibmesa-dev, disabled opengl
* New upstream release
* Simon McVittie <hacks@pseudorandom.co.uk> wonderful work:
- Work around Debian bug #267442 (glibc's sys/uio.h and gcc's altivec.h have
  conflicting uses for __vector) by re-ordering #includes
- Fix potential symlink attack in ./configure
- Disable support for binary codecs on platforms for which those codecs
  aren't available; also disable the corresponding Debconf note when it's
  inappropriate
- Changed Build-Depends: so it works in pbuilder
- Explicitly build-depend on libjpeg62-dev, libfontconfig1-dev,
  libungif4-dev 
- Tweak debian/rules to avoid certain errors being ignored
- Use --language=all
* provide a target  'debian/rules get-orig-source' 
  that recreates the orig.tar.gz ; then use the above orig.tar.gz
* rewrote some parts of debian/rules
* don't clean and recompile docs if upstream ships them
* mplayer-doc was shipping too much stuff
* translated man pages where not installed properly
* compile with libdv4-dev
* correct README.Debian
* Forgot build-dep on libtheora
* Must not depend on libxvidcore
* New upstream release
* new release.
* rc1 to become 0.90
* new pre-release
* new pre-release
* gtk bug fixed.
* new release.
* version bumped
* 0.60 pre2 release
* 0.60 pre-release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * Copyright (c) 2004 Michael Niedermayer <michaelni@gmx.at>
3
 
 *
4
 
 * This file is part of Libav.
5
 
 *
6
 
 * Libav is free software; you can redistribute it and/or
7
 
 * modify it under the terms of the GNU Lesser General Public
8
 
 * License as published by the Free Software Foundation; either
9
 
 * version 2.1 of the License, or (at your option) any later version.
10
 
 *
11
 
 * Libav is distributed in the hope that it will be useful,
12
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14
 
 * Lesser General Public License for more details.
15
 
 *
16
 
 * You should have received a copy of the GNU Lesser General Public
17
 
 * License along with Libav; if not, write to the Free Software
18
 
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19
 
 */
20
 
//#define DEBUG
21
 
 
22
 
#include "avcodec.h"
23
 
#include "thread.h"
24
 
 
25
 
#define WIN32_LEAN_AND_MEAN
26
 
#include <windows.h>
27
 
#include <process.h>
28
 
 
29
 
typedef struct ThreadContext{
30
 
    AVCodecContext *avctx;
31
 
    HANDLE thread;
32
 
    HANDLE work_sem;
33
 
    HANDLE job_sem;
34
 
    HANDLE done_sem;
35
 
    int (*func)(AVCodecContext *c, void *arg);
36
 
    int (*func2)(AVCodecContext *c, void *arg, int, int);
37
 
    void *arg;
38
 
    int argsize;
39
 
    int *jobnr;
40
 
    int *ret;
41
 
    int threadnr;
42
 
}ThreadContext;
43
 
 
44
 
 
45
 
static unsigned WINAPI attribute_align_arg thread_func(void *v){
46
 
    ThreadContext *c= v;
47
 
 
48
 
    for(;;){
49
 
        int ret, jobnr;
50
 
//printf("thread_func %X enter wait\n", (int)v); fflush(stdout);
51
 
        WaitForSingleObject(c->work_sem, INFINITE);
52
 
        // avoid trying to access jobnr if we should quit
53
 
        if (!c->func && !c->func2)
54
 
            break;
55
 
        WaitForSingleObject(c->job_sem, INFINITE);
56
 
        jobnr = (*c->jobnr)++;
57
 
        ReleaseSemaphore(c->job_sem, 1, 0);
58
 
//printf("thread_func %X after wait (func=%X)\n", (int)v, (int)c->func); fflush(stdout);
59
 
        if(c->func)
60
 
            ret= c->func(c->avctx, (uint8_t *)c->arg + jobnr*c->argsize);
61
 
        else
62
 
            ret= c->func2(c->avctx, c->arg, jobnr, c->threadnr);
63
 
        if (c->ret)
64
 
            c->ret[jobnr] = ret;
65
 
//printf("thread_func %X signal complete\n", (int)v); fflush(stdout);
66
 
        ReleaseSemaphore(c->done_sem, 1, 0);
67
 
    }
68
 
 
69
 
    return 0;
70
 
}
71
 
 
72
 
/**
73
 
 * Free what has been allocated by ff_thread_init().
74
 
 * Must be called after decoding has finished, especially do not call while avcodec_thread_execute() is running.
75
 
 */
76
 
void ff_thread_free(AVCodecContext *s){
77
 
    ThreadContext *c= s->thread_opaque;
78
 
    int i;
79
 
 
80
 
    for(i=0; i<s->thread_count; i++){
81
 
 
82
 
        c[i].func= NULL;
83
 
        c[i].func2= NULL;
84
 
    }
85
 
    ReleaseSemaphore(c[0].work_sem, s->thread_count, 0);
86
 
    for(i=0; i<s->thread_count; i++){
87
 
        WaitForSingleObject(c[i].thread, INFINITE);
88
 
        if(c[i].thread)   CloseHandle(c[i].thread);
89
 
    }
90
 
    if(c[0].work_sem) CloseHandle(c[0].work_sem);
91
 
    if(c[0].job_sem)  CloseHandle(c[0].job_sem);
92
 
    if(c[0].done_sem) CloseHandle(c[0].done_sem);
93
 
 
94
 
    av_freep(&s->thread_opaque);
95
 
}
96
 
 
97
 
static int avcodec_thread_execute(AVCodecContext *s, int (*func)(AVCodecContext *c2, void *arg2),void *arg, int *ret, int count, int size){
98
 
    ThreadContext *c= s->thread_opaque;
99
 
    int i;
100
 
    int jobnr = 0;
101
 
 
102
 
    assert(s == c->avctx);
103
 
 
104
 
    /* note, we can be certain that this is not called with the same AVCodecContext by different threads at the same time */
105
 
 
106
 
    for(i=0; i<s->thread_count; i++){
107
 
        c[i].arg= arg;
108
 
        c[i].argsize= size;
109
 
        c[i].func= func;
110
 
        c[i].ret= ret;
111
 
        c[i].jobnr = &jobnr;
112
 
    }
113
 
    ReleaseSemaphore(c[0].work_sem, count, 0);
114
 
    for(i=0; i<count; i++)
115
 
        WaitForSingleObject(c[0].done_sem, INFINITE);
116
 
 
117
 
    return 0;
118
 
}
119
 
 
120
 
static int avcodec_thread_execute2(AVCodecContext *s, int (*func)(AVCodecContext *c2, void *arg2, int, int),void *arg, int *ret, int count){
121
 
    ThreadContext *c= s->thread_opaque;
122
 
    int i;
123
 
    for(i=0; i<s->thread_count; i++)
124
 
        c[i].func2 = func;
125
 
    avcodec_thread_execute(s, NULL, arg, ret, count, 0);
126
 
}
127
 
 
128
 
int ff_thread_init(AVCodecContext *s){
129
 
    int i;
130
 
    ThreadContext *c;
131
 
    uint32_t threadid;
132
 
 
133
 
    if(!(s->thread_type & FF_THREAD_SLICE)){
134
 
        av_log(s, AV_LOG_WARNING, "The requested thread algorithm is not supported with this thread library.\n");
135
 
        return 0;
136
 
    }
137
 
 
138
 
    s->active_thread_type= FF_THREAD_SLICE;
139
 
 
140
 
    if (s->thread_count <= 1)
141
 
        return 0;
142
 
 
143
 
    assert(!s->thread_opaque);
144
 
    c= av_mallocz(sizeof(ThreadContext)*s->thread_count);
145
 
    s->thread_opaque= c;
146
 
    if(!(c[0].work_sem = CreateSemaphore(NULL, 0, INT_MAX, NULL)))
147
 
        goto fail;
148
 
    if(!(c[0].job_sem  = CreateSemaphore(NULL, 1, 1, NULL)))
149
 
        goto fail;
150
 
    if(!(c[0].done_sem = CreateSemaphore(NULL, 0, INT_MAX, NULL)))
151
 
        goto fail;
152
 
 
153
 
    for(i=0; i<s->thread_count; i++){
154
 
//printf("init semaphors %d\n", i); fflush(stdout);
155
 
        c[i].avctx= s;
156
 
        c[i].work_sem = c[0].work_sem;
157
 
        c[i].job_sem  = c[0].job_sem;
158
 
        c[i].done_sem = c[0].done_sem;
159
 
        c[i].threadnr = i;
160
 
 
161
 
//printf("create thread %d\n", i); fflush(stdout);
162
 
        c[i].thread = (HANDLE)_beginthreadex(NULL, 0, thread_func, &c[i], 0, &threadid );
163
 
        if( !c[i].thread ) goto fail;
164
 
    }
165
 
//printf("init done\n"); fflush(stdout);
166
 
 
167
 
    s->execute= avcodec_thread_execute;
168
 
    s->execute2= avcodec_thread_execute2;
169
 
 
170
 
    return 0;
171
 
fail:
172
 
    ff_thread_free(s);
173
 
    return -1;
174
 
}