mirror of
https://github.com/ossrs/srs.git
synced 2025-03-09 15:49:59 +00:00
for #239, empty the aac encoder
This commit is contained in:
parent
c0233542bf
commit
7674524c31
5 changed files with 7 additions and 186 deletions
|
@ -219,9 +219,10 @@ int SrsAacStreamEncoder::write_video(int64_t timestamp, char* data, int size)
|
||||||
return enc->write_video(timestamp, data, size);
|
return enc->write_video(timestamp, data, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
int SrsAacStreamEncoder::write_metadata(int64_t timestamp, char* data, int size)
|
int SrsAacStreamEncoder::write_metadata(int64_t /*timestamp*/, char* /*data*/, int /*size*/)
|
||||||
{
|
{
|
||||||
return enc->write_metadata(timestamp, data, size);
|
// aac ignore any flv metadata.
|
||||||
|
return ERROR_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
SrsStreamWriter::SrsStreamWriter(ISrsGoHttpResponseWriter* w)
|
SrsStreamWriter::SrsStreamWriter(ISrsGoHttpResponseWriter* w)
|
||||||
|
|
|
@ -58,8 +58,8 @@ int SrsAacEncoder::initialize(SrsFileWriter* fs)
|
||||||
srs_assert(fs);
|
srs_assert(fs);
|
||||||
|
|
||||||
if (!fs->is_open()) {
|
if (!fs->is_open()) {
|
||||||
ret = ERROR_KERNEL_FLV_STREAM_CLOSED;
|
ret = ERROR_KERNEL_AAC_STREAM_CLOSED;
|
||||||
srs_warn("stream is not open for decoder. ret=%d", ret);
|
srs_warn("stream is not open for encoder. ret=%d", ret);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -68,77 +68,6 @@ int SrsAacEncoder::initialize(SrsFileWriter* fs)
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int SrsAacEncoder::write_header()
|
|
||||||
{
|
|
||||||
int ret = ERROR_SUCCESS;
|
|
||||||
|
|
||||||
// 9bytes header and 4bytes first previous-tag-size
|
|
||||||
static char flv_header[] = {
|
|
||||||
'F', 'L', 'V', // Signatures "FLV"
|
|
||||||
(char)0x01, // File version (for example, 0x01 for FLV version 1)
|
|
||||||
(char)0x00, // 4, audio; 1, video; 5 audio+video.
|
|
||||||
(char)0x00, (char)0x00, (char)0x00, (char)0x09 // DataOffset UI32 The length of this header in bytes
|
|
||||||
};
|
|
||||||
|
|
||||||
// flv specification should set the audio and video flag,
|
|
||||||
// actually in practise, application generally ignore this flag,
|
|
||||||
// so we generally set the audio/video to 0.
|
|
||||||
|
|
||||||
// write 9bytes header.
|
|
||||||
if ((ret = write_header(flv_header)) != ERROR_SUCCESS) {
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
int SrsAacEncoder::write_header(char flv_header[9])
|
|
||||||
{
|
|
||||||
int ret = ERROR_SUCCESS;
|
|
||||||
|
|
||||||
// write data.
|
|
||||||
if ((ret = _fs->write(flv_header, 9, NULL)) != ERROR_SUCCESS) {
|
|
||||||
srs_error("write flv header failed. ret=%d", ret);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
char pts[] = { (char)0x00, (char)0x00, (char)0x00, (char)0x00 };
|
|
||||||
if ((ret = _fs->write(pts, 4, NULL)) != ERROR_SUCCESS) {
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
int SrsAacEncoder::write_metadata(char type, char* data, int size)
|
|
||||||
{
|
|
||||||
int ret = ERROR_SUCCESS;
|
|
||||||
|
|
||||||
srs_assert(data);
|
|
||||||
|
|
||||||
// 11 bytes tag header
|
|
||||||
static char tag_header[] = {
|
|
||||||
(char)type, // TagType UB [5], 18 = script data
|
|
||||||
(char)0x00, (char)0x00, (char)0x00, // DataSize UI24 Length of the message.
|
|
||||||
(char)0x00, (char)0x00, (char)0x00, // Timestamp UI24 Time in milliseconds at which the data in this tag applies.
|
|
||||||
(char)0x00, // TimestampExtended UI8
|
|
||||||
(char)0x00, (char)0x00, (char)0x00, // StreamID UI24 Always 0.
|
|
||||||
};
|
|
||||||
|
|
||||||
// write data size.
|
|
||||||
if ((ret = tag_stream->initialize(tag_header + 1, 3)) != ERROR_SUCCESS) {
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
tag_stream->write_3bytes(size);
|
|
||||||
|
|
||||||
if ((ret = write_tag(tag_header, sizeof(tag_header), data, size)) != ERROR_SUCCESS) {
|
|
||||||
srs_error("write flv data tag failed. ret=%d", ret);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
int SrsAacEncoder::write_audio(int64_t timestamp, char* data, int size)
|
int SrsAacEncoder::write_audio(int64_t timestamp, char* data, int size)
|
||||||
{
|
{
|
||||||
int ret = ERROR_SUCCESS;
|
int ret = ERROR_SUCCESS;
|
||||||
|
@ -147,29 +76,6 @@ int SrsAacEncoder::write_audio(int64_t timestamp, char* data, int size)
|
||||||
|
|
||||||
timestamp &= 0x7fffffff;
|
timestamp &= 0x7fffffff;
|
||||||
|
|
||||||
// 11bytes tag header
|
|
||||||
static char tag_header[] = {
|
|
||||||
(char)8, // TagType UB [5], 8 = audio
|
|
||||||
(char)0x00, (char)0x00, (char)0x00, // DataSize UI24 Length of the message.
|
|
||||||
(char)0x00, (char)0x00, (char)0x00, // Timestamp UI24 Time in milliseconds at which the data in this tag applies.
|
|
||||||
(char)0x00, // TimestampExtended UI8
|
|
||||||
(char)0x00, (char)0x00, (char)0x00, // StreamID UI24 Always 0.
|
|
||||||
};
|
|
||||||
|
|
||||||
// write data size.
|
|
||||||
if ((ret = tag_stream->initialize(tag_header + 1, 7)) != ERROR_SUCCESS) {
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
tag_stream->write_3bytes(size);
|
|
||||||
tag_stream->write_3bytes((int32_t)timestamp);
|
|
||||||
// default to little-endian
|
|
||||||
tag_stream->write_1bytes((timestamp >> 24) & 0xFF);
|
|
||||||
|
|
||||||
if ((ret = write_tag(tag_header, sizeof(tag_header), data, size)) != ERROR_SUCCESS) {
|
|
||||||
srs_error("write flv audio tag failed. ret=%d", ret);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -181,66 +87,6 @@ int SrsAacEncoder::write_video(int64_t timestamp, char* data, int size)
|
||||||
|
|
||||||
timestamp &= 0x7fffffff;
|
timestamp &= 0x7fffffff;
|
||||||
|
|
||||||
// 11bytes tag header
|
|
||||||
static char tag_header[] = {
|
|
||||||
(char)9, // TagType UB [5], 9 = video
|
|
||||||
(char)0x00, (char)0x00, (char)0x00, // DataSize UI24 Length of the message.
|
|
||||||
(char)0x00, (char)0x00, (char)0x00, // Timestamp UI24 Time in milliseconds at which the data in this tag applies.
|
|
||||||
(char)0x00, // TimestampExtended UI8
|
|
||||||
(char)0x00, (char)0x00, (char)0x00, // StreamID UI24 Always 0.
|
|
||||||
};
|
|
||||||
|
|
||||||
// write data size.
|
|
||||||
if ((ret = tag_stream->initialize(tag_header + 1, 7)) != ERROR_SUCCESS) {
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
tag_stream->write_3bytes(size);
|
|
||||||
tag_stream->write_3bytes((int32_t)timestamp);
|
|
||||||
// default to little-endian
|
|
||||||
tag_stream->write_1bytes((timestamp >> 24) & 0xFF);
|
|
||||||
|
|
||||||
if ((ret = write_tag(tag_header, sizeof(tag_header), data, size)) != ERROR_SUCCESS) {
|
|
||||||
srs_error("write flv video tag failed. ret=%d", ret);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int SrsAacEncoder::size_tag(int data_size)
|
|
||||||
{
|
|
||||||
srs_assert(data_size >= 0);
|
|
||||||
return SRS_FLV_TAG_HEADER_SIZE + data_size + SRS_FLV_PREVIOUS_TAG_SIZE;
|
|
||||||
}
|
|
||||||
|
|
||||||
int SrsAacEncoder::write_tag(char* header, int header_size, char* tag, int tag_size)
|
|
||||||
{
|
|
||||||
int ret = ERROR_SUCCESS;
|
|
||||||
|
|
||||||
// write tag header.
|
|
||||||
if ((ret = _fs->write(header, header_size, NULL)) != ERROR_SUCCESS) {
|
|
||||||
srs_error("write flv tag header failed. ret=%d", ret);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
// write tag data.
|
|
||||||
if ((ret = _fs->write(tag, tag_size, NULL)) != ERROR_SUCCESS) {
|
|
||||||
srs_error("write flv tag failed. ret=%d", ret);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
// PreviousTagSizeN UI32 Size of last tag, including its header, in bytes.
|
|
||||||
static char pre_size[SRS_FLV_PREVIOUS_TAG_SIZE];
|
|
||||||
if ((ret = tag_stream->initialize(pre_size, SRS_FLV_PREVIOUS_TAG_SIZE)) != ERROR_SUCCESS) {
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
tag_stream->write_4bytes(tag_size + header_size);
|
|
||||||
if ((ret = _fs->write(pre_size, sizeof(pre_size), NULL)) != ERROR_SUCCESS) {
|
|
||||||
srs_error("write flv previous tag size failed. ret=%d", ret);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -55,39 +55,12 @@ public:
|
||||||
*/
|
*/
|
||||||
virtual int initialize(SrsFileWriter* fs);
|
virtual int initialize(SrsFileWriter* fs);
|
||||||
public:
|
public:
|
||||||
/**
|
|
||||||
* write flv header.
|
|
||||||
* write following:
|
|
||||||
* 1. E.2 The FLV header
|
|
||||||
* 2. PreviousTagSize0 UI32 Always 0
|
|
||||||
* that is, 9+4=13bytes.
|
|
||||||
*/
|
|
||||||
virtual int write_header();
|
|
||||||
virtual int write_header(char flv_header[9]);
|
|
||||||
/**
|
|
||||||
* write flv metadata.
|
|
||||||
* @param type, the type of data, or other message type.
|
|
||||||
* @param data, the amf0 metadata which serialize from:
|
|
||||||
* AMF0 string: onMetaData,
|
|
||||||
* AMF0 object: the metadata object.
|
|
||||||
* @remark assert data is not NULL.
|
|
||||||
*/
|
|
||||||
virtual int write_metadata(char type, char* data, int size);
|
|
||||||
/**
|
/**
|
||||||
* write audio/video packet.
|
* write audio/video packet.
|
||||||
* @remark assert data is not NULL.
|
* @remark assert data is not NULL.
|
||||||
*/
|
*/
|
||||||
virtual int write_audio(int64_t timestamp, char* data, int size);
|
virtual int write_audio(int64_t timestamp, char* data, int size);
|
||||||
virtual int write_video(int64_t timestamp, char* data, int size);
|
virtual int write_video(int64_t timestamp, char* data, int size);
|
||||||
public:
|
|
||||||
/**
|
|
||||||
* get the tag size,
|
|
||||||
* including the tag header, body, and 4bytes previous tag size.
|
|
||||||
* @remark assert data_size is not negative.
|
|
||||||
*/
|
|
||||||
static int size_tag(int data_size);
|
|
||||||
private:
|
|
||||||
virtual int write_tag(char* header, int header_size, char* tag, int tag_size);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -203,6 +203,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
#define ERROR_AAC_ADTS_HEADER 3047
|
#define ERROR_AAC_ADTS_HEADER 3047
|
||||||
#define ERROR_AAC_DATA_INVALID 3048
|
#define ERROR_AAC_DATA_INVALID 3048
|
||||||
#define ERROR_HTTP_STATUS_INVLIAD 3049
|
#define ERROR_HTTP_STATUS_INVLIAD 3049
|
||||||
|
#define ERROR_KERNEL_AAC_STREAM_CLOSED 3050
|
||||||
|
|
||||||
///////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////
|
||||||
// HTTP protocol error.
|
// HTTP protocol error.
|
||||||
|
|
|
@ -59,7 +59,7 @@ int SrsFlvEncoder::initialize(SrsFileWriter* fs)
|
||||||
|
|
||||||
if (!fs->is_open()) {
|
if (!fs->is_open()) {
|
||||||
ret = ERROR_KERNEL_FLV_STREAM_CLOSED;
|
ret = ERROR_KERNEL_FLV_STREAM_CLOSED;
|
||||||
srs_warn("stream is not open for decoder. ret=%d", ret);
|
srs_warn("stream is not open for encoder. ret=%d", ret);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue