Changeset 5357
- Timestamp:
- Jun 27, 2016 11:09:01 AM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjmedia/src/pjmedia-audiodev/android_jni_dev.c
r5248 r5357 60 60 pjmedia_dir dir; 61 61 pjmedia_aud_param param; 62 62 63 63 int bytes_per_sample; 64 64 pj_uint32_t samples_per_sec; … … 77 77 pj_thread_t *rec_thread; 78 78 pj_sem_t *rec_sem; 79 pj_timestamp rec_timestamp;80 79 pj_timestamp rec_timestamp; 80 81 81 /* Track */ 82 82 jobject track; … … 87 87 pj_thread_t *play_thread; 88 88 pj_sem_t *play_sem; 89 pj_timestamp 89 pj_timestamp play_timestamp; 90 90 }; 91 91 … … 664 664 if (stream->dir & PJMEDIA_DIR_CAPTURE) { 665 665 jthrowable exc; 666 jobject record_obj; 666 667 int mic_source = 0; /* DEFAULT: default audio source */ 667 668 … … 695 696 696 697 do { 697 stream->record= (*jni_env)->NewObject(jni_env,698 699 700 701 702 703 704 705 if ( stream->record== 0) {698 record_obj = (*jni_env)->NewObject(jni_env, 699 stream->record_class, 700 constructor_method, 701 mic_source, 702 param->clock_rate, 703 channelInCfg, 704 sampleFormat, 705 inputBuffSizeRec); 706 if (record_obj == 0) { 706 707 PJ_LOG(3, (THIS_FILE, "Unable to create audio record object")); 707 708 status = PJMEDIA_EAUD_INIT; … … 732 733 goto on_error; 733 734 } 734 state = (*jni_env)->CallIntMethod(jni_env, stream->record, 735 method_id); 735 state = (*jni_env)->CallIntMethod(jni_env, record_obj, method_id); 736 736 if (state == 0) { /* STATE_UNINITIALIZED */ 737 737 PJ_LOG(3, (THIS_FILE, "Failure in initializing audio record.")); … … 745 745 } while (state == 0); 746 746 747 stream->record = (*jni_env)->NewGlobalRef(jni_env, stream->record);747 stream->record = (*jni_env)->NewGlobalRef(jni_env, record_obj); 748 748 if (stream->record == 0) { 749 PJ_LOG(3, (THIS_FILE, "Unable to create audio record global ref.")); 749 jmethodID release_method=0; 750 751 PJ_LOG(3, (THIS_FILE, "Unable to create audio record global ref.")); 752 release_method = (*jni_env)->GetMethodID(jni_env, 753 stream->record_class, 754 "release", "()V"); 755 (*jni_env)->CallVoidMethod(jni_env, record_obj, release_method); 756 750 757 status = PJMEDIA_EAUD_INIT; 751 758 goto on_error; … … 767 774 if (stream->dir & PJMEDIA_DIR_PLAYBACK) { 768 775 jthrowable exc; 776 jobject track_obj; 769 777 770 778 /* Get pointer to the constructor */ … … 778 786 } 779 787 780 stream->track= (*jni_env)->NewObject(jni_env,781 782 783 784 785 786 787 788 789 if ( stream->track== 0) {788 track_obj = (*jni_env)->NewObject(jni_env, 789 stream->track_class, 790 constructor_method, 791 0, /* STREAM_VOICE_CALL */ 792 param->clock_rate, 793 channelOutCfg, 794 sampleFormat, 795 inputBuffSizePlay, 796 1 /* MODE_STREAM */); 797 if (track_obj == 0) { 790 798 PJ_LOG(3, (THIS_FILE, "Unable to create audio track object.")); 791 799 status = PJMEDIA_EAUD_INIT; … … 802 810 } 803 811 804 stream->track = (*jni_env)->NewGlobalRef(jni_env, stream->track);812 stream->track = (*jni_env)->NewGlobalRef(jni_env, track_obj); 805 813 if (stream->track == 0) { 814 jmethodID release_method=0; 815 816 release_method = (*jni_env)->GetMethodID(jni_env, 817 stream->track_class, 818 "release", "()V"); 819 (*jni_env)->CallVoidMethod(jni_env, track_obj, release_method); 820 806 821 PJ_LOG(3, (THIS_FILE, "Unable to create audio track's global ref")); 807 822 status = PJMEDIA_EAUD_INIT; … … 973 988 974 989 PJ_LOG(4,(THIS_FILE, "Destroying Android JNI stream...")); 975 990 976 991 stream->quit_flag = PJ_TRUE; 977 992 … … 980 995 981 996 attached = attach_jvm(&jni_env); 982 997 983 998 if (stream->record){ 984 999 if (stream->rec_thread) { … … 993 1008 stream->rec_sem = NULL; 994 1009 } 995 996 release_method = (*jni_env)->GetMethodID(jni_env, stream->record_class, 997 "release", "()V"); 998 (*jni_env)->CallVoidMethod(jni_env, stream->record, release_method); 999 1010 if (stream->record_class) { 1011 release_method = (*jni_env)->GetMethodID(jni_env, 1012 stream->record_class, 1013 "release", "()V"); 1014 (*jni_env)->CallVoidMethod(jni_env, stream->record, 1015 release_method); 1016 } 1000 1017 (*jni_env)->DeleteGlobalRef(jni_env, stream->record); 1001 (*jni_env)->DeleteGlobalRef(jni_env, stream->record_class);1002 1018 stream->record = NULL; 1003 stream->record_class = NULL;1004 1019 PJ_LOG(4, (THIS_FILE, "Audio record released")); 1020 } 1021 if (stream->record_class) { 1022 (*jni_env)->DeleteGlobalRef(jni_env, stream->record_class); 1023 stream->record_class = NULL; 1005 1024 } 1006 1025 … … 1017 1036 stream->play_sem = NULL; 1018 1037 } 1019 1020 release_method = (*jni_env)->GetMethodID(jni_env, stream->track_class, 1021 "release", "()V"); 1022 (*jni_env)->CallVoidMethod(jni_env, stream->track, release_method); 1023 1038 if (stream->track_class) { 1039 release_method = (*jni_env)->GetMethodID(jni_env, 1040 stream->track_class, 1041 "release", "()V"); 1042 (*jni_env)->CallVoidMethod(jni_env, stream->track, 1043 release_method); 1044 } 1024 1045 (*jni_env)->DeleteGlobalRef(jni_env, stream->track); 1025 (*jni_env)->DeleteGlobalRef(jni_env, stream->track_class); 1026 stream->track = NULL; 1027 stream->track_class = NULL; 1028 PJ_LOG(3, (THIS_FILE, "Audio track released")); 1046 stream->track = NULL; 1047 PJ_LOG(4, (THIS_FILE, "Audio track released")); 1048 } 1049 if (stream->track_class) { 1050 (*jni_env)->DeleteGlobalRef(jni_env, stream->track_class); 1051 stream->track_class = NULL; 1029 1052 } 1030 1053
Note: See TracChangeset
for help on using the changeset viewer.