Changeset 1420:36debeac687f in mediastreamer2
- Timestamp:
- Oct 12, 2011 11:40:59 AM (20 months ago)
- Branch:
- default
- Location:
- src
- Files:
-
- 2 edited
-
CMakeLists.txt (modified) (2 diffs)
-
msandroid.cpp (modified) (17 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/CMakeLists.txt
r1412 r1420 34 34 if(ANDROID) 35 35 set(MS_SRCS ${MS_SRCS} msandroid.cpp msjava.c) 36 include_directories("${CMAKE_CURRENT_SOURCE_DIR}/../build/android") 36 37 add_definitions( 38 -include${CMAKE_CURRENT_SOURCE_DIR}/../build/android/libmediastreamer2_AndroidConfig.h) 39 include_directories("${CMAKE_CURRENT_SOURCE_DIR}/../build/android" dummy .) 40 41 if (USE_WEBRTC) 42 set(MS_SRCS ${MS_SRCS} msandroid_webrtc.cpp) 43 #set(MS_SRCS ${MS_SRCS} audio_device_android_jni.cc audio_device_buffer.cc 44 # file_impl.cc audio_device_utility.cc thread.cc thread_posix.cc 45 # critical_section_posix.cc critical_section.cc event_posix.cc 46 # event.cc audio_device_generic.cc audio_device_impl.cc 47 # dummy/audio_device_dummy.cc dummy/audio_device_utility_dummy.cc 48 # audio_device_utility_android.cc atomic32.cc msandroid_webrtc.cpp) 49 add_definitions(-DWEBRTC_ANDROID -DWEBRTC_CLOCK_TYPE_REALTIME 50 -DWEBRTC_LINUX) 51 endif() 52 37 53 endif() 38 54 … … 126 142 endif() 127 143 128 configure_file("${CMAKE_CURRENT_SOURCE_DIR}/mediastreamer-config.h.cmake" "${CMAKE_CURRENT_BINARY_DIR}/mediastreamer-config.h") 129 add_definitions( 144 if(NOT ANDROID) 145 configure_file("${CMAKE_CURRENT_SOURCE_DIR}/mediastreamer-config.h.cmake" "${CMAKE_CURRENT_BINARY_DIR}/mediastreamer-config.h") 146 add_definitions( 130 147 -DHAVE_CONFIG_H 131 148 ) 149 endif() 132 150 133 151 include_directories(${mediastreamer_SOURCE_DIR}/include ${CMAKE_CURRENT_BINARY_DIR} ${ORTP_INCLUDE_DIRS}) -
src/msandroid.cpp
r1387 r1420 20 20 */ 21 21 22 #include <sys/times.h> 23 #include <sys/resource.h> 22 24 #include "mediastreamer2/mssndcard.h" 23 25 #include "mediastreamer2/msfilter.h" … … 26 28 #include <jni.h> 27 29 30 28 31 static const float sndwrite_flush_threshold=0.050; //ms 29 32 … … 31 34 32 35 static void set_high_prio(void){ 33 struct sched_param param;34 36 int result=0; 37 /* struct sched_param param; 35 38 memset(¶m,0,sizeof(param)); 36 39 int policy=SCHED_OTHER; 37 param.sched_priority=sched_get_priority_max(policy); 38 if((result= pthread_setschedparam(pthread_self(),policy, ¶m))) {40 param.sched_priority=sched_get_priority_max(policy);*/ 41 if((result=setpriority(PRIO_PROCESS, gettid(), -19))) { 39 42 ms_warning("Set sched param failed with error code(%i)\n",result); 40 43 } else { 41 ms_ message("msandroid thread priority set to max");44 ms_error("msandroid thread priority set to max %x\n", -19); 42 45 } 43 46 } … … 189 192 jmethodID read_id=0; 190 193 jmethodID record_id=0; 194 jbyte* buf; 195 191 196 192 197 set_high_prio(); 193 198 194 199 JNIEnv *jni_env = ms_get_jni_env(); 200 201 ms_debug("read thread cb"); 195 202 record_id = jni_env->GetMethodID(d->audio_record_class,"startRecording", "()V"); 196 203 if(record_id==0) { … … 208 215 } 209 216 210 while (d->started && (nread=jni_env->CallIntMethod(d->audio_record,read_id,d->read_buff,0, d->read_chunk_size))>0) { 217 buf = jni_env->GetByteArrayElements(d->read_buff, 0); 218 219 while (d->started){ 220 bzero(buf, d->read_chunk_size); 221 nread=jni_env->CallIntMethod(d->audio_record,read_id,d->read_buff,0, d->read_chunk_size); 222 if (nread <= 0 || nread != d->read_chunk_size) { 223 ms_error("read failed with %d", nread); 224 continue; 225 } 211 226 m = allocb(nread,0); 212 jni_env->GetByteArrayRegion(d->read_buff, 0,nread, (jbyte*)m->b_wptr); 213 //ms_error("%i octets read",nread); 227 //jni_env->GetByteArrayRegion(d->read_buff, 0,nread, (jbyte*)m->b_wptr); 228 memcpy((jbyte*)m->b_wptr, buf, nread); 229 // ms_error("%i octets read\n begin %x",nread, *m->b_wptr); 214 230 m->b_wptr += nread; 215 231 ms_mutex_lock(&d->mutex); … … 220 236 goto end; 221 237 end: { 238 ms_debug("record thread finished"); 222 239 ms_thread_exit(NULL); 223 240 return 0; … … 252 269 } 253 270 d->buff_size = jni_env->CallStaticIntMethod(d->audio_record_class,min_buff_size_id,d->rate,2/*CHANNEL_CONFIGURATION_MONO*/,2/* ENCODING_PCM_16BIT */); 254 d->read_chunk_size = d->buff_size/2; 271 if (d->buff_size <= 4096) d->buff_size = 4096*3/2; 272 d->read_chunk_size = 0.02*(float)d->rate*2.0*(float)d->nchannels; 273 255 274 256 275 if (d->buff_size > 0) { … … 280 299 d->audio_record = jni_env->NewObject(d->audio_record_class 281 300 ,constructor_id 282 , 1/*MIC*/301 ,7/*MIC*/ 283 302 ,d->rate 284 303 ,2/*CHANNEL_CONFIGURATION_MONO*/ … … 287 306 288 307 289 d->audio_record = jni_env->NewGlobalRef(d->audio_record); 308 jmethodID state_method_id = jni_env->GetMethodID(d->audio_record_class,"getState", "()I"); 309 int state = jni_env->CallIntMethod(d->audio_record, state_method_id); 310 if(state == 0){ /* STATE_UNINITIALIZED */ 311 312 jmethodID release_method_id = jni_env->GetMethodID(d->audio_record_class,"release", "()V"); 313 jni_env->CallIntMethod(d->audio_record, release_method_id); 314 d->audio_record = jni_env->NewObject(d->audio_record_class 315 ,constructor_id 316 ,1/*MIC*/ 317 ,d->rate 318 ,2/*CHANNEL_CONFIGURATION_MONO*/ 319 ,2/* ENCODING_PCM_16BIT */ 320 ,d->buff_size); 321 322 state = jni_env->CallIntMethod(d->audio_record, state_method_id); 323 324 if (state == 0){ 325 jni_env->CallIntMethod(d->audio_record, release_method_id); 326 ms_error("cannot instanciate audio record"); 327 return; 328 } 329 ms_debug("audio record ok with dev %d bis", 1); 330 331 }else 332 ms_debug("audio record ok with dev %d", 1); 333 334 335 290 336 if (d->audio_record == 0) { 291 337 ms_error("cannot instanciate AudioRecord"); 292 338 return; 293 339 } 340 d->audio_record = jni_env->NewGlobalRef(d->audio_record); 294 341 295 342 d->started=true; 296 // start reader thread297 rc = ms_thread_create(&d->thread_id, 0, (void*(*)(void*))msandroid_read_cb, d);298 if (rc){299 ms_error("cannot create read thread return code is [%i]", rc);300 d->started=false;301 }302 343 } 303 344 … … 316 357 JNIEnv *jni_env = ms_get_jni_env(); 317 358 359 d->started = false; 360 if (d->thread_id !=0) ms_thread_join(d->thread_id,0); 361 318 362 //stop recording 319 363 stop_id = jni_env->GetMethodID(d->audio_record_class,"stop", "()V"); … … 323 367 } 324 368 325 d->started = false;326 if (d->thread_id !=0) ms_thread_join(d->thread_id,0);327 328 369 if (d->audio_record) { 329 370 jni_env->CallVoidMethod(d->audio_record,stop_id); … … 350 391 int nbytes=0.02*(float)d->rate*2.0*(float)d->nchannels; 351 392 393 if (d->thread_id == 0) { 394 int rc = ms_thread_create(&d->thread_id, 0, (void*(*)(void*))msandroid_read_cb, d); 395 if (rc){ 396 ms_error("cannot create read thread return code is [%i]", rc); 397 d->started=false; 398 } 399 } 400 352 401 // output a buffer only every 2 ticks + alpha 353 402 if ((f->ticker->time % 20)==0 || (f->ticker->time % 510)==0){ 403 int err; 354 404 mblk_t *om=allocb(nbytes,0); 355 int err;356 405 ms_mutex_lock(&d->mutex); 357 406 err=ms_bufferizer_read(&d->rb,om->b_wptr,nbytes); … … 465 514 int buff_size = d->getWriteBuffSize(); 466 515 JNIEnv *jni_env = ms_get_jni_env(); 516 ms_debug("write thread cb"); 467 517 468 518 // int write (byte[] audioData, int offsetInBytes, int sizeInBytes) … … 520 570 goto end; 521 571 end: { 572 ms_debug("finishing writer thread"); 522 573 ms_thread_exit(NULL); 523 574 return 0; … … 526 577 527 578 void msandroid_sound_write_preprocess(MSFilter *f){ 528 ms_debug(" andsnd_write_preprocess");579 ms_debug("write preprocess started"); 529 580 msandroid_sound_write_data *d=(msandroid_sound_write_data*)f->data; 530 581 jmethodID constructor_id=0; 531 582 532 int rc;533 583 jmethodID min_buff_size_id; 534 584 … … 584 634 } 585 635 586 587 // start reader thread588 636 d->started = true; 589 rc = ms_thread_create(&d->thread_id, 0, (void*(*)(void*))msandroid_write_cb, d);590 if (rc){591 ms_error("cannot create write thread return code is [%i]", rc);592 d->started = false;593 return;594 }595 637 } 596 638 … … 647 689 void msandroid_sound_write_process(MSFilter *f){ 648 690 msandroid_sound_write_data *d=(msandroid_sound_write_data*)f->data; 691 mblk_t *m; 649 692 650 mblk_t *m; 693 if (d->thread_id == 0) { 694 int rc = ms_thread_create(&d->thread_id, 0, (void*(*)(void*))msandroid_write_cb, d); 695 if (rc){ 696 ms_error("cannot create write thread return code is [%i]", rc); 697 d->started = false; 698 return; 699 } 700 } 651 701 while((m=ms_queue_get(f->inputs[0]))!=NULL){ 652 702 if (d->started){
Note: See TracChangeset
for help on using the changeset viewer.
