winlin

for bug #293, add mp3 id3 spec

@@ -365,7 +365,7 @@ MODULE_DEPENDS=("CORE") @@ -365,7 +365,7 @@ MODULE_DEPENDS=("CORE")
365 ModuleLibIncs=(${SRS_OBJS_DIR}) 365 ModuleLibIncs=(${SRS_OBJS_DIR})
366 MODULE_FILES=("srs_kernel_error" "srs_kernel_log" "srs_kernel_stream" 366 MODULE_FILES=("srs_kernel_error" "srs_kernel_log" "srs_kernel_stream"
367 "srs_kernel_utility" "srs_kernel_flv" "srs_kernel_codec" "srs_kernel_file" 367 "srs_kernel_utility" "srs_kernel_flv" "srs_kernel_codec" "srs_kernel_file"
368 - "srs_kernel_consts" "srs_kernel_aac") 368 + "srs_kernel_consts" "srs_kernel_aac" "srs_kernel_mp3")
369 KERNEL_INCS="src/kernel"; MODULE_DIR=${KERNEL_INCS} . auto/modules.sh 369 KERNEL_INCS="src/kernel"; MODULE_DIR=${KERNEL_INCS} . auto/modules.sh
370 KERNEL_OBJS="${MODULE_OBJS[@]}" 370 KERNEL_OBJS="${MODULE_OBJS[@]}"
371 # 371 #
不能预览此文件类型
@@ -63,4 +63,8 @@ http1.1-rfc2616.txt @@ -63,4 +63,8 @@ http1.1-rfc2616.txt
63 arpa-internet-text-messages-rfc822.txt 63 arpa-internet-text-messages-rfc822.txt
64 http://www.rfc-editor.org/rfc/rfc822.txt 64 http://www.rfc-editor.org/rfc/rfc822.txt
65 65
  66 +mp3规范:
  67 +mp3.id3v2.3.0.pdf
  68 + http://id3.org/id3v2.3.0
  69 +
66 Winlin 70 Winlin
@@ -45,6 +45,7 @@ using namespace std; @@ -45,6 +45,7 @@ using namespace std;
45 #include <srs_app_source.hpp> 45 #include <srs_app_source.hpp>
46 #include <srs_protocol_msg_array.hpp> 46 #include <srs_protocol_msg_array.hpp>
47 #include <srs_kernel_aac.hpp> 47 #include <srs_kernel_aac.hpp>
  48 +#include <srs_kernel_mp3.hpp>
48 49
49 SrsVodStream::SrsVodStream(string root_dir) 50 SrsVodStream::SrsVodStream(string root_dir)
50 : SrsGoHttpFileServer(root_dir) 51 : SrsGoHttpFileServer(root_dir)
@@ -226,6 +227,44 @@ int SrsAacStreamEncoder::write_metadata(int64_t /*timestamp*/, char* /*data*/, i @@ -226,6 +227,44 @@ int SrsAacStreamEncoder::write_metadata(int64_t /*timestamp*/, char* /*data*/, i
226 return ERROR_SUCCESS; 227 return ERROR_SUCCESS;
227 } 228 }
228 229
  230 +SrsMp3StreamEncoder::SrsMp3StreamEncoder()
  231 +{
  232 + enc = new SrsMp3Encoder();
  233 +}
  234 +
  235 +SrsMp3StreamEncoder::~SrsMp3StreamEncoder()
  236 +{
  237 + srs_freep(enc);
  238 +}
  239 +
  240 +int SrsMp3StreamEncoder::initialize(SrsFileWriter* w)
  241 +{
  242 + int ret = ERROR_SUCCESS;
  243 +
  244 + if ((ret = enc->initialize(w)) != ERROR_SUCCESS) {
  245 + return ret;
  246 + }
  247 +
  248 + return ret;
  249 +}
  250 +
  251 +int SrsMp3StreamEncoder::write_audio(int64_t timestamp, char* data, int size)
  252 +{
  253 + return enc->write_audio(timestamp, data, size);
  254 +}
  255 +
  256 +int SrsMp3StreamEncoder::write_video(int64_t /*timestamp*/, char* /*data*/, int /*size*/)
  257 +{
  258 + // mp3 ignore any flv video.
  259 + return ERROR_SUCCESS;
  260 +}
  261 +
  262 +int SrsMp3StreamEncoder::write_metadata(int64_t /*timestamp*/, char* /*data*/, int /*size*/)
  263 +{
  264 + // mp3 ignore any flv metadata.
  265 + return ERROR_SUCCESS;
  266 +}
  267 +
