diff --git a/trunk/configure b/trunk/configure index 24d595a50f..3800449f9d 100755 --- a/trunk/configure +++ b/trunk/configure @@ -365,7 +365,7 @@ MODULE_DEPENDS=("CORE") ModuleLibIncs=(${SRS_OBJS_DIR}) MODULE_FILES=("srs_kernel_error" "srs_kernel_log" "srs_kernel_stream" "srs_kernel_utility" "srs_kernel_flv" "srs_kernel_codec" "srs_kernel_file" - "srs_kernel_consts" "srs_kernel_aac") + "srs_kernel_consts" "srs_kernel_aac" "srs_kernel_mp3") KERNEL_INCS="src/kernel"; MODULE_DIR=${KERNEL_INCS} . auto/modules.sh KERNEL_OBJS="${MODULE_OBJS[@]}" # diff --git a/trunk/doc/mp3.id3v2.3.0.pdf b/trunk/doc/mp3.id3v2.3.0.pdf new file mode 100644 index 0000000000..0e919b5064 Binary files /dev/null and b/trunk/doc/mp3.id3v2.3.0.pdf differ diff --git a/trunk/doc/readme.txt b/trunk/doc/readme.txt index 3ddb2f288c..6de58c5007 100644 --- a/trunk/doc/readme.txt +++ b/trunk/doc/readme.txt @@ -63,4 +63,8 @@ http1.1-rfc2616.txt arpa-internet-text-messages-rfc822.txt http://www.rfc-editor.org/rfc/rfc822.txt +mp3规范: +mp3.id3v2.3.0.pdf + http://id3.org/id3v2.3.0 + Winlin diff --git a/trunk/src/app/srs_app_http_conn.cpp b/trunk/src/app/srs_app_http_conn.cpp index 17686c0219..ef27fa2631 100644 --- a/trunk/src/app/srs_app_http_conn.cpp +++ b/trunk/src/app/srs_app_http_conn.cpp @@ -45,6 +45,7 @@ using namespace std; #include #include #include +#include SrsVodStream::SrsVodStream(string root_dir) : SrsGoHttpFileServer(root_dir) @@ -226,6 +227,44 @@ int SrsAacStreamEncoder::write_metadata(int64_t /*timestamp*/, char* /*data*/, i return ERROR_SUCCESS; } +SrsMp3StreamEncoder::SrsMp3StreamEncoder() +{ + enc = new SrsMp3Encoder(); +} + +SrsMp3StreamEncoder::~SrsMp3StreamEncoder() +{ + srs_freep(enc); +} + +int SrsMp3StreamEncoder::initialize(SrsFileWriter* w) +{ + int ret = ERROR_SUCCESS; + + if ((ret = enc->initialize(w)) != ERROR_SUCCESS) { + return ret; + } + + return ret; +} + +int SrsMp3StreamEncoder::write_audio(int64_t timestamp, char* data, int size) +{ + return enc->write_audio(timestamp, data, size); +} + +int SrsMp3StreamEncoder::write_video(int64_t /*timestamp*/, char* /*data*/, int /*size*/) +{ + // mp3 ignore any flv video. + return ERROR_SUCCESS; +} + +int SrsMp3StreamEncoder::write_metadata(int64_t /*timestamp*/, char* /*data*/, int /*size*/) +{ + // mp3 ignore any flv metadata. + return ERROR_SUCCESS; +} + SrsStreamWriter::SrsStreamWriter(ISrsGoHttpResponseWriter* w) { writer = w; @@ -279,12 +318,15 @@ int SrsLiveStream::serve_http(ISrsGoHttpResponseWriter* w, SrsHttpMessage* r) bool serve_flv_streaming = false; bool serve_aac_streaming = false; + bool serve_mp3_streaming = false; srs_assert(entry); if (srs_string_ends_with(entry->pattern, ".flv")) { serve_flv_streaming = true; } else if (srs_string_ends_with(entry->pattern, ".aac")) { serve_aac_streaming = true; + } else if (srs_string_ends_with(entry->pattern, ".mp3")) { + serve_mp3_streaming = true; } else { ret = ERROR_HTTP_LIVE_STREAM_EXT; srs_error("http: unsupported pattern %s", entry->pattern.c_str()); @@ -322,6 +364,9 @@ int SrsLiveStream::serve_http(ISrsGoHttpResponseWriter* w, SrsHttpMessage* r) if (serve_aac_streaming) { enc = new SrsAacStreamEncoder(); } + if (serve_mp3_streaming) { + enc = new SrsMp3StreamEncoder(); + } SrsAutoFree(ISrsStreamEncoder, enc); if ((ret = enc->initialize(&writer)) != ERROR_SUCCESS) { diff --git a/trunk/src/app/srs_app_http_conn.hpp b/trunk/src/app/srs_app_http_conn.hpp index 3f90da7522..dac0e48228 100644 --- a/trunk/src/app/srs_app_http_conn.hpp +++ b/trunk/src/app/srs_app_http_conn.hpp @@ -42,6 +42,7 @@ class SrsSource; class SrsRequest; class SrsStSocket; class SrsAacEncoder; +class SrsMp3Encoder; class SrsFlvEncoder; class SrsHttpParser; class SrsHttpMessage; @@ -112,6 +113,23 @@ class SrsAacStreamEncoder : public ISrsStreamEncoder virtual int write_metadata(int64_t timestamp, char* data, int size); }; +/** +* the mp3 stream encoder, remux rtmp stream to mp3 stream. +*/ +class SrsMp3StreamEncoder : public ISrsStreamEncoder +{ +private: + SrsMp3Encoder* enc; +public: + SrsMp3StreamEncoder(); + virtual ~SrsMp3StreamEncoder(); +public: + virtual int initialize(SrsFileWriter* w); + 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_metadata(int64_t timestamp, char* data, int size); +}; + /** * write stream to http response direclty. */ diff --git a/trunk/src/kernel/srs_kernel_aac.cpp b/trunk/src/kernel/srs_kernel_aac.cpp index a68f386af5..80ec3d9d36 100644 --- a/trunk/src/kernel/srs_kernel_aac.cpp +++ b/trunk/src/kernel/srs_kernel_aac.cpp @@ -38,9 +38,6 @@ using namespace std; #include #include -#define SRS_FLV_TAG_HEADER_SIZE 11 -#define SRS_FLV_PREVIOUS_TAG_SIZE 4 - SrsAacEncoder::SrsAacEncoder() { _fs = NULL; diff --git a/trunk/src/kernel/srs_kernel_aac.hpp b/trunk/src/kernel/srs_kernel_aac.hpp index 536057e079..f4fddf5450 100644 --- a/trunk/src/kernel/srs_kernel_aac.hpp +++ b/trunk/src/kernel/srs_kernel_aac.hpp @@ -36,7 +36,7 @@ class SrsFileWriter; class SrsFileReader; /** -* encode data to flv file. +* encode data to aac file. */ class SrsAacEncoder { @@ -55,8 +55,8 @@ class SrsAacEncoder public: /** * initialize the underlayer file stream. - * @remark user can initialize multiple times to encode multiple flv files. - * @remark, user must free the fs, flv encoder never close/free it. + * @remark user can initialize multiple times to encode multiple aac files. + * @remark, user must free the fs, aac encoder never close/free it. */ virtual int initialize(SrsFileWriter* fs); public: diff --git a/trunk/src/kernel/srs_kernel_error.hpp b/trunk/src/kernel/srs_kernel_error.hpp index 5429603b15..0eabfa5315 100644 --- a/trunk/src/kernel/srs_kernel_error.hpp +++ b/trunk/src/kernel/srs_kernel_error.hpp @@ -202,9 +202,6 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #define ERROR_AAC_REQUIRED_ADTS 3046 #define ERROR_AAC_ADTS_HEADER 3047 #define ERROR_AAC_DATA_INVALID 3048 -#define ERROR_HTTP_STATUS_INVLIAD 3049 -#define ERROR_KERNEL_AAC_STREAM_CLOSED 3050 -#define ERROR_AAC_DECODE_ERROR 3051 /////////////////////////////////////////////////////// // HTTP protocol error. @@ -214,6 +211,11 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #define ERROR_HTTP_URL_NOT_CLEAN 4002 #define ERROR_HTTP_CONTENT_LENGTH 4003 #define ERROR_HTTP_LIVE_STREAM_EXT 4004 +#define ERROR_HTTP_STATUS_INVLIAD 4005 +#define ERROR_KERNEL_AAC_STREAM_CLOSED 4006 +#define ERROR_AAC_DECODE_ERROR 4007 +#define ERROR_KERNEL_MP3_STREAM_CLOSED 4008 +#define ERROR_MP3_DECODE_ERROR 4009 /** * whether the error code is an system control error. diff --git a/trunk/src/srs/srs.upp b/trunk/src/srs/srs.upp index 2bc0cd37d3..4840424eac 100755 --- a/trunk/src/srs/srs.upp +++ b/trunk/src/srs/srs.upp @@ -32,6 +32,8 @@ file ..\kernel\srs_kernel_flv.cpp, ..\kernel\srs_kernel_log.hpp, ..\kernel\srs_kernel_log.cpp, + ..\kernel\srs_kernel_mp3.hpp, + ..\kernel\srs_kernel_mp3.cpp, ..\kernel\srs_kernel_stream.hpp, ..\kernel\srs_kernel_stream.cpp, ..\kernel\srs_kernel_utility.hpp,