1
0
Fork 0
mirror of https://github.com/ossrs/srs.git synced 2025-03-09 15:49:59 +00:00

move codec to kernel.

This commit is contained in:
winlin 2014-05-28 17:37:15 +08:00
parent 608083d42f
commit 4970664e37
13 changed files with 116 additions and 19 deletions

View file

@ -23,7 +23,7 @@ git clone https://code.csdn.net/winlinvip/srs-csdn.git
报告问题(BugReport): [https://github.com/winlinvip/simple-rtmp-server/issues/new](https://github.com/winlinvip/simple-rtmp-server/issues/new)<br/> 报告问题(BugReport): [https://github.com/winlinvip/simple-rtmp-server/issues/new](https://github.com/winlinvip/simple-rtmp-server/issues/new)<br/>
中文资料(Wiki): [https://github.com/winlinvip/simple-rtmp-server/wiki](https://github.com/winlinvip/simple-rtmp-server/wiki) <br/> 中文资料(Wiki): [https://github.com/winlinvip/simple-rtmp-server/wiki](https://github.com/winlinvip/simple-rtmp-server/wiki) <br/>
使用步骤(Usage): [https://github.com/winlinvip/simple-rtmp-server#usage](#usage) <br/> 使用步骤(Usage): [https://github.com/winlinvip/simple-rtmp-server#usage](#usage) <br/>
公用机器(LiveShow): [https://github.com/winlinvip/simple-rtmp-server/wiki/LiveShow](供大家学习和使用的公用服务器) <br/> 公用机器(LiveShow): [https://github.com/winlinvip/simple-rtmp-server/wiki/LiveShow](https://github.com/winlinvip/simple-rtmp-server/wiki/LiveShow) <br/>
捐款(Donation): [GitHub](http://winlinvip.github.io/srs.release/donation/index.html) 捐款(Donation): [GitHub](http://winlinvip.github.io/srs.release/donation/index.html)
或 [阿里云镜像](http://182.92.80.26:8085/srs/donation/index.html) ,查看 或 [阿里云镜像](http://182.92.80.26:8085/srs/donation/index.html) ,查看
[捐献墙(Donations)](https://github.com/winlinvip/simple-rtmp-server/blob/master/DONATIONS.txt)<br/> [捐献墙(Donations)](https://github.com/winlinvip/simple-rtmp-server/blob/master/DONATIONS.txt)<br/>

4
trunk/configure vendored
View file

@ -447,7 +447,7 @@ MODULE_ID="KERNEL"
MODULE_DEPENDS=("CORE") MODULE_DEPENDS=("CORE")
ModuleLibIncs=(${SRS_OBJS}) ModuleLibIncs=(${SRS_OBJS})
MODULE_FILES=("srs_kernel_error" "srs_kernel_log" "srs_kernel_stream" "srs_kernel_buffer" MODULE_FILES=("srs_kernel_error" "srs_kernel_log" "srs_kernel_stream" "srs_kernel_buffer"
"srs_kernel_utility" "srs_kernel_flv") "srs_kernel_utility" "srs_kernel_flv" "srs_kernel_codec")
KERNEL_INCS="src/kernel"; MODULE_DIR=${KERNEL_INCS} . auto/modules.sh KERNEL_INCS="src/kernel"; MODULE_DIR=${KERNEL_INCS} . auto/modules.sh
KERNEL_OBJS="${MODULE_OBJS[@]}" KERNEL_OBJS="${MODULE_OBJS[@]}"
# #
@ -465,7 +465,7 @@ MODULE_ID="APP"
MODULE_DEPENDS=("CORE" "KERNEL" "RTMP") MODULE_DEPENDS=("CORE" "KERNEL" "RTMP")
ModuleLibIncs=(${LibSTRoot} ${LibHttpParserRoot} ${SRS_OBJS}) ModuleLibIncs=(${LibSTRoot} ${LibHttpParserRoot} ${SRS_OBJS})
MODULE_FILES=("srs_app_server" "srs_app_conn" "srs_app_rtmp_conn" "srs_app_socket" "srs_app_source" MODULE_FILES=("srs_app_server" "srs_app_conn" "srs_app_rtmp_conn" "srs_app_socket" "srs_app_source"
"srs_app_codec" "srs_app_refer" "srs_app_hls" "srs_app_forward" "srs_app_encoder" "srs_app_http" "srs_app_refer" "srs_app_hls" "srs_app_forward" "srs_app_encoder" "srs_app_http"
"srs_app_thread" "srs_app_bandwidth" "srs_app_st" "srs_app_log" "srs_app_config" "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_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_json" "srs_app_ingest" "srs_app_ffmpeg" "srs_app_utility" "srs_app_dvr" "srs_app_edge"

View file

@ -50,6 +50,7 @@ int main(int argc, char** argv)
srs_flv_t oc = NULL; srs_flv_t oc = NULL;
// temp variables. // temp variables.
int tmp_file_size = 0;
char* tmp_file; char* tmp_file;
if (argc <= 2) { if (argc <= 2) {
@ -68,20 +69,30 @@ int main(int argc, char** argv)
in_flv_file = argv[1]; in_flv_file = argv[1];
out_flv_file = argv[2]; out_flv_file = argv[2];
tmp_file = (char*)malloc(strlen(out_flv_file) + strlen(".tmp") + 1); tmp_file_size = strlen(out_flv_file) + strlen(".tmp") + 1;
tmp_file = (char*)malloc(tmp_file_size);
snprintf(tmp_file, tmp_file_size, "%s.tmp", out_flv_file);
trace("inject flv file keyframes to metadata."); trace("inject flv file keyframes to metadata.");
trace("srs(simple-rtmp-server) client librtmp library."); trace("srs(simple-rtmp-server) client librtmp library.");
trace("version: %d.%d.%d", srs_version_major(), srs_version_minor(), srs_version_revision()); trace("version: %d.%d.%d", srs_version_major(), srs_version_minor(), srs_version_revision());
trace("input: %s", in_flv_file); trace("input: %s", in_flv_file);
trace("output: %s", out_flv_file); trace("output: %s", out_flv_file);
trace("tmp_file: %s", tmp_file);
if ((ret = process(in_flv_file, out_flv_file, &ic, &oc)) != 0) { ret = process(in_flv_file, tmp_file, &ic, &oc);
return ret;
}
srs_flv_close(ic); srs_flv_close(ic);
srs_flv_close(oc); srs_flv_close(oc);
if (ret != 0) {
unlink(tmp_file);
trace("error, remove tmp file.");
} else {
rename(tmp_file, out_flv_file);
trace("completed, rename to %s", out_flv_file);
}
free(tmp_file); free(tmp_file);
return ret; return ret;
@ -110,9 +121,86 @@ int process(const char* in_flv_file, const char* out_flv_file, srs_flv_t* pic, s
return ret; return ret;
} }
int parse_metadata(char* data, int size, srs_amf0_t* pname, srs_amf0_t* pdata)
{
int ret = 0;
int nparsed = 0;
*pname = srs_amf0_parse(data, size, &nparsed);
if (*pname == NULL || nparsed >= size) {
trace("invalid amf0 name data.");
return -1;
}
*pdata = srs_amf0_parse(data + nparsed, size - nparsed, &nparsed);
if (*pdata == NULL || nparsed > size) {
trace("invalid amf0 value data");
return -1;
}
return ret;
}
int inject_flv(srs_flv_t ic, srs_flv_t oc) int inject_flv(srs_flv_t ic, srs_flv_t oc)
{ {
int ret = 0; int ret = 0;
// flv header
char header[13];
// packet data
char type;
u_int32_t timestamp = 0;
char* data = NULL;
int32_t size;
// metadata
srs_amf0_t amf0_name = NULL;
srs_amf0_t amf0_data = NULL;
// reset to generate metadata
srs_flv_lseek(ic, 0);
if ((ret = srs_flv_read_header(oc, header)) != 0) {
return ret;
}
trace("start inject flv");
for (;;) {
// tag header
if ((ret = srs_flv_read_tag_header(oc, &type, &size, &timestamp)) != 0) {
if (srs_flv_is_eof(ret)) {
trace("parse completed.");
return 0;
}
trace("flv get packet failed. ret=%d", ret);
return ret;
}
if (size <= 0) {
trace("invalid size=%d", size);
break;
}
// TODO: FIXME: mem leak when error.
data = (char*)malloc(size);
if ((ret = srs_flv_read_tag_data(oc, data, size)) != 0) {
return ret;
}
// data tag
if (type == SRS_RTMP_TYPE_VIDEO) {
} else if (type == SRS_RTMP_TYPE_SCRIPT) {
if ((ret = parse_metadata(data, size, &amf0_name, &amf0_data)) != 0) {
return ret;
}
}
free(data);
}
srs_amf0_free(amf0_name);
srs_amf0_free(amf0_data);
return ret; return ret;
} }

View file

@ -233,7 +233,7 @@ int parse_flv(srs_flv_t flv)
trace("parse completed."); trace("parse completed.");
return 0; return 0;
} }
trace("irtmp get packet failed. ret=%d", ret); trace("flv get packet failed. ret=%d", ret);
return ret; return ret;
} }

View file

@ -38,7 +38,7 @@ using namespace std;
#include <srs_kernel_stream.hpp> #include <srs_kernel_stream.hpp>
#include <srs_kernel_utility.hpp> #include <srs_kernel_utility.hpp>
#include <srs_app_http_hooks.hpp> #include <srs_app_http_hooks.hpp>
#include <srs_app_codec.hpp> #include <srs_kernel_codec.hpp>
#include <srs_kernel_flv.hpp> #include <srs_kernel_flv.hpp>
SrsFlvSegment::SrsFlvSegment() SrsFlvSegment::SrsFlvSegment()

View file

@ -35,7 +35,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
using namespace std; using namespace std;
#include <srs_kernel_error.hpp> #include <srs_kernel_error.hpp>
#include <srs_app_codec.hpp> #include <srs_kernel_codec.hpp>
#include <srs_protocol_amf0.hpp> #include <srs_protocol_amf0.hpp>
#include <srs_protocol_rtmp_stack.hpp> #include <srs_protocol_rtmp_stack.hpp>
#include <srs_app_config.hpp> #include <srs_app_config.hpp>

View file

@ -30,7 +30,7 @@ using namespace std;
#include <srs_protocol_rtmp_stack.hpp> #include <srs_protocol_rtmp_stack.hpp>
#include <srs_core_autofree.hpp> #include <srs_core_autofree.hpp>
#include <srs_protocol_amf0.hpp> #include <srs_protocol_amf0.hpp>
#include <srs_app_codec.hpp> #include <srs_kernel_codec.hpp>
#include <srs_app_hls.hpp> #include <srs_app_hls.hpp>
#include <srs_app_forward.hpp> #include <srs_app_forward.hpp>
#include <srs_app_config.hpp> #include <srs_app_config.hpp>

View file

@ -21,7 +21,7 @@ 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. CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/ */
#include <srs_app_codec.hpp> #include <srs_kernel_codec.hpp>
#include <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>

View file

@ -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. CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/ */
#ifndef SRS_APP_CODEC_HPP #ifndef SRS_KERNEL_CODEC_HPP
#define SRS_APP_CODEC_HPP #define SRS_KERNEL_CODEC_HPP
/* /*
#include <srs_app_codec.hpp> #include <srs_kernel_codec.hpp>
*/ */
#include <srs_core.hpp> #include <srs_core.hpp>

View file

@ -21,8 +21,8 @@ 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. CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/ */
#ifndef SRS_APP_FLV_HPP #ifndef SRS_KERNEL_FLV_HPP
#define SRS_APP_FLV_HPP #define SRS_KERNEL_FLV_HPP
/* /*
#include <srs_kernel_flv.hpp> #include <srs_kernel_flv.hpp>

View file

@ -40,6 +40,7 @@ using namespace std;
#include <srs_kernel_stream.hpp> #include <srs_kernel_stream.hpp>
#include <srs_protocol_amf0.hpp> #include <srs_protocol_amf0.hpp>
#include <srs_kernel_flv.hpp> #include <srs_kernel_flv.hpp>
#include <srs_kernel_codec.hpp>
// if user want to define log, define the folowing macro. // if user want to define log, define the folowing macro.
#ifndef SRS_RTMP_USER_DEFINED_LOG #ifndef SRS_RTMP_USER_DEFINED_LOG
@ -496,6 +497,12 @@ int64_t srs_flv_tellg(srs_flv_t flv)
return context->fs.tellg(); return context->fs.tellg();
} }
void srs_flv_lseek(srs_flv_t flv, int64_t offset)
{
FlvContext* context = (FlvContext*)flv;
context->fs.lseek(offset);
}
flv_bool srs_flv_is_eof(int error_code) flv_bool srs_flv_is_eof(int error_code)
{ {
return error_code == ERROR_SYSTEM_FILE_EOF; return error_code == ERROR_SYSTEM_FILE_EOF;

View file

@ -167,6 +167,8 @@ int srs_flv_read_tag_header(srs_flv_t flv, char* ptype, int32_t* pdata_size, u_i
int srs_flv_read_tag_data(srs_flv_t flv, char* data, int32_t size); int srs_flv_read_tag_data(srs_flv_t flv, char* data, int32_t size);
/* file stream tellg to get offset */ /* file stream tellg to get offset */
int64_t srs_flv_tellg(srs_flv_t flv); int64_t srs_flv_tellg(srs_flv_t flv);
/* seek file stream, offset is form the start of file */
void srs_flv_lseek(srs_flv_t flv, int64_t offset);
/* whether the error code indicates EOF */ /* whether the error code indicates EOF */
flv_bool srs_flv_is_eof(int error_code); flv_bool srs_flv_is_eof(int error_code);

View file

@ -17,6 +17,8 @@ file
kernel readonly separator, kernel readonly separator,
..\kernel\srs_kernel_buffer.hpp, ..\kernel\srs_kernel_buffer.hpp,
..\kernel\srs_kernel_buffer.cpp, ..\kernel\srs_kernel_buffer.cpp,
..\kernel\srs_kernel_codec.hpp,
..\kernel\srs_kernel_codec.cpp,
..\kernel\srs_kernel_error.hpp, ..\kernel\srs_kernel_error.hpp,
..\kernel\srs_kernel_error.cpp, ..\kernel\srs_kernel_error.cpp,
..\kernel\srs_kernel_flv.hpp, ..\kernel\srs_kernel_flv.hpp,
@ -43,8 +45,6 @@ file
app readonly separator, app readonly separator,
..\app\srs_app_bandwidth.hpp, ..\app\srs_app_bandwidth.hpp,
..\app\srs_app_bandwidth.cpp, ..\app\srs_app_bandwidth.cpp,
..\app\srs_app_codec.hpp,
..\app\srs_app_codec.cpp,
..\app\srs_app_conn.hpp, ..\app\srs_app_conn.hpp,
..\app\srs_app_conn.cpp, ..\app\srs_app_conn.cpp,
..\app\srs_app_config.hpp, ..\app\srs_app_config.hpp,