Changeset 1174:ab92fc287975 in mediastreamer2


Ignore:
Timestamp:
Oct 18, 2010 5:30:36 PM (3 years ago)
Author:
Simon Morlat <simon.morlat@…>
Branch:
default
Message:

android audio refinements

Files:
5 edited

Legend:

Unmodified
Added
Removed
  • build/android/Android.mk

    r1166 r1174  
    119119 
    120120 
     121ifeq ($(TARGET_ARCH_ABI),armeabi-v7a) 
     122        LOCAL_CFLAGS += -DUSE_HARDWARE_RATE=1  
     123endif 
     124 
     125 
    121126#LOCAL_CFLAGS += -DDEBUG 
    122127 
  • include/mediastreamer2/mediastream.h

    r1172 r1174  
    8181        MSFilter *source; 
    8282        MSFilter *gendtmf; 
     83        MSFilter *write_resampler; 
    8384        MSFilter *sndwrite; 
    8485}; 
  • src/audiostream.c

    r1157 r1174  
    589589        RingStream *stream; 
    590590        int tmp; 
     591        int srcrate,dstrate; 
     592        MSConnectionHelper h; 
     593 
    591594        stream=(RingStream *)ms_new0(RingStream,1); 
    592595        stream->source=ms_filter_new(MS_FILE_PLAYER_ID); 
     
    602605         
    603606        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        } 
    607617        ms_filter_call_method(stream->source,MS_FILTER_GET_NCHANNELS,&tmp); 
    608618        ms_filter_call_method(stream->gendtmf,MS_FILTER_SET_NCHANNELS,&tmp); 
     
    610620        stream->ticker=ms_ticker_new(); 
    611621        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); 
    614629        ms_ticker_attach(stream->ticker,stream->source); 
    615630        return stream; 
     
    627642 
    628643void ring_stop(RingStream *stream){ 
     644        MSConnectionHelper h; 
    629645        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 
    632654        ms_ticker_destroy(stream->ticker); 
    633655        ms_filter_destroy(stream->source); 
  • src/msandroid.cpp

    r1169 r1174  
    417417/***********************************write filter********************/ 
    418418static int set_write_rate(MSFilter *f, void *arg){ 
     419        msandroid_sound_data *d=(msandroid_sound_data*)f->data; 
     420#ifndef USE_HARDWARE_RATE 
    419421        int proposed_rate = *((int*)arg); 
    420422        ms_debug("set_rate %d",proposed_rate); 
    421         msandroid_sound_data *d=(msandroid_sound_data*)f->data; 
    422423        d->rate=proposed_rate; 
    423424        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 
     427we prefer do resampling by ourselves if cpu allows it*/ 
     428        return -1; 
     429#endif 
    431430} 
    432431 
     
    442441public: 
    443442        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; 
    444444                bufferizer = ms_bufferizer_new(); 
    445445                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); 
    446462        }; 
    447463        ~msandroid_sound_write_data() { 
     464                JNIEnv *jni_env=NULL; 
    448465                ms_mutex_lock(&mutex); 
    449466                ms_bufferizer_flush(bufferizer); 
     
    451468                ms_bufferizer_destroy(bufferizer); 
    452469                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                } 
    453477        } 
    454478        jclass                  audio_track_class; 
     
    552576                goto end; 
    553577        } 
    554         d->audio_track_class = (jclass)jni_env->NewGlobalRef(jni_env->FindClass("android/media/AudioTrack")); 
     578         
    555579        if (d->audio_track_class == 0) { 
    556                 ms_error("cannot find  android/media/AudioTrack\n"); 
    557580                goto end; 
    558581        } 
     
    668691end: { 
    669692        if (d->audio_track) jni_env->DeleteGlobalRef(d->audio_track); 
    670         jni_env->DeleteGlobalRef(d->audio_track_class); 
    671693        //d->jvm->DetachCurrentThread(); 
    672694        return; 
  • src/msspeex.c

    r1112 r1174  
    305305        } 
    306306        else { 
    307                 s->mode = -1; /* deault mode */ 
     307                s->mode = -1; /* default mode */ 
    308308        } 
    309309        return 0; 
Note: See TracChangeset for help on using the changeset viewer.