winlin

for bug #293, add mp3 id3 spec

... ... @@ -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[@]}"
#
... ...
不能预览此文件类型
... ... @@ -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
... ...
... ... @@ -45,6 +45,7 @@ using namespace std;
#include <srs_app_source.hpp>
#include <srs_protocol_msg_array.hpp>
#include <srs_kernel_aac.hpp>
#include <srs_kernel_mp3.hpp>
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) {
... ...
... ... @@ -42,6 +42,7 @@ class SrsSource;
class SrsRequest;
class SrsStSocket;
class SrsAacEncoder;
class SrsMp3Encoder;
class SrsFlvEncoder;
class SrsHttpParser;
class SrsHttpMessage;
... ... @@ -113,6 +114,23 @@ public:
};
/**
* 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.
*/
class SrsStreamWriter : public SrsFileWriter
... ...
... ... @@ -38,9 +38,6 @@ using namespace std;
#include <srs_kernel_file.hpp>
#include <srs_kernel_codec.hpp>
#define SRS_FLV_TAG_HEADER_SIZE 11
#define SRS_FLV_PREVIOUS_TAG_SIZE 4
SrsAacEncoder::SrsAacEncoder()
{
_fs = NULL;
... ...
... ... @@ -36,7 +36,7 @@ class SrsFileWriter;
class SrsFileReader;
/**
* encode data to flv file.
* encode data to aac file.
*/
class SrsAacEncoder
{
... ... @@ -55,8 +55,8 @@ public:
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:
... ...
... ... @@ -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.
... ...
... ... @@ -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,
... ...