Saving stream of bytes to file in Swift on iOS - ios

I'm using FileHandle to write stream of bytes to the mp4 file.
My data source allows me to input bytesOffset which is basically the current size of the file (if 0 it starts from the beginning, if more then it continue to save until reaches end).
I want to implement restart functionallity, but when write gets interrupted, the file exist, but size is always 0 KB.
Do you know any way to solve this or know any library which could help me with implementing this?

You can use Shamik framework for that.

Related

Generate CRC32 checksum of file swift

I have a .zip file inside the project and I am transferring it to the external ESP32 via Bluetooth. But I need to send the CRC-32 checksum at the end of the sending file. I don't have any idea how to generate it.
Can anyone help me with how to do it in the right way?
Thanks in advance.
So, I have found one amazing framework called CryptoSwift. This made my day. Here is how
Get file Data from the file path.
I have a function which returns Data from file name and type.
And CryptoSwift has the extension of Data which converts the crc32 by calling simply .crc32()
and than call crc32()
let crcChecksum = Utils.sharedInstance.getFileData(forResource: "firmware", withExtension: "bin").crc32()
For mote detail.
https://github.com/krzyzanowskim/CryptoSwift

Create an empty blank audio file of a specific duration in AudioKit

In my project, I am using AudioKit to play beats. I want to create an empty audio file of the same length of the main beat. and and whatever starting point I choose within the duration of the main beat. it will start recording from that point and will end when the main beat is stopped. override the previously recorded part with the newly recorded file. can I achieve with this an empty audio file at the start. Please guide.
In a documentation you can find info about silent file: https://github.com/FT-BOYS/SoundMix/blob/master/AudioKit/Common/Internals/Audio%20File/AKAudioFile%2BUtilities.swift
To create file you can provide just the number of samples to generate (equals length in seconds multiplied by sample rate). It would look something like this:
let file = try! AKAudioFile.silent(samples: sampleRate * seconds)

Can't get stats while using sout with libvlc

I want to display a stream, and monitor the video stats of the displayed stream while recording it using libvlc. When I use sout + duplicate to record the stream while displaying it, I can only get the demux_bitrate stat from the displayed stream using libvlc_media_get_stats function. I am looking to get decoded_video, displayed_pictures, etc as well.
I've tried using the duplicate module to try to make this happen but I can't seem to make this work - am not sure if what I want to do is supported. Code below is tweaked from https://wiki.videolan.org/Documentation:Modules/display/ example for transcoding a stream while displaying the original version.
:sout=#duplicate{dst='transcode{vcodec=h264}:std{access=file,mux=ts,dst=c:\junk\test.mp4}',dst=display}
The stream displays, the file is generated, but the only valid stat is demux_bitrate which seems like the stat that would be accessible from the non-display stream instead of the displayed version.
Display and save with Transcoding
:sout=#duplicate{dst=display,dst="transcode{vcodec=h264}:standard{access=file,mux=mp4,dst=c:\junk\test.mp4}"}
Display and save without Transcoding
:sout=#duplicate{dst=display,dst=standard{access=file,mux=mp4,dst=c:\junk\test.mp4}}

how to redirect the trace window output to a file in CANoe

i would like to get all the data present in the trace window to my text file, even log recording can help but it can't display date and time in that file, so i've a plan to copy entire trace window to file.
i've tried to do ctrl+a and paste in notepad, but it is just copying some sort of area only not all.
i would like to know is there any chance to redirect how trace window is printing like that i can see in text file, or at least is there any way to copy entire file and paste in text file.
The trace windows just display the data, you configure it in the Measurement Setup.
But be aware that this will be only a part of the data anyway. There is a buffer where CANoe stores the data for the Trace window. You can configure the type of this buffer (memory or hard disk) and its size. Go to Options -> Measurement -> Data History to change your settings.
You can also configure the size of the visible data range there. But even with a very long range and a large 200 GB buffer, there might be a possibility that some data will not be available, because the Trace works as a ring buffer deleting the old data on overflow.
If you need the complete data, you should enable the Logging in the Measurement setup. Yes, the data files will be not human-readable. You will then need to open them in the Offline Mode in CANoe to analyze them. The timestamps will be of course logged, so you can easily use them for your analysis.
You could pretty-print it to the write window using CAPL:
on message *
{
int i;
write("[%07.3f] %03X", this.time / 100000.0, this.id);
for (i = 0; i < this.dlc; i++)
writeEx(0, 0, " %02X", this.byte(i));
}
And then export it to a file.
Or you write it directly to a file.
Hi I would suggest logging the necessary data into a CSV and then analyzing using Excel. You can make use of the File Access CAPL functions like openFileWrite for the same

How to extract the song name from a live audio stream on the Blackberry Storm?

HI
I am new to Blackberry.
I am developing an application to get the song name from the live audio stream. I am able to get the mp3 stream bytes from the particular radioserver.To get the song name I add the flag "Icy-metadata:1".So I am getting the header from the stream.To get the mp3 block size I use "Icy-metaInt".How to recognize the metadatablocks with this mp3 block size.I am using the following code.can anyone help me to get it...Here the b[off+k] is the bytes that are from the server...I am converting whole stream in to charArray which is wrong, but how to recognize the metadataHeaders according to the mp3 block size..
b[off+k] = buffers[PlayBuf]PlayByte];
String metaSt = httpConn.getHeaderField("icy-metaint");
metaInt=Integer.parseInt(metaSt);
for (int i=0;i<b[off+k];i++)
{
metadataHeader+=(new String(b)).toCharArray();
System.out.println(metadataHeader);
metadataLength--;
Blackberry has no native regex functionality; I would recommend grabbing the regexp-me library (http://code.google.com/p/regexp-me/) and compiling it into your code. I've used it before and its regex support is pretty good. I think the regex in the code you posted would work just fine.

Resources