for bug #293, http ts stream, move the avc codec from app to kernel.
正在显示
17 个修改的文件
包含
309 行增加
和
134 行删除
| @@ -365,7 +365,8 @@ MODULE_DEPENDS=("CORE") | @@ -365,7 +365,8 @@ 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" "srs_kernel_mp3") | 368 | + "srs_kernel_consts" "srs_kernel_aac" "srs_kernel_mp3" "srs_kernel_ts" |
| 369 | + "srs_kernel_avc") | ||
| 369 | KERNEL_INCS="src/kernel"; MODULE_DIR=${KERNEL_INCS} . auto/modules.sh | 370 | KERNEL_INCS="src/kernel"; MODULE_DIR=${KERNEL_INCS} . auto/modules.sh |
| 370 | KERNEL_OBJS="${MODULE_OBJS[@]}" | 371 | KERNEL_OBJS="${MODULE_OBJS[@]}" |
| 371 | # | 372 | # |
| @@ -388,7 +389,7 @@ if [ $SRS_EXPORT_LIBRTMP_PROJECT = NO ]; then | @@ -388,7 +389,7 @@ if [ $SRS_EXPORT_LIBRTMP_PROJECT = NO ]; then | ||
| 388 | "srs_app_thread" "srs_app_bandwidth" "srs_app_st" "srs_app_log" "srs_app_config" | 389 | "srs_app_thread" "srs_app_bandwidth" "srs_app_st" "srs_app_log" "srs_app_config" |
| 389 | "srs_app_pithy_print" "srs_app_reload" "srs_app_http_api" "srs_app_http_conn" "srs_app_http_hooks" | 390 | "srs_app_pithy_print" "srs_app_reload" "srs_app_http_api" "srs_app_http_conn" "srs_app_http_hooks" |
| 390 | "srs_app_json" "srs_app_ingest" "srs_app_ffmpeg" "srs_app_utility" "srs_app_dvr" "srs_app_edge" | 391 | "srs_app_json" "srs_app_ingest" "srs_app_ffmpeg" "srs_app_utility" "srs_app_dvr" "srs_app_edge" |
| 391 | - "srs_app_kbps" "srs_app_heartbeat" "srs_app_empty" "srs_app_http_client" "srs_app_avc_aac" | 392 | + "srs_app_kbps" "srs_app_heartbeat" "srs_app_empty" "srs_app_http_client" |
| 392 | "srs_app_recv_thread" "srs_app_security" "srs_app_statistic") | 393 | "srs_app_recv_thread" "srs_app_security" "srs_app_statistic") |
| 393 | APP_INCS="src/app"; MODULE_DIR=${APP_INCS} . auto/modules.sh | 394 | APP_INCS="src/app"; MODULE_DIR=${APP_INCS} . auto/modules.sh |
| 394 | APP_OBJS="${MODULE_OBJS[@]}" | 395 | APP_OBJS="${MODULE_OBJS[@]}" |
| @@ -20,6 +20,8 @@ file | @@ -20,6 +20,8 @@ file | ||
| 20 | kernel readonly separator, | 20 | kernel readonly separator, |
| 21 | ../../src/kernel/srs_kernel_aac.hpp, | 21 | ../../src/kernel/srs_kernel_aac.hpp, |
| 22 | ../../src/kernel/srs_kernel_aac.cpp, | 22 | ../../src/kernel/srs_kernel_aac.cpp, |
| 23 | + ../../src/kernel/srs_kernel_avc.hpp, | ||
| 24 | + ../../src/kernel/srs_kernel_avc.cpp, | ||
| 23 | ../../src/kernel/srs_kernel_codec.hpp, | 25 | ../../src/kernel/srs_kernel_codec.hpp, |
| 24 | ../../src/kernel/srs_kernel_codec.cpp, | 26 | ../../src/kernel/srs_kernel_codec.cpp, |
| 25 | ../../src/kernel/srs_kernel_consts.hpp, | 27 | ../../src/kernel/srs_kernel_consts.hpp, |
| @@ -36,6 +38,8 @@ file | @@ -36,6 +38,8 @@ file | ||
| 36 | ../../src/kernel/srs_kernel_mp3.cpp, | 38 | ../../src/kernel/srs_kernel_mp3.cpp, |
| 37 | ../../src/kernel/srs_kernel_stream.hpp, | 39 | ../../src/kernel/srs_kernel_stream.hpp, |
| 38 | ../../src/kernel/srs_kernel_stream.cpp, | 40 | ../../src/kernel/srs_kernel_stream.cpp, |
| 41 | + ../../src/kernel/srs_kernel_ts.cpp, | ||
| 42 | + ../../src/kernel/srs_kernel_ts.hpp, | ||
| 39 | ../../src/kernel/srs_kernel_utility.hpp, | 43 | ../../src/kernel/srs_kernel_utility.hpp, |
| 40 | ../../src/kernel/srs_kernel_utility.cpp, | 44 | ../../src/kernel/srs_kernel_utility.cpp, |
| 41 | rtmp-protocol readonly separator, | 45 | rtmp-protocol readonly separator, |
| @@ -56,8 +60,6 @@ file | @@ -56,8 +60,6 @@ file | ||
| 56 | ../../src/rtmp/srs_protocol_utility.hpp, | 60 | ../../src/rtmp/srs_protocol_utility.hpp, |
| 57 | ../../src/rtmp/srs_protocol_utility.cpp, | 61 | ../../src/rtmp/srs_protocol_utility.cpp, |
| 58 | app readonly separator, | 62 | app readonly separator, |
| 59 | - ../../src/app/srs_app_avc_aac.hpp, | ||
| 60 | - ../../src/app/srs_app_avc_aac.cpp, | ||
| 61 | ../../src/app/srs_app_bandwidth.hpp, | 63 | ../../src/app/srs_app_bandwidth.hpp, |
| 62 | ../../src/app/srs_app_bandwidth.cpp, | 64 | ../../src/app/srs_app_bandwidth.cpp, |
| 63 | ../../src/app/srs_app_conn.hpp, | 65 | ../../src/app/srs_app_conn.hpp, |
| @@ -109,6 +109,7 @@ | @@ -109,6 +109,7 @@ | ||
| 109 | <ClInclude Include="..\..\src\kernel\srs_kernel_log.hpp" /> | 109 | <ClInclude Include="..\..\src\kernel\srs_kernel_log.hpp" /> |
| 110 | <ClInclude Include="..\..\src\kernel\srs_kernel_mp3.hpp" /> | 110 | <ClInclude Include="..\..\src\kernel\srs_kernel_mp3.hpp" /> |
| 111 | <ClInclude Include="..\..\src\kernel\srs_kernel_stream.hpp" /> | 111 | <ClInclude Include="..\..\src\kernel\srs_kernel_stream.hpp" /> |
| 112 | + <ClInclude Include="..\..\src\kernel\srs_kernel_ts.hpp" /> | ||
| 112 | <ClInclude Include="..\..\src\kernel\srs_kernel_utility.hpp" /> | 113 | <ClInclude Include="..\..\src\kernel\srs_kernel_utility.hpp" /> |
| 113 | <ClInclude Include="..\..\src\libs\srs_librtmp.hpp" /> | 114 | <ClInclude Include="..\..\src\libs\srs_librtmp.hpp" /> |
| 114 | <ClInclude Include="..\..\src\libs\srs_lib_bandwidth.hpp" /> | 115 | <ClInclude Include="..\..\src\libs\srs_lib_bandwidth.hpp" /> |
| @@ -182,6 +183,7 @@ | @@ -182,6 +183,7 @@ | ||
| 182 | <ClCompile Include="..\..\src\kernel\srs_kernel_log.cpp" /> | 183 | <ClCompile Include="..\..\src\kernel\srs_kernel_log.cpp" /> |
| 183 | <ClCompile Include="..\..\src\kernel\srs_kernel_mp3.cpp" /> | 184 | <ClCompile Include="..\..\src\kernel\srs_kernel_mp3.cpp" /> |
| 184 | <ClCompile Include="..\..\src\kernel\srs_kernel_stream.cpp" /> | 185 | <ClCompile Include="..\..\src\kernel\srs_kernel_stream.cpp" /> |
| 186 | + <ClCompile Include="..\..\src\kernel\srs_kernel_ts.cpp" /> | ||
| 185 | <ClCompile Include="..\..\src\kernel\srs_kernel_utility.cpp" /> | 187 | <ClCompile Include="..\..\src\kernel\srs_kernel_utility.cpp" /> |
| 186 | <ClCompile Include="..\..\src\libs\srs_librtmp.cpp" /> | 188 | <ClCompile Include="..\..\src\libs\srs_librtmp.cpp" /> |
| 187 | <ClCompile Include="..\..\src\libs\srs_lib_bandwidth.cpp" /> | 189 | <ClCompile Include="..\..\src\libs\srs_lib_bandwidth.cpp" /> |
| @@ -217,6 +217,9 @@ | @@ -217,6 +217,9 @@ | ||
| 217 | <ClCompile Include="..\..\research\librtmp\srs_aac_raw_publish.c"> | 217 | <ClCompile Include="..\..\research\librtmp\srs_aac_raw_publish.c"> |
| 218 | <Filter>librtmp</Filter> | 218 | <Filter>librtmp</Filter> |
| 219 | </ClCompile> | 219 | </ClCompile> |
| 220 | + <ClCompile Include="..\..\src\kernel\srs_kernel_ts.cpp"> | ||
| 221 | + <Filter>srs</Filter> | ||
| 222 | + </ClCompile> | ||
| 220 | </ItemGroup> | 223 | </ItemGroup> |
| 221 | <ItemGroup> | 224 | <ItemGroup> |
| 222 | <ClInclude Include="..\..\src\app\srs_app_avc_aac.hpp"> | 225 | <ClInclude Include="..\..\src\app\srs_app_avc_aac.hpp"> |
| @@ -396,6 +399,9 @@ | @@ -396,6 +399,9 @@ | ||
| 396 | <ClInclude Include="..\..\src\libs\srs_lib_simple_socket.hpp"> | 399 | <ClInclude Include="..\..\src\libs\srs_lib_simple_socket.hpp"> |
| 397 | <Filter>librtmp</Filter> | 400 | <Filter>librtmp</Filter> |
| 398 | </ClInclude> | 401 | </ClInclude> |
| 402 | + <ClInclude Include="..\..\src\kernel\srs_kernel_ts.hpp"> | ||
| 403 | + <Filter>srs</Filter> | ||
| 404 | + </ClInclude> | ||
| 399 | </ItemGroup> | 405 | </ItemGroup> |
| 400 | <ItemGroup> | 406 | <ItemGroup> |
| 401 | <Filter Include="research"> | 407 | <Filter Include="research"> |
| @@ -66,7 +66,7 @@ using namespace std; | @@ -66,7 +66,7 @@ using namespace std; | ||
| 66 | #include <srs_protocol_rtmp.hpp> | 66 | #include <srs_protocol_rtmp.hpp> |
| 67 | #include <srs_app_pithy_print.hpp> | 67 | #include <srs_app_pithy_print.hpp> |
| 68 | #include <srs_kernel_utility.hpp> | 68 | #include <srs_kernel_utility.hpp> |
| 69 | -#include <srs_app_avc_aac.hpp> | 69 | +#include <srs_kernel_avc.hpp> |
| 70 | #include <srs_kernel_file.hpp> | 70 | #include <srs_kernel_file.hpp> |
| 71 | #include <srs_protocol_buffer.hpp> | 71 | #include <srs_protocol_buffer.hpp> |
| 72 | 72 | ||
| @@ -1424,10 +1424,6 @@ int SrsHls::on_meta_data(SrsAmf0Object* metadata) | @@ -1424,10 +1424,6 @@ int SrsHls::on_meta_data(SrsAmf0Object* metadata) | ||
| 1424 | return ret; | 1424 | return ret; |
| 1425 | } | 1425 | } |
| 1426 | 1426 | ||
| 1427 | - if ((ret = codec->metadata_demux(metadata)) != ERROR_SUCCESS) { | ||
| 1428 | - return ret; | ||
| 1429 | - } | ||
| 1430 | - | ||
| 1431 | return ret; | 1427 | return ret; |
| 1432 | } | 1428 | } |
| 1433 | 1429 |
| @@ -275,8 +275,6 @@ SrsGoHttpFileServer::~SrsGoHttpFileServer() | @@ -275,8 +275,6 @@ SrsGoHttpFileServer::~SrsGoHttpFileServer() | ||
| 275 | 275 | ||
| 276 | int SrsGoHttpFileServer::serve_http(ISrsGoHttpResponseWriter* w, SrsHttpMessage* r) | 276 | int SrsGoHttpFileServer::serve_http(ISrsGoHttpResponseWriter* w, SrsHttpMessage* r) |
| 277 | { | 277 | { |
| 278 | - int ret = ERROR_SUCCESS; | ||
| 279 | - | ||
| 280 | string upath = r->path(); | 278 | string upath = r->path(); |
| 281 | 279 | ||
| 282 | // add default pages. | 280 | // add default pages. |
| @@ -760,6 +758,9 @@ int SrsGoHttpResponseWriter::send_header(char* data, int size) | @@ -760,6 +758,9 @@ int SrsGoHttpResponseWriter::send_header(char* data, int size) | ||
| 760 | if (content_length == -1) { | 758 | if (content_length == -1) { |
| 761 | hdr->set("Transfer-Encoding", "chunked"); | 759 | hdr->set("Transfer-Encoding", "chunked"); |
| 762 | } | 760 | } |
| 761 | + | ||
| 762 | + // keep alive to make vlc happy. | ||
| 763 | + hdr->set("Connection", "Keep-Alive"); | ||
| 763 | 764 | ||
| 764 | // write headers | 765 | // write headers |
| 765 | hdr->write(ss); | 766 | hdr->write(ss); |
| @@ -46,6 +46,7 @@ using namespace std; | @@ -46,6 +46,7 @@ using namespace std; | ||
| 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 | #include <srs_kernel_mp3.hpp> |
| 49 | +#include <srs_kernel_ts.hpp> | ||
| 49 | 50 | ||
| 50 | SrsVodStream::SrsVodStream(string root_dir) | 51 | SrsVodStream::SrsVodStream(string root_dir) |
| 51 | : SrsGoHttpFileServer(root_dir) | 52 | : SrsGoHttpFileServer(root_dir) |
| @@ -246,6 +247,54 @@ ISrsStreamEncoder::~ISrsStreamEncoder() | @@ -246,6 +247,54 @@ ISrsStreamEncoder::~ISrsStreamEncoder() | ||
| 246 | { | 247 | { |
| 247 | } | 248 | } |
| 248 | 249 | ||
| 250 | +SrsTsStreamEncoder::SrsTsStreamEncoder() | ||
| 251 | +{ | ||
| 252 | + enc = new SrsTsEncoder(); | ||
| 253 | +} | ||
| 254 | + | ||
| 255 | +SrsTsStreamEncoder::~SrsTsStreamEncoder() | ||
| 256 | +{ | ||
| 257 | + srs_freep(enc); | ||
| 258 | +} | ||
| 259 | + | ||
| 260 | +int SrsTsStreamEncoder::initialize(SrsFileWriter* w, SrsStreamCache* /*c*/) | ||
| 261 | +{ | ||
| 262 | + int ret = ERROR_SUCCESS; | ||
| 263 | + | ||
| 264 | + if ((ret = enc->initialize(w)) != ERROR_SUCCESS) { | ||
| 265 | + return ret; | ||
| 266 | + } | ||
| 267 | + | ||
| 268 | + return ret; | ||
| 269 | +} | ||
| 270 | + | ||
| 271 | +int SrsTsStreamEncoder::write_audio(int64_t timestamp, char* data, int size) | ||
| 272 | +{ | ||
| 273 | + return enc->write_audio(timestamp, data, size); | ||
| 274 | +} | ||
| 275 | + | ||
| 276 | +int SrsTsStreamEncoder::write_video(int64_t timestamp, char* data, int size) | ||
| 277 | +{ | ||
| 278 | + return enc->write_video(timestamp, data, size); | ||
| 279 | +} | ||
| 280 | + | ||
| 281 | +int SrsTsStreamEncoder::write_metadata(int64_t /*timestamp*/, char* /*data*/, int /*size*/) | ||
| 282 | +{ | ||
| 283 | + return ERROR_SUCCESS; | ||
| 284 | +} | ||
| 285 | + | ||
| 286 | +bool SrsTsStreamEncoder::has_cache() | ||
| 287 | +{ | ||
| 288 | + // for ts stream, use gop cache of SrsSource is ok. | ||
| 289 | + return false; | ||
| 290 | +} | ||
| 291 | + | ||
| 292 | +int SrsTsStreamEncoder::dump_cache(SrsConsumer* /*consumer*/) | ||
| 293 | +{ | ||
| 294 | + // for ts stream, ignore cache. | ||
| 295 | + return ERROR_SUCCESS; | ||
| 296 | +} | ||
| 297 | + | ||
| 249 | SrsFlvStreamEncoder::SrsFlvStreamEncoder() | 298 | SrsFlvStreamEncoder::SrsFlvStreamEncoder() |
| 250 | { | 299 | { |
| 251 | enc = new SrsFlvEncoder(); | 300 | enc = new SrsFlvEncoder(); |
| @@ -471,6 +520,9 @@ int SrsLiveStream::serve_http(ISrsGoHttpResponseWriter* w, SrsHttpMessage* r) | @@ -471,6 +520,9 @@ int SrsLiveStream::serve_http(ISrsGoHttpResponseWriter* w, SrsHttpMessage* r) | ||
| 471 | } else if (srs_string_ends_with(entry->pattern, ".mp3")) { | 520 | } else if (srs_string_ends_with(entry->pattern, ".mp3")) { |
| 472 | w->header()->set_content_type("audio/mpeg"); | 521 | w->header()->set_content_type("audio/mpeg"); |
| 473 | enc = new SrsMp3StreamEncoder(); | 522 | enc = new SrsMp3StreamEncoder(); |
| 523 | + } else if (srs_string_ends_with(entry->pattern, ".ts")) { | ||
| 524 | + w->header()->set_content_type("video/MP2T"); | ||
| 525 | + enc = new SrsTsStreamEncoder(); | ||
| 474 | } else { | 526 | } else { |
| 475 | ret = ERROR_HTTP_LIVE_STREAM_EXT; | 527 | ret = ERROR_HTTP_LIVE_STREAM_EXT; |
| 476 | srs_error("http: unsupported pattern %s", entry->pattern.c_str()); | 528 | srs_error("http: unsupported pattern %s", entry->pattern.c_str()); |
| @@ -43,6 +43,7 @@ class SrsSource; | @@ -43,6 +43,7 @@ class SrsSource; | ||
| 43 | class SrsRequest; | 43 | class SrsRequest; |
| 44 | class SrsConsumer; | 44 | class SrsConsumer; |
| 45 | class SrsStSocket; | 45 | class SrsStSocket; |
| 46 | +class SrsTsEncoder; | ||
| 46 | class SrsAacEncoder; | 47 | class SrsAacEncoder; |
| 47 | class SrsMp3Encoder; | 48 | class SrsMp3Encoder; |
| 48 | class SrsFlvEncoder; | 49 | class SrsFlvEncoder; |
| @@ -145,6 +146,26 @@ public: | @@ -145,6 +146,26 @@ public: | ||
| 145 | }; | 146 | }; |
| 146 | 147 | ||
| 147 | /** | 148 | /** |
| 149 | +* the ts stream encoder, remux rtmp stream to ts stream. | ||
| 150 | +*/ | ||
| 151 | +class SrsTsStreamEncoder : public ISrsStreamEncoder | ||
| 152 | +{ | ||
| 153 | +private: | ||
| 154 | + SrsTsEncoder* enc; | ||
| 155 | +public: | ||
| 156 | + SrsTsStreamEncoder(); | ||
| 157 | + virtual ~SrsTsStreamEncoder(); | ||
| 158 | +public: | ||
| 159 | + virtual int initialize(SrsFileWriter* w, SrsStreamCache* c); | ||
| 160 | + virtual int write_audio(int64_t timestamp, char* data, int size); | ||
| 161 | + virtual int write_video(int64_t timestamp, char* data, int size); | ||
| 162 | + virtual int write_metadata(int64_t timestamp, char* data, int size); | ||
| 163 | +public: | ||
| 164 | + virtual bool has_cache(); | ||
| 165 | + virtual int dump_cache(SrsConsumer* consumer); | ||
| 166 | +}; | ||
| 167 | + | ||
| 168 | +/** | ||
| 148 | * the aac stream encoder, remux rtmp stream to aac stream. | 169 | * the aac stream encoder, remux rtmp stream to aac stream. |
| 149 | */ | 170 | */ |
| 150 | class SrsAacStreamEncoder : public ISrsStreamEncoder | 171 | class SrsAacStreamEncoder : public ISrsStreamEncoder |
| @@ -40,7 +40,7 @@ using namespace std; | @@ -40,7 +40,7 @@ using namespace std; | ||
| 40 | #include <srs_kernel_stream.hpp> | 40 | #include <srs_kernel_stream.hpp> |
| 41 | #include <srs_app_edge.hpp> | 41 | #include <srs_app_edge.hpp> |
| 42 | #include <srs_kernel_utility.hpp> | 42 | #include <srs_kernel_utility.hpp> |
| 43 | -#include <srs_app_avc_aac.hpp> | 43 | +#include <srs_kernel_avc.hpp> |
| 44 | #include <srs_protocol_msg_array.hpp> | 44 | #include <srs_protocol_msg_array.hpp> |
| 45 | 45 | ||
| 46 | #define CONST_MAX_JITTER_MS 500 | 46 | #define CONST_MAX_JITTER_MS 500 |
| @@ -21,14 +21,12 @@ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | @@ -21,14 +21,12 @@ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
| 21 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | 21 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 22 | */ | 22 | */ |
| 23 | 23 | ||
| 24 | -#include <srs_app_avc_aac.hpp> | 24 | +#include <srs_kernel_avc.hpp> |
| 25 | 25 | ||
| 26 | #include <srs_kernel_error.hpp> | 26 | #include <srs_kernel_error.hpp> |
| 27 | #include <srs_kernel_log.hpp> | 27 | #include <srs_kernel_log.hpp> |
| 28 | #include <srs_kernel_stream.hpp> | 28 | #include <srs_kernel_stream.hpp> |
| 29 | -#include <srs_protocol_amf0.hpp> | ||
| 30 | -#include <srs_app_utility.hpp> | ||
| 31 | -#include <srs_protocol_utility.hpp> | 29 | +#include <srs_kernel_utility.hpp> |
| 32 | 30 | ||
| 33 | SrsCodecSampleUnit::SrsCodecSampleUnit() | 31 | SrsCodecSampleUnit::SrsCodecSampleUnit() |
| 34 | { | 32 | { |
| @@ -120,51 +118,6 @@ SrsAvcAacCodec::~SrsAvcAacCodec() | @@ -120,51 +118,6 @@ SrsAvcAacCodec::~SrsAvcAacCodec() | ||
| 120 | srs_freep(pictureParameterSetNALUnit); | 118 | srs_freep(pictureParameterSetNALUnit); |
| 121 | } | 119 | } |
| 122 | 120 | ||
| 123 | -int SrsAvcAacCodec::metadata_demux(SrsAmf0Object* metadata) | ||
| 124 | -{ | ||
| 125 | - int ret = ERROR_SUCCESS; | ||
| 126 | - | ||
| 127 | - srs_assert(metadata); | ||
| 128 | - | ||
| 129 | - SrsAmf0Object* obj = metadata; | ||
| 130 | - | ||
| 131 | - // finger out the codec info from metadata if possible. | ||
| 132 | - SrsAmf0Any* prop = NULL; | ||
| 133 | - | ||
| 134 | - if ((prop = obj->get_property("duration")) != NULL && prop->is_number()) { | ||
| 135 | - duration = (int)prop->to_number(); | ||
| 136 | - } | ||
| 137 | - if ((prop = obj->get_property("width")) != NULL && prop->is_number()) { | ||
| 138 | - width = (int)prop->to_number(); | ||
| 139 | - } | ||
| 140 | - if ((prop = obj->get_property("height")) != NULL && prop->is_number()) { | ||
| 141 | - height = (int)prop->to_number(); | ||
| 142 | - } | ||
| 143 | - if ((prop = obj->get_property("framerate")) != NULL && prop->is_number()) { | ||
| 144 | - frame_rate = (int)prop->to_number(); | ||
| 145 | - } | ||
| 146 | - if ((prop = obj->get_property("videocodecid")) != NULL && prop->is_number()) { | ||
| 147 | - video_codec_id = (int)prop->to_number(); | ||
| 148 | - } | ||
| 149 | - if ((prop = obj->get_property("videodatarate")) != NULL && prop->is_number()) { | ||
| 150 | - video_data_rate = (int)(1000 * prop->to_number()); | ||
| 151 | - } | ||
| 152 | - | ||
| 153 | - if ((prop = obj->get_property("audiocodecid")) != NULL && prop->is_number()) { | ||
| 154 | - audio_codec_id = (int)prop->to_number(); | ||
| 155 | - } | ||
| 156 | - if ((prop = obj->get_property("audiodatarate")) != NULL && prop->is_number()) { | ||
| 157 | - audio_data_rate = (int)(1000 * prop->to_number()); | ||
| 158 | - } | ||
| 159 | - | ||
| 160 | - // ignore the following, for each flv/rtmp packet contains them: | ||
| 161 | - // audiosamplerate, sample->sound_rate | ||
| 162 | - // audiosamplesize, sample->sound_size | ||
| 163 | - // stereo, sample->sound_type | ||
| 164 | - | ||
| 165 | - return ret; | ||
| 166 | -} | ||
| 167 | - | ||
| 168 | int SrsAvcAacCodec::audio_aac_demux(char* data, int size, SrsCodecSample* sample) | 121 | int SrsAvcAacCodec::audio_aac_demux(char* data, int size, SrsCodecSample* sample) |
| 169 | { | 122 | { |
| 170 | int ret = ERROR_SUCCESS; | 123 | int ret = ERROR_SUCCESS; |
| @@ -21,11 +21,11 @@ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | @@ -21,11 +21,11 @@ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
| 21 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | 21 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 22 | */ | 22 | */ |
| 23 | 23 | ||
| 24 | -#ifndef SRS_APP_AVC_AAC_HPP | ||
| 25 | -#define SRS_APP_AVC_AAC_HPP | 24 | +#ifndef SRS_KERNEL_AVC_HPP |
| 25 | +#define SRS_KERNEL_AVC_HPP | ||
| 26 | 26 | ||
| 27 | /* | 27 | /* |
| 28 | -#include <srs_app_avc_aac.hpp> | 28 | +#include <srs_kernel_avc.hpp> |
| 29 | */ | 29 | */ |
| 30 | 30 | ||
| 31 | #include <srs_core.hpp> | 31 | #include <srs_core.hpp> |
| @@ -239,12 +239,6 @@ public: | @@ -239,12 +239,6 @@ public: | ||
| 239 | // the following function used for hls to build the sample and codec. | 239 | // the following function used for hls to build the sample and codec. |
| 240 | public: | 240 | public: |
| 241 | /** | 241 | /** |
| 242 | - * demux the metadata, to to get the stream info, | ||
| 243 | - * for instance, the width/height, sample rate. | ||
| 244 | - * @param metadata, the metadata amf0 object. assert not NULL. | ||
| 245 | - */ | ||
| 246 | - virtual int metadata_demux(SrsAmf0Object* metadata); | ||
| 247 | - /** | ||
| 248 | * demux the audio packet in aac codec. | 242 | * demux the audio packet in aac codec. |
| 249 | * the packet mux in FLV/RTMP format defined in flv specification. | 243 | * the packet mux in FLV/RTMP format defined in flv specification. |
| 250 | * demux the audio speicified data(sound_format, sound_size, ...) to sample. | 244 | * demux the audio speicified data(sound_format, sound_size, ...) to sample. |
trunk/src/kernel/srs_kernel_ts.cpp
0 → 100644
| 1 | +/* | ||
| 2 | +The MIT License (MIT) | ||
| 3 | + | ||
| 4 | +Copyright (c) 2013-2015 winlin | ||
| 5 | + | ||
| 6 | +Permission is hereby granted, free of charge, to any person obtaining a copy of | ||
| 7 | +this software and associated documentation files (the "Software"), to deal in | ||
| 8 | +the Software without restriction, including without limitation the rights to | ||
| 9 | +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of | ||
| 10 | +the Software, and to permit persons to whom the Software is furnished to do so, | ||
| 11 | +subject to the following conditions: | ||
| 12 | + | ||
| 13 | +The above copyright notice and this permission notice shall be included in all | ||
| 14 | +copies or substantial portions of the Software. | ||
| 15 | + | ||
| 16 | +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| 17 | +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS | ||
| 18 | +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR | ||
| 19 | +COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER | ||
| 20 | +IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
| 21 | +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
| 22 | +*/ | ||
| 23 | + | ||
| 24 | +#include <srs_kernel_ts.hpp> | ||
| 25 | + | ||
| 26 | +// for srs-librtmp, @see https://github.com/winlinvip/simple-rtmp-server/issues/213 | ||
| 27 | +#ifndef _WIN32 | ||
| 28 | +#include <unistd.h> | ||
| 29 | +#endif | ||
| 30 | + | ||
| 31 | +#include <fcntl.h> | ||
| 32 | +#include <sstream> | ||
| 33 | +using namespace std; | ||
| 34 | + | ||
| 35 | +#include <srs_kernel_log.hpp> | ||
| 36 | +#include <srs_kernel_error.hpp> | ||
| 37 | +#include <srs_kernel_stream.hpp> | ||
| 38 | +#include <srs_kernel_file.hpp> | ||
| 39 | + | ||
| 40 | +SrsTsEncoder::SrsTsEncoder() | ||
| 41 | +{ | ||
| 42 | + _fs = NULL; | ||
| 43 | + tag_stream = new SrsStream(); | ||
| 44 | +} | ||
| 45 | + | ||
| 46 | +SrsTsEncoder::~SrsTsEncoder() | ||
| 47 | +{ | ||
| 48 | + srs_freep(tag_stream); | ||
| 49 | +} | ||
| 50 | + | ||
| 51 | +int SrsTsEncoder::initialize(SrsFileWriter* fs) | ||
| 52 | +{ | ||
| 53 | + int ret = ERROR_SUCCESS; | ||
| 54 | + | ||
| 55 | + srs_assert(fs); | ||
| 56 | + | ||
| 57 | + if (!fs->is_open()) { | ||
| 58 | + ret = ERROR_KERNEL_FLV_STREAM_CLOSED; | ||
| 59 | + srs_warn("stream is not open for encoder. ret=%d", ret); | ||
| 60 | + return ret; | ||
| 61 | + } | ||
| 62 | + | ||
| 63 | + _fs = fs; | ||
| 64 | + | ||
| 65 | + return ret; | ||
| 66 | +} | ||
| 67 | + | ||
| 68 | +int SrsTsEncoder::write_audio(int64_t timestamp, char* data, int size) | ||
| 69 | +{ | ||
| 70 | + int ret = ERROR_SUCCESS; | ||
| 71 | + return ret; | ||
| 72 | +} | ||
| 73 | + | ||
| 74 | +int SrsTsEncoder::write_video(int64_t timestamp, char* data, int size) | ||
| 75 | +{ | ||
| 76 | + int ret = ERROR_SUCCESS; | ||
| 77 | + return ret; | ||
| 78 | +} | ||
| 79 | + | ||
| 80 | + |
trunk/src/kernel/srs_kernel_ts.hpp
0 → 100644
| 1 | +/* | ||
| 2 | +The MIT License (MIT) | ||
| 3 | + | ||
| 4 | +Copyright (c) 2013-2015 winlin | ||
| 5 | + | ||
| 6 | +Permission is hereby granted, free of charge, to any person obtaining a copy of | ||
| 7 | +this software and associated documentation files (the "Software"), to deal in | ||
| 8 | +the Software without restriction, including without limitation the rights to | ||
| 9 | +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of | ||
| 10 | +the Software, and to permit persons to whom the Software is furnished to do so, | ||
| 11 | +subject to the following conditions: | ||
| 12 | + | ||
| 13 | +The above copyright notice and this permission notice shall be included in all | ||
| 14 | +copies or substantial portions of the Software. | ||
| 15 | + | ||
| 16 | +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| 17 | +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS | ||
| 18 | +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR | ||
| 19 | +COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER | ||
| 20 | +IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
| 21 | +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
| 22 | +*/ | ||
| 23 | + | ||
| 24 | +#ifndef SRS_KERNEL_TS_HPP | ||
| 25 | +#define SRS_KERNEL_TS_HPP | ||
| 26 | + | ||
| 27 | +/* | ||
| 28 | +#include <srs_kernel_ts.hpp> | ||
| 29 | +*/ | ||
| 30 | +#include <srs_core.hpp> | ||
| 31 | + | ||
| 32 | +#include <string> | ||
| 33 | + | ||
| 34 | +class SrsStream; | ||
| 35 | +class SrsFileWriter; | ||
| 36 | +class SrsFileReader; | ||
| 37 | + | ||
| 38 | +/** | ||
| 39 | +* encode data to ts file. | ||
| 40 | +*/ | ||
| 41 | +class SrsTsEncoder | ||
| 42 | +{ | ||
| 43 | +private: | ||
| 44 | + SrsFileWriter* _fs; | ||
| 45 | +private: | ||
| 46 | + SrsStream* tag_stream; | ||
| 47 | +public: | ||
| 48 | + SrsTsEncoder(); | ||
| 49 | + virtual ~SrsTsEncoder(); | ||
| 50 | +public: | ||
| 51 | + /** | ||
| 52 | + * initialize the underlayer file stream. | ||
| 53 | + */ | ||
| 54 | + virtual int initialize(SrsFileWriter* fs); | ||
| 55 | +public: | ||
| 56 | + /** | ||
| 57 | + * write audio/video packet. | ||
| 58 | + * @remark assert data is not NULL. | ||
| 59 | + */ | ||
| 60 | + virtual int write_audio(int64_t timestamp, char* data, int size); | ||
| 61 | + virtual int write_video(int64_t timestamp, char* data, int size); | ||
| 62 | +}; | ||
| 63 | + | ||
| 64 | +#endif | ||
| 65 | + |
| @@ -39,6 +39,7 @@ using namespace std; | @@ -39,6 +39,7 @@ using namespace std; | ||
| 39 | 39 | ||
| 40 | #include <srs_kernel_log.hpp> | 40 | #include <srs_kernel_log.hpp> |
| 41 | #include <srs_kernel_error.hpp> | 41 | #include <srs_kernel_error.hpp> |
| 42 | +#include <srs_kernel_stream.hpp> | ||
| 42 | 43 | ||
| 43 | // this value must: | 44 | // this value must: |
| 44 | // equals to (SRS_SYS_CYCLE_INTERVAL*SRS_SYS_TIME_RESOLUTION_MS_TIMES)*1000 | 45 | // equals to (SRS_SYS_CYCLE_INTERVAL*SRS_SYS_TIME_RESOLUTION_MS_TIMES)*1000 |
| @@ -278,3 +279,50 @@ int srs_create_dir_recursively(string dir) | @@ -278,3 +279,50 @@ int srs_create_dir_recursively(string dir) | ||
| 278 | return ret; | 279 | return ret; |
| 279 | } | 280 | } |
| 280 | 281 | ||
| 282 | +bool srs_avc_startswith_annexb(SrsStream* stream, int* pnb_start_code) | ||
| 283 | +{ | ||
| 284 | + char* bytes = stream->data() + stream->pos(); | ||
| 285 | + char* p = bytes; | ||
| 286 | + | ||
| 287 | + for (;;) { | ||
| 288 | + if (!stream->require(p - bytes + 3)) { | ||
| 289 | + return false; | ||
| 290 | + } | ||
| 291 | + | ||
| 292 | + // not match | ||
| 293 | + if (p[0] != (char)0x00 || p[1] != (char)0x00) { | ||
| 294 | + return false; | ||
| 295 | + } | ||
| 296 | + | ||
| 297 | + // match N[00] 00 00 01, where N>=0 | ||
| 298 | + if (p[2] == (char)0x01) { | ||
| 299 | + if (pnb_start_code) { | ||
| 300 | + *pnb_start_code = (int)(p - bytes) + 3; | ||
| 301 | + } | ||
| 302 | + return true; | ||
| 303 | + } | ||
| 304 | + | ||
| 305 | + p++; | ||
| 306 | + } | ||
| 307 | + | ||
| 308 | + return false; | ||
| 309 | +} | ||
| 310 | + | ||
| 311 | +bool srs_aac_startswith_adts(SrsStream* stream) | ||
| 312 | +{ | ||
| 313 | + char* bytes = stream->data() + stream->pos(); | ||
| 314 | + char* p = bytes; | ||
| 315 | + | ||
| 316 | + if (!stream->require(p - bytes + 2)) { | ||
| 317 | + return false; | ||
| 318 | + } | ||
| 319 | + | ||
| 320 | + // matched 12bits 0xFFF, | ||
| 321 | + // @remark, we must cast the 0xff to char to compare. | ||
| 322 | + if (p[0] != (char)0xff || (char)(p[1] & 0xf0) != (char)0xf0) { | ||
| 323 | + return false; | ||
| 324 | + } | ||
| 325 | + | ||
| 326 | + return true; | ||
| 327 | +} | ||
| 328 | + |
| @@ -32,6 +32,8 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | @@ -32,6 +32,8 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
| 32 | 32 | ||
| 33 | #include <string> | 33 | #include <string> |
| 34 | 34 | ||
| 35 | +class SrsStream; | ||
| 36 | + | ||
| 35 | // compare | 37 | // compare |
| 36 | #define srs_min(a, b) (((a) < (b))? (a) : (b)) | 38 | #define srs_min(a, b) (((a) < (b))? (a) : (b)) |
| 37 | #define srs_max(a, b) (((a) < (b))? (b) : (a)) | 39 | #define srs_max(a, b) (((a) < (b))? (b) : (a)) |
| @@ -62,5 +64,21 @@ extern bool srs_string_ends_with(std::string str, std::string flag); | @@ -62,5 +64,21 @@ extern bool srs_string_ends_with(std::string str, std::string flag); | ||
| 62 | // create dir recursively | 64 | // create dir recursively |
| 63 | extern int srs_create_dir_recursively(std::string dir); | 65 | extern int srs_create_dir_recursively(std::string dir); |
| 64 | 66 | ||
| 67 | +/** | ||
| 68 | +* whether stream starts with the avc NALU in "AnnexB" | ||
| 69 | +* from H.264-AVC-ISO_IEC_14496-10.pdf, page 211. | ||
| 70 | +* start code must be "N[00] 00 00 01" where N>=0 | ||
| 71 | +* @param pnb_start_code output the size of start code, must >=3. | ||
| 72 | +* NULL to ignore. | ||
| 73 | +*/ | ||
| 74 | +extern bool srs_avc_startswith_annexb(SrsStream* stream, int* pnb_start_code = NULL); | ||
| 75 | + | ||
| 76 | +/** | ||
| 77 | +* whether stream starts with the aac ADTS | ||
| 78 | +* from aac-mp4a-format-ISO_IEC_14496-3+2001.pdf, page 75, 1.A.2.2 ADTS. | ||
| 79 | +* start code must be '1111 1111 1111'B, that is 0xFFF | ||
| 80 | +*/ | ||
| 81 | +extern bool srs_aac_startswith_adts(SrsStream* stream); | ||
| 82 | + | ||
| 65 | #endif | 83 | #endif |
| 66 | 84 |
| @@ -157,53 +157,6 @@ bool srs_bytes_equals(void* pa, void* pb, int size) | @@ -157,53 +157,6 @@ bool srs_bytes_equals(void* pa, void* pb, int size) | ||
| 157 | return true; | 157 | return true; |
| 158 | } | 158 | } |
| 159 | 159 | ||
| 160 | -bool srs_avc_startswith_annexb(SrsStream* stream, int* pnb_start_code) | ||
| 161 | -{ | ||
| 162 | - char* bytes = stream->data() + stream->pos(); | ||
| 163 | - char* p = bytes; | ||
| 164 | - | ||
| 165 | - for (;;) { | ||
| 166 | - if (!stream->require(p - bytes + 3)) { | ||
| 167 | - return false; | ||
| 168 | - } | ||
| 169 | - | ||
| 170 | - // not match | ||
| 171 | - if (p[0] != (char)0x00 || p[1] != (char)0x00) { | ||
| 172 | - return false; | ||
| 173 | - } | ||
| 174 | - | ||
| 175 | - // match N[00] 00 00 01, where N>=0 | ||
| 176 | - if (p[2] == (char)0x01) { | ||
| 177 | - if (pnb_start_code) { | ||
| 178 | - *pnb_start_code = (int)(p - bytes) + 3; | ||
| 179 | - } | ||
| 180 | - return true; | ||
| 181 | - } | ||
| 182 | - | ||
| 183 | - p++; | ||
| 184 | - } | ||
| 185 | - | ||
| 186 | - return false; | ||
| 187 | -} | ||
| 188 | - | ||
| 189 | -bool srs_aac_startswith_adts(SrsStream* stream) | ||
| 190 | -{ | ||
| 191 | - char* bytes = stream->data() + stream->pos(); | ||
| 192 | - char* p = bytes; | ||
| 193 | - | ||
| 194 | - if (!stream->require(p - bytes + 2)) { | ||
| 195 | - return false; | ||
| 196 | - } | ||
| 197 | - | ||
| 198 | - // matched 12bits 0xFFF, | ||
| 199 | - // @remark, we must cast the 0xff to char to compare. | ||
| 200 | - if (p[0] != (char)0xff || (char)(p[1] & 0xf0) != (char)0xf0) { | ||
| 201 | - return false; | ||
| 202 | - } | ||
| 203 | - | ||
| 204 | - return true; | ||
| 205 | -} | ||
| 206 | - | ||
| 207 | int srs_chunk_header_c0( | 160 | int srs_chunk_header_c0( |
| 208 | int perfer_cid, u_int32_t timestamp, int32_t payload_length, | 161 | int perfer_cid, u_int32_t timestamp, int32_t payload_length, |
| 209 | int8_t message_type, int32_t stream_id, | 162 | int8_t message_type, int32_t stream_id, |
| @@ -33,7 +33,6 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | @@ -33,7 +33,6 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
| 33 | 33 | ||
| 34 | #include <srs_kernel_consts.hpp> | 34 | #include <srs_kernel_consts.hpp> |
| 35 | 35 | ||
| 36 | -class SrsStream; | ||
| 37 | class SrsMessageHeader; | 36 | class SrsMessageHeader; |
| 38 | 37 | ||
| 39 | /** | 38 | /** |
| @@ -89,22 +88,6 @@ extern std::string srs_generate_tc_url( | @@ -89,22 +88,6 @@ extern std::string srs_generate_tc_url( | ||
| 89 | extern bool srs_bytes_equals(void* pa, void* pb, int size); | 88 | extern bool srs_bytes_equals(void* pa, void* pb, int size); |
| 90 | 89 | ||
| 91 | /** | 90 | /** |
| 92 | -* whether stream starts with the avc NALU in "AnnexB" | ||
| 93 | -* from H.264-AVC-ISO_IEC_14496-10.pdf, page 211. | ||
| 94 | -* start code must be "N[00] 00 00 01" where N>=0 | ||
| 95 | -* @param pnb_start_code output the size of start code, must >=3. | ||
| 96 | -* NULL to ignore. | ||
| 97 | -*/ | ||
| 98 | -extern bool srs_avc_startswith_annexb(SrsStream* stream, int* pnb_start_code = NULL); | ||
| 99 | - | ||
| 100 | -/** | ||
| 101 | -* whether stream starts with the aac ADTS | ||
| 102 | -* from aac-mp4a-format-ISO_IEC_14496-3+2001.pdf, page 75, 1.A.2.2 ADTS. | ||
| 103 | -* start code must be '1111 1111 1111'B, that is 0xFFF | ||
| 104 | -*/ | ||
| 105 | -extern bool srs_aac_startswith_adts(SrsStream* stream); | ||
| 106 | - | ||
| 107 | -/** | ||
| 108 | * generate the c0 chunk header for msg. | 91 | * generate the c0 chunk header for msg. |
| 109 | * @param cache, the cache to write header. | 92 | * @param cache, the cache to write header. |
| 110 | * @param nb_cache, the size of cache. | 93 | * @param nb_cache, the size of cache. |
-
请 注册 或 登录 后发表评论