Ignore:
Timestamp:
Sep 27, 2006 10:49:55 PM (16 years ago)
Author:
bennylp
Message:

Added pjmedia_snd_stream_get_info() function.

NOTE SOUND DEVICE IMPLEMENTORS: YOU'LL NEED TO IMPLEMENT THIS

FUNCTION TOO *

File:
1 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjmedia/src/pjmedia/pasound.c

    r645 r744  
    1919#include <pjmedia/sound.h> 
    2020#include <pjmedia/errno.h> 
     21#include <pj/assert.h> 
    2122#include <pj/log.h> 
    2223#include <pj/os.h> 
     
    4344    pj_str_t             name; 
    4445    pjmedia_dir          dir; 
     46    int                  play_id; 
     47    int                  rec_id; 
    4548    int                  bytes_per_sample; 
    4649    pj_uint32_t          samples_per_sec; 
     50    unsigned             samples_per_frame; 
    4751    int                  channel_count; 
    4852 
     
    242246    const PaDeviceInfo *paDevInfo = NULL; 
    243247    const PaHostApiInfo *paHostApiInfo = NULL; 
    244     unsigned paFrames; 
     248    unsigned paFrames, paRate, paLatency; 
     249    const PaStreamInfo *paSI; 
    245250    PaError err; 
    246251 
     
    281286    pj_strdup2_with_null(pool, &stream->name, paDevInfo->name); 
    282287    stream->dir = PJMEDIA_DIR_CAPTURE; 
     288    stream->rec_id = index; 
     289    stream->play_id = -1; 
    283290    stream->user_data = user_data; 
    284291    stream->samples_per_sec = clock_rate; 
     292    stream->samples_per_frame = samples_per_frame; 
    285293    stream->bytes_per_sample = bits_per_sample / 8; 
    286294    stream->channel_count = channel_count; 
     
    307315    } 
    308316 
    309     PJ_LOG(5,(THIS_FILE, "%s opening device %s (%s) for recording, sample " 
     317    paSI = Pa_GetStreamInfo(stream->stream); 
     318    paRate = (unsigned)paSI->sampleRate; 
     319    paLatency = (unsigned)(paSI->inputLatency * 1000); 
     320 
     321    PJ_LOG(5,(THIS_FILE, "Opened device %s (%s) for recording, sample " 
    310322                         "rate=%d, ch=%d, " 
    311                          "bits=%d, %d samples per frame", 
    312                          (err==0 ? "Success" : "Error"), 
     323                         "bits=%d, %d samples per frame, latency=%d ms", 
    313324                         paDevInfo->name, paHostApiInfo->name, 
    314                          clock_rate, channel_count, 
    315                          bits_per_sample, samples_per_frame)); 
     325                         paSI->sampleRate, channel_count, 
     326                         bits_per_sample, samples_per_frame, 
     327                         paLatency)); 
    316328 
    317329    *p_snd_strm = stream; 
     
    335347    const PaDeviceInfo *paDevInfo = NULL; 
    336348    const PaHostApiInfo *paHostApiInfo = NULL; 
    337     unsigned paFrames; 
     349    const PaStreamInfo *paSI; 
     350    unsigned paFrames, paRate, paLatency; 
    338351    PaError err; 
    339352 
     
    374387    pj_strdup2_with_null(pool, &stream->name, paDevInfo->name); 
    375388    stream->dir = stream->dir = PJMEDIA_DIR_PLAYBACK; 
     389    stream->play_id = index; 
     390    stream->rec_id = -1; 
    376391    stream->user_data = user_data; 
    377392    stream->samples_per_sec = clock_rate; 
     393    stream->samples_per_frame = samples_per_frame; 
    378394    stream->bytes_per_sample = bits_per_sample / 8; 
    379395    stream->channel_count = channel_count; 
     
    400416    } 
    401417 
    402     PJ_LOG(5,(THIS_FILE, "%s opening device %d: %s(%s) for playing, sample rate=%d" 
     418    paSI = Pa_GetStreamInfo(stream->stream); 
     419    paRate = (unsigned)(paSI->sampleRate); 
     420    paLatency = (unsigned)(paSI->outputLatency * 1000); 
     421 
     422    PJ_LOG(5,(THIS_FILE, "Opened device %d: %s(%s) for playing, sample rate=%d" 
    403423                         ", ch=%d, " 
    404                          "bits=%d, %d samples per frame", 
    405                          (err==0 ? "Success" : "Error"), 
     424                         "bits=%d, %d samples per frame, latency=%d ms", 
    406425                         index, paDevInfo->name, paHostApiInfo->name,  
    407                          clock_rate, channel_count, 
    408                          bits_per_sample, samples_per_frame)); 
     426                         paRate, channel_count, 
     427                         bits_per_sample, samples_per_frame, paLatency)); 
    409428 
    410429    *p_snd_strm = stream; 
     
    437456    const PaHostApiInfo *paRecHostApiInfo = NULL; 
    438457    const PaHostApiInfo *paPlayHostApiInfo = NULL; 
    439     unsigned paFrames; 
     458    const PaStreamInfo *paSI; 
     459    unsigned paFrames, paRate, paInputLatency, paOutputLatency; 
    440460    PaError err; 
    441461 
     
    495515    pj_strdup2_with_null(pool, &stream->name, paRecDevInfo->name); 
    496516    stream->dir = PJMEDIA_DIR_CAPTURE_PLAYBACK; 
     517    stream->play_id = play_id; 
     518    stream->rec_id = rec_id; 
    497519    stream->user_data = user_data; 
    498520    stream->samples_per_sec = clock_rate; 
     521    stream->samples_per_frame = samples_per_frame; 
    499522    stream->bytes_per_sample = bits_per_sample / 8; 
    500523    stream->channel_count = channel_count; 
     
    531554    } 
    532555 
    533     PJ_LOG(5,(THIS_FILE, "%s opening device %s(%s)/%s(%s) for recording and " 
     556    paSI = Pa_GetStreamInfo(stream->stream); 
     557    paRate = (unsigned)(paSI->sampleRate); 
     558    paInputLatency = (unsigned)(paSI->inputLatency * 1000); 
     559    paOutputLatency = (unsigned)(paSI->outputLatency * 1000); 
     560 
     561    PJ_LOG(5,(THIS_FILE, "Opened device %s(%s)/%s(%s) for recording and " 
    534562                         "playback, sample rate=%d, ch=%d, " 
    535                          "bits=%d, %d samples per frame", 
    536                          (err==0 ? "Success" : "Error"), 
     563                         "bits=%d, %d samples per frame, input latency=%d ms, " 
     564                         "output latency=%d ms", 
    537565                         paRecDevInfo->name, paRecHostApiInfo->name, 
    538566                         paPlayDevInfo->name, paPlayHostApiInfo->name, 
    539                          clock_rate, channel_count, 
    540                          bits_per_sample, samples_per_frame)); 
     567                         paRate, channel_count, 
     568                         bits_per_sample, samples_per_frame, 
     569                         paInputLatency, paOutputLatency)); 
    541570 
    542571    *p_snd_strm = stream; 
     
    545574    return PJ_SUCCESS; 
    546575} 
     576 
     577 
     578/* 
     579 * Get stream info. 
     580 */ 
     581PJ_DEF(pj_status_t) pjmedia_snd_stream_get_info(pjmedia_snd_stream *strm, 
     582                                                pjmedia_snd_stream_info *pi) 
     583{ 
     584    const PaStreamInfo *paSI; 
     585 
     586    PJ_ASSERT_RETURN(strm && pi, PJ_EINVAL); 
     587    PJ_ASSERT_RETURN(strm->stream, PJ_EINVALIDOP); 
     588 
     589    paSI = Pa_GetStreamInfo(strm->stream); 
     590 
     591    pj_bzero(pi, sizeof(*pi)); 
     592    pi->dir = strm->dir; 
     593    pi->play_id = strm->play_id; 
     594    pi->rec_id = strm->rec_id; 
     595    pi->clock_rate = (unsigned)(paSI->sampleRate); 
     596    pi->channel_count = strm->channel_count; 
     597    pi->samples_per_frame = strm->samples_per_frame; 
     598    pi->bits_per_sample = strm->bytes_per_sample * 8; 
     599    pi->rec_latency = (unsigned)(paSI->inputLatency * paSI->sampleRate); 
     600    pi->play_latency = (unsigned)(paSI->outputLatency * paSI->sampleRate); 
     601 
     602    return PJ_SUCCESS; 
     603} 
     604 
    547605 
    548606/* 
Note: See TracChangeset for help on using the changeset viewer.