A kind of code stream retransmission method and systemTechnical field
The present invention relates to multimedia communication technology field, be specifically related to a kind of code stream retransmission method and system.
Background technology
In recent years, public security system has progressively built up video conferencing system, video monitoring system, 350M group system, and the multiple systems such as police service comprehensive application system, PGIS Police Geographic Information System, PKI/PMI digital certificate system, drastically increase the operating efficiency of all departments of public security organ, improve the routine work efficiency of public security system.Flattening video directing and scheduling system is a visual command dispatching system utilizing Police Geographic Information System to integrate the various audio and video resources such as video conferencing system, video monitoring system, 350M trunked communication system, mobile terminal, flattening video directing and scheduling system constructs efficient command scheduling system, integrate, converge the information resources of all kinds of existing and following information system yet to be built, achieve efficient modernization commander application.The overall framework of flattening video directing and scheduling system as shown in Figure 1, wherein, it is the nucleus module of system that code stream forwards submodule, interconnecting of subsystems can be realized by code stream forwarding module, when emergency command is dispatched, need the fast dispatch realizing various audio and video resources (video conference, monitoring, 350M hand platform, phone, mobile phone, individual soldier), require higher to forwarding performance, so forward submodule by an efficient code stream, to realize the forwarding of media code stream necessary.
Current most code stream forwarding mechanism is all take socket technology to carry out application layer forwarding, adopts this technology, needs experience to receive and sends two stages.In the reception stage, receive the application layer of frame data from network interface card, to the decapsulation process of totally 5 layers of link layer, IP layer, transport layer, application layer.Transmission phase, needs again from application layer, through transport layer, IP layer, link layer, the physical layer encapsulation process of totally 5 layers.Above, complete once the process that complete socket repeating process needs through 10 layers altogether, overhead is larger, the inefficiency that code stream forwards.
Summary of the invention
For this reason, technical problem to be solved by this invention is that the overhead needed for the code stream retransmission method of flattening command dispatching system in prior art is larger, and the efficiency that code stream forwards is low, thus proposes a kind of code stream retransmission method and system.
For solving the problems of the technologies described above, a kind of code stream retransmission method of the present invention, comprises the steps:
Physical layer receives data to be forwarded bag, and by described Packet Generation to link layer;
Link layer carries out decapsulation to the packet received, and by the Packet Generation after decapsulation to network layer;
Network layer is obtained by the Hook Function arranged and is filtered the packet entering network layer, by the Packet Generation after filtration to application layer;
Application layer receives packet and modifies, and the call back function that amended packet is registered by it is returned to network layer;
Network layer by the Packet Generation that receives to link layer;
Link layer encapsulates the packet received, and sends to physical layer;
Packet after encapsulation sends by physical layer.
Preferably, described network layer is obtained by the Hook Function arranged and is filtered the packet entering network layer, by the Packet Generation after filtering to the processing procedure of Hook Function described in application layer step is:
All packets entering network layer are obtained at test point;
Filter out the packet containing User Datagram Protocol in described packet;
Judge described whether consistent with the second destination interface that application layer is specified containing the first destination interface in the packet of User Datagram Protocol: if the first destination interface and the second destination interface consistent, then by the described Packet Generation containing User Datagram Protocol to application layer; Otherwise the described packet containing User Datagram Protocol is turned back to protocol stack.
Preferably, described application layer receives packet and modifies, and returns in network layer procedure by amended packet by the call back function that it is registered:
Described application layer is modified to the packet received by user's space, and the content of described amendment comprises destination address and the destination slogan of packet header.
Preferably, described network layer is obtained by the Hook Function arranged and is filtered the packet entering network layer, and the Packet Generation after filtering also is comprised step to before application layer step:
Network layer in ICP/IP protocol stack registers described Hook Function.
Preferably, described network layer in ICP/IP protocol stack is registered in described Hook Function step:
The described Hook Function Hook Function that priority is registered higher than other when registering.
The present invention also provides a kind of code stream repeater system, comprising:
Physical layer, comprising: receiving element, for receiving data to be forwarded bag and by described Packet Generation to link layer; Transmitting element, for sending the packet after link layer packaging;
Link layer, comprising: decapsulation unit, for receiving packet and sending to network layer after described packet is carried out decapsulation; Encapsulation unit, for being undertaken encapsulating and sending to physical layer by packet;
Network layer, comprising: acquiring unit, obtains for the Hook Function by arranging and filters the packet entering network layer, by the Packet Generation after filtration to application layer; Return data transmitting element, for the Packet Generation that will return after application-level modifications to link layer;
Application layer, for receiving packet and modifying, returns to network layer by the call back function that the packet revised is registered by it.
Preferably, described acquiring unit comprises:
Obtain subelement, obtain all packets entering network layer at test point;
Filter subelement: filter out the packet containing User Datagram Protocol in described packet;
Judgment sub-unit: judge described whether consistent with the second destination interface that application layer is specified containing the first destination interface in the packet of User Datagram Protocol: if the first destination interface and the second destination interface consistent, then by the described Packet Generation containing User Datagram Protocol to application layer; Otherwise the described packet containing User Datagram Protocol is turned back to protocol stack.
Preferably, in described application layer:
Described application layer is modified to the packet received by user's space, and the content of described amendment comprises destination address and the destination slogan of packet header.
Preferably, in described network layer:
Network layer in ICP/IP protocol stack registers described Hook Function.
Preferably, in described network layer:
The described Hook Function Hook Function that priority is registered higher than other when registering.
Technique scheme of the present invention has the following advantages compared to existing technology:
(1) a kind of code stream retransmission method of the present invention and system, data to be forwarded bag is received by physical layer, link layer carries out decapsulation to packet, the Hook Function arranged by network layer is again obtained and filters the packet entering network layer, packet after application layer receiving filtration is also modified, amended packet returns to network layer by the call back function of registration, and encapsulate packet at link layer, physical layer sends the packet encapsulated.The process that whole code stream forwards only needs the protocol stack overhead amounting to 7 layers, fewer than traditional socket mode overhead of 3 layers.Therefore, under same hardware condition, the efficiency that code stream forwards obtains very large lifting.
(2) a kind of code stream retransmission method of the present invention and system, by arranging Hook Function in network layer, the packet entering network layer is filtered, obtain the packet containing User Datagram Protocol, and judge described whether consistent with the second destination interface that application layer is specified containing the first destination interface in the packet of User Datagram Protocol, if consistent, by the Packet Generation containing User Datagram Protocol to application layer process, achieve the forwarding of packet at IP layer, thus eliminate the overhead of transport layer and application layer, substantially increase efficiency of transmission.
Accompanying drawing explanation
In order to make content of the present invention be more likely to be clearly understood, below according to a particular embodiment of the invention and by reference to the accompanying drawings, the present invention is further detailed explanation, wherein
The overall framework figure of Fig. 1 flattening video directing and scheduling system;
Fig. 2 is a kind of code stream retransmission method flow chart of one embodiment of the invention;
Fig. 3 is the software architecture figure of a kind of code stream forwarding module of one embodiment of the invention;
Fig. 4 is the schematic diagram that a kind of code stream forwarding submodule of one embodiment of the invention runs in flattening video directing dispatching platform;
Fig. 5 is a kind of code stream repeater system block schematic illustration of one embodiment of the invention.
Embodiment
Embodiment 1
The present embodiment provides a kind of code stream retransmission method, can be used for, in the command scheduling submodule of the visual emergency commanding platform of flattening as shown in Figure 1, comprising the steps, flow chart as shown in Figure 2:
S1: physical layer receives data to be forwarded bag, and by described Packet Generation to link layer.Physical layer receives data to be forwarded bag by network interface card.
S2: link layer carries out decapsulation to the packet received, and by the Packet Generation after decapsulation to network layer.
S3: network layer is obtained by the Hook Function arranged and filtered the packet entering network layer, by the Packet Generation after filtration to application layer.
The processing procedure of described Hook Function is:
All packets entering network layer are obtained at test point;
Filter out the packet containing User Datagram Protocol in described packet;
Judge described whether consistent with the second destination interface that application layer is specified containing the first destination interface in the packet of User Datagram Protocol: if the first destination interface and the second destination interface consistent, then by the described Packet Generation containing User Datagram Protocol to application layer; Otherwise the described packet containing User Datagram Protocol is turned back to protocol stack.
S4: application layer receives packet and modifies, returns to network layer by amended packet by the call back function of registration.Described application layer is modified to the packet received by user's space, and the content of described amendment comprises destination address and the destination slogan of packet header.Wherein, call back function is the return function comprising pointer, defines as required.
S5: network layer by the Packet Generation that receives to link layer
S6: link layer encapsulates the packet received, and sends to physical layer.
S7: the packet after encapsulation sends by physical layer.
Also step was comprised before step S3:
S0: the network layer in ICP/IP protocol stack registers described Hook Function.The described Hook Function Hook Function that priority is registered higher than other when registering.
A kind of code stream retransmission method that the present embodiment provides, data to be forwarded bag is received by physical layer, link layer carries out decapsulation to packet, the Hook Function arranged by network layer is again obtained and filters the packet entering network layer, packet after application layer receiving filtration is also modified, amended packet returns to network layer by the call back function of registration, and encapsulate packet at link layer, physical layer sends the packet encapsulated.The process that whole code stream forwards only needs the protocol stack overhead amounting to 7 layers, fewer than traditional socket mode overhead of 3 layers.Therefore, under same hardware condition, the efficiency that code stream forwards obtains very large lifting.
Embodiment 2
The present embodiment provides a kind of code stream to forward submodule, and in the present embodiment, code stream forwards the characteristic that can customize Hook Function that submodule (being also Dataswitch) make use of Netfilter framework and realizes needing the packet of forwarding to recombinate.
The NETFILTER framework of Linux comprises following three parts:
1, for procotol defines a set of Hook Function (IPv4 defines 5 Hook Functions), several key points that these Hook Functions flow through protocol stack in datagram are called.In these points, protocol stack will using datagram and Hook Function label as parameter call Netfilter framework.
2, any module of kernel can be registered one or more hooks of often kind of agreement, realizes mounting, and like this when certain packet is delivered to Netfilter framework, whether interior nuclear energy detects has any module to register this agreement and Hook Function.If have registered, then the call back function used when calling the registration of this module, these modules are just had an opportunity to check (may also can revise) this packet, abandon this packet and are indicated Netfilter this packet to be imported into the queue of user's space like this.
3, those packets of queuing up are delivered to processing asynchronously of user's space.A consumer process can check packet, Update Table bag, even can be again injected in kernel by the same Hook Function that leaves kernel by this packet.
The realization of Netfilter framework mainly relies on 5 test points, and each packet entering IP layer can through one or several of these test points:
[1]: NF_IP_PRE_ROUTING: just entered the packet of network layer by this point (just having carried out version number, the detections such as School Affairs), source address conversion is carried out at this point.
[2]: NF_IP_LOCAL_IN: after route querying, be sent to the machine by this checkpoint, INPUT packet filtering this point carry out.
[3]: NF_IP_FORWARD: the bag that forward is by this test point, and FORWORD packet filtering is carried out at this point.
[4]: NF_IP_POST_ROUTING: the bag that all horse backs just will be gone out by the network equipment is by this test point, and built-in destination address translation function (comprising address camouflage) is carried out at this point.
[5]: NF_IP_LOCAL_OUT: the bag that local processes sends is by this test point, and OUTPUT packet filtering is carried out at this point.
From the effect of each test point above, we can find out that a packet enters the whole process of Netfilter framework:
IP packet enters system, and after carrying out IP verification, datagram processes through first Hook Function NF_IP_PRE_ROUTING [1]; Then just enter route code, it determines that this packet needs forward or issue the machine; If this packet issues the machine, then then these data pass to upper-layer protocol after Hook Function NF_IP_LOCAL_IN [2] process; If this packet should be forwarded, it is processed by NF_IP_FORWARD [3]; Through the datagram that forwards after last Hook Function NF_IP_POST_ROUTING [4] processes, then to be transferred on network.The local data produced through Hook Function NF_IP_LOCAL_OUT [5] process can after, carry out Route Selection process, be then sent on network after NF_IP_POST_ROUTING [4] process.
Kernel module can carry out registration mounting to one or more such Hook Function, and be called through these Hook Functions in datagram, thus module can revise these datagrams, and return to Netfilter framework, following value: NF_ACCEPT, continues normal transmission datagram; NF_DROP, abandons this datagram, no longer transmits; NF_STOLEN, module takes over this datagram, does not continue this datagram of transmission; NF_QUEUE, ranks (being generally used for datagram to process to the process of user's space) to this datagram; NF_REPEAT, calls this Hook Function again.
The characteristic that can customize Hook Function that make use of Netfilter framework realizes needing the packet forwarded to recombinate, comprise the steps: T1: on this test point of NF_IP_LOCAL_IN, register a Hook Function, for intercepting and capturing the IP packet of all inputs, only definition is provided in the present embodiment, registration is with other Hook Function, and priority is higher than the Hook Function of other registrations, and Hook Function is as follows:
Ip_dsw_in is the Hook Function of our carry on NF_IP_LOCAL_IN test point, being implemented as of it:
The effect of Hook Function ip_dsw_in is destination address and the destination slogan of the IP packet of specifying according to user's space, and the packet mailing to this port is all returned NF_QUEUE.
The specific implementation of described Hook Function comprises the steps:
T11: monitor all IP messages importing IP layer into.Definition IP header structure points to the IP message that IP layer imports IP_LOCAL_IN monitoring point into.
T12: filter out UDP message wherein.Protocol fields protocol according to ip header structure judges, if the transport layer protocol of this ip message is UDP, then uses udp header structure udphdr to point to it.
T13: filter out the satisfactory IP message of destination slogan.The destination interface field dest of udphdr is judged, if with user's space transmission and come udp destination interface consistent, then returned NF_QUEUE.
T14: the IP message do not met the demands returns to protocol stack (returning NF_ACCEPT) and does and normally receive process.
T2: these packets stored in specified queue, are then injected user's space by nf_queue () by these packets by kernel.
T3: user's space revises destination address and the port numbers in packet header as required, and the return type of ruling bag is NF_ACCEPT
T4: refill kernel by nf_reinject, finally enters normal process of transmitting.
Code stream forwards the software architecture figure of submodule as shown in Figure 3:
Business: design " forwarding rule list ".The function that whole forwarding module will realize is: the packet received by certain port local, and according to user-defined " forwarding rule list ", amendment destination address and destination interface, then forward.
App/dataswitch: safeguard " forwarding rule list ", method of operation for this table is provided.
Nip/dataswitch:(1) provide system call interfaces, allow user tell kernel by this interface, need the packet getting which port.(2) call libipq and ip_queue mutual by netlink mechanism, seize/be re-injected into data.
Nip/libipq: the method for encapsulation User space and ip_queue module communication.
Ip_queue: kernel module, by netfilter mechanism network data.
Ip_dataswitch: kernel module, registration netfilter hook processing method.
A kind of code stream that the present embodiment provides forwards submodule, can run in the Linux equipment of PowerPC, arm, x86 framework, and code stream forwards submodule and also can run in flattening video directing dispatching platform, as shown in Figure 4.Video terminal, telephone set, mobile phone, SIP phone, mobile individual soldier, front monitoring front-end all pass through IP link access dispatching platform, can realize the intercommunication of audio frequency, video between them.Such as, commander wishes to assign audio frequency and video instruction by video terminal to mobile phone, the image of video terminal camera collection, by being H.264 encoded into frame data, frame data are cut encapsulating and are dressed up RTP message, then submodule is forwarded by the code stream of dispatching platform, realize the message repeating of IP layer, be transmitted to the mobile phone in front, after mobile phone receives RTP message, framing is decoded, and finally the image of command centre can be presented on mobile phone screen.Audio frequency and video intercommunication between above process implementation different types of terminals.
Embodiment 3
The present embodiment provides a kind of code stream repeater system, as shown in Figure 5, comprising:
Physical layer, comprising: receiving element, for receiving data to be forwarded bag and by described Packet Generation to link layer; Transmitting element, for sending the packet after link layer packaging;
Link layer, comprising: decapsulation unit, for receiving packet and sending to network layer after described packet is carried out decapsulation; Encapsulation unit, for being undertaken encapsulating and sending to physical layer by packet;
Network layer, comprising: acquiring unit, obtains for the Hook Function by arranging and filters the packet entering network layer, by the Packet Generation after filtration to application layer; Return data transmitting element, for the Packet Generation that will return after application-level modifications to link layer;
Application layer, for receiving packet and modifying, returns to network layer by the call back function that the packet revised is registered by it.
Described acquiring unit comprises:
Obtain subelement, obtain all packets entering network layer at test point;
Filter subelement: filter out the packet containing User Datagram Protocol in described packet;
Judgment sub-unit: judge described whether consistent with the second destination interface that application layer is specified containing the first destination interface in the packet of User Datagram Protocol: if the first destination interface and the second destination interface consistent, then by the described Packet Generation containing User Datagram Protocol to application layer; Otherwise the described packet containing User Datagram Protocol is turned back to protocol stack.
Described in described application layer, application layer is modified to the packet received by user's space, and the content of described amendment comprises destination address and the destination slogan of packet header.
Network layer in described network layer in ICP/IP protocol stack registers described Hook Function.The described Hook Function Hook Function that priority is registered higher than other when registering.
A kind of code stream repeater system that the present embodiment provides, data to be forwarded bag is received by physical layer, link layer carries out decapsulation to packet, the Hook Function arranged by network layer is again obtained and filters the packet entering network layer, packet after application layer receiving filtration is also modified, amended packet returns to network layer by the call back function of registration, and encapsulate packet at link layer, physical layer sends the packet encapsulated.The process that whole code stream forwards only needs the protocol stack overhead amounting to 7 layers, fewer than traditional socket mode overhead of 3 layers.Therefore, under same hardware condition, the efficiency that code stream forwards obtains very large lifting.
Those skilled in the art should understand, embodiments of the invention can be provided as method, system or computer program.Therefore, the present invention can adopt the form of complete hardware embodiment, completely software implementation or the embodiment in conjunction with software and hardware aspect.And the present invention can adopt in one or more form wherein including the upper computer program implemented of computer-usable storage medium (including but not limited to magnetic disc store, CD-ROM, optical memory etc.) of computer usable program code.
The present invention describes with reference to according to the flow chart of the method for the embodiment of the present invention, equipment (system) and computer program and/or block diagram.Should understand can by the combination of the flow process in each flow process in computer program instructions realization flow figure and/or block diagram and/or square frame and flow chart and/or block diagram and/or square frame.Can provide these computer program instructions to the processor of all-purpose computer, special-purpose computer, Embedded Processor or other programmable data processing device to produce a machine, the instruction that the processor established by computer or other programmable data process is performed produces the device for realizing the function of specifying in flow chart flow process or multiple flow process and/or block diagram square frame or multiple square frame.
These computer program instructions also can be stored in can in the computer-readable memory that works in a specific way of vectoring computer or other programmable data processing device, the instruction making to be stored in this computer-readable memory produces the manufacture comprising command device, and this command device realizes the function of specifying in flow chart flow process or multiple flow process and/or block diagram square frame or multiple square frame.
These computer program instructions also can be loaded in computer or other programmable data processing device, make on computer or other programmable devices, to perform sequence of operations step to produce computer implemented process, thus the instruction performed on computer or other programmable devices is provided for the step realizing the function of specifying in flow chart flow process or multiple flow process and/or block diagram square frame or multiple square frame.
Although describe the preferred embodiments of the present invention, those skilled in the art once obtain the basic creative concept of cicada, then can make other change and amendment to these embodiments.So claims are intended to be interpreted as comprising preferred embodiment and falling into all changes and the amendment of the scope of the invention.