Using libmms with Objective-C

I searched several days on the Internet for tutorials or examples of how to use libmms. It seems that there is not one that is strange for lib, which seems to be widely used.

LibMMS is a common library for parsing mms: // and mmsh: // the type of network streams. http://sourceforge.net/projects/libmms/files/libmms/0.6.2/libmms-0.6.2.tar.gz/download

The only sample code I found was from another post on stackoverflow.

What will be shown below.

mms_connect(NULL, NULL, g_tcUrl.av_val, g_hostname.av_val, g_playpath.av_val, "", g_port, 128*1024) 

Note:

 NSString* strTemp; strTemp = @"mms://123.30.49.85/htv2"; // strTemp = @"mms://212.58.251.92/wms/bbc_ami/radio1/radio1_bb_live_int_eq1_sl0"; g_tcUrl.av_val = new char[[strTemp length] + 1]; [strTemp getCString:g_tcUrl.av_val maxLength:([strTemp length]+1) encoding:NSUTF8StringEncoding]; g_tcUrl.av_len = strlen(g_tcUrl.av_val); //strTemp = @"212.58.251.92"; strTemp = @"123.30.49.85"; g_hostname.av_val = new char[[strTemp length]+1]; [strTemp getCString:g_hostname.av_val maxLength:([strTemp length]+1) encoding:NSUTF8StringEncoding]; g_hostname.av_len = strlen(g_hostname.av_val); //strTemp = @"/wms/bbc_ami/radio1/radio1_bb_live_int_eq1_sl0"; strTemp = @"/htv2"; g_playpath.av_val = new char[[strTemp length] + 1]; [strTemp getCString:g_playpath.av_val maxLength:([strTemp length]+1) encoding:NSUTF8StringEncoding]; g_playpath.av_len = strlen(g_playpath.av_val); g_port = 1755; 

This is not objective C, but shows what needs to be passed to the mms_connect method.

So, I created a new project, included all the necessary libmms files and built it. Compiled fine.

The next step was to turn on

 #import "mms.h" #import "mms_config.h" 

and declare

 mms_t *mms = 0; 

No problem so far.

The next thing I wanted to try is to call the mms_connect method, and this is where I got stuck.

I'm not a C programmer, so it might look FUBAR, but it was the best attempt. I can not use

 char *g_tcUrl = new char[[strTemp length] + 1]; 

because the new one is not recognized in lens c in the way it is used here. What should I use to achieve the same effect in Objective-C?

 mms_t *mms = 0; NSString* strTemp; strTemp = @"mms://123.30.49.85/htv2"; char *g_tcUrl = new char[[strTemp length] + 1]; [strTemp getCString:g_tcUrl maxLength:([strTemp length]+1) encoding:NSUTF8StringEncoding]; strTemp = @"123.30.49.85"; char *g_hostname = new char[[strTemp length]+1]; [strTemp getCString:g_hostname maxLength:([strTemp length]+1) encoding:NSUTF8StringEncoding]; strTemp = @"/htv2"; char * g_playpath = new char[[strTemp length] + 1]; [strTemp getCString:g_playpath maxLength:([strTemp length]+1) encoding:NSUTF8StringEncoding]; int g_port = 1755; //mms = mms_connect(mms_io_t *io, void *data, const char *url, const char *host, const char *uri, const char *query, int port, int bandwidth); mms = mms_connect(NULL, NULL, g_tcUrl, g_hostname, g_playpath, "", g_port, 128*1024); 

Now I am trying to mix C code inside objective-c files. This code was inside my viewDidLoad when I try to check and figure out exactly how to use libmms.

Guys, I would appreciate all the advice and help you can offer in my searches to get libmms to work in my application.

code

+6
source share
3 answers

The simplest version I can think of:

 // wherever these NSStrings come from in the app, we can use them NSString *mmsURL = @"mms://123.30.49.85/htv2", *mmsHostname = @"123.30.49.85", *mmsPath = @"/htv2"; NSInteger port = 1755; mms_t *mms = mms_connect(NULL, NULL, [mmsURL cStringUsingEncoding:NSASCIIStringEncoding], [mmsHostname cStringUsingEncoding:NSASCIIStringEncoding], [mmsPath cStringUsingEncoding:NSASCIIStringEncoding], "", port, 128*1024); 

To transfer data in another way (if you want to transfer stream data to a user movie player based on AVPlayer or similar):

 char *myCString = "some data coming from libmms"; NSString *myStringFromACString = [NSString stringWithCString:myCString usingEncoding:NSASCIIStringEncoding]; 
+3
source

You can mix C ++ and Objective-C in one file. Either specify the .mm extension file, or change the file type to sourcecode.cpp.objcpp.

+4
source

You make things too complicated. You do not need to use a new one here.

 mms_t *mms = 0; const char* g_tcUrl = "mms://123.30.49.85/htv2"; // Easy C String, // No need for heap allocation. const char* g_hostname = "123.30.49.85"; const char* g_playpath = "/htv2"; int g_port = 1755; //mms = mms_connect(mms_io_t *io, void *data, const char *url, const char *host, const char *uri, const char *query, int port, int bandwidth); mms = mms_connect(NULL, NULL, g_tcUrl, g_hostname, g_playpath, "", g_port, 128*1024); 

Also the new one is not part of C. It is part of C ++, in C you must use malloc to allocate memory on the heap.

+2
source

Source: https://habr.com/ru/post/885716/


All Articles