IOS DLNA Cyberlink,platinumkit Library complete DLNA feature

Source: Internet
Author: User
Tags cyberlink

After one months of research, the iOS DLNA is finally done. Record it.

With regard to DLNA development, there are currently two frameworks. A CyberLink, a platinumkit. The advantage of CyberLink is that it provides a set of OC APIs for you to call, very simple and convenient. However, this framework has many problems and is not fully functional. Platinumkit frame Bottom for C + +, to use this set of framework, you have to do OC and C + + mixed, I did not do the OC and C + + mixed, so to see the source of Platinumkit, feel headache incomparable, wasted a lot of time, However, there are many features that cannot be solved using the CyberLink framework, and the framework often has problems. The final completion of the DMC part of the time or the use of CyberLink, there are problems to do, can only bite the bullet to change the source. Fortunately, it was finally settled.

1.DMS

First let the mobile phone itself have the function of DMS, the Platinumkit frame used here. There was a demo:https://github.com/wangshuaidavid/dlna_ios_platinum on GitHub, which was largely dependent on the demo to complete the DMS portion of the phone. About the use of Platinumkit Library, the online tutorial, you can refer to, is to compile a. A file out, and then pull into their project: A file of the simulator and the real machine two, you can synthesize one through the terminal. There is nothing to say about the DMS section, mainly look at the demo is good.

2.dmc,dmr

Using the CyberLink Library to complete the DMC function, there is a demo:https://github.com/furuyamatakeshi/dlna on GitHub. This demo completes the basic DMC function and can search for DMS,DMR within the same LAN.

    cgupnpavcontroller* Avctrl = [[Cgupnpavcontroller alloc] init];    Avctrl. delegate = self ;    [Avctrl Search];     = Avctrl;

This Cgupnpavcontroller class is about searching for DMS,DMR. Through the Avctrl can get to the corresponding DMS, and then send a browse file to the DMS action, return to the file content, and finally always get avitem, that is, the address of the resource file. Then the DMR gets to this resource file address and, through Setavtransporturi, sets the request address of the real DMR device. Play will play when the settings are successful. It may seem simple to see here, but CyberLink's DMR only provides Play,stop,pause,next,previous,seek methods, and next,previous methods are useless. If you want to accomplish more, either use the Platinumkit framework or add these features to the DMR yourself. I chose the latter.

To change the source code first to understand the whole DLNA working principle. Detailed working principle I also do not understand, I just in the study of these two frameworks, I slowly understand some.

      First, either DMS, or DMR, is a device that can be seen through code. Cgupnpavserver,cgupnpavrender are inherited from the cgupnpdevice. The cgupnpdevice contains a structure of a cgupnpdevice. And this Cgupnpdevice class is the key to the construction of DMS,DMR. Cgupnpdevice This class has a method, initwithxmldescription. That is, a device is created from an XML. When you use DMS's standard XML to create a device, it is DMS. When you use the standard DMR XML to create a device, it is a DMR. The two XML that created the device are as follows

