mirror of
https://github.com/ossrs/srs.git
synced 2025-03-09 15:49:59 +00:00
fix #212, support publish audio raw frames. 2.0.27
This commit is contained in:
parent
856cc0a51d
commit
a058eeeb20
7 changed files with 301 additions and 4 deletions
|
@ -31,7 +31,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|||
// current release version
|
||||
#define VERSION_MAJOR 2
|
||||
#define VERSION_MINOR 0
|
||||
#define VERSION_REVISION 26
|
||||
#define VERSION_REVISION 27
|
||||
// server info.
|
||||
#define RTMP_SIG_SRS_KEY "SRS"
|
||||
#define RTMP_SIG_SRS_ROLE "origin/edge server"
|
||||
|
|
|
@ -1438,6 +1438,46 @@ char* srs_amf0_human_print(srs_amf0_t amf0, char** pdata, int* psize)
|
|||
return any->human_print(pdata, psize);
|
||||
}
|
||||
|
||||
/**
|
||||
* write audio raw frame to SRS.
|
||||
*/
|
||||
int srs_audio_write_raw_frame(srs_rtmp_t rtmp,
|
||||
char sound_format, char sound_rate, char sound_size, char sound_type,
|
||||
char aac_packet_type, char* frame, int frame_size, u_int32_t timestamp
|
||||
) {
|
||||
int ret = ERROR_SUCCESS;
|
||||
|
||||
Context* context = (Context*)rtmp;
|
||||
srs_assert(context);
|
||||
|
||||
// TODO: FIXME: for aac, must send the sequence header first.
|
||||
|
||||
// for audio frame, there is 1 or 2 bytes header:
|
||||
// 1bytes, SoundFormat|SoundRate|SoundSize|SoundType
|
||||
// 1bytes, AACPacketType for SoundFormat == 10
|
||||
int size = frame_size + 1;
|
||||
if (aac_packet_type == SrsCodecAudioAAC) {
|
||||
size += 1;
|
||||
}
|
||||
char* data = new char[size];
|
||||
char* p = data;
|
||||
|
||||
u_int8_t audio_header = sound_type & 0x01;
|
||||
audio_header |= (sound_size << 1) & 0x02;
|
||||
audio_header |= (sound_rate << 2) & 0x0c;
|
||||
audio_header |= (sound_format << 4) & 0xf0;
|
||||
|
||||
*p++ = audio_header;
|
||||
|
||||
if (aac_packet_type == SrsCodecAudioAAC) {
|
||||
*p++ = aac_packet_type;
|
||||
}
|
||||
|
||||
memcpy(p, frame, frame_size);
|
||||
|
||||
return srs_write_packet(context, SRS_RTMP_TYPE_AUDIO, timestamp, data, size);
|
||||
}
|
||||
|
||||
/**
|
||||
* write h264 packet, with rtmp header.
|
||||
* @param frame_type, SrsCodecVideoAVCFrameKeyFrame or SrsCodecVideoAVCFrameInterFrame.
|
||||
|
@ -1458,7 +1498,6 @@ int __srs_write_h264_packet(Context* context,
|
|||
// @see: E.4.3 Video Tags, video_file_format_spec_v10_1.pdf, page 78
|
||||
int size = h264_raw_size + 5;
|
||||
char* data = new char[size];
|
||||
memcpy(data + 5, h264_raw_data, h264_raw_size);
|
||||
char* p = data;
|
||||
|
||||
// @see: E.4.3 Video Tags, video_file_format_spec_v10_1.pdf, page 78
|
||||
|
@ -1480,6 +1519,9 @@ int __srs_write_h264_packet(Context* context,
|
|||
*p++ = pp[1];
|
||||
*p++ = pp[0];
|
||||
|
||||
// h.264 raw data.
|
||||
memcpy(p, h264_raw_data, h264_raw_size);
|
||||
|
||||
return srs_write_packet(context, SRS_RTMP_TYPE_VIDEO, timestamp, data, size);
|
||||
}
|
||||
|
||||
|
|
|
@ -461,6 +461,64 @@ extern void srs_amf0_strict_array_append(srs_amf0_t amf0, srs_amf0_t value);
|
|||
*/
|
||||
extern char* srs_amf0_human_print(srs_amf0_t amf0, char** pdata, int* psize);
|
||||
|
||||
/*************************************************************
|
||||
**************************************************************
|
||||
* audio raw codec
|
||||
**************************************************************
|
||||
*************************************************************/
|
||||
/**
|
||||
* write an audio raw frame to srs.
|
||||
* not similar to h.264 video, the audio never aggregated, always
|
||||
* encoded one frame by one, so this api is used to write a frame.
|
||||
*
|
||||
* @param sound_format Format of SoundData. The following values are defined:
|
||||
* 0 = Linear PCM, platform endian
|
||||
* 1 = ADPCM
|
||||
* 2 = MP3
|
||||
* 3 = Linear PCM, little endian
|
||||
* 4 = Nellymoser 16 kHz mono
|
||||
* 5 = Nellymoser 8 kHz mono
|
||||
* 6 = Nellymoser
|
||||
* 7 = G.711 A-law logarithmic PCM
|
||||
* 8 = G.711 mu-law logarithmic PCM
|
||||
* 9 = reserved
|
||||
* 10 = AAC
|
||||
* 11 = Speex
|
||||
* 14 = MP3 8 kHz
|
||||
* 15 = Device-specific sound
|
||||
* Formats 7, 8, 14, and 15 are reserved.
|
||||
* AAC is supported in Flash Player 9,0,115,0 and higher.
|
||||
* Speex is supported in Flash Player 10 and higher.
|
||||
* @param sound_rate Sampling rate. The following values are defined:
|
||||
* 0 = 5.5 kHz
|
||||
* 1 = 11 kHz
|
||||
* 2 = 22 kHz
|
||||
* 3 = 44 kHz
|
||||
* @param sound_size Size of each audio sample. This parameter only pertains to
|
||||
* uncompressed formats. Compressed formats always decode
|
||||
* to 16 bits internally.
|
||||
* 0 = 8-bit samples
|
||||
* 1 = 16-bit samples
|
||||
* @param sound_type Mono or stereo sound
|
||||
* 0 = Mono sound
|
||||
* 1 = Stereo sound
|
||||
* @param aac_packet_type The following values are defined:
|
||||
* 0 = AAC sequence header
|
||||
* 1 = AAC raw
|
||||
* @param timestamp The timestamp of audio.
|
||||
*
|
||||
* @remark Ignore aac_packet_type if not aac(sound_format!=10).
|
||||
*
|
||||
* @see https://github.com/winlinvip/simple-rtmp-server/issues/212
|
||||
* @see E.4.2.1 AUDIODATA of video_file_format_spec_v10_1.pdf
|
||||
*
|
||||
* @return 0, success; otherswise, failed.
|
||||
*/
|
||||
extern int srs_audio_write_raw_frame(srs_rtmp_t rtmp,
|
||||
char sound_format, char sound_rate, char sound_size, char sound_type,
|
||||
char aac_packet_type, char* frame, int frame_size, u_int32_t timestamp
|
||||
);
|
||||
|
||||
/*************************************************************
|
||||
**************************************************************
|
||||
* h264 raw codec
|
||||
|
@ -474,7 +532,7 @@ typedef int srs_h264_bool;
|
|||
* each frame prefixed h.264 annexb header, by N[00] 00 00 01, where N>=0,
|
||||
* for instance, frame = header(00 00 00 01) + payload(67 42 80 29 95 A0 14 01 6E 40)
|
||||
* about annexb, @see H.264-AVC-ISO_IEC_14496-10.pdf, page 211.
|
||||
* @paam frames_size the size of h264 raw data.
|
||||
* @param frames_size the size of h264 raw data.
|
||||
* assert frames_size > 0, at least has 1 bytes header.
|
||||
* @param dts the dts of h.264 raw data.
|
||||
* @param pts the pts of h.264 raw data.
|
||||
|
|
|
@ -128,6 +128,7 @@ file
|
|||
..\utest\srs_utest_reload.hpp,
|
||||
..\utest\srs_utest_reload.cpp,
|
||||
research readonly separator,
|
||||
..\..\research\librtmp\srs_audio_raw_publish.c,
|
||||
..\..\research\librtmp\srs_bandwidth_check.c,
|
||||
..\..\research\librtmp\srs_detect_rtmp.c,
|
||||
..\..\research\librtmp\srs_flv_injecter.c,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue