src/java.desktop/macosx/native/libjsound/PLATFORM_API_MacOSX_Ports.cpp
changeset 58319 18e7ed2cd7d1
parent 52089 081aed66b645
equal deleted inserted replaced
58318:f39420849ae9 58319:18e7ed2cd7d1
   412 // returns java control
   412 // returns java control
   413 static void* CreatePortControl(PortMixer *mixer, PortControlCreator *creator, PortControl::ControlType type,
   413 static void* CreatePortControl(PortMixer *mixer, PortControlCreator *creator, PortControl::ControlType type,
   414                                AudioControl **audioControls, int offset, int len) {
   414                                AudioControl **audioControls, int offset, int len) {
   415     void *jControl = NULL;
   415     void *jControl = NULL;
   416     PortControl *control = (PortControl *)calloc(1, sizeof(PortControl));
   416     PortControl *control = (PortControl *)calloc(1, sizeof(PortControl));
       
   417     if (control == NULL) {
       
   418         return NULL;
       
   419     }
   417     float precision = 0.01;
   420     float precision = 0.01;
   418 
   421 
   419     control->type = type;
   422     control->type = type;
   420     control->controlCount = len;
   423     control->controlCount = len;
   421     control->audioControls = (AudioControl **)malloc(len * sizeof(AudioControl *));
   424     control->audioControls = (AudioControl **)malloc(len * sizeof(AudioControl *));
       
   425     if (control->audioControls == NULL) {
       
   426         free(control);
       
   427         return NULL;
       
   428     }
   422     memcpy(control->audioControls, audioControls + offset, len * sizeof(AudioControl *));
   429     memcpy(control->audioControls, audioControls + offset, len * sizeof(AudioControl *));
   423 
   430 
   424     switch (control->type) {
   431     switch (control->type) {
   425     case PortControl::Volume:
   432     case PortControl::Volume:
   426         jControl = creator->newFloatControl(creator, control, CONTROL_TYPE_VOLUME, 0, 1, precision, "");
   433         jControl = creator->newFloatControl(creator, control, CONTROL_TYPE_VOLUME, 0, 1, precision, "");
   480 
   487 
   481             if (err) {
   488             if (err) {
   482                 OS_ERROR1(err, "PORT_GetControls (portIndex = %d) get OwnedObject values", portIndex);
   489                 OS_ERROR1(err, "PORT_GetControls (portIndex = %d) get OwnedObject values", portIndex);
   483             } else {
   490             } else {
   484                 mixer->deviceControls = (AudioControl *)calloc(mixer->deviceControlCount, sizeof(AudioControl));
   491                 mixer->deviceControls = (AudioControl *)calloc(mixer->deviceControlCount, sizeof(AudioControl));
       
   492                 if (mixer->deviceControls == NULL) {
       
   493                     return;
       
   494                 }
   485 
   495 
   486                 for (int i = 0; i < mixer->deviceControlCount; i++) {
   496                 for (int i = 0; i < mixer->deviceControlCount; i++) {
   487                     AudioControl *control = &mixer->deviceControls[i];
   497                     AudioControl *control = &mixer->deviceControls[i];
   488 
   498 
   489                     control->controlID = controlIDs[i];
   499                     control->controlID = controlIDs[i];
   613                 UInt32 size = sizeof(cfname);
   623                 UInt32 size = sizeof(cfname);
   614                 OSStatus err = AudioObjectGetPropertyData(mixer->deviceID, &address, 0, NULL, &size, &cfname);
   624                 OSStatus err = AudioObjectGetPropertyData(mixer->deviceID, &address, 0, NULL, &size, &cfname);
   615                 if (err == noErr) {
   625                 if (err == noErr) {
   616                     CFIndex length = CFStringGetLength(cfname) + 1;
   626                     CFIndex length = CFStringGetLength(cfname) + 1;
   617                     channelName = (char *)malloc(length);
   627                     channelName = (char *)malloc(length);
       
   628                     if (channelName == NULL) {
       
   629                         return;
       
   630                     }
   618                     CFStringGetCString(cfname, channelName, length, kCFStringEncodingUTF8);
   631                     CFStringGetCString(cfname, channelName, length, kCFStringEncodingUTF8);
   619                     CFRelease(cfname);
   632                     CFRelease(cfname);
   620                 } else {
   633                 } else {
   621                     channelName = (char *)malloc(16);
   634                     channelName = (char *)malloc(16);
       
   635                     if (channelName == NULL) {
       
   636                         return;
       
   637                     }
   622                     sprintf(channelName, "Ch %d", ch);
   638                     sprintf(channelName, "Ch %d", ch);
   623                 }
   639                 }
   624 
   640 
   625                 void* jControls[2];
   641                 void* jControls[2];
   626                 int controlCount = 0;
   642                 int controlCount = 0;