Save video stream VLC - streaming

Given below is the code to stream data using vlc. I want to save the stream. Doing that using GUI is straightforward. How to do it using the C program.
#include <stdio.h>
#include <iostream>
using namespace std;
int main(int argc, char **argv)
{
int ch=system("start C:\\Users\\Administrator\\Desktop\\VideoLAN\\VLC\\vlc http://169.254.159.110/mjpg/1/video.mjpg --sout=\"#duplicate{dst=std{access=file,mux=ts,dst=stream.mp4},dst=display}");
}
I am able to record the stream now the only problem that remains is how to apply a codec to the saved video. Currently, 10 second video is taking about 1MB of space. I want to reduce that substantially.
What do I do?

Related

STM32H745: how to use HAL functions across both cores (example UART)?

I am using UART5 for serial communication from my custom board to my PC. To enable communicating from both CPUs (CM4 and CM7), I use the following configuration in STM32CubeIDE:
So the corresponding initialization is done via the auto-generated code MX_UART5_Init() on CM4. The handle UART_HandleTypeDef huart5 is automatically placed in main() of CM4. Now if I want to send a string to my PC, I can use this HAL function:
HAL_UART_Transmit(&huart5, (const uint8_t*) strg, strLen, timeout);
So far, so good.
The problem is that I cannot call the same function from CM7 because obviously the handle huart5 is unknown on that core. Therefore I've tried to share the handle huart5 via shared memory (SRAM4) to make it known to CM7:
#define HUART ((UART_HandleTypeDef*) (0x30040000UL))
HUART = huart5;
But then the compiler complains that UART_HandleTypeDef is undeclared. Indeed, this typedef is declared in the driver stm32h7xx_hal_uart.h. But when I try to include this file in my corresponding code on CM7, the compiler barfs with hundreds of errors.
In general, what is the proper invocation of HAL functions in case I want to use them on both CPUs for something that's initialized on just one of the cores?
Am I going about serial communication via the dedicated HAL functions from both cores incorrectly?
The problem is that I cannot call the same function from CM7 because obviously the handle huart5 is unknown on that core. Therefore I've tried to share the handle huart5 via shared memory (SRAM4) to make it known to CM7:
That is not true. Your image shows that the UART5 is enabled for CM7 and CM4. In addition, CM4 is designated as the core that will do the initialization of UART5. When the Device Configuration Tool runs it will define huart5 in both cores.
If you look in CM4 and CM7's main.c file you will find:
UART_HandleTypeDef huart5;
To use it outside of main.c simple add the following extern to whatever c file you want to have access to huart5.
extern UART_HandleTypeDef huart5;
I generally add the extern defs for huart handles to the main.h file in each core.
/* Exported constants --------------------------------------------------------*/
/* USER CODE BEGIN EC */
extern UART_HandleTypeDef huart2;
extern UART_HandleTypeDef huart4;
extern UART_HandleTypeDef huart3;
extern osEventFlagsId_t MainTaskMasterEventHandle;
extern osEventFlagsId_t debugTaskMasterEventHandle;
extern osTimerId_t sendRxByteToDpmHandle;
extern TIM_HandleTypeDef htim2;
/* USER CODE END EC */

Simulink Legacy Code Tool - custom Arduino servo write block problem

