├── .gitattributes ├── README.md └── c++ ├── .DS_Store ├── Solution ├── .DS_Store ├── .vs │ └── Live │ │ └── v14 │ │ └── .suo └── Live.sln ├── Src ├── .DS_Store ├── Makefile ├── live_codec │ ├── CodecInterface.h │ ├── DecodeFactory.cpp │ ├── DecodeFactory.h │ ├── Makefile │ ├── ReadMe.txt │ ├── live_codec.vcxproj │ └── live_codec.vcxproj.filters ├── live_codec_nal │ ├── Makefile │ ├── NalDemuxer.cpp │ ├── NalDemuxer.h │ ├── NalFactory.cpp │ ├── NalFactory.h │ ├── live_codec_nal.cpp │ ├── live_codec_nal.def │ ├── live_codec_nal.vcxproj │ └── live_codec_nal.vcxproj.filters ├── live_comet │ ├── Caller.cpp │ ├── Caller.h │ ├── Channel.cpp │ ├── Channel.h │ ├── Constant.h │ ├── Engine.cpp │ ├── Engine.h │ ├── Makefile │ ├── OneClient.cpp │ ├── OneClient.h │ ├── QuickList.h │ ├── ReadMe.txt │ ├── Subscriber.cpp │ ├── Subscriber.h │ ├── live_comet.cpp │ ├── live_comet.vcxproj │ ├── live_comet.vcxproj.filters │ └── strings.h ├── live_common │ ├── BitStream.cpp │ ├── BitStream.h │ ├── Byte.cpp │ ├── Byte.h │ ├── ByteStream.cpp │ ├── ByteStream.h │ ├── Makefile │ ├── Profile.cpp │ ├── Profile.h │ ├── ReadMe.txt │ ├── ShareBlk.cpp │ ├── ShareBlk.h │ ├── SmartArr.h │ ├── SmartBlk.cpp │ ├── SmartBlk.h │ ├── SmartErr.cpp │ ├── SmartErr.h │ ├── SmartHdr.h │ ├── SmartLck.h │ ├── SmartNal.h │ ├── SmartPtr.h │ ├── SmartQue.h │ ├── SmartRet.h │ ├── copy_x64.bat │ ├── copy_x86.bat │ ├── file.cpp │ ├── file.h │ ├── ierror.h │ ├── live_common.vcxproj │ ├── net.cpp │ ├── net.h │ ├── os.h │ ├── wingetopt.c │ ├── wingetopt.h │ ├── xaid.h │ ├── xchar.h │ ├── xcritic.h │ ├── xevent.h │ ├── xexception.h │ ├── xmember.h │ ├── xsemaphore.h │ ├── xstring.h │ ├── xsystem.h │ ├── xthread.h │ ├── xutils.cpp │ └── xutils.h ├── live_gateway │ ├── Channel.cpp │ ├── Channel.h │ ├── ChannelFactory.cpp │ ├── ChannelFactory.h │ ├── CodecFactory.cpp │ ├── CodecFactory.h │ ├── EventBase.cpp │ ├── EventBase.h │ ├── GatewayClient.cpp │ ├── GatewayClient.h │ ├── GatewayServer.cpp │ ├── GatewayServer.h │ ├── Makefile │ ├── ReadMe.txt │ ├── SinkFactory.cpp │ ├── SinkFactory.h │ ├── SourceFactory.cpp │ ├── SourceFactory.h │ ├── SystemInfo.cpp │ ├── SystemInfo.h │ ├── live_gateway.cpp │ ├── live_gateway.vcxproj │ └── live_gateway.vcxproj.filters ├── live_input │ ├── ForwardProxy.cpp │ ├── ForwardProxy.h │ ├── InputFactory.cpp │ ├── InputFactory.h │ ├── Makefile │ ├── ReadMe.txt │ ├── SourceInterface.h │ ├── live_input.vcxproj │ └── live_input.vcxproj.filters ├── live_libevent │ ├── arc4random.c │ ├── buffer.c │ ├── buffer_iocp.c │ ├── bufferevent-internal.h │ ├── bufferevent.c │ ├── bufferevent_async.c │ ├── bufferevent_filter.c │ ├── bufferevent_pair.c │ ├── bufferevent_ratelim.c │ ├── bufferevent_sock.c │ ├── changelist-internal.h │ ├── defer-internal.h │ ├── evbuffer-internal.h │ ├── evdns.c │ ├── evdns.h │ ├── event-internal.h │ ├── event.c │ ├── event.h │ ├── event2 │ │ ├── buffer.h │ │ ├── buffer_compat.h │ │ ├── bufferevent.h │ │ ├── bufferevent_compat.h │ │ ├── bufferevent_ssl.h │ │ ├── bufferevent_struct.h │ │ ├── dns.h │ │ ├── dns_compat.h │ │ ├── dns_struct.h │ │ ├── event-config.h │ │ ├── event.h │ │ ├── event_compat.h │ │ ├── event_struct.h │ │ ├── http.h │ │ ├── http_compat.h │ │ ├── http_struct.h │ │ ├── keyvalq_struct.h │ │ ├── listener.h │ │ ├── rpc.h │ │ ├── rpc_compat.h │ │ ├── rpc_struct.h │ │ ├── tag.h │ │ ├── tag_compat.h │ │ ├── thread.h │ │ └── util.h │ ├── event_iocp.c │ ├── event_tagging.c │ ├── evmap-internal.h │ ├── evmap.c │ ├── evrpc-internal.h │ ├── evrpc.c │ ├── evrpc.h │ ├── evsignal-internal.h │ ├── evthread-internal.h │ ├── evthread.c │ ├── evthread_win32.c │ ├── evutil.c │ ├── evutil.h │ ├── evutil_rand.c │ ├── ht-internal.h │ ├── http-internal.h │ ├── http.c │ ├── iocp-internal.h │ ├── ipv6-internal.h │ ├── listener.c │ ├── live_libevent.def │ ├── live_libevent.vcxproj │ ├── live_libevent.vcxproj.filters │ ├── log-internal.h │ ├── log.c │ ├── minheap-internal.h │ ├── mm-internal.h │ ├── ratelim-internal.h │ ├── signal.c │ ├── strlcpy-internal.h │ ├── strlcpy.c │ ├── sys │ │ └── queue.h │ ├── util-internal.h │ └── win32select.c ├── live_literal │ ├── MD5CodeArith.cpp │ ├── MD5CodeArith.h │ ├── Makefile │ ├── Markup.cpp │ ├── Markup.h │ ├── ReadMe.txt │ ├── SHA1CodeArith.cpp │ ├── SHA1CodeArith.h │ ├── copy_x64.bat │ ├── copy_x86.bat │ ├── dllmain.cpp │ ├── json │ │ ├── assertions.h │ │ ├── autolink.h │ │ ├── config.h │ │ ├── features.h │ │ ├── forwards.h │ │ ├── json.h │ │ ├── json_batchallocator.h │ │ ├── json_internalarray.inl │ │ ├── json_internalmap.inl │ │ ├── json_reader.cpp │ │ ├── json_tool.h │ │ ├── json_value.cpp │ │ ├── json_valueiterator.inl │ │ ├── json_writer.cpp │ │ ├── reader.h │ │ ├── value.h │ │ └── writer.h │ ├── live_literal.vcxproj │ ├── live_literal.vcxproj.filters │ ├── pugixml │ │ ├── pugiconfig.hpp │ │ ├── pugixml.cpp │ │ └── pugixml.hpp │ └── tinyxml │ │ ├── tinystr.cpp │ │ ├── tinystr.h │ │ ├── tinyxml.cpp │ │ ├── tinyxml.h │ │ ├── tinyxmlerror.cpp │ │ └── tinyxmlparser.cpp ├── live_logging │ ├── ConsoleUI.cpp │ ├── ConsoleUI.h │ ├── ConsoleUIImpl.cpp │ ├── ConsoleUIImpl.h │ ├── LocalLogWriter.cpp │ ├── LocalLogWriter.h │ ├── LogWriter.cpp │ ├── LogWriter.h │ ├── Makefile │ ├── ModuleVersion.cpp │ ├── ModuleVersion.h │ ├── PipeWriter.cpp │ ├── PipeWriter.h │ ├── ReadMe.txt │ ├── SockWriter.cpp │ ├── SockWriter.h │ ├── Writelog.cpp │ ├── Writelog.h │ ├── copy_x64.bat │ ├── copy_x86.bat │ ├── dllmain.cpp │ └── live_logging.vcxproj ├── live_media │ ├── AACUtility.cpp │ ├── AACUtility.h │ ├── AVCConfig.cpp │ ├── AVCConfig.h │ ├── BitReader.cpp │ ├── BitReader.h │ ├── BitWriter.cpp │ ├── BitWriter.h │ ├── H264Utility.cpp │ ├── H264Utility.h │ ├── Makefile │ ├── ReadMe.txt │ ├── copy_x64.bat │ ├── copy_x86.bat │ ├── dllmain.cpp │ ├── h264.cpp │ ├── h264.h │ ├── h264_slice.cpp │ ├── h264_sps.cpp │ ├── live_media.vcxproj │ └── vlc_bits.h ├── live_network │ ├── HttpClient.cpp │ ├── HttpClient.h │ ├── Makefile │ ├── ReadMe.txt │ ├── copy_x64.bat │ ├── copy_x86.bat │ ├── dllmain.cpp │ ├── live_network.vcxproj │ └── live_network.vcxproj.filters ├── live_output │ ├── Makefile │ ├── OutputFactory.cpp │ ├── OutputFactory.h │ ├── ReadMe.txt │ ├── SinkInterface.h │ ├── live_output.vcxproj │ └── live_output.vcxproj.filters ├── live_rtmp │ ├── CommandMessage.cpp │ ├── CommandMessage.h │ ├── ComplexHandshake.cpp │ ├── ComplexHandshake.h │ ├── ControlMessage.cpp │ ├── ControlMessage.h │ ├── DataMessage.cpp │ ├── DataMessage.h │ ├── HandshakeBytes.cpp │ ├── HandshakeBytes.h │ ├── Makefile │ ├── ProtocolAmf0.cpp │ ├── ProtocolAmf0.h │ ├── ReadMe.txt │ ├── RtmpChunk.cpp │ ├── RtmpChunk.h │ ├── RtmpConstants.h │ ├── RtmpHandshake.cpp │ ├── RtmpHandshake.h │ ├── RtmpMessage.cpp │ ├── RtmpMessage.h │ ├── UserControlMessage.cpp │ ├── UserControlMessage.h │ ├── live_rtmp.vcxproj │ └── live_rtmp.vcxproj.filters ├── live_rtmp2 │ ├── Makefile │ ├── Metadata.cpp │ ├── Metadata.h │ ├── Publisher.cpp │ ├── Publisher.h │ ├── ReadMe.txt │ ├── Rtmp2Publisher.cpp │ ├── Rtmp2Publisher.h │ ├── amf.c │ ├── amf.h │ ├── bytes.h │ ├── copy_x64.bat │ ├── copy_x86.bat │ ├── dh.h │ ├── dhgroups.h │ ├── dllmain.cpp │ ├── handshake.h │ ├── http.h │ ├── live_rtmp2.def │ ├── live_rtmp2.vcxproj │ ├── live_rtmp2.vcxproj.filters │ ├── log.c │ ├── log.h │ ├── parseurl.c │ ├── rtmp.c │ ├── rtmp.h │ └── rtmp_sys.h ├── live_sink_file │ ├── FileFactory.cpp │ ├── FileFactory.h │ ├── FileWriter.cpp │ ├── FileWriter.h │ ├── Makefile │ ├── live_sink_file.cpp │ ├── live_sink_file.def │ ├── live_sink_file.vcxproj │ └── live_sink_file.vcxproj.filters ├── live_sink_flv │ ├── FlvFactory.cpp │ ├── FlvFactory.h │ ├── FlvWriter.cpp │ ├── FlvWriter.h │ ├── Makefile │ ├── live_sink_flv.cpp │ ├── live_sink_flv.def │ ├── live_sink_flv.vcxproj │ └── live_sink_flv.vcxproj.filters ├── live_sink_raw │ ├── ClientProxy.cpp │ ├── ClientProxy.h │ ├── Makefile │ ├── RawFactory.cpp │ ├── RawFactory.h │ ├── RawWriter.cpp │ ├── RawWriter.h │ ├── ReadMe.txt │ ├── dllmain.cpp │ ├── live_sink_raw.cpp │ ├── live_sink_raw.def │ ├── live_sink_raw.vcxproj │ └── live_sink_raw.vcxproj.filters ├── live_source_file │ ├── FileFactory.cpp │ ├── FileFactory.h │ ├── FileSource.cpp │ ├── FileSource.h │ ├── Makefile │ ├── ReadMe.txt │ ├── dllmain.cpp │ ├── live_source_file.cpp │ ├── live_source_file.def │ ├── live_source_file.vcxproj │ └── live_source_file.vcxproj.filters ├── live_source_hxht │ ├── HxhtFactory.cpp │ ├── HxhtFactory.h │ ├── HxhtReader.cpp │ ├── HxhtReader.h │ ├── HxhtServer.cpp │ ├── HxhtServer.h │ ├── Makefile │ ├── ReadMe.txt │ ├── dllmain.cpp │ ├── live_source_hxht.cpp │ ├── live_source_hxht.def │ ├── live_source_hxht.vcxproj │ └── live_source_hxht.vcxproj.filters ├── live_source_onvif │ ├── Makefile │ ├── OnvifControl.cpp │ ├── OnvifControl.h │ ├── OnvifFactory.cpp │ ├── OnvifFactory.h │ ├── OnvifPattern.cpp │ ├── OnvifPattern.h │ ├── OnvifSource.cpp │ ├── OnvifSource.h │ ├── RtpAacDemuxer.cpp │ ├── RtpAacDemuxer.h │ ├── RtpBaseDemuxer.cpp │ ├── RtpBaseDemuxer.h │ ├── RtpH264Demuxer.cpp │ ├── RtpH264Demuxer.h │ ├── RtspClient.cpp │ ├── RtspClient.h │ ├── SdpParser.cpp │ ├── SdpParser.h │ ├── freesdp │ │ ├── common.c │ │ ├── errorlist.c │ │ ├── formatter.c │ │ ├── formatterpriv.h │ │ ├── freesdp │ │ │ ├── common.h │ │ │ ├── config.h │ │ │ ├── formatter.h │ │ │ ├── freesdp.h │ │ │ └── parser.h │ │ ├── parser.c │ │ ├── parserpriv.h │ │ └── priv.h │ ├── live_source_onvif.cpp │ ├── live_source_onvif.def │ ├── live_source_onvif.vcxproj │ └── live_source_onvif.vcxproj.filters ├── live_source_rtmp │ ├── Makefile │ ├── ReadMe.txt │ ├── RtmpActor.h │ ├── RtmpConnection.cpp │ ├── RtmpConnection.h │ ├── RtmpFactory.cpp │ ├── RtmpFactory.h │ ├── RtmpPlayer.cpp │ ├── RtmpPlayer.h │ ├── RtmpPublisher.cpp │ ├── RtmpPublisher.h │ ├── dllmain.cpp │ ├── live_source_rtmp.cpp │ ├── live_source_rtmp.def │ ├── live_source_rtmp.vcxproj │ ├── live_source_rtmp.vcxproj.filters │ └── live_source_rtmp.vcxproj.user ├── live_source_vod │ ├── Makefile │ ├── ReadMe.txt │ ├── VodFactory.cpp │ ├── VodFactory.h │ ├── dllmain.cpp │ ├── live_source_vod.cpp │ ├── live_source_vod.def │ ├── live_source_vod.vcxproj │ └── live_source_vod.vcxproj.filters └── live_vpf │ ├── FileReader.cpp │ ├── FileReader.h │ ├── HttpReader.cpp │ ├── HttpReader.h │ ├── IOAccess.h │ ├── Makefile │ ├── ReadMe.txt │ ├── VpfReader.cpp │ ├── VpfReader.h │ ├── VpfWriter.cpp │ ├── VpfWriter.h │ ├── copy_x64.bat │ ├── copy_x86.bat │ ├── dllmain.cpp │ ├── live_vpf.vcxproj │ └── live_vpf.vcxproj.filters ├── linux ├── .DS_Store ├── inc │ ├── .DS_Store │ ├── event2 │ │ ├── buffer.h │ │ ├── buffer_compat.h │ │ ├── bufferevent.h │ │ ├── bufferevent_compat.h │ │ ├── bufferevent_ssl.h │ │ ├── bufferevent_struct.h │ │ ├── dns.h │ │ ├── dns_compat.h │ │ ├── dns_struct.h │ │ ├── event-config.h │ │ ├── event.h │ │ ├── event_compat.h │ │ ├── event_struct.h │ │ ├── http.h │ │ ├── http_compat.h │ │ ├── http_struct.h │ │ ├── keyvalq_struct.h │ │ ├── listener.h │ │ ├── rpc.h │ │ ├── rpc_compat.h │ │ ├── rpc_struct.h │ │ ├── tag.h │ │ ├── tag_compat.h │ │ ├── thread.h │ │ └── util.h │ ├── libz │ │ ├── zconf.h │ │ └── zlib.h │ └── openssl │ │ ├── aes.h │ │ ├── asn1.h │ │ ├── asn1_mac.h │ │ ├── asn1t.h │ │ ├── bio.h │ │ ├── blowfish.h │ │ ├── bn.h │ │ ├── buffer.h │ │ ├── camellia.h │ │ ├── cast.h │ │ ├── cmac.h │ │ ├── cms.h │ │ ├── comp.h │ │ ├── conf.h │ │ ├── conf_api.h │ │ ├── crypto.h │ │ ├── des.h │ │ ├── des_old.h │ │ ├── dh.h │ │ ├── dsa.h │ │ ├── dso.h │ │ ├── dtls1.h │ │ ├── e_os2.h │ │ ├── ebcdic.h │ │ ├── ec.h │ │ ├── ecdh.h │ │ ├── ecdsa.h │ │ ├── engine.h │ │ ├── err.h │ │ ├── evp.h │ │ ├── hmac.h │ │ ├── idea.h │ │ ├── krb5_asn.h │ │ ├── kssl.h │ │ ├── lhash.h │ │ ├── md4.h │ │ ├── md5.h │ │ ├── mdc2.h │ │ ├── modes.h │ │ ├── obj_mac.h │ │ ├── objects.h │ │ ├── ocsp.h │ │ ├── opensslconf.h │ │ ├── opensslv.h │ │ ├── ossl_typ.h │ │ ├── pem.h │ │ ├── pem2.h │ │ ├── pkcs12.h │ │ ├── pkcs7.h │ │ ├── pqueue.h │ │ ├── rand.h │ │ ├── rc2.h │ │ ├── rc4.h │ │ ├── ripemd.h │ │ ├── rsa.h │ │ ├── safestack.h │ │ ├── seed.h │ │ ├── sha.h │ │ ├── srp.h │ │ ├── srtp.h │ │ ├── ssl.h │ │ ├── ssl2.h │ │ ├── ssl23.h │ │ ├── ssl3.h │ │ ├── stack.h │ │ ├── symhacks.h │ │ ├── tls1.h │ │ ├── ts.h │ │ ├── txt_db.h │ │ ├── ui.h │ │ ├── ui_compat.h │ │ ├── whrlpool.h │ │ ├── x509.h │ │ ├── x509_vfy.h │ │ └── x509v3.h └── lib │ ├── libcrypto.a │ ├── libevent.a │ ├── libevent_core.a │ ├── libevent_extra.a │ ├── libevent_pthreads.a │ ├── libssl.a │ └── libz.a └── x64 ├── inc ├── event2 │ ├── buffer.h │ ├── buffer_compat.h │ ├── bufferevent.h │ ├── bufferevent_compat.h │ ├── bufferevent_ssl.h │ ├── bufferevent_struct.h │ ├── dns.h │ ├── dns_compat.h │ ├── dns_struct.h │ ├── event-config.h │ ├── event.h │ ├── event_compat.h │ ├── event_struct.h │ ├── http.h │ ├── http_compat.h │ ├── http_struct.h │ ├── keyvalq_struct.h │ ├── listener.h │ ├── rpc.h │ ├── rpc_compat.h │ ├── rpc_struct.h │ ├── tag.h │ ├── tag_compat.h │ ├── thread.h │ └── util.h ├── libz │ ├── tree.h │ ├── zconf.h │ └── zlib.h └── openssl │ ├── aes.h │ ├── asn1.h │ ├── asn1_mac.h │ ├── asn1t.h │ ├── bio.h │ ├── blowfish.h │ ├── bn.h │ ├── buffer.h │ ├── camellia.h │ ├── cast.h │ ├── cmac.h │ ├── cms.h │ ├── comp.h │ ├── conf.h │ ├── conf_api.h │ ├── crypto.h │ ├── des.h │ ├── des_old.h │ ├── dh.h │ ├── dsa.h │ ├── dso.h │ ├── dtls1.h │ ├── e_os2.h │ ├── ebcdic.h │ ├── ec.h │ ├── ecdh.h │ ├── ecdsa.h │ ├── engine.h │ ├── err.h │ ├── evp.h │ ├── hmac.h │ ├── idea.h │ ├── krb5_asn.h │ ├── kssl.h │ ├── lhash.h │ ├── md4.h │ ├── md5.h │ ├── mdc2.h │ ├── modes.h │ ├── obj_mac.h │ ├── objects.h │ ├── ocsp.h │ ├── opensslconf.h │ ├── opensslv.h │ ├── ossl_typ.h │ ├── pem.h │ ├── pem2.h │ ├── pkcs12.h │ ├── pkcs7.h │ ├── pqueue.h │ ├── rand.h │ ├── rc2.h │ ├── rc4.h │ ├── ripemd.h │ ├── rsa.h │ ├── safestack.h │ ├── seed.h │ ├── sha.h │ ├── srp.h │ ├── srtp.h │ ├── ssl.h │ ├── ssl2.h │ ├── ssl23.h │ ├── ssl3.h │ ├── stack.h │ ├── symhacks.h │ ├── tls1.h │ ├── ts.h │ ├── txt_db.h │ ├── ui.h │ ├── ui_compat.h │ ├── whrlpool.h │ ├── x509.h │ ├── x509_vfy.h │ └── x509v3.h └── lib ├── libeay32.lib ├── libevent.lib ├── libevent_core.lib ├── libevent_extras.lib ├── ssleay32.lib └── zlibstat.lib /.gitattributes: -------------------------------------------------------------------------------- 1 | *.* linguist-language=C++ 2 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # live 2 | 3 | > 基于libevent的媒体转发服务器 4 | 5 | * live_gateway 为流媒体转发服务器主程序,采用插件化方式支持rtmp以及国内平安城市最大供应商(接触过的人都知道)的直播流拉取 6 | * live_comet 为一个http转发请求服务器,实现从内网到内网的请求,可以用于一些调试场合,比如在你的android设备主机上植入comet设备端,当调试时可以通过comet直接访问android的的shell命令或者文件拉取 7 | 8 | * live_gateway采用插件结构,支持网关输入(source)、解编码(codec)、输出(sink)三个插件类型,通过编写相应的插件,让网关具有特定的功能。 9 | 已包含如下插件: 10 | * live_source_file 文件输入(支持对录制的原始码流重新放入到网关中作为输入使用,一般测试场景下会用到) 11 | * live_source_hxht HXHT插入插件(平安城市一个供应商) 12 | * live_source_onvif Onvif输入插件(支持Onvif摄像头输入) 13 | * live_source_rtmp Rtmp输入插件(一般可作为移动终端rtmp推流输入使用) 14 | * live_codec_nal AVC/AAC帧数据重定向编码插件 15 | * live_sink_file 点播输出插件(直接将本地文件通过http输出,与网关本身无关) 16 | * live_sink_flv Flv输出插件(将avc/aac编码为http/flv输出,可使用flash播放器或者ijkplayer移动播放播放网关流) 17 | * live_sink_raw 原始码流输出插件(将网关从源输入的信号原样输出,该格式的文件可供live_source_file再次使用,一般用于网关信号录制使用) 18 | 19 | * 工程编译: 20 | 支持Widnows x64和Centos两种平台: 21 | * windows:使用visual studio 2015打开Solution/live.sln即可编译,生成结果位于c++/x64/bin下; 22 | * linux:未使用configure,进入Src目录下执行make,生成文件位于gateway/gateway下,插件位于gateway/Plugins下; 23 | 24 | > 如有任何问题,欢迎联系yunsean@163.com 25 | -------------------------------------------------------------------------------- /c++/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yunsean/live/653fda0c4e444a94a4c8693a913faf92d356f595/c++/.DS_Store -------------------------------------------------------------------------------- /c++/Solution/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yunsean/live/653fda0c4e444a94a4c8693a913faf92d356f595/c++/Solution/.DS_Store -------------------------------------------------------------------------------- /c++/Solution/.vs/Live/v14/.suo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yunsean/live/653fda0c4e444a94a4c8693a913faf92d356f595/c++/Solution/.vs/Live/v14/.suo -------------------------------------------------------------------------------- /c++/Src/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yunsean/live/653fda0c4e444a94a4c8693a913faf92d356f595/c++/Src/.DS_Store -------------------------------------------------------------------------------- /c++/Src/Makefile: -------------------------------------------------------------------------------- 1 | SUBDIRS = live_common live_logging live_literal live_media live_input live_output live_codec live_vpf live_network live_rtmp live_rtmp2 2 | SUBDIRS += live_source_file live_source_onvif live_source_hxht live_source_rtmp live_sink_file live_sink_flv live_codec_nal 3 | SUBDIRS += live_comet live_gateway 4 | 5 | # 需要排除的目录 6 | exclude_dirs := include bin Debug Release log live_libevent live_demo 7 | # 取得当前子目录深度为1的所有目录名称 8 | dirs := $(shell find . -maxdepth 1 -type d) 9 | dirs := $(basename $(patsubst ./%,%,$(dirs))) 10 | dirs := $(filter-out $(exclude_dirs),$(dirs)) 11 | # 避免clean子目录操作同名,加上_clean_前缀 12 | clean_dirs := $(addprefix _clean_,SUBDIRS ) 13 | 14 | SUBDIRS := $(SUBDIRS) 15 | all:subdirs 16 | subdirs: 17 | for n in $(SUBDIRS);\ 18 | do $(MAKE) -C $$n || exit 1 ; \ 19 | done ; 20 | # ./live_gateway/gateway 21 | 22 | clean: 23 | for n in $(SUBDIRS); \ 24 | do $(MAKE) -C $$n clean; \ 25 | done 26 | -------------------------------------------------------------------------------- /c++/Src/live_codec/DecodeFactory.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yunsean/live/653fda0c4e444a94a4c8693a913faf92d356f595/c++/Src/live_codec/DecodeFactory.cpp -------------------------------------------------------------------------------- /c++/Src/live_codec/DecodeFactory.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include "SmartPtr.h" 7 | #include "SmartHdr.h" 8 | #include "xstring.h" 9 | #include "CodecInterface.h" 10 | 11 | namespace Json { 12 | class Value; 13 | } 14 | class CDecodeFactory { 15 | public: 16 | CDecodeFactory(); 17 | ~CDecodeFactory(); 18 | 19 | public: 20 | static CDecodeFactory& singleton(); 21 | 22 | public: 23 | bool initialize(bool usePlugin = true); 24 | IDecodeProxy* createDecoder(IDecodeProxyCallback* callback, const uint8_t* const header, const int length); 25 | void statusInfo(Json::Value& info); 26 | void uninitialize(); 27 | 28 | protected: 29 | bool initPlugin(); 30 | 31 | protected: 32 | void loadPath(LPCTSTR path); 33 | void loadFile(LPCTSTR file); 34 | 35 | protected: 36 | typedef CSmartHdr CModulePtr; 37 | typedef CSmartPtr IFactoryPtr; 38 | 39 | private: 40 | std::vector m_vModules; 41 | std::recursive_mutex m_lkFactories; 42 | std::vector m_vFactories; 43 | }; 44 | 45 | -------------------------------------------------------------------------------- /c++/Src/live_codec/Makefile: -------------------------------------------------------------------------------- 1 | # Copyright (c) 1999 Apple Computer, Inc. All rights reserved. 2 | # 3 | 4 | NAME = liblive_codec 5 | STATICLIB = liblive_codec.a 6 | SHAREDLIB = liblive_codec.so 7 | C++ = gcc #$(CPLUS) 8 | CC = gcc #$(CCOMP) 9 | LINK = $(LINKER) 10 | 11 | COMPILER_FLAGS = -D_REENTRANT -D__USE_POSIX -D__linux__ -pipe 12 | INCLUDE_FLAG = -include 13 | CCFLAGS += $(COMPILER_FLAGS) -fPIC -g -Wall -Wno-deprecated -std=c++11 14 | 15 | # OPTIMIZATION 16 | #CCFLAGS += -O2 17 | 18 | # EACH DIRECTORY WITH HEADERS MUST BE APPENDED IN THIS MANNER TO THE CCFLAGS 19 | 20 | CCFLAGS += -I. 21 | CCFLAGS += -I.. 22 | CCFLAGS += -I./live_input 23 | CCFLAGS += -I../../linux/inc/ 24 | CCLIBS += -fPIC 25 | 26 | C++FLAGS = $(CCFLAGS) 27 | 28 | CFILES = 29 | 30 | CPPFILES = DecodeFactory.cpp 31 | 32 | all: $(SHAREDLIB) $(STATICLIB) 33 | 34 | $(SHAREDLIB): $(CFILES:.c=.o) $(CPPFILES:.cpp=.o) 35 | g++ -shared -fPIC -o $(SHAREDLIB) $(CFILES:.c=.o) $(CPPFILES:.cpp=.o) $(CCLIBS) 36 | mkdir -p ../../linux/bin 37 | cp -f $(SHAREDLIB) ../../linux/bin 38 | 39 | $(STATICLIB): $(CFILES:.c=.o) $(CPPFILES:.cpp=.o) 40 | ar -r $(STATICLIB) $(CFILES:.c=.o) $(CPPFILES:.cpp=.o) 41 | ranlib $(STATICLIB) 42 | mkdir -p ../../linux/lib 43 | cp -f $(STATICLIB) ../../linux/lib 44 | mkdir -p ../../linux/inc 45 | cp -f CodecInterface.h ../../linux/inc/ 46 | cp -f DecodeFactory.h ../../linux/inc/ 47 | 48 | install: $(STATICLIB) 49 | clean: 50 | rm -f $(STATICLIB) $(SHAREDLIB) $(CFILES:.c=.o) $(CPPFILES:.cpp=.o) 51 | 52 | .SUFFIXES: .cpp .c .o 53 | 54 | .cpp.o: 55 | $(C++) -c -o $*.o $(DEFINES) $(C++FLAGS) $*.cpp 56 | 57 | .c.o: 58 | $(CC) -c -o $*.o $(DEFINES) $(CCFLAGS) $*.c 59 | 60 | 61 | -------------------------------------------------------------------------------- /c++/Src/live_codec/ReadMe.txt: -------------------------------------------------------------------------------- 1 | ======================================================================== 2 | 静态库:live_codec 项目概述 3 | ======================================================================== 4 | 5 | 应用程序向导已为您创建了此 live_codec 库项目。 6 | 7 | 没有为此项目创建源文件。 8 | 9 | 10 | live_codec.vcxproj 11 | 这是使用应用程序向导生成的 VC++ 项目的主项目文件,其中包含生成该文件的 Visual C++ 的版本信息,以及有关使用应用程序向导选择的平台、配置和项目功能的信息。 12 | 13 | live_codec.vcxproj.filters 14 | 这是使用“应用程序向导”生成的 VC++ 项目筛选器文件。它包含有关项目文件与筛选器之间的关联信息。在 IDE 中,通过这种关联,在特定节点下以分组形式显示具有相似扩展名的文件。例如,“.cpp”文件与“源文件”筛选器关联。 15 | 16 | ///////////////////////////////////////////////////////////////////////////// 17 | 其他注释: 18 | 19 | 应用程序向导使用“TODO:”注释来指示应添加或自定义的源代码部分。 20 | 21 | ///////////////////////////////////////////////////////////////////////////// 22 | -------------------------------------------------------------------------------- /c++/Src/live_codec/live_codec.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 头文件 23 | 24 | 25 | 头文件 26 | 27 | 28 | 29 | 30 | 源文件 31 | 32 | 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /c++/Src/live_codec_nal/Makefile: -------------------------------------------------------------------------------- 1 | # Copyright (c) 1999 Apple Computer, Inc. All rights reserved. 2 | # 3 | 4 | NAME = liblive_sink_raw 5 | STATICLIB = liblive_sink_raw.a 6 | SHAREDLIB = liblive_sink_raw.so 7 | C++ = gcc #$(CPLUS) 8 | CC = gcc #$(CCOMP) 9 | LINK = $(LINKER) 10 | 11 | COMPILER_FLAGS = -D_REENTRANT -D__USE_POSIX -D__linux__ -pipe 12 | INCLUDE_FLAG = -include 13 | CCFLAGS += $(COMPILER_FLAGS) -fPIC -g -Wall -Wno-deprecated -std=c++11 14 | 15 | # OPTIMIZATION 16 | #CCFLAGS += -O2 17 | 18 | # EACH DIRECTORY WITH HEADERS MUST BE APPENDED IN THIS MANNER TO THE CCFLAGS 19 | 20 | CCFLAGS += -I. 21 | CCFLAGS += -I.. 22 | CCFLAGS += -I../../linux/inc 23 | CCFLAGS += -I../live_codec 24 | 25 | C++FLAGS = $(CCFLAGS) 26 | 27 | CXXLIBS += -L../../linux/lib -llive_output -llive_logging -llive_media -llive_common -llive_literal -llive_network 28 | CXXLIBS += -L../../linux/lib -levent -levent_core -levent_pthreads 29 | CXXLIBS += -L./usr/local/lib -lpthread -ldl -fPIC 30 | 31 | CFILES = 32 | 33 | CPPFILES = live_codec_nal.cpp \ 34 | NalDemuxer.cpp \ 35 | NalFactory.cpp 36 | 37 | all: $(SHAREDLIB) $(STATICLIB) 38 | 39 | #-shared 40 | $(SHAREDLIB): $(CFILES:.c=.o) $(CPPFILES:.cpp=.o) 41 | g++ -shared -fPIC -o $(SHAREDLIB) $(CFILES:.c=.o) $(CPPFILES:.cpp=.o) $(CXXLIBS) 42 | mkdir -p ../../linux/bin 43 | cp -f $(SHAREDLIB) ../../linux/bin 44 | mkdir -p ../live_gateway/Plugin/codec/ 45 | cp -f $(SHAREDLIB) ../live_gateway/Plugin/codec/ 46 | 47 | $(STATICLIB): $(CFILES:.c=.o) $(CPPFILES:.cpp=.o) 48 | ar -r $(STATICLIB) $(CFILES:.c=.o) $(CPPFILES:.cpp=.o) 49 | ranlib $(STATICLIB) 50 | mkdir -p ../../linux/lib 51 | cp -f $(STATICLIB) ../../linux/lib 52 | mkdir -p ../../linux/inc 53 | 54 | install: $(STATICLIB) 55 | clean: 56 | rm -f $(STATICLIB) $(SHAREDLIB) $(CFILES:.c=.o) $(CPPFILES:.cpp=.o) 57 | 58 | .SUFFIXES: .cpp .c .o 59 | 60 | .cpp.o: 61 | $(C++) -c -o $*.o $(DEFINES) $(C++FLAGS) $*.cpp 62 | 63 | .c.o: 64 | $(CC) -c -o $*.o $(DEFINES) $(CCFLAGS) $*.c 65 | 66 | 67 | -------------------------------------------------------------------------------- /c++/Src/live_codec_nal/NalDemuxer.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yunsean/live/653fda0c4e444a94a4c8693a913faf92d356f595/c++/Src/live_codec_nal/NalDemuxer.h -------------------------------------------------------------------------------- /c++/Src/live_codec_nal/NalFactory.cpp: -------------------------------------------------------------------------------- 1 | #include "NalFactory.h" 2 | #include "NalDemuxer.h" 3 | #include "Writelog.h" 4 | #include "ConsoleUI.h" 5 | #include "json/value.h" 6 | #include "xaid.h" 7 | 8 | CNalFactory::CNalFactory() 9 | : m_lpszFactoryName(_T("Nal Demuxer")) { 10 | } 11 | CNalFactory::~CNalFactory() { 12 | } 13 | 14 | CNalFactory& CNalFactory::singleton() { 15 | static CNalFactory instance; 16 | return instance; 17 | } 18 | 19 | LPCTSTR CNalFactory::FactoryName() const { 20 | return m_lpszFactoryName; 21 | } 22 | bool CNalFactory::Initialize() { 23 | return true; 24 | } 25 | bool CNalFactory::DidSupport(const uint8_t* const header, const int length) { 26 | if (length < 4) return false; 27 | if (header[3] != 'N' || header[2] != 'A' || header[1] != 'L' || header[0] != '1') return false; 28 | return true; 29 | } 30 | IDecodeProxy* CNalFactory::CreateDecoder(IDecodeProxyCallback* callback, const uint8_t* const header, const int length) { 31 | if (length < 4) return nullptr; 32 | if (header[3] != 'N' || header[2] != 'A' || header[1] != 'L' || header[0] != '1') return nullptr; 33 | return new CNalDemuxer(callback); 34 | } 35 | bool CNalFactory::GetStatusInfo(LPSTR* json, void(**free)(LPSTR)) { 36 | return false; 37 | } 38 | void CNalFactory::Uninitialize() { 39 | 40 | } 41 | void CNalFactory::Destroy() { 42 | 43 | } -------------------------------------------------------------------------------- /c++/Src/live_codec_nal/NalFactory.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include 5 | #include "CodecInterface.h" 6 | #include "NalDemuxer.h" 7 | #include "SmartHdr.h" 8 | #include "SmartPtr.h" 9 | 10 | class CNalFactory : public IDecodeFactory { 11 | public: 12 | CNalFactory(); 13 | ~CNalFactory(); 14 | 15 | public: 16 | static CNalFactory& singleton(); 17 | 18 | protected: 19 | virtual LPCTSTR FactoryName() const; 20 | virtual bool Initialize(); 21 | virtual bool DidSupport(const uint8_t* const header, const int length); 22 | virtual IDecodeProxy* CreateDecoder(IDecodeProxyCallback* callback, const uint8_t* const header, const int length); 23 | virtual bool GetStatusInfo(LPSTR* json, void(**free)(LPSTR)); 24 | virtual void Uninitialize(); 25 | virtual void Destroy(); 26 | 27 | private: 28 | const LPCTSTR m_lpszFactoryName; 29 | }; 30 | 31 | -------------------------------------------------------------------------------- /c++/Src/live_codec_nal/live_codec_nal.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yunsean/live/653fda0c4e444a94a4c8693a913faf92d356f595/c++/Src/live_codec_nal/live_codec_nal.cpp -------------------------------------------------------------------------------- /c++/Src/live_codec_nal/live_codec_nal.def: -------------------------------------------------------------------------------- 1 | LIBRARY 2 | EXPORTS 3 | GetDecodeFactory 4 | -------------------------------------------------------------------------------- /c++/Src/live_codec_nal/live_codec_nal.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | 源文件 20 | 21 | 22 | 源文件 23 | 24 | 25 | 源文件 26 | 27 | 28 | 29 | 30 | 源文件 31 | 32 | 33 | 34 | 35 | 36 | 头文件 37 | 38 | 39 | 头文件 40 | 41 | 42 | -------------------------------------------------------------------------------- /c++/Src/live_comet/Caller.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | class CCaller { 13 | public: 14 | CCaller(); 15 | CCaller(const std::string& stub); 16 | ~CCaller(); 17 | 18 | public: 19 | void start(bufferevent* bev, const std::map& headers); 20 | void reply(bufferevent* bev, const std::map& headers); 21 | 22 | const std::string& stub() const { return m_stub; } 23 | bool replied() const { return m_callee != nullptr; } 24 | 25 | protected: 26 | static void on_read(bufferevent* event, void* userdata); 27 | void on_read(bufferevent* event); 28 | static void on_write(bufferevent* event, void* userdata); 29 | void on_write(bufferevent* event); 30 | static void on_error(bufferevent* event, short what, void* userdata); 31 | void on_error(bufferevent* event, short what); 32 | 33 | protected: 34 | void responseCaller(); 35 | void responseCallee(); 36 | 37 | private: 38 | static std::atomic m_callerIndex; 39 | 40 | private: 41 | std::string m_stub; 42 | std::unique_ptr> m_caller; 43 | std::unique_ptr> m_callee; 44 | std::map m_callerHeader; 45 | std::map m_calleeHeader; 46 | uint64_t m_calleeContentLength; 47 | uint64_t m_calleeReceived; 48 | }; 49 | 50 | -------------------------------------------------------------------------------- /c++/Src/live_comet/Channel.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include "Constant.h" 7 | #include "Subscriber.h" 8 | #include "QuickList.h" 9 | #include "xstring.h" 10 | #include "json/value.h" 11 | 12 | class COneClient; 13 | class CChannel { 14 | public: 15 | CChannel(const std::string& cname); 16 | ~CChannel(); 17 | 18 | public: 19 | bool addSubscriber(std::shared_ptr subscriber); 20 | int sendMessage(const std::string& message); 21 | int sendMessage(const Json::Value& message); 22 | 23 | const std::string& name() const { return m_name; } 24 | size_t messageCount() const { return m_messages.count(); } 25 | size_t subscriberCount() const { return m_subscribers.size(); } 26 | 27 | protected: 28 | void cacheMessage(unsigned long seq, const std::string& msg); 29 | int sendChunkedMessage(bool noop, const int seq, const std::string& message); 30 | 31 | protected: 32 | struct CMessage : QuickItem { 33 | unsigned long seq; 34 | std::string msg; 35 | }; 36 | 37 | private: 38 | const std::string m_name; 39 | unsigned long m_sequence; 40 | std::vector> m_subscribers; 41 | QuickList m_messages; 42 | }; 43 | 44 | -------------------------------------------------------------------------------- /c++/Src/live_comet/Constant.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | enum Mode { 4 | Pending, 5 | Message, 6 | Command, 7 | Media, 8 | Flv, 9 | Data 10 | }; -------------------------------------------------------------------------------- /c++/Src/live_comet/Engine.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yunsean/live/653fda0c4e444a94a4c8693a913faf92d356f595/c++/Src/live_comet/Engine.cpp -------------------------------------------------------------------------------- /c++/Src/live_comet/Makefile: -------------------------------------------------------------------------------- 1 | TERGET = comet 2 | 3 | CXX = g++ -g -Wall -D_REENTRANT -D__USE_POSIX -D__linux__ -D__PTHREADS_MUTEXES__ 4 | CXX += -D__STDC_FORMAT_MACROS 5 | CC = 6 | CXXFLAGS = -std=c++11 7 | CXXFLAGS += -I../../linux/inc/ 8 | CXXFLAGS += -I../live_input -I../live_output 9 | 10 | CXXLIBS += -L../../linux/lib -llive_network -llive_media -llive_logging -llive_common -llive_literal 11 | CXXLIBS += -L../../linux/lib -levent -levent_core -levent_pthreads 12 | CXXLIBS += -L./usr/local/lib -lpthread -ldl 13 | OBJES = live_comet.o \ 14 | Caller.o \ 15 | Engine.o \ 16 | Channel.o \ 17 | OneClient.o \ 18 | Subscriber.o 19 | 20 | SUBOBJES = 21 | SUBDIRS = 22 | 23 | .PHONY: subdirs $(SUBDIRS) $(TERGET) 24 | subdirs: $(SUBDIRS) $(TERGET) 25 | $(SUBDIRS): 26 | $(MAKE) -C $@ 27 | 28 | #all: $(TERGET) $(VOD) 29 | 30 | 31 | #echo -n $__TIMES__ 32 | 33 | $(TERGET):$(OBJES) 34 | $(CXX) -o $(TERGET) $(CXXFLAGS) $(OBJES) $(SUBOBJES) $(CXXLIBS) 35 | 36 | 37 | $(OBJES) : %.o : %.cpp 38 | $(CXX) -c $(CXXFLAGS) $< -o $@ 39 | 40 | 41 | clean: cleandir 42 | rm -f $(TERGET) *.o *.TMP *~ 43 | 44 | clear: cleardir 45 | rm -f *.o *.TMP *~ 46 | 47 | cleandir: 48 | for dir in $(SUBDIRS);do \ 49 | $(MAKE) -C $$dir clean; \ 50 | done 51 | 52 | cleardir: 53 | for dir in $(SUBDIRS);do \ 54 | $(MAKE) -C $$dir clear; \ 55 | done 56 | 57 | 58 | -------------------------------------------------------------------------------- /c++/Src/live_comet/QuickList.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | template 4 | struct QuickItem { 5 | QuickItem() : prev(NULL), next(NULL) { } 6 | T* prev; 7 | T* next; 8 | }; 9 | 10 | template 11 | class QuickList { 12 | 13 | public: 14 | class Iterator { 15 | public: 16 | friend class QuickList; 17 | T next() { 18 | T ret = p; 19 | if (p) { 20 | p = p->next; 21 | } 22 | return ret; 23 | } 24 | private: 25 | T p; 26 | }; 27 | friend class Iterator; 28 | 29 | public: 30 | QuickList() { 31 | size = 0; 32 | head = NULL; 33 | tail = NULL; 34 | } 35 | Iterator iterator() const { 36 | Iterator it; 37 | it.p = this->head; 38 | return it; 39 | } 40 | bool empty() const { 41 | return size == 0; 42 | } 43 | void remove(T t) { 44 | this->size--; 45 | if (t->prev) { 46 | t->prev->next = t->next; 47 | } 48 | if (t->next) { 49 | t->next->prev = t->prev; 50 | } 51 | if (this->head == t) { 52 | this->head = t->next; 53 | } 54 | if (this->tail == t) { 55 | this->tail = t->prev; 56 | } 57 | } 58 | T pop_front() { 59 | T t = this->head; 60 | this->remove(t); 61 | return t; 62 | } 63 | void push_back(T t) { 64 | this->size++; 65 | t->prev = this->tail; 66 | t->next = NULL; 67 | if (this->tail) { 68 | this->tail->next = t; 69 | } else { 70 | this->head = t; 71 | } 72 | this->tail = t; 73 | } 74 | int count() const { 75 | return size; 76 | } 77 | 78 | private: 79 | int size; 80 | T head; 81 | T tail; 82 | }; 83 | 84 | -------------------------------------------------------------------------------- /c++/Src/live_comet/ReadMe.txt: -------------------------------------------------------------------------------- 1 | 订阅通道 curl -v -X POST http://localhost:99/sub?token=111 -d[{\"cname\":\"haha\",\"seq\":0}] (注册源,并且订阅通道) 2 | 推送消息 curl -v "http://localhost:99/pub?cname=haha&content=111" 3 | 推送JSON curl -v -X POST http://localhost:99/pub?cname=haha -d{\"anybody\":1,\"anybody2\":\"ImDylan\"} (将JSON作为消息体推送出去,只能是JSON) 4 | 获取状态 curl http://localhost:88/info 5 | 6 | 拉取数据 curl -o bad.flv http://localhost:99/pull?stub=111 (stub要自己保证唯一,否则会覆盖之前的) 7 | 推送数据 curl -X POST http://localhost:99/push?stub=111 --data-binary @1.flv (必须确保stub已经在waiting状态) 8 | 获取状态 curl http://localhost:99/inspect?stub=111 9 | 10 | 远程调用 curl "http://localhost:88/call?method=play&timecode=1497892381066&token=xzuu4" (除开method之外的其他参数以及header中的非常规header将通过json方式原封传递给源,服务器会自动生成不重复的stub) 11 | 调用回答 curl -X POST "http://localhost:88/return?stub=1" --data-binary @1.flv (服务器会将非常规header以及content-length content-type等信息应答给调用者) 12 | 13 | 应用举例: 14 | 播放 ffplay "http://localhost:88/call?method=play&timecode=1497892381066&token=xzuu4" 15 | 关闭wifi wget -O - "http://localhost:88/call?method=wifi&enable=false&token=dylan" 16 | 启动wifi wget -O - "http://localhost:88/call?token=dylan&method=wifi&enable=true" 17 | 拉取分片列表 curl "http://localhost:88/call?begin=0&method=list&token=xzuu4" -------------------------------------------------------------------------------- /c++/Src/live_comet/Subscriber.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include "xstring.h" 10 | #include "Constant.h" 11 | #include "QuickList.h" 12 | #include "json/value.h" 13 | 14 | class COneClient; 15 | class CChannel; 16 | class CSubscriber : public QuickItem { 17 | public: 18 | CSubscriber(const std::string& token); 19 | ~CSubscriber(); 20 | 21 | public: 22 | int start(std::shared_ptr self, bufferevent* bev, const Json::Value& subscribe); 23 | bool notify(const std::string& cname, unsigned int seq, const std::string& chunk); 24 | void noop(const unsigned int shouldAfter, const unsigned int now); 25 | bool call(const std::string& stub, const std::map& params, const Json::Value& body); 26 | 27 | const std::string& token() const { return m_token; } 28 | const std::map& channels() const { return m_channels; } 29 | 30 | protected: 31 | static void on_write(bufferevent* event, void* userdata); 32 | void on_write(bufferevent* event); 33 | static void on_error(bufferevent* event, short what, void* userdata); 34 | void on_error(bufferevent* event, short what); 35 | 36 | private: 37 | friend class CChannel; 38 | const std::string m_token; 39 | unsigned int m_latestSend; 40 | std::map m_channels; 41 | std::unique_ptr> m_bev; 42 | }; 43 | 44 | -------------------------------------------------------------------------------- /c++/Src/live_comet/live_comet.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yunsean/live/653fda0c4e444a94a4c8693a913faf92d356f595/c++/Src/live_comet/live_comet.cpp -------------------------------------------------------------------------------- /c++/Src/live_common/BitStream.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yunsean/live/653fda0c4e444a94a4c8693a913faf92d356f595/c++/Src/live_common/BitStream.cpp -------------------------------------------------------------------------------- /c++/Src/live_common/BitStream.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "os.h" 3 | 4 | class CBitStream { 5 | public: 6 | CBitStream(); 7 | CBitStream(const uint8_t* b, int nb_b); 8 | virtual ~CBitStream(); 9 | 10 | public: 11 | void initialize(const uint8_t* b, int nb_b); 12 | uint32_t read(int bits); //nBitsNum >= 0 && <= 32 13 | void skip(int bits); //nBitsNuM >= 0 14 | int offset(); 15 | void alignSkip(); 16 | 17 | private: 18 | const uint8_t* m_buffer; 19 | int m_size; 20 | uint8_t* m_swap; 21 | uint32_t* m_result; 22 | uint8_t* m_pSrcByte; 23 | int64_t* m_move; 24 | int m_skiped; 25 | int m_nSrcByteLeftBits; 26 | int m_offset; 27 | }; 28 | 29 | -------------------------------------------------------------------------------- /c++/Src/live_common/Byte.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yunsean/live/653fda0c4e444a94a4c8693a913faf92d356f595/c++/Src/live_common/Byte.h -------------------------------------------------------------------------------- /c++/Src/live_common/ByteStream.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "os.h" 3 | 4 | class CByteStream { 5 | public: 6 | CByteStream(); 7 | CByteStream(uint8_t* b, int nb_b); 8 | CByteStream(char* b, int nb_b); 9 | ~CByteStream(); 10 | 11 | public: 12 | //stream never free the bytes, user must free it. 13 | bool initialize(uint8_t* b, int nb); 14 | bool initialize(char* b, int nb); 15 | uint8_t* data() const { return p; } 16 | int size() const { return nb_bytes; } 17 | int pos() const { return (int)(p - bytes); } 18 | bool empty(); 19 | //whether required size is ok. 20 | bool require(int required_size); 21 | 22 | public: 23 | void skip(int size); 24 | int8_t read_1bytes(); 25 | int16_t read_2bytes(); 26 | int32_t read_3bytes(); 27 | int32_t read_4bytes(); 28 | int64_t read_8bytes(); 29 | std::string read_string(int len); 30 | void read_bytes(uint8_t* data, int size); 31 | void read_bytes(char* data, int size); 32 | 33 | void write_1bytes(int8_t value); 34 | void write_2bytes(int16_t value); 35 | void write_4bytes(int32_t value); 36 | void write_3bytes(int32_t value); 37 | void write_8bytes(int64_t value); 38 | void write_string(std::string value); 39 | void write_bytes(const void* data, int size); 40 | 41 | private: 42 | void set_value(uint8_t* b, int nb_b); 43 | 44 | private: 45 | // current position at bytes. 46 | uint8_t* p; 47 | // the bytes data for stream to read or write. 48 | uint8_t* bytes; 49 | // the total number of bytes. 50 | int nb_bytes; 51 | }; 52 | 53 | -------------------------------------------------------------------------------- /c++/Src/live_common/ReadMe.txt: -------------------------------------------------------------------------------- 1 | ======================================================================== 2 | 静态库:live_common 项目概述 3 | ======================================================================== 4 | 5 | 应用程序向导已为您创建了此 live_common 库项目。 6 | 7 | 没有为此项目创建源文件。 8 | 9 | 10 | live_common.vcxproj 11 | 这是使用应用程序向导生成的 VC++ 项目的主项目文件,其中包含生成该文件的 Visual C++ 的版本信息,以及有关使用应用程序向导选择的平台、配置和项目功能的信息。 12 | 13 | live_common.vcxproj.filters 14 | 这是使用“应用程序向导”生成的 VC++ 项目筛选器文件。它包含有关项目文件与筛选器之间的关联信息。在 IDE 中,通过这种关联,在特定节点下以分组形式显示具有相似扩展名的文件。例如,“.cpp”文件与“源文件”筛选器关联。 15 | 16 | ///////////////////////////////////////////////////////////////////////////// 17 | 其他注释: 18 | 19 | 应用程序向导使用“TODO:”注释来指示应添加或自定义的源代码部分。 20 | 21 | ///////////////////////////////////////////////////////////////////////////// 22 | -------------------------------------------------------------------------------- /c++/Src/live_common/ShareBlk.cpp: -------------------------------------------------------------------------------- 1 | #include "ShareBlk.h" 2 | 3 | /************************************************************************ 4 | Ϊ������Ч�ʣ��������Գ�Ա�����������м��� 5 | ************************************************************************/ 6 | CSharedBlock::CSharedBlock() 7 | : m_lRefCount(0) 8 | , m_fnRelease(nullptr) 9 | , m_synchro(nullptr) 10 | , m_bReleased(true) { 11 | } 12 | long CSharedBlock::SetRef(const long count) { 13 | std::unique_lock lock(*m_synchro); 14 | m_lRefCount = count; 15 | m_bReleased = false; 16 | return m_lRefCount; 17 | } 18 | long CSharedBlock::AddRef() { 19 | std::unique_lock lock(*m_synchro); 20 | m_lRefCount++; 21 | return m_lRefCount; 22 | } 23 | long CSharedBlock::Release() { 24 | std::unique_lock lock(*m_synchro); 25 | m_lRefCount--; 26 | if (m_lRefCount <= 0) { 27 | if (!m_bReleased)m_fnRelease(this); 28 | m_bReleased = true; 29 | return 0; 30 | } 31 | return m_lRefCount; 32 | } 33 | void CSharedBlock::Reset() { 34 | std::unique_lock lock(*m_synchro); 35 | m_lRefCount = 0; 36 | if (!m_bReleased)m_fnRelease(this); 37 | m_bReleased = true; 38 | } 39 | void CSharedBlock::SetCB(const std::function& cb, std::mutex* syn) { 40 | m_fnRelease = cb; 41 | m_synchro = syn; 42 | } 43 | 44 | -------------------------------------------------------------------------------- /c++/Src/live_common/SmartLck.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "os.h" 3 | #include "xcritic.h" 4 | 5 | template 6 | class CSmartLock { 7 | public: 8 | CSmartLock(T& lock) 9 | : m_pMutex(&lock) { 10 | m_pMutex->lock(); 11 | } 12 | ~CSmartLock(void) { 13 | if(m_pMutex) { 14 | m_pMutex->unlock(); 15 | } 16 | } 17 | 18 | void Unlock(void) { 19 | if(m_pMutex) { 20 | m_pMutex->unlock(); 21 | m_pMutex = NULL; 22 | } 23 | } 24 | private: 25 | T* m_pMutex; 26 | }; 27 | 28 | typedef CSmartLock CSmartLck; 29 | 30 | 31 | -------------------------------------------------------------------------------- /c++/Src/live_common/SmartRet.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | template 4 | const T& ReturnAs(const T& retValue, const M&) { 5 | return retValue; 6 | } 7 | 8 | template 9 | void ReturnAs(const M&) { 10 | } 11 | 12 | #define rvaa(ret, any) (any, ret) 13 | #define raav(void, any) ReturnAs(any) 14 | #define raaa(ret, any) ReturnAs(ret, any) 15 | 16 | -------------------------------------------------------------------------------- /c++/Src/live_common/copy_x64.bat: -------------------------------------------------------------------------------- 1 | md ..\..\x64\inc\ 2 | copy SmartPtr.h ..\..\x64\inc\ 3 | copy SmartArr.h ..\..\x64\inc\ 4 | copy SmartHdr.h ..\..\x64\inc\ 5 | copy SmartRet.h ..\..\x64\inc\ 6 | copy SmartBlk.h ..\..\x64\inc\ 7 | copy SmartLck.h ..\..\x64\inc\ 8 | copy SmartErr.h ..\..\x64\inc\ 9 | copy SmartNal.h ..\..\x64\inc\ 10 | copy ShareBlk.h ..\..\x64\inc\ 11 | copy Byte.h ..\..\x64\inc\ 12 | copy ByteStream.h ..\..\x64\inc\ 13 | copy BitStream.h ..\..\x64\inc\ 14 | copy Profile.h ..\..\x64\inc\ 15 | copy xchar.h ..\..\x64\inc\ 16 | copy xevent.h ..\..\x64\inc\ 17 | copy xmember.h ..\..\x64\inc\ 18 | copy xsemaphore.h ..\..\x64\inc\ 19 | copy xstring.h ..\..\x64\inc\ 20 | copy xsystem.h ..\..\x64\inc\ 21 | copy xthread.h ..\..\x64\inc\ 22 | copy xexception.h ..\..\x64\inc\ 23 | copy xaid.h ..\..\x64\inc\ 24 | copy xutils.h ..\..\x64\inc\ 25 | copy os.h ..\..\x64\inc\ 26 | copy net.h ..\..\x64\inc\ 27 | copy file.h ..\..\x64\inc\ 28 | copy ierror.h ..\..\x64\inc\ 29 | copy wingetopt.h ..\..\x64\inc\ -------------------------------------------------------------------------------- /c++/Src/live_common/copy_x86.bat: -------------------------------------------------------------------------------- 1 | md ..\..\x86\inc\ 2 | copy SmartPtr.h ..\..\x86\inc\ 3 | copy SmartArr.h ..\..\x86\inc\ 4 | copy SmartHdr.h ..\..\x86\inc\ 5 | copy SmartRet.h ..\..\x86\inc\ 6 | copy SmartBlk.h ..\..\x86\inc\ 7 | copy SmartLck.h ..\..\x86\inc\ 8 | copy SmartErr.h ..\..\x86\inc\ 9 | copy SmartNal.h ..\..\x86\inc\ 10 | copy ShareBlk.h ..\..\x86\inc\ 11 | copy Byte.h ..\..\x86\inc\ 12 | copy ByteStream.h ..\..\x86\inc\ 13 | copy BitStream.h ..\..\x64\inc\ 14 | copy Profile.h ..\..\x86\inc\ 15 | copy xchar.h ..\..\x86\inc\ 16 | copy xevent.h ..\..\x86\inc\ 17 | copy xmember.h ..\..\x86\inc\ 18 | copy xsemaphore.h ..\..\x86\inc\ 19 | copy xstring.h ..\..\x86\inc\ 20 | copy xsystem.h ..\..\x86\inc\ 21 | copy xthread.h ..\..\x86\inc\ 22 | copy xexception.h ..\..\x86\inc\ 23 | copy xaid.h ..\..\x86\inc\ 24 | copy xutils.h ..\..\x86\inc\ 25 | copy os.h ..\..\x86\inc\ 26 | copy net.h ..\..\x86\inc\ 27 | copy file.h ..\..\x86\inc\ 28 | copy ierror.h ..\..\x86\inc\ 29 | copy wingetopt.h ..\..\x86\inc\ -------------------------------------------------------------------------------- /c++/Src/live_common/file.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include "xstring.h" 4 | 5 | #ifdef _WIN32 6 | #else 7 | void _split_whole_name(const char *whole_name, char *fname, char *ext); 8 | void _splitpath(const char* path, char* drive, char* dir, char* fname, char* ext); 9 | void _splitpath_s(const char* path, char* drive, size_t, char* dir, size_t, char* fname, size_t, char* ext); 10 | 11 | struct _finddata_t { 12 | char *name; 13 | int attrib; 14 | unsigned long size; 15 | }; 16 | #define FILE_ATTRIBUTE_READONLY 0x00000001 17 | #define FILE_ATTRIBUTE_HIDDEN 0x00000002 18 | #define FILE_ATTRIBUTE_SYSTEM 0x00000004 19 | #define FILE_ATTRIBUTE_DIRECTORY 0x00000010 20 | #define FILE_ATTRIBUTE_ARCHIVE 0x00000020 21 | #define FILE_ATTRIBUTE_NORMAL 0x00000080 22 | 23 | intptr_t _findfirst(const char *pattern, struct _finddata_t *data); 24 | int _findnext(intptr_t id, struct _finddata_t *data); 25 | int _findclose(intptr_t id); 26 | #endif 27 | namespace file { 28 | bool findFiles(LPCTSTR path, std::function onFile, const bool recursion = false); 29 | xtstring parentDirectory(LPCTSTR file); 30 | xtstring filename(LPCTSTR path); 31 | xtstring exeuteFilePath(); 32 | }; 33 | -------------------------------------------------------------------------------- /c++/Src/live_common/ierror.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "xchar.h" 3 | 4 | struct IError { 5 | public: 6 | virtual unsigned int GetLastErrorCode() const = 0; 7 | virtual LPCTSTR GetLastErrorDesc() const = 0; 8 | }; -------------------------------------------------------------------------------- /c++/Src/live_common/net.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include 5 | #if defined _WIN32 6 | # pragma comment(lib, "ws2_32.lib") 7 | # include 8 | # include 9 | # include 10 | #else 11 | # include 12 | # include 13 | # include 14 | # include 15 | # include 16 | # include 17 | # include 18 | # include 19 | # include 20 | #endif 21 | #include "xstring.h" 22 | 23 | #if defined _WIN32 24 | #define net_error() WSAGetLastError() 25 | #else 26 | typedef int SOCKET; 27 | #define INVALID_SOCKET -1 28 | #define SOCKET_ERROR -1 29 | #define closesocket(s) close(s) 30 | #define net_error() errno 31 | #endif 32 | 33 | #if defined _WIN32 34 | #define init_sockets()\ 35 | do {\ 36 | WSADATA wsaData;\ 37 | if (WSAStartup(MAKEWORD(2,2), &wsaData) != 0){\ 38 | printf("Error at WSAStartup()\n");\ 39 | exit(1);\ 40 | }\ 41 | } while(0) 42 | #else 43 | #define init_sockets() (void)0 44 | #endif 45 | 46 | #if defined _WIN32 47 | #define uninit_sockets()\ 48 | do {\ 49 | WSACleanup();\ 50 | } while(0) 51 | #else 52 | #define uninit_sockets() (void)0 53 | #endif 54 | 55 | int setnonblock(SOCKET fd); //evutil_make_socket_nonblocking 56 | int setkeepalive(SOCKET fd, int time, int interval); 57 | 58 | bool resolveUrl(const xtstring& url, xtstring& path, std::map& queries); 59 | xtstring composeQuery(const std::map& queries); 60 | xtstring composeUrl(const xtstring& path, const std::map& queries = std::map()); 61 | int resolveHeader(const char* const lpszHeader, std::map& payloads); 62 | std::string encodeUrl(const xtstring& url); 63 | xtstring decodeUrl(const std::string& url); -------------------------------------------------------------------------------- /c++/Src/live_common/os.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include 5 | 6 | #if defined(UNICODE) || defined(_UNICODE) 7 | #define w L 8 | #else 9 | #define w 10 | #endif 11 | 12 | #ifdef _WIN32 13 | 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | 23 | #undef min 24 | #undef max 25 | 26 | #ifndef ASSERT 27 | #include 28 | #define ASSERT(f) assert((f)) 29 | #endif 30 | 31 | #define inet_aton(ip, addr) inet_pton(AF_INET, ip, addr) 32 | #define PATH_SLASH '\\' 33 | 34 | #elif defined(__linux__) 35 | 36 | #include 37 | #include 38 | #include 39 | #include 40 | #include 41 | 42 | #define interface struct 43 | typedef void* HMODULE; 44 | #define PATH_SLASH '/' 45 | 46 | #endif 47 | 48 | #ifndef CONTAINING_RECORD 49 | #define CONTAINING_RECORD(addr, type, field) ((type*)((unsigned char*)addr - (unsigned long)&((type*)0)->field)) 50 | #endif 51 | 52 | -------------------------------------------------------------------------------- /c++/Src/live_common/wingetopt.c: -------------------------------------------------------------------------------- 1 | #include "wingetopt.h" 2 | #include 3 | #include 4 | 5 | #ifndef NULL 6 | #define NULL 0 7 | #endif 8 | #define EOF (-1) 9 | 10 | int opterr = 1; 11 | int optind = 1; 12 | int optopt; 13 | char *optarg = NULL; 14 | 15 | int getopt(int argc, char* argv[], char* opts) 16 | { 17 | int sp = 1; 18 | int c; 19 | char* cp = NULL; 20 | 21 | if(sp == 1) { 22 | if (optind >= argc || argv[optind][0] != '-' || argv[optind][1] == '\0') { 23 | return(EOF); 24 | } else if(strcmp(argv[optind], "--") == 0) { 25 | optind++; 26 | return(EOF); 27 | } 28 | optopt = c = argv[optind][sp]; 29 | if ((c == ':') || ((cp = strchr(opts, c)) == NULL)) { 30 | if(argv[optind][++sp] == '\0') { 31 | optind++; 32 | sp = 1; 33 | } 34 | return(':'); 35 | } 36 | if(*++cp == ':') { 37 | if(argv[optind][sp+1] != '\0') { 38 | optarg = &argv[optind++][sp+1]; 39 | } else if(++optind >= argc) { 40 | sp = 1; 41 | return(':'); 42 | } else { 43 | optarg = argv[optind++]; 44 | } 45 | sp = 1; 46 | } else { 47 | if(argv[optind][++sp] == '\0') { 48 | sp = 1; 49 | optind++; 50 | } 51 | optarg = NULL; 52 | } 53 | } 54 | return(c); 55 | } -------------------------------------------------------------------------------- /c++/Src/live_common/wingetopt.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifdef __GNUC__ 4 | #include 5 | #else 6 | #ifdef __cplusplus 7 | extern "C" { 8 | #endif 9 | extern int opterr; 10 | extern int optind; 11 | extern int optopt; 12 | extern char *optarg; 13 | extern int getopt(int argc, char **argv, char *opts); 14 | #ifdef __cplusplus 15 | } 16 | #endif 17 | #endif -------------------------------------------------------------------------------- /c++/Src/live_common/xcritic.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #ifdef _WIN32 4 | #include 5 | #include 6 | #endif 7 | #include "os.h" 8 | 9 | namespace std { 10 | 11 | class xcritic { 12 | 13 | public: 14 | void lock() { 15 | #ifdef _WIN32 16 | if (::GetCurrentThreadId() == holderTid){ 17 | holderCount++; 18 | return; 19 | } 20 | ::EnterCriticalSection(&critic); 21 | holderTid = ::GetCurrentThreadId(); 22 | holderCount++; 23 | #else 24 | mutex.lock(); 25 | #endif 26 | } 27 | void unlock() { 28 | #ifdef _WIN32 29 | if (::GetCurrentThreadId() != holderTid){ 30 | return; 31 | } 32 | holderCount--; 33 | if (holderCount == 0) { 34 | holderTid = 0; 35 | ::LeaveCriticalSection(&critic); 36 | } 37 | #else 38 | mutex.unlock(); 39 | #endif 40 | } 41 | bool trylock() { 42 | #ifdef _WIN32 43 | if (::GetCurrentThreadId() == holderTid){ 44 | holderCount++; 45 | return true; 46 | } 47 | bool res(::TryEnterCriticalSection(&critic) ? true : false); 48 | if (!res)return false; 49 | ::EnterCriticalSection(&critic); 50 | holderTid = ::GetCurrentThreadId(); 51 | holderCount++; 52 | return true; 53 | #else 54 | return mutex.try_lock(); 55 | #endif 56 | } 57 | 58 | public: 59 | xcritic() 60 | #ifdef _WIN32 61 | : holderTid(0) 62 | , holderCount(0) { 63 | ::InitializeCriticalSection(&critic); 64 | #else 65 | : mutex(){ 66 | #endif 67 | } 68 | ~xcritic() { 69 | #ifdef _WIN32 70 | ::DeleteCriticalSection(&critic); 71 | #endif 72 | } 73 | 74 | private: 75 | #ifdef _WIN32 76 | CRITICAL_SECTION critic; 77 | unsigned int holderTid; 78 | unsigned int holderCount; 79 | #else 80 | std::recursive_mutex mutex; 81 | #endif 82 | }; 83 | }; -------------------------------------------------------------------------------- /c++/Src/live_common/xevent.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | namespace std{ 9 | 10 | class xevent { 11 | public: 12 | xevent(bool manualReset = false, bool initialState = false) 13 | : m_mutex() 14 | , m_cond() 15 | , m_manualReset(manualReset) 16 | , m_state(initialState) { 17 | } 18 | virtual ~xevent() { 19 | } 20 | 21 | public: 22 | void set() { 23 | std::unique_lock lock(m_mutex); 24 | m_state = true; 25 | m_cond.notify_all(); 26 | } 27 | void reset() { 28 | std::unique_lock lock(m_mutex); 29 | m_state = false; 30 | } 31 | bool is() { 32 | return m_state; 33 | } 34 | bool wait(int timeout = -1) { 35 | std::unique_lock lock(m_mutex); 36 | bool res(true); 37 | if (!m_state) { 38 | if (timeout == -1) { 39 | m_cond.wait(lock); 40 | } else { 41 | std::cv_status status(std::cv_status::timeout); 42 | status = m_cond.wait_for(lock, std::chrono::milliseconds(timeout)); 43 | res = (status == std::cv_status::no_timeout); 44 | } 45 | } 46 | if (!m_manualReset)m_state = false; 47 | return res; 48 | } 49 | 50 | protected: 51 | std::mutex m_mutex; 52 | std::condition_variable m_cond; 53 | bool m_manualReset; 54 | bool m_state; 55 | }; 56 | }; -------------------------------------------------------------------------------- /c++/Src/live_common/xexception.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include 5 | #include "xsystem.h" 6 | 7 | #ifdef _WIN32 8 | #define _GLIBCXX_USE_NOEXCEPT 9 | #elif !defined(_GLIBCXX_USE_NOEXCEPT) 10 | #define _GLIBCXX_USE_NOEXCEPT throw() 11 | #endif 12 | class xexception : public std::exception { 13 | public: 14 | xexception(const char* const& msg, int err = -1) _GLIBCXX_USE_NOEXCEPT 15 | #ifdef _WIN32 16 | : m_msg(_strdup(msg)) 17 | #else 18 | : m_msg(strdup(msg)) 19 | #endif 20 | , m_err(err) { 21 | } 22 | xexception(int err) _GLIBCXX_USE_NOEXCEPT 23 | #ifdef _WIN32 24 | : m_msg(_strdup(std::errorText(err).c_str())) 25 | #else 26 | : m_msg(strdup(std::errorText(err).c_str())) 27 | #endif 28 | , m_err(err) { 29 | } 30 | virtual ~xexception() _GLIBCXX_USE_NOEXCEPT { 31 | if (m_msg) { 32 | free(m_msg); 33 | m_msg = nullptr; 34 | } 35 | } 36 | public: 37 | virtual const char* what() const _GLIBCXX_USE_NOEXCEPT { 38 | return m_msg; 39 | } 40 | virtual int error() const { 41 | return m_err; 42 | } 43 | private: 44 | char* m_msg; 45 | int m_err; 46 | }; -------------------------------------------------------------------------------- /c++/Src/live_common/xmember.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | namespace std { 5 | 6 | template 7 | class member_callback; 8 | 9 | template 10 | class member_callback 11 | { 12 | public: 13 | member_callback(R (T::*fn)(), T* self) 14 | : m_self(*self) 15 | , m_entry(fn){ 16 | } 17 | 18 | public: 19 | R operator()(){ 20 | T& inst(m_self); 21 | std::mem_fun_ref_t entry(m_entry); 22 | return entry(inst); 23 | } 24 | 25 | private: 26 | T& m_self; 27 | std::mem_fun_ref_t m_entry; 28 | }; 29 | 30 | template 31 | class member_callback 32 | { 33 | public: 34 | member_callback(R (T::*fn)(P1 p1), T* self) 35 | : m_self(*self) 36 | , m_entry(fn){ 37 | } 38 | 39 | public: 40 | R operator()(P1 p1){ 41 | return m_entry(m_self, p1); 42 | } 43 | 44 | private: 45 | T& m_self; 46 | std::mem_fun1_ref_t m_entry; 47 | }; 48 | 49 | template 50 | member_callback mem_wrapper(T* c, R (T::*fn)()) { 51 | return member_callback(fn, c); 52 | } 53 | template 54 | member_callback mem_wrapper(T* c, R (T::*fn)(P1)) { 55 | return member_callback(fn, c); 56 | } 57 | }; -------------------------------------------------------------------------------- /c++/Src/live_common/xsemaphore.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | namespace std { 8 | class xsemaphore { 9 | public: 10 | xsemaphore() 11 | : m_count() 12 | , m_mutex() 13 | , m_cond(){ 14 | m_count.store(0); 15 | } 16 | virtual ~xsemaphore() { 17 | } 18 | public: 19 | void notify() { 20 | std::lock_guard lock(m_mutex); 21 | m_count++; 22 | m_cond.notify_one(); 23 | } 24 | bool wait(int timeout = -1) { 25 | std::unique_lock lock(m_mutex); 26 | if (timeout == -1){ 27 | while (!m_count) { 28 | m_cond.wait(lock); 29 | } 30 | } else { 31 | std::chrono::system_clock::duration duration = std::chrono::milliseconds(timeout); 32 | std::chrono::time_point until(std::chrono::system_clock::now()); 33 | until += duration; 34 | #ifdef _WIN32 35 | std::cv_status::cv_status status(std::cv_status::no_timeout); 36 | #else 37 | std::cv_status status(std::cv_status::no_timeout); 38 | #endif 39 | while (!m_count && status == std::cv_status::no_timeout) { 40 | status = m_cond.wait_until(lock, until); 41 | } 42 | if (status != std::cv_status::no_timeout)return false; 43 | } 44 | m_count--; 45 | return true; 46 | } 47 | private: 48 | std::atomic_int m_count; 49 | std::mutex m_mutex; 50 | std::condition_variable m_cond; 51 | }; 52 | }; 53 | -------------------------------------------------------------------------------- /c++/Src/live_common/xthread.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include "xexception.h" 5 | 6 | class xthread { 7 | public: 8 | xthread() 9 | : thread(nullptr) { 10 | } 11 | template 12 | xthread(FN fn) 13 | : thread(new std::thread(fn)) { 14 | } 15 | template 16 | xthread(FN fn, P1 p) 17 | : thread(new std::thread(fn, p)) { 18 | } 19 | public: 20 | template 21 | void run(FN fn) { 22 | if (thread != nullptr) { 23 | throw xexception("thread is working!"); 24 | } 25 | thread = new std::thread(fn); 26 | } 27 | template 28 | void run(FN fn, P1 p) { 29 | if (thread != nullptr) { 30 | throw xexception("thread is working!"); 31 | } 32 | thread = new std::thread(fn, p); 33 | } 34 | void attach(std::thread* t) { 35 | if (thread != nullptr) { 36 | throw xexception("thread is working!"); 37 | } 38 | thread = t; 39 | } 40 | bool joinable() { 41 | if (thread == nullptr)return false; 42 | return thread->joinable(); 43 | } 44 | void join() { 45 | if (thread == nullptr)return; 46 | thread->join(); 47 | } 48 | void close() { 49 | if (thread == nullptr)return; 50 | if (thread->joinable()) { 51 | thread->join(); 52 | } 53 | delete thread; 54 | thread = nullptr; 55 | } 56 | #ifdef _WIN32 57 | void* native_handle() { 58 | if (thread == nullptr)return nullptr; 59 | #else 60 | int native_handle() { 61 | if (thread == nullptr)return 0; 62 | #endif 63 | return thread->native_handle(); 64 | } 65 | 66 | public: 67 | ~xthread() { 68 | close(); 69 | } 70 | protected: 71 | xthread(const xthread& src); 72 | xthread& operator=(const xthread& src); 73 | private: 74 | std::thread* thread; 75 | }; -------------------------------------------------------------------------------- /c++/Src/live_gateway/ChannelFactory.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include "SinkInterface.h" 7 | #include "Channel.h" 8 | #include "SmartPtr.h" 9 | #include "json/value.h" 10 | #include "xstring.h" 11 | 12 | class CHttpClient; 13 | struct event_base; 14 | class CChannelFactory { 15 | public: 16 | CChannelFactory(); 17 | ~CChannelFactory(); 18 | 19 | public: 20 | static CChannelFactory& singleton(); 21 | 22 | public: 23 | bool initialize(); 24 | void status(Json::Value& status); 25 | void uninitialize(); 26 | 27 | public: 28 | CChannel* getChannel(const xtstring& device, const xtstring& moniker, const xtstring& params); 29 | ISinkProxyCallback* bindChannel(ISinkProxy* proxy, const xtstring& device, const xtstring& moniker, const xtstring& params); 30 | void unbindChannel(CChannel* source); 31 | 32 | protected: 33 | typedef CSmartPtr CChannelPtr; 34 | 35 | private: 36 | std::recursive_mutex m_lkChannels; 37 | std::map m_liveChannels; 38 | std::vector m_corruptedChannels; 39 | }; 40 | 41 | -------------------------------------------------------------------------------- /c++/Src/live_gateway/CodecFactory.cpp: -------------------------------------------------------------------------------- 1 | #include "CodecFactory.h" 2 | #include "DecodeFactory.h" 3 | #include "HttpClient.h" 4 | #include "Writelog.h" 5 | #include "ConsoleUI.h" 6 | #include "xaid.h" 7 | 8 | CCodecFactory::CCodecFactory() { 9 | } 10 | CCodecFactory::~CCodecFactory() { 11 | } 12 | 13 | CCodecFactory& CCodecFactory::singleton() { 14 | static CCodecFactory instance; 15 | return instance; 16 | } 17 | 18 | bool CCodecFactory::initialize() { 19 | if (!CDecodeFactory::singleton().initialize()) { 20 | return wlet(false, _T("Initialize input factory failed.")); 21 | } 22 | return true; 23 | } 24 | void CCodecFactory::status(Json::Value& status) { 25 | CDecodeFactory::singleton().statusInfo(status); 26 | } 27 | void CCodecFactory::uninitialize() { 28 | CDecodeFactory::singleton().uninitialize(); 29 | } 30 | -------------------------------------------------------------------------------- /c++/Src/live_gateway/CodecFactory.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include "CodecInterface.h" 7 | #include "SmartPtr.h" 8 | #include "json/value.h" 9 | 10 | class CCodecFactory { 11 | public: 12 | CCodecFactory(); 13 | ~CCodecFactory(); 14 | 15 | public: 16 | static CCodecFactory& singleton(); 17 | 18 | public: 19 | bool initialize(); 20 | void status(Json::Value& status); 21 | void uninitialize(); 22 | }; 23 | 24 | -------------------------------------------------------------------------------- /c++/Src/live_gateway/EventBase.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yunsean/live/653fda0c4e444a94a4c8693a913faf92d356f595/c++/Src/live_gateway/EventBase.h -------------------------------------------------------------------------------- /c++/Src/live_gateway/GatewayClient.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include "HttpClient.h" 5 | #include "SinkInterface.h" 6 | 7 | class CGatewayClient : public CHttpClient, public ISinkHttpRequest { 8 | protected: 9 | CGatewayClient(); 10 | virtual ~CGatewayClient(); 11 | 12 | public: 13 | static CGatewayClient* newInstance(evutil_socket_t fd, struct sockaddr* addr); 14 | public: 15 | virtual void release(); 16 | 17 | protected: 18 | //ISinkHttpRequest 19 | virtual LPCTSTR GetOperation() const { return operation().c_str(); } 20 | virtual LPCTSTR GetVersion() const { return version().c_str(); } 21 | virtual LPCTSTR GetUrl() const { return url().c_str(); } 22 | virtual LPCTSTR GetPath() const { return path().c_str(); } 23 | virtual LPCTSTR GetAction() const { return action().c_str(); } 24 | virtual LPCTSTR GetIp() const { return ip().c_str(); } 25 | virtual int GetPort() const { return port(); } 26 | virtual LPCTSTR GetParam(LPCTSTR key) const { return param(key); } 27 | virtual LPCTSTR GetPayload(LPCTSTR key) const { return payload(key); } 28 | virtual evutil_socket_t GetSocket(bool detach /* = true */) { return fd(detach); } 29 | virtual event_base* GetBase() { return base(); } 30 | 31 | protected: 32 | static std::mutex m_mutex; 33 | static std::queue m_clients; 34 | 35 | protected: 36 | virtual void handle(); 37 | 38 | protected: 39 | void onSystemInfo(); 40 | void onStreamList(); 41 | void onPtzControl(); 42 | }; 43 | 44 | -------------------------------------------------------------------------------- /c++/Src/live_gateway/GatewayServer.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "xstring.h" 3 | 4 | class CGatewayServer { 5 | public: 6 | CGatewayServer(); 7 | ~CGatewayServer(); 8 | 9 | public: 10 | static CGatewayServer& singleton(); 11 | 12 | public: 13 | bool startup(const int port, const xtstring& ip = _T("0.0.0.0")); 14 | void shutdown(); 15 | 16 | private: 17 | static void listen_callback(struct evconnlistener* conn, evutil_socket_t sock, struct sockaddr* addr, int addrlen, void* context); 18 | void listen_callback(struct evconnlistener* conn, evutil_socket_t sock, struct sockaddr* addr, int addrlen); 19 | 20 | private: 21 | int m_listenPort; 22 | }; 23 | 24 | -------------------------------------------------------------------------------- /c++/Src/live_gateway/Makefile: -------------------------------------------------------------------------------- 1 | TERGET = gateway 2 | 3 | CXX = g++ -g -Wall -D_REENTRANT -D__USE_POSIX -D__linux__ -D__PTHREADS_MUTEXES__ 4 | CC = 5 | CXXFLAGS = -std=c++11 6 | CXXFLAGS += -I../../linux/inc/ 7 | CXXFLAGS += -I../live_input -I../live_output -I../live_codec 8 | 9 | CXXLIBS += -L../../linux/lib -llive_network -llive_output -llive_codec -llive_input -llive_media -llive_vpf -llive_logging -llive_common -llive_literal 10 | CXXLIBS += -L../../linux/lib -levent -levent_core -levent_pthreads 11 | CXXLIBS += -L./usr/local/lib -lpthread -ldl 12 | OBJES = Channel.o \ 13 | ChannelFactory.o \ 14 | CodecFactory.o \ 15 | EventBase.o \ 16 | GatewayClient.o \ 17 | GatewayServer.o \ 18 | live_gateway.o \ 19 | SinkFactory.o \ 20 | SourceFactory.o \ 21 | SystemInfo.o 22 | 23 | SUBOBJES = 24 | SUBDIRS = 25 | 26 | .PHONY: subdirs $(SUBDIRS) $(TERGET) 27 | subdirs: $(SUBDIRS) $(TERGET) 28 | $(SUBDIRS): 29 | $(MAKE) -C $@ 30 | 31 | #all: $(TERGET) $(VOD) 32 | 33 | 34 | #echo -n $__TIMES__ 35 | 36 | $(TERGET):$(OBJES) 37 | $(CXX) -o $(TERGET) $(CXXFLAGS) $(OBJES) $(SUBOBJES) $(CXXLIBS) 38 | 39 | 40 | $(OBJES) : %.o : %.cpp 41 | $(CXX) -c $(CXXFLAGS) $< -o $@ 42 | 43 | 44 | clean: cleandir 45 | rm -f $(TERGET) *.o *.TMP *~ 46 | 47 | clear: cleardir 48 | rm -f *.o *.TMP *~ 49 | 50 | cleandir: 51 | for dir in $(SUBDIRS);do \ 52 | $(MAKE) -C $$dir clean; \ 53 | done 54 | 55 | cleardir: 56 | for dir in $(SUBDIRS);do \ 57 | $(MAKE) -C $$dir clear; \ 58 | done 59 | 60 | 61 | -------------------------------------------------------------------------------- /c++/Src/live_gateway/ReadMe.txt: -------------------------------------------------------------------------------- 1 | ======================================================================== 2 | 控制台应用程序:live_gateway 项目概述 3 | ======================================================================== 4 | 5 | 应用程序向导已为您创建了此 live_gateway 应用程序。 6 | 7 | 本文件概要介绍组成 live_gateway 应用程序的每个文件的内容。 8 | 9 | 10 | live_gateway.vcxproj 11 | 这是使用应用程序向导生成的 VC++ 项目的主项目文件,其中包含生成该文件的 Visual C++ 的版本信息,以及有关使用应用程序向导选择的平台、配置和项目功能的信息。 12 | 13 | live_gateway.vcxproj.filters 14 | 这是使用“应用程序向导”生成的 VC++ 项目筛选器文件。它包含有关项目文件与筛选器之间的关联信息。在 IDE 中,通过这种关联,在特定节点下以分组形式显示具有相似扩展名的文件。例如,“.cpp”文件与“源文件”筛选器关联。 15 | 16 | live_gateway.cpp 17 | 这是主应用程序源文件。 18 | 19 | ///////////////////////////////////////////////////////////////////////////// 20 | 其他标准文件: 21 | 22 | StdAfx.h, StdAfx.cpp 23 | 这些文件用于生成名为 live_gateway.pch 的预编译头 (PCH) 文件和名为 StdAfx.obj 的预编译类型文件。 24 | 25 | ///////////////////////////////////////////////////////////////////////////// 26 | 其他注释: 27 | 28 | 应用程序向导使用“TODO:”注释来指示应添加或自定义的源代码部分。 29 | 30 | ///////////////////////////////////////////////////////////////////////////// 31 | -------------------------------------------------------------------------------- /c++/Src/live_gateway/SinkFactory.cpp: -------------------------------------------------------------------------------- 1 | #include "EventBase.h" 2 | #include "SinkFactory.h" 3 | #include "OutputFactory.h" 4 | #include "ChannelFactory.h" 5 | #include "ConsoleUI.h" 6 | #include "Writelog.h" 7 | 8 | CSinkFactory::CSinkFactory() { 9 | } 10 | CSinkFactory::~CSinkFactory() { 11 | } 12 | 13 | CSinkFactory& CSinkFactory::singleton() { 14 | static CSinkFactory instance; 15 | return instance; 16 | } 17 | 18 | bool CSinkFactory::initialize() { 19 | if (!COutputFactory::singleton().initialize(this)) { 20 | return wlet(false, _T("Initialize output factory failed.")); 21 | } 22 | return true; 23 | } 24 | void CSinkFactory::status(Json::Value& status) { 25 | COutputFactory::singleton().statusInfo(status); 26 | } 27 | 28 | event_base* CSinkFactory::GetPreferBase() { 29 | return CEventBase::singleton().preferBase(); 30 | } 31 | event_base** CSinkFactory::GetAllBase(int& count) { 32 | return CEventBase::singleton().allBase(count); 33 | } 34 | bool CSinkFactory::handleRequest(ISinkHttpRequest* request) { 35 | return COutputFactory::singleton().handleRequest(request); 36 | } 37 | ISinkProxyCallback* CSinkFactory::AddSink(ISinkProxy* proxy, LPCTSTR moniker, LPCTSTR device, LPCTSTR param /*= NULL*/) { 38 | return CChannelFactory::singleton().bindChannel(proxy, device, moniker, param); 39 | } 40 | ISinkProxyCallback* CSinkFactory::AddSink(ISinkProxy* proxy, LPCTSTR moniker, LPCTSTR device, LPCTSTR param, uint64_t beginTime, uint64_t endTime /*= 0*/) { 41 | return NULL; 42 | } 43 | 44 | -------------------------------------------------------------------------------- /c++/Src/live_gateway/SinkFactory.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "SinkInterface.h" 3 | #include "json/value.h" 4 | 5 | class CSinkFactory : public ISinkFactoryCallback { 6 | public: 7 | CSinkFactory(); 8 | ~CSinkFactory(); 9 | 10 | public: 11 | static CSinkFactory& singleton(); 12 | 13 | public: 14 | bool initialize(); 15 | bool handleRequest(ISinkHttpRequest* request); 16 | void status(Json::Value& status); 17 | 18 | protected: 19 | virtual event_base* GetPreferBase(); 20 | virtual event_base** GetAllBase(int& count); 21 | virtual ISinkProxyCallback* AddSink(ISinkProxy* proxy, LPCTSTR moniker, LPCTSTR device, LPCTSTR param = NULL); 22 | virtual ISinkProxyCallback* AddSink(ISinkProxy* proxy, LPCTSTR moniker, LPCTSTR device, LPCTSTR param, uint64_t beginTime, uint64_t endTime = 0); 23 | }; 24 | 25 | -------------------------------------------------------------------------------- /c++/Src/live_gateway/SourceFactory.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include "SourceInterface.h" 7 | #include "SmartPtr.h" 8 | #include "json/value.h" 9 | 10 | class CHttpClient; 11 | struct event_base; 12 | class CSourceFactory : public ISourceFactoryCallback { 13 | public: 14 | CSourceFactory(void); 15 | virtual ~CSourceFactory(void); 16 | 17 | public: 18 | static CSourceFactory& singleton(); 19 | 20 | public: 21 | bool initialize(); 22 | ISourceProxy* createLiveSource(ISourceProxyCallback* callback, LPCTSTR device, LPCTSTR moniker, LPCTSTR param); 23 | ISourceProxy* createPastSource(ISourceProxyCallback* callback, LPCTSTR device, LPCTSTR moniker, LPCTSTR param, uint64_t beginTime, uint64_t endTime = 0); 24 | bool streamList(xtstring& xml, const xtstring& device, bool onlineOnly); 25 | void status(Json::Value& status); 26 | void uninitialize(); 27 | 28 | public: 29 | virtual event_base* GetPreferBase(); 30 | virtual event_base** GetAllBase(int& count); 31 | virtual void OnNewSource(LPCTSTR lpszDevice, LPCTSTR lpszMoniker, LPCTSTR lpszName, LPCTSTR lpszMeta = NULL); 32 | virtual void OnSourceOver(LPCTSTR lpszDevice, LPCTSTR lpszMoniker); 33 | }; 34 | 35 | -------------------------------------------------------------------------------- /c++/Src/live_input/ForwardProxy.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include "SourceInterface.h" 4 | #include "xstring.h" 5 | 6 | class CForwardProxy : public ISourceProxy { 7 | public: 8 | CForwardProxy(const xtstring& device, const xtstring& moniker, const xtstring& param, const xtstring& beginTime = _T(""), const xtstring& endTime = _T("")); 9 | CForwardProxy(const xtstring& device, const xtstring& moniker, const xtstring& param, std::map extend); 10 | ~CForwardProxy(void); 11 | 12 | public: 13 | int openSuperior(const std::vector& superiors, const int premier); 14 | bool openSuperior(const xtstring& superior); 15 | 16 | protected: 17 | virtual LPCTSTR SourceName() const; 18 | virtual unsigned int MaxStartDelay(const unsigned int def) { return def; } 19 | virtual unsigned int MaxFrameDelay(const unsigned int def) { return def; } 20 | virtual bool StartFetch(ISourceProxyCallback* callback); 21 | virtual void WantKeyFrame(); 22 | virtual void StopFetch(); 23 | virtual bool PTZControl(const PTZAction action, const int value); 24 | virtual bool VideoEffect(const int bright, const int contrast, const int saturation, const int hue); 25 | virtual bool Destroy(); 26 | 27 | private: 28 | std::string buildQuery(const std::map& query); 29 | std::string uriEncode(const xtstring& uri); 30 | 31 | private: 32 | xtstring m_strDevice; 33 | xtstring m_strMoniker; 34 | xtstring m_strParam; 35 | xtstring m_strPath; 36 | std::string m_strHost; 37 | bool m_vod; 38 | }; 39 | 40 | -------------------------------------------------------------------------------- /c++/Src/live_input/InputFactory.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include "SmartPtr.h" 7 | #include "SmartHdr.h" 8 | #include "xstring.h" 9 | #include "SourceInterface.h" 10 | 11 | namespace Json { 12 | class Value; 13 | } 14 | struct event_base; 15 | class CInputFactory { 16 | public: 17 | CInputFactory(); 18 | ~CInputFactory(); 19 | 20 | public: 21 | static CInputFactory& singleton(); 22 | 23 | public: 24 | bool initialize(ISourceFactoryCallback* callback, bool usePlugin = true); 25 | ISourceProxy* createLiveSource(ISourceProxyCallback* callback, LPCTSTR device, LPCTSTR moniker, LPCTSTR param); 26 | ISourceProxy* createPastSource(ISourceProxyCallback* callback, LPCTSTR device, LPCTSTR moniker, LPCTSTR param, uint64_t beginTime, uint64_t endTime = 0); 27 | bool streamList(xtstring& xml, const xtstring& device, bool onlineOnly); 28 | void statusInfo(Json::Value& value); 29 | void uninitialize(); 30 | 31 | protected: 32 | bool initPlugin(ISourceFactoryCallback* callback); 33 | 34 | protected: 35 | void loadPath(LPCTSTR path, ISourceFactoryCallback* callback); 36 | void loadFile(LPCTSTR file, ISourceFactoryCallback* callback); 37 | 38 | protected: 39 | typedef CSmartHdr CModulePtr; 40 | typedef CSmartPtr IFactoryPtr; 41 | 42 | private: 43 | std::vector m_vModules; 44 | std::recursive_mutex m_lkFactories; 45 | std::vector m_vFactories; 46 | 47 | std::vector m_vForwardHost; 48 | int m_nLatestHost; 49 | }; 50 | 51 | -------------------------------------------------------------------------------- /c++/Src/live_input/Makefile: -------------------------------------------------------------------------------- 1 | # Copyright (c) 1999 Apple Computer, Inc. All rights reserved. 2 | # 3 | 4 | NAME = liblive_input 5 | STATICLIB = liblive_input.a 6 | SHAREDLIB = liblive_input.so 7 | C++ = gcc #$(CPLUS) 8 | CC = gcc #$(CCOMP) 9 | LINK = $(LINKER) 10 | 11 | COMPILER_FLAGS = -D_REENTRANT -D__USE_POSIX -D__linux__ -pipe 12 | INCLUDE_FLAG = -include 13 | CCFLAGS += $(COMPILER_FLAGS) -fPIC -g -Wall -Wno-deprecated -std=c++11 14 | 15 | # OPTIMIZATION 16 | #CCFLAGS += -O2 17 | 18 | # EACH DIRECTORY WITH HEADERS MUST BE APPENDED IN THIS MANNER TO THE CCFLAGS 19 | 20 | CCFLAGS += -I. 21 | CCFLAGS += -I.. 22 | CCFLAGS += -I./live_input 23 | CCFLAGS += -I../../linux/inc/ 24 | CCLIBS += -fPIC 25 | 26 | C++FLAGS = $(CCFLAGS) 27 | 28 | CFILES = 29 | 30 | CPPFILES = InputFactory.cpp \ 31 | ForwardProxy.cpp 32 | 33 | all: $(SHAREDLIB) $(STATICLIB) 34 | 35 | $(SHAREDLIB): $(CFILES:.c=.o) $(CPPFILES:.cpp=.o) 36 | g++ -shared -fPIC -o $(SHAREDLIB) $(CFILES:.c=.o) $(CPPFILES:.cpp=.o) $(CCLIBS) 37 | mkdir -p ../../linux/bin 38 | cp -f $(SHAREDLIB) ../../linux/bin 39 | 40 | $(STATICLIB): $(CFILES:.c=.o) $(CPPFILES:.cpp=.o) 41 | ar -r $(STATICLIB) $(CFILES:.c=.o) $(CPPFILES:.cpp=.o) 42 | ranlib $(STATICLIB) 43 | mkdir -p ../../linux/lib 44 | cp -f $(STATICLIB) ../../linux/lib 45 | mkdir -p ../../linux/inc 46 | 47 | install: $(STATICLIB) 48 | clean: 49 | rm -f $(STATICLIB) $(SHAREDLIB) $(CFILES:.c=.o) $(CPPFILES:.cpp=.o) 50 | 51 | .SUFFIXES: .cpp .c .o 52 | 53 | .cpp.o: 54 | $(C++) -c -o $*.o $(DEFINES) $(C++FLAGS) $*.cpp 55 | 56 | .c.o: 57 | $(CC) -c -o $*.o $(DEFINES) $(CCFLAGS) $*.c 58 | 59 | 60 | -------------------------------------------------------------------------------- /c++/Src/live_input/ReadMe.txt: -------------------------------------------------------------------------------- 1 | ======================================================================== 2 | 动态链接库:live_input 项目概述 3 | ======================================================================== 4 | 5 | 应用程序向导已为您创建了此 live_input DLL。 6 | 7 | 本文件概要介绍组成 live_input 应用程序的每个文件的内容。 8 | 9 | 10 | live_input.vcxproj 11 | 这是使用应用程序向导生成的 VC++ 项目的主项目文件,其中包含生成该文件的 Visual C++ 的版本信息,以及有关使用应用程序向导选择的平台、配置和项目功能的信息。 12 | 13 | live_input.vcxproj.filters 14 | 这是使用“应用程序向导”生成的 VC++ 项目筛选器文件。它包含有关项目文件与筛选器之间的关联信息。在 IDE 中,通过这种关联,在特定节点下以分组形式显示具有相似扩展名的文件。例如,“.cpp”文件与“源文件”筛选器关联。 15 | 16 | live_input.cpp 17 | 这是主 DLL 源文件。 18 | 19 | 此 DLL 在创建时不导出任何符号。因此,生成时不会产生 .lib 文件。如果希望此项目成为其他某个项目的项目依赖项,则需要添加代码以从 DLL 导出某些符号,以便产生一个导出库,或者,也可以在项目“属性页”对话框中的“链接器”文件夹中,将“常规”属性页上的“忽略输入库”属性设置为“是”。 20 | 21 | ///////////////////////////////////////////////////////////////////////////// 22 | 其他标准文件: 23 | 24 | StdAfx.h, StdAfx.cpp 25 | 这些文件用于生成名为 live_input.pch 的预编译头 (PCH) 文件和名为 StdAfx.obj 的预编译类型文件。 26 | 27 | ///////////////////////////////////////////////////////////////////////////// 28 | 其他注释: 29 | 30 | 应用程序向导使用“TODO:”注释来指示应添加或自定义的源代码部分。 31 | 32 | ///////////////////////////////////////////////////////////////////////////// 33 | -------------------------------------------------------------------------------- /c++/Src/live_input/SourceInterface.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yunsean/live/653fda0c4e444a94a4c8693a913faf92d356f595/c++/Src/live_input/SourceInterface.h -------------------------------------------------------------------------------- /c++/Src/live_input/live_input.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 源文件 23 | 24 | 25 | 源文件 26 | 27 | 28 | 29 | 30 | 头文件 31 | 32 | 33 | 头文件 34 | 35 | 36 | 头文件 37 | 38 | 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /c++/Src/live_libevent/evutil.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007-2012 Niels Provos and Nick Mathewson 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 1. Redistributions of source code must retain the above copyright 8 | * notice, this list of conditions and the following disclaimer. 9 | * 2. Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * 3. The name of the author may not be used to endorse or promote products 13 | * derived from this software without specific prior written permission. 14 | * 15 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 16 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 17 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 18 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 19 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 20 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 21 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 22 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 24 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | */ 26 | #ifndef _EVUTIL_H_ 27 | #define _EVUTIL_H_ 28 | 29 | /** @file evutil.h 30 | 31 | Utility and compatibility functions for Libevent. 32 | 33 | The header is deprecated in Libevent 2.0 and later; please 34 | use instead. 35 | */ 36 | 37 | #include 38 | 39 | #endif /* _EVUTIL_H_ */ 40 | -------------------------------------------------------------------------------- /c++/Src/live_libevent/live_libevent.def: -------------------------------------------------------------------------------- 1 | LIBRARY live_libevent 2 | EXPORTS 3 | event_new 4 | event_free 5 | event_active 6 | event_reinit 7 | event_add 8 | evhttp_bind_socket 9 | evhttp_uri_get_query 10 | evhttp_set_gencb 11 | event_set_fatal_callback 12 | event_assign 13 | evhttp_uri_parse_with_flags 14 | bufferevent_socket_new 15 | event_base_loopexit 16 | event_base_loop 17 | evhttp_free 18 | evhttp_uri_get_port 19 | event_base_new 20 | bufferevent_setcb 21 | evhttp_make_request 22 | evhttp_request_free 23 | evhttp_new 24 | event_set_log_callback 25 | evhttp_uri_get_host 26 | evhttp_connection_base_new 27 | evconnlistener_new_bind 28 | evhttp_request_new 29 | evhttp_uri_get_path 30 | bufferevent_enable 31 | evhttp_add_header 32 | event_enable_debug_mode 33 | event_base_loopbreak 34 | event_base_free 35 | event_del 36 | evutil_make_socket_nonblocking 37 | evutil_closesocket 38 | bufferevent_free 39 | bufferevent_write 40 | bufferevent_read 41 | bufferevent_disable 42 | evutil_socket_geterror 43 | bufferevent_get_output 44 | evbuffer_get_length 45 | bufferevent_base_set 46 | event_get_base 47 | event_base_once 48 | event_base_dispatch 49 | bufferevent_flush 50 | evthread_use_windows_threads 51 | evthread_enable_lock_debuging 52 | evutil_make_listen_socket_reuseable 53 | evconnlistener_new 54 | evconnlistener_get_base 55 | bufferevent_get_base 56 | evconnlistener_free 57 | evconnlistener_disable 58 | bufferevent_getfd 59 | evhttp_connection_free 60 | evhttp_find_header 61 | evbuffer_remove 62 | bufferevent_socket_connect_hostname 63 | evhttp_uri_free 64 | bufferevent_get_input 65 | evbuffer_search 66 | evbuffer_add_printf 67 | evbuffer_add 68 | evbuffer_add_buffer -------------------------------------------------------------------------------- /c++/Src/live_libevent/strlcpy-internal.h: -------------------------------------------------------------------------------- 1 | #ifndef _STRLCPY_INTERNAL_H_ 2 | #define _STRLCPY_INTERNAL_H_ 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | #include "event2/event-config.h" 9 | 10 | #ifndef _EVENT_HAVE_STRLCPY 11 | #include 12 | size_t _event_strlcpy(char *dst, const char *src, size_t siz); 13 | #define strlcpy _event_strlcpy 14 | #endif 15 | 16 | #ifdef __cplusplus 17 | } 18 | #endif 19 | 20 | #endif 21 | 22 | -------------------------------------------------------------------------------- /c++/Src/live_literal/MD5CodeArith.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | #ifdef _WIN32 5 | #ifdef LIVE_LITERAL_EXPORTS 6 | #define LITERAL_API __declspec(dllexport) 7 | #else 8 | #define LITERAL_API __declspec(dllimport) 9 | #endif 10 | #else 11 | #define LITERAL_API 12 | #endif 13 | 14 | class LITERAL_API CMD5CodeArith { 15 | public: 16 | CMD5CodeArith(void); 17 | ~CMD5CodeArith(void); 18 | 19 | public: 20 | static std::string md5(const unsigned char* data, int len); 21 | 22 | public: 23 | void Initialize(void); 24 | void UpdateData(const unsigned char* pInBuffer, unsigned int nBufferSize); 25 | void Finalize(unsigned char md5code[16]); 26 | 27 | private: 28 | struct MD5_CTX { 29 | unsigned int state[4]; /* state (ABCD) */ 30 | unsigned int count[2]; /* number of bits, modulo 2^64 (lsb first) */ 31 | unsigned char buffer[64]; /* input buffer */ 32 | } m_stMD5Ctx; 33 | 34 | private: 35 | static void MD5_memcpy(unsigned char* output, unsigned char* input, unsigned int len); 36 | static void MD5Transform(unsigned int state[4], const unsigned char block[64]); 37 | static void MD5_memset(unsigned char* output, int value, unsigned int len); 38 | static void Decode(unsigned int *output, const unsigned char *input, unsigned int len); 39 | static void Encode(unsigned char *output, const unsigned int *input, unsigned int len); 40 | }; 41 | -------------------------------------------------------------------------------- /c++/Src/live_literal/ReadMe.txt: -------------------------------------------------------------------------------- 1 | ======================================================================== 2 | 动态链接库:live_literal 项目概述 3 | ======================================================================== 4 | 5 | 应用程序向导已为您创建了此 live_literal DLL。 6 | 7 | 本文件概要介绍组成 live_literal 应用程序的每个文件的内容。 8 | 9 | 10 | live_literal.vcxproj 11 | 这是使用应用程序向导生成的 VC++ 项目的主项目文件,其中包含生成该文件的 Visual C++ 的版本信息,以及有关使用应用程序向导选择的平台、配置和项目功能的信息。 12 | 13 | live_literal.vcxproj.filters 14 | 这是使用“应用程序向导”生成的 VC++ 项目筛选器文件。它包含有关项目文件与筛选器之间的关联信息。在 IDE 中,通过这种关联,在特定节点下以分组形式显示具有相似扩展名的文件。例如,“.cpp”文件与“源文件”筛选器关联。 15 | 16 | live_literal.cpp 17 | 这是主 DLL 源文件。 18 | 19 | 此 DLL 在创建时不导出任何符号。因此,生成时不会产生 .lib 文件。如果希望此项目成为其他某个项目的项目依赖项,则需要添加代码以从 DLL 导出某些符号,以便产生一个导出库,或者,也可以在项目“属性页”对话框中的“链接器”文件夹中,将“常规”属性页上的“忽略输入库”属性设置为“是”。 20 | 21 | ///////////////////////////////////////////////////////////////////////////// 22 | 其他标准文件: 23 | 24 | StdAfx.h, StdAfx.cpp 25 | 这些文件用于生成名为 live_literal.pch 的预编译头 (PCH) 文件和名为 StdAfx.obj 的预编译类型文件。 26 | 27 | ///////////////////////////////////////////////////////////////////////////// 28 | 其他注释: 29 | 30 | 应用程序向导使用“TODO:”注释来指示应添加或自定义的源代码部分。 31 | 32 | ///////////////////////////////////////////////////////////////////////////// 33 | -------------------------------------------------------------------------------- /c++/Src/live_literal/SHA1CodeArith.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | #ifdef _WIN32 5 | #ifdef LIVE_LITERAL_EXPORTS 6 | #define LITERAL_API __declspec(dllexport) 7 | #else 8 | #define LITERAL_API __declspec(dllimport) 9 | #endif 10 | #else 11 | #define LITERAL_API 12 | #endif 13 | 14 | #define SHA_LBLOCK 16 15 | class LITERAL_API CSHA1CodeArith { 16 | public: 17 | CSHA1CodeArith(void); 18 | ~CSHA1CodeArith(void); 19 | 20 | private: 21 | static std::string sha1(const unsigned char* sha1, int len); 22 | 23 | public: 24 | void Initialize(void); 25 | void UpdateData(const unsigned char* pBuffer, unsigned int uBufferSize); 26 | void Finalize(unsigned char sha1code[20]); 27 | 28 | private: 29 | void SHA1Transform(unsigned char* b); 30 | void SHA1Block(unsigned int* W, int num); 31 | 32 | private: 33 | struct SHA1_CTX { 34 | unsigned int h0, h1, h2, h3, h4; 35 | unsigned int Nl, Nh; 36 | unsigned int data[SHA_LBLOCK]; 37 | int num; 38 | } m_stSHA1Ctx; 39 | }; 40 | -------------------------------------------------------------------------------- /c++/Src/live_literal/copy_x64.bat: -------------------------------------------------------------------------------- 1 | md ..\..\x64\inc\ 2 | copy Markup.h ..\..\x64\inc\ 3 | copy MD5CodeArith.h ..\..\x64\inc\ 4 | copy SHA1CodeArith.h ..\..\x64\inc\ 5 | md ..\..\x64\inc\json\ 6 | copy .\json\*.h ..\..\x64\inc\json\ 7 | md ..\..\x64\inc\tinyxml\ 8 | copy .\tinyxml\tinyxml.h ..\..\x64\inc\tinyxml\ 9 | copy .\tinyxml\tinystr.h ..\..\x64\inc\tinyxml\ 10 | md ..\..\x64\inc\pugixml\ 11 | copy .\pugixml\pugiconfig.hpp ..\..\x64\inc\pugixml\ 12 | copy .\pugixml\pugixml.hpp ..\..\x64\inc\pugixml\ -------------------------------------------------------------------------------- /c++/Src/live_literal/copy_x86.bat: -------------------------------------------------------------------------------- 1 | md ..\..\x86\inc\ 2 | copy Markup.h ..\..\x86\inc\ 3 | copy MD5CodeArith.h ..\..\x64\inc\ 4 | copy SHA1CodeArith.h ..\..\x64\inc\ 5 | md ..\..\x86\inc\json\ 6 | copy .\json\*.h ..\..\x86\inc\json\ 7 | md ..\..\x64\inc\tinyxml\ 8 | copy .\tinyxml\tinyxml.h ..\..\x64\inc\tinyxml\ 9 | copy .\tinyxml\tinystr.h ..\..\x64\inc\tinyxml\ 10 | md ..\..\x64\inc\pugixml\ 11 | copy .\pugixml\pugiconfig.hpp ..\..\x64\inc\pugixml\ 12 | copy .\pugixml\pugixml.hpp ..\..\x64\inc\pugixml\ -------------------------------------------------------------------------------- /c++/Src/live_literal/dllmain.cpp: -------------------------------------------------------------------------------- 1 | // dllmain.cpp : 定义 DLL 应用程序的入口点。 2 | #include "os.h" 3 | 4 | BOOL APIENTRY DllMain( HMODULE hModule, 5 | DWORD ul_reason_for_call, 6 | LPVOID lpReserved 7 | ) 8 | { 9 | switch (ul_reason_for_call) 10 | { 11 | case DLL_PROCESS_ATTACH: 12 | case DLL_THREAD_ATTACH: 13 | case DLL_THREAD_DETACH: 14 | case DLL_PROCESS_DETACH: 15 | break; 16 | } 17 | return TRUE; 18 | } 19 | 20 | -------------------------------------------------------------------------------- /c++/Src/live_literal/json/assertions.h: -------------------------------------------------------------------------------- 1 | // Copyright 2007-2010 Baptiste Lepilleur 2 | // Distributed under MIT license, or public domain if desired and 3 | // recognized in your jurisdiction. 4 | // See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE 5 | 6 | #ifndef CPPTL_JSON_ASSERTIONS_H_INCLUDED 7 | # define CPPTL_JSON_ASSERTIONS_H_INCLUDED 8 | 9 | #include 10 | 11 | #if !defined(JSON_IS_AMALGAMATION) 12 | # include 13 | #endif // if !defined(JSON_IS_AMALGAMATION) 14 | 15 | #if JSON_USE_EXCEPTION 16 | #define JSON_ASSERT( condition ) assert( condition ); // @todo <= change this into an exception throw 17 | #define JSON_FAIL_MESSAGE( message ) throw std::runtime_error( message ); 18 | #else // JSON_USE_EXCEPTION 19 | #define JSON_ASSERT( condition ) assert( condition ); 20 | 21 | // The call to assert() will show the failure message in debug builds. In 22 | // release bugs we write to invalid memory in order to crash hard, so that a 23 | // debugger or crash reporter gets the chance to take over. We still call exit() 24 | // afterward in order to tell the compiler that this macro doesn't return. 25 | #define JSON_FAIL_MESSAGE( message ) { assert(false && message); strcpy(reinterpret_cast(666), message); exit(123); } 26 | 27 | #endif 28 | 29 | #define JSON_ASSERT_MESSAGE( condition, message ) if (!( condition )) { JSON_FAIL_MESSAGE( message ) } 30 | 31 | #endif // CPPTL_JSON_ASSERTIONS_H_INCLUDED 32 | -------------------------------------------------------------------------------- /c++/Src/live_literal/json/autolink.h: -------------------------------------------------------------------------------- 1 | // Copyright 2007-2010 Baptiste Lepilleur 2 | // Distributed under MIT license, or public domain if desired and 3 | // recognized in your jurisdiction. 4 | // See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE 5 | 6 | #ifndef JSON_AUTOLINK_H_INCLUDED 7 | # define JSON_AUTOLINK_H_INCLUDED 8 | 9 | # include "config.h" 10 | 11 | # ifdef JSON_IN_CPPTL 12 | # include 13 | # endif 14 | 15 | # if !defined(JSON_NO_AUTOLINK) && !defined(JSON_DLL_BUILD) && !defined(JSON_IN_CPPTL) 16 | # define CPPTL_AUTOLINK_NAME "json" 17 | # undef CPPTL_AUTOLINK_DLL 18 | # ifdef JSON_DLL 19 | # define CPPTL_AUTOLINK_DLL 20 | # endif 21 | # include "autolink.h" 22 | # endif 23 | 24 | #endif // JSON_AUTOLINK_H_INCLUDED 25 | -------------------------------------------------------------------------------- /c++/Src/live_literal/json/features.h: -------------------------------------------------------------------------------- 1 | // Copyright 2007-2010 Baptiste Lepilleur 2 | // Distributed under MIT license, or public domain if desired and 3 | // recognized in your jurisdiction. 4 | // See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE 5 | 6 | #ifndef CPPTL_JSON_FEATURES_H_INCLUDED 7 | # define CPPTL_JSON_FEATURES_H_INCLUDED 8 | 9 | #if !defined(JSON_IS_AMALGAMATION) 10 | # include "forwards.h" 11 | #endif // if !defined(JSON_IS_AMALGAMATION) 12 | 13 | namespace Json { 14 | 15 | /** \brief Configuration passed to reader and writer. 16 | * This configuration object can be used to force the Reader or Writer 17 | * to behave in a standard conforming way. 18 | */ 19 | class JSON_API Features 20 | { 21 | public: 22 | /** \brief A configuration that allows all features and assumes all strings are UTF-8. 23 | * - C & C++ comments are allowed 24 | * - Root object can be any JSON value 25 | * - Assumes Value strings are encoded in UTF-8 26 | */ 27 | static Features all(); 28 | 29 | /** \brief A configuration that is strictly compatible with the JSON specification. 30 | * - Comments are forbidden. 31 | * - Root object must be either an array or an object value. 32 | * - Assumes Value strings are encoded in UTF-8 33 | */ 34 | static Features strictMode(); 35 | 36 | /** \brief Initialize the configuration like JsonConfig::allFeatures; 37 | */ 38 | Features(); 39 | 40 | /// \c true if comments are allowed. Default: \c true. 41 | bool allowComments_; 42 | 43 | /// \c true if root must be either an array or an object value. Default: \c false. 44 | bool strictRoot_; 45 | }; 46 | 47 | } // namespace Json 48 | 49 | #endif // CPPTL_JSON_FEATURES_H_INCLUDED 50 | -------------------------------------------------------------------------------- /c++/Src/live_literal/json/forwards.h: -------------------------------------------------------------------------------- 1 | // Copyright 2007-2010 Baptiste Lepilleur 2 | // Distributed under MIT license, or public domain if desired and 3 | // recognized in your jurisdiction. 4 | // See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE 5 | 6 | #ifndef JSON_FORWARDS_H_INCLUDED 7 | # define JSON_FORWARDS_H_INCLUDED 8 | 9 | #if !defined(JSON_IS_AMALGAMATION) 10 | # include "config.h" 11 | #endif // if !defined(JSON_IS_AMALGAMATION) 12 | 13 | namespace Json { 14 | 15 | // writer.h 16 | class FastWriter; 17 | class StyledWriter; 18 | 19 | // reader.h 20 | class Reader; 21 | 22 | // features.h 23 | class Features; 24 | 25 | // value.h 26 | typedef unsigned int ArrayIndex; 27 | class StaticString; 28 | class Path; 29 | class PathArgument; 30 | class Value; 31 | class ValueIteratorBase; 32 | class ValueIterator; 33 | class ValueConstIterator; 34 | #ifdef JSON_VALUE_USE_INTERNAL_MAP 35 | class ValueMapAllocator; 36 | class ValueInternalLink; 37 | class ValueInternalArray; 38 | class ValueInternalMap; 39 | #endif // #ifdef JSON_VALUE_USE_INTERNAL_MAP 40 | 41 | } // namespace Json 42 | 43 | 44 | #endif // JSON_FORWARDS_H_INCLUDED 45 | -------------------------------------------------------------------------------- /c++/Src/live_literal/json/json.h: -------------------------------------------------------------------------------- 1 | // Copyright 2007-2010 Baptiste Lepilleur 2 | // Distributed under MIT license, or public domain if desired and 3 | // recognized in your jurisdiction. 4 | // See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE 5 | 6 | #ifndef JSON_JSON_H_INCLUDED 7 | # define JSON_JSON_H_INCLUDED 8 | 9 | # include "value.h" 10 | # include "reader.h" 11 | # include "writer.h" 12 | # include "features.h" 13 | 14 | #endif // JSON_JSON_H_INCLUDED 15 | -------------------------------------------------------------------------------- /c++/Src/live_literal/tinyxml/tinyxmlerror.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | www.sourceforge.net/projects/tinyxml 3 | Original code (2.0 and earlier )copyright (c) 2000-2006 Lee Thomason (www.grinninglizard.com) 4 | 5 | This software is provided 'as-is', without any express or implied 6 | warranty. In no event will the authors be held liable for any 7 | damages arising from the use of this software. 8 | 9 | Permission is granted to anyone to use this software for any 10 | purpose, including commercial applications, and to alter it and 11 | redistribute it freely, subject to the following restrictions: 12 | 13 | 1. The origin of this software must not be misrepresented; you must 14 | not claim that you wrote the original software. If you use this 15 | software in a product, an acknowledgment in the product documentation 16 | would be appreciated but is not required. 17 | 18 | 2. Altered source versions must be plainly marked as such, and 19 | must not be misrepresented as being the original software. 20 | 21 | 3. This notice may not be removed or altered from any source 22 | distribution. 23 | */ 24 | 25 | #include "tinyxml.h" 26 | 27 | // The goal of the seperate error file is to make the first 28 | // step towards localization. tinyxml (currently) only supports 29 | // english error messages, but the could now be translated. 30 | // 31 | // It also cleans up the code a bit. 32 | // 33 | 34 | const char* TiXmlBase::errorString[ TiXmlBase::TIXML_ERROR_STRING_COUNT ] = 35 | { 36 | "No error", 37 | "Error", 38 | "Failed to open file", 39 | "Error parsing Element.", 40 | "Failed to read Element name", 41 | "Error reading Element value.", 42 | "Error reading Attributes.", 43 | "Error: empty tag.", 44 | "Error reading end tag.", 45 | "Error parsing Unknown.", 46 | "Error parsing Comment.", 47 | "Error parsing Declaration.", 48 | "Error document empty.", 49 | "Error null (0) or unexpected EOF found in input stream.", 50 | "Error parsing CDATA.", 51 | "Error when TiXmlDocument added to document, because TiXmlDocument can only be at the root.", 52 | }; 53 | -------------------------------------------------------------------------------- /c++/Src/live_logging/ConsoleUI.cpp: -------------------------------------------------------------------------------- 1 | #include "ConsoleUI.h" 2 | #include "ConsoleUIImpl.h" 3 | 4 | #ifdef _DEBUG 5 | #define new DEBUG_NEW 6 | #endif 7 | 8 | CConsoleUI& CConsoleUI::Singleton() 9 | { 10 | return CConsoleUIImpl::Singleton(); 11 | } 12 | 13 | -------------------------------------------------------------------------------- /c++/Src/live_logging/LocalLogWriter.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yunsean/live/653fda0c4e444a94a4c8693a913faf92d356f595/c++/Src/live_logging/LocalLogWriter.h -------------------------------------------------------------------------------- /c++/Src/live_logging/LogWriter.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yunsean/live/653fda0c4e444a94a4c8693a913faf92d356f595/c++/Src/live_logging/LogWriter.h -------------------------------------------------------------------------------- /c++/Src/live_logging/Makefile: -------------------------------------------------------------------------------- 1 | # Copyright (c) 1999 Apple Computer, Inc. All rights reserved. 2 | # 3 | 4 | NAME = liblive_logging 5 | STATICLIB = liblive_logging.a 6 | SHAREDLIB = liblive_logging.so 7 | C++ = gcc #$(CPLUS) 8 | CC = gcc #$(CCOMP) 9 | LINK = $(LINKER) 10 | 11 | COMPILER_FLAGS = -D_REENTRANT -D__USE_POSIX -D__linux__ -pipe 12 | INCLUDE_FLAG = -include 13 | CCFLAGS += $(COMPILER_FLAGS) -fPIC -g -Wall -Wno-deprecated -std=c++11 14 | 15 | # OPTIMIZATION 16 | #CCFLAGS += -O2 17 | 18 | # EACH DIRECTORY WITH HEADERS MUST BE APPENDED IN THIS MANNER TO THE CCFLAGS 19 | 20 | CCFLAGS += -I. 21 | CCFLAGS += -I.. 22 | CCFLAGS += -I../live_common 23 | CCLIBS += -fPIC 24 | 25 | C++FLAGS = $(CCFLAGS) 26 | 27 | CFILES = 28 | 29 | CPPFILES = ConsoleUI.cpp \ 30 | ConsoleUIImpl.cpp \ 31 | LocalLogWriter.cpp \ 32 | LogWriter.cpp \ 33 | ModuleVersion.cpp \ 34 | PipeWriter.cpp \ 35 | Writelog.cpp \ 36 | SockWriter.cpp 37 | 38 | all: $(SHAREDLIB) $(STATICLIB) 39 | 40 | $(SHAREDLIB): $(CFILES:.c=.o) $(CPPFILES:.cpp=.o) 41 | g++ -shared -fPIC -o $(SHAREDLIB) $(CFILES:.c=.o) $(CPPFILES:.cpp=.o) $(CCLIBS) 42 | mkdir -p ../../linux/bin 43 | cp -f $(SHAREDLIB) ../../linux/bin 44 | 45 | $(STATICLIB): $(CFILES:.c=.o) $(CPPFILES:.cpp=.o) 46 | ar -r $(STATICLIB) $(CFILES:.c=.o) $(CPPFILES:.cpp=.o) 47 | ranlib $(STATICLIB) 48 | mkdir -p ../../linux/lib 49 | cp -f $(STATICLIB) ../../linux/lib 50 | mkdir -p ../../linux/inc 51 | cp -f Writelog.h ../../linux/inc/ 52 | cp -f ConsoleUI.h ../../linux/inc/ 53 | 54 | install: $(STATICLIB) 55 | clean: 56 | rm -f $(STATICLIB) $(SHAREDLIB) $(CFILES:.c=.o) $(CPPFILES:.cpp=.o) 57 | 58 | .SUFFIXES: .cpp .c .o 59 | 60 | .cpp.o: 61 | $(C++) -c -o $*.o $(DEFINES) $(C++FLAGS) $*.cpp 62 | 63 | .c.o: 64 | $(CC) -c -o $*.o $(DEFINES) $(CCFLAGS) $*.c 65 | 66 | 67 | -------------------------------------------------------------------------------- /c++/Src/live_logging/ModuleVersion.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "xstring.h" 3 | #include "SmartArr.h" 4 | 5 | #ifdef _WIN32 6 | class CModuleVersion : public VS_FIXEDFILEINFO 7 | { 8 | public: 9 | CModuleVersion(LPCTSTR lpszFileName = NULL); 10 | virtual ~CModuleVersion(void); 11 | 12 | public: 13 | bool InitVersionInfo(LPCTSTR lpszFileName); 14 | xtstring GetVersionValue(LPCTSTR lpszVersionType); 15 | xtstring GetProductVersion(); 16 | xtstring GetFileVersion(); 17 | 18 | protected: 19 | CSmartArr m_saVersionInfo; 20 | struct TRANSLATION 21 | { 22 | WORD langID; 23 | WORD charset; 24 | }m_translation; 25 | }; 26 | #endif 27 | 28 | -------------------------------------------------------------------------------- /c++/Src/live_logging/PipeWriter.cpp: -------------------------------------------------------------------------------- 1 | #include "PipeWriter.h" 2 | #include "LogWriter.h" 3 | #include "LocalLogWriter.h" 4 | 5 | CPipeWriter::CPipeWriter(void) 6 | #ifdef _WIN32 7 | : m_shNamedPipe(::CloseHandle, INVALID_HANDLE_VALUE) 8 | #endif 9 | { 10 | } 11 | 12 | CPipeWriter::~CPipeWriter(void) 13 | { 14 | ClosePipe(); 15 | } 16 | 17 | bool CPipeWriter::IsOpend() 18 | { 19 | #ifdef _WIN32 20 | return (m_shNamedPipe != INVALID_HANDLE_VALUE && m_shNamedPipe != NULL); 21 | #else 22 | return false; 23 | #endif 24 | } 25 | 26 | bool CPipeWriter::ConnectPipe() 27 | { 28 | #ifdef _WIN32 29 | const xtstring strName(_T("\\\\.\\pipe\\seamedia_logpipe")); 30 | m_shNamedPipe = ::CreateFile(strName, GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL); 31 | if (m_shNamedPipe == INVALID_HANDLE_VALUE) 32 | { 33 | xtstring strMsg; 34 | strMsg.Format(L"LogClient: Connect to pipe (%s) failed. GetLastError() = %d\n", strName, GetLastError()); 35 | OutputDebugString(strMsg); 36 | return false; 37 | } 38 | else 39 | { 40 | xtstring strMsg; 41 | strMsg.Format(L"LogClient: Connect to pipe (%s) succeed.\n", strName); 42 | OutputDebugString(strMsg); 43 | return true; 44 | } 45 | #else 46 | return false; 47 | #endif 48 | } 49 | 50 | bool CPipeWriter::WriteString(const xtstring& strText) 51 | { 52 | #ifdef _WIN32 53 | if (m_shNamedPipe == INVALID_HANDLE_VALUE)return false; 54 | DWORD dwWritten(0); 55 | if(!::WriteFile(m_shNamedPipe, (LPCTSTR)strText, strText.GetLength() * sizeof(TCHAR), &dwWritten, NULL)) 56 | { 57 | ClosePipe(); 58 | return false; 59 | } 60 | return true; 61 | #else 62 | return false; 63 | #endif 64 | } 65 | 66 | void CPipeWriter::ClosePipe() 67 | { 68 | #ifdef _WIN32 69 | m_shNamedPipe = INVALID_HANDLE_VALUE; 70 | #endif 71 | } 72 | -------------------------------------------------------------------------------- /c++/Src/live_logging/PipeWriter.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "SmartHdr.h" 3 | #include "xstring.h" 4 | 5 | class CPipeWriter 6 | { 7 | public: 8 | CPipeWriter(void); 9 | virtual ~CPipeWriter(void); 10 | 11 | public: 12 | bool IsOpend(); 13 | bool ConnectPipe(); 14 | bool WriteString(const xtstring& strText); 15 | void ClosePipe(); 16 | 17 | private: 18 | #ifdef _WIN32 19 | CSmartHdr m_shNamedPipe; 20 | #endif 21 | }; 22 | 23 | -------------------------------------------------------------------------------- /c++/Src/live_logging/ReadMe.txt: -------------------------------------------------------------------------------- 1 | ======================================================================== 2 | 动态链接库:live_logging 项目概述 3 | ======================================================================== 4 | 5 | 应用程序向导已为您创建了此 live_logging DLL。 6 | 7 | 本文件概要介绍组成 live_logging 应用程序的每个文件的内容。 8 | 9 | 10 | live_logging.vcxproj 11 | 这是使用应用程序向导生成的 VC++ 项目的主项目文件,其中包含生成该文件的 Visual C++ 的版本信息,以及有关使用应用程序向导选择的平台、配置和项目功能的信息。 12 | 13 | live_logging.vcxproj.filters 14 | 这是使用“应用程序向导”生成的 VC++ 项目筛选器文件。它包含有关项目文件与筛选器之间的关联信息。在 IDE 中,通过这种关联,在特定节点下以分组形式显示具有相似扩展名的文件。例如,“.cpp”文件与“源文件”筛选器关联。 15 | 16 | live_logging.cpp 17 | 这是主 DLL 源文件。 18 | 19 | 此 DLL 在创建时不导出任何符号。因此,生成时不会产生 .lib 文件。如果希望此项目成为其他某个项目的项目依赖项,则需要添加代码以从 DLL 导出某些符号,以便产生一个导出库,或者,也可以在项目“属性页”对话框中的“链接器”文件夹中,将“常规”属性页上的“忽略输入库”属性设置为“是”。 20 | 21 | ///////////////////////////////////////////////////////////////////////////// 22 | 其他标准文件: 23 | 24 | StdAfx.h, StdAfx.cpp 25 | 这些文件用于生成名为 live_logging.pch 的预编译头 (PCH) 文件和名为 StdAfx.obj 的预编译类型文件。 26 | 27 | ///////////////////////////////////////////////////////////////////////////// 28 | 其他注释: 29 | 30 | 应用程序向导使用“TODO:”注释来指示应添加或自定义的源代码部分。 31 | 32 | ///////////////////////////////////////////////////////////////////////////// 33 | -------------------------------------------------------------------------------- /c++/Src/live_logging/SockWriter.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "SmartHdr.h" 3 | #include "xstring.h" 4 | 5 | class CSockWriter 6 | { 7 | public: 8 | CSockWriter(void); 9 | ~CSockWriter(void); 10 | 11 | public: 12 | bool IsOpend(); 13 | bool ConnectPipe(); 14 | bool WriteString(const xtstring& strText); 15 | void ClosePipe(); 16 | 17 | private: 18 | bool m_inited; 19 | #ifdef _WIN32 20 | CSmartHdr m_fd; 21 | #else 22 | CSmartHdr m_fd; 23 | #endif 24 | }; 25 | 26 | -------------------------------------------------------------------------------- /c++/Src/live_logging/Writelog.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yunsean/live/653fda0c4e444a94a4c8693a913faf92d356f595/c++/Src/live_logging/Writelog.h -------------------------------------------------------------------------------- /c++/Src/live_logging/copy_x64.bat: -------------------------------------------------------------------------------- 1 | md ..\..\x64\inc\ 2 | copy WriteLog.h ..\..\x64\inc\ 3 | copy ConsoleUI.h ..\..\x64\inc\ -------------------------------------------------------------------------------- /c++/Src/live_logging/copy_x86.bat: -------------------------------------------------------------------------------- 1 | md ..\..\x86\inc\ 2 | copy WriteLog.h ..\..\x86\inc\ 3 | copy ConsoleUI.h ..\..\x86\inc\ -------------------------------------------------------------------------------- /c++/Src/live_logging/dllmain.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yunsean/live/653fda0c4e444a94a4c8693a913faf92d356f595/c++/Src/live_logging/dllmain.cpp -------------------------------------------------------------------------------- /c++/Src/live_media/AVCConfig.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include "SmartNal.h" 4 | 5 | #ifdef _WIN32 6 | #ifdef LIVE_MEDIA_EXPORTS 7 | #define MEDIA_API __declspec(dllexport) 8 | #else 9 | #define MEDIA_API __declspec(dllimport) 10 | #endif 11 | #else 12 | #define MEDIA_API 13 | #endif 14 | 15 | class MEDIA_API CAVCConfig 16 | { 17 | public: 18 | CAVCConfig(void); 19 | virtual ~CAVCConfig(void); 20 | 21 | public: 22 | bool Serialize(CSmartNal& config); 23 | void Unserialize(const unsigned char* const config, const int size); 24 | 25 | void AddSps(const unsigned char* const sps, const int size); 26 | int SpsCount(); 27 | bool GetSps(const int index, CSmartNal& sps); 28 | 29 | void AddPps(const unsigned char* const pps, const int size); 30 | int PpsCount(); 31 | bool GetPps(const int index, CSmartNal& pps); 32 | 33 | public: 34 | int configurationVersion; 35 | int profileIndication; 36 | int profile_compatibility; 37 | int levelIndication; 38 | int lengthSizeMinusOne; 39 | 40 | protected: 41 | int CalcBufSize(); 42 | 43 | private: 44 | std::vector>* m_vsnSPS; 45 | std::vector>* m_vsnPPS; 46 | }; 47 | 48 | -------------------------------------------------------------------------------- /c++/Src/live_media/BitReader.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifdef _WIN32 4 | #ifdef LIVE_MEDIA_EXPORTS 5 | #define MEDIA_API __declspec(dllexport) 6 | #else 7 | #define MEDIA_API __declspec(dllimport) 8 | #endif 9 | #else 10 | #define MEDIA_API 11 | #endif 12 | 13 | class MEDIA_API CBitReader { 14 | public: 15 | CBitReader(); 16 | virtual ~CBitReader(); 17 | 18 | public: 19 | void Initialize(const unsigned char* const lpData, const int szData); 20 | unsigned int GetBits(int nBitsNum); //nBitsNum >= 0 && <= 32 21 | void SkipBits(int nBitsNum); //nBitsNuM >= 0 22 | int GetBitsOffset(); 23 | void AlignSkip(); 24 | 25 | private: 26 | const unsigned char* m_lpBuffer; 27 | int m_szBuffer; 28 | unsigned char* m_lpSwap; 29 | unsigned int* m_pRetrun; 30 | unsigned char* m_pSrcByte; 31 | long long* m_pMove; 32 | 33 | int m_nSkipNum; 34 | int m_nSrcByteLeftBits; 35 | int m_nBitsOffset; 36 | }; 37 | 38 | -------------------------------------------------------------------------------- /c++/Src/live_media/BitWriter.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifdef _WIN32 4 | #ifdef LIVE_MEDIA_EXPORTS 5 | #define MEDIA_API __declspec(dllexport) 6 | #else 7 | #define MEDIA_API __declspec(dllimport) 8 | #endif 9 | #else 10 | #define MEDIA_API 11 | #endif 12 | 13 | class MEDIA_API CBitWriter { 14 | public: 15 | CBitWriter(void); 16 | virtual ~CBitWriter(void); 17 | 18 | public: 19 | bool Initialize(const int nSize); 20 | bool Initialize(unsigned char* const lpCache, const int szCache); 21 | int SetPos(int nPos); 22 | void Clear(); 23 | const unsigned char*GetData() const{return m_lpBuffer;} 24 | int GetSize() const{return m_nDataSize;} 25 | 26 | void WriteBYTE(const unsigned char value); 27 | void WriteWORD(const unsigned short value, const bool big_endian = false); 28 | void WriteDWORD(const unsigned int value, const bool big_endian = false); 29 | void WriteInt(const int value, const bool big_endian = false); 30 | void WriteInt64(const long long value, const bool big_endian = false); 31 | void WriteDouble(const double value); 32 | void WriteData(const unsigned char* pData, const int nDataLen); 33 | void WriteDupBYTE(const unsigned char value, const int len); 34 | 35 | private: 36 | bool m_bExtraBuffer; 37 | unsigned char* m_lpBuffer; 38 | int m_szBuffer; 39 | int m_nDataSize; 40 | int m_nPos; 41 | }; 42 | -------------------------------------------------------------------------------- /c++/Src/live_media/H264Utility.h: -------------------------------------------------------------------------------- 1 | #ifndef _DYN_H264_UTILITY_H_ 2 | #define _DYN_H264_UTILITY_H_ 3 | #include 4 | #include "Byte.h" 5 | 6 | #ifdef _WIN32 7 | #ifdef LIVE_MEDIA_EXPORTS 8 | #define MEDIA_API __declspec(dllexport) 9 | #else 10 | #define MEDIA_API __declspec(dllimport) 11 | #endif 12 | #else 13 | #define MEDIA_API 14 | #endif 15 | 16 | struct h264_sps_t; 17 | class MEDIA_API CH264Utility { 18 | public: 19 | enum H264NalType{unknal = -1, sei = 6, sps = 7, pps = 8}; 20 | enum H264SliceType{unkslice = -1, islice = 2, pslice = 4, bslice = 8}; 21 | 22 | public: 23 | CH264Utility(void); 24 | virtual ~CH264Utility(void); 25 | 26 | public: 27 | static H264NalType GetNalType(const unsigned char* const data); 28 | static int NextNalStart(const unsigned char* const data, const int size, const int from = 0); 29 | 30 | public: 31 | bool SetExtraData(const unsigned char* const data, const int size, int* width = NULL, int* height = NULL); 32 | bool PickExtraData(const unsigned char* const data, const int size, int* width = NULL, int* height = NULL); 33 | const unsigned char* NormalizeH264(const unsigned char* const data, const int size, int& len, bool& key); 34 | void NormalizeH264(const unsigned char* const data, const int size, const std::function& callback, const bool autoAddConfig = true); 35 | H264SliceType GetSliceInfo(const unsigned char* const data, const int size, int* framenum = nullptr); 36 | const unsigned char* GetSps(int& len); 37 | const unsigned char* GetPps(int& len); 38 | bool GetImageSize(int* width, int* height); 39 | 40 | private: 41 | #pragma warning(push) 42 | #pragma warning(disable: 4251) 43 | CByte m_bySps; 44 | CByte m_byPps; 45 | CByte m_byCache; 46 | CByte m_byNal; 47 | h264_sps_t* m_spsinfo; 48 | int m_nLatestFrameNum; 49 | bool m_nLatestIsKey; 50 | #pragma warning(pop) 51 | }; 52 | 53 | #endif 54 | -------------------------------------------------------------------------------- /c++/Src/live_media/Makefile: -------------------------------------------------------------------------------- 1 | # Copyright (c) 1999 Apple Computer, Inc. All rights reserved. 2 | # 3 | 4 | NAME = liblive_media 5 | STATICLIB = liblive_media.a 6 | SHAREDLIB = liblive_media.so 7 | C++ = gcc #$(CPLUS) 8 | CC = gcc #$(CCOMP) 9 | LINK = $(LINKER) 10 | 11 | COMPILER_FLAGS = -D_REENTRANT -D__USE_POSIX -D__linux__ -pipe 12 | INCLUDE_FLAG = -include 13 | CCFLAGS += $(COMPILER_FLAGS) -fPIC -g -Wall -Wno-deprecated -std=c++11 14 | 15 | # OPTIMIZATION 16 | #CCFLAGS += -O2 17 | 18 | # EACH DIRECTORY WITH HEADERS MUST BE APPENDED IN THIS MANNER TO THE CCFLAGS 19 | 20 | CCFLAGS += -I. 21 | CCFLAGS += -I.. 22 | CCFLAGS += -I../live_common 23 | CCFLAGS += -I../live_logging 24 | CCLIBS += -fPIC 25 | 26 | C++FLAGS = $(CCFLAGS) 27 | 28 | CFILES = 29 | 30 | CPPFILES = AACUtility.cpp \ 31 | AVCConfig.cpp \ 32 | BitReader.cpp \ 33 | BitWriter.cpp \ 34 | h264.cpp \ 35 | h264_slice.cpp \ 36 | h264_sps.cpp \ 37 | H264Utility.cpp 38 | 39 | all: $(SHAREDLIB) $(STATICLIB) 40 | 41 | $(SHAREDLIB): $(CFILES:.c=.o) $(CPPFILES:.cpp=.o) 42 | g++ -shared -fPIC -o $(SHAREDLIB) $(CFILES:.c=.o) $(CPPFILES:.cpp=.o) $(CCLIBS) 43 | mkdir -p ../../linux/bin 44 | cp -f $(SHAREDLIB) ../../linux/bin 45 | 46 | $(STATICLIB): $(CFILES:.c=.o) $(CPPFILES:.cpp=.o) 47 | ar -r $(STATICLIB) $(CFILES:.c=.o) $(CPPFILES:.cpp=.o) 48 | ranlib $(STATICLIB) 49 | mkdir -p ../../linux/lib 50 | cp -f $(STATICLIB) ../../linux/lib 51 | mkdir -p ../../linux/inc 52 | cp -f AACUtility.h ../../linux/inc/ 53 | cp -f AVCConfig.h ../../linux/inc/ 54 | cp -f BitReader.h ../../linux/inc/ 55 | cp -f BitWriter.h ../../linux/inc/ 56 | cp -f H264Utility.h ../../linux/inc/ 57 | 58 | install: $(STATICLIB) 59 | clean: 60 | rm -f $(STATICLIB) $(SHAREDLIB) $(CFILES:.c=.o) $(CPPFILES:.cpp=.o) 61 | 62 | .SUFFIXES: .cpp .c .o 63 | 64 | .cpp.o: 65 | $(C++) -c -o $*.o $(DEFINES) $(C++FLAGS) $*.cpp 66 | 67 | .c.o: 68 | $(CC) -c -o $*.o $(DEFINES) $(CCFLAGS) $*.c 69 | 70 | 71 | -------------------------------------------------------------------------------- /c++/Src/live_media/ReadMe.txt: -------------------------------------------------------------------------------- 1 | ======================================================================== 2 | 动态链接库:live_media 项目概述 3 | ======================================================================== 4 | 5 | 应用程序向导已为您创建了此 live_media DLL。 6 | 7 | 本文件概要介绍组成 live_media 应用程序的每个文件的内容。 8 | 9 | 10 | live_media.vcxproj 11 | 这是使用应用程序向导生成的 VC++ 项目的主项目文件,其中包含生成该文件的 Visual C++ 的版本信息,以及有关使用应用程序向导选择的平台、配置和项目功能的信息。 12 | 13 | live_media.vcxproj.filters 14 | 这是使用“应用程序向导”生成的 VC++ 项目筛选器文件。它包含有关项目文件与筛选器之间的关联信息。在 IDE 中,通过这种关联,在特定节点下以分组形式显示具有相似扩展名的文件。例如,“.cpp”文件与“源文件”筛选器关联。 15 | 16 | live_media.cpp 17 | 这是主 DLL 源文件。 18 | 19 | 此 DLL 在创建时不导出任何符号。因此,生成时不会产生 .lib 文件。如果希望此项目成为其他某个项目的项目依赖项,则需要添加代码以从 DLL 导出某些符号,以便产生一个导出库,或者,也可以在项目“属性页”对话框中的“链接器”文件夹中,将“常规”属性页上的“忽略输入库”属性设置为“是”。 20 | 21 | ///////////////////////////////////////////////////////////////////////////// 22 | 其他标准文件: 23 | 24 | StdAfx.h, StdAfx.cpp 25 | 这些文件用于生成名为 live_media.pch 的预编译头 (PCH) 文件和名为 StdAfx.obj 的预编译类型文件。 26 | 27 | ///////////////////////////////////////////////////////////////////////////// 28 | 其他注释: 29 | 30 | 应用程序向导使用“TODO:”注释来指示应添加或自定义的源代码部分。 31 | 32 | ///////////////////////////////////////////////////////////////////////////// 33 | -------------------------------------------------------------------------------- /c++/Src/live_media/copy_x64.bat: -------------------------------------------------------------------------------- 1 | md ..\..\x64\inc\ 2 | copy AACUtility.h ..\..\x64\inc\ 3 | copy AVCConfig.h ..\..\x64\inc\ 4 | copy BitReader.h ..\..\x64\inc\ 5 | copy BitWriter.h ..\..\x64\inc\ 6 | copy H264Utility.h ..\..\x64\inc\ -------------------------------------------------------------------------------- /c++/Src/live_media/copy_x86.bat: -------------------------------------------------------------------------------- 1 | md ..\..\x86\inc\ 2 | copy AACUtility.h ..\..\x86\inc\ 3 | copy AVCConfig.h ..\..\x86\inc\ 4 | copy BitReader.h ..\..\x86\inc\ 5 | copy BitWriter.h ..\..\x86\inc\ 6 | copy H264Utility.h ..\..\x86\inc\ -------------------------------------------------------------------------------- /c++/Src/live_media/dllmain.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yunsean/live/653fda0c4e444a94a4c8693a913faf92d356f595/c++/Src/live_media/dllmain.cpp -------------------------------------------------------------------------------- /c++/Src/live_media/h264.cpp: -------------------------------------------------------------------------------- 1 | #include "h264.h" 2 | 3 | void h264_decode_annexb(unsigned char* dst, int* dstlen, const unsigned char* src, const int srclen ) 4 | { 5 | unsigned char *dst_sav = dst; 6 | const unsigned char *end = &src[srclen]; 7 | 8 | while (src < end) 9 | { 10 | if (src < end - 3 && src[0] == 0x00 && src[1] == 0x00 && 11 | src[2] == 0x03) 12 | { 13 | *dst++ = 0x00; 14 | *dst++ = 0x00; 15 | 16 | src += 3; 17 | continue; 18 | } 19 | *dst++ = *src++; 20 | } 21 | 22 | *dstlen = (int)(dst - dst_sav); 23 | } 24 | 25 | void h264_get_nal_type(int* p_nal_type, const unsigned char *p_nal) 26 | { 27 | int i_nal_hdr; 28 | 29 | i_nal_hdr = p_nal[3]; 30 | *p_nal_type = i_nal_hdr & 0x1f; 31 | } 32 | 33 | void h264_find_frame_end(bool* p_found_frame_start, bool* p_new_frame, const unsigned char* p_nal, const int nal_length, int i_nal_type) 34 | { 35 | if (i_nal_type == 1/*NAL_SLICE*/ || i_nal_type == 2/*NAL_DPA*/ || i_nal_type == 5/*NAL_IDR_SLICE*/) 36 | *p_found_frame_start = true; 37 | 38 | if (i_nal_type == 7/*NAL_SPS*/ || i_nal_type == 8/*NAL_PPS*/ || i_nal_type == 9/*NAL_AUD*/) 39 | *p_found_frame_start = false; 40 | 41 | if( (*p_found_frame_start) ) 42 | { 43 | for (int i = 3; i < nal_length; i++) 44 | { 45 | if (p_nal[i] & 0x80) 46 | { 47 | *p_found_frame_start = false; 48 | *p_new_frame = true; 49 | return; 50 | } 51 | } 52 | } 53 | 54 | *p_new_frame = false; 55 | } 56 | -------------------------------------------------------------------------------- /c++/Src/live_media/h264_slice.cpp: -------------------------------------------------------------------------------- 1 | #include "h264.h" 2 | #include "vlc_bits.h" 3 | 4 | #ifndef UNUSED 5 | #define UNUSED(x) x = (x) 6 | #endif 7 | 8 | void h264_decode_slice(h264_slice_t* p_slice, unsigned char* p_nal, int n_nal_size, int i_nal_type, const h264_sps_t* p_sps) 9 | { 10 | bs_t s; 11 | bs_init(&s, p_nal, n_nal_size); 12 | 13 | bs_read_ue( &s ); // first_mb_in_slice 14 | p_slice->i_slice_type = bs_read_ue( &s ); // slice type 15 | 16 | int i_pic_parameter_set_id = bs_read_ue( &s ); 17 | p_slice->i_frame_num = bs_read( &s, p_sps->log2_max_frame_num + 4 ); 18 | 19 | int i_field_pic_flag = 0; 20 | int i_bottom_field_flag = -1; 21 | if( !p_sps->frame_mbs_only_flag) 22 | { 23 | /* field_pic_flag */ 24 | i_field_pic_flag = bs_read( &s, 1 ); 25 | if( i_field_pic_flag ) 26 | i_bottom_field_flag = bs_read( &s, 1 ); 27 | } 28 | 29 | int i_idr_pic_id; 30 | if( i_nal_type == 5/*NAL_SLICE_IDR*/ ) 31 | i_idr_pic_id = bs_read_ue( &s ); 32 | 33 | int i_delta_pic_order_cnt_bottom = -1; 34 | int i_delta_pic_order_cnt0 = 0; 35 | int i_delta_pic_order_cnt1 = 0; 36 | 37 | p_slice->i_pic_order_cnt_lsb = 0; 38 | 39 | if( p_sps->poc_type == 0 ) 40 | { 41 | p_slice->i_pic_order_cnt_lsb = bs_read( &s, p_sps->log2_max_poc_lsb + 4 ); 42 | //if( g_pic_order_present_flag && !i_field_pic_flag ) 43 | // i_delta_pic_order_cnt_bottom = bs_read_se( &s ); 44 | } 45 | else if( (p_sps->poc_type == 1) && 46 | (!p_sps->delta_pic_order_always_zero_flag) ) 47 | { 48 | i_delta_pic_order_cnt0 = bs_read_se( &s ); 49 | //if( g_pic_order_present_flag && !i_field_pic_flag ) 50 | // i_delta_pic_order_cnt1 = bs_read_se( &s ); 51 | } 52 | 53 | UNUSED(i_pic_parameter_set_id); 54 | UNUSED(i_bottom_field_flag); 55 | UNUSED(i_idr_pic_id); 56 | UNUSED(i_delta_pic_order_cnt_bottom); 57 | UNUSED(i_delta_pic_order_cnt0); 58 | UNUSED(i_delta_pic_order_cnt1); 59 | } 60 | -------------------------------------------------------------------------------- /c++/Src/live_network/Makefile: -------------------------------------------------------------------------------- 1 | # Copyright (c) 1999 Apple Computer, Inc. All rights reserved. 2 | # 3 | 4 | NAME = liblive_network 5 | STATICLIB = liblive_network.a 6 | SHAREDLIB = liblive_network.so 7 | C++ = gcc #$(CPLUS) 8 | CC = gcc #$(CCOMP) 9 | LINK = $(LINKER) 10 | 11 | COMPILER_FLAGS = -D_REENTRANT -D__USE_POSIX -D__linux__ -pipe 12 | INCLUDE_FLAG = -include 13 | CCFLAGS += $(COMPILER_FLAGS) -fPIC -g -Wall -Wno-deprecated -std=c++11 14 | 15 | # OPTIMIZATION 16 | #CCFLAGS += -O2 17 | 18 | # EACH DIRECTORY WITH HEADERS MUST BE APPENDED IN THIS MANNER TO THE CCFLAGS 19 | 20 | CCFLAGS += -I. 21 | CCFLAGS += -I.. 22 | CCFLAGS += -I../../linux/inc 23 | CXXLIBS += -L../../linux/lib -llive_logging -llive_common -llive_literal 24 | CXXLIBS += -L../../linux/lib -levent -levent_core -levent_pthreads 25 | CCLIBS += -fPIC 26 | 27 | C++FLAGS = $(CCFLAGS) 28 | 29 | CFILES = 30 | 31 | CPPFILES = HttpClient.cpp 32 | 33 | all: $(SHAREDLIB) $(STATICLIB) 34 | 35 | $(SHAREDLIB): $(CFILES:.c=.o) $(CPPFILES:.cpp=.o) 36 | g++ -shared -fPIC -o $(SHAREDLIB) $(CFILES:.c=.o) $(CPPFILES:.cpp=.o) $(CCLIBS) 37 | mkdir -p ../../linux/bin 38 | cp -f $(SHAREDLIB) ../../linux/bin 39 | 40 | $(STATICLIB): $(CFILES:.c=.o) $(CPPFILES:.cpp=.o) 41 | ar -r $(STATICLIB) $(CFILES:.c=.o) $(CPPFILES:.cpp=.o) 42 | ranlib $(STATICLIB) 43 | mkdir -p ../../linux/lib 44 | cp -f $(STATICLIB) ../../linux/lib 45 | mkdir -p ../../linux/inc 46 | cp -f HttpClient.h ../../linux/inc/ 47 | 48 | install: $(STATICLIB) 49 | clean: 50 | rm -f $(STATICLIB) $(SHAREDLIB) $(CFILES:.c=.o) $(CPPFILES:.cpp=.o) 51 | 52 | .SUFFIXES: .cpp .c .o 53 | 54 | .cpp.o: 55 | $(C++) -c -o $*.o $(DEFINES) $(C++FLAGS) $*.cpp 56 | 57 | .c.o: 58 | $(CC) -c -o $*.o $(DEFINES) $(CCFLAGS) $*.c 59 | 60 | 61 | -------------------------------------------------------------------------------- /c++/Src/live_network/ReadMe.txt: -------------------------------------------------------------------------------- 1 | ======================================================================== 2 | 动态链接库:live_network 项目概述 3 | ======================================================================== 4 | 5 | 应用程序向导已为您创建了此 live_network DLL。 6 | 7 | 本文件概要介绍组成 live_network 应用程序的每个文件的内容。 8 | 9 | 10 | live_network.vcxproj 11 | 这是使用应用程序向导生成的 VC++ 项目的主项目文件,其中包含生成该文件的 Visual C++ 的版本信息,以及有关使用应用程序向导选择的平台、配置和项目功能的信息。 12 | 13 | live_network.vcxproj.filters 14 | 这是使用“应用程序向导”生成的 VC++ 项目筛选器文件。它包含有关项目文件与筛选器之间的关联信息。在 IDE 中,通过这种关联,在特定节点下以分组形式显示具有相似扩展名的文件。例如,“.cpp”文件与“源文件”筛选器关联。 15 | 16 | live_network.cpp 17 | 这是主 DLL 源文件。 18 | 19 | 此 DLL 在创建时不导出任何符号。因此,生成时不会产生 .lib 文件。如果希望此项目成为其他某个项目的项目依赖项,则需要添加代码以从 DLL 导出某些符号,以便产生一个导出库,或者,也可以在项目“属性页”对话框中的“链接器”文件夹中,将“常规”属性页上的“忽略输入库”属性设置为“是”。 20 | 21 | ///////////////////////////////////////////////////////////////////////////// 22 | 其他标准文件: 23 | 24 | StdAfx.h, StdAfx.cpp 25 | 这些文件用于生成名为 live_network.pch 的预编译头 (PCH) 文件和名为 StdAfx.obj 的预编译类型文件。 26 | 27 | ///////////////////////////////////////////////////////////////////////////// 28 | 其他注释: 29 | 30 | 应用程序向导使用“TODO:”注释来指示应添加或自定义的源代码部分。 31 | 32 | ///////////////////////////////////////////////////////////////////////////// 33 | -------------------------------------------------------------------------------- /c++/Src/live_network/copy_x64.bat: -------------------------------------------------------------------------------- 1 | md ..\..\x64\inc\ 2 | copy HttpClient.h ..\..\x64\inc\ -------------------------------------------------------------------------------- /c++/Src/live_network/copy_x86.bat: -------------------------------------------------------------------------------- 1 | md ..\..\x86\inc\ 2 | copy HttpClient.h ..\..\x86\inc\ -------------------------------------------------------------------------------- /c++/Src/live_network/dllmain.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yunsean/live/653fda0c4e444a94a4c8693a913faf92d356f595/c++/Src/live_network/dllmain.cpp -------------------------------------------------------------------------------- /c++/Src/live_network/live_network.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 源文件 23 | 24 | 25 | 源文件 26 | 27 | 28 | 29 | 30 | 头文件 31 | 32 | 33 | 34 | 35 | 源文件 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /c++/Src/live_output/Makefile: -------------------------------------------------------------------------------- 1 | # Copyright (c) 1999 Apple Computer, Inc. All rights reserved. 2 | # 3 | 4 | NAME = liblive_output 5 | STATICLIB = liblive_output.a 6 | SHAREDLIB = liblive_output.so 7 | C++ = gcc #$(CPLUS) 8 | CC = gcc #$(CCOMP) 9 | LINK = $(LINKER) 10 | 11 | COMPILER_FLAGS = -D_REENTRANT -D__USE_POSIX -D__linux__ -pipe 12 | INCLUDE_FLAG = -include 13 | CCFLAGS += $(COMPILER_FLAGS) -fPIC -g -Wall -Wno-deprecated -std=c++11 14 | 15 | # OPTIMIZATION 16 | #CCFLAGS += -O2 17 | 18 | # EACH DIRECTORY WITH HEADERS MUST BE APPENDED IN THIS MANNER TO THE CCFLAGS 19 | 20 | CCFLAGS += -I. 21 | CCFLAGS += -I.. 22 | CCFLAGS += -I./live_output 23 | CCFLAGS += -I../../linux/inc/ 24 | CCLIBS += -fPIC 25 | 26 | C++FLAGS = $(CCFLAGS) 27 | 28 | CFILES = 29 | 30 | CPPFILES = OutputFactory.cpp 31 | 32 | all: $(SHAREDLIB) $(STATICLIB) 33 | 34 | $(SHAREDLIB): $(CFILES:.c=.o) $(CPPFILES:.cpp=.o) 35 | g++ -shared -fPIC -o $(SHAREDLIB) $(CFILES:.c=.o) $(CPPFILES:.cpp=.o) $(CCLIBS) 36 | mkdir -p ../../linux/bin 37 | cp -f $(SHAREDLIB) ../../linux/bin 38 | 39 | $(STATICLIB): $(CFILES:.c=.o) $(CPPFILES:.cpp=.o) 40 | ar -r $(STATICLIB) $(CFILES:.c=.o) $(CPPFILES:.cpp=.o) 41 | ranlib $(STATICLIB) 42 | mkdir -p ../../linux/lib 43 | cp -f $(STATICLIB) ../../linux/lib 44 | mkdir -p ../../linux/inc 45 | 46 | install: $(STATICLIB) 47 | clean: 48 | rm -f $(STATICLIB) $(SHAREDLIB) $(CFILES:.c=.o) $(CPPFILES:.cpp=.o) 49 | 50 | .SUFFIXES: .cpp .c .o 51 | 52 | .cpp.o: 53 | $(C++) -c -o $*.o $(DEFINES) $(C++FLAGS) $*.cpp 54 | 55 | .c.o: 56 | $(CC) -c -o $*.o $(DEFINES) $(CCFLAGS) $*.c 57 | 58 | 59 | -------------------------------------------------------------------------------- /c++/Src/live_output/OutputFactory.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include "SmartPtr.h" 7 | #include "SmartHdr.h" 8 | #include "xstring.h" 9 | #include "SinkInterface.h" 10 | 11 | namespace Json { 12 | class Value; 13 | } 14 | struct event_base; 15 | class COutputFactory { 16 | public: 17 | COutputFactory(); 18 | ~COutputFactory(); 19 | 20 | public: 21 | static COutputFactory& singleton(); 22 | 23 | public: 24 | bool initialize(ISinkFactoryCallback* callback, bool usePlugin = true); 25 | bool handleRequest(ISinkHttpRequest* request); 26 | void statusInfo(Json::Value& info); 27 | void uninitialize(); 28 | 29 | protected: 30 | bool initPlugin(ISinkFactoryCallback* callback); 31 | 32 | protected: 33 | void loadPath(LPCTSTR path, ISinkFactoryCallback* callback); 34 | void loadFile(LPCTSTR file, ISinkFactoryCallback* callback); 35 | 36 | protected: 37 | typedef CSmartHdr CModulePtr; 38 | typedef CSmartPtr IFactoryPtr; 39 | 40 | private: 41 | std::vector m_vModules; 42 | std::recursive_mutex m_lkFactoried; 43 | std::vector m_vFactories; 44 | }; 45 | 46 | -------------------------------------------------------------------------------- /c++/Src/live_output/ReadMe.txt: -------------------------------------------------------------------------------- 1 | ======================================================================== 2 | 静态库:live_output 项目概述 3 | ======================================================================== 4 | 5 | 应用程序向导已为您创建了此 live_output 库项目。 6 | 7 | 没有为此项目创建源文件。 8 | 9 | 10 | live_output.vcxproj 11 | 这是使用应用程序向导生成的 VC++ 项目的主项目文件,其中包含生成该文件的 Visual C++ 的版本信息,以及有关使用应用程序向导选择的平台、配置和项目功能的信息。 12 | 13 | live_output.vcxproj.filters 14 | 这是使用“应用程序向导”生成的 VC++ 项目筛选器文件。它包含有关项目文件与筛选器之间的关联信息。在 IDE 中,通过这种关联,在特定节点下以分组形式显示具有相似扩展名的文件。例如,“.cpp”文件与“源文件”筛选器关联。 15 | 16 | ///////////////////////////////////////////////////////////////////////////// 17 | 其他注释: 18 | 19 | 应用程序向导使用“TODO:”注释来指示应添加或自定义的源代码部分。 20 | 21 | ///////////////////////////////////////////////////////////////////////////// 22 | -------------------------------------------------------------------------------- /c++/Src/live_output/SinkInterface.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yunsean/live/653fda0c4e444a94a4c8693a913faf92d356f595/c++/Src/live_output/SinkInterface.h -------------------------------------------------------------------------------- /c++/Src/live_output/live_output.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 头文件 23 | 24 | 25 | 头文件 26 | 27 | 28 | 29 | 30 | 源文件 31 | 32 | 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /c++/Src/live_rtmp/CommandMessage.cpp: -------------------------------------------------------------------------------- 1 | #include "CommandMessage.h" 2 | 3 | -------------------------------------------------------------------------------- /c++/Src/live_rtmp/DataMessage.cpp: -------------------------------------------------------------------------------- 1 | #include "DataMessage.h" 2 | 3 | -------------------------------------------------------------------------------- /c++/Src/live_rtmp/DataMessage.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "RtmpMessage.h" 3 | 4 | #define RTMP_AMF0_DATA_SET_DATAFRAME "@setDataFrame" 5 | #define RTMP_AMF0_DATA_ON_METADATA "onMetaData" 6 | 7 | template 8 | class CDataMessage : public CAmfxMessage { 9 | public: 10 | virtual ~CDataMessage() {} 11 | }; 12 | 13 | ////////////////////////////////////////////////////////////////////////// 14 | //Release Stream 15 | class COnMetadataRequest : public CDataMessage { 16 | public: 17 | std::string command; 18 | std::string name; 19 | CSmartPtr metadata; 20 | public: 21 | COnMetadataRequest() : command(RTMP_AMF0_DATA_SET_DATAFRAME), name(RTMP_AMF0_DATA_ON_METADATA), metadata(nullptr) {} 22 | MESSAGEPACKET_METHOD(command, name, (amf0::Amf0Any*&)metadata.GetPtr()); 23 | }; 24 | 25 | -------------------------------------------------------------------------------- /c++/Src/live_rtmp/HandshakeBytes.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include "SmartArr.h" 9 | 10 | class CHandshakeBytes { 11 | public: 12 | CHandshakeBytes(); 13 | ~CHandshakeBytes(); 14 | 15 | public: 16 | enum {Failed = -1, Succeed = 0, NeedMore = 1}; 17 | 18 | public: 19 | int read_c0c1(evbuffer* input); 20 | int read_s0s1s2(evbuffer* input); 21 | int read_c2(evbuffer* input); 22 | void create_c0c1(); 23 | void create_s0s1s2(const char* c1 = nullptr); 24 | void create_c2(); 25 | char* c0c1() { return m_c0c1; } 26 | char* s0s1s2() { return m_s0s1s2; } 27 | char* c2() { return m_c2; } 28 | 29 | private: 30 | void write_4bytes(char* bytes, int32_t value); 31 | 32 | private: 33 | CSmartArr m_c0c1; //[1 + 1536]; 34 | CSmartArr m_s0s1s2; //[1 + 1536 + 1536]; 35 | CSmartArr m_c2; //[1536]; 36 | }; 37 | 38 | -------------------------------------------------------------------------------- /c++/Src/live_rtmp/Makefile: -------------------------------------------------------------------------------- 1 | # Copyright (c) 1999 Apple Computer, Inc. All rights reserved. 2 | # 3 | 4 | NAME = liblive_rtmp 5 | STATICLIB = liblive_rtmp.a 6 | SHAREDLIB = liblive_rtmp.so 7 | C++ = gcc #$(CPLUS) 8 | CC = gcc #$(CCOMP) 9 | LINK = $(LINKER) 10 | 11 | COMPILER_FLAGS = -D_REENTRANT -D__USE_POSIX -D__linux__ -pipe 12 | INCLUDE_FLAG = -include 13 | CCFLAGS += $(COMPILER_FLAGS) -fPIC -g -Wall -Wno-deprecated -std=c++11 14 | 15 | # OPTIMIZATION 16 | #CCFLAGS += -O2 17 | 18 | # EACH DIRECTORY WITH HEADERS MUST BE APPENDED IN THIS MANNER TO THE CCFLAGS 19 | 20 | CCFLAGS += -I. 21 | CCFLAGS += -I.. 22 | CCFLAGS += -I../../linux/inc/ 23 | CCLIBS += -fPIC 24 | 25 | CXXLIBS += -L../../linux/lib -llive_logging -llive_common 26 | C++FLAGS = $(CCFLAGS) 27 | 28 | CFILES = 29 | 30 | CPPFILES = CommandMessage.cpp \ 31 | ComplexHandshake.cpp \ 32 | ControlMessage.cpp \ 33 | DataMessage.cpp \ 34 | HandshakeBytes.cpp \ 35 | ProtocolAmf0.cpp \ 36 | RtmpChunk.cpp \ 37 | RtmpHandshake.cpp \ 38 | RtmpMessage.cpp \ 39 | UserControlMessage.cpp 40 | 41 | all: $(SHAREDLIB) $(STATICLIB) 42 | 43 | $(SHAREDLIB): $(CFILES:.c=.o) $(CPPFILES:.cpp=.o) 44 | g++ -shared -fPIC -o $(SHAREDLIB) $(CFILES:.c=.o) $(CPPFILES:.cpp=.o) $(CCLIBS) 45 | mkdir -p ../../linux/bin 46 | cp -f $(SHAREDLIB) ../../linux/bin 47 | 48 | $(STATICLIB): $(CFILES:.c=.o) $(CPPFILES:.cpp=.o) 49 | ar -r $(STATICLIB) $(CFILES:.c=.o) $(CPPFILES:.cpp=.o) 50 | ranlib $(STATICLIB) 51 | mkdir -p ../../linux/lib 52 | cp -f $(STATICLIB) ../../linux/lib 53 | 54 | install: $(STATICLIB) 55 | clean: 56 | rm -f $(STATICLIB) $(SHAREDLIB) $(CFILES:.c=.o) $(CPPFILES:.cpp=.o) 57 | 58 | .SUFFIXES: .cpp .c .o 59 | 60 | .cpp.o: 61 | $(C++) -c -o $*.o $(DEFINES) $(C++FLAGS) $*.cpp 62 | 63 | .c.o: 64 | $(CC) -c -o $*.o $(DEFINES) $(CCFLAGS) $*.c 65 | 66 | 67 | -------------------------------------------------------------------------------- /c++/Src/live_rtmp/ReadMe.txt: -------------------------------------------------------------------------------- 1 | ======================================================================== 2 | 静态库:live_rtmp 项目概述 3 | ======================================================================== 4 | 5 | 应用程序向导已为您创建了此 live_rtmp 库项目。 6 | 7 | 没有为此项目创建源文件。 8 | 9 | 10 | live_rtmp.vcxproj 11 | 这是使用应用程序向导生成的 VC++ 项目的主项目文件,其中包含生成该文件的 Visual C++ 的版本信息,以及有关使用应用程序向导选择的平台、配置和项目功能的信息。 12 | 13 | live_rtmp.vcxproj.filters 14 | 这是使用“应用程序向导”生成的 VC++ 项目筛选器文件。它包含有关项目文件与筛选器之间的关联信息。在 IDE 中,通过这种关联,在特定节点下以分组形式显示具有相似扩展名的文件。例如,“.cpp”文件与“源文件”筛选器关联。 15 | 16 | ///////////////////////////////////////////////////////////////////////////// 17 | 其他注释: 18 | 19 | 应用程序向导使用“TODO:”注释来指示应添加或自定义的源代码部分。 20 | 21 | ///////////////////////////////////////////////////////////////////////////// 22 | -------------------------------------------------------------------------------- /c++/Src/live_rtmp/RtmpHandshake.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | enum HandshakeResult { 4 | HSRFailed = -1, HSRSucceed = 0, HSRNeedMore = 1, HSRTrySimple = 2 5 | }; 6 | 7 | struct evbuffer; 8 | interface CRtmpHandshake { 9 | virtual ~CRtmpHandshake() {} 10 | virtual HandshakeResult handshakeWithClient(CHandshakeBytes* bytes, evbuffer* input, evbuffer* output) = 0; 11 | virtual HandshakeResult handshakeWithServer(CHandshakeBytes* bytes, evbuffer* input, evbuffer* output) = 0; 12 | }; 13 | 14 | class CHandshakeBytes; 15 | class CSimpleHandshake : public CRtmpHandshake { 16 | public: 17 | CSimpleHandshake(); 18 | virtual ~CSimpleHandshake(); 19 | public: 20 | virtual HandshakeResult handshakeWithClient(CHandshakeBytes* bytes, evbuffer* input, evbuffer* output); 21 | virtual HandshakeResult handshakeWithServer(CHandshakeBytes* bytes, evbuffer* input, evbuffer* output); 22 | private: 23 | enum WorkStage { Inited, ReadC0C1, ReadC2, ReadS0S1S2, Succeed }; 24 | WorkStage m_workStage; 25 | }; 26 | 27 | // http://blog.csdn.net/win_lin/article/details/13006803 28 | namespace rtmp_handshake { 29 | class c1s1; 30 | } 31 | class CComplexHandshake : public CRtmpHandshake { 32 | public: 33 | CComplexHandshake(); 34 | virtual ~CComplexHandshake(); 35 | public: 36 | virtual HandshakeResult handshakeWithClient(CHandshakeBytes* bytes, evbuffer* input, evbuffer* output); 37 | virtual HandshakeResult handshakeWithServer(CHandshakeBytes* bytes, evbuffer* input, evbuffer* output); 38 | private: 39 | enum WorkStage { Inited, ReadC0C1, ReadC2, ReadS0S1S2, Succeed }; 40 | rtmp_handshake::c1s1* m_c1; 41 | WorkStage m_workStage; 42 | }; 43 | -------------------------------------------------------------------------------- /c++/Src/live_rtmp/RtmpMessage.cpp: -------------------------------------------------------------------------------- 1 | #include "RtmpMessage.h" 2 | #include "ByteStream.h" 3 | #include "RtmpConstants.h" 4 | #include "ProtocolAmf0.h" 5 | #include "Writelog.h" 6 | #include "RtmpChunk.h" 7 | using namespace amf0; 8 | 9 | bool CRtmpMessage::encode(uint32_t& size, uint8_t*& payload) { 10 | int length(totalSize()); 11 | uint8_t* data = NULL; 12 | if (length > 0) { 13 | data = new uint8_t[length]; 14 | CByteStream stream(data, length); 15 | if (!encode(&stream)) return false; 16 | } 17 | size = length; 18 | payload = data; 19 | return true; 20 | } 21 | -------------------------------------------------------------------------------- /c++/Src/live_rtmp2/Makefile: -------------------------------------------------------------------------------- 1 | # Copyright (c) 1999 Apple Computer, Inc. All rights reserved. 2 | # 3 | 4 | NAME = liblive_rtmp2 5 | STATICLIB = liblive_rtmp2.a 6 | SHAREDLIB = liblive_rtmp2.so 7 | C++ = gcc #$(CPLUS) 8 | CC = gcc #$(CCOMP) 9 | LINK = $(LINKER) 10 | 11 | COMPILER_FLAGS = -D_REENTRANT -D__USE_POSIX -D__linux__ -pipe 12 | INCLUDE_FLAG = -include 13 | CCFLAGS += $(COMPILER_FLAGS) -fPIC -g -Wall -Wno-deprecated -std=c++11 14 | 15 | # OPTIMIZATION 16 | #CCFLAGS += -O2 17 | 18 | # EACH DIRECTORY WITH HEADERS MUST BE APPENDED IN THIS MANNER TO THE CCFLAGS 19 | 20 | CCFLAGS += -I. 21 | CCFLAGS += -I.. 22 | CCFLAGS += -I../../linux/inc/ 23 | CCLIBS += -fPIC 24 | 25 | CXXLIBS += -L../../linux/lib -llive_logging -llive_common 26 | CCFLAGS += -DNO_CRYPTO 27 | C++FLAGS = $(CCFLAGS) 28 | 29 | CFILES = rtmp.c \ 30 | 31 | CPPFILES = amf.cpp \ 32 | log.cpp \ 33 | Metadata.cpp \ 34 | parseurl.cpp \ 35 | Publisher.cpp \ 36 | Rtmp2Publisher.cpp 37 | 38 | all: $(SHAREDLIB) $(STATICLIB) 39 | 40 | $(SHAREDLIB): $(CFILES:.c=.o) $(CPPFILES:.cpp=.o) 41 | g++ -shared -fPIC -o $(SHAREDLIB) $(CFILES:.c=.o) $(CPPFILES:.cpp=.o) $(CCLIBS) 42 | mkdir -p ../../linux/bin 43 | cp -f $(SHAREDLIB) ../../linux/bin 44 | 45 | $(STATICLIB): $(CFILES:.c=.o) $(CPPFILES:.cpp=.o) 46 | ar -r $(STATICLIB) $(CFILES:.c=.o) $(CPPFILES:.cpp=.o) 47 | ranlib $(STATICLIB) 48 | mkdir -p ../../linux/lib 49 | cp -f $(STATICLIB) ../../linux/lib 50 | mkdir -p ../../linux/inc 51 | cp -f Publisher.h ../../linux/inc/ 52 | 53 | install: $(STATICLIB) 54 | clean: 55 | rm -f $(STATICLIB) $(SHAREDLIB) $(CFILES:.c=.o) $(CPPFILES:.cpp=.o) 56 | 57 | .SUFFIXES: .cpp .c .o 58 | 59 | .cpp.o: 60 | $(C++) -c -o $*.o $(DEFINES) $(C++FLAGS) $*.cpp 61 | 62 | .c.o: 63 | $(CC) -c -o $*.o $(DEFINES) $(CCFLAGS) $*.c 64 | 65 | 66 | -------------------------------------------------------------------------------- /c++/Src/live_rtmp2/Metadata.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Byte.h" 3 | 4 | typedef struct RTMPMetadata { 5 | bool hasVideo; 6 | unsigned int width; 7 | unsigned int height; 8 | unsigned int frameRate; 9 | unsigned int videoBitRate; 10 | unsigned int spsLen; 11 | unsigned char sps[1024]; 12 | unsigned int ppsLen; 13 | unsigned char pps[1024]; 14 | 15 | bool hasAudio; 16 | unsigned int sampleRate; 17 | unsigned int audioBitRate; 18 | unsigned int channels; 19 | unsigned int esdsLen; 20 | unsigned char esds[10]; 21 | 22 | } *LPRTMPMetadata; 23 | 24 | class CMetadata { 25 | public: 26 | CMetadata(void); 27 | ~CMetadata(void); 28 | 29 | public: 30 | enum { 31 | FLV_CODECID_AVC = 7, 32 | FLV_CODECID_AAC = 10, 33 | FLV_CODECID_MP3 = 2, 34 | }; 35 | 36 | public: 37 | static void onMetadata(LPRTMPMetadata lpMetaData, CByte& body); 38 | 39 | protected: 40 | static char* put_byte(char* output, uint8_t nVal); 41 | static char* put_be16(char* output, uint16_t nVal); 42 | static char* put_be24(char* output, uint32_t nVal); 43 | static char* put_be32(char* output, uint32_t nVal); 44 | static char* put_be64(char* output, uint64_t nVal); 45 | static char* put_amf_string(char* c, const char* str); 46 | static char* put_amf_double(char* c, double d); 47 | }; -------------------------------------------------------------------------------- /c++/Src/live_rtmp2/Publisher.cpp: -------------------------------------------------------------------------------- 1 | #include "Publisher.h" 2 | #include "Rtmp2Publisher.h" 3 | 4 | CPublisher::CPublisher(const std::function& callback /*= nullptr*/) 5 | : m_publisher(new CRtmp2Publisher(callback)){ 6 | } 7 | CPublisher::~CPublisher() { 8 | delete m_publisher; 9 | } 10 | 11 | void CPublisher::setupVideo(const int width, const int height, const unsigned char* sps, const int szSps, const unsigned char* pps, const int szPps) { 12 | return m_publisher->setupVideo(width, height, sps, szSps, pps, szPps); 13 | } 14 | void CPublisher::setupAudio(int channels, int sampleRate, const unsigned char* esds, const int szEsds) { 15 | return m_publisher->setupAudio(channels, sampleRate, esds, szEsds); 16 | } 17 | void CPublisher::appendVideo(const unsigned char* datas, int length, long timecode, bool isKey, bool isNal /*= false*/, bool waitBlock /*= false*/) { 18 | return m_publisher->appendVideo(datas, length, timecode, isKey, isNal, waitBlock); 19 | } 20 | void CPublisher::appendAudio(const unsigned char* datas, int length, long timecode, bool waitBlock /*= false*/) { 21 | return m_publisher->appendAudio(datas, length, timecode, waitBlock); 22 | } 23 | bool CPublisher::connect(const char* url) { 24 | return m_publisher->connect(url); 25 | } 26 | void CPublisher::disconnect() { 27 | return m_publisher->disconnect(); 28 | } 29 | void CPublisher::cleanup() { 30 | return m_publisher->cleanup(); 31 | } 32 | -------------------------------------------------------------------------------- /c++/Src/live_rtmp2/Publisher.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | #ifdef _WIN32 5 | #ifdef LIVE_RTMP2_EXPORTS 6 | #define RTMP2_API __declspec(dllexport) 7 | #else 8 | #define RTMP2_API __declspec(dllimport) 9 | #endif 10 | #else 11 | #define RTMP2_API 12 | #endif 13 | 14 | class CRtmp2Publisher; 15 | class RTMP2_API CPublisher { 16 | public: 17 | CPublisher(const std::function& callback = nullptr); 18 | ~CPublisher(); 19 | 20 | public: 21 | void setupVideo(const int width, const int height, const unsigned char* sps, const int szSps, const unsigned char* pps, const int szPps); 22 | void setupAudio(int channels, int sampleRate, const unsigned char* esds, const int szEsds); 23 | bool connect(const char* url); 24 | void appendVideo(const unsigned char* datas, int length, long timecode, bool isKey, bool isNal = false, bool waitBlock = false); 25 | void appendAudio(const unsigned char* datas, int length, long timecode, bool waitBlock = false); 26 | void disconnect(); 27 | void cleanup(); 28 | 29 | private: 30 | CRtmp2Publisher* m_publisher; 31 | }; 32 | 33 | -------------------------------------------------------------------------------- /c++/Src/live_rtmp2/ReadMe.txt: -------------------------------------------------------------------------------- 1 | ======================================================================== 2 | 动态链接库:live_rtmp2 项目概述 3 | ======================================================================== 4 | 5 | 应用程序向导已为您创建了此 live_rtmp2 DLL。 6 | 7 | 本文件概要介绍组成 live_rtmp2 应用程序的每个文件的内容。 8 | 9 | 10 | live_rtmp2.vcxproj 11 | 这是使用应用程序向导生成的 VC++ 项目的主项目文件,其中包含生成该文件的 Visual C++ 的版本信息,以及有关使用应用程序向导选择的平台、配置和项目功能的信息。 12 | 13 | live_rtmp2.vcxproj.filters 14 | 这是使用“应用程序向导”生成的 VC++ 项目筛选器文件。它包含有关项目文件与筛选器之间的关联信息。在 IDE 中,通过这种关联,在特定节点下以分组形式显示具有相似扩展名的文件。例如,“.cpp”文件与“源文件”筛选器关联。 15 | 16 | live_rtmp2.cpp 17 | 这是主 DLL 源文件。 18 | 19 | 此 DLL 在创建时不导出任何符号。因此,生成时不会产生 .lib 文件。如果希望此项目成为其他某个项目的项目依赖项,则需要添加代码以从 DLL 导出某些符号,以便产生一个导出库,或者,也可以在项目“属性页”对话框中的“链接器”文件夹中,将“常规”属性页上的“忽略输入库”属性设置为“是”。 20 | 21 | ///////////////////////////////////////////////////////////////////////////// 22 | 其他标准文件: 23 | 24 | StdAfx.h, StdAfx.cpp 25 | 这些文件用于生成名为 live_rtmp2.pch 的预编译头 (PCH) 文件和名为 StdAfx.obj 的预编译类型文件。 26 | 27 | ///////////////////////////////////////////////////////////////////////////// 28 | 其他注释: 29 | 30 | 应用程序向导使用“TODO:”注释来指示应添加或自定义的源代码部分。 31 | 32 | ///////////////////////////////////////////////////////////////////////////// 33 | -------------------------------------------------------------------------------- /c++/Src/live_rtmp2/copy_x64.bat: -------------------------------------------------------------------------------- 1 | md ..\..\x64\inc\ 2 | copy Publisher.h ..\..\x64\inc\ -------------------------------------------------------------------------------- /c++/Src/live_rtmp2/copy_x86.bat: -------------------------------------------------------------------------------- 1 | md ..\..\x86\inc\ 2 | copy Publisher.h ..\..\x86\inc\ -------------------------------------------------------------------------------- /c++/Src/live_rtmp2/dllmain.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yunsean/live/653fda0c4e444a94a4c8693a913faf92d356f595/c++/Src/live_rtmp2/dllmain.cpp -------------------------------------------------------------------------------- /c++/Src/live_rtmp2/http.h: -------------------------------------------------------------------------------- 1 | #ifndef __RTMP_HTTP_H__ 2 | #define __RTMP_HTTP_H__ 3 | /* 4 | * Copyright (C) 2010 Howard Chu 5 | * Copyright (C) 2010 Antti Ajanki 6 | * 7 | * This file is part of librtmp. 8 | * 9 | * librtmp is free software; you can redistribute it and/or modify 10 | * it under the terms of the GNU Lesser General Public License as 11 | * published by the Free Software Foundation; either version 2.1, 12 | * or (at your option) any later version. 13 | * 14 | * librtmp is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public License 20 | * along with librtmp see the file COPYING. If not, write to 21 | * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 22 | * Boston, MA 02110-1301, USA. 23 | * http://www.gnu.org/copyleft/lgpl.html 24 | */ 25 | 26 | typedef enum { 27 | HTTPRES_OK, /* result OK */ 28 | HTTPRES_OK_NOT_MODIFIED, /* not modified since last request */ 29 | HTTPRES_NOT_FOUND, /* not found */ 30 | HTTPRES_BAD_REQUEST, /* client error */ 31 | HTTPRES_SERVER_ERROR, /* server reported an error */ 32 | HTTPRES_REDIRECTED, /* resource has been moved */ 33 | HTTPRES_LOST_CONNECTION /* connection lost while waiting for data */ 34 | } HTTPResult; 35 | 36 | struct HTTP_ctx { 37 | char *date; 38 | int size; 39 | int status; 40 | void *data; 41 | }; 42 | 43 | typedef size_t (HTTP_read_callback)(void *ptr, size_t size, size_t nmemb, void *stream); 44 | 45 | HTTPResult HTTP_get(struct HTTP_ctx *http, const char *url, HTTP_read_callback *cb); 46 | 47 | #endif 48 | -------------------------------------------------------------------------------- /c++/Src/live_rtmp2/live_rtmp2.def: -------------------------------------------------------------------------------- 1 | LIBRARY 2 | EXPORTS 3 | -------------------------------------------------------------------------------- /c++/Src/live_sink_file/FileFactory.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include "SinkInterface.h" 13 | #include "FileWriter.h" 14 | #include "SmartHdr.h" 15 | #include "SmartPtr.h" 16 | 17 | class CFileFactory : public ISinkFactory { 18 | public: 19 | CFileFactory(); 20 | ~CFileFactory(); 21 | 22 | public: 23 | static CFileFactory& singleton(); 24 | 25 | public: 26 | void removeWriter(CFileWriter* writer); 27 | xtstring getMime(const xtstring& file); 28 | 29 | protected: 30 | virtual LPCTSTR FactoryName() const; 31 | virtual bool Initialize(ISinkFactoryCallback* callback); 32 | virtual int HandleSort() { return 100; } 33 | virtual bool HandleRequest(ISinkHttpRequest* request); 34 | virtual bool GetStatusInfo(LPSTR* json, void(**free)(LPSTR)); 35 | virtual void Uninitialize(); 36 | virtual void Destroy(); 37 | 38 | private: 39 | void loadMimes(); 40 | 41 | private: 42 | static unsigned int m_lLicenseCount; 43 | static std::atomic m_lInvokeCount; 44 | static std::atomic m_lPlayingCount; 45 | static std::atomic m_lTotalReceived; 46 | static std::atomic m_lTotalSend; 47 | 48 | protected: 49 | typedef CSmartPtr CWriterPtr; 50 | 51 | private: 52 | const LPCTSTR m_lpszFactoryName; 53 | std::map m_mappers; 54 | std::map m_mimes; 55 | std::mutex m_mutex; 56 | std::list m_writers; 57 | std::list m_defaultFile; 58 | }; 59 | 60 | -------------------------------------------------------------------------------- /c++/Src/live_sink_file/FileWriter.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include 5 | #include "HttpClient.h" 6 | #include "SinkInterface.h" 7 | #include "H264Utility.h" 8 | #include "json/value.h" 9 | #include "xstring.h" 10 | #include "Byte.h" 11 | #include "xsystem.h" 12 | #include "SmartHdr.h" 13 | 14 | struct event; 15 | struct event_base; 16 | class CHttpClient; 17 | class CFileWriter { 18 | public: 19 | CFileWriter(const xtstring& path); 20 | ~CFileWriter(); 21 | 22 | public: 23 | bool Open(); 24 | bool Startup(ISinkHttpRequest* request); 25 | const xtstring& GetMoniker() const { return m_strMoniker; } 26 | 27 | protected: 28 | std::string GetHttpSucceedResponse(ISinkHttpRequest* request, const xtstring& contentType = _T("text/html")); 29 | 30 | protected: 31 | static void on_write(struct bufferevent* event, void* context); 32 | static void on_error(struct bufferevent* event, short what, void* context); 33 | void on_write(struct bufferevent* event); 34 | void on_error(struct bufferevent* event, short what); 35 | 36 | private: 37 | const xtstring m_strMoniker; 38 | CSmartHdr m_bev; 39 | CSmartHdr m_file; 40 | std::unique_ptr m_cache; 41 | }; 42 | 43 | -------------------------------------------------------------------------------- /c++/Src/live_sink_file/Makefile: -------------------------------------------------------------------------------- 1 | # Copyright (c) 1999 Apple Computer, Inc. All rights reserved. 2 | # 3 | 4 | NAME = liblive_sink_file 5 | STATICLIB = liblive_sink_file.a 6 | SHAREDLIB = liblive_sink_file.so 7 | C++ = gcc #$(CPLUS) 8 | CC = gcc #$(CCOMP) 9 | LINK = $(LINKER) 10 | 11 | COMPILER_FLAGS = -D_REENTRANT -D__USE_POSIX -D__linux__ -pipe 12 | INCLUDE_FLAG = -include 13 | CCFLAGS += $(COMPILER_FLAGS) -fPIC -g -Wall -Wno-deprecated -std=c++11 14 | 15 | # OPTIMIZATION 16 | #CCFLAGS += -O2 17 | 18 | # EACH DIRECTORY WITH HEADERS MUST BE APPENDED IN THIS MANNER TO THE CCFLAGS 19 | 20 | CCFLAGS += -I. 21 | CCFLAGS += -I.. 22 | CCFLAGS += -I../../linux/inc 23 | CCFLAGS += -I../live_output 24 | 25 | C++FLAGS = $(CCFLAGS) 26 | 27 | CXXLIBS += -L../../linux/lib -llive_vpf -llive_input -llive_logging -llive_media -llive_common -llive_literal 28 | CXXLIBS += -L../../linux/lib -levent -levent_core -levent_pthreads 29 | CXXLIBS += -L./usr/local/lib -lpthread -ldl -fPIC 30 | 31 | CFILES = 32 | 33 | CPPFILES = live_sink_file.cpp \ 34 | FileFactory.cpp \ 35 | FileWriter.cpp 36 | 37 | all: $(SHAREDLIB) $(STATICLIB) 38 | 39 | #-shared 40 | $(SHAREDLIB): $(CFILES:.c=.o) $(CPPFILES:.cpp=.o) 41 | g++ -shared -fPIC -o $(SHAREDLIB) $(CFILES:.c=.o) $(CPPFILES:.cpp=.o) $(CXXLIBS) 42 | mkdir -p ../../linux/bin 43 | cp -f $(SHAREDLIB) ../../linux/bin 44 | mkdir -p ../live_gateway/Plugin/sink/ 45 | cp -f $(SHAREDLIB) ../live_gateway/Plugin/sink/ 46 | 47 | $(STATICLIB): $(CFILES:.c=.o) $(CPPFILES:.cpp=.o) 48 | ar -r $(STATICLIB) $(CFILES:.c=.o) $(CPPFILES:.cpp=.o) 49 | ranlib $(STATICLIB) 50 | mkdir -p ../../linux/lib 51 | cp -f $(STATICLIB) ../../linux/lib 52 | mkdir -p ../../linux/inc 53 | 54 | install: $(STATICLIB) 55 | clean: 56 | rm -f $(STATICLIB) $(SHAREDLIB) $(CFILES:.c=.o) $(CPPFILES:.cpp=.o) 57 | 58 | .SUFFIXES: .cpp .c .o 59 | 60 | .cpp.o: 61 | $(C++) -c -o $*.o $(DEFINES) $(C++FLAGS) $*.cpp 62 | 63 | .c.o: 64 | $(CC) -c -o $*.o $(DEFINES) $(CCFLAGS) $*.c 65 | 66 | 67 | -------------------------------------------------------------------------------- /c++/Src/live_sink_file/live_sink_file.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yunsean/live/653fda0c4e444a94a4c8693a913faf92d356f595/c++/Src/live_sink_file/live_sink_file.cpp -------------------------------------------------------------------------------- /c++/Src/live_sink_file/live_sink_file.def: -------------------------------------------------------------------------------- 1 | LIBRARY 2 | EXPORTS 3 | GetSinkFactory 4 | -------------------------------------------------------------------------------- /c++/Src/live_sink_file/live_sink_file.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | 源文件 20 | 21 | 22 | 源文件 23 | 24 | 25 | 源文件 26 | 27 | 28 | 29 | 30 | 头文件 31 | 32 | 33 | 头文件 34 | 35 | 36 | 37 | 38 | 源文件 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /c++/Src/live_sink_flv/FlvFactory.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include "SinkInterface.h" 11 | #include "FlvWriter.h" 12 | #include "SmartHdr.h" 13 | #include "SmartPtr.h" 14 | 15 | class CFlvFactory : public ISinkFactory { 16 | public: 17 | CFlvFactory(); 18 | ~CFlvFactory(); 19 | 20 | public: 21 | static CFlvFactory& singleton(); 22 | 23 | public: 24 | static void AddPlayingCount(); 25 | static void DelPlayingCount(); 26 | static void AddTotalDataSize(uint64_t received, uint64_t send); 27 | static void UpdateTitle(); 28 | 29 | public: 30 | bool bindWriter(ISinkHttpRequest* client, const xtstring& device, const xtstring& moniker, const xtstring& params); 31 | void unbindWriter(CFlvWriter* writer); 32 | 33 | protected: 34 | virtual LPCTSTR FactoryName() const; 35 | virtual bool Initialize(ISinkFactoryCallback* callback); 36 | virtual int HandleSort() { return 0; } 37 | virtual bool HandleRequest(ISinkHttpRequest* request); 38 | virtual bool GetStatusInfo(LPSTR* json, void(**free)(LPSTR)); 39 | virtual void Uninitialize(); 40 | virtual void Destroy(); 41 | 42 | private: 43 | static unsigned int m_lLicenseCount; 44 | static std::atomic m_lInvokeCount; 45 | static std::atomic m_lPlayingCount; 46 | static std::atomic m_lTotalReceived; 47 | static std::atomic m_lTotalSend; 48 | 49 | protected: 50 | typedef CSmartPtr CWriterPtr; 51 | 52 | private: 53 | const LPCTSTR m_lpszFactoryName; 54 | ISinkFactoryCallback* m_lpCallback; 55 | 56 | std::recursive_mutex m_lkWriters; 57 | std::map m_liveWriter; 58 | }; 59 | 60 | -------------------------------------------------------------------------------- /c++/Src/live_sink_flv/Makefile: -------------------------------------------------------------------------------- 1 | # Copyright (c) 1999 Apple Computer, Inc. All rights reserved. 2 | # 3 | 4 | NAME = liblive_sink_flv 5 | STATICLIB = liblive_sink_flv.a 6 | SHAREDLIB = liblive_sink_flv.so 7 | C++ = gcc #$(CPLUS) 8 | CC = gcc #$(CCOMP) 9 | LINK = $(LINKER) 10 | 11 | COMPILER_FLAGS = -D_REENTRANT -D__USE_POSIX -D__linux__ -pipe 12 | INCLUDE_FLAG = -include 13 | CCFLAGS += $(COMPILER_FLAGS) -fPIC -g -Wall -Wno-deprecated -std=c++11 14 | 15 | # OPTIMIZATION 16 | #CCFLAGS += -O2 17 | 18 | # EACH DIRECTORY WITH HEADERS MUST BE APPENDED IN THIS MANNER TO THE CCFLAGS 19 | 20 | CCFLAGS += -I. 21 | CCFLAGS += -I.. 22 | CCFLAGS += -I../../linux/inc 23 | CCFLAGS += -I../live_output 24 | 25 | C++FLAGS = $(CCFLAGS) 26 | 27 | CXXLIBS += -L../../linux/lib -llive_vpf -llive_input -llive_logging -llive_media -llive_common -llive_literal 28 | CXXLIBS += -L../../linux/lib -levent -levent_core -levent_pthreads 29 | CXXLIBS += -L./usr/local/lib -lpthread -ldl -fPIC 30 | 31 | CFILES = 32 | 33 | CPPFILES = live_sink_flv.cpp \ 34 | FlvFactory.cpp \ 35 | FlvWriter.cpp 36 | 37 | all: $(SHAREDLIB) $(STATICLIB) 38 | 39 | #-shared 40 | $(SHAREDLIB): $(CFILES:.c=.o) $(CPPFILES:.cpp=.o) 41 | g++ -shared -fPIC -o $(SHAREDLIB) $(CFILES:.c=.o) $(CPPFILES:.cpp=.o) $(CXXLIBS) 42 | mkdir -p ../../linux/bin 43 | cp -f $(SHAREDLIB) ../../linux/bin 44 | mkdir -p ../live_gateway/Plugin/sink/ 45 | cp -f $(SHAREDLIB) ../live_gateway/Plugin/sink/ 46 | 47 | $(STATICLIB): $(CFILES:.c=.o) $(CPPFILES:.cpp=.o) 48 | ar -r $(STATICLIB) $(CFILES:.c=.o) $(CPPFILES:.cpp=.o) 49 | ranlib $(STATICLIB) 50 | mkdir -p ../../linux/lib 51 | cp -f $(STATICLIB) ../../linux/lib 52 | mkdir -p ../../linux/inc 53 | 54 | install: $(STATICLIB) 55 | clean: 56 | rm -f $(STATICLIB) $(SHAREDLIB) $(CFILES:.c=.o) $(CPPFILES:.cpp=.o) 57 | 58 | .SUFFIXES: .cpp .c .o 59 | 60 | .cpp.o: 61 | $(C++) -c -o $*.o $(DEFINES) $(C++FLAGS) $*.cpp 62 | 63 | .c.o: 64 | $(CC) -c -o $*.o $(DEFINES) $(CCFLAGS) $*.c 65 | 66 | 67 | -------------------------------------------------------------------------------- /c++/Src/live_sink_flv/live_sink_flv.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yunsean/live/653fda0c4e444a94a4c8693a913faf92d356f595/c++/Src/live_sink_flv/live_sink_flv.cpp -------------------------------------------------------------------------------- /c++/Src/live_sink_flv/live_sink_flv.def: -------------------------------------------------------------------------------- 1 | LIBRARY 2 | EXPORTS 3 | GetSinkFactory 4 | -------------------------------------------------------------------------------- /c++/Src/live_sink_flv/live_sink_flv.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | 源文件 20 | 21 | 22 | 23 | 24 | 25 | 源文件 26 | 27 | 28 | 源文件 29 | 30 | 31 | 源文件 32 | 33 | 34 | 35 | 36 | 头文件 37 | 38 | 39 | 头文件 40 | 41 | 42 | -------------------------------------------------------------------------------- /c++/Src/live_sink_raw/ClientProxy.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include "HttpClient.h" 5 | 6 | class CClientProxy : public CHttpClient { 7 | public: 8 | CClientProxy(); 9 | ~CClientProxy(); 10 | 11 | public: 12 | static CClientProxy* newInstance(evutil_socket_t fd, struct sockaddr* addr); 13 | 14 | public: 15 | virtual void release(); 16 | 17 | protected: 18 | static std::mutex m_mutex; 19 | static std::queue m_clients; 20 | 21 | protected: 22 | virtual void handle(); 23 | 24 | protected: 25 | void onSystemInfo(); 26 | void onStreamList(); 27 | void onPlayStream(); 28 | }; 29 | 30 | -------------------------------------------------------------------------------- /c++/Src/live_sink_raw/Makefile: -------------------------------------------------------------------------------- 1 | # Copyright (c) 1999 Apple Computer, Inc. All rights reserved. 2 | # 3 | 4 | NAME = liblive_sink_raw 5 | STATICLIB = liblive_sink_raw.a 6 | SHAREDLIB = liblive_sink_raw.so 7 | C++ = gcc #$(CPLUS) 8 | CC = gcc #$(CCOMP) 9 | LINK = $(LINKER) 10 | 11 | COMPILER_FLAGS = -D_REENTRANT -D__USE_POSIX -D__linux__ -pipe 12 | INCLUDE_FLAG = -include 13 | CCFLAGS += $(COMPILER_FLAGS) -fPIC -g -Wall -Wno-deprecated -std=c++11 14 | 15 | # OPTIMIZATION 16 | #CCFLAGS += -O2 17 | 18 | # EACH DIRECTORY WITH HEADERS MUST BE APPENDED IN THIS MANNER TO THE CCFLAGS 19 | 20 | CCFLAGS += -I. 21 | CCFLAGS += -I.. 22 | CCFLAGS += -I../../linux/inc 23 | CCFLAGS += -I../live_output 24 | 25 | C++FLAGS = $(CCFLAGS) 26 | 27 | CXXLIBS += -L../../linux/lib -llive_output -llive_logging -llive_media -llive_common -llive_literal -llive_network 28 | CXXLIBS += -L../../linux/lib -levent -levent_core -levent_pthreads 29 | CXXLIBS += -L./usr/local/lib -lpthread -ldl -fPIC 30 | 31 | CFILES = 32 | 33 | CPPFILES = live_sink_raw.cpp \ 34 | ClientProxy.cpp \ 35 | RawFactory.cpp \ 36 | RawWriter.cpp 37 | 38 | all: $(SHAREDLIB) $(STATICLIB) 39 | 40 | #-shared 41 | $(SHAREDLIB): $(CFILES:.c=.o) $(CPPFILES:.cpp=.o) 42 | g++ -shared -fPIC -o $(SHAREDLIB) $(CFILES:.c=.o) $(CPPFILES:.cpp=.o) $(CXXLIBS) 43 | mkdir -p ../../linux/bin 44 | cp -f $(SHAREDLIB) ../../linux/bin 45 | mkdir -p ../live_gateway/Plugin/sink/ 46 | cp -f $(SHAREDLIB) ../live_gateway/Plugin/sink/ 47 | 48 | $(STATICLIB): $(CFILES:.c=.o) $(CPPFILES:.cpp=.o) 49 | ar -r $(STATICLIB) $(CFILES:.c=.o) $(CPPFILES:.cpp=.o) 50 | ranlib $(STATICLIB) 51 | mkdir -p ../../linux/lib 52 | cp -f $(STATICLIB) ../../linux/lib 53 | mkdir -p ../../linux/inc 54 | 55 | install: $(STATICLIB) 56 | clean: 57 | rm -f $(STATICLIB) $(SHAREDLIB) $(CFILES:.c=.o) $(CPPFILES:.cpp=.o) 58 | 59 | .SUFFIXES: .cpp .c .o 60 | 61 | .cpp.o: 62 | $(C++) -c -o $*.o $(DEFINES) $(C++FLAGS) $*.cpp 63 | 64 | .c.o: 65 | $(CC) -c -o $*.o $(DEFINES) $(CCFLAGS) $*.c 66 | 67 | 68 | -------------------------------------------------------------------------------- /c++/Src/live_sink_raw/ReadMe.txt: -------------------------------------------------------------------------------- 1 | ======================================================================== 2 | 动态链接库:live_sink_raw 项目概述 3 | ======================================================================== 4 | 5 | 应用程序向导已为您创建了此 live_sink_raw DLL。 6 | 7 | 本文件概要介绍组成 live_sink_raw 应用程序的每个文件的内容。 8 | 9 | 10 | live_sink_raw.vcxproj 11 | 这是使用应用程序向导生成的 VC++ 项目的主项目文件,其中包含生成该文件的 Visual C++ 的版本信息,以及有关使用应用程序向导选择的平台、配置和项目功能的信息。 12 | 13 | live_sink_raw.vcxproj.filters 14 | 这是使用“应用程序向导”生成的 VC++ 项目筛选器文件。它包含有关项目文件与筛选器之间的关联信息。在 IDE 中,通过这种关联,在特定节点下以分组形式显示具有相似扩展名的文件。例如,“.cpp”文件与“源文件”筛选器关联。 15 | 16 | live_sink_raw.cpp 17 | 这是主 DLL 源文件。 18 | 19 | 此 DLL 在创建时不导出任何符号。因此,生成时不会产生 .lib 文件。如果希望此项目成为其他某个项目的项目依赖项,则需要添加代码以从 DLL 导出某些符号,以便产生一个导出库,或者,也可以在项目“属性页”对话框中的“链接器”文件夹中,将“常规”属性页上的“忽略输入库”属性设置为“是”。 20 | 21 | ///////////////////////////////////////////////////////////////////////////// 22 | 其他标准文件: 23 | 24 | StdAfx.h, StdAfx.cpp 25 | 这些文件用于生成名为 live_sink_raw.pch 的预编译头 (PCH) 文件和名为 StdAfx.obj 的预编译类型文件。 26 | 27 | ///////////////////////////////////////////////////////////////////////////// 28 | 其他注释: 29 | 30 | 应用程序向导使用“TODO:”注释来指示应添加或自定义的源代码部分。 31 | 32 | ///////////////////////////////////////////////////////////////////////////// 33 | -------------------------------------------------------------------------------- /c++/Src/live_sink_raw/dllmain.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yunsean/live/653fda0c4e444a94a4c8693a913faf92d356f595/c++/Src/live_sink_raw/dllmain.cpp -------------------------------------------------------------------------------- /c++/Src/live_sink_raw/live_sink_raw.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yunsean/live/653fda0c4e444a94a4c8693a913faf92d356f595/c++/Src/live_sink_raw/live_sink_raw.cpp -------------------------------------------------------------------------------- /c++/Src/live_sink_raw/live_sink_raw.def: -------------------------------------------------------------------------------- 1 | LIBRARY 2 | EXPORTS 3 | GetSinkFactory 4 | -------------------------------------------------------------------------------- /c++/Src/live_sink_raw/live_sink_raw.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 源文件 23 | 24 | 25 | 源文件 26 | 27 | 28 | 源文件 29 | 30 | 31 | 源文件 32 | 33 | 34 | 源文件 35 | 36 | 37 | 38 | 39 | 源文件 40 | 41 | 42 | 43 | 44 | 45 | 头文件 46 | 47 | 48 | 头文件 49 | 50 | 51 | 头文件 52 | 53 | 54 | -------------------------------------------------------------------------------- /c++/Src/live_source_file/FileFactory.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "SourceInterface.h" 3 | #include "xstring.h" 4 | 5 | class CFileFactory : public ISourceFactory { 6 | public: 7 | CFileFactory(); 8 | ~CFileFactory(); 9 | 10 | public: 11 | virtual LPCTSTR FactoryName() const; 12 | virtual bool Initialize(ISourceFactoryCallback* callback); 13 | virtual SupportState DidSupport(LPCTSTR device, LPCTSTR moniker, LPCTSTR param); 14 | virtual ISourceProxy* CreateLiveProxy(ISourceProxyCallback* callback, LPCTSTR device, LPCTSTR moniker, LPCTSTR param); 15 | virtual ISourceProxy* CreatePastProxy(ISourceProxyCallback* callback, LPCTSTR device, LPCTSTR moniker, LPCTSTR param, uint64_t beginTime, uint64_t endTime = 0); 16 | virtual bool GetSourceList(LPTSTR* xml, void(**free)(LPTSTR), bool onlineOnly, LPCTSTR device = NULL); 17 | virtual bool GetStatusInfo(LPSTR* json, void(**free)(LPSTR)); 18 | virtual void Uninitialize(); 19 | virtual void Destroy(); 20 | 21 | private: 22 | const LPCTSTR m_lpszFactoryName; 23 | xtstring m_strRootPath; 24 | }; 25 | 26 | -------------------------------------------------------------------------------- /c++/Src/live_source_file/FileSource.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include "SourceInterface.h" 8 | #include "xstring.h" 9 | #include "IOAccess.h" 10 | #include "SmartPtr.h" 11 | #include "SmartNal.h" 12 | #include "SmartHdr.h" 13 | #include "xthread.h" 14 | 15 | class CFileSource : public ISourceProxy { 16 | public: 17 | CFileSource(const xtstring& strMoniker, const xtstring& strParam); 18 | ~CFileSource(void); 19 | 20 | public: 21 | bool Open(ISourceProxyCallback* callback, const xtstring& strFile); 22 | 23 | protected: 24 | //ISourceProxy 25 | virtual LPCTSTR SourceName() const { return m_moniker; } 26 | virtual bool StartFetch(event_base* base); 27 | virtual void WantKeyFrame(); 28 | virtual ControlResult PTZControl(const unsigned int token, const unsigned int action, const int speed); 29 | virtual ControlResult VideoEffect(const unsigned int token, const int bright, const int contrast, const int saturation, const int hue); 30 | virtual bool Discard(); 31 | 32 | protected: 33 | static void ev_callback(evutil_socket_t fd, short flags, void* context); 34 | void ev_callback(evutil_socket_t fd, short flags); 35 | 36 | protected: 37 | enum PackType { Header = 0, Video, Audio, Error, Custom }; 38 | 39 | private: 40 | xtstring m_moniker; 41 | CSmartPtr m_spReader; 42 | CSmartNal m_snHeader; 43 | CSmartHdr m_timer; 44 | 45 | ISourceProxyCallback* m_lpCallback; 46 | uint32_t m_uBeginTC; 47 | uint32_t m_uRefTime; 48 | bool m_bDiscard; 49 | }; 50 | 51 | -------------------------------------------------------------------------------- /c++/Src/live_source_file/Makefile: -------------------------------------------------------------------------------- 1 | # Copyright (c) 1999 Apple Computer, Inc. All rights reserved. 2 | # 3 | 4 | NAME = liblive_source_file 5 | STATICLIB = liblive_source_file.a 6 | SHAREDLIB = liblive_source_file.so 7 | C++ = gcc #$(CPLUS) 8 | CC = gcc #$(CCOMP) 9 | LINK = $(LINKER) 10 | 11 | COMPILER_FLAGS = -D_REENTRANT -D__USE_POSIX -D__linux__ -pipe 12 | INCLUDE_FLAG = -include 13 | CCFLAGS += $(COMPILER_FLAGS) -fPIC -g -Wall -Wno-deprecated -std=c++11 14 | 15 | # OPTIMIZATION 16 | #CCFLAGS += -O2 17 | 18 | # EACH DIRECTORY WITH HEADERS MUST BE APPENDED IN THIS MANNER TO THE CCFLAGS 19 | 20 | CCFLAGS += -I. 21 | CCFLAGS += -I.. 22 | CCFLAGS += -I../../linux/inc 23 | CCFLAGS += -I../live_input 24 | 25 | C++FLAGS = $(CCFLAGS) 26 | 27 | CXXLIBS += -L../../linux/lib -llive_vpf -llive_input -llive_logging -llive_media -llive_common -llive_literal 28 | CXXLIBS += -L../../linux/lib -levent -levent_core -levent_pthreads 29 | CXXLIBS += -L./usr/local/lib -lpthread -ldl -fPIC 30 | 31 | CFILES = 32 | 33 | CPPFILES = live_source_file.cpp \ 34 | FileFactory.cpp \ 35 | FileSource.cpp 36 | 37 | all: $(SHAREDLIB) $(STATICLIB) 38 | 39 | #-shared 40 | $(SHAREDLIB): $(CFILES:.c=.o) $(CPPFILES:.cpp=.o) 41 | g++ -shared -fPIC -o $(SHAREDLIB) $(CFILES:.c=.o) $(CPPFILES:.cpp=.o) $(CXXLIBS) 42 | mkdir -p ../../linux/bin 43 | cp -f $(SHAREDLIB) ../../linux/bin 44 | mkdir -p ../live_gateway/Plugin/source/ 45 | cp -f $(SHAREDLIB) ../live_gateway/Plugin/source/ 46 | 47 | $(STATICLIB): $(CFILES:.c=.o) $(CPPFILES:.cpp=.o) 48 | ar -r $(STATICLIB) $(CFILES:.c=.o) $(CPPFILES:.cpp=.o) 49 | ranlib $(STATICLIB) 50 | mkdir -p ../../linux/lib 51 | cp -f $(STATICLIB) ../../linux/lib 52 | mkdir -p ../../linux/inc 53 | 54 | install: $(STATICLIB) 55 | clean: 56 | rm -f $(STATICLIB) $(SHAREDLIB) $(CFILES:.c=.o) $(CPPFILES:.cpp=.o) 57 | 58 | .SUFFIXES: .cpp .c .o 59 | 60 | .cpp.o: 61 | $(C++) -c -o $*.o $(DEFINES) $(C++FLAGS) $*.cpp 62 | 63 | .c.o: 64 | $(CC) -c -o $*.o $(DEFINES) $(CCFLAGS) $*.c 65 | 66 | 67 | -------------------------------------------------------------------------------- /c++/Src/live_source_file/ReadMe.txt: -------------------------------------------------------------------------------- 1 | ======================================================================== 2 | 动态链接库:live_source_file 项目概述 3 | ======================================================================== 4 | 5 | 应用程序向导已为您创建了此 live_source_file DLL。 6 | 7 | 本文件概要介绍组成 live_source_file 应用程序的每个文件的内容。 8 | 9 | 10 | live_source_file.vcxproj 11 | 这是使用应用程序向导生成的 VC++ 项目的主项目文件,其中包含生成该文件的 Visual C++ 的版本信息,以及有关使用应用程序向导选择的平台、配置和项目功能的信息。 12 | 13 | live_source_file.vcxproj.filters 14 | 这是使用“应用程序向导”生成的 VC++ 项目筛选器文件。它包含有关项目文件与筛选器之间的关联信息。在 IDE 中,通过这种关联,在特定节点下以分组形式显示具有相似扩展名的文件。例如,“.cpp”文件与“源文件”筛选器关联。 15 | 16 | live_source_file.cpp 17 | 这是主 DLL 源文件。 18 | 19 | 此 DLL 在创建时不导出任何符号。因此,生成时不会产生 .lib 文件。如果希望此项目成为其他某个项目的项目依赖项,则需要添加代码以从 DLL 导出某些符号,以便产生一个导出库,或者,也可以在项目“属性页”对话框中的“链接器”文件夹中,将“常规”属性页上的“忽略输入库”属性设置为“是”。 20 | 21 | ///////////////////////////////////////////////////////////////////////////// 22 | 其他标准文件: 23 | 24 | StdAfx.h, StdAfx.cpp 25 | 这些文件用于生成名为 live_source_file.pch 的预编译头 (PCH) 文件和名为 StdAfx.obj 的预编译类型文件。 26 | 27 | ///////////////////////////////////////////////////////////////////////////// 28 | 其他注释: 29 | 30 | 应用程序向导使用“TODO:”注释来指示应添加或自定义的源代码部分。 31 | 32 | ///////////////////////////////////////////////////////////////////////////// 33 | -------------------------------------------------------------------------------- /c++/Src/live_source_file/dllmain.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yunsean/live/653fda0c4e444a94a4c8693a913faf92d356f595/c++/Src/live_source_file/dllmain.cpp -------------------------------------------------------------------------------- /c++/Src/live_source_file/live_source_file.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yunsean/live/653fda0c4e444a94a4c8693a913faf92d356f595/c++/Src/live_source_file/live_source_file.cpp -------------------------------------------------------------------------------- /c++/Src/live_source_file/live_source_file.def: -------------------------------------------------------------------------------- 1 | LIBRARY 2 | EXPORTS 3 | GetSourceFactory 4 | -------------------------------------------------------------------------------- /c++/Src/live_source_file/live_source_file.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 源文件 23 | 24 | 25 | 源文件 26 | 27 | 28 | 源文件 29 | 30 | 31 | 源文件 32 | 33 | 34 | 35 | 36 | 源文件 37 | 38 | 39 | 40 | 41 | 42 | 头文件 43 | 44 | 45 | 头文件 46 | 47 | 48 | -------------------------------------------------------------------------------- /c++/Src/live_source_hxht/HxhtFactory.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include "SourceInterface.h" 10 | #include "HxhtServer.h" 11 | #include "xstring.h" 12 | #include "SmartPtr.h" 13 | 14 | class COnvifFactory : public ISourceFactory { 15 | public: 16 | COnvifFactory(); 17 | ~COnvifFactory(); 18 | 19 | public: 20 | static COnvifFactory& Singleton(); 21 | 22 | public: 23 | virtual LPCTSTR FactoryName() const; 24 | virtual bool Initialize(ISourceFactoryCallback* callback); 25 | virtual SupportState DidSupport(LPCTSTR device, LPCTSTR moniker, LPCTSTR param); 26 | virtual ISourceProxy* CreateLiveProxy(ISourceProxyCallback* callback, LPCTSTR device, LPCTSTR moniker, LPCTSTR param); 27 | virtual ISourceProxy* CreatePastProxy(ISourceProxyCallback* callback, LPCTSTR device, LPCTSTR moniker, LPCTSTR param, uint64_t beginTime, uint64_t endTime = 0); 28 | virtual bool GetSourceList(LPTSTR* xml, void(**free)(LPTSTR), bool onlineOnly, LPCTSTR device = NULL); 29 | virtual bool GetStatusInfo(LPSTR* json, void(**free)(LPSTR)); 30 | virtual void Uninitialize(); 31 | virtual void Destroy(); 32 | 33 | protected: 34 | friend class CHxhtServer; 35 | void RemoveServer(CHxhtServer* server); 36 | 37 | private: 38 | const LPCTSTR m_lpszFactoryName; 39 | ISourceFactoryCallback* m_lpCallback; 40 | std::mutex m_lkHxhtServers; 41 | std::vector m_vHxhtServers; 42 | }; 43 | 44 | -------------------------------------------------------------------------------- /c++/Src/live_source_hxht/HxhtServer.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include "SmartHdr.h" 11 | #include "Markup.h" 12 | #include "Byte.h" 13 | 14 | struct event_base; 15 | interface ISourceProxy; 16 | interface ISourceProxyCallback; 17 | class CHxhtServer { 18 | public: 19 | CHxhtServer(const xtstring& host, int port, const xtstring& usr, const xtstring& pwd); 20 | ~CHxhtServer(); 21 | 22 | public: 23 | bool StartEnum(event_base* base); 24 | void EnumCamera(CMarkup& xml, bool onlineOnly) const; 25 | bool HasCamera(LPCTSTR moniker); 26 | ISourceProxy* CreateProxy(ISourceProxyCallback* callback, LPCTSTR moniker); 27 | 28 | protected: 29 | friend class CHxhtReader; 30 | void SetOffline(const xtstring& naming, bool offline); 31 | 32 | protected: 33 | bool httpGet(const char* url); 34 | 35 | protected: 36 | static void http_callback(evhttp_request* req, void* context); 37 | void http_callback(evhttp_request* req); 38 | 39 | protected: 40 | void onLogin(CMarkup& xml); 41 | void onDevice(CMarkup& xml); 42 | void onEnumFailed(const xtstring& message); 43 | 44 | protected: 45 | bool unzip(char* data, int size, std::string& result); 46 | void enumOrgan(CMarkup& xml); 47 | 48 | protected: 49 | enum WorkStage{Inited, Login, EnumDevice, EnumOver}; 50 | 51 | protected: 52 | struct CameraVic { 53 | CameraVic(const xtstring& n) : name(n), offline(false) {} 54 | xtstring name; 55 | bool offline; 56 | }; 57 | 58 | private: 59 | xtstring m_host; 60 | int m_port; 61 | xtstring m_user; 62 | xtstring m_pwd; 63 | xtstring m_name; 64 | 65 | event_base* m_base; 66 | WorkStage m_stage; 67 | CSmartHdr m_connection; 68 | 69 | std::map> m_cameras; 70 | }; 71 | 72 | -------------------------------------------------------------------------------- /c++/Src/live_source_hxht/ReadMe.txt: -------------------------------------------------------------------------------- 1 | ======================================================================== 2 | 动态链接库:live_source_hxht 项目概述 3 | ======================================================================== 4 | 5 | 应用程序向导已为您创建了此 live_source_hxht DLL。 6 | 7 | 本文件概要介绍组成 live_source_hxht 应用程序的每个文件的内容。 8 | 9 | 10 | live_source_hxht.vcxproj 11 | 这是使用应用程序向导生成的 VC++ 项目的主项目文件,其中包含生成该文件的 Visual C++ 的版本信息,以及有关使用应用程序向导选择的平台、配置和项目功能的信息。 12 | 13 | live_source_hxht.vcxproj.filters 14 | 这是使用“应用程序向导”生成的 VC++ 项目筛选器文件。它包含有关项目文件与筛选器之间的关联信息。在 IDE 中,通过这种关联,在特定节点下以分组形式显示具有相似扩展名的文件。例如,“.cpp”文件与“源文件”筛选器关联。 15 | 16 | live_source_hxht.cpp 17 | 这是主 DLL 源文件。 18 | 19 | 此 DLL 在创建时不导出任何符号。因此,生成时不会产生 .lib 文件。如果希望此项目成为其他某个项目的项目依赖项,则需要添加代码以从 DLL 导出某些符号,以便产生一个导出库,或者,也可以在项目“属性页”对话框中的“链接器”文件夹中,将“常规”属性页上的“忽略输入库”属性设置为“是”。 20 | 21 | ///////////////////////////////////////////////////////////////////////////// 22 | 其他标准文件: 23 | 24 | StdAfx.h, StdAfx.cpp 25 | 这些文件用于生成名为 live_source_hxht.pch 的预编译头 (PCH) 文件和名为 StdAfx.obj 的预编译类型文件。 26 | 27 | ///////////////////////////////////////////////////////////////////////////// 28 | 其他注释: 29 | 30 | 应用程序向导使用“TODO:”注释来指示应添加或自定义的源代码部分。 31 | 32 | ///////////////////////////////////////////////////////////////////////////// 33 | -------------------------------------------------------------------------------- /c++/Src/live_source_hxht/dllmain.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yunsean/live/653fda0c4e444a94a4c8693a913faf92d356f595/c++/Src/live_source_hxht/dllmain.cpp -------------------------------------------------------------------------------- /c++/Src/live_source_hxht/live_source_hxht.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yunsean/live/653fda0c4e444a94a4c8693a913faf92d356f595/c++/Src/live_source_hxht/live_source_hxht.cpp -------------------------------------------------------------------------------- /c++/Src/live_source_hxht/live_source_hxht.def: -------------------------------------------------------------------------------- 1 | LIBRARY 2 | EXPORTS 3 | GetSourceFactory 4 | -------------------------------------------------------------------------------- /c++/Src/live_source_hxht/live_source_hxht.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 源文件 23 | 24 | 25 | 源文件 26 | 27 | 28 | 源文件 29 | 30 | 31 | 源文件 32 | 33 | 34 | 源文件 35 | 36 | 37 | 38 | 39 | 头文件 40 | 41 | 42 | 头文件 43 | 44 | 45 | 头文件 46 | 47 | 48 | 49 | 50 | 源文件 51 | 52 | 53 | 54 | -------------------------------------------------------------------------------- /c++/Src/live_source_onvif/OnvifControl.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yunsean/live/653fda0c4e444a94a4c8693a913faf92d356f595/c++/Src/live_source_onvif/OnvifControl.cpp -------------------------------------------------------------------------------- /c++/Src/live_source_onvif/OnvifPattern.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | class COnvifPattern { 5 | public: 6 | static std::string probe(const char* types, const char* scopes = "", const char* messageId = nullptr); 7 | static std::string getCapabilities(const char* username, const char* password, const char* category); //Media 8 | static std::string getProfiles(const char* username, const char* password); 9 | static std::string getStreamUri(const char* username, const char* password, const char* token, const char* protocol = "TCP"); 10 | static std::string getPanTilt(const char* username, const char* password, const char* token, int x, int y); 11 | static std::string getZoom(const char* username, const char* password, const char* token, int x); 12 | static std::string getStop(const char* username, const char* password, const char* token); 13 | 14 | public: 15 | static std::string messageID(const char* prefix = ""); 16 | 17 | private: 18 | static std::string format(const char* fmt, ...); 19 | static std::string getSecurity(const char* username, const char* password); 20 | }; 21 | 22 | -------------------------------------------------------------------------------- /c++/Src/live_source_onvif/RtpAacDemuxer.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include "RtpBaseDemuxer.h" 4 | #include "SourceInterface.h" 5 | #include "SmartArr.h" 6 | 7 | class CRtpAacDemuxer : public CRtpBaseDemuxer { 8 | public: 9 | CRtpAacDemuxer(); 10 | ~CRtpAacDemuxer(); 11 | 12 | public: 13 | static bool support(const char* codec) { return strncmp(codec, "mpeg4-generic", 13) == 0; } 14 | 15 | public: 16 | bool init(const fsdp_media_description_t* media); 17 | const char* control() const { return m_control.c_str(); } 18 | const uint8_t* extradata(int& size) const { size = m_extradataSize; return m_extradata.get(); } 19 | bool handle_packet(const uint8_t *buf, int len, uint32_t timestamp, uint16_t seq, int flags); 20 | uint32_t fourCC() const { return MKFCC(' ', 'C', 'A', 'A'); } 21 | 22 | private: 23 | bool sdp_parse_fmtp_config_aac(const char *attr, const char *value); 24 | bool parse_fmtp_config(const char *value); 25 | bool rtp_parse_mp4_au(const uint8_t* buf, int len); 26 | int rtp_parse_packet(const uint8_t *buf, int len, uint32_t timestamp, uint16_t seq, int flags); 27 | 28 | private: 29 | struct AUHeaders { 30 | int size; 31 | int index; 32 | }; 33 | 34 | private: 35 | int m_clockRate; 36 | std::string m_control; 37 | uint8_t m_profileIdc; 38 | int m_indexDeltaLength; 39 | 40 | int m_sizeLength; 41 | int m_indexLength; 42 | std::string m_mode; 43 | std::unique_ptr m_extradata; 44 | int m_extradataSize; 45 | 46 | int m_au_headers_length_bytes; 47 | int m_nb_au_headers; 48 | int m_au_headers_allocated; 49 | int m_cur_au_index; 50 | CSmartArr m_au_headers; 51 | int m_buf_pos; 52 | int m_buf_size; 53 | uint32_t m_timestamp; 54 | uint8_t m_buf[8191]; 55 | }; 56 | 57 | -------------------------------------------------------------------------------- /c++/Src/live_source_onvif/RtpBaseDemuxer.cpp: -------------------------------------------------------------------------------- 1 | #include "RtpBaseDemuxer.h" 2 | #include "xstring.h" 3 | 4 | #define SPACE_CHARS " \t\r\n" 5 | CRtpBaseDemuxer::CRtpBaseDemuxer() 6 | : m_interleaved(-1) 7 | , m_clientPort(-1) { 8 | } 9 | 10 | CRtpBaseDemuxer::~CRtpBaseDemuxer() { 11 | } 12 | 13 | std::string CRtpBaseDemuxer::transport() const { 14 | if (m_interleaved >= 0) { 15 | return xstring::format("RTP/AVP/TCP;unicast;interleaved=%d-%d", m_interleaved, m_interleaved + 1); 16 | } else { 17 | return xstring::format("RTP/AVP/UDP;unicast;client_port=%d-%d", m_clientPort, m_clientPort + 1); 18 | } 19 | } 20 | 21 | void CRtpBaseDemuxer::get_word_until_chars(char *buf, int buf_size, const char *sep, const char **pp) { 22 | const char *p; 23 | char *q; 24 | p = *pp; 25 | p += strspn(p, SPACE_CHARS); 26 | q = buf; 27 | while (!strchr(sep, *p) && *p != '\0') { 28 | if ((q - buf) < buf_size - 1) *q++ = *p; 29 | p++; 30 | } 31 | if (buf_size > 0) *q = '\0'; 32 | *pp = p; 33 | } 34 | void CRtpBaseDemuxer::get_word_sep(char *buf, int buf_size, const char *sep, const char **pp) { 35 | if (**pp == '/') (*pp)++; 36 | get_word_until_chars(buf, buf_size, sep, pp); 37 | } 38 | int CRtpBaseDemuxer::rtsp_next_attr_and_value(const char **p, char *attr, int attr_size, char *value, int value_size) { 39 | *p += strspn(*p, SPACE_CHARS); 40 | if (**p) { 41 | get_word_sep(attr, attr_size, "=", p); 42 | if (**p == '=') (*p)++; 43 | get_word_sep(value, value_size, ";", p); 44 | if (**p == ';') (*p)++; 45 | return 1; 46 | } 47 | return 0; 48 | } 49 | -------------------------------------------------------------------------------- /c++/Src/live_source_onvif/RtpBaseDemuxer.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include "xstring.h" 5 | #include "freesdp/freesdp/freesdp.h" 6 | 7 | class CRtpBaseDemuxer { 8 | public: 9 | CRtpBaseDemuxer(); 10 | ~CRtpBaseDemuxer(); 11 | 12 | public: 13 | virtual bool init(const fsdp_media_description_t* media) = 0; 14 | virtual void setCallback(const std::function& callback) { m_callback = callback; } 15 | virtual const char* control() const = 0; 16 | virtual void setInterleaved(int interleaved) { m_interleaved = interleaved; } 17 | virtual void setClientPort(int port) { m_clientPort = port; } 18 | virtual std::string transport() const; 19 | virtual int interleaved() const { return m_interleaved; } 20 | virtual int clientPort() const { return m_clientPort; } 21 | virtual const uint8_t* extradata(int& size) const { size = 0; return nullptr; } 22 | virtual bool handle_packet(const uint8_t *buf, int len, uint32_t timestamp, uint16_t seq, int flags) = 0; 23 | virtual uint32_t fourCC() const = 0; 24 | 25 | protected: 26 | void get_word_until_chars(char *buf, int buf_size, const char *sep, const char **pp); 27 | void get_word_sep(char *buf, int buf_size, const char *sep, const char **pp); 28 | int rtsp_next_attr_and_value(const char **p, char *attr, int attr_size, char *value, int value_size); 29 | 30 | protected: 31 | int m_interleaved; 32 | int m_clientPort; 33 | std::function m_callback; 34 | }; 35 | 36 | -------------------------------------------------------------------------------- /c++/Src/live_source_onvif/RtpH264Demuxer.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "RtpBaseDemuxer.h" 3 | #include "SourceInterface.h" 4 | #include "Byte.h" 5 | 6 | class CRtpH264Demuxer : public CRtpBaseDemuxer { 7 | public: 8 | CRtpH264Demuxer(); 9 | ~CRtpH264Demuxer(); 10 | 11 | public: 12 | static bool support(const char* codec) { return strncmp(codec, "H264", 4) == 0; } 13 | 14 | public: 15 | bool init(const fsdp_media_description_t* media); 16 | const char* control() const { return m_control.c_str(); } 17 | const uint8_t* extradata(int& size) const { size = m_extradataSize; return m_extradata.get(); } 18 | bool handle_packet(const uint8_t *buf, int len, uint32_t timestamp, uint16_t seq, int flags); 19 | uint32_t fourCC() const { return MKFCC(' ', 'C', 'V', 'A'); } 20 | 21 | private: 22 | bool sdp_parse_fmtp_config_h264(const char *attr, const char *value); 23 | void parse_profile_level_id(const char *value); 24 | int base64_decode(const char* input, uint8_t* output); 25 | bool h264_parse_sprop_parameter_sets(const char *value); 26 | 27 | private: 28 | bool h264_handle_aggregated_packet(const uint8_t *buf, int len, int skip_between); 29 | bool h264_handle_frag_packet(const uint8_t *buf, int len, int start_bit, int end_bit, const uint8_t *nal_header, int nal_header_len); 30 | bool h264_handle_packet_fu_a(const uint8_t *buf, int len); 31 | bool h264_handle_packet_normal(const uint8_t *buf, int len); 32 | 33 | private: 34 | int m_cachePadding; 35 | float m_videoFrameRate; 36 | int m_clockRate; 37 | int m_packetizationMode; 38 | std::string m_control; 39 | uint8_t m_profileIdc; 40 | uint8_t m_profileIop; 41 | uint8_t m_levelIdc; 42 | std::unique_ptr m_extradata; 43 | int m_extradataSize; 44 | CByte m_cache; 45 | uint64_t m_timestamp; 46 | uint32_t m_prevTimestamp; 47 | }; 48 | 49 | -------------------------------------------------------------------------------- /c++/Src/live_source_onvif/RtspClient.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yunsean/live/653fda0c4e444a94a4c8693a913faf92d356f595/c++/Src/live_source_onvif/RtspClient.cpp -------------------------------------------------------------------------------- /c++/Src/live_source_onvif/SdpParser.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | class CSdpParser { 8 | public: 9 | CSdpParser(); 10 | ~CSdpParser(); 11 | 12 | public: 13 | bool parse(const char* sdp); 14 | 15 | protected: 16 | enum StreamType { None, Video, Audio, Data, Subtitle }; 17 | 18 | protected: 19 | struct SDPParseState { 20 | std::string default_ip; 21 | int default_ttl; 22 | int skip_media; 23 | int nb_default_include_source_addrs; 24 | struct RTSPSource** default_include_source_addrs; 25 | int nb_default_exclude_source_addrs; 26 | struct RTSPSource** default_exclude_source_addrs; 27 | int seen_rtpmap; 28 | int seen_fmtp; 29 | char delayed_fmtp[2048]; 30 | }; 31 | struct RTSPStream { 32 | int stream_index; 33 | int interleaved_min; 34 | int interleaved_max; 35 | char control_url[1024]; 36 | int sdp_port; 37 | std::string sdp_ip; 38 | int nb_include_source_addrs; 39 | struct RTSPSource **include_source_addrs; /**< Source-specific multicast include source IP addresses (from SDP content) */ 40 | int nb_exclude_source_addrs; /**< Number of source-specific multicast exclude source IP addresses (from SDP content) */ 41 | struct RTSPSource **exclude_source_addrs; /**< Source-specific multicast exclude source IP addresses (from SDP content) */ 42 | int sdp_ttl; 43 | int sdp_payload_type; 44 | RTPDynamicProtocolHandler* dynamic_handler; 45 | PayloadContext *dynamic_protocol_context; 46 | int feedback; 47 | uint32_t ssrc; 48 | char crypto_suite[40]; 49 | char crypto_params[100]; 50 | }; 51 | 52 | protected: 53 | void sdp_parse_line(SDPParseState* s1, int letter, const char* buf); 54 | 55 | private: 56 | std::string m_title; 57 | std::string m_comment; 58 | int nb_streams; 59 | int nb_rtsp_streams; 60 | 61 | bool skip_media; 62 | bool seen_fmtp; 63 | bool seen_rtpmap; 64 | 65 | std::vector> m_streams; 66 | }; 67 | 68 | -------------------------------------------------------------------------------- /c++/Src/live_source_onvif/freesdp/formatterpriv.h: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of FreeSDP 3 | Copyright (C) 2001,2002,2003,2004 Federico Montesino Pouzols 4 | 5 | FreeSDP is free software; you can redistribute it and/or modify it 6 | under the terms of the GNU General Public License as published by 7 | the Free Software Foundation; either version 2 of the License, or 8 | (at your option) any later version. 9 | 10 | FreeSDP is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License 16 | along with this program; if not, write to the Free Software 17 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | */ 19 | 20 | /** 21 | * @file formatterpriv.h 22 | * 23 | * @short Private header for formatting module. 24 | **/ 25 | 26 | #ifndef FSDP_FORMATTERPRIV_H 27 | #define FSDP_FORMATTERPRIV_H 28 | 29 | #include "priv.h" 30 | #include 31 | 32 | #define EMAILS_MAX_COUNT 3 33 | #define PHONES_MAX_COUNT 3 34 | #define BW_MODIFIERS_MAX_COUNT 4 35 | #define TIME_PERIODS_MAX_COUNT 3 36 | #define REPEATS_MAX_COUNT 3 37 | #define MEDIA_ANNOUNCEMENTS_MAX_COUNT 5 38 | #define MEDIA_FORMATS_MAX_COUNT 5 39 | 40 | #endif /* FSDP_FORMATTERPRIV_H */ 41 | -------------------------------------------------------------------------------- /c++/Src/live_source_onvif/freesdp/freesdp/freesdp.h: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of FreeSDP. 3 | Copyright (C) 2001,2002,2003,2004 Federico Montesino Pouzols 4 | 5 | FreeSDP is free software; you can redistribute it and/or modify it 6 | under the terms of the GNU General Public License as published by 7 | the Free Software Foundation; either version 2 of the License, or 8 | (at your option) any later version. 9 | 10 | FreeSDP is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License 16 | along with this program; if not, write to the Free Software 17 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | */ 19 | 20 | /** 21 | * @file freesdp.h 22 | * 23 | * @short Global public header that includes both parsing and 24 | * formatting module headers, parser.h and formatter.h, respectively. 25 | **/ 26 | 27 | /** 28 | * Routines for parsing SDP descriptions and getting its properties. 29 | **/ 30 | #include 31 | 32 | /** 33 | * Routines for formatting SDP descriptions with given properties. 34 | **/ 35 | #include 36 | 37 | -------------------------------------------------------------------------------- /c++/Src/live_source_onvif/live_source_onvif.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yunsean/live/653fda0c4e444a94a4c8693a913faf92d356f595/c++/Src/live_source_onvif/live_source_onvif.cpp -------------------------------------------------------------------------------- /c++/Src/live_source_onvif/live_source_onvif.def: -------------------------------------------------------------------------------- 1 | LIBRARY 2 | EXPORTS 3 | GetSourceFactory 4 | -------------------------------------------------------------------------------- /c++/Src/live_source_rtmp/ReadMe.txt: -------------------------------------------------------------------------------- 1 | ======================================================================== 2 | 动态链接库:live_source_rtmp 项目概述 3 | ======================================================================== 4 | 5 | 应用程序向导已为您创建了此 live_source_rtmp DLL。 6 | 7 | 本文件概要介绍组成 live_source_rtmp 应用程序的每个文件的内容。 8 | 9 | 10 | live_source_rtmp.vcxproj 11 | 这是使用应用程序向导生成的 VC++ 项目的主项目文件,其中包含生成该文件的 Visual C++ 的版本信息,以及有关使用应用程序向导选择的平台、配置和项目功能的信息。 12 | 13 | live_source_rtmp.vcxproj.filters 14 | 这是使用“应用程序向导”生成的 VC++ 项目筛选器文件。它包含有关项目文件与筛选器之间的关联信息。在 IDE 中,通过这种关联,在特定节点下以分组形式显示具有相似扩展名的文件。例如,“.cpp”文件与“源文件”筛选器关联。 15 | 16 | live_source_rtmp.cpp 17 | 这是主 DLL 源文件。 18 | 19 | 此 DLL 在创建时不导出任何符号。因此,生成时不会产生 .lib 文件。如果希望此项目成为其他某个项目的项目依赖项,则需要添加代码以从 DLL 导出某些符号,以便产生一个导出库,或者,也可以在项目“属性页”对话框中的“链接器”文件夹中,将“常规”属性页上的“忽略输入库”属性设置为“是”。 20 | 21 | ///////////////////////////////////////////////////////////////////////////// 22 | 其他标准文件: 23 | 24 | StdAfx.h, StdAfx.cpp 25 | 这些文件用于生成名为 live_source_rtmp.pch 的预编译头 (PCH) 文件和名为 StdAfx.obj 的预编译类型文件。 26 | 27 | ///////////////////////////////////////////////////////////////////////////// 28 | 其他注释: 29 | 30 | 应用程序向导使用“TODO:”注释来指示应添加或自定义的源代码部分。 31 | 32 | ///////////////////////////////////////////////////////////////////////////// 33 | -------------------------------------------------------------------------------- /c++/Src/live_source_rtmp/RtmpActor.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include "os.h" 4 | 5 | struct evbuffer; 6 | class CRtmpChunk; 7 | class CRtmpMessage; 8 | interface CRtmpActor { 9 | enum Type{Publisher, Player}; 10 | virtual ~CRtmpActor() {} 11 | virtual Type getType() const = 0; 12 | virtual bool isStream(const std::string& streamName) const = 0; 13 | virtual bool onMessage(evbuffer* output, CRtmpChunk* chunk) = 0; 14 | virtual bool onMessage(evbuffer* output, CRtmpMessage* message) = 0; 15 | }; -------------------------------------------------------------------------------- /c++/Src/live_source_rtmp/RtmpPlayer.cpp: -------------------------------------------------------------------------------- 1 | #include "RtmpPlayer.h" 2 | #include "RtmpChunk.h" 3 | #include "RtmpMessage.h" 4 | #include "ConsoleUI.h" 5 | #include "Writelog.h" 6 | 7 | CRtmpPlayer::CRtmpPlayer(uint32_t outputChunkSize) 8 | : m_outputChunkSize(outputChunkSize) 9 | , m_streamName() 10 | , m_streamId() { 11 | } 12 | CRtmpPlayer::~CRtmpPlayer() { 13 | } 14 | 15 | bool CRtmpPlayer::isStream(const std::string& streamName) const { 16 | xtstring name(streamName); 17 | return m_streamName.Compare(name) == 0; 18 | } 19 | bool CRtmpPlayer::onMessage(evbuffer* output, CRtmpChunk* chunk) { 20 | switch (chunk->type()) { 21 | case RTMP_MSG_AudioMessage: 22 | case RTMP_MSG_VideoMessage: 23 | break; 24 | } 25 | CSmartPtr message(nullptr); 26 | if (!chunk->buildMessage(message.GetPtr())) { 27 | return wlet(false, _T("decode packet failed: messageType=%d, length=%d"), (int)chunk->type(), chunk->length()); 28 | } else { 29 | return onMessage(output, message); 30 | } 31 | } 32 | bool CRtmpPlayer::onMessage(evbuffer* output, CRtmpMessage* message) { 33 | switch (message->type()) { 34 | case PlayStreamRequest: 35 | return onPlayStream(output, dynamic_cast(message)); 36 | default: 37 | return true; 38 | } 39 | } 40 | 41 | bool CRtmpPlayer::onPlayStream(evbuffer* output, CPlayStreamRequest* message) { 42 | return true; 43 | } -------------------------------------------------------------------------------- /c++/Src/live_source_rtmp/RtmpPlayer.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "RtmpActor.h" 3 | #include "CommandMessage.h" 4 | #include "xstring.h" 5 | 6 | class CRtmpPlayer : public CRtmpActor { 7 | public: 8 | CRtmpPlayer(uint32_t outputChunkSize); 9 | ~CRtmpPlayer(); 10 | 11 | protected: 12 | virtual Type getType() const { return Player; } 13 | virtual bool isStream(const std::string& streamName) const; 14 | virtual bool onMessage(evbuffer* output, CRtmpChunk* chunk); 15 | virtual bool onMessage(evbuffer* output, CRtmpMessage* message); 16 | 17 | protected: 18 | bool onPlayStream(evbuffer* output, CPlayStreamRequest* message); 19 | 20 | private: 21 | uint32_t m_outputChunkSize; 22 | xtstring m_streamName; 23 | uint32_t m_streamId; 24 | }; 25 | 26 | -------------------------------------------------------------------------------- /c++/Src/live_source_rtmp/RtmpPublisher.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yunsean/live/653fda0c4e444a94a4c8693a913faf92d356f595/c++/Src/live_source_rtmp/RtmpPublisher.cpp -------------------------------------------------------------------------------- /c++/Src/live_source_rtmp/dllmain.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yunsean/live/653fda0c4e444a94a4c8693a913faf92d356f595/c++/Src/live_source_rtmp/dllmain.cpp -------------------------------------------------------------------------------- /c++/Src/live_source_rtmp/live_source_rtmp.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yunsean/live/653fda0c4e444a94a4c8693a913faf92d356f595/c++/Src/live_source_rtmp/live_source_rtmp.cpp -------------------------------------------------------------------------------- /c++/Src/live_source_rtmp/live_source_rtmp.def: -------------------------------------------------------------------------------- 1 | LIBRARY 2 | EXPORTS 3 | GetSourceFactory 4 | -------------------------------------------------------------------------------- /c++/Src/live_source_rtmp/live_source_rtmp.vcxproj.user: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | -------------------------------------------------------------------------------- /c++/Src/live_source_vod/ReadMe.txt: -------------------------------------------------------------------------------- 1 | ======================================================================== 2 | 动态链接库:live_source_vod 项目概述 3 | ======================================================================== 4 | 5 | 应用程序向导已为您创建了此 live_source_vod DLL。 6 | 7 | 本文件概要介绍组成 live_source_vod 应用程序的每个文件的内容。 8 | 9 | 10 | live_source_vod.vcxproj 11 | 这是使用应用程序向导生成的 VC++ 项目的主项目文件,其中包含生成该文件的 Visual C++ 的版本信息,以及有关使用应用程序向导选择的平台、配置和项目功能的信息。 12 | 13 | live_source_vod.vcxproj.filters 14 | 这是使用“应用程序向导”生成的 VC++ 项目筛选器文件。它包含有关项目文件与筛选器之间的关联信息。在 IDE 中,通过这种关联,在特定节点下以分组形式显示具有相似扩展名的文件。例如,“.cpp”文件与“源文件”筛选器关联。 15 | 16 | live_source_vod.cpp 17 | 这是主 DLL 源文件。 18 | 19 | 此 DLL 在创建时不导出任何符号。因此,生成时不会产生 .lib 文件。如果希望此项目成为其他某个项目的项目依赖项,则需要添加代码以从 DLL 导出某些符号,以便产生一个导出库,或者,也可以在项目“属性页”对话框中的“链接器”文件夹中,将“常规”属性页上的“忽略输入库”属性设置为“是”。 20 | 21 | ///////////////////////////////////////////////////////////////////////////// 22 | 其他标准文件: 23 | 24 | StdAfx.h, StdAfx.cpp 25 | 这些文件用于生成名为 live_source_vod.pch 的预编译头 (PCH) 文件和名为 StdAfx.obj 的预编译类型文件。 26 | 27 | ///////////////////////////////////////////////////////////////////////////// 28 | 其他注释: 29 | 30 | 应用程序向导使用“TODO:”注释来指示应添加或自定义的源代码部分。 31 | 32 | ///////////////////////////////////////////////////////////////////////////// 33 | -------------------------------------------------------------------------------- /c++/Src/live_source_vod/VodFactory.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include "SourceInterface.h" 10 | #include "xstring.h" 11 | #include "SmartPtr.h" 12 | #include "SmartHdr.h" 13 | 14 | class CVodFactory : public ISourceFactory { 15 | public: 16 | CVodFactory(); 17 | ~CVodFactory(); 18 | 19 | public: 20 | static CVodFactory& Singleton(); 21 | 22 | public: 23 | virtual LPCTSTR FactoryName() const; 24 | virtual bool Initialize(ISourceFactoryCallback* callback); 25 | virtual SupportState DidSupport(LPCTSTR device, LPCTSTR moniker, LPCTSTR param); 26 | virtual ISourceProxy* CreateLiveProxy(ISourceProxyCallback* callback, LPCTSTR device, LPCTSTR moniker, LPCTSTR param); 27 | virtual ISourceProxy* CreatePastProxy(ISourceProxyCallback* callback, LPCTSTR device, LPCTSTR moniker, LPCTSTR param, uint64_t beginTime, uint64_t endTime = 0); 28 | virtual bool GetSourceList(LPTSTR* xml, void(**free)(LPTSTR), bool onlineOnly, LPCTSTR device = NULL); 29 | virtual bool GetStatusInfo(LPSTR* json, void(**free)(LPSTR)); 30 | virtual void Uninitialize(); 31 | virtual void Destroy(); 32 | 33 | private: 34 | static void listen_callback(struct evconnlistener* conn, evutil_socket_t fd, struct sockaddr* addr, int addrlen, void* context); 35 | void listen_callback(struct evconnlistener* conn, evutil_socket_t fd, struct sockaddr* addr, int addrlen); 36 | 37 | private: 38 | const LPCTSTR m_lpszFactoryName; 39 | ISourceFactoryCallback* m_lpCallback; 40 | std::vector> m_listeners; 41 | }; 42 | 43 | -------------------------------------------------------------------------------- /c++/Src/live_source_vod/dllmain.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yunsean/live/653fda0c4e444a94a4c8693a913faf92d356f595/c++/Src/live_source_vod/dllmain.cpp -------------------------------------------------------------------------------- /c++/Src/live_source_vod/live_source_vod.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yunsean/live/653fda0c4e444a94a4c8693a913faf92d356f595/c++/Src/live_source_vod/live_source_vod.cpp -------------------------------------------------------------------------------- /c++/Src/live_source_vod/live_source_vod.def: -------------------------------------------------------------------------------- 1 | LIBRARY 2 | EXPORTS 3 | GetSourceFactory 4 | -------------------------------------------------------------------------------- /c++/Src/live_source_vod/live_source_vod.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 源文件 23 | 24 | 25 | 源文件 26 | 27 | 28 | 源文件 29 | 30 | 31 | 32 | 33 | 头文件 34 | 35 | 36 | 37 | 38 | 源文件 39 | 40 | 41 | -------------------------------------------------------------------------------- /c++/Src/live_vpf/FileReader.cpp: -------------------------------------------------------------------------------- 1 | #include "FileReader.h" 2 | #include "Writelog.h" 3 | 4 | CFileReader::CFileReader() 5 | : m_file(::fclose) { 6 | } 7 | CFileReader::~CFileReader() { 8 | Close(); 9 | } 10 | 11 | ////////////////////////////////////////////////////////////////////////// 12 | void CFileReader::OnSetError() { 13 | wle(m_strDesc); 14 | } 15 | 16 | bool CFileReader::Open(LPCTSTR strFile) { 17 | try { 18 | m_file = ::_tfopen(strFile, _T("rb+")); 19 | if (!m_file.isValid()) { 20 | return SetErrorT(false, _T("Open file failed.")); 21 | } 22 | } catch (...) { 23 | return SetErrorT(false, _T("Open file failed.")); 24 | } 25 | return true; 26 | } 27 | bool CFileReader::Read(void* cache, const int limit, int& read) { 28 | if (cache == nullptr) return false; 29 | if (!m_file.isValid()) return false; 30 | try { 31 | read = (int)::fread(reinterpret_cast(cache), 1, limit, m_file); 32 | } catch (std::exception ex) { 33 | return SetErrorT(false, ex); 34 | } 35 | return read > 0; 36 | } 37 | bool CFileReader::Seek(const int64_t offset) { 38 | if (!m_file.isValid()) return false; 39 | try { 40 | ::fseek(m_file, (long)offset, SEEK_SET); 41 | } 42 | catch (std::exception ex) { 43 | return SetErrorT(false, ex); 44 | } 45 | return ::ftell(m_file) == offset; 46 | } 47 | int64_t CFileReader::Offset() { 48 | if (!m_file.isValid()) return false; 49 | try { 50 | return ::ftell(m_file);; 51 | } 52 | catch (std::exception ex) { 53 | return SetErrorT(0, ex); 54 | } 55 | } 56 | bool CFileReader::Eof() { 57 | if (!m_file.isValid()) return true; 58 | return ::feof(m_file) != 0; 59 | } 60 | void CFileReader::Close() { 61 | m_file = NULL; 62 | } 63 | 64 | IIOReader* CreateFileReader() { 65 | return new CFileReader; 66 | } -------------------------------------------------------------------------------- /c++/Src/live_vpf/FileReader.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "IOAccess.h" 3 | #include "SmartErr.h" 4 | #include "SmartHdr.h" 5 | 6 | class CFileReader : public IIOReader, public CSmartErr { 7 | public: 8 | CFileReader(void); 9 | virtual ~CFileReader(void); 10 | 11 | protected: 12 | //IIOReader 13 | bool Open(LPCTSTR strFile); 14 | bool CanSeek() { return true; } 15 | bool Read(void* cache, const int limit, int& read); 16 | bool Seek(const int64_t offset); 17 | int64_t Offset(); 18 | bool Eof(); 19 | void Close(); 20 | 21 | protected: 22 | virtual void OnSetError(); 23 | virtual LPCTSTR GetLastErrorDesc() const { return m_strDesc; } 24 | virtual unsigned int GetLastErrorCode() const { return m_dwCode; } 25 | 26 | private: 27 | CSmartHdr m_file; 28 | }; 29 | 30 | -------------------------------------------------------------------------------- /c++/Src/live_vpf/HttpReader.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "event2/event.h" 3 | #include "event2/http.h" 4 | #include "event2/http_struct.h" 5 | #include "IOAccess.h" 6 | #include "SmartBlk.h" 7 | #include "xstring.h" 8 | #include "SmartErr.h" 9 | 10 | class CHttpReader : public IIOReader, public CSmartErr { 11 | public: 12 | CHttpReader(event_base* base); 13 | ~CHttpReader(void); 14 | 15 | protected: 16 | //IIOReader 17 | bool Open(LPCTSTR strFile); 18 | bool CanSeek() { return true; } 19 | bool Read(void* cache, const int limit, int& read); 20 | bool Seek(const int64_t offset); 21 | int64_t Offset(); 22 | bool Eof(); 23 | void Close(); 24 | 25 | protected: 26 | virtual void OnSetError(); 27 | virtual LPCTSTR GetLastErrorDesc() const { return m_strDesc; } 28 | virtual unsigned int GetLastErrorCode() const { return m_dwCode; } 29 | 30 | protected: 31 | bool openRequest(const int64_t offset); 32 | static void request_callback(struct evhttp_request* request, void* context); 33 | void request_callback(struct evhttp_request* request); 34 | void closeRequest(); 35 | 36 | protected: 37 | struct CHttpBlock : public CTypicalBlock { 38 | int ReadData(void* const lpCache, const int szWant); 39 | }; 40 | 41 | private: 42 | xtstring m_url; 43 | event_base* m_eventBase; 44 | evhttp_request* m_request; 45 | CSmartBlk m_blocks; 46 | CHttpBlock* m_writing; 47 | CHttpBlock* m_reading; 48 | bool m_hasError; 49 | int64_t m_offset; 50 | }; 51 | 52 | -------------------------------------------------------------------------------- /c++/Src/live_vpf/Makefile: -------------------------------------------------------------------------------- 1 | # Copyright (c) 1999 Apple Computer, Inc. All rights reserved. 2 | # 3 | 4 | NAME = liblive_vpf 5 | STATICLIB = liblive_vpf.a 6 | SHAREDLIB = liblive_vpf.so 7 | C++ = gcc #$(CPLUS) 8 | CC = gcc #$(CCOMP) 9 | LINK = $(LINKER) 10 | 11 | COMPILER_FLAGS = -D_REENTRANT -D__USE_POSIX -D__linux__ -pipe 12 | INCLUDE_FLAG = -include 13 | CCFLAGS += $(COMPILER_FLAGS) -fPIC -g -Wall -Wno-deprecated -std=c++11 14 | 15 | # OPTIMIZATION 16 | #CCFLAGS += -O2 17 | 18 | # EACH DIRECTORY WITH HEADERS MUST BE APPENDED IN THIS MANNER TO THE CCFLAGS 19 | 20 | CCFLAGS += -I. 21 | CCFLAGS += -I.. 22 | CCFLAGS += -I../../linux/inc/ 23 | CCLIBS += -fPIC 24 | 25 | CXXLIBS += -L../../linux/lib -llive_logging -llive_common 26 | C++FLAGS = $(CCFLAGS) 27 | 28 | CFILES = 29 | 30 | CPPFILES = FileReader.cpp \ 31 | HttpReader.cpp \ 32 | VpfReader.cpp \ 33 | VpfWriter.cpp 34 | 35 | all: $(SHAREDLIB) $(STATICLIB) 36 | 37 | $(SHAREDLIB): $(CFILES:.c=.o) $(CPPFILES:.cpp=.o) 38 | g++ -shared -fPIC -o $(SHAREDLIB) $(CFILES:.c=.o) $(CPPFILES:.cpp=.o) $(CCLIBS) 39 | mkdir -p ../../linux/bin 40 | cp -f $(SHAREDLIB) ../../linux/bin 41 | 42 | $(STATICLIB): $(CFILES:.c=.o) $(CPPFILES:.cpp=.o) 43 | ar -r $(STATICLIB) $(CFILES:.c=.o) $(CPPFILES:.cpp=.o) 44 | ranlib $(STATICLIB) 45 | mkdir -p ../../linux/lib 46 | cp -f $(STATICLIB) ../../linux/lib 47 | mkdir -p ../../linux/inc 48 | cp -f IOAccess.h ../../linux/inc/ 49 | 50 | install: $(STATICLIB) 51 | clean: 52 | rm -f $(STATICLIB) $(SHAREDLIB) $(CFILES:.c=.o) $(CPPFILES:.cpp=.o) 53 | 54 | .SUFFIXES: .cpp .c .o 55 | 56 | .cpp.o: 57 | $(C++) -c -o $*.o $(DEFINES) $(C++FLAGS) $*.cpp 58 | 59 | .c.o: 60 | $(CC) -c -o $*.o $(DEFINES) $(CCFLAGS) $*.c 61 | 62 | 63 | -------------------------------------------------------------------------------- /c++/Src/live_vpf/ReadMe.txt: -------------------------------------------------------------------------------- 1 | ======================================================================== 2 | 动态链接库:live_vpf 项目概述 3 | ======================================================================== 4 | 5 | 应用程序向导已为您创建了此 live_vpf DLL。 6 | 7 | 本文件概要介绍组成 live_vpf 应用程序的每个文件的内容。 8 | 9 | 10 | live_vpf.vcxproj 11 | 这是使用应用程序向导生成的 VC++ 项目的主项目文件,其中包含生成该文件的 Visual C++ 的版本信息,以及有关使用应用程序向导选择的平台、配置和项目功能的信息。 12 | 13 | live_vpf.vcxproj.filters 14 | 这是使用“应用程序向导”生成的 VC++ 项目筛选器文件。它包含有关项目文件与筛选器之间的关联信息。在 IDE 中,通过这种关联,在特定节点下以分组形式显示具有相似扩展名的文件。例如,“.cpp”文件与“源文件”筛选器关联。 15 | 16 | live_vpf.cpp 17 | 这是主 DLL 源文件。 18 | 19 | 此 DLL 在创建时不导出任何符号。因此,生成时不会产生 .lib 文件。如果希望此项目成为其他某个项目的项目依赖项,则需要添加代码以从 DLL 导出某些符号,以便产生一个导出库,或者,也可以在项目“属性页”对话框中的“链接器”文件夹中,将“常规”属性页上的“忽略输入库”属性设置为“是”。 20 | 21 | ///////////////////////////////////////////////////////////////////////////// 22 | 其他标准文件: 23 | 24 | StdAfx.h, StdAfx.cpp 25 | 这些文件用于生成名为 live_vpf.pch 的预编译头 (PCH) 文件和名为 StdAfx.obj 的预编译类型文件。 26 | 27 | ///////////////////////////////////////////////////////////////////////////// 28 | 其他注释: 29 | 30 | 应用程序向导使用“TODO:”注释来指示应添加或自定义的源代码部分。 31 | 32 | ///////////////////////////////////////////////////////////////////////////// 33 | -------------------------------------------------------------------------------- /c++/Src/live_vpf/VpfReader.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yunsean/live/653fda0c4e444a94a4c8693a913faf92d356f595/c++/Src/live_vpf/VpfReader.cpp -------------------------------------------------------------------------------- /c++/Src/live_vpf/VpfReader.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yunsean/live/653fda0c4e444a94a4c8693a913faf92d356f595/c++/Src/live_vpf/VpfReader.h -------------------------------------------------------------------------------- /c++/Src/live_vpf/VpfWriter.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yunsean/live/653fda0c4e444a94a4c8693a913faf92d356f595/c++/Src/live_vpf/VpfWriter.cpp -------------------------------------------------------------------------------- /c++/Src/live_vpf/VpfWriter.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "IOAccess.h" 3 | #include "SmartErr.h" 4 | #include "xstring.h" 5 | #include "Byte.h" 6 | 7 | class CVpfWriter : public IVpfWriter, public CSmartErr { 8 | public: 9 | CVpfWriter(void); 10 | ~CVpfWriter(void); 11 | 12 | public: 13 | bool OpenFile(LPCTSTR file, const uint64_t& utcBegin = ~0); 14 | bool WriteHead(const uint8_t* const data, const int size); 15 | bool WriteData(const uint8_t type, const uint8_t* const data, const int size, const uint32_t timecode = ~0); 16 | uint32_t GetLength() const; 17 | void CloseFile(bool* isValid = NULL); 18 | LPCTSTR GetInfo(uint64_t& utcBegin, uint64_t& utcEnd); 19 | 20 | protected: 21 | bool WriteHeader(const uint8_t* const data, const int size); 22 | bool Write10sIndex(const uint32_t nextTC); 23 | bool Write1sIndex(const uint32_t nextTC); 24 | bool WriteMediaData(const uint8_t type, const uint32_t timecode, const uint8_t* const data, const int size); 25 | bool WriteFooter(); 26 | 27 | protected: 28 | typedef int TCSecond; 29 | protected: 30 | bool AppendIndex(const TCSecond nextTC); 31 | 32 | protected: 33 | virtual void OnSetError(); 34 | virtual LPCTSTR GetLastErrorDesc() const { return m_strDesc; } 35 | virtual unsigned int GetLastErrorCode() const { return m_dwCode; } 36 | 37 | private: 38 | FILE* m_vpfFile; 39 | xtstring m_strName; 40 | xtstring m_strPath; 41 | bool m_bHasError; 42 | bool m_bWorking; 43 | uint64_t m_utcBegin; 44 | 45 | CByte m_byCache; 46 | bool m_bInnerIndex; 47 | TCSecond m_uLast10s; 48 | TCSecond m_uLast1s; 49 | long m_ll10sOffset; 50 | long m_ll1sOffset; 51 | 52 | long m_llLastOffset; 53 | long m_llBaseOffset; 54 | bool m_bHasHeader; 55 | uint32_t m_uFirstTC; 56 | uint32_t m_uLastTC; 57 | CByte m_byIndexes; 58 | }; 59 | 60 | 61 | -------------------------------------------------------------------------------- /c++/Src/live_vpf/copy_x64.bat: -------------------------------------------------------------------------------- 1 | md ..\..\x64\inc\ 2 | copy IOAccess.h ..\..\x64\inc\ 3 | -------------------------------------------------------------------------------- /c++/Src/live_vpf/copy_x86.bat: -------------------------------------------------------------------------------- 1 | md ..\..\x86\inc\ 2 | copy IOAccess.h ..\..\x86\inc\ 3 | -------------------------------------------------------------------------------- /c++/Src/live_vpf/dllmain.cpp: -------------------------------------------------------------------------------- 1 | #include "os.h" 2 | 3 | BOOL APIENTRY DllMain( HMODULE hModule, 4 | DWORD ul_reason_for_call, 5 | LPVOID lpReserved 6 | ) 7 | { 8 | switch (ul_reason_for_call) 9 | { 10 | case DLL_PROCESS_ATTACH: 11 | case DLL_THREAD_ATTACH: 12 | case DLL_THREAD_DETACH: 13 | case DLL_PROCESS_DETACH: 14 | break; 15 | } 16 | return TRUE; 17 | } 18 | 19 | -------------------------------------------------------------------------------- /c++/linux/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yunsean/live/653fda0c4e444a94a4c8693a913faf92d356f595/c++/linux/.DS_Store -------------------------------------------------------------------------------- /c++/linux/inc/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yunsean/live/653fda0c4e444a94a4c8693a913faf92d356f595/c++/linux/inc/.DS_Store -------------------------------------------------------------------------------- /c++/linux/inc/openssl/ebcdic.h: -------------------------------------------------------------------------------- 1 | /* crypto/ebcdic.h */ 2 | 3 | #ifndef HEADER_EBCDIC_H 4 | # define HEADER_EBCDIC_H 5 | 6 | # include 7 | 8 | #ifdef __cplusplus 9 | extern "C" { 10 | #endif 11 | 12 | /* Avoid name clashes with other applications */ 13 | # define os_toascii _openssl_os_toascii 14 | # define os_toebcdic _openssl_os_toebcdic 15 | # define ebcdic2ascii _openssl_ebcdic2ascii 16 | # define ascii2ebcdic _openssl_ascii2ebcdic 17 | 18 | extern const unsigned char os_toascii[256]; 19 | extern const unsigned char os_toebcdic[256]; 20 | void *ebcdic2ascii(void *dest, const void *srce, size_t count); 21 | void *ascii2ebcdic(void *dest, const void *srce, size_t count); 22 | 23 | #ifdef __cplusplus 24 | } 25 | #endif 26 | #endif 27 | -------------------------------------------------------------------------------- /c++/linux/inc/openssl/whrlpool.h: -------------------------------------------------------------------------------- 1 | #ifndef HEADER_WHRLPOOL_H 2 | # define HEADER_WHRLPOOL_H 3 | 4 | # include 5 | # include 6 | 7 | #ifdef __cplusplus 8 | extern "C" { 9 | #endif 10 | 11 | # define WHIRLPOOL_DIGEST_LENGTH (512/8) 12 | # define WHIRLPOOL_BBLOCK 512 13 | # define WHIRLPOOL_COUNTER (256/8) 14 | 15 | typedef struct { 16 | union { 17 | unsigned char c[WHIRLPOOL_DIGEST_LENGTH]; 18 | /* double q is here to ensure 64-bit alignment */ 19 | double q[WHIRLPOOL_DIGEST_LENGTH / sizeof(double)]; 20 | } H; 21 | unsigned char data[WHIRLPOOL_BBLOCK / 8]; 22 | unsigned int bitoff; 23 | size_t bitlen[WHIRLPOOL_COUNTER / sizeof(size_t)]; 24 | } WHIRLPOOL_CTX; 25 | 26 | # ifndef OPENSSL_NO_WHIRLPOOL 27 | # ifdef OPENSSL_FIPS 28 | int private_WHIRLPOOL_Init(WHIRLPOOL_CTX *c); 29 | # endif 30 | int WHIRLPOOL_Init(WHIRLPOOL_CTX *c); 31 | int WHIRLPOOL_Update(WHIRLPOOL_CTX *c, const void *inp, size_t bytes); 32 | void WHIRLPOOL_BitUpdate(WHIRLPOOL_CTX *c, const void *inp, size_t bits); 33 | int WHIRLPOOL_Final(unsigned char *md, WHIRLPOOL_CTX *c); 34 | unsigned char *WHIRLPOOL(const void *inp, size_t bytes, unsigned char *md); 35 | # endif 36 | 37 | #ifdef __cplusplus 38 | } 39 | #endif 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /c++/linux/lib/libcrypto.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yunsean/live/653fda0c4e444a94a4c8693a913faf92d356f595/c++/linux/lib/libcrypto.a -------------------------------------------------------------------------------- /c++/linux/lib/libevent.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yunsean/live/653fda0c4e444a94a4c8693a913faf92d356f595/c++/linux/lib/libevent.a -------------------------------------------------------------------------------- /c++/linux/lib/libevent_core.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yunsean/live/653fda0c4e444a94a4c8693a913faf92d356f595/c++/linux/lib/libevent_core.a -------------------------------------------------------------------------------- /c++/linux/lib/libevent_extra.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yunsean/live/653fda0c4e444a94a4c8693a913faf92d356f595/c++/linux/lib/libevent_extra.a -------------------------------------------------------------------------------- /c++/linux/lib/libevent_pthreads.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yunsean/live/653fda0c4e444a94a4c8693a913faf92d356f595/c++/linux/lib/libevent_pthreads.a -------------------------------------------------------------------------------- /c++/linux/lib/libssl.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yunsean/live/653fda0c4e444a94a4c8693a913faf92d356f595/c++/linux/lib/libssl.a -------------------------------------------------------------------------------- /c++/linux/lib/libz.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yunsean/live/653fda0c4e444a94a4c8693a913faf92d356f595/c++/linux/lib/libz.a -------------------------------------------------------------------------------- /c++/x64/inc/openssl/ebcdic.h: -------------------------------------------------------------------------------- 1 | /* crypto/ebcdic.h */ 2 | 3 | #ifndef HEADER_EBCDIC_H 4 | # define HEADER_EBCDIC_H 5 | 6 | # include 7 | 8 | #ifdef __cplusplus 9 | extern "C" { 10 | #endif 11 | 12 | /* Avoid name clashes with other applications */ 13 | # define os_toascii _openssl_os_toascii 14 | # define os_toebcdic _openssl_os_toebcdic 15 | # define ebcdic2ascii _openssl_ebcdic2ascii 16 | # define ascii2ebcdic _openssl_ascii2ebcdic 17 | 18 | extern const unsigned char os_toascii[256]; 19 | extern const unsigned char os_toebcdic[256]; 20 | void *ebcdic2ascii(void *dest, const void *srce, size_t count); 21 | void *ascii2ebcdic(void *dest, const void *srce, size_t count); 22 | 23 | #ifdef __cplusplus 24 | } 25 | #endif 26 | #endif 27 | -------------------------------------------------------------------------------- /c++/x64/inc/openssl/whrlpool.h: -------------------------------------------------------------------------------- 1 | #ifndef HEADER_WHRLPOOL_H 2 | # define HEADER_WHRLPOOL_H 3 | 4 | # include 5 | # include 6 | 7 | #ifdef __cplusplus 8 | extern "C" { 9 | #endif 10 | 11 | # define WHIRLPOOL_DIGEST_LENGTH (512/8) 12 | # define WHIRLPOOL_BBLOCK 512 13 | # define WHIRLPOOL_COUNTER (256/8) 14 | 15 | typedef struct { 16 | union { 17 | unsigned char c[WHIRLPOOL_DIGEST_LENGTH]; 18 | /* double q is here to ensure 64-bit alignment */ 19 | double q[WHIRLPOOL_DIGEST_LENGTH / sizeof(double)]; 20 | } H; 21 | unsigned char data[WHIRLPOOL_BBLOCK / 8]; 22 | unsigned int bitoff; 23 | size_t bitlen[WHIRLPOOL_COUNTER / sizeof(size_t)]; 24 | } WHIRLPOOL_CTX; 25 | 26 | # ifndef OPENSSL_NO_WHIRLPOOL 27 | # ifdef OPENSSL_FIPS 28 | int private_WHIRLPOOL_Init(WHIRLPOOL_CTX *c); 29 | # endif 30 | int WHIRLPOOL_Init(WHIRLPOOL_CTX *c); 31 | int WHIRLPOOL_Update(WHIRLPOOL_CTX *c, const void *inp, size_t bytes); 32 | void WHIRLPOOL_BitUpdate(WHIRLPOOL_CTX *c, const void *inp, size_t bits); 33 | int WHIRLPOOL_Final(unsigned char *md, WHIRLPOOL_CTX *c); 34 | unsigned char *WHIRLPOOL(const void *inp, size_t bytes, unsigned char *md); 35 | # endif 36 | 37 | #ifdef __cplusplus 38 | } 39 | #endif 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /c++/x64/lib/libeay32.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yunsean/live/653fda0c4e444a94a4c8693a913faf92d356f595/c++/x64/lib/libeay32.lib -------------------------------------------------------------------------------- /c++/x64/lib/libevent.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yunsean/live/653fda0c4e444a94a4c8693a913faf92d356f595/c++/x64/lib/libevent.lib -------------------------------------------------------------------------------- /c++/x64/lib/libevent_core.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yunsean/live/653fda0c4e444a94a4c8693a913faf92d356f595/c++/x64/lib/libevent_core.lib -------------------------------------------------------------------------------- /c++/x64/lib/libevent_extras.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yunsean/live/653fda0c4e444a94a4c8693a913faf92d356f595/c++/x64/lib/libevent_extras.lib -------------------------------------------------------------------------------- /c++/x64/lib/ssleay32.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yunsean/live/653fda0c4e444a94a4c8693a913faf92d356f595/c++/x64/lib/ssleay32.lib -------------------------------------------------------------------------------- /c++/x64/lib/zlibstat.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yunsean/live/653fda0c4e444a94a4c8693a913faf92d356f595/c++/x64/lib/zlibstat.lib --------------------------------------------------------------------------------