fix the global static instance error, use function to get server
正在显示
4 个修改的文件
包含
28 行增加
和
14 行删除
@@ -81,6 +81,8 @@ Annex A C CRC Decoder Model | @@ -81,6 +81,8 @@ Annex A C CRC Decoder Model | ||
81 | // Table 2-29 – Stream type assignments. page 66. | 81 | // Table 2-29 – Stream type assignments. page 66. |
82 | enum TSStreamType | 82 | enum TSStreamType |
83 | { | 83 | { |
84 | + // ITU-T | ISO/IEC Reserved | ||
85 | + TSStreamTypeReserved = 0x00, | ||
84 | /*defined by ffmpeg*/ | 86 | /*defined by ffmpeg*/ |
85 | TSStreamTypeVideoMpeg1 = 0x01, | 87 | TSStreamTypeVideoMpeg1 = 0x01, |
86 | TSStreamTypeVideoMpeg2 = 0x02, | 88 | TSStreamTypeVideoMpeg2 = 0x02, |
@@ -508,8 +510,12 @@ public: | @@ -508,8 +510,12 @@ public: | ||
508 | int demux(TSContext* ctx, TSPacket* pkt, u_int8_t* start, u_int8_t* last, u_int8_t*& p, TSMessage*& pmsg); | 510 | int demux(TSContext* ctx, TSPacket* pkt, u_int8_t* start, u_int8_t* last, u_int8_t*& p, TSMessage*& pmsg); |
509 | }; | 511 | }; |
510 | 512 | ||
513 | +/** | ||
514 | +* logic ts pid. | ||
515 | +*/ | ||
511 | struct TSPid | 516 | struct TSPid |
512 | { | 517 | { |
518 | + TSStreamType stream_type; | ||
513 | TSPidType type; | 519 | TSPidType type; |
514 | int16_t pid; | 520 | int16_t pid; |
515 | }; | 521 | }; |
@@ -526,6 +532,8 @@ public: | @@ -526,6 +532,8 @@ public: | ||
526 | 532 | ||
527 | // the type of pid. | 533 | // the type of pid. |
528 | TSPidType type; | 534 | TSPidType type; |
535 | + // the type of stream, codec type. | ||
536 | + TSStreamType stream_type; | ||
529 | 537 | ||
530 | // 2.4.3.7 Semantic definition of fields in PES packet. page 49 | 538 | // 2.4.3.7 Semantic definition of fields in PES packet. page 49 |
531 | // PES packet header size plus data size. | 539 | // PES packet header size plus data size. |
@@ -571,7 +579,7 @@ public: | @@ -571,7 +579,7 @@ public: | ||
571 | virtual ~TSContext(); | 579 | virtual ~TSContext(); |
572 | bool exists(int16_t pid); | 580 | bool exists(int16_t pid); |
573 | TSPid* get(int16_t pid); | 581 | TSPid* get(int16_t pid); |
574 | - void push(TSPidType type, int16_t pid); | 582 | + void push(TSStreamType stream_type, TSPidType type, int16_t pid); |
575 | 583 | ||
576 | TSMessage* get_msg(int16_t pid); | 584 | TSMessage* get_msg(int16_t pid); |
577 | void detach(TSMessage* msg); | 585 | void detach(TSMessage* msg); |
@@ -617,7 +625,7 @@ TSPid* TSContext::get(int16_t pid) | @@ -617,7 +625,7 @@ TSPid* TSContext::get(int16_t pid) | ||
617 | return NULL; | 625 | return NULL; |
618 | } | 626 | } |
619 | 627 | ||
620 | -void TSContext::push(TSPidType type, int16_t pid) | 628 | +void TSContext::push(TSStreamType stream_type, TSPidType type, int16_t pid) |
621 | { | 629 | { |
622 | if (exists(pid)) { | 630 | if (exists(pid)) { |
623 | return; | 631 | return; |
@@ -626,7 +634,7 @@ void TSContext::push(TSPidType type, int16_t pid) | @@ -626,7 +634,7 @@ void TSContext::push(TSPidType type, int16_t pid) | ||
626 | TSPid* p = new TSPid[pid_size + 1]; | 634 | TSPid* p = new TSPid[pid_size + 1]; |
627 | memcpy(p, pids, sizeof(TSPid) * pid_size); | 635 | memcpy(p, pids, sizeof(TSPid) * pid_size); |
628 | 636 | ||
629 | - p[pid_size] = (TSPid){type, pid}; | 637 | + p[pid_size] = (TSPid){stream_type, type, pid}; |
630 | pid_size++; | 638 | pid_size++; |
631 | 639 | ||
632 | srs_freepa(pids); | 640 | srs_freepa(pids); |
@@ -653,6 +661,7 @@ TSMessage::TSMessage() | @@ -653,6 +661,7 @@ TSMessage::TSMessage() | ||
653 | { | 661 | { |
654 | pid = 0; | 662 | pid = 0; |
655 | type = TSPidTypeReserved; | 663 | type = TSPidTypeReserved; |
664 | + stream_type = TSStreamTypeReserved; | ||
656 | stream_id = 0; | 665 | stream_id = 0; |
657 | packet_start_code_prefix = 0; | 666 | packet_start_code_prefix = 0; |
658 | PES_packet_length = 0; | 667 | PES_packet_length = 0; |
@@ -959,7 +968,7 @@ int TSPayloadPAT::demux(TSContext* ctx, TSPacket* pkt, u_int8_t* start, u_int8_t | @@ -959,7 +968,7 @@ int TSPayloadPAT::demux(TSContext* ctx, TSPacket* pkt, u_int8_t* start, u_int8_t | ||
959 | pp[0] = *p++; | 968 | pp[0] = *p++; |
960 | 969 | ||
961 | int16_t pid = programs[i] & 0x1FFF; | 970 | int16_t pid = programs[i] & 0x1FFF; |
962 | - ctx->push(TSPidTypePMT, pid); | 971 | + ctx->push(TSStreamTypeReserved, TSPidTypePMT, pid); |
963 | } | 972 | } |
964 | } | 973 | } |
965 | 974 | ||
@@ -1096,12 +1105,12 @@ int TSPayloadPMT::demux(TSContext* ctx, TSPacket* pkt, u_int8_t* start, u_int8_t | @@ -1096,12 +1105,12 @@ int TSPayloadPMT::demux(TSContext* ctx, TSPacket* pkt, u_int8_t* start, u_int8_t | ||
1096 | 1105 | ||
1097 | if (info->stream_type == TSStreamTypeVideoH264) { | 1106 | if (info->stream_type == TSStreamTypeVideoH264) { |
1098 | // TODO: support more video type. | 1107 | // TODO: support more video type. |
1099 | - ctx->push(TSPidTypeVideo, info->elementary_PID); | 1108 | + ctx->push((TSStreamType)info->stream_type, TSPidTypeVideo, info->elementary_PID); |
1100 | trace("ts+pmt add pid: %d, type: H264 video", info->elementary_PID); | 1109 | trace("ts+pmt add pid: %d, type: H264 video", info->elementary_PID); |
1101 | } else if (info->stream_type == TSStreamTypeAudioAAC) { | 1110 | } else if (info->stream_type == TSStreamTypeAudioAAC) { |
1102 | // TODO: support more audio type. | 1111 | // TODO: support more audio type. |
1103 | // see aac: 6.2 Audio Data Transport Stream, ADTS | 1112 | // see aac: 6.2 Audio Data Transport Stream, ADTS |
1104 | - ctx->push(TSPidTypeAudio, info->elementary_PID); | 1113 | + ctx->push((TSStreamType)info->stream_type, TSPidTypeAudio, info->elementary_PID); |
1105 | trace("ts+pmt add pid: %d, type: AAC audio", info->elementary_PID); | 1114 | trace("ts+pmt add pid: %d, type: AAC audio", info->elementary_PID); |
1106 | } else { | 1115 | } else { |
1107 | trace("ts+pmt ignore the stream type: %d", info->stream_type); | 1116 | trace("ts+pmt ignore the stream type: %d", info->stream_type); |
@@ -1406,6 +1415,7 @@ int TSPayloadPES::demux(TSContext* ctx, TSPacket* pkt, u_int8_t* start, u_int8_t | @@ -1406,6 +1415,7 @@ int TSPayloadPES::demux(TSContext* ctx, TSPacket* pkt, u_int8_t* start, u_int8_t | ||
1406 | TSMessage* msg = ctx->get_msg(pid->pid); | 1415 | TSMessage* msg = ctx->get_msg(pid->pid); |
1407 | 1416 | ||
1408 | msg->type = pid->type; | 1417 | msg->type = pid->type; |
1418 | + msg->stream_type = pid->stream_type; | ||
1409 | msg->stream_id = stream_id; | 1419 | msg->stream_id = stream_id; |
1410 | msg->packet_start_code_prefix = packet_start_code_prefix; | 1420 | msg->packet_start_code_prefix = packet_start_code_prefix; |
1411 | 1421 | ||
@@ -1615,7 +1625,7 @@ int TSHeader::demux(TSContext* ctx, TSPacket* pkt, u_int8_t* start, u_int8_t* la | @@ -1615,7 +1625,7 @@ int TSHeader::demux(TSContext* ctx, TSPacket* pkt, u_int8_t* start, u_int8_t* la | ||
1615 | transport_priority = (pid >> 13) & 0x01; | 1625 | transport_priority = (pid >> 13) & 0x01; |
1616 | pid &= 0x1FFF; | 1626 | pid &= 0x1FFF; |
1617 | 1627 | ||
1618 | - ctx->push(TSPidTypePAT, pid); | 1628 | + ctx->push(TSStreamTypeReserved, TSPidTypePAT, pid); |
1619 | 1629 | ||
1620 | continuity_counter = *p++; | 1630 | continuity_counter = *p++; |
1621 | 1631 |
@@ -171,6 +171,7 @@ SrsServer::SrsServer() | @@ -171,6 +171,7 @@ SrsServer::SrsServer() | ||
171 | { | 171 | { |
172 | signal_reload = false; | 172 | signal_reload = false; |
173 | 173 | ||
174 | + srs_assert(config); | ||
174 | config->subscribe(this); | 175 | config->subscribe(this); |
175 | } | 176 | } |
176 | 177 | ||
@@ -328,5 +329,8 @@ int SrsServer::on_reload_listen() | @@ -328,5 +329,8 @@ int SrsServer::on_reload_listen() | ||
328 | return listen(); | 329 | return listen(); |
329 | } | 330 | } |
330 | 331 | ||
331 | -SrsServer server; | ||
332 | - | 332 | +SrsServer* _server() |
333 | +{ | ||
334 | + static SrsServer server; | ||
335 | + return &server; | ||
336 | +} |
@@ -32,7 +32,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | @@ -32,7 +32,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
32 | void handler(int signo) | 32 | void handler(int signo) |
33 | { | 33 | { |
34 | srs_trace("get a signal, signo=%d", signo); | 34 | srs_trace("get a signal, signo=%d", signo); |
35 | - server.on_signal(signo); | 35 | + _server()->on_signal(signo); |
36 | } | 36 | } |
37 | 37 | ||
38 | int main(int argc, char** argv){ | 38 | int main(int argc, char** argv){ |
@@ -44,15 +44,15 @@ int main(int argc, char** argv){ | @@ -44,15 +44,15 @@ int main(int argc, char** argv){ | ||
44 | return ret; | 44 | return ret; |
45 | } | 45 | } |
46 | 46 | ||
47 | - if ((ret = server.initialize()) != ERROR_SUCCESS) { | 47 | + if ((ret = _server()->initialize()) != ERROR_SUCCESS) { |
48 | return ret; | 48 | return ret; |
49 | } | 49 | } |
50 | 50 | ||
51 | - if ((ret = server.listen()) != ERROR_SUCCESS) { | 51 | + if ((ret = _server()->listen()) != ERROR_SUCCESS) { |
52 | return ret; | 52 | return ret; |
53 | } | 53 | } |
54 | 54 | ||
55 | - if ((ret = server.cycle()) != ERROR_SUCCESS) { | 55 | + if ((ret = _server()->cycle()) != ERROR_SUCCESS) { |
56 | return ret; | 56 | return ret; |
57 | } | 57 | } |
58 | 58 |
-
请 注册 或 登录 后发表评论