Converted these images to PNG, saving a handful of bytes per image
[adiumx.git] / Plugins / QuickTime / QTPlugin.m
blob9131cb1e1a2b0d389883ecdf97058b0226dbd696
1 /* 
2  * Adium is the legal property of its developers, whose names are listed in the copyright file included
3  * with this source distribution.
4  * 
5  * This program is free software; you can redistribute it and/or modify it under the terms of the GNU
6  * General Public License as published by the Free Software Foundation; either version 2 of the License,
7  * or (at your option) any later version.
8  * 
9  * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
10  * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General
11  * Public License for more details.
12  * 
13  * You should have received a copy of the GNU General Public License along with this program; if not,
14  * write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
15  */
17 #import "QTPlugin.h"
19 #import <Adium/AIVideoConfControllerProtocol.h>
20 #import <Adium/AIPreferenceControllerProtocol.h>
21 #import <Adium/AIVideoConf.h>
22 #import <Adium/AIListObject.h>
23 #import <AIUtilities/AIDictionaryAdditions.h>
24 #import <AIUtilities/AIAttributedStringAdditions.h>
26 #import <QuickTime/QuickTime.h>
28 #import "QTConnection.h"
29 #import "QTRTPConnection.h"
30 #import "QTAdvancedPreferences.h"
32 /*!
33  * QuickTime plugin
34  */
35 @implementation QTPlugin
37 ////////////////////////////////////////////////////////////////////////////////
38 #pragma mark                     QuickTime Initialization
39 ////////////////////////////////////////////////////////////////////////////////
41 /*!
42  * Initialize QuickTime
43  */
44 - (void) startupQuickTime
46         NSLog(@"QuickTime startup");
47         EnterMovies();
50 /*!
51  * Shutdown QuickTime
52  */
53 - (void) shutdownQuickTime
55         NSLog(@"QuickTime shutdown");
56         ExitMovies();
59 ////////////////////////////////////////////////////////////////////////////////
60 #pragma mark                     QuickTime Properties
61 ////////////////////////////////////////////////////////////////////////////////
63 /*!
64  * @brief Set the mic volume
65  */
66 - (void) setDefaultMicVolumeTo: (int)volume
68         micVolume = volume;
71 /*!
72  * @brief Set the output volume
73  */
74 - (void) setDefaultOutVolumeTo: (int)volume
76         outVolume = volume;
79 /*!
80  * @brief Set the connection speed
81  */
82 - (void) setConnectionSpeed
84         OSErr err;
85         QTAtomContainer prefs;
86         QTAtom prefsAtom;
87         long dataSize;
88         Ptr atomData;
89         ConnectionSpeedPrefsRecord prefrec;
90         
91         err = GetQuickTimePreference (ConnectionSpeedPrefsType, &prefs);
92         if (err == noErr) {
93                 prefsAtom = QTFindChildByID (prefs,
94                                                                          kParentAtomIsContainer, 
95                                                                          ConnectionSpeedPrefsType,
96                                                                          1,
97                                                                          NULL);
98                 
99                 if (!prefsAtom) {
100                         // set the default setting to 28.8kpbs
101                         prefrec.connectionSpeed = kDataRate288ModemRate;
102                 } else {
103                         err = QTGetAtomDataPtr (prefs, prefsAtom, &dataSize, &atomData);
104                         if (dataSize != sizeof(ConnectionSpeedPrefsRecord)) {
105                                 // the prefs record wasn't the right size, 
106                                 // so it must be corrupt -- set to the default
107                                 prefrec.connectionSpeed = kDataRate288ModemRate;
108                         } else {
109                                 // everything was fine -- read the connection speed
110                                 prefrec = *(ConnectionSpeedPrefsRecord *)atomData;
111                         }
112                 }
113                 
114                 QTDisposeAtomContainer (prefs);
115         }
119 ////////////////////////////////////////////////////////////////////////////////
120 #pragma mark                  QuickTime General Information
121 ////////////////////////////////////////////////////////////////////////////////
122 - (NSArray*) getAudioPayloadsForProtocol:(VCProtocol)protocol
124         // So far, we only support RTP audio connections: get the list of payloads
125         // from there...
126         if (protocol == VC_RTP) {
127                 return [QTAudioRTPConnection getSupportedAudioPayloads];
128         } else {
129                 NSLog (@"Unsupported protocol in getAudioPayloadsForProtocol.");
130                 return nil;
131         }
134 - (NSArray*) getVideoPayloadsForProtocol:(VCProtocol)protocol
136         // TODO: we dont currently support any video codec...
137         NSLog (@"Warning: asking for video payloads to QTPlugin.");
138         return nil;
141 ////////////////////////////////////////////////////////////////////////////////
142 #pragma mark                      Connections Management
143 ////////////////////////////////////////////////////////////////////////////////
145  * Create a connection between two transport points, with the specified payload
146  * type. It should return the new connection, or nil if the protocol can not
147  * create this connection.
148  */
149 - (id) createConnectionWithProtocol:(VCProtocol)protocol
150                                                         payload:(VCPayload*)payload
151                                                            from:(VCTransport*)local
152                                                                  to:(VCTransport*)remote;
154         id<VCConnection> connection = nil;
155         
156         if (protocol == VC_RTP) {
157                 QTAudioRTPConnection    *rtpConnection;
159                 // Create the audio connection
160                 rtpConnection = [QTAudioRTPConnection createWithProtocol:protocol
161                                                                                                                  payload:payload
162                                                                                                                         from:local
163                                                                                                                           to:remote];
164                 // ...and set some media properties
165                 if(rtpConnection != nil) {
166                         [rtpConnection setMicVolumeTo:micVolume];
167                         [rtpConnection setOutVolumeTo:outVolume];                       
168                 } else {
169                         NSLog(@"Error: creating an RTP audio connection.");
170                 }
171                 
172                 connection = rtpConnection;
173         } else {
174                 NSLog(@"The supplied protocol is not supported yet.");
175         }
176         
177         return connection;
181  * Create a set of connections between several transport points, with the
182  * specified payload types. It should return "nil" if the protocol can not create
183  * these connections.
184  */
185 - (NSArray*) createConnectionsWithProtocol:(VCProtocol)protocol
186                                                                   payloads:(NSArray*)payload
187                                                                           from:(NSArray*)local
188                                                                                 to:(NSArray*)remote
190         NSLog(@"createConnectionsWithProtocol not implemented.");
191         return nil;
195 ////////////////////////////////////////////////////////////////////////////////
196 #pragma mark                     Plugin Management
197 ////////////////////////////////////////////////////////////////////////////////
200  * Install the plugin
201  */
202 - (void)installPlugin
204         // Observe workspace activity changes so we can mute sounds as necessary
205         NSNotificationCenter    *workspaceCenter;
206         
207         // Register this for some protocols
208         [[adium vcController] registerProvider:self forProtocol:VC_RTP];
209         
210     // Install some preferences
211         [[adium preferenceController] registerDefaults:[NSDictionary dictionaryNamed:QUICKTIME_PREFS
212                                                                                                                                                 forClass:[self class]]
213                                                                                   forGroup:QUICKTIME_PREFS];
214         
215         advancedPreferences = [[QTAdvancedPreferences preferencePane] retain];
216         
217         // Watch for preferences changes
218         [[adium preferenceController] registerPreferenceObserver:self forGroup:QUICKTIME_PREFS];
219         
220         workspaceCenter = [[NSWorkspace sharedWorkspace] notificationCenter];
221         
222         [workspaceCenter addObserver:self
223                                                 selector:@selector(workspaceSessionDidBecomeActive:)
224                                                         name:NSWorkspaceSessionDidBecomeActiveNotification
225                                                   object:nil];
226         
227         [workspaceCenter addObserver:self
228                                                 selector:@selector(workspaceSessionDidResignActive:)
229                                                         name:NSWorkspaceSessionDidResignActiveNotification
230                                                   object:nil];  
231         
232         [self startupQuickTime];
236  * Uninstall the plugin
237  */
238 - (void) uninstallPlugin
240         [self shutdownQuickTime];
241         
242         [[adium vcController] unregisterProviderForProtocol:VC_RTP];
243         
244         [[adium preferenceController] unregisterPreferenceObserver:self];
245         
246         [[[NSWorkspace sharedWorkspace] notificationCenter] removeObserver:self];       
251  * Preferences have changed
252  */
253 - (void) preferencesChangedForGroup:(NSString *)group
254                                                                 key:(NSString *)key
255                                                          object:(AIListObject *)object
256                                          preferenceDict:(NSDictionary *)prefDict
257                                                   firstTime:(BOOL)firstTime
259         [self setDefaultMicVolumeTo: [[prefDict objectForKey:KEY_MIC_VOLUME] intValue]];        
260         [self setDefaultOutVolumeTo: [[prefDict objectForKey:KEY_OUT_VOLUME] intValue]];
263 - (void)workspaceSessionDidBecomeActive:(NSNotification *)inNotification
265         
268 - (void)workspaceSessionDidResignActive:(NSNotification *)inNotification
270         
273 @end