annotate src/_gcommand.h @ 3194:9fcb7abf3185 default tip

Remove some gcc 4.7.2 compiler warnings
author Lenard Lindstrom <len-l@telus.net>
date Tue, 23 Apr 2013 19:53:36 -0700
parents ecec7d7c1642
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1935
ecec7d7c1642 Merged tylerthemovie branch changes r2168:2614 into the trunk
zeroth
parents:
diff changeset
1 /*
ecec7d7c1642 Merged tylerthemovie branch changes r2168:2614 into the trunk
zeroth
parents:
diff changeset
2 pygame - Python Game Library
ecec7d7c1642 Merged tylerthemovie branch changes r2168:2614 into the trunk
zeroth
parents:
diff changeset
3
ecec7d7c1642 Merged tylerthemovie branch changes r2168:2614 into the trunk
zeroth
parents:
diff changeset
4 This library is free software; you can redistribute it and/or
ecec7d7c1642 Merged tylerthemovie branch changes r2168:2614 into the trunk
zeroth
parents:
diff changeset
5 modify it under the terms of the GNU Library General Public
ecec7d7c1642 Merged tylerthemovie branch changes r2168:2614 into the trunk
zeroth
parents:
diff changeset
6 License as published by the Free Software Foundation; either
ecec7d7c1642 Merged tylerthemovie branch changes r2168:2614 into the trunk
zeroth
parents:
diff changeset
7 version 2 of the License, or (at your option) any later version.
ecec7d7c1642 Merged tylerthemovie branch changes r2168:2614 into the trunk
zeroth
parents:
diff changeset
8
ecec7d7c1642 Merged tylerthemovie branch changes r2168:2614 into the trunk
zeroth
parents:
diff changeset
9 This library is distributed in the hope that it will be useful,
ecec7d7c1642 Merged tylerthemovie branch changes r2168:2614 into the trunk
zeroth
parents:
diff changeset
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
ecec7d7c1642 Merged tylerthemovie branch changes r2168:2614 into the trunk
zeroth
parents:
diff changeset
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
ecec7d7c1642 Merged tylerthemovie branch changes r2168:2614 into the trunk
zeroth
parents:
diff changeset
12 Library General Public License for more details.
ecec7d7c1642 Merged tylerthemovie branch changes r2168:2614 into the trunk
zeroth
parents:
diff changeset
13
ecec7d7c1642 Merged tylerthemovie branch changes r2168:2614 into the trunk
zeroth
parents:
diff changeset
14 You should have received a copy of the GNU Library General Public
ecec7d7c1642 Merged tylerthemovie branch changes r2168:2614 into the trunk
zeroth
parents:
diff changeset
15 License along with this library; if not, write to the Free
ecec7d7c1642 Merged tylerthemovie branch changes r2168:2614 into the trunk
zeroth
parents:
diff changeset
16 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
ecec7d7c1642 Merged tylerthemovie branch changes r2168:2614 into the trunk
zeroth
parents:
diff changeset
17
ecec7d7c1642 Merged tylerthemovie branch changes r2168:2614 into the trunk
zeroth
parents:
diff changeset
18 */
ecec7d7c1642 Merged tylerthemovie branch changes r2168:2614 into the trunk
zeroth
parents:
diff changeset
19
ecec7d7c1642 Merged tylerthemovie branch changes r2168:2614 into the trunk
zeroth
parents:
diff changeset
20 /*
ecec7d7c1642 Merged tylerthemovie branch changes r2168:2614 into the trunk
zeroth
parents:
diff changeset
21 * _movie - movie support for pygame with ffmpeg
ecec7d7c1642 Merged tylerthemovie branch changes r2168:2614 into the trunk
zeroth
parents:
diff changeset
22 * Author: Tyler Laing
ecec7d7c1642 Merged tylerthemovie branch changes r2168:2614 into the trunk
zeroth
parents:
diff changeset
23 *
ecec7d7c1642 Merged tylerthemovie branch changes r2168:2614 into the trunk
zeroth
parents:
diff changeset
24 * This module allows for the loading of, playing, pausing, stopping, and so on
ecec7d7c1642 Merged tylerthemovie branch changes r2168:2614 into the trunk
zeroth
parents:
diff changeset
25 * of a video file. Any format supported by ffmpeg is supported by this
ecec7d7c1642 Merged tylerthemovie branch changes r2168:2614 into the trunk
zeroth
parents:
diff changeset
26 * video player. Any bugs, please email trinioler@gmail.com :)
ecec7d7c1642 Merged tylerthemovie branch changes r2168:2614 into the trunk
zeroth
parents:
diff changeset
27 */
ecec7d7c1642 Merged tylerthemovie branch changes r2168:2614 into the trunk
zeroth
parents:
diff changeset
28
ecec7d7c1642 Merged tylerthemovie branch changes r2168:2614 into the trunk
zeroth
parents:
diff changeset
29
ecec7d7c1642 Merged tylerthemovie branch changes r2168:2614 into the trunk
zeroth
parents:
diff changeset
30 #ifndef _GCOMMAND_H_
ecec7d7c1642 Merged tylerthemovie branch changes r2168:2614 into the trunk
zeroth
parents:
diff changeset
31 #define _GCOMMAND_H_
ecec7d7c1642 Merged tylerthemovie branch changes r2168:2614 into the trunk
zeroth
parents:
diff changeset
32 #include <SDL.h>
ecec7d7c1642 Merged tylerthemovie branch changes r2168:2614 into the trunk
zeroth
parents:
diff changeset
33 #include <SDL_thread.h>
ecec7d7c1642 Merged tylerthemovie branch changes r2168:2614 into the trunk
zeroth
parents:
diff changeset
34 #include <Python.h>
ecec7d7c1642 Merged tylerthemovie branch changes r2168:2614 into the trunk
zeroth
parents:
diff changeset
35
ecec7d7c1642 Merged tylerthemovie branch changes r2168:2614 into the trunk
zeroth
parents:
diff changeset
36
ecec7d7c1642 Merged tylerthemovie branch changes r2168:2614 into the trunk
zeroth
parents:
diff changeset
37 /* Documentation: Command Queue Infrastructure
ecec7d7c1642 Merged tylerthemovie branch changes r2168:2614 into the trunk
zeroth
parents:
diff changeset
38 * This lower-level infrastructure code is meant to provide greater stability and
ecec7d7c1642 Merged tylerthemovie branch changes r2168:2614 into the trunk
zeroth
parents:
diff changeset
39 * thread safety to the _movie module. Since we cannot manipulate the SDL event queue
ecec7d7c1642 Merged tylerthemovie branch changes r2168:2614 into the trunk
zeroth
parents:
diff changeset
40 * we have to use our own hand-rolled solution. It is just a singly linked list,
ecec7d7c1642 Merged tylerthemovie branch changes r2168:2614 into the trunk
zeroth
parents:
diff changeset
41 * with references to the first and last item, allowing us to do a
ecec7d7c1642 Merged tylerthemovie branch changes r2168:2614 into the trunk
zeroth
parents:
diff changeset
42 * simple push/pop implementation. The items in the list are structs that have
ecec7d7c1642 Merged tylerthemovie branch changes r2168:2614 into the trunk
zeroth
parents:
diff changeset
43 * all the first members of the default Command struct, making it safe to
ecec7d7c1642 Merged tylerthemovie branch changes r2168:2614 into the trunk
zeroth
parents:
diff changeset
44 * cast the pointers from the pseudo-Command structs to a pointer to
ecec7d7c1642 Merged tylerthemovie branch changes r2168:2614 into the trunk
zeroth
parents:
diff changeset
45 * Command struct. Realistically, you can cast any pointer to any other kind of
ecec7d7c1642 Merged tylerthemovie branch changes r2168:2614 into the trunk
zeroth
parents:
diff changeset
46 * pointer(as long as they are the same size!), and C will let you. This is dangerous,
ecec7d7c1642 Merged tylerthemovie branch changes r2168:2614 into the trunk
zeroth
parents:
diff changeset
47 * and should only be done very, very carefully. This facility is only useful
ecec7d7c1642 Merged tylerthemovie branch changes r2168:2614 into the trunk
zeroth
parents:
diff changeset
48 * when you need a OO approach, like we did here.
ecec7d7c1642 Merged tylerthemovie branch changes r2168:2614 into the trunk
zeroth
parents:
diff changeset
49 *
ecec7d7c1642 Merged tylerthemovie branch changes r2168:2614 into the trunk
zeroth
parents:
diff changeset
50 * When making new commands, use the FULL_COMMAND macro, and add a line to registerCommands
ecec7d7c1642 Merged tylerthemovie branch changes r2168:2614 into the trunk
zeroth
parents:
diff changeset
51 * in _gmovie.c to add a new type value. This also enables future proofing as any changes to
ecec7d7c1642 Merged tylerthemovie branch changes r2168:2614 into the trunk
zeroth
parents:
diff changeset
52 * the Command struct will be opaque to the user... mostly.
ecec7d7c1642 Merged tylerthemovie branch changes r2168:2614 into the trunk
zeroth
parents:
diff changeset
53 *
ecec7d7c1642 Merged tylerthemovie branch changes r2168:2614 into the trunk
zeroth
parents:
diff changeset
54 * -Tyler Laing, August 4th, 2009
ecec7d7c1642 Merged tylerthemovie branch changes r2168:2614 into the trunk
zeroth
parents:
diff changeset
55 */
ecec7d7c1642 Merged tylerthemovie branch changes r2168:2614 into the trunk
zeroth
parents:
diff changeset
56
ecec7d7c1642 Merged tylerthemovie branch changes r2168:2614 into the trunk
zeroth
parents:
diff changeset
57 typedef struct Command
ecec7d7c1642 Merged tylerthemovie branch changes r2168:2614 into the trunk
zeroth
parents:
diff changeset
58 {
ecec7d7c1642 Merged tylerthemovie branch changes r2168:2614 into the trunk
zeroth
parents:
diff changeset
59 int type;
ecec7d7c1642 Merged tylerthemovie branch changes r2168:2614 into the trunk
zeroth
parents:
diff changeset
60 struct Command *next;
ecec7d7c1642 Merged tylerthemovie branch changes r2168:2614 into the trunk
zeroth
parents:
diff changeset
61 } Command;
ecec7d7c1642 Merged tylerthemovie branch changes r2168:2614 into the trunk
zeroth
parents:
diff changeset
62
ecec7d7c1642 Merged tylerthemovie branch changes r2168:2614 into the trunk
zeroth
parents:
diff changeset
63 #define FULL_COMMAND \
ecec7d7c1642 Merged tylerthemovie branch changes r2168:2614 into the trunk
zeroth
parents:
diff changeset
64 int type;\
ecec7d7c1642 Merged tylerthemovie branch changes r2168:2614 into the trunk
zeroth
parents:
diff changeset
65 struct Command *next;
ecec7d7c1642 Merged tylerthemovie branch changes r2168:2614 into the trunk
zeroth
parents:
diff changeset
66
ecec7d7c1642 Merged tylerthemovie branch changes r2168:2614 into the trunk
zeroth
parents:
diff changeset
67 typedef struct CommandQueue
ecec7d7c1642 Merged tylerthemovie branch changes r2168:2614 into the trunk
zeroth
parents:
diff changeset
68 {
ecec7d7c1642 Merged tylerthemovie branch changes r2168:2614 into the trunk
zeroth
parents:
diff changeset
69 int size;
ecec7d7c1642 Merged tylerthemovie branch changes r2168:2614 into the trunk
zeroth
parents:
diff changeset
70 SDL_mutex *q_mutex;
ecec7d7c1642 Merged tylerthemovie branch changes r2168:2614 into the trunk
zeroth
parents:
diff changeset
71 Command *first;
ecec7d7c1642 Merged tylerthemovie branch changes r2168:2614 into the trunk
zeroth
parents:
diff changeset
72 Command *last;
ecec7d7c1642 Merged tylerthemovie branch changes r2168:2614 into the trunk
zeroth
parents:
diff changeset
73 int registry[1024];
ecec7d7c1642 Merged tylerthemovie branch changes r2168:2614 into the trunk
zeroth
parents:
diff changeset
74 int reg_ix;
ecec7d7c1642 Merged tylerthemovie branch changes r2168:2614 into the trunk
zeroth
parents:
diff changeset
75 } CommandQueue;
ecec7d7c1642 Merged tylerthemovie branch changes r2168:2614 into the trunk
zeroth
parents:
diff changeset
76
ecec7d7c1642 Merged tylerthemovie branch changes r2168:2614 into the trunk
zeroth
parents:
diff changeset
77
ecec7d7c1642 Merged tylerthemovie branch changes r2168:2614 into the trunk
zeroth
parents:
diff changeset
78 void addCommand(CommandQueue *q, Command *comm);
ecec7d7c1642 Merged tylerthemovie branch changes r2168:2614 into the trunk
zeroth
parents:
diff changeset
79 Command *getCommand(CommandQueue *q);
ecec7d7c1642 Merged tylerthemovie branch changes r2168:2614 into the trunk
zeroth
parents:
diff changeset
80 int hasCommand(CommandQueue *q);
ecec7d7c1642 Merged tylerthemovie branch changes r2168:2614 into the trunk
zeroth
parents:
diff changeset
81 void flushCommands(CommandQueue *q);
ecec7d7c1642 Merged tylerthemovie branch changes r2168:2614 into the trunk
zeroth
parents:
diff changeset
82 int registerCommand(CommandQueue *q);
ecec7d7c1642 Merged tylerthemovie branch changes r2168:2614 into the trunk
zeroth
parents:
diff changeset
83
ecec7d7c1642 Merged tylerthemovie branch changes r2168:2614 into the trunk
zeroth
parents:
diff changeset
84 //convience function for allocating a new command, and ensuring its type is set properly.
ecec7d7c1642 Merged tylerthemovie branch changes r2168:2614 into the trunk
zeroth
parents:
diff changeset
85 #define ALLOC_COMMAND(command, name) command* name = (command *)PyMem_Malloc(sizeof(command)); name->type=movie->command##Type;
ecec7d7c1642 Merged tylerthemovie branch changes r2168:2614 into the trunk
zeroth
parents:
diff changeset
86
ecec7d7c1642 Merged tylerthemovie branch changes r2168:2614 into the trunk
zeroth
parents:
diff changeset
87 #endif /*_GCOMMAND_H_*/