| 98 | |
| 99 | [[BR]] |
| 100 | |
| 101 | == Porting applications to new API == |
| 102 | |
| 103 | As stated above, existing applications should build fine with the new changes. However, it will still be beneficial to port the application to use the new API since the old sound API has been deprecated, and also to make use of the new features in the new Audio Device API. |
| 104 | |
| 105 | This section describes how to port applications to use the new Audio Device API. |
| 106 | |
| 107 | === PJSUA-LIB applications === |
| 108 | |
| 109 | PJSUA-LIB applications that only make use of the API in {{{<pjsua.h>}}} should require minimum changes. |
| 110 | |
| 111 | 1. Change in {{{pjsua_enum_snd_devs()}}} signature. Old API: |
| 112 | {{{ |
| 113 | PJ_DECL(pj_status_t) pjsua_enum_snd_devs(pjmedia_snd_dev_info info[], unsigned *count); |
| 114 | }}} |
| 115 | New API (notice the type difference in the ''info'' argument): |
| 116 | {{{ |
| 117 | PJ_DECL(pj_status_t) pjsua_enum_snd_devs(pjmedia_aud_dev_info info[], unsigned *count); |
| 118 | }}} |
| 119 | |
| 120 | 2. Add '''pjmedia-audiodev''' library to the link specifications of your application. |
| 121 | |
| 122 | |
| 123 | === PJMEDIA applications === |
| 124 | |
| 125 | Below are list of changes for applications that directly uses the old sound API as declared in {{{<pjmedia/sound.h>}}}. |
| 126 | |
| 127 | 1. Change the header file to include. Old code: |
| 128 | {{{ |
| 129 | #include <pjmedia/sound.h> |
| 130 | }}} |
| 131 | New code: |
| 132 | {{{ |
| 133 | #include <pjmedia_audiodev.h> |
| 134 | }}} |
| 135 | 2. Add '''pjmedia-audiodev''' library to the link specifications of your application. |
| 136 | 3. Sound device subsystem startup and shutdown. Old code: |
| 137 | {{{ |
| 138 | pjmedia_snd_init(pf); |
| 139 | ... |
| 140 | pjmedia_snd_deinit(); |
| 141 | }}} |
| 142 | New code: |
| 143 | {{{ |
| 144 | pjmedia_aud_subsys_init(pf); |
| 145 | ... |
| 146 | pjmedia_aud_subsys_shutdown(); |
| 147 | }}} |
| 148 | 4. Device enumeration. Old code: |
| 149 | {{{ |
| 150 | unsigned i, dev_count; |
| 151 | |
| 152 | dev_count = pjmedia_snd_get_dev_count(); |
| 153 | for (i=0; i<dev_count; ++i) { |
| 154 | const pjmedia_snd_dev_info *dev_info = pjmedia_snd_get_dev_info(i); |
| 155 | } |
| 156 | }}} |
| 157 | New code: |
| 158 | {{{ |
| 159 | unsigned i, dev_count; |
| 160 | |
| 161 | dev_count = pjmedia_aud_dev_count(); |
| 162 | for (i=0; i<dev_count; ++i) { |
| 163 | pjmedia_aud_dev_info dev_info; |
| 164 | pj_status_t status; |
| 165 | |
| 166 | status = pjmedia_aud_dev_get_info(i, &info); |
| 167 | } |
| 168 | }}} |
| 169 | 5. Opening sound device. Old code: |
| 170 | {{{ |
| 171 | pjmedia_snd_stream *stream; |
| 172 | pj_status_t status; |
| 173 | |
| 174 | status = pjmedia_snd_open(-1, // default capture device ID |
| 175 | -1, // default playback device ID |
| 176 | 8000, // clock rate |
| 177 | 1, // channel count |
| 178 | 160, // samples per frame |
| 179 | 16, // bits per sample |
| 180 | &rec_cb, // capture callback |
| 181 | &play_cb, // playback callback |
| 182 | user_data, |
| 183 | &stream); |
| 184 | if (status != PJ_SUCCESS) |
| 185 | .. |
| 186 | }}} |
| 187 | New code: |
| 188 | {{{ |
| 189 | pjmedia_aud_dev_param param; |
| 190 | pjmedia_aud_stream *stream; |
| 191 | pj_status_t status; |
| 192 | |
| 193 | status = pjmedia_aud_dev_default_param(PJMEDIA_AUD_DEV_DEFAULT, ¶m); |
| 194 | if (status != PJ_SUCCESS) |
| 195 | .. |
| 196 | |
| 197 | param.dir = PJMEDIA_DIR_CAPTURE_PLAYBACK; |
| 198 | param.rec_id = PJMEDIA_AUD_DEV_DEFAULT; |
| 199 | param.play_id = PJMEDIA_AUD_DEV_DEFAULT; |
| 200 | param.clock_rate = 8000; |
| 201 | param.channel_count = 1; |
| 202 | param.samples_per_frame = 160; |
| 203 | param.bits_per_sample = 16; |
| 204 | .. // put additional settings here |
| 205 | |
| 206 | status = pjmedia_aud_stream_create(¶m, |
| 207 | &rec_cb, |
| 208 | &play_cb, |
| 209 | user_data, |
| 210 | &stream); |
| 211 | if (status != PJ_SUCCESS) |
| 212 | .. |
| 213 | }}} |
| 214 | 6. .. and so on |
| 215 | |
| 216 | |
| 217 | |