move codec to kernel.

pull/133/head
winlin 11 years ago
parent 608083d42f
commit 4970664e37

@ -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/>
中文资料(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/>
公用机器(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)
或 [阿里云镜像](http://182.92.80.26:8085/srs/donation/index.html) ,查看
[捐献墙(Donations)](https://github.com/winlinvip/simple-rtmp-server/blob/master/DONATIONS.txt)<br/>

4
trunk/configure vendored

@ -447,7 +447,7 @@ MODULE_ID="KERNEL"
MODULE_DEPENDS=("CORE")
ModuleLibIncs=(${SRS_OBJS})
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_OBJS="${MODULE_OBJS[@]}"
#
@ -465,7 +465,7 @@ MODULE_ID="APP"
MODULE_DEPENDS=("CORE" "KERNEL" "RTMP")
ModuleLibIncs=(${LibSTRoot} ${LibHttpParserRoot} ${SRS_OBJS})
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_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"

@ -50,6 +50,7 @@ int main(int argc, char** argv)
srs_flv_t oc = NULL;
// temp variables.
int tmp_file_size = 0;
char* tmp_file;
if (argc <= 2) {
@ -68,20 +69,30 @@ int main(int argc, char** argv)
in_flv_file = argv[1];
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("srs(simple-rtmp-server) client librtmp library.");
trace("version: %d.%d.%d", srs_version_major(), srs_version_minor(), srs_version_revision());
trace("input: %s", in_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) {
return ret;
}
ret = process(in_flv_file, tmp_file, &ic, &oc);
srs_flv_close(ic);
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);
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;
}
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 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;
}

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

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

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

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

@ -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.
*/
#include <srs_app_codec.hpp>
#include <srs_kernel_codec.hpp>
#include <string.h>
#include <stdlib.h>

@ -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_CODEC_HPP
#define SRS_APP_CODEC_HPP
#ifndef SRS_KERNEL_CODEC_HPP
#define SRS_KERNEL_CODEC_HPP
/*
#include <srs_app_codec.hpp>
#include <srs_kernel_codec.hpp>
*/
#include <srs_core.hpp>

@ -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.
*/
#ifndef SRS_APP_FLV_HPP
#define SRS_APP_FLV_HPP
#ifndef SRS_KERNEL_FLV_HPP
#define SRS_KERNEL_FLV_HPP
/*
#include <srs_kernel_flv.hpp>

@ -40,6 +40,7 @@ using namespace std;
#include <srs_kernel_stream.hpp>
#include <srs_protocol_amf0.hpp>
#include <srs_kernel_flv.hpp>
#include <srs_kernel_codec.hpp>
// if user want to define log, define the folowing macro.
#ifndef SRS_RTMP_USER_DEFINED_LOG
@ -496,6 +497,12 @@ int64_t srs_flv_tellg(srs_flv_t flv)
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)
{
return error_code == ERROR_SYSTEM_FILE_EOF;

@ -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);
/* file stream tellg to get offset */
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 */
flv_bool srs_flv_is_eof(int error_code);

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

Loading…
Cancel
Save