Changeset 1174:ab92fc287975 in mediastreamer2
- Timestamp:
- Oct 18, 2010 5:30:36 PM (3 years ago)
- Branch:
- default
- Files:
-
- 5 edited
-
build/android/Android.mk (modified) (1 diff)
-
include/mediastreamer2/mediastream.h (modified) (1 diff)
-
src/audiostream.c (modified) (4 diffs)
-
src/msandroid.cpp (modified) (5 diffs)
-
src/msspeex.c (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
build/android/Android.mk
r1166 r1174 119 119 120 120 121 ifeq ($(TARGET_ARCH_ABI),armeabi-v7a) 122 LOCAL_CFLAGS += -DUSE_HARDWARE_RATE=1 123 endif 124 125 121 126 #LOCAL_CFLAGS += -DDEBUG 122 127 -
include/mediastreamer2/mediastream.h
r1172 r1174 81 81 MSFilter *source; 82 82 MSFilter *gendtmf; 83 MSFilter *write_resampler; 83 84 MSFilter *sndwrite; 84 85 }; -
src/audiostream.c
r1157 r1174 589 589 RingStream *stream; 590 590 int tmp; 591 int srcrate,dstrate; 592 MSConnectionHelper h; 593 591 594 stream=(RingStream *)ms_new0(RingStream,1); 592 595 stream->source=ms_filter_new(MS_FILE_PLAYER_ID); … … 602 605 603 606 stream->sndwrite=ms_snd_card_create_writer(sndcard); 604 ms_filter_call_method(stream->source,MS_FILTER_GET_SAMPLE_RATE,&tmp); 605 ms_filter_call_method(stream->gendtmf,MS_FILTER_SET_SAMPLE_RATE,&tmp); 606 ms_filter_call_method(stream->sndwrite,MS_FILTER_SET_SAMPLE_RATE,&tmp); 607 ms_filter_call_method(stream->source,MS_FILTER_GET_SAMPLE_RATE,&srcrate); 608 ms_filter_call_method(stream->gendtmf,MS_FILTER_SET_SAMPLE_RATE,&srcrate); 609 ms_filter_call_method(stream->sndwrite,MS_FILTER_SET_SAMPLE_RATE,&srcrate); 610 ms_filter_call_method(stream->sndwrite,MS_FILTER_GET_SAMPLE_RATE,&dstrate); 611 if (srcrate!=dstrate){ 612 stream->write_resampler=ms_filter_new(MS_RESAMPLE_ID); 613 ms_filter_call_method(stream->write_resampler,MS_FILTER_SET_SAMPLE_RATE,&srcrate); 614 ms_filter_call_method(stream->write_resampler,MS_FILTER_SET_OUTPUT_SAMPLE_RATE,&dstrate); 615 ms_message("configuring resampler from rate[%i] to rate [%i]", srcrate,dstrate); 616 } 607 617 ms_filter_call_method(stream->source,MS_FILTER_GET_NCHANNELS,&tmp); 608 618 ms_filter_call_method(stream->gendtmf,MS_FILTER_SET_NCHANNELS,&tmp); … … 610 620 stream->ticker=ms_ticker_new(); 611 621 ms_ticker_set_name(stream->ticker,"Audio (ring) MSTicker"); 612 ms_filter_link(stream->source,0,stream->gendtmf,0); 613 ms_filter_link(stream->gendtmf,0,stream->sndwrite,0); 622 623 ms_connection_helper_start(&h); 624 ms_connection_helper_link(&h,stream->source,-1,0); 625 ms_connection_helper_link(&h,stream->gendtmf,0,0); 626 if (stream->write_resampler) 627 ms_connection_helper_link(&h,stream->write_resampler,0,0); 628 ms_connection_helper_link(&h,stream->sndwrite,0,-1); 614 629 ms_ticker_attach(stream->ticker,stream->source); 615 630 return stream; … … 627 642 628 643 void ring_stop(RingStream *stream){ 644 MSConnectionHelper h; 629 645 ms_ticker_detach(stream->ticker,stream->source); 630 ms_filter_unlink(stream->source,0,stream->gendtmf,0); 631 ms_filter_unlink(stream->gendtmf,0,stream->sndwrite,0); 646 647 ms_connection_helper_start(&h); 648 ms_connection_helper_unlink(&h,stream->source,-1,0); 649 ms_connection_helper_unlink(&h,stream->gendtmf,0,0); 650 if (stream->write_resampler) 651 ms_connection_helper_unlink(&h,stream->write_resampler,0,0); 652 ms_connection_helper_unlink(&h,stream->sndwrite,0,-1); 653 632 654 ms_ticker_destroy(stream->ticker); 633 655 ms_filter_destroy(stream->source); -
src/msandroid.cpp
r1169 r1174 417 417 /***********************************write filter********************/ 418 418 static int set_write_rate(MSFilter *f, void *arg){ 419 msandroid_sound_data *d=(msandroid_sound_data*)f->data; 420 #ifndef USE_HARDWARE_RATE 419 421 int proposed_rate = *((int*)arg); 420 422 ms_debug("set_rate %d",proposed_rate); 421 msandroid_sound_data *d=(msandroid_sound_data*)f->data;422 423 d->rate=proposed_rate; 423 424 return 0; 424 /*d->rate=44100; //to improve latency on msn 7k 425 if (proposed_rate == d->rate) { 426 return 0; 427 } else { 428 return d->rate; 429 } 430 */ 425 #else 426 /*audioflingler resampling is really bad 427 we prefer do resampling by ourselves if cpu allows it*/ 428 return -1; 429 #endif 431 430 } 432 431 … … 442 441 public: 443 442 msandroid_sound_write_data() :audio_track_class(0),audio_track(0),write_chunk_size(0),writtenBytes(0),last_sample_date(0){ 443 JNIEnv *jni_env=NULL; 444 444 bufferizer = ms_bufferizer_new(); 445 445 ms_cond_init(&cond,0); 446 if (jvm->AttachCurrentThread(&jni_env,NULL)!=0){ 447 ms_error("msandroid_sound_write_data(): could not attach current thread."); 448 return; 449 } 450 audio_track_class = (jclass)jni_env->NewGlobalRef(jni_env->FindClass("android/media/AudioTrack")); 451 if (audio_track_class == 0) { 452 ms_error("cannot find android/media/AudioTrack\n"); 453 return; 454 } 455 jmethodID hwrate_id = jni_env->GetStaticMethodID(audio_track_class,"getNativeOutputSampleRate", "(I)I"); 456 if (hwrate_id == 0) { 457 ms_error("cannot find int AudioRecord.getNativeOutputSampleRate(int streamType)"); 458 return; 459 } 460 rate = jni_env->CallStaticIntMethod(audio_track_class,hwrate_id,0 /*STREAM_VOICE_CALL*/); 461 ms_message("Hardware sample rate is %i",rate); 446 462 }; 447 463 ~msandroid_sound_write_data() { 464 JNIEnv *jni_env=NULL; 448 465 ms_mutex_lock(&mutex); 449 466 ms_bufferizer_flush(bufferizer); … … 451 468 ms_bufferizer_destroy(bufferizer); 452 469 ms_cond_destroy(&cond); 470 if (audio_track_class!=0){ 471 if (jvm->AttachCurrentThread(&jni_env,NULL)!=0){ 472 ms_error("~msandroid_sound_write_data(): could not attach current thread."); 473 return; 474 } 475 jni_env->DeleteGlobalRef(audio_track_class); 476 } 453 477 } 454 478 jclass audio_track_class; … … 552 576 goto end; 553 577 } 554 d->audio_track_class = (jclass)jni_env->NewGlobalRef(jni_env->FindClass("android/media/AudioTrack"));578 555 579 if (d->audio_track_class == 0) { 556 ms_error("cannot find android/media/AudioTrack\n");557 580 goto end; 558 581 } … … 668 691 end: { 669 692 if (d->audio_track) jni_env->DeleteGlobalRef(d->audio_track); 670 jni_env->DeleteGlobalRef(d->audio_track_class);671 693 //d->jvm->DetachCurrentThread(); 672 694 return; -
src/msspeex.c
r1112 r1174 305 305 } 306 306 else { 307 s->mode = -1; /* de ault mode */307 s->mode = -1; /* default mode */ 308 308 } 309 309 return 0;
Note: See TracChangeset
for help on using the changeset viewer.
