|
1849
|
1 /*
|
|
|
2 pygame - Python Game Library
|
|
|
3
|
|
|
4 This library is free software; you can redistribute it and/or
|
|
|
5 modify it under the terms of the GNU Library General Public
|
|
|
6 License as published by the Free Software Foundation; either
|
|
|
7 version 2 of the License, or (at your option) any later version.
|
|
|
8
|
|
|
9 This library 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 GNU
|
|
|
12 Library General Public License for more details.
|
|
|
13
|
|
|
14 You should have received a copy of the GNU Library General Public
|
|
|
15 License along with this library; if not, write to the Free
|
|
|
16 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
17
|
|
|
18 */
|
|
|
19
|
|
|
20 /*
|
|
|
21 * _movie - movie support for pygame with ffmpeg
|
|
|
22 * Author: Tyler Laing
|
|
|
23 *
|
|
|
24 * This module allows for the loading of, playing, pausing, stopping, and so on
|
|
|
25 * of a video file. Any format supported by ffmpeg is supported by this
|
|
|
26 * video player. Any bugs, please email trinioler@gmail.com :)
|
|
|
27 */
|
|
|
28
|
|
|
29 #include "_gcommand.h"
|
|
|
30
|
|
|
31 /* command queue management routines... I make a lot of queues, don't I? */
|
|
|
32 void addCommand(CommandQueue *q, Command *comm)
|
|
|
33 {
|
|
|
34 SDL_LockMutex(q->q_mutex);
|
|
|
35 comm->next=NULL;
|
|
|
36 q->registry[comm->type]++;
|
|
|
37 if(!q->size)
|
|
|
38 {
|
|
|
39 q->first=comm;
|
|
|
40 q->size++;
|
|
|
41 SDL_UnlockMutex(q->q_mutex);
|
|
|
42 return;
|
|
|
43 }
|
|
|
44 if(q->size==1)
|
|
|
45 {
|
|
|
46 q->last=comm;
|
|
|
47 q->first->next=comm;
|
|
|
48 q->size++;
|
|
|
49 SDL_UnlockMutex(q->q_mutex);
|
|
|
50 return;
|
|
|
51 }
|
|
|
52 q->last->next=comm;
|
|
|
53 q->last=comm;
|
|
|
54 q->size++;
|
|
|
55 SDL_UnlockMutex(q->q_mutex);
|
|
|
56 return;
|
|
|
57 }
|
|
|
58
|
|
|
59 Command *getCommand(CommandQueue *q)
|
|
|
60 {
|
|
|
61 SDL_LockMutex(q->q_mutex);
|
|
|
62 Command *comm;
|
|
|
63 if(!q->last && q->first)
|
|
|
64 {
|
|
|
65 comm=q->first;
|
|
|
66 q->size--;
|
|
|
67 SDL_UnlockMutex(q->q_mutex);
|
|
|
68 return comm;
|
|
|
69 }
|
|
|
70 else if (!q->last && !q->first)
|
|
|
71 {
|
|
|
72 SDL_UnlockMutex(q->q_mutex);
|
|
|
73 return NULL;
|
|
|
74 }
|
|
|
75 comm=q->first;
|
|
|
76 q->first=q->first->next;
|
|
|
77 q->size--;
|
|
|
78 SDL_UnlockMutex(q->q_mutex);
|
|
|
79 return comm;
|
|
|
80 }
|
|
|
81
|
|
|
82 inline int hasCommand(CommandQueue *q)
|
|
|
83 {
|
|
|
84 if(q->size>0)
|
|
|
85 return 1;
|
|
|
86 return 0;
|
|
|
87 }
|
|
|
88
|
|
|
89 void flushCommands(CommandQueue *q)
|
|
|
90 {
|
|
|
91 SDL_LockMutex(q->q_mutex);
|
|
|
92 Command *prev;
|
|
|
93 Command *cur = q->first;
|
|
|
94 while(cur!=NULL)
|
|
|
95 {
|
|
|
96 prev=cur;
|
|
|
97 cur=cur->next;
|
|
|
98 PyMem_Free(prev);
|
|
|
99 q->size--;
|
|
|
100 }
|
|
|
101 SDL_UnlockMutex(q->q_mutex);
|
|
|
102 }
|
|
|
103
|
|
|
104 /* registers a command with a particular movie object's command queue.
|
|
|
105 * Basically, this means, theoretically, different movie objects could have different commands...
|
|
|
106 */
|
|
|
107 int registerCommand(CommandQueue *q)
|
|
|
108 {
|
|
|
109 //int cur = q->reg_ix;
|
|
|
110 if(q->reg_ix>=1024)
|
|
|
111 q->reg_ix=0;
|
|
|
112 q->registry[q->reg_ix]=0;
|
|
|
113 q->reg_ix++;
|
|
|
114 return q->reg_ix-1;
|
|
|
115 }
|