I'm trying to create my own servo.write block in Simulink for Arduino DUE deployment (and External Mode). Before you ask why if there is one available inside the Simulink Arduino Support Package, generally my final goal is to create a block that will use Arduino servo.writeMicroseconds function (there is no out of the box block for this one) but first i want to try with something simple to debug to see if i can get it to work....
I've been using this guide (https://www.mathworks.com/matlabcentral/fileexchange/39354-device-drivers) and one of working examples in there as a template and started modifying it (originally it implemented Digital Output driver). I took the LCT approach.
The the original digitalio_arduino.cpp/h files from the guide (example with digital read/out) were the files I modified as they were working without any issues out-of-the-box. Step by step i made following modifications:
Remove DIO read (leave only write) from CPP and H files
Change StartFcnSpec to digitalIOSetup and make changes in H file so port is always in OUTPUT mode
Include Servo.h library within CPP file and create Servo object
Up to this point, all edits went fine, no compile errors, all header files were detected by Simulink and diode kept blinking as it should so the code actually worked (i ran it in External Mode).
But as soon as i made the final modification and replaced pinMode() with myservo.attach() and digitalWrite() with myservo.write() (of course i changed the data type in writeDigitalPin function from boolean to uint8_T) the code, despite compiling and building without any issue didn't work at all. Specified servo port was completely dead, as it even wasn't initialised. Changing value on S-Function input didn't yield any results.
Of course If i replaced custom block with built in Servo Write block from Hardware Support Package, everything worked fine so its not hardware issue.
I'm completely out of ideas what could be wrong, especially that there are no errors so not even a hint where to look.
Here is the LCT *.m script used for generating S-Function:
def = legacy_code('initialize');
def.SFunctionName = 'dout_sfun';
def.OutputFcnSpec = 'void NO_OP(uint8 p1, uint8 u1)';
def.StartFcnSpec = 'void NO_OP(uint8 p1)';
legacy_code('sfcn_cmex_generate', def);
legacy_code('compile', def, '-DNO_OP=//')
def.SourceFiles = {fullfile(pwd,'..','src','digitalio_arduino.cpp')};
def.HeaderFiles = {'digitalio_arduino.h'};
def.IncPaths = {fullfile(pwd,'..','src'), 'C:\ProgramData\MATLAB\SupportPackages\R2021b\aIDE\libraries\Servo\src'};
def.OutputFcnSpec = 'void writeDigitalPin(uint8 p1, uint8 u1)';
def.StartFcnSpec = 'void digitalIOSetup(uint8 p1)';
legacy_code('sfcn_cmex_generate', def);
legacy_code('sfcn_tlc_generate', def);
legacy_code('rtwmakecfg_generate',def);
legacy_code('slblock_generate',def);
Here is digitalio_arduino.CPP file
#include <Arduino.h>
#include <Servo.h>
#include "digitalio_arduino.h"
Servo myservo;
// Digital I/O initialization
extern "C" void digitalIOSetup(uint8_T pin)
{
//pinMode(pin, OUTPUT);
myservo.attach(pin);
}
// Write a logic value to pin
extern "C" void writeDigitalPin(uint8_T pin, uint8_T val)
{
//digitalWrite(pin, val);
myservo.write(val);
}
// [EOF]
And here is digitalio_arduino.H file
#ifndef _DIGITALIO_ARDUINO_H_
#define _DIGITALIO_ARDUINO_H_
#include "rtwtypes.h"
#ifdef __cplusplus
extern "C" {
#endif
void digitalIOSetup(uint8_T pin);
void writeDigitalPin(uint8_T pin, uint8_T val);
#ifdef __cplusplus
}
#endif
#endif //_DIGITALIO_ARDUINO_H_
As I mentioned I've been using a working example as a reference. So I've modified it step by step to see if maybe there is a point when suddenly some error comes up but everything compiles yet does not work :/
I was wondering maybe if there is an issue with the Servo.h library or the Servo object and did some tinkering with these, like i removed Servo myservo; line of code to see if anything happens and just like expected, i started receiving errors that Servo is not defined. If I did not include Servo.h at all or forget to add IncPath to Servo.h as before compile errors about Servo not being supported symbol or not being able to find Servo.h library - so actually the code seems to be "working" in a way, it seems to have everything it needs to work :/
I also looked at the MathWorks implementation of Servo Write block, the MWServoReadWrite to see how Arduino API is being used and no surprise, it's being used in the same way as I've been trying to. They include Servo.h, they are using servo.attach() and servo.write() to control the servo port. And that's it. Yet for them it works, for me does not :/
When I inspect generated C code that runs on Arduino (with my custom S-Function block in it), it seems that all the functions are placed exactly where they are supposed to be, they receive correct arguments. I expected at least that I'll find a hint in there, i.e. missing code or anything else.

Implementing SPI library in Arduino (how do classes work?)

