scieee AI-readable full text Open interactive document viewer

Disseny i implementació d'un sistema de composició de fluxos de video

Serra Font, Antoni

Full text

TREBALL DE FI DE CARRERA TÍTOL DEL TFC: Implementation and design of a video stream composing system TITULACIÓ: Enginyeria Tècnica de Telecomunicació, especialitat Sistemes de Telecomunicació AUTOR: Antoni Serra Font DIRECTOR: Pedro Lorente SUPERVISOR: Xavier Miguelez Ortiz DATA: Títol: Implementation and design of a video stream composing system. Autor: Antoni Serra Font Director: Pedro Lorente Supervisor: Xavier Miguélez Ortiz Data: Resum En la nostra societat, la videoconferència s’està tornat més i més popular cada dia. Està cridada a substituir les relacions interpersonals quan aquestes, degut a la distancia, son impossibles. Dins de la videoconferència, la multi conferència és el següent gran objectiu de cara a l’evolució d’aquesta: una situació on múltiples persones puguin parlar i escoltar-se entre elles al mateix temps. L’estudi de la multi conferència porta de seguida a un gran problema: l’ample de banda necessari és molt gran. Aquest projecte proposa una primera aproximació a una possible solució a aquest problema, creant un mòdul intermig en la comunicació multi usuaris que s’encarregui de mesclar tots els fluxos de vídeo en un de sol que serà retransmès a tots els usuaris. D’aquesta manera que l’ample de banda necessari per conferenciar amb un sol usuari serà el mateix que per múltiples. En aquest projecte s’estudiarà la implementació d’un descodificador – mesclador –codificador en temps real utilitzant el format DV com a base. Es mostrarà el procés de desenvolupament així com diferents proves realitzades i els seus resultats. També es realitzaran diferents proves de transmissió a distancia utilitzant aquesta eina i es comprovarà la seva eficiència en un entorn de transmissió real. Finalment, s’oferiran unes conclusions extretes després dels tests i possibles camins futurs a seguir a partir d’aquestes Title: Implementation and design of a video stream composing system. Author: Antoni Serra Font Director: Pedro Lorente Supervisor: Xavier Miguélez Ortiz Date: Overview In this document the final career project called Implementation and design of a video stream composing system is presented. In our society, the videoconference is something that’s becoming more and more popular every day. It is called to substitute the interpersonal relationships when they become impossible due to distance. And within the videoconference, the multiconference is the second big objective to attain: a situation where multiple people can listen and talk to each other at the same time. The multiconference research leads to a problem soon enough: the bandwidth necessary to achieve it. This project proposes a first approach to a possible solution to that matter: create an intermediate module in the multi-users communication which job will be mix all the streams into one, which will be transmitted to every user. That will allow to be able to employ the same bandwidth for one user that for several In this project it will be studied the implementation of a decoder-composer- encoder module in real time using the DV format as a base. The process of development will be shown with the different tests and results. Also, the module will be tested in a real transmission environment in order to prove its efficiency. Finally, a conclusions of the whole will be extracted, and a future line of study and research will be proposed ACKNOLEDGEMENTS To Pedro Lorente, for not giving up on me and for his infinite patience. To David Cuenca, for always be there to listen to my complaints with a smile. To all the i2cat members, for their support and kindness. INDEX CHAPTER 1: INTRODUCTION ......................................................................... 4 CHAPTER 2: DV AND FRAME PROCESSING BASICS .................................. 6 2.1 DV Overview .............................................................................................. 6 2.2 DV color encoding ...................................................................................... 7 2.3 Chroma subsampling: YUV 4:2:0 ............................................................... 8 2.4 DV frame structure ................................................................................... 10 CHAPTER 3. COMPOSITION MODULE ......................................................... 12 3.1 Module overview ...................................................................................... 12 3.2 Decoder .................................................................................................... 13 3.3 Composer ................................................................................................... 14 3.3 Encoder .................................................................................................... 15 3.4 Composer tests ........................................................................................ 16 3.4.1 Image scaling........................................................................................................ 17 3.4.2 Sound Management ............................................................................................. 26 CHAPTER 4. REAL-TIME INTEGRATION TEST ........................................... 28 4.2 Ultragrid .................................................................................................... 29 4.2.1 Description: ........................................................................................................... 29 4.2.2 UG Test results ..................................................................................................... 30 4.3 MCU ......................................................................................................... 31 4.3.1 Video capturing test .............................................................................................. 34 4.3.2 Multiple sources capture test ................................................................................ 36 4.3.3 Real time composing test ..................................................................................... 38 4.3.4 Full transmission test ............................................................................................ 40 4.2.5 Overall test results ................................................................................................ 42 CHAPTER 5. ENVIRONMENTAL IMPACT ..................................................... 45 CHAPTER 6. CONCLUSIONS ......................................................................... 46 CHAPTER 7. FUTURE WORKS ...................................................................... 47 REFERENCES ................................................................................................. 48 ACRONYMS .................................................................................................... 49 ANNEX A: COMPOSER MODULE CODE (PROCESSDV.CPP) .................... 50 ANNEX B: COMPOSER MODULE CODE (PROCESSDV.H) ......................... 54 ANNEX C: MCU FRAME PROCESSING MODIFICATION (SOCKETWORKER.CPP::PROCESS FUNCTION) ........................................ 55 8 Implementation and design of a video stream composing system YUV 4:4:4 keep intact the luminance and the colour information. YUV 4:2:2 reduce sampling of the colour information by a half. YUV 4:1:1 reduce sampling of the colour information by a quarter. The YUV 4:2:2 encoding obtains near image quality to the RGB 4:4:4 encoding and it reduces the bandwidth by two-thirds, so it is normally used in High Definition video. In many sections of this project this color encoding is going to be used. Fig 2.2 Image and its three YUV components RGB to YUV formulas: Y = 0 , 299 R + 0 , 587 G + 0 , 114 B (2.1) U = 0 , 492 ( B − Y ) = − 0 , 147 R − 0 , 289 G + 0 , 436 B (2.2) V = 0 , 877 ( R − Y ) = 0 , 615 R − 0 , 515 G − 0 , 100 B (2.3) 2.3 Chroma subsampling: YUV 4:2:0 The PAL DV uses a YUV codification of 4:2:0 which responds to a chroma subsampling of the 4:2:0. Chroma subsampling is the practice of encoding images by implementing less resolution for chroma information than for luma information. It is used in many video encoding schemes — both analog and digital — and also in JPEG encoding. Chroma subsampling deviates from color science in that the luma and chroma components are formed as a weighted sum of gamma-corrected (tristimulus) R'G'B' components instead oflinear (tristimulus) RGB components. As a result, luminance and color detail are not completely independent of one another. There is some "bleeding" of luminance and color information between the luma and chroma components. The error is greatest for highly-saturated colors and Implementation and design of a video stream composing system__ 9 can be somewhat noticeable in between the magenta and green bars of a color bars test pattern (that has chroma subsampling applied). This engineering approximation (by reversing the order of operations between gamma correction and forming the weighted sum) allows color subsampling to be more easily implemented. Figure 2.3. Original. Without color subsampling. 200% zoom. Figure 2.4.: Image after color subsampling 4:2:0 U and V are each subsampled at a factor of 2 both horizontally and vertically. There are three variants of 4:2:0 schemes, having different horizontal and vertical siting. In 4:2:0 DV, U and V are cosited in the horizontal direction. In the vertical direction, they are cosited on alternating lines . The PAL and SECAM color systems are especially well-suited to this kind of data reduction. Most digital video formats corresponding to PAL use 4:2:0 chroma subsampling, with the exception of DVCPRO25, which uses 4:1:1 chroma subsampling. Both the 4:1:1 and 4:2:0 schemes halve the bandwidth compared to no chroma subsampling. With interlaced material, 4:2:0 chroma subsampling can result in motion artifacts if it is implemented the same way as for progressive material. The luma samples are derived from separate time intervals while the chroma samples would be derived from both time intervals. It is this difference that can result in motion artifacts. 10 Implementation and design of a video stream composing system 2.4 DV frame structure The standard defines de DV-based data structure for the interface of digital audio, subcode data, and compressed video with the following parameters: - 525/60 system: - 4:1:1 image sampling structure, 25MB/s data rate - 4:2:2 image sampling structure, 50 MB/s data rate - 625/50 system: - 4:1:1 image sampling structure, 25MB/s data rate - 4:2:2 image sampling structure, 50 MB/s data rate DATA STRUCTURE: The project uses the 625/50 system at 25MB/s since it will be working in PAL mode. The figure shows a scheme of how is structured a DV video frame in this system: Figure 2.5. Data structure for one video frame As can be seen, the structure of a video frame is divided into 12 DIF sequences, each one composed of 150 DIF blocks. Each DIF sequence has the following sections: - Header section: 1 DIF block - Subcode section: 2 DIF blocks Data in one video frame DIF sequence n-1,0 Header section Subcode section VAUX section Audio & Video section DIF sequence 0,0 DIF sequence 1,0 H0,0 SC0,0 SC1,0 VA0,0 VA1,0 VA2,0 A0,0 V0,0 ...... V132,0 V133,0 V134,0 ID Data Implementation and design of a video stream composing system__ 11 - VAUX section: 3 DIF blocks - Audio section: 9 DIF blocks - Video section: 135 DIF blocks Each DIF block consists of a 3 bytes ID and 77 bytes of data. That makes for a total of 144000 bytes in each PAL frame. 12 Implementation and design of a video stream composing system CHAPTER 3. COMPOSITION MODULE Presentation The goal of this chapter is to develop an independent module which should be capable of decode and encode an entire DV video independently from any commercial and more complex decode system, and compose a video frame in different modes. The reason is that since the whole system is oriented to a future implementation in videoconference system, it is needed to process as fast as possible, and in order to do so, it is imperative to use only the most basic features to achieve the encoding and decoding of the frame. What will be shown in this chapter is the explanation of the system in high level. 3.1 Module overview The scheme of the system is as shown in the block diagram below: Figure 3.1. Composer module block diagram As seen, the goal is not only to build a completely independent encodingdecoding DV system, but also to be able to treat the stream once decoded. The entire module is based on the functions from the libdv libraries. LIBDV is a software codec for DV video, the encoding format used by most digital camcorders, typically those that support the IEEE 1394 (a.k.a. FireWire or i.Link) interface. It basically decodes and encoder from and to the DV format. The data is extracted from the original raw DV file and stored in a vector so it can be treated later. The decoder-encoder module considers the data stream stored as a series of video frames one after another. The procedure will be to take one complete frame, decode it, treat it, and then encode it again in DV format. The entire sequence is built on a file with an initially known number of frames. DECODER COMPOSE ENCODER Implementation and design of a video stream composing system__ 13 3.2 Decoder The first approach is to work with a single captured DV frame, a system from which it is possible to decode, treat, and then encode is developed. The decoder is implemented as follows: Figure 3.2. Decoder block diagram As can be seen, the first step is to define the settings of the decoded file we expect. Those settings are the following: - dv_quality : There’s a range of options here, but since we expect to obtain a result similar to the original, we set the quality to BEST - dv_height/widtht: Next step is to define the height and width of the resulting frame. Libdv defines a series of variables which reflect the types of the most common video types: NTSC and PAL. Since PAL video is defined, the values are PAL_HEIGHT and WIDTH. - decode_format: dv_color_yuv is set as it is also the original’s format. - sampling: The video mode will be YUV 4:2:2. Once this is done, the only thing left to do is call the decode function decodeDV, which contains the variables and functions needed for the decoding procedure. The most important of which being: Decode_full_frame(); This function calls for the incoming stream of video, and using the previously defined settings, returns a decoded frame sized 720x560x2 bytes. Video settings Video data frames DecodeDV function Decoded raw video 14 Implementation and design of a video stream composing system It is also important to parse the headers so it leaves only the information to be fully treatable. To do so, the program uses the functions dv_parse_headers from the libdv library. At the end, we have a stream of data exclusively composed of video and audio data. Since this is the moment the data is completely treatable, the functions of compressing and mixing are called now. 3.3 Composer The name “composer” encloses every function which objective is to modify the original stream of data while preserving the structure of the video frame. This is the core of the module, since it will allow putting two or more frames info into a single one. As a test, three samples of modifying code are implemented as seen below: Figure 3.3. Composer functions diagram. Plain decoding: The objective is to return the same thing you decoded, so no additions are made. This is necessary in order to demonstrate the encodingdecoding system works, and also that the other tests are achievable. DECODER ENCODER Sound management Image scaling Plain decoding Implementation and design of a video stream composing system__ 15 Image scaling: The aim of this test is to create a single exit video stream from two different sources. Sound management: Once proved the previous test works, and for a future development, a set of tests with the audio of the video streams is performed. All the tests will be performed through a PIP function, being the responsible of calling the decoding and encoding functions, and each of the test-resizing ones. 3.3 Encoder For the encoding section, the implementation is essentially symmetric to the decoding one. Once the video is treated in RAW mode, the intention is to return the resulting video to DV format so it can be reproduced in any video player. Actually, the images shown until this point are the post-encoding ones. There’s a specific function programmed for that, which is called “encodeDV”. Basically it follows the same procedures as the decoder section: Figure 3.4. Encoder block diagram The main functions from the libdv library responsible for the encoding are: - Dv_encode_full_frame( ); Encodes the video frame - Dv_encode_full_audio( ); Encodes the audio selected The video encoder uses the settings already defined in the decode section to create the DV frame, so the result is exactly the same as the original as seen before. Enco function RAW video audio DV video Video settings 16 Implementation and design of a video stream composing system Once the DV frame is recomposed, the procedure is to save the result on a file so it can be played in any DV player available. This is a standard file-write procedure, saving one encoded frame after another writing them directly on the file. The incoming data stream is returned untouched to the encoding module. This is the first step in order to achieve the rest of the project: the creation of a fully functional encoder and decoder module independent from any other software. The figure 3.5 shows that the original image and the decoded and re-encoded one are exactly the same. Figure 3.5. Original (left) and decoded and re encoded (right) 3.4 Composer tests The decoder and encoder are fully functional. Next the composer is going to be tested; two tests will be performed: one for the video and one for the audio. For the purpose of the tests, two pairs of DV samples had been used as seen in figure 3.6: two single-frame DV videos and two more of 200 frames. Although as it has been said, the video is just set of frames one after another, to simplify the debugging process every test was performed first in a single frame, and then applied to the full video. Implementation and design of a video stream composing system__ 17 Figure 3.6. DV frames (up) and videos (down) used in the project. The images are extracted from the visualization program that’s going to be used for the whole project: the “kino” KINO Kino is a non-linear DV editor for GNU/Linux. It features excellent integration with IEEE-1394 for capture, VTR control, and recording back to the camera. It captures video to disk in Raw DV and AVI format, in both type-1 DV and type-2 DV (separate audio stream) encodings. You can load multiple video clips, cut and paste portions of video/audio, and save it to an edit decision list (SMIL XML format). Most edit and navigation commands are mapped to equivalent vi key commands. Also, Kino can export the composite movie in a number of formats: DV over IEEE 1394, Raw DV, DV AVI, still frames, WAV, MP3, Ogg Vorbis, MPEG-1, MPEG-2, and MPEG-4. Still frame import and export uses gdk-pixbuf, which has support for BMG, GIF, JPEG, PNG, PPM, SVG, Targa, TIFF, and XPM 3.4.1 Image scaling In this module, two images are decoded and mixed in a single one. This is performed once by every frame in the video stream; so the final result is as if two videos are shown at the same time. The basic scheme of this part is as follows: 24 Implementation and design of a video stream composing system Figure 3.14. Composition and resizing aplyied to a video feature. 3.4.1.3 Multiple scaling composition Since an image composed literally one over another is quite difficult to understand, and considering a situation where can be 3 or more of them in the same video output, the last test of the mixer has been with two compressed images in a third blank one that is used as a canvas for the others. Since it is already proved that frame and video mixing work the same way, the test was performed on the videos and the scheme of the result is: Implementation and design of a video stream composing system__ 25 Figure 3.14. Demonstration of composing using resizing and an empty base 26 Implementation and design of a video stream composing system 3.4.2 Sound Management It is important to notice that none of the tests or the code of the program had taken account of the audio until now. But also, as part of what videoconference is, it’s important to be able to select different audio depending on who’s on top, and silence the other participants. For that matter, an audio decoding module is also implemented. The overview of it being: Figure 3.15. Sound mixing diagram Audio Decoding: Either one or the other method, the audio decoding is implemented the same way. As part of the decoding method DecodeDV, the essential function used for decoding audio is an equivalent of the video one, called: Decode_full_audio(); which essentially grabs the audio from the frame and stores it in an audio buffer to be later implemented in the encoding section. It is also remarkable to see that there’s actually no need of decoding the audio at all for the video to work. In fact, the first tests where done with no audio whatsoever. Single audio decoding: Essentially, the idea is that either one or the other audio source from the videos is played in the output. The basic idea is that before decoding, the user chooses which audio wants to hear, and then only that one is decoded. Since the window position and the size of the videos are predetermined in the decoding module, there’s not really a need to decode both sources, which grants a delay reduction in the overall performance. The only issue of this method is that you essentially lose the audio of the video you’re not decoding SINGLE AUDIO DECODING MIXED AUDIO DECODING Audio sources Audio output Implementation and design of a video stream composing system__ 27 Shared audio decoding: The other mode it was tested was to insert in one video an audio signal from both sources. The method was to play 50% of the time from one audio source, and the rest from the other. That is also a way of seeing how the audio is bind to a frame instead to the full video. To do that, the decoding was performed for both the sources, but only encoded for one of them for half of the frames. The result output video have, as planned, the sound of one of them and in the middle, switch to the other. 28 Implementation and design of a video stream composing system RECEIVE SEND CHAPTER 4. REAL-TIME INTEGRATION TEST 4.1 Overview Once the composer module is completed, the following step is to try it inside a full transmission system, since it’s its final purpose. All the efforts to this point converge in a final situation where two sources from different places send via IP their stream of video and our system captures it, decodes each frame separately and then compose the resulting raw video, encodes it and resends it to a third user. The module is intended to act as an intermediary between the users as it is shown in the figure: Figure 4.1. Composition module integrated as an intermediary module in a multiconference For testing the online capabilities of the software, it will be integrated inside two softwares developed to work with videoconference: - Ultragrid - MCU The two will be presented and proved with a video transmission to test the composer in a real case scenario. User 1 User 3 COMPOSITION MODULE User 2 Implementation and design of a video stream composing system__ 29 4.2 Ultragrid 4.2.1 Description: To test the computing complexity of the software, a first test will be performed in order to check if there’s any loses in the net and also if the CPU is capable of handling the processing of frames without adding too much delay. The software that is going to be used is the open source software named UltraGrid (UG). It was initially developed by Ladan Gharai and Colin Perkins in the Information Sciences Institute East from University of Southern California. This software is used for real time transmissions of high definition video. It could be used as videoconference system and as distribution system. It is the first system able to transmit uncompressed HD video over IP. UG is able to capture from one HD source, transmit the HD-SDI (SMPTE 292M) stream captured over IP network using RTP/UDP protocols, and visualize it using several solutions. It supports full rate uncompressed HD video at over 1.2 Gbps with minimal latency. For uncompressed HD, UltraGrid operates in two different modes: 8b/10b colour depth. One of those operates at just under 1 Gbps (for environment limited to 1 Gbps transport as Gigabit Ethernet connection) and the other at full rate HD mode of over 1.2 Gbps. Ultragrid also works in DV based software, achieving a full encoding and decoding capabilities, along with receiving, sending and visualization. Ultragrid doesn’t decode audio at this moment, so the test will be performed without it. 30 Implementation and design of a video stream composing system TEST SETUP For this test purpose, it’s interesting the sending capabilities of the software. Using a DV capture module designed by Pedro Lorente, UG can capture from two cameras directly plugged into the PC, and then grab a frame from each of them and compose it, and then proceed to send it to a selected destination. The diagram of the process can be seen below: Figure 4.2. Diagram of the test setup UG captures the frame using a firewire wired based software and stores the stream of data in the memory. All the process will take place inside the firewire.c function from the video_capture set of functions The storage system is composed of two vectors holding each of the frames captured. It is important to insist in the fact that for this test, the sources are directly connected to the computer, so there’s no delay in the transmission. Also, since it will be done in a frame-based layer, the frames are not decomposed into packets to be sent to the net, so it frees a lot of memory. The buffer vectors are 3 frames long, so it recycles the positions once they arrive; the fourth frame will be overwriting the first one and so on. The program is designed so only one of the sources is transmitted to a receiver display. Using this code, the composing module will be inserted, once the two frames are captured and stored in the buffer. Then, the PIP function described before is called and it proceeds to compose both frames in real time. Once the operation is completed, the resulting frame is returned to the program so it can be sent to the destination IP. 4.2.2 UG Test results The results of the test allowed depuration of the leakage memory problems of the program so it would become able to process composition in real time a complete composing of data. More than that: showed that the frame mixing Video capture MIXER Implementation and design of a video stream composing system__ 31 process can be achieved within a single time of frame, adding few delay from the sources, since the video played smoothly at 30 fps. Nonetheless, it is important to say that the processing CPU had to be changed in order to achieve that: so not all ordinary CPU can handle the processing speed needed to maintain the requirements of the software. 4.3 MCU I2cat foundation developed this tool in order to moderate videoconferences avoiding the use of a multicast. The basic functioning skips the processing of the packets allowing high speed transmission in multi-conference. The basic operation of this software is the following: A source user is defined first, and then a series of destinations are attached to that particular source. It is possible to define multiple sources with multiple destinations, so for practical purposes, what you get is a system where multiple sources can be transmitted to multiple users. The figure shows how it is performed: Figure 4.3. MCU functioning diagram MCU 32 Implementation and design of a video stream composing system As can be seen, the program generates an object called “streamlist” each one composed by one source and its list of destinations, which are defined by “udpStream” objects. The whole capture process is done inside an object called “socketworker”, which holds all the logic of the software and it is shared by every incoming packet. The system is designed to maximize the transmission speed, so there’s no processing of packets whatsoever, just a method of capture it from the source and replicate it to every destination associated. It also works in two different modes: local and remote. In local mode the orders are given from the computer terminal where the program is located. In remote mode, the user can give the orders from a different location, sending them via telnet or any other mean. TEST SETUP The idea was to use this software to add the composer module already developed, applied to a real time stream of data instead of a fixed video length. Initially, and for the purposes of the project, the code modification will work with the following premises: - Only two sources will be transmitting at the same time - Only one destination will be receiving at the same time The data is sent from two different video cameras which send the video to a PC. Then a program called DVTS process the data and sends it packetized to the machine which runs the MCU. DVTS (Digital Video Transport System) is an application for sending and receiving DV(Digital Video) streams using the Internet (as refered in RFC3189) The DV data is sent over the Internet using RTP (Real-Time Transportation Protocol). The DV/RTP packet format is shown in Figure 4.6. Original packet format is adopted. As shown in Figure 3, the isochronous stream packet of DV is simply encapsulated with RTP/UDP/IP. Figure 4.4. DV/RTP packet format Implementation and design of a video stream composing system__ 33 The program inserted in the MCU proceeds to treat the data and resend the resulting frame packetized to the destination computer. Figure 4.6 shows the diagram of the whole process Figure 4.5. Complete MCU transmission diagram. CODE MODIFICATION To achieve that, the first thing to do was to find the access point of the MCU; and that point was the moment the packets are captured and transferred in a variable to be sent at the different destinations. In the figure 4.7 is shown an example of how two different sources with different destinations work with the same object. MCU 40 Implementation and design of a video stream composing system 4.3.4 Full transmission test The final step of the project is to split again the frame into packets and resent it to the net. The final process can be seen in the diagram below: Figure 4.12. Complete system algorithm diagram Receiving packets Both frames complete? Yes No Compose it Repacketize the frame Send it to the destinations Implementation and design of a video stream composing system__ 41 Fortunately, the same MCU provides the tools so the only thing needed is to literally grab the exact amount of data to put in each packet and store it in a variable so the program can send it. That size is known since it’s the same as the ones that were received, and that is: - One packet of 1200 bytes. - 105 packets of 1360 bytes. 144000 = 1360*x + 1200; X = 105; Also, there’s the header’s issue. The UDP/IP ones are implemented by the same MCU, but the RTP header has to be introduced manually. Fortunately, almost every part of it remains the same, and only the timestamp varies. That value is being stored for reference purposes all along, so it’s easy to be retrieved from the objects. Each of the two sources frame’s timestamp can be used, since the important thing here is that all the packets from the same frame, share the same timestamp for capturing and construction purposes. So the first step is to define a variable to store a single packet. To be consequent with the program, the same for capturing was replicated for the sending, which is a 2048 bytes memory slot. It’s much more than we needed, since the MPU will be of 1500 bytes, so it ought to be enough. With that done, the procedure is to overwrite the last captured packet’s header and substitute the timestamp to the correct one. That will occupy the first 12 bytes and define the RTP header. Then, the buffer containing the header will be filled with either 1360 or 1200 bytes every 105 packets. The frame is sent complete, so the capturing doesn’t start again until the frame deconstruction and sending iteration is complete. This also adds a complementary processing time in which we’re not processing frames, and thus, losing data. It is crucial for the future of the project, that the whole process of capture process and send doesn’t take longer than a time of frame so it registers no delay in the transmission. 42 Implementation and design of a video stream composing system MCU TEST SETUP The test setup was the complete system process: - Two cameras sending through a pc’s via the DVTS software. - A central CPU with the MCU program modified with the mixing program developed and the sending algorithm recently added - A PC with the DVTS software to be able to receive the sending mixed frame. 4.2.5 Overall test results The results are somewhat unstable: sometimes starts receiving and then stops for a while. The memory usage keeps increasing until saturates the CPU. But one thing’s clear, and that is that the processing time costs too much and the resulting received video is at a very low frame rate, barely conserving the movement. To be able to detect the problem, a profiler to see the program occupation was run. The results are presented in the following table: Samples % Image name Symbol name 4488 27,7294 strManager processDV::pip(unsigned char*, unsigned char*) 4036 24,9367 strManager socketWorker::build_select_list() 3725 23,0151 strManager socketWorker::check_select_list() 1648 10,1823 strManager socketWorker::process(int) Table 1: Profiler's CPU usage analysis results As can be seen in the chart and also in the graphic below(figure 4.13), the project uses only the 36% of the total program CPU usage in that particular software, which is quite low and it shouldn’t produce as bad results as it does: Implementation and design of a video stream composing system__ 43 Figure 4.13. CPU usage of the program and the project Observing more in detail the exact functions(figure 4.14), it can be seen that two of them whose are from the MCU, occupy 48% of the total usage even before executing the recomposing of the frame and the mixing. Thus, this program is rather inneficient to acomplish the real-time sending using the designed program, since it requires far more CPU capabilites than the program offers. Figure 4.14. CPU usage detailed by function 44 Implementation and design of a video stream composing system In the best situation though, what it is achieved is a noncontinuous smooth video, which it is not the aim it is seeked. The difficulty is, as it has been stated, that the program works in syncronous mode, and it delays the whole process. It’s reasonable to expect the mixer to work within a time of frame, but not the entire capturing, recreating the frames,mixing, repacketize and sending. For that matter, a thread for capturing and another for mixing will be a good trying as a solution. Implementation and design of a video stream composing system__ 45 CHAPTER 5. ENVIRONMENTAL IMPACT Rather than being a nuisance to the enviroment, the project is an aid to reducing the amount of energy and resources necessary for the same task without it. The project itself looks for an inprovement in bandwidth usage, and thus if less bandwitdht is needed, less energy is spent, which leads to a reduction of raw materials needed to produce it. Plus, the improvement presented in this project allows for a multiple users to communicate to each other with a minimum of bandwidth, which saves multiple connections and their correspondant waste in enegy and resources. Also, any inprovement in videoconferences helps people not having to move to a certain location to communicate with others, which allows savings in vehicle fuel and the contamination that carries with it. 46 Implementation and design of a video stream composing system CHAPTER 6. CONCLUSIONS The goal of bringing a mixer into de real-time videoconference is not as trivial as it may appear, but sure has lots of advantadges. First thing to consider is that the complete execution of the code had to be performed in less than a time of frame or so. In videoconference the response time is critical, and the software that was developed was aimed to that purpose: The idea of isolate the decoding and encoding side was done to be able to reduce the computing time to a minimum. The composer module may have it’s issues, after all, it may very well exist some other more optimal solutions to that; but it really won’t affect much the code itself, and the solution of eliminate pixels is as good as any other for the project objectives. One thing to take into account about the composer is that the functions of libdv used in the decoding and encoding process are far from ideal: In fact, in the same website of the developers advertise that their software is 2 or 3 times slower than the commercial versions. This may not be critical but is also another point where there’s still room for improvement. The real-time integration test is the one that brought the majority of the problems: it is necessary to take into account the delay and ensure that the videoconference doesn’t get affected by it. So as seen in the two tests, it is different for each software used: one worked perfectly and the other one didn’t. What the UG test shown was that it is possible for the module to work within the time of frame limit, and still be able to transmit without loses and reasonable delay. Achieving that, allowed to proove one of the main goals of the project: to create a fully operational composer which permits a full real-time transmission with acceptable delay and half the bandwith necessary. Thus, the program works, but since it’s completely dependant from the software used to capture and send the data, it still have room for some improvement. Also, the software is fully capable to be integrated in any C based videoconference software and the two tests were performed as example of that. The MCU test was not successful, more due to the fact that the software was not initially designed for handling a treatment of data, but for replicate the entry packets trying to achieve the maximum speed. Since the MCU works in packet level, and thus didn’t had it’s own frame mounting software, the whole system for capturing and creating the frame and the inverse process had to be designed from a scratch. Requires lots of improvement just to achieve a stable functioning. Also, the main problem of the MCU algorythm designed is that (unlike UG, which works with threads) it works as a syncronous program that can’t keep the transmition speed. Further tests were performed in faster CPUs but the problem remained that it wasn’t an efficient way of handling it. Implementation and design of a video stream composing system__ 47 CHAPTER 7. FUTURE WORKS The future works related to the project are kind of obvious: The software holds a fully functional composer that needs to be tested in a fully optimized software that allows the transmiting and receiving. It’s important to take into account the delay related to the reconstruction of the frame and resending. A good testing for the future will be change the type of resizing method in order to see if it affects the processing of the image, since for the project it was chosen a simple one. Also there’s the quality issue which was not studied in the project, but with the reduction of the size comes a loss in quality. Adapting that to the Ultragrid capabilities, it will also be possible the design of an automatic adaptation system that allows different compression types depending of which bandwidth there’s available. The results in the Ultragrid test still have some issues to resolve. For example it’s still to be tested if the full delay of a system transmiting with the composer module as intermediary will permit a reasonable real-time transmission without too much delay for the users. In other words: if the bandwidth win it’s worth it; since it is only tested the sending capabilities until this point. The MCU has some serious issues to be worked in. To begin with, as it has been said, the work in synchronous mode is not optimal, and a full re-thinking is required. Maybe a system of threads should be a solution, to handle the frame capturing on one side, and the frame processing on the other. It worked fine in UG and the MCU has some unique capabilites that makes it specially suited for the work. Even if that is achieved, the capturing of the packets and recreating of the frames is not optimal. The system was tried as a test to see if it was suitable to follow the work and the results shown it was not. Still in the MCU, too much computer work is dedicated to internal functions even when the system is not processing anything else than packets. It needs to be adapted and worked on if it is to be used for this function. This system is useful as a multiconference application. Although the tests were performed with only two sources for simplification purposes, it’s quite easy to adapt the system to hold a three, four or any number of sources without too much addition. The different compression tests shows there’s plenty of possibilities in order to create a composed frame with multiple sources, adding few extra computing time. For the time being, next step could be to try some more users and see how many can it handle without losing frames. It is understandable that is quite dependant of the processing capacities of the computer though. Since the number of participants affect the processing capacities, a software allowing a maximum number of participants depending of the processing capacitiy of the CPU is also a good idea, sending the others via direct bandwith if it is allowed and processing the frames in the receiver. Finally, the audio side is the less studied. Audio mixing hasn’t been tested yet, since it will require a further study on how the audio is decoded, for all the sources to play at the same time. 48 Implementation and design of a video stream composing system REFERENCES [1] Wikipedia. DV http://en.wikipedia.org/wiki/DV [2] Wikipedia. Modelo de color RGB. http://en.wikipedia.org/wiki/Modelo_de_color_RGB [3] Wikipedia. RGBA color space. http://en.wikipedia.org/wiki/RGBA_color_space [4] Wikipedia. YUV. http://en.wikipedia.org/wiki/YUV [5] Wikipedia. Chroma subsampling http://en.wikipedia.org/wiki/Chroma_subsampling [6] DV (falta la info del dossier) [7] DVCAM Format Overview 2000.Sony corporation [8] Quasar DV codec: libdv http://libdv.sourceforge.net/ [9] Kino Video editor http://www.kinodv.org/ [10] DVTS:DV stream encapsulated into IP http://www.sfc.wide.ad.jp/DVTS/ [11] UltraGrid. http://ultragrid.dcs.gla.ac.uk/ [12] RTP header structure http://www.geocities.com/intro_to_multimedia/RTP/header.html [13] Compression eliminating pixels Adaptive media content architecture regarding users capabilities. TFC. EPSC.David Cuenca. [14] DV Format Technology http://www.dvformat.com/htm/features/2000/8_00/dv_format_faq.htm [15] SMPTE standard for television – Data structure for DV-Based Audio, Data and compressed video – 25 and 50 Mb/s 1999. Society of motion picture and television engineers Implementation and design of a video stream composing system__ 49 ACRONYMS DV Digital Video DVTS Digital Video Transport System Fps frames per second HD High Definition IP Internet Protocol JPEG Joint Photographic Experts Group MCU Multi Conference Unit MPEG Moving Picture Expert Group NTSC National Television System Committee PAL Phase Alternating Line (720x576 pixels) RGB Red, Green and Blue RGBA Red, Green, Blue and Alpha RTP Real Time Protocol UDP User Datagram Protocol UG UltraGrid YUV a colour space that is defined by luminance (Y) and two components of chrominance (UV) YUV422 is YUV subsampling color by a half YUV420 is YUV 2:1 horizontal and 2:1 vertical down-sampling. PIP Picture in Picture 56 Implementation and design of a video stream composing system } else { if( packet->ts != frame1.refer) { commence = true; frame1.refer=packet->ts; if( frame1.lastOk==1) { // std::cout << "entra" << std::endl; //fwrite(frame1.buffer[frame1.AF],offset1,1,tryout); //indx1++; //frame1.lastOk = 0; // if( indx1 == 600 ){ // end1=1; // closeFileDV(tryout); //exit(0); } offset1=0; } if (commence == true && packet->ts == frame1.refer){ memcpy(frame1.video[frame1.AF].buffer+offset1,buffer+12,rlen- 12); offset1=offset1 + rlen-12; if(offset1 == 144000){ frame1.video[frame1.AF].isready =1; frame1.AF++; //std::cout << frame1.AF << std::endl; //frame1.lastOk = 1; } } Implementation and design of a video stream composing system__ 57 } } } // SEGON SOURCE if( port2 == frame2.sourceid ) { check2 = true; if(gole == true){ if( first == true) { frame2.refer= packet->ts; first = false; offset2=0; } else { if( packet->ts != frame2.refer) { commence = true; frame2.refer=packet->ts; if( frame2.lastOk==1) { // fwrite(frame2.buffer[frame2.AF],offset2,1,tryhard); // indx2++; // //frame2.lastOk = 0; // if( indx2 == 600 ){ // closeFileDV(tryhard); // end2=1; // //exit(0); //} } offset2=0; } if (commence == true && packet->ts == frame2.refer){ memcpy(frame2.video[frame2.AF].buffer+offset2,buffer+12,rlen- 12); offset2=offset2 + rlen-12; if(offset2 == 144000){ //std::cout << "entra" << std::endl; frame2.video[frame2.AF].isready=1; frame2.AF++; 58 Implementation and design of a video stream composing system //frame2.lastOk = 1; } } } } } if(trig == true){ int k, diffBxpckt,framelen; diffBxpckt=17*80; framelen=144000; // while ( off < framelen){ // printf("while\n"); // memcpy(buf_out,packet,12); // memcpy(buf_out+4,(char*)frame1.refer,4); // if (framelen - off < diffBxpckt){ // memcpy (buf_out+12, prec+off, framelen - off); // off=framelen; // } // else{ // memcpy (buf_out+12, prec+off, diffBxpckt); // off=off+diffBxpckt; // } for(k=0; k<106; k++){ if( k < 105){ memcpy(buf_out,packet,12); memcpy(buf_out+4,(char*)frame1.refer,4); memcpy(buf_out+12,prec+off,1360); off+=1360; } else { //for(j=0;j<2048;j++) buf_out[j]=0; memcpy(buf_out,packet,12); memcpy(buf_out+4,(char*)frame1.refer,4); memcpy(buf_out+12,prec+off,1200); off =0; } if (rlen < 0) LOG4CXX_ERROR(logger, "Error in recvfrom"); if (rlen > 0) { int port = fdPort[fd]; //cout << "Thprecread->, detecta paquete en: " << port << endl; Implementation and design of a video stream composing system__ 59 sockaddr_in a = (sockaddr_in)from; a.sin_port = htons(port); // ÑAPA very ugly. //int sn = ntohl(((uint16_t*)(&buf[0]))[1]); shared_ptr<streamList> b = this->getStreamListBySocket(a); if (!b) { LOG4CXX_WARN(logger,"NULL pointer streamList not found.") exit(0); return; } list < shared_ptr<udpStream> > c = b->getDestinations(); list < shared_ptr<udpStream> >::iterator it; for(it = c.begin(); it != c.end(); ++it) { sockaddr_in d= (*it)->getAddr(); sendto (fd, buf_out, rlen, 0, (struct sockaddr *)&d, sizeof (struct sockaddr_in)); } } } off=0; trig = false; } }