@@ -33,6 +33,8 @@ of this software and associated documentation files (the "Software"), to deal
33
33
#include < videocore/transforms/AspectTransform.h>
34
34
#include < videocore/transforms/PositionTransform.h>
35
35
36
+ #import " Reachability.h"
37
+
36
38
#ifdef __APPLE__
37
39
# include < videocore/mixers/Apple/AudioMixer.h>
38
40
# include < videocore/transforms/Apple/MP4Multiplexer.h>
@@ -147,6 +149,18 @@ @interface VCSimpleSession()
147
149
VCFilter _filter;
148
150
}
149
151
@property (nonatomic , readwrite ) VCSessionState rtmpSessionState;
152
+ /* *
153
+ 根据当前网络状态自动初始化:
154
+
155
+ 当前网络为Wifi条件时,视频为720p,当isPortrait=YES时采用 VCVideoQuality720x1280,NO时采用 VCVideoQuality1280x720;
156
+
157
+ 当前为移动网络时,视频为480p,当isPortrait=YES时采用 VCVideoQuality480x640,NO时采用 VCVideoQuality640x480;
158
+
159
+ 其他网络状态时,视频为360p,当isPortrait=YES时采用 VCVideoQuality360x480,NO时采用VCVideoQuality480x360.
160
+
161
+ @param isPortrait 屏幕宽高是否设置为竖屏方向
162
+ */
163
+ -(id )initWithCurrentNet : (BOOL )isPortrait ;
150
164
151
165
- (void ) setupGraph ;
152
166
@@ -468,50 +482,80 @@ - (instancetype) initWithVideoSize:(CGSize)videoSize
468
482
-(instancetype ) initWithQuality : (VCVideoQuality)quality
469
483
{
470
484
if (self = [super init ]) {
471
- CGSize videoSize;
472
- int bit = 0 ;
473
- int frameRate = 30 ;
474
- BOOL userOrientation = NO ;
475
- switch (quality) {
476
- case VCVideoQuality1280x720:
477
- bit = 10506240 ;
478
- videoSize = CGSizeMake (1280 , 720 );
479
- break ;
480
- case VCVideoQuality720x1280:
481
- bit = 10506240 ;
482
- videoSize = CGSizeMake (720 , 1280 );
483
- break ;
484
- case VCVideoQuality640x480:
485
- bit = 3502080 ;
486
- videoSize = CGSizeMake (640 , 480 );
487
- break ;
488
- case VCVideoQuality480x640:
489
- bit = 3502080 ;
490
- videoSize = CGSizeMake (480 , 640 );
491
- break ;
492
- case VCVideoQuality480x360:
493
- bit = 700000 ;
494
- videoSize = CGSizeMake (480 , 360 );
495
- break ;
496
- case VCVideoQuality360x480:
497
- bit = 700000 ;
498
- videoSize = CGSizeMake (360 , 480 );
499
- break ;
500
- default :
501
- break ;
502
- }
503
- if (bit > 0 ) {
504
- [self initInternalWithVideoSize: videoSize
505
- frameRate: frameRate
506
- bitrate: bit
507
- useInterfaceOrientation: userOrientation
508
- cameraState: VCCameraStateBack
509
- aspectMode: VCAspectModeFit];
485
+ [self initInternalWithQuality: quality];
486
+ }
487
+ return self;
488
+ }
489
+
490
+ -(id )initWithCurrentStatus
491
+ {
492
+ UIInterfaceOrientation orientation = [[UIApplication sharedApplication ] statusBarOrientation ];
493
+ BOOL isPortrait = UIInterfaceOrientationIsPortrait (orientation);
494
+ return [self initWithCurrentNet: isPortrait];
495
+ }
496
+
497
+ -(id )initWithCurrentNet : (BOOL )isPortrait
498
+ {
499
+ self = [super init ];
500
+ if (self) {
501
+ NetworkStatus status = [self currentStatus ];
502
+ if (status == ReachableViaWiFi) {
503
+ isPortrait ? [self initInternalWithQuality: VCVideoQuality720x1280]:[self initInternalWithQuality: VCVideoQuality1280x720];
504
+ } else if (status == ReachableViaWWAN) {
505
+ isPortrait ? [self initInternalWithQuality: VCVideoQuality640x480]:[self initInternalWithQuality: VCVideoQuality640x480];
506
+ } else {
507
+ isPortrait ? [self initInternalWithQuality: VCVideoQuality480x360]:[self initInternalWithQuality: VCVideoQuality480x360];
510
508
}
509
+ _useInterfaceOrientation = YES ;
510
+ _orientationLocked = YES ;
511
511
}
512
512
return self;
513
513
}
514
514
515
+ -(void ) initInternalWithQuality : (VCVideoQuality)quality
516
+ {
517
+ CGSize videoSize;
518
+ int bit = 0 ;
519
+ int frameRate = 30 ;
520
+ BOOL userOrientation = NO ;
521
+ switch (quality) {
522
+ case VCVideoQuality1280x720:
523
+ bit = 10506240 ;
524
+ videoSize = CGSizeMake (1280 , 720 );
525
+ break ;
526
+ case VCVideoQuality720x1280:
527
+ bit = 10506240 ;
528
+ videoSize = CGSizeMake (720 , 1280 );
529
+ break ;
530
+ case VCVideoQuality640x480:
531
+ bit = 3502080 ;
532
+ videoSize = CGSizeMake (640 , 480 );
533
+ break ;
534
+ case VCVideoQuality480x640:
535
+ bit = 3502080 ;
536
+ videoSize = CGSizeMake (480 , 640 );
537
+ break ;
538
+ case VCVideoQuality480x360:
539
+ bit = 700000 ;
540
+ videoSize = CGSizeMake (480 , 360 );
541
+ break ;
542
+ case VCVideoQuality360x480:
543
+ bit = 700000 ;
544
+ videoSize = CGSizeMake (360 , 480 );
545
+ break ;
546
+ default :
547
+ break ;
548
+ }
549
+ if (bit > 0 ) {
550
+ [self initInternalWithVideoSize: videoSize
551
+ frameRate: frameRate
552
+ bitrate: bit
553
+ useInterfaceOrientation: userOrientation
554
+ cameraState: VCCameraStateBack
555
+ aspectMode: VCAspectModeFit];
556
+ }
557
+ }
558
+
515
559
- (void ) initInternalWithVideoSize : (CGSize)videoSize
516
560
frameRate : (int )fps
517
561
bitrate : (int )bps
@@ -752,7 +796,21 @@ - (void)setFilter:(VCFilter)filterToChange {
752
796
// Private Methods
753
797
// -----------------------------------------------------------------------------
754
798
#pragma mark - Private Methods
755
-
799
+ -(NetworkStatus)currentStatus
800
+ {
801
+ NSLog (@" current status: %ld " ,[[Reachability reachabilityForLocalWiFi ] currentReachabilityStatus ]);
802
+ return [[Reachability reachabilityForLocalWiFi ] currentReachabilityStatus ];
803
+ }
804
+ -(BOOL )isWifi
805
+ {
806
+ NSLog (@" iswifi: %ld " ,[[Reachability reachabilityForLocalWiFi ] currentReachabilityStatus ]);
807
+ return ([[Reachability reachabilityForLocalWiFi ] currentReachabilityStatus ] != NotReachable);
808
+ }
809
+ -(BOOL )isNet
810
+ {
811
+ NSLog (@" iswifi: %ld " ,[[Reachability reachabilityForInternetConnection ] currentReachabilityStatus ]);
812
+ return ([[Reachability reachabilityForInternetConnection ] currentReachabilityStatus ] != NotReachable);
813
+ }
756
814
757
815
- (void ) setupGraph
758
816
{
0 commit comments