I am currently trying to self learn Arduino/C programming/Assembly. I am working on a project which requires a lot of data collection, and by research I discovered a chip called the "23K256" from Microchip (see here: http://www.microchip.com/wwwproducts/Devices.aspx?dDocName=en539039). Moreover, I have also discovered that an Arduino library taking advantage of this chip exists (see here: http://playground.arduino.cc/Main/SpiRAM). I downloaded the "spiRAM3a.zip" file, which I believe is the one most up-to-date. Note that I have only recently downloaded the Arduino software and thus have the latest version installed (I believe it's 1.0.6). Also note that I'm using Arduino Uno, although I will eventually need to use Arduino Mega (I just want this working on ANYTHING at this point). With this library is some code that exemplifies its use to read and write to the 23K256 (the file name is "SpiRAM_Example" included in the package I downloaded), effectively increasing the SRAM on Arduino available. Here is the actual, exact code:
#include <SPI.h>
#include <SpiRAM.h>
#define SS_PIN 10
byte clock = 0;
SpiRAM SpiRam(0, SS_PIN);
void setup() {
Serial.begin(9600);
}
void loop()
{
char data_to_chip[17] = "Testing 90123456";
char data_from_chip[17] = " ";
int i = 0;
// Write some data to RAM
SpiRam.write_stream(0, data_to_chip, 16);
delay(100);
// Read it back to a different buffer
SpiRam.read_stream(0, data_from_chip, 16);
// Write it to the serial port
for (i = 0; i < 16; i++) {
Serial.print(data_from_chip[i]);
}
Serial.print("\n");
delay(1000); // wait for a second
}
My problem is that when I complie the code, to test my confguration and try to learn its use, I surprisingly get an error. This is what I get:
SpiRAM_Example:7: error: 'SpiRAM' does not name a type
SpiRAM_Example.ino: In function 'void loop()':
SpiRAM_Example:20: 'SpiRAM' was not declared in this scope
So it's basically telling me that there's something wrong with the SpiRAM SpiRam(0, SS_PIN);line of code. My question is, why? Am I misunderstanding something very fundamental about how classes work? I feel like I must not be doing something because I highly doubt an incorrect piece of code would be published on Arduino's website. How can I get this code to compile, or at least be able to simply use this library? Should I post the code for the library itself ("SpiRAM.h"), which was included in the package I downloaded?
I would really appreciate any help I can get, and sincerely apologize if this is a really dumb question. I think this is the first I've worked with classes.
Did you download Attach:spiRAM3a.zip or the original? I installed this and your code. It complies on the IDE 1.05

MATLAB fork a (MS Windows) process

Im trying to fork a (MS Windows) process from matlab
myCaller = ['theExe.exe' ' its arguments' ' &'];
system(myCaller);
However, I cannt achieve a fork.
Eventually, what im trying to do is to start a (MS Windows) process, and close the calling MATLAB routine.
Any suggestions of how to achieve the above?
It's tough; I'm working on the same thing at the moment in Ubuntu.
Basically, MATLAB will sit and wait for the spawned program to complete before it continues with its own process, in spite of the & at the end.
The workaround I have been using has been to make use of a mex-file which creates a separate thread (using pthread). This separate thread starts theExe.exe, while the main mex thread exits.
Some untested hacked-together bits of my code which illustrates the process:
#include "mex.h"
#include <iostream>
#include "pthread.h" /* for threading */
// thread function which calls system call, and waits for it to finish
void *do_thread(void *pid)
{
mexPrintf("In thread\n");
// replace this with your system call - don't know if std::system works on windows?
std::system("your_system_call");
pthread_exit(NULL);
}
// main mex function
void mexFunction (int nlhs, mxArray * plhs[], int nrhs, const mxArray * prhs[])
{
pthread_t thread;
mexPrintf("In main: creating thread\n");
rc = pthread_create(&thread, NULL, do_thread, (void *)v);
return;
}
On Ubuntu, this can be compiled something like:
mex mex_filename.cpp -I/usr/include/ -lpthread -lrt
I admit I don't know how to compile this on Windows, but versions of pthreads does exist for Windows.

ACE acceptor - My_Svc_Handler class

I am using the ace acceptor to listen to a TCP port.
my class inherets from My_Svc_Handler and impliments the funcion int open (void *) of the class My_Svc_Handler.
In all the examples I saw, inside the open function, they registor the reactor:
ACE_Reactor::instance()->register_handler(this,
ACE_Event_Handler::READ_MASK);
I dont understant why do we need to registore? I already have a reactore waiting for an event. This I defined in main:
typedef ACE_Acceptor<My_Svc_Handler,ACE_LSOCK_ACCEPTOR> MyAcceptor;
int main(int argc, char* argv[]){
ACE_UNIX_Addr addr("/tmp/addr.ace");
MyAcceptor acceptor(address, ACE_Reactor::instance());
while(1) /* Start the reactors event loop */
ACE_Reactor::instance()->handle_events();
}
I guess I dont understand when is the open function called.
I have another question on that manner. Is there another way in the main not running the while(1) ?
The reason you need to register is because the default implementation of the Reactor in ACE on UNIX/Linux is Select_Reactor and as the name implies all this reactor is doing is running a select system call which dispatches events when the data is available on the socket. So unless you tell select to add the socket to the list of sockets in the selects reading or writing descriptor lists Reactor won't do anything when data is present on the socket.
That's what register_handler is for.