-(NSString *) getDMSDespritionXMl1000000000: (NSString *) uuid{return [NSString stringwithformat:@ "<?xml version=" 1.0 ' encoding= ' utf-8 ' standalone= ' yes '? ><root xmlns= ' urn:schemas-upnp-org:device-1-0 ' ><specversion ><major>1</major><minor>0</minor></specversion><device><devicetype >urn:schemas-upnp-org:device:mediaserver:1</devicetype><manufacturer>plutinosoft LLC</ Manufacturer><manufacturerurl>http://www.plutinosoft.com</manufacturerurl><modeldescription >plutinosoft AV Media Server device</modeldescription><modelname>av Media server Device</modelname ><modelurl>http://www.plutinosoft.com/platinum</modelurl><udn>uuid:%@</udn><dlna : X_dlnadoc xmlns:dlna= ' urn:schemas-dlna-org:device-1-0 ' >DMS-1.50</dlna:X_DLNADOC><serviceList> <service><serviceType>urn:microsoft.com:service:X_MS_MediaReceiverRegistrar:1</serviceType> <seRviceid>urn:microsoft.com:serviceid:x_ms_mediareceiverregistrar</serviceid><scpdurl>/x_ms_ mediareceiverregistrar/%@/scpd.xml</scpdurl><controlurl>/x_ms_mediareceiverregistrar/%@/ Control.xml</controlurl><eventsuburl>/x_ms_mediareceiverregistrar/%@/event.xml</eventsuburl> </service><service><servicetype>urn:schemas-upnp-org:service:contentdirectory:1</ servicetype><serviceid>urn:upnp-org:serviceid:contentdirectory</serviceid><scpdurl>/ Contentdirectory/%@/scpd.xml</scpdurl><controlurl>/contentdirectory/%@/control.xml</controlurl ><eventSubURL>/ContentDirectory/%@/event.xml</eventSubURL></service><service>< Servicetype>urn:schemas-upnp-org:service:connectionmanager:1</servicetype><serviceid>urn: upnp-org:serviceid:connectionmanager</serviceid><scpdurl>/connectionmanager/%@/scpd.xml</ Scpdurl><controlurl>/connectionmanager/%@/coNtrol.xml</controlurl><eventsuburl>/connectionmanager/%@/event.xml</eventsuburl></service ></serviceList></device></root> ", Uuid,uuid,uuid,uuid,uuid,uuid,uuid,uuid,uuid,uuid];}

 

-(NSString *) getDMRDescriptionXml11111: (NSString *) uuid{return [NSString stringwithformat:@ "<?xml version= ' 1.0 ' E ncoding= ' UTF-8 '? ><root xmlns= ' urn:schemas-upnp-org:device-1-0 ' xmlns:dlna= ' urn:schemas-dlna-org:device-1-0 ' ><specversion><major>1</major><minor>0</minor></specversion><device ><devicetype>urn:schemas-upnp-org:device:mediarenderer:1</devicetype><friendlyname>hitv_ Dmr</friendlyname><manufacturer>plutinosoft llc</manufacturer><manufacturerurl>http:// Www.plutinosoft.com</manufacturerURL><modelDescription>Plutinosoft AV Media Renderer device</ Modeldescription><modelname>av Renderer device</modelname><modelurl>http:// www.plutinosoft.com/platinum</modelurl><serialnumber></serialnumber><udn>uuid:%@</ Udn><dlna:x_dlnadoc xmlns:dlna= ' urn:schemas-dlna-org:device-1-0 ' >DMR-1.50</dlna:X_DLNADOC>< servicelist>&Lt;service><servicetype>urn:schemas-upnp-org:service:avtransport:1</servicetype><serviceid >urn:upnp-org:serviceid:avtransport</serviceid><scpdurl>/avtransport/%@/scpd.xml</scpdurl ><controlurl>/avtransport/%@/control.xml</controlurl><eventsuburl>/avtransport/%@/ Event.xml</eventsuburl></service><service><servicetype>urn:schemas-upnp-org:service: Connectionmanager:1</servicetype><serviceid>urn:upnp-org:serviceid:connectionmanager</serviceid ><scpdurl>/connectionmanager/%@/scpd.xml</scpdurl><controlurl>/connectionmanager/%@/ control.xml</controlurl><eventsuburl>/connectionmanager/%@/event.xml</eventsuburl></ Service><service><servicetype>urn:schemas-upnp-org:service:renderingcontrol:1</servicetype ><serviceid>urn:upnp-org:serviceid:renderingcontrol</serviceid><scpdurl>/renderingcontrol /%@/scpd.xml</scpdurl><contRolurl>/renderingcontrol/%@/control.xml</controlurl><eventsuburl>/renderingcontrol/%@/event.xml </eventSubURL></service></serviceList></device></root> ", Uuid,uuid,uuid,uuid,uuid  , Uuid,uuid,uuid,uuid,uuid];}

The UUID here does not have a device's UUID. After creating a good device from XML, you also need to set friendlyname and Loactionurl for the device. There is no way to set locationurl in the CyberLink library, so you have to add one yourself.

-(void) Setlocationurl: (NSString *) url{    if (!cobject) {        return;    }    Cg_upnp_device_setlocationfromssdppacket (CObject, (char *) [url utf8string]);}

This cg_upnp_device_setlocationfromssdppacket method is also added to the library itself. Looks more troublesome, in fact very simple, is through the device's sspdpacket to modify the Loactionurl. After you change this, your device is created, and you can create a DMS or a DMR by using the Initwithcobject method corresponding to DMS or DMR. Why do you create DMS or DMR yourself? This is because of my own development needs, I can not use Cgupnpavcontroller this class to search for DMS or DMR, so you can only take the initiative to create, if your needs are to do normal search function, do not need to do so, but I say these are to tell me about the DMS, Some understanding of the DMR.

Now let's see how the DMR is played.

if ([Self.renderer SetAVTransportWithItem:self.avItem]) {        [Self.renderer playwithurl:[self.avitem.resourceurl Description]];        Self.isplay = [Self.renderer isplaying];    }

  is just these lines of code, and the DMR plays the corresponding DMS resource file. Follow in this setavtransportwithitem method, found that it is mainly to obtain a Aciton, and then follow in, found to get a service first. This service is not the same as our DMS. This service is a device service. We can look at the XML that created the device again. The XML contains some basic information about the device, and it contains a servicelist! This is the servicelist.

<servicelist><service><servicetype>urn:schemas-upnp-org:service:avtransport:1</ servicetype><serviceid>urn:upnp-org:serviceid:avtransport</serviceid><scpdurl>/ avtransport/%@/scpd.xml</scpdurl><controlurl>/avtransport/%@/control.xml</controlurl>< Eventsuburl>/avtransport/%@/event.xml</eventsuburl></service><service><servicetype> Urn:schemas-upnp-org:service:connectionmanager:1</servicetype><serviceid>urn:upnp-org:serviceid: Connectionmanager</serviceid><scpdurl>/connectionmanager/%@/scpd.xml</scpdurl><controlurl >/ConnectionManager/%@/control.xml</controlURL><eventSubURL>/ConnectionManager/%@/event.xml< /eventsuburl></service><service><servicetype>urn:schemas-upnp-org:service: Renderingcontrol:1</servicetype><serviceid>urn:upnp-org:serviceid:renderingcontrol</serviceid ><SCPDURL>/RenderingControl/%@/scpd.xml</scpdurl><controlurl>/renderingcontrol/%@/control.xml</controlurl><eventsuburl>/ Renderingcontrol/%@/event.xml</eventsuburl></service></servicelist>

This should be understood, each device has a servicelist, by name to obtain the corresponding service, and then through the service to get to the action you want, and then post the action, Our real-world device can receive this action on the LAN, responding to actions. Including DMS, it works the same way, through post action, to get the file directory in DMS.

So how do we add the fast forward, rewind, volume and other functions we want to the DMR? you look at this servicelist, there are a few XML path, your Locationurl address is added to the XML path, and then opened in the browser (in Firefox browser Open). One of the actionlist,actionlist contains a variety of Aciton, and then you can take the initiative to get the action yourself, then post it, and add the features you want with your DMR.

There are some pits in the ps:cyberlink, I also remember not very clear, can add how much.

1:setavtransporturi This method does not distinguish between the category of item, such as music or pictures or video, you need to change it. I changed it into a setavtransportwithitem, passed Avitem in, and judged the type of item.

-(BOOL) Setavtransportwithitem: (Cgupnpavitem *) item{    cgupnpaction *action = [self actionoftransportserviceforname:@ "Setavtransporturi"];    if (!action)        return NO;    [Action setargumentvalue:@ "0" forname:@ "InstanceID"];    [Action Setargumentvalue:[item.resourceurl description] forname:@ "Currenturi"];    NSString *classstr = [NSString string];    if ([item Isaudioclass])         classstr = @ "Audioitem";    }    else if ([item Isvideoclass])    {        classstr = @ "Videoitem";    }    else if ([item Isimageclass])    {        classstr = @ "Imageitem";    }    [Action setargumentvalue:[self Getcurrenturimetadata:[item.resourceurl description] with:classstr] forname:@ " Currenturimetadata "];    if (![ Action post])        return NO;        return YES;}

2: In the creation of the device, in fact, your servicelist is not initialized, the specific reason is what I do not know, may be the framework itself defects. So you need to initiate the initialization yourself.

First you go to get the service, then get the action from the service, you will find the service actionlist is either empty, or only one action, follow the Getactionforname method, put

#ifdef Cg_optimized_cp_mode This line, this time it will determine whether the service has been initialized, not initialized once. Of course, this is not insurance, it is best to be able to create a device after the active initialization of servicelist. So I added a way to initialize the servicelist in Cgupnpdevice.

-(void) parisedscpdurl{    if (!cobject) {        return;    }    Nsarray *servise = self.services;    for (int i = 0; i < Servise.count; i++) {        Cgupnpservice *ser = servise[i];        CG_UPNP_CONTROLPOINT_PARSESCSERVICESCPD (Ser.cobject);    }}

That's fine. So every time you get the action, the inside Servicelist is initialized and there is no action to take.

3: Many of the network requests are not used in multi-threaded, such as to initialize the servicelist, it is best to add an asynchronous operation, to avoid blocking the main thread.

At present can think of so many, indeed cyberlink pits more, a start to complete the normal DMS,DMC and other functions in fact quite fast, but our needs are not the same, not allowed to expose DMS,DMR in the LAN, so only to actively build, in order to this demand went a lot of detours, has been studied for one months before the fix, write a blog post to retain the research process at that time ....

IOS DLNA Cyberlink,platinumkit Library complete DLNA functionality

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.