正在显示
8 个修改的文件
包含
286 行增加
和
50 行删除
| @@ -217,6 +217,7 @@ that is: | @@ -217,6 +217,7 @@ that is: | ||
| 217 | #define __SRS_JFIELD_STR(k, v) "\"" << k << "\":\"" << v << "\"" | 217 | #define __SRS_JFIELD_STR(k, v) "\"" << k << "\":\"" << v << "\"" |
| 218 | #define __SRS_JFIELD_ORG(k, v) "\"" << k << "\":" << std::dec << v | 218 | #define __SRS_JFIELD_ORG(k, v) "\"" << k << "\":" << std::dec << v |
| 219 | #define __SRS_JFIELD_BOOL(k, v) __SRS_JFIELD_ORG(k, (v? "true":"false")) | 219 | #define __SRS_JFIELD_BOOL(k, v) __SRS_JFIELD_ORG(k, (v? "true":"false")) |
| 220 | +#define __SRS_JFIELD_NULL(k) "\"" << k << "\":null" | ||
| 220 | #define __SRS_JFIELD_ERROR(ret) "\"" << "code" << "\":" << ret | 221 | #define __SRS_JFIELD_ERROR(ret) "\"" << "code" << "\":" << ret |
| 221 | #define __SRS_JFIELD_CONT "," | 222 | #define __SRS_JFIELD_CONT "," |
| 222 | #define __SRS_JOBJECT_END "}" | 223 | #define __SRS_JOBJECT_END "}" |
| @@ -202,7 +202,7 @@ int SrsRtmpConn::do_cycle() | @@ -202,7 +202,7 @@ int SrsRtmpConn::do_cycle() | ||
| 202 | ret = service_cycle(); | 202 | ret = service_cycle(); |
| 203 | http_hooks_on_close(); | 203 | http_hooks_on_close(); |
| 204 | SrsStatistic* stat = SrsStatistic::instance(); | 204 | SrsStatistic* stat = SrsStatistic::instance(); |
| 205 | - stat->on_close(_srs_context->get_id()); | 205 | + stat->on_disconnect(_srs_context->get_id()); |
| 206 | 206 | ||
| 207 | return ret; | 207 | return ret; |
| 208 | } | 208 | } |
| @@ -42,6 +42,7 @@ using namespace std; | @@ -42,6 +42,7 @@ using namespace std; | ||
| 42 | #include <srs_kernel_utility.hpp> | 42 | #include <srs_kernel_utility.hpp> |
| 43 | #include <srs_kernel_codec.hpp> | 43 | #include <srs_kernel_codec.hpp> |
| 44 | #include <srs_rtmp_msg_array.hpp> | 44 | #include <srs_rtmp_msg_array.hpp> |
| 45 | +#include <srs_app_statistic.hpp> | ||
| 45 | 46 | ||
| 46 | #define CONST_MAX_JITTER_MS 500 | 47 | #define CONST_MAX_JITTER_MS 500 |
| 47 | #define DEFAULT_FRAME_TIME_MS 40 | 48 | #define DEFAULT_FRAME_TIME_MS 40 |
| @@ -1373,6 +1374,7 @@ int SrsSource::on_audio(SrsCommonMessage* __audio) | @@ -1373,6 +1374,7 @@ int SrsSource::on_audio(SrsCommonMessage* __audio) | ||
| 1373 | 1374 | ||
| 1374 | // cache the sequence header of aac, or first packet of mp3. | 1375 | // cache the sequence header of aac, or first packet of mp3. |
| 1375 | // for example, the mp3 is used for hls to write the "right" audio codec. | 1376 | // for example, the mp3 is used for hls to write the "right" audio codec. |
| 1377 | + // TODO: FIXME: to refine the stream info system. | ||
| 1376 | bool is_aac_sequence_header = SrsFlvCodec::audio_is_sequence_header(msg.payload, msg.size); | 1378 | bool is_aac_sequence_header = SrsFlvCodec::audio_is_sequence_header(msg.payload, msg.size); |
| 1377 | if (is_aac_sequence_header || !cache_sh_audio) { | 1379 | if (is_aac_sequence_header || !cache_sh_audio) { |
| 1378 | srs_freep(cache_sh_audio); | 1380 | srs_freep(cache_sh_audio); |
| @@ -1392,6 +1394,13 @@ int SrsSource::on_audio(SrsCommonMessage* __audio) | @@ -1392,6 +1394,13 @@ int SrsSource::on_audio(SrsCommonMessage* __audio) | ||
| 1392 | 1394 | ||
| 1393 | static int flv_sample_sizes[] = {8, 16, 0}; | 1395 | static int flv_sample_sizes[] = {8, 16, 0}; |
| 1394 | static int flv_sound_types[] = {1, 2, 0}; | 1396 | static int flv_sound_types[] = {1, 2, 0}; |
| 1397 | + | ||
| 1398 | + // when got audio stream info. | ||
| 1399 | + SrsStatistic* stat = SrsStatistic::instance(); | ||
| 1400 | + if ((ret = stat->on_audio_info(_req, SrsCodecAudioAAC, sample.sound_rate, sample.sound_type, codec.aac_profile)) != ERROR_SUCCESS) { | ||
| 1401 | + return ret; | ||
| 1402 | + } | ||
| 1403 | + | ||
| 1395 | srs_trace("%dB audio sh, " | 1404 | srs_trace("%dB audio sh, " |
| 1396 | "codec(%d, profile=%d, %dchannels, %dkbps, %dHZ), " | 1405 | "codec(%d, profile=%d, %dchannels, %dkbps, %dHZ), " |
| 1397 | "flv(%dbits, %dchannels, %dHZ)", | 1406 | "flv(%dbits, %dchannels, %dHZ)", |
| @@ -1515,6 +1524,12 @@ int SrsSource::on_video(SrsCommonMessage* __video) | @@ -1515,6 +1524,12 @@ int SrsSource::on_video(SrsCommonMessage* __video) | ||
| 1515 | return ret; | 1524 | return ret; |
| 1516 | } | 1525 | } |
| 1517 | 1526 | ||
| 1527 | + // when got video stream info. | ||
| 1528 | + SrsStatistic* stat = SrsStatistic::instance(); | ||
| 1529 | + if ((ret = stat->on_video_info(_req, SrsCodecVideoAVC, codec.avc_profile, codec.avc_level)) != ERROR_SUCCESS) { | ||
| 1530 | + return ret; | ||
| 1531 | + } | ||
| 1532 | + | ||
| 1518 | srs_trace("%dB video sh, " | 1533 | srs_trace("%dB video sh, " |
| 1519 | "codec(%d, profile=%d, level=%d, %dx%d, %dkbps, %dfps, %ds)", | 1534 | "codec(%d, profile=%d, level=%d, %dx%d, %dkbps, %dfps, %ds)", |
| 1520 | msg.size, codec.video_codec_id, | 1535 | msg.size, codec.video_codec_id, |
| @@ -50,12 +50,29 @@ SrsStatisticStream::SrsStatisticStream() | @@ -50,12 +50,29 @@ SrsStatisticStream::SrsStatisticStream() | ||
| 50 | { | 50 | { |
| 51 | id = __srs_generate_id(); | 51 | id = __srs_generate_id(); |
| 52 | vhost = NULL; | 52 | vhost = NULL; |
| 53 | + | ||
| 54 | + has_video = false; | ||
| 55 | + vcodec = SrsCodecVideoReserved; | ||
| 56 | + avc_profile = 0; | ||
| 57 | + avc_level = 0; | ||
| 58 | + | ||
| 59 | + has_audio = false; | ||
| 60 | + acodec = SrsCodecAudioReserved1; | ||
| 61 | + asample_rate = SrsCodecAudioSampleRateReserved; | ||
| 62 | + asound_type = SrsCodecAudioSoundTypeReserved; | ||
| 63 | + aac_profile = 0; | ||
| 53 | } | 64 | } |
| 54 | 65 | ||
| 55 | SrsStatisticStream::~SrsStatisticStream() | 66 | SrsStatisticStream::~SrsStatisticStream() |
| 56 | { | 67 | { |
| 57 | } | 68 | } |
| 58 | 69 | ||
| 70 | +void SrsStatisticStream::close() | ||
| 71 | +{ | ||
| 72 | + has_video = false; | ||
| 73 | + has_audio = false; | ||
| 74 | +} | ||
| 75 | + | ||
| 59 | SrsStatistic* SrsStatistic::_instance = new SrsStatistic(); | 76 | SrsStatistic* SrsStatistic::_instance = new SrsStatistic(); |
| 60 | 77 | ||
| 61 | SrsStatistic::SrsStatistic() | 78 | SrsStatistic::SrsStatistic() |
| @@ -93,34 +110,54 @@ SrsStatistic* SrsStatistic::instance() | @@ -93,34 +110,54 @@ SrsStatistic* SrsStatistic::instance() | ||
| 93 | return _instance; | 110 | return _instance; |
| 94 | } | 111 | } |
| 95 | 112 | ||
| 96 | -int SrsStatistic::on_client(int id, SrsRequest* req) | ||
| 97 | -{ | 113 | +int SrsStatistic::on_video_info(SrsRequest* req, |
| 114 | + SrsCodecVideo vcodec, u_int8_t avc_profile, u_int8_t avc_level | ||
| 115 | +) { | ||
| 98 | int ret = ERROR_SUCCESS; | 116 | int ret = ERROR_SUCCESS; |
| 99 | 117 | ||
| 100 | - // create vhost if not exists. | ||
| 101 | - SrsStatisticVhost* vhost = NULL; | ||
| 102 | - if (vhosts.find(req->vhost) == vhosts.end()) { | ||
| 103 | - vhost = new SrsStatisticVhost(); | ||
| 104 | - vhost->vhost = req->vhost; | ||
| 105 | - vhosts[req->vhost] = vhost; | ||
| 106 | - } else { | ||
| 107 | - vhost = vhosts[req->vhost]; | ||
| 108 | - } | 118 | + SrsStatisticVhost* vhost = create_vhost(req); |
| 119 | + SrsStatisticStream* stream = create_stream(vhost, req); | ||
| 120 | + | ||
| 121 | + stream->has_video = true; | ||
| 122 | + stream->vcodec = vcodec; | ||
| 123 | + stream->avc_profile = avc_profile; | ||
| 124 | + stream->avc_level = avc_level; | ||
| 109 | 125 | ||
| 110 | - // the url to identify the stream. | ||
| 111 | - std::string url = req->get_stream_url(); | 126 | + return ret; |
| 127 | +} | ||
| 128 | + | ||
| 129 | +int SrsStatistic::on_audio_info(SrsRequest* req, | ||
| 130 | + SrsCodecAudio acodec, SrsCodecAudioSampleRate asample_rate, SrsCodecAudioSoundType asound_type, | ||
| 131 | + u_int8_t aac_profile | ||
| 132 | +) { | ||
| 133 | + int ret = ERROR_SUCCESS; | ||
| 112 | 134 | ||
| 113 | - // create stream if not exists. | ||
| 114 | - SrsStatisticStream* stream = NULL; | ||
| 115 | - if (streams.find(url) == streams.end()) { | ||
| 116 | - stream = new SrsStatisticStream(); | ||
| 117 | - stream->vhost = vhost; | ||
| 118 | - stream->stream = req->stream; | ||
| 119 | - stream->url = url; | ||
| 120 | - streams[url] = stream; | ||
| 121 | - } else { | ||
| 122 | - stream = streams[url]; | ||
| 123 | - } | 135 | + SrsStatisticVhost* vhost = create_vhost(req); |
| 136 | + SrsStatisticStream* stream = create_stream(vhost, req); | ||
| 137 | + | ||
| 138 | + stream->has_audio = true; | ||
| 139 | + stream->acodec = acodec; | ||
| 140 | + stream->asample_rate = asample_rate; | ||
| 141 | + stream->asound_type = asound_type; | ||
| 142 | + stream->aac_profile = aac_profile; | ||
| 143 | + | ||
| 144 | + return ret; | ||
| 145 | +} | ||
| 146 | + | ||
| 147 | +void SrsStatistic::on_stream_close(SrsRequest* req) | ||
| 148 | +{ | ||
| 149 | + SrsStatisticVhost* vhost = create_vhost(req); | ||
| 150 | + SrsStatisticStream* stream = create_stream(vhost, req); | ||
| 151 | + | ||
| 152 | + stream->close(); | ||
| 153 | +} | ||
| 154 | + | ||
| 155 | +int SrsStatistic::on_client(int id, SrsRequest* req) | ||
| 156 | +{ | ||
| 157 | + int ret = ERROR_SUCCESS; | ||
| 158 | + | ||
| 159 | + SrsStatisticVhost* vhost = create_vhost(req); | ||
| 160 | + SrsStatisticStream* stream = create_stream(vhost, req); | ||
| 124 | 161 | ||
| 125 | // create client if not exists | 162 | // create client if not exists |
| 126 | SrsStatisticClient* client = NULL; | 163 | SrsStatisticClient* client = NULL; |
| @@ -135,7 +172,7 @@ int SrsStatistic::on_client(int id, SrsRequest* req) | @@ -135,7 +172,7 @@ int SrsStatistic::on_client(int id, SrsRequest* req) | ||
| 135 | return ret; | 172 | return ret; |
| 136 | } | 173 | } |
| 137 | 174 | ||
| 138 | -void SrsStatistic::on_close(int id) | 175 | +void SrsStatistic::on_disconnect(int id) |
| 139 | { | 176 | { |
| 140 | std::map<int, SrsStatisticClient*>::iterator it; | 177 | std::map<int, SrsStatisticClient*>::iterator it; |
| 141 | it = clients.find(id); | 178 | it = clients.find(id); |
| @@ -198,10 +235,74 @@ int SrsStatistic::dumps_streams(stringstream& ss) | @@ -198,10 +235,74 @@ int SrsStatistic::dumps_streams(stringstream& ss) | ||
| 198 | << __SRS_JFIELD_ORG("id", stream->id) << __SRS_JFIELD_CONT | 235 | << __SRS_JFIELD_ORG("id", stream->id) << __SRS_JFIELD_CONT |
| 199 | << __SRS_JFIELD_STR("name", stream->stream) << __SRS_JFIELD_CONT | 236 | << __SRS_JFIELD_STR("name", stream->stream) << __SRS_JFIELD_CONT |
| 200 | << __SRS_JFIELD_ORG("vhost", stream->vhost->id) << __SRS_JFIELD_CONT | 237 | << __SRS_JFIELD_ORG("vhost", stream->vhost->id) << __SRS_JFIELD_CONT |
| 201 | - << __SRS_JFIELD_ORG("clients", client_num) | ||
| 202 | - << __SRS_JOBJECT_END; | 238 | + << __SRS_JFIELD_ORG("clients", client_num) << __SRS_JFIELD_CONT; |
| 239 | + | ||
| 240 | + if (!stream->has_video) { | ||
| 241 | + ss << __SRS_JFIELD_NULL("video") << __SRS_JFIELD_CONT; | ||
| 242 | + } else { | ||
| 243 | + ss << __SRS_JFIELD_NAME("video") | ||
| 244 | + << __SRS_JOBJECT_START | ||
| 245 | + << __SRS_JFIELD_STR("codec", srs_codec_video2str(stream->vcodec)) << __SRS_JFIELD_CONT | ||
| 246 | + << __SRS_JFIELD_ORG("profile", (int)stream->avc_profile) << __SRS_JFIELD_CONT | ||
| 247 | + << __SRS_JFIELD_ORG("level", (int)stream->avc_level) | ||
| 248 | + << __SRS_JOBJECT_END | ||
| 249 | + << __SRS_JFIELD_CONT; | ||
| 250 | + } | ||
| 251 | + | ||
| 252 | + if (!stream->has_audio) { | ||
| 253 | + ss << __SRS_JFIELD_NULL("audio"); | ||
| 254 | + } else { | ||
| 255 | + ss << __SRS_JFIELD_NAME("audio") | ||
| 256 | + << __SRS_JOBJECT_START | ||
| 257 | + << __SRS_JFIELD_STR("codec", srs_codec_audio2str(stream->acodec)) << __SRS_JFIELD_CONT | ||
| 258 | + << __SRS_JFIELD_ORG("sample_rate", (int)flv_sample_rates[stream->asample_rate]) << __SRS_JFIELD_CONT | ||
| 259 | + << __SRS_JFIELD_ORG("channel", (int)stream->asound_type + 1) << __SRS_JFIELD_CONT | ||
| 260 | + << __SRS_JFIELD_STR("profile", srs_codec_aac_profile2str(stream->aac_profile)) | ||
| 261 | + << __SRS_JOBJECT_END; | ||
| 262 | + } | ||
| 263 | + | ||
| 264 | + ss << __SRS_JOBJECT_END; | ||
| 203 | } | 265 | } |
| 204 | ss << __SRS_JARRAY_END; | 266 | ss << __SRS_JARRAY_END; |
| 205 | 267 | ||
| 206 | return ret; | 268 | return ret; |
| 207 | } | 269 | } |
| 270 | + | ||
| 271 | +SrsStatisticVhost* SrsStatistic::create_vhost(SrsRequest* req) | ||
| 272 | +{ | ||
| 273 | + SrsStatisticVhost* vhost = NULL; | ||
| 274 | + | ||
| 275 | + // create vhost if not exists. | ||
| 276 | + if (vhosts.find(req->vhost) == vhosts.end()) { | ||
| 277 | + vhost = new SrsStatisticVhost(); | ||
| 278 | + vhost->vhost = req->vhost; | ||
| 279 | + vhosts[req->vhost] = vhost; | ||
| 280 | + return vhost; | ||
| 281 | + } | ||
| 282 | + | ||
| 283 | + vhost = vhosts[req->vhost]; | ||
| 284 | + | ||
| 285 | + return vhost; | ||
| 286 | +} | ||
| 287 | + | ||
| 288 | +SrsStatisticStream* SrsStatistic::create_stream(SrsStatisticVhost* vhost, SrsRequest* req) | ||
| 289 | +{ | ||
| 290 | + std::string url = req->get_stream_url(); | ||
| 291 | + | ||
| 292 | + SrsStatisticStream* stream = NULL; | ||
| 293 | + | ||
| 294 | + // create stream if not exists. | ||
| 295 | + if (streams.find(url) == streams.end()) { | ||
| 296 | + stream = new SrsStatisticStream(); | ||
| 297 | + stream->vhost = vhost; | ||
| 298 | + stream->stream = req->stream; | ||
| 299 | + stream->url = url; | ||
| 300 | + streams[url] = stream; | ||
| 301 | + return stream; | ||
| 302 | + } | ||
| 303 | + | ||
| 304 | + stream = streams[url]; | ||
| 305 | + | ||
| 306 | + return stream; | ||
| 307 | +} | ||
| 308 | + |
| @@ -33,6 +33,8 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | @@ -33,6 +33,8 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
| 33 | #include <map> | 33 | #include <map> |
| 34 | #include <string> | 34 | #include <string> |
| 35 | 35 | ||
| 36 | +#include <srs_kernel_codec.hpp> | ||
| 37 | + | ||
| 36 | class SrsRequest; | 38 | class SrsRequest; |
| 37 | 39 | ||
| 38 | struct SrsStatisticVhost | 40 | struct SrsStatisticVhost |
| @@ -54,8 +56,32 @@ public: | @@ -54,8 +56,32 @@ public: | ||
| 54 | std::string stream; | 56 | std::string stream; |
| 55 | std::string url; | 57 | std::string url; |
| 56 | public: | 58 | public: |
| 59 | + bool has_video; | ||
| 60 | + SrsCodecVideo vcodec; | ||
| 61 | + // profile_idc, H.264-AVC-ISO_IEC_14496-10.pdf, page 45. | ||
| 62 | + u_int8_t avc_profile; | ||
| 63 | + // level_idc, H.264-AVC-ISO_IEC_14496-10.pdf, page 45. | ||
| 64 | + u_int8_t avc_level; | ||
| 65 | +public: | ||
| 66 | + bool has_audio; | ||
| 67 | + SrsCodecAudio acodec; | ||
| 68 | + SrsCodecAudioSampleRate asample_rate; | ||
| 69 | + SrsCodecAudioSoundType asound_type; | ||
| 70 | + /** | ||
| 71 | + * audio specified | ||
| 72 | + * audioObjectType, in 1.6.2.1 AudioSpecificConfig, page 33, | ||
| 73 | + * 1.5.1.1 Audio object type definition, page 23, | ||
| 74 | + * in aac-mp4a-format-ISO_IEC_14496-3+2001.pdf. | ||
| 75 | + */ | ||
| 76 | + u_int8_t aac_profile; | ||
| 77 | +public: | ||
| 57 | SrsStatisticStream(); | 78 | SrsStatisticStream(); |
| 58 | virtual ~SrsStatisticStream(); | 79 | virtual ~SrsStatisticStream(); |
| 80 | +public: | ||
| 81 | + /** | ||
| 82 | + * close the stream. | ||
| 83 | + */ | ||
| 84 | + virtual void close(); | ||
| 59 | }; | 85 | }; |
| 60 | 86 | ||
| 61 | struct SrsStatisticClient | 87 | struct SrsStatisticClient |
| @@ -73,7 +99,7 @@ private: | @@ -73,7 +99,7 @@ private: | ||
| 73 | int64_t _server_id; | 99 | int64_t _server_id; |
| 74 | // key: vhost name, value: vhost object. | 100 | // key: vhost name, value: vhost object. |
| 75 | std::map<std::string, SrsStatisticVhost*> vhosts; | 101 | std::map<std::string, SrsStatisticVhost*> vhosts; |
| 76 | - // key: stream name, value: stream object. | 102 | + // key: stream url, value: stream object. |
| 77 | std::map<std::string, SrsStatisticStream*> streams; | 103 | std::map<std::string, SrsStatisticStream*> streams; |
| 78 | // key: client id, value: stream object. | 104 | // key: client id, value: stream object. |
| 79 | std::map<int, SrsStatisticClient*> clients; | 105 | std::map<int, SrsStatisticClient*> clients; |
| @@ -84,15 +110,33 @@ public: | @@ -84,15 +110,33 @@ public: | ||
| 84 | static SrsStatistic* instance(); | 110 | static SrsStatistic* instance(); |
| 85 | public: | 111 | public: |
| 86 | /** | 112 | /** |
| 113 | + * when got video info for stream. | ||
| 114 | + */ | ||
| 115 | + virtual int on_video_info(SrsRequest* req, | ||
| 116 | + SrsCodecVideo vcodec, u_int8_t avc_profile, u_int8_t avc_level | ||
| 117 | + ); | ||
| 118 | + /** | ||
| 119 | + * when got audio info for stream. | ||
| 120 | + */ | ||
| 121 | + virtual int on_audio_info(SrsRequest* req, | ||
| 122 | + SrsCodecAudio acodec, SrsCodecAudioSampleRate asample_rate, SrsCodecAudioSoundType asound_type, | ||
| 123 | + u_int8_t aac_profile | ||
| 124 | + ); | ||
| 125 | + /** | ||
| 126 | + * when close stream. | ||
| 127 | + */ | ||
| 128 | + virtual void on_stream_close(SrsRequest* req); | ||
| 129 | +public: | ||
| 130 | + /** | ||
| 87 | * when got a client to publish/play stream, | 131 | * when got a client to publish/play stream, |
| 88 | * @param id, the client srs id. | 132 | * @param id, the client srs id. |
| 89 | * @param req, the client request object. | 133 | * @param req, the client request object. |
| 90 | */ | 134 | */ |
| 91 | virtual int on_client(int id, SrsRequest* req); | 135 | virtual int on_client(int id, SrsRequest* req); |
| 92 | /** | 136 | /** |
| 93 | - * client close | 137 | + * client disconnect |
| 94 | */ | 138 | */ |
| 95 | - virtual void on_close(int id); | 139 | + virtual void on_disconnect(int id); |
| 96 | public: | 140 | public: |
| 97 | /** | 141 | /** |
| 98 | * get the server id, used to identify the server. | 142 | * get the server id, used to identify the server. |
| @@ -107,6 +151,9 @@ public: | @@ -107,6 +151,9 @@ public: | ||
| 107 | * dumps the streams to sstream in json. | 151 | * dumps the streams to sstream in json. |
| 108 | */ | 152 | */ |
| 109 | virtual int dumps_streams(std::stringstream& ss); | 153 | virtual int dumps_streams(std::stringstream& ss); |
| 154 | +private: | ||
| 155 | + virtual SrsStatisticVhost* create_vhost(SrsRequest* req); | ||
| 156 | + virtual SrsStatisticStream* create_stream(SrsStatisticVhost* vhost, SrsRequest* req); | ||
| 110 | }; | 157 | }; |
| 111 | 158 | ||
| 112 | #endif | 159 | #endif |
| @@ -32,6 +32,80 @@ using namespace std; | @@ -32,6 +32,80 @@ using namespace std; | ||
| 32 | #include <srs_kernel_stream.hpp> | 32 | #include <srs_kernel_stream.hpp> |
| 33 | #include <srs_kernel_utility.hpp> | 33 | #include <srs_kernel_utility.hpp> |
| 34 | 34 | ||
| 35 | +string srs_codec_video2str(SrsCodecVideo codec) | ||
| 36 | +{ | ||
| 37 | + switch (codec) { | ||
| 38 | + case SrsCodecVideoAVC: | ||
| 39 | + return "H264"; | ||
| 40 | + case SrsCodecVideoOn2VP6: | ||
| 41 | + case SrsCodecVideoOn2VP6WithAlphaChannel: | ||
| 42 | + return "H264"; | ||
| 43 | + case SrsCodecVideoReserved: | ||
| 44 | + case SrsCodecVideoReserved1: | ||
| 45 | + case SrsCodecVideoReserved2: | ||
| 46 | + case SrsCodecVideoDisabled: | ||
| 47 | + case SrsCodecVideoSorensonH263: | ||
| 48 | + case SrsCodecVideoScreenVideo: | ||
| 49 | + case SrsCodecVideoScreenVideoVersion2: | ||
| 50 | + default: | ||
| 51 | + return "Other"; | ||
| 52 | + } | ||
| 53 | +} | ||
| 54 | + | ||
| 55 | +string srs_codec_audio2str(SrsCodecAudio codec) | ||
| 56 | +{ | ||
| 57 | + switch (codec) { | ||
| 58 | + case SrsCodecAudioAAC: | ||
| 59 | + return "AAC"; | ||
| 60 | + case SrsCodecAudioMP3: | ||
| 61 | + return "MP3"; | ||
| 62 | + case SrsCodecAudioReserved1: | ||
| 63 | + case SrsCodecAudioLinearPCMPlatformEndian: | ||
| 64 | + case SrsCodecAudioADPCM: | ||
| 65 | + case SrsCodecAudioLinearPCMLittleEndian: | ||
| 66 | + case SrsCodecAudioNellymoser16kHzMono: | ||
| 67 | + case SrsCodecAudioNellymoser8kHzMono: | ||
| 68 | + case SrsCodecAudioNellymoser: | ||
| 69 | + case SrsCodecAudioReservedG711AlawLogarithmicPCM: | ||
| 70 | + case SrsCodecAudioReservedG711MuLawLogarithmicPCM: | ||
| 71 | + case SrsCodecAudioReserved: | ||
| 72 | + case SrsCodecAudioSpeex: | ||
| 73 | + case SrsCodecAudioReservedMP3_8kHz: | ||
| 74 | + case SrsCodecAudioReservedDeviceSpecificSound: | ||
| 75 | + default: | ||
| 76 | + return "Other"; | ||
| 77 | + } | ||
| 78 | +} | ||
| 79 | + | ||
| 80 | +string srs_codec_aac_profile2str(u_int8_t aac_profile) | ||
| 81 | +{ | ||
| 82 | + switch (aac_profile) { | ||
| 83 | + case 1: return "Main"; | ||
| 84 | + case 2: return "LC"; | ||
| 85 | + case 3: return "SSR"; | ||
| 86 | + default: return "Other"; | ||
| 87 | + } | ||
| 88 | +} | ||
| 89 | + | ||
| 90 | +/** | ||
| 91 | +* the public data, event HLS disable, others can use it. | ||
| 92 | +*/ | ||
| 93 | +// 0 = 5.5 kHz = 5512 Hz | ||
| 94 | +// 1 = 11 kHz = 11025 Hz | ||
| 95 | +// 2 = 22 kHz = 22050 Hz | ||
| 96 | +// 3 = 44 kHz = 44100 Hz | ||
| 97 | +int flv_sample_rates[] = {5512, 11025, 22050, 44100}; | ||
| 98 | + | ||
| 99 | +// the sample rates in the codec, | ||
| 100 | +// in the sequence header. | ||
| 101 | +int aac_sample_rates[] = | ||
| 102 | +{ | ||
| 103 | + 96000, 88200, 64000, 48000, | ||
| 104 | + 44100, 32000, 24000, 22050, | ||
| 105 | + 16000, 12000, 11025, 8000, | ||
| 106 | + 7350, 0, 0, 0 | ||
| 107 | +}; | ||
| 108 | + | ||
| 35 | SrsFlvCodec::SrsFlvCodec() | 109 | SrsFlvCodec::SrsFlvCodec() |
| 36 | { | 110 | { |
| 37 | } | 111 | } |
| @@ -110,6 +110,7 @@ enum SrsCodecVideo | @@ -110,6 +110,7 @@ enum SrsCodecVideo | ||
| 110 | SrsCodecVideoScreenVideoVersion2 = 6, | 110 | SrsCodecVideoScreenVideoVersion2 = 6, |
| 111 | SrsCodecVideoAVC = 7, | 111 | SrsCodecVideoAVC = 7, |
| 112 | }; | 112 | }; |
| 113 | +std::string srs_codec_video2str(SrsCodecVideo codec); | ||
| 113 | 114 | ||
| 114 | // SoundFormat UB [4] | 115 | // SoundFormat UB [4] |
| 115 | // Format of SoundData. The following values are defined: | 116 | // Format of SoundData. The following values are defined: |
| @@ -150,6 +151,7 @@ enum SrsCodecAudio | @@ -150,6 +151,7 @@ enum SrsCodecAudio | ||
| 150 | SrsCodecAudioReservedMP3_8kHz = 14, | 151 | SrsCodecAudioReservedMP3_8kHz = 14, |
| 151 | SrsCodecAudioReservedDeviceSpecificSound = 15, | 152 | SrsCodecAudioReservedDeviceSpecificSound = 15, |
| 152 | }; | 153 | }; |
| 154 | +std::string srs_codec_audio2str(SrsCodecAudio codec); | ||
| 153 | 155 | ||
| 154 | /** | 156 | /** |
| 155 | * the FLV/RTMP supported audio sample rate. | 157 | * the FLV/RTMP supported audio sample rate. |
| @@ -373,6 +375,21 @@ enum SrsAvcPayloadFormat | @@ -373,6 +375,21 @@ enum SrsAvcPayloadFormat | ||
| 373 | SrsAvcPayloadFormatIbmf, | 375 | SrsAvcPayloadFormatIbmf, |
| 374 | }; | 376 | }; |
| 375 | 377 | ||
| 378 | +// the profile = object_id + 1 | ||
| 379 | +// @see aac-mp4a-format-ISO_IEC_14496-3+2001.pdf, page 78, | ||
| 380 | +// Table 1. A.9 C MPEG-2 Audio profiles and MPEG-4 Audio object types | ||
| 381 | +// the valid object type: | ||
| 382 | +// AAC Main(ID == 0) | ||
| 383 | +// AAC LC(ID == 1) | ||
| 384 | +// AAC SSR(ID == 2) | ||
| 385 | +// AAC LTP(ID == 3) | ||
| 386 | +// the valid aac profile: | ||
| 387 | +// Main profile (ID == 1) | ||
| 388 | +// Low Complexity profile (LC) (ID == 2) | ||
| 389 | +// Scalable Sampling Rate profile (SSR) (ID == 3) | ||
| 390 | +// (reserved) (ID == 4) | ||
| 391 | +std::string srs_codec_aac_profile2str(u_int8_t aac_profile); | ||
| 392 | + | ||
| 376 | /** | 393 | /** |
| 377 | * the h264/avc and aac codec, for media stream. | 394 | * the h264/avc and aac codec, for media stream. |
| 378 | * | 395 | * |
| @@ -56,25 +56,6 @@ using namespace std; | @@ -56,25 +56,6 @@ using namespace std; | ||
| 56 | #define TS_AUDIO_AAC_PID 0x102 | 56 | #define TS_AUDIO_AAC_PID 0x102 |
| 57 | #define TS_AUDIO_MP3_PID 0x103 | 57 | #define TS_AUDIO_MP3_PID 0x103 |
| 58 | 58 | ||
| 59 | -/** | ||
| 60 | -* the public data, event HLS disable, others can use it. | ||
| 61 | -*/ | ||
| 62 | -// 0 = 5.5 kHz = 5512 Hz | ||
| 63 | -// 1 = 11 kHz = 11025 Hz | ||
| 64 | -// 2 = 22 kHz = 22050 Hz | ||
| 65 | -// 3 = 44 kHz = 44100 Hz | ||
| 66 | -int flv_sample_rates[] = {5512, 11025, 22050, 44100}; | ||
| 67 | - | ||
| 68 | -// the sample rates in the codec, | ||
| 69 | -// in the sequence header. | ||
| 70 | -int aac_sample_rates[] = | ||
| 71 | -{ | ||
| 72 | - 96000, 88200, 64000, 48000, | ||
| 73 | - 44100, 32000, 24000, 22050, | ||
| 74 | - 16000, 12000, 11025, 8000, | ||
| 75 | - 7350, 0, 0, 0 | ||
| 76 | -}; | ||
| 77 | - | ||
| 78 | string srs_ts_stream2string(SrsTsStream stream) | 59 | string srs_ts_stream2string(SrsTsStream stream) |
| 79 | { | 60 | { |
| 80 | switch (stream) { | 61 | switch (stream) { |
-
请 注册 或 登录 后发表评论