正在显示
5 个修改的文件
包含
7 行增加
和
186 行删除
| @@ -219,9 +219,10 @@ int SrsAacStreamEncoder::write_video(int64_t timestamp, char* data, int size) | @@ -219,9 +219,10 @@ int SrsAacStreamEncoder::write_video(int64_t timestamp, char* data, int size) | ||
| 219 | return enc->write_video(timestamp, data, size); | 219 | return enc->write_video(timestamp, data, size); |
| 220 | } | 220 | } |
| 221 | 221 | ||
| 222 | -int SrsAacStreamEncoder::write_metadata(int64_t timestamp, char* data, int size) | 222 | +int SrsAacStreamEncoder::write_metadata(int64_t /*timestamp*/, char* /*data*/, int /*size*/) |
| 223 | { | 223 | { |
| 224 | - return enc->write_metadata(timestamp, data, size); | 224 | + // aac ignore any flv metadata. |
| 225 | + return ERROR_SUCCESS; | ||
| 225 | } | 226 | } |
| 226 | 227 | ||
| 227 | SrsStreamWriter::SrsStreamWriter(ISrsGoHttpResponseWriter* w) | 228 | SrsStreamWriter::SrsStreamWriter(ISrsGoHttpResponseWriter* w) |
| @@ -58,8 +58,8 @@ int SrsAacEncoder::initialize(SrsFileWriter* fs) | @@ -58,8 +58,8 @@ int SrsAacEncoder::initialize(SrsFileWriter* fs) | ||
| 58 | srs_assert(fs); | 58 | srs_assert(fs); |
| 59 | 59 | ||
| 60 | if (!fs->is_open()) { | 60 | if (!fs->is_open()) { |
| 61 | - ret = ERROR_KERNEL_FLV_STREAM_CLOSED; | ||
| 62 | - srs_warn("stream is not open for decoder. ret=%d", ret); | 61 | + ret = ERROR_KERNEL_AAC_STREAM_CLOSED; |
| 62 | + srs_warn("stream is not open for encoder. ret=%d", ret); | ||
| 63 | return ret; | 63 | return ret; |
| 64 | } | 64 | } |
| 65 | 65 | ||
| @@ -68,77 +68,6 @@ int SrsAacEncoder::initialize(SrsFileWriter* fs) | @@ -68,77 +68,6 @@ int SrsAacEncoder::initialize(SrsFileWriter* fs) | ||
| 68 | return ret; | 68 | return ret; |
| 69 | } | 69 | } |
| 70 | 70 | ||
| 71 | -int SrsAacEncoder::write_header() | ||
| 72 | -{ | ||
| 73 | - int ret = ERROR_SUCCESS; | ||
| 74 | - | ||
| 75 | - // 9bytes header and 4bytes first previous-tag-size | ||
| 76 | - static char flv_header[] = { | ||
| 77 | - 'F', 'L', 'V', // Signatures "FLV" | ||
| 78 | - (char)0x01, // File version (for example, 0x01 for FLV version 1) | ||
| 79 | - (char)0x00, // 4, audio; 1, video; 5 audio+video. | ||
| 80 | - (char)0x00, (char)0x00, (char)0x00, (char)0x09 // DataOffset UI32 The length of this header in bytes | ||
| 81 | - }; | ||
| 82 | - | ||
| 83 | - // flv specification should set the audio and video flag, | ||
| 84 | - // actually in practise, application generally ignore this flag, | ||
| 85 | - // so we generally set the audio/video to 0. | ||
| 86 | - | ||
| 87 | - // write 9bytes header. | ||
| 88 | - if ((ret = write_header(flv_header)) != ERROR_SUCCESS) { | ||
| 89 | - return ret; | ||
| 90 | - } | ||
| 91 | - | ||
| 92 | - return ret; | ||
| 93 | -} | ||
| 94 | - | ||
| 95 | -int SrsAacEncoder::write_header(char flv_header[9]) | ||
| 96 | -{ | ||
| 97 | - int ret = ERROR_SUCCESS; | ||
| 98 | - | ||
| 99 | - // write data. | ||
| 100 | - if ((ret = _fs->write(flv_header, 9, NULL)) != ERROR_SUCCESS) { | ||
| 101 | - srs_error("write flv header failed. ret=%d", ret); | ||
| 102 | - return ret; | ||
| 103 | - } | ||
| 104 | - | ||
| 105 | - char pts[] = { (char)0x00, (char)0x00, (char)0x00, (char)0x00 }; | ||
| 106 | - if ((ret = _fs->write(pts, 4, NULL)) != ERROR_SUCCESS) { | ||
| 107 | - return ret; | ||
| 108 | - } | ||
| 109 | - | ||
| 110 | - return ret; | ||
| 111 | -} | ||
| 112 | - | ||
| 113 | -int SrsAacEncoder::write_metadata(char type, char* data, int size) | ||
| 114 | -{ | ||
| 115 | - int ret = ERROR_SUCCESS; | ||
| 116 | - | ||
| 117 | - srs_assert(data); | ||
| 118 | - | ||
| 119 | - // 11 bytes tag header | ||
| 120 | - static char tag_header[] = { | ||
| 121 | - (char)type, // TagType UB [5], 18 = script data | ||
| 122 | - (char)0x00, (char)0x00, (char)0x00, // DataSize UI24 Length of the message. | ||
| 123 | - (char)0x00, (char)0x00, (char)0x00, // Timestamp UI24 Time in milliseconds at which the data in this tag applies. | ||
| 124 | - (char)0x00, // TimestampExtended UI8 | ||
| 125 | - (char)0x00, (char)0x00, (char)0x00, // StreamID UI24 Always 0. | ||
| 126 | - }; | ||
| 127 | - | ||
| 128 | - // write data size. | ||
| 129 | - if ((ret = tag_stream->initialize(tag_header + 1, 3)) != ERROR_SUCCESS) { | ||
| 130 | - return ret; | ||
| 131 | - } | ||
| 132 | - tag_stream->write_3bytes(size); | ||
| 133 | - | ||
| 134 | - if ((ret = write_tag(tag_header, sizeof(tag_header), data, size)) != ERROR_SUCCESS) { | ||
| 135 | - srs_error("write flv data tag failed. ret=%d", ret); | ||
| 136 | - return ret; | ||
| 137 | - } | ||
| 138 | - | ||
| 139 | - return ret; | ||
| 140 | -} | ||
| 141 | - | ||
| 142 | int SrsAacEncoder::write_audio(int64_t timestamp, char* data, int size) | 71 | int SrsAacEncoder::write_audio(int64_t timestamp, char* data, int size) |
| 143 | { | 72 | { |
| 144 | int ret = ERROR_SUCCESS; | 73 | int ret = ERROR_SUCCESS; |
| @@ -147,29 +76,6 @@ int SrsAacEncoder::write_audio(int64_t timestamp, char* data, int size) | @@ -147,29 +76,6 @@ int SrsAacEncoder::write_audio(int64_t timestamp, char* data, int size) | ||
| 147 | 76 | ||
| 148 | timestamp &= 0x7fffffff; | 77 | timestamp &= 0x7fffffff; |
| 149 | 78 | ||
| 150 | - // 11bytes tag header | ||
| 151 | - static char tag_header[] = { | ||
| 152 | - (char)8, // TagType UB [5], 8 = audio | ||
| 153 | - (char)0x00, (char)0x00, (char)0x00, // DataSize UI24 Length of the message. | ||
| 154 | - (char)0x00, (char)0x00, (char)0x00, // Timestamp UI24 Time in milliseconds at which the data in this tag applies. | ||
| 155 | - (char)0x00, // TimestampExtended UI8 | ||
| 156 | - (char)0x00, (char)0x00, (char)0x00, // StreamID UI24 Always 0. | ||
| 157 | - }; | ||
| 158 | - | ||
| 159 | - // write data size. | ||
| 160 | - if ((ret = tag_stream->initialize(tag_header + 1, 7)) != ERROR_SUCCESS) { | ||
| 161 | - return ret; | ||
| 162 | - } | ||
| 163 | - tag_stream->write_3bytes(size); | ||
| 164 | - tag_stream->write_3bytes((int32_t)timestamp); | ||
| 165 | - // default to little-endian | ||
| 166 | - tag_stream->write_1bytes((timestamp >> 24) & 0xFF); | ||
| 167 | - | ||
| 168 | - if ((ret = write_tag(tag_header, sizeof(tag_header), data, size)) != ERROR_SUCCESS) { | ||
| 169 | - srs_error("write flv audio tag failed. ret=%d", ret); | ||
| 170 | - return ret; | ||
| 171 | - } | ||
| 172 | - | ||
| 173 | return ret; | 79 | return ret; |
| 174 | } | 80 | } |
| 175 | 81 | ||
| @@ -181,66 +87,6 @@ int SrsAacEncoder::write_video(int64_t timestamp, char* data, int size) | @@ -181,66 +87,6 @@ int SrsAacEncoder::write_video(int64_t timestamp, char* data, int size) | ||
| 181 | 87 | ||
| 182 | timestamp &= 0x7fffffff; | 88 | timestamp &= 0x7fffffff; |
| 183 | 89 | ||
| 184 | - // 11bytes tag header | ||
| 185 | - static char tag_header[] = { | ||
| 186 | - (char)9, // TagType UB [5], 9 = video | ||
| 187 | - (char)0x00, (char)0x00, (char)0x00, // DataSize UI24 Length of the message. | ||
| 188 | - (char)0x00, (char)0x00, (char)0x00, // Timestamp UI24 Time in milliseconds at which the data in this tag applies. | ||
| 189 | - (char)0x00, // TimestampExtended UI8 | ||
| 190 | - (char)0x00, (char)0x00, (char)0x00, // StreamID UI24 Always 0. | ||
| 191 | - }; | ||
| 192 | - | ||
| 193 | - // write data size. | ||
| 194 | - if ((ret = tag_stream->initialize(tag_header + 1, 7)) != ERROR_SUCCESS) { | ||
| 195 | - return ret; | ||
| 196 | - } | ||
| 197 | - tag_stream->write_3bytes(size); | ||
| 198 | - tag_stream->write_3bytes((int32_t)timestamp); | ||
| 199 | - // default to little-endian | ||
| 200 | - tag_stream->write_1bytes((timestamp >> 24) & 0xFF); | ||
| 201 | - | ||
| 202 | - if ((ret = write_tag(tag_header, sizeof(tag_header), data, size)) != ERROR_SUCCESS) { | ||
| 203 | - srs_error("write flv video tag failed. ret=%d", ret); | ||
| 204 | - return ret; | ||
| 205 | - } | ||
| 206 | - | ||
| 207 | - return ret; | ||
| 208 | -} | ||
| 209 | - | ||
| 210 | -int SrsAacEncoder::size_tag(int data_size) | ||
| 211 | -{ | ||
| 212 | - srs_assert(data_size >= 0); | ||
| 213 | - return SRS_FLV_TAG_HEADER_SIZE + data_size + SRS_FLV_PREVIOUS_TAG_SIZE; | ||
| 214 | -} | ||
| 215 | - | ||
| 216 | -int SrsAacEncoder::write_tag(char* header, int header_size, char* tag, int tag_size) | ||
| 217 | -{ | ||
| 218 | - int ret = ERROR_SUCCESS; | ||
| 219 | - | ||
| 220 | - // write tag header. | ||
| 221 | - if ((ret = _fs->write(header, header_size, NULL)) != ERROR_SUCCESS) { | ||
| 222 | - srs_error("write flv tag header failed. ret=%d", ret); | ||
| 223 | - return ret; | ||
| 224 | - } | ||
| 225 | - | ||
| 226 | - // write tag data. | ||
| 227 | - if ((ret = _fs->write(tag, tag_size, NULL)) != ERROR_SUCCESS) { | ||
| 228 | - srs_error("write flv tag failed. ret=%d", ret); | ||
| 229 | - return ret; | ||
| 230 | - } | ||
| 231 | - | ||
| 232 | - // PreviousTagSizeN UI32 Size of last tag, including its header, in bytes. | ||
| 233 | - static char pre_size[SRS_FLV_PREVIOUS_TAG_SIZE]; | ||
| 234 | - if ((ret = tag_stream->initialize(pre_size, SRS_FLV_PREVIOUS_TAG_SIZE)) != ERROR_SUCCESS) { | ||
| 235 | - return ret; | ||
| 236 | - } | ||
| 237 | - tag_stream->write_4bytes(tag_size + header_size); | ||
| 238 | - if ((ret = _fs->write(pre_size, sizeof(pre_size), NULL)) != ERROR_SUCCESS) { | ||
| 239 | - srs_error("write flv previous tag size failed. ret=%d", ret); | ||
| 240 | - return ret; | ||
| 241 | - } | ||
| 242 | - | ||
| 243 | return ret; | 90 | return ret; |
| 244 | } | 91 | } |
| 245 | 92 | ||
| 246 | - |
| @@ -56,38 +56,11 @@ public: | @@ -56,38 +56,11 @@ public: | ||
| 56 | virtual int initialize(SrsFileWriter* fs); | 56 | virtual int initialize(SrsFileWriter* fs); |
| 57 | public: | 57 | public: |
| 58 | /** | 58 | /** |
| 59 | - * write flv header. | ||
| 60 | - * write following: | ||
| 61 | - * 1. E.2 The FLV header | ||
| 62 | - * 2. PreviousTagSize0 UI32 Always 0 | ||
| 63 | - * that is, 9+4=13bytes. | ||
| 64 | - */ | ||
| 65 | - virtual int write_header(); | ||
| 66 | - virtual int write_header(char flv_header[9]); | ||
| 67 | - /** | ||
| 68 | - * write flv metadata. | ||
| 69 | - * @param type, the type of data, or other message type. | ||
| 70 | - * @param data, the amf0 metadata which serialize from: | ||
| 71 | - * AMF0 string: onMetaData, | ||
| 72 | - * AMF0 object: the metadata object. | ||
| 73 | - * @remark assert data is not NULL. | ||
| 74 | - */ | ||
| 75 | - virtual int write_metadata(char type, char* data, int size); | ||
| 76 | - /** | ||
| 77 | * write audio/video packet. | 59 | * write audio/video packet. |
| 78 | * @remark assert data is not NULL. | 60 | * @remark assert data is not NULL. |
| 79 | */ | 61 | */ |
| 80 | virtual int write_audio(int64_t timestamp, char* data, int size); | 62 | virtual int write_audio(int64_t timestamp, char* data, int size); |
| 81 | virtual int write_video(int64_t timestamp, char* data, int size); | 63 | virtual int write_video(int64_t timestamp, char* data, int size); |
| 82 | -public: | ||
| 83 | - /** | ||
| 84 | - * get the tag size, | ||
| 85 | - * including the tag header, body, and 4bytes previous tag size. | ||
| 86 | - * @remark assert data_size is not negative. | ||
| 87 | - */ | ||
| 88 | - static int size_tag(int data_size); | ||
| 89 | -private: | ||
| 90 | - virtual int write_tag(char* header, int header_size, char* tag, int tag_size); | ||
| 91 | }; | 64 | }; |
| 92 | 65 | ||
| 93 | #endif | 66 | #endif |
| @@ -203,6 +203,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | @@ -203,6 +203,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
| 203 | #define ERROR_AAC_ADTS_HEADER 3047 | 203 | #define ERROR_AAC_ADTS_HEADER 3047 |
| 204 | #define ERROR_AAC_DATA_INVALID 3048 | 204 | #define ERROR_AAC_DATA_INVALID 3048 |
| 205 | #define ERROR_HTTP_STATUS_INVLIAD 3049 | 205 | #define ERROR_HTTP_STATUS_INVLIAD 3049 |
| 206 | +#define ERROR_KERNEL_AAC_STREAM_CLOSED 3050 | ||
| 206 | 207 | ||
| 207 | /////////////////////////////////////////////////////// | 208 | /////////////////////////////////////////////////////// |
| 208 | // HTTP protocol error. | 209 | // HTTP protocol error. |
| @@ -59,7 +59,7 @@ int SrsFlvEncoder::initialize(SrsFileWriter* fs) | @@ -59,7 +59,7 @@ int SrsFlvEncoder::initialize(SrsFileWriter* fs) | ||
| 59 | 59 | ||
| 60 | if (!fs->is_open()) { | 60 | if (!fs->is_open()) { |
| 61 | ret = ERROR_KERNEL_FLV_STREAM_CLOSED; | 61 | ret = ERROR_KERNEL_FLV_STREAM_CLOSED; |
| 62 | - srs_warn("stream is not open for decoder. ret=%d", ret); | 62 | + srs_warn("stream is not open for encoder. ret=%d", ret); |
| 63 | return ret; | 63 | return ret; |
| 64 | } | 64 | } |
| 65 | 65 |
-
请 注册 或 登录 后发表评论