Skip to content

Commit

Permalink
for bug ossrs#293, add mp3 id3 spec
Browse files Browse the repository at this point in the history
  • Loading branch information
winlinvip committed Jan 19, 2015
1 parent b04888a commit 99bf397
Show file tree
Hide file tree
Showing 9 changed files with 78 additions and 10 deletions.
2 changes: 1 addition & 1 deletion trunk/configure
Original file line number Diff line number Diff line change
Expand Up @@ -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[@]}"
#
Expand Down
Binary file added trunk/doc/mp3.id3v2.3.0.pdf
Binary file not shown.
4 changes: 4 additions & 0 deletions trunk/doc/readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 changes: 45 additions & 0 deletions trunk/src/app/srs_app_http_conn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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) {
Expand Down
18 changes: 18 additions & 0 deletions trunk/src/app/srs_app_http_conn.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class SrsSource;
class SrsRequest;
class SrsStSocket;
class SrsAacEncoder;
class SrsMp3Encoder;
class SrsFlvEncoder;
class SrsHttpParser;
class SrsHttpMessage;
Expand Down Expand Up @@ -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.
*/
Expand Down
3 changes: 0 additions & 3 deletions trunk/src/kernel/srs_kernel_aac.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions trunk/src/kernel/srs_kernel_aac.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class SrsFileWriter;
class SrsFileReader;

/**
* encode data to flv file.
* encode data to aac file.
*/
class SrsAacEncoder
{
Expand All @@ -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:
Expand Down
8 changes: 5 additions & 3 deletions trunk/src/kernel/srs_kernel_error.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
Expand Down
2 changes: 2 additions & 0 deletions trunk/src/srs/srs.upp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 99bf397

Please sign in to comment.