Skip to content

Commit

Permalink
for bug ossrs#293, http ts stream, move the avc codec from app to ker…
Browse files Browse the repository at this point in the history
…nel.
  • Loading branch information
winlinvip committed Jan 22, 2015
1 parent dc62991 commit 913f98b
Show file tree
Hide file tree
Showing 17 changed files with 309 additions and 134 deletions.
5 changes: 3 additions & 2 deletions trunk/configure
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,8 @@ 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_mp3")
"srs_kernel_consts" "srs_kernel_aac" "srs_kernel_mp3" "srs_kernel_ts"
"srs_kernel_avc")
KERNEL_INCS="src/kernel"; MODULE_DIR=${KERNEL_INCS} . auto/modules.sh
KERNEL_OBJS="${MODULE_OBJS[@]}"
#
Expand All @@ -388,7 +389,7 @@ if [ $SRS_EXPORT_LIBRTMP_PROJECT = NO ]; then
"srs_app_thread" "srs_app_bandwidth" "srs_app_st" "srs_app_log" "srs_app_config"
"srs_app_pithy_print" "srs_app_reload" "srs_app_http_api" "srs_app_http_conn" "srs_app_http_hooks"
"srs_app_json" "srs_app_ingest" "srs_app_ffmpeg" "srs_app_utility" "srs_app_dvr" "srs_app_edge"
"srs_app_kbps" "srs_app_heartbeat" "srs_app_empty" "srs_app_http_client" "srs_app_avc_aac"
"srs_app_kbps" "srs_app_heartbeat" "srs_app_empty" "srs_app_http_client"
"srs_app_recv_thread" "srs_app_security" "srs_app_statistic")
APP_INCS="src/app"; MODULE_DIR=${APP_INCS} . auto/modules.sh
APP_OBJS="${MODULE_OBJS[@]}"
Expand Down
6 changes: 4 additions & 2 deletions trunk/ide/srs_upp/srs_upp.upp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ file
kernel readonly separator,
../../src/kernel/srs_kernel_aac.hpp,
../../src/kernel/srs_kernel_aac.cpp,
../../src/kernel/srs_kernel_avc.hpp,
../../src/kernel/srs_kernel_avc.cpp,
../../src/kernel/srs_kernel_codec.hpp,
../../src/kernel/srs_kernel_codec.cpp,
../../src/kernel/srs_kernel_consts.hpp,
Expand All @@ -36,6 +38,8 @@ file
../../src/kernel/srs_kernel_mp3.cpp,
../../src/kernel/srs_kernel_stream.hpp,
../../src/kernel/srs_kernel_stream.cpp,
../../src/kernel/srs_kernel_ts.cpp,
../../src/kernel/srs_kernel_ts.hpp,
../../src/kernel/srs_kernel_utility.hpp,
../../src/kernel/srs_kernel_utility.cpp,
rtmp-protocol readonly separator,
Expand All @@ -56,8 +60,6 @@ file
../../src/rtmp/srs_protocol_utility.hpp,
../../src/rtmp/srs_protocol_utility.cpp,
app readonly separator,
../../src/app/srs_app_avc_aac.hpp,
../../src/app/srs_app_avc_aac.cpp,
../../src/app/srs_app_bandwidth.hpp,
../../src/app/srs_app_bandwidth.cpp,
../../src/app/srs_app_conn.hpp,
Expand Down
2 changes: 2 additions & 0 deletions trunk/ide/srs_vs2010/srs.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@
<ClInclude Include="..\..\src\kernel\srs_kernel_log.hpp" />
<ClInclude Include="..\..\src\kernel\srs_kernel_mp3.hpp" />
<ClInclude Include="..\..\src\kernel\srs_kernel_stream.hpp" />
<ClInclude Include="..\..\src\kernel\srs_kernel_ts.hpp" />
<ClInclude Include="..\..\src\kernel\srs_kernel_utility.hpp" />
<ClInclude Include="..\..\src\libs\srs_librtmp.hpp" />
<ClInclude Include="..\..\src\libs\srs_lib_bandwidth.hpp" />
Expand Down Expand Up @@ -182,6 +183,7 @@
<ClCompile Include="..\..\src\kernel\srs_kernel_log.cpp" />
<ClCompile Include="..\..\src\kernel\srs_kernel_mp3.cpp" />
<ClCompile Include="..\..\src\kernel\srs_kernel_stream.cpp" />
<ClCompile Include="..\..\src\kernel\srs_kernel_ts.cpp" />
<ClCompile Include="..\..\src\kernel\srs_kernel_utility.cpp" />
<ClCompile Include="..\..\src\libs\srs_librtmp.cpp" />
<ClCompile Include="..\..\src\libs\srs_lib_bandwidth.cpp" />
Expand Down
6 changes: 6 additions & 0 deletions trunk/ide/srs_vs2010/srs.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,9 @@
<ClCompile Include="..\..\research\librtmp\srs_aac_raw_publish.c">
<Filter>librtmp</Filter>
</ClCompile>
<ClCompile Include="..\..\src\kernel\srs_kernel_ts.cpp">
<Filter>srs</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\src\app\srs_app_avc_aac.hpp">
Expand Down Expand Up @@ -396,6 +399,9 @@
<ClInclude Include="..\..\src\libs\srs_lib_simple_socket.hpp">
<Filter>librtmp</Filter>
</ClInclude>
<ClInclude Include="..\..\src\kernel\srs_kernel_ts.hpp">
<Filter>srs</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<Filter Include="research">
Expand Down
6 changes: 1 addition & 5 deletions trunk/src/app/srs_app_hls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ using namespace std;
#include <srs_protocol_rtmp.hpp>
#include <srs_app_pithy_print.hpp>
#include <srs_kernel_utility.hpp>
#include <srs_app_avc_aac.hpp>
#include <srs_kernel_avc.hpp>
#include <srs_kernel_file.hpp>
#include <srs_protocol_buffer.hpp>

