fix the global static instance error, use function to get server

pull/133/head
winlin 11 years ago
parent c79372417d
commit d1e20dc866

@ -81,6 +81,8 @@ Annex A
// Table 2-29 Stream type assignments. page 66. // Table 2-29 Stream type assignments. page 66.
enum TSStreamType enum TSStreamType
{ {
// ITU-T | ISO/IEC Reserved
TSStreamTypeReserved = 0x00,
/*defined by ffmpeg*/ /*defined by ffmpeg*/
TSStreamTypeVideoMpeg1 = 0x01, TSStreamTypeVideoMpeg1 = 0x01,
TSStreamTypeVideoMpeg2 = 0x02, TSStreamTypeVideoMpeg2 = 0x02,
@ -508,8 +510,12 @@ public:
int demux(TSContext* ctx, TSPacket* pkt, u_int8_t* start, u_int8_t* last, u_int8_t*& p, TSMessage*& pmsg); int demux(TSContext* ctx, TSPacket* pkt, u_int8_t* start, u_int8_t* last, u_int8_t*& p, TSMessage*& pmsg);
}; };
/**
* logic ts pid.
*/
struct TSPid struct TSPid
{ {
TSStreamType stream_type;
TSPidType type; TSPidType type;
int16_t pid; int16_t pid;
}; };
@ -526,6 +532,8 @@ public:
// the type of pid. // the type of pid.
TSPidType type; TSPidType type;
// the type of stream, codec type.
TSStreamType stream_type;
// 2.4.3.7 Semantic definition of fields in PES packet. page 49 // 2.4.3.7 Semantic definition of fields in PES packet. page 49
// PES packet header size plus data size. // PES packet header size plus data size.
@ -571,7 +579,7 @@ public:
virtual ~TSContext(); virtual ~TSContext();
bool exists(int16_t pid); bool exists(int16_t pid);
TSPid* get(int16_t pid); TSPid* get(int16_t pid);
void push(TSPidType type, int16_t pid); void push(TSStreamType stream_type, TSPidType type, int16_t pid);
TSMessage* get_msg(int16_t pid); TSMessage* get_msg(int16_t pid);
void detach(TSMessage* msg); void detach(TSMessage* msg);
@ -617,7 +625,7 @@ TSPid* TSContext::get(int16_t pid)
return NULL; return NULL;
} }
void TSContext::push(TSPidType type, int16_t pid) void TSContext::push(TSStreamType stream_type, TSPidType type, int16_t pid)
{ {
if (exists(pid)) { if (exists(pid)) {
return; return;
@ -626,7 +634,7 @@ void TSContext::push(TSPidType type, int16_t pid)
TSPid* p = new TSPid[pid_size + 1]; TSPid* p = new TSPid[pid_size + 1];
memcpy(p, pids, sizeof(TSPid) * pid_size); memcpy(p, pids, sizeof(TSPid) * pid_size);
p[pid_size] = (TSPid){type, pid}; p[pid_size] = (TSPid){stream_type, type, pid};
pid_size++; pid_size++;
srs_freepa(pids); srs_freepa(pids);
@ -653,6 +661,7 @@ TSMessage::TSMessage()
{ {
pid = 0; pid = 0;
type = TSPidTypeReserved; type = TSPidTypeReserved;
stream_type = TSStreamTypeReserved;
stream_id = 0; stream_id = 0;
packet_start_code_prefix = 0; packet_start_code_prefix = 0;
PES_packet_length = 0; PES_packet_length = 0;
@ -959,7 +968,7 @@ int TSPayloadPAT::demux(TSContext* ctx, TSPacket* pkt, u_int8_t* start, u_int8_t
pp[0] = *p++; pp[0] = *p++;
int16_t pid = programs[i] & 0x1FFF; int16_t pid = programs[i] & 0x1FFF;
ctx->push(TSPidTypePMT, pid); ctx->push(TSStreamTypeReserved, TSPidTypePMT, pid);
} }
} }
@ -1096,12 +1105,12 @@ int TSPayloadPMT::demux(TSContext* ctx, TSPacket* pkt, u_int8_t* start, u_int8_t
if (info->stream_type == TSStreamTypeVideoH264) { if (info->stream_type == TSStreamTypeVideoH264) {
// TODO: support more video type. // TODO: support more video type.
ctx->push(TSPidTypeVideo, info->elementary_PID); ctx->push((TSStreamType)info->stream_type, TSPidTypeVideo, info->elementary_PID);
trace("ts+pmt add pid: %d, type: H264 video", info->elementary_PID); trace("ts+pmt add pid: %d, type: H264 video", info->elementary_PID);
} else if (info->stream_type == TSStreamTypeAudioAAC) { } else if (info->stream_type == TSStreamTypeAudioAAC) {
// TODO: support more audio type. // TODO: support more audio type.
// see aac: 6.2 Audio Data Transport Stream, ADTS // see aac: 6.2 Audio Data Transport Stream, ADTS
ctx->push(TSPidTypeAudio, info->elementary_PID); ctx->push((TSStreamType)info->stream_type, TSPidTypeAudio, info->elementary_PID);
trace("ts+pmt add pid: %d, type: AAC audio", info->elementary_PID); trace("ts+pmt add pid: %d, type: AAC audio", info->elementary_PID);
} else { } else {
trace("ts+pmt ignore the stream type: %d", info->stream_type); 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
TSMessage* msg = ctx->get_msg(pid->pid); TSMessage* msg = ctx->get_msg(pid->pid);
msg->type = pid->type; msg->type = pid->type;
msg->stream_type = pid->stream_type;
msg->stream_id = stream_id; msg->stream_id = stream_id;
msg->packet_start_code_prefix = packet_start_code_prefix; msg->packet_start_code_prefix = packet_start_code_prefix;
@ -1615,7 +1625,7 @@ int TSHeader::demux(TSContext* ctx, TSPacket* pkt, u_int8_t* start, u_int8_t* la
transport_priority = (pid >> 13) & 0x01; transport_priority = (pid >> 13) & 0x01;
pid &= 0x1FFF; pid &= 0x1FFF;
ctx->push(TSPidTypePAT, pid); ctx->push(TSStreamTypeReserved, TSPidTypePAT, pid);
continuity_counter = *p++; continuity_counter = *p++;

@ -171,6 +171,7 @@ SrsServer::SrsServer()
{ {
signal_reload = false; signal_reload = false;
srs_assert(config);
config->subscribe(this); config->subscribe(this);
} }
@ -328,5 +329,8 @@ int SrsServer::on_reload_listen()
return listen(); return listen();
} }
SrsServer server; SrsServer* _server()
{
static SrsServer server;
return &server;
}

@ -89,6 +89,6 @@ public:
virtual int on_reload_listen(); virtual int on_reload_listen();
}; };
extern SrsServer server; SrsServer* _server();
#endif #endif

@ -32,7 +32,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
void handler(int signo) void handler(int signo)
{ {
srs_trace("get a signal, signo=%d", signo); srs_trace("get a signal, signo=%d", signo);
server.on_signal(signo); _server()->on_signal(signo);
} }
int main(int argc, char** argv){ int main(int argc, char** argv){
@ -44,15 +44,15 @@ int main(int argc, char** argv){
return ret; return ret;
} }
if ((ret = server.initialize()) != ERROR_SUCCESS) { if ((ret = _server()->initialize()) != ERROR_SUCCESS) {
return ret; return ret;
} }
if ((ret = server.listen()) != ERROR_SUCCESS) { if ((ret = _server()->listen()) != ERROR_SUCCESS) {
return ret; return ret;
} }
if ((ret = server.cycle()) != ERROR_SUCCESS) { if ((ret = _server()->cycle()) != ERROR_SUCCESS) {
return ret; return ret;
} }

Loading…
Cancel
Save