229 SrsStreamWriter::SrsStreamWriter(ISrsGoHttpResponseWriter* w) 268 SrsStreamWriter::SrsStreamWriter(ISrsGoHttpResponseWriter* w)
230 { 269 {
231 writer = w; 270 writer = w;
@@ -279,12 +318,15 @@ int SrsLiveStream::serve_http(ISrsGoHttpResponseWriter* w, SrsHttpMessage* r) @@ -279,12 +318,15 @@ int SrsLiveStream::serve_http(ISrsGoHttpResponseWriter* w, SrsHttpMessage* r)
279 318
280 bool serve_flv_streaming = false; 319 bool serve_flv_streaming = false;
281 bool serve_aac_streaming = false; 320 bool serve_aac_streaming = false;
  321 + bool serve_mp3_streaming = false;
282 322
283 srs_assert(entry); 323 srs_assert(entry);
284 if (srs_string_ends_with(entry->pattern, ".flv")) { 324 if (srs_string_ends_with(entry->pattern, ".flv")) {
285 serve_flv_streaming = true; 325 serve_flv_streaming = true;
286 } else if (srs_string_ends_with(entry->pattern, ".aac")) { 326 } else if (srs_string_ends_with(entry->pattern, ".aac")) {
287 serve_aac_streaming = true; 327 serve_aac_streaming = true;
  328 + } else if (srs_string_ends_with(entry->pattern, ".mp3")) {
  329 + serve_mp3_streaming = true;
288 } else { 330 } else {
289 ret = ERROR_HTTP_LIVE_STREAM_EXT; 331 ret = ERROR_HTTP_LIVE_STREAM_EXT;
290 srs_error("http: unsupported pattern %s", entry->pattern.c_str()); 332 srs_error("http: unsupported pattern %s", entry->pattern.c_str());
@@ -322,6 +364,9 @@ int SrsLiveStream::serve_http(ISrsGoHttpResponseWriter* w, SrsHttpMessage* r) @@ -322,6 +364,9 @@ int SrsLiveStream::serve_http(ISrsGoHttpResponseWriter* w, SrsHttpMessage* r)
322 if (serve_aac_streaming) { 364 if (serve_aac_streaming) {
323 enc = new SrsAacStreamEncoder(); 365 enc = new SrsAacStreamEncoder();
324 } 366 }
  367 + if (serve_mp3_streaming) {
  368 + enc = new SrsMp3StreamEncoder();
  369 + }
325 SrsAutoFree(ISrsStreamEncoder, enc); 370 SrsAutoFree(ISrsStreamEncoder, enc);
326 371
327 if ((ret = enc->initialize(&writer)) != ERROR_SUCCESS) { 372 if ((ret = enc->initialize(&writer)) != ERROR_SUCCESS) {
@@ -42,6 +42,7 @@ class SrsSource; @@ -42,6 +42,7 @@ class SrsSource;
42 class SrsRequest; 42 class SrsRequest;
43 class SrsStSocket; 43 class SrsStSocket;
44 class SrsAacEncoder; 44 class SrsAacEncoder;
  45 +class SrsMp3Encoder;
45 class SrsFlvEncoder; 46 class SrsFlvEncoder;
46 class SrsHttpParser; 47 class SrsHttpParser;
47 class SrsHttpMessage; 48 class SrsHttpMessage;
@@ -113,6 +114,23 @@ public: @@ -113,6 +114,23 @@ public:
113 }; 114 };
114 115
115 /** 116 /**
  117 +* the mp3 stream encoder, remux rtmp stream to mp3 stream.
  118 +*/
  119 +class SrsMp3StreamEncoder : public ISrsStreamEncoder
  120 +{
  121 +private:
  122 + SrsMp3Encoder* enc;
  123 +public:
  124 + SrsMp3StreamEncoder();
  125 + virtual ~SrsMp3StreamEncoder();
  126 +public:
  127 + virtual int initialize(SrsFileWriter* w);
  128 + virtual int write_audio(int64_t timestamp, char* data, int size);
  129 + virtual int write_video(int64_t timestamp, char* data, int size);
  130 + virtual int write_metadata(int64_t timestamp, char* data, int size);
  131 +};
  132 +
  133 +/**
116 * write stream to http response direclty. 134 * write stream to http response direclty.
117 */ 135 */
118 class SrsStreamWriter : public SrsFileWriter 136 class SrsStreamWriter : public SrsFileWriter
@@ -38,9 +38,6 @@ using namespace std; @@ -38,9 +38,6 @@ using namespace std;
38 #include <srs_kernel_file.hpp> 38 #include <srs_kernel_file.hpp>
39 #include <srs_kernel_codec.hpp> 39 #include <srs_kernel_codec.hpp>
40 40
41 -#define SRS_FLV_TAG_HEADER_SIZE 11  
42 -#define SRS_FLV_PREVIOUS_TAG_SIZE 4  
43 -  
44 SrsAacEncoder::SrsAacEncoder() 41 SrsAacEncoder::SrsAacEncoder()
45 { 42 {
46 _fs = NULL; 43 _fs = NULL;
@@ -36,7 +36,7 @@ class SrsFileWriter; @@ -36,7 +36,7 @@ class SrsFileWriter;
36 class SrsFileReader; 36 class SrsFileReader;
37 37
38 /** 38 /**
39 -* encode data to flv file. 39 +* encode data to aac file.
40 */ 40 */
41 class SrsAacEncoder 41 class SrsAacEncoder
42 { 42 {
@@ -55,8 +55,8 @@ public: @@ -55,8 +55,8 @@ public:
55 public: 55 public:
56 /** 56 /**
57 * initialize the underlayer file stream. 57 * initialize the underlayer file stream.
58 - * @remark user can initialize multiple times to encode multiple flv files.  
59 - * @remark, user must free the fs, flv encoder never close/free it. 58 + * @remark user can initialize multiple times to encode multiple aac files.
  59 + * @remark, user must free the fs, aac encoder never close/free it.
60 */ 60 */
61 virtual int initialize(SrsFileWriter* fs); 61 virtual int initialize(SrsFileWriter* fs);
62 public: 62 public:
@@ -202,9 +202,6 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. @@ -202,9 +202,6 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
202 #define ERROR_AAC_REQUIRED_ADTS 3046 202 #define ERROR_AAC_REQUIRED_ADTS 3046
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  
206 -#define ERROR_KERNEL_AAC_STREAM_CLOSED 3050  
207 -#define ERROR_AAC_DECODE_ERROR 3051  
208 205
209 /////////////////////////////////////////////////////// 206 ///////////////////////////////////////////////////////
210 // HTTP protocol error. 207 // HTTP protocol error.
@@ -214,6 +211,11 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. @@ -214,6 +211,11 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
214 #define ERROR_HTTP_URL_NOT_CLEAN 4002 211 #define ERROR_HTTP_URL_NOT_CLEAN 4002
215 #define ERROR_HTTP_CONTENT_LENGTH 4003 212 #define ERROR_HTTP_CONTENT_LENGTH 4003
216 #define ERROR_HTTP_LIVE_STREAM_EXT 4004 213 #define ERROR_HTTP_LIVE_STREAM_EXT 4004
  214 +#define ERROR_HTTP_STATUS_INVLIAD 4005
  215 +#define ERROR_KERNEL_AAC_STREAM_CLOSED 4006
  216 +#define ERROR_AAC_DECODE_ERROR 4007
  217 +#define ERROR_KERNEL_MP3_STREAM_CLOSED 4008
  218 +#define ERROR_MP3_DECODE_ERROR 4009
217 219
218 /** 220 /**
219 * whether the error code is an system control error. 221 * whether the error code is an system control error.
@@ -32,6 +32,8 @@ file @@ -32,6 +32,8 @@ file
32 ..\kernel\srs_kernel_flv.cpp, 32 ..\kernel\srs_kernel_flv.cpp,
33 ..\kernel\srs_kernel_log.hpp, 33 ..\kernel\srs_kernel_log.hpp,
34 ..\kernel\srs_kernel_log.cpp, 34 ..\kernel\srs_kernel_log.cpp,
  35 + ..\kernel\srs_kernel_mp3.hpp,
  36 + ..\kernel\srs_kernel_mp3.cpp,
35 ..\kernel\srs_kernel_stream.hpp, 37 ..\kernel\srs_kernel_stream.hpp,
36 ..\kernel\srs_kernel_stream.cpp, 38 ..\kernel\srs_kernel_stream.cpp,
37 ..\kernel\srs_kernel_utility.hpp, 39 ..\kernel\srs_kernel_utility.hpp,