Expand Down Expand Up @@ -1424,10 +1424,6 @@ int SrsHls::on_meta_data(SrsAmf0Object* metadata)
return ret;
}

if ((ret = codec->metadata_demux(metadata)) != ERROR_SUCCESS) {
return ret;
}

return ret;
}

Expand Down
5 changes: 3 additions & 2 deletions trunk/src/app/srs_app_http.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -275,8 +275,6 @@ SrsGoHttpFileServer::~SrsGoHttpFileServer()

int SrsGoHttpFileServer::serve_http(ISrsGoHttpResponseWriter* w, SrsHttpMessage* r)
{
int ret = ERROR_SUCCESS;

string upath = r->path();

// add default pages.
Expand Down Expand Up @@ -760,6 +758,9 @@ int SrsGoHttpResponseWriter::send_header(char* data, int size)
if (content_length == -1) {
hdr->set("Transfer-Encoding", "chunked");
}

// keep alive to make vlc happy.
hdr->set("Connection", "Keep-Alive");

// write headers
hdr->write(ss);
Expand Down
52 changes: 52 additions & 0 deletions trunk/src/app/srs_app_http_conn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ using namespace std;
#include <srs_protocol_msg_array.hpp>
#include <srs_kernel_aac.hpp>
#include <srs_kernel_mp3.hpp>
#include <srs_kernel_ts.hpp>

SrsVodStream::SrsVodStream(string root_dir)
: SrsGoHttpFileServer(root_dir)
Expand Down Expand Up @@ -246,6 +247,54 @@ ISrsStreamEncoder::~ISrsStreamEncoder()
{
}

SrsTsStreamEncoder::SrsTsStreamEncoder()
{
enc = new SrsTsEncoder();
}

SrsTsStreamEncoder::~SrsTsStreamEncoder()
{
srs_freep(enc);
}

int SrsTsStreamEncoder::initialize(SrsFileWriter* w, SrsStreamCache* /*c*/)
{
int ret = ERROR_SUCCESS;

if ((ret = enc->initialize(w)) != ERROR_SUCCESS) {
return ret;
}

return ret;
}

int SrsTsStreamEncoder::write_audio(int64_t timestamp, char* data, int size)
{
return enc->write_audio(timestamp, data, size);
}

int SrsTsStreamEncoder::write_video(int64_t timestamp, char* data, int size)
{
return enc->write_video(timestamp, data, size);
}

int SrsTsStreamEncoder::write_metadata(int64_t /*timestamp*/, char* /*data*/, int /*size*/)
{
return ERROR_SUCCESS;
}

bool SrsTsStreamEncoder::has_cache()
{
// for ts stream, use gop cache of SrsSource is ok.
return false;
}

int SrsTsStreamEncoder::dump_cache(SrsConsumer* /*consumer*/)
{
// for ts stream, ignore cache.
return ERROR_SUCCESS;
}

SrsFlvStreamEncoder::SrsFlvStreamEncoder()
{
enc = new SrsFlvEncoder();
Expand Down Expand Up @@ -471,6 +520,9 @@ int SrsLiveStream::serve_http(ISrsGoHttpResponseWriter* w, SrsHttpMessage* r)
} else if (srs_string_ends_with(entry->pattern, ".mp3")) {
w->header()->set_content_type("audio/mpeg");
enc = new SrsMp3StreamEncoder();
} else if (srs_string_ends_with(entry->pattern, ".ts")) {
w->header()->set_content_type("video/MP2T");
enc = new SrsTsStreamEncoder();
} else {
ret = ERROR_HTTP_LIVE_STREAM_EXT;
srs_error("http: unsupported pattern %s", entry->pattern.c_str());
Expand Down
21 changes: 21 additions & 0 deletions trunk/src/app/srs_app_http_conn.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class SrsSource;
class SrsRequest;
class SrsConsumer;
class SrsStSocket;
class SrsTsEncoder;
class SrsAacEncoder;
class SrsMp3Encoder;
class SrsFlvEncoder;
Expand Down Expand Up @@ -144,6 +145,26 @@ class SrsFlvStreamEncoder : public ISrsStreamEncoder
virtual int dump_cache(SrsConsumer* consumer);
};

/**
* the ts stream encoder, remux rtmp stream to ts stream.
*/
class SrsTsStreamEncoder : public ISrsStreamEncoder
{
private:
SrsTsEncoder* enc;
public:
SrsTsStreamEncoder();
virtual ~SrsTsStreamEncoder();
public:
virtual int initialize(SrsFileWriter* w, SrsStreamCache* c);
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);
public:
virtual bool has_cache();
virtual int dump_cache(SrsConsumer* consumer);
};

