|
HOME
SIP/media Features
High Performance SIP
Small Footprint SIP
Symbian Port
FAQ
Documentation
Licensing
Download
Development (Trac)
Projects using pjsip
Mailing List
Open Source Links
About: PJLIB, PJLIB-UTIL, PJSIP, and PJMEDIA are created by: Benny Prijono <bennylp pjsip.org>
|
|
Home --> Documentations --> PJMEDIA Reference
This example demonstrates how to use Resample Port to change the sampling rate of the media streams.
This file is pjsip-apps/src/samples/resampleplay.c
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00032 #include <pjmedia.h>
00033 #include <pjlib-util.h>
00034 #include <pjlib.h>
00035
00036 #include <stdio.h>
00037 #include <stdlib.h>
00038
00039 #include "util.h"
00040
00041
00042 #define THIS_FILE "resampleplay.c"
00043
00044
00045 static const char *desc =
00046 " FILE \n"
00047 " \n"
00048 " resampleplay.c \n"
00049 " \n"
00050 " PURPOSE \n"
00051 " \n"
00052 " Demonstrate how use resample port to play a WAV file to sound \n"
00053 " device using different sampling rate. \n"
00054 " \n"
00055 " USAGE \n"
00056 " \n"
00057 " resampleplay [options] FILE.WAV \n"
00058 " \n"
00059 " where options: \n"
00060 SND_USAGE
00061 " \n"
00062 " The WAV file could have mono or stereo channels with arbitrary \n"
00063 " sampling rate, but MUST contain uncompressed (i.e. 16bit) PCM. \n";
00064
00065
00066 int main(int argc, char *argv[])
00067 {
00068 pj_caching_pool cp;
00069 pjmedia_endpt *med_endpt;
00070 pj_pool_t *pool;
00071 pjmedia_port *file_port;
00072 pjmedia_port *resample_port;
00073 pjmedia_snd_port *snd_port;
00074 char tmp[10];
00075 pj_status_t status;
00076
00077 int dev_id = -1;
00078 int sampling_rate = CLOCK_RATE;
00079 int channel_count = NCHANNELS;
00080 int samples_per_frame = NSAMPLES;
00081 int bits_per_sample = NBITS;
00082
00083
00084
00085
00086 status = pj_init();
00087 PJ_ASSERT_RETURN(status == PJ_SUCCESS, 1);
00088
00089
00090
00091 if (get_snd_options(THIS_FILE, argc, argv, &dev_id, &sampling_rate,
00092 &channel_count, &samples_per_frame, &bits_per_sample))
00093 {
00094 puts("");
00095 puts(desc);
00096 return 1;
00097 }
00098
00099 if (!argv[pj_optind]) {
00100 puts("Error: no file is specified");
00101 puts(desc);
00102 return 1;
00103 }
00104
00105
00106 pj_caching_pool_init(&cp, &pj_pool_factory_default_policy, 0);
00107
00108
00109
00110
00111
00112 status = pjmedia_endpt_create(&cp.factory, NULL, 1, &med_endpt);
00113 PJ_ASSERT_RETURN(status == PJ_SUCCESS, 1);
00114
00115
00116 pool = pj_pool_create( &cp.factory,
00117 "app",
00118 4000,
00119 4000,
00120 NULL
00121 );
00122
00123
00124 status = pjmedia_wav_player_port_create( pool, argv[pj_optind], 0, 0,
00125 0, &file_port);
00126 if (status != PJ_SUCCESS) {
00127 app_perror(THIS_FILE, "Unable to open file", status);
00128 return 1;
00129 }
00130
00131
00132 if (file_port->info.channel_count != (unsigned)channel_count) {
00133 PJ_LOG(3,(THIS_FILE, "Error: file has different number of channels. "
00134 "Perhaps you'd need -c option?"));
00135 pjmedia_port_destroy(file_port);
00136 return 1;
00137 }
00138
00139
00140
00141
00142
00143 status = pjmedia_resample_port_create( pool, file_port,
00144 sampling_rate, 0,
00145 &resample_port);
00146 if (status != PJ_SUCCESS) {
00147 app_perror(THIS_FILE, "Unable to create resample port", status);
00148 return 1;
00149 }
00150
00151
00152 status = pjmedia_snd_port_create(
00153 pool,
00154 dev_id,
00155 dev_id,
00156 sampling_rate,
00157 channel_count,
00158 samples_per_frame,
00159 bits_per_sample,
00160 0,
00161 &snd_port
00162 );
00163 if (status != PJ_SUCCESS) {
00164 app_perror(THIS_FILE, "Unable to open sound device", status);
00165 return 1;
00166 }
00167
00168
00169 status = pjmedia_snd_port_connect( snd_port, resample_port);
00170 if (status != PJ_SUCCESS) {
00171 app_perror(THIS_FILE, "Error connecting sound ports", status);
00172 return 1;
00173 }
00174
00175
00176
00177 dump_pool_usage(THIS_FILE, &cp);
00178
00179
00180
00181
00182
00183
00184
00185 pj_thread_sleep(100);
00186
00187
00188 printf("Playing %s at sampling rate %d (original file sampling rate=%d)\n",
00189 argv[pj_optind], sampling_rate, file_port->info.clock_rate);
00190 puts("");
00191 puts("Press <ENTER> to stop playing and quit");
00192
00193 if (fgets(tmp, sizeof(tmp), stdin) == NULL) {
00194 puts("EOF while reading stdin, will quit now..");
00195 }
00196
00197
00198
00199
00200
00201 status = pjmedia_snd_port_destroy( snd_port );
00202 PJ_ASSERT_RETURN(status == PJ_SUCCESS, 1);
00203
00204
00205
00206
00207
00208 status = pjmedia_port_destroy( resample_port );
00209 PJ_ASSERT_RETURN(status == PJ_SUCCESS, 1);
00210
00211
00212
00213 pj_pool_release( pool );
00214
00215
00216 pjmedia_endpt_destroy( med_endpt );
00217
00218
00219 pj_caching_pool_destroy( &cp );
00220
00221
00222 pj_shutdown();
00223
00224
00225
00226 return 0;
00227
00228 }
00229
00230
00231
PJMEDIA small footprint Open Source media stack
Copyright (C) 2006-2008 Teluu Inc.
|
|