From 04aa6f82962706f8d435703e8adb7abaf406a33f Mon Sep 17 00:00:00 2001 From: winlin Date: Sat, 17 Jan 2015 13:23:30 +0800 Subject: [PATCH] drop script data except the onMetaData packet. --- trunk/research/librtmp/srs_rtmp_dump.c | 7 +++++++ trunk/src/libs/srs_librtmp.cpp | 25 +++++++++++++++++++++++++ trunk/src/libs/srs_librtmp.hpp | 5 +++++ 3 files changed, 37 insertions(+) diff --git a/trunk/research/librtmp/srs_rtmp_dump.c b/trunk/research/librtmp/srs_rtmp_dump.c index 5f5fb422d..0e7e82b69 100644 --- a/trunk/research/librtmp/srs_rtmp_dump.c +++ b/trunk/research/librtmp/srs_rtmp_dump.c @@ -275,6 +275,13 @@ int main(int argc, char** argv) // we only write some types of messages to flv file. int is_flv_msg = type == SRS_RTMP_TYPE_AUDIO || type == SRS_RTMP_TYPE_VIDEO || type == SRS_RTMP_TYPE_SCRIPT; + + // for script data, ignore except onMetaData + if (type == SRS_RTMP_TYPE_SCRIPT) { + if (!srs_rtmp_is_onMetaData(type, data, size)) { + is_flv_msg = 0; + } + } if (flv) { if (is_flv_msg) { diff --git a/trunk/src/libs/srs_librtmp.cpp b/trunk/src/libs/srs_librtmp.cpp index a9dedbbaa..eefd006a3 100644 --- a/trunk/src/libs/srs_librtmp.cpp +++ b/trunk/src/libs/srs_librtmp.cpp @@ -1064,6 +1064,31 @@ int srs_rtmp_write_packet(srs_rtmp_t rtmp, char type, u_int32_t timestamp, char* return ret; } +srs_bool srs_rtmp_is_onMetaData(char type, char* data, int size) +{ + int ret = ERROR_SUCCESS; + + if (type != SRS_RTMP_TYPE_SCRIPT) { + return false; + } + + SrsStream stream; + if ((ret = stream.initialize(data, size)) != ERROR_SUCCESS) { + return false; + } + + std::string name; + if ((ret = srs_amf0_read_string(&stream, name)) != ERROR_SUCCESS) { + return false; + } + + if (name != "onMetaData") { + return false; + } + + return true; +} + /** * directly write a audio frame. */ diff --git a/trunk/src/libs/srs_librtmp.hpp b/trunk/src/libs/srs_librtmp.hpp index 3a26519af..cc0122e55 100644 --- a/trunk/src/libs/srs_librtmp.hpp +++ b/trunk/src/libs/srs_librtmp.hpp @@ -264,6 +264,11 @@ extern int srs_rtmp_write_packet(srs_rtmp_t rtmp, char type, u_int32_t timestamp, char* data, int size ); +/** +* whether type is script data and the data is onMetaData. +*/ +extern srs_bool srs_rtmp_is_onMetaData(char type, char* data, int size); + /************************************************************* ************************************************************** * audio raw codec