/**
* the aac stream encoder, remux rtmp stream to aac stream.
*/
Expand Down
2 changes: 1 addition & 1 deletion trunk/src/app/srs_app_source.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ using namespace std;
#include <srs_kernel_stream.hpp>
#include <srs_app_edge.hpp>
#include <srs_kernel_utility.hpp>
#include <srs_app_avc_aac.hpp>
#include <srs_kernel_avc.hpp>
#include <srs_protocol_msg_array.hpp>

#define CONST_MAX_JITTER_MS 500
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,12 @@ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

#include <srs_app_avc_aac.hpp>
#include <srs_kernel_avc.hpp>

#include <srs_kernel_error.hpp>
#include <srs_kernel_log.hpp>
#include <srs_kernel_stream.hpp>
#include <srs_protocol_amf0.hpp>
#include <srs_app_utility.hpp>
#include <srs_protocol_utility.hpp>
#include <srs_kernel_utility.hpp>

SrsCodecSampleUnit::SrsCodecSampleUnit()
{
Expand Down Expand Up @@ -120,51 +118,6 @@ SrsAvcAacCodec::~SrsAvcAacCodec()
srs_freep(pictureParameterSetNALUnit);
}

int SrsAvcAacCodec::metadata_demux(SrsAmf0Object* metadata)
{
int ret = ERROR_SUCCESS;

srs_assert(metadata);

SrsAmf0Object* obj = metadata;

// finger out the codec info from metadata if possible.
SrsAmf0Any* prop = NULL;

if ((prop = obj->get_property("duration")) != NULL && prop->is_number()) {
duration = (int)prop->to_number();
}
if ((prop = obj->get_property("width")) != NULL && prop->is_number()) {
width = (int)prop->to_number();
}
if ((prop = obj->get_property("height")) != NULL && prop->is_number()) {
height = (int)prop->to_number();
}
if ((prop = obj->get_property("framerate")) != NULL && prop->is_number()) {
frame_rate = (int)prop->to_number();
}
if ((prop = obj->get_property("videocodecid")) != NULL && prop->is_number()) {
video_codec_id = (int)prop->to_number();
}
if ((prop = obj->get_property("videodatarate")) != NULL && prop->is_number()) {
video_data_rate = (int)(1000 * prop->to_number());
}

if ((prop = obj->get_property("audiocodecid")) != NULL && prop->is_number()) {
audio_codec_id = (int)prop->to_number();
}
if ((prop = obj->get_property("audiodatarate")) != NULL && prop->is_number()) {
audio_data_rate = (int)(1000 * prop->to_number());
}

// ignore the following, for each flv/rtmp packet contains them:
// audiosamplerate, sample->sound_rate
// audiosamplesize, sample->sound_size
// stereo, sample->sound_type

return ret;
}

int SrsAvcAacCodec::audio_aac_demux(char* data, int size, SrsCodecSample* sample)
{
int ret = ERROR_SUCCESS;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

#ifndef SRS_APP_AVC_AAC_HPP
#define SRS_APP_AVC_AAC_HPP
#ifndef SRS_KERNEL_AVC_HPP
#define SRS_KERNEL_AVC_HPP

/*
#include <srs_app_avc_aac.hpp>
#include <srs_kernel_avc.hpp>
*/

#include <srs_core.hpp>
Expand Down Expand Up @@ -238,12 +238,6 @@ class SrsAvcAacCodec
virtual ~SrsAvcAacCodec();
// the following function used for hls to build the sample and codec.
public:
/**
* demux the metadata, to to get the stream info,
* for instance, the width/height, sample rate.
* @param metadata, the metadata amf0 object. assert not NULL.
*/
virtual int metadata_demux(SrsAmf0Object* metadata);
/**
* demux the audio packet in aac codec.
* the packet mux in FLV/RTMP format defined in flv specification.
Expand Down
Loading

0 comments on commit 913f98b

Please sign in to comment.