| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
#include <pjmedia.h> |
| 21 |
#include <pjlib-util.h> |
| 22 |
#include <pjlib.h> |
| 23 |
#include <stdio.h> |
| 24 |
#include <stdlib.h> |
| 25 |
|
| 26 |
#include "util.h" |
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
#define THIS_FILE "playfile.c" |
| 62 |
|
| 63 |
|
| 64 |
static const char *desc = |
| 65 |
" FILE \n" |
| 66 |
" \n" |
| 67 |
" playfile.c \n" |
| 68 |
" \n" |
| 69 |
" PURPOSE \n" |
| 70 |
" \n" |
| 71 |
" Demonstrate how to play a WAV file. \n" |
| 72 |
" \n" |
| 73 |
" USAGE \n" |
| 74 |
" \n" |
| 75 |
" playfile FILE.WAV \n" |
| 76 |
" \n" |
| 77 |
" The WAV file could have mono or stereo channels with arbitrary \n" |
| 78 |
" sampling rate, but MUST contain uncompressed (i.e. 16bit) PCM. \n"; |
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
int main(int argc, char *argv[]) |
| 85 |
{ |
| 86 |
pj_caching_pool cp; |
| 87 |
pjmedia_endpt *med_endpt; |
| 88 |
pj_pool_t *pool; |
| 89 |
pjmedia_port *file_port; |
| 90 |
pjmedia_snd_port *snd_port; |
| 91 |
char tmp[10]; |
| 92 |
pj_status_t status; |
| 93 |
|
| 94 |
|
| 95 |
if (argc != 2) { |
| 96 |
puts("Error: filename required"); |
| 97 |
puts(desc); |
| 98 |
return 1; |
| 99 |
} |
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
status = pj_init(); |
| 104 |
PJ_ASSERT_RETURN(status == PJ_SUCCESS, 1); |
| 105 |
|
| 106 |
|
| 107 |
pj_caching_pool_init(&cp, &pj_pool_factory_default_policy, 0); |
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
status = pjmedia_endpt_create(&cp.factory, NULL, 1, &med_endpt); |
| 114 |
PJ_ASSERT_RETURN(status == PJ_SUCCESS, 1); |
| 115 |
|
| 116 |
|
| 117 |
pool = pj_pool_create( &cp.factory, |
| 118 |
"wav", |
| 119 |
4000, |
| 120 |
4000, |
| 121 |
NULL |
| 122 |
); |
| 123 |
|
| 124 |
|
| 125 |
status = pjmedia_wav_player_port_create( pool, |
| 126 |
argv[1], |
| 127 |
20, |
| 128 |
0, |
| 129 |
0, |
| 130 |
&file_port |
| 131 |
); |
| 132 |
if (status != PJ_SUCCESS) { |
| 133 |
app_perror(THIS_FILE, "Unable to use WAV file", status); |
| 134 |
return 1; |
| 135 |
} |
| 136 |
|
| 137 |
|
| 138 |
status = pjmedia_snd_port_create_player( |
| 139 |
pool, |
| 140 |
-1, |
| 141 |
PJMEDIA_PIA_SRATE(&file_port->info), |
| 142 |
PJMEDIA_PIA_CCNT(&file_port->info), |
| 143 |
PJMEDIA_PIA_SPF(&file_port->info), |
| 144 |
PJMEDIA_PIA_BITS(&file_port->info), |
| 145 |
0, |
| 146 |
&snd_port |
| 147 |
); |
| 148 |
if (status != PJ_SUCCESS) { |
| 149 |
app_perror(THIS_FILE, "Unable to open sound device", status); |
| 150 |
return 1; |
| 151 |
} |
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
status = pjmedia_snd_port_connect( snd_port, file_port); |
| 157 |
PJ_ASSERT_RETURN(status == PJ_SUCCESS, 1); |
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
pj_thread_sleep(100); |
| 168 |
|
| 169 |
|
| 170 |
printf("Playing %s..\n", argv[1]); |
| 171 |
puts(""); |
| 172 |
puts("Press <ENTER> to stop playing and quit"); |
| 173 |
|
| 174 |
if (fgets(tmp, sizeof(tmp), stdin) == NULL) { |
| 175 |
puts("EOF while reading stdin, will quit now.."); |
| 176 |
} |
| 177 |
|
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
status = pjmedia_snd_port_disconnect(snd_port); |
| 183 |
PJ_ASSERT_RETURN(status == PJ_SUCCESS, 1); |
| 184 |
|
| 185 |
|
| 186 |
|
| 187 |
|
| 188 |
pj_thread_sleep(100); |
| 189 |
|
| 190 |
|
| 191 |
status = pjmedia_snd_port_destroy( snd_port ); |
| 192 |
PJ_ASSERT_RETURN(status == PJ_SUCCESS, 1); |
| 193 |
|
| 194 |
|
| 195 |
|
| 196 |
status = pjmedia_port_destroy( file_port ); |
| 197 |
PJ_ASSERT_RETURN(status == PJ_SUCCESS, 1); |
| 198 |
|
| 199 |
|
| 200 |
|
| 201 |
pj_pool_release( pool ); |
| 202 |
|
| 203 |
|
| 204 |
pjmedia_endpt_destroy( med_endpt ); |
| 205 |
|
| 206 |
|
| 207 |
pj_caching_pool_destroy( &cp ); |
| 208 |
|
| 209 |
|
| 210 |
pj_shutdown(); |
| 211 |
|
| 212 |
|
| 213 |
|
| 214 |
return 0; |
| 215 |
} |
| 216 |
|