Changeset 358


Ignore:
Timestamp:
Mar 24, 2006 8:41:20 PM (18 years ago)
Author:
bennylp
Message:

Added WAVE writer and resample port, and also found out why audio quality is poor with DirectSound?

Location:
pjproject/trunk/pjmedia
Files:
3 added
1 deleted
14 edited
1 moved

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjmedia/build/Makefile

    r355 r358  
    6565export PJMEDIA_SRCDIR = ../src/pjmedia 
    6666export PJMEDIA_OBJS += $(OS_OBJS) $(M_OBJS) $(CC_OBJS) $(HOST_OBJS) \ 
    67                         codec.o conference.o endpoint.o errno.o file_port.o \ 
    68                         g711.o jbuf.o null_port.o port.o resample.o rtcp.o \ 
    69                         rtp.o sdp.o sdp_cmp.o sdp_neg.o session.o silencedet.o \ 
     67                        codec.o conference.o endpoint.o errno.o file_player.o \ 
     68                        g711.o jbuf.o null_port.o port.o resample.o resample_port.o \ 
     69                        rtcp.o rtp.o sdp.o sdp_cmp.o sdp_neg.o session.o silencedet.o \ 
    7070                        sound_port.o stream.o $(SOUND_OBJS) $(NULLSOUND_OBJS) 
    7171 
  • pjproject/trunk/pjmedia/build/pjmedia.dsp

    r321 r358  
    6666# PROP Target_Dir "" 
    6767# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /YX /FD /GZ /c 
    68 # ADD CPP /nologo /MTd /W4 /Gm /GX /ZI /Od /I "../include" /I "../../pjlib/include" /I "../../pjlib-util/include" /I "../src/pjmedia/portaudio" /D "_DEBUG" /D "PA_NO_ASIO" /D "PA_NO_WMME" /D "WIN32" /D "_MBCS" /D "_LIB" /D PJ_WIN32=1 /D PJ_M_I386=1 /FR /FD /GZ /c 
     68# ADD CPP /nologo /MTd /W4 /Gm /GX /ZI /Od /I "../include" /I "../../pjlib/include" /I "../../pjlib-util/include" /I "../src/pjmedia/portaudio" /D "_DEBUG" /D "PA_NO_ASIO" /D "PA_NO_DS" /D "WIN32" /D "_MBCS" /D "_LIB" /D PJ_WIN32=1 /D PJ_M_I386=1 /FR /FD /GZ /c 
    6969# SUBTRACT CPP /YX 
    7070# ADD BASE RSC /l 0x409 /d "_DEBUG" 
     
    109109# Begin Source File 
    110110 
    111 SOURCE=..\src\pjmedia\file_port.c 
     111SOURCE=..\src\pjmedia\file_player.c 
     112# End Source File 
     113# Begin Source File 
     114 
     115SOURCE=..\src\pjmedia\file_writer.c 
    112116# End Source File 
    113117# Begin Source File 
     
    141145# Begin Source File 
    142146 
     147SOURCE=..\src\pjmedia\resample_port.c 
     148# End Source File 
     149# Begin Source File 
     150 
    143151SOURCE=..\src\pjmedia\rtcp.c 
    144152# End Source File 
     
    174182 
    175183SOURCE=..\src\pjmedia\stream.c 
     184# End Source File 
     185# Begin Source File 
     186 
     187SOURCE=..\src\pjmedia\wave.c 
    176188# End Source File 
    177189# End Group 
  • pjproject/trunk/pjmedia/include/pjmedia.h

    r355 r358  
    3535#include <pjmedia/null_port.h> 
    3636#include <pjmedia/port.h> 
     37#include <pjmedia/resample.h> 
    3738#include <pjmedia/rtcp.h> 
    3839#include <pjmedia/rtp.h> 
  • pjproject/trunk/pjmedia/include/pjmedia/config.h

    r347 r358  
    6969 
    7070 
     71/** 
     72 * Default file player/writer buffer size. 
     73 */ 
     74#ifndef PJMEDIA_FILE_PORT_BUFSIZE 
     75#   define PJMEDIA_FILE_PORT_BUFSIZE    4000 
     76#endif 
     77 
     78 
    7179#endif  /* __PJMEDIA_CONFIG_H__ */ 
    7280 
  • pjproject/trunk/pjmedia/include/pjmedia/errno.h

    r334 r358  
    441441 */ 
    442442#define PJMEDIA_EWAVETOOSHORT       (PJMEDIA_ERRNO_START+182)    /* 220182 */ 
     443/** 
     444 * @hideinitializer 
     445 * Sound frame is too large for file buffer. 
     446 */ 
     447#define PJMEDIA_EFRMFILETOOBIG      (PJMEDIA_ERRNO_START+183)    /* 220183 */ 
    443448 
    444449 
  • pjproject/trunk/pjmedia/include/pjmedia/file_port.h

    r222 r358  
    2727 
    2828 
     29 
    2930PJ_BEGIN_DECL 
    3031 
    3132 
    3233/** 
    33  * Create file player port. 
     34 * Create a media port to play streams from a WAV file. 
     35 * 
     36 * @param pool          Pool to create memory buffers for this port. 
     37 * @param filename      File name to open. 
     38 * @param flags         Port creation flags. 
     39 * @param buf_size      Buffer size to be allocated. If the value is zero or 
     40 *                      negative, the port will use default buffer size (which 
     41 *                      is about 4KB). 
     42 * @param user_data     User data to be associated with the file player port. 
     43 * @param p_port        Pointer to receive the file port instance. 
     44 * 
     45 * @return              PJ_SUCCESS on success. 
    3446 */ 
    3547PJ_DECL(pj_status_t) pjmedia_file_player_port_create( pj_pool_t *pool, 
     
    4254 
    4355 
     56/** 
     57 * Create a media port to record streams to a WAV file. Note that the port 
     58 * must be closed properly (with #pjmedia_port_destroy()) so that the WAV 
     59 * header can be filled with correct values (such as the file length). 
     60 * 
     61 * @param pool          Pool to create memory buffers for this port. 
     62 * @param filename      File name. 
     63 * @param flags         Port creation flags. 
     64 * @param buf_size      Buffer size to be allocated. If the value is zero or 
     65 *                      negative, the port will use default buffer size (which 
     66 *                      is about 4KB). 
     67 * @param user_data     User data to be associated with the file writer port. 
     68 * @param p_port        Pointer to receive the file port instance. 
     69 * 
     70 * @return              PJ_SUCCESS on success. 
     71 */ 
     72PJ_DECL(pj_status_t) pjmedia_file_writer_port_create( pj_pool_t *pool, 
     73                                                      const char *filename, 
     74                                                      unsigned sampling_rate, 
     75                                                      unsigned channel_count, 
     76                                                      unsigned samples_per_frame, 
     77                                                      unsigned bits_per_sample, 
     78                                                      unsigned flags, 
     79                                                      pj_ssize_t buff_size, 
     80                                                      void *user_data, 
     81                                                      pjmedia_port **p_port ); 
     82 
     83 
     84 
     85 
    4486PJ_END_DECL 
    4587 
  • pjproject/trunk/pjmedia/include/pjmedia/resample.h

    r277 r358  
    2626 * @brief Sample rate converter. 
    2727 */ 
    28 #include "pjmedia/types.h" 
     28#include <pjmedia/types.h> 
     29#include <pjmedia/port.h> 
     30 
    2931 
    3032PJ_BEGIN_DECL 
     33 
     34/* 
     35 * This file declares two types of API: 
     36 * 
     37 * Application can use #pjmedia_resample_create() and #pjmedia_resample_run() 
     38 * to convert a frame from source rate to destination rate. The inpuit frame  
     39 * must have a constant length. 
     40 * 
     41 * Alternatively, application can create a resampling port with 
     42 * #pjmedia_resample_port_create() and connect the port to other ports to 
     43 * change the sampling rate of the samples. 
     44 */ 
     45 
    3146 
    3247/** 
     
    6075 
    6176/** 
    62  * Resample a frame. 
     77 * Use the resample session to resample a frame. The frame must have the 
     78 * same size and settings as the resample session, or otherwise the 
     79 * behavior is undefined. 
    6380 * 
    6481 * @param resample              The resample session. 
     
    7188 
    7289 
     90/** 
     91 * Get the input frame size of a resample session. 
     92 * 
     93 * @param resample              The resample session. 
     94 * 
     95 * @return                      The frame size, in number of samples. 
     96 */ 
     97PJ_DECL(unsigned) pjmedia_resample_get_input_size(pjmedia_resample *resample); 
     98 
     99 
     100/** 
     101 * Create a resample port. This creates a bidirectional resample session, 
     102 * which will resample frames when the port's get_frame() and put_frame() 
     103 * is called. 
     104 * 
     105 * When the resample port's get_frame() is called, this port will get 
     106 * a frame from the downstream port and resample the frame to the upstream 
     107 * port's clock rate before returning it to the caller. 
     108 * 
     109 * When the resample port's put_frame() is called, this port will resample 
     110 * the frame to the downstream's port clock rate before giving the frame 
     111 * to the downstream port. 
     112 * 
     113 * @param pool                  Pool to allocate the structure and buffers. 
     114 * @param high_quality          If true, then high quality conversion will be 
     115 *                              used, at the expense of more CPU and memory, 
     116 *                              because temporary buffer needs to be created. 
     117 * @param large_filter          If true, large filter size will be used. 
     118 * @param downstream_rate       The sampling rate of the downstream port. 
     119 * @param upstream_rate         The sampling rate of the upstream port. 
     120 * @param channel_count         The number of channels. This argument is only 
     121 *                              used for the port information. It does not 
     122 *                              change the behavior of the resample port. 
     123 * @param samples_per_frame     Number of samples per frame from the downstream 
     124 *                              port. 
     125 * @param p_port                Pointer to receive the resample port instance. 
     126 * 
     127 * @return PJ_SUCCESS on success. 
     128 */ 
     129PJ_DECL(pj_status_t) pjmedia_resample_port_create( pj_pool_t *pool, 
     130                                                   pj_bool_t high_quality, 
     131                                                   pj_bool_t large_filter, 
     132                                                   unsigned downstream_rate, 
     133                                                   unsigned upstream_rate, 
     134                                                   unsigned channel_count, 
     135                                                   unsigned samples_per_frame, 
     136                                                   pjmedia_port **p_port ); 
     137 
     138 
    73139PJ_END_DECL 
    74140 
  • pjproject/trunk/pjmedia/include/pjmedia/wave.h

    r341 r358  
    3333#define PJMEDIA_WAVE_TAG        ('E'<<24|'V'<<16|'A'<<8|'W') 
    3434#define PJMEDIA_FMT_TAG         (' '<<24|'t'<<16|'m'<<8|'f') 
     35#define PJMEDIA_DATA_TAG        ('a'<<24|'t'<<16|'a'<<8|'d') 
    3536 
    3637 
     
    7071 
    7172 
     73/** 
     74 * On big-endian hosts, this function swaps the byte order of the values 
     75 * in the WAVE header fields. On little-endian hosts, this function does  
     76 * nothing. 
     77 * 
     78 * Application SHOULD call this function after reading the WAVE header 
     79 * chunks from a file. 
     80 * 
     81 * @param hdr       The WAVE header. 
     82 */ 
     83PJ_DECL(void) pjmedia_wave_hdr_file_to_host( pjmedia_wave_hdr *hdr ); 
     84 
     85 
     86/** 
     87 * On big-endian hosts, this function swaps the byte order of the values 
     88 * in the WAVE header fields. On little-endian hosts, this function does  
     89 * nothing. 
     90 * 
     91 * Application SHOULD call this function before writing the WAVE header 
     92 * to a file. 
     93 * 
     94 * @param hdr       The WAVE header. 
     95 */ 
     96PJ_DECL(void) pjmedia_wave_hdr_host_to_file( pjmedia_wave_hdr *hdr ); 
     97 
     98 
    7299PJ_END_DECL 
    73100 
  • pjproject/trunk/pjmedia/src/pjmedia/conference.c

    r352 r358  
    2929#include <pj/string.h> 
    3030 
     31/* CONF_DEBUG enables detailed operation of the conference bridge. 
     32 * Beware that it prints large amounts of logs (several lines per frame). 
     33 */ 
    3134//#define CONF_DEBUG 
    3235#ifdef CONF_DEBUG 
    3336#   include <stdio.h> 
    34 #   define TRACE_(x)   {printf x; fflush(stdout); } 
     37#   define TRACE_(x)   PJ_LOG(5,x) 
    3538#else 
    3639#   define TRACE_(x) 
     40#endif 
     41 
     42 
     43/* REC_FILE macro enables recording of the samples written to the sound 
     44 * device. The file contains RAW PCM data with no header, and has the 
     45 * same settings (clock rate etc) as the conference bridge. 
     46 * This should only be enabled when debugging audio quality *only*. 
     47 */ 
     48//#define REC_FILE    "confrec.pcm" 
     49#ifdef REC_FILE 
     50static FILE *fhnd_rec; 
    3751#endif 
    3852 
     
    967981    pj_assert(count == conf->samples_per_frame); 
    968982 
     983    TRACE_((THIS_FILE, "read_port %.*s: count=%d",  
     984                       (int)cport->name.slen, cport->name.ptr, 
     985                       count)); 
     986 
    969987    /* If port's samples per frame and sampling rate matches conference 
    970988     * bridge's settings, get the frame directly from the port. 
     
    976994        f.buf = frame; 
    977995        f.size = count * BYTES_PER_SAMPLE; 
     996 
     997        TRACE_((THIS_FILE, "  get_frame %.*s: count=%d",  
     998                   (int)cport->name.slen, cport->name.ptr, 
     999                   count)); 
    9781000 
    9791001        status = (cport->port->get_frame)(cport->port, &f); 
     
    9981020            f.size = cport->samples_per_frame * BYTES_PER_SAMPLE; 
    9991021 
     1022            TRACE_((THIS_FILE, "  get_frame, count=%d",  
     1023                       cport->samples_per_frame)); 
     1024 
    10001025            status = pjmedia_port_get_frame(cport->port, &f); 
    10011026 
     
    10061031 
    10071032            if (f.type != PJMEDIA_FRAME_TYPE_AUDIO) { 
     1033                TRACE_((THIS_FILE, "  get_frame returned non-audio")); 
    10081034                zero_samples( cport->rx_buf + cport->rx_buf_count, 
    10091035                              cport->samples_per_frame); 
     
    10111037 
    10121038            cport->rx_buf_count += cport->samples_per_frame; 
     1039 
     1040            TRACE_((THIS_FILE, "  rx buffer size is now %d", 
     1041                    cport->rx_buf_count)); 
    10131042 
    10141043            pj_assert(cport->rx_buf_count <= cport->rx_buf_cap); 
     
    10231052            unsigned src_count; 
    10241053 
     1054            TRACE_((THIS_FILE, "  resample, input count=%d",  
     1055                    pjmedia_resample_get_input_size(cport->rx_resample))); 
     1056 
    10251057            pjmedia_resample_run( cport->rx_resample,cport->rx_buf, frame); 
    10261058 
     
    10331065            } 
    10341066 
     1067            TRACE_((THIS_FILE, "  rx buffer size is now %d", 
     1068                    cport->rx_buf_count)); 
     1069 
    10351070        } else { 
    10361071 
     
    10681103        frame.size = 0; 
    10691104 
    1070         if (cport->port && cport->port->put_frame) 
     1105        if (cport->port && cport->port->put_frame) { 
    10711106            pjmedia_port_put_frame(cport->port, &frame); 
     1107        } 
    10721108 
    10731109        cport->tx_level = 0; 
     
    11121148        } 
    11131149 
    1114     } else { 
     1150    } else if (cport->sources) { 
    11151151        /* No need to adjust signal level. */ 
    11161152        for (j=0; j<conf->samples_per_frame; ++j) { 
    11171153            buf[j] = unsigned2pcm(cport->mix_buf[j] / cport->sources); 
    11181154        } 
     1155    } else { 
     1156        // Not necessarry. Buffer has been zeroed before. 
     1157        // zero_samples(buf, conf->samples_per_frame); 
     1158        pj_assert(buf[0] == 0); 
    11191159    } 
    11201160 
     
    11551195            frame.timestamp.u64 = timestamp; 
    11561196 
     1197            TRACE_((THIS_FILE, "put_frame %.*s, count=%d",  
     1198                               (int)cport->name.slen, cport->name.ptr, 
     1199                               frame.size / BYTES_PER_SAMPLE)); 
     1200 
    11571201            return pjmedia_port_put_frame(cport->port, &frame); 
    11581202        } else 
     
    11861230        pj_status_t status; 
    11871231 
     1232        TRACE_((THIS_FILE, "write_port %.*s: count=%d",  
     1233                           (int)cport->name.slen, cport->name.ptr, 
     1234                           cport->samples_per_frame)); 
     1235 
    11881236        if (cport->port) { 
    11891237            pjmedia_frame frame; 
     
    11931241            frame.size = cport->samples_per_frame * BYTES_PER_SAMPLE; 
    11941242            frame.timestamp.u64 = timestamp; 
     1243 
     1244            TRACE_((THIS_FILE, "put_frame %.*s, count=%d",  
     1245                               (int)cport->name.slen, cport->name.ptr, 
     1246                               frame.size / BYTES_PER_SAMPLE)); 
    11951247 
    11961248            status = pjmedia_port_put_frame(cport->port, &frame); 
     
    12061258        } 
    12071259 
     1260        TRACE_((THIS_FILE, " tx_buf count now is %d",  
     1261                           cport->tx_buf_count)); 
     1262 
    12081263        return status; 
    12091264    } 
     
    12221277    unsigned ci, cj, i, j; 
    12231278     
     1279    TRACE_((THIS_FILE, "- clock -")); 
     1280 
    12241281    /* Check that correct size is specified. */ 
    12251282    pj_assert(frame->size == conf->samples_per_frame * 
     
    12281285    /* Must lock mutex (must we??) */ 
    12291286    pj_mutex_lock(conf->mutex); 
    1230  
    1231     TRACE_(("p")); 
    12321287 
    12331288    /* Zero all port's temporary buffers. */ 
     
    12451300        mix_buf = conf_port->mix_buf; 
    12461301 
    1247         for (j=0; j<conf->samples_per_frame; ++j) 
    1248             mix_buf[j] = 0; 
     1302        for (j=0; j<conf->samples_per_frame; ++j) mix_buf[j] = 0; 
    12491303    } 
    12501304 
     
    14221476    /* Return sound playback frame. */ 
    14231477    if (conf->ports[0]->sources) { 
     1478        TRACE_((THIS_FILE, "write to audio, count=%d",  
     1479                           conf->samples_per_frame)); 
     1480 
    14241481        copy_samples( frame->buf, (pj_int16_t*)conf->ports[0]->mix_buf,  
    14251482                      conf->samples_per_frame); 
     
    14321489 
    14331490    pj_mutex_unlock(conf->mutex); 
     1491 
     1492#ifdef REC_FILE 
     1493    if (fhnd_rec == NULL) 
     1494        fhnd_rec = fopen(REC_FILE, "wb"); 
     1495    if (fhnd_rec) 
     1496        fwrite(frame->buf, frame->size, 1, fhnd_rec); 
     1497#endif 
    14341498 
    14351499    return PJ_SUCCESS; 
     
    14481512    pj_int16_t *target_snd_buf; 
    14491513    unsigned i; 
    1450  
    1451     TRACE_(("r")); 
    14521514 
    14531515    /* Check for correct size. */ 
  • pjproject/trunk/pjmedia/src/pjmedia/errno.c

    r355 r358  
    123123    { PJMEDIA_EWAVEUNSUPP,          "Unsupported WAVE file format" }, 
    124124    { PJMEDIA_EWAVETOOSHORT,        "WAVE file too short" }, 
     125    { PJMEDIA_EFRMFILETOOBIG,       "Sound frame too large for file buffer"}, 
    125126 
    126127    /* Sound device errors: */ 
  • pjproject/trunk/pjmedia/src/pjmedia/file_player.c

    r357 r358  
    3131 
    3232 
    33 #ifndef PJMEDIA_FILE_PORT_BUFSIZE 
    34 #   define PJMEDIA_FILE_PORT_BUFSIZE    4000 
    35 #endif 
    36  
    37  
    38 #define SIGNATURE       ('F'<<24|'I'<<16|'L'<<8|'E') 
     33#define SIGNATURE           ('F'<<24|'P'<<16|'L'<<8|'Y') 
     34#define BYTES_PER_SAMPLE    2 
     35 
    3936 
    4037#if 1 
     
    4542 
    4643#if defined(PJ_IS_BIG_ENDIAN) && PJ_IS_BIG_ENDIAN!=0 
    47     PJ_INLINE(pj_int16_t) swap16(pj_int16_t val) 
    48     { 
    49         pj_uint8_t *p = (pj_uint8_t*)&val; 
    50         pj_uint8_t tmp = *p; 
    51         *p = *(p+1); 
    52         *(p+1) = tmp; 
    53         return val; 
    54     } 
    55     PJ_INLINE(pj_int32_t) swap32(pj_int32_t val) 
    56     { 
    57         pj_uint8_t *p = (pj_uint8_t*)&val; 
    58         pj_uint8_t tmp = *p; 
    59         *p = *(p+3); 
    60         *(p+3) = tmp; 
    61         tmp = *(p+1); 
    62         *(p+1) = *(p+2); 
    63         *(p+2) = tmp; 
    64         return val; 
    65     } 
    66 #   define SWAP16(val16)        swap16(val16) 
    67 #   define SWAP32(val32)        swap32(val32) 
    6844    static void samples_to_host(pj_int16_t *samples, unsigned count) 
    6945    { 
    7046        unsigned i; 
    7147        for (i=0; i<count; ++i) { 
    72             samples[i] = SWAP16(samples[i]); 
     48            samples[i] = pj_swap16(samples[i]); 
    7349        } 
    7450    } 
    7551#else 
    76 #   define SWAP16(val16)        (val16) 
    77 #   define SWAP32(val32)        (val32) 
    7852#   define samples_to_host(samples,count) 
    7953#endif 
     
    171145 
    172146    /* Convert samples to host rep */ 
    173     samples_to_host((pj_int16_t*)fport->buf, fport->bufsize/2); 
     147    samples_to_host((pj_int16_t*)fport->buf, fport->bufsize/BYTES_PER_SAMPLE); 
    174148 
    175149    return PJ_SUCCESS; 
    176150} 
    177  
    178  
    179 /* 
    180  * Change the endianness of WAVE header fields. 
    181  */ 
    182 void pjmedia_wave_hdr_swap_bytes( pjmedia_wave_hdr *hdr ) 
    183 { 
    184     hdr->riff_hdr.riff              = SWAP32(hdr->riff_hdr.riff); 
    185     hdr->riff_hdr.file_len          = SWAP32(hdr->riff_hdr.file_len); 
    186     hdr->riff_hdr.wave              = SWAP32(hdr->riff_hdr.wave); 
    187      
    188     hdr->fmt_hdr.fmt                = SWAP32(hdr->fmt_hdr.fmt); 
    189     hdr->fmt_hdr.len                = SWAP32(hdr->fmt_hdr.len); 
    190     hdr->fmt_hdr.fmt_tag            = SWAP16(hdr->fmt_hdr.fmt_tag); 
    191     hdr->fmt_hdr.nchan              = SWAP16(hdr->fmt_hdr.nchan); 
    192     hdr->fmt_hdr.sample_rate        = SWAP32(hdr->fmt_hdr.sample_rate); 
    193     hdr->fmt_hdr.bytes_per_sec      = SWAP32(hdr->fmt_hdr.bytes_per_sec); 
    194     hdr->fmt_hdr.block_align        = SWAP16(hdr->fmt_hdr.block_align); 
    195     hdr->fmt_hdr.bits_per_sample    = SWAP16(hdr->fmt_hdr.bits_per_sample); 
    196      
    197     hdr->data_hdr.data              = SWAP32(hdr->data_hdr.data); 
    198     hdr->data_hdr.len               = SWAP32(hdr->data_hdr.len); 
    199 } 
    200  
    201  
    202 #if defined(PJ_IS_BIG_ENDIAN) && PJ_IS_BIG_ENDIAN!=0 
    203 #   define normalize_wave_hdr(hdr)  pjmedia_wave_hdr_swap_bytes(hdr) 
    204 #else 
    205 #   define normalize_wave_hdr(hdr) 
    206 #endif 
    207151 
    208152 
     
    224168 
    225169    PJ_UNUSED_ARG(flags); 
    226     PJ_UNUSED_ARG(buff_size); 
    227170 
    228171    /* Check arguments. */ 
     
    266209    } 
    267210 
    268     /* Normalize WAVE header fields value (only used in big-endian hosts) */ 
    269     normalize_wave_hdr(&wave_hdr); 
     211    /* Normalize WAVE header fields values from little-endian to host 
     212     * byte order. 
     213     */ 
     214    pjmedia_wave_hdr_file_to_host(&wave_hdr); 
    270215     
    271216    /* Validate WAVE file. */ 
     
    292237 
    293238    /* Block align must be 2*nchannels */ 
    294     if (wave_hdr.fmt_hdr.block_align != wave_hdr.fmt_hdr.nchan*2) { 
     239    if (wave_hdr.fmt_hdr.block_align != wave_hdr.fmt_hdr.nchan*BYTES_PER_SAMPLE) { 
    295240        pj_file_close(fport->fd); 
    296241        return PJMEDIA_EWAVEUNSUPP; 
     
    327272    /* Create file buffer. 
    328273     */ 
    329     fport->bufsize = PJMEDIA_FILE_PORT_BUFSIZE; 
     274    if (buff_size < 1) buff_size = PJMEDIA_FILE_PORT_BUFSIZE; 
     275    fport->bufsize = buff_size; 
    330276 
    331277 
     
    355301 
    356302    PJ_LOG(4,(THIS_FILE,  
    357               "File port '%.*s' created: clock=%dKHz, bufsize=%uKB, " 
     303              "File player '%.*s' created: samp.rate=%d, ch=%d, bufsize=%uKB, " 
    358304              "filesize=%luKB", 
    359305              (int)fport->base.info.name.slen, 
    360306              fport->base.info.name.ptr, 
    361               fport->base.info.sample_rate/1000, 
     307              fport->base.info.sample_rate, 
     308              fport->base.info.channel_count, 
    362309              fport->bufsize / 1000, 
    363310              (unsigned long)(fport->fsize / 1000))); 
     
    390337    pj_assert(fport->base.info.signature == SIGNATURE); 
    391338 
    392     frame_size = fport->base.info.bytes_per_frame; 
    393     pj_assert(frame->size == frame_size); 
     339    //frame_size = fport->base.info.bytes_per_frame; 
     340    //pj_assert(frame->size == frame_size); 
     341    frame_size = frame->size; 
    394342 
    395343    /* Copy frame from buffer. */ 
  • pjproject/trunk/pjmedia/src/pjmedia/pasound.c

    r352 r358  
    132132    } 
    133133 
    134     if (statusFlags & paInputUnderflow) 
     134    if (statusFlags & paOutputUnderflow) 
    135135        ++stream->underflow; 
    136     if (statusFlags & paInputOverflow) 
     136    if (statusFlags & paOutputOverflow) 
    137137        ++stream->overflow; 
    138138 
     
    240240    int sampleFormat; 
    241241    const PaDeviceInfo *paDevInfo = NULL; 
     242    const PaHostApiInfo *paHostApiInfo = NULL; 
    242243    unsigned paFrames; 
    243244    PaError err; 
     
    292293    inputParam.suggestedLatency = paDevInfo->defaultLowInputLatency; 
    293294 
     295    paHostApiInfo = Pa_GetHostApiInfo(paDevInfo->hostApi); 
     296 
    294297    /* Frames in PortAudio is number of samples in a single channel */ 
    295298    paFrames = samples_per_frame / channel_count; 
     
    303306    } 
    304307 
    305     PJ_LOG(5,(THIS_FILE, "%s opening device %s for recording, sample rate=%d, " 
    306                          "channel count=%d, " 
    307                          "%d bits per sample, %d samples per buffer", 
     308    PJ_LOG(5,(THIS_FILE, "%s opening device %s (%s) for recording, sample " 
     309                         "rate=%d, ch=%d, " 
     310                         "bits=%d, %d samples per frame", 
    308311                         (err==0 ? "Success" : "Error"), 
    309                          paDevInfo->name, clock_rate, channel_count, 
     312                         paDevInfo->name, paHostApiInfo->name, 
     313                         clock_rate, channel_count, 
    310314                         bits_per_sample, samples_per_frame)); 
    311315 
     
    329333    int sampleFormat; 
    330334    const PaDeviceInfo *paDevInfo = NULL; 
     335    const PaHostApiInfo *paHostApiInfo = NULL; 
    331336    unsigned paFrames; 
    332337    PaError err; 
     
    381386    outputParam.suggestedLatency = paDevInfo->defaultLowInputLatency; 
    382387 
     388    paHostApiInfo = Pa_GetHostApiInfo(paDevInfo->hostApi); 
     389 
    383390    /* Frames in PortAudio is number of samples in a single channel */ 
    384391    paFrames = samples_per_frame / channel_count; 
     
    392399    } 
    393400 
    394     PJ_LOG(5,(THIS_FILE, "%s opening device %s for playing, sample rate=%d, " 
    395                          "channel count=%d, " 
    396                          "%d bits per sample, %d samples per frame", 
     401    PJ_LOG(5,(THIS_FILE, "%s opening device %s(%s) for playing, sample rate=%d" 
     402                         ", ch=%d, " 
     403                         "bits=%d, %d samples per frame", 
    397404                         (err==0 ? "Success" : "Error"), 
    398                          paDevInfo->name, clock_rate, channel_count, 
     405                         paDevInfo->name, paHostApiInfo->name,  
     406                         clock_rate, channel_count, 
    399407                         bits_per_sample, samples_per_frame)); 
    400408 
     
    426434    const PaDeviceInfo *paRecDevInfo = NULL; 
    427435    const PaDeviceInfo *paPlayDevInfo = NULL; 
     436    const PaHostApiInfo *paRecHostApiInfo = NULL; 
     437    const PaHostApiInfo *paPlayHostApiInfo = NULL; 
    428438    unsigned paFrames; 
    429439    PaError err; 
     
    498508    inputParam.suggestedLatency = paRecDevInfo->defaultLowInputLatency; 
    499509 
     510    paRecHostApiInfo = Pa_GetHostApiInfo(paRecDevInfo->hostApi); 
     511 
    500512    pj_memset(&outputParam, 0, sizeof(outputParam)); 
    501513    outputParam.device = play_id; 
     
    503515    outputParam.hostApiSpecificStreamInfo = NULL; 
    504516    outputParam.sampleFormat = sampleFormat; 
    505     outputParam.suggestedLatency = paPlayDevInfo->defaultLowInputLatency; 
     517    outputParam.suggestedLatency = paPlayDevInfo->defaultLowOutputLatency; 
     518 
     519    paPlayHostApiInfo = Pa_GetHostApiInfo(paPlayDevInfo->hostApi); 
    506520 
    507521    /* Frames in PortAudio is number of samples in a single channel */ 
     
    516530    } 
    517531 
    518     PJ_LOG(5,(THIS_FILE, "%s opening device %s/%s for recording and playback, " 
    519                          "sample rate=%d, channel count=%d, " 
    520                          "%d bits per sample, %d samples per buffer", 
     532    PJ_LOG(5,(THIS_FILE, "%s opening device %s(%s)/%s(%s) for recording and " 
     533                         "playback, sample rate=%d, ch=%d, " 
     534                         "bits=%d, %d samples per frame", 
    521535                         (err==0 ? "Success" : "Error"), 
    522                          paRecDevInfo->name, paPlayDevInfo->name, 
     536                         paRecDevInfo->name, paRecHostApiInfo->name, 
     537                         paPlayDevInfo->name, paPlayHostApiInfo->name, 
    523538                         clock_rate, channel_count, 
    524539                         bits_per_sample, samples_per_frame)); 
  • pjproject/trunk/pjmedia/src/pjmedia/port.c

    r335 r358  
    3636    PJ_ASSERT_RETURN(pool && upstream_port && downstream_port, PJ_EINVAL); 
    3737 
     38#if 0 
    3839    /* They both MUST have the same media type. */ 
    3940    PJ_ASSERT_RETURN(upstream_port->info.type == 
     
    5859                     downstream_port->info.bytes_per_frame,  
    5960                     PJMEDIA_ENCBYTES); 
     61#endif 
    6062 
    6163    /* Create mutual attachment. */ 
    62     status = upstream_port->on_downstream_connect( pool, upstream_port, 
    63                                                    downstream_port ); 
    64     if (status != PJ_SUCCESS) 
    65         return status; 
     64    if (upstream_port->on_downstream_connect) { 
     65        status = upstream_port->on_downstream_connect( pool, upstream_port, 
     66                                                       downstream_port ); 
     67        if (status != PJ_SUCCESS) 
     68            return status; 
     69    } 
    6670 
    67     status = downstream_port->on_upstream_connect( pool, downstream_port, 
    68                                                    upstream_port ); 
    69     if (status != PJ_SUCCESS) 
    70         return status; 
     71    if (downstream_port->on_upstream_connect) { 
     72        status = downstream_port->on_upstream_connect( pool, downstream_port, 
     73                                                       upstream_port ); 
     74        if (status != PJ_SUCCESS) 
     75            return status; 
     76    } 
    7177 
    7278    /* Save the attachment. */ 
  • pjproject/trunk/pjmedia/src/pjmedia/resample.c

    r347 r358  
    499499     */ 
    500500    if (rate_out < rate_in) { 
    501         high_quality = 0; 
     501        //high_quality = 0; 
    502502    } 
    503503 
     
    580580         */ 
    581581        dst_buf = resample->buffer + resample->xoff*2; 
    582         for (i=0; i<resample->frame_size; ++i) 
    583             dst_buf[i] = input[i]; 
     582        for (i=0; i<resample->frame_size; ++i) dst_buf[i] = input[i]; 
    584583             
    585584        if (resample->factor >= 1) { 
     
    633632    } 
    634633} 
     634 
     635PJ_DEF(unsigned) pjmedia_resample_get_input_size(pjmedia_resample *resample) 
     636{ 
     637    PJ_ASSERT_RETURN(resample != NULL, 0); 
     638    return resample->frame_size; 
     639} 
     640 
  • pjproject/trunk/pjmedia/src/pjmedia/sound_port.c

    r352 r358  
    7171        goto no_frame; 
    7272 
     73    /* Must supply the required samples */ 
     74    pj_assert(frame.size == size); 
     75 
    7376    return PJ_SUCCESS; 
    7477 
Note: See TracChangeset for help on using the changeset viewer.