Changeset 353


Ignore:
Timestamp:
Mar 23, 2006 2:20:42 PM (18 years ago)
Author:
bennylp
Message:

Fixed unable to open simultaneous sound streams in MacOS

Location:
pjproject/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjmedia/build/os-darwinos.mak

    r341 r353  
    88# to all operating systems should go in Makefile instead. 
    99# 
    10 export PJMEDIA_OBJS += $(PA_DIR)/pa_mac_core.o $(PA_DIR)/pa_mac_hostapis.o \ 
    11                        $(PA_DIR)/pa_unix_util.o 
     10export PJMEDIA_OBJS += $(PA_DIR)/pa_mac_hostapis.o \ 
     11                       $(PA_DIR)/pa_unix_util.o \ 
     12                       $(PA_DIR)/pa_mac_core.o 
     13 
     14#                      $(PA_DIR)/pa_mac_alt.o 
    1215#                      $(PA_DIR)/ringbuffer.o 
    1316 
  • pjproject/trunk/pjsip-apps/src/samples/sndinfo.c

    r350 r353  
    2525 "                                                                          \n" 
    2626 " USAGE:                                                                   \n" 
    27  "  sndinfo [id r/p clockrate nchan bits]                                   \n" 
     27 "  sndinfo [id rec/play/both clockrate nchan bits]                         \n" 
    2828 "                                                                          \n" 
    2929 " DESCRIPTION:                                                             \n" 
     
    3333 "  When invoked with arguments, the program tests if device can be opened  \n" 
    3434 "  with the specified arguments. All these arguments must be specified:    \n" 
    35  "  - id         The device ID (-1 for the first capable device)            \n" 
    36  "  - r/p        Specify r for recording/capture, p for playing.            \n" 
    37  "  - clockrate  Specify clock rate (e.g. 8000, 11025, etc.)                \n" 
    38  "  - nchan      Number of channels (1=mono, 2=stereo).                     \n" 
    39  "  - bits       Number of bits per sample (normally 16).                   \n"; 
     35 "  - id             The device ID (-1 for the first capable device)        \n" 
     36 "  - rec/play/both  Specify which streams to open.                         \n" 
     37 "  - clockrate      Specify clock rate (e.g. 8000, 11025, etc.)            \n" 
     38 "  - nchan          Number of channels (1=mono, 2=stereo).                 \n" 
     39 "  - bits           Number of bits per sample (normally 16).               \n"; 
    4040 
    4141#include <pjmedia.h> 
     
    7070                info->default_samples_per_sec); 
    7171    } 
    72 } 
    73  
     72    puts(""); 
     73    puts("Run with -h to get more options"); 
     74} 
     75 
     76static int play_counter; 
     77static int rec_counter; 
    7478 
    7579static pj_status_t play_cb(void *user_data, pj_uint32_t timestamp, 
    7680                           void *output, unsigned size) 
    7781{ 
     82    ++play_counter; 
    7883    return PJ_SUCCESS; 
    7984} 
     
    8287                          const void *input, unsigned size) 
    8388{ 
     89    ++rec_counter; 
    8490    return PJ_SUCCESS; 
    8591} 
    8692 
    87 static int open_device(int dev_id, int capturing, int clock_rate,  
    88                        int nchannel, int bits) 
    89 { 
    90     pj_status_t status; 
     93static void app_perror(const char *title, pj_status_t status) 
     94{ 
     95    char errmsg[PJ_ERR_MSG_SIZE]; 
     96 
     97    pj_strerror(status, errmsg, sizeof(errmsg));         
     98    printf( "%s: %s (err=%d)\n", 
     99            title, errmsg, status); 
     100} 
     101                 
     102static int open_device(int dev_id, pjmedia_dir dir, 
     103                       int clock_rate, int nchannel, int bits) 
     104{ 
     105    pj_status_t status = PJ_SUCCESS; 
    91106    unsigned nsamples; 
    92107    pjmedia_snd_stream *strm; 
    93  
     108    const char *dirtype; 
     109 
     110    switch (dir) { 
     111    case PJMEDIA_DIR_CAPTURE: 
     112        dirtype = "capture"; break;     
     113    case PJMEDIA_DIR_PLAYBACK: 
     114        dirtype = "playback"; break;     
     115    case PJMEDIA_DIR_CAPTURE_PLAYBACK: 
     116        dirtype = "capture/playback"; break;     
     117    default: 
     118        return 1; 
     119    } 
     120     
    94121    nsamples = clock_rate * 20 / 1000; 
    95122 
    96     printf( "Opening device %d: clockrate=%d, nchannel=%d, bits=%d, " 
    97             "nsamples=%d..\n", 
    98             dev_id, clock_rate, nchannel, bits, nsamples); 
    99  
    100     if (capturing) { 
    101         status = pjmedia_snd_open_recorder( dev_id, clock_rate, nchannel, 
    102                                             nsamples, bits, &rec_cb, NULL, 
    103                                             &strm); 
    104     } else { 
     123    printf( "Opening device %d for %s: clockrate=%d, nchannel=%d, " 
     124            "bits=%d, nsamples=%d..\n", 
     125            dev_id, dirtype, clock_rate, nchannel, bits, nsamples); 
     126 
     127    if (dir == PJMEDIA_DIR_CAPTURE) { 
     128        status = pjmedia_snd_open_rec( dev_id, clock_rate, nchannel, 
     129                                       nsamples, bits, &rec_cb, NULL, 
     130                                       &strm); 
     131    } else if (dir == PJMEDIA_DIR_PLAYBACK) { 
    105132        status = pjmedia_snd_open_player( dev_id, clock_rate, nchannel, 
    106133                                          nsamples, bits, &play_cb, NULL, 
    107134                                          &strm); 
     135    } else { 
     136        status = pjmedia_snd_open( dev_id, dev_id, clock_rate, nchannel, 
     137                                   nsamples, bits, &rec_cb, &play_cb, NULL, 
     138                                   &strm); 
    108139    } 
    109140     
    110141    if (status != PJ_SUCCESS) { 
    111         char errmsg[PJ_ERR_MSG_SIZE]; 
    112  
    113         pj_strerror(status, errmsg, sizeof(errmsg));     
    114         printf( "Error: unable to open device %d for %s: %s (err=%d)\n", 
    115                 dev_id, (capturing ? "capture" : "playback"), 
    116                 errmsg, status); 
    117         return 1; 
    118          
    119     } else { 
    120         puts("Device opened successfully"); 
    121     } 
     142        app_perror("Unable to open device for capture", status); 
     143        return 1; 
     144    } 
     145 
     146    status = pjmedia_snd_stream_start(strm); 
     147    if (status != PJ_SUCCESS) { 
     148        app_perror("Unable to start capture stream", status); 
     149        return 1; 
     150    } 
     151     
     152    /* Let playback/capture runs for a while */ 
     153    pj_thread_sleep(1000); 
    122154 
    123155    pjmedia_snd_stream_close(strm); 
     156 
     157    if ((dir & PJMEDIA_DIR_CAPTURE) && rec_counter==0) { 
     158        printf("Error: capture stream was not running\n"); 
     159        return 1; 
     160    } 
     161 
     162    if ((dir & PJMEDIA_DIR_PLAYBACK) && play_counter==0) { 
     163        printf("Error: playback stream was not running\n"); 
     164        return 1; 
     165    } 
     166 
     167    puts("Success."); 
    124168    return 0; 
    125169} 
     
    153197         
    154198        int dev_id; 
    155         int capturing; 
     199        pjmedia_dir dir; 
    156200        int clock_rate; 
    157201        int nchannel; 
     
    159203 
    160204        dev_id = atoi(argv[1]); 
    161         capturing = (strcmp(argv[2], "r") == 0); 
     205 
     206        if (strcmp(argv[2], "rec")==0) 
     207            dir = PJMEDIA_DIR_CAPTURE; 
     208        else if (strcmp(argv[2], "play")==0) 
     209            dir = PJMEDIA_DIR_PLAYBACK; 
     210        else if (strcmp(argv[2], "both")==0) 
     211            dir = PJMEDIA_DIR_CAPTURE_PLAYBACK; 
     212 
    162213        clock_rate = atoi(argv[3]); 
    163214        nchannel = atoi(argv[4]); 
    164215        bits = atoi(argv[5]); 
    165216 
    166         return open_device(dev_id, capturing, clock_rate, nchannel, bits); 
     217        return open_device(dev_id, dir, clock_rate, nchannel, bits); 
    167218 
    168219    } else { 
Note: See TracChangeset for help on using the changeset viewer.