int main() { void*p = rtmp_sender_alloc("rtmp://127.0.0.1:1935/live/ddd"); //return handle rtmp_sender_start_publish(p, 0, 0); int fd = open("cms.264", O_RDONLY); uint8_t * buf = malloc(3 *1024 * 1024); uint32_t total; total = read(fd, buf, (1024*1024 *3)); close(fd); int aacfd = open("audiotest.aac", O_RDONLY); uint8_t * audio_buf = malloc(1 *1024 * 1024); uint32_t audio_total; audio_total = read(aacfd, audio_buf, (1024*1024 *3)); close(aacfd); uint8_t *buf_offset = buf; uint8_t *audio_buf_offset = audio_buf; uint32_t len; uint32_t audio_len; uint8_t *p_video ; uint8_t *pp; uint8_t *p_audio; uint32_t audio_ts = 0; uint32_t ts = 0; uint32_t len_1; uint32_t len_2; while (1) { p_audio = get_adts(&audio_len, &audio_buf_offset, audio_buf, audio_total); if (p_audio == NULL){ audio_buf_offset = audio_buf; continue; } rtmp_sender_write_audio_frame(p, p_audio, audio_len, audio_ts); p_video = get_nal(&len, &buf_offset, buf, total); if (p_video == NULL) { buf_offset = buf; continue; } printf("%x %d\n", p_video[0], len); if (p_video[0] == 0x67) { pp = get_nal(&len_1, &buf_offset, buf, total); printf("%x %d\n", pp[0], len_1); pp = get_nal(&len_2, &buf_offset, buf, total); printf("%x %d\n", pp[0], len_2); uint8_t temp = len + len_1 + len_2 + 12; printf("temp %d\n", temp); rtmp_sender_write_video_frame(p, p_video - 4, temp, ts, 0); } else rtmp_sender_write_video_frame(p, p_video - 4, len + 4, ts, 0); ts += 50; audio_ts += 50; usleep(50 * 1000); } }
JNIEXPORT jint JNICALL Java_net_butterflytv_rtmp_1client_RTMPMuxer_writeAudio(JNIEnv *env, jobject instance, jbyteArray data_, jint offset, jint length, jint timestamp) { jbyte *data = (*env)->GetByteArrayElements(env, data_, NULL); jint result = rtmp_sender_write_audio_frame(data, length, timestamp, 0); (*env)->ReleaseByteArrayElements(env, data_, data, 0); return result; }
JNIEXPORT jint JNICALL Java_net_butterflytv_rtmp_1client_RTMPMuxer_writeAudio(JNIEnv *env, jobject thiz, jbyteArray data_, jint offset, jint length, jint timestamp) { jfieldID fid = (*env)->GetFieldID(env, (*env)->GetObjectClass(env, thiz), "rtmp", "J"); jlong raw_rtmp = (*env)->GetLongField(env, thiz, fid); RTMP *rtmp = (RTMP*)(*(void**)&raw_rtmp); if(rtmp == NULL) { return -10000; } jbyte *data = (*env)->GetByteArrayElements(env, data_, NULL); jint result = rtmp_sender_write_audio_frame(rtmp, data, length, timestamp, 0); (*env)->ReleaseByteArrayElements(env, data_, data, 0); return result; }