Changeset 657 for trunk


Ignore:
Timestamp:
04/07/13 20:15:59 (12 years ago)
Author:
Nicholas Riley
Message:

AudioDevicemodule.c: Make error handling more useful and consistent.
Make spacing consistent. Ignore sporadic kAudioHardwareBadObjectError.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/StreamVision/AudioDevicemodule.c

    r654 r657  
    11#include "Python.h"
    22#include <AudioToolbox/AudioServices.h>
     3
     4#define FourCC2Str(code) (char[5]){(code >> 24) & 0xFF, (code >> 16) & 0xFF, (code >> 8) & 0xFF, code & 0xFF, 0}
     5
     6static PyObject *
     7OSError_from_HALError(const char *failed_operation, OSStatus err) {
     8    // these error codes are actually mnemonic, so display them
     9    return PyErr_Format(PyExc_OSError,
     10                        "%s failed (%ld - %s)",
     11                        failed_operation, (long)err, FourCC2Str(err));
     12}
    313
    414static PyObject *
     
    1727                                            &size, &deviceID);
    1828  if (err != noErr)
    19     return PyErr_Format(PyExc_OSError,
    20                         "AudioHardwareServiceGetPropertyData failed (%ld)",
    21                         (long)err);
     29    return OSError_from_HALError("AudioHardwareServiceGetPropertyData", err);
    2230 
    2331  if (deviceID == kAudioDeviceUnknown)
     
    2937                                   &propertyAddress, 0, NULL,
    3038                                   &size, &transportType);
     39  if (err == kAudioHardwareBadObjectError)
     40    Py_RETURN_NONE;
    3141  if (err != noErr)
    32     return PyErr_Format(PyExc_OSError,
    33                         "AudioObjectGetPropertyData failed (%ld)",
    34                         (long)err);
     42    return OSError_from_HALError("AudioObjectGetPropertyData", err);
    3543
    3644  if (transportType == kAudioDeviceTransportTypeAirPlay)
    37       Py_RETURN_TRUE;
     45    Py_RETURN_TRUE;
    3846  else
    39       Py_RETURN_FALSE;
     47    Py_RETURN_FALSE;
    4048}
    4149
     
    7886                                         NULL);
    7987    if (err != noErr)
    80       return PyErr_Format(PyExc_OSError,
    81                           "AudioObjectAddPropertyListener failed (%ld)",
    82                           (long)err);
     88      return OSError_from_HALError("AudioObjectAddPropertyListener", err);
    8389  } else {
    8490    Py_DECREF(default_output_device_changed_callback);
Note: See TracChangeset for help on using the changeset viewer.