From bbe0d01ef80435902ae777cecb70d18be96acfb7 Mon Sep 17 00:00:00 2001 From: xufulong <839789740@qq.com> Date: Wed, 15 Apr 2020 22:00:16 +0800 Subject: [PATCH] translate AudioStream into English translate AudioStream into English --- Live/src/main/cpp/AudioStream.cpp | 18 ++++++------------ Live/src/main/cpp/AudioStream.h | 3 ++- Live/src/main/cpp/VideoStream.h | 5 +++-- Live/src/main/cpp/safe_queue.h | 6 +++--- 4 files changed, 14 insertions(+), 18 deletions(-) diff --git a/Live/src/main/cpp/AudioStream.cpp b/Live/src/main/cpp/AudioStream.cpp index 8a7fd48..74025a6 100644 --- a/Live/src/main/cpp/AudioStream.cpp +++ b/Live/src/main/cpp/AudioStream.cpp @@ -20,28 +20,22 @@ void AudioStream::setAudioCallback(AudioCallback audioCallback) { } void AudioStream::setAudioEncInfo(int samplesInHZ, int channels) { - //打开编码器 mChannels = channels; - //一次最大能输入编码器的样本数量 (一个样本是16位 2字节) - //编码后的最大字节数 + //open faac encoder audioCodec = faacEncOpen(static_cast(samplesInHZ), static_cast(channels), &inputSamples, &maxOutputBytes); - //设置编码器参数 + //set encoder params faacEncConfigurationPtr config = faacEncGetCurrentConfiguration(audioCodec); - //指定为 mpeg4 标准 config->mpegVersion = MPEG4; - //lc 标准 config->aacObjectType = LOW; - //16位 config->inputFormat = FAAC_INPUT_16BIT; - // 编码出原始数据 config->outputFormat = 0; faacEncSetConfiguration(audioCodec, config); - //输出缓冲区 编码后的数据 用这个缓冲区来保存 + //output buffer buffer = new u_char[maxOutputBytes]; } @@ -56,7 +50,7 @@ RTMPPacket *AudioStream::getAudioTag() { int bodySize = static_cast(2 + len); RTMPPacket *packet = new RTMPPacket; RTMPPacket_Alloc(packet, bodySize); - //双声道 + //channel layout: stereo packet->m_body[0] = 0xAF; if (mChannels == 1) { packet->m_body[0] = 0xAE; @@ -74,7 +68,7 @@ RTMPPacket *AudioStream::getAudioTag() { } void AudioStream::encodeData(int8_t *data) { - //返回编码后数据字节的长度 + //encode a frame, and return encoded len int byteLen = faacEncEncode(audioCodec, reinterpret_cast(data), static_cast(inputSamples), buffer, @@ -83,7 +77,7 @@ void AudioStream::encodeData(int8_t *data) { int bodySize = 2 + byteLen; RTMPPacket *packet = new RTMPPacket; RTMPPacket_Alloc(packet, bodySize); - //双声道 + //stereo packet->m_body[0] = 0xAF; if (mChannels == 1) { packet->m_body[0] = 0xAE; diff --git a/Live/src/main/cpp/AudioStream.h b/Live/src/main/cpp/AudioStream.h index 2fed7aa..8f6a0fa 100644 --- a/Live/src/main/cpp/AudioStream.h +++ b/Live/src/main/cpp/AudioStream.h @@ -22,7 +22,8 @@ public: void encodeData(int8_t *data); - RTMPPacket* getAudioTag(); + RTMPPacket *getAudioTag(); + private: AudioCallback audioCallback; int mChannels; diff --git a/Live/src/main/cpp/VideoStream.h b/Live/src/main/cpp/VideoStream.h index 8d84fa6..98abcbb 100644 --- a/Live/src/main/cpp/VideoStream.h +++ b/Live/src/main/cpp/VideoStream.h @@ -8,13 +8,13 @@ #include "include/x264/x264.h" class VideoStream { - typedef void (*VideoCallback)(RTMPPacket* packet); + typedef void (*VideoCallback)(RTMPPacket *packet); + public: VideoStream(); ~VideoStream(); - //创建x264编码器 void setVideoEncInfo(int width, int height, int fps, int bitrate); void encodeData(int8_t *data); @@ -35,6 +35,7 @@ private: int ySize; int uvSize; VideoCallback videoCallback; + void sendSpsPps(uint8_t *sps, uint8_t *pps, int sps_len, int pps_len); void sendFrame(int type, uint8_t *payload, int i_payload); diff --git a/Live/src/main/cpp/safe_queue.h b/Live/src/main/cpp/safe_queue.h index e7d6cf9..9f7b401 100644 --- a/Live/src/main/cpp/safe_queue.h +++ b/Live/src/main/cpp/safe_queue.h @@ -37,7 +37,7 @@ public: } - void push( T new_value) { + void push(T new_value) { #ifdef C11 //锁 和智能指针原理类似,自动释放 lock_guard lk(mt); @@ -50,7 +50,7 @@ public: if (work) { q.push(new_value); pthread_cond_signal(&cond); - }else{ + } else { releaseCallback(new_value); } pthread_mutex_unlock(&mutex); @@ -59,7 +59,7 @@ public: } - int pop(T& value) { + int pop(T &value) { int ret = 0; #ifdef C11 //占用空间相对lock_guard 更大一点且相对更慢一点,但是配合条件必须使用它,更灵活