Push-Flow is a third-party iflivekit framework. This framework is based on RTMP protocol, the C language and OC language is very clear, very friendly to OC language, relatively simple to use.
The gpuiimage is integrated inside the Iflivekit. The interior achieves such glamorous effects as image rendering. Reduces the development time of the glamorous effect of debugging.
Requirements: Create a simple push-flow page. Included features are: 1. Push-flow status monitoring. 2. Switch the camera. 3. Toggle the glamorous effect. 4. Switch push-flow.
One. Before pushing the stream, you need to check the camera and microphone for permission to open and start the camera, the core code is as follows:
//determine if there is a camera if(![Uiimagepickercontroller Issourcetypeavailable:uiimagepickercontrollersourcetypecamera]) {[Self showinfo:@"your device does not have a webcam or related driver and cannot be streamed"]; return; } //determine if camera permissions are availableAvauthorizationstatus Authorizationstatus =[Avcapturedevice Authorizationstatusformediatype:avmediatypevideo]; if(Authorizationstatus = = avauthorizationstatusrestricted| | authorizationstatus = =avauthorizationstatusdenied) {[Self showinfo:@"the app needs to access your webcam. \ n Please enable webcam-settings/privacy/webcam"]; return ; }Avaudiosession *audiosession =[Avaudiosession sharedinstance]; if([audiosession respondstoselector: @selector (requestrecordpermission:)]) {[Audiosession performselector: @selec Tor (requestrecordpermission:) Withobject:^(BOOL granted) {if(granted) {returnYES; } Else{[Self showinfo:@"the app needs to access your microphone. \ n Please enable microphone-settings/privacy/Microphone"]; returnNO; } }]; }
Two. Create a button. Click the start stream code below:
-(lflivesession*) session{if(!_session) { /** * Default Resolution 368 * 640 Audio: 44.1 iphone6 above 48 dual channel Direction Vertical screen * **/_session=[[Lflivesession alloc] initwithaudioconfiguration:[lfliveaudioconfiguration defaultconfiguration] Videoconfiguration:[lflivevideoconfiguration Defaultconfigurationforquality:lflivevideoquality_medium2]]; /** Customized high-quality audio 128K resolution set to 720*1280 direction vertical screen*/ /* Lfliveaudioconfiguration *audioconfiguration = [lfliveaudioconfiguration new]; Audioconfiguration.numberofchannels = 2; Audioconfiguration.audiobitrate = lfliveaudiobitrate_128kbps; Audioconfiguration.audiosamplerate = lfliveaudiosamplerate_44100hz; Lflivevideoconfiguration *videoconfiguration = [lflivevideoconfiguration new]; Videoconfiguration.videosize = Cgsizemake (720, 1280); Videoconfiguration.videobitrate = 800*1024; Videoconfiguration.videomaxbitrate = 1000*1024; Videoconfiguration.videominbitrate = 500*1024; Videoconfiguration.videoframerate = 15; Videoconfiguration.videomaxkeyframeinterval = 30; Videoconfiguration.orientation = uiinterfaceorientationportrait; Videoconfiguration.sessionpreset = lfcapturesessionpreset720x1280; _session = [[Lflivesession alloc] initwithaudioconfiguration:audioconfiguration videoconfiguration: Videoconfiguration LivetypE:LFLIVERTMP]; */ //Set up proxy_session.Delegate=Self ; _session.running=YES; _session.preview=Self.livingpreview; } return_session;}-(Ibaction) starttouched: (ID) Sender {Lflivestreaminfo*stream = [LflivestreaminfoNew]; //Local push stream addressStream.url =@"Rtmp://192.168.199.131:1935/rtmplive/room"; Self.rtmpurl=Stream.url; [Self.session Startlive:stream];}
3. Create a button click to close the push stream, the code is as follows
-(Ibaction) endtouched: (ID) sender { // end live broadcast [self.session stoplive ]; = [NSString stringWithFormat:@ " Status: Live is turned off \nrtmp:%@", Self.rtmpurl];}
4. Create a button click Switch front and rear camera, code as follows
-(Ibaction) camabtntouched: (ID) sender { = self.session.captureDevicePosition; = (Devicepositon = = avcapturedevicepositionback)? Avcapturedevicepositionfront:avcapturedevicepositionback; NSLog (@ " Toggle Front/rear camera ");}
5. Create a button to set the glamorous function, the code is as follows
-(Ibaction) beautiybtntouched: (ID) sender {( (UIButton*) sender). Selected =! ( (uibutton*) sender). Selected; // The default is to turn on the beauty function Self.session.beautyFace =! Self.session.beautyFace;}
6. Push Stream status monitor, accept Agent, code as follows:
#pragmaMark--Lfstreamingsessiondelegate/** Live status changed'll callback*/- (void) Livesession: (Nullable lflivesession *) session Livestatedidchange: (lflivestate) state{nsstring*Tempstatus; Switch(state) { CaseLfliveready:tempstatus=@"in preparation"; Break; CaseLflivepending:tempstatus=@"in the connection"; Break; CaseLflivestart:tempstatus=@"is connected"; Break; CaseLflivestop:tempstatus=@"has been disconnected"; Break; CaseLfliveerror:tempstatus=@"Connection Error"; Break; default: Break; } Self.stateLable.text= [NSString stringWithFormat:@"Status:%@\nrtmp:%@", Tempstatus, Self.rtmpurl];}/** Live Debug Info callback*/- (void) Livesession: (Nullable lflivesession *) session Debuginfo: (Nullable lflivedebug*) debuginfo{}/** Callback Socket ErrorCode*/- (void) Livesession: (Nullable lflivesession*) session ErrorCode: (Lflivesocketerrorcode) errorcode{}
6. You also need to see your own push-flow screen, and observe the glamorous effect, the code is as follows:
-(UIView *) livingpreview{ if (! _livingpreview) { *livingpreview = [[UIView alloc] initWithFrame:self.view.bounds]; = [Uicolor clearcolor]; = Uiviewautoresizingflexiblewidth | Uiviewautoresizingflexibleheight; [Self.view insertsubview:livingpreview Atindex: 0 ]; = livingpreview; } return _livingpreview;}
At this point, the push-flow work is completed.
iOS simple live streaming Implementation (II: Push stream)