annotate decoders/quicktime.c @ 326:1b33baef9bf9

Added seek method.
author Ryan C. Gordon <icculus@icculus.org>
date Mon, 20 May 2002 06:40:10 +0000
parents df024df56996
children a7c1dbcf5e00
rev   line source
318
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1 /*
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2 * SDL_sound -- An abstract sound format decoding API.
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
3 * Copyright (C) 2001 Ryan C. Gordon.
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
4 *
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
5 * This library is free software; you can redistribute it and/or
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
6 * modify it under the terms of the GNU Lesser General Public
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
7 * License as published by the Free Software Foundation; either
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
8 * version 2.1 of the License, or (at your option) any later version.
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
9 *
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
10 * This library is distributed in the hope that it will be useful,
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
13 * Lesser General Public License for more details.
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
14 *
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
15 * You should have received a copy of the GNU Lesser General Public
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
16 * License along with this library; if not, write to the Free Software
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
18 */
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
19
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
20 /*
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
21 * QuickTime decoder for sound formats that QuickTime supports.
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
22 * April 28, 2002
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
23 *
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
24 * This driver handles .mov files with a sound track. In
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
25 * theory, it could handle any format that QuickTime supports.
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
26 * In practice, it may only handle a select few of these formats.
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
27 *
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
28 * It seems able to play back AIFF and other standard Mac formats.
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
29 * Rewinding is not supported yet.
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
30 *
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
31 * The routine QT_create_data_ref() needs to be
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
32 * tweaked to support different media types.
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
33 * This code was originally written to get MP3 support,
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
34 * as it turns out, this isn't possible using this method.
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
35 *
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
36 * The only way to get streaming MP3 support through QuickTime,
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
37 * and hence support for SDL_RWops, is to write
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
38 * a DataHandler component, which suddenly gets much more difficult :-(
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
39 *
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
40 * This file was written by Darrell Walisser (walisser@mac.com)
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
41 * Portions have been borrowed from the "MP3Player" sample code,
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
42 * courtesy of Apple.
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
43 */
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
44
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
45 #if HAVE_CONFIG_H
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
46 # include <config.h>
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
47 #endif
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
48
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
49 #ifdef SOUND_SUPPORTS_QUICKTIME
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
50 #ifdef macintosh
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
51 typedef long int32_t;
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
52 # define OPAQUE_UPP_TYPES 0
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
53 # include <QuickTime.h>
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
54 #else
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
55 # include <QuickTime/QuickTime.h>
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
56 # include <Carbon/Carbon.h>
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
57 #endif
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
58
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
59 #include <stdio.h>
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
60 #include <stdlib.h>
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
61 #include <stdint.h>
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
62 #include <string.h>
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
63 #include <assert.h>
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
64
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
65 #include "SDL_sound.h"
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
66
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
67 #define __SDL_SOUND_INTERNAL__
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
68 #include "SDL_sound_internal.h"
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
69
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
70 static int QT_init(void);
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
71 static void QT_quit(void);
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
72 static int QT_open(Sound_Sample *sample, const char *ext);
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
73 static void QT_close(Sound_Sample *sample);
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
74 static Uint32 QT_read(Sound_Sample *sample);
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
75 static int QT_rewind(Sound_Sample *sample);
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
76
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
77 #define QT_MAX_INPUT_BUFFER (32*1024) /* Maximum size of internal buffer (internal->buffer_size) */
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
78
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
79 static const char *extensions_quicktime[] = { "mov", NULL };
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
80 const Sound_DecoderFunctions __Sound_DecoderFunctions_QuickTime =
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
81 {
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
82 {
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
83 extensions_quicktime,
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
84 "QuickTime format",
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
85 "Darrell Walisser <dwaliss1@purdue.edu>",
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
86 "http://www.icculus.org/SDL_sound/"
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
87 },
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
88
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
89 QT_init, /* init() method */
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
90 QT_quit, /* quit() method */
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
91 QT_open, /* open() method */
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
92 QT_close, /* close() method */
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
93 QT_read, /* read() method */
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
94 QT_rewind /* rewind() method */
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
95 };
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
96
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
97 typedef struct {
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
98
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
99 ExtendedSoundComponentData compData;
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
100 Handle hSource; /* source media buffer */
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
101 Media sourceMedia; /* sound media identifier */
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
102 TimeValue getMediaAtThisTime;
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
103 TimeValue sourceDuration;
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
104 Boolean isThereMoreSource;
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
105 UInt32 maxBufferSize;
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
106
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
107 } SCFillBufferData, *SCFillBufferDataPtr;
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
108
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
109 typedef struct {
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
110
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
111 Movie movie;
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
112 Track track;
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
113 Media media;
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
114 AudioFormatAtomPtr atom;
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
115 SoundComponentData source_format;
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
116 SoundComponentData dest_format;
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
117 SoundConverter converter;
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
118 SCFillBufferData buffer_data;
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
119 SoundConverterFillBufferDataUPP fill_buffer_proc;
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
120
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
121 } qt_t;
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
122
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
123
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
124
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
125
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
126 /*
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
127 * This procedure creates a description of the raw data
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
128 * read from SDL_RWops so that QuickTime can identify
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
129 * the codec it needs to use to decompress it.
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
130 */
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
131 static Handle QT_create_data_ref (const char *file_extension) {
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
132
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
133 Handle tmp_handle, data_ref;
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
134 StringPtr file_name = "\p"; /* empty since we don't know the file name! */
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
135 OSType file_type;
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
136 StringPtr mime_type;
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
137 long atoms[3];
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
138
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
139 /*
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
140 if (__Sound_strcasecmp (file_extension, "mp3")==0) {
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
141 file_type = 'MPEG';
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
142 mime_type = "\pvideo/mpeg";
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
143 }
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
144 else {
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
145
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
146 return NULL;
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
147 }
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
148 */
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
149
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
150 if (__Sound_strcasecmp (file_extension, "mov") == 0) {
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
151
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
152 file_type = 'MooV';
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
153 mime_type = "\pvideo/quicktime";
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
154 }
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
155 else {
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
156
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
157 return NULL;
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
158 }
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
159
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
160 tmp_handle = NewHandle(0);
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
161 assert (tmp_handle != NULL);
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
162 assert (noErr == PtrToHand (&tmp_handle, &data_ref, sizeof(Handle)));
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
163 assert (noErr == PtrAndHand (file_name, data_ref, file_name[0]+1));
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
164
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
165 atoms[0] = EndianU32_NtoB (sizeof(long) * 3);
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
166 atoms[1] = EndianU32_NtoB (kDataRefExtensionMacOSFileType);
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
167 atoms[2] = EndianU32_NtoB (file_type);
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
168
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
169 assert (noErr == PtrAndHand (atoms, data_ref, sizeof(long)*3));
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
170
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
171 atoms[0] = EndianU32_NtoB (sizeof(long)*2 + mime_type[0]+1);
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
172 atoms[1] = EndianU32_NtoB (kDataRefExtensionMIMEType);
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
173
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
174 assert (noErr == PtrAndHand (atoms, data_ref, sizeof(long)*2));
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
175 assert (noErr == PtrAndHand (mime_type, data_ref, mime_type[0]+1));
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
176
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
177 return data_ref;
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
178 }
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
179
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
180 /*
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
181 * This procedure is a hook for QuickTime to grab data from the
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
182 * SDL_RWOps data structure when it needs it
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
183 */
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
184 static pascal OSErr QT_get_movie_data_proc (long offset, long size,
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
185 void *data, void *user_data)
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
186 {
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
187 SDL_RWops* rw = (SDL_RWops*)user_data;
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
188 OSErr error;
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
189
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
190 if (offset == SDL_RWseek (rw, offset, SEEK_SET)) {
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
191
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
192 if (size == SDL_RWread (rw, data, 1, size)) {
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
193 error = noErr;
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
194 }
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
195 else {
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
196 error = notEnoughDataErr;
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
197 }
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
198 }
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
199 else {
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
200 error = fileOffsetTooBigErr;
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
201 }
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
202
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
203 return (error);
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
204 }
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
205
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
206 /* * ----------------------------
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
207 * SoundConverterFillBufferDataProc
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
208 *
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
209 * the callback routine that provides the source data for conversion -
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
210 * it provides data by setting outData to a pointer to a properly
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
211 * filled out ExtendedSoundComponentData structure
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
212 */
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
213 static pascal Boolean QT_sound_converter_fill_buffer_data_proc (SoundComponentDataPtr *outData, void *inRefCon)
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
214 {
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
215 SCFillBufferDataPtr pFillData = (SCFillBufferDataPtr)inRefCon;
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
216
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
217 OSErr err = noErr;
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
218
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
219 /* if after getting the last chunk of data the total time is over
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
220 * the duration, we're done
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
221 */
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
222 if (pFillData->getMediaAtThisTime >= pFillData->sourceDuration) {
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
223 pFillData->isThereMoreSource = false;
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
224 pFillData->compData.desc.buffer = NULL;
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
225 pFillData->compData.desc.sampleCount = 0;
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
226 pFillData->compData.bufferSize = 0;
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
227 }
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
228
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
229 if (pFillData->isThereMoreSource) {
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
230
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
231 long sourceBytesReturned;
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
232 long numberOfSamples;
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
233 TimeValue sourceReturnedTime, durationPerSample;
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
234
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
235 HUnlock(pFillData->hSource);
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
236
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
237 err = GetMediaSample
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
238 (pFillData->sourceMedia,/* specifies the media for this operation */
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
239 pFillData->hSource, /* function returns the sample data into this handle */
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
240 pFillData->maxBufferSize, /* maximum number of bytes of sample data to be returned */
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
241 &sourceBytesReturned, /* the number of bytes of sample data returned */
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
242 pFillData->getMediaAtThisTime,/* starting time of the sample to
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
243 be retrieved (must be in
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
244 Media's TimeScale) */
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
245 &sourceReturnedTime,/* indicates the actual time of the returned sample data */
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
246 &durationPerSample, /* duration of each sample in the media */
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
247 NULL, /* sample description corresponding to the returned sample data (NULL to ignore) */
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
248 NULL, /* index value to the sample description that corresponds
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
249 to the returned sample data (NULL to ignore) */
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
250 0, /* maximum number of samples to be returned (0 to use a
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
251 value that is appropriate for the media) */
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
252 &numberOfSamples, /* number of samples it actually returned */
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
253 NULL); /* flags that describe the sample (NULL to ignore) */
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
254
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
255 HLock(pFillData->hSource);
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
256
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
257 if ((noErr != err) || (sourceBytesReturned == 0)) {
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
258 pFillData->isThereMoreSource = false;
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
259 pFillData->compData.desc.buffer = NULL;
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
260 pFillData->compData.desc.sampleCount = 0;
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
261
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
262 if ((err != noErr) && (sourceBytesReturned > 0))
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
263 DebugStr("\pGetMediaSample - Failed in FillBufferDataProc");
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
264 }
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
265
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
266 pFillData->getMediaAtThisTime = sourceReturnedTime + (durationPerSample * numberOfSamples);
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
267 pFillData->compData.bufferSize = sourceBytesReturned;
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
268 }
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
269
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
270 /* set outData to a properly filled out ExtendedSoundComponentData struct */
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
271 *outData = (SoundComponentDataPtr)&pFillData->compData;
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
272
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
273 return (pFillData->isThereMoreSource);
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
274 }
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
275
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
276
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
277 static int QT_init_internal () {
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
278
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
279 OSErr error;
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
280
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
281 error = EnterMovies(); /* initialize the movie toolbox */
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
282
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
283 return (error == noErr);
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
284 }
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
285
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
286 static void QT_quit_internal () {
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
287
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
288 ExitMovies();
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
289 }
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
290
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
291 static qt_t* QT_open_internal (Sound_Sample *sample, const char *extension)
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
292 {
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
293 Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque;
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
294
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
295 qt_t *instance;
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
296 OSErr error;
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
297 Movie movie;
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
298 Track sound_track;
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
299 Media sound_track_media;
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
300 AudioFormatAtomPtr source_sound_decomp_atom;
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
301
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
302 SoundDescriptionV1Handle source_sound_description;
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
303 Handle source_sound_description_extension;
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
304 Size source_sound_description_extension_size;
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
305 Handle data_ref;
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
306
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
307 data_ref = QT_create_data_ref (extension);
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
308
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
309 /* create a movie that will read data using SDL_RWops */
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
310 error = NewMovieFromUserProc
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
311 (&movie,
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
312 0,
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
313 NULL,
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
314 NewGetMovieUPP(QT_get_movie_data_proc),
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
315 (void*) internal->rw,
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
316 data_ref,
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
317 'hndl');
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
318
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
319 if (error != noErr) {
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
320
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
321 return NULL;
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
322 }
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
323
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
324 /* get the first sound track of the movie; other tracks will be ignored */
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
325 sound_track = GetMovieIndTrackType (movie, 1, SoundMediaType, movieTrackMediaType);
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
326 if (sound_track == NULL) {
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
327
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
328 /* movie needs a sound track! */
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
329
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
330 return NULL;
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
331 }
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
332
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
333 /* get and return the sound track media */
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
334 sound_track_media = GetTrackMedia (sound_track);
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
335 if (sound_track_media == NULL) {
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
336
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
337 return NULL;
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
338 }
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
339
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
340 /* create a description of the source sound so we can convert it later */
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
341 source_sound_description = (SoundDescriptionV1Handle)NewHandle(0);
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
342 assert (source_sound_description != NULL); /* out of memory */
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
343
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
344 GetMediaSampleDescription (sound_track_media, 1,
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
345 (SampleDescriptionHandle)source_sound_description);
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
346 error = GetMoviesError();
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
347 if (error != noErr) {
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
348
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
349 return NULL;
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
350 }
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
351
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
352 source_sound_description_extension = NewHandle(0);
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
353 assert (source_sound_description_extension != NULL); /* out of memory */
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
354
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
355 error = GetSoundDescriptionExtension ((SoundDescriptionHandle) source_sound_description,
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
356 &source_sound_description_extension,
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
357 siDecompressionParams);
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
358
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
359 if (error == noErr) {
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
360
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
361 /* copy extension to atom format description if we have an extension */
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
362
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
363 source_sound_description_extension_size =
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
364 GetHandleSize (source_sound_description_extension);
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
365 HLock (source_sound_description_extension);
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
366
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
367 source_sound_decomp_atom = (AudioFormatAtom*)
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
368 NewPtr (source_sound_description_extension_size);
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
369 assert (source_sound_decomp_atom != NULL); /* out of memory */
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
370
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
371 BlockMoveData (*source_sound_description_extension,
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
372 source_sound_decomp_atom,
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
373 source_sound_description_extension_size);
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
374
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
375 HUnlock (source_sound_description_extension);
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
376 }
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
377
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
378 else {
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
379
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
380 source_sound_decomp_atom = NULL;
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
381 }
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
382
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
383 instance = (qt_t*) malloc (sizeof(*instance));
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
384 assert (instance != NULL); /* out of memory */
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
385
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
386 instance->movie = movie;
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
387 instance->track = sound_track;
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
388 instance->media = sound_track_media;
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
389 instance->atom = source_sound_decomp_atom;
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
390
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
391 instance->source_format.flags = 0;
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
392 instance->source_format.format = (*source_sound_description)->desc.dataFormat;
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
393 instance->source_format.numChannels = (*source_sound_description)->desc.numChannels;
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
394 instance->source_format.sampleSize = (*source_sound_description)->desc.sampleSize;
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
395 instance->source_format.sampleRate = (*source_sound_description)->desc.sampleRate;
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
396 instance->source_format.sampleCount = 0;
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
397 instance->source_format.buffer = NULL;
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
398 instance->source_format.reserved = 0;
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
399
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
400 instance->dest_format.flags = 0;
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
401 instance->dest_format.format = kSoundNotCompressed;
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
402 instance->dest_format.numChannels = (*source_sound_description)->desc.numChannels;
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
403 instance->dest_format.sampleSize = (*source_sound_description)->desc.sampleSize;
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
404 instance->dest_format.sampleRate = (*source_sound_description)->desc.sampleRate;
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
405 instance->dest_format.sampleCount = 0;
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
406 instance->dest_format.buffer = NULL;
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
407 instance->dest_format.reserved = 0;
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
408
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
409 sample->actual.channels = (*source_sound_description)->desc.numChannels;
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
410 sample->actual.rate = (*source_sound_description)->desc.sampleRate >> 16;
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
411
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
412 if ((*source_sound_description)->desc.sampleSize == 16) {
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
413
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
414 sample->actual.format = AUDIO_S16SYS;
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
415 }
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
416 else if ((*source_sound_description)->desc.sampleSize == 8) {
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
417
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
418 sample->actual.format = AUDIO_U8;
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
419 }
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
420 else {
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
421
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
422 /* 24-bit or others... (which SDL can't handle) */
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
423 return NULL;
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
424 }
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
425
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
426 DisposeHandle (source_sound_description_extension);
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
427 DisposeHandle ((Handle)source_sound_description);
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
428
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
429 /* This next code sets up the SoundConverter component */
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
430 error = SoundConverterOpen (&instance->source_format, &instance->dest_format,
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
431 &instance->converter);
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
432
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
433 if (error != noErr) {
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
434
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
435 return NULL;
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
436 }
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
437
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
438 error = SoundConverterSetInfo (instance->converter, siDecompressionParams,
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
439 instance->atom);
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
440 if (error == siUnknownInfoType) {
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
441
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
442 /* ignore */
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
443 }
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
444 else if (error != noErr) {
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
445
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
446 /* reall error */
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
447 return NULL;
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
448 }
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
449
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
450 error = SoundConverterBeginConversion (instance->converter);
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
451 if (error != noErr) {
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
452
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
453 return NULL;
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
454 }
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
455
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
456 instance->buffer_data.sourceMedia = instance->media;
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
457 instance->buffer_data.getMediaAtThisTime = 0;
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
458 instance->buffer_data.sourceDuration = GetMediaDuration(instance->media);
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
459 instance->buffer_data.isThereMoreSource = true;
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
460 instance->buffer_data.maxBufferSize = QT_MAX_INPUT_BUFFER;
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
461 /* allocate source media buffer */
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
462 instance->buffer_data.hSource = NewHandle((long)instance->buffer_data.maxBufferSize);
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
463 assert (instance->buffer_data.hSource != NULL); /* out of memory */
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
464
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
465 instance->buffer_data.compData.desc = instance->source_format;
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
466 instance->buffer_data.compData.desc.buffer = (Byte *)*instance->buffer_data.hSource;
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
467 instance->buffer_data.compData.desc.flags = kExtendedSoundData;
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
468 instance->buffer_data.compData.recordSize = sizeof(ExtendedSoundComponentData);
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
469 instance->buffer_data.compData.extendedFlags =
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
470 kExtendedSoundSampleCountNotValid | kExtendedSoundBufferSizeValid;
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
471 instance->buffer_data.compData.bufferSize = 0;
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
472
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
473 instance->fill_buffer_proc =
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
474 NewSoundConverterFillBufferDataUPP (QT_sound_converter_fill_buffer_data_proc);
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
475
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
476 return (instance);
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
477
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
478 } /* QT_open_internal */
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
479
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
480 static void QT_close_internal (qt_t *instance)
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
481 {
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
482
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
483 } /* QT_close_internal */
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
484
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
485 static Uint32 QT_read_internal(Sound_Sample *sample)
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
486 {
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
487 Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque;
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
488 qt_t *instance = (qt_t*) internal->decoder_private;
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
489 long output_bytes, output_frames, output_flags;
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
490 OSErr error;
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
491
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
492 error = SoundConverterFillBuffer
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
493 (instance->converter, /* a sound converter */
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
494 instance->fill_buffer_proc, /* the callback UPP */
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
495 &instance->buffer_data, /* refCon passed to FillDataProc */
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
496 internal->buffer, /* the decompressed data 'play' buffer */
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
497 internal->buffer_size, /* size of the 'play' buffer */
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
498 &output_bytes, /* number of output bytes */
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
499 &output_frames, /* number of output frames */
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
500 &output_flags); /* fillbuffer retured advisor flags */
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
501
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
502 if (output_flags & kSoundConverterHasLeftOverData) {
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
503
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
504 sample->flags |= SOUND_SAMPLEFLAG_EAGAIN;
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
505 }
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
506 else {
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
507
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
508 sample->flags |= SOUND_SAMPLEFLAG_EOF;
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
509 }
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
510
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
511 if (error != noErr) {
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
512
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
513 sample->flags |= SOUND_SAMPLEFLAG_ERROR;
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
514 }
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
515
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
516 return (output_bytes);
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
517
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
518 } /* QT_read_internal */
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
519
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
520 static int QT_rewind_internal (Sound_Sample *sample)
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
521 {
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
522
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
523 return 0;
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
524
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
525 } /* QT_rewind_internal */
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
526
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
527
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
528
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
529 static int QT_init(void)
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
530 {
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
531 return (QT_init_internal());
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
532
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
533 } /* QT_init */
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
534
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
535 static void QT_quit(void)
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
536 {
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
537 QT_quit_internal();
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
538
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
539 } /* QT_quit */
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
540
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
541 static int QT_open(Sound_Sample *sample, const char *ext)
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
542 {
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
543 Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque;
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
544 qt_t *instance;
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
545
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
546 instance = QT_open_internal(sample, ext);
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
547 internal->decoder_private = (void*)instance;
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
548
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
549 return(instance != NULL);
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
550
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
551 } /* QT_open */
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
552
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
553
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
554 static void QT_close(Sound_Sample *sample)
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
555 {
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
556 Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque;
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
557 qt_t *instance = (qt_t *) internal->decoder_private;
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
558
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
559 QT_close_internal (instance);
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
560
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
561 free (instance);
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
562
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
563 } /* QT_close */
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
564
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
565
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
566 static Uint32 QT_read(Sound_Sample *sample)
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
567 {
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
568 return(QT_read_internal(sample));
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
569
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
570 } /* QT_read */
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
571
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
572
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
573 static int QT_rewind(Sound_Sample *sample)
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
574 {
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
575
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
576 return(QT_rewind_internal(sample));
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
577
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
578 } /* QT_rewind */
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
579
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
580 #endif /* SOUND_SUPPORTS_QUICKTIME */
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
581
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
582 /* end of quicktime.c ... */
df024df56996 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
583