<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[LIVEOP X Team - Medium]]></title>
        <description><![CDATA[Insights, development stories and noteworthy updates from the LIVEOP X Product Team. LIVEOP X is the most advanced mobile operational intelligence and collaboration platform for public safety services and government agencies. - Medium]]></description>
        <link>https://medium.com/liveop-x-team?source=rss----fac86e03e899---4</link>
        <image>
            <url>https://cdn-images-1.medium.com/proxy/1*TGH72Nnw24QL3iV9IOm4VA.png</url>
            <title>LIVEOP X Team - Medium</title>
            <link>https://medium.com/liveop-x-team?source=rss----fac86e03e899---4</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 13:12:16 GMT</lastBuildDate>
        <atom:link href="https://medium.com/feed/liveop-x-team" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Using NSUndoManager for fun and profit]]></title>
            <link>https://medium.com/liveop-x-team/using-nsundomanager-for-fun-and-profit-16a8d7aa77be?source=rss----fac86e03e899---4</link>
            <guid isPermaLink="false">https://medium.com/p/16a8d7aa77be</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[intelligence]]></category>
            <category><![CDATA[public-safety]]></category>
            <category><![CDATA[fire-department]]></category>
            <dc:creator><![CDATA[Damiaan Twelker]]></dc:creator>
            <pubDate>Tue, 09 Oct 2018 13:22:12 GMT</pubDate>
            <atom:updated>2018-10-09T13:22:12.501Z</atom:updated>
            <content:encoded><![CDATA[<p>In the real world, where the real world is restricted to the world of computer software, undo operations are a common phenomenon. The use cases that usually come to mind when thinking of undo operations are productivity applications, such as document editors, or creativity applications such as photo editors. Indeed, in the LIVEOP X iOS app, a drawing component formed our first encounter with NSUndoManager as well.</p><p>Productivity plays a key role in LIVEOP X. In a critical situation, there is no room for error, misinterpretation or “trying to switch it on and off”. If the application does not respond the user expects it to, the user will simply abandon the app, stow the tablet, and provide first aid without all the essential information the app has to offer. To prevent this and to reach the goal of creating value for the user, we must set the highest standards in terms of productivity and app performance. This starts with the development, where sometimes we find ourselves getting some help from unexpected sources.</p><p>Within our GEO tool, first responders are handed a paint bucket to draw instructions on the map and share these with others. The hand-drawn instructions are rendered in real-time across all zoom-levels on the map, as if they were there from the beginning. The tool especially comes in handy to sketch out approach paths for units that are still en-route, or to assess the impact area of potentially toxic gas clouds. Part of the drawing tool is an undo button that undos the previously drawn line segment. An illustration is given below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bkU4UZe1z2Su7BW9EMhbzQ.png" /><figcaption>Drawing an approach route over Dam Square in Amsterdam. The view encompasses a variety of information, such as building type colouring (BAG), height information through the use of 3D buildings, and satellite imagery.</figcaption></figure><p>How does that look in code? Very simple. At the same time when the line segment is added to the map, we register an undo operation with a single NSUndoManager for the exact same line segment.</p><pre>- (void)addHandDrawnAnnotations:(NSArray &lt;id&gt; *)annotations</pre><pre>{<br>    for (id annotation in annotations) {</pre><pre>        [self.mapController addAnnotation:annotation];</pre><pre>}</pre><pre>    [self.undoManager registerUndoWithTarget:self selector:@selector(removeHandDrawnAnnotations:) object:annotations];</pre><pre>}</pre><p>NSUndoManager&#39;s APIs make it incredibly easy to use. In fact, its applicability and suitability in a codebase extends far beyond its typical use cases as described earlier.</p><h4>Undo outside a clear user context</h4><p>In our GEO configuration portal, customers can define custom actions and attach them to map layers. Then whenever an annotation belonging to a map layer is selected in the iOS app, the actions configured for that layer will be executed. An action could be to select additional map layers, or to reveal additional UI elements. An action is just a description telling the app what to do when the user selects an annotation. When an action changes in the server configuration, we simply recreate the view model representing the action.</p><p>The actions run just once. But whenever a map layer is deselected, either programmatically or by the user, or when a new annotation is selected from the same map layer, we want the impact of previously executed actions to be voided: all actions assume a clean slate. At first thought this would require a lot of hairy code checking what actions have been applied, finding and matching it with the consequences in the app, and discarding those. It is however infeasible to couple the consequences (e.g. extra UI added as a result of an action) with the action view models, since the view models are recreated on the fly. NSUndoManager forms a great solution here. Plus, overall we like to avoid hairy code if possible.</p><p>On the map layer view model, we define an NSUndoManager with one group. The group is opened on creation. Then whenever we want to undo a layer’s actions, we close the group, call -undo, and open a new group. We use grouping in order to get rid of all actions at once. Undo actions are registered at the same time actions are executed. In case of an action that adds a button to the UI, this looks as follows:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/871/1*_rjTAP9IrMXqVGpstay6Rw.png" /></figure><p>Here model is the map layer view model. Note that NSUndoManager provides two methods for registering undo actions. In case the undo selector has just one argument, registerUndoWithTarget:selector:object can be used. For more complicated undo handling, we could resort to registerUndoWithTarget:handler:.</p><p>When the layer is deselected, or when a new annotation is selected from the same layer, we close the one undo group and call -undo, causing the consequences of all actions to be discarded:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/579/1*edcpHBw0EOwGG1jks7PJxQ.png" /></figure><p>In conclusion, NSUndoManager is a very powerful tool that comes in handy in a lot of situations in which one might not immediately think of it. In the use case highlighted above, we save ourselves a lot of unnecessary and hard to maintain spaghetti code.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=16a8d7aa77be" width="1" height="1" alt=""><hr><p><a href="https://medium.com/liveop-x-team/using-nsundomanager-for-fun-and-profit-16a8d7aa77be">Using NSUndoManager for fun and profit</a> was originally published in <a href="https://medium.com/liveop-x-team">LIVEOP X Team</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Accelerating H264 decoding on iOS with FFMPEG and VideoToolbox]]></title>
            <link>https://medium.com/liveop-x-team/accelerating-h264-decoding-on-ios-with-ffmpeg-and-videotoolbox-1f000cb6c549?source=rss----fac86e03e899---4</link>
            <guid isPermaLink="false">https://medium.com/p/1f000cb6c549</guid>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[ffmpeg]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[videos]]></category>
            <category><![CDATA[gpu]]></category>
            <dc:creator><![CDATA[Damiaan Twelker]]></dc:creator>
            <pubDate>Tue, 10 Jul 2018 12:12:14 GMT</pubDate>
            <atom:updated>2018-07-10T12:12:13.571Z</atom:updated>
            <content:encoded><![CDATA[<p>At LIVEOP, we focus on providing first responders with the most relevant information in a concise manner, while at the same time not compromising on our seamless user experience. When we partnered up with <a href="https://zepcam.com/">Zepcam</a>, a leading provider of wireless (body-worn) camera systems around the world, we wanted to make sure that we delivered an experience that conforms to our high standards, not compromising on performance or efficiency.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*10b9kIXm4ZZ3wC5v2gsHEg.jpeg" /><figcaption>Optimal end-user experience is critical and perhaps the most valued aspect of LIVEOP X</figcaption></figure><p>Camera streams hosted by Zepcam come in several different formats, most importantly, HTTP Live Streaming (HLS), a first class citizen in the iOS ecosystem with built-in support in AVFoundation, and RTSP, the Real Time Streaming Protocol. HLS streams are commonly used for live television and news broadcasts. It focuses on a seamless experience for the viewer: frame drops are disallowed, out-of-order playback of frames is not allowed, and a small buffer of upcoming frames is maintained to ensure a smooth playback experience. The situations during which Zepcam streams are activated are often life-threatening. Officers could be live-streaming from their body-worn camera’s while attempting to contain a riot, or a ladder engine with a camera mounted on top could be providing a birds eye view of a large building fire including the position of firefighters on the ground. Our definition of a seamless user experience is different from the one prescribed by HTTP Live Streaming: in our case, it is important that the frames displayed to the user are as realtime as possible. They could arrive out-of-order, and a couple of frames could be dropped, as long as this benefits the realtime-ness of the stream. Adding our requirements up, we arrived at using RTSP over UDP.</p><p>Apple does not provide support in any of the high-level frameworks for playback of RTSP streams. MPMoviePlayerController, AVPlayerItem and AVPlayer, all high-level system classes for playback of video streams, do not support RTSP streams. Fortunately, <strong>FFMPEG</strong>, the swiss army knife of audio/video processing, is equipped with the right tools to process and decode RTSP streams. FFMPEG has been around for 17 years now in the open source community, and has since established itself as a reliable force behind a variety of end-user applications, such as VLC, Google Chrome, and Chromium¹.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dcYYWSH6SdHx_pQs94uZrw.jpeg" /><figcaption>Underneath the beautiful package lies an immense amount of power. To keep it running smoothly when every second counts, heavy optimization is key.</figcaption></figure><h4>Setting up FFMPEG</h4><p>The RTSP streams served by Zepcam are encoded with the H264 codec. In order to prevent a massive increase in binary size of our final iOS application file (.ipa), we chose to compile the latest release of FFMPEG from scratch (v4.0.1), enabling only those features that we expect to use. We use the excellent build script found <a href="https://github.com/kewlbear/FFmpeg-iOS-build-script/blob/master/build-ffmpeg.sh">here</a>, with a couple adjustments:</p><ul><li>Change the FF_VERSION variable to 4.0.1</li><li>Change the DEPLOYMENT_TARGET to the deployment target of your iOS application</li><li>Change the CONFIGURE_FLAGS to enable bitcode, and disable all features except those required for our stream:</li></ul><pre>CONFIGURE_FLAGS=&quot;--enable-cross-compile --disable-debug --disable-programs --disable-doc --extra-cflags=-fembed-bitcode --extra-cxxflags=-fembed-bitcode --disable-ffmpeg --disable-ffprobe --disable-avdevice --disable-avfilter --disable-encoders --disable-parsers --disable-decoders --disable-protocols --disable-filters  --disable-muxers --disable-bsfs --disable-indevs --disable-outdevs  --disable-demuxers --enable-protocol=file --enable-protocol=tcp --enable-protocol=udp --enable-decoder=mjpeg --enable-decoder=h264 --enable-parser=mjpeg --enable-parser=h264 --enable-parser=aac --enable-demuxer=rtsp --enable-videotoolbox&quot;</pre><p>In addition, a small change in the FFMPEG sourcefile libswresample/arm/audio_convert_neon.S is required, as described <a href="https://github.com/DeviLeo/DLGPlayer/issues/19#issuecomment-384847629">here</a>. Compilation should now succeed, yielding several different libraries. Drag the libraries into your Xcode project and make sure to link them with your application target (Build Phases &gt; Link Binary With Libraries).</p><p>The global setup required to achieve video playback through FFMPEG is quite straightforward. Open the input URL pointing to the RTSP stream with avformat_open_input, find the streams from the input with avformat_find_stream_info, allocate a codec context with avcodec_alloc_context3 and avcodec_parameters_to_context, and finally open the codec with avcodec_open2. It is important to implement proper error handling and memory cleanup for all these methods, as they could all fail depending on the circumstances. In our application we also chose to implement an interrupt callback in order to exit the blocking methods early in certain situations, such as a lack of internet connection as signalled by SCNetworkReachability APIs or after a custom timeout timer has expired. Especially coupling with the reachability APIs allows us to circumvent built-in FFMPEG timeouts and fail early when no internet connection is detected.</p><h4>Decoding Frames</h4><p>The AVCodecContext struct exposes a get_format field which allows us to pick an outputAVPixelFormat for the video frames delivered by the decoder, out of a list of available formats. If we leave this field empty, the video frames will be formatted as AV_PIX_FMT_YUV420P, a format automatically detected by the decoder based on the underlying stream. Images on iOS are formatted in RGB(A) (AV_PIX_FMT_RGB24), hence an extra step would be required to convert the frames from AV_PIX_FMT_YUV420P to AV_PIX_FMT_RGB24 before display. libswscale provides a function sws_scale that does exactly this, but unfortunately it is not implemented on the GPU, meaning we incur a performance hit while performing the extra conversion step from YUV420P to RGB24.</p><p>Out of the list of available pixel formats we receive through the get_format function, there is one that requires our special attention: AV_PIX_FMT_VIDEOTOOLBOX. Although poorly documented, this format tells the decoder to pass the incoming frames to Apple’s VideoToolbox.framework. It will decode each incoming frame on the GPU, returning a CVPixelBufferRef holding the decoded data. This is much preferred over the default implementation, which requires an extra conversion from YUV420 to RGB24 on the CPU. Our function handle passed to the get_format field of the AVCodecContext now looks like this:</p><pre>static enum AVPixelFormat negotiate_pixel_format(struct AVCodecContext *s, const enum AVPixelFormat *fmt) {</pre><pre>    while (*fmt != AV_PIX_FMT_NONE) {<br>        if (*fmt == AV_PIX_FMT_VIDEOTOOLBOX) {  <br>            if (s-&gt;hwaccel_context == NULL) {<br>                int result = av_videotoolbox_default_init(s);<br>                if (result &lt; 0) {<br>                    return s-&gt;pix_fmt;<br>                }<br>            }<br>            return *fmt;<br>        }<br>        ++fmt;<br>    }<br>    return s-&gt;pix_fmt;<br>}</pre><p>We make sure the VideoToolbox format is available before attempting to use it. If it is not available, or if initializing the videotoolbox integration fails, we fall back to the format originally found by the decoder. Note that the AV_PIX_FMT_VIDEOTOOLBOX is unavailable on the iOS simulator. In the teardown method of our videoplayer class, we check if the codec context’s hwaccell_context is not NULL and call av_videotoolbox_default_free if this is the case.</p><p>Individual video frames are received with avcodec_receive_frame. On return of this function, the AVFrame output parameter will be filled with information encoding a single video frame, depending on the pixel format used. If the VideoToolbox format was successfully used, then a CVPixelBufferRef holding the frame data can be found at AVFrame.data[3]. Although this is not explicitly documented, it is obvious from the comments placed behind the definitions of other hardware-accelerated formats in pixfmt.h. The CVPixelBufferRef cannot immediately be displayed. We first convert it to a CIImage with +[CIImage imageWithCVPixelBuffer:], and then turn the CIImage into a UIImage with +[UIImage imageWithCIImage:]. The finalUIImage describes one video frame and can now be displayed within your video player, e.g. implemented as a plain UIImageView.</p><p>In our tests between using the default pixel format, including the extra conversion step to RGB24, and the VideoToolbox format, we noticed a significant performance difference. With CPU decoding, we experienced an overall sluggish playback and a relatively large number of frame drops. With GPU decoding, close to zero frames were dropped. Despite not being documented too well, digging deeper into the internals of FFMPEG to achieve GPU accelerated decoding of video streams on iOS is definitely worth it.</p><p>We cannot wait to see how our Zepcam integration will improve the workflow of the men and women working everyday to keep our society safe.</p><ol><li><a href="https://trac.ffmpeg.org/wiki/Projects">https://trac.ffmpeg.org/wiki/Projects</a></li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1f000cb6c549" width="1" height="1" alt=""><hr><p><a href="https://medium.com/liveop-x-team/accelerating-h264-decoding-on-ios-with-ffmpeg-and-videotoolbox-1f000cb6c549">Accelerating H264 decoding on iOS with FFMPEG and VideoToolbox</a> was originally published in <a href="https://medium.com/liveop-x-team">LIVEOP X Team</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>