1
0
Fork 0
mirror of https://github.com/ossrs/srs.git synced 2025-03-09 15:49:59 +00:00

For #299, refine code.

This commit is contained in:
winlin 2017-03-25 17:21:39 +08:00
parent 62b7204514
commit f32aab3d92
175 changed files with 15529 additions and 15935 deletions

View file

@ -29,22 +29,21 @@
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include "../../objs/include/srs_librtmp.h"
// https://github.com/ossrs/srs/issues/212#issuecomment-63648892
// allspace:
// Take this file as an example: https://github.com/allspace/files/blob/master/srs.pcm
// It's captured using SDK callback method. I have filtered out h264 video, so it's audio only now.
// For every frame, it's a 8 bytes vendor specific header, following 160 bytes audio frame.
// For every frame, it's a 8 bytes vendor specific header, following 160 bytes audio frame.
// The header part can be ignored.
int read_audio_frame(char* audio_raw, int file_size, char** pp, char** pdata, int* psize)
int read_audio_frame(char* audio_raw, int file_size, char** pp, char** pdata, int* psize)
{
char* p = *pp;
if (file_size - (p - audio_raw) < 168) {
srs_human_trace("audio must be 160+8 bytes. left %d bytes.",
(int)(file_size - (p - audio_raw)));
srs_human_trace("audio must be 160+8 bytes. left %d bytes.", (int)(file_size - (p - audio_raw)));
return - 1;
}
@ -105,7 +104,7 @@ int main(int argc, char** argv)
lseek(raw_fd, 0, SEEK_SET);
ssize_t nb_read = 0;
if ((nb_read = read(raw_fd, audio_raw, file_size)) != file_size) {
srs_human_trace("buffer %s failed, expect=%dKB, actual=%dKB.",
srs_human_trace("buffer %s failed, expect=%dKB, actual=%dKB.",
raw_file, (int)(file_size / 1024), (int)(nb_read / 1024));
goto rtmp_destroy;
}
@ -161,15 +160,12 @@ int main(int argc, char** argv)
timestamp += time_delta;
if (srs_audio_write_raw_frame(rtmp,
sound_format, sound_rate, sound_size, sound_type,
data, size, timestamp) != 0
) {
if (srs_audio_write_raw_frame(rtmp, sound_format, sound_rate, sound_size, sound_type, data, size, timestamp) != 0) {
srs_human_trace("send audio raw data failed.");
goto rtmp_destroy;
}
srs_human_trace("sent packet: type=%s, time=%d, size=%d, codec=%d, rate=%d, sample=%d, channel=%d",
srs_human_trace("sent packet: type=%s, time=%d, size=%d, codec=%d, rate=%d, sample=%d, channel=%d",
srs_human_flv_tag_type2string(SRS_RTMP_TYPE_AUDIO), timestamp, size, sound_format, sound_rate, sound_size,
sound_type);