SrsFastLog::~SrsFastLog() { srs_freepa(log_data); if (fd > 0) { ::close(fd); fd = -1; } if (_srs_config) { _srs_config->unsubscribe(this); } }
int SrsSource::on_meta_data(SrsCommonMessage* msg, SrsOnMetaDataPacket* metadata) { int ret = ERROR_SUCCESS; #ifdef SRS_HLS if ((ret = hls->on_meta_data(metadata)) != ERROR_SUCCESS) { srs_error("hls process onMetaData message failed. ret=%d", ret); return ret; } #endif metadata->metadata->set("server", new SrsAmf0String( RTMP_SIG_SRS_KEY" "RTMP_SIG_SRS_VERSION" ("RTMP_SIG_SRS_URL_SHORT")")); SrsAmf0Any* prop = NULL; if ((prop = metadata->metadata->get_property("audiosamplerate")) != NULL) { if (prop->is_number()) { sample_rate = (int)(srs_amf0_convert<SrsAmf0Number>(prop)->value); } } if ((prop = metadata->metadata->get_property("framerate")) != NULL) { if (prop->is_number()) { frame_rate = (int)(srs_amf0_convert<SrsAmf0Number>(prop)->value); } } // encode the metadata to payload int size = metadata->get_payload_length(); if (size <= 0) { srs_warn("ignore the invalid metadata. size=%d", size); return ret; } srs_verbose("get metadata size success."); char* payload = new char[size]; memset(payload, 0, size); if ((ret = metadata->encode(size, payload)) != ERROR_SUCCESS) { srs_error("encode metadata error. ret=%d", ret); srs_freepa(payload); return ret; } srs_verbose("encode metadata success."); // create a shared ptr message. srs_freep(cache_metadata); cache_metadata = new SrsSharedPtrMessage(); // dump message to shared ptr message. if ((ret = cache_metadata->initialize(msg, payload, size)) != ERROR_SUCCESS) { srs_error("initialize the cache metadata failed. ret=%d", ret); return ret; } srs_verbose("initialize shared ptr metadata success."); // copy to all consumer if (true) { std::vector<SrsConsumer*>::iterator it; for (it = consumers.begin(); it != consumers.end(); ++it) { SrsConsumer* consumer = *it; if ((ret = consumer->enqueue(cache_metadata->copy(), sample_rate, frame_rate)) != ERROR_SUCCESS) { srs_error("dispatch the metadata failed. ret=%d", ret); return ret; } } srs_trace("dispatch metadata success."); } // copy to all forwarders if (true) { std::vector<SrsForwarder*>::iterator it; for (it = forwarders.begin(); it != forwarders.end(); ++it) { SrsForwarder* forwarder = *it; if ((ret = forwarder->on_meta_data(cache_metadata->copy())) != ERROR_SUCCESS) { srs_error("forwarder process onMetaData message failed. ret=%d", ret); return ret; } } } return ret; }